nfp_net_debugfs.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 nfp_net *nn;
  45. void *frag;
  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. frag = READ_ONCE(rx_ring->rxbufs[i].frag);
  67. if (frag)
  68. seq_printf(file, " frag=%p", frag);
  69. if (rx_ring->rxbufs[i].dma_addr)
  70. seq_printf(file, " dma_addr=%pad",
  71. &rx_ring->rxbufs[i].dma_addr);
  72. if (i == rx_ring->rd_p % rxd_cnt)
  73. seq_puts(file, " H_RD ");
  74. if (i == rx_ring->wr_p % rxd_cnt)
  75. seq_puts(file, " H_WR ");
  76. if (i == fl_rd_p % rxd_cnt)
  77. seq_puts(file, " FL_RD");
  78. if (i == fl_wr_p % rxd_cnt)
  79. seq_puts(file, " FL_WR");
  80. if (i == rx_rd_p % rxd_cnt)
  81. seq_puts(file, " RX_RD");
  82. if (i == rx_wr_p % rxd_cnt)
  83. seq_puts(file, " RX_WR");
  84. seq_putc(file, '\n');
  85. }
  86. out:
  87. rtnl_unlock();
  88. return 0;
  89. }
  90. static int nfp_net_debugfs_rx_q_open(struct inode *inode, struct file *f)
  91. {
  92. return single_open(f, nfp_net_debugfs_rx_q_read, inode->i_private);
  93. }
  94. static const struct file_operations nfp_rx_q_fops = {
  95. .owner = THIS_MODULE,
  96. .open = nfp_net_debugfs_rx_q_open,
  97. .release = single_release,
  98. .read = seq_read,
  99. .llseek = seq_lseek
  100. };
  101. static int nfp_net_debugfs_tx_q_open(struct inode *inode, struct file *f);
  102. static const struct file_operations nfp_tx_q_fops = {
  103. .owner = THIS_MODULE,
  104. .open = nfp_net_debugfs_tx_q_open,
  105. .release = single_release,
  106. .read = seq_read,
  107. .llseek = seq_lseek
  108. };
  109. static int nfp_net_debugfs_tx_q_read(struct seq_file *file, void *data)
  110. {
  111. struct nfp_net_r_vector *r_vec = file->private;
  112. struct nfp_net_tx_ring *tx_ring;
  113. struct nfp_net_tx_desc *txd;
  114. int d_rd_p, d_wr_p, txd_cnt;
  115. struct sk_buff *skb;
  116. struct nfp_net *nn;
  117. int i;
  118. rtnl_lock();
  119. if (debugfs_real_fops(file->file) == &nfp_tx_q_fops)
  120. tx_ring = r_vec->tx_ring;
  121. else
  122. tx_ring = r_vec->xdp_ring;
  123. if (!r_vec->nfp_net || !tx_ring)
  124. goto out;
  125. nn = r_vec->nfp_net;
  126. if (!netif_running(nn->netdev))
  127. goto out;
  128. txd_cnt = tx_ring->cnt;
  129. d_rd_p = nfp_qcp_rd_ptr_read(tx_ring->qcp_q);
  130. d_wr_p = nfp_qcp_wr_ptr_read(tx_ring->qcp_q);
  131. seq_printf(file, "TX[%02d]: H_RD=%d H_WR=%d D_RD=%d D_WR=%d\n",
  132. tx_ring->idx, tx_ring->rd_p, tx_ring->wr_p, d_rd_p, d_wr_p);
  133. for (i = 0; i < txd_cnt; i++) {
  134. txd = &tx_ring->txds[i];
  135. seq_printf(file, "%04d: 0x%08x 0x%08x 0x%08x 0x%08x", i,
  136. txd->vals[0], txd->vals[1],
  137. txd->vals[2], txd->vals[3]);
  138. skb = READ_ONCE(tx_ring->txbufs[i].skb);
  139. if (skb) {
  140. if (tx_ring == r_vec->tx_ring)
  141. seq_printf(file, " skb->head=%p skb->data=%p",
  142. skb->head, skb->data);
  143. else
  144. seq_printf(file, " frag=%p", skb);
  145. }
  146. if (tx_ring->txbufs[i].dma_addr)
  147. seq_printf(file, " dma_addr=%pad",
  148. &tx_ring->txbufs[i].dma_addr);
  149. if (i == tx_ring->rd_p % txd_cnt)
  150. seq_puts(file, " H_RD");
  151. if (i == tx_ring->wr_p % txd_cnt)
  152. seq_puts(file, " H_WR");
  153. if (i == d_rd_p % txd_cnt)
  154. seq_puts(file, " D_RD");
  155. if (i == d_wr_p % txd_cnt)
  156. seq_puts(file, " D_WR");
  157. seq_putc(file, '\n');
  158. }
  159. out:
  160. rtnl_unlock();
  161. return 0;
  162. }
  163. static int nfp_net_debugfs_tx_q_open(struct inode *inode, struct file *f)
  164. {
  165. return single_open(f, nfp_net_debugfs_tx_q_read, inode->i_private);
  166. }
  167. static const struct file_operations nfp_xdp_q_fops = {
  168. .owner = THIS_MODULE,
  169. .open = nfp_net_debugfs_tx_q_open,
  170. .release = single_release,
  171. .read = seq_read,
  172. .llseek = seq_lseek
  173. };
  174. void nfp_net_debugfs_adapter_add(struct nfp_net *nn)
  175. {
  176. struct dentry *queues, *tx, *rx, *xdp;
  177. char int_name[16];
  178. int i;
  179. if (IS_ERR_OR_NULL(nfp_dir))
  180. return;
  181. nn->debugfs_dir = debugfs_create_dir(pci_name(nn->pdev), nfp_dir);
  182. if (IS_ERR_OR_NULL(nn->debugfs_dir))
  183. return;
  184. /* Create queue debugging sub-tree */
  185. queues = debugfs_create_dir("queue", nn->debugfs_dir);
  186. if (IS_ERR_OR_NULL(queues))
  187. return;
  188. rx = debugfs_create_dir("rx", queues);
  189. tx = debugfs_create_dir("tx", queues);
  190. xdp = debugfs_create_dir("xdp", queues);
  191. if (IS_ERR_OR_NULL(rx) || IS_ERR_OR_NULL(tx) || IS_ERR_OR_NULL(xdp))
  192. return;
  193. for (i = 0; i < min(nn->max_rx_rings, nn->max_r_vecs); i++) {
  194. sprintf(int_name, "%d", i);
  195. debugfs_create_file(int_name, S_IRUSR, rx,
  196. &nn->r_vecs[i], &nfp_rx_q_fops);
  197. debugfs_create_file(int_name, S_IRUSR, xdp,
  198. &nn->r_vecs[i], &nfp_xdp_q_fops);
  199. }
  200. for (i = 0; i < min(nn->max_tx_rings, nn->max_r_vecs); i++) {
  201. sprintf(int_name, "%d", i);
  202. debugfs_create_file(int_name, S_IRUSR, tx,
  203. &nn->r_vecs[i], &nfp_tx_q_fops);
  204. }
  205. }
  206. void nfp_net_debugfs_adapter_del(struct nfp_net *nn)
  207. {
  208. debugfs_remove_recursive(nn->debugfs_dir);
  209. nn->debugfs_dir = NULL;
  210. }
  211. void nfp_net_debugfs_create(void)
  212. {
  213. nfp_dir = debugfs_create_dir("nfp_net", NULL);
  214. }
  215. void nfp_net_debugfs_destroy(void)
  216. {
  217. debugfs_remove_recursive(nfp_dir);
  218. nfp_dir = NULL;
  219. }