Jeff Kirsher | 51dce24 | 2018-04-26 08:08:09 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* Copyright(c) 1999 - 2018 Intel Corporation. */ |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 3 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 4 | #include <linux/debugfs.h> |
| 5 | #include <linux/module.h> |
| 6 | |
| 7 | #include "ixgbe.h" |
| 8 | |
| 9 | static struct dentry *ixgbe_dbg_root; |
| 10 | |
Catherine Sullivan | 91fbd8f | 2012-08-10 01:59:21 +0000 | [diff] [blame] | 11 | static char ixgbe_dbg_reg_ops_buf[256] = ""; |
| 12 | |
YueHaibing | e9c7218 | 2018-05-23 20:08:13 +0800 | [diff] [blame] | 13 | static ssize_t ixgbe_dbg_common_ops_read(struct file *filp, char __user *buffer, |
| 14 | size_t count, loff_t *ppos, |
| 15 | char *dbg_buf) |
Catherine Sullivan | 91fbd8f | 2012-08-10 01:59:21 +0000 | [diff] [blame] | 16 | { |
| 17 | struct ixgbe_adapter *adapter = filp->private_data; |
joshua.a.hay@intel.com | 3288d73 | 2012-11-28 05:49:20 +0000 | [diff] [blame] | 18 | char *buf; |
Catherine Sullivan | 91fbd8f | 2012-08-10 01:59:21 +0000 | [diff] [blame] | 19 | int len; |
| 20 | |
| 21 | /* don't allow partial reads */ |
| 22 | if (*ppos != 0) |
| 23 | return 0; |
| 24 | |
joshua.a.hay@intel.com | 3288d73 | 2012-11-28 05:49:20 +0000 | [diff] [blame] | 25 | buf = kasprintf(GFP_KERNEL, "%s: %s\n", |
YueHaibing | e9c7218 | 2018-05-23 20:08:13 +0800 | [diff] [blame] | 26 | adapter->netdev->name, dbg_buf); |
joshua.a.hay@intel.com | 3288d73 | 2012-11-28 05:49:20 +0000 | [diff] [blame] | 27 | if (!buf) |
| 28 | return -ENOMEM; |
Catherine Sullivan | 91fbd8f | 2012-08-10 01:59:21 +0000 | [diff] [blame] | 29 | |
joshua.a.hay@intel.com | 3288d73 | 2012-11-28 05:49:20 +0000 | [diff] [blame] | 30 | if (count < strlen(buf)) { |
| 31 | kfree(buf); |
| 32 | return -ENOSPC; |
| 33 | } |
| 34 | |
| 35 | len = simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf)); |
| 36 | |
| 37 | kfree(buf); |
Catherine Sullivan | 91fbd8f | 2012-08-10 01:59:21 +0000 | [diff] [blame] | 38 | return len; |
| 39 | } |
| 40 | |
| 41 | /** |
YueHaibing | e9c7218 | 2018-05-23 20:08:13 +0800 | [diff] [blame] | 42 | * ixgbe_dbg_reg_ops_read - read for reg_ops datum |
| 43 | * @filp: the opened file |
| 44 | * @buffer: where to write the data for the user to read |
| 45 | * @count: the size of the user's buffer |
| 46 | * @ppos: file position offset |
| 47 | **/ |
| 48 | static ssize_t ixgbe_dbg_reg_ops_read(struct file *filp, char __user *buffer, |
| 49 | size_t count, loff_t *ppos) |
| 50 | { |
| 51 | return ixgbe_dbg_common_ops_read(filp, buffer, count, ppos, |
| 52 | ixgbe_dbg_reg_ops_buf); |
| 53 | } |
| 54 | |
| 55 | /** |
Catherine Sullivan | 91fbd8f | 2012-08-10 01:59:21 +0000 | [diff] [blame] | 56 | * ixgbe_dbg_reg_ops_write - write into reg_ops datum |
| 57 | * @filp: the opened file |
| 58 | * @buffer: where to find the user's data |
| 59 | * @count: the length of the user's data |
| 60 | * @ppos: file position offset |
| 61 | **/ |
| 62 | static ssize_t ixgbe_dbg_reg_ops_write(struct file *filp, |
| 63 | const char __user *buffer, |
| 64 | size_t count, loff_t *ppos) |
| 65 | { |
| 66 | struct ixgbe_adapter *adapter = filp->private_data; |
joshua.a.hay@intel.com | 3288d73 | 2012-11-28 05:49:20 +0000 | [diff] [blame] | 67 | int len; |
Catherine Sullivan | 91fbd8f | 2012-08-10 01:59:21 +0000 | [diff] [blame] | 68 | |
| 69 | /* don't allow partial writes */ |
| 70 | if (*ppos != 0) |
| 71 | return 0; |
| 72 | if (count >= sizeof(ixgbe_dbg_reg_ops_buf)) |
| 73 | return -ENOSPC; |
| 74 | |
joshua.a.hay@intel.com | 3288d73 | 2012-11-28 05:49:20 +0000 | [diff] [blame] | 75 | len = simple_write_to_buffer(ixgbe_dbg_reg_ops_buf, |
| 76 | sizeof(ixgbe_dbg_reg_ops_buf)-1, |
| 77 | ppos, |
| 78 | buffer, |
| 79 | count); |
| 80 | if (len < 0) |
| 81 | return len; |
| 82 | |
| 83 | ixgbe_dbg_reg_ops_buf[len] = '\0'; |
Catherine Sullivan | 91fbd8f | 2012-08-10 01:59:21 +0000 | [diff] [blame] | 84 | |
| 85 | if (strncmp(ixgbe_dbg_reg_ops_buf, "write", 5) == 0) { |
| 86 | u32 reg, value; |
| 87 | int cnt; |
| 88 | cnt = sscanf(&ixgbe_dbg_reg_ops_buf[5], "%x %x", ®, &value); |
| 89 | if (cnt == 2) { |
| 90 | IXGBE_WRITE_REG(&adapter->hw, reg, value); |
| 91 | value = IXGBE_READ_REG(&adapter->hw, reg); |
| 92 | e_dev_info("write: 0x%08x = 0x%08x\n", reg, value); |
| 93 | } else { |
| 94 | e_dev_info("write <reg> <value>\n"); |
| 95 | } |
| 96 | } else if (strncmp(ixgbe_dbg_reg_ops_buf, "read", 4) == 0) { |
| 97 | u32 reg, value; |
| 98 | int cnt; |
| 99 | cnt = sscanf(&ixgbe_dbg_reg_ops_buf[4], "%x", ®); |
| 100 | if (cnt == 1) { |
| 101 | value = IXGBE_READ_REG(&adapter->hw, reg); |
| 102 | e_dev_info("read 0x%08x = 0x%08x\n", reg, value); |
| 103 | } else { |
| 104 | e_dev_info("read <reg>\n"); |
| 105 | } |
| 106 | } else { |
| 107 | e_dev_info("Unknown command %s\n", ixgbe_dbg_reg_ops_buf); |
| 108 | e_dev_info("Available commands:\n"); |
| 109 | e_dev_info(" read <reg>\n"); |
| 110 | e_dev_info(" write <reg> <value>\n"); |
| 111 | } |
| 112 | return count; |
| 113 | } |
| 114 | |
| 115 | static const struct file_operations ixgbe_dbg_reg_ops_fops = { |
| 116 | .owner = THIS_MODULE, |
Wei Yongjun | 21cc57f | 2012-10-18 06:34:08 +0000 | [diff] [blame] | 117 | .open = simple_open, |
Catherine Sullivan | 91fbd8f | 2012-08-10 01:59:21 +0000 | [diff] [blame] | 118 | .read = ixgbe_dbg_reg_ops_read, |
| 119 | .write = ixgbe_dbg_reg_ops_write, |
| 120 | }; |
| 121 | |
Catherine Sullivan | 826ff0d | 2012-08-10 01:59:15 +0000 | [diff] [blame] | 122 | static char ixgbe_dbg_netdev_ops_buf[256] = ""; |
| 123 | |
| 124 | /** |
Catherine Sullivan | 826ff0d | 2012-08-10 01:59:15 +0000 | [diff] [blame] | 125 | * ixgbe_dbg_netdev_ops_read - read for netdev_ops datum |
| 126 | * @filp: the opened file |
| 127 | * @buffer: where to write the data for the user to read |
| 128 | * @count: the size of the user's buffer |
| 129 | * @ppos: file position offset |
| 130 | **/ |
YueHaibing | e9c7218 | 2018-05-23 20:08:13 +0800 | [diff] [blame] | 131 | static ssize_t ixgbe_dbg_netdev_ops_read(struct file *filp, char __user *buffer, |
Catherine Sullivan | 826ff0d | 2012-08-10 01:59:15 +0000 | [diff] [blame] | 132 | size_t count, loff_t *ppos) |
| 133 | { |
YueHaibing | e9c7218 | 2018-05-23 20:08:13 +0800 | [diff] [blame] | 134 | return ixgbe_dbg_common_ops_read(filp, buffer, count, ppos, |
| 135 | ixgbe_dbg_netdev_ops_buf); |
Catherine Sullivan | 826ff0d | 2012-08-10 01:59:15 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | /** |
| 139 | * ixgbe_dbg_netdev_ops_write - write into netdev_ops datum |
| 140 | * @filp: the opened file |
| 141 | * @buffer: where to find the user's data |
| 142 | * @count: the length of the user's data |
| 143 | * @ppos: file position offset |
| 144 | **/ |
| 145 | static ssize_t ixgbe_dbg_netdev_ops_write(struct file *filp, |
| 146 | const char __user *buffer, |
| 147 | size_t count, loff_t *ppos) |
| 148 | { |
| 149 | struct ixgbe_adapter *adapter = filp->private_data; |
joshua.a.hay@intel.com | 3288d73 | 2012-11-28 05:49:20 +0000 | [diff] [blame] | 150 | int len; |
Catherine Sullivan | 826ff0d | 2012-08-10 01:59:15 +0000 | [diff] [blame] | 151 | |
| 152 | /* don't allow partial writes */ |
| 153 | if (*ppos != 0) |
| 154 | return 0; |
| 155 | if (count >= sizeof(ixgbe_dbg_netdev_ops_buf)) |
| 156 | return -ENOSPC; |
| 157 | |
joshua.a.hay@intel.com | 3288d73 | 2012-11-28 05:49:20 +0000 | [diff] [blame] | 158 | len = simple_write_to_buffer(ixgbe_dbg_netdev_ops_buf, |
| 159 | sizeof(ixgbe_dbg_netdev_ops_buf)-1, |
| 160 | ppos, |
| 161 | buffer, |
| 162 | count); |
| 163 | if (len < 0) |
| 164 | return len; |
| 165 | |
| 166 | ixgbe_dbg_netdev_ops_buf[len] = '\0'; |
Catherine Sullivan | 826ff0d | 2012-08-10 01:59:15 +0000 | [diff] [blame] | 167 | |
| 168 | if (strncmp(ixgbe_dbg_netdev_ops_buf, "tx_timeout", 10) == 0) { |
Michael S. Tsirkin | 0290bd2 | 2019-12-10 09:23:51 -0500 | [diff] [blame] | 169 | /* TX Queue number below is wrong, but ixgbe does not use it */ |
| 170 | adapter->netdev->netdev_ops->ndo_tx_timeout(adapter->netdev, |
| 171 | UINT_MAX); |
Catherine Sullivan | 826ff0d | 2012-08-10 01:59:15 +0000 | [diff] [blame] | 172 | e_dev_info("tx_timeout called\n"); |
| 173 | } else { |
| 174 | e_dev_info("Unknown command: %s\n", ixgbe_dbg_netdev_ops_buf); |
| 175 | e_dev_info("Available commands:\n"); |
| 176 | e_dev_info(" tx_timeout\n"); |
| 177 | } |
| 178 | return count; |
| 179 | } |
| 180 | |
| 181 | static const struct file_operations ixgbe_dbg_netdev_ops_fops = { |
| 182 | .owner = THIS_MODULE, |
Wei Yongjun | 21cc57f | 2012-10-18 06:34:08 +0000 | [diff] [blame] | 183 | .open = simple_open, |
Catherine Sullivan | 826ff0d | 2012-08-10 01:59:15 +0000 | [diff] [blame] | 184 | .read = ixgbe_dbg_netdev_ops_read, |
| 185 | .write = ixgbe_dbg_netdev_ops_write, |
| 186 | }; |
| 187 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 188 | /** |
| 189 | * ixgbe_dbg_adapter_init - setup the debugfs directory for the adapter |
| 190 | * @adapter: the adapter that is starting up |
| 191 | **/ |
| 192 | void ixgbe_dbg_adapter_init(struct ixgbe_adapter *adapter) |
| 193 | { |
| 194 | const char *name = pci_name(adapter->pdev); |
Greg Kroah-Hartman | 35dc61e | 2019-08-10 12:17:31 +0200 | [diff] [blame] | 195 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 196 | adapter->ixgbe_dbg_adapter = debugfs_create_dir(name, ixgbe_dbg_root); |
Greg Kroah-Hartman | 35dc61e | 2019-08-10 12:17:31 +0200 | [diff] [blame] | 197 | debugfs_create_file("reg_ops", 0600, adapter->ixgbe_dbg_adapter, |
| 198 | adapter, &ixgbe_dbg_reg_ops_fops); |
| 199 | debugfs_create_file("netdev_ops", 0600, adapter->ixgbe_dbg_adapter, |
| 200 | adapter, &ixgbe_dbg_netdev_ops_fops); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | /** |
| 204 | * ixgbe_dbg_adapter_exit - clear out the adapter's debugfs entries |
Tony Nguyen | 5ba643c | 2017-12-04 11:28:30 -0800 | [diff] [blame] | 205 | * @adapter: the adapter that is exiting |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 206 | **/ |
| 207 | void ixgbe_dbg_adapter_exit(struct ixgbe_adapter *adapter) |
| 208 | { |
Jacob Keller | ec73942 | 2014-04-09 06:03:15 +0000 | [diff] [blame] | 209 | debugfs_remove_recursive(adapter->ixgbe_dbg_adapter); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 210 | adapter->ixgbe_dbg_adapter = NULL; |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * ixgbe_dbg_init - start up debugfs for the driver |
| 215 | **/ |
| 216 | void ixgbe_dbg_init(void) |
| 217 | { |
| 218 | ixgbe_dbg_root = debugfs_create_dir(ixgbe_driver_name, NULL); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | /** |
| 222 | * ixgbe_dbg_exit - clean out the driver's debugfs entries |
| 223 | **/ |
| 224 | void ixgbe_dbg_exit(void) |
| 225 | { |
| 226 | debugfs_remove_recursive(ixgbe_dbg_root); |
| 227 | } |