]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/net/ethernet/netronome/nfp/nfp_net_debugfs.c
nfp: use alloc_frag() and build_skb()
[mirror_ubuntu-artful-kernel.git] / drivers / net / ethernet / netronome / nfp / nfp_net_debugfs.c
CommitLineData
4c352362
JK
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
37#include "nfp_net.h"
38
39static struct dentry *nfp_dir;
40
41static int nfp_net_debugfs_rx_q_read(struct seq_file *file, void *data)
42{
4c352362 43 int fl_rd_p, fl_wr_p, rx_rd_p, rx_wr_p, rxd_cnt;
73725d9d
JK
44 struct nfp_net_r_vector *r_vec = file->private;
45 struct nfp_net_rx_ring *rx_ring;
4c352362 46 struct nfp_net_rx_desc *rxd;
4c352362 47 struct nfp_net *nn;
c0f031bc 48 void *frag;
4c352362
JK
49 int i;
50
51 rtnl_lock();
52
73725d9d 53 if (!r_vec->nfp_net || !r_vec->rx_ring)
4c352362 54 goto out;
73725d9d
JK
55 nn = r_vec->nfp_net;
56 rx_ring = r_vec->rx_ring;
4c352362
JK
57 if (!netif_running(nn->netdev))
58 goto out;
59
60 rxd_cnt = rx_ring->cnt;
61
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);
66
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);
70
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]);
75
c0f031bc
JK
76 frag = READ_ONCE(rx_ring->rxbufs[i].frag);
77 if (frag)
78 seq_printf(file, " frag=%p", frag);
4c352362
JK
79
80 if (rx_ring->rxbufs[i].dma_addr)
81 seq_printf(file, " dma_addr=%pad",
82 &rx_ring->rxbufs[i].dma_addr);
83
84 if (i == rx_ring->rd_p % rxd_cnt)
85 seq_puts(file, " H_RD ");
86 if (i == rx_ring->wr_p % rxd_cnt)
87 seq_puts(file, " H_WR ");
88 if (i == fl_rd_p % rxd_cnt)
89 seq_puts(file, " FL_RD");
90 if (i == fl_wr_p % rxd_cnt)
91 seq_puts(file, " FL_WR");
92 if (i == rx_rd_p % rxd_cnt)
93 seq_puts(file, " RX_RD");
94 if (i == rx_wr_p % rxd_cnt)
95 seq_puts(file, " RX_WR");
96
97 seq_putc(file, '\n');
98 }
99out:
100 rtnl_unlock();
101 return 0;
102}
103
104static int nfp_net_debugfs_rx_q_open(struct inode *inode, struct file *f)
105{
106 return single_open(f, nfp_net_debugfs_rx_q_read, inode->i_private);
107}
108
109static const struct file_operations nfp_rx_q_fops = {
110 .owner = THIS_MODULE,
111 .open = nfp_net_debugfs_rx_q_open,
112 .release = single_release,
113 .read = seq_read,
114 .llseek = seq_lseek
115};
116
117static int nfp_net_debugfs_tx_q_read(struct seq_file *file, void *data)
118{
73725d9d
JK
119 struct nfp_net_r_vector *r_vec = file->private;
120 struct nfp_net_tx_ring *tx_ring;
4c352362
JK
121 struct nfp_net_tx_desc *txd;
122 int d_rd_p, d_wr_p, txd_cnt;
123 struct sk_buff *skb;
124 struct nfp_net *nn;
125 int i;
126
127 rtnl_lock();
128
73725d9d 129 if (!r_vec->nfp_net || !r_vec->tx_ring)
4c352362 130 goto out;
73725d9d
JK
131 nn = r_vec->nfp_net;
132 tx_ring = r_vec->tx_ring;
4c352362
JK
133 if (!netif_running(nn->netdev))
134 goto out;
135
136 txd_cnt = tx_ring->cnt;
137
138 d_rd_p = nfp_qcp_rd_ptr_read(tx_ring->qcp_q);
139 d_wr_p = nfp_qcp_wr_ptr_read(tx_ring->qcp_q);
140
141 seq_printf(file, "TX[%02d]: H_RD=%d H_WR=%d D_RD=%d D_WR=%d\n",
142 tx_ring->idx, tx_ring->rd_p, tx_ring->wr_p, d_rd_p, d_wr_p);
143
144 for (i = 0; i < txd_cnt; i++) {
145 txd = &tx_ring->txds[i];
146 seq_printf(file, "%04d: 0x%08x 0x%08x 0x%08x 0x%08x", i,
147 txd->vals[0], txd->vals[1],
148 txd->vals[2], txd->vals[3]);
149
150 skb = READ_ONCE(tx_ring->txbufs[i].skb);
151 if (skb)
152 seq_printf(file, " skb->head=%p skb->data=%p",
153 skb->head, skb->data);
154 if (tx_ring->txbufs[i].dma_addr)
155 seq_printf(file, " dma_addr=%pad",
156 &tx_ring->txbufs[i].dma_addr);
157
158 if (i == tx_ring->rd_p % txd_cnt)
159 seq_puts(file, " H_RD");
160 if (i == tx_ring->wr_p % txd_cnt)
161 seq_puts(file, " H_WR");
162 if (i == d_rd_p % txd_cnt)
163 seq_puts(file, " D_RD");
164 if (i == d_wr_p % txd_cnt)
165 seq_puts(file, " D_WR");
166
167 seq_putc(file, '\n');
168 }
169out:
170 rtnl_unlock();
171 return 0;
172}
173
174static int nfp_net_debugfs_tx_q_open(struct inode *inode, struct file *f)
175{
176 return single_open(f, nfp_net_debugfs_tx_q_read, inode->i_private);
177}
178
179static const struct file_operations nfp_tx_q_fops = {
180 .owner = THIS_MODULE,
181 .open = nfp_net_debugfs_tx_q_open,
182 .release = single_release,
183 .read = seq_read,
184 .llseek = seq_lseek
185};
186
187void nfp_net_debugfs_adapter_add(struct nfp_net *nn)
188{
c160692e 189 struct dentry *queues, *tx, *rx;
4c352362
JK
190 char int_name[16];
191 int i;
192
193 if (IS_ERR_OR_NULL(nfp_dir))
194 return;
195
196 nn->debugfs_dir = debugfs_create_dir(pci_name(nn->pdev), nfp_dir);
197 if (IS_ERR_OR_NULL(nn->debugfs_dir))
198 return;
199
200 /* Create queue debugging sub-tree */
201 queues = debugfs_create_dir("queue", nn->debugfs_dir);
5b161096 202 if (IS_ERR_OR_NULL(queues))
4c352362
JK
203 return;
204
205 rx = debugfs_create_dir("rx", queues);
206 tx = debugfs_create_dir("tx", queues);
207 if (IS_ERR_OR_NULL(rx) || IS_ERR_OR_NULL(tx))
208 return;
209
210 for (i = 0; i < nn->num_rx_rings; i++) {
211 sprintf(int_name, "%d", i);
212 debugfs_create_file(int_name, S_IRUSR, rx,
73725d9d 213 &nn->r_vecs[i], &nfp_rx_q_fops);
4c352362
JK
214 }
215
216 for (i = 0; i < nn->num_tx_rings; i++) {
217 sprintf(int_name, "%d", i);
218 debugfs_create_file(int_name, S_IRUSR, tx,
73725d9d 219 &nn->r_vecs[i], &nfp_tx_q_fops);
4c352362
JK
220 }
221}
222
223void nfp_net_debugfs_adapter_del(struct nfp_net *nn)
224{
225 debugfs_remove_recursive(nn->debugfs_dir);
226 nn->debugfs_dir = NULL;
227}
228
229void nfp_net_debugfs_create(void)
230{
231 nfp_dir = debugfs_create_dir("nfp_net", NULL);
232}
233
234void nfp_net_debugfs_destroy(void)
235{
236 debugfs_remove_recursive(nfp_dir);
237 nfp_dir = NULL;
238}