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