fm10k_debugfs.c 6.6 KB

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