Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
| 4 | Copyright(c) 1999 - 2012 Intel Corporation. |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License along with |
| 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
| 22 | Contact Information: |
| 23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 25 | |
| 26 | *******************************************************************************/ |
| 27 | |
| 28 | #ifdef CONFIG_DEBUG_FS |
| 29 | |
| 30 | #include <linux/debugfs.h> |
| 31 | #include <linux/module.h> |
| 32 | |
| 33 | #include "ixgbe.h" |
| 34 | |
| 35 | static struct dentry *ixgbe_dbg_root; |
| 36 | |
Catherine Sullivan | 91fbd8f | 2012-08-10 01:59:21 +0000 | [diff] [blame] | 37 | static char ixgbe_dbg_reg_ops_buf[256] = ""; |
| 38 | |
| 39 | /** |
Catherine Sullivan | 91fbd8f | 2012-08-10 01:59:21 +0000 | [diff] [blame] | 40 | * ixgbe_dbg_reg_ops_read - read for reg_ops datum |
| 41 | * @filp: the opened file |
| 42 | * @buffer: where to write the data for the user to read |
| 43 | * @count: the size of the user's buffer |
| 44 | * @ppos: file position offset |
| 45 | **/ |
| 46 | static ssize_t ixgbe_dbg_reg_ops_read(struct file *filp, char __user *buffer, |
| 47 | size_t count, loff_t *ppos) |
| 48 | { |
| 49 | struct ixgbe_adapter *adapter = filp->private_data; |
joshua.a.hay@intel.com | 3288d73 | 2012-11-28 05:49:20 +0000 | [diff] [blame^] | 50 | char *buf; |
Catherine Sullivan | 91fbd8f | 2012-08-10 01:59:21 +0000 | [diff] [blame] | 51 | int len; |
| 52 | |
| 53 | /* don't allow partial reads */ |
| 54 | if (*ppos != 0) |
| 55 | return 0; |
| 56 | |
joshua.a.hay@intel.com | 3288d73 | 2012-11-28 05:49:20 +0000 | [diff] [blame^] | 57 | buf = kasprintf(GFP_KERNEL, "%s: %s\n", |
| 58 | adapter->netdev->name, |
| 59 | ixgbe_dbg_reg_ops_buf); |
| 60 | if (!buf) |
| 61 | return -ENOMEM; |
Catherine Sullivan | 91fbd8f | 2012-08-10 01:59:21 +0000 | [diff] [blame] | 62 | |
joshua.a.hay@intel.com | 3288d73 | 2012-11-28 05:49:20 +0000 | [diff] [blame^] | 63 | if (count < strlen(buf)) { |
| 64 | kfree(buf); |
| 65 | return -ENOSPC; |
| 66 | } |
| 67 | |
| 68 | len = simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf)); |
| 69 | |
| 70 | kfree(buf); |
Catherine Sullivan | 91fbd8f | 2012-08-10 01:59:21 +0000 | [diff] [blame] | 71 | return len; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * ixgbe_dbg_reg_ops_write - write into reg_ops datum |
| 76 | * @filp: the opened file |
| 77 | * @buffer: where to find the user's data |
| 78 | * @count: the length of the user's data |
| 79 | * @ppos: file position offset |
| 80 | **/ |
| 81 | static ssize_t ixgbe_dbg_reg_ops_write(struct file *filp, |
| 82 | const char __user *buffer, |
| 83 | size_t count, loff_t *ppos) |
| 84 | { |
| 85 | struct ixgbe_adapter *adapter = filp->private_data; |
joshua.a.hay@intel.com | 3288d73 | 2012-11-28 05:49:20 +0000 | [diff] [blame^] | 86 | int len; |
Catherine Sullivan | 91fbd8f | 2012-08-10 01:59:21 +0000 | [diff] [blame] | 87 | |
| 88 | /* don't allow partial writes */ |
| 89 | if (*ppos != 0) |
| 90 | return 0; |
| 91 | if (count >= sizeof(ixgbe_dbg_reg_ops_buf)) |
| 92 | return -ENOSPC; |
| 93 | |
joshua.a.hay@intel.com | 3288d73 | 2012-11-28 05:49:20 +0000 | [diff] [blame^] | 94 | len = simple_write_to_buffer(ixgbe_dbg_reg_ops_buf, |
| 95 | sizeof(ixgbe_dbg_reg_ops_buf)-1, |
| 96 | ppos, |
| 97 | buffer, |
| 98 | count); |
| 99 | if (len < 0) |
| 100 | return len; |
| 101 | |
| 102 | ixgbe_dbg_reg_ops_buf[len] = '\0'; |
Catherine Sullivan | 91fbd8f | 2012-08-10 01:59:21 +0000 | [diff] [blame] | 103 | |
| 104 | if (strncmp(ixgbe_dbg_reg_ops_buf, "write", 5) == 0) { |
| 105 | u32 reg, value; |
| 106 | int cnt; |
| 107 | cnt = sscanf(&ixgbe_dbg_reg_ops_buf[5], "%x %x", ®, &value); |
| 108 | if (cnt == 2) { |
| 109 | IXGBE_WRITE_REG(&adapter->hw, reg, value); |
| 110 | value = IXGBE_READ_REG(&adapter->hw, reg); |
| 111 | e_dev_info("write: 0x%08x = 0x%08x\n", reg, value); |
| 112 | } else { |
| 113 | e_dev_info("write <reg> <value>\n"); |
| 114 | } |
| 115 | } else if (strncmp(ixgbe_dbg_reg_ops_buf, "read", 4) == 0) { |
| 116 | u32 reg, value; |
| 117 | int cnt; |
| 118 | cnt = sscanf(&ixgbe_dbg_reg_ops_buf[4], "%x", ®); |
| 119 | if (cnt == 1) { |
| 120 | value = IXGBE_READ_REG(&adapter->hw, reg); |
| 121 | e_dev_info("read 0x%08x = 0x%08x\n", reg, value); |
| 122 | } else { |
| 123 | e_dev_info("read <reg>\n"); |
| 124 | } |
| 125 | } else { |
| 126 | e_dev_info("Unknown command %s\n", ixgbe_dbg_reg_ops_buf); |
| 127 | e_dev_info("Available commands:\n"); |
| 128 | e_dev_info(" read <reg>\n"); |
| 129 | e_dev_info(" write <reg> <value>\n"); |
| 130 | } |
| 131 | return count; |
| 132 | } |
| 133 | |
| 134 | static const struct file_operations ixgbe_dbg_reg_ops_fops = { |
| 135 | .owner = THIS_MODULE, |
Wei Yongjun | 21cc57f | 2012-10-18 06:34:08 +0000 | [diff] [blame] | 136 | .open = simple_open, |
Catherine Sullivan | 91fbd8f | 2012-08-10 01:59:21 +0000 | [diff] [blame] | 137 | .read = ixgbe_dbg_reg_ops_read, |
| 138 | .write = ixgbe_dbg_reg_ops_write, |
| 139 | }; |
| 140 | |
Catherine Sullivan | 826ff0d | 2012-08-10 01:59:15 +0000 | [diff] [blame] | 141 | static char ixgbe_dbg_netdev_ops_buf[256] = ""; |
| 142 | |
| 143 | /** |
Catherine Sullivan | 826ff0d | 2012-08-10 01:59:15 +0000 | [diff] [blame] | 144 | * ixgbe_dbg_netdev_ops_read - read for netdev_ops datum |
| 145 | * @filp: the opened file |
| 146 | * @buffer: where to write the data for the user to read |
| 147 | * @count: the size of the user's buffer |
| 148 | * @ppos: file position offset |
| 149 | **/ |
| 150 | static ssize_t ixgbe_dbg_netdev_ops_read(struct file *filp, |
| 151 | char __user *buffer, |
| 152 | size_t count, loff_t *ppos) |
| 153 | { |
| 154 | struct ixgbe_adapter *adapter = filp->private_data; |
joshua.a.hay@intel.com | 3288d73 | 2012-11-28 05:49:20 +0000 | [diff] [blame^] | 155 | char *buf; |
Catherine Sullivan | 826ff0d | 2012-08-10 01:59:15 +0000 | [diff] [blame] | 156 | int len; |
| 157 | |
| 158 | /* don't allow partial reads */ |
| 159 | if (*ppos != 0) |
| 160 | return 0; |
| 161 | |
joshua.a.hay@intel.com | 3288d73 | 2012-11-28 05:49:20 +0000 | [diff] [blame^] | 162 | buf = kasprintf(GFP_KERNEL, "%s: %s\n", |
| 163 | adapter->netdev->name, |
| 164 | ixgbe_dbg_netdev_ops_buf); |
| 165 | if (!buf) |
| 166 | return -ENOMEM; |
Catherine Sullivan | 826ff0d | 2012-08-10 01:59:15 +0000 | [diff] [blame] | 167 | |
joshua.a.hay@intel.com | 3288d73 | 2012-11-28 05:49:20 +0000 | [diff] [blame^] | 168 | if (count < strlen(buf)) { |
| 169 | kfree(buf); |
| 170 | return -ENOSPC; |
| 171 | } |
| 172 | |
| 173 | len = simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf)); |
| 174 | |
| 175 | kfree(buf); |
Catherine Sullivan | 826ff0d | 2012-08-10 01:59:15 +0000 | [diff] [blame] | 176 | return len; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * ixgbe_dbg_netdev_ops_write - write into netdev_ops datum |
| 181 | * @filp: the opened file |
| 182 | * @buffer: where to find the user's data |
| 183 | * @count: the length of the user's data |
| 184 | * @ppos: file position offset |
| 185 | **/ |
| 186 | static ssize_t ixgbe_dbg_netdev_ops_write(struct file *filp, |
| 187 | const char __user *buffer, |
| 188 | size_t count, loff_t *ppos) |
| 189 | { |
| 190 | struct ixgbe_adapter *adapter = filp->private_data; |
joshua.a.hay@intel.com | 3288d73 | 2012-11-28 05:49:20 +0000 | [diff] [blame^] | 191 | int len; |
Catherine Sullivan | 826ff0d | 2012-08-10 01:59:15 +0000 | [diff] [blame] | 192 | |
| 193 | /* don't allow partial writes */ |
| 194 | if (*ppos != 0) |
| 195 | return 0; |
| 196 | if (count >= sizeof(ixgbe_dbg_netdev_ops_buf)) |
| 197 | return -ENOSPC; |
| 198 | |
joshua.a.hay@intel.com | 3288d73 | 2012-11-28 05:49:20 +0000 | [diff] [blame^] | 199 | len = simple_write_to_buffer(ixgbe_dbg_netdev_ops_buf, |
| 200 | sizeof(ixgbe_dbg_netdev_ops_buf)-1, |
| 201 | ppos, |
| 202 | buffer, |
| 203 | count); |
| 204 | if (len < 0) |
| 205 | return len; |
| 206 | |
| 207 | ixgbe_dbg_netdev_ops_buf[len] = '\0'; |
Catherine Sullivan | 826ff0d | 2012-08-10 01:59:15 +0000 | [diff] [blame] | 208 | |
| 209 | if (strncmp(ixgbe_dbg_netdev_ops_buf, "tx_timeout", 10) == 0) { |
| 210 | adapter->netdev->netdev_ops->ndo_tx_timeout(adapter->netdev); |
| 211 | e_dev_info("tx_timeout called\n"); |
| 212 | } else { |
| 213 | e_dev_info("Unknown command: %s\n", ixgbe_dbg_netdev_ops_buf); |
| 214 | e_dev_info("Available commands:\n"); |
| 215 | e_dev_info(" tx_timeout\n"); |
| 216 | } |
| 217 | return count; |
| 218 | } |
| 219 | |
| 220 | static const struct file_operations ixgbe_dbg_netdev_ops_fops = { |
| 221 | .owner = THIS_MODULE, |
Wei Yongjun | 21cc57f | 2012-10-18 06:34:08 +0000 | [diff] [blame] | 222 | .open = simple_open, |
Catherine Sullivan | 826ff0d | 2012-08-10 01:59:15 +0000 | [diff] [blame] | 223 | .read = ixgbe_dbg_netdev_ops_read, |
| 224 | .write = ixgbe_dbg_netdev_ops_write, |
| 225 | }; |
| 226 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 227 | /** |
| 228 | * ixgbe_dbg_adapter_init - setup the debugfs directory for the adapter |
| 229 | * @adapter: the adapter that is starting up |
| 230 | **/ |
| 231 | void ixgbe_dbg_adapter_init(struct ixgbe_adapter *adapter) |
| 232 | { |
| 233 | const char *name = pci_name(adapter->pdev); |
Catherine Sullivan | 826ff0d | 2012-08-10 01:59:15 +0000 | [diff] [blame] | 234 | struct dentry *pfile; |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 235 | adapter->ixgbe_dbg_adapter = debugfs_create_dir(name, ixgbe_dbg_root); |
Catherine Sullivan | 826ff0d | 2012-08-10 01:59:15 +0000 | [diff] [blame] | 236 | if (adapter->ixgbe_dbg_adapter) { |
Catherine Sullivan | 91fbd8f | 2012-08-10 01:59:21 +0000 | [diff] [blame] | 237 | pfile = debugfs_create_file("reg_ops", 0600, |
| 238 | adapter->ixgbe_dbg_adapter, adapter, |
| 239 | &ixgbe_dbg_reg_ops_fops); |
| 240 | if (!pfile) |
| 241 | e_dev_err("debugfs reg_ops for %s failed\n", name); |
Catherine Sullivan | 826ff0d | 2012-08-10 01:59:15 +0000 | [diff] [blame] | 242 | pfile = debugfs_create_file("netdev_ops", 0600, |
| 243 | adapter->ixgbe_dbg_adapter, adapter, |
| 244 | &ixgbe_dbg_netdev_ops_fops); |
| 245 | if (!pfile) |
| 246 | e_dev_err("debugfs netdev_ops for %s failed\n", name); |
| 247 | } else { |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 248 | e_dev_err("debugfs entry for %s failed\n", name); |
Catherine Sullivan | 826ff0d | 2012-08-10 01:59:15 +0000 | [diff] [blame] | 249 | } |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | /** |
| 253 | * ixgbe_dbg_adapter_exit - clear out the adapter's debugfs entries |
| 254 | * @pf: the pf that is stopping |
| 255 | **/ |
| 256 | void ixgbe_dbg_adapter_exit(struct ixgbe_adapter *adapter) |
| 257 | { |
| 258 | if (adapter->ixgbe_dbg_adapter) |
| 259 | debugfs_remove_recursive(adapter->ixgbe_dbg_adapter); |
| 260 | adapter->ixgbe_dbg_adapter = NULL; |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * ixgbe_dbg_init - start up debugfs for the driver |
| 265 | **/ |
| 266 | void ixgbe_dbg_init(void) |
| 267 | { |
| 268 | ixgbe_dbg_root = debugfs_create_dir(ixgbe_driver_name, NULL); |
| 269 | if (ixgbe_dbg_root == NULL) |
| 270 | pr_err("init of debugfs failed\n"); |
| 271 | } |
| 272 | |
| 273 | /** |
| 274 | * ixgbe_dbg_exit - clean out the driver's debugfs entries |
| 275 | **/ |
| 276 | void ixgbe_dbg_exit(void) |
| 277 | { |
| 278 | debugfs_remove_recursive(ixgbe_dbg_root); |
| 279 | } |
| 280 | |
| 281 | #endif /* CONFIG_DEBUG_FS */ |