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_CORE_H 5 #define _MLXSW_CORE_H 6 7 #include <linux/module.h> 8 #include <linux/device.h> 9 #include <linux/slab.h> 10 #include <linux/gfp.h> 11 #include <linux/types.h> 12 #include <linux/skbuff.h> 13 #include <linux/workqueue.h> 14 #include <linux/net_namespace.h> 15 #include <linux/auxiliary_bus.h> 16 #include <net/devlink.h> 17 18 #include "trap.h" 19 #include "reg.h" 20 #include "cmd.h" 21 #include "resources.h" 22 #include "../mlxfw/mlxfw.h" 23 24 enum mlxsw_core_resource_id { 25 MLXSW_CORE_RESOURCE_PORTS = 1, 26 MLXSW_CORE_RESOURCE_MAX, 27 }; 28 29 struct mlxsw_core; 30 struct mlxsw_core_port; 31 struct mlxsw_driver; 32 struct mlxsw_bus; 33 struct mlxsw_bus_info; 34 struct mlxsw_fw_rev; 35 36 unsigned int mlxsw_core_max_ports(const struct mlxsw_core *mlxsw_core); 37 38 void *mlxsw_core_driver_priv(struct mlxsw_core *mlxsw_core); 39 40 struct mlxsw_linecards *mlxsw_core_linecards(struct mlxsw_core *mlxsw_core); 41 42 void mlxsw_core_linecards_set(struct mlxsw_core *mlxsw_core, 43 struct mlxsw_linecards *linecard); 44 45 bool 46 mlxsw_core_fw_rev_minor_subminor_validate(const struct mlxsw_fw_rev *rev, 47 const struct mlxsw_fw_rev *req_rev); 48 49 int mlxsw_core_driver_register(struct mlxsw_driver *mlxsw_driver); 50 void mlxsw_core_driver_unregister(struct mlxsw_driver *mlxsw_driver); 51 52 int mlxsw_core_fw_flash(struct mlxsw_core *mlxsw_core, 53 struct mlxfw_dev *mlxfw_dev, 54 const struct firmware *firmware, 55 struct netlink_ext_ack *extack); 56 57 int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info, 58 const struct mlxsw_bus *mlxsw_bus, 59 void *bus_priv, bool reload, 60 struct devlink *devlink, 61 struct netlink_ext_ack *extack); 62 void mlxsw_core_bus_device_unregister(struct mlxsw_core *mlxsw_core, bool reload); 63 64 struct mlxsw_tx_info { 65 u16 local_port; 66 bool is_emad; 67 }; 68 69 struct mlxsw_rx_md_info { 70 u32 cookie_index; 71 u32 latency; 72 u32 tx_congestion; 73 union { 74 /* Valid when 'tx_port_valid' is set. */ 75 u16 tx_sys_port; 76 u16 tx_lag_id; 77 }; 78 u16 tx_lag_port_index; /* Valid when 'tx_port_is_lag' is set. */ 79 u8 tx_tc; 80 u8 latency_valid:1, 81 tx_congestion_valid:1, 82 tx_tc_valid:1, 83 tx_port_valid:1, 84 tx_port_is_lag:1, 85 unused:3; 86 }; 87 88 bool mlxsw_core_skb_transmit_busy(struct mlxsw_core *mlxsw_core, 89 const struct mlxsw_tx_info *tx_info); 90 int mlxsw_core_skb_transmit(struct mlxsw_core *mlxsw_core, struct sk_buff *skb, 91 const struct mlxsw_tx_info *tx_info); 92 void mlxsw_core_ptp_transmitted(struct mlxsw_core *mlxsw_core, 93 struct sk_buff *skb, u16 local_port); 94 95 struct mlxsw_rx_listener { 96 void (*func)(struct sk_buff *skb, u16 local_port, void *priv); 97 u16 local_port; 98 u8 mirror_reason; 99 u16 trap_id; 100 }; 101 102 struct mlxsw_event_listener { 103 void (*func)(const struct mlxsw_reg_info *reg, 104 char *payload, void *priv); 105 enum mlxsw_event_trap_id trap_id; 106 }; 107 108 struct mlxsw_listener { 109 u16 trap_id; 110 union { 111 struct mlxsw_rx_listener rx_listener; 112 struct mlxsw_event_listener event_listener; 113 }; 114 enum mlxsw_reg_hpkt_action en_action; /* Action when enabled */ 115 enum mlxsw_reg_hpkt_action dis_action; /* Action when disabled */ 116 u8 en_trap_group; /* Trap group when enabled */ 117 u8 dis_trap_group; /* Trap group when disabled */ 118 u8 is_ctrl:1, /* should go via control buffer or not */ 119 is_event:1, 120 enabled_on_register:1; /* Trap should be enabled when listener 121 * is registered. 122 */ 123 }; 124 125 #define __MLXSW_RXL(_func, _trap_id, _en_action, _is_ctrl, _en_trap_group, \ 126 _dis_action, _enabled_on_register, _dis_trap_group, \ 127 _mirror_reason) \ 128 { \ 129 .trap_id = MLXSW_TRAP_ID_##_trap_id, \ 130 .rx_listener = \ 131 { \ 132 .func = _func, \ 133 .local_port = MLXSW_PORT_DONT_CARE, \ 134 .mirror_reason = _mirror_reason, \ 135 .trap_id = MLXSW_TRAP_ID_##_trap_id, \ 136 }, \ 137 .en_action = MLXSW_REG_HPKT_ACTION_##_en_action, \ 138 .dis_action = MLXSW_REG_HPKT_ACTION_##_dis_action, \ 139 .en_trap_group = MLXSW_REG_HTGT_TRAP_GROUP_##_en_trap_group, \ 140 .dis_trap_group = MLXSW_REG_HTGT_TRAP_GROUP_##_dis_trap_group, \ 141 .is_ctrl = _is_ctrl, \ 142 .enabled_on_register = _enabled_on_register, \ 143 } 144 145 #define MLXSW_RXL(_func, _trap_id, _en_action, _is_ctrl, _trap_group, \ 146 _dis_action) \ 147 __MLXSW_RXL(_func, _trap_id, _en_action, _is_ctrl, _trap_group, \ 148 _dis_action, true, _trap_group, 0) 149 150 #define MLXSW_RXL_DIS(_func, _trap_id, _en_action, _is_ctrl, _en_trap_group, \ 151 _dis_action, _dis_trap_group) \ 152 __MLXSW_RXL(_func, _trap_id, _en_action, _is_ctrl, _en_trap_group, \ 153 _dis_action, false, _dis_trap_group, 0) 154 155 #define MLXSW_RXL_MIRROR(_func, _session_id, _trap_group, _mirror_reason) \ 156 __MLXSW_RXL(_func, MIRROR_SESSION##_session_id, TRAP_TO_CPU, false, \ 157 _trap_group, TRAP_TO_CPU, true, _trap_group, \ 158 _mirror_reason) 159 160 #define MLXSW_EVENTL(_func, _trap_id, _trap_group) \ 161 { \ 162 .trap_id = MLXSW_TRAP_ID_##_trap_id, \ 163 .event_listener = \ 164 { \ 165 .func = _func, \ 166 .trap_id = MLXSW_TRAP_ID_##_trap_id, \ 167 }, \ 168 .en_action = MLXSW_REG_HPKT_ACTION_TRAP_TO_CPU, \ 169 .en_trap_group = MLXSW_REG_HTGT_TRAP_GROUP_##_trap_group, \ 170 .is_event = true, \ 171 .enabled_on_register = true, \ 172 } 173 174 #define MLXSW_CORE_EVENTL(_func, _trap_id) \ 175 MLXSW_EVENTL(_func, _trap_id, CORE_EVENT) 176 177 int mlxsw_core_rx_listener_register(struct mlxsw_core *mlxsw_core, 178 const struct mlxsw_rx_listener *rxl, 179 void *priv, bool enabled); 180 void mlxsw_core_rx_listener_unregister(struct mlxsw_core *mlxsw_core, 181 const struct mlxsw_rx_listener *rxl); 182 183 int mlxsw_core_event_listener_register(struct mlxsw_core *mlxsw_core, 184 const struct mlxsw_event_listener *el, 185 void *priv); 186 void mlxsw_core_event_listener_unregister(struct mlxsw_core *mlxsw_core, 187 const struct mlxsw_event_listener *el); 188 189 int mlxsw_core_trap_register(struct mlxsw_core *mlxsw_core, 190 const struct mlxsw_listener *listener, 191 void *priv); 192 void mlxsw_core_trap_unregister(struct mlxsw_core *mlxsw_core, 193 const struct mlxsw_listener *listener, 194 void *priv); 195 int mlxsw_core_traps_register(struct mlxsw_core *mlxsw_core, 196 const struct mlxsw_listener *listeners, 197 size_t listeners_count, void *priv); 198 void mlxsw_core_traps_unregister(struct mlxsw_core *mlxsw_core, 199 const struct mlxsw_listener *listeners, 200 size_t listeners_count, void *priv); 201 int mlxsw_core_trap_state_set(struct mlxsw_core *mlxsw_core, 202 const struct mlxsw_listener *listener, 203 bool enabled); 204 205 typedef void mlxsw_reg_trans_cb_t(struct mlxsw_core *mlxsw_core, char *payload, 206 size_t payload_len, unsigned long cb_priv); 207 208 int mlxsw_reg_trans_query(struct mlxsw_core *mlxsw_core, 209 const struct mlxsw_reg_info *reg, char *payload, 210 struct list_head *bulk_list, 211 mlxsw_reg_trans_cb_t *cb, unsigned long cb_priv); 212 int mlxsw_reg_trans_write(struct mlxsw_core *mlxsw_core, 213 const struct mlxsw_reg_info *reg, char *payload, 214 struct list_head *bulk_list, 215 mlxsw_reg_trans_cb_t *cb, unsigned long cb_priv); 216 int mlxsw_reg_trans_bulk_wait(struct list_head *bulk_list); 217 218 int mlxsw_reg_query(struct mlxsw_core *mlxsw_core, 219 const struct mlxsw_reg_info *reg, char *payload); 220 int mlxsw_reg_write(struct mlxsw_core *mlxsw_core, 221 const struct mlxsw_reg_info *reg, char *payload); 222 223 struct mlxsw_rx_info { 224 bool is_lag; 225 union { 226 u16 sys_port; 227 u16 lag_id; 228 } u; 229 u16 lag_port_index; 230 u8 mirror_reason; 231 int trap_id; 232 }; 233 234 void mlxsw_core_skb_receive(struct mlxsw_core *mlxsw_core, struct sk_buff *skb, 235 struct mlxsw_rx_info *rx_info); 236 237 void mlxsw_core_lag_mapping_set(struct mlxsw_core *mlxsw_core, 238 u16 lag_id, u8 port_index, u16 local_port); 239 u16 mlxsw_core_lag_mapping_get(struct mlxsw_core *mlxsw_core, 240 u16 lag_id, u8 port_index); 241 void mlxsw_core_lag_mapping_clear(struct mlxsw_core *mlxsw_core, 242 u16 lag_id, u16 local_port); 243 244 void *mlxsw_core_port_driver_priv(struct mlxsw_core_port *mlxsw_core_port); 245 int mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u16 local_port, 246 u8 slot_index, u32 port_number, bool split, 247 u32 split_port_subnumber, 248 bool splittable, u32 lanes, 249 const unsigned char *switch_id, 250 unsigned char switch_id_len); 251 void mlxsw_core_port_fini(struct mlxsw_core *mlxsw_core, u16 local_port); 252 int mlxsw_core_cpu_port_init(struct mlxsw_core *mlxsw_core, 253 void *port_driver_priv, 254 const unsigned char *switch_id, 255 unsigned char switch_id_len); 256 void mlxsw_core_cpu_port_fini(struct mlxsw_core *mlxsw_core); 257 void mlxsw_core_port_eth_set(struct mlxsw_core *mlxsw_core, u16 local_port, 258 void *port_driver_priv, struct net_device *dev); 259 void mlxsw_core_port_ib_set(struct mlxsw_core *mlxsw_core, u16 local_port, 260 void *port_driver_priv); 261 void mlxsw_core_port_clear(struct mlxsw_core *mlxsw_core, u16 local_port, 262 void *port_driver_priv); 263 enum devlink_port_type mlxsw_core_port_type_get(struct mlxsw_core *mlxsw_core, 264 u16 local_port); 265 struct devlink_port * 266 mlxsw_core_port_devlink_port_get(struct mlxsw_core *mlxsw_core, 267 u16 local_port); 268 struct mlxsw_linecard * 269 mlxsw_core_port_linecard_get(struct mlxsw_core *mlxsw_core, 270 u16 local_port); 271 void mlxsw_core_ports_remove_selected(struct mlxsw_core *mlxsw_core, 272 bool (*selector)(void *priv, 273 u16 local_port), 274 void *priv); 275 struct mlxsw_env *mlxsw_core_env(const struct mlxsw_core *mlxsw_core); 276 277 int mlxsw_core_schedule_dw(struct delayed_work *dwork, unsigned long delay); 278 bool mlxsw_core_schedule_work(struct work_struct *work); 279 void mlxsw_core_flush_owq(void); 280 int mlxsw_core_resources_query(struct mlxsw_core *mlxsw_core, char *mbox, 281 struct mlxsw_res *res); 282 283 #define MLXSW_CONFIG_PROFILE_SWID_COUNT 8 284 285 struct mlxsw_swid_config { 286 u8 used_type:1, 287 used_properties:1; 288 u8 type; 289 u8 properties; 290 }; 291 292 struct mlxsw_config_profile { 293 u16 used_max_vepa_channels:1, 294 used_max_mid:1, 295 used_max_pgt:1, 296 used_max_system_port:1, 297 used_max_vlan_groups:1, 298 used_max_regions:1, 299 used_flood_tables:1, 300 used_flood_mode:1, 301 used_max_ib_mc:1, 302 used_max_pkey:1, 303 used_ar_sec:1, 304 used_adaptive_routing_group_cap:1, 305 used_ubridge:1, 306 used_kvd_sizes:1, 307 used_cqe_time_stamp_type:1; 308 u8 max_vepa_channels; 309 u16 max_mid; 310 u16 max_pgt; 311 u16 max_system_port; 312 u16 max_vlan_groups; 313 u16 max_regions; 314 u8 max_flood_tables; 315 u8 max_vid_flood_tables; 316 u8 flood_mode; 317 u8 max_fid_offset_flood_tables; 318 u16 fid_offset_flood_table_size; 319 u8 max_fid_flood_tables; 320 u16 fid_flood_table_size; 321 u16 max_ib_mc; 322 u16 max_pkey; 323 u8 ar_sec; 324 u16 adaptive_routing_group_cap; 325 u8 arn; 326 u8 ubridge; 327 u32 kvd_linear_size; 328 u8 kvd_hash_single_parts; 329 u8 kvd_hash_double_parts; 330 u8 cqe_time_stamp_type; 331 struct mlxsw_swid_config swid_config[MLXSW_CONFIG_PROFILE_SWID_COUNT]; 332 }; 333 334 struct mlxsw_driver { 335 struct list_head list; 336 const char *kind; 337 size_t priv_size; 338 const struct mlxsw_fw_rev *fw_req_rev; 339 const char *fw_filename; 340 int (*init)(struct mlxsw_core *mlxsw_core, 341 const struct mlxsw_bus_info *mlxsw_bus_info, 342 struct netlink_ext_ack *extack); 343 void (*fini)(struct mlxsw_core *mlxsw_core); 344 int (*port_type_set)(struct mlxsw_core *mlxsw_core, u16 local_port, 345 enum devlink_port_type new_type); 346 int (*port_split)(struct mlxsw_core *mlxsw_core, u16 local_port, 347 unsigned int count, struct netlink_ext_ack *extack); 348 int (*port_unsplit)(struct mlxsw_core *mlxsw_core, u16 local_port, 349 struct netlink_ext_ack *extack); 350 void (*ports_remove_selected)(struct mlxsw_core *mlxsw_core, 351 bool (*selector)(void *priv, 352 u16 local_port), 353 void *priv); 354 int (*sb_pool_get)(struct mlxsw_core *mlxsw_core, 355 unsigned int sb_index, u16 pool_index, 356 struct devlink_sb_pool_info *pool_info); 357 int (*sb_pool_set)(struct mlxsw_core *mlxsw_core, 358 unsigned int sb_index, u16 pool_index, u32 size, 359 enum devlink_sb_threshold_type threshold_type, 360 struct netlink_ext_ack *extack); 361 int (*sb_port_pool_get)(struct mlxsw_core_port *mlxsw_core_port, 362 unsigned int sb_index, u16 pool_index, 363 u32 *p_threshold); 364 int (*sb_port_pool_set)(struct mlxsw_core_port *mlxsw_core_port, 365 unsigned int sb_index, u16 pool_index, 366 u32 threshold, struct netlink_ext_ack *extack); 367 int (*sb_tc_pool_bind_get)(struct mlxsw_core_port *mlxsw_core_port, 368 unsigned int sb_index, u16 tc_index, 369 enum devlink_sb_pool_type pool_type, 370 u16 *p_pool_index, u32 *p_threshold); 371 int (*sb_tc_pool_bind_set)(struct mlxsw_core_port *mlxsw_core_port, 372 unsigned int sb_index, u16 tc_index, 373 enum devlink_sb_pool_type pool_type, 374 u16 pool_index, u32 threshold, 375 struct netlink_ext_ack *extack); 376 int (*sb_occ_snapshot)(struct mlxsw_core *mlxsw_core, 377 unsigned int sb_index); 378 int (*sb_occ_max_clear)(struct mlxsw_core *mlxsw_core, 379 unsigned int sb_index); 380 int (*sb_occ_port_pool_get)(struct mlxsw_core_port *mlxsw_core_port, 381 unsigned int sb_index, u16 pool_index, 382 u32 *p_cur, u32 *p_max); 383 int (*sb_occ_tc_port_bind_get)(struct mlxsw_core_port *mlxsw_core_port, 384 unsigned int sb_index, u16 tc_index, 385 enum devlink_sb_pool_type pool_type, 386 u32 *p_cur, u32 *p_max); 387 int (*trap_init)(struct mlxsw_core *mlxsw_core, 388 const struct devlink_trap *trap, void *trap_ctx); 389 void (*trap_fini)(struct mlxsw_core *mlxsw_core, 390 const struct devlink_trap *trap, void *trap_ctx); 391 int (*trap_action_set)(struct mlxsw_core *mlxsw_core, 392 const struct devlink_trap *trap, 393 enum devlink_trap_action action, 394 struct netlink_ext_ack *extack); 395 int (*trap_group_init)(struct mlxsw_core *mlxsw_core, 396 const struct devlink_trap_group *group); 397 int (*trap_group_set)(struct mlxsw_core *mlxsw_core, 398 const struct devlink_trap_group *group, 399 const struct devlink_trap_policer *policer, 400 struct netlink_ext_ack *extack); 401 int (*trap_policer_init)(struct mlxsw_core *mlxsw_core, 402 const struct devlink_trap_policer *policer); 403 void (*trap_policer_fini)(struct mlxsw_core *mlxsw_core, 404 const struct devlink_trap_policer *policer); 405 int (*trap_policer_set)(struct mlxsw_core *mlxsw_core, 406 const struct devlink_trap_policer *policer, 407 u64 rate, u64 burst, 408 struct netlink_ext_ack *extack); 409 int (*trap_policer_counter_get)(struct mlxsw_core *mlxsw_core, 410 const struct devlink_trap_policer *policer, 411 u64 *p_drops); 412 void (*txhdr_construct)(struct sk_buff *skb, 413 const struct mlxsw_tx_info *tx_info); 414 int (*resources_register)(struct mlxsw_core *mlxsw_core); 415 int (*kvd_sizes_get)(struct mlxsw_core *mlxsw_core, 416 const struct mlxsw_config_profile *profile, 417 u64 *p_single_size, u64 *p_double_size, 418 u64 *p_linear_size); 419 int (*params_register)(struct mlxsw_core *mlxsw_core); 420 void (*params_unregister)(struct mlxsw_core *mlxsw_core); 421 422 /* Notify a driver that a timestamped packet was transmitted. Driver 423 * is responsible for freeing the passed-in SKB. 424 */ 425 void (*ptp_transmitted)(struct mlxsw_core *mlxsw_core, 426 struct sk_buff *skb, u16 local_port); 427 428 u8 txhdr_len; 429 const struct mlxsw_config_profile *profile; 430 bool sdq_supports_cqe_v2; 431 }; 432 433 int mlxsw_core_kvd_sizes_get(struct mlxsw_core *mlxsw_core, 434 const struct mlxsw_config_profile *profile, 435 u64 *p_single_size, u64 *p_double_size, 436 u64 *p_linear_size); 437 438 u32 mlxsw_core_read_frc_h(struct mlxsw_core *mlxsw_core); 439 u32 mlxsw_core_read_frc_l(struct mlxsw_core *mlxsw_core); 440 441 u32 mlxsw_core_read_utc_sec(struct mlxsw_core *mlxsw_core); 442 u32 mlxsw_core_read_utc_nsec(struct mlxsw_core *mlxsw_core); 443 444 bool mlxsw_core_sdq_supports_cqe_v2(struct mlxsw_core *mlxsw_core); 445 446 void mlxsw_core_emad_string_tlv_enable(struct mlxsw_core *mlxsw_core); 447 448 bool mlxsw_core_res_valid(struct mlxsw_core *mlxsw_core, 449 enum mlxsw_res_id res_id); 450 451 #define MLXSW_CORE_RES_VALID(mlxsw_core, short_res_id) \ 452 mlxsw_core_res_valid(mlxsw_core, MLXSW_RES_ID_##short_res_id) 453 454 u64 mlxsw_core_res_get(struct mlxsw_core *mlxsw_core, 455 enum mlxsw_res_id res_id); 456 457 #define MLXSW_CORE_RES_GET(mlxsw_core, short_res_id) \ 458 mlxsw_core_res_get(mlxsw_core, MLXSW_RES_ID_##short_res_id) 459 460 static inline struct net *mlxsw_core_net(struct mlxsw_core *mlxsw_core) 461 { 462 return devlink_net(priv_to_devlink(mlxsw_core)); 463 } 464 465 #define MLXSW_BUS_F_TXRX BIT(0) 466 #define MLXSW_BUS_F_RESET BIT(1) 467 468 struct mlxsw_bus { 469 const char *kind; 470 int (*init)(void *bus_priv, struct mlxsw_core *mlxsw_core, 471 const struct mlxsw_config_profile *profile, 472 struct mlxsw_res *res); 473 void (*fini)(void *bus_priv); 474 bool (*skb_transmit_busy)(void *bus_priv, 475 const struct mlxsw_tx_info *tx_info); 476 int (*skb_transmit)(void *bus_priv, struct sk_buff *skb, 477 const struct mlxsw_tx_info *tx_info); 478 int (*cmd_exec)(void *bus_priv, u16 opcode, u8 opcode_mod, 479 u32 in_mod, bool out_mbox_direct, 480 char *in_mbox, size_t in_mbox_size, 481 char *out_mbox, size_t out_mbox_size, 482 u8 *p_status); 483 u32 (*read_frc_h)(void *bus_priv); 484 u32 (*read_frc_l)(void *bus_priv); 485 u32 (*read_utc_sec)(void *bus_priv); 486 u32 (*read_utc_nsec)(void *bus_priv); 487 u8 features; 488 }; 489 490 struct mlxsw_fw_rev { 491 u16 major; 492 u16 minor; 493 u16 subminor; 494 u16 can_reset_minor; 495 }; 496 497 struct mlxsw_bus_info { 498 const char *device_kind; 499 const char *device_name; 500 struct device *dev; 501 struct mlxsw_fw_rev fw_rev; 502 u8 vsd[MLXSW_CMD_BOARDINFO_VSD_LEN]; 503 u8 psid[MLXSW_CMD_BOARDINFO_PSID_LEN]; 504 u8 low_frequency:1, 505 read_clock_capable:1; 506 }; 507 508 struct mlxsw_hwmon; 509 510 #ifdef CONFIG_MLXSW_CORE_HWMON 511 512 int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core, 513 const struct mlxsw_bus_info *mlxsw_bus_info, 514 struct mlxsw_hwmon **p_hwmon); 515 void mlxsw_hwmon_fini(struct mlxsw_hwmon *mlxsw_hwmon); 516 517 #else 518 519 static inline int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core, 520 const struct mlxsw_bus_info *mlxsw_bus_info, 521 struct mlxsw_hwmon **p_hwmon) 522 { 523 return 0; 524 } 525 526 static inline void mlxsw_hwmon_fini(struct mlxsw_hwmon *mlxsw_hwmon) 527 { 528 } 529 530 #endif 531 532 struct mlxsw_thermal; 533 534 #ifdef CONFIG_MLXSW_CORE_THERMAL 535 536 int mlxsw_thermal_init(struct mlxsw_core *mlxsw_core, 537 const struct mlxsw_bus_info *mlxsw_bus_info, 538 struct mlxsw_thermal **p_thermal); 539 void mlxsw_thermal_fini(struct mlxsw_thermal *thermal); 540 541 #else 542 543 static inline int mlxsw_thermal_init(struct mlxsw_core *mlxsw_core, 544 const struct mlxsw_bus_info *mlxsw_bus_info, 545 struct mlxsw_thermal **p_thermal) 546 { 547 return 0; 548 } 549 550 static inline void mlxsw_thermal_fini(struct mlxsw_thermal *thermal) 551 { 552 } 553 554 #endif 555 556 enum mlxsw_devlink_param_id { 557 MLXSW_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX, 558 MLXSW_DEVLINK_PARAM_ID_ACL_REGION_REHASH_INTERVAL, 559 }; 560 561 struct mlxsw_cqe_ts { 562 u8 sec; 563 u32 nsec; 564 }; 565 566 struct mlxsw_skb_cb { 567 union { 568 struct mlxsw_tx_info tx_info; 569 struct mlxsw_rx_md_info rx_md_info; 570 }; 571 struct mlxsw_cqe_ts cqe_ts; 572 }; 573 574 static inline struct mlxsw_skb_cb *mlxsw_skb_cb(struct sk_buff *skb) 575 { 576 BUILD_BUG_ON(sizeof(mlxsw_skb_cb) > sizeof(skb->cb)); 577 return (struct mlxsw_skb_cb *) skb->cb; 578 } 579 580 struct mlxsw_linecards; 581 582 enum mlxsw_linecard_status_event_type { 583 MLXSW_LINECARD_STATUS_EVENT_TYPE_PROVISION, 584 MLXSW_LINECARD_STATUS_EVENT_TYPE_UNPROVISION, 585 }; 586 587 struct mlxsw_linecard_bdev; 588 589 struct mlxsw_linecard_device_info { 590 u16 fw_major; 591 u16 fw_minor; 592 u16 fw_sub_minor; 593 char psid[MLXSW_REG_MGIR_FW_INFO_PSID_SIZE]; 594 }; 595 596 struct mlxsw_linecard { 597 u8 slot_index; 598 struct mlxsw_linecards *linecards; 599 struct devlink_linecard *devlink_linecard; 600 struct mutex lock; /* Locks accesses to the linecard structure */ 601 char name[MLXSW_REG_MDDQ_SLOT_ASCII_NAME_LEN]; 602 char mbct_pl[MLXSW_REG_MBCT_LEN]; /* Too big for stack */ 603 enum mlxsw_linecard_status_event_type status_event_type_to; 604 struct delayed_work status_event_to_dw; 605 u8 provisioned:1, 606 ready:1, 607 active:1; 608 u16 hw_revision; 609 u16 ini_version; 610 struct mlxsw_linecard_bdev *bdev; 611 struct { 612 struct mlxsw_linecard_device_info info; 613 u8 index; 614 } device; 615 }; 616 617 struct mlxsw_linecard_types_info; 618 619 struct mlxsw_linecards { 620 struct mlxsw_core *mlxsw_core; 621 const struct mlxsw_bus_info *bus_info; 622 u8 count; 623 struct mlxsw_linecard_types_info *types_info; 624 struct list_head event_ops_list; 625 struct mutex event_ops_list_lock; /* Locks accesses to event ops list */ 626 struct mlxsw_linecard linecards[]; 627 }; 628 629 static inline struct mlxsw_linecard * 630 mlxsw_linecard_get(struct mlxsw_linecards *linecards, u8 slot_index) 631 { 632 return &linecards->linecards[slot_index - 1]; 633 } 634 635 int mlxsw_linecard_devlink_info_get(struct mlxsw_linecard *linecard, 636 struct devlink_info_req *req, 637 struct netlink_ext_ack *extack); 638 int mlxsw_linecard_flash_update(struct devlink *linecard_devlink, 639 struct mlxsw_linecard *linecard, 640 const struct firmware *firmware, 641 struct netlink_ext_ack *extack); 642 643 int mlxsw_linecards_init(struct mlxsw_core *mlxsw_core, 644 const struct mlxsw_bus_info *bus_info); 645 void mlxsw_linecards_fini(struct mlxsw_core *mlxsw_core); 646 647 typedef void mlxsw_linecards_event_op_t(struct mlxsw_core *mlxsw_core, 648 u8 slot_index, void *priv); 649 650 struct mlxsw_linecards_event_ops { 651 mlxsw_linecards_event_op_t *got_active; 652 mlxsw_linecards_event_op_t *got_inactive; 653 }; 654 655 int mlxsw_linecards_event_ops_register(struct mlxsw_core *mlxsw_core, 656 struct mlxsw_linecards_event_ops *ops, 657 void *priv); 658 void mlxsw_linecards_event_ops_unregister(struct mlxsw_core *mlxsw_core, 659 struct mlxsw_linecards_event_ops *ops, 660 void *priv); 661 662 int mlxsw_linecard_bdev_add(struct mlxsw_linecard *linecard); 663 void mlxsw_linecard_bdev_del(struct mlxsw_linecard *linecard); 664 665 int mlxsw_linecard_driver_register(void); 666 void mlxsw_linecard_driver_unregister(void); 667 668 #endif 669