1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 /* Copyright (C) 2015-2018 Netronome Systems, Inc. */ 3 #include <linux/debugfs.h> 4 #include <linux/module.h> 5 #include <linux/rtnetlink.h> 6 7 #include "nfp_net.h" 8 9 static struct dentry *nfp_dir; 10 11 static int nfp_net_debugfs_rx_q_read(struct seq_file *file, void *data) 12 { 13 struct nfp_net_r_vector *r_vec = file->private; 14 struct nfp_net_rx_ring *rx_ring; 15 int fl_rd_p, fl_wr_p, rxd_cnt; 16 struct nfp_net_rx_desc *rxd; 17 struct nfp_net *nn; 18 void *frag; 19 int i; 20 21 rtnl_lock(); 22 23 if (!r_vec->nfp_net || !r_vec->rx_ring) 24 goto out; 25 nn = r_vec->nfp_net; 26 rx_ring = r_vec->rx_ring; 27 if (!nfp_net_running(nn)) 28 goto out; 29 30 rxd_cnt = rx_ring->cnt; 31 32 fl_rd_p = nfp_qcp_rd_ptr_read(rx_ring->qcp_fl); 33 fl_wr_p = nfp_qcp_wr_ptr_read(rx_ring->qcp_fl); 34 35 seq_printf(file, "RX[%02d,%02d]: cnt=%u dma=%pad host=%p H_RD=%u H_WR=%u FL_RD=%u FL_WR=%u\n", 36 rx_ring->idx, rx_ring->fl_qcidx, 37 rx_ring->cnt, &rx_ring->dma, rx_ring->rxds, 38 rx_ring->rd_p, rx_ring->wr_p, fl_rd_p, fl_wr_p); 39 40 for (i = 0; i < rxd_cnt; i++) { 41 rxd = &rx_ring->rxds[i]; 42 seq_printf(file, "%04d: 0x%08x 0x%08x", i, 43 rxd->vals[0], rxd->vals[1]); 44 45 frag = READ_ONCE(rx_ring->rxbufs[i].frag); 46 if (frag) 47 seq_printf(file, " frag=%p", frag); 48 49 if (rx_ring->rxbufs[i].dma_addr) 50 seq_printf(file, " dma_addr=%pad", 51 &rx_ring->rxbufs[i].dma_addr); 52 53 if (i == rx_ring->rd_p % rxd_cnt) 54 seq_puts(file, " H_RD "); 55 if (i == rx_ring->wr_p % rxd_cnt) 56 seq_puts(file, " H_WR "); 57 if (i == fl_rd_p % rxd_cnt) 58 seq_puts(file, " FL_RD"); 59 if (i == fl_wr_p % rxd_cnt) 60 seq_puts(file, " FL_WR"); 61 62 seq_putc(file, '\n'); 63 } 64 out: 65 rtnl_unlock(); 66 return 0; 67 } 68 69 static int nfp_net_debugfs_rx_q_open(struct inode *inode, struct file *f) 70 { 71 return single_open(f, nfp_net_debugfs_rx_q_read, inode->i_private); 72 } 73 74 static const struct file_operations nfp_rx_q_fops = { 75 .owner = THIS_MODULE, 76 .open = nfp_net_debugfs_rx_q_open, 77 .release = single_release, 78 .read = seq_read, 79 .llseek = seq_lseek 80 }; 81 82 static int nfp_net_debugfs_tx_q_open(struct inode *inode, struct file *f); 83 84 static const struct file_operations nfp_tx_q_fops = { 85 .owner = THIS_MODULE, 86 .open = nfp_net_debugfs_tx_q_open, 87 .release = single_release, 88 .read = seq_read, 89 .llseek = seq_lseek 90 }; 91 92 static int nfp_net_debugfs_tx_q_read(struct seq_file *file, void *data) 93 { 94 struct nfp_net_r_vector *r_vec = file->private; 95 struct nfp_net_tx_ring *tx_ring; 96 struct nfp_net_tx_desc *txd; 97 int d_rd_p, d_wr_p, txd_cnt; 98 struct nfp_net *nn; 99 int i; 100 101 rtnl_lock(); 102 103 if (debugfs_real_fops(file->file) == &nfp_tx_q_fops) 104 tx_ring = r_vec->tx_ring; 105 else 106 tx_ring = r_vec->xdp_ring; 107 if (!r_vec->nfp_net || !tx_ring) 108 goto out; 109 nn = r_vec->nfp_net; 110 if (!nfp_net_running(nn)) 111 goto out; 112 113 txd_cnt = tx_ring->cnt; 114 115 d_rd_p = nfp_qcp_rd_ptr_read(tx_ring->qcp_q); 116 d_wr_p = nfp_qcp_wr_ptr_read(tx_ring->qcp_q); 117 118 seq_printf(file, "TX[%02d,%02d%s]: cnt=%u dma=%pad host=%p H_RD=%u H_WR=%u D_RD=%u D_WR=%u\n", 119 tx_ring->idx, tx_ring->qcidx, 120 tx_ring == r_vec->tx_ring ? "" : "xdp", 121 tx_ring->cnt, &tx_ring->dma, tx_ring->txds, 122 tx_ring->rd_p, tx_ring->wr_p, d_rd_p, d_wr_p); 123 124 for (i = 0; i < txd_cnt; i++) { 125 txd = &tx_ring->txds[i]; 126 seq_printf(file, "%04d: 0x%08x 0x%08x 0x%08x 0x%08x", i, 127 txd->vals[0], txd->vals[1], 128 txd->vals[2], txd->vals[3]); 129 130 if (tx_ring == r_vec->tx_ring) { 131 struct sk_buff *skb = READ_ONCE(tx_ring->txbufs[i].skb); 132 133 if (skb) 134 seq_printf(file, " skb->head=%p skb->data=%p", 135 skb->head, skb->data); 136 } else { 137 seq_printf(file, " frag=%p", 138 READ_ONCE(tx_ring->txbufs[i].frag)); 139 } 140 141 if (tx_ring->txbufs[i].dma_addr) 142 seq_printf(file, " dma_addr=%pad", 143 &tx_ring->txbufs[i].dma_addr); 144 145 if (i == tx_ring->rd_p % txd_cnt) 146 seq_puts(file, " H_RD"); 147 if (i == tx_ring->wr_p % txd_cnt) 148 seq_puts(file, " H_WR"); 149 if (i == d_rd_p % txd_cnt) 150 seq_puts(file, " D_RD"); 151 if (i == d_wr_p % txd_cnt) 152 seq_puts(file, " D_WR"); 153 154 seq_putc(file, '\n'); 155 } 156 out: 157 rtnl_unlock(); 158 return 0; 159 } 160 161 static int nfp_net_debugfs_tx_q_open(struct inode *inode, struct file *f) 162 { 163 return single_open(f, nfp_net_debugfs_tx_q_read, inode->i_private); 164 } 165 166 static const struct file_operations nfp_xdp_q_fops = { 167 .owner = THIS_MODULE, 168 .open = nfp_net_debugfs_tx_q_open, 169 .release = single_release, 170 .read = seq_read, 171 .llseek = seq_lseek 172 }; 173 174 void nfp_net_debugfs_vnic_add(struct nfp_net *nn, struct dentry *ddir) 175 { 176 struct dentry *queues, *tx, *rx, *xdp; 177 char name[20]; 178 int i; 179 180 if (IS_ERR_OR_NULL(nfp_dir)) 181 return; 182 183 if (nfp_net_is_data_vnic(nn)) 184 sprintf(name, "vnic%d", nn->id); 185 else 186 strcpy(name, "ctrl-vnic"); 187 nn->debugfs_dir = debugfs_create_dir(name, ddir); 188 if (IS_ERR_OR_NULL(nn->debugfs_dir)) 189 return; 190 191 /* Create queue debugging sub-tree */ 192 queues = debugfs_create_dir("queue", nn->debugfs_dir); 193 if (IS_ERR_OR_NULL(queues)) 194 return; 195 196 rx = debugfs_create_dir("rx", queues); 197 tx = debugfs_create_dir("tx", queues); 198 xdp = debugfs_create_dir("xdp", queues); 199 if (IS_ERR_OR_NULL(rx) || IS_ERR_OR_NULL(tx) || IS_ERR_OR_NULL(xdp)) 200 return; 201 202 for (i = 0; i < min(nn->max_rx_rings, nn->max_r_vecs); i++) { 203 sprintf(name, "%d", i); 204 debugfs_create_file(name, 0400, rx, 205 &nn->r_vecs[i], &nfp_rx_q_fops); 206 debugfs_create_file(name, 0400, xdp, 207 &nn->r_vecs[i], &nfp_xdp_q_fops); 208 } 209 210 for (i = 0; i < min(nn->max_tx_rings, nn->max_r_vecs); i++) { 211 sprintf(name, "%d", i); 212 debugfs_create_file(name, 0400, tx, 213 &nn->r_vecs[i], &nfp_tx_q_fops); 214 } 215 } 216 217 struct dentry *nfp_net_debugfs_device_add(struct pci_dev *pdev) 218 { 219 struct dentry *dev_dir; 220 221 if (IS_ERR_OR_NULL(nfp_dir)) 222 return NULL; 223 224 dev_dir = debugfs_create_dir(pci_name(pdev), nfp_dir); 225 if (IS_ERR_OR_NULL(dev_dir)) 226 return NULL; 227 228 return dev_dir; 229 } 230 231 void nfp_net_debugfs_dir_clean(struct dentry **dir) 232 { 233 debugfs_remove_recursive(*dir); 234 *dir = NULL; 235 } 236 237 void nfp_net_debugfs_create(void) 238 { 239 nfp_dir = debugfs_create_dir("nfp_net", NULL); 240 } 241 242 void nfp_net_debugfs_destroy(void) 243 { 244 debugfs_remove_recursive(nfp_dir); 245 nfp_dir = NULL; 246 } 247