blob: c5933f6dceee928be6c225cb6eba42c48284b011 [file] [log] [blame]
Catherine Sullivan00949162012-08-10 01:59:10 +00001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmore434c5e32013-01-08 05:02:28 +00004 Copyright(c) 1999 - 2013 Intel Corporation.
Catherine Sullivan00949162012-08-10 01:59:10 +00005
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*******************************************************************************/
Catherine Sullivan00949162012-08-10 01:59:10 +000027#include <linux/debugfs.h>
28#include <linux/module.h>
29
30#include "ixgbe.h"
31
32static struct dentry *ixgbe_dbg_root;
33
Catherine Sullivan91fbd8f2012-08-10 01:59:21 +000034static char ixgbe_dbg_reg_ops_buf[256] = "";
35
36/**
Catherine Sullivan91fbd8f2012-08-10 01:59:21 +000037 * ixgbe_dbg_reg_ops_read - read for reg_ops datum
38 * @filp: the opened file
39 * @buffer: where to write the data for the user to read
40 * @count: the size of the user's buffer
41 * @ppos: file position offset
42 **/
43static ssize_t ixgbe_dbg_reg_ops_read(struct file *filp, char __user *buffer,
44 size_t count, loff_t *ppos)
45{
46 struct ixgbe_adapter *adapter = filp->private_data;
joshua.a.hay@intel.com3288d732012-11-28 05:49:20 +000047 char *buf;
Catherine Sullivan91fbd8f2012-08-10 01:59:21 +000048 int len;
49
50 /* don't allow partial reads */
51 if (*ppos != 0)
52 return 0;
53
joshua.a.hay@intel.com3288d732012-11-28 05:49:20 +000054 buf = kasprintf(GFP_KERNEL, "%s: %s\n",
55 adapter->netdev->name,
56 ixgbe_dbg_reg_ops_buf);
57 if (!buf)
58 return -ENOMEM;
Catherine Sullivan91fbd8f2012-08-10 01:59:21 +000059
joshua.a.hay@intel.com3288d732012-11-28 05:49:20 +000060 if (count < strlen(buf)) {
61 kfree(buf);
62 return -ENOSPC;
63 }
64
65 len = simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
66
67 kfree(buf);
Catherine Sullivan91fbd8f2012-08-10 01:59:21 +000068 return len;
69}
70
71/**
72 * ixgbe_dbg_reg_ops_write - write into reg_ops datum
73 * @filp: the opened file
74 * @buffer: where to find the user's data
75 * @count: the length of the user's data
76 * @ppos: file position offset
77 **/
78static ssize_t ixgbe_dbg_reg_ops_write(struct file *filp,
79 const char __user *buffer,
80 size_t count, loff_t *ppos)
81{
82 struct ixgbe_adapter *adapter = filp->private_data;
joshua.a.hay@intel.com3288d732012-11-28 05:49:20 +000083 int len;
Catherine Sullivan91fbd8f2012-08-10 01:59:21 +000084
85 /* don't allow partial writes */
86 if (*ppos != 0)
87 return 0;
88 if (count >= sizeof(ixgbe_dbg_reg_ops_buf))
89 return -ENOSPC;
90
joshua.a.hay@intel.com3288d732012-11-28 05:49:20 +000091 len = simple_write_to_buffer(ixgbe_dbg_reg_ops_buf,
92 sizeof(ixgbe_dbg_reg_ops_buf)-1,
93 ppos,
94 buffer,
95 count);
96 if (len < 0)
97 return len;
98
99 ixgbe_dbg_reg_ops_buf[len] = '\0';
Catherine Sullivan91fbd8f2012-08-10 01:59:21 +0000100
101 if (strncmp(ixgbe_dbg_reg_ops_buf, "write", 5) == 0) {
102 u32 reg, value;
103 int cnt;
104 cnt = sscanf(&ixgbe_dbg_reg_ops_buf[5], "%x %x", &reg, &value);
105 if (cnt == 2) {
106 IXGBE_WRITE_REG(&adapter->hw, reg, value);
107 value = IXGBE_READ_REG(&adapter->hw, reg);
108 e_dev_info("write: 0x%08x = 0x%08x\n", reg, value);
109 } else {
110 e_dev_info("write <reg> <value>\n");
111 }
112 } else if (strncmp(ixgbe_dbg_reg_ops_buf, "read", 4) == 0) {
113 u32 reg, value;
114 int cnt;
115 cnt = sscanf(&ixgbe_dbg_reg_ops_buf[4], "%x", &reg);
116 if (cnt == 1) {
117 value = IXGBE_READ_REG(&adapter->hw, reg);
118 e_dev_info("read 0x%08x = 0x%08x\n", reg, value);
119 } else {
120 e_dev_info("read <reg>\n");
121 }
122 } else {
123 e_dev_info("Unknown command %s\n", ixgbe_dbg_reg_ops_buf);
124 e_dev_info("Available commands:\n");
125 e_dev_info(" read <reg>\n");
126 e_dev_info(" write <reg> <value>\n");
127 }
128 return count;
129}
130
131static const struct file_operations ixgbe_dbg_reg_ops_fops = {
132 .owner = THIS_MODULE,
Wei Yongjun21cc57f2012-10-18 06:34:08 +0000133 .open = simple_open,
Catherine Sullivan91fbd8f2012-08-10 01:59:21 +0000134 .read = ixgbe_dbg_reg_ops_read,
135 .write = ixgbe_dbg_reg_ops_write,
136};
137
Catherine Sullivan826ff0d2012-08-10 01:59:15 +0000138static char ixgbe_dbg_netdev_ops_buf[256] = "";
139
140/**
Catherine Sullivan826ff0d2012-08-10 01:59:15 +0000141 * ixgbe_dbg_netdev_ops_read - read for netdev_ops datum
142 * @filp: the opened file
143 * @buffer: where to write the data for the user to read
144 * @count: the size of the user's buffer
145 * @ppos: file position offset
146 **/
147static ssize_t ixgbe_dbg_netdev_ops_read(struct file *filp,
148 char __user *buffer,
149 size_t count, loff_t *ppos)
150{
151 struct ixgbe_adapter *adapter = filp->private_data;
joshua.a.hay@intel.com3288d732012-11-28 05:49:20 +0000152 char *buf;
Catherine Sullivan826ff0d2012-08-10 01:59:15 +0000153 int len;
154
155 /* don't allow partial reads */
156 if (*ppos != 0)
157 return 0;
158
joshua.a.hay@intel.com3288d732012-11-28 05:49:20 +0000159 buf = kasprintf(GFP_KERNEL, "%s: %s\n",
160 adapter->netdev->name,
161 ixgbe_dbg_netdev_ops_buf);
162 if (!buf)
163 return -ENOMEM;
Catherine Sullivan826ff0d2012-08-10 01:59:15 +0000164
joshua.a.hay@intel.com3288d732012-11-28 05:49:20 +0000165 if (count < strlen(buf)) {
166 kfree(buf);
167 return -ENOSPC;
168 }
169
170 len = simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
171
172 kfree(buf);
Catherine Sullivan826ff0d2012-08-10 01:59:15 +0000173 return len;
174}
175
176/**
177 * ixgbe_dbg_netdev_ops_write - write into netdev_ops datum
178 * @filp: the opened file
179 * @buffer: where to find the user's data
180 * @count: the length of the user's data
181 * @ppos: file position offset
182 **/
183static ssize_t ixgbe_dbg_netdev_ops_write(struct file *filp,
184 const char __user *buffer,
185 size_t count, loff_t *ppos)
186{
187 struct ixgbe_adapter *adapter = filp->private_data;
joshua.a.hay@intel.com3288d732012-11-28 05:49:20 +0000188 int len;
Catherine Sullivan826ff0d2012-08-10 01:59:15 +0000189
190 /* don't allow partial writes */
191 if (*ppos != 0)
192 return 0;
193 if (count >= sizeof(ixgbe_dbg_netdev_ops_buf))
194 return -ENOSPC;
195
joshua.a.hay@intel.com3288d732012-11-28 05:49:20 +0000196 len = simple_write_to_buffer(ixgbe_dbg_netdev_ops_buf,
197 sizeof(ixgbe_dbg_netdev_ops_buf)-1,
198 ppos,
199 buffer,
200 count);
201 if (len < 0)
202 return len;
203
204 ixgbe_dbg_netdev_ops_buf[len] = '\0';
Catherine Sullivan826ff0d2012-08-10 01:59:15 +0000205
206 if (strncmp(ixgbe_dbg_netdev_ops_buf, "tx_timeout", 10) == 0) {
207 adapter->netdev->netdev_ops->ndo_tx_timeout(adapter->netdev);
208 e_dev_info("tx_timeout called\n");
209 } else {
210 e_dev_info("Unknown command: %s\n", ixgbe_dbg_netdev_ops_buf);
211 e_dev_info("Available commands:\n");
212 e_dev_info(" tx_timeout\n");
213 }
214 return count;
215}
216
217static const struct file_operations ixgbe_dbg_netdev_ops_fops = {
218 .owner = THIS_MODULE,
Wei Yongjun21cc57f2012-10-18 06:34:08 +0000219 .open = simple_open,
Catherine Sullivan826ff0d2012-08-10 01:59:15 +0000220 .read = ixgbe_dbg_netdev_ops_read,
221 .write = ixgbe_dbg_netdev_ops_write,
222};
223
Catherine Sullivan00949162012-08-10 01:59:10 +0000224/**
225 * ixgbe_dbg_adapter_init - setup the debugfs directory for the adapter
226 * @adapter: the adapter that is starting up
227 **/
228void ixgbe_dbg_adapter_init(struct ixgbe_adapter *adapter)
229{
230 const char *name = pci_name(adapter->pdev);
Catherine Sullivan826ff0d2012-08-10 01:59:15 +0000231 struct dentry *pfile;
Catherine Sullivan00949162012-08-10 01:59:10 +0000232 adapter->ixgbe_dbg_adapter = debugfs_create_dir(name, ixgbe_dbg_root);
Catherine Sullivan826ff0d2012-08-10 01:59:15 +0000233 if (adapter->ixgbe_dbg_adapter) {
Catherine Sullivan91fbd8f2012-08-10 01:59:21 +0000234 pfile = debugfs_create_file("reg_ops", 0600,
235 adapter->ixgbe_dbg_adapter, adapter,
236 &ixgbe_dbg_reg_ops_fops);
237 if (!pfile)
238 e_dev_err("debugfs reg_ops for %s failed\n", name);
Catherine Sullivan826ff0d2012-08-10 01:59:15 +0000239 pfile = debugfs_create_file("netdev_ops", 0600,
240 adapter->ixgbe_dbg_adapter, adapter,
241 &ixgbe_dbg_netdev_ops_fops);
242 if (!pfile)
243 e_dev_err("debugfs netdev_ops for %s failed\n", name);
244 } else {
Catherine Sullivan00949162012-08-10 01:59:10 +0000245 e_dev_err("debugfs entry for %s failed\n", name);
Catherine Sullivan826ff0d2012-08-10 01:59:15 +0000246 }
Catherine Sullivan00949162012-08-10 01:59:10 +0000247}
248
249/**
250 * ixgbe_dbg_adapter_exit - clear out the adapter's debugfs entries
251 * @pf: the pf that is stopping
252 **/
253void ixgbe_dbg_adapter_exit(struct ixgbe_adapter *adapter)
254{
255 if (adapter->ixgbe_dbg_adapter)
256 debugfs_remove_recursive(adapter->ixgbe_dbg_adapter);
257 adapter->ixgbe_dbg_adapter = NULL;
258}
259
260/**
261 * ixgbe_dbg_init - start up debugfs for the driver
262 **/
263void ixgbe_dbg_init(void)
264{
265 ixgbe_dbg_root = debugfs_create_dir(ixgbe_driver_name, NULL);
266 if (ixgbe_dbg_root == NULL)
267 pr_err("init of debugfs failed\n");
268}
269
270/**
271 * ixgbe_dbg_exit - clean out the driver's debugfs entries
272 **/
273void ixgbe_dbg_exit(void)
274{
275 debugfs_remove_recursive(ixgbe_dbg_root);
276}