17c7d92ce08eb3ec7a332bbee6e9ed16cd945694
[openwrt/staging/981213.git] / target / linux / generic / pending-6.6 / 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 @@ -26,6 +26,7 @@
20 #include <linux/bitfield.h>
21 #include <net/dsa.h>
22 #include <net/dst_metadata.h>
23 +#include <net/gso.h>
24 #include <net/page_pool/helpers.h>
25
26 #include "mtk_eth_soc.h"
27 @@ -1562,12 +1562,28 @@ static void mtk_wake_queue(struct mtk_et
28 }
29 }
30
31 +static bool mtk_skb_has_small_frag(struct sk_buff *skb)
32 +{
33 + int min_size = 16;
34 + int i;
35 +
36 + if (skb_headlen(skb) < min_size)
37 + return true;
38 +
39 + for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
40 + if (skb_frag_size(&skb_shinfo(skb)->frags[i]) < min_size)
41 + return true;
42 +
43 + return false;
44 +}
45 +
46 static netdev_tx_t mtk_start_xmit(struct sk_buff *skb, struct net_device *dev)
47 {
48 struct mtk_mac *mac = netdev_priv(dev);
49 struct mtk_eth *eth = mac->hw;
50 struct mtk_tx_ring *ring = &eth->tx_ring;
51 struct net_device_stats *stats = &dev->stats;
52 + struct sk_buff *segs, *next;
53 bool gso = false;
54 int tx_num;
55
56 @@ -1589,6 +1605,18 @@ static netdev_tx_t mtk_start_xmit(struct
57 return NETDEV_TX_BUSY;
58 }
59
60 + if (mtk_is_netsys_v1(eth) &&
61 + skb_is_gso(skb) && mtk_skb_has_small_frag(skb)) {
62 + segs = skb_gso_segment(skb, dev->features & ~NETIF_F_ALL_TSO);
63 + if (IS_ERR(segs))
64 + goto drop;
65 +
66 + if (segs) {
67 + consume_skb(skb);
68 + skb = segs;
69 + }
70 + }
71 +
72 /* TSO: fill MSS info in tcp checksum field */
73 if (skb_is_gso(skb)) {
74 if (skb_cow_head(skb, 0)) {
75 @@ -1604,8 +1632,14 @@ static netdev_tx_t mtk_start_xmit(struct
76 }
77 }
78
79 - if (mtk_tx_map(skb, dev, tx_num, ring, gso) < 0)
80 - goto drop;
81 + skb_list_walk_safe(skb, skb, next) {
82 + if ((mtk_is_netsys_v1(eth) &&
83 + mtk_skb_has_small_frag(skb) && skb_linearize(skb)) ||
84 + mtk_tx_map(skb, dev, tx_num, ring, gso) < 0) {
85 + stats->tx_dropped++;
86 + dev_kfree_skb_any(skb);
87 + }
88 + }
89
90 if (unlikely(atomic_read(&ring->free_count) <= ring->thresh))
91 netif_tx_stop_all_queues(dev);
92 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
93 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
94 @@ -268,7 +268,7 @@
95 #define MTK_CHK_DDONE_EN BIT(28)
96 #define MTK_DMAD_WR_WDONE BIT(26)
97 #define MTK_WCOMP_EN BIT(24)
98 -#define MTK_RESV_BUF (0x40 << 16)
99 +#define MTK_RESV_BUF (0x80 << 16)
100 #define MTK_MUTLI_CNT (0x4 << 12)
101 #define MTK_LEAKY_BUCKET_EN BIT(11)
102