ixgbe_debugfs.c 7.3 KB

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