Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
0002 /* Copyright (c) 2015-2018 Mellanox Technologies. All rights reserved */
0003 
0004 #ifndef _MLXSW_CORE_H
0005 #define _MLXSW_CORE_H
0006 
0007 #include <linux/module.h>
0008 #include <linux/device.h>
0009 #include <linux/slab.h>
0010 #include <linux/gfp.h>
0011 #include <linux/types.h>
0012 #include <linux/skbuff.h>
0013 #include <linux/workqueue.h>
0014 #include <linux/net_namespace.h>
0015 #include <linux/auxiliary_bus.h>
0016 #include <net/devlink.h>
0017 
0018 #include "trap.h"
0019 #include "reg.h"
0020 #include "cmd.h"
0021 #include "resources.h"
0022 #include "../mlxfw/mlxfw.h"
0023 
0024 enum mlxsw_core_resource_id {
0025     MLXSW_CORE_RESOURCE_PORTS = 1,
0026     MLXSW_CORE_RESOURCE_MAX,
0027 };
0028 
0029 struct mlxsw_core;
0030 struct mlxsw_core_port;
0031 struct mlxsw_driver;
0032 struct mlxsw_bus;
0033 struct mlxsw_bus_info;
0034 struct mlxsw_fw_rev;
0035 
0036 unsigned int mlxsw_core_max_ports(const struct mlxsw_core *mlxsw_core);
0037 
0038 void *mlxsw_core_driver_priv(struct mlxsw_core *mlxsw_core);
0039 
0040 struct mlxsw_linecards *mlxsw_core_linecards(struct mlxsw_core *mlxsw_core);
0041 
0042 void mlxsw_core_linecards_set(struct mlxsw_core *mlxsw_core,
0043                   struct mlxsw_linecards *linecard);
0044 
0045 bool
0046 mlxsw_core_fw_rev_minor_subminor_validate(const struct mlxsw_fw_rev *rev,
0047                       const struct mlxsw_fw_rev *req_rev);
0048 
0049 int mlxsw_core_driver_register(struct mlxsw_driver *mlxsw_driver);
0050 void mlxsw_core_driver_unregister(struct mlxsw_driver *mlxsw_driver);
0051 
0052 int mlxsw_core_fw_flash(struct mlxsw_core *mlxsw_core,
0053             struct mlxfw_dev *mlxfw_dev,
0054             const struct firmware *firmware,
0055             struct netlink_ext_ack *extack);
0056 
0057 int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
0058                    const struct mlxsw_bus *mlxsw_bus,
0059                    void *bus_priv, bool reload,
0060                    struct devlink *devlink,
0061                    struct netlink_ext_ack *extack);
0062 void mlxsw_core_bus_device_unregister(struct mlxsw_core *mlxsw_core, bool reload);
0063 
0064 struct mlxsw_tx_info {
0065     u16 local_port;
0066     bool is_emad;
0067 };
0068 
0069 struct mlxsw_rx_md_info {
0070     u32 cookie_index;
0071     u32 latency;
0072     u32 tx_congestion;
0073     union {
0074         /* Valid when 'tx_port_valid' is set. */
0075         u16 tx_sys_port;
0076         u16 tx_lag_id;
0077     };
0078     u16 tx_lag_port_index; /* Valid when 'tx_port_is_lag' is set. */
0079     u8 tx_tc;
0080     u8 latency_valid:1,
0081        tx_congestion_valid:1,
0082        tx_tc_valid:1,
0083        tx_port_valid:1,
0084        tx_port_is_lag:1,
0085        unused:3;
0086 };
0087 
0088 bool mlxsw_core_skb_transmit_busy(struct mlxsw_core *mlxsw_core,
0089                   const struct mlxsw_tx_info *tx_info);
0090 int mlxsw_core_skb_transmit(struct mlxsw_core *mlxsw_core, struct sk_buff *skb,
0091                 const struct mlxsw_tx_info *tx_info);
0092 void mlxsw_core_ptp_transmitted(struct mlxsw_core *mlxsw_core,
0093                 struct sk_buff *skb, u16 local_port);
0094 
0095 struct mlxsw_rx_listener {
0096     void (*func)(struct sk_buff *skb, u16 local_port, void *priv);
0097     u16 local_port;
0098     u8 mirror_reason;
0099     u16 trap_id;
0100 };
0101 
0102 struct mlxsw_event_listener {
0103     void (*func)(const struct mlxsw_reg_info *reg,
0104              char *payload, void *priv);
0105     enum mlxsw_event_trap_id trap_id;
0106 };
0107 
0108 struct mlxsw_listener {
0109     u16 trap_id;
0110     union {
0111         struct mlxsw_rx_listener rx_listener;
0112         struct mlxsw_event_listener event_listener;
0113     };
0114     enum mlxsw_reg_hpkt_action en_action; /* Action when enabled */
0115     enum mlxsw_reg_hpkt_action dis_action; /* Action when disabled */
0116     u8 en_trap_group; /* Trap group when enabled */
0117     u8 dis_trap_group; /* Trap group when disabled */
0118     u8 is_ctrl:1, /* should go via control buffer or not */
0119        is_event:1,
0120        enabled_on_register:1; /* Trap should be enabled when listener
0121                    * is registered.
0122                    */
0123 };
0124 
0125 #define __MLXSW_RXL(_func, _trap_id, _en_action, _is_ctrl, _en_trap_group,  \
0126             _dis_action, _enabled_on_register, _dis_trap_group,     \
0127             _mirror_reason)                     \
0128     {                                   \
0129         .trap_id = MLXSW_TRAP_ID_##_trap_id,                \
0130         .rx_listener =                          \
0131         {                               \
0132             .func = _func,                      \
0133             .local_port = MLXSW_PORT_DONT_CARE,         \
0134             .mirror_reason = _mirror_reason,            \
0135             .trap_id = MLXSW_TRAP_ID_##_trap_id,            \
0136         },                              \
0137         .en_action = MLXSW_REG_HPKT_ACTION_##_en_action,        \
0138         .dis_action = MLXSW_REG_HPKT_ACTION_##_dis_action,      \
0139         .en_trap_group = MLXSW_REG_HTGT_TRAP_GROUP_##_en_trap_group,    \
0140         .dis_trap_group = MLXSW_REG_HTGT_TRAP_GROUP_##_dis_trap_group,  \
0141         .is_ctrl = _is_ctrl,                        \
0142         .enabled_on_register = _enabled_on_register,            \
0143     }
0144 
0145 #define MLXSW_RXL(_func, _trap_id, _en_action, _is_ctrl, _trap_group,       \
0146           _dis_action)                          \
0147     __MLXSW_RXL(_func, _trap_id, _en_action, _is_ctrl, _trap_group,     \
0148             _dis_action, true, _trap_group, 0)
0149 
0150 #define MLXSW_RXL_DIS(_func, _trap_id, _en_action, _is_ctrl, _en_trap_group,    \
0151               _dis_action, _dis_trap_group)             \
0152     __MLXSW_RXL(_func, _trap_id, _en_action, _is_ctrl, _en_trap_group,  \
0153             _dis_action, false, _dis_trap_group, 0)
0154 
0155 #define MLXSW_RXL_MIRROR(_func, _session_id, _trap_group, _mirror_reason)   \
0156     __MLXSW_RXL(_func, MIRROR_SESSION##_session_id, TRAP_TO_CPU, false, \
0157             _trap_group, TRAP_TO_CPU, true, _trap_group,        \
0158             _mirror_reason)
0159 
0160 #define MLXSW_EVENTL(_func, _trap_id, _trap_group)              \
0161     {                                   \
0162         .trap_id = MLXSW_TRAP_ID_##_trap_id,                \
0163         .event_listener =                       \
0164         {                               \
0165             .func = _func,                      \
0166             .trap_id = MLXSW_TRAP_ID_##_trap_id,            \
0167         },                              \
0168         .en_action = MLXSW_REG_HPKT_ACTION_TRAP_TO_CPU,         \
0169         .en_trap_group = MLXSW_REG_HTGT_TRAP_GROUP_##_trap_group,   \
0170         .is_event = true,                       \
0171         .enabled_on_register = true,                    \
0172     }
0173 
0174 #define MLXSW_CORE_EVENTL(_func, _trap_id)      \
0175     MLXSW_EVENTL(_func, _trap_id, CORE_EVENT)
0176 
0177 int mlxsw_core_rx_listener_register(struct mlxsw_core *mlxsw_core,
0178                     const struct mlxsw_rx_listener *rxl,
0179                     void *priv, bool enabled);
0180 void mlxsw_core_rx_listener_unregister(struct mlxsw_core *mlxsw_core,
0181                        const struct mlxsw_rx_listener *rxl);
0182 
0183 int mlxsw_core_event_listener_register(struct mlxsw_core *mlxsw_core,
0184                        const struct mlxsw_event_listener *el,
0185                        void *priv);
0186 void mlxsw_core_event_listener_unregister(struct mlxsw_core *mlxsw_core,
0187                       const struct mlxsw_event_listener *el);
0188 
0189 int mlxsw_core_trap_register(struct mlxsw_core *mlxsw_core,
0190                  const struct mlxsw_listener *listener,
0191                  void *priv);
0192 void mlxsw_core_trap_unregister(struct mlxsw_core *mlxsw_core,
0193                 const struct mlxsw_listener *listener,
0194                 void *priv);
0195 int mlxsw_core_traps_register(struct mlxsw_core *mlxsw_core,
0196                   const struct mlxsw_listener *listeners,
0197                   size_t listeners_count, void *priv);
0198 void mlxsw_core_traps_unregister(struct mlxsw_core *mlxsw_core,
0199                  const struct mlxsw_listener *listeners,
0200                  size_t listeners_count, void *priv);
0201 int mlxsw_core_trap_state_set(struct mlxsw_core *mlxsw_core,
0202                   const struct mlxsw_listener *listener,
0203                   bool enabled);
0204 
0205 typedef void mlxsw_reg_trans_cb_t(struct mlxsw_core *mlxsw_core, char *payload,
0206                   size_t payload_len, unsigned long cb_priv);
0207 
0208 int mlxsw_reg_trans_query(struct mlxsw_core *mlxsw_core,
0209               const struct mlxsw_reg_info *reg, char *payload,
0210               struct list_head *bulk_list,
0211               mlxsw_reg_trans_cb_t *cb, unsigned long cb_priv);
0212 int mlxsw_reg_trans_write(struct mlxsw_core *mlxsw_core,
0213               const struct mlxsw_reg_info *reg, char *payload,
0214               struct list_head *bulk_list,
0215               mlxsw_reg_trans_cb_t *cb, unsigned long cb_priv);
0216 int mlxsw_reg_trans_bulk_wait(struct list_head *bulk_list);
0217 
0218 int mlxsw_reg_query(struct mlxsw_core *mlxsw_core,
0219             const struct mlxsw_reg_info *reg, char *payload);
0220 int mlxsw_reg_write(struct mlxsw_core *mlxsw_core,
0221             const struct mlxsw_reg_info *reg, char *payload);
0222 
0223 struct mlxsw_rx_info {
0224     bool is_lag;
0225     union {
0226         u16 sys_port;
0227         u16 lag_id;
0228     } u;
0229     u16 lag_port_index;
0230     u8 mirror_reason;
0231     int trap_id;
0232 };
0233 
0234 void mlxsw_core_skb_receive(struct mlxsw_core *mlxsw_core, struct sk_buff *skb,
0235                 struct mlxsw_rx_info *rx_info);
0236 
0237 void mlxsw_core_lag_mapping_set(struct mlxsw_core *mlxsw_core,
0238                 u16 lag_id, u8 port_index, u16 local_port);
0239 u16 mlxsw_core_lag_mapping_get(struct mlxsw_core *mlxsw_core,
0240                    u16 lag_id, u8 port_index);
0241 void mlxsw_core_lag_mapping_clear(struct mlxsw_core *mlxsw_core,
0242                   u16 lag_id, u16 local_port);
0243 
0244 void *mlxsw_core_port_driver_priv(struct mlxsw_core_port *mlxsw_core_port);
0245 int mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u16 local_port,
0246              u8 slot_index, u32 port_number, bool split,
0247              u32 split_port_subnumber,
0248              bool splittable, u32 lanes,
0249              const unsigned char *switch_id,
0250              unsigned char switch_id_len);
0251 void mlxsw_core_port_fini(struct mlxsw_core *mlxsw_core, u16 local_port);
0252 int mlxsw_core_cpu_port_init(struct mlxsw_core *mlxsw_core,
0253                  void *port_driver_priv,
0254                  const unsigned char *switch_id,
0255                  unsigned char switch_id_len);
0256 void mlxsw_core_cpu_port_fini(struct mlxsw_core *mlxsw_core);
0257 void mlxsw_core_port_eth_set(struct mlxsw_core *mlxsw_core, u16 local_port,
0258                  void *port_driver_priv, struct net_device *dev);
0259 void mlxsw_core_port_ib_set(struct mlxsw_core *mlxsw_core, u16 local_port,
0260                 void *port_driver_priv);
0261 void mlxsw_core_port_clear(struct mlxsw_core *mlxsw_core, u16 local_port,
0262                void *port_driver_priv);
0263 enum devlink_port_type mlxsw_core_port_type_get(struct mlxsw_core *mlxsw_core,
0264                         u16 local_port);
0265 struct devlink_port *
0266 mlxsw_core_port_devlink_port_get(struct mlxsw_core *mlxsw_core,
0267                  u16 local_port);
0268 struct mlxsw_linecard *
0269 mlxsw_core_port_linecard_get(struct mlxsw_core *mlxsw_core,
0270                  u16 local_port);
0271 void mlxsw_core_ports_remove_selected(struct mlxsw_core *mlxsw_core,
0272                       bool (*selector)(void *priv,
0273                                u16 local_port),
0274                       void *priv);
0275 struct mlxsw_env *mlxsw_core_env(const struct mlxsw_core *mlxsw_core);
0276 
0277 int mlxsw_core_schedule_dw(struct delayed_work *dwork, unsigned long delay);
0278 bool mlxsw_core_schedule_work(struct work_struct *work);
0279 void mlxsw_core_flush_owq(void);
0280 int mlxsw_core_resources_query(struct mlxsw_core *mlxsw_core, char *mbox,
0281                    struct mlxsw_res *res);
0282 
0283 #define MLXSW_CONFIG_PROFILE_SWID_COUNT 8
0284 
0285 struct mlxsw_swid_config {
0286     u8  used_type:1,
0287         used_properties:1;
0288     u8  type;
0289     u8  properties;
0290 };
0291 
0292 struct mlxsw_config_profile {
0293     u16 used_max_vepa_channels:1,
0294         used_max_mid:1,
0295         used_max_pgt:1,
0296         used_max_system_port:1,
0297         used_max_vlan_groups:1,
0298         used_max_regions:1,
0299         used_flood_tables:1,
0300         used_flood_mode:1,
0301         used_max_ib_mc:1,
0302         used_max_pkey:1,
0303         used_ar_sec:1,
0304         used_adaptive_routing_group_cap:1,
0305         used_ubridge:1,
0306         used_kvd_sizes:1,
0307         used_cqe_time_stamp_type:1;
0308     u8  max_vepa_channels;
0309     u16 max_mid;
0310     u16 max_pgt;
0311     u16 max_system_port;
0312     u16 max_vlan_groups;
0313     u16 max_regions;
0314     u8  max_flood_tables;
0315     u8  max_vid_flood_tables;
0316     u8  flood_mode;
0317     u8  max_fid_offset_flood_tables;
0318     u16 fid_offset_flood_table_size;
0319     u8  max_fid_flood_tables;
0320     u16 fid_flood_table_size;
0321     u16 max_ib_mc;
0322     u16 max_pkey;
0323     u8  ar_sec;
0324     u16 adaptive_routing_group_cap;
0325     u8  arn;
0326     u8  ubridge;
0327     u32 kvd_linear_size;
0328     u8  kvd_hash_single_parts;
0329     u8  kvd_hash_double_parts;
0330     u8  cqe_time_stamp_type;
0331     struct mlxsw_swid_config swid_config[MLXSW_CONFIG_PROFILE_SWID_COUNT];
0332 };
0333 
0334 struct mlxsw_driver {
0335     struct list_head list;
0336     const char *kind;
0337     size_t priv_size;
0338     const struct mlxsw_fw_rev *fw_req_rev;
0339     const char *fw_filename;
0340     int (*init)(struct mlxsw_core *mlxsw_core,
0341             const struct mlxsw_bus_info *mlxsw_bus_info,
0342             struct netlink_ext_ack *extack);
0343     void (*fini)(struct mlxsw_core *mlxsw_core);
0344     int (*port_type_set)(struct mlxsw_core *mlxsw_core, u16 local_port,
0345                  enum devlink_port_type new_type);
0346     int (*port_split)(struct mlxsw_core *mlxsw_core, u16 local_port,
0347               unsigned int count, struct netlink_ext_ack *extack);
0348     int (*port_unsplit)(struct mlxsw_core *mlxsw_core, u16 local_port,
0349                 struct netlink_ext_ack *extack);
0350     void (*ports_remove_selected)(struct mlxsw_core *mlxsw_core,
0351                       bool (*selector)(void *priv,
0352                                u16 local_port),
0353                       void *priv);
0354     int (*sb_pool_get)(struct mlxsw_core *mlxsw_core,
0355                unsigned int sb_index, u16 pool_index,
0356                struct devlink_sb_pool_info *pool_info);
0357     int (*sb_pool_set)(struct mlxsw_core *mlxsw_core,
0358                unsigned int sb_index, u16 pool_index, u32 size,
0359                enum devlink_sb_threshold_type threshold_type,
0360                struct netlink_ext_ack *extack);
0361     int (*sb_port_pool_get)(struct mlxsw_core_port *mlxsw_core_port,
0362                 unsigned int sb_index, u16 pool_index,
0363                 u32 *p_threshold);
0364     int (*sb_port_pool_set)(struct mlxsw_core_port *mlxsw_core_port,
0365                 unsigned int sb_index, u16 pool_index,
0366                 u32 threshold, struct netlink_ext_ack *extack);
0367     int (*sb_tc_pool_bind_get)(struct mlxsw_core_port *mlxsw_core_port,
0368                    unsigned int sb_index, u16 tc_index,
0369                    enum devlink_sb_pool_type pool_type,
0370                    u16 *p_pool_index, u32 *p_threshold);
0371     int (*sb_tc_pool_bind_set)(struct mlxsw_core_port *mlxsw_core_port,
0372                    unsigned int sb_index, u16 tc_index,
0373                    enum devlink_sb_pool_type pool_type,
0374                    u16 pool_index, u32 threshold,
0375                    struct netlink_ext_ack *extack);
0376     int (*sb_occ_snapshot)(struct mlxsw_core *mlxsw_core,
0377                    unsigned int sb_index);
0378     int (*sb_occ_max_clear)(struct mlxsw_core *mlxsw_core,
0379                 unsigned int sb_index);
0380     int (*sb_occ_port_pool_get)(struct mlxsw_core_port *mlxsw_core_port,
0381                     unsigned int sb_index, u16 pool_index,
0382                     u32 *p_cur, u32 *p_max);
0383     int (*sb_occ_tc_port_bind_get)(struct mlxsw_core_port *mlxsw_core_port,
0384                        unsigned int sb_index, u16 tc_index,
0385                        enum devlink_sb_pool_type pool_type,
0386                        u32 *p_cur, u32 *p_max);
0387     int (*trap_init)(struct mlxsw_core *mlxsw_core,
0388              const struct devlink_trap *trap, void *trap_ctx);
0389     void (*trap_fini)(struct mlxsw_core *mlxsw_core,
0390               const struct devlink_trap *trap, void *trap_ctx);
0391     int (*trap_action_set)(struct mlxsw_core *mlxsw_core,
0392                    const struct devlink_trap *trap,
0393                    enum devlink_trap_action action,
0394                    struct netlink_ext_ack *extack);
0395     int (*trap_group_init)(struct mlxsw_core *mlxsw_core,
0396                    const struct devlink_trap_group *group);
0397     int (*trap_group_set)(struct mlxsw_core *mlxsw_core,
0398                   const struct devlink_trap_group *group,
0399                   const struct devlink_trap_policer *policer,
0400                   struct netlink_ext_ack *extack);
0401     int (*trap_policer_init)(struct mlxsw_core *mlxsw_core,
0402                  const struct devlink_trap_policer *policer);
0403     void (*trap_policer_fini)(struct mlxsw_core *mlxsw_core,
0404                   const struct devlink_trap_policer *policer);
0405     int (*trap_policer_set)(struct mlxsw_core *mlxsw_core,
0406                 const struct devlink_trap_policer *policer,
0407                 u64 rate, u64 burst,
0408                 struct netlink_ext_ack *extack);
0409     int (*trap_policer_counter_get)(struct mlxsw_core *mlxsw_core,
0410                     const struct devlink_trap_policer *policer,
0411                     u64 *p_drops);
0412     void (*txhdr_construct)(struct sk_buff *skb,
0413                 const struct mlxsw_tx_info *tx_info);
0414     int (*resources_register)(struct mlxsw_core *mlxsw_core);
0415     int (*kvd_sizes_get)(struct mlxsw_core *mlxsw_core,
0416                  const struct mlxsw_config_profile *profile,
0417                  u64 *p_single_size, u64 *p_double_size,
0418                  u64 *p_linear_size);
0419     int (*params_register)(struct mlxsw_core *mlxsw_core);
0420     void (*params_unregister)(struct mlxsw_core *mlxsw_core);
0421 
0422     /* Notify a driver that a timestamped packet was transmitted. Driver
0423      * is responsible for freeing the passed-in SKB.
0424      */
0425     void (*ptp_transmitted)(struct mlxsw_core *mlxsw_core,
0426                 struct sk_buff *skb, u16 local_port);
0427 
0428     u8 txhdr_len;
0429     const struct mlxsw_config_profile *profile;
0430     bool sdq_supports_cqe_v2;
0431 };
0432 
0433 int mlxsw_core_kvd_sizes_get(struct mlxsw_core *mlxsw_core,
0434                  const struct mlxsw_config_profile *profile,
0435                  u64 *p_single_size, u64 *p_double_size,
0436                  u64 *p_linear_size);
0437 
0438 u32 mlxsw_core_read_frc_h(struct mlxsw_core *mlxsw_core);
0439 u32 mlxsw_core_read_frc_l(struct mlxsw_core *mlxsw_core);
0440 
0441 u32 mlxsw_core_read_utc_sec(struct mlxsw_core *mlxsw_core);
0442 u32 mlxsw_core_read_utc_nsec(struct mlxsw_core *mlxsw_core);
0443 
0444 bool mlxsw_core_sdq_supports_cqe_v2(struct mlxsw_core *mlxsw_core);
0445 
0446 void mlxsw_core_emad_string_tlv_enable(struct mlxsw_core *mlxsw_core);
0447 
0448 bool mlxsw_core_res_valid(struct mlxsw_core *mlxsw_core,
0449               enum mlxsw_res_id res_id);
0450 
0451 #define MLXSW_CORE_RES_VALID(mlxsw_core, short_res_id)          \
0452     mlxsw_core_res_valid(mlxsw_core, MLXSW_RES_ID_##short_res_id)
0453 
0454 u64 mlxsw_core_res_get(struct mlxsw_core *mlxsw_core,
0455                enum mlxsw_res_id res_id);
0456 
0457 #define MLXSW_CORE_RES_GET(mlxsw_core, short_res_id)            \
0458     mlxsw_core_res_get(mlxsw_core, MLXSW_RES_ID_##short_res_id)
0459 
0460 static inline struct net *mlxsw_core_net(struct mlxsw_core *mlxsw_core)
0461 {
0462     return devlink_net(priv_to_devlink(mlxsw_core));
0463 }
0464 
0465 #define MLXSW_BUS_F_TXRX    BIT(0)
0466 #define MLXSW_BUS_F_RESET   BIT(1)
0467 
0468 struct mlxsw_bus {
0469     const char *kind;
0470     int (*init)(void *bus_priv, struct mlxsw_core *mlxsw_core,
0471             const struct mlxsw_config_profile *profile,
0472             struct mlxsw_res *res);
0473     void (*fini)(void *bus_priv);
0474     bool (*skb_transmit_busy)(void *bus_priv,
0475                   const struct mlxsw_tx_info *tx_info);
0476     int (*skb_transmit)(void *bus_priv, struct sk_buff *skb,
0477                 const struct mlxsw_tx_info *tx_info);
0478     int (*cmd_exec)(void *bus_priv, u16 opcode, u8 opcode_mod,
0479             u32 in_mod, bool out_mbox_direct,
0480             char *in_mbox, size_t in_mbox_size,
0481             char *out_mbox, size_t out_mbox_size,
0482             u8 *p_status);
0483     u32 (*read_frc_h)(void *bus_priv);
0484     u32 (*read_frc_l)(void *bus_priv);
0485     u32 (*read_utc_sec)(void *bus_priv);
0486     u32 (*read_utc_nsec)(void *bus_priv);
0487     u8 features;
0488 };
0489 
0490 struct mlxsw_fw_rev {
0491     u16 major;
0492     u16 minor;
0493     u16 subminor;
0494     u16 can_reset_minor;
0495 };
0496 
0497 struct mlxsw_bus_info {
0498     const char *device_kind;
0499     const char *device_name;
0500     struct device *dev;
0501     struct mlxsw_fw_rev fw_rev;
0502     u8 vsd[MLXSW_CMD_BOARDINFO_VSD_LEN];
0503     u8 psid[MLXSW_CMD_BOARDINFO_PSID_LEN];
0504     u8 low_frequency:1,
0505        read_clock_capable:1;
0506 };
0507 
0508 struct mlxsw_hwmon;
0509 
0510 #ifdef CONFIG_MLXSW_CORE_HWMON
0511 
0512 int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core,
0513              const struct mlxsw_bus_info *mlxsw_bus_info,
0514              struct mlxsw_hwmon **p_hwmon);
0515 void mlxsw_hwmon_fini(struct mlxsw_hwmon *mlxsw_hwmon);
0516 
0517 #else
0518 
0519 static inline int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core,
0520                    const struct mlxsw_bus_info *mlxsw_bus_info,
0521                    struct mlxsw_hwmon **p_hwmon)
0522 {
0523     return 0;
0524 }
0525 
0526 static inline void mlxsw_hwmon_fini(struct mlxsw_hwmon *mlxsw_hwmon)
0527 {
0528 }
0529 
0530 #endif
0531 
0532 struct mlxsw_thermal;
0533 
0534 #ifdef CONFIG_MLXSW_CORE_THERMAL
0535 
0536 int mlxsw_thermal_init(struct mlxsw_core *mlxsw_core,
0537                const struct mlxsw_bus_info *mlxsw_bus_info,
0538                struct mlxsw_thermal **p_thermal);
0539 void mlxsw_thermal_fini(struct mlxsw_thermal *thermal);
0540 
0541 #else
0542 
0543 static inline int mlxsw_thermal_init(struct mlxsw_core *mlxsw_core,
0544                      const struct mlxsw_bus_info *mlxsw_bus_info,
0545                      struct mlxsw_thermal **p_thermal)
0546 {
0547     return 0;
0548 }
0549 
0550 static inline void mlxsw_thermal_fini(struct mlxsw_thermal *thermal)
0551 {
0552 }
0553 
0554 #endif
0555 
0556 enum mlxsw_devlink_param_id {
0557     MLXSW_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
0558     MLXSW_DEVLINK_PARAM_ID_ACL_REGION_REHASH_INTERVAL,
0559 };
0560 
0561 struct mlxsw_cqe_ts {
0562     u8 sec;
0563     u32 nsec;
0564 };
0565 
0566 struct mlxsw_skb_cb {
0567     union {
0568         struct mlxsw_tx_info tx_info;
0569         struct mlxsw_rx_md_info rx_md_info;
0570     };
0571     struct mlxsw_cqe_ts cqe_ts;
0572 };
0573 
0574 static inline struct mlxsw_skb_cb *mlxsw_skb_cb(struct sk_buff *skb)
0575 {
0576     BUILD_BUG_ON(sizeof(mlxsw_skb_cb) > sizeof(skb->cb));
0577     return (struct mlxsw_skb_cb *) skb->cb;
0578 }
0579 
0580 struct mlxsw_linecards;
0581 
0582 enum mlxsw_linecard_status_event_type {
0583     MLXSW_LINECARD_STATUS_EVENT_TYPE_PROVISION,
0584     MLXSW_LINECARD_STATUS_EVENT_TYPE_UNPROVISION,
0585 };
0586 
0587 struct mlxsw_linecard_bdev;
0588 
0589 struct mlxsw_linecard_device_info {
0590     u16 fw_major;
0591     u16 fw_minor;
0592     u16 fw_sub_minor;
0593     char psid[MLXSW_REG_MGIR_FW_INFO_PSID_SIZE];
0594 };
0595 
0596 struct mlxsw_linecard {
0597     u8 slot_index;
0598     struct mlxsw_linecards *linecards;
0599     struct devlink_linecard *devlink_linecard;
0600     struct mutex lock; /* Locks accesses to the linecard structure */
0601     char name[MLXSW_REG_MDDQ_SLOT_ASCII_NAME_LEN];
0602     char mbct_pl[MLXSW_REG_MBCT_LEN]; /* Too big for stack */
0603     enum mlxsw_linecard_status_event_type status_event_type_to;
0604     struct delayed_work status_event_to_dw;
0605     u8 provisioned:1,
0606        ready:1,
0607        active:1;
0608     u16 hw_revision;
0609     u16 ini_version;
0610     struct mlxsw_linecard_bdev *bdev;
0611     struct {
0612         struct mlxsw_linecard_device_info info;
0613         u8 index;
0614     } device;
0615 };
0616 
0617 struct mlxsw_linecard_types_info;
0618 
0619 struct mlxsw_linecards {
0620     struct mlxsw_core *mlxsw_core;
0621     const struct mlxsw_bus_info *bus_info;
0622     u8 count;
0623     struct mlxsw_linecard_types_info *types_info;
0624     struct list_head event_ops_list;
0625     struct mutex event_ops_list_lock; /* Locks accesses to event ops list */
0626     struct mlxsw_linecard linecards[];
0627 };
0628 
0629 static inline struct mlxsw_linecard *
0630 mlxsw_linecard_get(struct mlxsw_linecards *linecards, u8 slot_index)
0631 {
0632     return &linecards->linecards[slot_index - 1];
0633 }
0634 
0635 int mlxsw_linecard_devlink_info_get(struct mlxsw_linecard *linecard,
0636                     struct devlink_info_req *req,
0637                     struct netlink_ext_ack *extack);
0638 int mlxsw_linecard_flash_update(struct devlink *linecard_devlink,
0639                 struct mlxsw_linecard *linecard,
0640                 const struct firmware *firmware,
0641                 struct netlink_ext_ack *extack);
0642 
0643 int mlxsw_linecards_init(struct mlxsw_core *mlxsw_core,
0644              const struct mlxsw_bus_info *bus_info);
0645 void mlxsw_linecards_fini(struct mlxsw_core *mlxsw_core);
0646 
0647 typedef void mlxsw_linecards_event_op_t(struct mlxsw_core *mlxsw_core,
0648                     u8 slot_index, void *priv);
0649 
0650 struct mlxsw_linecards_event_ops {
0651     mlxsw_linecards_event_op_t *got_active;
0652     mlxsw_linecards_event_op_t *got_inactive;
0653 };
0654 
0655 int mlxsw_linecards_event_ops_register(struct mlxsw_core *mlxsw_core,
0656                        struct mlxsw_linecards_event_ops *ops,
0657                        void *priv);
0658 void mlxsw_linecards_event_ops_unregister(struct mlxsw_core *mlxsw_core,
0659                       struct mlxsw_linecards_event_ops *ops,
0660                       void *priv);
0661 
0662 int mlxsw_linecard_bdev_add(struct mlxsw_linecard *linecard);
0663 void mlxsw_linecard_bdev_del(struct mlxsw_linecard *linecard);
0664 
0665 int mlxsw_linecard_driver_register(void);
0666 void mlxsw_linecard_driver_unregister(void);
0667 
0668 #endif