kernel: bump 5.15 to 5.15.123
[openwrt/openwrt.git] / target / linux / generic / pending-5.15 / 737-02-net-ethernet-mtk_eth_soc-move-MAX_DEVS-in-mtk_soc_da.patch
1 From 5af2b2dc4d6ba0ff7696e79f18e5b2bf862194eb Mon Sep 17 00:00:00 2001
2 From: Lorenzo Bianconi <lorenzo@kernel.org>
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
6 This is a preliminary patch to add MT7988 SoC support since it runs 3
7 macs instead of 2.
8
9 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
10 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
11 ---
12 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 34 +++++++++++++++++++--
13 drivers/net/ethernet/mediatek/mtk_eth_soc.h | 11 +++----
14 2 files changed, 36 insertions(+), 9 deletions(-)
15
16 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
17 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
18 @@ -3972,7 +3972,10 @@ static void mtk_sgmii_destroy(struct mtk
19 {
20 int i;
21
22 - for (i = 0; i < MTK_MAX_DEVS; i++)
23 + if (!eth->sgmii_pcs)
24 + return;
25 +
26 + for (i = 0; i < eth->soc->num_devs; i++)
27 mtk_pcs_lynxi_destroy(eth->sgmii_pcs[i]);
28 }
29
30 @@ -4425,7 +4428,12 @@ static int mtk_sgmii_init(struct mtk_eth
31 u32 flags;
32 int i;
33
34 - for (i = 0; i < MTK_MAX_DEVS; i++) {
35 + eth->sgmii_pcs = devm_kzalloc(eth->dev,
36 + sizeof(*eth->sgmii_pcs) *
37 + eth->soc->num_devs,
38 + GFP_KERNEL);
39 +
40 + for (i = 0; i < eth->soc->num_devs; i++) {
41 np = of_parse_phandle(eth->dev->of_node, "mediatek,sgmiisys", i);
42 if (!np)
43 break;
44 @@ -4470,6 +4478,18 @@ static int mtk_probe(struct platform_dev
45 if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628))
46 eth->ip_align = NET_IP_ALIGN;
47
48 + eth->netdev = devm_kzalloc(eth->dev,
49 + sizeof(*eth->netdev) * eth->soc->num_devs,
50 + GFP_KERNEL);
51 + if (!eth->netdev)
52 + return -ENOMEM;
53 +
54 + eth->mac = devm_kzalloc(eth->dev,
55 + sizeof(*eth->mac) * eth->soc->num_devs,
56 + GFP_KERNEL);
57 + if (!eth->mac)
58 + return -ENOMEM;
59 +
60 spin_lock_init(&eth->page_lock);
61 spin_lock_init(&eth->tx_irq_lock);
62 spin_lock_init(&eth->rx_irq_lock);
63 @@ -4655,7 +4675,7 @@ static int mtk_probe(struct platform_dev
64 goto err_free_dev;
65 }
66
67 - for (i = 0; i < MTK_MAX_DEVS; i++) {
68 + for (i = 0; i < eth->soc->num_devs; i++) {
69 if (!eth->netdev[i])
70 continue;
71
72 @@ -4732,6 +4752,7 @@ static const struct mtk_soc_data mt2701_
73 .hw_features = MTK_HW_FEATURES,
74 .required_clks = MT7623_CLKS_BITMAP,
75 .required_pctl = true,
76 + .num_devs = 2,
77 .txrx = {
78 .txd_size = sizeof(struct mtk_tx_dma),
79 .rxd_size = sizeof(struct mtk_rx_dma),
80 @@ -4750,6 +4771,7 @@ static const struct mtk_soc_data mt7621_
81 .required_pctl = false,
82 .offload_version = 1,
83 .hash_offset = 2,
84 + .num_devs = 2,
85 .foe_entry_size = sizeof(struct mtk_foe_entry) - 16,
86 .txrx = {
87 .txd_size = sizeof(struct mtk_tx_dma),
88 @@ -4771,6 +4793,7 @@ static const struct mtk_soc_data mt7622_
89 .offload_version = 2,
90 .hash_offset = 2,
91 .has_accounting = true,
92 + .num_devs = 2,
93 .foe_entry_size = sizeof(struct mtk_foe_entry) - 16,
94 .txrx = {
95 .txd_size = sizeof(struct mtk_tx_dma),
96 @@ -4790,6 +4813,7 @@ static const struct mtk_soc_data mt7623_
97 .required_pctl = true,
98 .offload_version = 1,
99 .hash_offset = 2,
100 + .num_devs = 2,
101 .foe_entry_size = sizeof(struct mtk_foe_entry) - 16,
102 .txrx = {
103 .txd_size = sizeof(struct mtk_tx_dma),
104 @@ -4809,6 +4833,7 @@ static const struct mtk_soc_data mt7629_
105 .required_clks = MT7629_CLKS_BITMAP,
106 .required_pctl = false,
107 .has_accounting = true,
108 + .num_devs = 2,
109 .txrx = {
110 .txd_size = sizeof(struct mtk_tx_dma),
111 .rxd_size = sizeof(struct mtk_rx_dma),
112 @@ -4830,6 +4855,7 @@ static const struct mtk_soc_data mt7981_
113 .hash_offset = 4,
114 .foe_entry_size = sizeof(struct mtk_foe_entry),
115 .has_accounting = true,
116 + .num_devs = 2,
117 .txrx = {
118 .txd_size = sizeof(struct mtk_tx_dma_v2),
119 .rxd_size = sizeof(struct mtk_rx_dma_v2),
120 @@ -4849,6 +4875,7 @@ static const struct mtk_soc_data mt7986_
121 .required_pctl = false,
122 .offload_version = 2,
123 .hash_offset = 4,
124 + .num_devs = 2,
125 .foe_entry_size = sizeof(struct mtk_foe_entry),
126 .has_accounting = true,
127 .txrx = {
128 @@ -4867,6 +4894,7 @@ static const struct mtk_soc_data rt5350_
129 .hw_features = MTK_HW_FEATURES_MT7628,
130 .required_clks = MT7628_CLKS_BITMAP,
131 .required_pctl = false,
132 + .num_devs = 2,
133 .txrx = {
134 .txd_size = sizeof(struct mtk_tx_dma),
135 .rxd_size = sizeof(struct mtk_rx_dma),
136 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
137 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
138 @@ -1018,6 +1018,7 @@ struct mtk_reg_map {
139 * @required_pctl A bool value to show whether the SoC requires
140 * the extra setup for those pins used by GMAC.
141 * @hash_offset Flow table hash offset.
142 + * @num_devs SoC number of macs.
143 * @foe_entry_size Foe table entry size.
144 * @has_accounting Bool indicating support for accounting of
145 * offloaded flows.
146 @@ -1036,6 +1037,7 @@ struct mtk_soc_data {
147 bool required_pctl;
148 u8 offload_version;
149 u8 hash_offset;
150 + u8 num_devs;
151 u16 foe_entry_size;
152 netdev_features_t hw_features;
153 bool has_accounting;
154 @@ -1051,9 +1053,6 @@ struct mtk_soc_data {
155
156 #define MTK_DMA_MONITOR_TIMEOUT msecs_to_jiffies(1000)
157
158 -/* currently no SoC has more than 2 macs */
159 -#define MTK_MAX_DEVS 2
160 -
161 /* struct mtk_eth - This is the main datasructure for holding the state
162 * of the driver
163 * @dev: The device pointer
164 @@ -1108,14 +1107,14 @@ struct mtk_eth {
165 spinlock_t tx_irq_lock;
166 spinlock_t rx_irq_lock;
167 struct net_device dummy_dev;
168 - struct net_device *netdev[MTK_MAX_DEVS];
169 - struct mtk_mac *mac[MTK_MAX_DEVS];
170 + struct net_device **netdev;
171 + struct mtk_mac **mac;
172 int irq[3];
173 u32 msg_enable;
174 unsigned long sysclk;
175 struct regmap *ethsys;
176 struct regmap *infra;
177 - struct phylink_pcs *sgmii_pcs[MTK_MAX_DEVS];
178 + struct phylink_pcs **sgmii_pcs;
179 struct regmap *pctl;
180 bool hwlro;
181 refcount_t dma_refcnt;