mtd: fix build with GCC 14
[openwrt/openwrt.git] / target / linux / generic / pending-5.15 / 732-01-net-ethernet-mtk_eth_soc-work-around-issue-with-send.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Thu, 3 Nov 2022 12:38:49 +0100
3 Subject: [PATCH] net: ethernet: mtk_eth_soc: work around issue with sending
4 small fragments
5
6 When lots of frames are sent with a number of very small fragments, an
7 internal FIFO can overflow, causing the DMA engine to lock up lock up and
8 transmit attempts time out.
9
10 Fix this on MT7986 by increasing the reserved FIFO space.
11 Fix this on older chips by detecting the presence of small fragments and use
12 skb_gso_segment + skb_linearize to deal with them.
13
14 Signed-off-by: Felix Fietkau <nbd@nbd.name>
15 ---
16
17 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
18 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
19 @@ -1517,12 +1517,28 @@ static void mtk_wake_queue(struct mtk_et
20 }
21 }
22
23 +static bool mtk_skb_has_small_frag(struct sk_buff *skb)
24 +{
25 + int min_size = 16;
26 + int i;
27 +
28 + if (skb_headlen(skb) < min_size)
29 + return true;
30 +
31 + for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
32 + if (skb_frag_size(&skb_shinfo(skb)->frags[i]) < min_size)
33 + return true;
34 +
35 + return false;
36 +}
37 +
38 static netdev_tx_t mtk_start_xmit(struct sk_buff *skb, struct net_device *dev)
39 {
40 struct mtk_mac *mac = netdev_priv(dev);
41 struct mtk_eth *eth = mac->hw;
42 struct mtk_tx_ring *ring = &eth->tx_ring;
43 struct net_device_stats *stats = &dev->stats;
44 + struct sk_buff *segs, *next;
45 bool gso = false;
46 int tx_num;
47
48 @@ -1544,6 +1560,18 @@ static netdev_tx_t mtk_start_xmit(struct
49 return NETDEV_TX_BUSY;
50 }
51
52 + if (mtk_is_netsys_v1(eth) &&
53 + skb_is_gso(skb) && mtk_skb_has_small_frag(skb)) {
54 + segs = skb_gso_segment(skb, dev->features & ~NETIF_F_ALL_TSO);
55 + if (IS_ERR(segs))
56 + goto drop;
57 +
58 + if (segs) {
59 + consume_skb(skb);
60 + skb = segs;
61 + }
62 + }
63 +
64 /* TSO: fill MSS info in tcp checksum field */
65 if (skb_is_gso(skb)) {
66 if (skb_cow_head(skb, 0)) {
67 @@ -1559,8 +1587,14 @@ static netdev_tx_t mtk_start_xmit(struct
68 }
69 }
70
71 - if (mtk_tx_map(skb, dev, tx_num, ring, gso) < 0)
72 - goto drop;
73 + skb_list_walk_safe(skb, skb, next) {
74 + if ((mtk_is_netsys_v1(eth) &&
75 + mtk_skb_has_small_frag(skb) && skb_linearize(skb)) ||
76 + mtk_tx_map(skb, dev, tx_num, ring, gso) < 0) {
77 + stats->tx_dropped++;
78 + dev_kfree_skb_any(skb);
79 + }
80 + }
81
82 if (unlikely(atomic_read(&ring->free_count) <= ring->thresh))
83 netif_tx_stop_all_queues(dev);
84 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
85 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
86 @@ -268,7 +268,7 @@
87 #define MTK_CHK_DDONE_EN BIT(28)
88 #define MTK_DMAD_WR_WDONE BIT(26)
89 #define MTK_WCOMP_EN BIT(24)
90 -#define MTK_RESV_BUF (0x40 << 16)
91 +#define MTK_RESV_BUF (0x80 << 16)
92 #define MTK_MUTLI_CNT (0x4 << 12)
93 #define MTK_LEAKY_BUCKET_EN BIT(11)
94