737-02-net-ethernet-mtk_eth_soc-move-MAX_DEVS-in-mtk_soc_da.patch 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. From 5af2b2dc4d6ba0ff7696e79f18e5b2bf862194eb Mon Sep 17 00:00:00 2001
  2. From: Lorenzo Bianconi <[email protected]>
  3. Date: Tue, 7 Mar 2023 15:55:24 +0000
  4. Subject: [PATCH 2/7] net: ethernet: mtk_eth_soc: move MAX_DEVS in mtk_soc_data
  5. This is a preliminary patch to add MT7988 SoC support since it runs 3
  6. macs instead of 2.
  7. Signed-off-by: Lorenzo Bianconi <[email protected]>
  8. Signed-off-by: Daniel Golle <[email protected]>
  9. ---
  10. drivers/net/ethernet/mediatek/mtk_eth_soc.c | 34 +++++++++++++++++++--
  11. drivers/net/ethernet/mediatek/mtk_eth_soc.h | 11 +++----
  12. 2 files changed, 36 insertions(+), 9 deletions(-)
  13. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  14. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
  15. @@ -4026,7 +4026,10 @@ static void mtk_sgmii_destroy(struct mtk
  16. {
  17. int i;
  18. - for (i = 0; i < MTK_MAX_DEVS; i++)
  19. + if (!eth->sgmii_pcs)
  20. + return;
  21. +
  22. + for (i = 0; i < eth->soc->num_devs; i++)
  23. mtk_pcs_lynxi_destroy(eth->sgmii_pcs[i]);
  24. }
  25. @@ -4479,7 +4482,12 @@ static int mtk_sgmii_init(struct mtk_eth
  26. u32 flags;
  27. int i;
  28. - for (i = 0; i < MTK_MAX_DEVS; i++) {
  29. + eth->sgmii_pcs = devm_kzalloc(eth->dev,
  30. + sizeof(*eth->sgmii_pcs) *
  31. + eth->soc->num_devs,
  32. + GFP_KERNEL);
  33. +
  34. + for (i = 0; i < eth->soc->num_devs; i++) {
  35. np = of_parse_phandle(eth->dev->of_node, "mediatek,sgmiisys", i);
  36. if (!np)
  37. break;
  38. @@ -4524,6 +4532,18 @@ static int mtk_probe(struct platform_dev
  39. if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628))
  40. eth->ip_align = NET_IP_ALIGN;
  41. + eth->netdev = devm_kzalloc(eth->dev,
  42. + sizeof(*eth->netdev) * eth->soc->num_devs,
  43. + GFP_KERNEL);
  44. + if (!eth->netdev)
  45. + return -ENOMEM;
  46. +
  47. + eth->mac = devm_kzalloc(eth->dev,
  48. + sizeof(*eth->mac) * eth->soc->num_devs,
  49. + GFP_KERNEL);
  50. + if (!eth->mac)
  51. + return -ENOMEM;
  52. +
  53. spin_lock_init(&eth->page_lock);
  54. spin_lock_init(&eth->tx_irq_lock);
  55. spin_lock_init(&eth->rx_irq_lock);
  56. @@ -4709,7 +4729,7 @@ static int mtk_probe(struct platform_dev
  57. goto err_deinit_ppe;
  58. }
  59. - for (i = 0; i < MTK_MAX_DEVS; i++) {
  60. + for (i = 0; i < eth->soc->num_devs; i++) {
  61. if (!eth->netdev[i])
  62. continue;
  63. @@ -4785,6 +4805,7 @@ static const struct mtk_soc_data mt2701_
  64. .hw_features = MTK_HW_FEATURES,
  65. .required_clks = MT7623_CLKS_BITMAP,
  66. .required_pctl = true,
  67. + .num_devs = 2,
  68. .txrx = {
  69. .txd_size = sizeof(struct mtk_tx_dma),
  70. .rxd_size = sizeof(struct mtk_rx_dma),
  71. @@ -4803,6 +4824,7 @@ static const struct mtk_soc_data mt7621_
  72. .required_pctl = false,
  73. .offload_version = 1,
  74. .hash_offset = 2,
  75. + .num_devs = 2,
  76. .foe_entry_size = sizeof(struct mtk_foe_entry) - 16,
  77. .txrx = {
  78. .txd_size = sizeof(struct mtk_tx_dma),
  79. @@ -4824,6 +4846,7 @@ static const struct mtk_soc_data mt7622_
  80. .offload_version = 2,
  81. .hash_offset = 2,
  82. .has_accounting = true,
  83. + .num_devs = 2,
  84. .foe_entry_size = sizeof(struct mtk_foe_entry) - 16,
  85. .txrx = {
  86. .txd_size = sizeof(struct mtk_tx_dma),
  87. @@ -4843,6 +4866,7 @@ static const struct mtk_soc_data mt7623_
  88. .required_pctl = true,
  89. .offload_version = 1,
  90. .hash_offset = 2,
  91. + .num_devs = 2,
  92. .foe_entry_size = sizeof(struct mtk_foe_entry) - 16,
  93. .txrx = {
  94. .txd_size = sizeof(struct mtk_tx_dma),
  95. @@ -4862,6 +4886,7 @@ static const struct mtk_soc_data mt7629_
  96. .required_clks = MT7629_CLKS_BITMAP,
  97. .required_pctl = false,
  98. .has_accounting = true,
  99. + .num_devs = 2,
  100. .txrx = {
  101. .txd_size = sizeof(struct mtk_tx_dma),
  102. .rxd_size = sizeof(struct mtk_rx_dma),
  103. @@ -4883,6 +4908,7 @@ static const struct mtk_soc_data mt7981_
  104. .hash_offset = 4,
  105. .foe_entry_size = sizeof(struct mtk_foe_entry),
  106. .has_accounting = true,
  107. + .num_devs = 2,
  108. .txrx = {
  109. .txd_size = sizeof(struct mtk_tx_dma_v2),
  110. .rxd_size = sizeof(struct mtk_rx_dma_v2),
  111. @@ -4902,6 +4928,7 @@ static const struct mtk_soc_data mt7986_
  112. .required_pctl = false,
  113. .offload_version = 2,
  114. .hash_offset = 4,
  115. + .num_devs = 2,
  116. .foe_entry_size = sizeof(struct mtk_foe_entry),
  117. .has_accounting = true,
  118. .txrx = {
  119. @@ -4920,6 +4947,7 @@ static const struct mtk_soc_data rt5350_
  120. .hw_features = MTK_HW_FEATURES_MT7628,
  121. .required_clks = MT7628_CLKS_BITMAP,
  122. .required_pctl = false,
  123. + .num_devs = 2,
  124. .txrx = {
  125. .txd_size = sizeof(struct mtk_tx_dma),
  126. .rxd_size = sizeof(struct mtk_rx_dma),
  127. --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
  128. +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
  129. @@ -1021,6 +1021,7 @@ struct mtk_reg_map {
  130. * @required_pctl A bool value to show whether the SoC requires
  131. * the extra setup for those pins used by GMAC.
  132. * @hash_offset Flow table hash offset.
  133. + * @num_devs SoC number of macs.
  134. * @foe_entry_size Foe table entry size.
  135. * @has_accounting Bool indicating support for accounting of
  136. * offloaded flows.
  137. @@ -1039,6 +1040,7 @@ struct mtk_soc_data {
  138. bool required_pctl;
  139. u8 offload_version;
  140. u8 hash_offset;
  141. + u8 num_devs;
  142. u16 foe_entry_size;
  143. netdev_features_t hw_features;
  144. bool has_accounting;
  145. @@ -1054,9 +1056,6 @@ struct mtk_soc_data {
  146. #define MTK_DMA_MONITOR_TIMEOUT msecs_to_jiffies(1000)
  147. -/* currently no SoC has more than 2 macs */
  148. -#define MTK_MAX_DEVS 2
  149. -
  150. /* struct mtk_eth - This is the main datasructure for holding the state
  151. * of the driver
  152. * @dev: The device pointer
  153. @@ -1111,14 +1110,14 @@ struct mtk_eth {
  154. spinlock_t tx_irq_lock;
  155. spinlock_t rx_irq_lock;
  156. struct net_device dummy_dev;
  157. - struct net_device *netdev[MTK_MAX_DEVS];
  158. - struct mtk_mac *mac[MTK_MAX_DEVS];
  159. + struct net_device **netdev;
  160. + struct mtk_mac **mac;
  161. int irq[3];
  162. u32 msg_enable;
  163. unsigned long sysclk;
  164. struct regmap *ethsys;
  165. struct regmap *infra;
  166. - struct phylink_pcs *sgmii_pcs[MTK_MAX_DEVS];
  167. + struct phylink_pcs **sgmii_pcs;
  168. struct regmap *pctl;
  169. bool hwlro;
  170. refcount_t dma_refcnt;