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