fm10k_debugfs.c 5.9 KB

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