ixgbe_debugfs.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2012 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. #ifdef CONFIG_DEBUG_FS
  21. #include <linux/debugfs.h>
  22. #include <linux/module.h>
  23. #include "ixgbe.h"
  24. static struct dentry *ixgbe_dbg_root;
  25. static char ixgbe_dbg_reg_ops_buf[256] = "";
  26. /**
  27. * ixgbe_dbg_reg_ops_open - prep the debugfs pokee data item when opened
  28. * @inode: inode that was opened
  29. * @filp: file info
  30. *
  31. * Stash the adapter pointer hiding in the inode into the file pointer where
  32. * we can find it later in the read and write calls
  33. **/
  34. static int ixgbe_dbg_reg_ops_open(struct inode *inode, struct file *filp)
  35. {
  36. filp->private_data = inode->i_private;
  37. return 0;
  38. }
  39. /**
  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
  45. **/
  46. static 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. /* don't allow partial reads */
  54. if (*ppos != 0)
  55. return 0;
  56. len = snprintf(buf, sizeof(buf), "%s: %s\n",
  57. adapter->netdev->name, ixgbe_dbg_reg_ops_buf);
  58. if (count < len)
  59. return -ENOSPC;
  60. bytes_not_copied = copy_to_user(buffer, buf, len);
  61. if (bytes_not_copied < 0)
  62. return bytes_not_copied;
  63. *ppos = len;
  64. return len;
  65. }
  66. /**
  67. * ixgbe_dbg_reg_ops_write - write into reg_ops datum
  68. * @filp: the opened file
  69. * @buffer: where to find the user's data
  70. * @count: the length of the user's data
  71. * @ppos: file position offset
  72. **/
  73. static ssize_t ixgbe_dbg_reg_ops_write(struct file *filp,
  74. const char __user *buffer,
  75. size_t count, loff_t *ppos)
  76. {
  77. struct ixgbe_adapter *adapter = filp->private_data;
  78. int bytes_not_copied;
  79. /* don't allow partial writes */
  80. if (*ppos != 0)
  81. return 0;
  82. if (count >= sizeof(ixgbe_dbg_reg_ops_buf))
  83. return -ENOSPC;
  84. bytes_not_copied = copy_from_user(ixgbe_dbg_reg_ops_buf, buffer, count);
  85. if (bytes_not_copied < 0)
  86. return bytes_not_copied;
  87. else if (bytes_not_copied < count)
  88. count -= bytes_not_copied;
  89. else
  90. return -ENOSPC;
  91. ixgbe_dbg_reg_ops_buf[count] = '\0';
  92. if (strncmp(ixgbe_dbg_reg_ops_buf, "write", 5) == 0) {
  93. u32 reg, value;
  94. int cnt;
  95. cnt = sscanf(&ixgbe_dbg_reg_ops_buf[5], "%x %x", &reg, &value);
  96. if (cnt == 2) {
  97. IXGBE_WRITE_REG(&adapter->hw, reg, value);
  98. value = IXGBE_READ_REG(&adapter->hw, reg);
  99. e_dev_info("write: 0x%08x = 0x%08x\n", reg, value);
  100. } else {
  101. e_dev_info("write <reg> <value>\n");
  102. }
  103. } else if (strncmp(ixgbe_dbg_reg_ops_buf, "read", 4) == 0) {
  104. u32 reg, value;
  105. int cnt;
  106. cnt = sscanf(&ixgbe_dbg_reg_ops_buf[4], "%x", &reg);
  107. if (cnt == 1) {
  108. value = IXGBE_READ_REG(&adapter->hw, reg);
  109. e_dev_info("read 0x%08x = 0x%08x\n", reg, value);
  110. } else {
  111. e_dev_info("read <reg>\n");
  112. }
  113. } else {
  114. e_dev_info("Unknown command %s\n", ixgbe_dbg_reg_ops_buf);
  115. e_dev_info("Available commands:\n");
  116. e_dev_info(" read <reg>\n");
  117. e_dev_info(" write <reg> <value>\n");
  118. }
  119. return count;
  120. }
  121. static const struct file_operations ixgbe_dbg_reg_ops_fops = {
  122. .owner = THIS_MODULE,
  123. .open = ixgbe_dbg_reg_ops_open,
  124. .read = ixgbe_dbg_reg_ops_read,
  125. .write = ixgbe_dbg_reg_ops_write,
  126. };
  127. static char ixgbe_dbg_netdev_ops_buf[256] = "";
  128. /**
  129. * ixgbe_dbg_netdev_ops_open - prep the debugfs netdev_ops data item
  130. * @inode: inode that was opened
  131. * @filp: file info
  132. *
  133. * Stash the adapter pointer hiding in the inode into the file pointer
  134. * where we can find it later in the read and write calls
  135. **/
  136. static int ixgbe_dbg_netdev_ops_open(struct inode *inode, struct file *filp)
  137. {
  138. filp->private_data = inode->i_private;
  139. return 0;
  140. }
  141. /**
  142. * ixgbe_dbg_netdev_ops_read - read for netdev_ops datum
  143. * @filp: the opened file
  144. * @buffer: where to write the data for the user to read
  145. * @count: the size of the user's buffer
  146. * @ppos: file position offset
  147. **/
  148. static ssize_t ixgbe_dbg_netdev_ops_read(struct file *filp,
  149. char __user *buffer,
  150. size_t count, loff_t *ppos)
  151. {
  152. struct ixgbe_adapter *adapter = filp->private_data;
  153. char buf[256];
  154. int bytes_not_copied;
  155. int len;
  156. /* don't allow partial reads */
  157. if (*ppos != 0)
  158. return 0;
  159. len = snprintf(buf, sizeof(buf), "%s: %s\n",
  160. adapter->netdev->name, ixgbe_dbg_netdev_ops_buf);
  161. if (count < len)
  162. return -ENOSPC;
  163. bytes_not_copied = copy_to_user(buffer, buf, len);
  164. if (bytes_not_copied < 0)
  165. return bytes_not_copied;
  166. *ppos = len;
  167. return len;
  168. }
  169. /**
  170. * ixgbe_dbg_netdev_ops_write - write into netdev_ops datum
  171. * @filp: the opened file
  172. * @buffer: where to find the user's data
  173. * @count: the length of the user's data
  174. * @ppos: file position offset
  175. **/
  176. static ssize_t ixgbe_dbg_netdev_ops_write(struct file *filp,
  177. const char __user *buffer,
  178. size_t count, loff_t *ppos)
  179. {
  180. struct ixgbe_adapter *adapter = filp->private_data;
  181. int bytes_not_copied;
  182. /* don't allow partial writes */
  183. if (*ppos != 0)
  184. return 0;
  185. if (count >= sizeof(ixgbe_dbg_netdev_ops_buf))
  186. return -ENOSPC;
  187. bytes_not_copied = copy_from_user(ixgbe_dbg_netdev_ops_buf,
  188. buffer, count);
  189. if (bytes_not_copied < 0)
  190. return bytes_not_copied;
  191. else if (bytes_not_copied < count)
  192. count -= bytes_not_copied;
  193. else
  194. return -ENOSPC;
  195. ixgbe_dbg_netdev_ops_buf[count] = '\0';
  196. if (strncmp(ixgbe_dbg_netdev_ops_buf, "tx_timeout", 10) == 0) {
  197. adapter->netdev->netdev_ops->ndo_tx_timeout(adapter->netdev);
  198. e_dev_info("tx_timeout called\n");
  199. } else {
  200. e_dev_info("Unknown command: %s\n", ixgbe_dbg_netdev_ops_buf);
  201. e_dev_info("Available commands:\n");
  202. e_dev_info(" tx_timeout\n");
  203. }
  204. return count;
  205. }
  206. static const struct file_operations ixgbe_dbg_netdev_ops_fops = {
  207. .owner = THIS_MODULE,
  208. .open = ixgbe_dbg_netdev_ops_open,
  209. .read = ixgbe_dbg_netdev_ops_read,
  210. .write = ixgbe_dbg_netdev_ops_write,
  211. };
  212. /**
  213. * ixgbe_dbg_adapter_init - setup the debugfs directory for the adapter
  214. * @adapter: the adapter that is starting up
  215. **/
  216. void ixgbe_dbg_adapter_init(struct ixgbe_adapter *adapter)
  217. {
  218. const char *name = pci_name(adapter->pdev);
  219. struct dentry *pfile;
  220. adapter->ixgbe_dbg_adapter = debugfs_create_dir(name, ixgbe_dbg_root);
  221. if (adapter->ixgbe_dbg_adapter) {
  222. pfile = debugfs_create_file("reg_ops", 0600,
  223. adapter->ixgbe_dbg_adapter, adapter,
  224. &ixgbe_dbg_reg_ops_fops);
  225. if (!pfile)
  226. e_dev_err("debugfs reg_ops for %s failed\n", name);
  227. pfile = debugfs_create_file("netdev_ops", 0600,
  228. adapter->ixgbe_dbg_adapter, adapter,
  229. &ixgbe_dbg_netdev_ops_fops);
  230. if (!pfile)
  231. e_dev_err("debugfs netdev_ops for %s failed\n", name);
  232. } else {
  233. e_dev_err("debugfs entry for %s failed\n", name);
  234. }
  235. }
  236. /**
  237. * ixgbe_dbg_adapter_exit - clear out the adapter's debugfs entries
  238. * @pf: the pf that is stopping
  239. **/
  240. void ixgbe_dbg_adapter_exit(struct ixgbe_adapter *adapter)
  241. {
  242. if (adapter->ixgbe_dbg_adapter)
  243. debugfs_remove_recursive(adapter->ixgbe_dbg_adapter);
  244. adapter->ixgbe_dbg_adapter = NULL;
  245. }
  246. /**
  247. * ixgbe_dbg_init - start up debugfs for the driver
  248. **/
  249. void ixgbe_dbg_init(void)
  250. {
  251. ixgbe_dbg_root = debugfs_create_dir(ixgbe_driver_name, NULL);
  252. if (ixgbe_dbg_root == NULL)
  253. pr_err("init of debugfs failed\n");
  254. }
  255. /**
  256. * ixgbe_dbg_exit - clean out the driver's debugfs entries
  257. **/
  258. void ixgbe_dbg_exit(void)
  259. {
  260. debugfs_remove_recursive(ixgbe_dbg_root);
  261. }
  262. #endif /* CONFIG_DEBUG_FS */