xref: /openbmc/linux/include/soc/mscc/ocelot.h (revision 400928bf)
15e256365SVladimir Oltean /* SPDX-License-Identifier: (GPL-2.0 OR MIT) */
25e256365SVladimir Oltean /* Copyright (c) 2017 Microsemi Corporation
35e256365SVladimir Oltean  */
45e256365SVladimir Oltean 
55e256365SVladimir Oltean #ifndef _SOC_MSCC_OCELOT_H
65e256365SVladimir Oltean #define _SOC_MSCC_OCELOT_H
75e256365SVladimir Oltean 
85e256365SVladimir Oltean #include <linux/ptp_clock_kernel.h>
95e256365SVladimir Oltean #include <linux/net_tstamp.h>
105e256365SVladimir Oltean #include <linux/if_vlan.h>
115e256365SVladimir Oltean #include <linux/regmap.h>
125e256365SVladimir Oltean #include <net/dsa.h>
135e256365SVladimir Oltean 
145e256365SVladimir Oltean #define IFH_INJ_BYPASS			BIT(31)
155e256365SVladimir Oltean #define IFH_INJ_POP_CNT_DISABLE		(3 << 28)
165e256365SVladimir Oltean 
175e256365SVladimir Oltean #define IFH_TAG_TYPE_C			0
185e256365SVladimir Oltean #define IFH_TAG_TYPE_S			1
195e256365SVladimir Oltean 
205e256365SVladimir Oltean #define IFH_REW_OP_NOOP			0x0
215e256365SVladimir Oltean #define IFH_REW_OP_DSCP			0x1
225e256365SVladimir Oltean #define IFH_REW_OP_ONE_STEP_PTP		0x2
235e256365SVladimir Oltean #define IFH_REW_OP_TWO_STEP_PTP		0x3
245e256365SVladimir Oltean #define IFH_REW_OP_ORIGIN_PTP		0x5
255e256365SVladimir Oltean 
265e256365SVladimir Oltean #define OCELOT_TAG_LEN			16
275e256365SVladimir Oltean #define OCELOT_SHORT_PREFIX_LEN		4
285e256365SVladimir Oltean #define OCELOT_LONG_PREFIX_LEN		16
295e256365SVladimir Oltean 
305e256365SVladimir Oltean #define OCELOT_SPEED_2500		0
315e256365SVladimir Oltean #define OCELOT_SPEED_1000		1
325e256365SVladimir Oltean #define OCELOT_SPEED_100		2
335e256365SVladimir Oltean #define OCELOT_SPEED_10			3
345e256365SVladimir Oltean 
355e256365SVladimir Oltean #define TARGET_OFFSET			24
365e256365SVladimir Oltean #define REG_MASK			GENMASK(TARGET_OFFSET - 1, 0)
375e256365SVladimir Oltean #define REG(reg, offset)		[reg & REG_MASK] = offset
385e256365SVladimir Oltean 
395e256365SVladimir Oltean #define REG_RESERVED_ADDR		0xffffffff
405e256365SVladimir Oltean #define REG_RESERVED(reg)		REG(reg, REG_RESERVED_ADDR)
415e256365SVladimir Oltean 
425e256365SVladimir Oltean enum ocelot_target {
435e256365SVladimir Oltean 	ANA = 1,
445e256365SVladimir Oltean 	QS,
455e256365SVladimir Oltean 	QSYS,
465e256365SVladimir Oltean 	REW,
475e256365SVladimir Oltean 	SYS,
485e256365SVladimir Oltean 	S2,
495e256365SVladimir Oltean 	HSIO,
505e256365SVladimir Oltean 	PTP,
515e256365SVladimir Oltean 	GCB,
525e256365SVladimir Oltean 	TARGET_MAX,
535e256365SVladimir Oltean };
545e256365SVladimir Oltean 
555e256365SVladimir Oltean enum ocelot_reg {
565e256365SVladimir Oltean 	ANA_ADVLEARN = ANA << TARGET_OFFSET,
575e256365SVladimir Oltean 	ANA_VLANMASK,
585e256365SVladimir Oltean 	ANA_PORT_B_DOMAIN,
595e256365SVladimir Oltean 	ANA_ANAGEFIL,
605e256365SVladimir Oltean 	ANA_ANEVENTS,
615e256365SVladimir Oltean 	ANA_STORMLIMIT_BURST,
625e256365SVladimir Oltean 	ANA_STORMLIMIT_CFG,
635e256365SVladimir Oltean 	ANA_ISOLATED_PORTS,
645e256365SVladimir Oltean 	ANA_COMMUNITY_PORTS,
655e256365SVladimir Oltean 	ANA_AUTOAGE,
665e256365SVladimir Oltean 	ANA_MACTOPTIONS,
675e256365SVladimir Oltean 	ANA_LEARNDISC,
685e256365SVladimir Oltean 	ANA_AGENCTRL,
695e256365SVladimir Oltean 	ANA_MIRRORPORTS,
705e256365SVladimir Oltean 	ANA_EMIRRORPORTS,
715e256365SVladimir Oltean 	ANA_FLOODING,
725e256365SVladimir Oltean 	ANA_FLOODING_IPMC,
735e256365SVladimir Oltean 	ANA_SFLOW_CFG,
745e256365SVladimir Oltean 	ANA_PORT_MODE,
755e256365SVladimir Oltean 	ANA_CUT_THRU_CFG,
765e256365SVladimir Oltean 	ANA_PGID_PGID,
775e256365SVladimir Oltean 	ANA_TABLES_ANMOVED,
785e256365SVladimir Oltean 	ANA_TABLES_MACHDATA,
795e256365SVladimir Oltean 	ANA_TABLES_MACLDATA,
805e256365SVladimir Oltean 	ANA_TABLES_STREAMDATA,
815e256365SVladimir Oltean 	ANA_TABLES_MACACCESS,
825e256365SVladimir Oltean 	ANA_TABLES_MACTINDX,
835e256365SVladimir Oltean 	ANA_TABLES_VLANACCESS,
845e256365SVladimir Oltean 	ANA_TABLES_VLANTIDX,
855e256365SVladimir Oltean 	ANA_TABLES_ISDXACCESS,
865e256365SVladimir Oltean 	ANA_TABLES_ISDXTIDX,
875e256365SVladimir Oltean 	ANA_TABLES_ENTRYLIM,
885e256365SVladimir Oltean 	ANA_TABLES_PTP_ID_HIGH,
895e256365SVladimir Oltean 	ANA_TABLES_PTP_ID_LOW,
905e256365SVladimir Oltean 	ANA_TABLES_STREAMACCESS,
915e256365SVladimir Oltean 	ANA_TABLES_STREAMTIDX,
925e256365SVladimir Oltean 	ANA_TABLES_SEQ_HISTORY,
935e256365SVladimir Oltean 	ANA_TABLES_SEQ_MASK,
945e256365SVladimir Oltean 	ANA_TABLES_SFID_MASK,
955e256365SVladimir Oltean 	ANA_TABLES_SFIDACCESS,
965e256365SVladimir Oltean 	ANA_TABLES_SFIDTIDX,
975e256365SVladimir Oltean 	ANA_MSTI_STATE,
985e256365SVladimir Oltean 	ANA_OAM_UPM_LM_CNT,
995e256365SVladimir Oltean 	ANA_SG_ACCESS_CTRL,
1005e256365SVladimir Oltean 	ANA_SG_CONFIG_REG_1,
1015e256365SVladimir Oltean 	ANA_SG_CONFIG_REG_2,
1025e256365SVladimir Oltean 	ANA_SG_CONFIG_REG_3,
1035e256365SVladimir Oltean 	ANA_SG_CONFIG_REG_4,
1045e256365SVladimir Oltean 	ANA_SG_CONFIG_REG_5,
1055e256365SVladimir Oltean 	ANA_SG_GCL_GS_CONFIG,
1065e256365SVladimir Oltean 	ANA_SG_GCL_TI_CONFIG,
1075e256365SVladimir Oltean 	ANA_SG_STATUS_REG_1,
1085e256365SVladimir Oltean 	ANA_SG_STATUS_REG_2,
1095e256365SVladimir Oltean 	ANA_SG_STATUS_REG_3,
1105e256365SVladimir Oltean 	ANA_PORT_VLAN_CFG,
1115e256365SVladimir Oltean 	ANA_PORT_DROP_CFG,
1125e256365SVladimir Oltean 	ANA_PORT_QOS_CFG,
1135e256365SVladimir Oltean 	ANA_PORT_VCAP_CFG,
1145e256365SVladimir Oltean 	ANA_PORT_VCAP_S1_KEY_CFG,
1155e256365SVladimir Oltean 	ANA_PORT_VCAP_S2_CFG,
1165e256365SVladimir Oltean 	ANA_PORT_PCP_DEI_MAP,
1175e256365SVladimir Oltean 	ANA_PORT_CPU_FWD_CFG,
1185e256365SVladimir Oltean 	ANA_PORT_CPU_FWD_BPDU_CFG,
1195e256365SVladimir Oltean 	ANA_PORT_CPU_FWD_GARP_CFG,
1205e256365SVladimir Oltean 	ANA_PORT_CPU_FWD_CCM_CFG,
1215e256365SVladimir Oltean 	ANA_PORT_PORT_CFG,
1225e256365SVladimir Oltean 	ANA_PORT_POL_CFG,
1235e256365SVladimir Oltean 	ANA_PORT_PTP_CFG,
1245e256365SVladimir Oltean 	ANA_PORT_PTP_DLY1_CFG,
1255e256365SVladimir Oltean 	ANA_PORT_PTP_DLY2_CFG,
1265e256365SVladimir Oltean 	ANA_PORT_SFID_CFG,
1275e256365SVladimir Oltean 	ANA_PFC_PFC_CFG,
1285e256365SVladimir Oltean 	ANA_PFC_PFC_TIMER,
1295e256365SVladimir Oltean 	ANA_IPT_OAM_MEP_CFG,
1305e256365SVladimir Oltean 	ANA_IPT_IPT,
1315e256365SVladimir Oltean 	ANA_PPT_PPT,
1325e256365SVladimir Oltean 	ANA_FID_MAP_FID_MAP,
1335e256365SVladimir Oltean 	ANA_AGGR_CFG,
1345e256365SVladimir Oltean 	ANA_CPUQ_CFG,
1355e256365SVladimir Oltean 	ANA_CPUQ_CFG2,
1365e256365SVladimir Oltean 	ANA_CPUQ_8021_CFG,
1375e256365SVladimir Oltean 	ANA_DSCP_CFG,
1385e256365SVladimir Oltean 	ANA_DSCP_REWR_CFG,
1395e256365SVladimir Oltean 	ANA_VCAP_RNG_TYPE_CFG,
1405e256365SVladimir Oltean 	ANA_VCAP_RNG_VAL_CFG,
1415e256365SVladimir Oltean 	ANA_VRAP_CFG,
1425e256365SVladimir Oltean 	ANA_VRAP_HDR_DATA,
1435e256365SVladimir Oltean 	ANA_VRAP_HDR_MASK,
1445e256365SVladimir Oltean 	ANA_DISCARD_CFG,
1455e256365SVladimir Oltean 	ANA_FID_CFG,
1465e256365SVladimir Oltean 	ANA_POL_PIR_CFG,
1475e256365SVladimir Oltean 	ANA_POL_CIR_CFG,
1485e256365SVladimir Oltean 	ANA_POL_MODE_CFG,
1495e256365SVladimir Oltean 	ANA_POL_PIR_STATE,
1505e256365SVladimir Oltean 	ANA_POL_CIR_STATE,
1515e256365SVladimir Oltean 	ANA_POL_STATE,
1525e256365SVladimir Oltean 	ANA_POL_FLOWC,
1535e256365SVladimir Oltean 	ANA_POL_HYST,
1545e256365SVladimir Oltean 	ANA_POL_MISC_CFG,
1555e256365SVladimir Oltean 	QS_XTR_GRP_CFG = QS << TARGET_OFFSET,
1565e256365SVladimir Oltean 	QS_XTR_RD,
1575e256365SVladimir Oltean 	QS_XTR_FRM_PRUNING,
1585e256365SVladimir Oltean 	QS_XTR_FLUSH,
1595e256365SVladimir Oltean 	QS_XTR_DATA_PRESENT,
1605e256365SVladimir Oltean 	QS_XTR_CFG,
1615e256365SVladimir Oltean 	QS_INJ_GRP_CFG,
1625e256365SVladimir Oltean 	QS_INJ_WR,
1635e256365SVladimir Oltean 	QS_INJ_CTRL,
1645e256365SVladimir Oltean 	QS_INJ_STATUS,
1655e256365SVladimir Oltean 	QS_INJ_ERR,
1665e256365SVladimir Oltean 	QS_INH_DBG,
1675e256365SVladimir Oltean 	QSYS_PORT_MODE = QSYS << TARGET_OFFSET,
1685e256365SVladimir Oltean 	QSYS_SWITCH_PORT_MODE,
1695e256365SVladimir Oltean 	QSYS_STAT_CNT_CFG,
1705e256365SVladimir Oltean 	QSYS_EEE_CFG,
1715e256365SVladimir Oltean 	QSYS_EEE_THRES,
1725e256365SVladimir Oltean 	QSYS_IGR_NO_SHARING,
1735e256365SVladimir Oltean 	QSYS_EGR_NO_SHARING,
1745e256365SVladimir Oltean 	QSYS_SW_STATUS,
1755e256365SVladimir Oltean 	QSYS_EXT_CPU_CFG,
1765e256365SVladimir Oltean 	QSYS_PAD_CFG,
1775e256365SVladimir Oltean 	QSYS_CPU_GROUP_MAP,
1785e256365SVladimir Oltean 	QSYS_QMAP,
1795e256365SVladimir Oltean 	QSYS_ISDX_SGRP,
1805e256365SVladimir Oltean 	QSYS_TIMED_FRAME_ENTRY,
1815e256365SVladimir Oltean 	QSYS_TFRM_MISC,
1825e256365SVladimir Oltean 	QSYS_TFRM_PORT_DLY,
1835e256365SVladimir Oltean 	QSYS_TFRM_TIMER_CFG_1,
1845e256365SVladimir Oltean 	QSYS_TFRM_TIMER_CFG_2,
1855e256365SVladimir Oltean 	QSYS_TFRM_TIMER_CFG_3,
1865e256365SVladimir Oltean 	QSYS_TFRM_TIMER_CFG_4,
1875e256365SVladimir Oltean 	QSYS_TFRM_TIMER_CFG_5,
1885e256365SVladimir Oltean 	QSYS_TFRM_TIMER_CFG_6,
1895e256365SVladimir Oltean 	QSYS_TFRM_TIMER_CFG_7,
1905e256365SVladimir Oltean 	QSYS_TFRM_TIMER_CFG_8,
1915e256365SVladimir Oltean 	QSYS_RED_PROFILE,
1925e256365SVladimir Oltean 	QSYS_RES_QOS_MODE,
1935e256365SVladimir Oltean 	QSYS_RES_CFG,
1945e256365SVladimir Oltean 	QSYS_RES_STAT,
1955e256365SVladimir Oltean 	QSYS_EGR_DROP_MODE,
1965e256365SVladimir Oltean 	QSYS_EQ_CTRL,
1975e256365SVladimir Oltean 	QSYS_EVENTS_CORE,
1985e256365SVladimir Oltean 	QSYS_QMAXSDU_CFG_0,
1995e256365SVladimir Oltean 	QSYS_QMAXSDU_CFG_1,
2005e256365SVladimir Oltean 	QSYS_QMAXSDU_CFG_2,
2015e256365SVladimir Oltean 	QSYS_QMAXSDU_CFG_3,
2025e256365SVladimir Oltean 	QSYS_QMAXSDU_CFG_4,
2035e256365SVladimir Oltean 	QSYS_QMAXSDU_CFG_5,
2045e256365SVladimir Oltean 	QSYS_QMAXSDU_CFG_6,
2055e256365SVladimir Oltean 	QSYS_QMAXSDU_CFG_7,
2065e256365SVladimir Oltean 	QSYS_PREEMPTION_CFG,
2075e256365SVladimir Oltean 	QSYS_CIR_CFG,
2085e256365SVladimir Oltean 	QSYS_EIR_CFG,
2095e256365SVladimir Oltean 	QSYS_SE_CFG,
2105e256365SVladimir Oltean 	QSYS_SE_DWRR_CFG,
2115e256365SVladimir Oltean 	QSYS_SE_CONNECT,
2125e256365SVladimir Oltean 	QSYS_SE_DLB_SENSE,
2135e256365SVladimir Oltean 	QSYS_CIR_STATE,
2145e256365SVladimir Oltean 	QSYS_EIR_STATE,
2155e256365SVladimir Oltean 	QSYS_SE_STATE,
2165e256365SVladimir Oltean 	QSYS_HSCH_MISC_CFG,
2175e256365SVladimir Oltean 	QSYS_TAG_CONFIG,
2185e256365SVladimir Oltean 	QSYS_TAS_PARAM_CFG_CTRL,
2195e256365SVladimir Oltean 	QSYS_PORT_MAX_SDU,
2205e256365SVladimir Oltean 	QSYS_PARAM_CFG_REG_1,
2215e256365SVladimir Oltean 	QSYS_PARAM_CFG_REG_2,
2225e256365SVladimir Oltean 	QSYS_PARAM_CFG_REG_3,
2235e256365SVladimir Oltean 	QSYS_PARAM_CFG_REG_4,
2245e256365SVladimir Oltean 	QSYS_PARAM_CFG_REG_5,
2255e256365SVladimir Oltean 	QSYS_GCL_CFG_REG_1,
2265e256365SVladimir Oltean 	QSYS_GCL_CFG_REG_2,
2275e256365SVladimir Oltean 	QSYS_PARAM_STATUS_REG_1,
2285e256365SVladimir Oltean 	QSYS_PARAM_STATUS_REG_2,
2295e256365SVladimir Oltean 	QSYS_PARAM_STATUS_REG_3,
2305e256365SVladimir Oltean 	QSYS_PARAM_STATUS_REG_4,
2315e256365SVladimir Oltean 	QSYS_PARAM_STATUS_REG_5,
2325e256365SVladimir Oltean 	QSYS_PARAM_STATUS_REG_6,
2335e256365SVladimir Oltean 	QSYS_PARAM_STATUS_REG_7,
2345e256365SVladimir Oltean 	QSYS_PARAM_STATUS_REG_8,
2355e256365SVladimir Oltean 	QSYS_PARAM_STATUS_REG_9,
2365e256365SVladimir Oltean 	QSYS_GCL_STATUS_REG_1,
2375e256365SVladimir Oltean 	QSYS_GCL_STATUS_REG_2,
2385e256365SVladimir Oltean 	REW_PORT_VLAN_CFG = REW << TARGET_OFFSET,
2395e256365SVladimir Oltean 	REW_TAG_CFG,
2405e256365SVladimir Oltean 	REW_PORT_CFG,
2415e256365SVladimir Oltean 	REW_DSCP_CFG,
2425e256365SVladimir Oltean 	REW_PCP_DEI_QOS_MAP_CFG,
2435e256365SVladimir Oltean 	REW_PTP_CFG,
2445e256365SVladimir Oltean 	REW_PTP_DLY1_CFG,
2455e256365SVladimir Oltean 	REW_RED_TAG_CFG,
2465e256365SVladimir Oltean 	REW_DSCP_REMAP_DP1_CFG,
2475e256365SVladimir Oltean 	REW_DSCP_REMAP_CFG,
2485e256365SVladimir Oltean 	REW_STAT_CFG,
2495e256365SVladimir Oltean 	REW_REW_STICKY,
2505e256365SVladimir Oltean 	REW_PPT,
2515e256365SVladimir Oltean 	SYS_COUNT_RX_OCTETS = SYS << TARGET_OFFSET,
2525e256365SVladimir Oltean 	SYS_COUNT_RX_UNICAST,
2535e256365SVladimir Oltean 	SYS_COUNT_RX_MULTICAST,
2545e256365SVladimir Oltean 	SYS_COUNT_RX_BROADCAST,
2555e256365SVladimir Oltean 	SYS_COUNT_RX_SHORTS,
2565e256365SVladimir Oltean 	SYS_COUNT_RX_FRAGMENTS,
2575e256365SVladimir Oltean 	SYS_COUNT_RX_JABBERS,
2585e256365SVladimir Oltean 	SYS_COUNT_RX_CRC_ALIGN_ERRS,
2595e256365SVladimir Oltean 	SYS_COUNT_RX_SYM_ERRS,
2605e256365SVladimir Oltean 	SYS_COUNT_RX_64,
2615e256365SVladimir Oltean 	SYS_COUNT_RX_65_127,
2625e256365SVladimir Oltean 	SYS_COUNT_RX_128_255,
2635e256365SVladimir Oltean 	SYS_COUNT_RX_256_1023,
2645e256365SVladimir Oltean 	SYS_COUNT_RX_1024_1526,
2655e256365SVladimir Oltean 	SYS_COUNT_RX_1527_MAX,
2665e256365SVladimir Oltean 	SYS_COUNT_RX_PAUSE,
2675e256365SVladimir Oltean 	SYS_COUNT_RX_CONTROL,
2685e256365SVladimir Oltean 	SYS_COUNT_RX_LONGS,
2695e256365SVladimir Oltean 	SYS_COUNT_RX_CLASSIFIED_DROPS,
2705e256365SVladimir Oltean 	SYS_COUNT_TX_OCTETS,
2715e256365SVladimir Oltean 	SYS_COUNT_TX_UNICAST,
2725e256365SVladimir Oltean 	SYS_COUNT_TX_MULTICAST,
2735e256365SVladimir Oltean 	SYS_COUNT_TX_BROADCAST,
2745e256365SVladimir Oltean 	SYS_COUNT_TX_COLLISION,
2755e256365SVladimir Oltean 	SYS_COUNT_TX_DROPS,
2765e256365SVladimir Oltean 	SYS_COUNT_TX_PAUSE,
2775e256365SVladimir Oltean 	SYS_COUNT_TX_64,
2785e256365SVladimir Oltean 	SYS_COUNT_TX_65_127,
2795e256365SVladimir Oltean 	SYS_COUNT_TX_128_511,
2805e256365SVladimir Oltean 	SYS_COUNT_TX_512_1023,
2815e256365SVladimir Oltean 	SYS_COUNT_TX_1024_1526,
2825e256365SVladimir Oltean 	SYS_COUNT_TX_1527_MAX,
2835e256365SVladimir Oltean 	SYS_COUNT_TX_AGING,
2845e256365SVladimir Oltean 	SYS_RESET_CFG,
2855e256365SVladimir Oltean 	SYS_SR_ETYPE_CFG,
2865e256365SVladimir Oltean 	SYS_VLAN_ETYPE_CFG,
2875e256365SVladimir Oltean 	SYS_PORT_MODE,
2885e256365SVladimir Oltean 	SYS_FRONT_PORT_MODE,
2895e256365SVladimir Oltean 	SYS_FRM_AGING,
2905e256365SVladimir Oltean 	SYS_STAT_CFG,
2915e256365SVladimir Oltean 	SYS_SW_STATUS,
2925e256365SVladimir Oltean 	SYS_MISC_CFG,
2935e256365SVladimir Oltean 	SYS_REW_MAC_HIGH_CFG,
2945e256365SVladimir Oltean 	SYS_REW_MAC_LOW_CFG,
2955e256365SVladimir Oltean 	SYS_TIMESTAMP_OFFSET,
2965e256365SVladimir Oltean 	SYS_CMID,
2975e256365SVladimir Oltean 	SYS_PAUSE_CFG,
2985e256365SVladimir Oltean 	SYS_PAUSE_TOT_CFG,
2995e256365SVladimir Oltean 	SYS_ATOP,
3005e256365SVladimir Oltean 	SYS_ATOP_TOT_CFG,
3015e256365SVladimir Oltean 	SYS_MAC_FC_CFG,
3025e256365SVladimir Oltean 	SYS_MMGT,
3035e256365SVladimir Oltean 	SYS_MMGT_FAST,
3045e256365SVladimir Oltean 	SYS_EVENTS_DIF,
3055e256365SVladimir Oltean 	SYS_EVENTS_CORE,
3065e256365SVladimir Oltean 	SYS_CNT,
3075e256365SVladimir Oltean 	SYS_PTP_STATUS,
3085e256365SVladimir Oltean 	SYS_PTP_TXSTAMP,
3095e256365SVladimir Oltean 	SYS_PTP_NXT,
3105e256365SVladimir Oltean 	SYS_PTP_CFG,
3115e256365SVladimir Oltean 	SYS_RAM_INIT,
3125e256365SVladimir Oltean 	SYS_CM_ADDR,
3135e256365SVladimir Oltean 	SYS_CM_DATA_WR,
3145e256365SVladimir Oltean 	SYS_CM_DATA_RD,
3155e256365SVladimir Oltean 	SYS_CM_OP,
3165e256365SVladimir Oltean 	SYS_CM_DATA,
3175e256365SVladimir Oltean 	S2_CORE_UPDATE_CTRL = S2 << TARGET_OFFSET,
3185e256365SVladimir Oltean 	S2_CORE_MV_CFG,
3195e256365SVladimir Oltean 	S2_CACHE_ENTRY_DAT,
3205e256365SVladimir Oltean 	S2_CACHE_MASK_DAT,
3215e256365SVladimir Oltean 	S2_CACHE_ACTION_DAT,
3225e256365SVladimir Oltean 	S2_CACHE_CNT_DAT,
3235e256365SVladimir Oltean 	S2_CACHE_TG_DAT,
3245e256365SVladimir Oltean 	PTP_PIN_CFG = PTP << TARGET_OFFSET,
3255e256365SVladimir Oltean 	PTP_PIN_TOD_SEC_MSB,
3265e256365SVladimir Oltean 	PTP_PIN_TOD_SEC_LSB,
3275e256365SVladimir Oltean 	PTP_PIN_TOD_NSEC,
3285e256365SVladimir Oltean 	PTP_CFG_MISC,
3295e256365SVladimir Oltean 	PTP_CLK_CFG_ADJ_CFG,
3305e256365SVladimir Oltean 	PTP_CLK_CFG_ADJ_FREQ,
3315e256365SVladimir Oltean 	GCB_SOFT_RST = GCB << TARGET_OFFSET,
3325e256365SVladimir Oltean };
3335e256365SVladimir Oltean 
3345e256365SVladimir Oltean enum ocelot_regfield {
3355e256365SVladimir Oltean 	ANA_ADVLEARN_VLAN_CHK,
3365e256365SVladimir Oltean 	ANA_ADVLEARN_LEARN_MIRROR,
3375e256365SVladimir Oltean 	ANA_ANEVENTS_FLOOD_DISCARD,
3385e256365SVladimir Oltean 	ANA_ANEVENTS_MSTI_DROP,
3395e256365SVladimir Oltean 	ANA_ANEVENTS_ACLKILL,
3405e256365SVladimir Oltean 	ANA_ANEVENTS_ACLUSED,
3415e256365SVladimir Oltean 	ANA_ANEVENTS_AUTOAGE,
3425e256365SVladimir Oltean 	ANA_ANEVENTS_VS2TTL1,
3435e256365SVladimir Oltean 	ANA_ANEVENTS_STORM_DROP,
3445e256365SVladimir Oltean 	ANA_ANEVENTS_LEARN_DROP,
3455e256365SVladimir Oltean 	ANA_ANEVENTS_AGED_ENTRY,
3465e256365SVladimir Oltean 	ANA_ANEVENTS_CPU_LEARN_FAILED,
3475e256365SVladimir Oltean 	ANA_ANEVENTS_AUTO_LEARN_FAILED,
3485e256365SVladimir Oltean 	ANA_ANEVENTS_LEARN_REMOVE,
3495e256365SVladimir Oltean 	ANA_ANEVENTS_AUTO_LEARNED,
3505e256365SVladimir Oltean 	ANA_ANEVENTS_AUTO_MOVED,
3515e256365SVladimir Oltean 	ANA_ANEVENTS_DROPPED,
3525e256365SVladimir Oltean 	ANA_ANEVENTS_CLASSIFIED_DROP,
3535e256365SVladimir Oltean 	ANA_ANEVENTS_CLASSIFIED_COPY,
3545e256365SVladimir Oltean 	ANA_ANEVENTS_VLAN_DISCARD,
3555e256365SVladimir Oltean 	ANA_ANEVENTS_FWD_DISCARD,
3565e256365SVladimir Oltean 	ANA_ANEVENTS_MULTICAST_FLOOD,
3575e256365SVladimir Oltean 	ANA_ANEVENTS_UNICAST_FLOOD,
3585e256365SVladimir Oltean 	ANA_ANEVENTS_DEST_KNOWN,
3595e256365SVladimir Oltean 	ANA_ANEVENTS_BUCKET3_MATCH,
3605e256365SVladimir Oltean 	ANA_ANEVENTS_BUCKET2_MATCH,
3615e256365SVladimir Oltean 	ANA_ANEVENTS_BUCKET1_MATCH,
3625e256365SVladimir Oltean 	ANA_ANEVENTS_BUCKET0_MATCH,
3635e256365SVladimir Oltean 	ANA_ANEVENTS_CPU_OPERATION,
3645e256365SVladimir Oltean 	ANA_ANEVENTS_DMAC_LOOKUP,
3655e256365SVladimir Oltean 	ANA_ANEVENTS_SMAC_LOOKUP,
3665e256365SVladimir Oltean 	ANA_ANEVENTS_SEQ_GEN_ERR_0,
3675e256365SVladimir Oltean 	ANA_ANEVENTS_SEQ_GEN_ERR_1,
3685e256365SVladimir Oltean 	ANA_TABLES_MACACCESS_B_DOM,
3695e256365SVladimir Oltean 	ANA_TABLES_MACTINDX_BUCKET,
3705e256365SVladimir Oltean 	ANA_TABLES_MACTINDX_M_INDEX,
3715e256365SVladimir Oltean 	QSYS_TIMED_FRAME_ENTRY_TFRM_VLD,
3725e256365SVladimir Oltean 	QSYS_TIMED_FRAME_ENTRY_TFRM_FP,
3735e256365SVladimir Oltean 	QSYS_TIMED_FRAME_ENTRY_TFRM_PORTNO,
3745e256365SVladimir Oltean 	QSYS_TIMED_FRAME_ENTRY_TFRM_TM_SEL,
3755e256365SVladimir Oltean 	QSYS_TIMED_FRAME_ENTRY_TFRM_TM_T,
3765e256365SVladimir Oltean 	SYS_RESET_CFG_CORE_ENA,
3775e256365SVladimir Oltean 	SYS_RESET_CFG_MEM_ENA,
3785e256365SVladimir Oltean 	SYS_RESET_CFG_MEM_INIT,
3795e256365SVladimir Oltean 	GCB_SOFT_RST_SWC_RST,
3805e256365SVladimir Oltean 	REGFIELD_MAX
3815e256365SVladimir Oltean };
3825e256365SVladimir Oltean 
3835e256365SVladimir Oltean enum ocelot_clk_pins {
3845e256365SVladimir Oltean 	ALT_PPS_PIN	= 1,
3855e256365SVladimir Oltean 	EXT_CLK_PIN,
3865e256365SVladimir Oltean 	ALT_LDST_PIN,
3875e256365SVladimir Oltean 	TOD_ACC_PIN
3885e256365SVladimir Oltean };
3895e256365SVladimir Oltean 
3905e256365SVladimir Oltean struct ocelot_stat_layout {
3915e256365SVladimir Oltean 	u32 offset;
3925e256365SVladimir Oltean 	char name[ETH_GSTRING_LEN];
3935e256365SVladimir Oltean };
3945e256365SVladimir Oltean 
3955e256365SVladimir Oltean enum ocelot_tag_prefix {
3965e256365SVladimir Oltean 	OCELOT_TAG_PREFIX_DISABLED	= 0,
3975e256365SVladimir Oltean 	OCELOT_TAG_PREFIX_NONE,
3985e256365SVladimir Oltean 	OCELOT_TAG_PREFIX_SHORT,
3995e256365SVladimir Oltean 	OCELOT_TAG_PREFIX_LONG,
4005e256365SVladimir Oltean };
4015e256365SVladimir Oltean 
4025e256365SVladimir Oltean struct ocelot;
4035e256365SVladimir Oltean 
4045e256365SVladimir Oltean struct ocelot_ops {
4055e256365SVladimir Oltean 	void (*pcs_init)(struct ocelot *ocelot, int port);
4065e256365SVladimir Oltean 	int (*reset)(struct ocelot *ocelot);
4075e256365SVladimir Oltean };
4085e256365SVladimir Oltean 
409e23a7b3eSYangbo Lu struct ocelot_skb {
410e23a7b3eSYangbo Lu 	struct list_head head;
411e23a7b3eSYangbo Lu 	struct sk_buff *skb;
412e23a7b3eSYangbo Lu 	u8 id;
413e23a7b3eSYangbo Lu };
414e23a7b3eSYangbo Lu 
415e23a7b3eSYangbo Lu 
4165e256365SVladimir Oltean struct ocelot_port {
4175e256365SVladimir Oltean 	struct ocelot			*ocelot;
4185e256365SVladimir Oltean 
4195e256365SVladimir Oltean 	void __iomem			*regs;
4205e256365SVladimir Oltean 
4215e256365SVladimir Oltean 	/* Ingress default VLAN (pvid) */
4225e256365SVladimir Oltean 	u16				pvid;
4235e256365SVladimir Oltean 
4245e256365SVladimir Oltean 	/* Egress default VLAN (vid) */
4255e256365SVladimir Oltean 	u16				vid;
4265e256365SVladimir Oltean 
4275e256365SVladimir Oltean 	u8				ptp_cmd;
4285e256365SVladimir Oltean 	struct list_head		skbs;
4295e256365SVladimir Oltean 	u8				ts_id;
4305e256365SVladimir Oltean };
4315e256365SVladimir Oltean 
4325e256365SVladimir Oltean struct ocelot {
4335e256365SVladimir Oltean 	struct device			*dev;
4345e256365SVladimir Oltean 
4355e256365SVladimir Oltean 	const struct ocelot_ops		*ops;
4365e256365SVladimir Oltean 	struct regmap			*targets[TARGET_MAX];
4375e256365SVladimir Oltean 	struct regmap_field		*regfields[REGFIELD_MAX];
4385e256365SVladimir Oltean 	const u32 *const		*map;
4395e256365SVladimir Oltean 	const struct ocelot_stat_layout	*stats_layout;
4405e256365SVladimir Oltean 	unsigned int			num_stats;
4415e256365SVladimir Oltean 
4425e256365SVladimir Oltean 	int				shared_queue_sz;
4435e256365SVladimir Oltean 
4445e256365SVladimir Oltean 	struct net_device		*hw_bridge_dev;
4455e256365SVladimir Oltean 	u16				bridge_mask;
4465e256365SVladimir Oltean 	u16				bridge_fwd_mask;
4475e256365SVladimir Oltean 
4485e256365SVladimir Oltean 	struct ocelot_port		**ports;
4495e256365SVladimir Oltean 
4505e256365SVladimir Oltean 	u8				base_mac[ETH_ALEN];
4515e256365SVladimir Oltean 
4525e256365SVladimir Oltean 	/* Keep track of the vlan port masks */
4535e256365SVladimir Oltean 	u32				vlan_mask[VLAN_N_VID];
4545e256365SVladimir Oltean 
4555e256365SVladimir Oltean 	u8				num_phys_ports;
4565e256365SVladimir Oltean 	u8				num_cpu_ports;
4575e256365SVladimir Oltean 	u8				cpu;
4585e256365SVladimir Oltean 
4595e256365SVladimir Oltean 	u32				*lags;
4605e256365SVladimir Oltean 
4615e256365SVladimir Oltean 	struct list_head		multicast;
4625e256365SVladimir Oltean 
4635e256365SVladimir Oltean 	/* Workqueue to check statistics for overflow with its lock */
4645e256365SVladimir Oltean 	struct mutex			stats_lock;
4655e256365SVladimir Oltean 	u64				*stats;
4665e256365SVladimir Oltean 	struct delayed_work		stats_work;
4675e256365SVladimir Oltean 	struct workqueue_struct		*stats_queue;
4685e256365SVladimir Oltean 
4695e256365SVladimir Oltean 	u8				ptp:1;
4705e256365SVladimir Oltean 	struct ptp_clock		*ptp_clock;
4715e256365SVladimir Oltean 	struct ptp_clock_info		ptp_info;
4725e256365SVladimir Oltean 	struct hwtstamp_config		hwtstamp_config;
4735e256365SVladimir Oltean 	/* Protects the PTP interface state */
4745e256365SVladimir Oltean 	struct mutex			ptp_lock;
4755e256365SVladimir Oltean 	/* Protects the PTP clock */
4765e256365SVladimir Oltean 	spinlock_t			ptp_clock_lock;
4775e256365SVladimir Oltean 
4785e256365SVladimir Oltean 	void (*port_pcs_init)(struct ocelot_port *port);
4795e256365SVladimir Oltean };
4805e256365SVladimir Oltean 
4815e256365SVladimir Oltean #define ocelot_read_ix(ocelot, reg, gi, ri) __ocelot_read_ix(ocelot, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
4825e256365SVladimir Oltean #define ocelot_read_gix(ocelot, reg, gi) __ocelot_read_ix(ocelot, reg, reg##_GSZ * (gi))
4835e256365SVladimir Oltean #define ocelot_read_rix(ocelot, reg, ri) __ocelot_read_ix(ocelot, reg, reg##_RSZ * (ri))
4845e256365SVladimir Oltean #define ocelot_read(ocelot, reg) __ocelot_read_ix(ocelot, reg, 0)
4855e256365SVladimir Oltean 
4865e256365SVladimir Oltean #define ocelot_write_ix(ocelot, val, reg, gi, ri) __ocelot_write_ix(ocelot, val, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
4875e256365SVladimir Oltean #define ocelot_write_gix(ocelot, val, reg, gi) __ocelot_write_ix(ocelot, val, reg, reg##_GSZ * (gi))
4885e256365SVladimir Oltean #define ocelot_write_rix(ocelot, val, reg, ri) __ocelot_write_ix(ocelot, val, reg, reg##_RSZ * (ri))
4895e256365SVladimir Oltean #define ocelot_write(ocelot, val, reg) __ocelot_write_ix(ocelot, val, reg, 0)
4905e256365SVladimir Oltean 
4915e256365SVladimir Oltean #define ocelot_rmw_ix(ocelot, val, m, reg, gi, ri) __ocelot_rmw_ix(ocelot, val, m, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
4925e256365SVladimir Oltean #define ocelot_rmw_gix(ocelot, val, m, reg, gi) __ocelot_rmw_ix(ocelot, val, m, reg, reg##_GSZ * (gi))
4935e256365SVladimir Oltean #define ocelot_rmw_rix(ocelot, val, m, reg, ri) __ocelot_rmw_ix(ocelot, val, m, reg, reg##_RSZ * (ri))
4945e256365SVladimir Oltean #define ocelot_rmw(ocelot, val, m, reg) __ocelot_rmw_ix(ocelot, val, m, reg, 0)
4955e256365SVladimir Oltean 
4965e256365SVladimir Oltean /* I/O */
4975e256365SVladimir Oltean u32 ocelot_port_readl(struct ocelot_port *port, u32 reg);
4985e256365SVladimir Oltean void ocelot_port_writel(struct ocelot_port *port, u32 val, u32 reg);
4995e256365SVladimir Oltean u32 __ocelot_read_ix(struct ocelot *ocelot, u32 reg, u32 offset);
5005e256365SVladimir Oltean void __ocelot_write_ix(struct ocelot *ocelot, u32 val, u32 reg, u32 offset);
5015e256365SVladimir Oltean void __ocelot_rmw_ix(struct ocelot *ocelot, u32 val, u32 mask, u32 reg,
5025e256365SVladimir Oltean 		     u32 offset);
5035e256365SVladimir Oltean 
5045e256365SVladimir Oltean /* Hardware initialization */
5055e256365SVladimir Oltean int ocelot_regfields_init(struct ocelot *ocelot,
5065e256365SVladimir Oltean 			  const struct reg_field *const regfields);
5075e256365SVladimir Oltean struct regmap *ocelot_regmap_init(struct ocelot *ocelot, struct resource *res);
5085e256365SVladimir Oltean void ocelot_set_cpu_port(struct ocelot *ocelot, int cpu,
5095e256365SVladimir Oltean 			 enum ocelot_tag_prefix injection,
5105e256365SVladimir Oltean 			 enum ocelot_tag_prefix extraction);
5115e256365SVladimir Oltean int ocelot_init(struct ocelot *ocelot);
5125e256365SVladimir Oltean void ocelot_deinit(struct ocelot *ocelot);
5135e256365SVladimir Oltean void ocelot_init_port(struct ocelot *ocelot, int port);
5145e256365SVladimir Oltean 
5155e256365SVladimir Oltean /* DSA callbacks */
5165e256365SVladimir Oltean void ocelot_port_enable(struct ocelot *ocelot, int port,
5175e256365SVladimir Oltean 			struct phy_device *phy);
5185e256365SVladimir Oltean void ocelot_port_disable(struct ocelot *ocelot, int port);
5195e256365SVladimir Oltean void ocelot_get_strings(struct ocelot *ocelot, int port, u32 sset, u8 *data);
5205e256365SVladimir Oltean void ocelot_get_ethtool_stats(struct ocelot *ocelot, int port, u64 *data);
5215e256365SVladimir Oltean int ocelot_get_sset_count(struct ocelot *ocelot, int port, int sset);
5225e256365SVladimir Oltean int ocelot_get_ts_info(struct ocelot *ocelot, int port,
5235e256365SVladimir Oltean 		       struct ethtool_ts_info *info);
5245e256365SVladimir Oltean void ocelot_set_ageing_time(struct ocelot *ocelot, unsigned int msecs);
5255e256365SVladimir Oltean void ocelot_adjust_link(struct ocelot *ocelot, int port,
5265e256365SVladimir Oltean 			struct phy_device *phydev);
5275e256365SVladimir Oltean void ocelot_port_vlan_filtering(struct ocelot *ocelot, int port,
5285e256365SVladimir Oltean 				bool vlan_aware);
5295e256365SVladimir Oltean void ocelot_bridge_stp_state_set(struct ocelot *ocelot, int port, u8 state);
5305e256365SVladimir Oltean int ocelot_port_bridge_join(struct ocelot *ocelot, int port,
5315e256365SVladimir Oltean 			    struct net_device *bridge);
5325e256365SVladimir Oltean int ocelot_port_bridge_leave(struct ocelot *ocelot, int port,
5335e256365SVladimir Oltean 			     struct net_device *bridge);
5345e256365SVladimir Oltean int ocelot_fdb_dump(struct ocelot *ocelot, int port,
5355e256365SVladimir Oltean 		    dsa_fdb_dump_cb_t *cb, void *data);
5365e256365SVladimir Oltean int ocelot_fdb_add(struct ocelot *ocelot, int port,
5375e256365SVladimir Oltean 		   const unsigned char *addr, u16 vid, bool vlan_aware);
5385e256365SVladimir Oltean int ocelot_fdb_del(struct ocelot *ocelot, int port,
5395e256365SVladimir Oltean 		   const unsigned char *addr, u16 vid);
5405e256365SVladimir Oltean int ocelot_vlan_add(struct ocelot *ocelot, int port, u16 vid, bool pvid,
5415e256365SVladimir Oltean 		    bool untagged);
5425e256365SVladimir Oltean int ocelot_vlan_del(struct ocelot *ocelot, int port, u16 vid);
543f145922dSYangbo Lu int ocelot_hwstamp_get(struct ocelot *ocelot, int port, struct ifreq *ifr);
544f145922dSYangbo Lu int ocelot_hwstamp_set(struct ocelot *ocelot, int port, struct ifreq *ifr);
5455e256365SVladimir Oltean int ocelot_ptp_gettime64(struct ptp_clock_info *ptp, struct timespec64 *ts);
546*400928bfSYangbo Lu int ocelot_port_add_txtstamp_skb(struct ocelot_port *ocelot_port,
547*400928bfSYangbo Lu 				 struct sk_buff *skb);
548e23a7b3eSYangbo Lu void ocelot_get_txtstamp(struct ocelot *ocelot);
5495e256365SVladimir Oltean 
5505e256365SVladimir Oltean #endif
551