kernel: bump 5.4 to 5.4.102
[openwrt/openwrt.git] / target / linux / mvebu / patches-5.4 / 008-net-mvneta-make-tx-buffer-array-agnostic.patch
1 From 9e58c8b410650b5a6eb5b8fad8474bd8425a4023 Mon Sep 17 00:00:00 2001
2 From: Lorenzo Bianconi <lorenzo@kernel.org>
3 Date: Sat, 19 Oct 2019 10:13:26 +0200
4 Subject: [PATCH 6/7] net: mvneta: make tx buffer array agnostic
5
6 Allow tx buffer array to contain both skb and xdp buffers in order to
7 enable xdp frame recycling adding XDP_TX verdict support
8
9 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
10 Signed-off-by: David S. Miller <davem@davemloft.net>
11 ---
12 drivers/net/ethernet/marvell/mvneta.c | 66 +++++++++++++++++----------
13 1 file changed, 43 insertions(+), 23 deletions(-)
14
15 --- a/drivers/net/ethernet/marvell/mvneta.c
16 +++ b/drivers/net/ethernet/marvell/mvneta.c
17 @@ -565,6 +565,20 @@ struct mvneta_rx_desc {
18 };
19 #endif
20
21 +enum mvneta_tx_buf_type {
22 + MVNETA_TYPE_SKB,
23 + MVNETA_TYPE_XDP_TX,
24 + MVNETA_TYPE_XDP_NDO,
25 +};
26 +
27 +struct mvneta_tx_buf {
28 + enum mvneta_tx_buf_type type;
29 + union {
30 + struct xdp_frame *xdpf;
31 + struct sk_buff *skb;
32 + };
33 +};
34 +
35 struct mvneta_tx_queue {
36 /* Number of this TX queue, in the range 0-7 */
37 u8 id;
38 @@ -580,8 +594,8 @@ struct mvneta_tx_queue {
39 int tx_stop_threshold;
40 int tx_wake_threshold;
41
42 - /* Array of transmitted skb */
43 - struct sk_buff **tx_skb;
44 + /* Array of transmitted buffers */
45 + struct mvneta_tx_buf *buf;
46
47 /* Index of last TX DMA descriptor that was inserted */
48 int txq_put_index;
49 @@ -1793,14 +1807,9 @@ static void mvneta_txq_bufs_free(struct
50 int i;
51
52 for (i = 0; i < num; i++) {
53 + struct mvneta_tx_buf *buf = &txq->buf[txq->txq_get_index];
54 struct mvneta_tx_desc *tx_desc = txq->descs +
55 txq->txq_get_index;
56 - struct sk_buff *skb = txq->tx_skb[txq->txq_get_index];
57 -
58 - if (skb) {
59 - bytes_compl += skb->len;
60 - pkts_compl++;
61 - }
62
63 mvneta_txq_inc_get(txq);
64
65 @@ -1808,9 +1817,12 @@ static void mvneta_txq_bufs_free(struct
66 dma_unmap_single(pp->dev->dev.parent,
67 tx_desc->buf_phys_addr,
68 tx_desc->data_size, DMA_TO_DEVICE);
69 - if (!skb)
70 + if (!buf->skb)
71 continue;
72 - dev_kfree_skb_any(skb);
73 +
74 + bytes_compl += buf->skb->len;
75 + pkts_compl++;
76 + dev_kfree_skb_any(buf->skb);
77 }
78
79 netdev_tx_completed_queue(nq, pkts_compl, bytes_compl);
80 @@ -2335,16 +2347,19 @@ static inline void
81 mvneta_tso_put_hdr(struct sk_buff *skb,
82 struct mvneta_port *pp, struct mvneta_tx_queue *txq)
83 {
84 - struct mvneta_tx_desc *tx_desc;
85 int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
86 + struct mvneta_tx_buf *buf = &txq->buf[txq->txq_put_index];
87 + struct mvneta_tx_desc *tx_desc;
88
89 - txq->tx_skb[txq->txq_put_index] = NULL;
90 tx_desc = mvneta_txq_next_desc_get(txq);
91 tx_desc->data_size = hdr_len;
92 tx_desc->command = mvneta_skb_tx_csum(pp, skb);
93 tx_desc->command |= MVNETA_TXD_F_DESC;
94 tx_desc->buf_phys_addr = txq->tso_hdrs_phys +
95 txq->txq_put_index * TSO_HEADER_SIZE;
96 + buf->type = MVNETA_TYPE_SKB;
97 + buf->skb = NULL;
98 +
99 mvneta_txq_inc_put(txq);
100 }
101
102 @@ -2353,6 +2368,7 @@ mvneta_tso_put_data(struct net_device *d
103 struct sk_buff *skb, char *data, int size,
104 bool last_tcp, bool is_last)
105 {
106 + struct mvneta_tx_buf *buf = &txq->buf[txq->txq_put_index];
107 struct mvneta_tx_desc *tx_desc;
108
109 tx_desc = mvneta_txq_next_desc_get(txq);
110 @@ -2366,7 +2382,8 @@ mvneta_tso_put_data(struct net_device *d
111 }
112
113 tx_desc->command = 0;
114 - txq->tx_skb[txq->txq_put_index] = NULL;
115 + buf->type = MVNETA_TYPE_SKB;
116 + buf->skb = NULL;
117
118 if (last_tcp) {
119 /* last descriptor in the TCP packet */
120 @@ -2374,7 +2391,7 @@ mvneta_tso_put_data(struct net_device *d
121
122 /* last descriptor in SKB */
123 if (is_last)
124 - txq->tx_skb[txq->txq_put_index] = skb;
125 + buf->skb = skb;
126 }
127 mvneta_txq_inc_put(txq);
128 return 0;
129 @@ -2459,6 +2476,7 @@ static int mvneta_tx_frag_process(struct
130 int i, nr_frags = skb_shinfo(skb)->nr_frags;
131
132 for (i = 0; i < nr_frags; i++) {
133 + struct mvneta_tx_buf *buf = &txq->buf[txq->txq_put_index];
134 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
135 void *addr = skb_frag_address(frag);
136
137 @@ -2478,12 +2496,13 @@ static int mvneta_tx_frag_process(struct
138 if (i == nr_frags - 1) {
139 /* Last descriptor */
140 tx_desc->command = MVNETA_TXD_L_DESC | MVNETA_TXD_Z_PAD;
141 - txq->tx_skb[txq->txq_put_index] = skb;
142 + buf->skb = skb;
143 } else {
144 /* Descriptor in the middle: Not First, Not Last */
145 tx_desc->command = 0;
146 - txq->tx_skb[txq->txq_put_index] = NULL;
147 + buf->skb = NULL;
148 }
149 + buf->type = MVNETA_TYPE_SKB;
150 mvneta_txq_inc_put(txq);
151 }
152
153 @@ -2511,6 +2530,7 @@ static netdev_tx_t mvneta_tx(struct sk_b
154 struct mvneta_port *pp = netdev_priv(dev);
155 u16 txq_id = skb_get_queue_mapping(skb);
156 struct mvneta_tx_queue *txq = &pp->txqs[txq_id];
157 + struct mvneta_tx_buf *buf = &txq->buf[txq->txq_put_index];
158 struct mvneta_tx_desc *tx_desc;
159 int len = skb->len;
160 int frags = 0;
161 @@ -2543,16 +2563,17 @@ static netdev_tx_t mvneta_tx(struct sk_b
162 goto out;
163 }
164
165 + buf->type = MVNETA_TYPE_SKB;
166 if (frags == 1) {
167 /* First and Last descriptor */
168 tx_cmd |= MVNETA_TXD_FLZ_DESC;
169 tx_desc->command = tx_cmd;
170 - txq->tx_skb[txq->txq_put_index] = skb;
171 + buf->skb = skb;
172 mvneta_txq_inc_put(txq);
173 } else {
174 /* First but not Last */
175 tx_cmd |= MVNETA_TXD_F_DESC;
176 - txq->tx_skb[txq->txq_put_index] = NULL;
177 + buf->skb = NULL;
178 mvneta_txq_inc_put(txq);
179 tx_desc->command = tx_cmd;
180 /* Continue with other skb fragments */
181 @@ -3138,9 +3159,8 @@ static int mvneta_txq_sw_init(struct mvn
182
183 txq->last_desc = txq->size - 1;
184
185 - txq->tx_skb = kmalloc_array(txq->size, sizeof(*txq->tx_skb),
186 - GFP_KERNEL);
187 - if (!txq->tx_skb) {
188 + txq->buf = kmalloc_array(txq->size, sizeof(*txq->buf), GFP_KERNEL);
189 + if (!txq->buf) {
190 dma_free_coherent(pp->dev->dev.parent,
191 txq->size * MVNETA_DESC_ALIGNED_SIZE,
192 txq->descs, txq->descs_phys);
193 @@ -3152,7 +3172,7 @@ static int mvneta_txq_sw_init(struct mvn
194 txq->size * TSO_HEADER_SIZE,
195 &txq->tso_hdrs_phys, GFP_KERNEL);
196 if (!txq->tso_hdrs) {
197 - kfree(txq->tx_skb);
198 + kfree(txq->buf);
199 dma_free_coherent(pp->dev->dev.parent,
200 txq->size * MVNETA_DESC_ALIGNED_SIZE,
201 txq->descs, txq->descs_phys);
202 @@ -3207,7 +3227,7 @@ static void mvneta_txq_sw_deinit(struct
203 {
204 struct netdev_queue *nq = netdev_get_tx_queue(pp->dev, txq->id);
205
206 - kfree(txq->tx_skb);
207 + kfree(txq->buf);
208
209 if (txq->tso_hdrs)
210 dma_free_coherent(pp->dev->dev.parent,