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