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