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 typedef void mlxsw_irq_event_cb_t(struct mlxsw_core *mlxsw_core);
219 
220 int mlxsw_core_irq_event_handler_register(struct mlxsw_core *mlxsw_core,
221 					  mlxsw_irq_event_cb_t cb);
222 void mlxsw_core_irq_event_handler_unregister(struct mlxsw_core *mlxsw_core,
223 					     mlxsw_irq_event_cb_t cb);
224 void mlxsw_core_irq_event_handlers_call(struct mlxsw_core *mlxsw_core);
225 
226 int mlxsw_reg_query(struct mlxsw_core *mlxsw_core,
227 		    const struct mlxsw_reg_info *reg, char *payload);
228 int mlxsw_reg_write(struct mlxsw_core *mlxsw_core,
229 		    const struct mlxsw_reg_info *reg, char *payload);
230 
231 struct mlxsw_rx_info {
232 	bool is_lag;
233 	union {
234 		u16 sys_port;
235 		u16 lag_id;
236 	} u;
237 	u16 lag_port_index;
238 	u8 mirror_reason;
239 	int trap_id;
240 };
241 
242 void mlxsw_core_skb_receive(struct mlxsw_core *mlxsw_core, struct sk_buff *skb,
243 			    struct mlxsw_rx_info *rx_info);
244 
245 void mlxsw_core_lag_mapping_set(struct mlxsw_core *mlxsw_core,
246 				u16 lag_id, u8 port_index, u16 local_port);
247 u16 mlxsw_core_lag_mapping_get(struct mlxsw_core *mlxsw_core,
248 			       u16 lag_id, u8 port_index);
249 void mlxsw_core_lag_mapping_clear(struct mlxsw_core *mlxsw_core,
250 				  u16 lag_id, u16 local_port);
251 
252 void *mlxsw_core_port_driver_priv(struct mlxsw_core_port *mlxsw_core_port);
253 int mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u16 local_port,
254 			 u8 slot_index, u32 port_number, bool split,
255 			 u32 split_port_subnumber,
256 			 bool splittable, u32 lanes,
257 			 const unsigned char *switch_id,
258 			 unsigned char switch_id_len);
259 void mlxsw_core_port_fini(struct mlxsw_core *mlxsw_core, u16 local_port);
260 int mlxsw_core_cpu_port_init(struct mlxsw_core *mlxsw_core,
261 			     void *port_driver_priv,
262 			     const unsigned char *switch_id,
263 			     unsigned char switch_id_len);
264 void mlxsw_core_cpu_port_fini(struct mlxsw_core *mlxsw_core);
265 void mlxsw_core_port_eth_set(struct mlxsw_core *mlxsw_core, u16 local_port,
266 			     void *port_driver_priv, struct net_device *dev);
267 void mlxsw_core_port_clear(struct mlxsw_core *mlxsw_core, u16 local_port,
268 			   void *port_driver_priv);
269 struct devlink_port *
270 mlxsw_core_port_devlink_port_get(struct mlxsw_core *mlxsw_core,
271 				 u16 local_port);
272 struct mlxsw_linecard *
273 mlxsw_core_port_linecard_get(struct mlxsw_core *mlxsw_core,
274 			     u16 local_port);
275 void mlxsw_core_ports_remove_selected(struct mlxsw_core *mlxsw_core,
276 				      bool (*selector)(void *priv,
277 						       u16 local_port),
278 				      void *priv);
279 struct mlxsw_env *mlxsw_core_env(const struct mlxsw_core *mlxsw_core);
280 
281 int mlxsw_core_schedule_dw(struct delayed_work *dwork, unsigned long delay);
282 bool mlxsw_core_schedule_work(struct work_struct *work);
283 void mlxsw_core_flush_owq(void);
284 int mlxsw_core_resources_query(struct mlxsw_core *mlxsw_core, char *mbox,
285 			       struct mlxsw_res *res);
286 
287 #define MLXSW_CONFIG_PROFILE_SWID_COUNT 8
288 
289 struct mlxsw_swid_config {
290 	u8	used_type:1,
291 		used_properties:1;
292 	u8	type;
293 	u8	properties;
294 };
295 
296 struct mlxsw_config_profile {
297 	u16	used_max_vepa_channels:1,
298 		used_max_mid:1,
299 		used_max_pgt:1,
300 		used_max_system_port:1,
301 		used_max_vlan_groups:1,
302 		used_max_regions:1,
303 		used_flood_tables:1,
304 		used_flood_mode:1,
305 		used_max_ib_mc:1,
306 		used_max_pkey:1,
307 		used_ar_sec:1,
308 		used_adaptive_routing_group_cap:1,
309 		used_ubridge:1,
310 		used_kvd_sizes:1,
311 		used_cqe_time_stamp_type:1;
312 	u8	max_vepa_channels;
313 	u16	max_mid;
314 	u16	max_pgt;
315 	u16	max_system_port;
316 	u16	max_vlan_groups;
317 	u16	max_regions;
318 	u8	max_flood_tables;
319 	u8	max_vid_flood_tables;
320 	u8	flood_mode;
321 	u8	max_fid_offset_flood_tables;
322 	u16	fid_offset_flood_table_size;
323 	u8	max_fid_flood_tables;
324 	u16	fid_flood_table_size;
325 	u16	max_ib_mc;
326 	u16	max_pkey;
327 	u8	ar_sec;
328 	u16	adaptive_routing_group_cap;
329 	u8	arn;
330 	u8	ubridge;
331 	u32	kvd_linear_size;
332 	u8	kvd_hash_single_parts;
333 	u8	kvd_hash_double_parts;
334 	u8	cqe_time_stamp_type;
335 	struct mlxsw_swid_config swid_config[MLXSW_CONFIG_PROFILE_SWID_COUNT];
336 };
337 
338 struct mlxsw_driver {
339 	struct list_head list;
340 	const char *kind;
341 	size_t priv_size;
342 	const struct mlxsw_fw_rev *fw_req_rev;
343 	const char *fw_filename;
344 	int (*init)(struct mlxsw_core *mlxsw_core,
345 		    const struct mlxsw_bus_info *mlxsw_bus_info,
346 		    struct netlink_ext_ack *extack);
347 	void (*fini)(struct mlxsw_core *mlxsw_core);
348 	int (*port_split)(struct mlxsw_core *mlxsw_core, u16 local_port,
349 			  unsigned int count, struct netlink_ext_ack *extack);
350 	int (*port_unsplit)(struct mlxsw_core *mlxsw_core, u16 local_port,
351 			    struct netlink_ext_ack *extack);
352 	void (*ports_remove_selected)(struct mlxsw_core *mlxsw_core,
353 				      bool (*selector)(void *priv,
354 						       u16 local_port),
355 				      void *priv);
356 	int (*sb_pool_get)(struct mlxsw_core *mlxsw_core,
357 			   unsigned int sb_index, u16 pool_index,
358 			   struct devlink_sb_pool_info *pool_info);
359 	int (*sb_pool_set)(struct mlxsw_core *mlxsw_core,
360 			   unsigned int sb_index, u16 pool_index, u32 size,
361 			   enum devlink_sb_threshold_type threshold_type,
362 			   struct netlink_ext_ack *extack);
363 	int (*sb_port_pool_get)(struct mlxsw_core_port *mlxsw_core_port,
364 				unsigned int sb_index, u16 pool_index,
365 				u32 *p_threshold);
366 	int (*sb_port_pool_set)(struct mlxsw_core_port *mlxsw_core_port,
367 				unsigned int sb_index, u16 pool_index,
368 				u32 threshold, struct netlink_ext_ack *extack);
369 	int (*sb_tc_pool_bind_get)(struct mlxsw_core_port *mlxsw_core_port,
370 				   unsigned int sb_index, u16 tc_index,
371 				   enum devlink_sb_pool_type pool_type,
372 				   u16 *p_pool_index, u32 *p_threshold);
373 	int (*sb_tc_pool_bind_set)(struct mlxsw_core_port *mlxsw_core_port,
374 				   unsigned int sb_index, u16 tc_index,
375 				   enum devlink_sb_pool_type pool_type,
376 				   u16 pool_index, u32 threshold,
377 				   struct netlink_ext_ack *extack);
378 	int (*sb_occ_snapshot)(struct mlxsw_core *mlxsw_core,
379 			       unsigned int sb_index);
380 	int (*sb_occ_max_clear)(struct mlxsw_core *mlxsw_core,
381 				unsigned int sb_index);
382 	int (*sb_occ_port_pool_get)(struct mlxsw_core_port *mlxsw_core_port,
383 				    unsigned int sb_index, u16 pool_index,
384 				    u32 *p_cur, u32 *p_max);
385 	int (*sb_occ_tc_port_bind_get)(struct mlxsw_core_port *mlxsw_core_port,
386 				       unsigned int sb_index, u16 tc_index,
387 				       enum devlink_sb_pool_type pool_type,
388 				       u32 *p_cur, u32 *p_max);
389 	int (*trap_init)(struct mlxsw_core *mlxsw_core,
390 			 const struct devlink_trap *trap, void *trap_ctx);
391 	void (*trap_fini)(struct mlxsw_core *mlxsw_core,
392 			  const struct devlink_trap *trap, void *trap_ctx);
393 	int (*trap_action_set)(struct mlxsw_core *mlxsw_core,
394 			       const struct devlink_trap *trap,
395 			       enum devlink_trap_action action,
396 			       struct netlink_ext_ack *extack);
397 	int (*trap_group_init)(struct mlxsw_core *mlxsw_core,
398 			       const struct devlink_trap_group *group);
399 	int (*trap_group_set)(struct mlxsw_core *mlxsw_core,
400 			      const struct devlink_trap_group *group,
401 			      const struct devlink_trap_policer *policer,
402 			      struct netlink_ext_ack *extack);
403 	int (*trap_policer_init)(struct mlxsw_core *mlxsw_core,
404 				 const struct devlink_trap_policer *policer);
405 	void (*trap_policer_fini)(struct mlxsw_core *mlxsw_core,
406 				  const struct devlink_trap_policer *policer);
407 	int (*trap_policer_set)(struct mlxsw_core *mlxsw_core,
408 				const struct devlink_trap_policer *policer,
409 				u64 rate, u64 burst,
410 				struct netlink_ext_ack *extack);
411 	int (*trap_policer_counter_get)(struct mlxsw_core *mlxsw_core,
412 					const struct devlink_trap_policer *policer,
413 					u64 *p_drops);
414 	void (*txhdr_construct)(struct sk_buff *skb,
415 				const struct mlxsw_tx_info *tx_info);
416 	int (*resources_register)(struct mlxsw_core *mlxsw_core);
417 	int (*kvd_sizes_get)(struct mlxsw_core *mlxsw_core,
418 			     const struct mlxsw_config_profile *profile,
419 			     u64 *p_single_size, u64 *p_double_size,
420 			     u64 *p_linear_size);
421 	int (*params_register)(struct mlxsw_core *mlxsw_core);
422 	void (*params_unregister)(struct mlxsw_core *mlxsw_core);
423 
424 	/* Notify a driver that a timestamped packet was transmitted. Driver
425 	 * is responsible for freeing the passed-in SKB.
426 	 */
427 	void (*ptp_transmitted)(struct mlxsw_core *mlxsw_core,
428 				struct sk_buff *skb, u16 local_port);
429 
430 	u8 txhdr_len;
431 	const struct mlxsw_config_profile *profile;
432 	bool sdq_supports_cqe_v2;
433 };
434 
435 int mlxsw_core_kvd_sizes_get(struct mlxsw_core *mlxsw_core,
436 			     const struct mlxsw_config_profile *profile,
437 			     u64 *p_single_size, u64 *p_double_size,
438 			     u64 *p_linear_size);
439 
440 u32 mlxsw_core_read_frc_h(struct mlxsw_core *mlxsw_core);
441 u32 mlxsw_core_read_frc_l(struct mlxsw_core *mlxsw_core);
442 
443 u32 mlxsw_core_read_utc_sec(struct mlxsw_core *mlxsw_core);
444 u32 mlxsw_core_read_utc_nsec(struct mlxsw_core *mlxsw_core);
445 
446 bool mlxsw_core_sdq_supports_cqe_v2(struct mlxsw_core *mlxsw_core);
447 
448 void mlxsw_core_emad_string_tlv_enable(struct mlxsw_core *mlxsw_core);
449 
450 bool mlxsw_core_res_valid(struct mlxsw_core *mlxsw_core,
451 			  enum mlxsw_res_id res_id);
452 
453 #define MLXSW_CORE_RES_VALID(mlxsw_core, short_res_id)			\
454 	mlxsw_core_res_valid(mlxsw_core, MLXSW_RES_ID_##short_res_id)
455 
456 u64 mlxsw_core_res_get(struct mlxsw_core *mlxsw_core,
457 		       enum mlxsw_res_id res_id);
458 
459 #define MLXSW_CORE_RES_GET(mlxsw_core, short_res_id)			\
460 	mlxsw_core_res_get(mlxsw_core, MLXSW_RES_ID_##short_res_id)
461 
462 static inline struct net *mlxsw_core_net(struct mlxsw_core *mlxsw_core)
463 {
464 	return devlink_net(priv_to_devlink(mlxsw_core));
465 }
466 
467 #define MLXSW_BUS_F_TXRX	BIT(0)
468 #define MLXSW_BUS_F_RESET	BIT(1)
469 
470 struct mlxsw_bus {
471 	const char *kind;
472 	int (*init)(void *bus_priv, struct mlxsw_core *mlxsw_core,
473 		    const struct mlxsw_config_profile *profile,
474 		    struct mlxsw_res *res);
475 	void (*fini)(void *bus_priv);
476 	bool (*skb_transmit_busy)(void *bus_priv,
477 				  const struct mlxsw_tx_info *tx_info);
478 	int (*skb_transmit)(void *bus_priv, struct sk_buff *skb,
479 			    const struct mlxsw_tx_info *tx_info);
480 	int (*cmd_exec)(void *bus_priv, u16 opcode, u8 opcode_mod,
481 			u32 in_mod, bool out_mbox_direct,
482 			char *in_mbox, size_t in_mbox_size,
483 			char *out_mbox, size_t out_mbox_size,
484 			u8 *p_status);
485 	u32 (*read_frc_h)(void *bus_priv);
486 	u32 (*read_frc_l)(void *bus_priv);
487 	u32 (*read_utc_sec)(void *bus_priv);
488 	u32 (*read_utc_nsec)(void *bus_priv);
489 	u8 features;
490 };
491 
492 struct mlxsw_fw_rev {
493 	u16 major;
494 	u16 minor;
495 	u16 subminor;
496 	u16 can_reset_minor;
497 };
498 
499 struct mlxsw_bus_info {
500 	const char *device_kind;
501 	const char *device_name;
502 	struct device *dev;
503 	struct mlxsw_fw_rev fw_rev;
504 	u8 vsd[MLXSW_CMD_BOARDINFO_VSD_LEN];
505 	u8 psid[MLXSW_CMD_BOARDINFO_PSID_LEN];
506 	u8 low_frequency:1,
507 	   read_clock_capable:1;
508 };
509 
510 struct mlxsw_hwmon;
511 
512 #ifdef CONFIG_MLXSW_CORE_HWMON
513 
514 int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core,
515 		     const struct mlxsw_bus_info *mlxsw_bus_info,
516 		     struct mlxsw_hwmon **p_hwmon);
517 void mlxsw_hwmon_fini(struct mlxsw_hwmon *mlxsw_hwmon);
518 
519 #else
520 
521 static inline int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core,
522 				   const struct mlxsw_bus_info *mlxsw_bus_info,
523 				   struct mlxsw_hwmon **p_hwmon)
524 {
525 	return 0;
526 }
527 
528 static inline void mlxsw_hwmon_fini(struct mlxsw_hwmon *mlxsw_hwmon)
529 {
530 }
531 
532 #endif
533 
534 struct mlxsw_thermal;
535 
536 #ifdef CONFIG_MLXSW_CORE_THERMAL
537 
538 int mlxsw_thermal_init(struct mlxsw_core *mlxsw_core,
539 		       const struct mlxsw_bus_info *mlxsw_bus_info,
540 		       struct mlxsw_thermal **p_thermal);
541 void mlxsw_thermal_fini(struct mlxsw_thermal *thermal);
542 
543 #else
544 
545 static inline int mlxsw_thermal_init(struct mlxsw_core *mlxsw_core,
546 				     const struct mlxsw_bus_info *mlxsw_bus_info,
547 				     struct mlxsw_thermal **p_thermal)
548 {
549 	return 0;
550 }
551 
552 static inline void mlxsw_thermal_fini(struct mlxsw_thermal *thermal)
553 {
554 }
555 
556 #endif
557 
558 enum mlxsw_devlink_param_id {
559 	MLXSW_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
560 	MLXSW_DEVLINK_PARAM_ID_ACL_REGION_REHASH_INTERVAL,
561 };
562 
563 struct mlxsw_cqe_ts {
564 	u8 sec;
565 	u32 nsec;
566 };
567 
568 struct mlxsw_skb_cb {
569 	union {
570 		struct mlxsw_tx_info tx_info;
571 		struct mlxsw_rx_md_info rx_md_info;
572 	};
573 	struct mlxsw_cqe_ts cqe_ts;
574 };
575 
576 static inline struct mlxsw_skb_cb *mlxsw_skb_cb(struct sk_buff *skb)
577 {
578 	BUILD_BUG_ON(sizeof(mlxsw_skb_cb) > sizeof(skb->cb));
579 	return (struct mlxsw_skb_cb *) skb->cb;
580 }
581 
582 struct mlxsw_linecards;
583 
584 enum mlxsw_linecard_status_event_type {
585 	MLXSW_LINECARD_STATUS_EVENT_TYPE_PROVISION,
586 	MLXSW_LINECARD_STATUS_EVENT_TYPE_UNPROVISION,
587 };
588 
589 struct mlxsw_linecard_bdev;
590 
591 struct mlxsw_linecard_device_info {
592 	u16 fw_major;
593 	u16 fw_minor;
594 	u16 fw_sub_minor;
595 	char psid[MLXSW_REG_MGIR_FW_INFO_PSID_SIZE];
596 };
597 
598 struct mlxsw_linecard {
599 	u8 slot_index;
600 	struct mlxsw_linecards *linecards;
601 	struct devlink_linecard *devlink_linecard;
602 	struct mutex lock; /* Locks accesses to the linecard structure */
603 	char name[MLXSW_REG_MDDQ_SLOT_ASCII_NAME_LEN];
604 	char mbct_pl[MLXSW_REG_MBCT_LEN]; /* Too big for stack */
605 	enum mlxsw_linecard_status_event_type status_event_type_to;
606 	struct delayed_work status_event_to_dw;
607 	u8 provisioned:1,
608 	   ready:1,
609 	   active:1;
610 	u16 hw_revision;
611 	u16 ini_version;
612 	struct mlxsw_linecard_bdev *bdev;
613 	struct {
614 		struct mlxsw_linecard_device_info info;
615 		u8 index;
616 	} device;
617 };
618 
619 struct mlxsw_linecard_types_info;
620 
621 struct mlxsw_linecards {
622 	struct mlxsw_core *mlxsw_core;
623 	const struct mlxsw_bus_info *bus_info;
624 	u8 count;
625 	struct mlxsw_linecard_types_info *types_info;
626 	struct list_head event_ops_list;
627 	struct mutex event_ops_list_lock; /* Locks accesses to event ops list */
628 	struct mlxsw_linecard linecards[];
629 };
630 
631 static inline struct mlxsw_linecard *
632 mlxsw_linecard_get(struct mlxsw_linecards *linecards, u8 slot_index)
633 {
634 	return &linecards->linecards[slot_index - 1];
635 }
636 
637 int mlxsw_linecard_devlink_info_get(struct mlxsw_linecard *linecard,
638 				    struct devlink_info_req *req,
639 				    struct netlink_ext_ack *extack);
640 int mlxsw_linecard_flash_update(struct devlink *linecard_devlink,
641 				struct mlxsw_linecard *linecard,
642 				const struct firmware *firmware,
643 				struct netlink_ext_ack *extack);
644 
645 int mlxsw_linecards_init(struct mlxsw_core *mlxsw_core,
646 			 const struct mlxsw_bus_info *bus_info);
647 void mlxsw_linecards_fini(struct mlxsw_core *mlxsw_core);
648 
649 typedef void mlxsw_linecards_event_op_t(struct mlxsw_core *mlxsw_core,
650 					u8 slot_index, void *priv);
651 
652 struct mlxsw_linecards_event_ops {
653 	mlxsw_linecards_event_op_t *got_active;
654 	mlxsw_linecards_event_op_t *got_inactive;
655 };
656 
657 int mlxsw_linecards_event_ops_register(struct mlxsw_core *mlxsw_core,
658 				       struct mlxsw_linecards_event_ops *ops,
659 				       void *priv);
660 void mlxsw_linecards_event_ops_unregister(struct mlxsw_core *mlxsw_core,
661 					  struct mlxsw_linecards_event_ops *ops,
662 					  void *priv);
663 
664 int mlxsw_linecard_bdev_add(struct mlxsw_linecard *linecard);
665 void mlxsw_linecard_bdev_del(struct mlxsw_linecard *linecard);
666 
667 int mlxsw_linecard_driver_register(void);
668 void mlxsw_linecard_driver_unregister(void);
669 
670 #endif
671