nfp_net_debugfs.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /*
  2. * Copyright (C) 2015 Netronome Systems, Inc.
  3. *
  4. * This software is dual licensed under the GNU General License Version 2,
  5. * June 1991 as shown in the file COPYING in the top-level directory of this
  6. * source tree or the BSD 2-Clause License provided below. You have the
  7. * option to license this software under the complete terms of either license.
  8. *
  9. * The BSD 2-Clause License:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * 1. Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * 2. Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. #include <linux/debugfs.h>
  34. #include <linux/module.h>
  35. #include <linux/rtnetlink.h>
  36. #include "nfp_net.h"
  37. static struct dentry *nfp_dir;
  38. static int nfp_net_debugfs_rx_q_read(struct seq_file *file, void *data)
  39. {
  40. int fl_rd_p, fl_wr_p, rx_rd_p, rx_wr_p, rxd_cnt;
  41. struct nfp_net_r_vector *r_vec = file->private;
  42. struct nfp_net_rx_ring *rx_ring;
  43. struct nfp_net_rx_desc *rxd;
  44. struct sk_buff *skb;
  45. struct nfp_net *nn;
  46. int i;
  47. rtnl_lock();
  48. if (!r_vec->nfp_net || !r_vec->rx_ring)
  49. goto out;
  50. nn = r_vec->nfp_net;
  51. rx_ring = r_vec->rx_ring;
  52. if (!netif_running(nn->netdev))
  53. goto out;
  54. rxd_cnt = rx_ring->cnt;
  55. fl_rd_p = nfp_qcp_rd_ptr_read(rx_ring->qcp_fl);
  56. fl_wr_p = nfp_qcp_wr_ptr_read(rx_ring->qcp_fl);
  57. rx_rd_p = nfp_qcp_rd_ptr_read(rx_ring->qcp_rx);
  58. rx_wr_p = nfp_qcp_wr_ptr_read(rx_ring->qcp_rx);
  59. seq_printf(file, "RX[%02d]: H_RD=%d H_WR=%d FL_RD=%d FL_WR=%d RX_RD=%d RX_WR=%d\n",
  60. rx_ring->idx, rx_ring->rd_p, rx_ring->wr_p,
  61. fl_rd_p, fl_wr_p, rx_rd_p, rx_wr_p);
  62. for (i = 0; i < rxd_cnt; i++) {
  63. rxd = &rx_ring->rxds[i];
  64. seq_printf(file, "%04d: 0x%08x 0x%08x", i,
  65. rxd->vals[0], rxd->vals[1]);
  66. skb = READ_ONCE(rx_ring->rxbufs[i].skb);
  67. if (skb)
  68. seq_printf(file, " skb->head=%p skb->data=%p",
  69. skb->head, skb->data);
  70. if (rx_ring->rxbufs[i].dma_addr)
  71. seq_printf(file, " dma_addr=%pad",
  72. &rx_ring->rxbufs[i].dma_addr);
  73. if (i == rx_ring->rd_p % rxd_cnt)
  74. seq_puts(file, " H_RD ");
  75. if (i == rx_ring->wr_p % rxd_cnt)
  76. seq_puts(file, " H_WR ");
  77. if (i == fl_rd_p % rxd_cnt)
  78. seq_puts(file, " FL_RD");
  79. if (i == fl_wr_p % rxd_cnt)
  80. seq_puts(file, " FL_WR");
  81. if (i == rx_rd_p % rxd_cnt)
  82. seq_puts(file, " RX_RD");
  83. if (i == rx_wr_p % rxd_cnt)
  84. seq_puts(file, " RX_WR");
  85. seq_putc(file, '\n');
  86. }
  87. out:
  88. rtnl_unlock();
  89. return 0;
  90. }
  91. static int nfp_net_debugfs_rx_q_open(struct inode *inode, struct file *f)
  92. {
  93. return single_open(f, nfp_net_debugfs_rx_q_read, inode->i_private);
  94. }
  95. static const struct file_operations nfp_rx_q_fops = {
  96. .owner = THIS_MODULE,
  97. .open = nfp_net_debugfs_rx_q_open,
  98. .release = single_release,
  99. .read = seq_read,
  100. .llseek = seq_lseek
  101. };
  102. static int nfp_net_debugfs_tx_q_read(struct seq_file *file, void *data)
  103. {
  104. struct nfp_net_r_vector *r_vec = file->private;
  105. struct nfp_net_tx_ring *tx_ring;
  106. struct nfp_net_tx_desc *txd;
  107. int d_rd_p, d_wr_p, txd_cnt;
  108. struct sk_buff *skb;
  109. struct nfp_net *nn;
  110. int i;
  111. rtnl_lock();
  112. if (!r_vec->nfp_net || !r_vec->tx_ring)
  113. goto out;
  114. nn = r_vec->nfp_net;
  115. tx_ring = r_vec->tx_ring;
  116. if (!netif_running(nn->netdev))
  117. goto out;
  118. txd_cnt = tx_ring->cnt;
  119. d_rd_p = nfp_qcp_rd_ptr_read(tx_ring->qcp_q);
  120. d_wr_p = nfp_qcp_wr_ptr_read(tx_ring->qcp_q);
  121. seq_printf(file, "TX[%02d]: H_RD=%d H_WR=%d D_RD=%d D_WR=%d\n",
  122. tx_ring->idx, tx_ring->rd_p, tx_ring->wr_p, d_rd_p, d_wr_p);
  123. for (i = 0; i < txd_cnt; i++) {
  124. txd = &tx_ring->txds[i];
  125. seq_printf(file, "%04d: 0x%08x 0x%08x 0x%08x 0x%08x", i,
  126. txd->vals[0], txd->vals[1],
  127. txd->vals[2], txd->vals[3]);
  128. skb = READ_ONCE(tx_ring->txbufs[i].skb);
  129. if (skb)
  130. seq_printf(file, " skb->head=%p skb->data=%p",
  131. skb->head, skb->data);
  132. if (tx_ring->txbufs[i].dma_addr)
  133. seq_printf(file, " dma_addr=%pad",
  134. &tx_ring->txbufs[i].dma_addr);
  135. if (i == tx_ring->rd_p % txd_cnt)
  136. seq_puts(file, " H_RD");
  137. if (i == tx_ring->wr_p % txd_cnt)
  138. seq_puts(file, " H_WR");
  139. if (i == d_rd_p % txd_cnt)
  140. seq_puts(file, " D_RD");
  141. if (i == d_wr_p % txd_cnt)
  142. seq_puts(file, " D_WR");
  143. seq_putc(file, '\n');
  144. }
  145. out:
  146. rtnl_unlock();
  147. return 0;
  148. }
  149. static int nfp_net_debugfs_tx_q_open(struct inode *inode, struct file *f)
  150. {
  151. return single_open(f, nfp_net_debugfs_tx_q_read, inode->i_private);
  152. }
  153. static const struct file_operations nfp_tx_q_fops = {
  154. .owner = THIS_MODULE,
  155. .open = nfp_net_debugfs_tx_q_open,
  156. .release = single_release,
  157. .read = seq_read,
  158. .llseek = seq_lseek
  159. };
  160. void nfp_net_debugfs_adapter_add(struct nfp_net *nn)
  161. {
  162. struct dentry *queues, *tx, *rx;
  163. char int_name[16];
  164. int i;
  165. if (IS_ERR_OR_NULL(nfp_dir))
  166. return;
  167. nn->debugfs_dir = debugfs_create_dir(pci_name(nn->pdev), nfp_dir);
  168. if (IS_ERR_OR_NULL(nn->debugfs_dir))
  169. return;
  170. /* Create queue debugging sub-tree */
  171. queues = debugfs_create_dir("queue", nn->debugfs_dir);
  172. if (IS_ERR_OR_NULL(queues))
  173. return;
  174. rx = debugfs_create_dir("rx", queues);
  175. tx = debugfs_create_dir("tx", queues);
  176. if (IS_ERR_OR_NULL(rx) || IS_ERR_OR_NULL(tx))
  177. return;
  178. for (i = 0; i < nn->num_rx_rings; i++) {
  179. sprintf(int_name, "%d", i);
  180. debugfs_create_file(int_name, S_IRUSR, rx,
  181. &nn->r_vecs[i], &nfp_rx_q_fops);
  182. }
  183. for (i = 0; i < nn->num_tx_rings; i++) {
  184. sprintf(int_name, "%d", i);
  185. debugfs_create_file(int_name, S_IRUSR, tx,
  186. &nn->r_vecs[i], &nfp_tx_q_fops);
  187. }
  188. }
  189. void nfp_net_debugfs_adapter_del(struct nfp_net *nn)
  190. {
  191. debugfs_remove_recursive(nn->debugfs_dir);
  192. nn->debugfs_dir = NULL;
  193. }
  194. void nfp_net_debugfs_create(void)
  195. {
  196. nfp_dir = debugfs_create_dir("nfp_net", NULL);
  197. }
  198. void nfp_net_debugfs_destroy(void)
  199. {
  200. debugfs_remove_recursive(nfp_dir);
  201. nfp_dir = NULL;
  202. }