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