aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCatherine Sullivan <catherine.sullivan@intel.com>2012-08-09 21:59:21 -0400
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>2012-09-15 19:36:45 -0400
commit91fbd8f081e22a3d296b45766eaf5045925f9313 (patch)
tree05eff9ef046b585d24f2ac81e3bd6f32c0b95db6
parent826ff0de1178669eac123d706f78b455aa0f2c4d (diff)
ixgbe: added reg_ops file to debugfs
Added the reg_ops file to debugfs with commands to read and write a register to give users the ability to read and write individual registers on the fly. Signed-off-by: Catherine Sullivan <catherine.sullivan@intel.com> Tested-by: Phil Schmitt <phillip.j.schmitt@intel.com> Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_debugfs.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_debugfs.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_debugfs.c
index 2dd169ee5e68..8d3a21889099 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_debugfs.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_debugfs.c
@@ -34,6 +34,119 @@
34 34
35static struct dentry *ixgbe_dbg_root; 35static struct dentry *ixgbe_dbg_root;
36 36
37static char ixgbe_dbg_reg_ops_buf[256] = "";
38
39/**
40 * ixgbe_dbg_reg_ops_open - prep the debugfs pokee data item when opened
41 * @inode: inode that was opened
42 * @filp: file info
43 *
44 * Stash the adapter pointer hiding in the inode into the file pointer where
45 * we can find it later in the read and write calls
46 **/
47static int ixgbe_dbg_reg_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_reg_ops_read - read for reg_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 **/
60static ssize_t ixgbe_dbg_reg_ops_read(struct file *filp, char __user *buffer,
61 size_t count, loff_t *ppos)
62{
63 struct ixgbe_adapter *adapter = filp->private_data;
64 char buf[256];
65 int bytes_not_copied;
66 int len;
67
68 /* don't allow partial reads */
69 if (*ppos != 0)
70 return 0;
71
72 len = snprintf(buf, sizeof(buf), "%s: %s\n",
73 adapter->netdev->name, ixgbe_dbg_reg_ops_buf);
74 if (count < len)
75 return -ENOSPC;
76 bytes_not_copied = copy_to_user(buffer, buf, len);
77 if (bytes_not_copied < 0)
78 return bytes_not_copied;
79
80 *ppos = len;
81 return len;
82}
83
84/**
85 * ixgbe_dbg_reg_ops_write - write into reg_ops datum
86 * @filp: the opened file
87 * @buffer: where to find the user's data
88 * @count: the length of the user's data
89 * @ppos: file position offset
90 **/
91static ssize_t ixgbe_dbg_reg_ops_write(struct file *filp,
92 const char __user *buffer,
93 size_t count, loff_t *ppos)
94{
95 struct ixgbe_adapter *adapter = filp->private_data;
96 int bytes_not_copied;
97
98 /* don't allow partial writes */
99 if (*ppos != 0)
100 return 0;
101 if (count >= sizeof(ixgbe_dbg_reg_ops_buf))
102 return -ENOSPC;
103
104 bytes_not_copied = copy_from_user(ixgbe_dbg_reg_ops_buf, buffer, count);
105 if (bytes_not_copied < 0)
106 return bytes_not_copied;
107 else if (bytes_not_copied < count)
108 count -= bytes_not_copied;
109 else
110 return -ENOSPC;
111 ixgbe_dbg_reg_ops_buf[count] = '\0';
112
113 if (strncmp(ixgbe_dbg_reg_ops_buf, "write", 5) == 0) {
114 u32 reg, value;
115 int cnt;
116 cnt = sscanf(&ixgbe_dbg_reg_ops_buf[5], "%x %x", &reg, &value);
117 if (cnt == 2) {
118 IXGBE_WRITE_REG(&adapter->hw, reg, value);
119 value = IXGBE_READ_REG(&adapter->hw, reg);
120 e_dev_info("write: 0x%08x = 0x%08x\n", reg, value);
121 } else {
122 e_dev_info("write <reg> <value>\n");
123 }
124 } else if (strncmp(ixgbe_dbg_reg_ops_buf, "read", 4) == 0) {
125 u32 reg, value;
126 int cnt;
127 cnt = sscanf(&ixgbe_dbg_reg_ops_buf[4], "%x", &reg);
128 if (cnt == 1) {
129 value = IXGBE_READ_REG(&adapter->hw, reg);
130 e_dev_info("read 0x%08x = 0x%08x\n", reg, value);
131 } else {
132 e_dev_info("read <reg>\n");
133 }
134 } else {
135 e_dev_info("Unknown command %s\n", ixgbe_dbg_reg_ops_buf);
136 e_dev_info("Available commands:\n");
137 e_dev_info(" read <reg>\n");
138 e_dev_info(" write <reg> <value>\n");
139 }
140 return count;
141}
142
143static const struct file_operations ixgbe_dbg_reg_ops_fops = {
144 .owner = THIS_MODULE,
145 .open = ixgbe_dbg_reg_ops_open,
146 .read = ixgbe_dbg_reg_ops_read,
147 .write = ixgbe_dbg_reg_ops_write,
148};
149
37static char ixgbe_dbg_netdev_ops_buf[256] = ""; 150static char ixgbe_dbg_netdev_ops_buf[256] = "";
38 151
39/** 152/**
@@ -140,6 +253,11 @@ void ixgbe_dbg_adapter_init(struct ixgbe_adapter *adapter)
140 struct dentry *pfile; 253 struct dentry *pfile;
141 adapter->ixgbe_dbg_adapter = debugfs_create_dir(name, ixgbe_dbg_root); 254 adapter->ixgbe_dbg_adapter = debugfs_create_dir(name, ixgbe_dbg_root);
142 if (adapter->ixgbe_dbg_adapter) { 255 if (adapter->ixgbe_dbg_adapter) {
256 pfile = debugfs_create_file("reg_ops", 0600,
257 adapter->ixgbe_dbg_adapter, adapter,
258 &ixgbe_dbg_reg_ops_fops);
259 if (!pfile)
260 e_dev_err("debugfs reg_ops for %s failed\n", name);
143 pfile = debugfs_create_file("netdev_ops", 0600, 261 pfile = debugfs_create_file("netdev_ops", 0600,
144 adapter->ixgbe_dbg_adapter, adapter, 262 adapter->ixgbe_dbg_adapter, adapter,
145 &ixgbe_dbg_netdev_ops_fops); 263 &ixgbe_dbg_netdev_ops_fops);