xref: /openbmc/linux/include/soc/mscc/ocelot.h (revision cacea62f)
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 
141cf3299bSVladimir Oltean /* Port Group IDs (PGID) are masks of destination ports.
151cf3299bSVladimir Oltean  *
161cf3299bSVladimir Oltean  * For L2 forwarding, the switch performs 3 lookups in the PGID table for each
171cf3299bSVladimir Oltean  * frame, and forwards the frame to the ports that are present in the logical
181cf3299bSVladimir Oltean  * AND of all 3 PGIDs.
191cf3299bSVladimir Oltean  *
201cf3299bSVladimir Oltean  * These PGID lookups are:
211cf3299bSVladimir Oltean  * - In one of PGID[0-63]: for the destination masks. There are 2 paths by
221cf3299bSVladimir Oltean  *   which the switch selects a destination PGID:
231cf3299bSVladimir Oltean  *     - The {DMAC, VID} is present in the MAC table. In that case, the
241cf3299bSVladimir Oltean  *       destination PGID is given by the DEST_IDX field of the MAC table entry
251cf3299bSVladimir Oltean  *       that matched.
261cf3299bSVladimir Oltean  *     - The {DMAC, VID} is not present in the MAC table (it is unknown). The
271cf3299bSVladimir Oltean  *       frame is disseminated as being either unicast, multicast or broadcast,
281cf3299bSVladimir Oltean  *       and according to that, the destination PGID is chosen as being the
291cf3299bSVladimir Oltean  *       value contained by ANA_FLOODING_FLD_UNICAST,
301cf3299bSVladimir Oltean  *       ANA_FLOODING_FLD_MULTICAST or ANA_FLOODING_FLD_BROADCAST.
311cf3299bSVladimir Oltean  *   The destination PGID can be an unicast set: the first PGIDs, 0 to
321cf3299bSVladimir Oltean  *   ocelot->num_phys_ports - 1, or a multicast set: the PGIDs from
331cf3299bSVladimir Oltean  *   ocelot->num_phys_ports to 63. By convention, a unicast PGID corresponds to
341cf3299bSVladimir Oltean  *   a physical port and has a single bit set in the destination ports mask:
351cf3299bSVladimir Oltean  *   that corresponding to the port number itself. In contrast, a multicast
361cf3299bSVladimir Oltean  *   PGID will have potentially more than one single bit set in the destination
371cf3299bSVladimir Oltean  *   ports mask.
381cf3299bSVladimir Oltean  * - In one of PGID[64-79]: for the aggregation mask. The switch classifier
391cf3299bSVladimir Oltean  *   dissects each frame and generates a 4-bit Link Aggregation Code which is
401cf3299bSVladimir Oltean  *   used for this second PGID table lookup. The goal of link aggregation is to
411cf3299bSVladimir Oltean  *   hash multiple flows within the same LAG on to different destination ports.
421cf3299bSVladimir Oltean  *   The first lookup will result in a PGID with all the LAG members present in
431cf3299bSVladimir Oltean  *   the destination ports mask, and the second lookup, by Link Aggregation
441cf3299bSVladimir Oltean  *   Code, will ensure that each flow gets forwarded only to a single port out
451cf3299bSVladimir Oltean  *   of that mask (there are no duplicates).
461cf3299bSVladimir Oltean  * - In one of PGID[80-90]: for the source mask. The third time, the PGID table
471cf3299bSVladimir Oltean  *   is indexed with the ingress port (plus 80). These PGIDs answer the
481cf3299bSVladimir Oltean  *   question "is port i allowed to forward traffic to port j?" If yes, then
491cf3299bSVladimir Oltean  *   BIT(j) of PGID 80+i will be found set. The third PGID lookup can be used
501cf3299bSVladimir Oltean  *   to enforce the L2 forwarding matrix imposed by e.g. a Linux bridge.
511cf3299bSVladimir Oltean  */
521cf3299bSVladimir Oltean 
531cf3299bSVladimir Oltean /* Reserve some destination PGIDs at the end of the range:
541cf3299bSVladimir Oltean  * PGID_CPU: used for whitelisting certain MAC addresses, such as the addresses
551cf3299bSVladimir Oltean  *           of the switch port net devices, towards the CPU port module.
561cf3299bSVladimir Oltean  * PGID_UC: the flooding destinations for unknown unicast traffic.
571cf3299bSVladimir Oltean  * PGID_MC: the flooding destinations for broadcast and non-IP multicast
581cf3299bSVladimir Oltean  *          traffic.
591cf3299bSVladimir Oltean  * PGID_MCIPV4: the flooding destinations for IPv4 multicast traffic.
601cf3299bSVladimir Oltean  * PGID_MCIPV6: the flooding destinations for IPv6 multicast traffic.
611cf3299bSVladimir Oltean  */
621cf3299bSVladimir Oltean #define PGID_CPU			59
631cf3299bSVladimir Oltean #define PGID_UC				60
641cf3299bSVladimir Oltean #define PGID_MC				61
651cf3299bSVladimir Oltean #define PGID_MCIPV4			62
661cf3299bSVladimir Oltean #define PGID_MCIPV6			63
671cf3299bSVladimir Oltean 
6896b029b0SVladimir Oltean #define for_each_unicast_dest_pgid(ocelot, pgid)		\
6996b029b0SVladimir Oltean 	for ((pgid) = 0;					\
7096b029b0SVladimir Oltean 	     (pgid) < (ocelot)->num_phys_ports;			\
7196b029b0SVladimir Oltean 	     (pgid)++)
7296b029b0SVladimir Oltean 
7396b029b0SVladimir Oltean #define for_each_nonreserved_multicast_dest_pgid(ocelot, pgid)	\
7496b029b0SVladimir Oltean 	for ((pgid) = (ocelot)->num_phys_ports + 1;		\
7596b029b0SVladimir Oltean 	     (pgid) < PGID_CPU;					\
7696b029b0SVladimir Oltean 	     (pgid)++)
7796b029b0SVladimir Oltean 
7896b029b0SVladimir Oltean #define for_each_aggr_pgid(ocelot, pgid)			\
7996b029b0SVladimir Oltean 	for ((pgid) = PGID_AGGR;				\
8096b029b0SVladimir Oltean 	     (pgid) < PGID_SRC;					\
8196b029b0SVladimir Oltean 	     (pgid)++)
8296b029b0SVladimir Oltean 
831cf3299bSVladimir Oltean /* Aggregation PGIDs, one per Link Aggregation Code */
841cf3299bSVladimir Oltean #define PGID_AGGR			64
851cf3299bSVladimir Oltean 
861cf3299bSVladimir Oltean /* Source PGIDs, one per physical port */
871cf3299bSVladimir Oltean #define PGID_SRC			80
881cf3299bSVladimir Oltean 
895e256365SVladimir Oltean #define IFH_INJ_BYPASS			BIT(31)
905e256365SVladimir Oltean #define IFH_INJ_POP_CNT_DISABLE		(3 << 28)
915e256365SVladimir Oltean 
925e256365SVladimir Oltean #define IFH_TAG_TYPE_C			0
935e256365SVladimir Oltean #define IFH_TAG_TYPE_S			1
945e256365SVladimir Oltean 
955e256365SVladimir Oltean #define IFH_REW_OP_NOOP			0x0
965e256365SVladimir Oltean #define IFH_REW_OP_DSCP			0x1
975e256365SVladimir Oltean #define IFH_REW_OP_ONE_STEP_PTP		0x2
985e256365SVladimir Oltean #define IFH_REW_OP_TWO_STEP_PTP		0x3
995e256365SVladimir Oltean #define IFH_REW_OP_ORIGIN_PTP		0x5
1005e256365SVladimir Oltean 
10170d39a6eSVladimir Oltean #define OCELOT_NUM_TC			8
1025e256365SVladimir Oltean #define OCELOT_TAG_LEN			16
1035e256365SVladimir Oltean #define OCELOT_SHORT_PREFIX_LEN		4
1045e256365SVladimir Oltean #define OCELOT_LONG_PREFIX_LEN		16
1055124197cSVladimir Oltean #define OCELOT_TOTAL_TAG_LEN	(OCELOT_SHORT_PREFIX_LEN + OCELOT_TAG_LEN)
1065e256365SVladimir Oltean 
1075e256365SVladimir Oltean #define OCELOT_SPEED_2500		0
1085e256365SVladimir Oltean #define OCELOT_SPEED_1000		1
1095e256365SVladimir Oltean #define OCELOT_SPEED_100		2
1105e256365SVladimir Oltean #define OCELOT_SPEED_10			3
1115e256365SVladimir Oltean 
112cc2d87bbSYangbo Lu #define OCELOT_PTP_PINS_NUM		4
113cc2d87bbSYangbo Lu 
1145e256365SVladimir Oltean #define TARGET_OFFSET			24
1155e256365SVladimir Oltean #define REG_MASK			GENMASK(TARGET_OFFSET - 1, 0)
1165e256365SVladimir Oltean #define REG(reg, offset)		[reg & REG_MASK] = offset
1175e256365SVladimir Oltean 
1185e256365SVladimir Oltean #define REG_RESERVED_ADDR		0xffffffff
1195e256365SVladimir Oltean #define REG_RESERVED(reg)		REG(reg, REG_RESERVED_ADDR)
1205e256365SVladimir Oltean 
1215e256365SVladimir Oltean enum ocelot_target {
1225e256365SVladimir Oltean 	ANA = 1,
1235e256365SVladimir Oltean 	QS,
1245e256365SVladimir Oltean 	QSYS,
1255e256365SVladimir Oltean 	REW,
1265e256365SVladimir Oltean 	SYS,
127e3aea296SVladimir Oltean 	S0,
128a61e365dSVladimir Oltean 	S1,
1295e256365SVladimir Oltean 	S2,
1305e256365SVladimir Oltean 	HSIO,
1315e256365SVladimir Oltean 	PTP,
1325e256365SVladimir Oltean 	GCB,
13391c724cfSVladimir Oltean 	DEV_GMII,
1345e256365SVladimir Oltean 	TARGET_MAX,
1355e256365SVladimir Oltean };
1365e256365SVladimir Oltean 
1375e256365SVladimir Oltean enum ocelot_reg {
1385e256365SVladimir Oltean 	ANA_ADVLEARN = ANA << TARGET_OFFSET,
1395e256365SVladimir Oltean 	ANA_VLANMASK,
1405e256365SVladimir Oltean 	ANA_PORT_B_DOMAIN,
1415e256365SVladimir Oltean 	ANA_ANAGEFIL,
1425e256365SVladimir Oltean 	ANA_ANEVENTS,
1435e256365SVladimir Oltean 	ANA_STORMLIMIT_BURST,
1445e256365SVladimir Oltean 	ANA_STORMLIMIT_CFG,
1455e256365SVladimir Oltean 	ANA_ISOLATED_PORTS,
1465e256365SVladimir Oltean 	ANA_COMMUNITY_PORTS,
1475e256365SVladimir Oltean 	ANA_AUTOAGE,
1485e256365SVladimir Oltean 	ANA_MACTOPTIONS,
1495e256365SVladimir Oltean 	ANA_LEARNDISC,
1505e256365SVladimir Oltean 	ANA_AGENCTRL,
1515e256365SVladimir Oltean 	ANA_MIRRORPORTS,
1525e256365SVladimir Oltean 	ANA_EMIRRORPORTS,
1535e256365SVladimir Oltean 	ANA_FLOODING,
1545e256365SVladimir Oltean 	ANA_FLOODING_IPMC,
1555e256365SVladimir Oltean 	ANA_SFLOW_CFG,
1565e256365SVladimir Oltean 	ANA_PORT_MODE,
1575e256365SVladimir Oltean 	ANA_CUT_THRU_CFG,
1585e256365SVladimir Oltean 	ANA_PGID_PGID,
1595e256365SVladimir Oltean 	ANA_TABLES_ANMOVED,
1605e256365SVladimir Oltean 	ANA_TABLES_MACHDATA,
1615e256365SVladimir Oltean 	ANA_TABLES_MACLDATA,
1625e256365SVladimir Oltean 	ANA_TABLES_STREAMDATA,
1635e256365SVladimir Oltean 	ANA_TABLES_MACACCESS,
1645e256365SVladimir Oltean 	ANA_TABLES_MACTINDX,
1655e256365SVladimir Oltean 	ANA_TABLES_VLANACCESS,
1665e256365SVladimir Oltean 	ANA_TABLES_VLANTIDX,
1675e256365SVladimir Oltean 	ANA_TABLES_ISDXACCESS,
1685e256365SVladimir Oltean 	ANA_TABLES_ISDXTIDX,
1695e256365SVladimir Oltean 	ANA_TABLES_ENTRYLIM,
1705e256365SVladimir Oltean 	ANA_TABLES_PTP_ID_HIGH,
1715e256365SVladimir Oltean 	ANA_TABLES_PTP_ID_LOW,
1725e256365SVladimir Oltean 	ANA_TABLES_STREAMACCESS,
1735e256365SVladimir Oltean 	ANA_TABLES_STREAMTIDX,
1745e256365SVladimir Oltean 	ANA_TABLES_SEQ_HISTORY,
1755e256365SVladimir Oltean 	ANA_TABLES_SEQ_MASK,
1765e256365SVladimir Oltean 	ANA_TABLES_SFID_MASK,
1775e256365SVladimir Oltean 	ANA_TABLES_SFIDACCESS,
1785e256365SVladimir Oltean 	ANA_TABLES_SFIDTIDX,
1795e256365SVladimir Oltean 	ANA_MSTI_STATE,
1805e256365SVladimir Oltean 	ANA_OAM_UPM_LM_CNT,
1815e256365SVladimir Oltean 	ANA_SG_ACCESS_CTRL,
1825e256365SVladimir Oltean 	ANA_SG_CONFIG_REG_1,
1835e256365SVladimir Oltean 	ANA_SG_CONFIG_REG_2,
1845e256365SVladimir Oltean 	ANA_SG_CONFIG_REG_3,
1855e256365SVladimir Oltean 	ANA_SG_CONFIG_REG_4,
1865e256365SVladimir Oltean 	ANA_SG_CONFIG_REG_5,
1875e256365SVladimir Oltean 	ANA_SG_GCL_GS_CONFIG,
1885e256365SVladimir Oltean 	ANA_SG_GCL_TI_CONFIG,
1895e256365SVladimir Oltean 	ANA_SG_STATUS_REG_1,
1905e256365SVladimir Oltean 	ANA_SG_STATUS_REG_2,
1915e256365SVladimir Oltean 	ANA_SG_STATUS_REG_3,
1925e256365SVladimir Oltean 	ANA_PORT_VLAN_CFG,
1935e256365SVladimir Oltean 	ANA_PORT_DROP_CFG,
1945e256365SVladimir Oltean 	ANA_PORT_QOS_CFG,
1955e256365SVladimir Oltean 	ANA_PORT_VCAP_CFG,
1965e256365SVladimir Oltean 	ANA_PORT_VCAP_S1_KEY_CFG,
1975e256365SVladimir Oltean 	ANA_PORT_VCAP_S2_CFG,
1985e256365SVladimir Oltean 	ANA_PORT_PCP_DEI_MAP,
1995e256365SVladimir Oltean 	ANA_PORT_CPU_FWD_CFG,
2005e256365SVladimir Oltean 	ANA_PORT_CPU_FWD_BPDU_CFG,
2015e256365SVladimir Oltean 	ANA_PORT_CPU_FWD_GARP_CFG,
2025e256365SVladimir Oltean 	ANA_PORT_CPU_FWD_CCM_CFG,
2035e256365SVladimir Oltean 	ANA_PORT_PORT_CFG,
2045e256365SVladimir Oltean 	ANA_PORT_POL_CFG,
2055e256365SVladimir Oltean 	ANA_PORT_PTP_CFG,
2065e256365SVladimir Oltean 	ANA_PORT_PTP_DLY1_CFG,
2075e256365SVladimir Oltean 	ANA_PORT_PTP_DLY2_CFG,
2085e256365SVladimir Oltean 	ANA_PORT_SFID_CFG,
2095e256365SVladimir Oltean 	ANA_PFC_PFC_CFG,
2105e256365SVladimir Oltean 	ANA_PFC_PFC_TIMER,
2115e256365SVladimir Oltean 	ANA_IPT_OAM_MEP_CFG,
2125e256365SVladimir Oltean 	ANA_IPT_IPT,
2135e256365SVladimir Oltean 	ANA_PPT_PPT,
2145e256365SVladimir Oltean 	ANA_FID_MAP_FID_MAP,
2155e256365SVladimir Oltean 	ANA_AGGR_CFG,
2165e256365SVladimir Oltean 	ANA_CPUQ_CFG,
2175e256365SVladimir Oltean 	ANA_CPUQ_CFG2,
2185e256365SVladimir Oltean 	ANA_CPUQ_8021_CFG,
2195e256365SVladimir Oltean 	ANA_DSCP_CFG,
2205e256365SVladimir Oltean 	ANA_DSCP_REWR_CFG,
2215e256365SVladimir Oltean 	ANA_VCAP_RNG_TYPE_CFG,
2225e256365SVladimir Oltean 	ANA_VCAP_RNG_VAL_CFG,
2235e256365SVladimir Oltean 	ANA_VRAP_CFG,
2245e256365SVladimir Oltean 	ANA_VRAP_HDR_DATA,
2255e256365SVladimir Oltean 	ANA_VRAP_HDR_MASK,
2265e256365SVladimir Oltean 	ANA_DISCARD_CFG,
2275e256365SVladimir Oltean 	ANA_FID_CFG,
2285e256365SVladimir Oltean 	ANA_POL_PIR_CFG,
2295e256365SVladimir Oltean 	ANA_POL_CIR_CFG,
2305e256365SVladimir Oltean 	ANA_POL_MODE_CFG,
2315e256365SVladimir Oltean 	ANA_POL_PIR_STATE,
2325e256365SVladimir Oltean 	ANA_POL_CIR_STATE,
2335e256365SVladimir Oltean 	ANA_POL_STATE,
2345e256365SVladimir Oltean 	ANA_POL_FLOWC,
2355e256365SVladimir Oltean 	ANA_POL_HYST,
2365e256365SVladimir Oltean 	ANA_POL_MISC_CFG,
2375e256365SVladimir Oltean 	QS_XTR_GRP_CFG = QS << TARGET_OFFSET,
2385e256365SVladimir Oltean 	QS_XTR_RD,
2395e256365SVladimir Oltean 	QS_XTR_FRM_PRUNING,
2405e256365SVladimir Oltean 	QS_XTR_FLUSH,
2415e256365SVladimir Oltean 	QS_XTR_DATA_PRESENT,
2425e256365SVladimir Oltean 	QS_XTR_CFG,
2435e256365SVladimir Oltean 	QS_INJ_GRP_CFG,
2445e256365SVladimir Oltean 	QS_INJ_WR,
2455e256365SVladimir Oltean 	QS_INJ_CTRL,
2465e256365SVladimir Oltean 	QS_INJ_STATUS,
2475e256365SVladimir Oltean 	QS_INJ_ERR,
2485e256365SVladimir Oltean 	QS_INH_DBG,
2495e256365SVladimir Oltean 	QSYS_PORT_MODE = QSYS << TARGET_OFFSET,
2505e256365SVladimir Oltean 	QSYS_SWITCH_PORT_MODE,
2515e256365SVladimir Oltean 	QSYS_STAT_CNT_CFG,
2525e256365SVladimir Oltean 	QSYS_EEE_CFG,
2535e256365SVladimir Oltean 	QSYS_EEE_THRES,
2545e256365SVladimir Oltean 	QSYS_IGR_NO_SHARING,
2555e256365SVladimir Oltean 	QSYS_EGR_NO_SHARING,
2565e256365SVladimir Oltean 	QSYS_SW_STATUS,
2575e256365SVladimir Oltean 	QSYS_EXT_CPU_CFG,
2585e256365SVladimir Oltean 	QSYS_PAD_CFG,
2595e256365SVladimir Oltean 	QSYS_CPU_GROUP_MAP,
2605e256365SVladimir Oltean 	QSYS_QMAP,
2615e256365SVladimir Oltean 	QSYS_ISDX_SGRP,
2625e256365SVladimir Oltean 	QSYS_TIMED_FRAME_ENTRY,
2635e256365SVladimir Oltean 	QSYS_TFRM_MISC,
2645e256365SVladimir Oltean 	QSYS_TFRM_PORT_DLY,
2655e256365SVladimir Oltean 	QSYS_TFRM_TIMER_CFG_1,
2665e256365SVladimir Oltean 	QSYS_TFRM_TIMER_CFG_2,
2675e256365SVladimir Oltean 	QSYS_TFRM_TIMER_CFG_3,
2685e256365SVladimir Oltean 	QSYS_TFRM_TIMER_CFG_4,
2695e256365SVladimir Oltean 	QSYS_TFRM_TIMER_CFG_5,
2705e256365SVladimir Oltean 	QSYS_TFRM_TIMER_CFG_6,
2715e256365SVladimir Oltean 	QSYS_TFRM_TIMER_CFG_7,
2725e256365SVladimir Oltean 	QSYS_TFRM_TIMER_CFG_8,
2735e256365SVladimir Oltean 	QSYS_RED_PROFILE,
2745e256365SVladimir Oltean 	QSYS_RES_QOS_MODE,
2755e256365SVladimir Oltean 	QSYS_RES_CFG,
2765e256365SVladimir Oltean 	QSYS_RES_STAT,
2775e256365SVladimir Oltean 	QSYS_EGR_DROP_MODE,
2785e256365SVladimir Oltean 	QSYS_EQ_CTRL,
2795e256365SVladimir Oltean 	QSYS_EVENTS_CORE,
2805e256365SVladimir Oltean 	QSYS_QMAXSDU_CFG_0,
2815e256365SVladimir Oltean 	QSYS_QMAXSDU_CFG_1,
2825e256365SVladimir Oltean 	QSYS_QMAXSDU_CFG_2,
2835e256365SVladimir Oltean 	QSYS_QMAXSDU_CFG_3,
2845e256365SVladimir Oltean 	QSYS_QMAXSDU_CFG_4,
2855e256365SVladimir Oltean 	QSYS_QMAXSDU_CFG_5,
2865e256365SVladimir Oltean 	QSYS_QMAXSDU_CFG_6,
2875e256365SVladimir Oltean 	QSYS_QMAXSDU_CFG_7,
2885e256365SVladimir Oltean 	QSYS_PREEMPTION_CFG,
2895e256365SVladimir Oltean 	QSYS_CIR_CFG,
2905e256365SVladimir Oltean 	QSYS_EIR_CFG,
2915e256365SVladimir Oltean 	QSYS_SE_CFG,
2925e256365SVladimir Oltean 	QSYS_SE_DWRR_CFG,
2935e256365SVladimir Oltean 	QSYS_SE_CONNECT,
2945e256365SVladimir Oltean 	QSYS_SE_DLB_SENSE,
2955e256365SVladimir Oltean 	QSYS_CIR_STATE,
2965e256365SVladimir Oltean 	QSYS_EIR_STATE,
2975e256365SVladimir Oltean 	QSYS_SE_STATE,
2985e256365SVladimir Oltean 	QSYS_HSCH_MISC_CFG,
2995e256365SVladimir Oltean 	QSYS_TAG_CONFIG,
3005e256365SVladimir Oltean 	QSYS_TAS_PARAM_CFG_CTRL,
3015e256365SVladimir Oltean 	QSYS_PORT_MAX_SDU,
3025e256365SVladimir Oltean 	QSYS_PARAM_CFG_REG_1,
3035e256365SVladimir Oltean 	QSYS_PARAM_CFG_REG_2,
3045e256365SVladimir Oltean 	QSYS_PARAM_CFG_REG_3,
3055e256365SVladimir Oltean 	QSYS_PARAM_CFG_REG_4,
3065e256365SVladimir Oltean 	QSYS_PARAM_CFG_REG_5,
3075e256365SVladimir Oltean 	QSYS_GCL_CFG_REG_1,
3085e256365SVladimir Oltean 	QSYS_GCL_CFG_REG_2,
3095e256365SVladimir Oltean 	QSYS_PARAM_STATUS_REG_1,
3105e256365SVladimir Oltean 	QSYS_PARAM_STATUS_REG_2,
3115e256365SVladimir Oltean 	QSYS_PARAM_STATUS_REG_3,
3125e256365SVladimir Oltean 	QSYS_PARAM_STATUS_REG_4,
3135e256365SVladimir Oltean 	QSYS_PARAM_STATUS_REG_5,
3145e256365SVladimir Oltean 	QSYS_PARAM_STATUS_REG_6,
3155e256365SVladimir Oltean 	QSYS_PARAM_STATUS_REG_7,
3165e256365SVladimir Oltean 	QSYS_PARAM_STATUS_REG_8,
3175e256365SVladimir Oltean 	QSYS_PARAM_STATUS_REG_9,
3185e256365SVladimir Oltean 	QSYS_GCL_STATUS_REG_1,
3195e256365SVladimir Oltean 	QSYS_GCL_STATUS_REG_2,
3205e256365SVladimir Oltean 	REW_PORT_VLAN_CFG = REW << TARGET_OFFSET,
3215e256365SVladimir Oltean 	REW_TAG_CFG,
3225e256365SVladimir Oltean 	REW_PORT_CFG,
3235e256365SVladimir Oltean 	REW_DSCP_CFG,
3245e256365SVladimir Oltean 	REW_PCP_DEI_QOS_MAP_CFG,
3255e256365SVladimir Oltean 	REW_PTP_CFG,
3265e256365SVladimir Oltean 	REW_PTP_DLY1_CFG,
3275e256365SVladimir Oltean 	REW_RED_TAG_CFG,
3285e256365SVladimir Oltean 	REW_DSCP_REMAP_DP1_CFG,
3295e256365SVladimir Oltean 	REW_DSCP_REMAP_CFG,
3305e256365SVladimir Oltean 	REW_STAT_CFG,
3315e256365SVladimir Oltean 	REW_REW_STICKY,
3325e256365SVladimir Oltean 	REW_PPT,
3335e256365SVladimir Oltean 	SYS_COUNT_RX_OCTETS = SYS << TARGET_OFFSET,
3345e256365SVladimir Oltean 	SYS_COUNT_RX_UNICAST,
3355e256365SVladimir Oltean 	SYS_COUNT_RX_MULTICAST,
3365e256365SVladimir Oltean 	SYS_COUNT_RX_BROADCAST,
3375e256365SVladimir Oltean 	SYS_COUNT_RX_SHORTS,
3385e256365SVladimir Oltean 	SYS_COUNT_RX_FRAGMENTS,
3395e256365SVladimir Oltean 	SYS_COUNT_RX_JABBERS,
3405e256365SVladimir Oltean 	SYS_COUNT_RX_CRC_ALIGN_ERRS,
3415e256365SVladimir Oltean 	SYS_COUNT_RX_SYM_ERRS,
3425e256365SVladimir Oltean 	SYS_COUNT_RX_64,
3435e256365SVladimir Oltean 	SYS_COUNT_RX_65_127,
3445e256365SVladimir Oltean 	SYS_COUNT_RX_128_255,
3455e256365SVladimir Oltean 	SYS_COUNT_RX_256_1023,
3465e256365SVladimir Oltean 	SYS_COUNT_RX_1024_1526,
3475e256365SVladimir Oltean 	SYS_COUNT_RX_1527_MAX,
3485e256365SVladimir Oltean 	SYS_COUNT_RX_PAUSE,
3495e256365SVladimir Oltean 	SYS_COUNT_RX_CONTROL,
3505e256365SVladimir Oltean 	SYS_COUNT_RX_LONGS,
3515e256365SVladimir Oltean 	SYS_COUNT_RX_CLASSIFIED_DROPS,
3525e256365SVladimir Oltean 	SYS_COUNT_TX_OCTETS,
3535e256365SVladimir Oltean 	SYS_COUNT_TX_UNICAST,
3545e256365SVladimir Oltean 	SYS_COUNT_TX_MULTICAST,
3555e256365SVladimir Oltean 	SYS_COUNT_TX_BROADCAST,
3565e256365SVladimir Oltean 	SYS_COUNT_TX_COLLISION,
3575e256365SVladimir Oltean 	SYS_COUNT_TX_DROPS,
3585e256365SVladimir Oltean 	SYS_COUNT_TX_PAUSE,
3595e256365SVladimir Oltean 	SYS_COUNT_TX_64,
3605e256365SVladimir Oltean 	SYS_COUNT_TX_65_127,
3615e256365SVladimir Oltean 	SYS_COUNT_TX_128_511,
3625e256365SVladimir Oltean 	SYS_COUNT_TX_512_1023,
3635e256365SVladimir Oltean 	SYS_COUNT_TX_1024_1526,
3645e256365SVladimir Oltean 	SYS_COUNT_TX_1527_MAX,
3655e256365SVladimir Oltean 	SYS_COUNT_TX_AGING,
3665e256365SVladimir Oltean 	SYS_RESET_CFG,
3675e256365SVladimir Oltean 	SYS_SR_ETYPE_CFG,
3685e256365SVladimir Oltean 	SYS_VLAN_ETYPE_CFG,
3695e256365SVladimir Oltean 	SYS_PORT_MODE,
3705e256365SVladimir Oltean 	SYS_FRONT_PORT_MODE,
3715e256365SVladimir Oltean 	SYS_FRM_AGING,
3725e256365SVladimir Oltean 	SYS_STAT_CFG,
3735e256365SVladimir Oltean 	SYS_SW_STATUS,
3745e256365SVladimir Oltean 	SYS_MISC_CFG,
3755e256365SVladimir Oltean 	SYS_REW_MAC_HIGH_CFG,
3765e256365SVladimir Oltean 	SYS_REW_MAC_LOW_CFG,
3775e256365SVladimir Oltean 	SYS_TIMESTAMP_OFFSET,
3785e256365SVladimir Oltean 	SYS_CMID,
3795e256365SVladimir Oltean 	SYS_PAUSE_CFG,
3805e256365SVladimir Oltean 	SYS_PAUSE_TOT_CFG,
3815e256365SVladimir Oltean 	SYS_ATOP,
3825e256365SVladimir Oltean 	SYS_ATOP_TOT_CFG,
3835e256365SVladimir Oltean 	SYS_MAC_FC_CFG,
3845e256365SVladimir Oltean 	SYS_MMGT,
3855e256365SVladimir Oltean 	SYS_MMGT_FAST,
3865e256365SVladimir Oltean 	SYS_EVENTS_DIF,
3875e256365SVladimir Oltean 	SYS_EVENTS_CORE,
3885e256365SVladimir Oltean 	SYS_CNT,
3895e256365SVladimir Oltean 	SYS_PTP_STATUS,
3905e256365SVladimir Oltean 	SYS_PTP_TXSTAMP,
3915e256365SVladimir Oltean 	SYS_PTP_NXT,
3925e256365SVladimir Oltean 	SYS_PTP_CFG,
3935e256365SVladimir Oltean 	SYS_RAM_INIT,
3945e256365SVladimir Oltean 	SYS_CM_ADDR,
3955e256365SVladimir Oltean 	SYS_CM_DATA_WR,
3965e256365SVladimir Oltean 	SYS_CM_DATA_RD,
3975e256365SVladimir Oltean 	SYS_CM_OP,
3985e256365SVladimir Oltean 	SYS_CM_DATA,
3995e256365SVladimir Oltean 	PTP_PIN_CFG = PTP << TARGET_OFFSET,
4005e256365SVladimir Oltean 	PTP_PIN_TOD_SEC_MSB,
4015e256365SVladimir Oltean 	PTP_PIN_TOD_SEC_LSB,
4025e256365SVladimir Oltean 	PTP_PIN_TOD_NSEC,
40394aca082SYangbo Lu 	PTP_PIN_WF_HIGH_PERIOD,
40494aca082SYangbo Lu 	PTP_PIN_WF_LOW_PERIOD,
4055e256365SVladimir Oltean 	PTP_CFG_MISC,
4065e256365SVladimir Oltean 	PTP_CLK_CFG_ADJ_CFG,
4075e256365SVladimir Oltean 	PTP_CLK_CFG_ADJ_FREQ,
4085e256365SVladimir Oltean 	GCB_SOFT_RST = GCB << TARGET_OFFSET,
4092789658fSMaxim Kochetkov 	GCB_MIIM_MII_STATUS,
4102789658fSMaxim Kochetkov 	GCB_MIIM_MII_CMD,
4112789658fSMaxim Kochetkov 	GCB_MIIM_MII_DATA,
41291c724cfSVladimir Oltean 	DEV_CLOCK_CFG = DEV_GMII << TARGET_OFFSET,
41391c724cfSVladimir Oltean 	DEV_PORT_MISC,
41491c724cfSVladimir Oltean 	DEV_EVENTS,
41591c724cfSVladimir Oltean 	DEV_EEE_CFG,
41691c724cfSVladimir Oltean 	DEV_RX_PATH_DELAY,
41791c724cfSVladimir Oltean 	DEV_TX_PATH_DELAY,
41891c724cfSVladimir Oltean 	DEV_PTP_PREDICT_CFG,
41991c724cfSVladimir Oltean 	DEV_MAC_ENA_CFG,
42091c724cfSVladimir Oltean 	DEV_MAC_MODE_CFG,
42191c724cfSVladimir Oltean 	DEV_MAC_MAXLEN_CFG,
42291c724cfSVladimir Oltean 	DEV_MAC_TAGS_CFG,
42391c724cfSVladimir Oltean 	DEV_MAC_ADV_CHK_CFG,
42491c724cfSVladimir Oltean 	DEV_MAC_IFG_CFG,
42591c724cfSVladimir Oltean 	DEV_MAC_HDX_CFG,
42691c724cfSVladimir Oltean 	DEV_MAC_DBG_CFG,
42791c724cfSVladimir Oltean 	DEV_MAC_FC_MAC_LOW_CFG,
42891c724cfSVladimir Oltean 	DEV_MAC_FC_MAC_HIGH_CFG,
42991c724cfSVladimir Oltean 	DEV_MAC_STICKY,
43091c724cfSVladimir Oltean 	PCS1G_CFG,
43191c724cfSVladimir Oltean 	PCS1G_MODE_CFG,
43291c724cfSVladimir Oltean 	PCS1G_SD_CFG,
43391c724cfSVladimir Oltean 	PCS1G_ANEG_CFG,
43491c724cfSVladimir Oltean 	PCS1G_ANEG_NP_CFG,
43591c724cfSVladimir Oltean 	PCS1G_LB_CFG,
43691c724cfSVladimir Oltean 	PCS1G_DBG_CFG,
43791c724cfSVladimir Oltean 	PCS1G_CDET_CFG,
43891c724cfSVladimir Oltean 	PCS1G_ANEG_STATUS,
43991c724cfSVladimir Oltean 	PCS1G_ANEG_NP_STATUS,
44091c724cfSVladimir Oltean 	PCS1G_LINK_STATUS,
44191c724cfSVladimir Oltean 	PCS1G_LINK_DOWN_CNT,
44291c724cfSVladimir Oltean 	PCS1G_STICKY,
44391c724cfSVladimir Oltean 	PCS1G_DEBUG_STATUS,
44491c724cfSVladimir Oltean 	PCS1G_LPI_CFG,
44591c724cfSVladimir Oltean 	PCS1G_LPI_WAKE_ERROR_CNT,
44691c724cfSVladimir Oltean 	PCS1G_LPI_STATUS,
44791c724cfSVladimir Oltean 	PCS1G_TSTPAT_MODE_CFG,
44891c724cfSVladimir Oltean 	PCS1G_TSTPAT_STATUS,
44991c724cfSVladimir Oltean 	DEV_PCS_FX100_CFG,
45091c724cfSVladimir Oltean 	DEV_PCS_FX100_STATUS,
4515e256365SVladimir Oltean };
4525e256365SVladimir Oltean 
4535e256365SVladimir Oltean enum ocelot_regfield {
4545e256365SVladimir Oltean 	ANA_ADVLEARN_VLAN_CHK,
4555e256365SVladimir Oltean 	ANA_ADVLEARN_LEARN_MIRROR,
4565e256365SVladimir Oltean 	ANA_ANEVENTS_FLOOD_DISCARD,
4575e256365SVladimir Oltean 	ANA_ANEVENTS_MSTI_DROP,
4585e256365SVladimir Oltean 	ANA_ANEVENTS_ACLKILL,
4595e256365SVladimir Oltean 	ANA_ANEVENTS_ACLUSED,
4605e256365SVladimir Oltean 	ANA_ANEVENTS_AUTOAGE,
4615e256365SVladimir Oltean 	ANA_ANEVENTS_VS2TTL1,
4625e256365SVladimir Oltean 	ANA_ANEVENTS_STORM_DROP,
4635e256365SVladimir Oltean 	ANA_ANEVENTS_LEARN_DROP,
4645e256365SVladimir Oltean 	ANA_ANEVENTS_AGED_ENTRY,
4655e256365SVladimir Oltean 	ANA_ANEVENTS_CPU_LEARN_FAILED,
4665e256365SVladimir Oltean 	ANA_ANEVENTS_AUTO_LEARN_FAILED,
4675e256365SVladimir Oltean 	ANA_ANEVENTS_LEARN_REMOVE,
4685e256365SVladimir Oltean 	ANA_ANEVENTS_AUTO_LEARNED,
4695e256365SVladimir Oltean 	ANA_ANEVENTS_AUTO_MOVED,
4705e256365SVladimir Oltean 	ANA_ANEVENTS_DROPPED,
4715e256365SVladimir Oltean 	ANA_ANEVENTS_CLASSIFIED_DROP,
4725e256365SVladimir Oltean 	ANA_ANEVENTS_CLASSIFIED_COPY,
4735e256365SVladimir Oltean 	ANA_ANEVENTS_VLAN_DISCARD,
4745e256365SVladimir Oltean 	ANA_ANEVENTS_FWD_DISCARD,
4755e256365SVladimir Oltean 	ANA_ANEVENTS_MULTICAST_FLOOD,
4765e256365SVladimir Oltean 	ANA_ANEVENTS_UNICAST_FLOOD,
4775e256365SVladimir Oltean 	ANA_ANEVENTS_DEST_KNOWN,
4785e256365SVladimir Oltean 	ANA_ANEVENTS_BUCKET3_MATCH,
4795e256365SVladimir Oltean 	ANA_ANEVENTS_BUCKET2_MATCH,
4805e256365SVladimir Oltean 	ANA_ANEVENTS_BUCKET1_MATCH,
4815e256365SVladimir Oltean 	ANA_ANEVENTS_BUCKET0_MATCH,
4825e256365SVladimir Oltean 	ANA_ANEVENTS_CPU_OPERATION,
4835e256365SVladimir Oltean 	ANA_ANEVENTS_DMAC_LOOKUP,
4845e256365SVladimir Oltean 	ANA_ANEVENTS_SMAC_LOOKUP,
4855e256365SVladimir Oltean 	ANA_ANEVENTS_SEQ_GEN_ERR_0,
4865e256365SVladimir Oltean 	ANA_ANEVENTS_SEQ_GEN_ERR_1,
4875e256365SVladimir Oltean 	ANA_TABLES_MACACCESS_B_DOM,
4885e256365SVladimir Oltean 	ANA_TABLES_MACTINDX_BUCKET,
4895e256365SVladimir Oltean 	ANA_TABLES_MACTINDX_M_INDEX,
490886e1387SVladimir Oltean 	QSYS_SWITCH_PORT_MODE_PORT_ENA,
491886e1387SVladimir Oltean 	QSYS_SWITCH_PORT_MODE_SCH_NEXT_CFG,
492886e1387SVladimir Oltean 	QSYS_SWITCH_PORT_MODE_YEL_RSRVD,
493886e1387SVladimir Oltean 	QSYS_SWITCH_PORT_MODE_INGRESS_DROP_MODE,
494886e1387SVladimir Oltean 	QSYS_SWITCH_PORT_MODE_TX_PFC_ENA,
495886e1387SVladimir Oltean 	QSYS_SWITCH_PORT_MODE_TX_PFC_MODE,
4965e256365SVladimir Oltean 	QSYS_TIMED_FRAME_ENTRY_TFRM_VLD,
4975e256365SVladimir Oltean 	QSYS_TIMED_FRAME_ENTRY_TFRM_FP,
4985e256365SVladimir Oltean 	QSYS_TIMED_FRAME_ENTRY_TFRM_PORTNO,
4995e256365SVladimir Oltean 	QSYS_TIMED_FRAME_ENTRY_TFRM_TM_SEL,
5005e256365SVladimir Oltean 	QSYS_TIMED_FRAME_ENTRY_TFRM_TM_T,
501886e1387SVladimir Oltean 	SYS_PORT_MODE_DATA_WO_TS,
502886e1387SVladimir Oltean 	SYS_PORT_MODE_INCL_INJ_HDR,
503886e1387SVladimir Oltean 	SYS_PORT_MODE_INCL_XTR_HDR,
504886e1387SVladimir Oltean 	SYS_PORT_MODE_INCL_HDR_ERR,
5055e256365SVladimir Oltean 	SYS_RESET_CFG_CORE_ENA,
5065e256365SVladimir Oltean 	SYS_RESET_CFG_MEM_ENA,
5075e256365SVladimir Oltean 	SYS_RESET_CFG_MEM_INIT,
5085e256365SVladimir Oltean 	GCB_SOFT_RST_SWC_RST,
5092789658fSMaxim Kochetkov 	GCB_MIIM_MII_STATUS_PENDING,
5102789658fSMaxim Kochetkov 	GCB_MIIM_MII_STATUS_BUSY,
511541132f0SMaxim Kochetkov 	SYS_PAUSE_CFG_PAUSE_START,
512541132f0SMaxim Kochetkov 	SYS_PAUSE_CFG_PAUSE_STOP,
513541132f0SMaxim Kochetkov 	SYS_PAUSE_CFG_PAUSE_ENA,
5145e256365SVladimir Oltean 	REGFIELD_MAX
5155e256365SVladimir Oltean };
5165e256365SVladimir Oltean 
517c1c3993eSVladimir Oltean enum {
518c1c3993eSVladimir Oltean 	/* VCAP_CORE_CFG */
519c1c3993eSVladimir Oltean 	VCAP_CORE_UPDATE_CTRL,
520c1c3993eSVladimir Oltean 	VCAP_CORE_MV_CFG,
521c1c3993eSVladimir Oltean 	/* VCAP_CORE_CACHE */
522c1c3993eSVladimir Oltean 	VCAP_CACHE_ENTRY_DAT,
523c1c3993eSVladimir Oltean 	VCAP_CACHE_MASK_DAT,
524c1c3993eSVladimir Oltean 	VCAP_CACHE_ACTION_DAT,
525c1c3993eSVladimir Oltean 	VCAP_CACHE_CNT_DAT,
526c1c3993eSVladimir Oltean 	VCAP_CACHE_TG_DAT,
52720968054SVladimir Oltean 	/* VCAP_CONST */
52820968054SVladimir Oltean 	VCAP_CONST_VCAP_VER,
52920968054SVladimir Oltean 	VCAP_CONST_ENTRY_WIDTH,
53020968054SVladimir Oltean 	VCAP_CONST_ENTRY_CNT,
53120968054SVladimir Oltean 	VCAP_CONST_ENTRY_SWCNT,
53220968054SVladimir Oltean 	VCAP_CONST_ENTRY_TG_WIDTH,
53320968054SVladimir Oltean 	VCAP_CONST_ACTION_DEF_CNT,
53420968054SVladimir Oltean 	VCAP_CONST_ACTION_WIDTH,
53520968054SVladimir Oltean 	VCAP_CONST_CNT_WIDTH,
53620968054SVladimir Oltean 	VCAP_CONST_CORE_CNT,
53720968054SVladimir Oltean 	VCAP_CONST_IF_CNT,
538c1c3993eSVladimir Oltean };
539c1c3993eSVladimir Oltean 
5403007bc73SYangbo Lu enum ocelot_ptp_pins {
5413007bc73SYangbo Lu 	PTP_PIN_0,
5423007bc73SYangbo Lu 	PTP_PIN_1,
5433007bc73SYangbo Lu 	PTP_PIN_2,
5443007bc73SYangbo Lu 	PTP_PIN_3,
5455e256365SVladimir Oltean 	TOD_ACC_PIN
5465e256365SVladimir Oltean };
5475e256365SVladimir Oltean 
5485e256365SVladimir Oltean struct ocelot_stat_layout {
5495e256365SVladimir Oltean 	u32 offset;
5505e256365SVladimir Oltean 	char name[ETH_GSTRING_LEN];
5515e256365SVladimir Oltean };
5525e256365SVladimir Oltean 
5535e256365SVladimir Oltean enum ocelot_tag_prefix {
5545e256365SVladimir Oltean 	OCELOT_TAG_PREFIX_DISABLED	= 0,
5555e256365SVladimir Oltean 	OCELOT_TAG_PREFIX_NONE,
5565e256365SVladimir Oltean 	OCELOT_TAG_PREFIX_SHORT,
5575e256365SVladimir Oltean 	OCELOT_TAG_PREFIX_LONG,
5585e256365SVladimir Oltean };
5595e256365SVladimir Oltean 
5605e256365SVladimir Oltean struct ocelot;
5615e256365SVladimir Oltean 
5625e256365SVladimir Oltean struct ocelot_ops {
563319e4dd1SVladimir Oltean 	struct net_device *(*port_to_netdev)(struct ocelot *ocelot, int port);
564319e4dd1SVladimir Oltean 	int (*netdev_to_port)(struct net_device *dev);
5655e256365SVladimir Oltean 	int (*reset)(struct ocelot *ocelot);
566aa92d836SMaxim Kochetkov 	u16 (*wm_enc)(u16 value);
567703b7621SVladimir Oltean 	u16 (*wm_dec)(u16 value);
568703b7621SVladimir Oltean 	void (*wm_stat)(u32 val, u32 *inuse, u32 *maxuse);
5695e256365SVladimir Oltean };
5705e256365SVladimir Oltean 
571aae4e500SVladimir Oltean struct ocelot_vcap_block {
572a56d7a34SVladimir Oltean 	struct list_head rules;
573a56d7a34SVladimir Oltean 	int count;
574c9a7fe12SXiaoliang Yang 	int pol_lpr;
575a56d7a34SVladimir Oltean };
576a56d7a34SVladimir Oltean 
577c3e58a75SVladimir Oltean struct ocelot_vlan {
578e2b2e83eSVladimir Oltean 	bool valid;
579c3e58a75SVladimir Oltean 	u16 vid;
580c3e58a75SVladimir Oltean };
581c3e58a75SVladimir Oltean 
582f59fd9caSVladimir Oltean enum ocelot_sb {
583f59fd9caSVladimir Oltean 	OCELOT_SB_BUF,
584f59fd9caSVladimir Oltean 	OCELOT_SB_REF,
585f59fd9caSVladimir Oltean 	OCELOT_SB_NUM,
586f59fd9caSVladimir Oltean };
587f59fd9caSVladimir Oltean 
588f59fd9caSVladimir Oltean enum ocelot_sb_pool {
589f59fd9caSVladimir Oltean 	OCELOT_SB_POOL_ING,
590f59fd9caSVladimir Oltean 	OCELOT_SB_POOL_EGR,
591f59fd9caSVladimir Oltean 	OCELOT_SB_POOL_NUM,
592f59fd9caSVladimir Oltean };
593f59fd9caSVladimir Oltean 
5945e256365SVladimir Oltean struct ocelot_port {
5955e256365SVladimir Oltean 	struct ocelot			*ocelot;
5965e256365SVladimir Oltean 
59791c724cfSVladimir Oltean 	struct regmap			*target;
5985e256365SVladimir Oltean 
59987b0f983SVladimir Oltean 	bool				vlan_aware;
600c3e58a75SVladimir Oltean 	/* VLAN that untagged frames are classified to, on ingress */
601c3e58a75SVladimir Oltean 	struct ocelot_vlan		pvid_vlan;
602c3e58a75SVladimir Oltean 	/* The VLAN ID that will be transmitted as untagged, on egress */
603c3e58a75SVladimir Oltean 	struct ocelot_vlan		native_vlan;
6045e256365SVladimir Oltean 
6055e256365SVladimir Oltean 	u8				ptp_cmd;
606b049da13SYangbo Lu 	struct sk_buff_head		tx_skbs;
6075e256365SVladimir Oltean 	u8				ts_id;
6086565243cSVladimir Oltean 	spinlock_t			ts_id_lock;
609ee50d07cSVladimir Oltean 
610ee50d07cSVladimir Oltean 	phy_interface_t			phy_mode;
61167c24049SVladimir Oltean 
61267c24049SVladimir Oltean 	u8				*xmit_template;
6135e256365SVladimir Oltean };
6145e256365SVladimir Oltean 
6155e256365SVladimir Oltean struct ocelot {
6165e256365SVladimir Oltean 	struct device			*dev;
6176c30384eSVladimir Oltean 	struct devlink			*devlink;
6186c30384eSVladimir Oltean 	struct devlink_port		*devlink_ports;
6195e256365SVladimir Oltean 
6205e256365SVladimir Oltean 	const struct ocelot_ops		*ops;
6215e256365SVladimir Oltean 	struct regmap			*targets[TARGET_MAX];
6225e256365SVladimir Oltean 	struct regmap_field		*regfields[REGFIELD_MAX];
6235e256365SVladimir Oltean 	const u32 *const		*map;
6245e256365SVladimir Oltean 	const struct ocelot_stat_layout	*stats_layout;
6255e256365SVladimir Oltean 	unsigned int			num_stats;
6265e256365SVladimir Oltean 
627f59fd9caSVladimir Oltean 	u32				pool_size[OCELOT_SB_NUM][OCELOT_SB_POOL_NUM];
628f6fe01d6SVladimir Oltean 	int				packet_buffer_size;
629f6fe01d6SVladimir Oltean 	int				num_frame_refs;
63021ce7f3eSVladimir Oltean 	int				num_mact_rows;
6315e256365SVladimir Oltean 
6325e256365SVladimir Oltean 	struct net_device		*hw_bridge_dev;
6335e256365SVladimir Oltean 	u16				bridge_mask;
6345e256365SVladimir Oltean 	u16				bridge_fwd_mask;
6355e256365SVladimir Oltean 
6365e256365SVladimir Oltean 	struct ocelot_port		**ports;
6375e256365SVladimir Oltean 
6385e256365SVladimir Oltean 	u8				base_mac[ETH_ALEN];
6395e256365SVladimir Oltean 
6405e256365SVladimir Oltean 	/* Keep track of the vlan port masks */
6415e256365SVladimir Oltean 	u32				vlan_mask[VLAN_N_VID];
6425e256365SVladimir Oltean 
643edd2410bSVladimir Oltean 	/* Switches like VSC9959 have flooding per traffic class */
644edd2410bSVladimir Oltean 	int				num_flooding_pgids;
645edd2410bSVladimir Oltean 
64669df578cSVladimir Oltean 	/* In tables like ANA:PORT and the ANA:PGID:PGID mask,
64769df578cSVladimir Oltean 	 * the CPU is located after the physical ports (at the
64869df578cSVladimir Oltean 	 * num_phys_ports index).
64969df578cSVladimir Oltean 	 */
6505e256365SVladimir Oltean 	u8				num_phys_ports;
6515e256365SVladimir Oltean 
6520b912fc9SVladimir Oltean 	int				npi;
6530b912fc9SVladimir Oltean 
654*cacea62fSVladimir Oltean 	enum ocelot_tag_prefix		npi_inj_prefix;
655*cacea62fSVladimir Oltean 	enum ocelot_tag_prefix		npi_xtr_prefix;
6560b912fc9SVladimir Oltean 
6575e256365SVladimir Oltean 	u32				*lags;
6585e256365SVladimir Oltean 
6595e256365SVladimir Oltean 	struct list_head		multicast;
660e5d1f896SVladimir Oltean 	struct list_head		pgids;
6615e256365SVladimir Oltean 
6621397a2ebSVladimir Oltean 	struct list_head		dummy_rules;
6631397a2ebSVladimir Oltean 	struct ocelot_vcap_block	block[3];
66420968054SVladimir Oltean 	struct vcap_props		*vcap;
665e0632940SVladimir Oltean 
6665e256365SVladimir Oltean 	/* Workqueue to check statistics for overflow with its lock */
6675e256365SVladimir Oltean 	struct mutex			stats_lock;
6685e256365SVladimir Oltean 	u64				*stats;
6695e256365SVladimir Oltean 	struct delayed_work		stats_work;
6705e256365SVladimir Oltean 	struct workqueue_struct		*stats_queue;
6715e256365SVladimir Oltean 
672ca0b272bSVladimir Oltean 	struct workqueue_struct		*owq;
673ca0b272bSVladimir Oltean 
6745e256365SVladimir Oltean 	u8				ptp:1;
6755e256365SVladimir Oltean 	struct ptp_clock		*ptp_clock;
6765e256365SVladimir Oltean 	struct ptp_clock_info		ptp_info;
6775e256365SVladimir Oltean 	struct hwtstamp_config		hwtstamp_config;
6785e256365SVladimir Oltean 	/* Protects the PTP interface state */
6795e256365SVladimir Oltean 	struct mutex			ptp_lock;
6805e256365SVladimir Oltean 	/* Protects the PTP clock */
6815e256365SVladimir Oltean 	spinlock_t			ptp_clock_lock;
682cc2d87bbSYangbo Lu 	struct ptp_pin_desc		ptp_pins[OCELOT_PTP_PINS_NUM];
6835e256365SVladimir Oltean };
6845e256365SVladimir Oltean 
685fc411eaaSVladimir Oltean struct ocelot_policer {
686fc411eaaSVladimir Oltean 	u32 rate; /* kilobit per second */
687fc411eaaSVladimir Oltean 	u32 burst; /* bytes */
688fc411eaaSVladimir Oltean };
689fc411eaaSVladimir Oltean 
6905e256365SVladimir Oltean #define ocelot_read_ix(ocelot, reg, gi, ri) __ocelot_read_ix(ocelot, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
6915e256365SVladimir Oltean #define ocelot_read_gix(ocelot, reg, gi) __ocelot_read_ix(ocelot, reg, reg##_GSZ * (gi))
6925e256365SVladimir Oltean #define ocelot_read_rix(ocelot, reg, ri) __ocelot_read_ix(ocelot, reg, reg##_RSZ * (ri))
6935e256365SVladimir Oltean #define ocelot_read(ocelot, reg) __ocelot_read_ix(ocelot, reg, 0)
6945e256365SVladimir Oltean 
6955e256365SVladimir Oltean #define ocelot_write_ix(ocelot, val, reg, gi, ri) __ocelot_write_ix(ocelot, val, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
6965e256365SVladimir Oltean #define ocelot_write_gix(ocelot, val, reg, gi) __ocelot_write_ix(ocelot, val, reg, reg##_GSZ * (gi))
6975e256365SVladimir Oltean #define ocelot_write_rix(ocelot, val, reg, ri) __ocelot_write_ix(ocelot, val, reg, reg##_RSZ * (ri))
6985e256365SVladimir Oltean #define ocelot_write(ocelot, val, reg) __ocelot_write_ix(ocelot, val, reg, 0)
6995e256365SVladimir Oltean 
7005e256365SVladimir Oltean #define ocelot_rmw_ix(ocelot, val, m, reg, gi, ri) __ocelot_rmw_ix(ocelot, val, m, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
7015e256365SVladimir Oltean #define ocelot_rmw_gix(ocelot, val, m, reg, gi) __ocelot_rmw_ix(ocelot, val, m, reg, reg##_GSZ * (gi))
7025e256365SVladimir Oltean #define ocelot_rmw_rix(ocelot, val, m, reg, ri) __ocelot_rmw_ix(ocelot, val, m, reg, reg##_RSZ * (ri))
7035e256365SVladimir Oltean #define ocelot_rmw(ocelot, val, m, reg) __ocelot_rmw_ix(ocelot, val, m, reg, 0)
7045e256365SVladimir Oltean 
705886e1387SVladimir Oltean #define ocelot_field_write(ocelot, reg, val) regmap_field_write((ocelot)->regfields[(reg)], (val))
706886e1387SVladimir Oltean #define ocelot_field_read(ocelot, reg, val) regmap_field_read((ocelot)->regfields[(reg)], (val))
707886e1387SVladimir Oltean #define ocelot_fields_write(ocelot, id, reg, val) regmap_fields_write((ocelot)->regfields[(reg)], (id), (val))
708886e1387SVladimir Oltean #define ocelot_fields_read(ocelot, id, reg, val) regmap_fields_read((ocelot)->regfields[(reg)], (id), (val))
709886e1387SVladimir Oltean 
7103c0e37a9SVladimir Oltean #define ocelot_target_read_ix(ocelot, target, reg, gi, ri) \
7113c0e37a9SVladimir Oltean 	__ocelot_target_read_ix(ocelot, target, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
7123c0e37a9SVladimir Oltean #define ocelot_target_read_gix(ocelot, target, reg, gi) \
7133c0e37a9SVladimir Oltean 	__ocelot_target_read_ix(ocelot, target, reg, reg##_GSZ * (gi))
7143c0e37a9SVladimir Oltean #define ocelot_target_read_rix(ocelot, target, reg, ri) \
7153c0e37a9SVladimir Oltean 	__ocelot_target_read_ix(ocelot, target, reg, reg##_RSZ * (ri))
7163c0e37a9SVladimir Oltean #define ocelot_target_read(ocelot, target, reg) \
7173c0e37a9SVladimir Oltean 	__ocelot_target_read_ix(ocelot, target, reg, 0)
7183c0e37a9SVladimir Oltean 
7193c0e37a9SVladimir Oltean #define ocelot_target_write_ix(ocelot, target, val, reg, gi, ri) \
7203c0e37a9SVladimir Oltean 	__ocelot_target_write_ix(ocelot, target, val, reg, reg##_GSZ * (gi) + reg##_RSZ * (ri))
7213c0e37a9SVladimir Oltean #define ocelot_target_write_gix(ocelot, target, val, reg, gi) \
7223c0e37a9SVladimir Oltean 	__ocelot_target_write_ix(ocelot, target, val, reg, reg##_GSZ * (gi))
7233c0e37a9SVladimir Oltean #define ocelot_target_write_rix(ocelot, target, val, reg, ri) \
7243c0e37a9SVladimir Oltean 	__ocelot_target_write_ix(ocelot, target, val, reg, reg##_RSZ * (ri))
7253c0e37a9SVladimir Oltean #define ocelot_target_write(ocelot, target, val, reg) \
7263c0e37a9SVladimir Oltean 	__ocelot_target_write_ix(ocelot, target, val, reg, 0)
7273c0e37a9SVladimir Oltean 
7285e256365SVladimir Oltean /* I/O */
7295e256365SVladimir Oltean u32 ocelot_port_readl(struct ocelot_port *port, u32 reg);
7305e256365SVladimir Oltean void ocelot_port_writel(struct ocelot_port *port, u32 val, u32 reg);
7315e256365SVladimir Oltean u32 __ocelot_read_ix(struct ocelot *ocelot, u32 reg, u32 offset);
7325e256365SVladimir Oltean void __ocelot_write_ix(struct ocelot *ocelot, u32 val, u32 reg, u32 offset);
7335e256365SVladimir Oltean void __ocelot_rmw_ix(struct ocelot *ocelot, u32 val, u32 mask, u32 reg,
7345e256365SVladimir Oltean 		     u32 offset);
7353c0e37a9SVladimir Oltean u32 __ocelot_target_read_ix(struct ocelot *ocelot, enum ocelot_target target,
7363c0e37a9SVladimir Oltean 			    u32 reg, u32 offset);
7373c0e37a9SVladimir Oltean void __ocelot_target_write_ix(struct ocelot *ocelot, enum ocelot_target target,
7383c0e37a9SVladimir Oltean 			      u32 val, u32 reg, u32 offset);
7395e256365SVladimir Oltean 
7405e256365SVladimir Oltean /* Hardware initialization */
7415e256365SVladimir Oltean int ocelot_regfields_init(struct ocelot *ocelot,
7425e256365SVladimir Oltean 			  const struct reg_field *const regfields);
7435e256365SVladimir Oltean struct regmap *ocelot_regmap_init(struct ocelot *ocelot, struct resource *res);
7445e256365SVladimir Oltean int ocelot_init(struct ocelot *ocelot);
7455e256365SVladimir Oltean void ocelot_deinit(struct ocelot *ocelot);
7465e256365SVladimir Oltean void ocelot_init_port(struct ocelot *ocelot, int port);
747e5fb512dSVladimir Oltean void ocelot_deinit_port(struct ocelot *ocelot, int port);
7485e256365SVladimir Oltean 
7495e256365SVladimir Oltean /* DSA callbacks */
7505e256365SVladimir Oltean void ocelot_port_enable(struct ocelot *ocelot, int port,
7515e256365SVladimir Oltean 			struct phy_device *phy);
7525e256365SVladimir Oltean void ocelot_port_disable(struct ocelot *ocelot, int port);
7535e256365SVladimir Oltean void ocelot_get_strings(struct ocelot *ocelot, int port, u32 sset, u8 *data);
7545e256365SVladimir Oltean void ocelot_get_ethtool_stats(struct ocelot *ocelot, int port, u64 *data);
7555e256365SVladimir Oltean int ocelot_get_sset_count(struct ocelot *ocelot, int port, int sset);
7565e256365SVladimir Oltean int ocelot_get_ts_info(struct ocelot *ocelot, int port,
7575e256365SVladimir Oltean 		       struct ethtool_ts_info *info);
7585e256365SVladimir Oltean void ocelot_set_ageing_time(struct ocelot *ocelot, unsigned int msecs);
7595e256365SVladimir Oltean void ocelot_adjust_link(struct ocelot *ocelot, int port,
7605e256365SVladimir Oltean 			struct phy_device *phydev);
761bae33f2bSVladimir Oltean int ocelot_port_vlan_filtering(struct ocelot *ocelot, int port, bool enabled);
7625e256365SVladimir Oltean void ocelot_bridge_stp_state_set(struct ocelot *ocelot, int port, u8 state);
7635e256365SVladimir Oltean int ocelot_port_bridge_join(struct ocelot *ocelot, int port,
7645e256365SVladimir Oltean 			    struct net_device *bridge);
7655e256365SVladimir Oltean int ocelot_port_bridge_leave(struct ocelot *ocelot, int port,
7665e256365SVladimir Oltean 			     struct net_device *bridge);
7675e256365SVladimir Oltean int ocelot_fdb_dump(struct ocelot *ocelot, int port,
7685e256365SVladimir Oltean 		    dsa_fdb_dump_cb_t *cb, void *data);
7695e256365SVladimir Oltean int ocelot_fdb_add(struct ocelot *ocelot, int port,
77087b0f983SVladimir Oltean 		   const unsigned char *addr, u16 vid);
7715e256365SVladimir Oltean int ocelot_fdb_del(struct ocelot *ocelot, int port,
7725e256365SVladimir Oltean 		   const unsigned char *addr, u16 vid);
7732f0402feSVladimir Oltean int ocelot_vlan_prepare(struct ocelot *ocelot, int port, u16 vid, bool pvid,
7742f0402feSVladimir Oltean 			bool untagged);
7755e256365SVladimir Oltean int ocelot_vlan_add(struct ocelot *ocelot, int port, u16 vid, bool pvid,
7765e256365SVladimir Oltean 		    bool untagged);
7775e256365SVladimir Oltean int ocelot_vlan_del(struct ocelot *ocelot, int port, u16 vid);
778f145922dSYangbo Lu int ocelot_hwstamp_get(struct ocelot *ocelot, int port, struct ifreq *ifr);
779f145922dSYangbo Lu int ocelot_hwstamp_set(struct ocelot *ocelot, int port, struct ifreq *ifr);
780e2f9a8feSVladimir Oltean void ocelot_port_add_txtstamp_skb(struct ocelot *ocelot, int port,
781e2f9a8feSVladimir Oltean 				  struct sk_buff *clone);
782e23a7b3eSYangbo Lu void ocelot_get_txtstamp(struct ocelot *ocelot);
7830b912fc9SVladimir Oltean void ocelot_port_set_maxlen(struct ocelot *ocelot, int port, size_t sdu);
7840b912fc9SVladimir Oltean int ocelot_get_max_mtu(struct ocelot *ocelot, int port);
785fc411eaaSVladimir Oltean int ocelot_port_policer_add(struct ocelot *ocelot, int port,
786fc411eaaSVladimir Oltean 			    struct ocelot_policer *pol);
787fc411eaaSVladimir Oltean int ocelot_port_policer_del(struct ocelot *ocelot, int port);
78807d985eeSVladimir Oltean int ocelot_cls_flower_replace(struct ocelot *ocelot, int port,
78907d985eeSVladimir Oltean 			      struct flow_cls_offload *f, bool ingress);
79007d985eeSVladimir Oltean int ocelot_cls_flower_destroy(struct ocelot *ocelot, int port,
79107d985eeSVladimir Oltean 			      struct flow_cls_offload *f, bool ingress);
79207d985eeSVladimir Oltean int ocelot_cls_flower_stats(struct ocelot *ocelot, int port,
79307d985eeSVladimir Oltean 			    struct flow_cls_offload *f, bool ingress);
794209edf95SVladimir Oltean int ocelot_port_mdb_add(struct ocelot *ocelot, int port,
795209edf95SVladimir Oltean 			const struct switchdev_obj_port_mdb *mdb);
796209edf95SVladimir Oltean int ocelot_port_mdb_del(struct ocelot *ocelot, int port,
797209edf95SVladimir Oltean 			const struct switchdev_obj_port_mdb *mdb);
7985e256365SVladimir Oltean 
799f59fd9caSVladimir Oltean int ocelot_devlink_sb_register(struct ocelot *ocelot);
800f59fd9caSVladimir Oltean void ocelot_devlink_sb_unregister(struct ocelot *ocelot);
801f59fd9caSVladimir Oltean int ocelot_sb_pool_get(struct ocelot *ocelot, unsigned int sb_index,
802f59fd9caSVladimir Oltean 		       u16 pool_index,
803f59fd9caSVladimir Oltean 		       struct devlink_sb_pool_info *pool_info);
804f59fd9caSVladimir Oltean int ocelot_sb_pool_set(struct ocelot *ocelot, unsigned int sb_index,
805f59fd9caSVladimir Oltean 		       u16 pool_index, u32 size,
806f59fd9caSVladimir Oltean 		       enum devlink_sb_threshold_type threshold_type,
807f59fd9caSVladimir Oltean 		       struct netlink_ext_ack *extack);
808f59fd9caSVladimir Oltean int ocelot_sb_port_pool_get(struct ocelot *ocelot, int port,
809f59fd9caSVladimir Oltean 			    unsigned int sb_index, u16 pool_index,
810f59fd9caSVladimir Oltean 			    u32 *p_threshold);
811f59fd9caSVladimir Oltean int ocelot_sb_port_pool_set(struct ocelot *ocelot, int port,
812f59fd9caSVladimir Oltean 			    unsigned int sb_index, u16 pool_index,
813f59fd9caSVladimir Oltean 			    u32 threshold, struct netlink_ext_ack *extack);
814f59fd9caSVladimir Oltean int ocelot_sb_tc_pool_bind_get(struct ocelot *ocelot, int port,
815f59fd9caSVladimir Oltean 			       unsigned int sb_index, u16 tc_index,
816f59fd9caSVladimir Oltean 			       enum devlink_sb_pool_type pool_type,
817f59fd9caSVladimir Oltean 			       u16 *p_pool_index, u32 *p_threshold);
818f59fd9caSVladimir Oltean int ocelot_sb_tc_pool_bind_set(struct ocelot *ocelot, int port,
819f59fd9caSVladimir Oltean 			       unsigned int sb_index, u16 tc_index,
820f59fd9caSVladimir Oltean 			       enum devlink_sb_pool_type pool_type,
821f59fd9caSVladimir Oltean 			       u16 pool_index, u32 threshold,
822f59fd9caSVladimir Oltean 			       struct netlink_ext_ack *extack);
823f59fd9caSVladimir Oltean int ocelot_sb_occ_snapshot(struct ocelot *ocelot, unsigned int sb_index);
824f59fd9caSVladimir Oltean int ocelot_sb_occ_max_clear(struct ocelot *ocelot, unsigned int sb_index);
825f59fd9caSVladimir Oltean int ocelot_sb_occ_port_pool_get(struct ocelot *ocelot, int port,
826f59fd9caSVladimir Oltean 				unsigned int sb_index, u16 pool_index,
827f59fd9caSVladimir Oltean 				u32 *p_cur, u32 *p_max);
828f59fd9caSVladimir Oltean int ocelot_sb_occ_tc_port_bind_get(struct ocelot *ocelot, int port,
829f59fd9caSVladimir Oltean 				   unsigned int sb_index, u16 tc_index,
830f59fd9caSVladimir Oltean 				   enum devlink_sb_pool_type pool_type,
831f59fd9caSVladimir Oltean 				   u32 *p_cur, u32 *p_max);
832f59fd9caSVladimir Oltean 
8335e256365SVladimir Oltean #endif
834