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
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.
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.
14 Signed-off-by: Felix Fietkau <nbd@nbd.name>
17 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
18 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
19 @@ -1516,12 +1516,28 @@ static void mtk_wake_queue(struct mtk_et
23 +static bool mtk_skb_has_small_frag(struct sk_buff *skb)
28 + if (skb_headlen(skb) < min_size)
31 + for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
32 + if (skb_frag_size(&skb_shinfo(skb)->frags[i]) < min_size)
38 static netdev_tx_t mtk_start_xmit(struct sk_buff *skb, struct net_device *dev)
40 struct mtk_mac *mac = netdev_priv(dev);
41 struct mtk_eth *eth = mac->hw;
42 struct mtk_tx_ring *ring = ð->tx_ring;
43 struct net_device_stats *stats = &dev->stats;
44 + struct sk_buff *segs, *next;
48 @@ -1543,6 +1559,18 @@ static netdev_tx_t mtk_start_xmit(struct
49 return NETDEV_TX_BUSY;
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);
64 /* TSO: fill MSS info in tcp checksum field */
65 if (skb_is_gso(skb)) {
66 if (skb_cow_head(skb, 0)) {
67 @@ -1558,8 +1586,14 @@ static netdev_tx_t mtk_start_xmit(struct
71 - if (mtk_tx_map(skb, dev, tx_num, ring, gso) < 0)
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);
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
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)