33a76166521af7cab1a38fbfd76324cd26a5dd8f
[openwrt/staging/ansuel.git] /
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
5 utility routine
6
7 This is a preliminary patch to add xdp multi-frag support to mtk_eth_soc
8 driver
9
10 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
11 Signed-off-by: David S. Miller <davem@davemloft.net>
12 ---
13 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 68 +++++++++++++--------
14 1 file changed, 42 insertions(+), 26 deletions(-)
15
16 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
17 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
18 @@ -1479,6 +1479,41 @@ static void mtk_rx_put_buff(struct mtk_r
19 skb_free_frag(data);
20 }
21
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)
26 +{
27 + struct mtk_tx_ring *ring = &eth->tx_ring;
28 + struct mtk_mac *mac = netdev_priv(dev);
29 + struct mtk_tx_dma *txd_pdma;
30 +
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)))
35 + return -ENOMEM;
36 +
37 + tx_buf->flags |= MTK_TX_FLAGS_SINGLE0;
38 + } else {
39 + struct page *page = virt_to_head_page(data);
40 +
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);
45 + }
46 + mtk_tx_set_dma_desc(dev, txd, txd_info);
47 +
48 + tx_buf->flags |= !mac->id ? MTK_TX_FLAGS_FPORT0 : MTK_TX_FLAGS_FPORT1;
49 +
50 + txd_pdma = qdma_to_pdma(ring, txd);
51 + setup_tx_buf(eth, tx_buf, txd_pdma, txd_info->addr, txd_info->size,
52 + index);
53 +
54 + return 0;
55 +}
56 +
57 static int mtk_xdp_submit_frame(struct mtk_eth *eth, struct xdp_frame *xdpf,
58 struct net_device *dev, bool dma_map)
59 {
60 @@ -1489,9 +1524,8 @@ static int mtk_xdp_submit_frame(struct m
61 .first = true,
62 .last = true,
63 };
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;
69
70 if (unlikely(test_bit(MTK_RESETTING, &eth->state)))
71 @@ -1511,36 +1545,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));
74
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))) {
79 - err = -ENOMEM;
80 - goto out;
81 - }
82 - tx_buf->flags |= MTK_TX_FLAGS_SINGLE0;
83 - } else {
84 - struct page *page = virt_to_head_page(xdpf->data);
85 -
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,
89 - txd_info.size,
90 - DMA_BIDIRECTIONAL);
91 - }
92 - mtk_tx_set_dma_desc(dev, txd, &txd_info);
93 -
94 - tx_buf->flags |= !mac->id ? MTK_TX_FLAGS_FPORT0 : MTK_TX_FLAGS_FPORT1;
95 -
96 - txd_pdma = qdma_to_pdma(ring, txd);
97 - setup_tx_buf(eth, tx_buf, txd_pdma, txd_info.addr, txd_info.size,
98 - index++);
99 + err = mtk_xdp_frame_map(eth, dev, &txd_info, txd, tx_buf,
100 + xdpf->data, xdpf->headroom, index,
101 + dma_map);
102 + if (err < 0)
103 + goto out;
104
105 /* store xdpf for cleanup */
106 tx_buf->type = dma_map ? MTK_TYPE_XDP_NDO : MTK_TYPE_XDP_TX;
107 tx_buf->data = xdpf;
108
109 if (!MTK_HAS_CAPS(soc->caps, MTK_QDMA)) {
110 + txd_pdma = qdma_to_pdma(ring, txd);
111 if (index & 1)
112 txd_pdma->txd2 |= TX_DMA_LS0;
113 else