729-20-v6.3-net-ethernet-mtk_eth_soc-align-reset-procedure-to-ve.patch 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. From: Lorenzo Bianconi <[email protected]>
  2. Date: Sat, 14 Jan 2023 18:01:30 +0100
  3. Subject: [PATCH] net: ethernet: mtk_eth_soc: align reset procedure to vendor
  4. sdk
  5. Avoid to power-down the ethernet chip during hw reset and align reset
  6. procedure to vendor sdk.
  7. Reviewed-by: Leon Romanovsky <[email protected]>
  8. Tested-by: Daniel Golle <[email protected]>
  9. Co-developed-by: Sujuan Chen <[email protected]>
  10. Signed-off-by: Sujuan Chen <[email protected]>
  11. Signed-off-by: Lorenzo Bianconi <[email protected]>
  12. Signed-off-by: Paolo Abeni <[email protected]>
  13. ---
  14. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  15. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  16. @@ -2785,14 +2785,29 @@ static void mtk_dma_free(struct mtk_eth
  17. kfree(eth->scratch_head);
  18. }
  19. +static bool mtk_hw_reset_check(struct mtk_eth *eth)
  20. +{
  21. + u32 val = mtk_r32(eth, MTK_INT_STATUS2);
  22. +
  23. + return (val & MTK_FE_INT_FQ_EMPTY) || (val & MTK_FE_INT_RFIFO_UF) ||
  24. + (val & MTK_FE_INT_RFIFO_OV) || (val & MTK_FE_INT_TSO_FAIL) ||
  25. + (val & MTK_FE_INT_TSO_ALIGN) || (val & MTK_FE_INT_TSO_ILLEGAL);
  26. +}
  27. +
  28. static void mtk_tx_timeout(struct net_device *dev, unsigned int txqueue)
  29. {
  30. struct mtk_mac *mac = netdev_priv(dev);
  31. struct mtk_eth *eth = mac->hw;
  32. + if (test_bit(MTK_RESETTING, &eth->state))
  33. + return;
  34. +
  35. + if (!mtk_hw_reset_check(eth))
  36. + return;
  37. +
  38. eth->netdev[mac->id]->stats.tx_errors++;
  39. - netif_err(eth, tx_err, dev,
  40. - "transmit timed out\n");
  41. + netif_err(eth, tx_err, dev, "transmit timed out\n");
  42. +
  43. schedule_work(&eth->pending_work);
  44. }
  45. @@ -3274,15 +3289,17 @@ static int mtk_hw_init(struct mtk_eth *e
  46. const struct mtk_reg_map *reg_map = eth->soc->reg_map;
  47. int i, val, ret;
  48. - if (test_and_set_bit(MTK_HW_INIT, &eth->state))
  49. + if (!reset && test_and_set_bit(MTK_HW_INIT, &eth->state))
  50. return 0;
  51. - pm_runtime_enable(eth->dev);
  52. - pm_runtime_get_sync(eth->dev);
  53. + if (!reset) {
  54. + pm_runtime_enable(eth->dev);
  55. + pm_runtime_get_sync(eth->dev);
  56. - ret = mtk_clk_enable(eth);
  57. - if (ret)
  58. - goto err_disable_pm;
  59. + ret = mtk_clk_enable(eth);
  60. + if (ret)
  61. + goto err_disable_pm;
  62. + }
  63. if (eth->ethsys)
  64. regmap_update_bits(eth->ethsys, ETHSYS_DMA_AG_MAP, dma_mask,
  65. @@ -3408,8 +3425,10 @@ static int mtk_hw_init(struct mtk_eth *e
  66. return 0;
  67. err_disable_pm:
  68. - pm_runtime_put_sync(eth->dev);
  69. - pm_runtime_disable(eth->dev);
  70. + if (!reset) {
  71. + pm_runtime_put_sync(eth->dev);
  72. + pm_runtime_disable(eth->dev);
  73. + }
  74. return ret;
  75. }
  76. @@ -3488,30 +3507,53 @@ static int mtk_do_ioctl(struct net_devic
  77. return -EOPNOTSUPP;
  78. }
  79. +static void mtk_prepare_for_reset(struct mtk_eth *eth)
  80. +{
  81. + u32 val;
  82. + int i;
  83. +
  84. + /* disabe FE P3 and P4 */
  85. + val = mtk_r32(eth, MTK_FE_GLO_CFG) | MTK_FE_LINK_DOWN_P3;
  86. + if (MTK_HAS_CAPS(eth->soc->caps, MTK_RSTCTRL_PPE1))
  87. + val |= MTK_FE_LINK_DOWN_P4;
  88. + mtk_w32(eth, val, MTK_FE_GLO_CFG);
  89. +
  90. + /* adjust PPE configurations to prepare for reset */
  91. + for (i = 0; i < ARRAY_SIZE(eth->ppe); i++)
  92. + mtk_ppe_prepare_reset(eth->ppe[i]);
  93. +
  94. + /* disable NETSYS interrupts */
  95. + mtk_w32(eth, 0, MTK_FE_INT_ENABLE);
  96. +
  97. + /* force link down GMAC */
  98. + for (i = 0; i < 2; i++) {
  99. + val = mtk_r32(eth, MTK_MAC_MCR(i)) & ~MAC_MCR_FORCE_LINK;
  100. + mtk_w32(eth, val, MTK_MAC_MCR(i));
  101. + }
  102. +}
  103. +
  104. static void mtk_pending_work(struct work_struct *work)
  105. {
  106. struct mtk_eth *eth = container_of(work, struct mtk_eth, pending_work);
  107. - int err, i;
  108. unsigned long restart = 0;
  109. + u32 val;
  110. + int i;
  111. rtnl_lock();
  112. -
  113. - dev_dbg(eth->dev, "[%s][%d] reset\n", __func__, __LINE__);
  114. set_bit(MTK_RESETTING, &eth->state);
  115. + mtk_prepare_for_reset(eth);
  116. +
  117. /* stop all devices to make sure that dma is properly shut down */
  118. for (i = 0; i < MTK_MAC_COUNT; i++) {
  119. - if (!eth->netdev[i])
  120. + if (!eth->netdev[i] || !netif_running(eth->netdev[i]))
  121. continue;
  122. +
  123. mtk_stop(eth->netdev[i]);
  124. __set_bit(i, &restart);
  125. }
  126. - dev_dbg(eth->dev, "[%s][%d] mtk_stop ends\n", __func__, __LINE__);
  127. - /* restart underlying hardware such as power, clock, pin mux
  128. - * and the connected phy
  129. - */
  130. - mtk_hw_deinit(eth);
  131. + usleep_range(15000, 16000);
  132. if (eth->dev->pins)
  133. pinctrl_select_state(eth->dev->pins->p,
  134. @@ -3522,15 +3564,19 @@ static void mtk_pending_work(struct work
  135. for (i = 0; i < MTK_MAC_COUNT; i++) {
  136. if (!test_bit(i, &restart))
  137. continue;
  138. - err = mtk_open(eth->netdev[i]);
  139. - if (err) {
  140. +
  141. + if (mtk_open(eth->netdev[i])) {
  142. netif_alert(eth, ifup, eth->netdev[i],
  143. - "Driver up/down cycle failed, closing device.\n");
  144. + "Driver up/down cycle failed\n");
  145. dev_close(eth->netdev[i]);
  146. }
  147. }
  148. - dev_dbg(eth->dev, "[%s][%d] reset done\n", __func__, __LINE__);
  149. + /* enabe FE P3 and P4 */
  150. + val = mtk_r32(eth, MTK_FE_GLO_CFG) & ~MTK_FE_LINK_DOWN_P3;
  151. + if (MTK_HAS_CAPS(eth->soc->caps, MTK_RSTCTRL_PPE1))
  152. + val &= ~MTK_FE_LINK_DOWN_P4;
  153. + mtk_w32(eth, val, MTK_FE_GLO_CFG);
  154. clear_bit(MTK_RESETTING, &eth->state);
  155. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
  156. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
  157. @@ -72,12 +72,24 @@
  158. #define MTK_HW_LRO_REPLACE_DELTA 1000
  159. #define MTK_HW_LRO_SDL_REMAIN_ROOM 1522
  160. +/* Frame Engine Global Configuration */
  161. +#define MTK_FE_GLO_CFG 0x00
  162. +#define MTK_FE_LINK_DOWN_P3 BIT(11)
  163. +#define MTK_FE_LINK_DOWN_P4 BIT(12)
  164. +
  165. /* Frame Engine Global Reset Register */
  166. #define MTK_RST_GL 0x04
  167. #define RST_GL_PSE BIT(0)
  168. /* Frame Engine Interrupt Status Register */
  169. #define MTK_INT_STATUS2 0x08
  170. +#define MTK_FE_INT_ENABLE 0x0c
  171. +#define MTK_FE_INT_FQ_EMPTY BIT(8)
  172. +#define MTK_FE_INT_TSO_FAIL BIT(12)
  173. +#define MTK_FE_INT_TSO_ILLEGAL BIT(13)
  174. +#define MTK_FE_INT_TSO_ALIGN BIT(14)
  175. +#define MTK_FE_INT_RFIFO_OV BIT(18)
  176. +#define MTK_FE_INT_RFIFO_UF BIT(19)
  177. #define MTK_GDM1_AF BIT(28)
  178. #define MTK_GDM2_AF BIT(29)
  179. --- a/drivers/net/ethernet/mediatek/mtk_ppe.c
  180. +++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
  181. @@ -716,6 +716,33 @@ int mtk_foe_entry_idle_time(struct mtk_p
  182. return __mtk_foe_entry_idle_time(ppe, entry->data.ib1);
  183. }
  184. +int mtk_ppe_prepare_reset(struct mtk_ppe *ppe)
  185. +{
  186. + if (!ppe)
  187. + return -EINVAL;
  188. +
  189. + /* disable KA */
  190. + ppe_clear(ppe, MTK_PPE_TB_CFG, MTK_PPE_TB_CFG_KEEPALIVE);
  191. + ppe_clear(ppe, MTK_PPE_BIND_LMT1, MTK_PPE_NTU_KEEPALIVE);
  192. + ppe_w32(ppe, MTK_PPE_KEEPALIVE, 0);
  193. + usleep_range(10000, 11000);
  194. +
  195. + /* set KA timer to maximum */
  196. + ppe_set(ppe, MTK_PPE_BIND_LMT1, MTK_PPE_NTU_KEEPALIVE);
  197. + ppe_w32(ppe, MTK_PPE_KEEPALIVE, 0xffffffff);
  198. +
  199. + /* set KA tick select */
  200. + ppe_set(ppe, MTK_PPE_TB_CFG, MTK_PPE_TB_TICK_SEL);
  201. + ppe_set(ppe, MTK_PPE_TB_CFG, MTK_PPE_TB_CFG_KEEPALIVE);
  202. + usleep_range(10000, 11000);
  203. +
  204. + /* disable scan mode */
  205. + ppe_clear(ppe, MTK_PPE_TB_CFG, MTK_PPE_TB_CFG_SCAN_MODE);
  206. + usleep_range(10000, 11000);
  207. +
  208. + return mtk_ppe_wait_busy(ppe);
  209. +}
  210. +
  211. struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base,
  212. int version, int index)
  213. {
  214. --- a/drivers/net/ethernet/mediatek/mtk_ppe.h
  215. +++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
  216. @@ -306,6 +306,7 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_
  217. int version, int index);
  218. void mtk_ppe_start(struct mtk_ppe *ppe);
  219. int mtk_ppe_stop(struct mtk_ppe *ppe);
  220. +int mtk_ppe_prepare_reset(struct mtk_ppe *ppe);
  221. void __mtk_ppe_check_skb(struct mtk_ppe *ppe, struct sk_buff *skb, u16 hash);
  222. --- a/drivers/net/ethernet/mediatek/mtk_ppe_regs.h
  223. +++ b/drivers/net/ethernet/mediatek/mtk_ppe_regs.h
  224. @@ -58,6 +58,12 @@
  225. #define MTK_PPE_TB_CFG_SCAN_MODE GENMASK(17, 16)
  226. #define MTK_PPE_TB_CFG_HASH_DEBUG GENMASK(19, 18)
  227. #define MTK_PPE_TB_CFG_INFO_SEL BIT(20)
  228. +#define MTK_PPE_TB_TICK_SEL BIT(24)
  229. +
  230. +#define MTK_PPE_BIND_LMT1 0x230
  231. +#define MTK_PPE_NTU_KEEPALIVE GENMASK(23, 16)
  232. +
  233. +#define MTK_PPE_KEEPALIVE 0x234
  234. enum {
  235. MTK_PPE_SCAN_MODE_DISABLED,