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