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