1
2
3
4#ifndef _MLXSW_SPECTRUM_H
5#define _MLXSW_SPECTRUM_H
6
7#include <linux/types.h>
8#include <linux/netdevice.h>
9#include <linux/rhashtable.h>
10#include <linux/bitops.h>
11#include <linux/if_vlan.h>
12#include <linux/list.h>
13#include <linux/dcbnl.h>
14#include <linux/in6.h>
15#include <linux/notifier.h>
16#include <net/psample.h>
17#include <net/pkt_cls.h>
18#include <net/red.h>
19
20#include "port.h"
21#include "core.h"
22#include "core_acl_flex_keys.h"
23#include "core_acl_flex_actions.h"
24#include "reg.h"
25
26#define MLXSW_SP_FID_8021D_MAX 1024
27
28#define MLXSW_SP_MID_MAX 7000
29
30#define MLXSW_SP_PORTS_PER_CLUSTER_MAX 4
31
32#define MLXSW_SP_PORT_BASE_SPEED 25000
33
34#define MLXSW_SP_KVD_LINEAR_SIZE 98304
35#define MLXSW_SP_KVD_GRANULARITY 128
36
37#define MLXSW_SP_RESOURCE_NAME_KVD "kvd"
38#define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR "linear"
39#define MLXSW_SP_RESOURCE_NAME_KVD_HASH_SINGLE "hash_single"
40#define MLXSW_SP_RESOURCE_NAME_KVD_HASH_DOUBLE "hash_double"
41#define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_SINGLES "singles"
42#define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_CHUNKS "chunks"
43#define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_LARGE_CHUNKS "large_chunks"
44
45enum mlxsw_sp_resource_id {
46 MLXSW_SP_RESOURCE_KVD = 1,
47 MLXSW_SP_RESOURCE_KVD_LINEAR,
48 MLXSW_SP_RESOURCE_KVD_HASH_SINGLE,
49 MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE,
50 MLXSW_SP_RESOURCE_KVD_LINEAR_SINGLE,
51 MLXSW_SP_RESOURCE_KVD_LINEAR_CHUNKS,
52 MLXSW_SP_RESOURCE_KVD_LINEAR_LARGE_CHUNKS,
53};
54
55struct mlxsw_sp_port;
56struct mlxsw_sp_rif;
57struct mlxsw_sp_span_entry;
58
59struct mlxsw_sp_upper {
60 struct net_device *dev;
61 unsigned int ref_count;
62};
63
64enum mlxsw_sp_rif_type {
65 MLXSW_SP_RIF_TYPE_SUBPORT,
66 MLXSW_SP_RIF_TYPE_VLAN,
67 MLXSW_SP_RIF_TYPE_FID,
68 MLXSW_SP_RIF_TYPE_IPIP_LB,
69 MLXSW_SP_RIF_TYPE_MAX,
70};
71
72enum mlxsw_sp_fid_type {
73 MLXSW_SP_FID_TYPE_8021Q,
74 MLXSW_SP_FID_TYPE_8021D,
75 MLXSW_SP_FID_TYPE_RFID,
76 MLXSW_SP_FID_TYPE_DUMMY,
77 MLXSW_SP_FID_TYPE_MAX,
78};
79
80struct mlxsw_sp_mid {
81 struct list_head list;
82 unsigned char addr[ETH_ALEN];
83 u16 fid;
84 u16 mid;
85 bool in_hw;
86 unsigned long *ports_in_mid;
87};
88
89enum mlxsw_sp_port_mall_action_type {
90 MLXSW_SP_PORT_MALL_MIRROR,
91 MLXSW_SP_PORT_MALL_SAMPLE,
92};
93
94struct mlxsw_sp_port_mall_mirror_tc_entry {
95 int span_id;
96 bool ingress;
97};
98
99struct mlxsw_sp_port_mall_tc_entry {
100 struct list_head list;
101 unsigned long cookie;
102 enum mlxsw_sp_port_mall_action_type type;
103 union {
104 struct mlxsw_sp_port_mall_mirror_tc_entry mirror;
105 };
106};
107
108struct mlxsw_sp_sb;
109struct mlxsw_sp_bridge;
110struct mlxsw_sp_router;
111struct mlxsw_sp_mr;
112struct mlxsw_sp_acl;
113struct mlxsw_sp_counter_pool;
114struct mlxsw_sp_fid_core;
115struct mlxsw_sp_kvdl;
116struct mlxsw_sp_kvdl_ops;
117struct mlxsw_sp_mr_tcam_ops;
118struct mlxsw_sp_acl_tcam_ops;
119
120struct mlxsw_sp {
121 struct mlxsw_sp_port **ports;
122 struct mlxsw_core *core;
123 const struct mlxsw_bus_info *bus_info;
124 unsigned char base_mac[ETH_ALEN];
125 struct mlxsw_sp_upper *lags;
126 int *port_to_module;
127 struct mlxsw_sp_sb *sb;
128 struct mlxsw_sp_bridge *bridge;
129 struct mlxsw_sp_router *router;
130 struct mlxsw_sp_mr *mr;
131 struct mlxsw_afa *afa;
132 struct mlxsw_sp_acl *acl;
133 struct mlxsw_sp_fid_core *fid_core;
134 struct mlxsw_sp_kvdl *kvdl;
135 struct notifier_block netdevice_nb;
136
137 struct mlxsw_sp_counter_pool *counter_pool;
138 struct {
139 struct mlxsw_sp_span_entry *entries;
140 int entries_count;
141 } span;
142 const struct mlxsw_fw_rev *req_rev;
143 const char *fw_filename;
144 const struct mlxsw_sp_kvdl_ops *kvdl_ops;
145 const struct mlxsw_afa_ops *afa_ops;
146 const struct mlxsw_afk_ops *afk_ops;
147 const struct mlxsw_sp_mr_tcam_ops *mr_tcam_ops;
148 const struct mlxsw_sp_acl_tcam_ops *acl_tcam_ops;
149};
150
151static inline struct mlxsw_sp_upper *
152mlxsw_sp_lag_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id)
153{
154 return &mlxsw_sp->lags[lag_id];
155}
156
157struct mlxsw_sp_port_pcpu_stats {
158 u64 rx_packets;
159 u64 rx_bytes;
160 u64 tx_packets;
161 u64 tx_bytes;
162 struct u64_stats_sync syncp;
163 u32 tx_dropped;
164};
165
166struct mlxsw_sp_port_sample {
167 struct psample_group __rcu *psample_group;
168 u32 trunc_size;
169 u32 rate;
170 bool truncate;
171};
172
173struct mlxsw_sp_bridge_port;
174struct mlxsw_sp_fid;
175
176struct mlxsw_sp_port_vlan {
177 struct list_head list;
178 struct mlxsw_sp_port *mlxsw_sp_port;
179 struct mlxsw_sp_fid *fid;
180 unsigned int ref_count;
181 u16 vid;
182 struct mlxsw_sp_bridge_port *bridge_port;
183 struct list_head bridge_vlan_node;
184};
185
186
187struct mlxsw_sp_port_xstats {
188 u64 ecn;
189 u64 wred_drop[TC_MAX_QUEUE];
190 u64 tail_drop[TC_MAX_QUEUE];
191 u64 backlog[TC_MAX_QUEUE];
192 u64 tx_bytes[IEEE_8021QAZ_MAX_TCS];
193 u64 tx_packets[IEEE_8021QAZ_MAX_TCS];
194};
195
196struct mlxsw_sp_port {
197 struct net_device *dev;
198 struct mlxsw_sp_port_pcpu_stats __percpu *pcpu_stats;
199 struct mlxsw_sp *mlxsw_sp;
200 u8 local_port;
201 u8 lagged:1,
202 split:1;
203 u16 pvid;
204 u16 lag_id;
205 struct {
206 u8 tx_pause:1,
207 rx_pause:1,
208 autoneg:1;
209 } link;
210 struct {
211 struct ieee_ets *ets;
212 struct ieee_maxrate *maxrate;
213 struct ieee_pfc *pfc;
214 enum mlxsw_reg_qpts_trust_state trust_state;
215 } dcb;
216 struct {
217 u8 module;
218 u8 width;
219 u8 lane;
220 } mapping;
221
222 struct list_head mall_tc_list;
223 struct {
224 #define MLXSW_HW_STATS_UPDATE_TIME HZ
225 struct rtnl_link_stats64 stats;
226 struct mlxsw_sp_port_xstats xstats;
227 struct delayed_work update_dw;
228 } periodic_hw_stats;
229 struct mlxsw_sp_port_sample *sample;
230 struct list_head vlans_list;
231 struct mlxsw_sp_qdisc *root_qdisc;
232 struct mlxsw_sp_qdisc *tclass_qdiscs;
233 unsigned acl_rule_count;
234 struct mlxsw_sp_acl_block *ing_acl_block;
235 struct mlxsw_sp_acl_block *eg_acl_block;
236};
237
238static inline bool
239mlxsw_sp_port_is_pause_en(const struct mlxsw_sp_port *mlxsw_sp_port)
240{
241 return mlxsw_sp_port->link.tx_pause || mlxsw_sp_port->link.rx_pause;
242}
243
244static inline struct mlxsw_sp_port *
245mlxsw_sp_port_lagged_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id, u8 port_index)
246{
247 struct mlxsw_sp_port *mlxsw_sp_port;
248 u8 local_port;
249
250 local_port = mlxsw_core_lag_mapping_get(mlxsw_sp->core,
251 lag_id, port_index);
252 mlxsw_sp_port = mlxsw_sp->ports[local_port];
253 return mlxsw_sp_port && mlxsw_sp_port->lagged ? mlxsw_sp_port : NULL;
254}
255
256static inline struct mlxsw_sp_port_vlan *
257mlxsw_sp_port_vlan_find_by_vid(const struct mlxsw_sp_port *mlxsw_sp_port,
258 u16 vid)
259{
260 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
261
262 list_for_each_entry(mlxsw_sp_port_vlan, &mlxsw_sp_port->vlans_list,
263 list) {
264 if (mlxsw_sp_port_vlan->vid == vid)
265 return mlxsw_sp_port_vlan;
266 }
267
268 return NULL;
269}
270
271enum mlxsw_sp_flood_type {
272 MLXSW_SP_FLOOD_TYPE_UC,
273 MLXSW_SP_FLOOD_TYPE_BC,
274 MLXSW_SP_FLOOD_TYPE_MC,
275};
276
277
278int mlxsw_sp_buffers_init(struct mlxsw_sp *mlxsw_sp);
279void mlxsw_sp_buffers_fini(struct mlxsw_sp *mlxsw_sp);
280int mlxsw_sp_port_buffers_init(struct mlxsw_sp_port *mlxsw_sp_port);
281int mlxsw_sp_sb_pool_get(struct mlxsw_core *mlxsw_core,
282 unsigned int sb_index, u16 pool_index,
283 struct devlink_sb_pool_info *pool_info);
284int mlxsw_sp_sb_pool_set(struct mlxsw_core *mlxsw_core,
285 unsigned int sb_index, u16 pool_index, u32 size,
286 enum devlink_sb_threshold_type threshold_type);
287int mlxsw_sp_sb_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
288 unsigned int sb_index, u16 pool_index,
289 u32 *p_threshold);
290int mlxsw_sp_sb_port_pool_set(struct mlxsw_core_port *mlxsw_core_port,
291 unsigned int sb_index, u16 pool_index,
292 u32 threshold);
293int mlxsw_sp_sb_tc_pool_bind_get(struct mlxsw_core_port *mlxsw_core_port,
294 unsigned int sb_index, u16 tc_index,
295 enum devlink_sb_pool_type pool_type,
296 u16 *p_pool_index, u32 *p_threshold);
297int mlxsw_sp_sb_tc_pool_bind_set(struct mlxsw_core_port *mlxsw_core_port,
298 unsigned int sb_index, u16 tc_index,
299 enum devlink_sb_pool_type pool_type,
300 u16 pool_index, u32 threshold);
301int mlxsw_sp_sb_occ_snapshot(struct mlxsw_core *mlxsw_core,
302 unsigned int sb_index);
303int mlxsw_sp_sb_occ_max_clear(struct mlxsw_core *mlxsw_core,
304 unsigned int sb_index);
305int mlxsw_sp_sb_occ_port_pool_get(struct mlxsw_core_port *mlxsw_core_port,
306 unsigned int sb_index, u16 pool_index,
307 u32 *p_cur, u32 *p_max);
308int mlxsw_sp_sb_occ_tc_port_bind_get(struct mlxsw_core_port *mlxsw_core_port,
309 unsigned int sb_index, u16 tc_index,
310 enum devlink_sb_pool_type pool_type,
311 u32 *p_cur, u32 *p_max);
312u32 mlxsw_sp_cells_bytes(const struct mlxsw_sp *mlxsw_sp, u32 cells);
313u32 mlxsw_sp_bytes_cells(const struct mlxsw_sp *mlxsw_sp, u32 bytes);
314
315
316int mlxsw_sp_switchdev_init(struct mlxsw_sp *mlxsw_sp);
317void mlxsw_sp_switchdev_fini(struct mlxsw_sp *mlxsw_sp);
318void mlxsw_sp_port_switchdev_init(struct mlxsw_sp_port *mlxsw_sp_port);
319void mlxsw_sp_port_switchdev_fini(struct mlxsw_sp_port *mlxsw_sp_port);
320int mlxsw_sp_rif_fdb_op(struct mlxsw_sp *mlxsw_sp, const char *mac, u16 fid,
321 bool adding);
322void
323mlxsw_sp_port_vlan_bridge_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
324int mlxsw_sp_port_bridge_join(struct mlxsw_sp_port *mlxsw_sp_port,
325 struct net_device *brport_dev,
326 struct net_device *br_dev,
327 struct netlink_ext_ack *extack);
328void mlxsw_sp_port_bridge_leave(struct mlxsw_sp_port *mlxsw_sp_port,
329 struct net_device *brport_dev,
330 struct net_device *br_dev);
331bool mlxsw_sp_bridge_device_is_offloaded(const struct mlxsw_sp *mlxsw_sp,
332 const struct net_device *br_dev);
333
334
335int mlxsw_sp_port_ets_set(struct mlxsw_sp_port *mlxsw_sp_port,
336 enum mlxsw_reg_qeec_hr hr, u8 index, u8 next_index,
337 bool dwrr, u8 dwrr_weight);
338int mlxsw_sp_port_prio_tc_set(struct mlxsw_sp_port *mlxsw_sp_port,
339 u8 switch_prio, u8 tclass);
340int __mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port, int mtu,
341 u8 *prio_tc, bool pause_en,
342 struct ieee_pfc *my_pfc);
343int mlxsw_sp_port_ets_maxrate_set(struct mlxsw_sp_port *mlxsw_sp_port,
344 enum mlxsw_reg_qeec_hr hr, u8 index,
345 u8 next_index, u32 maxrate);
346enum mlxsw_reg_spms_state mlxsw_sp_stp_spms_state(u8 stp_state);
347int mlxsw_sp_port_vid_stp_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
348 u8 state);
349int mlxsw_sp_port_vp_mode_set(struct mlxsw_sp_port *mlxsw_sp_port, bool enable);
350int mlxsw_sp_port_vid_learning_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
351 bool learn_enable);
352int mlxsw_sp_port_pvid_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
353struct mlxsw_sp_port_vlan *
354mlxsw_sp_port_vlan_get(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
355void mlxsw_sp_port_vlan_put(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
356int mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid_begin,
357 u16 vid_end, bool is_member, bool untagged);
358int mlxsw_sp_flow_counter_get(struct mlxsw_sp *mlxsw_sp,
359 unsigned int counter_index, u64 *packets,
360 u64 *bytes);
361int mlxsw_sp_flow_counter_alloc(struct mlxsw_sp *mlxsw_sp,
362 unsigned int *p_counter_index);
363void mlxsw_sp_flow_counter_free(struct mlxsw_sp *mlxsw_sp,
364 unsigned int counter_index);
365bool mlxsw_sp_port_dev_check(const struct net_device *dev);
366struct mlxsw_sp *mlxsw_sp_lower_get(struct net_device *dev);
367struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find(struct net_device *dev);
368struct mlxsw_sp_port *mlxsw_sp_port_lower_dev_hold(struct net_device *dev);
369void mlxsw_sp_port_dev_put(struct mlxsw_sp_port *mlxsw_sp_port);
370struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find_rcu(struct net_device *dev);
371
372
373#ifdef CONFIG_MLXSW_SPECTRUM_DCB
374int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port);
375void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port);
376#else
377static inline int mlxsw_sp_port_dcb_init(struct mlxsw_sp_port *mlxsw_sp_port)
378{
379 return 0;
380}
381static inline void mlxsw_sp_port_dcb_fini(struct mlxsw_sp_port *mlxsw_sp_port)
382{}
383#endif
384
385
386int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp);
387void mlxsw_sp_router_fini(struct mlxsw_sp *mlxsw_sp);
388int mlxsw_sp_netdevice_router_port_event(struct net_device *dev);
389void mlxsw_sp_rif_macvlan_del(struct mlxsw_sp *mlxsw_sp,
390 const struct net_device *macvlan_dev);
391int mlxsw_sp_inetaddr_event(struct notifier_block *unused,
392 unsigned long event, void *ptr);
393int mlxsw_sp_inetaddr_valid_event(struct notifier_block *unused,
394 unsigned long event, void *ptr);
395int mlxsw_sp_inet6addr_event(struct notifier_block *unused,
396 unsigned long event, void *ptr);
397int mlxsw_sp_inet6addr_valid_event(struct notifier_block *unused,
398 unsigned long event, void *ptr);
399int mlxsw_sp_netdevice_vrf_event(struct net_device *l3_dev, unsigned long event,
400 struct netdev_notifier_changeupper_info *info);
401bool mlxsw_sp_netdev_is_ipip_ol(const struct mlxsw_sp *mlxsw_sp,
402 const struct net_device *dev);
403bool mlxsw_sp_netdev_is_ipip_ul(const struct mlxsw_sp *mlxsw_sp,
404 const struct net_device *dev);
405int mlxsw_sp_netdevice_ipip_ol_event(struct mlxsw_sp *mlxsw_sp,
406 struct net_device *l3_dev,
407 unsigned long event,
408 struct netdev_notifier_info *info);
409int
410mlxsw_sp_netdevice_ipip_ul_event(struct mlxsw_sp *mlxsw_sp,
411 struct net_device *l3_dev,
412 unsigned long event,
413 struct netdev_notifier_info *info);
414void
415mlxsw_sp_port_vlan_router_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan);
416void mlxsw_sp_rif_destroy(struct mlxsw_sp_rif *rif);
417void mlxsw_sp_rif_destroy_by_dev(struct mlxsw_sp *mlxsw_sp,
418 struct net_device *dev);
419
420
421enum mlxsw_sp_kvdl_entry_type {
422 MLXSW_SP_KVDL_ENTRY_TYPE_ADJ,
423 MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET,
424 MLXSW_SP_KVDL_ENTRY_TYPE_PBS,
425 MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR,
426};
427
428static inline unsigned int
429mlxsw_sp_kvdl_entry_size(enum mlxsw_sp_kvdl_entry_type type)
430{
431 switch (type) {
432 case MLXSW_SP_KVDL_ENTRY_TYPE_ADJ:
433 case MLXSW_SP_KVDL_ENTRY_TYPE_ACTSET:
434 case MLXSW_SP_KVDL_ENTRY_TYPE_PBS:
435 case MLXSW_SP_KVDL_ENTRY_TYPE_MCRIGR:
436 default:
437 return 1;
438 }
439}
440
441struct mlxsw_sp_kvdl_ops {
442 size_t priv_size;
443 int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
444 void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
445 int (*alloc)(struct mlxsw_sp *mlxsw_sp, void *priv,
446 enum mlxsw_sp_kvdl_entry_type type,
447 unsigned int entry_count, u32 *p_entry_index);
448 void (*free)(struct mlxsw_sp *mlxsw_sp, void *priv,
449 enum mlxsw_sp_kvdl_entry_type type,
450 unsigned int entry_count, int entry_index);
451 int (*alloc_size_query)(struct mlxsw_sp *mlxsw_sp, void *priv,
452 enum mlxsw_sp_kvdl_entry_type type,
453 unsigned int entry_count,
454 unsigned int *p_alloc_count);
455 int (*resources_register)(struct mlxsw_sp *mlxsw_sp, void *priv);
456};
457
458int mlxsw_sp_kvdl_init(struct mlxsw_sp *mlxsw_sp);
459void mlxsw_sp_kvdl_fini(struct mlxsw_sp *mlxsw_sp);
460int mlxsw_sp_kvdl_alloc(struct mlxsw_sp *mlxsw_sp,
461 enum mlxsw_sp_kvdl_entry_type type,
462 unsigned int entry_count, u32 *p_entry_index);
463void mlxsw_sp_kvdl_free(struct mlxsw_sp *mlxsw_sp,
464 enum mlxsw_sp_kvdl_entry_type type,
465 unsigned int entry_count, int entry_index);
466int mlxsw_sp_kvdl_alloc_count_query(struct mlxsw_sp *mlxsw_sp,
467 enum mlxsw_sp_kvdl_entry_type type,
468 unsigned int entry_count,
469 unsigned int *p_alloc_count);
470
471
472extern const struct mlxsw_sp_kvdl_ops mlxsw_sp1_kvdl_ops;
473int mlxsw_sp1_kvdl_resources_register(struct mlxsw_core *mlxsw_core);
474
475
476extern const struct mlxsw_sp_kvdl_ops mlxsw_sp2_kvdl_ops;
477
478struct mlxsw_sp_acl_rule_info {
479 unsigned int priority;
480 struct mlxsw_afk_element_values values;
481 struct mlxsw_afa_block *act_block;
482 unsigned int counter_index;
483};
484
485struct mlxsw_sp_acl_block;
486struct mlxsw_sp_acl_ruleset;
487
488
489enum mlxsw_sp_acl_profile {
490 MLXSW_SP_ACL_PROFILE_FLOWER,
491};
492
493struct mlxsw_afk *mlxsw_sp_acl_afk(struct mlxsw_sp_acl *acl);
494struct mlxsw_sp *mlxsw_sp_acl_block_mlxsw_sp(struct mlxsw_sp_acl_block *block);
495unsigned int mlxsw_sp_acl_block_rule_count(struct mlxsw_sp_acl_block *block);
496void mlxsw_sp_acl_block_disable_inc(struct mlxsw_sp_acl_block *block);
497void mlxsw_sp_acl_block_disable_dec(struct mlxsw_sp_acl_block *block);
498bool mlxsw_sp_acl_block_disabled(struct mlxsw_sp_acl_block *block);
499struct mlxsw_sp_acl_block *mlxsw_sp_acl_block_create(struct mlxsw_sp *mlxsw_sp,
500 struct net *net);
501void mlxsw_sp_acl_block_destroy(struct mlxsw_sp_acl_block *block);
502int mlxsw_sp_acl_block_bind(struct mlxsw_sp *mlxsw_sp,
503 struct mlxsw_sp_acl_block *block,
504 struct mlxsw_sp_port *mlxsw_sp_port,
505 bool ingress);
506int mlxsw_sp_acl_block_unbind(struct mlxsw_sp *mlxsw_sp,
507 struct mlxsw_sp_acl_block *block,
508 struct mlxsw_sp_port *mlxsw_sp_port,
509 bool ingress);
510bool mlxsw_sp_acl_block_is_egress_bound(struct mlxsw_sp_acl_block *block);
511struct mlxsw_sp_acl_ruleset *
512mlxsw_sp_acl_ruleset_lookup(struct mlxsw_sp *mlxsw_sp,
513 struct mlxsw_sp_acl_block *block, u32 chain_index,
514 enum mlxsw_sp_acl_profile profile);
515struct mlxsw_sp_acl_ruleset *
516mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp,
517 struct mlxsw_sp_acl_block *block, u32 chain_index,
518 enum mlxsw_sp_acl_profile profile,
519 struct mlxsw_afk_element_usage *tmplt_elusage);
520void mlxsw_sp_acl_ruleset_put(struct mlxsw_sp *mlxsw_sp,
521 struct mlxsw_sp_acl_ruleset *ruleset);
522u16 mlxsw_sp_acl_ruleset_group_id(struct mlxsw_sp_acl_ruleset *ruleset);
523
524struct mlxsw_sp_acl_rule_info *
525mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl);
526void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp_acl_rule_info *rulei);
527int mlxsw_sp_acl_rulei_commit(struct mlxsw_sp_acl_rule_info *rulei);
528void mlxsw_sp_acl_rulei_priority(struct mlxsw_sp_acl_rule_info *rulei,
529 unsigned int priority);
530void mlxsw_sp_acl_rulei_keymask_u32(struct mlxsw_sp_acl_rule_info *rulei,
531 enum mlxsw_afk_element element,
532 u32 key_value, u32 mask_value);
533void mlxsw_sp_acl_rulei_keymask_buf(struct mlxsw_sp_acl_rule_info *rulei,
534 enum mlxsw_afk_element element,
535 const char *key_value,
536 const char *mask_value, unsigned int len);
537int mlxsw_sp_acl_rulei_act_continue(struct mlxsw_sp_acl_rule_info *rulei);
538int mlxsw_sp_acl_rulei_act_jump(struct mlxsw_sp_acl_rule_info *rulei,
539 u16 group_id);
540int mlxsw_sp_acl_rulei_act_terminate(struct mlxsw_sp_acl_rule_info *rulei);
541int mlxsw_sp_acl_rulei_act_drop(struct mlxsw_sp_acl_rule_info *rulei);
542int mlxsw_sp_acl_rulei_act_trap(struct mlxsw_sp_acl_rule_info *rulei);
543int mlxsw_sp_acl_rulei_act_mirror(struct mlxsw_sp *mlxsw_sp,
544 struct mlxsw_sp_acl_rule_info *rulei,
545 struct mlxsw_sp_acl_block *block,
546 struct net_device *out_dev,
547 struct netlink_ext_ack *extack);
548int mlxsw_sp_acl_rulei_act_fwd(struct mlxsw_sp *mlxsw_sp,
549 struct mlxsw_sp_acl_rule_info *rulei,
550 struct net_device *out_dev,
551 struct netlink_ext_ack *extack);
552int mlxsw_sp_acl_rulei_act_vlan(struct mlxsw_sp *mlxsw_sp,
553 struct mlxsw_sp_acl_rule_info *rulei,
554 u32 action, u16 vid, u16 proto, u8 prio,
555 struct netlink_ext_ack *extack);
556int mlxsw_sp_acl_rulei_act_count(struct mlxsw_sp *mlxsw_sp,
557 struct mlxsw_sp_acl_rule_info *rulei,
558 struct netlink_ext_ack *extack);
559int mlxsw_sp_acl_rulei_act_fid_set(struct mlxsw_sp *mlxsw_sp,
560 struct mlxsw_sp_acl_rule_info *rulei,
561 u16 fid, struct netlink_ext_ack *extack);
562
563struct mlxsw_sp_acl_rule;
564
565struct mlxsw_sp_acl_rule *
566mlxsw_sp_acl_rule_create(struct mlxsw_sp *mlxsw_sp,
567 struct mlxsw_sp_acl_ruleset *ruleset,
568 unsigned long cookie,
569 struct netlink_ext_ack *extack);
570void mlxsw_sp_acl_rule_destroy(struct mlxsw_sp *mlxsw_sp,
571 struct mlxsw_sp_acl_rule *rule);
572int mlxsw_sp_acl_rule_add(struct mlxsw_sp *mlxsw_sp,
573 struct mlxsw_sp_acl_rule *rule);
574void mlxsw_sp_acl_rule_del(struct mlxsw_sp *mlxsw_sp,
575 struct mlxsw_sp_acl_rule *rule);
576struct mlxsw_sp_acl_rule *
577mlxsw_sp_acl_rule_lookup(struct mlxsw_sp *mlxsw_sp,
578 struct mlxsw_sp_acl_ruleset *ruleset,
579 unsigned long cookie);
580struct mlxsw_sp_acl_rule_info *
581mlxsw_sp_acl_rule_rulei(struct mlxsw_sp_acl_rule *rule);
582int mlxsw_sp_acl_rule_get_stats(struct mlxsw_sp *mlxsw_sp,
583 struct mlxsw_sp_acl_rule *rule,
584 u64 *packets, u64 *bytes, u64 *last_use);
585
586struct mlxsw_sp_fid *mlxsw_sp_acl_dummy_fid(struct mlxsw_sp *mlxsw_sp);
587
588int mlxsw_sp_acl_init(struct mlxsw_sp *mlxsw_sp);
589void mlxsw_sp_acl_fini(struct mlxsw_sp *mlxsw_sp);
590
591
592struct mlxsw_sp_acl_tcam;
593struct mlxsw_sp_acl_tcam_region;
594
595struct mlxsw_sp_acl_tcam_ops {
596 enum mlxsw_reg_ptar_key_type key_type;
597 size_t priv_size;
598 int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv,
599 struct mlxsw_sp_acl_tcam *tcam);
600 void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
601 size_t region_priv_size;
602 int (*region_init)(struct mlxsw_sp *mlxsw_sp, void *region_priv,
603 void *tcam_priv,
604 struct mlxsw_sp_acl_tcam_region *region);
605 void (*region_fini)(struct mlxsw_sp *mlxsw_sp, void *region_priv);
606 int (*region_associate)(struct mlxsw_sp *mlxsw_sp,
607 struct mlxsw_sp_acl_tcam_region *region);
608 size_t chunk_priv_size;
609 void (*chunk_init)(void *region_priv, void *chunk_priv,
610 unsigned int priority);
611 void (*chunk_fini)(void *chunk_priv);
612 size_t entry_priv_size;
613 int (*entry_add)(struct mlxsw_sp *mlxsw_sp,
614 void *region_priv, void *chunk_priv,
615 void *entry_priv,
616 struct mlxsw_sp_acl_rule_info *rulei);
617 void (*entry_del)(struct mlxsw_sp *mlxsw_sp,
618 void *region_priv, void *chunk_priv,
619 void *entry_priv);
620 int (*entry_activity_get)(struct mlxsw_sp *mlxsw_sp,
621 void *region_priv, void *entry_priv,
622 bool *activity);
623};
624
625
626extern const struct mlxsw_sp_acl_tcam_ops mlxsw_sp1_acl_tcam_ops;
627
628
629extern const struct mlxsw_sp_acl_tcam_ops mlxsw_sp2_acl_tcam_ops;
630
631
632extern const struct mlxsw_afa_ops mlxsw_sp1_act_afa_ops;
633extern const struct mlxsw_afa_ops mlxsw_sp2_act_afa_ops;
634
635
636extern const struct mlxsw_afk_ops mlxsw_sp1_afk_ops;
637extern const struct mlxsw_afk_ops mlxsw_sp2_afk_ops;
638
639
640int mlxsw_sp_flower_replace(struct mlxsw_sp *mlxsw_sp,
641 struct mlxsw_sp_acl_block *block,
642 struct tc_cls_flower_offload *f);
643void mlxsw_sp_flower_destroy(struct mlxsw_sp *mlxsw_sp,
644 struct mlxsw_sp_acl_block *block,
645 struct tc_cls_flower_offload *f);
646int mlxsw_sp_flower_stats(struct mlxsw_sp *mlxsw_sp,
647 struct mlxsw_sp_acl_block *block,
648 struct tc_cls_flower_offload *f);
649int mlxsw_sp_flower_tmplt_create(struct mlxsw_sp *mlxsw_sp,
650 struct mlxsw_sp_acl_block *block,
651 struct tc_cls_flower_offload *f);
652void mlxsw_sp_flower_tmplt_destroy(struct mlxsw_sp *mlxsw_sp,
653 struct mlxsw_sp_acl_block *block,
654 struct tc_cls_flower_offload *f);
655
656
657int mlxsw_sp_tc_qdisc_init(struct mlxsw_sp_port *mlxsw_sp_port);
658void mlxsw_sp_tc_qdisc_fini(struct mlxsw_sp_port *mlxsw_sp_port);
659int mlxsw_sp_setup_tc_red(struct mlxsw_sp_port *mlxsw_sp_port,
660 struct tc_red_qopt_offload *p);
661int mlxsw_sp_setup_tc_prio(struct mlxsw_sp_port *mlxsw_sp_port,
662 struct tc_prio_qopt_offload *p);
663
664
665int mlxsw_sp_fid_flood_set(struct mlxsw_sp_fid *fid,
666 enum mlxsw_sp_flood_type packet_type, u8 local_port,
667 bool member);
668int mlxsw_sp_fid_port_vid_map(struct mlxsw_sp_fid *fid,
669 struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
670void mlxsw_sp_fid_port_vid_unmap(struct mlxsw_sp_fid *fid,
671 struct mlxsw_sp_port *mlxsw_sp_port, u16 vid);
672enum mlxsw_sp_rif_type mlxsw_sp_fid_rif_type(const struct mlxsw_sp_fid *fid);
673u16 mlxsw_sp_fid_index(const struct mlxsw_sp_fid *fid);
674enum mlxsw_sp_fid_type mlxsw_sp_fid_type(const struct mlxsw_sp_fid *fid);
675void mlxsw_sp_fid_rif_set(struct mlxsw_sp_fid *fid, struct mlxsw_sp_rif *rif);
676enum mlxsw_sp_rif_type
677mlxsw_sp_fid_type_rif_type(const struct mlxsw_sp *mlxsw_sp,
678 enum mlxsw_sp_fid_type type);
679u16 mlxsw_sp_fid_8021q_vid(const struct mlxsw_sp_fid *fid);
680struct mlxsw_sp_fid *mlxsw_sp_fid_8021q_get(struct mlxsw_sp *mlxsw_sp, u16 vid);
681struct mlxsw_sp_fid *mlxsw_sp_fid_8021d_get(struct mlxsw_sp *mlxsw_sp,
682 int br_ifindex);
683struct mlxsw_sp_fid *mlxsw_sp_fid_rfid_get(struct mlxsw_sp *mlxsw_sp,
684 u16 rif_index);
685struct mlxsw_sp_fid *mlxsw_sp_fid_dummy_get(struct mlxsw_sp *mlxsw_sp);
686void mlxsw_sp_fid_put(struct mlxsw_sp_fid *fid);
687int mlxsw_sp_port_fids_init(struct mlxsw_sp_port *mlxsw_sp_port);
688void mlxsw_sp_port_fids_fini(struct mlxsw_sp_port *mlxsw_sp_port);
689int mlxsw_sp_fids_init(struct mlxsw_sp *mlxsw_sp);
690void mlxsw_sp_fids_fini(struct mlxsw_sp *mlxsw_sp);
691
692
693enum mlxsw_sp_mr_route_prio {
694 MLXSW_SP_MR_ROUTE_PRIO_SG,
695 MLXSW_SP_MR_ROUTE_PRIO_STARG,
696 MLXSW_SP_MR_ROUTE_PRIO_CATCHALL,
697 __MLXSW_SP_MR_ROUTE_PRIO_MAX
698};
699
700#define MLXSW_SP_MR_ROUTE_PRIO_MAX (__MLXSW_SP_MR_ROUTE_PRIO_MAX - 1)
701
702struct mlxsw_sp_mr_route_key;
703
704struct mlxsw_sp_mr_tcam_ops {
705 size_t priv_size;
706 int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
707 void (*fini)(void *priv);
708 size_t route_priv_size;
709 int (*route_create)(struct mlxsw_sp *mlxsw_sp, void *priv,
710 void *route_priv,
711 struct mlxsw_sp_mr_route_key *key,
712 struct mlxsw_afa_block *afa_block,
713 enum mlxsw_sp_mr_route_prio prio);
714 void (*route_destroy)(struct mlxsw_sp *mlxsw_sp, void *priv,
715 void *route_priv,
716 struct mlxsw_sp_mr_route_key *key);
717 int (*route_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
718 struct mlxsw_sp_mr_route_key *key,
719 struct mlxsw_afa_block *afa_block);
720};
721
722
723extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp1_mr_tcam_ops;
724
725
726extern const struct mlxsw_sp_mr_tcam_ops mlxsw_sp2_mr_tcam_ops;
727
728#endif
729