1 From ba39b344e9240a4a5fd4ab8178200b85cd1809da Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Sat, 23 Jul 2022 16:29:32 +0200
4 Subject: [PATCH 4/5] net: ethernet: stmicro: stmmac: generate stmmac dma conf
7 Rework the driver to generate the stmmac dma_conf before stmmac_open.
8 This permits a function to first check if it's possible to allocate a
9 new dma_config and then pass it directly to __stmmac_open and "open" the
10 interface with the new configuration.
12 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
13 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
15 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 462 +++++++++++-------
16 1 file changed, 289 insertions(+), 173 deletions(-)
18 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
19 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
20 @@ -1301,7 +1301,8 @@ static int stmmac_phy_setup(struct stmma
24 -static void stmmac_display_rx_rings(struct stmmac_priv *priv)
25 +static void stmmac_display_rx_rings(struct stmmac_priv *priv,
26 + struct stmmac_dma_conf *dma_conf)
28 u32 rx_cnt = priv->plat->rx_queues_to_use;
29 unsigned int desc_size;
30 @@ -1310,7 +1311,7 @@ static void stmmac_display_rx_rings(stru
32 /* Display RX rings */
33 for (queue = 0; queue < rx_cnt; queue++) {
34 - struct stmmac_rx_queue *rx_q = &priv->dma_conf.rx_queue[queue];
35 + struct stmmac_rx_queue *rx_q = &dma_conf->rx_queue[queue];
37 pr_info("\tRX Queue %u rings\n", queue);
39 @@ -1323,12 +1324,13 @@ static void stmmac_display_rx_rings(stru
43 - stmmac_display_ring(priv, head_rx, priv->dma_conf.dma_rx_size, true,
44 + stmmac_display_ring(priv, head_rx, dma_conf->dma_rx_size, true,
45 rx_q->dma_rx_phy, desc_size);
49 -static void stmmac_display_tx_rings(struct stmmac_priv *priv)
50 +static void stmmac_display_tx_rings(struct stmmac_priv *priv,
51 + struct stmmac_dma_conf *dma_conf)
53 u32 tx_cnt = priv->plat->tx_queues_to_use;
54 unsigned int desc_size;
55 @@ -1337,7 +1339,7 @@ static void stmmac_display_tx_rings(stru
57 /* Display TX rings */
58 for (queue = 0; queue < tx_cnt; queue++) {
59 - struct stmmac_tx_queue *tx_q = &priv->dma_conf.tx_queue[queue];
60 + struct stmmac_tx_queue *tx_q = &dma_conf->tx_queue[queue];
62 pr_info("\tTX Queue %d rings\n", queue);
64 @@ -1352,18 +1354,19 @@ static void stmmac_display_tx_rings(stru
65 desc_size = sizeof(struct dma_desc);
68 - stmmac_display_ring(priv, head_tx, priv->dma_conf.dma_tx_size, false,
69 + stmmac_display_ring(priv, head_tx, dma_conf->dma_tx_size, false,
70 tx_q->dma_tx_phy, desc_size);
74 -static void stmmac_display_rings(struct stmmac_priv *priv)
75 +static void stmmac_display_rings(struct stmmac_priv *priv,
76 + struct stmmac_dma_conf *dma_conf)
79 - stmmac_display_rx_rings(priv);
80 + stmmac_display_rx_rings(priv, dma_conf);
83 - stmmac_display_tx_rings(priv);
84 + stmmac_display_tx_rings(priv, dma_conf);
87 static int stmmac_set_bfsize(int mtu, int bufsize)
88 @@ -1387,44 +1390,50 @@ static int stmmac_set_bfsize(int mtu, in
90 * stmmac_clear_rx_descriptors - clear RX descriptors
91 * @priv: driver private structure
92 + * @dma_conf: structure to take the dma data
93 * @queue: RX queue index
94 * Description: this function is called to clear the RX descriptors
95 * in case of both basic and extended descriptors are used.
97 -static void stmmac_clear_rx_descriptors(struct stmmac_priv *priv, u32 queue)
98 +static void stmmac_clear_rx_descriptors(struct stmmac_priv *priv,
99 + struct stmmac_dma_conf *dma_conf,
102 - struct stmmac_rx_queue *rx_q = &priv->dma_conf.rx_queue[queue];
103 + struct stmmac_rx_queue *rx_q = &dma_conf->rx_queue[queue];
106 /* Clear the RX descriptors */
107 - for (i = 0; i < priv->dma_conf.dma_rx_size; i++)
108 + for (i = 0; i < dma_conf->dma_rx_size; i++)
109 if (priv->extend_desc)
110 stmmac_init_rx_desc(priv, &rx_q->dma_erx[i].basic,
111 priv->use_riwt, priv->mode,
112 - (i == priv->dma_conf.dma_rx_size - 1),
113 - priv->dma_conf.dma_buf_sz);
114 + (i == dma_conf->dma_rx_size - 1),
115 + dma_conf->dma_buf_sz);
117 stmmac_init_rx_desc(priv, &rx_q->dma_rx[i],
118 priv->use_riwt, priv->mode,
119 - (i == priv->dma_conf.dma_rx_size - 1),
120 - priv->dma_conf.dma_buf_sz);
121 + (i == dma_conf->dma_rx_size - 1),
122 + dma_conf->dma_buf_sz);
126 * stmmac_clear_tx_descriptors - clear tx descriptors
127 * @priv: driver private structure
128 + * @dma_conf: structure to take the dma data
129 * @queue: TX queue index.
130 * Description: this function is called to clear the TX descriptors
131 * in case of both basic and extended descriptors are used.
133 -static void stmmac_clear_tx_descriptors(struct stmmac_priv *priv, u32 queue)
134 +static void stmmac_clear_tx_descriptors(struct stmmac_priv *priv,
135 + struct stmmac_dma_conf *dma_conf,
138 - struct stmmac_tx_queue *tx_q = &priv->dma_conf.tx_queue[queue];
139 + struct stmmac_tx_queue *tx_q = &dma_conf->tx_queue[queue];
142 /* Clear the TX descriptors */
143 - for (i = 0; i < priv->dma_conf.dma_tx_size; i++) {
144 - int last = (i == (priv->dma_conf.dma_tx_size - 1));
145 + for (i = 0; i < dma_conf->dma_tx_size; i++) {
146 + int last = (i == (dma_conf->dma_tx_size - 1));
149 if (priv->extend_desc)
150 @@ -1441,10 +1450,12 @@ static void stmmac_clear_tx_descriptors(
152 * stmmac_clear_descriptors - clear descriptors
153 * @priv: driver private structure
154 + * @dma_conf: structure to take the dma data
155 * Description: this function is called to clear the TX and RX descriptors
156 * in case of both basic and extended descriptors are used.
158 -static void stmmac_clear_descriptors(struct stmmac_priv *priv)
159 +static void stmmac_clear_descriptors(struct stmmac_priv *priv,
160 + struct stmmac_dma_conf *dma_conf)
162 u32 rx_queue_cnt = priv->plat->rx_queues_to_use;
163 u32 tx_queue_cnt = priv->plat->tx_queues_to_use;
164 @@ -1452,16 +1463,17 @@ static void stmmac_clear_descriptors(str
166 /* Clear the RX descriptors */
167 for (queue = 0; queue < rx_queue_cnt; queue++)
168 - stmmac_clear_rx_descriptors(priv, queue);
169 + stmmac_clear_rx_descriptors(priv, dma_conf, queue);
171 /* Clear the TX descriptors */
172 for (queue = 0; queue < tx_queue_cnt; queue++)
173 - stmmac_clear_tx_descriptors(priv, queue);
174 + stmmac_clear_tx_descriptors(priv, dma_conf, queue);
178 * stmmac_init_rx_buffers - init the RX descriptor buffer.
179 * @priv: driver private structure
180 + * @dma_conf: structure to take the dma data
181 * @p: descriptor pointer
182 * @i: descriptor index
184 @@ -1469,10 +1481,12 @@ static void stmmac_clear_descriptors(str
185 * Description: this function is called to allocate a receive buffer, perform
186 * the DMA mapping and init the descriptor.
188 -static int stmmac_init_rx_buffers(struct stmmac_priv *priv, struct dma_desc *p,
189 +static int stmmac_init_rx_buffers(struct stmmac_priv *priv,
190 + struct stmmac_dma_conf *dma_conf,
191 + struct dma_desc *p,
192 int i, gfp_t flags, u32 queue)
194 - struct stmmac_rx_queue *rx_q = &priv->dma_conf.rx_queue[queue];
195 + struct stmmac_rx_queue *rx_q = &dma_conf->rx_queue[queue];
196 struct stmmac_rx_buffer *buf = &rx_q->buf_pool[i];
199 @@ -1497,7 +1511,7 @@ static int stmmac_init_rx_buffers(struct
200 buf->addr = page_pool_get_dma_addr(buf->page) + buf->page_offset;
202 stmmac_set_desc_addr(priv, p, buf->addr);
203 - if (priv->dma_conf.dma_buf_sz == BUF_SIZE_16KiB)
204 + if (dma_conf->dma_buf_sz == BUF_SIZE_16KiB)
205 stmmac_init_desc3(priv, p);
208 @@ -1506,12 +1520,13 @@ static int stmmac_init_rx_buffers(struct
210 * stmmac_free_rx_buffer - free RX dma buffers
211 * @priv: private structure
212 - * @queue: RX queue index
216 -static void stmmac_free_rx_buffer(struct stmmac_priv *priv, u32 queue, int i)
217 +static void stmmac_free_rx_buffer(struct stmmac_priv *priv,
218 + struct stmmac_rx_queue *rx_q,
221 - struct stmmac_rx_queue *rx_q = &priv->dma_conf.rx_queue[queue];
222 struct stmmac_rx_buffer *buf = &rx_q->buf_pool[i];
225 @@ -1526,12 +1541,15 @@ static void stmmac_free_rx_buffer(struct
227 * stmmac_free_tx_buffer - free RX dma buffers
228 * @priv: private structure
229 + * @dma_conf: structure to take the dma data
230 * @queue: RX queue index
233 -static void stmmac_free_tx_buffer(struct stmmac_priv *priv, u32 queue, int i)
234 +static void stmmac_free_tx_buffer(struct stmmac_priv *priv,
235 + struct stmmac_dma_conf *dma_conf,
238 - struct stmmac_tx_queue *tx_q = &priv->dma_conf.tx_queue[queue];
239 + struct stmmac_tx_queue *tx_q = &dma_conf->tx_queue[queue];
241 if (tx_q->tx_skbuff_dma[i].buf &&
242 tx_q->tx_skbuff_dma[i].buf_type != STMMAC_TXBUF_T_XDP_TX) {
243 @@ -1570,23 +1588,28 @@ static void stmmac_free_tx_buffer(struct
245 * dma_free_rx_skbufs - free RX dma buffers
246 * @priv: private structure
247 + * @dma_conf: structure to take the dma data
248 * @queue: RX queue index
250 -static void dma_free_rx_skbufs(struct stmmac_priv *priv, u32 queue)
251 +static void dma_free_rx_skbufs(struct stmmac_priv *priv,
252 + struct stmmac_dma_conf *dma_conf,
255 + struct stmmac_rx_queue *rx_q = &dma_conf->rx_queue[queue];
258 - for (i = 0; i < priv->dma_conf.dma_rx_size; i++)
259 - stmmac_free_rx_buffer(priv, queue, i);
260 + for (i = 0; i < dma_conf->dma_rx_size; i++)
261 + stmmac_free_rx_buffer(priv, rx_q, i);
264 -static int stmmac_alloc_rx_buffers(struct stmmac_priv *priv, u32 queue,
266 +static int stmmac_alloc_rx_buffers(struct stmmac_priv *priv,
267 + struct stmmac_dma_conf *dma_conf,
268 + u32 queue, gfp_t flags)
270 - struct stmmac_rx_queue *rx_q = &priv->dma_conf.rx_queue[queue];
271 + struct stmmac_rx_queue *rx_q = &dma_conf->rx_queue[queue];
274 - for (i = 0; i < priv->dma_conf.dma_rx_size; i++) {
275 + for (i = 0; i < dma_conf->dma_rx_size; i++) {
279 @@ -1595,7 +1618,7 @@ static int stmmac_alloc_rx_buffers(struc
281 p = rx_q->dma_rx + i;
283 - ret = stmmac_init_rx_buffers(priv, p, i, flags,
284 + ret = stmmac_init_rx_buffers(priv, dma_conf, p, i, flags,
288 @@ -1609,14 +1632,17 @@ static int stmmac_alloc_rx_buffers(struc
290 * dma_free_rx_xskbufs - free RX dma buffers from XSK pool
291 * @priv: private structure
292 + * @dma_conf: structure to take the dma data
293 * @queue: RX queue index
295 -static void dma_free_rx_xskbufs(struct stmmac_priv *priv, u32 queue)
296 +static void dma_free_rx_xskbufs(struct stmmac_priv *priv,
297 + struct stmmac_dma_conf *dma_conf,
300 - struct stmmac_rx_queue *rx_q = &priv->dma_conf.rx_queue[queue];
301 + struct stmmac_rx_queue *rx_q = &dma_conf->rx_queue[queue];
304 - for (i = 0; i < priv->dma_conf.dma_rx_size; i++) {
305 + for (i = 0; i < dma_conf->dma_rx_size; i++) {
306 struct stmmac_rx_buffer *buf = &rx_q->buf_pool[i];
309 @@ -1627,12 +1653,14 @@ static void dma_free_rx_xskbufs(struct s
313 -static int stmmac_alloc_rx_buffers_zc(struct stmmac_priv *priv, u32 queue)
314 +static int stmmac_alloc_rx_buffers_zc(struct stmmac_priv *priv,
315 + struct stmmac_dma_conf *dma_conf,
318 - struct stmmac_rx_queue *rx_q = &priv->dma_conf.rx_queue[queue];
319 + struct stmmac_rx_queue *rx_q = &dma_conf->rx_queue[queue];
322 - for (i = 0; i < priv->dma_conf.dma_rx_size; i++) {
323 + for (i = 0; i < dma_conf->dma_rx_size; i++) {
324 struct stmmac_rx_buffer *buf;
327 @@ -1667,22 +1695,25 @@ static struct xsk_buff_pool *stmmac_get_
329 * __init_dma_rx_desc_rings - init the RX descriptor ring (per queue)
330 * @priv: driver private structure
331 + * @dma_conf: structure to take the dma data
332 * @queue: RX queue index
334 * Description: this function initializes the DMA RX descriptors
335 * and allocates the socket buffers. It supports the chained and ring
338 -static int __init_dma_rx_desc_rings(struct stmmac_priv *priv, u32 queue, gfp_t flags)
339 +static int __init_dma_rx_desc_rings(struct stmmac_priv *priv,
340 + struct stmmac_dma_conf *dma_conf,
341 + u32 queue, gfp_t flags)
343 - struct stmmac_rx_queue *rx_q = &priv->dma_conf.rx_queue[queue];
344 + struct stmmac_rx_queue *rx_q = &dma_conf->rx_queue[queue];
347 netif_dbg(priv, probe, priv->dev,
348 "(%s) dma_rx_phy=0x%08x\n", __func__,
349 (u32)rx_q->dma_rx_phy);
351 - stmmac_clear_rx_descriptors(priv, queue);
352 + stmmac_clear_rx_descriptors(priv, dma_conf, queue);
354 xdp_rxq_info_unreg_mem_model(&rx_q->xdp_rxq);
356 @@ -1709,9 +1740,9 @@ static int __init_dma_rx_desc_rings(stru
357 /* RX XDP ZC buffer pool may not be populated, e.g.
360 - stmmac_alloc_rx_buffers_zc(priv, queue);
361 + stmmac_alloc_rx_buffers_zc(priv, dma_conf, queue);
363 - ret = stmmac_alloc_rx_buffers(priv, queue, flags);
364 + ret = stmmac_alloc_rx_buffers(priv, dma_conf, queue, flags);
368 @@ -1721,17 +1752,19 @@ static int __init_dma_rx_desc_rings(stru
369 if (priv->extend_desc)
370 stmmac_mode_init(priv, rx_q->dma_erx,
372 - priv->dma_conf.dma_rx_size, 1);
373 + dma_conf->dma_rx_size, 1);
375 stmmac_mode_init(priv, rx_q->dma_rx,
377 - priv->dma_conf.dma_rx_size, 0);
378 + dma_conf->dma_rx_size, 0);
384 -static int init_dma_rx_desc_rings(struct net_device *dev, gfp_t flags)
385 +static int init_dma_rx_desc_rings(struct net_device *dev,
386 + struct stmmac_dma_conf *dma_conf,
389 struct stmmac_priv *priv = netdev_priv(dev);
390 u32 rx_count = priv->plat->rx_queues_to_use;
391 @@ -1743,7 +1776,7 @@ static int init_dma_rx_desc_rings(struct
392 "SKB addresses:\nskb\t\tskb data\tdma data\n");
394 for (queue = 0; queue < rx_count; queue++) {
395 - ret = __init_dma_rx_desc_rings(priv, queue, flags);
396 + ret = __init_dma_rx_desc_rings(priv, dma_conf, queue, flags);
398 goto err_init_rx_buffers;
400 @@ -1752,12 +1785,12 @@ static int init_dma_rx_desc_rings(struct
404 - struct stmmac_rx_queue *rx_q = &priv->dma_conf.rx_queue[queue];
405 + struct stmmac_rx_queue *rx_q = &dma_conf->rx_queue[queue];
408 - dma_free_rx_xskbufs(priv, queue);
409 + dma_free_rx_xskbufs(priv, dma_conf, queue);
411 - dma_free_rx_skbufs(priv, queue);
412 + dma_free_rx_skbufs(priv, dma_conf, queue);
414 rx_q->buf_alloc_num = 0;
415 rx_q->xsk_pool = NULL;
416 @@ -1774,14 +1807,17 @@ err_init_rx_buffers:
418 * __init_dma_tx_desc_rings - init the TX descriptor ring (per queue)
419 * @priv: driver private structure
420 - * @queue : TX queue index
421 + * @dma_conf: structure to take the dma data
422 + * @queue: TX queue index
423 * Description: this function initializes the DMA TX descriptors
424 * and allocates the socket buffers. It supports the chained and ring
427 -static int __init_dma_tx_desc_rings(struct stmmac_priv *priv, u32 queue)
428 +static int __init_dma_tx_desc_rings(struct stmmac_priv *priv,
429 + struct stmmac_dma_conf *dma_conf,
432 - struct stmmac_tx_queue *tx_q = &priv->dma_conf.tx_queue[queue];
433 + struct stmmac_tx_queue *tx_q = &dma_conf->tx_queue[queue];
436 netif_dbg(priv, probe, priv->dev,
437 @@ -1793,16 +1829,16 @@ static int __init_dma_tx_desc_rings(stru
438 if (priv->extend_desc)
439 stmmac_mode_init(priv, tx_q->dma_etx,
441 - priv->dma_conf.dma_tx_size, 1);
442 + dma_conf->dma_tx_size, 1);
443 else if (!(tx_q->tbs & STMMAC_TBS_AVAIL))
444 stmmac_mode_init(priv, tx_q->dma_tx,
446 - priv->dma_conf.dma_tx_size, 0);
447 + dma_conf->dma_tx_size, 0);
450 tx_q->xsk_pool = stmmac_get_xsk_pool(priv, queue);
452 - for (i = 0; i < priv->dma_conf.dma_tx_size; i++) {
453 + for (i = 0; i < dma_conf->dma_tx_size; i++) {
456 if (priv->extend_desc)
457 @@ -1824,7 +1860,8 @@ static int __init_dma_tx_desc_rings(stru
461 -static int init_dma_tx_desc_rings(struct net_device *dev)
462 +static int init_dma_tx_desc_rings(struct net_device *dev,
463 + struct stmmac_dma_conf *dma_conf)
465 struct stmmac_priv *priv = netdev_priv(dev);
467 @@ -1833,7 +1870,7 @@ static int init_dma_tx_desc_rings(struct
468 tx_queue_cnt = priv->plat->tx_queues_to_use;
470 for (queue = 0; queue < tx_queue_cnt; queue++)
471 - __init_dma_tx_desc_rings(priv, queue);
472 + __init_dma_tx_desc_rings(priv, dma_conf, queue);
476 @@ -1841,26 +1878,29 @@ static int init_dma_tx_desc_rings(struct
478 * init_dma_desc_rings - init the RX/TX descriptor rings
479 * @dev: net device structure
480 + * @dma_conf: structure to take the dma data
482 * Description: this function initializes the DMA RX/TX descriptors
483 * and allocates the socket buffers. It supports the chained and ring
486 -static int init_dma_desc_rings(struct net_device *dev, gfp_t flags)
487 +static int init_dma_desc_rings(struct net_device *dev,
488 + struct stmmac_dma_conf *dma_conf,
491 struct stmmac_priv *priv = netdev_priv(dev);
494 - ret = init_dma_rx_desc_rings(dev, flags);
495 + ret = init_dma_rx_desc_rings(dev, dma_conf, flags);
499 - ret = init_dma_tx_desc_rings(dev);
500 + ret = init_dma_tx_desc_rings(dev, dma_conf);
502 - stmmac_clear_descriptors(priv);
503 + stmmac_clear_descriptors(priv, dma_conf);
505 if (netif_msg_hw(priv))
506 - stmmac_display_rings(priv);
507 + stmmac_display_rings(priv, dma_conf);
511 @@ -1868,17 +1908,20 @@ static int init_dma_desc_rings(struct ne
513 * dma_free_tx_skbufs - free TX dma buffers
514 * @priv: private structure
515 + * @dma_conf: structure to take the dma data
516 * @queue: TX queue index
518 -static void dma_free_tx_skbufs(struct stmmac_priv *priv, u32 queue)
519 +static void dma_free_tx_skbufs(struct stmmac_priv *priv,
520 + struct stmmac_dma_conf *dma_conf,
523 - struct stmmac_tx_queue *tx_q = &priv->dma_conf.tx_queue[queue];
524 + struct stmmac_tx_queue *tx_q = &dma_conf->tx_queue[queue];
527 tx_q->xsk_frames_done = 0;
529 - for (i = 0; i < priv->dma_conf.dma_tx_size; i++)
530 - stmmac_free_tx_buffer(priv, queue, i);
531 + for (i = 0; i < dma_conf->dma_tx_size; i++)
532 + stmmac_free_tx_buffer(priv, dma_conf, queue, i);
534 if (tx_q->xsk_pool && tx_q->xsk_frames_done) {
535 xsk_tx_completed(tx_q->xsk_pool, tx_q->xsk_frames_done);
536 @@ -1897,34 +1940,37 @@ static void stmmac_free_tx_skbufs(struct
539 for (queue = 0; queue < tx_queue_cnt; queue++)
540 - dma_free_tx_skbufs(priv, queue);
541 + dma_free_tx_skbufs(priv, &priv->dma_conf, queue);
545 * __free_dma_rx_desc_resources - free RX dma desc resources (per queue)
546 * @priv: private structure
547 + * @dma_conf: structure to take the dma data
548 * @queue: RX queue index
550 -static void __free_dma_rx_desc_resources(struct stmmac_priv *priv, u32 queue)
551 +static void __free_dma_rx_desc_resources(struct stmmac_priv *priv,
552 + struct stmmac_dma_conf *dma_conf,
555 - struct stmmac_rx_queue *rx_q = &priv->dma_conf.rx_queue[queue];
556 + struct stmmac_rx_queue *rx_q = &dma_conf->rx_queue[queue];
558 /* Release the DMA RX socket buffers */
560 - dma_free_rx_xskbufs(priv, queue);
561 + dma_free_rx_xskbufs(priv, dma_conf, queue);
563 - dma_free_rx_skbufs(priv, queue);
564 + dma_free_rx_skbufs(priv, dma_conf, queue);
566 rx_q->buf_alloc_num = 0;
567 rx_q->xsk_pool = NULL;
569 /* Free DMA regions of consistent memory previously allocated */
570 if (!priv->extend_desc)
571 - dma_free_coherent(priv->device, priv->dma_conf.dma_rx_size *
572 + dma_free_coherent(priv->device, dma_conf->dma_rx_size *
573 sizeof(struct dma_desc),
574 rx_q->dma_rx, rx_q->dma_rx_phy);
576 - dma_free_coherent(priv->device, priv->dma_conf.dma_rx_size *
577 + dma_free_coherent(priv->device, dma_conf->dma_rx_size *
578 sizeof(struct dma_extended_desc),
579 rx_q->dma_erx, rx_q->dma_rx_phy);
581 @@ -1936,29 +1982,33 @@ static void __free_dma_rx_desc_resources
582 page_pool_destroy(rx_q->page_pool);
585 -static void free_dma_rx_desc_resources(struct stmmac_priv *priv)
586 +static void free_dma_rx_desc_resources(struct stmmac_priv *priv,
587 + struct stmmac_dma_conf *dma_conf)
589 u32 rx_count = priv->plat->rx_queues_to_use;
592 /* Free RX queue resources */
593 for (queue = 0; queue < rx_count; queue++)
594 - __free_dma_rx_desc_resources(priv, queue);
595 + __free_dma_rx_desc_resources(priv, dma_conf, queue);
599 * __free_dma_tx_desc_resources - free TX dma desc resources (per queue)
600 * @priv: private structure
601 + * @dma_conf: structure to take the dma data
602 * @queue: TX queue index
604 -static void __free_dma_tx_desc_resources(struct stmmac_priv *priv, u32 queue)
605 +static void __free_dma_tx_desc_resources(struct stmmac_priv *priv,
606 + struct stmmac_dma_conf *dma_conf,
609 - struct stmmac_tx_queue *tx_q = &priv->dma_conf.tx_queue[queue];
610 + struct stmmac_tx_queue *tx_q = &dma_conf->tx_queue[queue];
614 /* Release the DMA TX socket buffers */
615 - dma_free_tx_skbufs(priv, queue);
616 + dma_free_tx_skbufs(priv, dma_conf, queue);
618 if (priv->extend_desc) {
619 size = sizeof(struct dma_extended_desc);
620 @@ -1971,7 +2021,7 @@ static void __free_dma_tx_desc_resources
624 - size *= priv->dma_conf.dma_tx_size;
625 + size *= dma_conf->dma_tx_size;
627 dma_free_coherent(priv->device, size, addr, tx_q->dma_tx_phy);
629 @@ -1979,28 +2029,32 @@ static void __free_dma_tx_desc_resources
630 kfree(tx_q->tx_skbuff);
633 -static void free_dma_tx_desc_resources(struct stmmac_priv *priv)
634 +static void free_dma_tx_desc_resources(struct stmmac_priv *priv,
635 + struct stmmac_dma_conf *dma_conf)
637 u32 tx_count = priv->plat->tx_queues_to_use;
640 /* Free TX queue resources */
641 for (queue = 0; queue < tx_count; queue++)
642 - __free_dma_tx_desc_resources(priv, queue);
643 + __free_dma_tx_desc_resources(priv, dma_conf, queue);
647 * __alloc_dma_rx_desc_resources - alloc RX resources (per queue).
648 * @priv: private structure
649 + * @dma_conf: structure to take the dma data
650 * @queue: RX queue index
651 * Description: according to which descriptor can be used (extend or basic)
652 * this function allocates the resources for TX and RX paths. In case of
653 * reception, for example, it pre-allocated the RX socket buffer in order to
654 * allow zero-copy mechanism.
656 -static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv, u32 queue)
657 +static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv,
658 + struct stmmac_dma_conf *dma_conf,
661 - struct stmmac_rx_queue *rx_q = &priv->dma_conf.rx_queue[queue];
662 + struct stmmac_rx_queue *rx_q = &dma_conf->rx_queue[queue];
663 struct stmmac_channel *ch = &priv->channel[queue];
664 bool xdp_prog = stmmac_xdp_is_enabled(priv);
665 struct page_pool_params pp_params = { 0 };
666 @@ -2012,8 +2066,8 @@ static int __alloc_dma_rx_desc_resources
667 rx_q->priv_data = priv;
669 pp_params.flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV;
670 - pp_params.pool_size = priv->dma_conf.dma_rx_size;
671 - num_pages = DIV_ROUND_UP(priv->dma_conf.dma_buf_sz, PAGE_SIZE);
672 + pp_params.pool_size = dma_conf->dma_rx_size;
673 + num_pages = DIV_ROUND_UP(dma_conf->dma_buf_sz, PAGE_SIZE);
674 pp_params.order = ilog2(num_pages);
675 pp_params.nid = dev_to_node(priv->device);
676 pp_params.dev = priv->device;
677 @@ -2028,7 +2082,7 @@ static int __alloc_dma_rx_desc_resources
681 - rx_q->buf_pool = kcalloc(priv->dma_conf.dma_rx_size,
682 + rx_q->buf_pool = kcalloc(dma_conf->dma_rx_size,
683 sizeof(*rx_q->buf_pool),
686 @@ -2036,7 +2090,7 @@ static int __alloc_dma_rx_desc_resources
688 if (priv->extend_desc) {
689 rx_q->dma_erx = dma_alloc_coherent(priv->device,
690 - priv->dma_conf.dma_rx_size *
691 + dma_conf->dma_rx_size *
692 sizeof(struct dma_extended_desc),
695 @@ -2045,7 +2099,7 @@ static int __alloc_dma_rx_desc_resources
698 rx_q->dma_rx = dma_alloc_coherent(priv->device,
699 - priv->dma_conf.dma_rx_size *
700 + dma_conf->dma_rx_size *
701 sizeof(struct dma_desc),
704 @@ -2070,7 +2124,8 @@ static int __alloc_dma_rx_desc_resources
708 -static int alloc_dma_rx_desc_resources(struct stmmac_priv *priv)
709 +static int alloc_dma_rx_desc_resources(struct stmmac_priv *priv,
710 + struct stmmac_dma_conf *dma_conf)
712 u32 rx_count = priv->plat->rx_queues_to_use;
714 @@ -2078,7 +2133,7 @@ static int alloc_dma_rx_desc_resources(s
716 /* RX queues buffers and DMA */
717 for (queue = 0; queue < rx_count; queue++) {
718 - ret = __alloc_dma_rx_desc_resources(priv, queue);
719 + ret = __alloc_dma_rx_desc_resources(priv, dma_conf, queue);
723 @@ -2086,7 +2141,7 @@ static int alloc_dma_rx_desc_resources(s
727 - free_dma_rx_desc_resources(priv);
728 + free_dma_rx_desc_resources(priv, dma_conf);
732 @@ -2094,28 +2149,31 @@ err_dma:
734 * __alloc_dma_tx_desc_resources - alloc TX resources (per queue).
735 * @priv: private structure
736 + * @dma_conf: structure to take the dma data
737 * @queue: TX queue index
738 * Description: according to which descriptor can be used (extend or basic)
739 * this function allocates the resources for TX and RX paths. In case of
740 * reception, for example, it pre-allocated the RX socket buffer in order to
741 * allow zero-copy mechanism.
743 -static int __alloc_dma_tx_desc_resources(struct stmmac_priv *priv, u32 queue)
744 +static int __alloc_dma_tx_desc_resources(struct stmmac_priv *priv,
745 + struct stmmac_dma_conf *dma_conf,
748 - struct stmmac_tx_queue *tx_q = &priv->dma_conf.tx_queue[queue];
749 + struct stmmac_tx_queue *tx_q = &dma_conf->tx_queue[queue];
753 tx_q->queue_index = queue;
754 tx_q->priv_data = priv;
756 - tx_q->tx_skbuff_dma = kcalloc(priv->dma_conf.dma_tx_size,
757 + tx_q->tx_skbuff_dma = kcalloc(dma_conf->dma_tx_size,
758 sizeof(*tx_q->tx_skbuff_dma),
760 if (!tx_q->tx_skbuff_dma)
763 - tx_q->tx_skbuff = kcalloc(priv->dma_conf.dma_tx_size,
764 + tx_q->tx_skbuff = kcalloc(dma_conf->dma_tx_size,
765 sizeof(struct sk_buff *),
767 if (!tx_q->tx_skbuff)
768 @@ -2128,7 +2186,7 @@ static int __alloc_dma_tx_desc_resources
770 size = sizeof(struct dma_desc);
772 - size *= priv->dma_conf.dma_tx_size;
773 + size *= dma_conf->dma_tx_size;
775 addr = dma_alloc_coherent(priv->device, size,
776 &tx_q->dma_tx_phy, GFP_KERNEL);
777 @@ -2145,7 +2203,8 @@ static int __alloc_dma_tx_desc_resources
781 -static int alloc_dma_tx_desc_resources(struct stmmac_priv *priv)
782 +static int alloc_dma_tx_desc_resources(struct stmmac_priv *priv,
783 + struct stmmac_dma_conf *dma_conf)
785 u32 tx_count = priv->plat->tx_queues_to_use;
787 @@ -2153,7 +2212,7 @@ static int alloc_dma_tx_desc_resources(s
789 /* TX queues buffers and DMA */
790 for (queue = 0; queue < tx_count; queue++) {
791 - ret = __alloc_dma_tx_desc_resources(priv, queue);
792 + ret = __alloc_dma_tx_desc_resources(priv, dma_conf, queue);
796 @@ -2161,27 +2220,29 @@ static int alloc_dma_tx_desc_resources(s
800 - free_dma_tx_desc_resources(priv);
801 + free_dma_tx_desc_resources(priv, dma_conf);
806 * alloc_dma_desc_resources - alloc TX/RX resources.
807 * @priv: private structure
808 + * @dma_conf: structure to take the dma data
809 * Description: according to which descriptor can be used (extend or basic)
810 * this function allocates the resources for TX and RX paths. In case of
811 * reception, for example, it pre-allocated the RX socket buffer in order to
812 * allow zero-copy mechanism.
814 -static int alloc_dma_desc_resources(struct stmmac_priv *priv)
815 +static int alloc_dma_desc_resources(struct stmmac_priv *priv,
816 + struct stmmac_dma_conf *dma_conf)
819 - int ret = alloc_dma_rx_desc_resources(priv);
820 + int ret = alloc_dma_rx_desc_resources(priv, dma_conf);
825 - ret = alloc_dma_tx_desc_resources(priv);
826 + ret = alloc_dma_tx_desc_resources(priv, dma_conf);
830 @@ -2189,16 +2250,18 @@ static int alloc_dma_desc_resources(stru
832 * free_dma_desc_resources - free dma desc resources
833 * @priv: private structure
834 + * @dma_conf: structure to take the dma data
836 -static void free_dma_desc_resources(struct stmmac_priv *priv)
837 +static void free_dma_desc_resources(struct stmmac_priv *priv,
838 + struct stmmac_dma_conf *dma_conf)
840 /* Release the DMA TX socket buffers */
841 - free_dma_tx_desc_resources(priv);
842 + free_dma_tx_desc_resources(priv, dma_conf);
844 /* Release the DMA RX socket buffers later
845 * to ensure all pending XDP_TX buffers are returned.
847 - free_dma_rx_desc_resources(priv);
848 + free_dma_rx_desc_resources(priv, dma_conf);
852 @@ -2687,8 +2750,8 @@ static void stmmac_tx_err(struct stmmac_
853 netif_tx_stop_queue(netdev_get_tx_queue(priv->dev, chan));
855 stmmac_stop_tx_dma(priv, chan);
856 - dma_free_tx_skbufs(priv, chan);
857 - stmmac_clear_tx_descriptors(priv, chan);
858 + dma_free_tx_skbufs(priv, &priv->dma_conf, chan);
859 + stmmac_clear_tx_descriptors(priv, &priv->dma_conf, chan);
860 stmmac_reset_tx_queue(priv, chan);
861 stmmac_init_tx_chan(priv, priv->ioaddr, priv->plat->dma_cfg,
862 tx_q->dma_tx_phy, chan);
863 @@ -3686,19 +3749,93 @@ static int stmmac_request_irq(struct net
867 - * stmmac_open - open entry point of the driver
868 + * stmmac_setup_dma_desc - Generate a dma_conf and allocate DMA queue
869 + * @priv: driver private structure
870 + * @mtu: MTU to setup the dma queue and buf with
871 + * Description: Allocate and generate a dma_conf based on the provided MTU.
872 + * Allocate the Tx/Rx DMA queue and init them.
874 + * the dma_conf allocated struct on success and an appropriate ERR_PTR on failure.
876 +static struct stmmac_dma_conf *
877 +stmmac_setup_dma_desc(struct stmmac_priv *priv, unsigned int mtu)
879 + struct stmmac_dma_conf *dma_conf;
880 + int chan, bfsize, ret;
882 + dma_conf = kzalloc(sizeof(*dma_conf), GFP_KERNEL);
884 + netdev_err(priv->dev, "%s: DMA conf allocation failed\n",
886 + return ERR_PTR(-ENOMEM);
889 + bfsize = stmmac_set_16kib_bfsize(priv, mtu);
893 + if (bfsize < BUF_SIZE_16KiB)
894 + bfsize = stmmac_set_bfsize(mtu, 0);
896 + dma_conf->dma_buf_sz = bfsize;
897 + /* Chose the tx/rx size from the already defined one in the
898 + * priv struct. (if defined)
900 + dma_conf->dma_tx_size = priv->dma_conf.dma_tx_size;
901 + dma_conf->dma_rx_size = priv->dma_conf.dma_rx_size;
903 + if (!dma_conf->dma_tx_size)
904 + dma_conf->dma_tx_size = DMA_DEFAULT_TX_SIZE;
905 + if (!dma_conf->dma_rx_size)
906 + dma_conf->dma_rx_size = DMA_DEFAULT_RX_SIZE;
908 + /* Earlier check for TBS */
909 + for (chan = 0; chan < priv->plat->tx_queues_to_use; chan++) {
910 + struct stmmac_tx_queue *tx_q = &dma_conf->tx_queue[chan];
911 + int tbs_en = priv->plat->tx_queues_cfg[chan].tbs_en;
913 + /* Setup per-TXQ tbs flag before TX descriptor alloc */
914 + tx_q->tbs |= tbs_en ? STMMAC_TBS_AVAIL : 0;
917 + ret = alloc_dma_desc_resources(priv, dma_conf);
919 + netdev_err(priv->dev, "%s: DMA descriptors allocation failed\n",
924 + ret = init_dma_desc_rings(priv->dev, dma_conf, GFP_KERNEL);
926 + netdev_err(priv->dev, "%s: DMA descriptors initialization failed\n",
934 + free_dma_desc_resources(priv, dma_conf);
937 + return ERR_PTR(ret);
941 + * __stmmac_open - open entry point of the driver
942 * @dev : pointer to the device structure.
943 + * @dma_conf : structure to take the dma data
945 * This function is the open entry point of the driver.
947 * 0 on success and an appropriate (-)ve integer as defined in errno.h
950 -static int stmmac_open(struct net_device *dev)
951 +static int __stmmac_open(struct net_device *dev,
952 + struct stmmac_dma_conf *dma_conf)
954 struct stmmac_priv *priv = netdev_priv(dev);
955 int mode = priv->plat->phy_interface;
960 @@ -3725,45 +3862,10 @@ static int stmmac_open(struct net_device
961 memset(&priv->xstats, 0, sizeof(struct stmmac_extra_stats));
962 priv->xstats.threshold = tc;
964 - bfsize = stmmac_set_16kib_bfsize(priv, dev->mtu);
968 - if (bfsize < BUF_SIZE_16KiB)
969 - bfsize = stmmac_set_bfsize(dev->mtu, priv->dma_conf.dma_buf_sz);
971 - priv->dma_conf.dma_buf_sz = bfsize;
974 priv->rx_copybreak = STMMAC_RX_COPYBREAK;
976 - if (!priv->dma_conf.dma_tx_size)
977 - priv->dma_conf.dma_tx_size = DMA_DEFAULT_TX_SIZE;
978 - if (!priv->dma_conf.dma_rx_size)
979 - priv->dma_conf.dma_rx_size = DMA_DEFAULT_RX_SIZE;
981 - /* Earlier check for TBS */
982 - for (chan = 0; chan < priv->plat->tx_queues_to_use; chan++) {
983 - struct stmmac_tx_queue *tx_q = &priv->dma_conf.tx_queue[chan];
984 - int tbs_en = priv->plat->tx_queues_cfg[chan].tbs_en;
986 - /* Setup per-TXQ tbs flag before TX descriptor alloc */
987 - tx_q->tbs |= tbs_en ? STMMAC_TBS_AVAIL : 0;
990 - ret = alloc_dma_desc_resources(priv);
992 - netdev_err(priv->dev, "%s: DMA descriptors allocation failed\n",
994 - goto dma_desc_error;
997 - ret = init_dma_desc_rings(dev, GFP_KERNEL);
999 - netdev_err(priv->dev, "%s: DMA descriptors initialization failed\n",
1003 + buf_sz = dma_conf->dma_buf_sz;
1004 + memcpy(&priv->dma_conf, dma_conf, sizeof(*dma_conf));
1006 if (priv->plat->serdes_powerup) {
1007 ret = priv->plat->serdes_powerup(dev, priv->plat->bsp_priv);
1008 @@ -3806,14 +3908,28 @@ irq_error:
1010 stmmac_hw_teardown(dev);
1012 - free_dma_desc_resources(priv);
1014 + free_dma_desc_resources(priv, &priv->dma_conf);
1015 phylink_disconnect_phy(priv->phylink);
1017 pm_runtime_put(priv->device);
1021 +static int stmmac_open(struct net_device *dev)
1023 + struct stmmac_priv *priv = netdev_priv(dev);
1024 + struct stmmac_dma_conf *dma_conf;
1027 + dma_conf = stmmac_setup_dma_desc(priv, dev->mtu);
1028 + if (IS_ERR(dma_conf))
1029 + return PTR_ERR(dma_conf);
1031 + ret = __stmmac_open(dev, dma_conf);
1036 static void stmmac_fpe_stop_wq(struct stmmac_priv *priv)
1038 set_bit(__FPE_REMOVING, &priv->fpe_task_state);
1039 @@ -3862,7 +3978,7 @@ static int stmmac_release(struct net_dev
1040 stmmac_stop_all_dma(priv);
1042 /* Release and free the Rx/Tx resources */
1043 - free_dma_desc_resources(priv);
1044 + free_dma_desc_resources(priv, &priv->dma_conf);
1046 /* Disable the MAC Rx/Tx */
1047 stmmac_mac_set(priv, priv->ioaddr, false);
1048 @@ -6385,7 +6501,7 @@ void stmmac_disable_rx_queue(struct stmm
1049 spin_unlock_irqrestore(&ch->lock, flags);
1051 stmmac_stop_rx_dma(priv, queue);
1052 - __free_dma_rx_desc_resources(priv, queue);
1053 + __free_dma_rx_desc_resources(priv, &priv->dma_conf, queue);
1056 void stmmac_enable_rx_queue(struct stmmac_priv *priv, u32 queue)
1057 @@ -6396,21 +6512,21 @@ void stmmac_enable_rx_queue(struct stmma
1061 - ret = __alloc_dma_rx_desc_resources(priv, queue);
1062 + ret = __alloc_dma_rx_desc_resources(priv, &priv->dma_conf, queue);
1064 netdev_err(priv->dev, "Failed to alloc RX desc.\n");
1068 - ret = __init_dma_rx_desc_rings(priv, queue, GFP_KERNEL);
1069 + ret = __init_dma_rx_desc_rings(priv, &priv->dma_conf, queue, GFP_KERNEL);
1071 - __free_dma_rx_desc_resources(priv, queue);
1072 + __free_dma_rx_desc_resources(priv, &priv->dma_conf, queue);
1073 netdev_err(priv->dev, "Failed to init RX desc.\n");
1077 stmmac_reset_rx_queue(priv, queue);
1078 - stmmac_clear_rx_descriptors(priv, queue);
1079 + stmmac_clear_rx_descriptors(priv, &priv->dma_conf, queue);
1081 stmmac_init_rx_chan(priv, priv->ioaddr, priv->plat->dma_cfg,
1082 rx_q->dma_rx_phy, rx_q->queue_index);
1083 @@ -6448,7 +6564,7 @@ void stmmac_disable_tx_queue(struct stmm
1084 spin_unlock_irqrestore(&ch->lock, flags);
1086 stmmac_stop_tx_dma(priv, queue);
1087 - __free_dma_tx_desc_resources(priv, queue);
1088 + __free_dma_tx_desc_resources(priv, &priv->dma_conf, queue);
1091 void stmmac_enable_tx_queue(struct stmmac_priv *priv, u32 queue)
1092 @@ -6458,21 +6574,21 @@ void stmmac_enable_tx_queue(struct stmma
1093 unsigned long flags;
1096 - ret = __alloc_dma_tx_desc_resources(priv, queue);
1097 + ret = __alloc_dma_tx_desc_resources(priv, &priv->dma_conf, queue);
1099 netdev_err(priv->dev, "Failed to alloc TX desc.\n");
1103 - ret = __init_dma_tx_desc_rings(priv, queue);
1104 + ret = __init_dma_tx_desc_rings(priv, &priv->dma_conf, queue);
1106 - __free_dma_tx_desc_resources(priv, queue);
1107 + __free_dma_tx_desc_resources(priv, &priv->dma_conf, queue);
1108 netdev_err(priv->dev, "Failed to init TX desc.\n");
1112 stmmac_reset_tx_queue(priv, queue);
1113 - stmmac_clear_tx_descriptors(priv, queue);
1114 + stmmac_clear_tx_descriptors(priv, &priv->dma_conf, queue);
1116 stmmac_init_tx_chan(priv, priv->ioaddr, priv->plat->dma_cfg,
1117 tx_q->dma_tx_phy, tx_q->queue_index);
1118 @@ -6512,7 +6628,7 @@ void stmmac_xdp_release(struct net_devic
1119 stmmac_stop_all_dma(priv);
1121 /* Release and free the Rx/Tx resources */
1122 - free_dma_desc_resources(priv);
1123 + free_dma_desc_resources(priv, &priv->dma_conf);
1125 /* Disable the MAC Rx/Tx */
1126 stmmac_mac_set(priv, priv->ioaddr, false);
1127 @@ -6537,14 +6653,14 @@ int stmmac_xdp_open(struct net_device *d
1131 - ret = alloc_dma_desc_resources(priv);
1132 + ret = alloc_dma_desc_resources(priv, &priv->dma_conf);
1134 netdev_err(dev, "%s: DMA descriptors allocation failed\n",
1136 goto dma_desc_error;
1139 - ret = init_dma_desc_rings(dev, GFP_KERNEL);
1140 + ret = init_dma_desc_rings(dev, &priv->dma_conf, GFP_KERNEL);
1142 netdev_err(dev, "%s: DMA descriptors initialization failed\n",
1144 @@ -6626,7 +6742,7 @@ irq_error:
1146 stmmac_hw_teardown(dev);
1148 - free_dma_desc_resources(priv);
1149 + free_dma_desc_resources(priv, &priv->dma_conf);
1153 @@ -7492,7 +7608,7 @@ int stmmac_resume(struct device *dev)
1154 stmmac_reset_queues_param(priv);
1156 stmmac_free_tx_skbufs(priv);
1157 - stmmac_clear_descriptors(priv);
1158 + stmmac_clear_descriptors(priv, &priv->dma_conf);
1160 stmmac_hw_setup(ndev, false);
1161 stmmac_init_coalesce(priv);