Commit | Line | Data |
---|---|---|
00949167 CS |
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 | ||
826ff0de CS |
37 | static char ixgbe_dbg_netdev_ops_buf[256] = ""; |
38 | ||
39 | /** | |
40 | * ixgbe_dbg_netdev_ops_open - prep the debugfs netdev_ops data item | |
41 | * @inode: inode that was opened | |
42 | * @filp: file info | |
43 | * | |
44 | * Stash the adapter pointer hiding in the inode into the file pointer | |
45 | * where we can find it later in the read and write calls | |
46 | **/ | |
47 | static int ixgbe_dbg_netdev_ops_open(struct inode *inode, struct file *filp) | |
48 | { | |
49 | filp->private_data = inode->i_private; | |
50 | return 0; | |
51 | } | |
52 | ||
53 | /** | |
54 | * ixgbe_dbg_netdev_ops_read - read for netdev_ops datum | |
55 | * @filp: the opened file | |
56 | * @buffer: where to write the data for the user to read | |
57 | * @count: the size of the user's buffer | |
58 | * @ppos: file position offset | |
59 | **/ | |
60 | static ssize_t ixgbe_dbg_netdev_ops_read(struct file *filp, | |
61 | char __user *buffer, | |
62 | size_t count, loff_t *ppos) | |
63 | { | |
64 | struct ixgbe_adapter *adapter = filp->private_data; | |
65 | char buf[256]; | |
66 | int bytes_not_copied; | |
67 | int len; | |
68 | ||
69 | /* don't allow partial reads */ | |
70 | if (*ppos != 0) | |
71 | return 0; | |
72 | ||
73 | len = snprintf(buf, sizeof(buf), "%s: %s\n", | |
74 | adapter->netdev->name, ixgbe_dbg_netdev_ops_buf); | |
75 | if (count < len) | |
76 | return -ENOSPC; | |
77 | bytes_not_copied = copy_to_user(buffer, buf, len); | |
78 | if (bytes_not_copied < 0) | |
79 | return bytes_not_copied; | |
80 | ||
81 | *ppos = len; | |
82 | return len; | |
83 | } | |
84 | ||
85 | /** | |
86 | * ixgbe_dbg_netdev_ops_write - write into netdev_ops datum | |
87 | * @filp: the opened file | |
88 | * @buffer: where to find the user's data | |
89 | * @count: the length of the user's data | |
90 | * @ppos: file position offset | |
91 | **/ | |
92 | static ssize_t ixgbe_dbg_netdev_ops_write(struct file *filp, | |
93 | const char __user *buffer, | |
94 | size_t count, loff_t *ppos) | |
95 | { | |
96 | struct ixgbe_adapter *adapter = filp->private_data; | |
97 | int bytes_not_copied; | |
98 | ||
99 | /* don't allow partial writes */ | |
100 | if (*ppos != 0) | |
101 | return 0; | |
102 | if (count >= sizeof(ixgbe_dbg_netdev_ops_buf)) | |
103 | return -ENOSPC; | |
104 | ||
105 | bytes_not_copied = copy_from_user(ixgbe_dbg_netdev_ops_buf, | |
106 | buffer, count); | |
107 | if (bytes_not_copied < 0) | |
108 | return bytes_not_copied; | |
109 | else if (bytes_not_copied < count) | |
110 | count -= bytes_not_copied; | |
111 | else | |
112 | return -ENOSPC; | |
113 | ixgbe_dbg_netdev_ops_buf[count] = '\0'; | |
114 | ||
115 | if (strncmp(ixgbe_dbg_netdev_ops_buf, "tx_timeout", 10) == 0) { | |
116 | adapter->netdev->netdev_ops->ndo_tx_timeout(adapter->netdev); | |
117 | e_dev_info("tx_timeout called\n"); | |
118 | } else { | |
119 | e_dev_info("Unknown command: %s\n", ixgbe_dbg_netdev_ops_buf); | |
120 | e_dev_info("Available commands:\n"); | |
121 | e_dev_info(" tx_timeout\n"); | |
122 | } | |
123 | return count; | |
124 | } | |
125 | ||
126 | static const struct file_operations ixgbe_dbg_netdev_ops_fops = { | |
127 | .owner = THIS_MODULE, | |
128 | .open = ixgbe_dbg_netdev_ops_open, | |
129 | .read = ixgbe_dbg_netdev_ops_read, | |
130 | .write = ixgbe_dbg_netdev_ops_write, | |
131 | }; | |
132 | ||
00949167 CS |
133 | /** |
134 | * ixgbe_dbg_adapter_init - setup the debugfs directory for the adapter | |
135 | * @adapter: the adapter that is starting up | |
136 | **/ | |
137 | void ixgbe_dbg_adapter_init(struct ixgbe_adapter *adapter) | |
138 | { | |
139 | const char *name = pci_name(adapter->pdev); | |
826ff0de | 140 | struct dentry *pfile; |
00949167 | 141 | adapter->ixgbe_dbg_adapter = debugfs_create_dir(name, ixgbe_dbg_root); |
826ff0de CS |
142 | if (adapter->ixgbe_dbg_adapter) { |
143 | pfile = debugfs_create_file("netdev_ops", 0600, | |
144 | adapter->ixgbe_dbg_adapter, adapter, | |
145 | &ixgbe_dbg_netdev_ops_fops); | |
146 | if (!pfile) | |
147 | e_dev_err("debugfs netdev_ops for %s failed\n", name); | |
148 | } else { | |
00949167 | 149 | e_dev_err("debugfs entry for %s failed\n", name); |
826ff0de | 150 | } |
00949167 CS |
151 | } |
152 | ||
153 | /** | |
154 | * ixgbe_dbg_adapter_exit - clear out the adapter's debugfs entries | |
155 | * @pf: the pf that is stopping | |
156 | **/ | |
157 | void ixgbe_dbg_adapter_exit(struct ixgbe_adapter *adapter) | |
158 | { | |
159 | if (adapter->ixgbe_dbg_adapter) | |
160 | debugfs_remove_recursive(adapter->ixgbe_dbg_adapter); | |
161 | adapter->ixgbe_dbg_adapter = NULL; | |
162 | } | |
163 | ||
164 | /** | |
165 | * ixgbe_dbg_init - start up debugfs for the driver | |
166 | **/ | |
167 | void ixgbe_dbg_init(void) | |
168 | { | |
169 | ixgbe_dbg_root = debugfs_create_dir(ixgbe_driver_name, NULL); | |
170 | if (ixgbe_dbg_root == NULL) | |
171 | pr_err("init of debugfs failed\n"); | |
172 | } | |
173 | ||
174 | /** | |
175 | * ixgbe_dbg_exit - clean out the driver's debugfs entries | |
176 | **/ | |
177 | void ixgbe_dbg_exit(void) | |
178 | { | |
179 | debugfs_remove_recursive(ixgbe_dbg_root); | |
180 | } | |
181 | ||
182 | #endif /* CONFIG_DEBUG_FS */ |