blob: efaf9a73cc79a534edd877dd724bace80ba3cf5b [file] [log] [blame]
Catherine Sullivan00949162012-08-10 01:59:10 +00001/*******************************************************************************
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
35static struct dentry *ixgbe_dbg_root;
36
Catherine Sullivan91fbd8f2012-08-10 01:59:21 +000037static char ixgbe_dbg_reg_ops_buf[256] = "";
38
39/**
Catherine Sullivan91fbd8f2012-08-10 01:59:21 +000040 * 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 **/
46static 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;
50 char buf[256];
51 int bytes_not_copied;
52 int len;
53
54 /* don't allow partial reads */
55 if (*ppos != 0)
56 return 0;
57
58 len = snprintf(buf, sizeof(buf), "%s: %s\n",
59 adapter->netdev->name, ixgbe_dbg_reg_ops_buf);
60 if (count < len)
61 return -ENOSPC;
62 bytes_not_copied = copy_to_user(buffer, buf, len);
63 if (bytes_not_copied < 0)
64 return bytes_not_copied;
65
66 *ppos = len;
67 return len;
68}
69
70/**
71 * ixgbe_dbg_reg_ops_write - write into reg_ops datum
72 * @filp: the opened file
73 * @buffer: where to find the user's data
74 * @count: the length of the user's data
75 * @ppos: file position offset
76 **/
77static ssize_t ixgbe_dbg_reg_ops_write(struct file *filp,
78 const char __user *buffer,
79 size_t count, loff_t *ppos)
80{
81 struct ixgbe_adapter *adapter = filp->private_data;
82 int bytes_not_copied;
83
84 /* don't allow partial writes */
85 if (*ppos != 0)
86 return 0;
87 if (count >= sizeof(ixgbe_dbg_reg_ops_buf))
88 return -ENOSPC;
89
90 bytes_not_copied = copy_from_user(ixgbe_dbg_reg_ops_buf, buffer, count);
91 if (bytes_not_copied < 0)
92 return bytes_not_copied;
93 else if (bytes_not_copied < count)
94 count -= bytes_not_copied;
95 else
96 return -ENOSPC;
97 ixgbe_dbg_reg_ops_buf[count] = '\0';
98
99 if (strncmp(ixgbe_dbg_reg_ops_buf, "write", 5) == 0) {
100 u32 reg, value;
101 int cnt;
102 cnt = sscanf(&ixgbe_dbg_reg_ops_buf[5], "%x %x", &reg, &value);
103 if (cnt == 2) {
104 IXGBE_WRITE_REG(&adapter->hw, reg, value);
105 value = IXGBE_READ_REG(&adapter->hw, reg);
106 e_dev_info("write: 0x%08x = 0x%08x\n", reg, value);
107 } else {
108 e_dev_info("write <reg> <value>\n");
109 }
110 } else if (strncmp(ixgbe_dbg_reg_ops_buf, "read", 4) == 0) {
111 u32 reg, value;
112 int cnt;
113 cnt = sscanf(&ixgbe_dbg_reg_ops_buf[4], "%x", &reg);
114 if (cnt == 1) {
115 value = IXGBE_READ_REG(&adapter->hw, reg);
116 e_dev_info("read 0x%08x = 0x%08x\n", reg, value);
117 } else {
118 e_dev_info("read <reg>\n");
119 }
120 } else {
121 e_dev_info("Unknown command %s\n", ixgbe_dbg_reg_ops_buf);
122 e_dev_info("Available commands:\n");
123 e_dev_info(" read <reg>\n");
124 e_dev_info(" write <reg> <value>\n");
125 }
126 return count;
127}
128
129static const struct file_operations ixgbe_dbg_reg_ops_fops = {
130 .owner = THIS_MODULE,
Wei Yongjun21cc57f2012-10-18 06:34:08 +0000131 .open = simple_open,
Catherine Sullivan91fbd8f2012-08-10 01:59:21 +0000132 .read = ixgbe_dbg_reg_ops_read,
133 .write = ixgbe_dbg_reg_ops_write,
134};
135
Catherine Sullivan826ff0d2012-08-10 01:59:15 +0000136static char ixgbe_dbg_netdev_ops_buf[256] = "";
137
138/**
Catherine Sullivan826ff0d2012-08-10 01:59:15 +0000139 * ixgbe_dbg_netdev_ops_read - read for netdev_ops datum
140 * @filp: the opened file
141 * @buffer: where to write the data for the user to read
142 * @count: the size of the user's buffer
143 * @ppos: file position offset
144 **/
145static ssize_t ixgbe_dbg_netdev_ops_read(struct file *filp,
146 char __user *buffer,
147 size_t count, loff_t *ppos)
148{
149 struct ixgbe_adapter *adapter = filp->private_data;
150 char buf[256];
151 int bytes_not_copied;
152 int len;
153
154 /* don't allow partial reads */
155 if (*ppos != 0)
156 return 0;
157
158 len = snprintf(buf, sizeof(buf), "%s: %s\n",
159 adapter->netdev->name, ixgbe_dbg_netdev_ops_buf);
160 if (count < len)
161 return -ENOSPC;
162 bytes_not_copied = copy_to_user(buffer, buf, len);
163 if (bytes_not_copied < 0)
164 return bytes_not_copied;
165
166 *ppos = len;
167 return len;
168}
169
170/**
171 * ixgbe_dbg_netdev_ops_write - write into netdev_ops datum
172 * @filp: the opened file
173 * @buffer: where to find the user's data
174 * @count: the length of the user's data
175 * @ppos: file position offset
176 **/
177static ssize_t ixgbe_dbg_netdev_ops_write(struct file *filp,
178 const char __user *buffer,
179 size_t count, loff_t *ppos)
180{
181 struct ixgbe_adapter *adapter = filp->private_data;
182 int bytes_not_copied;
183
184 /* don't allow partial writes */
185 if (*ppos != 0)
186 return 0;
187 if (count >= sizeof(ixgbe_dbg_netdev_ops_buf))
188 return -ENOSPC;
189
190 bytes_not_copied = copy_from_user(ixgbe_dbg_netdev_ops_buf,
191 buffer, count);
192 if (bytes_not_copied < 0)
193 return bytes_not_copied;
194 else if (bytes_not_copied < count)
195 count -= bytes_not_copied;
196 else
197 return -ENOSPC;
198 ixgbe_dbg_netdev_ops_buf[count] = '\0';
199
200 if (strncmp(ixgbe_dbg_netdev_ops_buf, "tx_timeout", 10) == 0) {
201 adapter->netdev->netdev_ops->ndo_tx_timeout(adapter->netdev);
202 e_dev_info("tx_timeout called\n");
203 } else {
204 e_dev_info("Unknown command: %s\n", ixgbe_dbg_netdev_ops_buf);
205 e_dev_info("Available commands:\n");
206 e_dev_info(" tx_timeout\n");
207 }
208 return count;
209}
210
211static const struct file_operations ixgbe_dbg_netdev_ops_fops = {
212 .owner = THIS_MODULE,
Wei Yongjun21cc57f2012-10-18 06:34:08 +0000213 .open = simple_open,
Catherine Sullivan826ff0d2012-08-10 01:59:15 +0000214 .read = ixgbe_dbg_netdev_ops_read,
215 .write = ixgbe_dbg_netdev_ops_write,
216};
217
Catherine Sullivan00949162012-08-10 01:59:10 +0000218/**
219 * ixgbe_dbg_adapter_init - setup the debugfs directory for the adapter
220 * @adapter: the adapter that is starting up
221 **/
222void ixgbe_dbg_adapter_init(struct ixgbe_adapter *adapter)
223{
224 const char *name = pci_name(adapter->pdev);
Catherine Sullivan826ff0d2012-08-10 01:59:15 +0000225 struct dentry *pfile;
Catherine Sullivan00949162012-08-10 01:59:10 +0000226 adapter->ixgbe_dbg_adapter = debugfs_create_dir(name, ixgbe_dbg_root);
Catherine Sullivan826ff0d2012-08-10 01:59:15 +0000227 if (adapter->ixgbe_dbg_adapter) {
Catherine Sullivan91fbd8f2012-08-10 01:59:21 +0000228 pfile = debugfs_create_file("reg_ops", 0600,
229 adapter->ixgbe_dbg_adapter, adapter,
230 &ixgbe_dbg_reg_ops_fops);
231 if (!pfile)
232 e_dev_err("debugfs reg_ops for %s failed\n", name);
Catherine Sullivan826ff0d2012-08-10 01:59:15 +0000233 pfile = debugfs_create_file("netdev_ops", 0600,
234 adapter->ixgbe_dbg_adapter, adapter,
235 &ixgbe_dbg_netdev_ops_fops);
236 if (!pfile)
237 e_dev_err("debugfs netdev_ops for %s failed\n", name);
238 } else {
Catherine Sullivan00949162012-08-10 01:59:10 +0000239 e_dev_err("debugfs entry for %s failed\n", name);
Catherine Sullivan826ff0d2012-08-10 01:59:15 +0000240 }
Catherine Sullivan00949162012-08-10 01:59:10 +0000241}
242
243/**
244 * ixgbe_dbg_adapter_exit - clear out the adapter's debugfs entries
245 * @pf: the pf that is stopping
246 **/
247void ixgbe_dbg_adapter_exit(struct ixgbe_adapter *adapter)
248{
249 if (adapter->ixgbe_dbg_adapter)
250 debugfs_remove_recursive(adapter->ixgbe_dbg_adapter);
251 adapter->ixgbe_dbg_adapter = NULL;
252}
253
254/**
255 * ixgbe_dbg_init - start up debugfs for the driver
256 **/
257void ixgbe_dbg_init(void)
258{
259 ixgbe_dbg_root = debugfs_create_dir(ixgbe_driver_name, NULL);
260 if (ixgbe_dbg_root == NULL)
261 pr_err("init of debugfs failed\n");
262}
263
264/**
265 * ixgbe_dbg_exit - clean out the driver's debugfs entries
266 **/
267void ixgbe_dbg_exit(void)
268{
269 debugfs_remove_recursive(ixgbe_dbg_root);
270}
271
272#endif /* CONFIG_DEBUG_FS */