fm10k_debugfs.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /* Intel Ethernet Switch Host Interface Driver
  2. * Copyright(c) 2013 - 2015 Intel Corporation.
  3. *
  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. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * The full GNU General Public License is included in this distribution in
  14. * the file called "COPYING".
  15. *
  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 "fm10k.h"
  22. #include <linux/debugfs.h>
  23. #include <linux/seq_file.h>
  24. static struct dentry *dbg_root;
  25. /* Descriptor Seq Functions */
  26. static void *fm10k_dbg_desc_seq_start(struct seq_file *s, loff_t *pos)
  27. {
  28. struct fm10k_ring *ring = s->private;
  29. return (*pos < ring->count) ? pos : NULL;
  30. }
  31. static void *fm10k_dbg_desc_seq_next(struct seq_file *s,
  32. void __always_unused *v,
  33. loff_t *pos)
  34. {
  35. struct fm10k_ring *ring = s->private;
  36. return (++(*pos) < ring->count) ? pos : NULL;
  37. }
  38. static void fm10k_dbg_desc_seq_stop(struct seq_file __always_unused *s,
  39. void __always_unused *v)
  40. {
  41. /* Do nothing. */
  42. }
  43. static void fm10k_dbg_desc_break(struct seq_file *s, int i)
  44. {
  45. while (i--)
  46. seq_puts(s, "-");
  47. seq_puts(s, "\n");
  48. }
  49. static int fm10k_dbg_tx_desc_seq_show(struct seq_file *s, void *v)
  50. {
  51. struct fm10k_ring *ring = s->private;
  52. int i = *(loff_t *)v;
  53. static const char tx_desc_hdr[] =
  54. "DES BUFFER_ADDRESS LENGTH VLAN MSS HDRLEN FLAGS\n";
  55. /* Generate header */
  56. if (!i) {
  57. seq_printf(s, tx_desc_hdr);
  58. fm10k_dbg_desc_break(s, sizeof(tx_desc_hdr) - 1);
  59. }
  60. /* Validate descriptor allocation */
  61. if (!ring->desc) {
  62. seq_printf(s, "%03X Descriptor ring not allocated.\n", i);
  63. } else {
  64. struct fm10k_tx_desc *txd = FM10K_TX_DESC(ring, i);
  65. seq_printf(s, "%03X %#018llx %#06x %#06x %#06x %#06x %#04x\n",
  66. i, txd->buffer_addr, txd->buflen, txd->vlan,
  67. txd->mss, txd->hdrlen, txd->flags);
  68. }
  69. return 0;
  70. }
  71. static int fm10k_dbg_rx_desc_seq_show(struct seq_file *s, void *v)
  72. {
  73. struct fm10k_ring *ring = s->private;
  74. int i = *(loff_t *)v;
  75. static const char rx_desc_hdr[] =
  76. "DES DATA RSS STATERR LENGTH VLAN DGLORT SGLORT TIMESTAMP\n";
  77. /* Generate header */
  78. if (!i) {
  79. seq_printf(s, rx_desc_hdr);
  80. fm10k_dbg_desc_break(s, sizeof(rx_desc_hdr) - 1);
  81. }
  82. /* Validate descriptor allocation */
  83. if (!ring->desc) {
  84. seq_printf(s, "%03X Descriptor ring not allocated.\n", i);
  85. } else {
  86. union fm10k_rx_desc *rxd = FM10K_RX_DESC(ring, i);
  87. seq_printf(s,
  88. "%03X %#010x %#010x %#010x %#06x %#06x %#06x %#06x %#018llx\n",
  89. i, rxd->d.data, rxd->d.rss, rxd->d.staterr,
  90. rxd->w.length, rxd->w.vlan, rxd->w.dglort,
  91. rxd->w.sglort, rxd->q.timestamp);
  92. }
  93. return 0;
  94. }
  95. static const struct seq_operations fm10k_dbg_tx_desc_seq_ops = {
  96. .start = fm10k_dbg_desc_seq_start,
  97. .next = fm10k_dbg_desc_seq_next,
  98. .stop = fm10k_dbg_desc_seq_stop,
  99. .show = fm10k_dbg_tx_desc_seq_show,
  100. };
  101. static const struct seq_operations fm10k_dbg_rx_desc_seq_ops = {
  102. .start = fm10k_dbg_desc_seq_start,
  103. .next = fm10k_dbg_desc_seq_next,
  104. .stop = fm10k_dbg_desc_seq_stop,
  105. .show = fm10k_dbg_rx_desc_seq_show,
  106. };
  107. static int fm10k_dbg_desc_open(struct inode *inode, struct file *filep)
  108. {
  109. struct fm10k_ring *ring = inode->i_private;
  110. struct fm10k_q_vector *q_vector = ring->q_vector;
  111. const struct seq_operations *desc_seq_ops;
  112. int err;
  113. if (ring < q_vector->rx.ring)
  114. desc_seq_ops = &fm10k_dbg_tx_desc_seq_ops;
  115. else
  116. desc_seq_ops = &fm10k_dbg_rx_desc_seq_ops;
  117. err = seq_open(filep, desc_seq_ops);
  118. if (err)
  119. return err;
  120. ((struct seq_file *)filep->private_data)->private = ring;
  121. return 0;
  122. }
  123. static const struct file_operations fm10k_dbg_desc_fops = {
  124. .owner = THIS_MODULE,
  125. .open = fm10k_dbg_desc_open,
  126. .read = seq_read,
  127. .llseek = seq_lseek,
  128. .release = seq_release,
  129. };
  130. /**
  131. * fm10k_dbg_q_vector_init - setup debugfs for the q_vectors
  132. * @q_vector: q_vector to allocate directories for
  133. *
  134. * A folder is created for each q_vector found. In each q_vector
  135. * folder, a debugfs file is created for each tx and rx ring
  136. * allocated to the q_vector.
  137. **/
  138. void fm10k_dbg_q_vector_init(struct fm10k_q_vector *q_vector)
  139. {
  140. struct fm10k_intfc *interface = q_vector->interface;
  141. char name[16];
  142. int i;
  143. if (!interface->dbg_intfc)
  144. return;
  145. /* Generate a folder for each q_vector */
  146. snprintf(name, sizeof(name), "q_vector.%03d", q_vector->v_idx);
  147. q_vector->dbg_q_vector = debugfs_create_dir(name, interface->dbg_intfc);
  148. if (!q_vector->dbg_q_vector)
  149. return;
  150. /* Generate a file for each rx ring in the q_vector */
  151. for (i = 0; i < q_vector->tx.count; i++) {
  152. struct fm10k_ring *ring = &q_vector->tx.ring[i];
  153. snprintf(name, sizeof(name), "tx_ring.%03d", ring->queue_index);
  154. debugfs_create_file(name, 0600,
  155. q_vector->dbg_q_vector, ring,
  156. &fm10k_dbg_desc_fops);
  157. }
  158. /* Generate a file for each rx ring in the q_vector */
  159. for (i = 0; i < q_vector->rx.count; i++) {
  160. struct fm10k_ring *ring = &q_vector->rx.ring[i];
  161. snprintf(name, sizeof(name), "rx_ring.%03d", ring->queue_index);
  162. debugfs_create_file(name, 0600,
  163. q_vector->dbg_q_vector, ring,
  164. &fm10k_dbg_desc_fops);
  165. }
  166. }
  167. /**
  168. * fm10k_dbg_free_q_vector_dir - setup debugfs for the q_vectors
  169. * @q_vector: q_vector to allocate directories for
  170. **/
  171. void fm10k_dbg_q_vector_exit(struct fm10k_q_vector *q_vector)
  172. {
  173. struct fm10k_intfc *interface = q_vector->interface;
  174. if (interface->dbg_intfc)
  175. debugfs_remove_recursive(q_vector->dbg_q_vector);
  176. q_vector->dbg_q_vector = NULL;
  177. }
  178. /**
  179. * fm10k_dbg_intfc_init - setup the debugfs directory for the intferface
  180. * @interface: the interface that is starting up
  181. **/
  182. void fm10k_dbg_intfc_init(struct fm10k_intfc *interface)
  183. {
  184. const char *name = pci_name(interface->pdev);
  185. if (dbg_root)
  186. interface->dbg_intfc = debugfs_create_dir(name, dbg_root);
  187. }
  188. /**
  189. * fm10k_dbg_intfc_exit - clean out the interface's debugfs entries
  190. * @interface: the interface that is stopping
  191. **/
  192. void fm10k_dbg_intfc_exit(struct fm10k_intfc *interface)
  193. {
  194. if (dbg_root)
  195. debugfs_remove_recursive(interface->dbg_intfc);
  196. interface->dbg_intfc = NULL;
  197. }
  198. /**
  199. * fm10k_dbg_init - start up debugfs for the driver
  200. **/
  201. void fm10k_dbg_init(void)
  202. {
  203. dbg_root = debugfs_create_dir(fm10k_driver_name, NULL);
  204. }
  205. /**
  206. * fm10k_dbg_exit - clean out the driver's debugfs entries
  207. **/
  208. void fm10k_dbg_exit(void)
  209. {
  210. debugfs_remove_recursive(dbg_root);
  211. dbg_root = NULL;
  212. }
  213. #endif /* CONFIG_DEBUG_FS */