blob: 35c4dc2799c0e915a2d4480b70f2d9b58cbb9142 [file] [log] [blame]
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001// SPDX-License-Identifier: (GPL-2.0 OR MIT)
2/* Distributed Switch Architecture VSC9953 driver
3 * Copyright (C) 2020, Maxim Kochetkov <fido_max@inbox.ru>
4 */
5#include <linux/types.h>
6#include <soc/mscc/ocelot_vcap.h>
7#include <soc/mscc/ocelot_sys.h>
8#include <soc/mscc/ocelot.h>
9#include <linux/of_platform.h>
Ioana Ciornei588d0552020-08-30 11:34:02 +030010#include <linux/pcs-lynx.h>
Maxim Kochetkov84705fc2020-07-13 19:57:10 +030011#include <linux/packing.h>
12#include <linux/iopoll.h>
13#include "felix.h"
14
15#define VSC9953_VCAP_IS2_CNT 1024
16#define VSC9953_VCAP_IS2_ENTRY_WIDTH 376
17#define VSC9953_VCAP_PORT_CNT 10
18
Vladimir Oltean123d2312020-09-18 13:57:48 +030019#define MSCC_MIIM_CMD_OPR_WRITE BIT(1)
20#define MSCC_MIIM_CMD_OPR_READ BIT(2)
21#define MSCC_MIIM_CMD_WRDATA_SHIFT 4
22#define MSCC_MIIM_CMD_REGAD_SHIFT 20
23#define MSCC_MIIM_CMD_PHYAD_SHIFT 25
24#define MSCC_MIIM_CMD_VLD BIT(31)
Maxim Kochetkov84705fc2020-07-13 19:57:10 +030025
26static const u32 vsc9953_ana_regmap[] = {
27 REG(ANA_ADVLEARN, 0x00b500),
28 REG(ANA_VLANMASK, 0x00b504),
29 REG_RESERVED(ANA_PORT_B_DOMAIN),
30 REG(ANA_ANAGEFIL, 0x00b50c),
31 REG(ANA_ANEVENTS, 0x00b510),
32 REG(ANA_STORMLIMIT_BURST, 0x00b514),
33 REG(ANA_STORMLIMIT_CFG, 0x00b518),
34 REG(ANA_ISOLATED_PORTS, 0x00b528),
35 REG(ANA_COMMUNITY_PORTS, 0x00b52c),
36 REG(ANA_AUTOAGE, 0x00b530),
37 REG(ANA_MACTOPTIONS, 0x00b534),
38 REG(ANA_LEARNDISC, 0x00b538),
39 REG(ANA_AGENCTRL, 0x00b53c),
40 REG(ANA_MIRRORPORTS, 0x00b540),
41 REG(ANA_EMIRRORPORTS, 0x00b544),
42 REG(ANA_FLOODING, 0x00b548),
43 REG(ANA_FLOODING_IPMC, 0x00b54c),
44 REG(ANA_SFLOW_CFG, 0x00b550),
45 REG(ANA_PORT_MODE, 0x00b57c),
46 REG_RESERVED(ANA_CUT_THRU_CFG),
47 REG(ANA_PGID_PGID, 0x00b600),
48 REG(ANA_TABLES_ANMOVED, 0x00b4ac),
49 REG(ANA_TABLES_MACHDATA, 0x00b4b0),
50 REG(ANA_TABLES_MACLDATA, 0x00b4b4),
51 REG_RESERVED(ANA_TABLES_STREAMDATA),
52 REG(ANA_TABLES_MACACCESS, 0x00b4b8),
53 REG(ANA_TABLES_MACTINDX, 0x00b4bc),
54 REG(ANA_TABLES_VLANACCESS, 0x00b4c0),
55 REG(ANA_TABLES_VLANTIDX, 0x00b4c4),
56 REG_RESERVED(ANA_TABLES_ISDXACCESS),
57 REG_RESERVED(ANA_TABLES_ISDXTIDX),
58 REG(ANA_TABLES_ENTRYLIM, 0x00b480),
59 REG_RESERVED(ANA_TABLES_PTP_ID_HIGH),
60 REG_RESERVED(ANA_TABLES_PTP_ID_LOW),
61 REG_RESERVED(ANA_TABLES_STREAMACCESS),
62 REG_RESERVED(ANA_TABLES_STREAMTIDX),
63 REG_RESERVED(ANA_TABLES_SEQ_HISTORY),
64 REG_RESERVED(ANA_TABLES_SEQ_MASK),
65 REG_RESERVED(ANA_TABLES_SFID_MASK),
66 REG_RESERVED(ANA_TABLES_SFIDACCESS),
67 REG_RESERVED(ANA_TABLES_SFIDTIDX),
68 REG_RESERVED(ANA_MSTI_STATE),
69 REG_RESERVED(ANA_OAM_UPM_LM_CNT),
70 REG_RESERVED(ANA_SG_ACCESS_CTRL),
71 REG_RESERVED(ANA_SG_CONFIG_REG_1),
72 REG_RESERVED(ANA_SG_CONFIG_REG_2),
73 REG_RESERVED(ANA_SG_CONFIG_REG_3),
74 REG_RESERVED(ANA_SG_CONFIG_REG_4),
75 REG_RESERVED(ANA_SG_CONFIG_REG_5),
76 REG_RESERVED(ANA_SG_GCL_GS_CONFIG),
77 REG_RESERVED(ANA_SG_GCL_TI_CONFIG),
78 REG_RESERVED(ANA_SG_STATUS_REG_1),
79 REG_RESERVED(ANA_SG_STATUS_REG_2),
80 REG_RESERVED(ANA_SG_STATUS_REG_3),
81 REG(ANA_PORT_VLAN_CFG, 0x000000),
82 REG(ANA_PORT_DROP_CFG, 0x000004),
83 REG(ANA_PORT_QOS_CFG, 0x000008),
84 REG(ANA_PORT_VCAP_CFG, 0x00000c),
85 REG(ANA_PORT_VCAP_S1_KEY_CFG, 0x000010),
86 REG(ANA_PORT_VCAP_S2_CFG, 0x00001c),
87 REG(ANA_PORT_PCP_DEI_MAP, 0x000020),
88 REG(ANA_PORT_CPU_FWD_CFG, 0x000060),
89 REG(ANA_PORT_CPU_FWD_BPDU_CFG, 0x000064),
90 REG(ANA_PORT_CPU_FWD_GARP_CFG, 0x000068),
91 REG(ANA_PORT_CPU_FWD_CCM_CFG, 0x00006c),
92 REG(ANA_PORT_PORT_CFG, 0x000070),
93 REG(ANA_PORT_POL_CFG, 0x000074),
94 REG_RESERVED(ANA_PORT_PTP_CFG),
95 REG_RESERVED(ANA_PORT_PTP_DLY1_CFG),
96 REG_RESERVED(ANA_PORT_PTP_DLY2_CFG),
97 REG_RESERVED(ANA_PORT_SFID_CFG),
98 REG(ANA_PFC_PFC_CFG, 0x00c000),
99 REG_RESERVED(ANA_PFC_PFC_TIMER),
100 REG_RESERVED(ANA_IPT_OAM_MEP_CFG),
101 REG_RESERVED(ANA_IPT_IPT),
102 REG_RESERVED(ANA_PPT_PPT),
103 REG_RESERVED(ANA_FID_MAP_FID_MAP),
104 REG(ANA_AGGR_CFG, 0x00c600),
105 REG(ANA_CPUQ_CFG, 0x00c604),
106 REG_RESERVED(ANA_CPUQ_CFG2),
107 REG(ANA_CPUQ_8021_CFG, 0x00c60c),
108 REG(ANA_DSCP_CFG, 0x00c64c),
109 REG(ANA_DSCP_REWR_CFG, 0x00c74c),
110 REG(ANA_VCAP_RNG_TYPE_CFG, 0x00c78c),
111 REG(ANA_VCAP_RNG_VAL_CFG, 0x00c7ac),
112 REG_RESERVED(ANA_VRAP_CFG),
113 REG_RESERVED(ANA_VRAP_HDR_DATA),
114 REG_RESERVED(ANA_VRAP_HDR_MASK),
115 REG(ANA_DISCARD_CFG, 0x00c7d8),
116 REG(ANA_FID_CFG, 0x00c7dc),
117 REG(ANA_POL_PIR_CFG, 0x00a000),
118 REG(ANA_POL_CIR_CFG, 0x00a004),
119 REG(ANA_POL_MODE_CFG, 0x00a008),
120 REG(ANA_POL_PIR_STATE, 0x00a00c),
121 REG(ANA_POL_CIR_STATE, 0x00a010),
122 REG_RESERVED(ANA_POL_STATE),
123 REG(ANA_POL_FLOWC, 0x00c280),
124 REG(ANA_POL_HYST, 0x00c2ec),
125 REG_RESERVED(ANA_POL_MISC_CFG),
126};
127
128static const u32 vsc9953_qs_regmap[] = {
129 REG(QS_XTR_GRP_CFG, 0x000000),
130 REG(QS_XTR_RD, 0x000008),
131 REG(QS_XTR_FRM_PRUNING, 0x000010),
132 REG(QS_XTR_FLUSH, 0x000018),
133 REG(QS_XTR_DATA_PRESENT, 0x00001c),
134 REG(QS_XTR_CFG, 0x000020),
135 REG(QS_INJ_GRP_CFG, 0x000024),
136 REG(QS_INJ_WR, 0x00002c),
137 REG(QS_INJ_CTRL, 0x000034),
138 REG(QS_INJ_STATUS, 0x00003c),
139 REG(QS_INJ_ERR, 0x000040),
140 REG_RESERVED(QS_INH_DBG),
141};
142
Vladimir Olteanc1c39932020-09-30 01:27:23 +0300143static const u32 vsc9953_vcap_regmap[] = {
144 /* VCAP_CORE_CFG */
145 REG(VCAP_CORE_UPDATE_CTRL, 0x000000),
146 REG(VCAP_CORE_MV_CFG, 0x000004),
147 /* VCAP_CORE_CACHE */
148 REG(VCAP_CACHE_ENTRY_DAT, 0x000008),
149 REG(VCAP_CACHE_MASK_DAT, 0x000108),
150 REG(VCAP_CACHE_ACTION_DAT, 0x000208),
151 REG(VCAP_CACHE_CNT_DAT, 0x000308),
152 REG(VCAP_CACHE_TG_DAT, 0x000388),
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300153};
154
155static const u32 vsc9953_qsys_regmap[] = {
156 REG(QSYS_PORT_MODE, 0x003600),
157 REG(QSYS_SWITCH_PORT_MODE, 0x003630),
158 REG(QSYS_STAT_CNT_CFG, 0x00365c),
159 REG(QSYS_EEE_CFG, 0x003660),
160 REG(QSYS_EEE_THRES, 0x003688),
161 REG(QSYS_IGR_NO_SHARING, 0x00368c),
162 REG(QSYS_EGR_NO_SHARING, 0x003690),
163 REG(QSYS_SW_STATUS, 0x003694),
164 REG(QSYS_EXT_CPU_CFG, 0x0036c0),
165 REG_RESERVED(QSYS_PAD_CFG),
166 REG(QSYS_CPU_GROUP_MAP, 0x0036c8),
167 REG_RESERVED(QSYS_QMAP),
168 REG_RESERVED(QSYS_ISDX_SGRP),
169 REG_RESERVED(QSYS_TIMED_FRAME_ENTRY),
170 REG_RESERVED(QSYS_TFRM_MISC),
171 REG_RESERVED(QSYS_TFRM_PORT_DLY),
172 REG_RESERVED(QSYS_TFRM_TIMER_CFG_1),
173 REG_RESERVED(QSYS_TFRM_TIMER_CFG_2),
174 REG_RESERVED(QSYS_TFRM_TIMER_CFG_3),
175 REG_RESERVED(QSYS_TFRM_TIMER_CFG_4),
176 REG_RESERVED(QSYS_TFRM_TIMER_CFG_5),
177 REG_RESERVED(QSYS_TFRM_TIMER_CFG_6),
178 REG_RESERVED(QSYS_TFRM_TIMER_CFG_7),
179 REG_RESERVED(QSYS_TFRM_TIMER_CFG_8),
180 REG(QSYS_RED_PROFILE, 0x003724),
181 REG(QSYS_RES_QOS_MODE, 0x003764),
182 REG(QSYS_RES_CFG, 0x004000),
183 REG(QSYS_RES_STAT, 0x004004),
184 REG(QSYS_EGR_DROP_MODE, 0x003768),
185 REG(QSYS_EQ_CTRL, 0x00376c),
186 REG_RESERVED(QSYS_EVENTS_CORE),
187 REG_RESERVED(QSYS_QMAXSDU_CFG_0),
188 REG_RESERVED(QSYS_QMAXSDU_CFG_1),
189 REG_RESERVED(QSYS_QMAXSDU_CFG_2),
190 REG_RESERVED(QSYS_QMAXSDU_CFG_3),
191 REG_RESERVED(QSYS_QMAXSDU_CFG_4),
192 REG_RESERVED(QSYS_QMAXSDU_CFG_5),
193 REG_RESERVED(QSYS_QMAXSDU_CFG_6),
194 REG_RESERVED(QSYS_QMAXSDU_CFG_7),
195 REG_RESERVED(QSYS_PREEMPTION_CFG),
196 REG(QSYS_CIR_CFG, 0x000000),
197 REG_RESERVED(QSYS_EIR_CFG),
198 REG(QSYS_SE_CFG, 0x000008),
199 REG(QSYS_SE_DWRR_CFG, 0x00000c),
200 REG_RESERVED(QSYS_SE_CONNECT),
201 REG_RESERVED(QSYS_SE_DLB_SENSE),
202 REG(QSYS_CIR_STATE, 0x000044),
203 REG_RESERVED(QSYS_EIR_STATE),
204 REG_RESERVED(QSYS_SE_STATE),
205 REG(QSYS_HSCH_MISC_CFG, 0x003774),
206 REG_RESERVED(QSYS_TAG_CONFIG),
207 REG_RESERVED(QSYS_TAS_PARAM_CFG_CTRL),
208 REG_RESERVED(QSYS_PORT_MAX_SDU),
209 REG_RESERVED(QSYS_PARAM_CFG_REG_1),
210 REG_RESERVED(QSYS_PARAM_CFG_REG_2),
211 REG_RESERVED(QSYS_PARAM_CFG_REG_3),
212 REG_RESERVED(QSYS_PARAM_CFG_REG_4),
213 REG_RESERVED(QSYS_PARAM_CFG_REG_5),
214 REG_RESERVED(QSYS_GCL_CFG_REG_1),
215 REG_RESERVED(QSYS_GCL_CFG_REG_2),
216 REG_RESERVED(QSYS_PARAM_STATUS_REG_1),
217 REG_RESERVED(QSYS_PARAM_STATUS_REG_2),
218 REG_RESERVED(QSYS_PARAM_STATUS_REG_3),
219 REG_RESERVED(QSYS_PARAM_STATUS_REG_4),
220 REG_RESERVED(QSYS_PARAM_STATUS_REG_5),
221 REG_RESERVED(QSYS_PARAM_STATUS_REG_6),
222 REG_RESERVED(QSYS_PARAM_STATUS_REG_7),
223 REG_RESERVED(QSYS_PARAM_STATUS_REG_8),
224 REG_RESERVED(QSYS_PARAM_STATUS_REG_9),
225 REG_RESERVED(QSYS_GCL_STATUS_REG_1),
226 REG_RESERVED(QSYS_GCL_STATUS_REG_2),
227};
228
229static const u32 vsc9953_rew_regmap[] = {
230 REG(REW_PORT_VLAN_CFG, 0x000000),
231 REG(REW_TAG_CFG, 0x000004),
232 REG(REW_PORT_CFG, 0x000008),
233 REG(REW_DSCP_CFG, 0x00000c),
234 REG(REW_PCP_DEI_QOS_MAP_CFG, 0x000010),
235 REG_RESERVED(REW_PTP_CFG),
236 REG_RESERVED(REW_PTP_DLY1_CFG),
237 REG_RESERVED(REW_RED_TAG_CFG),
238 REG(REW_DSCP_REMAP_DP1_CFG, 0x000610),
239 REG(REW_DSCP_REMAP_CFG, 0x000710),
240 REG_RESERVED(REW_STAT_CFG),
241 REG_RESERVED(REW_REW_STICKY),
242 REG_RESERVED(REW_PPT),
243};
244
245static const u32 vsc9953_sys_regmap[] = {
246 REG(SYS_COUNT_RX_OCTETS, 0x000000),
247 REG(SYS_COUNT_RX_MULTICAST, 0x000008),
248 REG(SYS_COUNT_RX_SHORTS, 0x000010),
249 REG(SYS_COUNT_RX_FRAGMENTS, 0x000014),
250 REG(SYS_COUNT_RX_JABBERS, 0x000018),
251 REG(SYS_COUNT_RX_64, 0x000024),
252 REG(SYS_COUNT_RX_65_127, 0x000028),
253 REG(SYS_COUNT_RX_128_255, 0x00002c),
254 REG(SYS_COUNT_RX_256_1023, 0x000030),
255 REG(SYS_COUNT_RX_1024_1526, 0x000034),
256 REG(SYS_COUNT_RX_1527_MAX, 0x000038),
257 REG(SYS_COUNT_RX_LONGS, 0x000048),
258 REG(SYS_COUNT_TX_OCTETS, 0x000100),
259 REG(SYS_COUNT_TX_COLLISION, 0x000110),
260 REG(SYS_COUNT_TX_DROPS, 0x000114),
261 REG(SYS_COUNT_TX_64, 0x00011c),
262 REG(SYS_COUNT_TX_65_127, 0x000120),
263 REG(SYS_COUNT_TX_128_511, 0x000124),
264 REG(SYS_COUNT_TX_512_1023, 0x000128),
265 REG(SYS_COUNT_TX_1024_1526, 0x00012c),
266 REG(SYS_COUNT_TX_1527_MAX, 0x000130),
267 REG(SYS_COUNT_TX_AGING, 0x000178),
268 REG(SYS_RESET_CFG, 0x000318),
269 REG_RESERVED(SYS_SR_ETYPE_CFG),
270 REG(SYS_VLAN_ETYPE_CFG, 0x000320),
271 REG(SYS_PORT_MODE, 0x000324),
272 REG(SYS_FRONT_PORT_MODE, 0x000354),
273 REG(SYS_FRM_AGING, 0x00037c),
274 REG(SYS_STAT_CFG, 0x000380),
275 REG_RESERVED(SYS_SW_STATUS),
276 REG_RESERVED(SYS_MISC_CFG),
277 REG_RESERVED(SYS_REW_MAC_HIGH_CFG),
278 REG_RESERVED(SYS_REW_MAC_LOW_CFG),
279 REG_RESERVED(SYS_TIMESTAMP_OFFSET),
280 REG(SYS_PAUSE_CFG, 0x00044c),
281 REG(SYS_PAUSE_TOT_CFG, 0x000478),
282 REG(SYS_ATOP, 0x00047c),
283 REG(SYS_ATOP_TOT_CFG, 0x0004a8),
284 REG(SYS_MAC_FC_CFG, 0x0004ac),
285 REG(SYS_MMGT, 0x0004d4),
286 REG_RESERVED(SYS_MMGT_FAST),
287 REG_RESERVED(SYS_EVENTS_DIF),
288 REG_RESERVED(SYS_EVENTS_CORE),
289 REG_RESERVED(SYS_CNT),
290 REG_RESERVED(SYS_PTP_STATUS),
291 REG_RESERVED(SYS_PTP_TXSTAMP),
292 REG_RESERVED(SYS_PTP_NXT),
293 REG_RESERVED(SYS_PTP_CFG),
294 REG_RESERVED(SYS_RAM_INIT),
295 REG_RESERVED(SYS_CM_ADDR),
296 REG_RESERVED(SYS_CM_DATA_WR),
297 REG_RESERVED(SYS_CM_DATA_RD),
298 REG_RESERVED(SYS_CM_OP),
299 REG_RESERVED(SYS_CM_DATA),
300};
301
302static const u32 vsc9953_gcb_regmap[] = {
303 REG(GCB_SOFT_RST, 0x000008),
304 REG(GCB_MIIM_MII_STATUS, 0x0000ac),
305 REG(GCB_MIIM_MII_CMD, 0x0000b4),
306 REG(GCB_MIIM_MII_DATA, 0x0000b8),
307};
308
309static const u32 vsc9953_dev_gmii_regmap[] = {
310 REG(DEV_CLOCK_CFG, 0x0),
311 REG(DEV_PORT_MISC, 0x4),
312 REG_RESERVED(DEV_EVENTS),
313 REG(DEV_EEE_CFG, 0xc),
314 REG_RESERVED(DEV_RX_PATH_DELAY),
315 REG_RESERVED(DEV_TX_PATH_DELAY),
316 REG_RESERVED(DEV_PTP_PREDICT_CFG),
317 REG(DEV_MAC_ENA_CFG, 0x10),
318 REG(DEV_MAC_MODE_CFG, 0x14),
319 REG(DEV_MAC_MAXLEN_CFG, 0x18),
320 REG(DEV_MAC_TAGS_CFG, 0x1c),
321 REG(DEV_MAC_ADV_CHK_CFG, 0x20),
322 REG(DEV_MAC_IFG_CFG, 0x24),
323 REG(DEV_MAC_HDX_CFG, 0x28),
324 REG_RESERVED(DEV_MAC_DBG_CFG),
325 REG(DEV_MAC_FC_MAC_LOW_CFG, 0x30),
326 REG(DEV_MAC_FC_MAC_HIGH_CFG, 0x34),
327 REG(DEV_MAC_STICKY, 0x38),
328 REG_RESERVED(PCS1G_CFG),
329 REG_RESERVED(PCS1G_MODE_CFG),
330 REG_RESERVED(PCS1G_SD_CFG),
331 REG_RESERVED(PCS1G_ANEG_CFG),
332 REG_RESERVED(PCS1G_ANEG_NP_CFG),
333 REG_RESERVED(PCS1G_LB_CFG),
334 REG_RESERVED(PCS1G_DBG_CFG),
335 REG_RESERVED(PCS1G_CDET_CFG),
336 REG_RESERVED(PCS1G_ANEG_STATUS),
337 REG_RESERVED(PCS1G_ANEG_NP_STATUS),
338 REG_RESERVED(PCS1G_LINK_STATUS),
339 REG_RESERVED(PCS1G_LINK_DOWN_CNT),
340 REG_RESERVED(PCS1G_STICKY),
341 REG_RESERVED(PCS1G_DEBUG_STATUS),
342 REG_RESERVED(PCS1G_LPI_CFG),
343 REG_RESERVED(PCS1G_LPI_WAKE_ERROR_CNT),
344 REG_RESERVED(PCS1G_LPI_STATUS),
345 REG_RESERVED(PCS1G_TSTPAT_MODE_CFG),
346 REG_RESERVED(PCS1G_TSTPAT_STATUS),
347 REG_RESERVED(DEV_PCS_FX100_CFG),
348 REG_RESERVED(DEV_PCS_FX100_STATUS),
349};
350
351static const u32 *vsc9953_regmap[TARGET_MAX] = {
352 [ANA] = vsc9953_ana_regmap,
353 [QS] = vsc9953_qs_regmap,
354 [QSYS] = vsc9953_qsys_regmap,
355 [REW] = vsc9953_rew_regmap,
356 [SYS] = vsc9953_sys_regmap,
Vladimir Olteanc1c39932020-09-30 01:27:23 +0300357 [S2] = vsc9953_vcap_regmap,
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300358 [GCB] = vsc9953_gcb_regmap,
359 [DEV_GMII] = vsc9953_dev_gmii_regmap,
360};
361
362/* Addresses are relative to the device's base address */
363static const struct resource vsc9953_target_io_res[TARGET_MAX] = {
364 [ANA] = {
365 .start = 0x0280000,
366 .end = 0x028ffff,
367 .name = "ana",
368 },
369 [QS] = {
370 .start = 0x0080000,
371 .end = 0x00800ff,
372 .name = "qs",
373 },
374 [QSYS] = {
375 .start = 0x0200000,
376 .end = 0x021ffff,
377 .name = "qsys",
378 },
379 [REW] = {
380 .start = 0x0030000,
381 .end = 0x003ffff,
382 .name = "rew",
383 },
384 [SYS] = {
385 .start = 0x0010000,
386 .end = 0x001ffff,
387 .name = "sys",
388 },
389 [S2] = {
390 .start = 0x0060000,
391 .end = 0x00603ff,
392 .name = "s2",
393 },
394 [PTP] = {
395 .start = 0x0090000,
396 .end = 0x00900cb,
397 .name = "ptp",
398 },
399 [GCB] = {
400 .start = 0x0070000,
401 .end = 0x00701ff,
402 .name = "devcpu_gcb",
403 },
404};
405
406static const struct resource vsc9953_port_io_res[] = {
407 {
408 .start = 0x0100000,
409 .end = 0x010ffff,
410 .name = "port0",
411 },
412 {
413 .start = 0x0110000,
414 .end = 0x011ffff,
415 .name = "port1",
416 },
417 {
418 .start = 0x0120000,
419 .end = 0x012ffff,
420 .name = "port2",
421 },
422 {
423 .start = 0x0130000,
424 .end = 0x013ffff,
425 .name = "port3",
426 },
427 {
428 .start = 0x0140000,
429 .end = 0x014ffff,
430 .name = "port4",
431 },
432 {
433 .start = 0x0150000,
434 .end = 0x015ffff,
435 .name = "port5",
436 },
437 {
438 .start = 0x0160000,
439 .end = 0x016ffff,
440 .name = "port6",
441 },
442 {
443 .start = 0x0170000,
444 .end = 0x017ffff,
445 .name = "port7",
446 },
447 {
448 .start = 0x0180000,
449 .end = 0x018ffff,
450 .name = "port8",
451 },
452 {
453 .start = 0x0190000,
454 .end = 0x019ffff,
455 .name = "port9",
456 },
457};
458
459static const struct reg_field vsc9953_regfields[REGFIELD_MAX] = {
460 [ANA_ADVLEARN_VLAN_CHK] = REG_FIELD(ANA_ADVLEARN, 10, 10),
461 [ANA_ADVLEARN_LEARN_MIRROR] = REG_FIELD(ANA_ADVLEARN, 0, 9),
462 [ANA_ANEVENTS_AUTOAGE] = REG_FIELD(ANA_ANEVENTS, 24, 24),
463 [ANA_ANEVENTS_STORM_DROP] = REG_FIELD(ANA_ANEVENTS, 22, 22),
464 [ANA_ANEVENTS_LEARN_DROP] = REG_FIELD(ANA_ANEVENTS, 21, 21),
465 [ANA_ANEVENTS_AGED_ENTRY] = REG_FIELD(ANA_ANEVENTS, 20, 20),
466 [ANA_ANEVENTS_CPU_LEARN_FAILED] = REG_FIELD(ANA_ANEVENTS, 19, 19),
467 [ANA_ANEVENTS_AUTO_LEARN_FAILED] = REG_FIELD(ANA_ANEVENTS, 18, 18),
468 [ANA_ANEVENTS_LEARN_REMOVE] = REG_FIELD(ANA_ANEVENTS, 17, 17),
469 [ANA_ANEVENTS_AUTO_LEARNED] = REG_FIELD(ANA_ANEVENTS, 16, 16),
470 [ANA_ANEVENTS_AUTO_MOVED] = REG_FIELD(ANA_ANEVENTS, 15, 15),
471 [ANA_ANEVENTS_CLASSIFIED_DROP] = REG_FIELD(ANA_ANEVENTS, 13, 13),
472 [ANA_ANEVENTS_CLASSIFIED_COPY] = REG_FIELD(ANA_ANEVENTS, 12, 12),
473 [ANA_ANEVENTS_VLAN_DISCARD] = REG_FIELD(ANA_ANEVENTS, 11, 11),
474 [ANA_ANEVENTS_FWD_DISCARD] = REG_FIELD(ANA_ANEVENTS, 10, 10),
475 [ANA_ANEVENTS_MULTICAST_FLOOD] = REG_FIELD(ANA_ANEVENTS, 9, 9),
476 [ANA_ANEVENTS_UNICAST_FLOOD] = REG_FIELD(ANA_ANEVENTS, 8, 8),
477 [ANA_ANEVENTS_DEST_KNOWN] = REG_FIELD(ANA_ANEVENTS, 7, 7),
478 [ANA_ANEVENTS_BUCKET3_MATCH] = REG_FIELD(ANA_ANEVENTS, 6, 6),
479 [ANA_ANEVENTS_BUCKET2_MATCH] = REG_FIELD(ANA_ANEVENTS, 5, 5),
480 [ANA_ANEVENTS_BUCKET1_MATCH] = REG_FIELD(ANA_ANEVENTS, 4, 4),
481 [ANA_ANEVENTS_BUCKET0_MATCH] = REG_FIELD(ANA_ANEVENTS, 3, 3),
482 [ANA_ANEVENTS_CPU_OPERATION] = REG_FIELD(ANA_ANEVENTS, 2, 2),
483 [ANA_ANEVENTS_DMAC_LOOKUP] = REG_FIELD(ANA_ANEVENTS, 1, 1),
484 [ANA_ANEVENTS_SMAC_LOOKUP] = REG_FIELD(ANA_ANEVENTS, 0, 0),
485 [ANA_TABLES_MACACCESS_B_DOM] = REG_FIELD(ANA_TABLES_MACACCESS, 16, 16),
486 [ANA_TABLES_MACTINDX_BUCKET] = REG_FIELD(ANA_TABLES_MACTINDX, 11, 12),
487 [ANA_TABLES_MACTINDX_M_INDEX] = REG_FIELD(ANA_TABLES_MACTINDX, 0, 10),
488 [SYS_RESET_CFG_CORE_ENA] = REG_FIELD(SYS_RESET_CFG, 7, 7),
489 [SYS_RESET_CFG_MEM_ENA] = REG_FIELD(SYS_RESET_CFG, 6, 6),
490 [SYS_RESET_CFG_MEM_INIT] = REG_FIELD(SYS_RESET_CFG, 5, 5),
491 [GCB_SOFT_RST_SWC_RST] = REG_FIELD(GCB_SOFT_RST, 0, 0),
492 [GCB_MIIM_MII_STATUS_PENDING] = REG_FIELD(GCB_MIIM_MII_STATUS, 2, 2),
493 [GCB_MIIM_MII_STATUS_BUSY] = REG_FIELD(GCB_MIIM_MII_STATUS, 3, 3),
494 /* Replicated per number of ports (11), register size 4 per port */
495 [QSYS_SWITCH_PORT_MODE_PORT_ENA] = REG_FIELD_ID(QSYS_SWITCH_PORT_MODE, 13, 13, 11, 4),
496 [QSYS_SWITCH_PORT_MODE_YEL_RSRVD] = REG_FIELD_ID(QSYS_SWITCH_PORT_MODE, 10, 10, 11, 4),
497 [QSYS_SWITCH_PORT_MODE_INGRESS_DROP_MODE] = REG_FIELD_ID(QSYS_SWITCH_PORT_MODE, 9, 9, 11, 4),
498 [QSYS_SWITCH_PORT_MODE_TX_PFC_ENA] = REG_FIELD_ID(QSYS_SWITCH_PORT_MODE, 1, 8, 11, 4),
499 [QSYS_SWITCH_PORT_MODE_TX_PFC_MODE] = REG_FIELD_ID(QSYS_SWITCH_PORT_MODE, 0, 0, 11, 4),
500 [SYS_PORT_MODE_INCL_INJ_HDR] = REG_FIELD_ID(SYS_PORT_MODE, 4, 5, 11, 4),
501 [SYS_PORT_MODE_INCL_XTR_HDR] = REG_FIELD_ID(SYS_PORT_MODE, 2, 3, 11, 4),
502 [SYS_PORT_MODE_INCL_HDR_ERR] = REG_FIELD_ID(SYS_PORT_MODE, 0, 0, 11, 4),
503 [SYS_PAUSE_CFG_PAUSE_START] = REG_FIELD_ID(SYS_PAUSE_CFG, 11, 20, 11, 4),
504 [SYS_PAUSE_CFG_PAUSE_STOP] = REG_FIELD_ID(SYS_PAUSE_CFG, 1, 10, 11, 4),
505 [SYS_PAUSE_CFG_PAUSE_ENA] = REG_FIELD_ID(SYS_PAUSE_CFG, 0, 1, 11, 4),
506};
507
508static const struct ocelot_stat_layout vsc9953_stats_layout[] = {
509 { .offset = 0x00, .name = "rx_octets", },
510 { .offset = 0x01, .name = "rx_unicast", },
511 { .offset = 0x02, .name = "rx_multicast", },
512 { .offset = 0x03, .name = "rx_broadcast", },
513 { .offset = 0x04, .name = "rx_shorts", },
514 { .offset = 0x05, .name = "rx_fragments", },
515 { .offset = 0x06, .name = "rx_jabbers", },
516 { .offset = 0x07, .name = "rx_crc_align_errs", },
517 { .offset = 0x08, .name = "rx_sym_errs", },
518 { .offset = 0x09, .name = "rx_frames_below_65_octets", },
519 { .offset = 0x0A, .name = "rx_frames_65_to_127_octets", },
520 { .offset = 0x0B, .name = "rx_frames_128_to_255_octets", },
521 { .offset = 0x0C, .name = "rx_frames_256_to_511_octets", },
522 { .offset = 0x0D, .name = "rx_frames_512_to_1023_octets", },
523 { .offset = 0x0E, .name = "rx_frames_1024_to_1526_octets", },
524 { .offset = 0x0F, .name = "rx_frames_over_1526_octets", },
525 { .offset = 0x10, .name = "rx_pause", },
526 { .offset = 0x11, .name = "rx_control", },
527 { .offset = 0x12, .name = "rx_longs", },
528 { .offset = 0x13, .name = "rx_classified_drops", },
529 { .offset = 0x14, .name = "rx_red_prio_0", },
530 { .offset = 0x15, .name = "rx_red_prio_1", },
531 { .offset = 0x16, .name = "rx_red_prio_2", },
532 { .offset = 0x17, .name = "rx_red_prio_3", },
533 { .offset = 0x18, .name = "rx_red_prio_4", },
534 { .offset = 0x19, .name = "rx_red_prio_5", },
535 { .offset = 0x1A, .name = "rx_red_prio_6", },
536 { .offset = 0x1B, .name = "rx_red_prio_7", },
537 { .offset = 0x1C, .name = "rx_yellow_prio_0", },
538 { .offset = 0x1D, .name = "rx_yellow_prio_1", },
539 { .offset = 0x1E, .name = "rx_yellow_prio_2", },
540 { .offset = 0x1F, .name = "rx_yellow_prio_3", },
541 { .offset = 0x20, .name = "rx_yellow_prio_4", },
542 { .offset = 0x21, .name = "rx_yellow_prio_5", },
543 { .offset = 0x22, .name = "rx_yellow_prio_6", },
544 { .offset = 0x23, .name = "rx_yellow_prio_7", },
545 { .offset = 0x24, .name = "rx_green_prio_0", },
546 { .offset = 0x25, .name = "rx_green_prio_1", },
547 { .offset = 0x26, .name = "rx_green_prio_2", },
548 { .offset = 0x27, .name = "rx_green_prio_3", },
549 { .offset = 0x28, .name = "rx_green_prio_4", },
550 { .offset = 0x29, .name = "rx_green_prio_5", },
551 { .offset = 0x2A, .name = "rx_green_prio_6", },
552 { .offset = 0x2B, .name = "rx_green_prio_7", },
553 { .offset = 0x40, .name = "tx_octets", },
554 { .offset = 0x41, .name = "tx_unicast", },
555 { .offset = 0x42, .name = "tx_multicast", },
556 { .offset = 0x43, .name = "tx_broadcast", },
557 { .offset = 0x44, .name = "tx_collision", },
558 { .offset = 0x45, .name = "tx_drops", },
559 { .offset = 0x46, .name = "tx_pause", },
560 { .offset = 0x47, .name = "tx_frames_below_65_octets", },
561 { .offset = 0x48, .name = "tx_frames_65_to_127_octets", },
562 { .offset = 0x49, .name = "tx_frames_128_255_octets", },
563 { .offset = 0x4A, .name = "tx_frames_256_511_octets", },
564 { .offset = 0x4B, .name = "tx_frames_512_1023_octets", },
565 { .offset = 0x4C, .name = "tx_frames_1024_1526_octets", },
566 { .offset = 0x4D, .name = "tx_frames_over_1526_octets", },
567 { .offset = 0x4E, .name = "tx_yellow_prio_0", },
568 { .offset = 0x4F, .name = "tx_yellow_prio_1", },
569 { .offset = 0x50, .name = "tx_yellow_prio_2", },
570 { .offset = 0x51, .name = "tx_yellow_prio_3", },
571 { .offset = 0x52, .name = "tx_yellow_prio_4", },
572 { .offset = 0x53, .name = "tx_yellow_prio_5", },
573 { .offset = 0x54, .name = "tx_yellow_prio_6", },
574 { .offset = 0x55, .name = "tx_yellow_prio_7", },
575 { .offset = 0x56, .name = "tx_green_prio_0", },
576 { .offset = 0x57, .name = "tx_green_prio_1", },
577 { .offset = 0x58, .name = "tx_green_prio_2", },
578 { .offset = 0x59, .name = "tx_green_prio_3", },
579 { .offset = 0x5A, .name = "tx_green_prio_4", },
580 { .offset = 0x5B, .name = "tx_green_prio_5", },
581 { .offset = 0x5C, .name = "tx_green_prio_6", },
582 { .offset = 0x5D, .name = "tx_green_prio_7", },
583 { .offset = 0x5E, .name = "tx_aged", },
584 { .offset = 0x80, .name = "drop_local", },
585 { .offset = 0x81, .name = "drop_tail", },
586 { .offset = 0x82, .name = "drop_yellow_prio_0", },
587 { .offset = 0x83, .name = "drop_yellow_prio_1", },
588 { .offset = 0x84, .name = "drop_yellow_prio_2", },
589 { .offset = 0x85, .name = "drop_yellow_prio_3", },
590 { .offset = 0x86, .name = "drop_yellow_prio_4", },
591 { .offset = 0x87, .name = "drop_yellow_prio_5", },
592 { .offset = 0x88, .name = "drop_yellow_prio_6", },
593 { .offset = 0x89, .name = "drop_yellow_prio_7", },
594 { .offset = 0x8A, .name = "drop_green_prio_0", },
595 { .offset = 0x8B, .name = "drop_green_prio_1", },
596 { .offset = 0x8C, .name = "drop_green_prio_2", },
597 { .offset = 0x8D, .name = "drop_green_prio_3", },
598 { .offset = 0x8E, .name = "drop_green_prio_4", },
599 { .offset = 0x8F, .name = "drop_green_prio_5", },
600 { .offset = 0x90, .name = "drop_green_prio_6", },
601 { .offset = 0x91, .name = "drop_green_prio_7", },
602};
603
604static struct vcap_field vsc9953_vcap_is2_keys[] = {
605 /* Common: 41 bits */
606 [VCAP_IS2_TYPE] = { 0, 4},
607 [VCAP_IS2_HK_FIRST] = { 4, 1},
608 [VCAP_IS2_HK_PAG] = { 5, 8},
609 [VCAP_IS2_HK_IGR_PORT_MASK] = { 13, 11},
610 [VCAP_IS2_HK_RSV2] = { 24, 1},
611 [VCAP_IS2_HK_HOST_MATCH] = { 25, 1},
612 [VCAP_IS2_HK_L2_MC] = { 26, 1},
613 [VCAP_IS2_HK_L2_BC] = { 27, 1},
614 [VCAP_IS2_HK_VLAN_TAGGED] = { 28, 1},
615 [VCAP_IS2_HK_VID] = { 29, 12},
616 [VCAP_IS2_HK_DEI] = { 41, 1},
617 [VCAP_IS2_HK_PCP] = { 42, 3},
618 /* MAC_ETYPE / MAC_LLC / MAC_SNAP / OAM common */
619 [VCAP_IS2_HK_L2_DMAC] = { 45, 48},
620 [VCAP_IS2_HK_L2_SMAC] = { 93, 48},
621 /* MAC_ETYPE (TYPE=000) */
622 [VCAP_IS2_HK_MAC_ETYPE_ETYPE] = {141, 16},
623 [VCAP_IS2_HK_MAC_ETYPE_L2_PAYLOAD0] = {157, 16},
624 [VCAP_IS2_HK_MAC_ETYPE_L2_PAYLOAD1] = {173, 8},
625 [VCAP_IS2_HK_MAC_ETYPE_L2_PAYLOAD2] = {181, 3},
626 /* MAC_LLC (TYPE=001) */
627 [VCAP_IS2_HK_MAC_LLC_L2_LLC] = {141, 40},
628 /* MAC_SNAP (TYPE=010) */
629 [VCAP_IS2_HK_MAC_SNAP_L2_SNAP] = {141, 40},
630 /* MAC_ARP (TYPE=011) */
631 [VCAP_IS2_HK_MAC_ARP_SMAC] = { 45, 48},
632 [VCAP_IS2_HK_MAC_ARP_ADDR_SPACE_OK] = { 93, 1},
633 [VCAP_IS2_HK_MAC_ARP_PROTO_SPACE_OK] = { 94, 1},
634 [VCAP_IS2_HK_MAC_ARP_LEN_OK] = { 95, 1},
635 [VCAP_IS2_HK_MAC_ARP_TARGET_MATCH] = { 96, 1},
636 [VCAP_IS2_HK_MAC_ARP_SENDER_MATCH] = { 97, 1},
637 [VCAP_IS2_HK_MAC_ARP_OPCODE_UNKNOWN] = { 98, 1},
638 [VCAP_IS2_HK_MAC_ARP_OPCODE] = { 99, 2},
639 [VCAP_IS2_HK_MAC_ARP_L3_IP4_DIP] = {101, 32},
640 [VCAP_IS2_HK_MAC_ARP_L3_IP4_SIP] = {133, 32},
641 [VCAP_IS2_HK_MAC_ARP_DIP_EQ_SIP] = {165, 1},
642 /* IP4_TCP_UDP / IP4_OTHER common */
643 [VCAP_IS2_HK_IP4] = { 45, 1},
644 [VCAP_IS2_HK_L3_FRAGMENT] = { 46, 1},
645 [VCAP_IS2_HK_L3_FRAG_OFS_GT0] = { 47, 1},
646 [VCAP_IS2_HK_L3_OPTIONS] = { 48, 1},
647 [VCAP_IS2_HK_IP4_L3_TTL_GT0] = { 49, 1},
648 [VCAP_IS2_HK_L3_TOS] = { 50, 8},
649 [VCAP_IS2_HK_L3_IP4_DIP] = { 58, 32},
650 [VCAP_IS2_HK_L3_IP4_SIP] = { 90, 32},
651 [VCAP_IS2_HK_DIP_EQ_SIP] = {122, 1},
652 /* IP4_TCP_UDP (TYPE=100) */
653 [VCAP_IS2_HK_TCP] = {123, 1},
Vladimir Oltean7a023072020-09-22 01:56:37 +0300654 [VCAP_IS2_HK_L4_DPORT] = {124, 16},
655 [VCAP_IS2_HK_L4_SPORT] = {140, 16},
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300656 [VCAP_IS2_HK_L4_RNG] = {156, 8},
657 [VCAP_IS2_HK_L4_SPORT_EQ_DPORT] = {164, 1},
658 [VCAP_IS2_HK_L4_SEQUENCE_EQ0] = {165, 1},
Vladimir Oltean7a023072020-09-22 01:56:37 +0300659 [VCAP_IS2_HK_L4_FIN] = {166, 1},
660 [VCAP_IS2_HK_L4_SYN] = {167, 1},
661 [VCAP_IS2_HK_L4_RST] = {168, 1},
662 [VCAP_IS2_HK_L4_PSH] = {169, 1},
663 [VCAP_IS2_HK_L4_ACK] = {170, 1},
664 [VCAP_IS2_HK_L4_URG] = {171, 1},
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300665 /* IP4_OTHER (TYPE=101) */
666 [VCAP_IS2_HK_IP4_L3_PROTO] = {123, 8},
667 [VCAP_IS2_HK_L3_PAYLOAD] = {131, 56},
668 /* IP6_STD (TYPE=110) */
669 [VCAP_IS2_HK_IP6_L3_TTL_GT0] = { 45, 1},
670 [VCAP_IS2_HK_L3_IP6_SIP] = { 46, 128},
671 [VCAP_IS2_HK_IP6_L3_PROTO] = {174, 8},
672};
673
674static struct vcap_field vsc9953_vcap_is2_actions[] = {
675 [VCAP_IS2_ACT_HIT_ME_ONCE] = { 0, 1},
676 [VCAP_IS2_ACT_CPU_COPY_ENA] = { 1, 1},
677 [VCAP_IS2_ACT_CPU_QU_NUM] = { 2, 3},
678 [VCAP_IS2_ACT_MASK_MODE] = { 5, 2},
679 [VCAP_IS2_ACT_MIRROR_ENA] = { 7, 1},
680 [VCAP_IS2_ACT_LRN_DIS] = { 8, 1},
681 [VCAP_IS2_ACT_POLICE_ENA] = { 9, 1},
682 [VCAP_IS2_ACT_POLICE_IDX] = { 10, 8},
683 [VCAP_IS2_ACT_POLICE_VCAP_ONLY] = { 21, 1},
684 [VCAP_IS2_ACT_PORT_MASK] = { 22, 10},
685 [VCAP_IS2_ACT_ACL_ID] = { 44, 6},
686 [VCAP_IS2_ACT_HIT_CNT] = { 50, 32},
687};
688
689static const struct vcap_props vsc9953_vcap_props[] = {
690 [VCAP_IS2] = {
691 .tg_width = 2,
692 .sw_count = 4,
693 .entry_count = VSC9953_VCAP_IS2_CNT,
694 .entry_width = VSC9953_VCAP_IS2_ENTRY_WIDTH,
695 .action_count = VSC9953_VCAP_IS2_CNT +
696 VSC9953_VCAP_PORT_CNT + 2,
697 .action_width = 101,
698 .action_type_width = 1,
699 .action_table = {
700 [IS2_ACTION_TYPE_NORMAL] = {
701 .width = 44,
702 .count = 2
703 },
704 [IS2_ACTION_TYPE_SMAC_SIP] = {
705 .width = 6,
706 .count = 4
707 },
708 },
709 .counter_words = 4,
710 .counter_width = 32,
Vladimir Olteanc1c39932020-09-30 01:27:23 +0300711 .target = S2,
712 .keys = vsc9953_vcap_is2_keys,
713 .actions = vsc9953_vcap_is2_actions,
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300714 },
715};
716
717#define VSC9953_INIT_TIMEOUT 50000
718#define VSC9953_GCB_RST_SLEEP 100
719#define VSC9953_SYS_RAMINIT_SLEEP 80
720#define VCS9953_MII_TIMEOUT 10000
721
722static int vsc9953_gcb_soft_rst_status(struct ocelot *ocelot)
723{
724 int val;
725
726 ocelot_field_read(ocelot, GCB_SOFT_RST_SWC_RST, &val);
727
728 return val;
729}
730
731static int vsc9953_sys_ram_init_status(struct ocelot *ocelot)
732{
733 int val;
734
735 ocelot_field_read(ocelot, SYS_RESET_CFG_MEM_INIT, &val);
736
737 return val;
738}
739
740static int vsc9953_gcb_miim_pending_status(struct ocelot *ocelot)
741{
742 int val;
743
744 ocelot_field_read(ocelot, GCB_MIIM_MII_STATUS_PENDING, &val);
745
746 return val;
747}
748
749static int vsc9953_gcb_miim_busy_status(struct ocelot *ocelot)
750{
751 int val;
752
753 ocelot_field_read(ocelot, GCB_MIIM_MII_STATUS_BUSY, &val);
754
755 return val;
756}
757
758static int vsc9953_mdio_write(struct mii_bus *bus, int phy_id, int regnum,
759 u16 value)
760{
761 struct ocelot *ocelot = bus->priv;
762 int err, cmd, val;
763
764 /* Wait while MIIM controller becomes idle */
765 err = readx_poll_timeout(vsc9953_gcb_miim_pending_status, ocelot,
766 val, !val, 10, VCS9953_MII_TIMEOUT);
767 if (err) {
768 dev_err(ocelot->dev, "MDIO write: pending timeout\n");
769 goto out;
770 }
771
772 cmd = MSCC_MIIM_CMD_VLD | (phy_id << MSCC_MIIM_CMD_PHYAD_SHIFT) |
773 (regnum << MSCC_MIIM_CMD_REGAD_SHIFT) |
774 (value << MSCC_MIIM_CMD_WRDATA_SHIFT) |
775 MSCC_MIIM_CMD_OPR_WRITE;
776
777 ocelot_write(ocelot, cmd, GCB_MIIM_MII_CMD);
778
779out:
780 return err;
781}
782
783static int vsc9953_mdio_read(struct mii_bus *bus, int phy_id, int regnum)
784{
785 struct ocelot *ocelot = bus->priv;
786 int err, cmd, val;
787
788 /* Wait until MIIM controller becomes idle */
789 err = readx_poll_timeout(vsc9953_gcb_miim_pending_status, ocelot,
790 val, !val, 10, VCS9953_MII_TIMEOUT);
791 if (err) {
792 dev_err(ocelot->dev, "MDIO read: pending timeout\n");
793 goto out;
794 }
795
796 /* Write the MIIM COMMAND register */
797 cmd = MSCC_MIIM_CMD_VLD | (phy_id << MSCC_MIIM_CMD_PHYAD_SHIFT) |
798 (regnum << MSCC_MIIM_CMD_REGAD_SHIFT) | MSCC_MIIM_CMD_OPR_READ;
799
800 ocelot_write(ocelot, cmd, GCB_MIIM_MII_CMD);
801
802 /* Wait while read operation via the MIIM controller is in progress */
803 err = readx_poll_timeout(vsc9953_gcb_miim_busy_status, ocelot,
804 val, !val, 10, VCS9953_MII_TIMEOUT);
805 if (err) {
806 dev_err(ocelot->dev, "MDIO read: busy timeout\n");
807 goto out;
808 }
809
810 val = ocelot_read(ocelot, GCB_MIIM_MII_DATA);
811
812 err = val & 0xFFFF;
813out:
814 return err;
815}
816
Vladimir Olteanc129fc52020-09-18 13:57:46 +0300817/* CORE_ENA is in SYS:SYSTEM:RESET_CFG
818 * MEM_INIT is in SYS:SYSTEM:RESET_CFG
819 * MEM_ENA is in SYS:SYSTEM:RESET_CFG
820 */
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300821static int vsc9953_reset(struct ocelot *ocelot)
822{
823 int val, err;
824
825 /* soft-reset the switch core */
826 ocelot_field_write(ocelot, GCB_SOFT_RST_SWC_RST, 1);
827
828 err = readx_poll_timeout(vsc9953_gcb_soft_rst_status, ocelot, val, !val,
829 VSC9953_GCB_RST_SLEEP, VSC9953_INIT_TIMEOUT);
830 if (err) {
831 dev_err(ocelot->dev, "timeout: switch core reset\n");
832 return err;
833 }
834
835 /* initialize switch mem ~40us */
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300836 ocelot_field_write(ocelot, SYS_RESET_CFG_MEM_ENA, 1);
Vladimir Oltean9a73f0b2020-09-18 13:57:45 +0300837 ocelot_field_write(ocelot, SYS_RESET_CFG_MEM_INIT, 1);
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300838
839 err = readx_poll_timeout(vsc9953_sys_ram_init_status, ocelot, val, !val,
840 VSC9953_SYS_RAMINIT_SLEEP,
841 VSC9953_INIT_TIMEOUT);
842 if (err) {
843 dev_err(ocelot->dev, "timeout: switch sram init\n");
844 return err;
845 }
846
847 /* enable switch core */
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300848 ocelot_field_write(ocelot, SYS_RESET_CFG_CORE_ENA, 1);
849
850 return 0;
851}
852
853static void vsc9953_phylink_validate(struct ocelot *ocelot, int port,
854 unsigned long *supported,
855 struct phylink_link_state *state)
856{
857 struct ocelot_port *ocelot_port = ocelot->ports[port];
858 __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
859
860 if (state->interface != PHY_INTERFACE_MODE_NA &&
861 state->interface != ocelot_port->phy_mode) {
862 bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
863 return;
864 }
865
866 phylink_set_port_modes(mask);
867 phylink_set(mask, Autoneg);
868 phylink_set(mask, Pause);
869 phylink_set(mask, Asym_Pause);
870 phylink_set(mask, 10baseT_Full);
871 phylink_set(mask, 10baseT_Half);
872 phylink_set(mask, 100baseT_Full);
873 phylink_set(mask, 100baseT_Half);
874 phylink_set(mask, 1000baseT_Full);
875
876 if (state->interface == PHY_INTERFACE_MODE_INTERNAL) {
877 phylink_set(mask, 2500baseT_Full);
878 phylink_set(mask, 2500baseX_Full);
879 }
880
881 bitmap_and(supported, supported, mask,
882 __ETHTOOL_LINK_MODE_MASK_NBITS);
883 bitmap_and(state->advertising, state->advertising, mask,
884 __ETHTOOL_LINK_MODE_MASK_NBITS);
885}
886
887static int vsc9953_prevalidate_phy_mode(struct ocelot *ocelot, int port,
888 phy_interface_t phy_mode)
889{
890 switch (phy_mode) {
891 case PHY_INTERFACE_MODE_INTERNAL:
892 if (port != 8 && port != 9)
893 return -ENOTSUPP;
894 return 0;
895 case PHY_INTERFACE_MODE_SGMII:
896 case PHY_INTERFACE_MODE_QSGMII:
897 /* Not supported on internal to-CPU ports */
898 if (port == 8 || port == 9)
899 return -ENOTSUPP;
900 return 0;
901 default:
902 return -ENOTSUPP;
903 }
904}
905
906/* Watermark encode
907 * Bit 9: Unit; 0:1, 1:16
908 * Bit 8-0: Value to be multiplied with unit
909 */
910static u16 vsc9953_wm_enc(u16 value)
911{
912 if (value >= BIT(9))
913 return BIT(9) | (value / 16);
914
915 return value;
916}
917
918static const struct ocelot_ops vsc9953_ops = {
919 .reset = vsc9953_reset,
920 .wm_enc = vsc9953_wm_enc,
921};
922
923static int vsc9953_mdio_bus_alloc(struct ocelot *ocelot)
924{
925 struct felix *felix = ocelot_to_felix(ocelot);
926 struct device *dev = ocelot->dev;
927 struct mii_bus *bus;
928 int port;
929 int rc;
930
931 felix->pcs = devm_kcalloc(dev, felix->info->num_ports,
932 sizeof(struct phy_device *),
933 GFP_KERNEL);
934 if (!felix->pcs) {
935 dev_err(dev, "failed to allocate array for PCS PHYs\n");
936 return -ENOMEM;
937 }
938
939 bus = devm_mdiobus_alloc(dev);
940 if (!bus)
941 return -ENOMEM;
942
943 bus->name = "VSC9953 internal MDIO bus";
944 bus->read = vsc9953_mdio_read;
945 bus->write = vsc9953_mdio_write;
946 bus->parent = dev;
947 bus->priv = ocelot;
948 snprintf(bus->id, MII_BUS_ID_SIZE, "%s-imdio", dev_name(dev));
949
950 /* Needed in order to initialize the bus mutex lock */
951 rc = mdiobus_register(bus);
952 if (rc < 0) {
953 dev_err(dev, "failed to register MDIO bus\n");
954 return rc;
955 }
956
957 felix->imdio = bus;
958
959 for (port = 0; port < felix->info->num_ports; port++) {
960 struct ocelot_port *ocelot_port = ocelot->ports[port];
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300961 int addr = port + 4;
Ioana Ciornei588d0552020-08-30 11:34:02 +0300962 struct mdio_device *pcs;
963 struct lynx_pcs *lynx;
964
965 if (dsa_is_unused_port(felix->ds, port))
966 continue;
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300967
968 if (ocelot_port->phy_mode == PHY_INTERFACE_MODE_INTERNAL)
969 continue;
970
Ioana Ciornei588d0552020-08-30 11:34:02 +0300971 pcs = mdio_device_create(felix->imdio, addr);
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300972 if (IS_ERR(pcs))
973 continue;
974
Ioana Ciornei588d0552020-08-30 11:34:02 +0300975 lynx = lynx_pcs_create(pcs);
976 if (!lynx) {
977 mdio_device_free(pcs);
978 continue;
979 }
980
981 felix->pcs[port] = lynx;
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300982
983 dev_info(dev, "Found PCS at internal MDIO address %d\n", addr);
984 }
985
986 return 0;
987}
988
Vladimir Olteanccfdbab2020-09-18 13:57:50 +0300989static void vsc9953_mdio_bus_free(struct ocelot *ocelot)
990{
991 struct felix *felix = ocelot_to_felix(ocelot);
992 int port;
993
994 for (port = 0; port < ocelot->num_phys_ports; port++) {
995 struct lynx_pcs *pcs = felix->pcs[port];
996
997 if (!pcs)
998 continue;
999
1000 mdio_device_free(pcs->mdio);
1001 lynx_pcs_destroy(pcs);
1002 }
1003 mdiobus_unregister(felix->imdio);
1004}
1005
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001006static void vsc9953_xmit_template_populate(struct ocelot *ocelot, int port)
1007{
1008 struct ocelot_port *ocelot_port = ocelot->ports[port];
1009 u8 *template = ocelot_port->xmit_template;
1010 u64 bypass, dest, src;
Vladimir Oltean51241972020-09-26 22:32:04 +03001011 __be32 *prefix;
1012 u8 *injection;
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001013
1014 /* Set the source port as the CPU port module and not the
1015 * NPI port
1016 */
1017 src = ocelot->num_phys_ports;
1018 dest = BIT(port);
1019 bypass = true;
1020
Vladimir Oltean51241972020-09-26 22:32:04 +03001021 injection = template + OCELOT_SHORT_PREFIX_LEN;
1022 prefix = (__be32 *)template;
1023
1024 packing(injection, &bypass, 127, 127, OCELOT_TAG_LEN, PACK, 0);
1025 packing(injection, &dest, 67, 57, OCELOT_TAG_LEN, PACK, 0);
1026 packing(injection, &src, 46, 43, OCELOT_TAG_LEN, PACK, 0);
1027
1028 *prefix = cpu_to_be32(0x88800005);
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001029}
1030
1031static const struct felix_info seville_info_vsc9953 = {
1032 .target_io_res = vsc9953_target_io_res,
1033 .port_io_res = vsc9953_port_io_res,
1034 .regfields = vsc9953_regfields,
1035 .map = vsc9953_regmap,
1036 .ops = &vsc9953_ops,
1037 .stats_layout = vsc9953_stats_layout,
1038 .num_stats = ARRAY_SIZE(vsc9953_stats_layout),
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001039 .vcap = vsc9953_vcap_props,
Vladimir Olteana63ed922020-09-18 04:07:25 +03001040 .shared_queue_sz = 2048 * 1024,
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001041 .num_mact_rows = 2048,
1042 .num_ports = 10,
1043 .mdio_bus_alloc = vsc9953_mdio_bus_alloc,
Vladimir Olteanccfdbab2020-09-18 13:57:50 +03001044 .mdio_bus_free = vsc9953_mdio_bus_free,
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001045 .phylink_validate = vsc9953_phylink_validate,
1046 .prevalidate_phy_mode = vsc9953_prevalidate_phy_mode,
1047 .xmit_template_populate = vsc9953_xmit_template_populate,
1048};
1049
1050static int seville_probe(struct platform_device *pdev)
1051{
1052 struct dsa_switch *ds;
1053 struct ocelot *ocelot;
1054 struct resource *res;
1055 struct felix *felix;
1056 int err;
1057
1058 felix = kzalloc(sizeof(struct felix), GFP_KERNEL);
1059 if (!felix) {
1060 err = -ENOMEM;
1061 dev_err(&pdev->dev, "Failed to allocate driver memory\n");
1062 goto err_alloc_felix;
1063 }
1064
1065 platform_set_drvdata(pdev, felix);
1066
1067 ocelot = &felix->ocelot;
1068 ocelot->dev = &pdev->dev;
1069 felix->info = &seville_info_vsc9953;
1070
1071 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1072 felix->switch_base = res->start;
1073
1074 ds = kzalloc(sizeof(struct dsa_switch), GFP_KERNEL);
1075 if (!ds) {
1076 err = -ENOMEM;
1077 dev_err(&pdev->dev, "Failed to allocate DSA switch\n");
1078 goto err_alloc_ds;
1079 }
1080
1081 ds->dev = &pdev->dev;
1082 ds->num_ports = felix->info->num_ports;
1083 ds->ops = &felix_switch_ops;
1084 ds->priv = ocelot;
1085 felix->ds = ds;
1086
1087 err = dsa_register_switch(ds);
1088 if (err) {
1089 dev_err(&pdev->dev, "Failed to register DSA switch: %d\n", err);
1090 goto err_register_ds;
1091 }
1092
1093 return 0;
1094
1095err_register_ds:
1096 kfree(ds);
1097err_alloc_ds:
1098err_alloc_felix:
1099 kfree(felix);
1100 return err;
1101}
1102
1103static int seville_remove(struct platform_device *pdev)
1104{
1105 struct felix *felix;
1106
1107 felix = platform_get_drvdata(pdev);
1108
1109 dsa_unregister_switch(felix->ds);
1110
1111 kfree(felix->ds);
1112 kfree(felix);
1113
1114 return 0;
1115}
1116
1117static const struct of_device_id seville_of_match[] = {
1118 { .compatible = "mscc,vsc9953-switch" },
1119 { },
1120};
1121MODULE_DEVICE_TABLE(of, seville_of_match);
1122
Vladimir Olteand60bc622020-09-18 13:57:53 +03001123static struct platform_driver seville_vsc9953_driver = {
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001124 .probe = seville_probe,
1125 .remove = seville_remove,
1126 .driver = {
1127 .name = "mscc_seville",
1128 .of_match_table = of_match_ptr(seville_of_match),
1129 },
1130};
Vladimir Olteand60bc622020-09-18 13:57:53 +03001131module_platform_driver(seville_vsc9953_driver);
1132
1133MODULE_DESCRIPTION("Seville Switch driver");
1134MODULE_LICENSE("GPL v2");