287728ba1df5f79b987e5c832b1667d48fe3159e
[openwrt/staging/stintel.git] /
1 From d6d80269cf5c79f9dfe7d69f8b41a72015c89748 Mon Sep 17 00:00:00 2001
2 From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
3 Date: Mon, 3 Apr 2023 19:30:20 +0100
4 Subject: [PATCH 1/5] net: mvneta: fix transmit path dma-unmapping on error
5
6 The transmit code assumes that the transmit descriptors that are used
7 begin with the first descriptor in the ring, but this may not be the
8 case. Fix this by providing a new function that dma-unmaps a range of
9 numbered descriptor entries, and use that to do the unmapping.
10
11 Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
12 ---
13 drivers/net/ethernet/marvell/mvneta.c | 53 +++++++++++++++++----------
14 1 file changed, 33 insertions(+), 20 deletions(-)
15
16 --- a/drivers/net/ethernet/marvell/mvneta.c
17 +++ b/drivers/net/ethernet/marvell/mvneta.c
18 @@ -2647,14 +2647,40 @@ mvneta_tso_put_data(struct net_device *d
19 return 0;
20 }
21
22 +static void mvneta_release_descs(struct mvneta_port *pp,
23 + struct mvneta_tx_queue *txq,
24 + int first, int num)
25 +{
26 + int desc_idx, i;
27 +
28 + desc_idx = first + num;
29 + if (desc_idx >= txq->size)
30 + desc_idx -= txq->size;
31 +
32 + for (i = num; i >= 0; i--) {
33 + struct mvneta_tx_desc *tx_desc = txq->descs + desc_idx;
34 +
35 + if (!IS_TSO_HEADER(txq, tx_desc->buf_phys_addr))
36 + dma_unmap_single(pp->dev->dev.parent,
37 + tx_desc->buf_phys_addr,
38 + tx_desc->data_size,
39 + DMA_TO_DEVICE);
40 +
41 + mvneta_txq_desc_put(txq);
42 +
43 + if (desc_idx == 0)
44 + desc_idx = txq->size;
45 + desc_idx -= 1;
46 + }
47 +}
48 +
49 static int mvneta_tx_tso(struct sk_buff *skb, struct net_device *dev,
50 struct mvneta_tx_queue *txq)
51 {
52 int hdr_len, total_len, data_left;
53 - int desc_count = 0;
54 + int first_desc, desc_count = 0;
55 struct mvneta_port *pp = netdev_priv(dev);
56 struct tso_t tso;
57 - int i;
58
59 /* Count needed descriptors */
60 if ((txq->count + tso_count_descs(skb)) >= txq->size)
61 @@ -2665,6 +2691,8 @@ static int mvneta_tx_tso(struct sk_buff
62 return 0;
63 }
64
65 + first_desc = txq->txq_put_index;
66 +
67 /* Initialize the TSO handler, and prepare the first payload */
68 hdr_len = tso_start(skb, &tso);
69
70 @@ -2705,15 +2733,7 @@ err_release:
71 /* Release all used data descriptors; header descriptors must not
72 * be DMA-unmapped.
73 */
74 - for (i = desc_count - 1; i >= 0; i--) {
75 - struct mvneta_tx_desc *tx_desc = txq->descs + i;
76 - if (!IS_TSO_HEADER(txq, tx_desc->buf_phys_addr))
77 - dma_unmap_single(pp->dev->dev.parent,
78 - tx_desc->buf_phys_addr,
79 - tx_desc->data_size,
80 - DMA_TO_DEVICE);
81 - mvneta_txq_desc_put(txq);
82 - }
83 + mvneta_release_descs(pp, txq, first_desc, desc_count - 1);
84 return 0;
85 }
86
87 @@ -2723,6 +2743,7 @@ static int mvneta_tx_frag_process(struct
88 {
89 struct mvneta_tx_desc *tx_desc;
90 int i, nr_frags = skb_shinfo(skb)->nr_frags;
91 + int first_desc = txq->txq_put_index;
92
93 for (i = 0; i < nr_frags; i++) {
94 struct mvneta_tx_buf *buf = &txq->buf[txq->txq_put_index];
95 @@ -2761,15 +2782,7 @@ error:
96 /* Release all descriptors that were used to map fragments of
97 * this packet, as well as the corresponding DMA mappings
98 */
99 - for (i = i - 1; i >= 0; i--) {
100 - tx_desc = txq->descs + i;
101 - dma_unmap_single(pp->dev->dev.parent,
102 - tx_desc->buf_phys_addr,
103 - tx_desc->data_size,
104 - DMA_TO_DEVICE);
105 - mvneta_txq_desc_put(txq);
106 - }
107 -
108 + mvneta_release_descs(pp, txq, first_desc, i - 1);
109 return -ENOMEM;
110 }
111