2 * Copyright (C) 2015 Netronome Systems, Inc.
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.
9 * The BSD 2-Clause License:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * 1. Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
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.
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
33 #include <linux/debugfs.h>
34 #include <linux/module.h>
35 #include <linux/rtnetlink.h>
39 static struct dentry *nfp_dir;
41 static int nfp_net_debugfs_rx_q_read(struct seq_file *file, void *data)
43 int fl_rd_p, fl_wr_p, rx_rd_p, rx_wr_p, rxd_cnt;
44 struct nfp_net_r_vector *r_vec = file->private;
45 struct nfp_net_rx_ring *rx_ring;
46 struct nfp_net_rx_desc *rxd;
53 if (!r_vec->nfp_net || !r_vec->rx_ring)
56 rx_ring = r_vec->rx_ring;
57 if (!netif_running(nn->netdev))
60 rxd_cnt = rx_ring->cnt;
62 fl_rd_p = nfp_qcp_rd_ptr_read(rx_ring->qcp_fl);
63 fl_wr_p = nfp_qcp_wr_ptr_read(rx_ring->qcp_fl);
64 rx_rd_p = nfp_qcp_rd_ptr_read(rx_ring->qcp_rx);
65 rx_wr_p = nfp_qcp_wr_ptr_read(rx_ring->qcp_rx);
67 seq_printf(file, "RX[%02d]: H_RD=%d H_WR=%d FL_RD=%d FL_WR=%d RX_RD=%d RX_WR=%d\n",
68 rx_ring->idx, rx_ring->rd_p, rx_ring->wr_p,
69 fl_rd_p, fl_wr_p, rx_rd_p, rx_wr_p);
71 for (i = 0; i < rxd_cnt; i++) {
72 rxd = &rx_ring->rxds[i];
73 seq_printf(file, "%04d: 0x%08x 0x%08x", i,
74 rxd->vals[0], rxd->vals[1]);
76 skb = READ_ONCE(rx_ring->rxbufs[i].skb);
78 seq_printf(file, " skb->head=%p skb->data=%p",
79 skb->head, skb->data);
81 if (rx_ring->rxbufs[i].dma_addr)
82 seq_printf(file, " dma_addr=%pad",
83 &rx_ring->rxbufs[i].dma_addr);
85 if (i == rx_ring->rd_p % rxd_cnt)
86 seq_puts(file, " H_RD ");
87 if (i == rx_ring->wr_p % rxd_cnt)
88 seq_puts(file, " H_WR ");
89 if (i == fl_rd_p % rxd_cnt)
90 seq_puts(file, " FL_RD");
91 if (i == fl_wr_p % rxd_cnt)
92 seq_puts(file, " FL_WR");
93 if (i == rx_rd_p % rxd_cnt)
94 seq_puts(file, " RX_RD");
95 if (i == rx_wr_p % rxd_cnt)
96 seq_puts(file, " RX_WR");
105 static int nfp_net_debugfs_rx_q_open(struct inode *inode, struct file *f)
107 return single_open(f, nfp_net_debugfs_rx_q_read, inode->i_private);
110 static const struct file_operations nfp_rx_q_fops = {
111 .owner = THIS_MODULE,
112 .open = nfp_net_debugfs_rx_q_open,
113 .release = single_release,
118 static int nfp_net_debugfs_tx_q_read(struct seq_file *file, void *data)
120 struct nfp_net_r_vector *r_vec = file->private;
121 struct nfp_net_tx_ring *tx_ring;
122 struct nfp_net_tx_desc *txd;
123 int d_rd_p, d_wr_p, txd_cnt;
130 if (!r_vec->nfp_net || !r_vec->tx_ring)
133 tx_ring = r_vec->tx_ring;
134 if (!netif_running(nn->netdev))
137 txd_cnt = tx_ring->cnt;
139 d_rd_p = nfp_qcp_rd_ptr_read(tx_ring->qcp_q);
140 d_wr_p = nfp_qcp_wr_ptr_read(tx_ring->qcp_q);
142 seq_printf(file, "TX[%02d]: H_RD=%d H_WR=%d D_RD=%d D_WR=%d\n",
143 tx_ring->idx, tx_ring->rd_p, tx_ring->wr_p, d_rd_p, d_wr_p);
145 for (i = 0; i < txd_cnt; i++) {
146 txd = &tx_ring->txds[i];
147 seq_printf(file, "%04d: 0x%08x 0x%08x 0x%08x 0x%08x", i,
148 txd->vals[0], txd->vals[1],
149 txd->vals[2], txd->vals[3]);
151 skb = READ_ONCE(tx_ring->txbufs[i].skb);
153 seq_printf(file, " skb->head=%p skb->data=%p",
154 skb->head, skb->data);
155 if (tx_ring->txbufs[i].dma_addr)
156 seq_printf(file, " dma_addr=%pad",
157 &tx_ring->txbufs[i].dma_addr);
159 if (i == tx_ring->rd_p % txd_cnt)
160 seq_puts(file, " H_RD");
161 if (i == tx_ring->wr_p % txd_cnt)
162 seq_puts(file, " H_WR");
163 if (i == d_rd_p % txd_cnt)
164 seq_puts(file, " D_RD");
165 if (i == d_wr_p % txd_cnt)
166 seq_puts(file, " D_WR");
168 seq_putc(file, '\n');
175 static int nfp_net_debugfs_tx_q_open(struct inode *inode, struct file *f)
177 return single_open(f, nfp_net_debugfs_tx_q_read, inode->i_private);
180 static const struct file_operations nfp_tx_q_fops = {
181 .owner = THIS_MODULE,
182 .open = nfp_net_debugfs_tx_q_open,
183 .release = single_release,
188 void nfp_net_debugfs_adapter_add(struct nfp_net *nn)
190 struct dentry *queues, *tx, *rx;
194 if (IS_ERR_OR_NULL(nfp_dir))
197 nn->debugfs_dir = debugfs_create_dir(pci_name(nn->pdev), nfp_dir);
198 if (IS_ERR_OR_NULL(nn->debugfs_dir))
201 /* Create queue debugging sub-tree */
202 queues = debugfs_create_dir("queue", nn->debugfs_dir);
203 if (IS_ERR_OR_NULL(queues))
206 rx = debugfs_create_dir("rx", queues);
207 tx = debugfs_create_dir("tx", queues);
208 if (IS_ERR_OR_NULL(rx) || IS_ERR_OR_NULL(tx))
211 for (i = 0; i < nn->num_rx_rings; i++) {
212 sprintf(int_name, "%d", i);
213 debugfs_create_file(int_name, S_IRUSR, rx,
214 &nn->r_vecs[i], &nfp_rx_q_fops);
217 for (i = 0; i < nn->num_tx_rings; i++) {
218 sprintf(int_name, "%d", i);
219 debugfs_create_file(int_name, S_IRUSR, tx,
220 &nn->r_vecs[i], &nfp_tx_q_fops);
224 void nfp_net_debugfs_adapter_del(struct nfp_net *nn)
226 debugfs_remove_recursive(nn->debugfs_dir);
227 nn->debugfs_dir = NULL;
230 void nfp_net_debugfs_create(void)
232 nfp_dir = debugfs_create_dir("nfp_net", NULL);
235 void nfp_net_debugfs_destroy(void)
237 debugfs_remove_recursive(nfp_dir);