ixgbe_debugfs.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. #include <linux/debugfs.h>
  21. #include <linux/module.h>
  22. #include "ixgbe.h"
  23. static struct dentry *ixgbe_dbg_root;
  24. static char ixgbe_dbg_reg_ops_buf[256] = "";
  25. /**
  26. * ixgbe_dbg_reg_ops_read - read for reg_ops datum
  27. * @filp: the opened file
  28. * @buffer: where to write the data for the user to read
  29. * @count: the size of the user's buffer
  30. * @ppos: file position offset
  31. **/
  32. static ssize_t ixgbe_dbg_reg_ops_read(struct file *filp, char __user *buffer,
  33. size_t count, loff_t *ppos)
  34. {
  35. struct ixgbe_adapter *adapter = filp->private_data;
  36. char *buf;
  37. int len;
  38. /* don't allow partial reads */
  39. if (*ppos != 0)
  40. return 0;
  41. buf = kasprintf(GFP_KERNEL, "%s: %s\n",
  42. adapter->netdev->name,
  43. ixgbe_dbg_reg_ops_buf);
  44. if (!buf)
  45. return -ENOMEM;
  46. if (count < strlen(buf)) {
  47. kfree(buf);
  48. return -ENOSPC;
  49. }
  50. len = simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
  51. kfree(buf);
  52. return len;
  53. }
  54. /**
  55. * ixgbe_dbg_reg_ops_write - write into reg_ops datum
  56. * @filp: the opened file
  57. * @buffer: where to find the user's data
  58. * @count: the length of the user's data
  59. * @ppos: file position offset
  60. **/
  61. static ssize_t ixgbe_dbg_reg_ops_write(struct file *filp,
  62. const char __user *buffer,
  63. size_t count, loff_t *ppos)
  64. {
  65. struct ixgbe_adapter *adapter = filp->private_data;
  66. int len;
  67. /* don't allow partial writes */
  68. if (*ppos != 0)
  69. return 0;
  70. if (count >= sizeof(ixgbe_dbg_reg_ops_buf))
  71. return -ENOSPC;
  72. len = simple_write_to_buffer(ixgbe_dbg_reg_ops_buf,
  73. sizeof(ixgbe_dbg_reg_ops_buf)-1,
  74. ppos,
  75. buffer,
  76. count);
  77. if (len < 0)
  78. return len;
  79. ixgbe_dbg_reg_ops_buf[len] = '\0';
  80. if (strncmp(ixgbe_dbg_reg_ops_buf, "write", 5) == 0) {
  81. u32 reg, value;
  82. int cnt;
  83. cnt = sscanf(&ixgbe_dbg_reg_ops_buf[5], "%x %x", &reg, &value);
  84. if (cnt == 2) {
  85. IXGBE_WRITE_REG(&adapter->hw, reg, value);
  86. value = IXGBE_READ_REG(&adapter->hw, reg);
  87. e_dev_info("write: 0x%08x = 0x%08x\n", reg, value);
  88. } else {
  89. e_dev_info("write <reg> <value>\n");
  90. }
  91. } else if (strncmp(ixgbe_dbg_reg_ops_buf, "read", 4) == 0) {
  92. u32 reg, value;
  93. int cnt;
  94. cnt = sscanf(&ixgbe_dbg_reg_ops_buf[4], "%x", &reg);
  95. if (cnt == 1) {
  96. value = IXGBE_READ_REG(&adapter->hw, reg);
  97. e_dev_info("read 0x%08x = 0x%08x\n", reg, value);
  98. } else {
  99. e_dev_info("read <reg>\n");
  100. }
  101. } else {
  102. e_dev_info("Unknown command %s\n", ixgbe_dbg_reg_ops_buf);
  103. e_dev_info("Available commands:\n");
  104. e_dev_info(" read <reg>\n");
  105. e_dev_info(" write <reg> <value>\n");
  106. }
  107. return count;
  108. }
  109. static const struct file_operations ixgbe_dbg_reg_ops_fops = {
  110. .owner = THIS_MODULE,
  111. .open = simple_open,
  112. .read = ixgbe_dbg_reg_ops_read,
  113. .write = ixgbe_dbg_reg_ops_write,
  114. };
  115. static char ixgbe_dbg_netdev_ops_buf[256] = "";
  116. /**
  117. * ixgbe_dbg_netdev_ops_read - read for netdev_ops datum
  118. * @filp: the opened file
  119. * @buffer: where to write the data for the user to read
  120. * @count: the size of the user's buffer
  121. * @ppos: file position offset
  122. **/
  123. static ssize_t ixgbe_dbg_netdev_ops_read(struct file *filp,
  124. char __user *buffer,
  125. size_t count, loff_t *ppos)
  126. {
  127. struct ixgbe_adapter *adapter = filp->private_data;
  128. char *buf;
  129. int len;
  130. /* don't allow partial reads */
  131. if (*ppos != 0)
  132. return 0;
  133. buf = kasprintf(GFP_KERNEL, "%s: %s\n",
  134. adapter->netdev->name,
  135. ixgbe_dbg_netdev_ops_buf);
  136. if (!buf)
  137. return -ENOMEM;
  138. if (count < strlen(buf)) {
  139. kfree(buf);
  140. return -ENOSPC;
  141. }
  142. len = simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
  143. kfree(buf);
  144. return len;
  145. }
  146. /**
  147. * ixgbe_dbg_netdev_ops_write - write into netdev_ops datum
  148. * @filp: the opened file
  149. * @buffer: where to find the user's data
  150. * @count: the length of the user's data
  151. * @ppos: file position offset
  152. **/
  153. static ssize_t ixgbe_dbg_netdev_ops_write(struct file *filp,
  154. const char __user *buffer,
  155. size_t count, loff_t *ppos)
  156. {
  157. struct ixgbe_adapter *adapter = filp->private_data;
  158. int len;
  159. /* don't allow partial writes */
  160. if (*ppos != 0)
  161. return 0;
  162. if (count >= sizeof(ixgbe_dbg_netdev_ops_buf))
  163. return -ENOSPC;
  164. len = simple_write_to_buffer(ixgbe_dbg_netdev_ops_buf,
  165. sizeof(ixgbe_dbg_netdev_ops_buf)-1,
  166. ppos,
  167. buffer,
  168. count);
  169. if (len < 0)
  170. return len;
  171. ixgbe_dbg_netdev_ops_buf[len] = '\0';
  172. if (strncmp(ixgbe_dbg_netdev_ops_buf, "tx_timeout", 10) == 0) {
  173. adapter->netdev->netdev_ops->ndo_tx_timeout(adapter->netdev);
  174. e_dev_info("tx_timeout called\n");
  175. } else {
  176. e_dev_info("Unknown command: %s\n", ixgbe_dbg_netdev_ops_buf);
  177. e_dev_info("Available commands:\n");
  178. e_dev_info(" tx_timeout\n");
  179. }
  180. return count;
  181. }
  182. static const struct file_operations ixgbe_dbg_netdev_ops_fops = {
  183. .owner = THIS_MODULE,
  184. .open = simple_open,
  185. .read = ixgbe_dbg_netdev_ops_read,
  186. .write = ixgbe_dbg_netdev_ops_write,
  187. };
  188. /**
  189. * ixgbe_dbg_adapter_init - setup the debugfs directory for the adapter
  190. * @adapter: the adapter that is starting up
  191. **/
  192. void ixgbe_dbg_adapter_init(struct ixgbe_adapter *adapter)
  193. {
  194. const char *name = pci_name(adapter->pdev);
  195. struct dentry *pfile;
  196. adapter->ixgbe_dbg_adapter = debugfs_create_dir(name, ixgbe_dbg_root);
  197. if (adapter->ixgbe_dbg_adapter) {
  198. pfile = debugfs_create_file("reg_ops", 0600,
  199. adapter->ixgbe_dbg_adapter, adapter,
  200. &ixgbe_dbg_reg_ops_fops);
  201. if (!pfile)
  202. e_dev_err("debugfs reg_ops for %s failed\n", name);
  203. pfile = debugfs_create_file("netdev_ops", 0600,
  204. adapter->ixgbe_dbg_adapter, adapter,
  205. &ixgbe_dbg_netdev_ops_fops);
  206. if (!pfile)
  207. e_dev_err("debugfs netdev_ops for %s failed\n", name);
  208. } else {
  209. e_dev_err("debugfs entry for %s failed\n", name);
  210. }
  211. }
  212. /**
  213. * ixgbe_dbg_adapter_exit - clear out the adapter's debugfs entries
  214. * @pf: the pf that is stopping
  215. **/
  216. void ixgbe_dbg_adapter_exit(struct ixgbe_adapter *adapter)
  217. {
  218. if (adapter->ixgbe_dbg_adapter)
  219. debugfs_remove_recursive(adapter->ixgbe_dbg_adapter);
  220. adapter->ixgbe_dbg_adapter = NULL;
  221. }
  222. /**
  223. * ixgbe_dbg_init - start up debugfs for the driver
  224. **/
  225. void ixgbe_dbg_init(void)
  226. {
  227. ixgbe_dbg_root = debugfs_create_dir(ixgbe_driver_name, NULL);
  228. if (ixgbe_dbg_root == NULL)
  229. pr_err("init of debugfs failed\n");
  230. }
  231. /**
  232. * ixgbe_dbg_exit - clean out the driver's debugfs entries
  233. **/
  234. void ixgbe_dbg_exit(void)
  235. {
  236. debugfs_remove_recursive(ixgbe_dbg_root);
  237. }