750-v6.5-07-net-ethernet-mtk_eth_soc-rely-on-MTK_MAX_DEVS-and-re.patch 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. From 856be974290f28d7943be2ac5a382c4139486196 Mon Sep 17 00:00:00 2001
  2. From: Lorenzo Bianconi <[email protected]>
  3. Date: Tue, 25 Jul 2023 01:52:44 +0100
  4. Subject: [PATCH 101/250] net: ethernet: mtk_eth_soc: rely on MTK_MAX_DEVS and
  5. remove MTK_MAC_COUNT
  6. Get rid of MTK_MAC_COUNT since it is a duplicated of MTK_MAX_DEVS.
  7. Signed-off-by: Lorenzo Bianconi <[email protected]>
  8. Signed-off-by: Daniel Golle <[email protected]>
  9. Link: https://lore.kernel.org/r/1856f4266f2fc80677807b1bad867659e7b00c65.1690246066.git.daniel@makrotopia.org
  10. Signed-off-by: Jakub Kicinski <[email protected]>
  11. ---
  12. drivers/net/ethernet/mediatek/mtk_eth_soc.c | 49 ++++++++++++---------
  13. drivers/net/ethernet/mediatek/mtk_eth_soc.h | 1 -
  14. 2 files changed, 27 insertions(+), 23 deletions(-)
  15. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  16. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  17. @@ -838,7 +838,7 @@ static void mtk_stats_update(struct mtk_
  18. {
  19. int i;
  20. - for (i = 0; i < MTK_MAC_COUNT; i++) {
  21. + for (i = 0; i < MTK_MAX_DEVS; i++) {
  22. if (!eth->mac[i] || !eth->mac[i]->hw_stats)
  23. continue;
  24. if (spin_trylock(&eth->mac[i]->hw_stats->stats_lock)) {
  25. @@ -1341,7 +1341,7 @@ static int mtk_queue_stopped(struct mtk_
  26. {
  27. int i;
  28. - for (i = 0; i < MTK_MAC_COUNT; i++) {
  29. + for (i = 0; i < MTK_MAX_DEVS; i++) {
  30. if (!eth->netdev[i])
  31. continue;
  32. if (netif_queue_stopped(eth->netdev[i]))
  33. @@ -1355,7 +1355,7 @@ static void mtk_wake_queue(struct mtk_et
  34. {
  35. int i;
  36. - for (i = 0; i < MTK_MAC_COUNT; i++) {
  37. + for (i = 0; i < MTK_MAX_DEVS; i++) {
  38. if (!eth->netdev[i])
  39. continue;
  40. netif_tx_wake_all_queues(eth->netdev[i]);
  41. @@ -1812,7 +1812,7 @@ static int mtk_poll_rx(struct napi_struc
  42. !(trxd.rxd4 & RX_DMA_SPECIAL_TAG))
  43. mac = RX_DMA_GET_SPORT(trxd.rxd4) - 1;
  44. - if (unlikely(mac < 0 || mac >= MTK_MAC_COUNT ||
  45. + if (unlikely(mac < 0 || mac >= MTK_MAX_DEVS ||
  46. !eth->netdev[mac]))
  47. goto release_desc;
  48. @@ -2844,7 +2844,7 @@ static void mtk_dma_free(struct mtk_eth
  49. const struct mtk_soc_data *soc = eth->soc;
  50. int i;
  51. - for (i = 0; i < MTK_MAC_COUNT; i++)
  52. + for (i = 0; i < MTK_MAX_DEVS; i++)
  53. if (eth->netdev[i])
  54. netdev_reset_queue(eth->netdev[i]);
  55. if (eth->scratch_ring) {
  56. @@ -2998,8 +2998,13 @@ static void mtk_gdm_config(struct mtk_et
  57. if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628))
  58. return;
  59. - for (i = 0; i < MTK_MAC_COUNT; i++) {
  60. - u32 val = mtk_r32(eth, MTK_GDMA_FWD_CFG(i));
  61. + for (i = 0; i < MTK_MAX_DEVS; i++) {
  62. + u32 val;
  63. +
  64. + if (!eth->netdev[i])
  65. + continue;
  66. +
  67. + val = mtk_r32(eth, MTK_GDMA_FWD_CFG(i));
  68. /* default setup the forward port to send frame to PDMA */
  69. val &= ~0xffff;
  70. @@ -3009,7 +3014,7 @@ static void mtk_gdm_config(struct mtk_et
  71. val |= config;
  72. - if (eth->netdev[i] && netdev_uses_dsa(eth->netdev[i]))
  73. + if (netdev_uses_dsa(eth->netdev[i]))
  74. val |= MTK_GDMA_SPECIAL_TAG;
  75. mtk_w32(eth, val, MTK_GDMA_FWD_CFG(i));
  76. @@ -3608,15 +3613,15 @@ static int mtk_hw_init(struct mtk_eth *e
  77. * up with the more appropriate value when mtk_mac_config call is being
  78. * invoked.
  79. */
  80. - for (i = 0; i < MTK_MAC_COUNT; i++) {
  81. + for (i = 0; i < MTK_MAX_DEVS; i++) {
  82. struct net_device *dev = eth->netdev[i];
  83. - mtk_w32(eth, MAC_MCR_FORCE_LINK_DOWN, MTK_MAC_MCR(i));
  84. - if (dev) {
  85. - struct mtk_mac *mac = netdev_priv(dev);
  86. + if (!dev)
  87. + continue;
  88. - mtk_set_mcr_max_rx(mac, dev->mtu + MTK_RX_ETH_HLEN);
  89. - }
  90. + mtk_w32(eth, MAC_MCR_FORCE_LINK_DOWN, MTK_MAC_MCR(i));
  91. + mtk_set_mcr_max_rx(netdev_priv(dev),
  92. + dev->mtu + MTK_RX_ETH_HLEN);
  93. }
  94. /* Indicates CDM to parse the MTK special tag from CPU
  95. @@ -3796,7 +3801,7 @@ static void mtk_pending_work(struct work
  96. mtk_prepare_for_reset(eth);
  97. /* stop all devices to make sure that dma is properly shut down */
  98. - for (i = 0; i < MTK_MAC_COUNT; i++) {
  99. + for (i = 0; i < MTK_MAX_DEVS; i++) {
  100. if (!eth->netdev[i] || !netif_running(eth->netdev[i]))
  101. continue;
  102. @@ -3812,8 +3817,8 @@ static void mtk_pending_work(struct work
  103. mtk_hw_init(eth, true);
  104. /* restart DMA and enable IRQs */
  105. - for (i = 0; i < MTK_MAC_COUNT; i++) {
  106. - if (!test_bit(i, &restart))
  107. + for (i = 0; i < MTK_MAX_DEVS; i++) {
  108. + if (!eth->netdev[i] || !test_bit(i, &restart))
  109. continue;
  110. if (mtk_open(eth->netdev[i])) {
  111. @@ -3840,7 +3845,7 @@ static int mtk_free_dev(struct mtk_eth *
  112. {
  113. int i;
  114. - for (i = 0; i < MTK_MAC_COUNT; i++) {
  115. + for (i = 0; i < MTK_MAX_DEVS; i++) {
  116. if (!eth->netdev[i])
  117. continue;
  118. free_netdev(eth->netdev[i]);
  119. @@ -3859,7 +3864,7 @@ static int mtk_unreg_dev(struct mtk_eth
  120. {
  121. int i;
  122. - for (i = 0; i < MTK_MAC_COUNT; i++) {
  123. + for (i = 0; i < MTK_MAX_DEVS; i++) {
  124. struct mtk_mac *mac;
  125. if (!eth->netdev[i])
  126. continue;
  127. @@ -4160,7 +4165,7 @@ static int mtk_add_mac(struct mtk_eth *e
  128. }
  129. id = be32_to_cpup(_id);
  130. - if (id >= MTK_MAC_COUNT) {
  131. + if (id >= MTK_MAX_DEVS) {
  132. dev_err(eth->dev, "%d is not a valid mac id\n", id);
  133. return -EINVAL;
  134. }
  135. @@ -4305,7 +4310,7 @@ void mtk_eth_set_dma_device(struct mtk_e
  136. rtnl_lock();
  137. - for (i = 0; i < MTK_MAC_COUNT; i++) {
  138. + for (i = 0; i < MTK_MAX_DEVS; i++) {
  139. dev = eth->netdev[i];
  140. if (!dev || !(dev->flags & IFF_UP))
  141. @@ -4613,7 +4618,7 @@ static int mtk_remove(struct platform_de
  142. int i;
  143. /* stop all devices to make sure that dma is properly shut down */
  144. - for (i = 0; i < MTK_MAC_COUNT; i++) {
  145. + for (i = 0; i < MTK_MAX_DEVS; i++) {
  146. if (!eth->netdev[i])
  147. continue;
  148. mtk_stop(eth->netdev[i]);
  149. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
  150. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
  151. @@ -33,7 +33,6 @@
  152. #define MTK_TX_DMA_BUF_LEN_V2 0xffff
  153. #define MTK_QDMA_RING_SIZE 2048
  154. #define MTK_DMA_SIZE 512
  155. -#define MTK_MAC_COUNT 2
  156. #define MTK_RX_ETH_HLEN (VLAN_ETH_HLEN + ETH_FCS_LEN)
  157. #define MTK_RX_HLEN (NET_SKB_PAD + MTK_RX_ETH_HLEN + NET_IP_ALIGN)
  158. #define MTK_DMA_DUMMY_DESC 0xffffffff