1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2012 Intel Corporation.
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.
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
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.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
28 #ifdef CONFIG_DEBUG_FS
30 #include <linux/debugfs.h>
31 #include <linux/module.h>
35 static struct dentry
*ixgbe_dbg_root
;
37 static char ixgbe_dbg_reg_ops_buf
[256] = "";
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
46 static ssize_t
ixgbe_dbg_reg_ops_read(struct file
*filp
, char __user
*buffer
,
47 size_t count
, loff_t
*ppos
)
49 struct ixgbe_adapter
*adapter
= filp
->private_data
;
53 /* don't allow partial reads */
57 buf
= kasprintf(GFP_KERNEL
, "%s: %s\n",
58 adapter
->netdev
->name
,
59 ixgbe_dbg_reg_ops_buf
);
63 if (count
< strlen(buf
)) {
68 len
= simple_read_from_buffer(buffer
, count
, ppos
, buf
, strlen(buf
));
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
81 static ssize_t
ixgbe_dbg_reg_ops_write(struct file
*filp
,
82 const char __user
*buffer
,
83 size_t count
, loff_t
*ppos
)
85 struct ixgbe_adapter
*adapter
= filp
->private_data
;
88 /* don't allow partial writes */
91 if (count
>= sizeof(ixgbe_dbg_reg_ops_buf
))
94 len
= simple_write_to_buffer(ixgbe_dbg_reg_ops_buf
,
95 sizeof(ixgbe_dbg_reg_ops_buf
)-1,
102 ixgbe_dbg_reg_ops_buf
[len
] = '\0';
104 if (strncmp(ixgbe_dbg_reg_ops_buf
, "write", 5) == 0) {
107 cnt
= sscanf(&ixgbe_dbg_reg_ops_buf
[5], "%x %x", ®
, &value
);
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
);
113 e_dev_info("write <reg> <value>\n");
115 } else if (strncmp(ixgbe_dbg_reg_ops_buf
, "read", 4) == 0) {
118 cnt
= sscanf(&ixgbe_dbg_reg_ops_buf
[4], "%x", ®
);
120 value
= IXGBE_READ_REG(&adapter
->hw
, reg
);
121 e_dev_info("read 0x%08x = 0x%08x\n", reg
, value
);
123 e_dev_info("read <reg>\n");
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");
134 static const struct file_operations ixgbe_dbg_reg_ops_fops
= {
135 .owner
= THIS_MODULE
,
137 .read
= ixgbe_dbg_reg_ops_read
,
138 .write
= ixgbe_dbg_reg_ops_write
,
141 static char ixgbe_dbg_netdev_ops_buf
[256] = "";
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
150 static ssize_t
ixgbe_dbg_netdev_ops_read(struct file
*filp
,
152 size_t count
, loff_t
*ppos
)
154 struct ixgbe_adapter
*adapter
= filp
->private_data
;
158 /* don't allow partial reads */
162 buf
= kasprintf(GFP_KERNEL
, "%s: %s\n",
163 adapter
->netdev
->name
,
164 ixgbe_dbg_netdev_ops_buf
);
168 if (count
< strlen(buf
)) {
173 len
= simple_read_from_buffer(buffer
, count
, ppos
, buf
, strlen(buf
));
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
186 static ssize_t
ixgbe_dbg_netdev_ops_write(struct file
*filp
,
187 const char __user
*buffer
,
188 size_t count
, loff_t
*ppos
)
190 struct ixgbe_adapter
*adapter
= filp
->private_data
;
193 /* don't allow partial writes */
196 if (count
>= sizeof(ixgbe_dbg_netdev_ops_buf
))
199 len
= simple_write_to_buffer(ixgbe_dbg_netdev_ops_buf
,
200 sizeof(ixgbe_dbg_netdev_ops_buf
)-1,
207 ixgbe_dbg_netdev_ops_buf
[len
] = '\0';
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");
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");
220 static const struct file_operations ixgbe_dbg_netdev_ops_fops
= {
221 .owner
= THIS_MODULE
,
223 .read
= ixgbe_dbg_netdev_ops_read
,
224 .write
= ixgbe_dbg_netdev_ops_write
,
228 * ixgbe_dbg_adapter_init - setup the debugfs directory for the adapter
229 * @adapter: the adapter that is starting up
231 void ixgbe_dbg_adapter_init(struct ixgbe_adapter
*adapter
)
233 const char *name
= pci_name(adapter
->pdev
);
234 struct dentry
*pfile
;
235 adapter
->ixgbe_dbg_adapter
= debugfs_create_dir(name
, ixgbe_dbg_root
);
236 if (adapter
->ixgbe_dbg_adapter
) {
237 pfile
= debugfs_create_file("reg_ops", 0600,
238 adapter
->ixgbe_dbg_adapter
, adapter
,
239 &ixgbe_dbg_reg_ops_fops
);
241 e_dev_err("debugfs reg_ops for %s failed\n", name
);
242 pfile
= debugfs_create_file("netdev_ops", 0600,
243 adapter
->ixgbe_dbg_adapter
, adapter
,
244 &ixgbe_dbg_netdev_ops_fops
);
246 e_dev_err("debugfs netdev_ops for %s failed\n", name
);
248 e_dev_err("debugfs entry for %s failed\n", name
);
253 * ixgbe_dbg_adapter_exit - clear out the adapter's debugfs entries
254 * @pf: the pf that is stopping
256 void ixgbe_dbg_adapter_exit(struct ixgbe_adapter
*adapter
)
258 if (adapter
->ixgbe_dbg_adapter
)
259 debugfs_remove_recursive(adapter
->ixgbe_dbg_adapter
);
260 adapter
->ixgbe_dbg_adapter
= NULL
;
264 * ixgbe_dbg_init - start up debugfs for the driver
266 void ixgbe_dbg_init(void)
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");
274 * ixgbe_dbg_exit - clean out the driver's debugfs entries
276 void ixgbe_dbg_exit(void)
278 debugfs_remove_recursive(ixgbe_dbg_root
);
281 #endif /* CONFIG_DEBUG_FS */