xref: /OK3568_Linux_fs/kernel/drivers/net/ethernet/mellanox/mlxsw/spectrum.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
2*4882a593Smuzhiyun /* Copyright (c) 2015-2018 Mellanox Technologies. All rights reserved */
3*4882a593Smuzhiyun 
4*4882a593Smuzhiyun #ifndef _MLXSW_SPECTRUM_H
5*4882a593Smuzhiyun #define _MLXSW_SPECTRUM_H
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #include <linux/types.h>
8*4882a593Smuzhiyun #include <linux/netdevice.h>
9*4882a593Smuzhiyun #include <linux/rhashtable.h>
10*4882a593Smuzhiyun #include <linux/bitops.h>
11*4882a593Smuzhiyun #include <linux/if_bridge.h>
12*4882a593Smuzhiyun #include <linux/if_vlan.h>
13*4882a593Smuzhiyun #include <linux/list.h>
14*4882a593Smuzhiyun #include <linux/dcbnl.h>
15*4882a593Smuzhiyun #include <linux/in6.h>
16*4882a593Smuzhiyun #include <linux/notifier.h>
17*4882a593Smuzhiyun #include <linux/net_namespace.h>
18*4882a593Smuzhiyun #include <net/psample.h>
19*4882a593Smuzhiyun #include <net/pkt_cls.h>
20*4882a593Smuzhiyun #include <net/red.h>
21*4882a593Smuzhiyun #include <net/vxlan.h>
22*4882a593Smuzhiyun #include <net/flow_offload.h>
23*4882a593Smuzhiyun #include <net/inet_ecn.h>
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun #include "port.h"
26*4882a593Smuzhiyun #include "core.h"
27*4882a593Smuzhiyun #include "core_acl_flex_keys.h"
28*4882a593Smuzhiyun #include "core_acl_flex_actions.h"
29*4882a593Smuzhiyun #include "reg.h"
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun #define MLXSW_SP_DEFAULT_VID (VLAN_N_VID - 1)
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun #define MLXSW_SP_FID_8021D_MAX 1024
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun #define MLXSW_SP_MID_MAX 7000
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun #define MLXSW_SP_KVD_LINEAR_SIZE 98304 /* entries */
38*4882a593Smuzhiyun #define MLXSW_SP_KVD_GRANULARITY 128
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun #define MLXSW_SP_RESOURCE_NAME_KVD "kvd"
41*4882a593Smuzhiyun #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR "linear"
42*4882a593Smuzhiyun #define MLXSW_SP_RESOURCE_NAME_KVD_HASH_SINGLE "hash_single"
43*4882a593Smuzhiyun #define MLXSW_SP_RESOURCE_NAME_KVD_HASH_DOUBLE "hash_double"
44*4882a593Smuzhiyun #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_SINGLES "singles"
45*4882a593Smuzhiyun #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_CHUNKS "chunks"
46*4882a593Smuzhiyun #define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_LARGE_CHUNKS "large_chunks"
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun #define MLXSW_SP_RESOURCE_NAME_SPAN "span_agents"
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun #define MLXSW_SP_RESOURCE_NAME_COUNTERS "counters"
51*4882a593Smuzhiyun #define MLXSW_SP_RESOURCE_NAME_COUNTERS_FLOW "flow"
52*4882a593Smuzhiyun #define MLXSW_SP_RESOURCE_NAME_COUNTERS_RIF "rif"
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun enum mlxsw_sp_resource_id {
55*4882a593Smuzhiyun 	MLXSW_SP_RESOURCE_KVD = 1,
56*4882a593Smuzhiyun 	MLXSW_SP_RESOURCE_KVD_LINEAR,
57*4882a593Smuzhiyun 	MLXSW_SP_RESOURCE_KVD_HASH_SINGLE,
58*4882a593Smuzhiyun 	MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE,
59*4882a593Smuzhiyun 	MLXSW_SP_RESOURCE_KVD_LINEAR_SINGLE,
60*4882a593Smuzhiyun 	MLXSW_SP_RESOURCE_KVD_LINEAR_CHUNKS,
61*4882a593Smuzhiyun 	MLXSW_SP_RESOURCE_KVD_LINEAR_LARGE_CHUNKS,
62*4882a593Smuzhiyun 	MLXSW_SP_RESOURCE_SPAN,
63*4882a593Smuzhiyun 	MLXSW_SP_RESOURCE_COUNTERS,
64*4882a593Smuzhiyun 	MLXSW_SP_RESOURCE_COUNTERS_FLOW,
65*4882a593Smuzhiyun 	MLXSW_SP_RESOURCE_COUNTERS_RIF,
66*4882a593Smuzhiyun 	MLXSW_SP_RESOURCE_GLOBAL_POLICERS,
67*4882a593Smuzhiyun 	MLXSW_SP_RESOURCE_SINGLE_RATE_POLICERS,
68*4882a593Smuzhiyun };
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun struct mlxsw_sp_port;
71*4882a593Smuzhiyun struct mlxsw_sp_rif;
72*4882a593Smuzhiyun struct mlxsw_sp_span_entry;
73*4882a593Smuzhiyun enum mlxsw_sp_l3proto;
74*4882a593Smuzhiyun union mlxsw_sp_l3addr;
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun struct mlxsw_sp_upper {
77*4882a593Smuzhiyun 	struct net_device *dev;
78*4882a593Smuzhiyun 	unsigned int ref_count;
79*4882a593Smuzhiyun };
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun enum mlxsw_sp_rif_type {
82*4882a593Smuzhiyun 	MLXSW_SP_RIF_TYPE_SUBPORT,
83*4882a593Smuzhiyun 	MLXSW_SP_RIF_TYPE_VLAN,
84*4882a593Smuzhiyun 	MLXSW_SP_RIF_TYPE_FID,
85*4882a593Smuzhiyun 	MLXSW_SP_RIF_TYPE_IPIP_LB, /* IP-in-IP loopback. */
86*4882a593Smuzhiyun 	MLXSW_SP_RIF_TYPE_MAX,
87*4882a593Smuzhiyun };
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun struct mlxsw_sp_rif_ops;
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun extern const struct mlxsw_sp_rif_ops *mlxsw_sp1_rif_ops_arr[];
92*4882a593Smuzhiyun extern const struct mlxsw_sp_rif_ops *mlxsw_sp2_rif_ops_arr[];
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun enum mlxsw_sp_fid_type {
95*4882a593Smuzhiyun 	MLXSW_SP_FID_TYPE_8021Q,
96*4882a593Smuzhiyun 	MLXSW_SP_FID_TYPE_8021D,
97*4882a593Smuzhiyun 	MLXSW_SP_FID_TYPE_RFID,
98*4882a593Smuzhiyun 	MLXSW_SP_FID_TYPE_DUMMY,
99*4882a593Smuzhiyun 	MLXSW_SP_FID_TYPE_MAX,
100*4882a593Smuzhiyun };
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun enum mlxsw_sp_nve_type {
103*4882a593Smuzhiyun 	MLXSW_SP_NVE_TYPE_VXLAN,
104*4882a593Smuzhiyun };
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun struct mlxsw_sp_mid {
107*4882a593Smuzhiyun 	struct list_head list;
108*4882a593Smuzhiyun 	unsigned char addr[ETH_ALEN];
109*4882a593Smuzhiyun 	u16 fid;
110*4882a593Smuzhiyun 	u16 mid;
111*4882a593Smuzhiyun 	bool in_hw;
112*4882a593Smuzhiyun 	unsigned long *ports_in_mid; /* bits array */
113*4882a593Smuzhiyun };
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun struct mlxsw_sp_sb;
116*4882a593Smuzhiyun struct mlxsw_sp_bridge;
117*4882a593Smuzhiyun struct mlxsw_sp_router;
118*4882a593Smuzhiyun struct mlxsw_sp_mr;
119*4882a593Smuzhiyun struct mlxsw_sp_acl;
120*4882a593Smuzhiyun struct mlxsw_sp_counter_pool;
121*4882a593Smuzhiyun struct mlxsw_sp_fid_core;
122*4882a593Smuzhiyun struct mlxsw_sp_kvdl;
123*4882a593Smuzhiyun struct mlxsw_sp_nve;
124*4882a593Smuzhiyun struct mlxsw_sp_kvdl_ops;
125*4882a593Smuzhiyun struct mlxsw_sp_mr_tcam_ops;
126*4882a593Smuzhiyun struct mlxsw_sp_acl_rulei_ops;
127*4882a593Smuzhiyun struct mlxsw_sp_acl_tcam_ops;
128*4882a593Smuzhiyun struct mlxsw_sp_nve_ops;
129*4882a593Smuzhiyun struct mlxsw_sp_sb_ops;
130*4882a593Smuzhiyun struct mlxsw_sp_sb_vals;
131*4882a593Smuzhiyun struct mlxsw_sp_port_type_speed_ops;
132*4882a593Smuzhiyun struct mlxsw_sp_ptp_state;
133*4882a593Smuzhiyun struct mlxsw_sp_ptp_ops;
134*4882a593Smuzhiyun struct mlxsw_sp_span_ops;
135*4882a593Smuzhiyun struct mlxsw_sp_qdisc_state;
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun struct mlxsw_sp_port_mapping {
138*4882a593Smuzhiyun 	u8 module;
139*4882a593Smuzhiyun 	u8 width;
140*4882a593Smuzhiyun 	u8 lane;
141*4882a593Smuzhiyun };
142*4882a593Smuzhiyun 
143*4882a593Smuzhiyun struct mlxsw_sp {
144*4882a593Smuzhiyun 	struct mlxsw_sp_port **ports;
145*4882a593Smuzhiyun 	struct mlxsw_core *core;
146*4882a593Smuzhiyun 	const struct mlxsw_bus_info *bus_info;
147*4882a593Smuzhiyun 	unsigned char base_mac[ETH_ALEN];
148*4882a593Smuzhiyun 	const unsigned char *mac_mask;
149*4882a593Smuzhiyun 	struct mlxsw_sp_upper *lags;
150*4882a593Smuzhiyun 	struct mlxsw_sp_port_mapping **port_mapping;
151*4882a593Smuzhiyun 	struct mlxsw_sp_sb *sb;
152*4882a593Smuzhiyun 	struct mlxsw_sp_bridge *bridge;
153*4882a593Smuzhiyun 	struct mlxsw_sp_router *router;
154*4882a593Smuzhiyun 	struct mlxsw_sp_mr *mr;
155*4882a593Smuzhiyun 	struct mlxsw_afa *afa;
156*4882a593Smuzhiyun 	struct mlxsw_sp_acl *acl;
157*4882a593Smuzhiyun 	struct mlxsw_sp_fid_core *fid_core;
158*4882a593Smuzhiyun 	struct mlxsw_sp_policer_core *policer_core;
159*4882a593Smuzhiyun 	struct mlxsw_sp_kvdl *kvdl;
160*4882a593Smuzhiyun 	struct mlxsw_sp_nve *nve;
161*4882a593Smuzhiyun 	struct notifier_block netdevice_nb;
162*4882a593Smuzhiyun 	struct mlxsw_sp_ptp_clock *clock;
163*4882a593Smuzhiyun 	struct mlxsw_sp_ptp_state *ptp_state;
164*4882a593Smuzhiyun 	struct mlxsw_sp_counter_pool *counter_pool;
165*4882a593Smuzhiyun 	struct mlxsw_sp_span *span;
166*4882a593Smuzhiyun 	struct mlxsw_sp_trap *trap;
167*4882a593Smuzhiyun 	const struct mlxsw_sp_kvdl_ops *kvdl_ops;
168*4882a593Smuzhiyun 	const struct mlxsw_afa_ops *afa_ops;
169*4882a593Smuzhiyun 	const struct mlxsw_afk_ops *afk_ops;
170*4882a593Smuzhiyun 	const struct mlxsw_sp_mr_tcam_ops *mr_tcam_ops;
171*4882a593Smuzhiyun 	const struct mlxsw_sp_acl_rulei_ops *acl_rulei_ops;
172*4882a593Smuzhiyun 	const struct mlxsw_sp_acl_tcam_ops *acl_tcam_ops;
173*4882a593Smuzhiyun 	const struct mlxsw_sp_nve_ops **nve_ops_arr;
174*4882a593Smuzhiyun 	const struct mlxsw_sp_rif_ops **rif_ops_arr;
175*4882a593Smuzhiyun 	const struct mlxsw_sp_sb_vals *sb_vals;
176*4882a593Smuzhiyun 	const struct mlxsw_sp_sb_ops *sb_ops;
177*4882a593Smuzhiyun 	const struct mlxsw_sp_port_type_speed_ops *port_type_speed_ops;
178*4882a593Smuzhiyun 	const struct mlxsw_sp_ptp_ops *ptp_ops;
179*4882a593Smuzhiyun 	const struct mlxsw_sp_span_ops *span_ops;
180*4882a593Smuzhiyun 	const struct mlxsw_sp_policer_core_ops *policer_core_ops;
181*4882a593Smuzhiyun 	const struct mlxsw_sp_trap_ops *trap_ops;
182*4882a593Smuzhiyun 	const struct mlxsw_listener *listeners;
183*4882a593Smuzhiyun 	size_t listeners_count;
184*4882a593Smuzhiyun 	u32 lowest_shaper_bs;
185*4882a593Smuzhiyun };
186*4882a593Smuzhiyun 
187*4882a593Smuzhiyun struct mlxsw_sp_ptp_ops {
188*4882a593Smuzhiyun 	struct mlxsw_sp_ptp_clock *
189*4882a593Smuzhiyun 		(*clock_init)(struct mlxsw_sp *mlxsw_sp, struct device *dev);
190*4882a593Smuzhiyun 	void (*clock_fini)(struct mlxsw_sp_ptp_clock *clock);
191*4882a593Smuzhiyun 
192*4882a593Smuzhiyun 	struct mlxsw_sp_ptp_state *(*init)(struct mlxsw_sp *mlxsw_sp);
193*4882a593Smuzhiyun 	void (*fini)(struct mlxsw_sp_ptp_state *ptp_state);
194*4882a593Smuzhiyun 
195*4882a593Smuzhiyun 	/* Notify a driver that a packet that might be PTP was received. Driver
196*4882a593Smuzhiyun 	 * is responsible for freeing the passed-in SKB.
197*4882a593Smuzhiyun 	 */
198*4882a593Smuzhiyun 	void (*receive)(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
199*4882a593Smuzhiyun 			u8 local_port);
200*4882a593Smuzhiyun 
201*4882a593Smuzhiyun 	/* Notify a driver that a timestamped packet was transmitted. Driver
202*4882a593Smuzhiyun 	 * is responsible for freeing the passed-in SKB.
203*4882a593Smuzhiyun 	 */
204*4882a593Smuzhiyun 	void (*transmitted)(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
205*4882a593Smuzhiyun 			    u8 local_port);
206*4882a593Smuzhiyun 
207*4882a593Smuzhiyun 	int (*hwtstamp_get)(struct mlxsw_sp_port *mlxsw_sp_port,
208*4882a593Smuzhiyun 			    struct hwtstamp_config *config);
209*4882a593Smuzhiyun 	int (*hwtstamp_set)(struct mlxsw_sp_port *mlxsw_sp_port,
210*4882a593Smuzhiyun 			    struct hwtstamp_config *config);
211*4882a593Smuzhiyun 	void (*shaper_work)(struct work_struct *work);
212*4882a593Smuzhiyun 	int (*get_ts_info)(struct mlxsw_sp *mlxsw_sp,
213*4882a593Smuzhiyun 			   struct ethtool_ts_info *info);
214*4882a593Smuzhiyun 	int (*get_stats_count)(void);
215*4882a593Smuzhiyun 	void (*get_stats_strings)(u8 **p);
216*4882a593Smuzhiyun 	void (*get_stats)(struct mlxsw_sp_port *mlxsw_sp_port,
217*4882a593Smuzhiyun 			  u64 *data, int data_index);
218*4882a593Smuzhiyun };
219*4882a593Smuzhiyun 
220*4882a593Smuzhiyun static inline struct mlxsw_sp_upper *
mlxsw_sp_lag_get(struct mlxsw_sp * mlxsw_sp,u16 lag_id)221*4882a593Smuzhiyun mlxsw_sp_lag_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id)
222*4882a593Smuzhiyun {
223*4882a593Smuzhiyun 	return &mlxsw_sp->lags[lag_id];
224*4882a593Smuzhiyun }
225*4882a593Smuzhiyun 
226*4882a593Smuzhiyun struct mlxsw_sp_port_pcpu_stats {
227*4882a593Smuzhiyun 	u64			rx_packets;
228*4882a593Smuzhiyun 	u64			rx_bytes;
229*4882a593Smuzhiyun 	u64			tx_packets;
230*4882a593Smuzhiyun 	u64			tx_bytes;
231*4882a593Smuzhiyun 	struct u64_stats_sync	syncp;
232*4882a593Smuzhiyun 	u32			tx_dropped;
233*4882a593Smuzhiyun };
234*4882a593Smuzhiyun 
235*4882a593Smuzhiyun struct mlxsw_sp_port_sample {
236*4882a593Smuzhiyun 	struct psample_group *psample_group;
237*4882a593Smuzhiyun 	u32 trunc_size;
238*4882a593Smuzhiyun 	u32 rate;
239*4882a593Smuzhiyun 	bool truncate;
240*4882a593Smuzhiyun };
241*4882a593Smuzhiyun 
242*4882a593Smuzhiyun struct mlxsw_sp_bridge_port;
243*4882a593Smuzhiyun struct mlxsw_sp_fid;
244*4882a593Smuzhiyun 
245*4882a593Smuzhiyun struct mlxsw_sp_port_vlan {
246*4882a593Smuzhiyun 	struct list_head list;
247*4882a593Smuzhiyun 	struct mlxsw_sp_port *mlxsw_sp_port;
248*4882a593Smuzhiyun 	struct mlxsw_sp_fid *fid;
249*4882a593Smuzhiyun 	u16 vid;
250*4882a593Smuzhiyun 	struct mlxsw_sp_bridge_port *bridge_port;
251*4882a593Smuzhiyun 	struct list_head bridge_vlan_node;
252*4882a593Smuzhiyun };
253*4882a593Smuzhiyun 
254*4882a593Smuzhiyun /* No need an internal lock; At worse - miss a single periodic iteration */
255*4882a593Smuzhiyun struct mlxsw_sp_port_xstats {
256*4882a593Smuzhiyun 	u64 ecn;
257*4882a593Smuzhiyun 	u64 wred_drop[TC_MAX_QUEUE];
258*4882a593Smuzhiyun 	u64 tail_drop[TC_MAX_QUEUE];
259*4882a593Smuzhiyun 	u64 backlog[TC_MAX_QUEUE];
260*4882a593Smuzhiyun 	u64 tx_bytes[IEEE_8021QAZ_MAX_TCS];
261*4882a593Smuzhiyun 	u64 tx_packets[IEEE_8021QAZ_MAX_TCS];
262*4882a593Smuzhiyun };
263*4882a593Smuzhiyun 
264*4882a593Smuzhiyun struct mlxsw_sp_ptp_port_dir_stats {
265*4882a593Smuzhiyun 	u64 packets;
266*4882a593Smuzhiyun 	u64 timestamps;
267*4882a593Smuzhiyun };
268*4882a593Smuzhiyun 
269*4882a593Smuzhiyun struct mlxsw_sp_ptp_port_stats {
270*4882a593Smuzhiyun 	struct mlxsw_sp_ptp_port_dir_stats rx_gcd;
271*4882a593Smuzhiyun 	struct mlxsw_sp_ptp_port_dir_stats tx_gcd;
272*4882a593Smuzhiyun };
273*4882a593Smuzhiyun 
274*4882a593Smuzhiyun struct mlxsw_sp_port {
275*4882a593Smuzhiyun 	struct net_device *dev;
276*4882a593Smuzhiyun 	struct mlxsw_sp_port_pcpu_stats __percpu *pcpu_stats;
277*4882a593Smuzhiyun 	struct mlxsw_sp *mlxsw_sp;
278*4882a593Smuzhiyun 	u8 local_port;
279*4882a593Smuzhiyun 	u8 lagged:1,
280*4882a593Smuzhiyun 	   split:1;
281*4882a593Smuzhiyun 	u16 pvid;
282*4882a593Smuzhiyun 	u16 lag_id;
283*4882a593Smuzhiyun 	struct {
284*4882a593Smuzhiyun 		u8 tx_pause:1,
285*4882a593Smuzhiyun 		   rx_pause:1,
286*4882a593Smuzhiyun 		   autoneg:1;
287*4882a593Smuzhiyun 	} link;
288*4882a593Smuzhiyun 	struct {
289*4882a593Smuzhiyun 		struct ieee_ets *ets;
290*4882a593Smuzhiyun 		struct ieee_maxrate *maxrate;
291*4882a593Smuzhiyun 		struct ieee_pfc *pfc;
292*4882a593Smuzhiyun 		enum mlxsw_reg_qpts_trust_state trust_state;
293*4882a593Smuzhiyun 	} dcb;
294*4882a593Smuzhiyun 	struct mlxsw_sp_port_mapping mapping; /* mapping is constant during the
295*4882a593Smuzhiyun 					       * mlxsw_sp_port lifetime, however
296*4882a593Smuzhiyun 					       * the same localport can have
297*4882a593Smuzhiyun 					       * different mapping.
298*4882a593Smuzhiyun 					       */
299*4882a593Smuzhiyun 	struct {
300*4882a593Smuzhiyun 		#define MLXSW_HW_STATS_UPDATE_TIME HZ
301*4882a593Smuzhiyun 		struct rtnl_link_stats64 stats;
302*4882a593Smuzhiyun 		struct mlxsw_sp_port_xstats xstats;
303*4882a593Smuzhiyun 		struct delayed_work update_dw;
304*4882a593Smuzhiyun 	} periodic_hw_stats;
305*4882a593Smuzhiyun 	struct mlxsw_sp_port_sample __rcu *sample;
306*4882a593Smuzhiyun 	struct list_head vlans_list;
307*4882a593Smuzhiyun 	struct mlxsw_sp_port_vlan *default_vlan;
308*4882a593Smuzhiyun 	struct mlxsw_sp_qdisc_state *qdisc;
309*4882a593Smuzhiyun 	unsigned acl_rule_count;
310*4882a593Smuzhiyun 	struct mlxsw_sp_flow_block *ing_flow_block;
311*4882a593Smuzhiyun 	struct mlxsw_sp_flow_block *eg_flow_block;
312*4882a593Smuzhiyun 	struct {
313*4882a593Smuzhiyun 		struct delayed_work shaper_dw;
314*4882a593Smuzhiyun 		struct hwtstamp_config hwtstamp_config;
315*4882a593Smuzhiyun 		u16 ing_types;
316*4882a593Smuzhiyun 		u16 egr_types;
317*4882a593Smuzhiyun 		struct mlxsw_sp_ptp_port_stats stats;
318*4882a593Smuzhiyun 	} ptp;
319*4882a593Smuzhiyun 	u8 split_base_local_port;
320*4882a593Smuzhiyun 	int max_mtu;
321*4882a593Smuzhiyun 	u32 max_speed;
322*4882a593Smuzhiyun 	struct mlxsw_sp_hdroom *hdroom;
323*4882a593Smuzhiyun 	u64 module_overheat_initial_val;
324*4882a593Smuzhiyun };
325*4882a593Smuzhiyun 
326*4882a593Smuzhiyun struct mlxsw_sp_port_type_speed_ops {
327*4882a593Smuzhiyun 	void (*from_ptys_supported_port)(struct mlxsw_sp *mlxsw_sp,
328*4882a593Smuzhiyun 					 u32 ptys_eth_proto,
329*4882a593Smuzhiyun 					 struct ethtool_link_ksettings *cmd);
330*4882a593Smuzhiyun 	void (*from_ptys_link)(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto,
331*4882a593Smuzhiyun 			       u8 width, unsigned long *mode);
332*4882a593Smuzhiyun 	u32 (*from_ptys_speed)(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto);
333*4882a593Smuzhiyun 	void (*from_ptys_speed_duplex)(struct mlxsw_sp *mlxsw_sp,
334*4882a593Smuzhiyun 				       bool carrier_ok, u32 ptys_eth_proto,
335*4882a593Smuzhiyun 				       struct ethtool_link_ksettings *cmd);
336*4882a593Smuzhiyun 	int (*ptys_max_speed)(struct mlxsw_sp_port *mlxsw_sp_port, u32 *p_max_speed);
337*4882a593Smuzhiyun 	u32 (*to_ptys_advert_link)(struct mlxsw_sp *mlxsw_sp, u8 width,
338*4882a593Smuzhiyun 				   const struct ethtool_link_ksettings *cmd);
339*4882a593Smuzhiyun 	u32 (*to_ptys_speed)(struct mlxsw_sp *mlxsw_sp, u8 width, u32 speed);
340*4882a593Smuzhiyun 	void (*reg_ptys_eth_pack)(struct mlxsw_sp *mlxsw_sp, char *payload,
341*4882a593Smuzhiyun 				  u8 local_port, u32 proto_admin, bool autoneg);
342*4882a593Smuzhiyun 	void (*reg_ptys_eth_unpack)(struct mlxsw_sp *mlxsw_sp, char *payload,
343*4882a593Smuzhiyun 				    u32 *p_eth_proto_cap,
344*4882a593Smuzhiyun 				    u32 *p_eth_proto_admin,
345*4882a593Smuzhiyun 				    u32 *p_eth_proto_oper);
346*4882a593Smuzhiyun 	u32 (*ptys_proto_cap_masked_get)(u32 eth_proto_cap);
347*4882a593Smuzhiyun };
348*4882a593Smuzhiyun 
mlxsw_sp_tunnel_ecn_decap(u8 outer_ecn,u8 inner_ecn,bool * trap_en)349*4882a593Smuzhiyun static inline u8 mlxsw_sp_tunnel_ecn_decap(u8 outer_ecn, u8 inner_ecn,
350*4882a593Smuzhiyun 					   bool *trap_en)
351*4882a593Smuzhiyun {
352*4882a593Smuzhiyun 	bool set_ce = false;
353*4882a593Smuzhiyun 
354*4882a593Smuzhiyun 	*trap_en = !!__INET_ECN_decapsulate(outer_ecn, inner_ecn, &set_ce);
355*4882a593Smuzhiyun 	if (set_ce)
356*4882a593Smuzhiyun 		return INET_ECN_CE;
357*4882a593Smuzhiyun 	else if (outer_ecn == INET_ECN_ECT_1 && inner_ecn == INET_ECN_ECT_0)
358*4882a593Smuzhiyun 		return INET_ECN_ECT_1;
359*4882a593Smuzhiyun 	else
360*4882a593Smuzhiyun 		return inner_ecn;
361*4882a593Smuzhiyun }
362*4882a593Smuzhiyun 
363*4882a593Smuzhiyun static inline struct net_device *
mlxsw_sp_bridge_vxlan_dev_find(struct net_device * br_dev)364*4882a593Smuzhiyun mlxsw_sp_bridge_vxlan_dev_find(struct net_device *br_dev)
365*4882a593Smuzhiyun {
366*4882a593Smuzhiyun 	struct net_device *dev;
367*4882a593Smuzhiyun 	struct list_head *iter;
368*4882a593Smuzhiyun 
369*4882a593Smuzhiyun 	netdev_for_each_lower_dev(br_dev, dev, iter) {
370*4882a593Smuzhiyun 		if (netif_is_vxlan(dev))
371*4882a593Smuzhiyun 			return dev;
372*4882a593Smuzhiyun 	}
373*4882a593Smuzhiyun 
374*4882a593Smuzhiyun 	return NULL;
375*4882a593Smuzhiyun }
376*4882a593Smuzhiyun 
mlxsw_sp_bridge_has_vxlan(struct net_device * br_dev)377*4882a593Smuzhiyun static inline bool mlxsw_sp_bridge_has_vxlan(struct net_device *br_dev)
378*4882a593Smuzhiyun {
379*4882a593Smuzhiyun 	return !!mlxsw_sp_bridge_vxlan_dev_find(br_dev);
380*4882a593Smuzhiyun }
381*4882a593Smuzhiyun 
382*4882a593Smuzhiyun static inline int
mlxsw_sp_vxlan_mapped_vid(const struct net_device * vxlan_dev,u16 * p_vid)383*4882a593Smuzhiyun mlxsw_sp_vxlan_mapped_vid(const struct net_device *vxlan_dev, u16 *p_vid)
384*4882a593Smuzhiyun {
385*4882a593Smuzhiyun 	struct bridge_vlan_info vinfo;
386*4882a593Smuzhiyun 	u16 vid = 0;
387*4882a593Smuzhiyun 	int err;
388*4882a593Smuzhiyun 
389*4882a593Smuzhiyun 	err = br_vlan_get_pvid(vxlan_dev, &vid);
390*4882a593Smuzhiyun 	if (err || !vid)
391*4882a593Smuzhiyun 		goto out;
392*4882a593Smuzhiyun 
393*4882a593Smuzhiyun 	err = br_vlan_get_info(vxlan_dev, vid, &vinfo);
394*4882a593Smuzhiyun 	if (err || !(vinfo.flags & BRIDGE_VLAN_INFO_UNTAGGED))
395*4882a593Smuzhiyun 		vid = 0;
396*4882a593Smuzhiyun 
397*4882a593Smuzhiyun out:
398*4882a593Smuzhiyun 	*p_vid = vid;
399*4882a593Smuzhiyun 	return err;
400*4882a593Smuzhiyun }
401*4882a593Smuzhiyun 
402*4882a593Smuzhiyun static inline bool
mlxsw_sp_port_is_pause_en(const struct mlxsw_sp_port * mlxsw_sp_port)403*4882a593Smuzhiyun mlxsw_sp_port_is_pause_en(const struct mlxsw_sp_port *mlxsw_sp_port)
404*4882a593Smuzhiyun {
405*4882a593Smuzhiyun 	return mlxsw_sp_port->link.tx_pause || mlxsw_sp_port->link.rx_pause;
406*4882a593Smuzhiyun }
407*4882a593Smuzhiyun 
408*4882a593Smuzhiyun static inline struct mlxsw_sp_port *
mlxsw_sp_port_lagged_get(struct mlxsw_sp * mlxsw_sp,u16 lag_id,u8 port_index)409*4882a593Smuzhiyun mlxsw_sp_port_lagged_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id, u8 port_index)
410*4882a593Smuzhiyun {
411*4882a593Smuzhiyun 	struct mlxsw_sp_port *mlxsw_sp_port;
412*4882a593Smuzhiyun 	u8 local_port;
413*4882a593Smuzhiyun 
414*4882a593Smuzhiyun 	local_port = mlxsw_core_lag_mapping_get(mlxsw_sp->core,
415*4882a593Smuzhiyun 						lag_id, port_index);
416*4882a593Smuzhiyun 	mlxsw_sp_port = mlxsw_sp->ports[local_port];
417*4882a593Smuzhiyun 	return mlxsw_sp_port && mlxsw_sp_port->lagged ? mlxsw_sp_port : NULL;
418*4882a593Smuzhiyun }
419*4882a593Smuzhiyun 
420*4882a593Smuzhiyun static inline struct mlxsw_sp_port_vlan *
mlxsw_sp_port_vlan_find_by_vid(const struct mlxsw_sp_port * mlxsw_sp_port,u16 vid)421*4882a593Smuzhiyun mlxsw_sp_port_vlan_find_by_vid(const struct mlxsw_sp_port *mlxsw_sp_port,
422*4882a593Smuzhiyun 			       u16 vid)
423*4882a593Smuzhiyun {
424*4882a593Smuzhiyun 	struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
425*4882a593Smuzhiyun 
426*4882a593Smuzhiyun 	list_for_each_entry(mlxsw_sp_port_vlan, &mlxsw_sp_port->vlans_list,
427*4882a593Smuzhiyun 			    list) {
428*4882a593Smuzhiyun 		if (mlxsw_sp_port_vlan->vid == vid)
429*4882a593Smuzhiyun 			return mlxsw_sp_port_vlan;
430*4882a593Smuzhiyun 	}
431*4882a593Smuzhiyun 
432*4882a593Smuzhiyun 	return NULL;
433*4882a593Smuzhiyun }
434*4882a593Smuzhiyun 
435*4882a593Smuzhiyun enum mlxsw_sp_flood_type {
436*4882a593Smuzhiyun 	MLXSW_SP_FLOOD_TYPE_UC,
437*4882a593Smuzhiyun 	MLXSW_SP_FLOOD_TYPE_BC,
438*4882a593Smuzhiyun 	MLXSW_SP_FLOOD_TYPE_MC,
439*4882a593Smuzhiyun };
440*4882a593Smuzhiyun 
441*4882a593Smuzhiyun int mlxsw_sp_port_get_stats_raw(struct net_device *dev, int grp,
442*4882a593Smuzhiyun 				int prio, char *ppcnt_pl);
443*4882a593Smuzhiyun int mlxsw_sp_port_admin_status_set(struct mlxsw_sp_port *mlxsw_sp_port,
444*4882a593Smuzhiyun 				   bool is_up);
445*4882a593Smuzhiyun 
446*4882a593Smuzhiyun /* spectrum_buffers.c */
447*4882a593Smuzhiyun struct mlxsw_sp_hdroom_prio {
448*4882a593Smuzhiyun 	/* Number of port buffer associated with this priority. This is the
449*4882a593Smuzhiyun 	 * actually configured value.
450*4882a593Smuzhiyun 	 */
451*4882a593Smuzhiyun 	u8 buf_idx;
452*4882a593Smuzhiyun 	/* Value of buf_idx deduced from the DCB ETS configuration. */
453*4882a593Smuzhiyun 	u8 ets_buf_idx;
454*4882a593Smuzhiyun 	/* Value of buf_idx taken from the dcbnl_setbuffer configuration. */
455*4882a593Smuzhiyun 	u8 set_buf_idx;
456*4882a593Smuzhiyun 	bool lossy;
457*4882a593Smuzhiyun };
458*4882a593Smuzhiyun 
459*4882a593Smuzhiyun struct mlxsw_sp_hdroom_buf {
460*4882a593Smuzhiyun 	u32 thres_cells;
461*4882a593Smuzhiyun 	u32 size_cells;
462*4882a593Smuzhiyun 	/* Size requirement form dcbnl_setbuffer. */
463*4882a593Smuzhiyun 	u32 set_size_cells;
464*4882a593Smuzhiyun 	bool lossy;
465*4882a593Smuzhiyun };
466*4882a593Smuzhiyun 
467*4882a593Smuzhiyun enum mlxsw_sp_hdroom_mode {
468*4882a593Smuzhiyun 	MLXSW_SP_HDROOM_MODE_DCB,
469*4882a593Smuzhiyun 	MLXSW_SP_HDROOM_MODE_TC,
470*4882a593Smuzhiyun };
471*4882a593Smuzhiyun 
472*4882a593Smuzhiyun #define MLXSW_SP_PB_COUNT 10
473*4882a593Smuzhiyun 
474*4882a593Smuzhiyun struct mlxsw_sp_hdroom {
475*4882a593Smuzhiyun 	enum mlxsw_sp_hdroom_mode mode;
476*4882a593Smuzhiyun 
477*4882a593Smuzhiyun 	struct {
478*4882a593Smuzhiyun 		struct mlxsw_sp_hdroom_prio prio[IEEE_8021Q_MAX_PRIORITIES];
479*4882a593Smuzhiyun 	} prios;
480*4882a593Smuzhiyun 	struct {
481*4882a593Smuzhiyun 		struct mlxsw_sp_hdroom_buf buf[MLXSW_SP_PB_COUNT];
482*4882a593Smuzhiyun 	} bufs;
483*4882a593Smuzhiyun 	struct {
484*4882a593Smuzhiyun 		/* Size actually configured for the internal buffer. Equal to
485*4882a593Smuzhiyun 		 * reserve when internal buffer is enabled.
486*4882a593Smuzhiyun 		 */
487*4882a593Smuzhiyun 		u32 size_cells;
488*4882a593Smuzhiyun 		/* Space reserved in the headroom for the internal buffer. Port
489*4882a593Smuzhiyun 		 * buffers are not allowed to grow into this space.
490*4882a593Smuzhiyun 		 */
491*4882a593Smuzhiyun 		u32 reserve_cells;
492*4882a593Smuzhiyun 		bool enable;
493*4882a593Smuzhiyun 	} int_buf;
494*4882a593Smuzhiyun 	int delay_bytes;
495*4882a593Smuzhiyun 	int mtu;
496*4882a593Smuzhiyun };
497*4882a593Smuzhiyun 
498*4882a593Smuzhiyun int mlxsw_sp_buffers_init(struct mlxsw_sp *mlxsw_sp);
499*4882a593Smuzhiyun void mlxsw_sp_buffers_fini(struct mlxsw_sp *mlxsw_sp);
500*4882a593Smuzhiyun int mlxsw_sp_port_buffers_init(struct mlxsw_sp_port *mlxsw_sp_port);
501*4882a593Smuzhiyun void mlxsw_sp_port_buffers_fini(struct mlxsw_sp_port *mlxsw_sp_port);
502*4882a593Smuzhiyun int mlxsw_sp_sb_pool_get(struct mlxsw_core *mlxsw_core,
503*4882a593Smuzhiyun 			 unsigned int sb_index, u16 pool_index,
504*4882a593Smuzhiyun 			 struct devlink_sb_pool_info *pool_info);
505*4882a593Smuzhiyun int mlxsw_sp_sb_pool_set(struct mlxsw_core *mlxsw_core,
506*4882a593Smuzhiyun 			 unsigned int sb_index, u16 pool_index, u32 size,
507*4882a593Smuzhiyun 			 enum devlink_sb_threshold_type threshold_type,
508*4882a593Smuzhiyun 			 struct netlink_ext_ack *extack);
509*4882a593Smuzhiyun int mlxsw_sp_sb_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
510*4882a593Smuzhiyun 			      unsigned int sb_index, u16 pool_index,
511*4882a593Smuzhiyun 			      u32 *p_threshold);
512*4882a593Smuzhiyun int mlxsw_sp_sb_port_pool_set(struct mlxsw_core_port *mlxsw_core_port,
513*4882a593Smuzhiyun 			      unsigned int sb_index, u16 pool_index,
514*4882a593Smuzhiyun 			      u32 threshold, struct netlink_ext_ack *extack);
515*4882a593Smuzhiyun int mlxsw_sp_sb_tc_pool_bind_get(struct mlxsw_core_port *mlxsw_core_port,
516*4882a593Smuzhiyun 				 unsigned int sb_index, u16 tc_index,
517*4882a593Smuzhiyun 				 enum devlink_sb_pool_type pool_type,
518*4882a593Smuzhiyun 				 u16 *p_pool_index, u32 *p_threshold);
519*4882a593Smuzhiyun int mlxsw_sp_sb_tc_pool_bind_set(struct mlxsw_core_port *mlxsw_core_port,
520*4882a593Smuzhiyun 				 unsigned int sb_index, u16 tc_index,
521*4882a593Smuzhiyun 				 enum devlink_sb_pool_type pool_type,
522*4882a593Smuzhiyun 				 u16 pool_index, u32 threshold,
523*4882a593Smuzhiyun 				 struct netlink_ext_ack *extack);
524*4882a593Smuzhiyun int mlxsw_sp_sb_occ_snapshot(struct mlxsw_core *mlxsw_core,
525*4882a593Smuzhiyun 			     unsigned int sb_index);
526*4882a593Smuzhiyun int mlxsw_sp_sb_occ_max_clear(struct mlxsw_core *mlxsw_core,
527*4882a593Smuzhiyun 			      unsigned int sb_index);
528*4882a593Smuzhiyun int mlxsw_sp_sb_occ_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
529*4882a593Smuzhiyun 				  unsigned int sb_index, u16 pool_index,
530*4882a593Smuzhiyun 				  u32 *p_cur, u32 *p_max);
531*4882a593Smuzhiyun int mlxsw_sp_sb_occ_tc_port_bind_get(struct mlxsw_core_port *mlxsw_core_port,
532*4882a593Smuzhiyun 				     unsigned int sb_index, u16 tc_index,
533*4882a593Smuzhiyun 				     enum devlink_sb_pool_type pool_type,
534*4882a593Smuzhiyun 				     u32 *p_cur, u32 *p_max);
535*4882a593Smuzhiyun u32 mlxsw_sp_cells_bytes(const struct mlxsw_sp *mlxsw_sp, u32 cells);
536*4882a593Smuzhiyun u32 mlxsw_sp_bytes_cells(const struct mlxsw_sp *mlxsw_sp, u32 bytes);
537*4882a593Smuzhiyun void mlxsw_sp_hdroom_prios_reset_buf_idx(struct mlxsw_sp_hdroom *hdroom);
538*4882a593Smuzhiyun void mlxsw_sp_hdroom_bufs_reset_lossiness(struct mlxsw_sp_hdroom *hdroom);
539*4882a593Smuzhiyun void mlxsw_sp_hdroom_bufs_reset_sizes(struct mlxsw_sp_port *mlxsw_sp_port,
540*4882a593Smuzhiyun 				      struct mlxsw_sp_hdroom *hdroom);
541*4882a593Smuzhiyun int mlxsw_sp_hdroom_configure(struct mlxsw_sp_port *mlxsw_sp_port,
542*4882a593Smuzhiyun 			      const struct mlxsw_sp_hdroom *hdroom);
543*4882a593Smuzhiyun 
544*4882a593Smuzhiyun extern const struct mlxsw_sp_sb_vals mlxsw_sp1_sb_vals;
545*4882a593Smuzhiyun extern const struct mlxsw_sp_sb_vals mlxsw_sp2_sb_vals;
546*4882a593Smuzhiyun 
547*4882a593Smuzhiyun extern const struct mlxsw_sp_sb_ops mlxsw_sp1_sb_ops;
548*4882a593Smuzhiyun extern const struct mlxsw_sp_sb_ops mlxsw_sp2_sb_ops;
549*4882a593Smuzhiyun extern const struct mlxsw_sp_sb_ops mlxsw_sp3_sb_ops;
550*4882a593Smuzhiyun 
551*4882a593Smuzhiyun /* spectrum_switchdev.c */
552*4882a593Smuzhiyun int mlxsw_sp_switchdev_init(struct mlxsw_sp *mlxsw_sp);
553*4882a593Smuzhiyun void mlxsw_sp_switchdev_fini(struct mlxsw_sp *mlxsw_sp);
554*4882a593Smuzhiyun int mlxsw_sp_rif_fdb_op(struct mlxsw_sp *mlxsw_sp, const char *mac, u16 fid,
555*4882a593Smuzhiyun 			bool adding);
556*4882a593Smuzhiyun void
557*4882a593Smuzhiyun mlxsw_sp_port_vlan_bridge_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
558*4882a593Smuzhiyun int mlxsw_sp_port_bridge_join(struct mlxsw_sp_port *mlxsw_sp_port,
559*4882a593Smuzhiyun 			      struct net_device *brport_dev,
560*4882a593Smuzhiyun 			      struct net_device *br_dev,
561*4882a593Smuzhiyun 			      struct netlink_ext_ack *extack);
562*4882a593Smuzhiyun void mlxsw_sp_port_bridge_leave(struct mlxsw_sp_port *mlxsw_sp_port,
563*4882a593Smuzhiyun 				struct net_device *brport_dev,
564*4882a593Smuzhiyun 				struct net_device *br_dev);
565*4882a593Smuzhiyun bool mlxsw_sp_bridge_device_is_offloaded(const struct mlxsw_sp *mlxsw_sp,
566*4882a593Smuzhiyun 					 const struct net_device *br_dev);
567*4882a593Smuzhiyun int mlxsw_sp_bridge_vxlan_join(struct mlxsw_sp *mlxsw_sp,
568*4882a593Smuzhiyun 			       const struct net_device *br_dev,
569*4882a593Smuzhiyun 			       const struct net_device *vxlan_dev, u16 vid,
570*4882a593Smuzhiyun 			       struct netlink_ext_ack *extack);
571*4882a593Smuzhiyun void mlxsw_sp_bridge_vxlan_leave(struct mlxsw_sp *mlxsw_sp,
572*4882a593Smuzhiyun 				 const struct net_device *vxlan_dev);
573*4882a593Smuzhiyun extern struct notifier_block mlxsw_sp_switchdev_notifier;
574*4882a593Smuzhiyun 
575*4882a593Smuzhiyun /* spectrum.c */
576*4882a593Smuzhiyun void mlxsw_sp_rx_listener_no_mark_func(struct sk_buff *skb,
577*4882a593Smuzhiyun 				       u8 local_port, void *priv);
578*4882a593Smuzhiyun void mlxsw_sp_ptp_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
579*4882a593Smuzhiyun 			  u8 local_port);
580*4882a593Smuzhiyun void mlxsw_sp_sample_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
581*4882a593Smuzhiyun 			     u8 local_port);
582*4882a593Smuzhiyun int mlxsw_sp_port_speed_get(struct mlxsw_sp_port *mlxsw_sp_port, u32 *speed);
583*4882a593Smuzhiyun int mlxsw_sp_port_ets_set(struct mlxsw_sp_port *mlxsw_sp_port,
584*4882a593Smuzhiyun 			  enum mlxsw_reg_qeec_hr hr, u8 index, u8 next_index,
585*4882a593Smuzhiyun 			  bool dwrr, u8 dwrr_weight);
586*4882a593Smuzhiyun int mlxsw_sp_port_prio_tc_set(struct mlxsw_sp_port *mlxsw_sp_port,
587*4882a593Smuzhiyun 			      u8 switch_prio, u8 tclass);
588*4882a593Smuzhiyun int mlxsw_sp_port_ets_maxrate_set(struct mlxsw_sp_port *mlxsw_sp_port,
589*4882a593Smuzhiyun 				  enum mlxsw_reg_qeec_hr hr, u8 index,
590*4882a593Smuzhiyun 				  u8 next_index, u32 maxrate, u8 burst_size);
591*4882a593Smuzhiyun enum mlxsw_reg_spms_state mlxsw_sp_stp_spms_state(u8 stp_state);
592*4882a593Smuzhiyun int mlxsw_sp_port_vid_stp_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
593*4882a593Smuzhiyun 			      u8 state);
594*4882a593Smuzhiyun int mlxsw_sp_port_vp_mode_set(struct mlxsw_sp_port *mlxsw_sp_port, bool enable);
595*4882a593Smuzhiyun int mlxsw_sp_port_vid_learning_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
596*4882a593Smuzhiyun 				   bool learn_enable);
597*4882a593Smuzhiyun int mlxsw_sp_port_pvid_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
598*4882a593Smuzhiyun struct mlxsw_sp_port_vlan *
599*4882a593Smuzhiyun mlxsw_sp_port_vlan_create(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
600*4882a593Smuzhiyun void mlxsw_sp_port_vlan_destroy(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
601*4882a593Smuzhiyun int mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid_begin,
602*4882a593Smuzhiyun 			   u16 vid_end, bool is_member, bool untagged);
603*4882a593Smuzhiyun int mlxsw_sp_flow_counter_get(struct mlxsw_sp *mlxsw_sp,
604*4882a593Smuzhiyun 			      unsigned int counter_index, u64 *packets,
605*4882a593Smuzhiyun 			      u64 *bytes);
606*4882a593Smuzhiyun int mlxsw_sp_flow_counter_alloc(struct mlxsw_sp *mlxsw_sp,
607*4882a593Smuzhiyun 				unsigned int *p_counter_index);
608*4882a593Smuzhiyun void mlxsw_sp_flow_counter_free(struct mlxsw_sp *mlxsw_sp,
609*4882a593Smuzhiyun 				unsigned int counter_index);
610*4882a593Smuzhiyun bool mlxsw_sp_port_dev_check(const struct net_device *dev);
611*4882a593Smuzhiyun struct mlxsw_sp *mlxsw_sp_lower_get(struct net_device *dev);
612*4882a593Smuzhiyun struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find(struct net_device *dev);
613*4882a593Smuzhiyun struct mlxsw_sp_port *mlxsw_sp_port_lower_dev_hold(struct net_device *dev);
614*4882a593Smuzhiyun void mlxsw_sp_port_dev_put(struct mlxsw_sp_port *mlxsw_sp_port);
615*4882a593Smuzhiyun struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find_rcu(struct net_device *dev);
616*4882a593Smuzhiyun 
617*4882a593Smuzhiyun /* spectrum_dcb.c */
618*4882a593Smuzhiyun #ifdef CONFIG_MLXSW_SPECTRUM_DCB
619*4882a593Smuzhiyun int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port);
620*4882a593Smuzhiyun void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port);
621*4882a593Smuzhiyun #else
mlxsw_sp_port_dcb_init(struct mlxsw_sp_port * mlxsw_sp_port)622*4882a593Smuzhiyun static inline int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port)
623*4882a593Smuzhiyun {
624*4882a593Smuzhiyun 	return 0;
625*4882a593Smuzhiyun }
mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port * mlxsw_sp_port)626*4882a593Smuzhiyun static inline void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port)
627*4882a593Smuzhiyun {}
628*4882a593Smuzhiyun #endif
629*4882a593Smuzhiyun 
630*4882a593Smuzhiyun /* spectrum_router.c */
631*4882a593Smuzhiyun enum mlxsw_sp_l3proto {
632*4882a593Smuzhiyun 	MLXSW_SP_L3_PROTO_IPV4,
633*4882a593Smuzhiyun 	MLXSW_SP_L3_PROTO_IPV6,
634*4882a593Smuzhiyun #define MLXSW_SP_L3_PROTO_MAX	(MLXSW_SP_L3_PROTO_IPV6 + 1)
635*4882a593Smuzhiyun };
636*4882a593Smuzhiyun 
637*4882a593Smuzhiyun union mlxsw_sp_l3addr {
638*4882a593Smuzhiyun 	__be32 addr4;
639*4882a593Smuzhiyun 	struct in6_addr addr6;
640*4882a593Smuzhiyun };
641*4882a593Smuzhiyun 
642*4882a593Smuzhiyun int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp,
643*4882a593Smuzhiyun 			 struct netlink_ext_ack *extack);
644*4882a593Smuzhiyun void mlxsw_sp_router_fini(struct mlxsw_sp *mlxsw_sp);
645*4882a593Smuzhiyun int mlxsw_sp_netdevice_router_port_event(struct net_device *dev,
646*4882a593Smuzhiyun 					 unsigned long event, void *ptr);
647*4882a593Smuzhiyun void mlxsw_sp_rif_macvlan_del(struct mlxsw_sp *mlxsw_sp,
648*4882a593Smuzhiyun 			      const struct net_device *macvlan_dev);
649*4882a593Smuzhiyun int mlxsw_sp_inetaddr_valid_event(struct notifier_block *unused,
650*4882a593Smuzhiyun 				  unsigned long event, void *ptr);
651*4882a593Smuzhiyun int mlxsw_sp_inet6addr_valid_event(struct notifier_block *unused,
652*4882a593Smuzhiyun 				   unsigned long event, void *ptr);
653*4882a593Smuzhiyun int mlxsw_sp_netdevice_vrf_event(struct net_device *l3_dev, unsigned long event,
654*4882a593Smuzhiyun 				 struct netdev_notifier_changeupper_info *info);
655*4882a593Smuzhiyun bool mlxsw_sp_netdev_is_ipip_ol(const struct mlxsw_sp *mlxsw_sp,
656*4882a593Smuzhiyun 				const struct net_device *dev);
657*4882a593Smuzhiyun bool mlxsw_sp_netdev_is_ipip_ul(struct mlxsw_sp *mlxsw_sp,
658*4882a593Smuzhiyun 				const struct net_device *dev);
659*4882a593Smuzhiyun int mlxsw_sp_netdevice_ipip_ol_event(struct mlxsw_sp *mlxsw_sp,
660*4882a593Smuzhiyun 				     struct net_device *l3_dev,
661*4882a593Smuzhiyun 				     unsigned long event,
662*4882a593Smuzhiyun 				     struct netdev_notifier_info *info);
663*4882a593Smuzhiyun int
664*4882a593Smuzhiyun mlxsw_sp_netdevice_ipip_ul_event(struct mlxsw_sp *mlxsw_sp,
665*4882a593Smuzhiyun 				 struct net_device *l3_dev,
666*4882a593Smuzhiyun 				 unsigned long event,
667*4882a593Smuzhiyun 				 struct netdev_notifier_info *info);
668*4882a593Smuzhiyun void
669*4882a593Smuzhiyun mlxsw_sp_port_vlan_router_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
670*4882a593Smuzhiyun void mlxsw_sp_rif_destroy_by_dev(struct mlxsw_sp *mlxsw_sp,
671*4882a593Smuzhiyun 				 struct net_device *dev);
672*4882a593Smuzhiyun bool mlxsw_sp_rif_exists(struct mlxsw_sp *mlxsw_sp,
673*4882a593Smuzhiyun 			 const struct net_device *dev);
674*4882a593Smuzhiyun u16 mlxsw_sp_rif_vid(struct mlxsw_sp *mlxsw_sp, const struct net_device *dev);
675*4882a593Smuzhiyun u8 mlxsw_sp_router_port(const struct mlxsw_sp *mlxsw_sp);
676*4882a593Smuzhiyun int mlxsw_sp_router_nve_promote_decap(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id,
677*4882a593Smuzhiyun 				      enum mlxsw_sp_l3proto ul_proto,
678*4882a593Smuzhiyun 				      const union mlxsw_sp_l3addr *ul_sip,
679*4882a593Smuzhiyun 				      u32 tunnel_index);
680*4882a593Smuzhiyun void mlxsw_sp_router_nve_demote_decap(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id,
681*4882a593Smuzhiyun 				      enum mlxsw_sp_l3proto ul_proto,
682*4882a593Smuzhiyun 				      const union mlxsw_sp_l3addr *ul_sip);
683*4882a593Smuzhiyun int mlxsw_sp_router_tb_id_vr_id(struct mlxsw_sp *mlxsw_sp, u32 tb_id,
684*4882a593Smuzhiyun 				u16 *vr_id);
685*4882a593Smuzhiyun int mlxsw_sp_router_ul_rif_get(struct mlxsw_sp *mlxsw_sp, u32 ul_tb_id,
686*4882a593Smuzhiyun 			       u16 *ul_rif_index);
687*4882a593Smuzhiyun void mlxsw_sp_router_ul_rif_put(struct mlxsw_sp *mlxsw_sp, u16 ul_rif_index);
688*4882a593Smuzhiyun 
689*4882a593Smuzhiyun /* spectrum_kvdl.c */
690*4882a593Smuzhiyun enum mlxsw_sp_kvdl_entry_type {
691*4882a593Smuzhiyun 	MLXSW_SP_KVDL_ENTRY_TYPE_ADJ,
692*4882a593Smuzhiyun 	MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET,
693*4882a593Smuzhiyun 	MLXSW_SP_KVDL_ENTRY_TYPE_PBS,
694*4882a593Smuzhiyun 	MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR,
695*4882a593Smuzhiyun 	MLXSW_SP_KVDL_ENTRY_TYPE_TNUMT,
696*4882a593Smuzhiyun };
697*4882a593Smuzhiyun 
698*4882a593Smuzhiyun static inline unsigned int
mlxsw_sp_kvdl_entry_size(enum mlxsw_sp_kvdl_entry_type type)699*4882a593Smuzhiyun mlxsw_sp_kvdl_entry_size(enum mlxsw_sp_kvdl_entry_type type)
700*4882a593Smuzhiyun {
701*4882a593Smuzhiyun 	switch (type) {
702*4882a593Smuzhiyun 	case MLXSW_SP_KVDL_ENTRY_TYPE_ADJ:
703*4882a593Smuzhiyun 	case MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET:
704*4882a593Smuzhiyun 	case MLXSW_SP_KVDL_ENTRY_TYPE_PBS:
705*4882a593Smuzhiyun 	case MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR:
706*4882a593Smuzhiyun 	case MLXSW_SP_KVDL_ENTRY_TYPE_TNUMT:
707*4882a593Smuzhiyun 	default:
708*4882a593Smuzhiyun 		return 1;
709*4882a593Smuzhiyun 	}
710*4882a593Smuzhiyun }
711*4882a593Smuzhiyun 
712*4882a593Smuzhiyun struct mlxsw_sp_kvdl_ops {
713*4882a593Smuzhiyun 	size_t priv_size;
714*4882a593Smuzhiyun 	int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
715*4882a593Smuzhiyun 	void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
716*4882a593Smuzhiyun 	int (*alloc)(struct mlxsw_sp *mlxsw_sp, void *priv,
717*4882a593Smuzhiyun 		     enum mlxsw_sp_kvdl_entry_type type,
718*4882a593Smuzhiyun 		     unsigned int entry_count, u32 *p_entry_index);
719*4882a593Smuzhiyun 	void (*free)(struct mlxsw_sp *mlxsw_sp, void *priv,
720*4882a593Smuzhiyun 		     enum mlxsw_sp_kvdl_entry_type type,
721*4882a593Smuzhiyun 		     unsigned int entry_count, int entry_index);
722*4882a593Smuzhiyun 	int (*alloc_size_query)(struct mlxsw_sp *mlxsw_sp, void *priv,
723*4882a593Smuzhiyun 				enum mlxsw_sp_kvdl_entry_type type,
724*4882a593Smuzhiyun 				unsigned int entry_count,
725*4882a593Smuzhiyun 				unsigned int *p_alloc_count);
726*4882a593Smuzhiyun 	int (*resources_register)(struct mlxsw_sp *mlxsw_sp, void *priv);
727*4882a593Smuzhiyun };
728*4882a593Smuzhiyun 
729*4882a593Smuzhiyun int mlxsw_sp_kvdl_init(struct mlxsw_sp *mlxsw_sp);
730*4882a593Smuzhiyun void mlxsw_sp_kvdl_fini(struct mlxsw_sp *mlxsw_sp);
731*4882a593Smuzhiyun int mlxsw_sp_kvdl_alloc(struct mlxsw_sp *mlxsw_sp,
732*4882a593Smuzhiyun 			enum mlxsw_sp_kvdl_entry_type type,
733*4882a593Smuzhiyun 			unsigned int entry_count, u32 *p_entry_index);
734*4882a593Smuzhiyun void mlxsw_sp_kvdl_free(struct mlxsw_sp *mlxsw_sp,
735*4882a593Smuzhiyun 			enum mlxsw_sp_kvdl_entry_type type,
736*4882a593Smuzhiyun 			unsigned int entry_count, int entry_index);
737*4882a593Smuzhiyun int mlxsw_sp_kvdl_alloc_count_query(struct mlxsw_sp *mlxsw_sp,
738*4882a593Smuzhiyun 				    enum mlxsw_sp_kvdl_entry_type type,
739*4882a593Smuzhiyun 				    unsigned int entry_count,
740*4882a593Smuzhiyun 				    unsigned int *p_alloc_count);
741*4882a593Smuzhiyun 
742*4882a593Smuzhiyun /* spectrum1_kvdl.c */
743*4882a593Smuzhiyun extern const struct mlxsw_sp_kvdl_ops mlxsw_sp1_kvdl_ops;
744*4882a593Smuzhiyun int mlxsw_sp1_kvdl_resources_register(struct mlxsw_core *mlxsw_core);
745*4882a593Smuzhiyun 
746*4882a593Smuzhiyun /* spectrum2_kvdl.c */
747*4882a593Smuzhiyun extern const struct mlxsw_sp_kvdl_ops mlxsw_sp2_kvdl_ops;
748*4882a593Smuzhiyun 
749*4882a593Smuzhiyun struct mlxsw_sp_acl_rule_info {
750*4882a593Smuzhiyun 	unsigned int priority;
751*4882a593Smuzhiyun 	struct mlxsw_afk_element_values values;
752*4882a593Smuzhiyun 	struct mlxsw_afa_block *act_block;
753*4882a593Smuzhiyun 	u8 action_created:1,
754*4882a593Smuzhiyun 	   ingress_bind_blocker:1,
755*4882a593Smuzhiyun 	   egress_bind_blocker:1,
756*4882a593Smuzhiyun 	   counter_valid:1,
757*4882a593Smuzhiyun 	   policer_index_valid:1;
758*4882a593Smuzhiyun 	unsigned int counter_index;
759*4882a593Smuzhiyun 	u16 policer_index;
760*4882a593Smuzhiyun };
761*4882a593Smuzhiyun 
762*4882a593Smuzhiyun /* spectrum_flow.c */
763*4882a593Smuzhiyun struct mlxsw_sp_flow_block {
764*4882a593Smuzhiyun 	struct list_head binding_list;
765*4882a593Smuzhiyun 	struct {
766*4882a593Smuzhiyun 		struct list_head list;
767*4882a593Smuzhiyun 		unsigned int min_prio;
768*4882a593Smuzhiyun 		unsigned int max_prio;
769*4882a593Smuzhiyun 	} mall;
770*4882a593Smuzhiyun 	struct mlxsw_sp_acl_ruleset *ruleset_zero;
771*4882a593Smuzhiyun 	struct mlxsw_sp *mlxsw_sp;
772*4882a593Smuzhiyun 	unsigned int rule_count;
773*4882a593Smuzhiyun 	unsigned int disable_count;
774*4882a593Smuzhiyun 	unsigned int ingress_blocker_rule_count;
775*4882a593Smuzhiyun 	unsigned int egress_blocker_rule_count;
776*4882a593Smuzhiyun 	unsigned int ingress_binding_count;
777*4882a593Smuzhiyun 	unsigned int egress_binding_count;
778*4882a593Smuzhiyun 	struct net *net;
779*4882a593Smuzhiyun };
780*4882a593Smuzhiyun 
781*4882a593Smuzhiyun struct mlxsw_sp_flow_block_binding {
782*4882a593Smuzhiyun 	struct list_head list;
783*4882a593Smuzhiyun 	struct mlxsw_sp_port *mlxsw_sp_port;
784*4882a593Smuzhiyun 	bool ingress;
785*4882a593Smuzhiyun };
786*4882a593Smuzhiyun 
787*4882a593Smuzhiyun static inline struct mlxsw_sp *
mlxsw_sp_flow_block_mlxsw_sp(struct mlxsw_sp_flow_block * block)788*4882a593Smuzhiyun mlxsw_sp_flow_block_mlxsw_sp(struct mlxsw_sp_flow_block *block)
789*4882a593Smuzhiyun {
790*4882a593Smuzhiyun 	return block->mlxsw_sp;
791*4882a593Smuzhiyun }
792*4882a593Smuzhiyun 
793*4882a593Smuzhiyun static inline unsigned int
mlxsw_sp_flow_block_rule_count(const struct mlxsw_sp_flow_block * block)794*4882a593Smuzhiyun mlxsw_sp_flow_block_rule_count(const struct mlxsw_sp_flow_block *block)
795*4882a593Smuzhiyun {
796*4882a593Smuzhiyun 	return block ? block->rule_count : 0;
797*4882a593Smuzhiyun }
798*4882a593Smuzhiyun 
799*4882a593Smuzhiyun static inline void
mlxsw_sp_flow_block_disable_inc(struct mlxsw_sp_flow_block * block)800*4882a593Smuzhiyun mlxsw_sp_flow_block_disable_inc(struct mlxsw_sp_flow_block *block)
801*4882a593Smuzhiyun {
802*4882a593Smuzhiyun 	if (block)
803*4882a593Smuzhiyun 		block->disable_count++;
804*4882a593Smuzhiyun }
805*4882a593Smuzhiyun 
806*4882a593Smuzhiyun static inline void
mlxsw_sp_flow_block_disable_dec(struct mlxsw_sp_flow_block * block)807*4882a593Smuzhiyun mlxsw_sp_flow_block_disable_dec(struct mlxsw_sp_flow_block *block)
808*4882a593Smuzhiyun {
809*4882a593Smuzhiyun 	if (block)
810*4882a593Smuzhiyun 		block->disable_count--;
811*4882a593Smuzhiyun }
812*4882a593Smuzhiyun 
813*4882a593Smuzhiyun static inline bool
mlxsw_sp_flow_block_disabled(const struct mlxsw_sp_flow_block * block)814*4882a593Smuzhiyun mlxsw_sp_flow_block_disabled(const struct mlxsw_sp_flow_block *block)
815*4882a593Smuzhiyun {
816*4882a593Smuzhiyun 	return block->disable_count;
817*4882a593Smuzhiyun }
818*4882a593Smuzhiyun 
819*4882a593Smuzhiyun static inline bool
mlxsw_sp_flow_block_is_egress_bound(const struct mlxsw_sp_flow_block * block)820*4882a593Smuzhiyun mlxsw_sp_flow_block_is_egress_bound(const struct mlxsw_sp_flow_block *block)
821*4882a593Smuzhiyun {
822*4882a593Smuzhiyun 	return block->egress_binding_count;
823*4882a593Smuzhiyun }
824*4882a593Smuzhiyun 
825*4882a593Smuzhiyun static inline bool
mlxsw_sp_flow_block_is_ingress_bound(const struct mlxsw_sp_flow_block * block)826*4882a593Smuzhiyun mlxsw_sp_flow_block_is_ingress_bound(const struct mlxsw_sp_flow_block *block)
827*4882a593Smuzhiyun {
828*4882a593Smuzhiyun 	return block->ingress_binding_count;
829*4882a593Smuzhiyun }
830*4882a593Smuzhiyun 
831*4882a593Smuzhiyun static inline bool
mlxsw_sp_flow_block_is_mixed_bound(const struct mlxsw_sp_flow_block * block)832*4882a593Smuzhiyun mlxsw_sp_flow_block_is_mixed_bound(const struct mlxsw_sp_flow_block *block)
833*4882a593Smuzhiyun {
834*4882a593Smuzhiyun 	return block->ingress_binding_count && block->egress_binding_count;
835*4882a593Smuzhiyun }
836*4882a593Smuzhiyun 
837*4882a593Smuzhiyun struct mlxsw_sp_flow_block *mlxsw_sp_flow_block_create(struct mlxsw_sp *mlxsw_sp,
838*4882a593Smuzhiyun 						       struct net *net);
839*4882a593Smuzhiyun void mlxsw_sp_flow_block_destroy(struct mlxsw_sp_flow_block *block);
840*4882a593Smuzhiyun int mlxsw_sp_setup_tc_block_clsact(struct mlxsw_sp_port *mlxsw_sp_port,
841*4882a593Smuzhiyun 				   struct flow_block_offload *f,
842*4882a593Smuzhiyun 				   bool ingress);
843*4882a593Smuzhiyun 
844*4882a593Smuzhiyun /* spectrum_acl.c */
845*4882a593Smuzhiyun struct mlxsw_sp_acl_ruleset;
846*4882a593Smuzhiyun 
847*4882a593Smuzhiyun enum mlxsw_sp_acl_profile {
848*4882a593Smuzhiyun 	MLXSW_SP_ACL_PROFILE_FLOWER,
849*4882a593Smuzhiyun 	MLXSW_SP_ACL_PROFILE_MR,
850*4882a593Smuzhiyun };
851*4882a593Smuzhiyun 
852*4882a593Smuzhiyun struct mlxsw_afk *mlxsw_sp_acl_afk(struct mlxsw_sp_acl *acl);
853*4882a593Smuzhiyun 
854*4882a593Smuzhiyun int mlxsw_sp_acl_ruleset_bind(struct mlxsw_sp *mlxsw_sp,
855*4882a593Smuzhiyun 			      struct mlxsw_sp_flow_block *block,
856*4882a593Smuzhiyun 			      struct mlxsw_sp_flow_block_binding *binding);
857*4882a593Smuzhiyun void mlxsw_sp_acl_ruleset_unbind(struct mlxsw_sp *mlxsw_sp,
858*4882a593Smuzhiyun 				 struct mlxsw_sp_flow_block *block,
859*4882a593Smuzhiyun 				 struct mlxsw_sp_flow_block_binding *binding);
860*4882a593Smuzhiyun struct mlxsw_sp_acl_ruleset *
861*4882a593Smuzhiyun mlxsw_sp_acl_ruleset_lookup(struct mlxsw_sp *mlxsw_sp,
862*4882a593Smuzhiyun 			    struct mlxsw_sp_flow_block *block, u32 chain_index,
863*4882a593Smuzhiyun 			    enum mlxsw_sp_acl_profile profile);
864*4882a593Smuzhiyun struct mlxsw_sp_acl_ruleset *
865*4882a593Smuzhiyun mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp,
866*4882a593Smuzhiyun 			 struct mlxsw_sp_flow_block *block, u32 chain_index,
867*4882a593Smuzhiyun 			 enum mlxsw_sp_acl_profile profile,
868*4882a593Smuzhiyun 			 struct mlxsw_afk_element_usage *tmplt_elusage);
869*4882a593Smuzhiyun void mlxsw_sp_acl_ruleset_put(struct mlxsw_sp *mlxsw_sp,
870*4882a593Smuzhiyun 			      struct mlxsw_sp_acl_ruleset *ruleset);
871*4882a593Smuzhiyun u16 mlxsw_sp_acl_ruleset_group_id(struct mlxsw_sp_acl_ruleset *ruleset);
872*4882a593Smuzhiyun void mlxsw_sp_acl_ruleset_prio_get(struct mlxsw_sp_acl_ruleset *ruleset,
873*4882a593Smuzhiyun 				   unsigned int *p_min_prio,
874*4882a593Smuzhiyun 				   unsigned int *p_max_prio);
875*4882a593Smuzhiyun 
876*4882a593Smuzhiyun struct mlxsw_sp_acl_rule_info *
877*4882a593Smuzhiyun mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl,
878*4882a593Smuzhiyun 			  struct mlxsw_afa_block *afa_block);
879*4882a593Smuzhiyun void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp_acl_rule_info *rulei);
880*4882a593Smuzhiyun int mlxsw_sp_acl_rulei_commit(struct mlxsw_sp_acl_rule_info *rulei);
881*4882a593Smuzhiyun void mlxsw_sp_acl_rulei_priority(struct mlxsw_sp_acl_rule_info *rulei,
882*4882a593Smuzhiyun 				 unsigned int priority);
883*4882a593Smuzhiyun void mlxsw_sp_acl_rulei_keymask_u32(struct mlxsw_sp_acl_rule_info *rulei,
884*4882a593Smuzhiyun 				    enum mlxsw_afk_element element,
885*4882a593Smuzhiyun 				    u32 key_value, u32 mask_value);
886*4882a593Smuzhiyun void mlxsw_sp_acl_rulei_keymask_buf(struct mlxsw_sp_acl_rule_info *rulei,
887*4882a593Smuzhiyun 				    enum mlxsw_afk_element element,
888*4882a593Smuzhiyun 				    const char *key_value,
889*4882a593Smuzhiyun 				    const char *mask_value, unsigned int len);
890*4882a593Smuzhiyun int mlxsw_sp_acl_rulei_act_continue(struct mlxsw_sp_acl_rule_info *rulei);
891*4882a593Smuzhiyun int mlxsw_sp_acl_rulei_act_jump(struct mlxsw_sp_acl_rule_info *rulei,
892*4882a593Smuzhiyun 				u16 group_id);
893*4882a593Smuzhiyun int mlxsw_sp_acl_rulei_act_terminate(struct mlxsw_sp_acl_rule_info *rulei);
894*4882a593Smuzhiyun int mlxsw_sp_acl_rulei_act_drop(struct mlxsw_sp_acl_rule_info *rulei,
895*4882a593Smuzhiyun 				bool ingress,
896*4882a593Smuzhiyun 				const struct flow_action_cookie *fa_cookie,
897*4882a593Smuzhiyun 				struct netlink_ext_ack *extack);
898*4882a593Smuzhiyun int mlxsw_sp_acl_rulei_act_trap(struct mlxsw_sp_acl_rule_info *rulei);
899*4882a593Smuzhiyun int mlxsw_sp_acl_rulei_act_mirror(struct mlxsw_sp *mlxsw_sp,
900*4882a593Smuzhiyun 				  struct mlxsw_sp_acl_rule_info *rulei,
901*4882a593Smuzhiyun 				  struct mlxsw_sp_flow_block *block,
902*4882a593Smuzhiyun 				  struct net_device *out_dev,
903*4882a593Smuzhiyun 				  struct netlink_ext_ack *extack);
904*4882a593Smuzhiyun int mlxsw_sp_acl_rulei_act_fwd(struct mlxsw_sp *mlxsw_sp,
905*4882a593Smuzhiyun 			       struct mlxsw_sp_acl_rule_info *rulei,
906*4882a593Smuzhiyun 			       struct net_device *out_dev,
907*4882a593Smuzhiyun 			       struct netlink_ext_ack *extack);
908*4882a593Smuzhiyun int mlxsw_sp_acl_rulei_act_vlan(struct mlxsw_sp *mlxsw_sp,
909*4882a593Smuzhiyun 				struct mlxsw_sp_acl_rule_info *rulei,
910*4882a593Smuzhiyun 				u32 action, u16 vid, u16 proto, u8 prio,
911*4882a593Smuzhiyun 				struct netlink_ext_ack *extack);
912*4882a593Smuzhiyun int mlxsw_sp_acl_rulei_act_priority(struct mlxsw_sp *mlxsw_sp,
913*4882a593Smuzhiyun 				    struct mlxsw_sp_acl_rule_info *rulei,
914*4882a593Smuzhiyun 				    u32 prio, struct netlink_ext_ack *extack);
915*4882a593Smuzhiyun int mlxsw_sp_acl_rulei_act_mangle(struct mlxsw_sp *mlxsw_sp,
916*4882a593Smuzhiyun 				  struct mlxsw_sp_acl_rule_info *rulei,
917*4882a593Smuzhiyun 				  enum flow_action_mangle_base htype,
918*4882a593Smuzhiyun 				  u32 offset, u32 mask, u32 val,
919*4882a593Smuzhiyun 				  struct netlink_ext_ack *extack);
920*4882a593Smuzhiyun int mlxsw_sp_acl_rulei_act_police(struct mlxsw_sp *mlxsw_sp,
921*4882a593Smuzhiyun 				  struct mlxsw_sp_acl_rule_info *rulei,
922*4882a593Smuzhiyun 				  u32 index, u64 rate_bytes_ps,
923*4882a593Smuzhiyun 				  u32 burst, struct netlink_ext_ack *extack);
924*4882a593Smuzhiyun int mlxsw_sp_acl_rulei_act_count(struct mlxsw_sp *mlxsw_sp,
925*4882a593Smuzhiyun 				 struct mlxsw_sp_acl_rule_info *rulei,
926*4882a593Smuzhiyun 				 struct netlink_ext_ack *extack);
927*4882a593Smuzhiyun int mlxsw_sp_acl_rulei_act_fid_set(struct mlxsw_sp *mlxsw_sp,
928*4882a593Smuzhiyun 				   struct mlxsw_sp_acl_rule_info *rulei,
929*4882a593Smuzhiyun 				   u16 fid, struct netlink_ext_ack *extack);
930*4882a593Smuzhiyun 
931*4882a593Smuzhiyun struct mlxsw_sp_acl_rule;
932*4882a593Smuzhiyun 
933*4882a593Smuzhiyun struct mlxsw_sp_acl_rule *
934*4882a593Smuzhiyun mlxsw_sp_acl_rule_create(struct mlxsw_sp *mlxsw_sp,
935*4882a593Smuzhiyun 			 struct mlxsw_sp_acl_ruleset *ruleset,
936*4882a593Smuzhiyun 			 unsigned long cookie,
937*4882a593Smuzhiyun 			 struct mlxsw_afa_block *afa_block,
938*4882a593Smuzhiyun 			 struct netlink_ext_ack *extack);
939*4882a593Smuzhiyun void mlxsw_sp_acl_rule_destroy(struct mlxsw_sp *mlxsw_sp,
940*4882a593Smuzhiyun 			       struct mlxsw_sp_acl_rule *rule);
941*4882a593Smuzhiyun int mlxsw_sp_acl_rule_add(struct mlxsw_sp *mlxsw_sp,
942*4882a593Smuzhiyun 			  struct mlxsw_sp_acl_rule *rule);
943*4882a593Smuzhiyun void mlxsw_sp_acl_rule_del(struct mlxsw_sp *mlxsw_sp,
944*4882a593Smuzhiyun 			   struct mlxsw_sp_acl_rule *rule);
945*4882a593Smuzhiyun int mlxsw_sp_acl_rule_action_replace(struct mlxsw_sp *mlxsw_sp,
946*4882a593Smuzhiyun 				     struct mlxsw_sp_acl_rule *rule,
947*4882a593Smuzhiyun 				     struct mlxsw_afa_block *afa_block);
948*4882a593Smuzhiyun struct mlxsw_sp_acl_rule *
949*4882a593Smuzhiyun mlxsw_sp_acl_rule_lookup(struct mlxsw_sp *mlxsw_sp,
950*4882a593Smuzhiyun 			 struct mlxsw_sp_acl_ruleset *ruleset,
951*4882a593Smuzhiyun 			 unsigned long cookie);
952*4882a593Smuzhiyun struct mlxsw_sp_acl_rule_info *
953*4882a593Smuzhiyun mlxsw_sp_acl_rule_rulei(struct mlxsw_sp_acl_rule *rule);
954*4882a593Smuzhiyun int mlxsw_sp_acl_rule_get_stats(struct mlxsw_sp *mlxsw_sp,
955*4882a593Smuzhiyun 				struct mlxsw_sp_acl_rule *rule,
956*4882a593Smuzhiyun 				u64 *packets, u64 *bytes, u64 *drops,
957*4882a593Smuzhiyun 				u64 *last_use,
958*4882a593Smuzhiyun 				enum flow_action_hw_stats *used_hw_stats);
959*4882a593Smuzhiyun 
960*4882a593Smuzhiyun struct mlxsw_sp_fid *mlxsw_sp_acl_dummy_fid(struct mlxsw_sp *mlxsw_sp);
961*4882a593Smuzhiyun 
962*4882a593Smuzhiyun static inline const struct flow_action_cookie *
mlxsw_sp_acl_act_cookie_lookup(struct mlxsw_sp * mlxsw_sp,u32 cookie_index)963*4882a593Smuzhiyun mlxsw_sp_acl_act_cookie_lookup(struct mlxsw_sp *mlxsw_sp, u32 cookie_index)
964*4882a593Smuzhiyun {
965*4882a593Smuzhiyun 	return mlxsw_afa_cookie_lookup(mlxsw_sp->afa, cookie_index);
966*4882a593Smuzhiyun }
967*4882a593Smuzhiyun 
968*4882a593Smuzhiyun int mlxsw_sp_acl_init(struct mlxsw_sp *mlxsw_sp);
969*4882a593Smuzhiyun void mlxsw_sp_acl_fini(struct mlxsw_sp *mlxsw_sp);
970*4882a593Smuzhiyun u32 mlxsw_sp_acl_region_rehash_intrvl_get(struct mlxsw_sp *mlxsw_sp);
971*4882a593Smuzhiyun int mlxsw_sp_acl_region_rehash_intrvl_set(struct mlxsw_sp *mlxsw_sp, u32 val);
972*4882a593Smuzhiyun 
973*4882a593Smuzhiyun struct mlxsw_sp_acl_mangle_action;
974*4882a593Smuzhiyun 
975*4882a593Smuzhiyun struct mlxsw_sp_acl_rulei_ops {
976*4882a593Smuzhiyun 	int (*act_mangle_field)(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_rule_info *rulei,
977*4882a593Smuzhiyun 				struct mlxsw_sp_acl_mangle_action *mact, u32 val,
978*4882a593Smuzhiyun 				struct netlink_ext_ack *extack);
979*4882a593Smuzhiyun };
980*4882a593Smuzhiyun 
981*4882a593Smuzhiyun extern struct mlxsw_sp_acl_rulei_ops mlxsw_sp1_acl_rulei_ops;
982*4882a593Smuzhiyun extern struct mlxsw_sp_acl_rulei_ops mlxsw_sp2_acl_rulei_ops;
983*4882a593Smuzhiyun 
984*4882a593Smuzhiyun /* spectrum_acl_tcam.c */
985*4882a593Smuzhiyun struct mlxsw_sp_acl_tcam;
986*4882a593Smuzhiyun struct mlxsw_sp_acl_tcam_region;
987*4882a593Smuzhiyun 
988*4882a593Smuzhiyun struct mlxsw_sp_acl_tcam_ops {
989*4882a593Smuzhiyun 	enum mlxsw_reg_ptar_key_type key_type;
990*4882a593Smuzhiyun 	size_t priv_size;
991*4882a593Smuzhiyun 	int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv,
992*4882a593Smuzhiyun 		    struct mlxsw_sp_acl_tcam *tcam);
993*4882a593Smuzhiyun 	void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
994*4882a593Smuzhiyun 	size_t region_priv_size;
995*4882a593Smuzhiyun 	int (*region_init)(struct mlxsw_sp *mlxsw_sp, void *region_priv,
996*4882a593Smuzhiyun 			   void *tcam_priv,
997*4882a593Smuzhiyun 			   struct mlxsw_sp_acl_tcam_region *region,
998*4882a593Smuzhiyun 			   void *hints_priv);
999*4882a593Smuzhiyun 	void (*region_fini)(struct mlxsw_sp *mlxsw_sp, void *region_priv);
1000*4882a593Smuzhiyun 	int (*region_associate)(struct mlxsw_sp *mlxsw_sp,
1001*4882a593Smuzhiyun 				struct mlxsw_sp_acl_tcam_region *region);
1002*4882a593Smuzhiyun 	void * (*region_rehash_hints_get)(void *region_priv);
1003*4882a593Smuzhiyun 	void (*region_rehash_hints_put)(void *hints_priv);
1004*4882a593Smuzhiyun 	size_t chunk_priv_size;
1005*4882a593Smuzhiyun 	void (*chunk_init)(void *region_priv, void *chunk_priv,
1006*4882a593Smuzhiyun 			   unsigned int priority);
1007*4882a593Smuzhiyun 	void (*chunk_fini)(void *chunk_priv);
1008*4882a593Smuzhiyun 	size_t entry_priv_size;
1009*4882a593Smuzhiyun 	int (*entry_add)(struct mlxsw_sp *mlxsw_sp,
1010*4882a593Smuzhiyun 			 void *region_priv, void *chunk_priv,
1011*4882a593Smuzhiyun 			 void *entry_priv,
1012*4882a593Smuzhiyun 			 struct mlxsw_sp_acl_rule_info *rulei);
1013*4882a593Smuzhiyun 	void (*entry_del)(struct mlxsw_sp *mlxsw_sp,
1014*4882a593Smuzhiyun 			  void *region_priv, void *chunk_priv,
1015*4882a593Smuzhiyun 			  void *entry_priv);
1016*4882a593Smuzhiyun 	int (*entry_action_replace)(struct mlxsw_sp *mlxsw_sp,
1017*4882a593Smuzhiyun 				    void *region_priv, void *entry_priv,
1018*4882a593Smuzhiyun 				    struct mlxsw_sp_acl_rule_info *rulei);
1019*4882a593Smuzhiyun 	int (*entry_activity_get)(struct mlxsw_sp *mlxsw_sp,
1020*4882a593Smuzhiyun 				  void *region_priv, void *entry_priv,
1021*4882a593Smuzhiyun 				  bool *activity);
1022*4882a593Smuzhiyun };
1023*4882a593Smuzhiyun 
1024*4882a593Smuzhiyun /* spectrum1_acl_tcam.c */
1025*4882a593Smuzhiyun extern const struct mlxsw_sp_acl_tcam_ops mlxsw_sp1_acl_tcam_ops;
1026*4882a593Smuzhiyun 
1027*4882a593Smuzhiyun /* spectrum2_acl_tcam.c */
1028*4882a593Smuzhiyun extern const struct mlxsw_sp_acl_tcam_ops mlxsw_sp2_acl_tcam_ops;
1029*4882a593Smuzhiyun 
1030*4882a593Smuzhiyun /* spectrum_acl_flex_actions.c */
1031*4882a593Smuzhiyun extern const struct mlxsw_afa_ops mlxsw_sp1_act_afa_ops;
1032*4882a593Smuzhiyun extern const struct mlxsw_afa_ops mlxsw_sp2_act_afa_ops;
1033*4882a593Smuzhiyun 
1034*4882a593Smuzhiyun /* spectrum_acl_flex_keys.c */
1035*4882a593Smuzhiyun extern const struct mlxsw_afk_ops mlxsw_sp1_afk_ops;
1036*4882a593Smuzhiyun extern const struct mlxsw_afk_ops mlxsw_sp2_afk_ops;
1037*4882a593Smuzhiyun 
1038*4882a593Smuzhiyun /* spectrum_matchall.c */
1039*4882a593Smuzhiyun enum mlxsw_sp_mall_action_type {
1040*4882a593Smuzhiyun 	MLXSW_SP_MALL_ACTION_TYPE_MIRROR,
1041*4882a593Smuzhiyun 	MLXSW_SP_MALL_ACTION_TYPE_SAMPLE,
1042*4882a593Smuzhiyun 	MLXSW_SP_MALL_ACTION_TYPE_TRAP,
1043*4882a593Smuzhiyun };
1044*4882a593Smuzhiyun 
1045*4882a593Smuzhiyun struct mlxsw_sp_mall_mirror_entry {
1046*4882a593Smuzhiyun 	const struct net_device *to_dev;
1047*4882a593Smuzhiyun 	int span_id;
1048*4882a593Smuzhiyun };
1049*4882a593Smuzhiyun 
1050*4882a593Smuzhiyun struct mlxsw_sp_mall_trap_entry {
1051*4882a593Smuzhiyun 	int span_id;
1052*4882a593Smuzhiyun };
1053*4882a593Smuzhiyun 
1054*4882a593Smuzhiyun struct mlxsw_sp_mall_entry {
1055*4882a593Smuzhiyun 	struct list_head list;
1056*4882a593Smuzhiyun 	unsigned long cookie;
1057*4882a593Smuzhiyun 	unsigned int priority;
1058*4882a593Smuzhiyun 	enum mlxsw_sp_mall_action_type type;
1059*4882a593Smuzhiyun 	bool ingress;
1060*4882a593Smuzhiyun 	union {
1061*4882a593Smuzhiyun 		struct mlxsw_sp_mall_mirror_entry mirror;
1062*4882a593Smuzhiyun 		struct mlxsw_sp_mall_trap_entry trap;
1063*4882a593Smuzhiyun 		struct mlxsw_sp_port_sample sample;
1064*4882a593Smuzhiyun 	};
1065*4882a593Smuzhiyun 	struct rcu_head rcu;
1066*4882a593Smuzhiyun };
1067*4882a593Smuzhiyun 
1068*4882a593Smuzhiyun int mlxsw_sp_mall_replace(struct mlxsw_sp *mlxsw_sp,
1069*4882a593Smuzhiyun 			  struct mlxsw_sp_flow_block *block,
1070*4882a593Smuzhiyun 			  struct tc_cls_matchall_offload *f);
1071*4882a593Smuzhiyun void mlxsw_sp_mall_destroy(struct mlxsw_sp_flow_block *block,
1072*4882a593Smuzhiyun 			   struct tc_cls_matchall_offload *f);
1073*4882a593Smuzhiyun int mlxsw_sp_mall_port_bind(struct mlxsw_sp_flow_block *block,
1074*4882a593Smuzhiyun 			    struct mlxsw_sp_port *mlxsw_sp_port);
1075*4882a593Smuzhiyun void mlxsw_sp_mall_port_unbind(struct mlxsw_sp_flow_block *block,
1076*4882a593Smuzhiyun 			       struct mlxsw_sp_port *mlxsw_sp_port);
1077*4882a593Smuzhiyun int mlxsw_sp_mall_prio_get(struct mlxsw_sp_flow_block *block, u32 chain_index,
1078*4882a593Smuzhiyun 			   unsigned int *p_min_prio, unsigned int *p_max_prio);
1079*4882a593Smuzhiyun 
1080*4882a593Smuzhiyun /* spectrum_flower.c */
1081*4882a593Smuzhiyun int mlxsw_sp_flower_replace(struct mlxsw_sp *mlxsw_sp,
1082*4882a593Smuzhiyun 			    struct mlxsw_sp_flow_block *block,
1083*4882a593Smuzhiyun 			    struct flow_cls_offload *f);
1084*4882a593Smuzhiyun void mlxsw_sp_flower_destroy(struct mlxsw_sp *mlxsw_sp,
1085*4882a593Smuzhiyun 			     struct mlxsw_sp_flow_block *block,
1086*4882a593Smuzhiyun 			     struct flow_cls_offload *f);
1087*4882a593Smuzhiyun int mlxsw_sp_flower_stats(struct mlxsw_sp *mlxsw_sp,
1088*4882a593Smuzhiyun 			  struct mlxsw_sp_flow_block *block,
1089*4882a593Smuzhiyun 			  struct flow_cls_offload *f);
1090*4882a593Smuzhiyun int mlxsw_sp_flower_tmplt_create(struct mlxsw_sp *mlxsw_sp,
1091*4882a593Smuzhiyun 				 struct mlxsw_sp_flow_block *block,
1092*4882a593Smuzhiyun 				 struct flow_cls_offload *f);
1093*4882a593Smuzhiyun void mlxsw_sp_flower_tmplt_destroy(struct mlxsw_sp *mlxsw_sp,
1094*4882a593Smuzhiyun 				   struct mlxsw_sp_flow_block *block,
1095*4882a593Smuzhiyun 				   struct flow_cls_offload *f);
1096*4882a593Smuzhiyun int mlxsw_sp_flower_prio_get(struct mlxsw_sp *mlxsw_sp,
1097*4882a593Smuzhiyun 			     struct mlxsw_sp_flow_block *block,
1098*4882a593Smuzhiyun 			     u32 chain_index, unsigned int *p_min_prio,
1099*4882a593Smuzhiyun 			     unsigned int *p_max_prio);
1100*4882a593Smuzhiyun 
1101*4882a593Smuzhiyun /* spectrum_qdisc.c */
1102*4882a593Smuzhiyun int mlxsw_sp_tc_qdisc_init(struct mlxsw_sp_port *mlxsw_sp_port);
1103*4882a593Smuzhiyun void mlxsw_sp_tc_qdisc_fini(struct mlxsw_sp_port *mlxsw_sp_port);
1104*4882a593Smuzhiyun int mlxsw_sp_setup_tc_red(struct mlxsw_sp_port *mlxsw_sp_port,
1105*4882a593Smuzhiyun 			  struct tc_red_qopt_offload *p);
1106*4882a593Smuzhiyun int mlxsw_sp_setup_tc_prio(struct mlxsw_sp_port *mlxsw_sp_port,
1107*4882a593Smuzhiyun 			   struct tc_prio_qopt_offload *p);
1108*4882a593Smuzhiyun int mlxsw_sp_setup_tc_ets(struct mlxsw_sp_port *mlxsw_sp_port,
1109*4882a593Smuzhiyun 			  struct tc_ets_qopt_offload *p);
1110*4882a593Smuzhiyun int mlxsw_sp_setup_tc_tbf(struct mlxsw_sp_port *mlxsw_sp_port,
1111*4882a593Smuzhiyun 			  struct tc_tbf_qopt_offload *p);
1112*4882a593Smuzhiyun int mlxsw_sp_setup_tc_fifo(struct mlxsw_sp_port *mlxsw_sp_port,
1113*4882a593Smuzhiyun 			   struct tc_fifo_qopt_offload *p);
1114*4882a593Smuzhiyun int mlxsw_sp_setup_tc_block_qevent_early_drop(struct mlxsw_sp_port *mlxsw_sp_port,
1115*4882a593Smuzhiyun 					      struct flow_block_offload *f);
1116*4882a593Smuzhiyun 
1117*4882a593Smuzhiyun /* spectrum_fid.c */
1118*4882a593Smuzhiyun bool mlxsw_sp_fid_is_dummy(struct mlxsw_sp *mlxsw_sp, u16 fid_index);
1119*4882a593Smuzhiyun bool mlxsw_sp_fid_lag_vid_valid(const struct mlxsw_sp_fid *fid);
1120*4882a593Smuzhiyun struct mlxsw_sp_fid *mlxsw_sp_fid_lookup_by_index(struct mlxsw_sp *mlxsw_sp,
1121*4882a593Smuzhiyun 						  u16 fid_index);
1122*4882a593Smuzhiyun int mlxsw_sp_fid_nve_ifindex(const struct mlxsw_sp_fid *fid, int *nve_ifindex);
1123*4882a593Smuzhiyun int mlxsw_sp_fid_nve_type(const struct mlxsw_sp_fid *fid,
1124*4882a593Smuzhiyun 			  enum mlxsw_sp_nve_type *p_type);
1125*4882a593Smuzhiyun struct mlxsw_sp_fid *mlxsw_sp_fid_lookup_by_vni(struct mlxsw_sp *mlxsw_sp,
1126*4882a593Smuzhiyun 						__be32 vni);
1127*4882a593Smuzhiyun int mlxsw_sp_fid_vni(const struct mlxsw_sp_fid *fid, __be32 *vni);
1128*4882a593Smuzhiyun int mlxsw_sp_fid_nve_flood_index_set(struct mlxsw_sp_fid *fid,
1129*4882a593Smuzhiyun 				     u32 nve_flood_index);
1130*4882a593Smuzhiyun void mlxsw_sp_fid_nve_flood_index_clear(struct mlxsw_sp_fid *fid);
1131*4882a593Smuzhiyun bool mlxsw_sp_fid_nve_flood_index_is_set(const struct mlxsw_sp_fid *fid);
1132*4882a593Smuzhiyun int mlxsw_sp_fid_vni_set(struct mlxsw_sp_fid *fid, enum mlxsw_sp_nve_type type,
1133*4882a593Smuzhiyun 			 __be32 vni, int nve_ifindex);
1134*4882a593Smuzhiyun void mlxsw_sp_fid_vni_clear(struct mlxsw_sp_fid *fid);
1135*4882a593Smuzhiyun bool mlxsw_sp_fid_vni_is_set(const struct mlxsw_sp_fid *fid);
1136*4882a593Smuzhiyun void mlxsw_sp_fid_fdb_clear_offload(const struct mlxsw_sp_fid *fid,
1137*4882a593Smuzhiyun 				    const struct net_device *nve_dev);
1138*4882a593Smuzhiyun int mlxsw_sp_fid_flood_set(struct mlxsw_sp_fid *fid,
1139*4882a593Smuzhiyun 			   enum mlxsw_sp_flood_type packet_type, u8 local_port,
1140*4882a593Smuzhiyun 			   bool member);
1141*4882a593Smuzhiyun int mlxsw_sp_fid_port_vid_map(struct mlxsw_sp_fid *fid,
1142*4882a593Smuzhiyun 			      struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
1143*4882a593Smuzhiyun void mlxsw_sp_fid_port_vid_unmap(struct mlxsw_sp_fid *fid,
1144*4882a593Smuzhiyun 				 struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
1145*4882a593Smuzhiyun u16 mlxsw_sp_fid_index(const struct mlxsw_sp_fid *fid);
1146*4882a593Smuzhiyun enum mlxsw_sp_fid_type mlxsw_sp_fid_type(const struct mlxsw_sp_fid *fid);
1147*4882a593Smuzhiyun void mlxsw_sp_fid_rif_set(struct mlxsw_sp_fid *fid, struct mlxsw_sp_rif *rif);
1148*4882a593Smuzhiyun struct mlxsw_sp_rif *mlxsw_sp_fid_rif(const struct mlxsw_sp_fid *fid);
1149*4882a593Smuzhiyun enum mlxsw_sp_rif_type
1150*4882a593Smuzhiyun mlxsw_sp_fid_type_rif_type(const struct mlxsw_sp *mlxsw_sp,
1151*4882a593Smuzhiyun 			   enum mlxsw_sp_fid_type type);
1152*4882a593Smuzhiyun u16 mlxsw_sp_fid_8021q_vid(const struct mlxsw_sp_fid *fid);
1153*4882a593Smuzhiyun struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_get(struct mlxsw_sp *mlxsw_sp, u16 vid);
1154*4882a593Smuzhiyun struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_get(struct mlxsw_sp *mlxsw_sp,
1155*4882a593Smuzhiyun 					    int br_ifindex);
1156*4882a593Smuzhiyun struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_lookup(struct mlxsw_sp *mlxsw_sp,
1157*4882a593Smuzhiyun 					       u16 vid);
1158*4882a593Smuzhiyun struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_lookup(struct mlxsw_sp *mlxsw_sp,
1159*4882a593Smuzhiyun 					       int br_ifindex);
1160*4882a593Smuzhiyun struct mlxsw_sp_fid *mlxsw_sp_fid_rfid_get(struct mlxsw_sp *mlxsw_sp,
1161*4882a593Smuzhiyun 					   u16 rif_index);
1162*4882a593Smuzhiyun struct mlxsw_sp_fid *mlxsw_sp_fid_dummy_get(struct mlxsw_sp *mlxsw_sp);
1163*4882a593Smuzhiyun void mlxsw_sp_fid_put(struct mlxsw_sp_fid *fid);
1164*4882a593Smuzhiyun int mlxsw_sp_port_fids_init(struct mlxsw_sp_port *mlxsw_sp_port);
1165*4882a593Smuzhiyun void mlxsw_sp_port_fids_fini(struct mlxsw_sp_port *mlxsw_sp_port);
1166*4882a593Smuzhiyun int mlxsw_sp_fids_init(struct mlxsw_sp *mlxsw_sp);
1167*4882a593Smuzhiyun void mlxsw_sp_fids_fini(struct mlxsw_sp *mlxsw_sp);
1168*4882a593Smuzhiyun 
1169*4882a593Smuzhiyun /* spectrum_mr.c */
1170*4882a593Smuzhiyun enum mlxsw_sp_mr_route_prio {
1171*4882a593Smuzhiyun 	MLXSW_SP_MR_ROUTE_PRIO_SG,
1172*4882a593Smuzhiyun 	MLXSW_SP_MR_ROUTE_PRIO_STARG,
1173*4882a593Smuzhiyun 	MLXSW_SP_MR_ROUTE_PRIO_CATCHALL,
1174*4882a593Smuzhiyun 	__MLXSW_SP_MR_ROUTE_PRIO_MAX
1175*4882a593Smuzhiyun };
1176*4882a593Smuzhiyun 
1177*4882a593Smuzhiyun #define MLXSW_SP_MR_ROUTE_PRIO_MAX (__MLXSW_SP_MR_ROUTE_PRIO_MAX - 1)
1178*4882a593Smuzhiyun 
1179*4882a593Smuzhiyun struct mlxsw_sp_mr_route_key;
1180*4882a593Smuzhiyun 
1181*4882a593Smuzhiyun struct mlxsw_sp_mr_tcam_ops {
1182*4882a593Smuzhiyun 	size_t priv_size;
1183*4882a593Smuzhiyun 	int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
1184*4882a593Smuzhiyun 	void (*fini)(void *priv);
1185*4882a593Smuzhiyun 	size_t route_priv_size;
1186*4882a593Smuzhiyun 	int (*route_create)(struct mlxsw_sp *mlxsw_sp, void *priv,
1187*4882a593Smuzhiyun 			    void *route_priv,
1188*4882a593Smuzhiyun 			    struct mlxsw_sp_mr_route_key *key,
1189*4882a593Smuzhiyun 			    struct mlxsw_afa_block *afa_block,
1190*4882a593Smuzhiyun 			    enum mlxsw_sp_mr_route_prio prio);
1191*4882a593Smuzhiyun 	void (*route_destroy)(struct mlxsw_sp *mlxsw_sp, void *priv,
1192*4882a593Smuzhiyun 			      void *route_priv,
1193*4882a593Smuzhiyun 			      struct mlxsw_sp_mr_route_key *key);
1194*4882a593Smuzhiyun 	int (*route_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
1195*4882a593Smuzhiyun 			    struct mlxsw_sp_mr_route_key *key,
1196*4882a593Smuzhiyun 			    struct mlxsw_afa_block *afa_block);
1197*4882a593Smuzhiyun };
1198*4882a593Smuzhiyun 
1199*4882a593Smuzhiyun /* spectrum1_mr_tcam.c */
1200*4882a593Smuzhiyun extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp1_mr_tcam_ops;
1201*4882a593Smuzhiyun 
1202*4882a593Smuzhiyun /* spectrum2_mr_tcam.c */
1203*4882a593Smuzhiyun extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp2_mr_tcam_ops;
1204*4882a593Smuzhiyun 
1205*4882a593Smuzhiyun /* spectrum_nve.c */
1206*4882a593Smuzhiyun struct mlxsw_sp_nve_params {
1207*4882a593Smuzhiyun 	enum mlxsw_sp_nve_type type;
1208*4882a593Smuzhiyun 	__be32 vni;
1209*4882a593Smuzhiyun 	const struct net_device *dev;
1210*4882a593Smuzhiyun };
1211*4882a593Smuzhiyun 
1212*4882a593Smuzhiyun extern const struct mlxsw_sp_nve_ops *mlxsw_sp1_nve_ops_arr[];
1213*4882a593Smuzhiyun extern const struct mlxsw_sp_nve_ops *mlxsw_sp2_nve_ops_arr[];
1214*4882a593Smuzhiyun 
1215*4882a593Smuzhiyun int mlxsw_sp_nve_learned_ip_resolve(struct mlxsw_sp *mlxsw_sp, u32 uip,
1216*4882a593Smuzhiyun 				    enum mlxsw_sp_l3proto proto,
1217*4882a593Smuzhiyun 				    union mlxsw_sp_l3addr *addr);
1218*4882a593Smuzhiyun int mlxsw_sp_nve_flood_ip_add(struct mlxsw_sp *mlxsw_sp,
1219*4882a593Smuzhiyun 			      struct mlxsw_sp_fid *fid,
1220*4882a593Smuzhiyun 			      enum mlxsw_sp_l3proto proto,
1221*4882a593Smuzhiyun 			      union mlxsw_sp_l3addr *addr);
1222*4882a593Smuzhiyun void mlxsw_sp_nve_flood_ip_del(struct mlxsw_sp *mlxsw_sp,
1223*4882a593Smuzhiyun 			       struct mlxsw_sp_fid *fid,
1224*4882a593Smuzhiyun 			       enum mlxsw_sp_l3proto proto,
1225*4882a593Smuzhiyun 			       union mlxsw_sp_l3addr *addr);
1226*4882a593Smuzhiyun int mlxsw_sp_nve_fid_enable(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_fid *fid,
1227*4882a593Smuzhiyun 			    struct mlxsw_sp_nve_params *params,
1228*4882a593Smuzhiyun 			    struct netlink_ext_ack *extack);
1229*4882a593Smuzhiyun void mlxsw_sp_nve_fid_disable(struct mlxsw_sp *mlxsw_sp,
1230*4882a593Smuzhiyun 			      struct mlxsw_sp_fid *fid);
1231*4882a593Smuzhiyun int mlxsw_sp_port_nve_init(struct mlxsw_sp_port *mlxsw_sp_port);
1232*4882a593Smuzhiyun void mlxsw_sp_port_nve_fini(struct mlxsw_sp_port *mlxsw_sp_port);
1233*4882a593Smuzhiyun int mlxsw_sp_nve_init(struct mlxsw_sp *mlxsw_sp);
1234*4882a593Smuzhiyun void mlxsw_sp_nve_fini(struct mlxsw_sp *mlxsw_sp);
1235*4882a593Smuzhiyun 
1236*4882a593Smuzhiyun /* spectrum_nve_vxlan.c */
1237*4882a593Smuzhiyun int mlxsw_sp_nve_inc_parsing_depth_get(struct mlxsw_sp *mlxsw_sp);
1238*4882a593Smuzhiyun void mlxsw_sp_nve_inc_parsing_depth_put(struct mlxsw_sp *mlxsw_sp);
1239*4882a593Smuzhiyun 
1240*4882a593Smuzhiyun /* spectrum_trap.c */
1241*4882a593Smuzhiyun int mlxsw_sp_devlink_traps_init(struct mlxsw_sp *mlxsw_sp);
1242*4882a593Smuzhiyun void mlxsw_sp_devlink_traps_fini(struct mlxsw_sp *mlxsw_sp);
1243*4882a593Smuzhiyun int mlxsw_sp_trap_init(struct mlxsw_core *mlxsw_core,
1244*4882a593Smuzhiyun 		       const struct devlink_trap *trap, void *trap_ctx);
1245*4882a593Smuzhiyun void mlxsw_sp_trap_fini(struct mlxsw_core *mlxsw_core,
1246*4882a593Smuzhiyun 			const struct devlink_trap *trap, void *trap_ctx);
1247*4882a593Smuzhiyun int mlxsw_sp_trap_action_set(struct mlxsw_core *mlxsw_core,
1248*4882a593Smuzhiyun 			     const struct devlink_trap *trap,
1249*4882a593Smuzhiyun 			     enum devlink_trap_action action,
1250*4882a593Smuzhiyun 			     struct netlink_ext_ack *extack);
1251*4882a593Smuzhiyun int mlxsw_sp_trap_group_init(struct mlxsw_core *mlxsw_core,
1252*4882a593Smuzhiyun 			     const struct devlink_trap_group *group);
1253*4882a593Smuzhiyun int mlxsw_sp_trap_group_set(struct mlxsw_core *mlxsw_core,
1254*4882a593Smuzhiyun 			    const struct devlink_trap_group *group,
1255*4882a593Smuzhiyun 			    const struct devlink_trap_policer *policer,
1256*4882a593Smuzhiyun 			    struct netlink_ext_ack *extack);
1257*4882a593Smuzhiyun int
1258*4882a593Smuzhiyun mlxsw_sp_trap_policer_init(struct mlxsw_core *mlxsw_core,
1259*4882a593Smuzhiyun 			   const struct devlink_trap_policer *policer);
1260*4882a593Smuzhiyun void mlxsw_sp_trap_policer_fini(struct mlxsw_core *mlxsw_core,
1261*4882a593Smuzhiyun 				const struct devlink_trap_policer *policer);
1262*4882a593Smuzhiyun int
1263*4882a593Smuzhiyun mlxsw_sp_trap_policer_set(struct mlxsw_core *mlxsw_core,
1264*4882a593Smuzhiyun 			  const struct devlink_trap_policer *policer,
1265*4882a593Smuzhiyun 			  u64 rate, u64 burst, struct netlink_ext_ack *extack);
1266*4882a593Smuzhiyun int
1267*4882a593Smuzhiyun mlxsw_sp_trap_policer_counter_get(struct mlxsw_core *mlxsw_core,
1268*4882a593Smuzhiyun 				  const struct devlink_trap_policer *policer,
1269*4882a593Smuzhiyun 				  u64 *p_drops);
1270*4882a593Smuzhiyun int mlxsw_sp_trap_group_policer_hw_id_get(struct mlxsw_sp *mlxsw_sp, u16 id,
1271*4882a593Smuzhiyun 					  bool *p_enabled, u16 *p_hw_id);
1272*4882a593Smuzhiyun 
mlxsw_sp_net(struct mlxsw_sp * mlxsw_sp)1273*4882a593Smuzhiyun static inline struct net *mlxsw_sp_net(struct mlxsw_sp *mlxsw_sp)
1274*4882a593Smuzhiyun {
1275*4882a593Smuzhiyun 	return mlxsw_core_net(mlxsw_sp->core);
1276*4882a593Smuzhiyun }
1277*4882a593Smuzhiyun 
1278*4882a593Smuzhiyun /* spectrum_ethtool.c */
1279*4882a593Smuzhiyun extern const struct ethtool_ops mlxsw_sp_port_ethtool_ops;
1280*4882a593Smuzhiyun extern const struct mlxsw_sp_port_type_speed_ops mlxsw_sp1_port_type_speed_ops;
1281*4882a593Smuzhiyun extern const struct mlxsw_sp_port_type_speed_ops mlxsw_sp2_port_type_speed_ops;
1282*4882a593Smuzhiyun 
1283*4882a593Smuzhiyun /* spectrum_policer.c */
1284*4882a593Smuzhiyun extern const struct mlxsw_sp_policer_core_ops mlxsw_sp1_policer_core_ops;
1285*4882a593Smuzhiyun extern const struct mlxsw_sp_policer_core_ops mlxsw_sp2_policer_core_ops;
1286*4882a593Smuzhiyun 
1287*4882a593Smuzhiyun enum mlxsw_sp_policer_type {
1288*4882a593Smuzhiyun 	MLXSW_SP_POLICER_TYPE_SINGLE_RATE,
1289*4882a593Smuzhiyun 
1290*4882a593Smuzhiyun 	__MLXSW_SP_POLICER_TYPE_MAX,
1291*4882a593Smuzhiyun 	MLXSW_SP_POLICER_TYPE_MAX = __MLXSW_SP_POLICER_TYPE_MAX - 1,
1292*4882a593Smuzhiyun };
1293*4882a593Smuzhiyun 
1294*4882a593Smuzhiyun struct mlxsw_sp_policer_params {
1295*4882a593Smuzhiyun 	u64 rate;
1296*4882a593Smuzhiyun 	u64 burst;
1297*4882a593Smuzhiyun 	bool bytes;
1298*4882a593Smuzhiyun };
1299*4882a593Smuzhiyun 
1300*4882a593Smuzhiyun int mlxsw_sp_policer_add(struct mlxsw_sp *mlxsw_sp,
1301*4882a593Smuzhiyun 			 enum mlxsw_sp_policer_type type,
1302*4882a593Smuzhiyun 			 const struct mlxsw_sp_policer_params *params,
1303*4882a593Smuzhiyun 			 struct netlink_ext_ack *extack, u16 *p_policer_index);
1304*4882a593Smuzhiyun void mlxsw_sp_policer_del(struct mlxsw_sp *mlxsw_sp,
1305*4882a593Smuzhiyun 			  enum mlxsw_sp_policer_type type,
1306*4882a593Smuzhiyun 			  u16 policer_index);
1307*4882a593Smuzhiyun int mlxsw_sp_policer_drops_counter_get(struct mlxsw_sp *mlxsw_sp,
1308*4882a593Smuzhiyun 				       enum mlxsw_sp_policer_type type,
1309*4882a593Smuzhiyun 				       u16 policer_index, u64 *p_drops);
1310*4882a593Smuzhiyun int mlxsw_sp_policers_init(struct mlxsw_sp *mlxsw_sp);
1311*4882a593Smuzhiyun void mlxsw_sp_policers_fini(struct mlxsw_sp *mlxsw_sp);
1312*4882a593Smuzhiyun int mlxsw_sp_policer_resources_register(struct mlxsw_core *mlxsw_core);
1313*4882a593Smuzhiyun 
1314*4882a593Smuzhiyun #endif
1315