blob: db124922c3747103f409ee1a4a16f72f02b88b94 [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>
Vladimir Oltean40d3f292021-02-14 00:37:56 +020011#include <linux/dsa/ocelot.h>
Maxim Kochetkov84705fc2020-07-13 19:57:10 +030012#include <linux/iopoll.h>
Colin Foster5186c4a2021-11-28 17:57:36 -080013#include <linux/of_mdio.h>
Maxim Kochetkov84705fc2020-07-13 19:57:10 +030014#include "felix.h"
15
Vladimir Oltean123d2312020-09-18 13:57:48 +030016#define MSCC_MIIM_CMD_OPR_WRITE BIT(1)
17#define MSCC_MIIM_CMD_OPR_READ BIT(2)
18#define MSCC_MIIM_CMD_WRDATA_SHIFT 4
19#define MSCC_MIIM_CMD_REGAD_SHIFT 20
20#define MSCC_MIIM_CMD_PHYAD_SHIFT 25
21#define MSCC_MIIM_CMD_VLD BIT(31)
Xiaoliang Yang77043c32021-11-18 18:12:02 +080022#define VSC9953_VCAP_POLICER_BASE 11
23#define VSC9953_VCAP_POLICER_MAX 31
24#define VSC9953_VCAP_POLICER_BASE2 120
25#define VSC9953_VCAP_POLICER_MAX2 161
Maxim Kochetkov84705fc2020-07-13 19:57:10 +030026
27static const u32 vsc9953_ana_regmap[] = {
28 REG(ANA_ADVLEARN, 0x00b500),
29 REG(ANA_VLANMASK, 0x00b504),
30 REG_RESERVED(ANA_PORT_B_DOMAIN),
31 REG(ANA_ANAGEFIL, 0x00b50c),
32 REG(ANA_ANEVENTS, 0x00b510),
33 REG(ANA_STORMLIMIT_BURST, 0x00b514),
34 REG(ANA_STORMLIMIT_CFG, 0x00b518),
35 REG(ANA_ISOLATED_PORTS, 0x00b528),
36 REG(ANA_COMMUNITY_PORTS, 0x00b52c),
37 REG(ANA_AUTOAGE, 0x00b530),
38 REG(ANA_MACTOPTIONS, 0x00b534),
39 REG(ANA_LEARNDISC, 0x00b538),
40 REG(ANA_AGENCTRL, 0x00b53c),
41 REG(ANA_MIRRORPORTS, 0x00b540),
42 REG(ANA_EMIRRORPORTS, 0x00b544),
43 REG(ANA_FLOODING, 0x00b548),
44 REG(ANA_FLOODING_IPMC, 0x00b54c),
45 REG(ANA_SFLOW_CFG, 0x00b550),
46 REG(ANA_PORT_MODE, 0x00b57c),
47 REG_RESERVED(ANA_CUT_THRU_CFG),
48 REG(ANA_PGID_PGID, 0x00b600),
49 REG(ANA_TABLES_ANMOVED, 0x00b4ac),
50 REG(ANA_TABLES_MACHDATA, 0x00b4b0),
51 REG(ANA_TABLES_MACLDATA, 0x00b4b4),
52 REG_RESERVED(ANA_TABLES_STREAMDATA),
53 REG(ANA_TABLES_MACACCESS, 0x00b4b8),
54 REG(ANA_TABLES_MACTINDX, 0x00b4bc),
55 REG(ANA_TABLES_VLANACCESS, 0x00b4c0),
56 REG(ANA_TABLES_VLANTIDX, 0x00b4c4),
57 REG_RESERVED(ANA_TABLES_ISDXACCESS),
58 REG_RESERVED(ANA_TABLES_ISDXTIDX),
59 REG(ANA_TABLES_ENTRYLIM, 0x00b480),
60 REG_RESERVED(ANA_TABLES_PTP_ID_HIGH),
61 REG_RESERVED(ANA_TABLES_PTP_ID_LOW),
62 REG_RESERVED(ANA_TABLES_STREAMACCESS),
63 REG_RESERVED(ANA_TABLES_STREAMTIDX),
64 REG_RESERVED(ANA_TABLES_SEQ_HISTORY),
65 REG_RESERVED(ANA_TABLES_SEQ_MASK),
66 REG_RESERVED(ANA_TABLES_SFID_MASK),
67 REG_RESERVED(ANA_TABLES_SFIDACCESS),
68 REG_RESERVED(ANA_TABLES_SFIDTIDX),
69 REG_RESERVED(ANA_MSTI_STATE),
70 REG_RESERVED(ANA_OAM_UPM_LM_CNT),
71 REG_RESERVED(ANA_SG_ACCESS_CTRL),
72 REG_RESERVED(ANA_SG_CONFIG_REG_1),
73 REG_RESERVED(ANA_SG_CONFIG_REG_2),
74 REG_RESERVED(ANA_SG_CONFIG_REG_3),
75 REG_RESERVED(ANA_SG_CONFIG_REG_4),
76 REG_RESERVED(ANA_SG_CONFIG_REG_5),
77 REG_RESERVED(ANA_SG_GCL_GS_CONFIG),
78 REG_RESERVED(ANA_SG_GCL_TI_CONFIG),
79 REG_RESERVED(ANA_SG_STATUS_REG_1),
80 REG_RESERVED(ANA_SG_STATUS_REG_2),
81 REG_RESERVED(ANA_SG_STATUS_REG_3),
82 REG(ANA_PORT_VLAN_CFG, 0x000000),
83 REG(ANA_PORT_DROP_CFG, 0x000004),
84 REG(ANA_PORT_QOS_CFG, 0x000008),
85 REG(ANA_PORT_VCAP_CFG, 0x00000c),
86 REG(ANA_PORT_VCAP_S1_KEY_CFG, 0x000010),
87 REG(ANA_PORT_VCAP_S2_CFG, 0x00001c),
88 REG(ANA_PORT_PCP_DEI_MAP, 0x000020),
89 REG(ANA_PORT_CPU_FWD_CFG, 0x000060),
90 REG(ANA_PORT_CPU_FWD_BPDU_CFG, 0x000064),
91 REG(ANA_PORT_CPU_FWD_GARP_CFG, 0x000068),
92 REG(ANA_PORT_CPU_FWD_CCM_CFG, 0x00006c),
93 REG(ANA_PORT_PORT_CFG, 0x000070),
94 REG(ANA_PORT_POL_CFG, 0x000074),
95 REG_RESERVED(ANA_PORT_PTP_CFG),
96 REG_RESERVED(ANA_PORT_PTP_DLY1_CFG),
97 REG_RESERVED(ANA_PORT_PTP_DLY2_CFG),
98 REG_RESERVED(ANA_PORT_SFID_CFG),
99 REG(ANA_PFC_PFC_CFG, 0x00c000),
100 REG_RESERVED(ANA_PFC_PFC_TIMER),
101 REG_RESERVED(ANA_IPT_OAM_MEP_CFG),
102 REG_RESERVED(ANA_IPT_IPT),
103 REG_RESERVED(ANA_PPT_PPT),
104 REG_RESERVED(ANA_FID_MAP_FID_MAP),
105 REG(ANA_AGGR_CFG, 0x00c600),
106 REG(ANA_CPUQ_CFG, 0x00c604),
107 REG_RESERVED(ANA_CPUQ_CFG2),
108 REG(ANA_CPUQ_8021_CFG, 0x00c60c),
109 REG(ANA_DSCP_CFG, 0x00c64c),
110 REG(ANA_DSCP_REWR_CFG, 0x00c74c),
111 REG(ANA_VCAP_RNG_TYPE_CFG, 0x00c78c),
112 REG(ANA_VCAP_RNG_VAL_CFG, 0x00c7ac),
113 REG_RESERVED(ANA_VRAP_CFG),
114 REG_RESERVED(ANA_VRAP_HDR_DATA),
115 REG_RESERVED(ANA_VRAP_HDR_MASK),
116 REG(ANA_DISCARD_CFG, 0x00c7d8),
117 REG(ANA_FID_CFG, 0x00c7dc),
118 REG(ANA_POL_PIR_CFG, 0x00a000),
119 REG(ANA_POL_CIR_CFG, 0x00a004),
120 REG(ANA_POL_MODE_CFG, 0x00a008),
121 REG(ANA_POL_PIR_STATE, 0x00a00c),
122 REG(ANA_POL_CIR_STATE, 0x00a010),
123 REG_RESERVED(ANA_POL_STATE),
124 REG(ANA_POL_FLOWC, 0x00c280),
125 REG(ANA_POL_HYST, 0x00c2ec),
126 REG_RESERVED(ANA_POL_MISC_CFG),
127};
128
129static const u32 vsc9953_qs_regmap[] = {
130 REG(QS_XTR_GRP_CFG, 0x000000),
131 REG(QS_XTR_RD, 0x000008),
132 REG(QS_XTR_FRM_PRUNING, 0x000010),
133 REG(QS_XTR_FLUSH, 0x000018),
134 REG(QS_XTR_DATA_PRESENT, 0x00001c),
135 REG(QS_XTR_CFG, 0x000020),
136 REG(QS_INJ_GRP_CFG, 0x000024),
137 REG(QS_INJ_WR, 0x00002c),
138 REG(QS_INJ_CTRL, 0x000034),
139 REG(QS_INJ_STATUS, 0x00003c),
140 REG(QS_INJ_ERR, 0x000040),
141 REG_RESERVED(QS_INH_DBG),
142};
143
Vladimir Olteanc1c39932020-09-30 01:27:23 +0300144static const u32 vsc9953_vcap_regmap[] = {
145 /* VCAP_CORE_CFG */
146 REG(VCAP_CORE_UPDATE_CTRL, 0x000000),
147 REG(VCAP_CORE_MV_CFG, 0x000004),
148 /* VCAP_CORE_CACHE */
149 REG(VCAP_CACHE_ENTRY_DAT, 0x000008),
150 REG(VCAP_CACHE_MASK_DAT, 0x000108),
151 REG(VCAP_CACHE_ACTION_DAT, 0x000208),
152 REG(VCAP_CACHE_CNT_DAT, 0x000308),
153 REG(VCAP_CACHE_TG_DAT, 0x000388),
Vladimir Oltean20968052020-09-30 01:27:26 +0300154 /* VCAP_CONST */
155 REG(VCAP_CONST_VCAP_VER, 0x000398),
156 REG(VCAP_CONST_ENTRY_WIDTH, 0x00039c),
157 REG(VCAP_CONST_ENTRY_CNT, 0x0003a0),
158 REG(VCAP_CONST_ENTRY_SWCNT, 0x0003a4),
159 REG(VCAP_CONST_ENTRY_TG_WIDTH, 0x0003a8),
160 REG(VCAP_CONST_ACTION_DEF_CNT, 0x0003ac),
161 REG(VCAP_CONST_ACTION_WIDTH, 0x0003b0),
162 REG(VCAP_CONST_CNT_WIDTH, 0x0003b4),
163 REG_RESERVED(VCAP_CONST_CORE_CNT),
164 REG_RESERVED(VCAP_CONST_IF_CNT),
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300165};
166
167static const u32 vsc9953_qsys_regmap[] = {
168 REG(QSYS_PORT_MODE, 0x003600),
169 REG(QSYS_SWITCH_PORT_MODE, 0x003630),
170 REG(QSYS_STAT_CNT_CFG, 0x00365c),
171 REG(QSYS_EEE_CFG, 0x003660),
172 REG(QSYS_EEE_THRES, 0x003688),
173 REG(QSYS_IGR_NO_SHARING, 0x00368c),
174 REG(QSYS_EGR_NO_SHARING, 0x003690),
175 REG(QSYS_SW_STATUS, 0x003694),
176 REG(QSYS_EXT_CPU_CFG, 0x0036c0),
177 REG_RESERVED(QSYS_PAD_CFG),
178 REG(QSYS_CPU_GROUP_MAP, 0x0036c8),
179 REG_RESERVED(QSYS_QMAP),
180 REG_RESERVED(QSYS_ISDX_SGRP),
181 REG_RESERVED(QSYS_TIMED_FRAME_ENTRY),
182 REG_RESERVED(QSYS_TFRM_MISC),
183 REG_RESERVED(QSYS_TFRM_PORT_DLY),
184 REG_RESERVED(QSYS_TFRM_TIMER_CFG_1),
185 REG_RESERVED(QSYS_TFRM_TIMER_CFG_2),
186 REG_RESERVED(QSYS_TFRM_TIMER_CFG_3),
187 REG_RESERVED(QSYS_TFRM_TIMER_CFG_4),
188 REG_RESERVED(QSYS_TFRM_TIMER_CFG_5),
189 REG_RESERVED(QSYS_TFRM_TIMER_CFG_6),
190 REG_RESERVED(QSYS_TFRM_TIMER_CFG_7),
191 REG_RESERVED(QSYS_TFRM_TIMER_CFG_8),
192 REG(QSYS_RED_PROFILE, 0x003724),
193 REG(QSYS_RES_QOS_MODE, 0x003764),
194 REG(QSYS_RES_CFG, 0x004000),
195 REG(QSYS_RES_STAT, 0x004004),
196 REG(QSYS_EGR_DROP_MODE, 0x003768),
197 REG(QSYS_EQ_CTRL, 0x00376c),
198 REG_RESERVED(QSYS_EVENTS_CORE),
199 REG_RESERVED(QSYS_QMAXSDU_CFG_0),
200 REG_RESERVED(QSYS_QMAXSDU_CFG_1),
201 REG_RESERVED(QSYS_QMAXSDU_CFG_2),
202 REG_RESERVED(QSYS_QMAXSDU_CFG_3),
203 REG_RESERVED(QSYS_QMAXSDU_CFG_4),
204 REG_RESERVED(QSYS_QMAXSDU_CFG_5),
205 REG_RESERVED(QSYS_QMAXSDU_CFG_6),
206 REG_RESERVED(QSYS_QMAXSDU_CFG_7),
207 REG_RESERVED(QSYS_PREEMPTION_CFG),
208 REG(QSYS_CIR_CFG, 0x000000),
209 REG_RESERVED(QSYS_EIR_CFG),
210 REG(QSYS_SE_CFG, 0x000008),
211 REG(QSYS_SE_DWRR_CFG, 0x00000c),
212 REG_RESERVED(QSYS_SE_CONNECT),
213 REG_RESERVED(QSYS_SE_DLB_SENSE),
214 REG(QSYS_CIR_STATE, 0x000044),
215 REG_RESERVED(QSYS_EIR_STATE),
216 REG_RESERVED(QSYS_SE_STATE),
217 REG(QSYS_HSCH_MISC_CFG, 0x003774),
218 REG_RESERVED(QSYS_TAG_CONFIG),
219 REG_RESERVED(QSYS_TAS_PARAM_CFG_CTRL),
220 REG_RESERVED(QSYS_PORT_MAX_SDU),
221 REG_RESERVED(QSYS_PARAM_CFG_REG_1),
222 REG_RESERVED(QSYS_PARAM_CFG_REG_2),
223 REG_RESERVED(QSYS_PARAM_CFG_REG_3),
224 REG_RESERVED(QSYS_PARAM_CFG_REG_4),
225 REG_RESERVED(QSYS_PARAM_CFG_REG_5),
226 REG_RESERVED(QSYS_GCL_CFG_REG_1),
227 REG_RESERVED(QSYS_GCL_CFG_REG_2),
228 REG_RESERVED(QSYS_PARAM_STATUS_REG_1),
229 REG_RESERVED(QSYS_PARAM_STATUS_REG_2),
230 REG_RESERVED(QSYS_PARAM_STATUS_REG_3),
231 REG_RESERVED(QSYS_PARAM_STATUS_REG_4),
232 REG_RESERVED(QSYS_PARAM_STATUS_REG_5),
233 REG_RESERVED(QSYS_PARAM_STATUS_REG_6),
234 REG_RESERVED(QSYS_PARAM_STATUS_REG_7),
235 REG_RESERVED(QSYS_PARAM_STATUS_REG_8),
236 REG_RESERVED(QSYS_PARAM_STATUS_REG_9),
237 REG_RESERVED(QSYS_GCL_STATUS_REG_1),
238 REG_RESERVED(QSYS_GCL_STATUS_REG_2),
239};
240
241static const u32 vsc9953_rew_regmap[] = {
242 REG(REW_PORT_VLAN_CFG, 0x000000),
243 REG(REW_TAG_CFG, 0x000004),
244 REG(REW_PORT_CFG, 0x000008),
245 REG(REW_DSCP_CFG, 0x00000c),
246 REG(REW_PCP_DEI_QOS_MAP_CFG, 0x000010),
247 REG_RESERVED(REW_PTP_CFG),
248 REG_RESERVED(REW_PTP_DLY1_CFG),
249 REG_RESERVED(REW_RED_TAG_CFG),
250 REG(REW_DSCP_REMAP_DP1_CFG, 0x000610),
251 REG(REW_DSCP_REMAP_CFG, 0x000710),
252 REG_RESERVED(REW_STAT_CFG),
253 REG_RESERVED(REW_REW_STICKY),
254 REG_RESERVED(REW_PPT),
255};
256
257static const u32 vsc9953_sys_regmap[] = {
258 REG(SYS_COUNT_RX_OCTETS, 0x000000),
259 REG(SYS_COUNT_RX_MULTICAST, 0x000008),
260 REG(SYS_COUNT_RX_SHORTS, 0x000010),
261 REG(SYS_COUNT_RX_FRAGMENTS, 0x000014),
262 REG(SYS_COUNT_RX_JABBERS, 0x000018),
263 REG(SYS_COUNT_RX_64, 0x000024),
264 REG(SYS_COUNT_RX_65_127, 0x000028),
265 REG(SYS_COUNT_RX_128_255, 0x00002c),
266 REG(SYS_COUNT_RX_256_1023, 0x000030),
267 REG(SYS_COUNT_RX_1024_1526, 0x000034),
268 REG(SYS_COUNT_RX_1527_MAX, 0x000038),
269 REG(SYS_COUNT_RX_LONGS, 0x000048),
270 REG(SYS_COUNT_TX_OCTETS, 0x000100),
271 REG(SYS_COUNT_TX_COLLISION, 0x000110),
272 REG(SYS_COUNT_TX_DROPS, 0x000114),
273 REG(SYS_COUNT_TX_64, 0x00011c),
274 REG(SYS_COUNT_TX_65_127, 0x000120),
275 REG(SYS_COUNT_TX_128_511, 0x000124),
276 REG(SYS_COUNT_TX_512_1023, 0x000128),
277 REG(SYS_COUNT_TX_1024_1526, 0x00012c),
278 REG(SYS_COUNT_TX_1527_MAX, 0x000130),
279 REG(SYS_COUNT_TX_AGING, 0x000178),
280 REG(SYS_RESET_CFG, 0x000318),
281 REG_RESERVED(SYS_SR_ETYPE_CFG),
282 REG(SYS_VLAN_ETYPE_CFG, 0x000320),
283 REG(SYS_PORT_MODE, 0x000324),
284 REG(SYS_FRONT_PORT_MODE, 0x000354),
285 REG(SYS_FRM_AGING, 0x00037c),
286 REG(SYS_STAT_CFG, 0x000380),
287 REG_RESERVED(SYS_SW_STATUS),
288 REG_RESERVED(SYS_MISC_CFG),
289 REG_RESERVED(SYS_REW_MAC_HIGH_CFG),
290 REG_RESERVED(SYS_REW_MAC_LOW_CFG),
291 REG_RESERVED(SYS_TIMESTAMP_OFFSET),
292 REG(SYS_PAUSE_CFG, 0x00044c),
293 REG(SYS_PAUSE_TOT_CFG, 0x000478),
294 REG(SYS_ATOP, 0x00047c),
295 REG(SYS_ATOP_TOT_CFG, 0x0004a8),
296 REG(SYS_MAC_FC_CFG, 0x0004ac),
297 REG(SYS_MMGT, 0x0004d4),
298 REG_RESERVED(SYS_MMGT_FAST),
299 REG_RESERVED(SYS_EVENTS_DIF),
300 REG_RESERVED(SYS_EVENTS_CORE),
301 REG_RESERVED(SYS_CNT),
302 REG_RESERVED(SYS_PTP_STATUS),
303 REG_RESERVED(SYS_PTP_TXSTAMP),
304 REG_RESERVED(SYS_PTP_NXT),
305 REG_RESERVED(SYS_PTP_CFG),
306 REG_RESERVED(SYS_RAM_INIT),
307 REG_RESERVED(SYS_CM_ADDR),
308 REG_RESERVED(SYS_CM_DATA_WR),
309 REG_RESERVED(SYS_CM_DATA_RD),
310 REG_RESERVED(SYS_CM_OP),
311 REG_RESERVED(SYS_CM_DATA),
312};
313
314static const u32 vsc9953_gcb_regmap[] = {
315 REG(GCB_SOFT_RST, 0x000008),
316 REG(GCB_MIIM_MII_STATUS, 0x0000ac),
317 REG(GCB_MIIM_MII_CMD, 0x0000b4),
318 REG(GCB_MIIM_MII_DATA, 0x0000b8),
319};
320
321static const u32 vsc9953_dev_gmii_regmap[] = {
322 REG(DEV_CLOCK_CFG, 0x0),
323 REG(DEV_PORT_MISC, 0x4),
324 REG_RESERVED(DEV_EVENTS),
325 REG(DEV_EEE_CFG, 0xc),
326 REG_RESERVED(DEV_RX_PATH_DELAY),
327 REG_RESERVED(DEV_TX_PATH_DELAY),
328 REG_RESERVED(DEV_PTP_PREDICT_CFG),
329 REG(DEV_MAC_ENA_CFG, 0x10),
330 REG(DEV_MAC_MODE_CFG, 0x14),
331 REG(DEV_MAC_MAXLEN_CFG, 0x18),
332 REG(DEV_MAC_TAGS_CFG, 0x1c),
333 REG(DEV_MAC_ADV_CHK_CFG, 0x20),
334 REG(DEV_MAC_IFG_CFG, 0x24),
335 REG(DEV_MAC_HDX_CFG, 0x28),
336 REG_RESERVED(DEV_MAC_DBG_CFG),
337 REG(DEV_MAC_FC_MAC_LOW_CFG, 0x30),
338 REG(DEV_MAC_FC_MAC_HIGH_CFG, 0x34),
339 REG(DEV_MAC_STICKY, 0x38),
340 REG_RESERVED(PCS1G_CFG),
341 REG_RESERVED(PCS1G_MODE_CFG),
342 REG_RESERVED(PCS1G_SD_CFG),
343 REG_RESERVED(PCS1G_ANEG_CFG),
344 REG_RESERVED(PCS1G_ANEG_NP_CFG),
345 REG_RESERVED(PCS1G_LB_CFG),
346 REG_RESERVED(PCS1G_DBG_CFG),
347 REG_RESERVED(PCS1G_CDET_CFG),
348 REG_RESERVED(PCS1G_ANEG_STATUS),
349 REG_RESERVED(PCS1G_ANEG_NP_STATUS),
350 REG_RESERVED(PCS1G_LINK_STATUS),
351 REG_RESERVED(PCS1G_LINK_DOWN_CNT),
352 REG_RESERVED(PCS1G_STICKY),
353 REG_RESERVED(PCS1G_DEBUG_STATUS),
354 REG_RESERVED(PCS1G_LPI_CFG),
355 REG_RESERVED(PCS1G_LPI_WAKE_ERROR_CNT),
356 REG_RESERVED(PCS1G_LPI_STATUS),
357 REG_RESERVED(PCS1G_TSTPAT_MODE_CFG),
358 REG_RESERVED(PCS1G_TSTPAT_STATUS),
359 REG_RESERVED(DEV_PCS_FX100_CFG),
360 REG_RESERVED(DEV_PCS_FX100_STATUS),
361};
362
363static const u32 *vsc9953_regmap[TARGET_MAX] = {
364 [ANA] = vsc9953_ana_regmap,
365 [QS] = vsc9953_qs_regmap,
366 [QSYS] = vsc9953_qsys_regmap,
367 [REW] = vsc9953_rew_regmap,
368 [SYS] = vsc9953_sys_regmap,
Vladimir Olteane3aea292020-09-30 01:27:25 +0300369 [S0] = vsc9953_vcap_regmap,
Vladimir Olteana61e3652020-09-30 01:27:24 +0300370 [S1] = vsc9953_vcap_regmap,
Vladimir Olteanc1c39932020-09-30 01:27:23 +0300371 [S2] = vsc9953_vcap_regmap,
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300372 [GCB] = vsc9953_gcb_regmap,
373 [DEV_GMII] = vsc9953_dev_gmii_regmap,
374};
375
376/* Addresses are relative to the device's base address */
377static const struct resource vsc9953_target_io_res[TARGET_MAX] = {
378 [ANA] = {
379 .start = 0x0280000,
380 .end = 0x028ffff,
381 .name = "ana",
382 },
383 [QS] = {
384 .start = 0x0080000,
385 .end = 0x00800ff,
386 .name = "qs",
387 },
388 [QSYS] = {
389 .start = 0x0200000,
390 .end = 0x021ffff,
391 .name = "qsys",
392 },
393 [REW] = {
394 .start = 0x0030000,
395 .end = 0x003ffff,
396 .name = "rew",
397 },
398 [SYS] = {
399 .start = 0x0010000,
400 .end = 0x001ffff,
401 .name = "sys",
402 },
Vladimir Olteane3aea292020-09-30 01:27:25 +0300403 [S0] = {
404 .start = 0x0040000,
405 .end = 0x00403ff,
406 .name = "s0",
407 },
Vladimir Olteana61e3652020-09-30 01:27:24 +0300408 [S1] = {
409 .start = 0x0050000,
410 .end = 0x00503ff,
411 .name = "s1",
412 },
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300413 [S2] = {
414 .start = 0x0060000,
415 .end = 0x00603ff,
416 .name = "s2",
417 },
418 [PTP] = {
419 .start = 0x0090000,
420 .end = 0x00900cb,
421 .name = "ptp",
422 },
423 [GCB] = {
424 .start = 0x0070000,
425 .end = 0x00701ff,
426 .name = "devcpu_gcb",
427 },
428};
429
430static const struct resource vsc9953_port_io_res[] = {
431 {
432 .start = 0x0100000,
433 .end = 0x010ffff,
434 .name = "port0",
435 },
436 {
437 .start = 0x0110000,
438 .end = 0x011ffff,
439 .name = "port1",
440 },
441 {
442 .start = 0x0120000,
443 .end = 0x012ffff,
444 .name = "port2",
445 },
446 {
447 .start = 0x0130000,
448 .end = 0x013ffff,
449 .name = "port3",
450 },
451 {
452 .start = 0x0140000,
453 .end = 0x014ffff,
454 .name = "port4",
455 },
456 {
457 .start = 0x0150000,
458 .end = 0x015ffff,
459 .name = "port5",
460 },
461 {
462 .start = 0x0160000,
463 .end = 0x016ffff,
464 .name = "port6",
465 },
466 {
467 .start = 0x0170000,
468 .end = 0x017ffff,
469 .name = "port7",
470 },
471 {
472 .start = 0x0180000,
473 .end = 0x018ffff,
474 .name = "port8",
475 },
476 {
477 .start = 0x0190000,
478 .end = 0x019ffff,
479 .name = "port9",
480 },
481};
482
483static const struct reg_field vsc9953_regfields[REGFIELD_MAX] = {
484 [ANA_ADVLEARN_VLAN_CHK] = REG_FIELD(ANA_ADVLEARN, 10, 10),
485 [ANA_ADVLEARN_LEARN_MIRROR] = REG_FIELD(ANA_ADVLEARN, 0, 9),
486 [ANA_ANEVENTS_AUTOAGE] = REG_FIELD(ANA_ANEVENTS, 24, 24),
487 [ANA_ANEVENTS_STORM_DROP] = REG_FIELD(ANA_ANEVENTS, 22, 22),
488 [ANA_ANEVENTS_LEARN_DROP] = REG_FIELD(ANA_ANEVENTS, 21, 21),
489 [ANA_ANEVENTS_AGED_ENTRY] = REG_FIELD(ANA_ANEVENTS, 20, 20),
490 [ANA_ANEVENTS_CPU_LEARN_FAILED] = REG_FIELD(ANA_ANEVENTS, 19, 19),
491 [ANA_ANEVENTS_AUTO_LEARN_FAILED] = REG_FIELD(ANA_ANEVENTS, 18, 18),
492 [ANA_ANEVENTS_LEARN_REMOVE] = REG_FIELD(ANA_ANEVENTS, 17, 17),
493 [ANA_ANEVENTS_AUTO_LEARNED] = REG_FIELD(ANA_ANEVENTS, 16, 16),
494 [ANA_ANEVENTS_AUTO_MOVED] = REG_FIELD(ANA_ANEVENTS, 15, 15),
495 [ANA_ANEVENTS_CLASSIFIED_DROP] = REG_FIELD(ANA_ANEVENTS, 13, 13),
496 [ANA_ANEVENTS_CLASSIFIED_COPY] = REG_FIELD(ANA_ANEVENTS, 12, 12),
497 [ANA_ANEVENTS_VLAN_DISCARD] = REG_FIELD(ANA_ANEVENTS, 11, 11),
498 [ANA_ANEVENTS_FWD_DISCARD] = REG_FIELD(ANA_ANEVENTS, 10, 10),
499 [ANA_ANEVENTS_MULTICAST_FLOOD] = REG_FIELD(ANA_ANEVENTS, 9, 9),
500 [ANA_ANEVENTS_UNICAST_FLOOD] = REG_FIELD(ANA_ANEVENTS, 8, 8),
501 [ANA_ANEVENTS_DEST_KNOWN] = REG_FIELD(ANA_ANEVENTS, 7, 7),
502 [ANA_ANEVENTS_BUCKET3_MATCH] = REG_FIELD(ANA_ANEVENTS, 6, 6),
503 [ANA_ANEVENTS_BUCKET2_MATCH] = REG_FIELD(ANA_ANEVENTS, 5, 5),
504 [ANA_ANEVENTS_BUCKET1_MATCH] = REG_FIELD(ANA_ANEVENTS, 4, 4),
505 [ANA_ANEVENTS_BUCKET0_MATCH] = REG_FIELD(ANA_ANEVENTS, 3, 3),
506 [ANA_ANEVENTS_CPU_OPERATION] = REG_FIELD(ANA_ANEVENTS, 2, 2),
507 [ANA_ANEVENTS_DMAC_LOOKUP] = REG_FIELD(ANA_ANEVENTS, 1, 1),
508 [ANA_ANEVENTS_SMAC_LOOKUP] = REG_FIELD(ANA_ANEVENTS, 0, 0),
509 [ANA_TABLES_MACACCESS_B_DOM] = REG_FIELD(ANA_TABLES_MACACCESS, 16, 16),
510 [ANA_TABLES_MACTINDX_BUCKET] = REG_FIELD(ANA_TABLES_MACTINDX, 11, 12),
511 [ANA_TABLES_MACTINDX_M_INDEX] = REG_FIELD(ANA_TABLES_MACTINDX, 0, 10),
512 [SYS_RESET_CFG_CORE_ENA] = REG_FIELD(SYS_RESET_CFG, 7, 7),
513 [SYS_RESET_CFG_MEM_ENA] = REG_FIELD(SYS_RESET_CFG, 6, 6),
514 [SYS_RESET_CFG_MEM_INIT] = REG_FIELD(SYS_RESET_CFG, 5, 5),
515 [GCB_SOFT_RST_SWC_RST] = REG_FIELD(GCB_SOFT_RST, 0, 0),
516 [GCB_MIIM_MII_STATUS_PENDING] = REG_FIELD(GCB_MIIM_MII_STATUS, 2, 2),
517 [GCB_MIIM_MII_STATUS_BUSY] = REG_FIELD(GCB_MIIM_MII_STATUS, 3, 3),
518 /* Replicated per number of ports (11), register size 4 per port */
519 [QSYS_SWITCH_PORT_MODE_PORT_ENA] = REG_FIELD_ID(QSYS_SWITCH_PORT_MODE, 13, 13, 11, 4),
520 [QSYS_SWITCH_PORT_MODE_YEL_RSRVD] = REG_FIELD_ID(QSYS_SWITCH_PORT_MODE, 10, 10, 11, 4),
521 [QSYS_SWITCH_PORT_MODE_INGRESS_DROP_MODE] = REG_FIELD_ID(QSYS_SWITCH_PORT_MODE, 9, 9, 11, 4),
522 [QSYS_SWITCH_PORT_MODE_TX_PFC_ENA] = REG_FIELD_ID(QSYS_SWITCH_PORT_MODE, 1, 8, 11, 4),
523 [QSYS_SWITCH_PORT_MODE_TX_PFC_MODE] = REG_FIELD_ID(QSYS_SWITCH_PORT_MODE, 0, 0, 11, 4),
524 [SYS_PORT_MODE_INCL_INJ_HDR] = REG_FIELD_ID(SYS_PORT_MODE, 4, 5, 11, 4),
525 [SYS_PORT_MODE_INCL_XTR_HDR] = REG_FIELD_ID(SYS_PORT_MODE, 2, 3, 11, 4),
526 [SYS_PORT_MODE_INCL_HDR_ERR] = REG_FIELD_ID(SYS_PORT_MODE, 0, 0, 11, 4),
527 [SYS_PAUSE_CFG_PAUSE_START] = REG_FIELD_ID(SYS_PAUSE_CFG, 11, 20, 11, 4),
528 [SYS_PAUSE_CFG_PAUSE_STOP] = REG_FIELD_ID(SYS_PAUSE_CFG, 1, 10, 11, 4),
529 [SYS_PAUSE_CFG_PAUSE_ENA] = REG_FIELD_ID(SYS_PAUSE_CFG, 0, 1, 11, 4),
530};
531
532static const struct ocelot_stat_layout vsc9953_stats_layout[] = {
533 { .offset = 0x00, .name = "rx_octets", },
534 { .offset = 0x01, .name = "rx_unicast", },
535 { .offset = 0x02, .name = "rx_multicast", },
536 { .offset = 0x03, .name = "rx_broadcast", },
537 { .offset = 0x04, .name = "rx_shorts", },
538 { .offset = 0x05, .name = "rx_fragments", },
539 { .offset = 0x06, .name = "rx_jabbers", },
540 { .offset = 0x07, .name = "rx_crc_align_errs", },
541 { .offset = 0x08, .name = "rx_sym_errs", },
542 { .offset = 0x09, .name = "rx_frames_below_65_octets", },
543 { .offset = 0x0A, .name = "rx_frames_65_to_127_octets", },
544 { .offset = 0x0B, .name = "rx_frames_128_to_255_octets", },
545 { .offset = 0x0C, .name = "rx_frames_256_to_511_octets", },
546 { .offset = 0x0D, .name = "rx_frames_512_to_1023_octets", },
547 { .offset = 0x0E, .name = "rx_frames_1024_to_1526_octets", },
548 { .offset = 0x0F, .name = "rx_frames_over_1526_octets", },
549 { .offset = 0x10, .name = "rx_pause", },
550 { .offset = 0x11, .name = "rx_control", },
551 { .offset = 0x12, .name = "rx_longs", },
552 { .offset = 0x13, .name = "rx_classified_drops", },
553 { .offset = 0x14, .name = "rx_red_prio_0", },
554 { .offset = 0x15, .name = "rx_red_prio_1", },
555 { .offset = 0x16, .name = "rx_red_prio_2", },
556 { .offset = 0x17, .name = "rx_red_prio_3", },
557 { .offset = 0x18, .name = "rx_red_prio_4", },
558 { .offset = 0x19, .name = "rx_red_prio_5", },
559 { .offset = 0x1A, .name = "rx_red_prio_6", },
560 { .offset = 0x1B, .name = "rx_red_prio_7", },
561 { .offset = 0x1C, .name = "rx_yellow_prio_0", },
562 { .offset = 0x1D, .name = "rx_yellow_prio_1", },
563 { .offset = 0x1E, .name = "rx_yellow_prio_2", },
564 { .offset = 0x1F, .name = "rx_yellow_prio_3", },
565 { .offset = 0x20, .name = "rx_yellow_prio_4", },
566 { .offset = 0x21, .name = "rx_yellow_prio_5", },
567 { .offset = 0x22, .name = "rx_yellow_prio_6", },
568 { .offset = 0x23, .name = "rx_yellow_prio_7", },
569 { .offset = 0x24, .name = "rx_green_prio_0", },
570 { .offset = 0x25, .name = "rx_green_prio_1", },
571 { .offset = 0x26, .name = "rx_green_prio_2", },
572 { .offset = 0x27, .name = "rx_green_prio_3", },
573 { .offset = 0x28, .name = "rx_green_prio_4", },
574 { .offset = 0x29, .name = "rx_green_prio_5", },
575 { .offset = 0x2A, .name = "rx_green_prio_6", },
576 { .offset = 0x2B, .name = "rx_green_prio_7", },
577 { .offset = 0x40, .name = "tx_octets", },
578 { .offset = 0x41, .name = "tx_unicast", },
579 { .offset = 0x42, .name = "tx_multicast", },
580 { .offset = 0x43, .name = "tx_broadcast", },
581 { .offset = 0x44, .name = "tx_collision", },
582 { .offset = 0x45, .name = "tx_drops", },
583 { .offset = 0x46, .name = "tx_pause", },
584 { .offset = 0x47, .name = "tx_frames_below_65_octets", },
585 { .offset = 0x48, .name = "tx_frames_65_to_127_octets", },
586 { .offset = 0x49, .name = "tx_frames_128_255_octets", },
587 { .offset = 0x4A, .name = "tx_frames_256_511_octets", },
588 { .offset = 0x4B, .name = "tx_frames_512_1023_octets", },
589 { .offset = 0x4C, .name = "tx_frames_1024_1526_octets", },
590 { .offset = 0x4D, .name = "tx_frames_over_1526_octets", },
591 { .offset = 0x4E, .name = "tx_yellow_prio_0", },
592 { .offset = 0x4F, .name = "tx_yellow_prio_1", },
593 { .offset = 0x50, .name = "tx_yellow_prio_2", },
594 { .offset = 0x51, .name = "tx_yellow_prio_3", },
595 { .offset = 0x52, .name = "tx_yellow_prio_4", },
596 { .offset = 0x53, .name = "tx_yellow_prio_5", },
597 { .offset = 0x54, .name = "tx_yellow_prio_6", },
598 { .offset = 0x55, .name = "tx_yellow_prio_7", },
599 { .offset = 0x56, .name = "tx_green_prio_0", },
600 { .offset = 0x57, .name = "tx_green_prio_1", },
601 { .offset = 0x58, .name = "tx_green_prio_2", },
602 { .offset = 0x59, .name = "tx_green_prio_3", },
603 { .offset = 0x5A, .name = "tx_green_prio_4", },
604 { .offset = 0x5B, .name = "tx_green_prio_5", },
605 { .offset = 0x5C, .name = "tx_green_prio_6", },
606 { .offset = 0x5D, .name = "tx_green_prio_7", },
607 { .offset = 0x5E, .name = "tx_aged", },
608 { .offset = 0x80, .name = "drop_local", },
609 { .offset = 0x81, .name = "drop_tail", },
610 { .offset = 0x82, .name = "drop_yellow_prio_0", },
611 { .offset = 0x83, .name = "drop_yellow_prio_1", },
612 { .offset = 0x84, .name = "drop_yellow_prio_2", },
613 { .offset = 0x85, .name = "drop_yellow_prio_3", },
614 { .offset = 0x86, .name = "drop_yellow_prio_4", },
615 { .offset = 0x87, .name = "drop_yellow_prio_5", },
616 { .offset = 0x88, .name = "drop_yellow_prio_6", },
617 { .offset = 0x89, .name = "drop_yellow_prio_7", },
618 { .offset = 0x8A, .name = "drop_green_prio_0", },
619 { .offset = 0x8B, .name = "drop_green_prio_1", },
620 { .offset = 0x8C, .name = "drop_green_prio_2", },
621 { .offset = 0x8D, .name = "drop_green_prio_3", },
622 { .offset = 0x8E, .name = "drop_green_prio_4", },
623 { .offset = 0x8F, .name = "drop_green_prio_5", },
624 { .offset = 0x90, .name = "drop_green_prio_6", },
625 { .offset = 0x91, .name = "drop_green_prio_7", },
626};
627
Vladimir Olteane3aea292020-09-30 01:27:25 +0300628static const struct vcap_field vsc9953_vcap_es0_keys[] = {
629 [VCAP_ES0_EGR_PORT] = { 0, 4},
630 [VCAP_ES0_IGR_PORT] = { 4, 4},
631 [VCAP_ES0_RSV] = { 8, 2},
632 [VCAP_ES0_L2_MC] = { 10, 1},
633 [VCAP_ES0_L2_BC] = { 11, 1},
634 [VCAP_ES0_VID] = { 12, 12},
635 [VCAP_ES0_DP] = { 24, 1},
636 [VCAP_ES0_PCP] = { 25, 3},
637};
638
639static const struct vcap_field vsc9953_vcap_es0_actions[] = {
640 [VCAP_ES0_ACT_PUSH_OUTER_TAG] = { 0, 2},
641 [VCAP_ES0_ACT_PUSH_INNER_TAG] = { 2, 1},
642 [VCAP_ES0_ACT_TAG_A_TPID_SEL] = { 3, 2},
643 [VCAP_ES0_ACT_TAG_A_VID_SEL] = { 5, 1},
644 [VCAP_ES0_ACT_TAG_A_PCP_SEL] = { 6, 2},
645 [VCAP_ES0_ACT_TAG_A_DEI_SEL] = { 8, 2},
646 [VCAP_ES0_ACT_TAG_B_TPID_SEL] = { 10, 2},
647 [VCAP_ES0_ACT_TAG_B_VID_SEL] = { 12, 1},
648 [VCAP_ES0_ACT_TAG_B_PCP_SEL] = { 13, 2},
649 [VCAP_ES0_ACT_TAG_B_DEI_SEL] = { 15, 2},
650 [VCAP_ES0_ACT_VID_A_VAL] = { 17, 12},
651 [VCAP_ES0_ACT_PCP_A_VAL] = { 29, 3},
652 [VCAP_ES0_ACT_DEI_A_VAL] = { 32, 1},
653 [VCAP_ES0_ACT_VID_B_VAL] = { 33, 12},
654 [VCAP_ES0_ACT_PCP_B_VAL] = { 45, 3},
655 [VCAP_ES0_ACT_DEI_B_VAL] = { 48, 1},
656 [VCAP_ES0_ACT_RSV] = { 49, 24},
657 [VCAP_ES0_ACT_HIT_STICKY] = { 73, 1},
658};
659
Vladimir Olteana61e3652020-09-30 01:27:24 +0300660static const struct vcap_field vsc9953_vcap_is1_keys[] = {
661 [VCAP_IS1_HK_TYPE] = { 0, 1},
662 [VCAP_IS1_HK_LOOKUP] = { 1, 2},
663 [VCAP_IS1_HK_IGR_PORT_MASK] = { 3, 11},
664 [VCAP_IS1_HK_RSV] = { 14, 10},
665 /* VCAP_IS1_HK_OAM_Y1731 not supported */
666 [VCAP_IS1_HK_L2_MC] = { 24, 1},
667 [VCAP_IS1_HK_L2_BC] = { 25, 1},
668 [VCAP_IS1_HK_IP_MC] = { 26, 1},
669 [VCAP_IS1_HK_VLAN_TAGGED] = { 27, 1},
670 [VCAP_IS1_HK_VLAN_DBL_TAGGED] = { 28, 1},
671 [VCAP_IS1_HK_TPID] = { 29, 1},
672 [VCAP_IS1_HK_VID] = { 30, 12},
673 [VCAP_IS1_HK_DEI] = { 42, 1},
674 [VCAP_IS1_HK_PCP] = { 43, 3},
675 /* Specific Fields for IS1 Half Key S1_NORMAL */
676 [VCAP_IS1_HK_L2_SMAC] = { 46, 48},
677 [VCAP_IS1_HK_ETYPE_LEN] = { 94, 1},
678 [VCAP_IS1_HK_ETYPE] = { 95, 16},
679 [VCAP_IS1_HK_IP_SNAP] = {111, 1},
680 [VCAP_IS1_HK_IP4] = {112, 1},
681 /* Layer-3 Information */
682 [VCAP_IS1_HK_L3_FRAGMENT] = {113, 1},
683 [VCAP_IS1_HK_L3_FRAG_OFS_GT0] = {114, 1},
684 [VCAP_IS1_HK_L3_OPTIONS] = {115, 1},
685 [VCAP_IS1_HK_L3_DSCP] = {116, 6},
686 [VCAP_IS1_HK_L3_IP4_SIP] = {122, 32},
687 /* Layer-4 Information */
688 [VCAP_IS1_HK_TCP_UDP] = {154, 1},
689 [VCAP_IS1_HK_TCP] = {155, 1},
690 [VCAP_IS1_HK_L4_SPORT] = {156, 16},
691 [VCAP_IS1_HK_L4_RNG] = {172, 8},
692 /* Specific Fields for IS1 Half Key S1_5TUPLE_IP4 */
693 [VCAP_IS1_HK_IP4_INNER_TPID] = { 46, 1},
694 [VCAP_IS1_HK_IP4_INNER_VID] = { 47, 12},
695 [VCAP_IS1_HK_IP4_INNER_DEI] = { 59, 1},
696 [VCAP_IS1_HK_IP4_INNER_PCP] = { 60, 3},
697 [VCAP_IS1_HK_IP4_IP4] = { 63, 1},
698 [VCAP_IS1_HK_IP4_L3_FRAGMENT] = { 64, 1},
699 [VCAP_IS1_HK_IP4_L3_FRAG_OFS_GT0] = { 65, 1},
700 [VCAP_IS1_HK_IP4_L3_OPTIONS] = { 66, 1},
701 [VCAP_IS1_HK_IP4_L3_DSCP] = { 67, 6},
702 [VCAP_IS1_HK_IP4_L3_IP4_DIP] = { 73, 32},
703 [VCAP_IS1_HK_IP4_L3_IP4_SIP] = {105, 32},
704 [VCAP_IS1_HK_IP4_L3_PROTO] = {137, 8},
705 [VCAP_IS1_HK_IP4_TCP_UDP] = {145, 1},
706 [VCAP_IS1_HK_IP4_TCP] = {146, 1},
707 [VCAP_IS1_HK_IP4_L4_RNG] = {147, 8},
708 [VCAP_IS1_HK_IP4_IP_PAYLOAD_S1_5TUPLE] = {155, 32},
709};
710
711static const struct vcap_field vsc9953_vcap_is1_actions[] = {
712 [VCAP_IS1_ACT_DSCP_ENA] = { 0, 1},
713 [VCAP_IS1_ACT_DSCP_VAL] = { 1, 6},
714 [VCAP_IS1_ACT_QOS_ENA] = { 7, 1},
715 [VCAP_IS1_ACT_QOS_VAL] = { 8, 3},
716 [VCAP_IS1_ACT_DP_ENA] = { 11, 1},
717 [VCAP_IS1_ACT_DP_VAL] = { 12, 1},
718 [VCAP_IS1_ACT_PAG_OVERRIDE_MASK] = { 13, 8},
719 [VCAP_IS1_ACT_PAG_VAL] = { 21, 8},
720 [VCAP_IS1_ACT_RSV] = { 29, 11},
721 [VCAP_IS1_ACT_VID_REPLACE_ENA] = { 40, 1},
722 [VCAP_IS1_ACT_VID_ADD_VAL] = { 41, 12},
723 [VCAP_IS1_ACT_FID_SEL] = { 53, 2},
724 [VCAP_IS1_ACT_FID_VAL] = { 55, 13},
725 [VCAP_IS1_ACT_PCP_DEI_ENA] = { 68, 1},
726 [VCAP_IS1_ACT_PCP_VAL] = { 69, 3},
727 [VCAP_IS1_ACT_DEI_VAL] = { 72, 1},
728 [VCAP_IS1_ACT_VLAN_POP_CNT_ENA] = { 73, 1},
729 [VCAP_IS1_ACT_VLAN_POP_CNT] = { 74, 2},
730 [VCAP_IS1_ACT_CUSTOM_ACE_TYPE_ENA] = { 76, 4},
731 [VCAP_IS1_ACT_HIT_STICKY] = { 80, 1},
732};
733
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300734static struct vcap_field vsc9953_vcap_is2_keys[] = {
735 /* Common: 41 bits */
736 [VCAP_IS2_TYPE] = { 0, 4},
737 [VCAP_IS2_HK_FIRST] = { 4, 1},
738 [VCAP_IS2_HK_PAG] = { 5, 8},
739 [VCAP_IS2_HK_IGR_PORT_MASK] = { 13, 11},
740 [VCAP_IS2_HK_RSV2] = { 24, 1},
741 [VCAP_IS2_HK_HOST_MATCH] = { 25, 1},
742 [VCAP_IS2_HK_L2_MC] = { 26, 1},
743 [VCAP_IS2_HK_L2_BC] = { 27, 1},
744 [VCAP_IS2_HK_VLAN_TAGGED] = { 28, 1},
745 [VCAP_IS2_HK_VID] = { 29, 12},
746 [VCAP_IS2_HK_DEI] = { 41, 1},
747 [VCAP_IS2_HK_PCP] = { 42, 3},
748 /* MAC_ETYPE / MAC_LLC / MAC_SNAP / OAM common */
749 [VCAP_IS2_HK_L2_DMAC] = { 45, 48},
750 [VCAP_IS2_HK_L2_SMAC] = { 93, 48},
751 /* MAC_ETYPE (TYPE=000) */
752 [VCAP_IS2_HK_MAC_ETYPE_ETYPE] = {141, 16},
753 [VCAP_IS2_HK_MAC_ETYPE_L2_PAYLOAD0] = {157, 16},
754 [VCAP_IS2_HK_MAC_ETYPE_L2_PAYLOAD1] = {173, 8},
755 [VCAP_IS2_HK_MAC_ETYPE_L2_PAYLOAD2] = {181, 3},
756 /* MAC_LLC (TYPE=001) */
757 [VCAP_IS2_HK_MAC_LLC_L2_LLC] = {141, 40},
758 /* MAC_SNAP (TYPE=010) */
759 [VCAP_IS2_HK_MAC_SNAP_L2_SNAP] = {141, 40},
760 /* MAC_ARP (TYPE=011) */
761 [VCAP_IS2_HK_MAC_ARP_SMAC] = { 45, 48},
762 [VCAP_IS2_HK_MAC_ARP_ADDR_SPACE_OK] = { 93, 1},
763 [VCAP_IS2_HK_MAC_ARP_PROTO_SPACE_OK] = { 94, 1},
764 [VCAP_IS2_HK_MAC_ARP_LEN_OK] = { 95, 1},
765 [VCAP_IS2_HK_MAC_ARP_TARGET_MATCH] = { 96, 1},
766 [VCAP_IS2_HK_MAC_ARP_SENDER_MATCH] = { 97, 1},
767 [VCAP_IS2_HK_MAC_ARP_OPCODE_UNKNOWN] = { 98, 1},
768 [VCAP_IS2_HK_MAC_ARP_OPCODE] = { 99, 2},
769 [VCAP_IS2_HK_MAC_ARP_L3_IP4_DIP] = {101, 32},
770 [VCAP_IS2_HK_MAC_ARP_L3_IP4_SIP] = {133, 32},
771 [VCAP_IS2_HK_MAC_ARP_DIP_EQ_SIP] = {165, 1},
772 /* IP4_TCP_UDP / IP4_OTHER common */
773 [VCAP_IS2_HK_IP4] = { 45, 1},
774 [VCAP_IS2_HK_L3_FRAGMENT] = { 46, 1},
775 [VCAP_IS2_HK_L3_FRAG_OFS_GT0] = { 47, 1},
776 [VCAP_IS2_HK_L3_OPTIONS] = { 48, 1},
777 [VCAP_IS2_HK_IP4_L3_TTL_GT0] = { 49, 1},
778 [VCAP_IS2_HK_L3_TOS] = { 50, 8},
779 [VCAP_IS2_HK_L3_IP4_DIP] = { 58, 32},
780 [VCAP_IS2_HK_L3_IP4_SIP] = { 90, 32},
781 [VCAP_IS2_HK_DIP_EQ_SIP] = {122, 1},
782 /* IP4_TCP_UDP (TYPE=100) */
783 [VCAP_IS2_HK_TCP] = {123, 1},
Vladimir Oltean7a023072020-09-22 01:56:37 +0300784 [VCAP_IS2_HK_L4_DPORT] = {124, 16},
785 [VCAP_IS2_HK_L4_SPORT] = {140, 16},
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300786 [VCAP_IS2_HK_L4_RNG] = {156, 8},
787 [VCAP_IS2_HK_L4_SPORT_EQ_DPORT] = {164, 1},
788 [VCAP_IS2_HK_L4_SEQUENCE_EQ0] = {165, 1},
Vladimir Oltean7a023072020-09-22 01:56:37 +0300789 [VCAP_IS2_HK_L4_FIN] = {166, 1},
790 [VCAP_IS2_HK_L4_SYN] = {167, 1},
791 [VCAP_IS2_HK_L4_RST] = {168, 1},
792 [VCAP_IS2_HK_L4_PSH] = {169, 1},
793 [VCAP_IS2_HK_L4_ACK] = {170, 1},
794 [VCAP_IS2_HK_L4_URG] = {171, 1},
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300795 /* IP4_OTHER (TYPE=101) */
796 [VCAP_IS2_HK_IP4_L3_PROTO] = {123, 8},
797 [VCAP_IS2_HK_L3_PAYLOAD] = {131, 56},
798 /* IP6_STD (TYPE=110) */
799 [VCAP_IS2_HK_IP6_L3_TTL_GT0] = { 45, 1},
800 [VCAP_IS2_HK_L3_IP6_SIP] = { 46, 128},
801 [VCAP_IS2_HK_IP6_L3_PROTO] = {174, 8},
802};
803
804static struct vcap_field vsc9953_vcap_is2_actions[] = {
805 [VCAP_IS2_ACT_HIT_ME_ONCE] = { 0, 1},
806 [VCAP_IS2_ACT_CPU_COPY_ENA] = { 1, 1},
807 [VCAP_IS2_ACT_CPU_QU_NUM] = { 2, 3},
808 [VCAP_IS2_ACT_MASK_MODE] = { 5, 2},
809 [VCAP_IS2_ACT_MIRROR_ENA] = { 7, 1},
810 [VCAP_IS2_ACT_LRN_DIS] = { 8, 1},
811 [VCAP_IS2_ACT_POLICE_ENA] = { 9, 1},
812 [VCAP_IS2_ACT_POLICE_IDX] = { 10, 8},
813 [VCAP_IS2_ACT_POLICE_VCAP_ONLY] = { 21, 1},
814 [VCAP_IS2_ACT_PORT_MASK] = { 22, 10},
815 [VCAP_IS2_ACT_ACL_ID] = { 44, 6},
816 [VCAP_IS2_ACT_HIT_CNT] = { 50, 32},
817};
818
Vladimir Oltean20968052020-09-30 01:27:26 +0300819static struct vcap_props vsc9953_vcap_props[] = {
Vladimir Olteane3aea292020-09-30 01:27:25 +0300820 [VCAP_ES0] = {
821 .action_type_width = 0,
822 .action_table = {
823 [ES0_ACTION_TYPE_NORMAL] = {
824 .width = 73, /* HIT_STICKY not included */
825 .count = 1,
826 },
827 },
828 .target = S0,
829 .keys = vsc9953_vcap_es0_keys,
830 .actions = vsc9953_vcap_es0_actions,
831 },
Vladimir Olteana61e3652020-09-30 01:27:24 +0300832 [VCAP_IS1] = {
833 .action_type_width = 0,
834 .action_table = {
835 [IS1_ACTION_TYPE_NORMAL] = {
836 .width = 80, /* HIT_STICKY not included */
837 .count = 4,
838 },
839 },
840 .target = S1,
841 .keys = vsc9953_vcap_is1_keys,
842 .actions = vsc9953_vcap_is1_actions,
843 },
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300844 [VCAP_IS2] = {
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300845 .action_type_width = 1,
846 .action_table = {
847 [IS2_ACTION_TYPE_NORMAL] = {
Vladimir Olteaneaa03552020-09-29 14:20:25 +0300848 .width = 50, /* HIT_CNT not included */
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300849 .count = 2
850 },
851 [IS2_ACTION_TYPE_SMAC_SIP] = {
852 .width = 6,
853 .count = 4
854 },
855 },
Vladimir Olteanc1c39932020-09-30 01:27:23 +0300856 .target = S2,
857 .keys = vsc9953_vcap_is2_keys,
858 .actions = vsc9953_vcap_is2_actions,
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300859 },
860};
861
862#define VSC9953_INIT_TIMEOUT 50000
863#define VSC9953_GCB_RST_SLEEP 100
864#define VSC9953_SYS_RAMINIT_SLEEP 80
865#define VCS9953_MII_TIMEOUT 10000
866
867static int vsc9953_gcb_soft_rst_status(struct ocelot *ocelot)
868{
869 int val;
870
871 ocelot_field_read(ocelot, GCB_SOFT_RST_SWC_RST, &val);
872
873 return val;
874}
875
876static int vsc9953_sys_ram_init_status(struct ocelot *ocelot)
877{
878 int val;
879
880 ocelot_field_read(ocelot, SYS_RESET_CFG_MEM_INIT, &val);
881
882 return val;
883}
884
885static int vsc9953_gcb_miim_pending_status(struct ocelot *ocelot)
886{
887 int val;
888
889 ocelot_field_read(ocelot, GCB_MIIM_MII_STATUS_PENDING, &val);
890
891 return val;
892}
893
894static int vsc9953_gcb_miim_busy_status(struct ocelot *ocelot)
895{
896 int val;
897
898 ocelot_field_read(ocelot, GCB_MIIM_MII_STATUS_BUSY, &val);
899
900 return val;
901}
902
903static int vsc9953_mdio_write(struct mii_bus *bus, int phy_id, int regnum,
904 u16 value)
905{
906 struct ocelot *ocelot = bus->priv;
907 int err, cmd, val;
908
909 /* Wait while MIIM controller becomes idle */
910 err = readx_poll_timeout(vsc9953_gcb_miim_pending_status, ocelot,
911 val, !val, 10, VCS9953_MII_TIMEOUT);
912 if (err) {
913 dev_err(ocelot->dev, "MDIO write: pending timeout\n");
914 goto out;
915 }
916
917 cmd = MSCC_MIIM_CMD_VLD | (phy_id << MSCC_MIIM_CMD_PHYAD_SHIFT) |
918 (regnum << MSCC_MIIM_CMD_REGAD_SHIFT) |
919 (value << MSCC_MIIM_CMD_WRDATA_SHIFT) |
920 MSCC_MIIM_CMD_OPR_WRITE;
921
922 ocelot_write(ocelot, cmd, GCB_MIIM_MII_CMD);
923
924out:
925 return err;
926}
927
928static int vsc9953_mdio_read(struct mii_bus *bus, int phy_id, int regnum)
929{
930 struct ocelot *ocelot = bus->priv;
931 int err, cmd, val;
932
933 /* Wait until MIIM controller becomes idle */
934 err = readx_poll_timeout(vsc9953_gcb_miim_pending_status, ocelot,
935 val, !val, 10, VCS9953_MII_TIMEOUT);
936 if (err) {
937 dev_err(ocelot->dev, "MDIO read: pending timeout\n");
938 goto out;
939 }
940
941 /* Write the MIIM COMMAND register */
942 cmd = MSCC_MIIM_CMD_VLD | (phy_id << MSCC_MIIM_CMD_PHYAD_SHIFT) |
943 (regnum << MSCC_MIIM_CMD_REGAD_SHIFT) | MSCC_MIIM_CMD_OPR_READ;
944
945 ocelot_write(ocelot, cmd, GCB_MIIM_MII_CMD);
946
947 /* Wait while read operation via the MIIM controller is in progress */
948 err = readx_poll_timeout(vsc9953_gcb_miim_busy_status, ocelot,
949 val, !val, 10, VCS9953_MII_TIMEOUT);
950 if (err) {
951 dev_err(ocelot->dev, "MDIO read: busy timeout\n");
952 goto out;
953 }
954
955 val = ocelot_read(ocelot, GCB_MIIM_MII_DATA);
956
957 err = val & 0xFFFF;
958out:
959 return err;
960}
961
Vladimir Olteanc129fc52020-09-18 13:57:46 +0300962/* CORE_ENA is in SYS:SYSTEM:RESET_CFG
963 * MEM_INIT is in SYS:SYSTEM:RESET_CFG
964 * MEM_ENA is in SYS:SYSTEM:RESET_CFG
965 */
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300966static int vsc9953_reset(struct ocelot *ocelot)
967{
968 int val, err;
969
970 /* soft-reset the switch core */
971 ocelot_field_write(ocelot, GCB_SOFT_RST_SWC_RST, 1);
972
973 err = readx_poll_timeout(vsc9953_gcb_soft_rst_status, ocelot, val, !val,
974 VSC9953_GCB_RST_SLEEP, VSC9953_INIT_TIMEOUT);
975 if (err) {
976 dev_err(ocelot->dev, "timeout: switch core reset\n");
977 return err;
978 }
979
980 /* initialize switch mem ~40us */
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300981 ocelot_field_write(ocelot, SYS_RESET_CFG_MEM_ENA, 1);
Vladimir Oltean9a73f0b2020-09-18 13:57:45 +0300982 ocelot_field_write(ocelot, SYS_RESET_CFG_MEM_INIT, 1);
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300983
984 err = readx_poll_timeout(vsc9953_sys_ram_init_status, ocelot, val, !val,
985 VSC9953_SYS_RAMINIT_SLEEP,
986 VSC9953_INIT_TIMEOUT);
987 if (err) {
988 dev_err(ocelot->dev, "timeout: switch sram init\n");
989 return err;
990 }
991
992 /* enable switch core */
Maxim Kochetkov84705fc2020-07-13 19:57:10 +0300993 ocelot_field_write(ocelot, SYS_RESET_CFG_CORE_ENA, 1);
994
995 return 0;
996}
997
998static void vsc9953_phylink_validate(struct ocelot *ocelot, int port,
999 unsigned long *supported,
1000 struct phylink_link_state *state)
1001{
1002 struct ocelot_port *ocelot_port = ocelot->ports[port];
1003 __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
1004
1005 if (state->interface != PHY_INTERFACE_MODE_NA &&
1006 state->interface != ocelot_port->phy_mode) {
Sean Anderson49730562021-10-22 18:41:04 -04001007 linkmode_zero(supported);
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001008 return;
1009 }
1010
1011 phylink_set_port_modes(mask);
1012 phylink_set(mask, Autoneg);
1013 phylink_set(mask, Pause);
1014 phylink_set(mask, Asym_Pause);
1015 phylink_set(mask, 10baseT_Full);
1016 phylink_set(mask, 10baseT_Half);
1017 phylink_set(mask, 100baseT_Full);
1018 phylink_set(mask, 100baseT_Half);
1019 phylink_set(mask, 1000baseT_Full);
1020
1021 if (state->interface == PHY_INTERFACE_MODE_INTERNAL) {
1022 phylink_set(mask, 2500baseT_Full);
1023 phylink_set(mask, 2500baseX_Full);
1024 }
1025
Sean Anderson49730562021-10-22 18:41:04 -04001026 linkmode_and(supported, supported, mask);
1027 linkmode_and(state->advertising, state->advertising, mask);
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001028}
1029
1030static int vsc9953_prevalidate_phy_mode(struct ocelot *ocelot, int port,
1031 phy_interface_t phy_mode)
1032{
1033 switch (phy_mode) {
1034 case PHY_INTERFACE_MODE_INTERNAL:
1035 if (port != 8 && port != 9)
1036 return -ENOTSUPP;
1037 return 0;
1038 case PHY_INTERFACE_MODE_SGMII:
1039 case PHY_INTERFACE_MODE_QSGMII:
1040 /* Not supported on internal to-CPU ports */
1041 if (port == 8 || port == 9)
1042 return -ENOTSUPP;
1043 return 0;
1044 default:
1045 return -ENOTSUPP;
1046 }
1047}
1048
1049/* Watermark encode
1050 * Bit 9: Unit; 0:1, 1:16
1051 * Bit 8-0: Value to be multiplied with unit
1052 */
1053static u16 vsc9953_wm_enc(u16 value)
1054{
Vladimir Oltean01326492020-10-05 12:09:12 +03001055 WARN_ON(value >= 16 * BIT(9));
1056
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001057 if (value >= BIT(9))
1058 return BIT(9) | (value / 16);
1059
1060 return value;
1061}
1062
Vladimir Oltean703b7622021-01-15 04:11:12 +02001063static u16 vsc9953_wm_dec(u16 wm)
1064{
1065 WARN_ON(wm & ~GENMASK(9, 0));
1066
1067 if (wm & BIT(9))
1068 return (wm & GENMASK(8, 0)) * 16;
1069
1070 return wm;
1071}
1072
1073static void vsc9953_wm_stat(u32 val, u32 *inuse, u32 *maxuse)
1074{
1075 *inuse = (val & GENMASK(25, 13)) >> 13;
1076 *maxuse = val & GENMASK(12, 0);
1077}
1078
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001079static const struct ocelot_ops vsc9953_ops = {
1080 .reset = vsc9953_reset,
1081 .wm_enc = vsc9953_wm_enc,
Vladimir Oltean703b7622021-01-15 04:11:12 +02001082 .wm_dec = vsc9953_wm_dec,
1083 .wm_stat = vsc9953_wm_stat,
Vladimir Oltean319e4dd2020-10-02 15:02:21 +03001084 .port_to_netdev = felix_port_to_netdev,
1085 .netdev_to_port = felix_netdev_to_port,
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001086};
1087
1088static int vsc9953_mdio_bus_alloc(struct ocelot *ocelot)
1089{
1090 struct felix *felix = ocelot_to_felix(ocelot);
1091 struct device *dev = ocelot->dev;
1092 struct mii_bus *bus;
1093 int port;
1094 int rc;
1095
1096 felix->pcs = devm_kcalloc(dev, felix->info->num_ports,
1097 sizeof(struct phy_device *),
1098 GFP_KERNEL);
1099 if (!felix->pcs) {
1100 dev_err(dev, "failed to allocate array for PCS PHYs\n");
1101 return -ENOMEM;
1102 }
1103
1104 bus = devm_mdiobus_alloc(dev);
1105 if (!bus)
1106 return -ENOMEM;
1107
1108 bus->name = "VSC9953 internal MDIO bus";
1109 bus->read = vsc9953_mdio_read;
1110 bus->write = vsc9953_mdio_write;
1111 bus->parent = dev;
1112 bus->priv = ocelot;
1113 snprintf(bus->id, MII_BUS_ID_SIZE, "%s-imdio", dev_name(dev));
1114
1115 /* Needed in order to initialize the bus mutex lock */
Colin Foster5186c4a2021-11-28 17:57:36 -08001116 rc = of_mdiobus_register(bus, NULL);
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001117 if (rc < 0) {
1118 dev_err(dev, "failed to register MDIO bus\n");
1119 return rc;
1120 }
1121
1122 felix->imdio = bus;
1123
1124 for (port = 0; port < felix->info->num_ports; port++) {
1125 struct ocelot_port *ocelot_port = ocelot->ports[port];
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001126 int addr = port + 4;
Ioana Ciornei588d0552020-08-30 11:34:02 +03001127 struct mdio_device *pcs;
1128 struct lynx_pcs *lynx;
1129
1130 if (dsa_is_unused_port(felix->ds, port))
1131 continue;
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001132
1133 if (ocelot_port->phy_mode == PHY_INTERFACE_MODE_INTERNAL)
1134 continue;
1135
Ioana Ciornei588d0552020-08-30 11:34:02 +03001136 pcs = mdio_device_create(felix->imdio, addr);
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001137 if (IS_ERR(pcs))
1138 continue;
1139
Ioana Ciornei588d0552020-08-30 11:34:02 +03001140 lynx = lynx_pcs_create(pcs);
1141 if (!lynx) {
1142 mdio_device_free(pcs);
1143 continue;
1144 }
1145
1146 felix->pcs[port] = lynx;
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001147
1148 dev_info(dev, "Found PCS at internal MDIO address %d\n", addr);
1149 }
1150
1151 return 0;
1152}
1153
Vladimir Olteanccfdbab2020-09-18 13:57:50 +03001154static void vsc9953_mdio_bus_free(struct ocelot *ocelot)
1155{
1156 struct felix *felix = ocelot_to_felix(ocelot);
1157 int port;
1158
1159 for (port = 0; port < ocelot->num_phys_ports; port++) {
1160 struct lynx_pcs *pcs = felix->pcs[port];
1161
1162 if (!pcs)
1163 continue;
1164
1165 mdio_device_free(pcs->mdio);
1166 lynx_pcs_destroy(pcs);
1167 }
1168 mdiobus_unregister(felix->imdio);
1169}
1170
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001171static const struct felix_info seville_info_vsc9953 = {
1172 .target_io_res = vsc9953_target_io_res,
1173 .port_io_res = vsc9953_port_io_res,
1174 .regfields = vsc9953_regfields,
1175 .map = vsc9953_regmap,
1176 .ops = &vsc9953_ops,
1177 .stats_layout = vsc9953_stats_layout,
1178 .num_stats = ARRAY_SIZE(vsc9953_stats_layout),
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001179 .vcap = vsc9953_vcap_props,
Xiaoliang Yang77043c32021-11-18 18:12:02 +08001180 .vcap_pol_base = VSC9953_VCAP_POLICER_BASE,
1181 .vcap_pol_max = VSC9953_VCAP_POLICER_MAX,
1182 .vcap_pol_base2 = VSC9953_VCAP_POLICER_BASE2,
1183 .vcap_pol_max2 = VSC9953_VCAP_POLICER_MAX2,
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001184 .num_mact_rows = 2048,
1185 .num_ports = 10,
Vladimir Oltean70d39a62021-01-15 04:11:16 +02001186 .num_tx_queues = OCELOT_NUM_TC,
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001187 .mdio_bus_alloc = vsc9953_mdio_bus_alloc,
Vladimir Olteanccfdbab2020-09-18 13:57:50 +03001188 .mdio_bus_free = vsc9953_mdio_bus_free,
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001189 .phylink_validate = vsc9953_phylink_validate,
1190 .prevalidate_phy_mode = vsc9953_prevalidate_phy_mode,
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001191};
1192
1193static int seville_probe(struct platform_device *pdev)
1194{
1195 struct dsa_switch *ds;
1196 struct ocelot *ocelot;
1197 struct resource *res;
1198 struct felix *felix;
1199 int err;
1200
1201 felix = kzalloc(sizeof(struct felix), GFP_KERNEL);
1202 if (!felix) {
1203 err = -ENOMEM;
1204 dev_err(&pdev->dev, "Failed to allocate driver memory\n");
1205 goto err_alloc_felix;
1206 }
1207
1208 platform_set_drvdata(pdev, felix);
1209
1210 ocelot = &felix->ocelot;
1211 ocelot->dev = &pdev->dev;
Vladimir Olteanedd24102020-12-04 19:54:16 +02001212 ocelot->num_flooding_pgids = 1;
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001213 felix->info = &seville_info_vsc9953;
1214
1215 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Yang Yingliangf1fe19c2021-06-05 10:31:48 +08001216 if (!res) {
1217 err = -EINVAL;
1218 dev_err(&pdev->dev, "Invalid resource\n");
1219 goto err_alloc_felix;
1220 }
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001221 felix->switch_base = res->start;
1222
1223 ds = kzalloc(sizeof(struct dsa_switch), GFP_KERNEL);
1224 if (!ds) {
1225 err = -ENOMEM;
1226 dev_err(&pdev->dev, "Failed to allocate DSA switch\n");
1227 goto err_alloc_ds;
1228 }
1229
1230 ds->dev = &pdev->dev;
1231 ds->num_ports = felix->info->num_ports;
1232 ds->ops = &felix_switch_ops;
1233 ds->priv = ocelot;
1234 felix->ds = ds;
Vladimir Oltean7c4bb542021-02-14 00:37:58 +02001235 felix->tag_proto = DSA_TAG_PROTO_SEVILLE;
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001236
1237 err = dsa_register_switch(ds);
1238 if (err) {
1239 dev_err(&pdev->dev, "Failed to register DSA switch: %d\n", err);
1240 goto err_register_ds;
1241 }
1242
1243 return 0;
1244
1245err_register_ds:
1246 kfree(ds);
1247err_alloc_ds:
1248err_alloc_felix:
1249 kfree(felix);
1250 return err;
1251}
1252
1253static int seville_remove(struct platform_device *pdev)
1254{
Vladimir Oltean0650bf52021-09-17 16:34:33 +03001255 struct felix *felix = platform_get_drvdata(pdev);
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001256
Vladimir Oltean0650bf52021-09-17 16:34:33 +03001257 if (!felix)
1258 return 0;
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001259
1260 dsa_unregister_switch(felix->ds);
1261
1262 kfree(felix->ds);
1263 kfree(felix);
1264
Vladimir Oltean0650bf52021-09-17 16:34:33 +03001265 platform_set_drvdata(pdev, NULL);
1266
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001267 return 0;
1268}
1269
Vladimir Oltean0650bf52021-09-17 16:34:33 +03001270static void seville_shutdown(struct platform_device *pdev)
1271{
1272 struct felix *felix = platform_get_drvdata(pdev);
1273
1274 if (!felix)
1275 return;
1276
1277 dsa_switch_shutdown(felix->ds);
1278
1279 platform_set_drvdata(pdev, NULL);
1280}
1281
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001282static const struct of_device_id seville_of_match[] = {
1283 { .compatible = "mscc,vsc9953-switch" },
1284 { },
1285};
1286MODULE_DEVICE_TABLE(of, seville_of_match);
1287
Vladimir Olteand60bc622020-09-18 13:57:53 +03001288static struct platform_driver seville_vsc9953_driver = {
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001289 .probe = seville_probe,
1290 .remove = seville_remove,
Vladimir Oltean0650bf52021-09-17 16:34:33 +03001291 .shutdown = seville_shutdown,
Maxim Kochetkov84705fc2020-07-13 19:57:10 +03001292 .driver = {
1293 .name = "mscc_seville",
1294 .of_match_table = of_match_ptr(seville_of_match),
1295 },
1296};
Vladimir Olteand60bc622020-09-18 13:57:53 +03001297module_platform_driver(seville_vsc9953_driver);
1298
1299MODULE_DESCRIPTION("Seville Switch driver");
1300MODULE_LICENSE("GPL v2");