static int nfp_net_debugfs_rx_q_read(struct seq_file *file, void *data) { struct nfp_net_r_vector *r_vec = file->private; struct nfp_net_rx_ring *rx_ring; int fl_rd_p, fl_wr_p, rxd_cnt; struct nfp_net_rx_desc *rxd; struct nfp_net *nn; void *frag; int i; rtnl_lock(); if (!r_vec->nfp_net || !r_vec->rx_ring) goto out; nn = r_vec->nfp_net; rx_ring = r_vec->rx_ring; if (!netif_running(nn->dp.netdev)) goto out; rxd_cnt = rx_ring->cnt; fl_rd_p = nfp_qcp_rd_ptr_read(rx_ring->qcp_fl); fl_wr_p = nfp_qcp_wr_ptr_read(rx_ring->qcp_fl); seq_printf(file, "RX[%02d,%02d]: cnt=%d dma=%pad host=%p H_RD=%d H_WR=%d FL_RD=%d FL_WR=%d\n", rx_ring->idx, rx_ring->fl_qcidx, rx_ring->cnt, &rx_ring->dma, rx_ring->rxds, rx_ring->rd_p, rx_ring->wr_p, fl_rd_p, fl_wr_p); for (i = 0; i < rxd_cnt; i++) { rxd = &rx_ring->rxds[i]; seq_printf(file, "%04d: 0x%08x 0x%08x", i, rxd->vals[0], rxd->vals[1]); frag = READ_ONCE(rx_ring->rxbufs[i].frag); if (frag) seq_printf(file, " frag=%p", frag); if (rx_ring->rxbufs[i].dma_addr) seq_printf(file, " dma_addr=%pad", &rx_ring->rxbufs[i].dma_addr); if (i == rx_ring->rd_p % rxd_cnt) seq_puts(file, " H_RD "); if (i == rx_ring->wr_p % rxd_cnt) seq_puts(file, " H_WR "); if (i == fl_rd_p % rxd_cnt) seq_puts(file, " FL_RD"); if (i == fl_wr_p % rxd_cnt) seq_puts(file, " FL_WR"); seq_putc(file, '\n'); } out: rtnl_unlock(); return 0; }
/** * nfp_net_tx_complete() - Handled completed TX packets * @tx_ring: TX ring structure * * Return: Number of completed TX descriptors */ static void nfp_net_tx_complete(struct nfp_net_tx_ring *tx_ring) { struct nfp_net_r_vector *r_vec = tx_ring->r_vec; struct nfp_net *nn = r_vec->nfp_net; const struct skb_frag_struct *frag; struct netdev_queue *nd_q; u32 done_pkts = 0, done_bytes = 0; struct sk_buff *skb; int todo, nr_frags; u32 qcp_rd_p; int fidx; int idx; /* Work out how many descriptors have been transmitted */ qcp_rd_p = nfp_qcp_rd_ptr_read(tx_ring->qcp_q); if (qcp_rd_p == tx_ring->qcp_rd_p) return; if (qcp_rd_p > tx_ring->qcp_rd_p) todo = qcp_rd_p - tx_ring->qcp_rd_p; else todo = qcp_rd_p + tx_ring->cnt - tx_ring->qcp_rd_p; while (todo--) { idx = tx_ring->rd_p % tx_ring->cnt; tx_ring->rd_p++; skb = tx_ring->txbufs[idx].skb; if (!skb) continue; nr_frags = skb_shinfo(skb)->nr_frags; fidx = tx_ring->txbufs[idx].fidx; if (fidx == -1) { /* unmap head */ dma_unmap_single(&nn->pdev->dev, tx_ring->txbufs[idx].dma_addr, skb_headlen(skb), DMA_TO_DEVICE); done_pkts += tx_ring->txbufs[idx].pkt_cnt; done_bytes += tx_ring->txbufs[idx].real_len; } else { /* unmap fragment */ frag = &skb_shinfo(skb)->frags[fidx]; dma_unmap_page(&nn->pdev->dev, tx_ring->txbufs[idx].dma_addr, skb_frag_size(frag), DMA_TO_DEVICE); } /* check for last gather fragment */ if (fidx == nr_frags - 1) dev_kfree_skb_any(skb); tx_ring->txbufs[idx].dma_addr = 0; tx_ring->txbufs[idx].skb = NULL; tx_ring->txbufs[idx].fidx = -2; } tx_ring->qcp_rd_p = qcp_rd_p; u64_stats_update_begin(&r_vec->tx_sync); r_vec->tx_bytes += done_bytes; r_vec->tx_pkts += done_pkts; u64_stats_update_end(&r_vec->tx_sync); nd_q = netdev_get_tx_queue(nn->netdev, tx_ring->idx); netdev_tx_completed_queue(nd_q, done_pkts, done_bytes); if (nfp_net_tx_ring_should_wake(tx_ring)) { /* Make sure TX thread will see updated tx_ring->rd_p */ smp_mb(); if (unlikely(netif_tx_queue_stopped(nd_q))) netif_tx_wake_queue(nd_q); } WARN_ONCE(tx_ring->wr_p - tx_ring->rd_p > tx_ring->cnt, "TX ring corruption rd_p=%u wr_p=%u cnt=%u\n", tx_ring->rd_p, tx_ring->wr_p, tx_ring->cnt); }
static int nfp_net_debugfs_tx_q_read(struct seq_file *file, void *data) { struct nfp_net_r_vector *r_vec = file->private; struct nfp_net_tx_ring *tx_ring; struct nfp_net_tx_desc *txd; int d_rd_p, d_wr_p, txd_cnt; struct sk_buff *skb; struct nfp_net *nn; int i; rtnl_lock(); if (debugfs_real_fops(file->file) == &nfp_tx_q_fops) tx_ring = r_vec->tx_ring; else tx_ring = r_vec->xdp_ring; if (!r_vec->nfp_net || !tx_ring) goto out; nn = r_vec->nfp_net; if (!netif_running(nn->dp.netdev)) goto out; txd_cnt = tx_ring->cnt; d_rd_p = nfp_qcp_rd_ptr_read(tx_ring->qcp_q); d_wr_p = nfp_qcp_wr_ptr_read(tx_ring->qcp_q); seq_printf(file, "TX[%02d,%02d%s]: cnt=%d dma=%pad host=%p H_RD=%d H_WR=%d D_RD=%d D_WR=%d\n", tx_ring->idx, tx_ring->qcidx, tx_ring == r_vec->tx_ring ? "" : "xdp", tx_ring->cnt, &tx_ring->dma, tx_ring->txds, tx_ring->rd_p, tx_ring->wr_p, d_rd_p, d_wr_p); for (i = 0; i < txd_cnt; i++) { txd = &tx_ring->txds[i]; seq_printf(file, "%04d: 0x%08x 0x%08x 0x%08x 0x%08x", i, txd->vals[0], txd->vals[1], txd->vals[2], txd->vals[3]); skb = READ_ONCE(tx_ring->txbufs[i].skb); if (skb) { if (tx_ring == r_vec->tx_ring) seq_printf(file, " skb->head=%p skb->data=%p", skb->head, skb->data); else seq_printf(file, " frag=%p", skb); } if (tx_ring->txbufs[i].dma_addr) seq_printf(file, " dma_addr=%pad", &tx_ring->txbufs[i].dma_addr); if (i == tx_ring->rd_p % txd_cnt) seq_puts(file, " H_RD"); if (i == tx_ring->wr_p % txd_cnt) seq_puts(file, " H_WR"); if (i == d_rd_p % txd_cnt) seq_puts(file, " D_RD"); if (i == d_wr_p % txd_cnt) seq_puts(file, " D_WR"); seq_putc(file, '\n'); } out: rtnl_unlock(); return 0; }