2
0

729-06-v6.1-net-ethernet-mtk_eth_soc-do-not-overwrite-mtu-config.patch 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. From: Lorenzo Bianconi <[email protected]>
  2. Date: Thu, 17 Nov 2022 00:35:04 +0100
  3. Subject: [PATCH] net: ethernet: mtk_eth_soc: do not overwrite mtu
  4. configuration running reset routine
  5. Restore user configured MTU running mtk_hw_init() during tx timeout routine
  6. since it will be overwritten after a hw reset.
  7. Reported-by: Felix Fietkau <[email protected]>
  8. Fixes: 9ea4d311509f ("net: ethernet: mediatek: add the whole ethernet reset into the reset process")
  9. Signed-off-by: Lorenzo Bianconi <[email protected]>
  10. Signed-off-by: David S. Miller <[email protected]>
  11. ---
  12. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  13. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  14. @@ -3176,6 +3176,30 @@ static void mtk_dim_tx(struct work_struc
  15. dim->state = DIM_START_MEASURE;
  16. }
  17. +static void mtk_set_mcr_max_rx(struct mtk_mac *mac, u32 val)
  18. +{
  19. + struct mtk_eth *eth = mac->hw;
  20. + u32 mcr_cur, mcr_new;
  21. +
  22. + if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628))
  23. + return;
  24. +
  25. + mcr_cur = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id));
  26. + mcr_new = mcr_cur & ~MAC_MCR_MAX_RX_MASK;
  27. +
  28. + if (val <= 1518)
  29. + mcr_new |= MAC_MCR_MAX_RX(MAC_MCR_MAX_RX_1518);
  30. + else if (val <= 1536)
  31. + mcr_new |= MAC_MCR_MAX_RX(MAC_MCR_MAX_RX_1536);
  32. + else if (val <= 1552)
  33. + mcr_new |= MAC_MCR_MAX_RX(MAC_MCR_MAX_RX_1552);
  34. + else
  35. + mcr_new |= MAC_MCR_MAX_RX(MAC_MCR_MAX_RX_2048);
  36. +
  37. + if (mcr_new != mcr_cur)
  38. + mtk_w32(mac->hw, mcr_new, MTK_MAC_MCR(mac->id));
  39. +}
  40. +
  41. static int mtk_hw_init(struct mtk_eth *eth)
  42. {
  43. u32 dma_mask = ETHSYS_DMA_AG_MAP_PDMA | ETHSYS_DMA_AG_MAP_QDMA |
  44. @@ -3250,8 +3274,16 @@ static int mtk_hw_init(struct mtk_eth *e
  45. * up with the more appropriate value when mtk_mac_config call is being
  46. * invoked.
  47. */
  48. - for (i = 0; i < MTK_MAC_COUNT; i++)
  49. + for (i = 0; i < MTK_MAC_COUNT; i++) {
  50. + struct net_device *dev = eth->netdev[i];
  51. +
  52. mtk_w32(eth, MAC_MCR_FORCE_LINK_DOWN, MTK_MAC_MCR(i));
  53. + if (dev) {
  54. + struct mtk_mac *mac = netdev_priv(dev);
  55. +
  56. + mtk_set_mcr_max_rx(mac, dev->mtu + MTK_RX_ETH_HLEN);
  57. + }
  58. + }
  59. /* Indicates CDM to parse the MTK special tag from CPU
  60. * which also is working out for untag packets.
  61. @@ -3367,7 +3399,6 @@ static int mtk_change_mtu(struct net_dev
  62. int length = new_mtu + MTK_RX_ETH_HLEN;
  63. struct mtk_mac *mac = netdev_priv(dev);
  64. struct mtk_eth *eth = mac->hw;
  65. - u32 mcr_cur, mcr_new;
  66. if (rcu_access_pointer(eth->prog) &&
  67. length > MTK_PP_MAX_BUF_SIZE) {
  68. @@ -3375,23 +3406,7 @@ static int mtk_change_mtu(struct net_dev
  69. return -EINVAL;
  70. }
  71. - if (!MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628)) {
  72. - mcr_cur = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id));
  73. - mcr_new = mcr_cur & ~MAC_MCR_MAX_RX_MASK;
  74. -
  75. - if (length <= 1518)
  76. - mcr_new |= MAC_MCR_MAX_RX(MAC_MCR_MAX_RX_1518);
  77. - else if (length <= 1536)
  78. - mcr_new |= MAC_MCR_MAX_RX(MAC_MCR_MAX_RX_1536);
  79. - else if (length <= 1552)
  80. - mcr_new |= MAC_MCR_MAX_RX(MAC_MCR_MAX_RX_1552);
  81. - else
  82. - mcr_new |= MAC_MCR_MAX_RX(MAC_MCR_MAX_RX_2048);
  83. -
  84. - if (mcr_new != mcr_cur)
  85. - mtk_w32(mac->hw, mcr_new, MTK_MAC_MCR(mac->id));
  86. - }
  87. -
  88. + mtk_set_mcr_max_rx(mac, length);
  89. dev->mtu = new_mtu;
  90. return 0;