1 From b16fe6d82b71fa0dd5c957bc22d66a694976d6eb Mon Sep 17 00:00:00 2001
2 From: Lorenzo Bianconi <lorenzo@kernel.org>
3 Date: Wed, 27 Jul 2022 23:20:50 +0200
4 Subject: [PATCH] net: ethernet: mtk_eth_soc: introduce mtk_xdp_frame_map
7 This is a preliminary patch to add xdp multi-frag support to mtk_eth_soc
10 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
11 Signed-off-by: David S. Miller <davem@davemloft.net>
13 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 68 +++++++++++++--------
14 1 file changed, 42 insertions(+), 26 deletions(-)
16 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
17 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
18 @@ -1480,6 +1480,41 @@ static void mtk_rx_put_buff(struct mtk_r
22 +static int mtk_xdp_frame_map(struct mtk_eth *eth, struct net_device *dev,
23 + struct mtk_tx_dma_desc_info *txd_info,
24 + struct mtk_tx_dma *txd, struct mtk_tx_buf *tx_buf,
25 + void *data, u16 headroom, int index, bool dma_map)
27 + struct mtk_tx_ring *ring = ð->tx_ring;
28 + struct mtk_mac *mac = netdev_priv(dev);
29 + struct mtk_tx_dma *txd_pdma;
31 + if (dma_map) { /* ndo_xdp_xmit */
32 + txd_info->addr = dma_map_single(eth->dma_dev, data,
33 + txd_info->size, DMA_TO_DEVICE);
34 + if (unlikely(dma_mapping_error(eth->dma_dev, txd_info->addr)))
37 + tx_buf->flags |= MTK_TX_FLAGS_SINGLE0;
39 + struct page *page = virt_to_head_page(data);
41 + txd_info->addr = page_pool_get_dma_addr(page) +
42 + sizeof(struct xdp_frame) + headroom;
43 + dma_sync_single_for_device(eth->dma_dev, txd_info->addr,
44 + txd_info->size, DMA_BIDIRECTIONAL);
46 + mtk_tx_set_dma_desc(dev, txd, txd_info);
48 + tx_buf->flags |= !mac->id ? MTK_TX_FLAGS_FPORT0 : MTK_TX_FLAGS_FPORT1;
50 + txd_pdma = qdma_to_pdma(ring, txd);
51 + setup_tx_buf(eth, tx_buf, txd_pdma, txd_info->addr, txd_info->size,
57 static int mtk_xdp_submit_frame(struct mtk_eth *eth, struct xdp_frame *xdpf,
58 struct net_device *dev, bool dma_map)
60 @@ -1490,9 +1525,8 @@ static int mtk_xdp_submit_frame(struct m
64 - struct mtk_mac *mac = netdev_priv(dev);
65 - struct mtk_tx_dma *txd, *txd_pdma;
66 int err = 0, index = 0, n_desc = 1;
67 + struct mtk_tx_dma *txd, *txd_pdma;
68 struct mtk_tx_buf *tx_buf;
70 if (unlikely(test_bit(MTK_RESETTING, ð->state)))
71 @@ -1512,36 +1546,18 @@ static int mtk_xdp_submit_frame(struct m
72 tx_buf = mtk_desc_to_tx_buf(ring, txd, soc->txrx.txd_size);
73 memset(tx_buf, 0, sizeof(*tx_buf));
75 - if (dma_map) { /* ndo_xdp_xmit */
76 - txd_info.addr = dma_map_single(eth->dma_dev, xdpf->data,
77 - txd_info.size, DMA_TO_DEVICE);
78 - if (unlikely(dma_mapping_error(eth->dma_dev, txd_info.addr))) {
82 - tx_buf->flags |= MTK_TX_FLAGS_SINGLE0;
84 - struct page *page = virt_to_head_page(xdpf->data);
86 - txd_info.addr = page_pool_get_dma_addr(page) +
87 - sizeof(*xdpf) + xdpf->headroom;
88 - dma_sync_single_for_device(eth->dma_dev, txd_info.addr,
92 - mtk_tx_set_dma_desc(dev, txd, &txd_info);
94 - tx_buf->flags |= !mac->id ? MTK_TX_FLAGS_FPORT0 : MTK_TX_FLAGS_FPORT1;
96 - txd_pdma = qdma_to_pdma(ring, txd);
97 - setup_tx_buf(eth, tx_buf, txd_pdma, txd_info.addr, txd_info.size,
99 + err = mtk_xdp_frame_map(eth, dev, &txd_info, txd, tx_buf,
100 + xdpf->data, xdpf->headroom, index,
105 /* store xdpf for cleanup */
106 tx_buf->type = dma_map ? MTK_TYPE_XDP_NDO : MTK_TYPE_XDP_TX;
109 if (!MTK_HAS_CAPS(soc->caps, MTK_QDMA)) {
110 + txd_pdma = qdma_to_pdma(ring, txd);
112 txd_pdma->txd2 |= TX_DMA_LS0;