ixgbe_debugfs.c 7.5 KB

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