732-10-net-ethernet-mtk_eth_soc-work-around-issue-with-send.patch 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. From: Felix Fietkau <[email protected]>
  2. Date: Thu, 3 Nov 2022 12:38:49 +0100
  3. Subject: [PATCH] net: ethernet: mtk_eth_soc: work around issue with
  4. sending small fragments
  5. When frames are sent with very small fragments, the DMA engine appears to
  6. lock up and transmit attempts time out. Fix this by detecting the presence
  7. of small fragments and use skb_gso_segment + skb_linearize to deal with
  8. them
  9. Signed-off-by: Felix Fietkau <[email protected]>
  10. ---
  11. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  12. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  13. @@ -1396,12 +1396,28 @@ static void mtk_wake_queue(struct mtk_et
  14. }
  15. }
  16. +static bool mtk_skb_has_small_frag(struct sk_buff *skb)
  17. +{
  18. + int min_size = 16;
  19. + int i;
  20. +
  21. + if (skb_headlen(skb) < min_size)
  22. + return true;
  23. +
  24. + for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
  25. + if (skb_frag_size(&skb_shinfo(skb)->frags[i]) < min_size)
  26. + return true;
  27. +
  28. + return false;
  29. +}
  30. +
  31. static netdev_tx_t mtk_start_xmit(struct sk_buff *skb, struct net_device *dev)
  32. {
  33. struct mtk_mac *mac = netdev_priv(dev);
  34. struct mtk_eth *eth = mac->hw;
  35. struct mtk_tx_ring *ring = &eth->tx_ring;
  36. struct net_device_stats *stats = &dev->stats;
  37. + struct sk_buff *segs, *next;
  38. bool gso = false;
  39. int tx_num;
  40. @@ -1423,6 +1439,17 @@ static netdev_tx_t mtk_start_xmit(struct
  41. return NETDEV_TX_BUSY;
  42. }
  43. + if (skb_is_gso(skb) && mtk_skb_has_small_frag(skb)) {
  44. + segs = skb_gso_segment(skb, dev->features & ~NETIF_F_ALL_TSO);
  45. + if (IS_ERR(segs))
  46. + goto drop;
  47. +
  48. + if (segs) {
  49. + consume_skb(skb);
  50. + skb = segs;
  51. + }
  52. + }
  53. +
  54. /* TSO: fill MSS info in tcp checksum field */
  55. if (skb_is_gso(skb)) {
  56. if (skb_cow_head(skb, 0)) {
  57. @@ -1438,8 +1465,13 @@ static netdev_tx_t mtk_start_xmit(struct
  58. }
  59. }
  60. - if (mtk_tx_map(skb, dev, tx_num, ring, gso) < 0)
  61. - goto drop;
  62. + skb_list_walk_safe(skb, skb, next) {
  63. + if ((mtk_skb_has_small_frag(skb) && skb_linearize(skb)) ||
  64. + mtk_tx_map(skb, dev, tx_num, ring, gso) < 0) {
  65. + stats->tx_dropped++;
  66. + dev_kfree_skb_any(skb);
  67. + }
  68. + }
  69. if (unlikely(atomic_read(&ring->free_count) <= ring->thresh))
  70. netif_tx_stop_all_queues(dev);