1 // SPDX-License-Identifier: GPL-2.0+
2 /* Microchip Sparx5 Switch driver
4 * Copyright (c) 2021 Microchip Technology Inc. and its subsidiaries.
6 * The Sparx5 Chip Register Model can be browsed at this location:
7 * https://github.com/microchip-ung/sparx-5_reginfo
9 #include <linux/module.h>
10 #include <linux/device.h>
11 #include <linux/netdevice.h>
12 #include <linux/platform_device.h>
13 #include <linux/interrupt.h>
15 #include <linux/of_net.h>
16 #include <linux/of_mdio.h>
17 #include <net/switchdev.h>
18 #include <linux/etherdevice.h>
20 #include <linux/printk.h>
21 #include <linux/iopoll.h>
22 #include <linux/mfd/syscon.h>
23 #include <linux/regmap.h>
24 #include <linux/types.h>
25 #include <linux/reset.h>
27 #include "../lan969x/lan969x.h" /* for lan969x match data */
29 #include "sparx5_main_regs.h"
30 #include "sparx5_main.h"
31 #include "sparx5_port.h"
32 #include "sparx5_qos.h"
33 #include "sparx5_vcap_ag_api.h"
34 #include "sparx5_vcap_impl.h"
36 const struct sparx5_regs
*regs
;
40 struct initial_port_config
{
42 struct device_node
*node
;
43 struct sparx5_port_config conf
;
47 struct sparx5_ram_config
{
48 void __iomem
*init_reg
;
52 static const struct sparx5_main_io_resource sparx5_main_iomap
[] = {
53 { TARGET_CPU
, 0, 0 }, /* 0x600000000 */
54 { TARGET_FDMA
, 0x80000, 0 }, /* 0x600080000 */
55 { TARGET_PCEP
, 0x400000, 0 }, /* 0x600400000 */
56 { TARGET_DEV2G5
, 0x10004000, 1 }, /* 0x610004000 */
57 { TARGET_DEV5G
, 0x10008000, 1 }, /* 0x610008000 */
58 { TARGET_PCS5G_BR
, 0x1000c000, 1 }, /* 0x61000c000 */
59 { TARGET_DEV2G5
+ 1, 0x10010000, 1 }, /* 0x610010000 */
60 { TARGET_DEV5G
+ 1, 0x10014000, 1 }, /* 0x610014000 */
61 { TARGET_PCS5G_BR
+ 1, 0x10018000, 1 }, /* 0x610018000 */
62 { TARGET_DEV2G5
+ 2, 0x1001c000, 1 }, /* 0x61001c000 */
63 { TARGET_DEV5G
+ 2, 0x10020000, 1 }, /* 0x610020000 */
64 { TARGET_PCS5G_BR
+ 2, 0x10024000, 1 }, /* 0x610024000 */
65 { TARGET_DEV2G5
+ 6, 0x10028000, 1 }, /* 0x610028000 */
66 { TARGET_DEV5G
+ 6, 0x1002c000, 1 }, /* 0x61002c000 */
67 { TARGET_PCS5G_BR
+ 6, 0x10030000, 1 }, /* 0x610030000 */
68 { TARGET_DEV2G5
+ 7, 0x10034000, 1 }, /* 0x610034000 */
69 { TARGET_DEV5G
+ 7, 0x10038000, 1 }, /* 0x610038000 */
70 { TARGET_PCS5G_BR
+ 7, 0x1003c000, 1 }, /* 0x61003c000 */
71 { TARGET_DEV2G5
+ 8, 0x10040000, 1 }, /* 0x610040000 */
72 { TARGET_DEV5G
+ 8, 0x10044000, 1 }, /* 0x610044000 */
73 { TARGET_PCS5G_BR
+ 8, 0x10048000, 1 }, /* 0x610048000 */
74 { TARGET_DEV2G5
+ 9, 0x1004c000, 1 }, /* 0x61004c000 */
75 { TARGET_DEV5G
+ 9, 0x10050000, 1 }, /* 0x610050000 */
76 { TARGET_PCS5G_BR
+ 9, 0x10054000, 1 }, /* 0x610054000 */
77 { TARGET_DEV2G5
+ 10, 0x10058000, 1 }, /* 0x610058000 */
78 { TARGET_DEV5G
+ 10, 0x1005c000, 1 }, /* 0x61005c000 */
79 { TARGET_PCS5G_BR
+ 10, 0x10060000, 1 }, /* 0x610060000 */
80 { TARGET_DEV2G5
+ 11, 0x10064000, 1 }, /* 0x610064000 */
81 { TARGET_DEV5G
+ 11, 0x10068000, 1 }, /* 0x610068000 */
82 { TARGET_PCS5G_BR
+ 11, 0x1006c000, 1 }, /* 0x61006c000 */
83 { TARGET_DEV2G5
+ 12, 0x10070000, 1 }, /* 0x610070000 */
84 { TARGET_DEV10G
, 0x10074000, 1 }, /* 0x610074000 */
85 { TARGET_PCS10G_BR
, 0x10078000, 1 }, /* 0x610078000 */
86 { TARGET_DEV2G5
+ 14, 0x1007c000, 1 }, /* 0x61007c000 */
87 { TARGET_DEV10G
+ 2, 0x10080000, 1 }, /* 0x610080000 */
88 { TARGET_PCS10G_BR
+ 2, 0x10084000, 1 }, /* 0x610084000 */
89 { TARGET_DEV2G5
+ 15, 0x10088000, 1 }, /* 0x610088000 */
90 { TARGET_DEV10G
+ 3, 0x1008c000, 1 }, /* 0x61008c000 */
91 { TARGET_PCS10G_BR
+ 3, 0x10090000, 1 }, /* 0x610090000 */
92 { TARGET_DEV2G5
+ 16, 0x10094000, 1 }, /* 0x610094000 */
93 { TARGET_DEV2G5
+ 17, 0x10098000, 1 }, /* 0x610098000 */
94 { TARGET_DEV2G5
+ 18, 0x1009c000, 1 }, /* 0x61009c000 */
95 { TARGET_DEV2G5
+ 19, 0x100a0000, 1 }, /* 0x6100a0000 */
96 { TARGET_DEV2G5
+ 20, 0x100a4000, 1 }, /* 0x6100a4000 */
97 { TARGET_DEV2G5
+ 21, 0x100a8000, 1 }, /* 0x6100a8000 */
98 { TARGET_DEV2G5
+ 22, 0x100ac000, 1 }, /* 0x6100ac000 */
99 { TARGET_DEV2G5
+ 23, 0x100b0000, 1 }, /* 0x6100b0000 */
100 { TARGET_DEV2G5
+ 32, 0x100b4000, 1 }, /* 0x6100b4000 */
101 { TARGET_DEV2G5
+ 33, 0x100b8000, 1 }, /* 0x6100b8000 */
102 { TARGET_DEV2G5
+ 34, 0x100bc000, 1 }, /* 0x6100bc000 */
103 { TARGET_DEV2G5
+ 35, 0x100c0000, 1 }, /* 0x6100c0000 */
104 { TARGET_DEV2G5
+ 36, 0x100c4000, 1 }, /* 0x6100c4000 */
105 { TARGET_DEV2G5
+ 37, 0x100c8000, 1 }, /* 0x6100c8000 */
106 { TARGET_DEV2G5
+ 38, 0x100cc000, 1 }, /* 0x6100cc000 */
107 { TARGET_DEV2G5
+ 39, 0x100d0000, 1 }, /* 0x6100d0000 */
108 { TARGET_DEV2G5
+ 40, 0x100d4000, 1 }, /* 0x6100d4000 */
109 { TARGET_DEV2G5
+ 41, 0x100d8000, 1 }, /* 0x6100d8000 */
110 { TARGET_DEV2G5
+ 42, 0x100dc000, 1 }, /* 0x6100dc000 */
111 { TARGET_DEV2G5
+ 43, 0x100e0000, 1 }, /* 0x6100e0000 */
112 { TARGET_DEV2G5
+ 44, 0x100e4000, 1 }, /* 0x6100e4000 */
113 { TARGET_DEV2G5
+ 45, 0x100e8000, 1 }, /* 0x6100e8000 */
114 { TARGET_DEV2G5
+ 46, 0x100ec000, 1 }, /* 0x6100ec000 */
115 { TARGET_DEV2G5
+ 47, 0x100f0000, 1 }, /* 0x6100f0000 */
116 { TARGET_DEV2G5
+ 57, 0x100f4000, 1 }, /* 0x6100f4000 */
117 { TARGET_DEV25G
+ 1, 0x100f8000, 1 }, /* 0x6100f8000 */
118 { TARGET_PCS25G_BR
+ 1, 0x100fc000, 1 }, /* 0x6100fc000 */
119 { TARGET_DEV2G5
+ 59, 0x10104000, 1 }, /* 0x610104000 */
120 { TARGET_DEV25G
+ 3, 0x10108000, 1 }, /* 0x610108000 */
121 { TARGET_PCS25G_BR
+ 3, 0x1010c000, 1 }, /* 0x61010c000 */
122 { TARGET_DEV2G5
+ 60, 0x10114000, 1 }, /* 0x610114000 */
123 { TARGET_DEV25G
+ 4, 0x10118000, 1 }, /* 0x610118000 */
124 { TARGET_PCS25G_BR
+ 4, 0x1011c000, 1 }, /* 0x61011c000 */
125 { TARGET_DEV2G5
+ 64, 0x10124000, 1 }, /* 0x610124000 */
126 { TARGET_DEV5G
+ 12, 0x10128000, 1 }, /* 0x610128000 */
127 { TARGET_PCS5G_BR
+ 12, 0x1012c000, 1 }, /* 0x61012c000 */
128 { TARGET_PORT_CONF
, 0x10130000, 1 }, /* 0x610130000 */
129 { TARGET_DEV2G5
+ 3, 0x10404000, 1 }, /* 0x610404000 */
130 { TARGET_DEV5G
+ 3, 0x10408000, 1 }, /* 0x610408000 */
131 { TARGET_PCS5G_BR
+ 3, 0x1040c000, 1 }, /* 0x61040c000 */
132 { TARGET_DEV2G5
+ 4, 0x10410000, 1 }, /* 0x610410000 */
133 { TARGET_DEV5G
+ 4, 0x10414000, 1 }, /* 0x610414000 */
134 { TARGET_PCS5G_BR
+ 4, 0x10418000, 1 }, /* 0x610418000 */
135 { TARGET_DEV2G5
+ 5, 0x1041c000, 1 }, /* 0x61041c000 */
136 { TARGET_DEV5G
+ 5, 0x10420000, 1 }, /* 0x610420000 */
137 { TARGET_PCS5G_BR
+ 5, 0x10424000, 1 }, /* 0x610424000 */
138 { TARGET_DEV2G5
+ 13, 0x10428000, 1 }, /* 0x610428000 */
139 { TARGET_DEV10G
+ 1, 0x1042c000, 1 }, /* 0x61042c000 */
140 { TARGET_PCS10G_BR
+ 1, 0x10430000, 1 }, /* 0x610430000 */
141 { TARGET_DEV2G5
+ 24, 0x10434000, 1 }, /* 0x610434000 */
142 { TARGET_DEV2G5
+ 25, 0x10438000, 1 }, /* 0x610438000 */
143 { TARGET_DEV2G5
+ 26, 0x1043c000, 1 }, /* 0x61043c000 */
144 { TARGET_DEV2G5
+ 27, 0x10440000, 1 }, /* 0x610440000 */
145 { TARGET_DEV2G5
+ 28, 0x10444000, 1 }, /* 0x610444000 */
146 { TARGET_DEV2G5
+ 29, 0x10448000, 1 }, /* 0x610448000 */
147 { TARGET_DEV2G5
+ 30, 0x1044c000, 1 }, /* 0x61044c000 */
148 { TARGET_DEV2G5
+ 31, 0x10450000, 1 }, /* 0x610450000 */
149 { TARGET_DEV2G5
+ 48, 0x10454000, 1 }, /* 0x610454000 */
150 { TARGET_DEV10G
+ 4, 0x10458000, 1 }, /* 0x610458000 */
151 { TARGET_PCS10G_BR
+ 4, 0x1045c000, 1 }, /* 0x61045c000 */
152 { TARGET_DEV2G5
+ 49, 0x10460000, 1 }, /* 0x610460000 */
153 { TARGET_DEV10G
+ 5, 0x10464000, 1 }, /* 0x610464000 */
154 { TARGET_PCS10G_BR
+ 5, 0x10468000, 1 }, /* 0x610468000 */
155 { TARGET_DEV2G5
+ 50, 0x1046c000, 1 }, /* 0x61046c000 */
156 { TARGET_DEV10G
+ 6, 0x10470000, 1 }, /* 0x610470000 */
157 { TARGET_PCS10G_BR
+ 6, 0x10474000, 1 }, /* 0x610474000 */
158 { TARGET_DEV2G5
+ 51, 0x10478000, 1 }, /* 0x610478000 */
159 { TARGET_DEV10G
+ 7, 0x1047c000, 1 }, /* 0x61047c000 */
160 { TARGET_PCS10G_BR
+ 7, 0x10480000, 1 }, /* 0x610480000 */
161 { TARGET_DEV2G5
+ 52, 0x10484000, 1 }, /* 0x610484000 */
162 { TARGET_DEV10G
+ 8, 0x10488000, 1 }, /* 0x610488000 */
163 { TARGET_PCS10G_BR
+ 8, 0x1048c000, 1 }, /* 0x61048c000 */
164 { TARGET_DEV2G5
+ 53, 0x10490000, 1 }, /* 0x610490000 */
165 { TARGET_DEV10G
+ 9, 0x10494000, 1 }, /* 0x610494000 */
166 { TARGET_PCS10G_BR
+ 9, 0x10498000, 1 }, /* 0x610498000 */
167 { TARGET_DEV2G5
+ 54, 0x1049c000, 1 }, /* 0x61049c000 */
168 { TARGET_DEV10G
+ 10, 0x104a0000, 1 }, /* 0x6104a0000 */
169 { TARGET_PCS10G_BR
+ 10, 0x104a4000, 1 }, /* 0x6104a4000 */
170 { TARGET_DEV2G5
+ 55, 0x104a8000, 1 }, /* 0x6104a8000 */
171 { TARGET_DEV10G
+ 11, 0x104ac000, 1 }, /* 0x6104ac000 */
172 { TARGET_PCS10G_BR
+ 11, 0x104b0000, 1 }, /* 0x6104b0000 */
173 { TARGET_DEV2G5
+ 56, 0x104b4000, 1 }, /* 0x6104b4000 */
174 { TARGET_DEV25G
, 0x104b8000, 1 }, /* 0x6104b8000 */
175 { TARGET_PCS25G_BR
, 0x104bc000, 1 }, /* 0x6104bc000 */
176 { TARGET_DEV2G5
+ 58, 0x104c4000, 1 }, /* 0x6104c4000 */
177 { TARGET_DEV25G
+ 2, 0x104c8000, 1 }, /* 0x6104c8000 */
178 { TARGET_PCS25G_BR
+ 2, 0x104cc000, 1 }, /* 0x6104cc000 */
179 { TARGET_DEV2G5
+ 61, 0x104d4000, 1 }, /* 0x6104d4000 */
180 { TARGET_DEV25G
+ 5, 0x104d8000, 1 }, /* 0x6104d8000 */
181 { TARGET_PCS25G_BR
+ 5, 0x104dc000, 1 }, /* 0x6104dc000 */
182 { TARGET_DEV2G5
+ 62, 0x104e4000, 1 }, /* 0x6104e4000 */
183 { TARGET_DEV25G
+ 6, 0x104e8000, 1 }, /* 0x6104e8000 */
184 { TARGET_PCS25G_BR
+ 6, 0x104ec000, 1 }, /* 0x6104ec000 */
185 { TARGET_DEV2G5
+ 63, 0x104f4000, 1 }, /* 0x6104f4000 */
186 { TARGET_DEV25G
+ 7, 0x104f8000, 1 }, /* 0x6104f8000 */
187 { TARGET_PCS25G_BR
+ 7, 0x104fc000, 1 }, /* 0x6104fc000 */
188 { TARGET_DSM
, 0x10504000, 1 }, /* 0x610504000 */
189 { TARGET_ASM
, 0x10600000, 1 }, /* 0x610600000 */
190 { TARGET_GCB
, 0x11010000, 2 }, /* 0x611010000 */
191 { TARGET_QS
, 0x11030000, 2 }, /* 0x611030000 */
192 { TARGET_PTP
, 0x11040000, 2 }, /* 0x611040000 */
193 { TARGET_ANA_ACL
, 0x11050000, 2 }, /* 0x611050000 */
194 { TARGET_LRN
, 0x11060000, 2 }, /* 0x611060000 */
195 { TARGET_VCAP_SUPER
, 0x11080000, 2 }, /* 0x611080000 */
196 { TARGET_QSYS
, 0x110a0000, 2 }, /* 0x6110a0000 */
197 { TARGET_QFWD
, 0x110b0000, 2 }, /* 0x6110b0000 */
198 { TARGET_XQS
, 0x110c0000, 2 }, /* 0x6110c0000 */
199 { TARGET_VCAP_ES2
, 0x110d0000, 2 }, /* 0x6110d0000 */
200 { TARGET_VCAP_ES0
, 0x110e0000, 2 }, /* 0x6110e0000 */
201 { TARGET_CLKGEN
, 0x11100000, 2 }, /* 0x611100000 */
202 { TARGET_ANA_AC_POL
, 0x11200000, 2 }, /* 0x611200000 */
203 { TARGET_QRES
, 0x11280000, 2 }, /* 0x611280000 */
204 { TARGET_EACL
, 0x112c0000, 2 }, /* 0x6112c0000 */
205 { TARGET_ANA_CL
, 0x11400000, 2 }, /* 0x611400000 */
206 { TARGET_ANA_L3
, 0x11480000, 2 }, /* 0x611480000 */
207 { TARGET_ANA_AC_SDLB
, 0x11500000, 2 }, /* 0x611500000 */
208 { TARGET_HSCH
, 0x11580000, 2 }, /* 0x611580000 */
209 { TARGET_REW
, 0x11600000, 2 }, /* 0x611600000 */
210 { TARGET_ANA_L2
, 0x11800000, 2 }, /* 0x611800000 */
211 { TARGET_ANA_AC
, 0x11900000, 2 }, /* 0x611900000 */
212 { TARGET_VOP
, 0x11a00000, 2 }, /* 0x611a00000 */
215 bool is_sparx5(struct sparx5
*sparx5
)
217 switch (sparx5
->target_ct
) {
218 case SPX5_TARGET_CT_7546
:
219 case SPX5_TARGET_CT_7549
:
220 case SPX5_TARGET_CT_7552
:
221 case SPX5_TARGET_CT_7556
:
222 case SPX5_TARGET_CT_7558
:
223 case SPX5_TARGET_CT_7546TSN
:
224 case SPX5_TARGET_CT_7549TSN
:
225 case SPX5_TARGET_CT_7552TSN
:
226 case SPX5_TARGET_CT_7556TSN
:
227 case SPX5_TARGET_CT_7558TSN
:
234 static void sparx5_init_features(struct sparx5
*sparx5
)
236 switch (sparx5
->target_ct
) {
237 case SPX5_TARGET_CT_7546
:
238 case SPX5_TARGET_CT_7549
:
239 case SPX5_TARGET_CT_7552
:
240 case SPX5_TARGET_CT_7556
:
241 case SPX5_TARGET_CT_7558
:
242 case SPX5_TARGET_CT_7546TSN
:
243 case SPX5_TARGET_CT_7549TSN
:
244 case SPX5_TARGET_CT_7552TSN
:
245 case SPX5_TARGET_CT_7556TSN
:
246 case SPX5_TARGET_CT_7558TSN
:
247 case SPX5_TARGET_CT_LAN9691VAO
:
248 case SPX5_TARGET_CT_LAN9694TSN
:
249 case SPX5_TARGET_CT_LAN9694RED
:
250 case SPX5_TARGET_CT_LAN9692VAO
:
251 case SPX5_TARGET_CT_LAN9696TSN
:
252 case SPX5_TARGET_CT_LAN9696RED
:
253 case SPX5_TARGET_CT_LAN9693VAO
:
254 case SPX5_TARGET_CT_LAN9698TSN
:
255 case SPX5_TARGET_CT_LAN9698RED
:
256 sparx5
->features
= (SPX5_FEATURE_PSFP
| SPX5_FEATURE_PTP
);
263 bool sparx5_has_feature(struct sparx5
*sparx5
, enum sparx5_feature feature
)
265 return sparx5
->features
& feature
;
268 static int sparx5_create_targets(struct sparx5
*sparx5
)
270 const struct sparx5_main_io_resource
*iomap
= sparx5
->data
->iomap
;
271 int iomap_size
= sparx5
->data
->iomap_size
;
272 int ioranges
= sparx5
->data
->ioranges
;
273 struct resource
*iores
[IO_RANGES
];
274 void __iomem
*iomem
[IO_RANGES
];
275 void __iomem
*begin
[IO_RANGES
];
276 int range_id
[IO_RANGES
];
279 for (idx
= 0, jdx
= 0; jdx
< iomap_size
; jdx
++) {
280 const struct sparx5_main_io_resource
*io
= &iomap
[jdx
];
282 if (idx
== io
->range
) {
287 for (idx
= 0; idx
< ioranges
; idx
++) {
288 iores
[idx
] = platform_get_resource(sparx5
->pdev
, IORESOURCE_MEM
,
291 dev_err(sparx5
->dev
, "Invalid resource\n");
294 iomem
[idx
] = devm_ioremap(sparx5
->dev
,
296 resource_size(iores
[idx
]));
298 dev_err(sparx5
->dev
, "Unable to get switch registers: %s\n",
302 begin
[idx
] = iomem
[idx
] - iomap
[range_id
[idx
]].offset
;
304 for (jdx
= 0; jdx
< iomap_size
; jdx
++) {
305 const struct sparx5_main_io_resource
*io
= &iomap
[jdx
];
307 sparx5
->regs
[io
->id
] = begin
[io
->range
] + io
->offset
;
312 static int sparx5_create_port(struct sparx5
*sparx5
,
313 struct initial_port_config
*config
)
315 struct sparx5_port
*spx5_port
;
316 struct net_device
*ndev
;
317 struct phylink
*phylink
;
320 ndev
= sparx5_create_netdev(sparx5
, config
->portno
);
322 dev_err(sparx5
->dev
, "Could not create net device: %02u\n",
324 return PTR_ERR(ndev
);
326 spx5_port
= netdev_priv(ndev
);
327 spx5_port
->of_node
= config
->node
;
328 spx5_port
->serdes
= config
->serdes
;
329 spx5_port
->pvid
= NULL_VID
;
330 spx5_port
->signd_internal
= true;
331 spx5_port
->signd_active_high
= true;
332 spx5_port
->signd_enable
= true;
333 spx5_port
->max_vlan_tags
= SPX5_PORT_MAX_TAGS_NONE
;
334 spx5_port
->vlan_type
= SPX5_VLAN_PORT_TYPE_UNAWARE
;
335 spx5_port
->custom_etype
= 0x8880; /* Vitesse */
336 spx5_port
->phylink_pcs
.poll
= true;
337 spx5_port
->phylink_pcs
.ops
= &sparx5_phylink_pcs_ops
;
338 spx5_port
->phylink_pcs
.neg_mode
= true;
339 spx5_port
->is_mrouter
= false;
340 INIT_LIST_HEAD(&spx5_port
->tc_templates
);
341 sparx5
->ports
[config
->portno
] = spx5_port
;
343 err
= sparx5_port_init(sparx5
, spx5_port
, &config
->conf
);
345 dev_err(sparx5
->dev
, "port init failed\n");
348 spx5_port
->conf
= config
->conf
;
351 sparx5_vlan_port_setup(sparx5
, spx5_port
->portno
);
353 /* Create a phylink for PHY management. Also handles SFPs */
354 spx5_port
->phylink_config
.dev
= &spx5_port
->ndev
->dev
;
355 spx5_port
->phylink_config
.type
= PHYLINK_NETDEV
;
356 spx5_port
->phylink_config
.mac_capabilities
= MAC_ASYM_PAUSE
|
357 MAC_SYM_PAUSE
| MAC_10
| MAC_100
| MAC_1000FD
|
358 MAC_2500FD
| MAC_5000FD
| MAC_10000FD
| MAC_25000FD
;
360 __set_bit(PHY_INTERFACE_MODE_SGMII
,
361 spx5_port
->phylink_config
.supported_interfaces
);
362 __set_bit(PHY_INTERFACE_MODE_QSGMII
,
363 spx5_port
->phylink_config
.supported_interfaces
);
364 __set_bit(PHY_INTERFACE_MODE_1000BASEX
,
365 spx5_port
->phylink_config
.supported_interfaces
);
366 __set_bit(PHY_INTERFACE_MODE_2500BASEX
,
367 spx5_port
->phylink_config
.supported_interfaces
);
369 if (spx5_port
->conf
.bandwidth
== SPEED_5000
||
370 spx5_port
->conf
.bandwidth
== SPEED_10000
||
371 spx5_port
->conf
.bandwidth
== SPEED_25000
)
372 __set_bit(PHY_INTERFACE_MODE_5GBASER
,
373 spx5_port
->phylink_config
.supported_interfaces
);
375 if (spx5_port
->conf
.bandwidth
== SPEED_10000
||
376 spx5_port
->conf
.bandwidth
== SPEED_25000
)
377 __set_bit(PHY_INTERFACE_MODE_10GBASER
,
378 spx5_port
->phylink_config
.supported_interfaces
);
380 if (spx5_port
->conf
.bandwidth
== SPEED_25000
)
381 __set_bit(PHY_INTERFACE_MODE_25GBASER
,
382 spx5_port
->phylink_config
.supported_interfaces
);
384 phylink
= phylink_create(&spx5_port
->phylink_config
,
385 of_fwnode_handle(config
->node
),
386 config
->conf
.phy_mode
,
387 &sparx5_phylink_mac_ops
);
389 return PTR_ERR(phylink
);
391 spx5_port
->phylink
= phylink
;
396 static int sparx5_init_ram(struct sparx5
*s5
)
398 const struct sparx5_ram_config spx5_ram_cfg
[] = {
399 {spx5_reg_get(s5
, ANA_AC_STAT_RESET
), ANA_AC_STAT_RESET_RESET
},
400 {spx5_reg_get(s5
, ASM_STAT_CFG
), ASM_STAT_CFG_STAT_CNT_CLR_SHOT
},
401 {spx5_reg_get(s5
, QSYS_RAM_INIT
), QSYS_RAM_INIT_RAM_INIT
},
402 {spx5_reg_get(s5
, REW_RAM_INIT
), QSYS_RAM_INIT_RAM_INIT
},
403 {spx5_reg_get(s5
, VOP_RAM_INIT
), QSYS_RAM_INIT_RAM_INIT
},
404 {spx5_reg_get(s5
, ANA_AC_RAM_INIT
), QSYS_RAM_INIT_RAM_INIT
},
405 {spx5_reg_get(s5
, ASM_RAM_INIT
), QSYS_RAM_INIT_RAM_INIT
},
406 {spx5_reg_get(s5
, EACL_RAM_INIT
), QSYS_RAM_INIT_RAM_INIT
},
407 {spx5_reg_get(s5
, VCAP_SUPER_RAM_INIT
), QSYS_RAM_INIT_RAM_INIT
},
408 {spx5_reg_get(s5
, DSM_RAM_INIT
), QSYS_RAM_INIT_RAM_INIT
}
410 const struct sparx5_ram_config
*cfg
;
411 u32 value
, pending
, jdx
, idx
;
413 for (jdx
= 0; jdx
< 10; jdx
++) {
414 pending
= ARRAY_SIZE(spx5_ram_cfg
);
415 for (idx
= 0; idx
< ARRAY_SIZE(spx5_ram_cfg
); idx
++) {
416 cfg
= &spx5_ram_cfg
[idx
];
418 writel(cfg
->init_val
, cfg
->init_reg
);
420 value
= readl(cfg
->init_reg
);
421 if ((value
& cfg
->init_val
) != cfg
->init_val
)
427 usleep_range(USEC_PER_MSEC
, 2 * USEC_PER_MSEC
);
431 /* Still initializing, should be complete in
434 dev_err(s5
->dev
, "Memory initialization error\n");
440 static int sparx5_init_switchcore(struct sparx5
*sparx5
)
445 spx5_rmw(EACL_POL_EACL_CFG_EACL_FORCE_INIT_SET(1),
446 EACL_POL_EACL_CFG_EACL_FORCE_INIT
,
450 spx5_rmw(EACL_POL_EACL_CFG_EACL_FORCE_INIT_SET(0),
451 EACL_POL_EACL_CFG_EACL_FORCE_INIT
,
455 /* Initialize memories, if not done already */
456 value
= spx5_rd(sparx5
, HSCH_RESET_CFG
);
457 if (!(value
& HSCH_RESET_CFG_CORE_ENA
)) {
458 err
= sparx5_init_ram(sparx5
);
464 spx5_wr(ANA_AC_STAT_RESET_RESET_SET(1), sparx5
, ANA_AC_STAT_RESET
);
465 spx5_wr(ASM_STAT_CFG_STAT_CNT_CLR_SHOT_SET(1), sparx5
, ASM_STAT_CFG
);
467 /* Enable switch-core and queue system */
468 spx5_wr(HSCH_RESET_CFG_CORE_ENA_SET(1), sparx5
, HSCH_RESET_CFG
);
473 static int sparx5_init_coreclock(struct sparx5
*sparx5
)
475 enum sparx5_core_clockfreq freq
= sparx5
->coreclock
;
476 u32 clk_div
, clk_period
, pol_upd_int
, idx
;
478 /* Verify if core clock frequency is supported on target.
479 * If 'VTSS_CORE_CLOCK_DEFAULT' then the highest supported
482 switch (sparx5
->target_ct
) {
483 case SPX5_TARGET_CT_7546
:
484 if (sparx5
->coreclock
== SPX5_CORE_CLOCK_DEFAULT
)
485 freq
= SPX5_CORE_CLOCK_250MHZ
;
486 else if (sparx5
->coreclock
!= SPX5_CORE_CLOCK_250MHZ
)
487 freq
= 0; /* Not supported */
489 case SPX5_TARGET_CT_7549
:
490 case SPX5_TARGET_CT_7552
:
491 case SPX5_TARGET_CT_7556
:
492 if (sparx5
->coreclock
== SPX5_CORE_CLOCK_DEFAULT
)
493 freq
= SPX5_CORE_CLOCK_500MHZ
;
494 else if (sparx5
->coreclock
!= SPX5_CORE_CLOCK_500MHZ
)
495 freq
= 0; /* Not supported */
497 case SPX5_TARGET_CT_7558
:
498 case SPX5_TARGET_CT_7558TSN
:
499 if (sparx5
->coreclock
== SPX5_CORE_CLOCK_DEFAULT
)
500 freq
= SPX5_CORE_CLOCK_625MHZ
;
501 else if (sparx5
->coreclock
!= SPX5_CORE_CLOCK_625MHZ
)
502 freq
= 0; /* Not supported */
504 case SPX5_TARGET_CT_7546TSN
:
505 if (sparx5
->coreclock
== SPX5_CORE_CLOCK_DEFAULT
)
506 freq
= SPX5_CORE_CLOCK_625MHZ
;
508 case SPX5_TARGET_CT_7549TSN
:
509 case SPX5_TARGET_CT_7552TSN
:
510 case SPX5_TARGET_CT_7556TSN
:
511 if (sparx5
->coreclock
== SPX5_CORE_CLOCK_DEFAULT
)
512 freq
= SPX5_CORE_CLOCK_625MHZ
;
513 else if (sparx5
->coreclock
== SPX5_CORE_CLOCK_250MHZ
)
514 freq
= 0; /* Not supported */
516 case SPX5_TARGET_CT_LAN9694
:
517 case SPX5_TARGET_CT_LAN9691VAO
:
518 case SPX5_TARGET_CT_LAN9694TSN
:
519 case SPX5_TARGET_CT_LAN9694RED
:
520 case SPX5_TARGET_CT_LAN9696
:
521 case SPX5_TARGET_CT_LAN9692VAO
:
522 case SPX5_TARGET_CT_LAN9696TSN
:
523 case SPX5_TARGET_CT_LAN9696RED
:
524 case SPX5_TARGET_CT_LAN9698
:
525 case SPX5_TARGET_CT_LAN9693VAO
:
526 case SPX5_TARGET_CT_LAN9698TSN
:
527 case SPX5_TARGET_CT_LAN9698RED
:
528 freq
= SPX5_CORE_CLOCK_328MHZ
;
531 dev_err(sparx5
->dev
, "Target (%#04x) not supported\n",
536 if (is_sparx5(sparx5
)) {
538 case SPX5_CORE_CLOCK_250MHZ
:
542 case SPX5_CORE_CLOCK_500MHZ
:
546 case SPX5_CORE_CLOCK_625MHZ
:
552 "%d coreclock not supported on (%#04x)\n",
553 sparx5
->coreclock
, sparx5
->target_ct
);
557 /* Configure the LCPLL */
558 spx5_rmw(CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_CLK_DIV_SET(clk_div
) |
559 CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_PRE_DIV_SET(0) |
560 CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_ROT_DIR_SET(0) |
561 CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_ROT_SEL_SET(0) |
562 CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_ROT_ENA_SET(0) |
563 CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_CLK_ENA_SET(1),
564 CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_CLK_DIV
|
565 CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_PRE_DIV
|
566 CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_ROT_DIR
|
567 CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_ROT_SEL
|
568 CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_ROT_ENA
|
569 CLKGEN_LCPLL1_CORE_CLK_CFG_CORE_CLK_ENA
,
570 sparx5
, CLKGEN_LCPLL1_CORE_CLK_CFG
);
572 pol_upd_int
= 820; // SPX5_CORE_CLOCK_328MHZ
575 /* Update state with chosen frequency */
576 sparx5
->coreclock
= freq
;
577 clk_period
= sparx5_clk_period(freq
);
579 if (is_sparx5(sparx5
))
580 spx5_rmw(HSCH_SYS_CLK_PER_100PS_SET(clk_period
/ 100),
581 HSCH_SYS_CLK_PER_100PS
,
585 spx5_rmw(ANA_AC_POL_BDLB_DLB_CTRL_CLK_PERIOD_01NS_SET(clk_period
/ 100),
586 ANA_AC_POL_BDLB_DLB_CTRL_CLK_PERIOD_01NS
,
588 ANA_AC_POL_BDLB_DLB_CTRL
);
590 spx5_rmw(ANA_AC_POL_SLB_DLB_CTRL_CLK_PERIOD_01NS_SET(clk_period
/ 100),
591 ANA_AC_POL_SLB_DLB_CTRL_CLK_PERIOD_01NS
,
593 ANA_AC_POL_SLB_DLB_CTRL
);
595 spx5_rmw(LRN_AUTOAGE_CFG_1_CLK_PERIOD_01NS_SET(clk_period
/ 100),
596 LRN_AUTOAGE_CFG_1_CLK_PERIOD_01NS
,
600 for (idx
= 0; idx
< sparx5
->data
->consts
->n_sio_clks
; idx
++)
601 spx5_rmw(GCB_SIO_CLOCK_SYS_CLK_PERIOD_SET(clk_period
/ 100),
602 GCB_SIO_CLOCK_SYS_CLK_PERIOD
,
606 spx5_rmw(HSCH_TAS_STATEMACHINE_CFG_REVISIT_DLY_SET
607 ((256 * 1000) / clk_period
),
608 HSCH_TAS_STATEMACHINE_CFG_REVISIT_DLY
,
610 HSCH_TAS_STATEMACHINE_CFG
);
612 spx5_rmw(ANA_AC_POL_POL_UPD_INT_CFG_POL_UPD_INT_SET(pol_upd_int
),
613 ANA_AC_POL_POL_UPD_INT_CFG_POL_UPD_INT
,
615 ANA_AC_POL_POL_UPD_INT_CFG
);
620 static u32
qlim_wm(struct sparx5
*sparx5
, int fraction
)
622 return (sparx5
->data
->consts
->buf_size
/ SPX5_BUFFER_CELL_SZ
- 100) *
626 static int sparx5_qlim_set(struct sparx5
*sparx5
)
628 const struct sparx5_consts
*consts
= sparx5
->data
->consts
;
631 for (res
= 0; res
< 2; res
++) {
632 for (prio
= 0; prio
< 8; prio
++)
633 spx5_wr(0xFFF, sparx5
,
635 consts
->qres_max_prio_idx
+
638 for (dp
= 0; dp
< 4; dp
++)
639 spx5_wr(0xFFF, sparx5
,
641 consts
->qres_max_colour_idx
+
645 /* Set 80,90,95,100% of memory size for top watermarks */
646 spx5_wr(qlim_wm(sparx5
, 80), sparx5
, XQS_QLIMIT_SHR_QLIM_CFG(0));
647 spx5_wr(qlim_wm(sparx5
, 90), sparx5
, XQS_QLIMIT_SHR_CTOP_CFG(0));
648 spx5_wr(qlim_wm(sparx5
, 95), sparx5
, XQS_QLIMIT_SHR_ATOP_CFG(0));
649 spx5_wr(qlim_wm(sparx5
, 100), sparx5
, XQS_QLIMIT_SHR_TOP_CFG(0));
654 /* Some boards needs to map the SGPIO for signal detect explicitly to the
657 static void sparx5_board_init(struct sparx5
*sparx5
)
661 if (!sparx5
->sd_sgpio_remapping
)
664 /* Enable SGPIO Signal Detect remapping */
665 spx5_rmw(GCB_HW_SGPIO_SD_CFG_SD_MAP_SEL
,
666 GCB_HW_SGPIO_SD_CFG_SD_MAP_SEL
,
668 GCB_HW_SGPIO_SD_CFG
);
670 /* Refer to LOS SGPIO */
671 for (idx
= 0; idx
< sparx5
->data
->consts
->n_ports
; idx
++)
672 if (sparx5
->ports
[idx
])
673 if (sparx5
->ports
[idx
]->conf
.sd_sgpio
!= ~0)
674 spx5_wr(sparx5
->ports
[idx
]->conf
.sd_sgpio
,
676 GCB_HW_SGPIO_TO_SD_MAP_CFG(idx
));
679 static int sparx5_start(struct sparx5
*sparx5
)
681 u8 broadcast
[ETH_ALEN
] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
682 const struct sparx5_consts
*consts
= sparx5
->data
->consts
;
683 const struct sparx5_ops
*ops
= sparx5
->data
->ops
;
688 /* Setup own UPSIDs */
689 for (idx
= 0; idx
< consts
->n_own_upsids
; idx
++) {
690 spx5_wr(idx
, sparx5
, ANA_AC_OWN_UPSID(idx
));
691 spx5_wr(idx
, sparx5
, ANA_CL_OWN_UPSID(idx
));
692 spx5_wr(idx
, sparx5
, ANA_L2_OWN_UPSID(idx
));
693 spx5_wr(idx
, sparx5
, REW_OWN_UPSID(idx
));
696 /* Enable CPU ports */
697 for (idx
= consts
->n_ports
; idx
< consts
->n_ports_all
; idx
++)
698 spx5_rmw(QFWD_SWITCH_PORT_MODE_PORT_ENA_SET(1),
699 QFWD_SWITCH_PORT_MODE_PORT_ENA
,
701 QFWD_SWITCH_PORT_MODE(idx
));
704 sparx5_update_fwd(sparx5
);
706 /* CPU copy CPU pgids */
707 spx5_wr(ANA_AC_PGID_MISC_CFG_PGID_CPU_COPY_ENA_SET(1), sparx5
,
708 ANA_AC_PGID_MISC_CFG(sparx5_get_pgid(sparx5
, PGID_CPU
)));
709 spx5_wr(ANA_AC_PGID_MISC_CFG_PGID_CPU_COPY_ENA_SET(1), sparx5
,
710 ANA_AC_PGID_MISC_CFG(sparx5_get_pgid(sparx5
, PGID_BCAST
)));
712 /* Recalc injected frame FCS */
713 for (idx
= sparx5_get_internal_port(sparx5
, SPX5_PORT_CPU_0
);
714 idx
<= sparx5_get_internal_port(sparx5
, SPX5_PORT_CPU_1
); idx
++)
715 spx5_rmw(ANA_CL_FILTER_CTRL_FORCE_FCS_UPDATE_ENA_SET(1),
716 ANA_CL_FILTER_CTRL_FORCE_FCS_UPDATE_ENA
,
717 sparx5
, ANA_CL_FILTER_CTRL(idx
));
719 /* Init MAC table, ageing */
720 sparx5_mact_init(sparx5
);
722 /* Init PGID table arbitrator */
723 sparx5_pgid_init(sparx5
);
726 sparx5_vlan_init(sparx5
);
728 /* Add host mode BC address (points only to CPU) */
729 sparx5_mact_learn(sparx5
, sparx5_get_pgid(sparx5
, PGID_CPU
), broadcast
,
732 /* Enable queue limitation watermarks */
733 sparx5_qlim_set(sparx5
);
735 err
= sparx5_config_auto_calendar(sparx5
);
739 err
= sparx5_config_dsm_calendar(sparx5
);
744 err
= sparx_stats_init(sparx5
);
748 /* Init mact_sw struct */
749 mutex_init(&sparx5
->mact_lock
);
750 INIT_LIST_HEAD(&sparx5
->mact_entries
);
751 snprintf(queue_name
, sizeof(queue_name
), "%s-mact",
752 dev_name(sparx5
->dev
));
753 sparx5
->mact_queue
= create_singlethread_workqueue(queue_name
);
754 if (!sparx5
->mact_queue
)
757 INIT_DELAYED_WORK(&sparx5
->mact_work
, sparx5_mact_pull_work
);
758 queue_delayed_work(sparx5
->mact_queue
, &sparx5
->mact_work
,
759 SPX5_MACT_PULL_DELAY
);
761 mutex_init(&sparx5
->mdb_lock
);
762 INIT_LIST_HEAD(&sparx5
->mdb_entries
);
764 err
= sparx5_register_netdevs(sparx5
);
768 sparx5_board_init(sparx5
);
769 err
= sparx5_register_notifier_blocks(sparx5
);
773 err
= sparx5_vcap_init(sparx5
);
775 sparx5_unregister_notifier_blocks(sparx5
);
779 /* Start Frame DMA with fallback to register based INJ/XTR */
781 if (sparx5
->fdma_irq
>= 0 && is_sparx5(sparx5
)) {
782 if (GCB_CHIP_ID_REV_ID_GET(sparx5
->chip_id
) > 0)
783 err
= devm_request_threaded_irq(sparx5
->dev
,
788 "sparx5-fdma", sparx5
);
790 err
= sparx5_fdma_start(sparx5
);
792 sparx5
->fdma_irq
= -ENXIO
;
794 sparx5
->fdma_irq
= -ENXIO
;
796 if (err
&& sparx5
->xtr_irq
>= 0) {
797 err
= devm_request_irq(sparx5
->dev
, sparx5
->xtr_irq
,
798 sparx5_xtr_handler
, IRQF_SHARED
,
799 "sparx5-xtr", sparx5
);
801 err
= sparx5_manual_injection_mode(sparx5
);
803 sparx5
->xtr_irq
= -ENXIO
;
805 sparx5
->xtr_irq
= -ENXIO
;
808 if (sparx5
->ptp_irq
>= 0 &&
809 sparx5_has_feature(sparx5
, SPX5_FEATURE_PTP
)) {
810 err
= devm_request_threaded_irq(sparx5
->dev
, sparx5
->ptp_irq
,
811 NULL
, ops
->ptp_irq_handler
,
812 IRQF_ONESHOT
, "sparx5-ptp",
815 sparx5
->ptp_irq
= -ENXIO
;
823 static void sparx5_cleanup_ports(struct sparx5
*sparx5
)
825 sparx5_unregister_netdevs(sparx5
);
826 sparx5_destroy_netdevs(sparx5
);
829 static int mchp_sparx5_probe(struct platform_device
*pdev
)
831 struct initial_port_config
*configs
, *config
;
832 struct device_node
*np
= pdev
->dev
.of_node
;
833 struct device_node
*ports
, *portnp
;
834 struct reset_control
*reset
;
835 struct sparx5
*sparx5
;
836 int idx
= 0, err
= 0;
838 if (!np
&& !pdev
->dev
.platform_data
)
841 sparx5
= devm_kzalloc(&pdev
->dev
, sizeof(*sparx5
), GFP_KERNEL
);
845 platform_set_drvdata(pdev
, sparx5
);
847 sparx5
->dev
= &pdev
->dev
;
848 spin_lock_init(&sparx5
->tx_lock
);
850 sparx5
->data
= device_get_match_data(sparx5
->dev
);
854 regs
= sparx5
->data
->regs
;
856 /* Do switch core reset if available */
857 reset
= devm_reset_control_get_optional_shared(&pdev
->dev
, "switch");
859 return dev_err_probe(&pdev
->dev
, PTR_ERR(reset
),
860 "Failed to get switch reset controller.\n");
861 reset_control_reset(reset
);
863 /* Default values, some from DT */
864 sparx5
->coreclock
= SPX5_CORE_CLOCK_DEFAULT
;
866 sparx5
->debugfs_root
= debugfs_create_dir("sparx5", NULL
);
868 ports
= of_get_child_by_name(np
, "ethernet-ports");
870 dev_err(sparx5
->dev
, "no ethernet-ports child node found\n");
873 sparx5
->port_count
= of_get_child_count(ports
);
875 configs
= kcalloc(sparx5
->port_count
,
876 sizeof(struct initial_port_config
), GFP_KERNEL
);
882 for_each_available_child_of_node(ports
, portnp
) {
883 struct sparx5_port_config
*conf
;
887 err
= of_property_read_u32(portnp
, "reg", &portno
);
889 dev_err(sparx5
->dev
, "port reg property error\n");
892 config
= &configs
[idx
];
893 conf
= &config
->conf
;
894 conf
->speed
= SPEED_UNKNOWN
;
895 conf
->bandwidth
= SPEED_UNKNOWN
;
896 err
= of_get_phy_mode(portnp
, &conf
->phy_mode
);
898 dev_err(sparx5
->dev
, "port %u: missing phy-mode\n",
902 err
= of_property_read_u32(portnp
, "microchip,bandwidth",
905 dev_err(sparx5
->dev
, "port %u: missing bandwidth\n",
909 err
= of_property_read_u32(portnp
, "microchip,sd-sgpio", &conf
->sd_sgpio
);
913 sparx5
->sd_sgpio_remapping
= true;
914 serdes
= devm_of_phy_get(sparx5
->dev
, portnp
, NULL
);
915 if (IS_ERR(serdes
)) {
916 err
= dev_err_probe(sparx5
->dev
, PTR_ERR(serdes
),
917 "port %u: missing serdes\n",
922 config
->portno
= portno
;
923 config
->node
= portnp
;
924 config
->serdes
= serdes
;
926 conf
->media
= PHY_MEDIA_DAC
;
927 conf
->serdes_reset
= true;
928 conf
->portmode
= conf
->phy_mode
;
929 conf
->power_down
= true;
933 err
= sparx5_create_targets(sparx5
);
937 if (of_get_mac_address(np
, sparx5
->base_mac
)) {
938 dev_info(sparx5
->dev
, "MAC addr was not set, use random MAC\n");
939 eth_random_addr(sparx5
->base_mac
);
940 sparx5
->base_mac
[5] = 0;
943 sparx5
->fdma_irq
= platform_get_irq_byname(sparx5
->pdev
, "fdma");
944 sparx5
->xtr_irq
= platform_get_irq_byname(sparx5
->pdev
, "xtr");
945 sparx5
->ptp_irq
= platform_get_irq_byname(sparx5
->pdev
, "ptp");
947 /* Read chip ID to check CPU interface */
948 sparx5
->chip_id
= spx5_rd(sparx5
, GCB_CHIP_ID
);
950 sparx5
->target_ct
= (enum spx5_target_chiptype
)
951 GCB_CHIP_ID_PART_ID_GET(sparx5
->chip_id
);
953 /* Initialize the features based on the target */
954 sparx5_init_features(sparx5
);
956 /* Initialize Switchcore and internal RAMs */
957 err
= sparx5_init_switchcore(sparx5
);
959 dev_err(sparx5
->dev
, "Switchcore initialization error\n");
963 /* Initialize the LC-PLL (core clock) and set affected registers */
964 err
= sparx5_init_coreclock(sparx5
);
966 dev_err(sparx5
->dev
, "LC-PLL initialization error\n");
970 for (idx
= 0; idx
< sparx5
->port_count
; ++idx
) {
971 config
= &configs
[idx
];
975 err
= sparx5_create_port(sparx5
, config
);
977 dev_err(sparx5
->dev
, "port create error\n");
982 err
= sparx5_start(sparx5
);
984 dev_err(sparx5
->dev
, "Start failed\n");
988 err
= sparx5_qos_init(sparx5
);
990 dev_err(sparx5
->dev
, "Failed to initialize QoS\n");
994 err
= sparx5_ptp_init(sparx5
);
996 dev_err(sparx5
->dev
, "PTP failed\n");
1000 INIT_LIST_HEAD(&sparx5
->mall_entries
);
1002 goto cleanup_config
;
1005 sparx5_cleanup_ports(sparx5
);
1006 if (sparx5
->mact_queue
)
1007 destroy_workqueue(sparx5
->mact_queue
);
1015 static void mchp_sparx5_remove(struct platform_device
*pdev
)
1017 struct sparx5
*sparx5
= platform_get_drvdata(pdev
);
1019 debugfs_remove_recursive(sparx5
->debugfs_root
);
1020 if (sparx5
->xtr_irq
) {
1021 disable_irq(sparx5
->xtr_irq
);
1022 sparx5
->xtr_irq
= -ENXIO
;
1024 if (sparx5
->fdma_irq
) {
1025 disable_irq(sparx5
->fdma_irq
);
1026 sparx5
->fdma_irq
= -ENXIO
;
1028 sparx5_ptp_deinit(sparx5
);
1029 sparx5_fdma_stop(sparx5
);
1030 sparx5_cleanup_ports(sparx5
);
1031 sparx5_vcap_destroy(sparx5
);
1032 /* Unregister netdevs */
1033 sparx5_unregister_notifier_blocks(sparx5
);
1034 destroy_workqueue(sparx5
->mact_queue
);
1037 static const struct sparx5_regs sparx5_regs
= {
1038 .tsize
= sparx5_tsize
,
1039 .gaddr
= sparx5_gaddr
,
1040 .gcnt
= sparx5_gcnt
,
1041 .gsize
= sparx5_gsize
,
1042 .raddr
= sparx5_raddr
,
1043 .rcnt
= sparx5_rcnt
,
1044 .fpos
= sparx5_fpos
,
1045 .fsize
= sparx5_fsize
,
1048 static const struct sparx5_consts sparx5_consts
= {
1051 .n_hsch_l1_elems
= 64,
1054 .n_pgids
= 2113, /* (2048 + n_ports) */
1061 .n_dsm_cal_taxis
= 8,
1062 .buf_size
= 4194280,
1063 .qres_max_prio_idx
= 630,
1064 .qres_max_colour_idx
= 638,
1066 .vcaps
= sparx5_vcaps
,
1067 .vcaps_cfg
= sparx5_vcap_inst_cfg
,
1068 .vcap_stats
= &sparx5_vcap_stats
,
1071 static const struct sparx5_ops sparx5_ops
= {
1072 .is_port_2g5
= &sparx5_port_is_2g5
,
1073 .is_port_5g
= &sparx5_port_is_5g
,
1074 .is_port_10g
= &sparx5_port_is_10g
,
1075 .is_port_25g
= &sparx5_port_is_25g
,
1076 .get_port_dev_index
= &sparx5_port_dev_mapping
,
1077 .get_port_dev_bit
= &sparx5_port_dev_mapping
,
1078 .get_hsch_max_group_rate
= &sparx5_get_hsch_max_group_rate
,
1079 .get_sdlb_group
= &sparx5_get_sdlb_group
,
1080 .set_port_mux
= &sparx5_port_mux_set
,
1081 .ptp_irq_handler
= &sparx5_ptp_irq_handler
,
1082 .dsm_calendar_calc
= &sparx5_dsm_calendar_calc
,
1085 static const struct sparx5_match_data sparx5_desc
= {
1086 .iomap
= sparx5_main_iomap
,
1087 .iomap_size
= ARRAY_SIZE(sparx5_main_iomap
),
1089 .regs
= &sparx5_regs
,
1090 .consts
= &sparx5_consts
,
1094 static const struct of_device_id mchp_sparx5_match
[] = {
1095 { .compatible
= "microchip,sparx5-switch", .data
= &sparx5_desc
},
1096 #if IS_ENABLED(CONFIG_LAN969X_SWITCH)
1097 { .compatible
= "microchip,lan9691-switch", .data
= &lan969x_desc
},
1101 MODULE_DEVICE_TABLE(of
, mchp_sparx5_match
);
1103 static struct platform_driver mchp_sparx5_driver
= {
1104 .probe
= mchp_sparx5_probe
,
1105 .remove
= mchp_sparx5_remove
,
1107 .name
= "sparx5-switch",
1108 .of_match_table
= mchp_sparx5_match
,
1112 module_platform_driver(mchp_sparx5_driver
);
1114 MODULE_DESCRIPTION("Microchip Sparx5 switch driver");
1115 MODULE_AUTHOR("Steen Hegelund <steen.hegelund@microchip.com>");
1116 MODULE_LICENSE("Dual MIT/GPL");