fm10k_debugfs.c 6.6 KB

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