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