1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 1999 - 2018 Intel Corporation. */
4 #include <linux/debugfs.h>
5 #include <linux/module.h>
9 static struct dentry *ixgbe_dbg_root;
11 static char ixgbe_dbg_reg_ops_buf[256] = "";
13 static ssize_t ixgbe_dbg_common_ops_read(struct file *filp, char __user *buffer,
14 size_t count, loff_t *ppos,
17 struct ixgbe_adapter *adapter = filp->private_data;
21 /* don't allow partial reads */
25 buf = kasprintf(GFP_KERNEL, "%s: %s\n",
26 adapter->netdev->name, dbg_buf);
30 if (count < strlen(buf)) {
35 len = simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
42 * ixgbe_dbg_reg_ops_read - read for reg_ops datum
43 * @filp: the opened file
44 * @buffer: where to write the data for the user to read
45 * @count: the size of the user's buffer
46 * @ppos: file position offset
48 static ssize_t ixgbe_dbg_reg_ops_read(struct file *filp, char __user *buffer,
49 size_t count, loff_t *ppos)
51 return ixgbe_dbg_common_ops_read(filp, buffer, count, ppos,
52 ixgbe_dbg_reg_ops_buf);
56 * ixgbe_dbg_reg_ops_write - write into reg_ops datum
57 * @filp: the opened file
58 * @buffer: where to find the user's data
59 * @count: the length of the user's data
60 * @ppos: file position offset
62 static ssize_t ixgbe_dbg_reg_ops_write(struct file *filp,
63 const char __user *buffer,
64 size_t count, loff_t *ppos)
66 struct ixgbe_adapter *adapter = filp->private_data;
69 /* don't allow partial writes */
72 if (count >= sizeof(ixgbe_dbg_reg_ops_buf))
75 len = simple_write_to_buffer(ixgbe_dbg_reg_ops_buf,
76 sizeof(ixgbe_dbg_reg_ops_buf)-1,
83 ixgbe_dbg_reg_ops_buf[len] = '\0';
85 if (strncmp(ixgbe_dbg_reg_ops_buf, "write", 5) == 0) {
88 cnt = sscanf(&ixgbe_dbg_reg_ops_buf[5], "%x %x", ®, &value);
90 IXGBE_WRITE_REG(&adapter->hw, reg, value);
91 value = IXGBE_READ_REG(&adapter->hw, reg);
92 e_dev_info("write: 0x%08x = 0x%08x\n", reg, value);
94 e_dev_info("write <reg> <value>\n");
96 } else if (strncmp(ixgbe_dbg_reg_ops_buf, "read", 4) == 0) {
99 cnt = sscanf(&ixgbe_dbg_reg_ops_buf[4], "%x", ®);
101 value = IXGBE_READ_REG(&adapter->hw, reg);
102 e_dev_info("read 0x%08x = 0x%08x\n", reg, value);
104 e_dev_info("read <reg>\n");
107 e_dev_info("Unknown command %s\n", ixgbe_dbg_reg_ops_buf);
108 e_dev_info("Available commands:\n");
109 e_dev_info(" read <reg>\n");
110 e_dev_info(" write <reg> <value>\n");
115 static const struct file_operations ixgbe_dbg_reg_ops_fops = {
116 .owner = THIS_MODULE,
118 .read = ixgbe_dbg_reg_ops_read,
119 .write = ixgbe_dbg_reg_ops_write,
122 static char ixgbe_dbg_netdev_ops_buf[256] = "";
125 * ixgbe_dbg_netdev_ops_read - read for netdev_ops datum
126 * @filp: the opened file
127 * @buffer: where to write the data for the user to read
128 * @count: the size of the user's buffer
129 * @ppos: file position offset
131 static ssize_t ixgbe_dbg_netdev_ops_read(struct file *filp, char __user *buffer,
132 size_t count, loff_t *ppos)
134 return ixgbe_dbg_common_ops_read(filp, buffer, count, ppos,
135 ixgbe_dbg_netdev_ops_buf);
139 * ixgbe_dbg_netdev_ops_write - write into netdev_ops datum
140 * @filp: the opened file
141 * @buffer: where to find the user's data
142 * @count: the length of the user's data
143 * @ppos: file position offset
145 static ssize_t ixgbe_dbg_netdev_ops_write(struct file *filp,
146 const char __user *buffer,
147 size_t count, loff_t *ppos)
149 struct ixgbe_adapter *adapter = filp->private_data;
152 /* don't allow partial writes */
155 if (count >= sizeof(ixgbe_dbg_netdev_ops_buf))
158 len = simple_write_to_buffer(ixgbe_dbg_netdev_ops_buf,
159 sizeof(ixgbe_dbg_netdev_ops_buf)-1,
166 ixgbe_dbg_netdev_ops_buf[len] = '\0';
168 if (strncmp(ixgbe_dbg_netdev_ops_buf, "tx_timeout", 10) == 0) {
169 adapter->netdev->netdev_ops->ndo_tx_timeout(adapter->netdev);
170 e_dev_info("tx_timeout called\n");
172 e_dev_info("Unknown command: %s\n", ixgbe_dbg_netdev_ops_buf);
173 e_dev_info("Available commands:\n");
174 e_dev_info(" tx_timeout\n");
179 static const struct file_operations ixgbe_dbg_netdev_ops_fops = {
180 .owner = THIS_MODULE,
182 .read = ixgbe_dbg_netdev_ops_read,
183 .write = ixgbe_dbg_netdev_ops_write,
187 * ixgbe_dbg_adapter_init - setup the debugfs directory for the adapter
188 * @adapter: the adapter that is starting up
190 void ixgbe_dbg_adapter_init(struct ixgbe_adapter *adapter)
192 const char *name = pci_name(adapter->pdev);
193 struct dentry *pfile;
194 adapter->ixgbe_dbg_adapter = debugfs_create_dir(name, ixgbe_dbg_root);
195 if (adapter->ixgbe_dbg_adapter) {
196 pfile = debugfs_create_file("reg_ops", 0600,
197 adapter->ixgbe_dbg_adapter, adapter,
198 &ixgbe_dbg_reg_ops_fops);
200 e_dev_err("debugfs reg_ops for %s failed\n", name);
201 pfile = debugfs_create_file("netdev_ops", 0600,
202 adapter->ixgbe_dbg_adapter, adapter,
203 &ixgbe_dbg_netdev_ops_fops);
205 e_dev_err("debugfs netdev_ops for %s failed\n", name);
207 e_dev_err("debugfs entry for %s failed\n", name);
212 * ixgbe_dbg_adapter_exit - clear out the adapter's debugfs entries
213 * @adapter: the adapter that is exiting
215 void ixgbe_dbg_adapter_exit(struct ixgbe_adapter *adapter)
217 debugfs_remove_recursive(adapter->ixgbe_dbg_adapter);
218 adapter->ixgbe_dbg_adapter = NULL;
222 * ixgbe_dbg_init - start up debugfs for the driver
224 void ixgbe_dbg_init(void)
226 ixgbe_dbg_root = debugfs_create_dir(ixgbe_driver_name, NULL);
227 if (ixgbe_dbg_root == NULL)
228 pr_err("init of debugfs failed\n");
232 * ixgbe_dbg_exit - clean out the driver's debugfs entries
234 void ixgbe_dbg_exit(void)
236 debugfs_remove_recursive(ixgbe_dbg_root);