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