forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/net/ethernet/mellanox/mlxsw/core.h
....@@ -11,6 +11,7 @@
1111 #include <linux/types.h>
1212 #include <linux/skbuff.h>
1313 #include <linux/workqueue.h>
14
+#include <linux/net_namespace.h>
1415 #include <net/devlink.h>
1516
1617 #include "trap.h"
....@@ -23,10 +24,19 @@
2324 struct mlxsw_driver;
2425 struct mlxsw_bus;
2526 struct mlxsw_bus_info;
27
+struct mlxsw_fw_rev;
2628
2729 unsigned int mlxsw_core_max_ports(const struct mlxsw_core *mlxsw_core);
2830
2931 void *mlxsw_core_driver_priv(struct mlxsw_core *mlxsw_core);
32
+
33
+bool mlxsw_core_res_query_enabled(const struct mlxsw_core *mlxsw_core);
34
+
35
+bool mlxsw_core_temp_warn_enabled(const struct mlxsw_core *mlxsw_core);
36
+
37
+bool
38
+mlxsw_core_fw_rev_minor_subminor_validate(const struct mlxsw_fw_rev *rev,
39
+ const struct mlxsw_fw_rev *req_rev);
3040
3141 int mlxsw_core_driver_register(struct mlxsw_driver *mlxsw_driver);
3242 void mlxsw_core_driver_unregister(struct mlxsw_driver *mlxsw_driver);
....@@ -34,7 +44,8 @@
3444 int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
3545 const struct mlxsw_bus *mlxsw_bus,
3646 void *bus_priv, bool reload,
37
- struct devlink *devlink);
47
+ struct devlink *devlink,
48
+ struct netlink_ext_ack *extack);
3849 void mlxsw_core_bus_device_unregister(struct mlxsw_core *mlxsw_core, bool reload);
3950
4051 struct mlxsw_tx_info {
....@@ -46,12 +57,14 @@
4657 const struct mlxsw_tx_info *tx_info);
4758 int mlxsw_core_skb_transmit(struct mlxsw_core *mlxsw_core, struct sk_buff *skb,
4859 const struct mlxsw_tx_info *tx_info);
60
+void mlxsw_core_ptp_transmitted(struct mlxsw_core *mlxsw_core,
61
+ struct sk_buff *skb, u8 local_port);
4962
5063 struct mlxsw_rx_listener {
5164 void (*func)(struct sk_buff *skb, u8 local_port, void *priv);
5265 u8 local_port;
66
+ u8 mirror_reason;
5367 u16 trap_id;
54
- enum mlxsw_reg_hpkt_action action;
5568 };
5669
5770 struct mlxsw_event_listener {
....@@ -65,58 +78,78 @@
6578 union {
6679 struct mlxsw_rx_listener rx_listener;
6780 struct mlxsw_event_listener event_listener;
68
- } u;
69
- enum mlxsw_reg_hpkt_action action;
70
- enum mlxsw_reg_hpkt_action unreg_action;
71
- u8 trap_group;
72
- bool is_ctrl; /* should go via control buffer or not */
73
- bool is_event;
81
+ };
82
+ enum mlxsw_reg_hpkt_action en_action; /* Action when enabled */
83
+ enum mlxsw_reg_hpkt_action dis_action; /* Action when disabled */
84
+ u8 en_trap_group; /* Trap group when enabled */
85
+ u8 dis_trap_group; /* Trap group when disabled */
86
+ u8 is_ctrl:1, /* should go via control buffer or not */
87
+ is_event:1,
88
+ enabled_on_register:1; /* Trap should be enabled when listener
89
+ * is registered.
90
+ */
7491 };
7592
76
-#define MLXSW_RXL(_func, _trap_id, _action, _is_ctrl, _trap_group, \
77
- _unreg_action) \
78
- { \
79
- .trap_id = MLXSW_TRAP_ID_##_trap_id, \
80
- .u.rx_listener = \
81
- { \
82
- .func = _func, \
83
- .local_port = MLXSW_PORT_DONT_CARE, \
84
- .trap_id = MLXSW_TRAP_ID_##_trap_id, \
85
- }, \
86
- .action = MLXSW_REG_HPKT_ACTION_##_action, \
87
- .unreg_action = MLXSW_REG_HPKT_ACTION_##_unreg_action, \
88
- .trap_group = MLXSW_REG_HTGT_TRAP_GROUP_##_trap_group, \
89
- .is_ctrl = _is_ctrl, \
90
- .is_event = false, \
93
+#define __MLXSW_RXL(_func, _trap_id, _en_action, _is_ctrl, _en_trap_group, \
94
+ _dis_action, _enabled_on_register, _dis_trap_group, \
95
+ _mirror_reason) \
96
+ { \
97
+ .trap_id = MLXSW_TRAP_ID_##_trap_id, \
98
+ .rx_listener = \
99
+ { \
100
+ .func = _func, \
101
+ .local_port = MLXSW_PORT_DONT_CARE, \
102
+ .mirror_reason = _mirror_reason, \
103
+ .trap_id = MLXSW_TRAP_ID_##_trap_id, \
104
+ }, \
105
+ .en_action = MLXSW_REG_HPKT_ACTION_##_en_action, \
106
+ .dis_action = MLXSW_REG_HPKT_ACTION_##_dis_action, \
107
+ .en_trap_group = MLXSW_REG_HTGT_TRAP_GROUP_##_en_trap_group, \
108
+ .dis_trap_group = MLXSW_REG_HTGT_TRAP_GROUP_##_dis_trap_group, \
109
+ .is_ctrl = _is_ctrl, \
110
+ .enabled_on_register = _enabled_on_register, \
91111 }
92112
93
-#define MLXSW_EVENTL(_func, _trap_id, _trap_group) \
94
- { \
95
- .trap_id = MLXSW_TRAP_ID_##_trap_id, \
96
- .u.event_listener = \
97
- { \
98
- .func = _func, \
99
- .trap_id = MLXSW_TRAP_ID_##_trap_id, \
100
- }, \
101
- .action = MLXSW_REG_HPKT_ACTION_TRAP_TO_CPU, \
102
- .trap_group = MLXSW_REG_HTGT_TRAP_GROUP_##_trap_group, \
103
- .is_ctrl = false, \
104
- .is_event = true, \
113
+#define MLXSW_RXL(_func, _trap_id, _en_action, _is_ctrl, _trap_group, \
114
+ _dis_action) \
115
+ __MLXSW_RXL(_func, _trap_id, _en_action, _is_ctrl, _trap_group, \
116
+ _dis_action, true, _trap_group, 0)
117
+
118
+#define MLXSW_RXL_DIS(_func, _trap_id, _en_action, _is_ctrl, _en_trap_group, \
119
+ _dis_action, _dis_trap_group) \
120
+ __MLXSW_RXL(_func, _trap_id, _en_action, _is_ctrl, _en_trap_group, \
121
+ _dis_action, false, _dis_trap_group, 0)
122
+
123
+#define MLXSW_RXL_MIRROR(_func, _session_id, _trap_group, _mirror_reason) \
124
+ __MLXSW_RXL(_func, MIRROR_SESSION##_session_id, TRAP_TO_CPU, false, \
125
+ _trap_group, TRAP_TO_CPU, true, _trap_group, \
126
+ _mirror_reason)
127
+
128
+#define MLXSW_EVENTL(_func, _trap_id, _trap_group) \
129
+ { \
130
+ .trap_id = MLXSW_TRAP_ID_##_trap_id, \
131
+ .event_listener = \
132
+ { \
133
+ .func = _func, \
134
+ .trap_id = MLXSW_TRAP_ID_##_trap_id, \
135
+ }, \
136
+ .en_action = MLXSW_REG_HPKT_ACTION_TRAP_TO_CPU, \
137
+ .en_trap_group = MLXSW_REG_HTGT_TRAP_GROUP_##_trap_group, \
138
+ .is_event = true, \
139
+ .enabled_on_register = true, \
105140 }
106141
107142 int mlxsw_core_rx_listener_register(struct mlxsw_core *mlxsw_core,
108143 const struct mlxsw_rx_listener *rxl,
109
- void *priv);
144
+ void *priv, bool enabled);
110145 void mlxsw_core_rx_listener_unregister(struct mlxsw_core *mlxsw_core,
111
- const struct mlxsw_rx_listener *rxl,
112
- void *priv);
146
+ const struct mlxsw_rx_listener *rxl);
113147
114148 int mlxsw_core_event_listener_register(struct mlxsw_core *mlxsw_core,
115149 const struct mlxsw_event_listener *el,
116150 void *priv);
117151 void mlxsw_core_event_listener_unregister(struct mlxsw_core *mlxsw_core,
118
- const struct mlxsw_event_listener *el,
119
- void *priv);
152
+ const struct mlxsw_event_listener *el);
120153
121154 int mlxsw_core_trap_register(struct mlxsw_core *mlxsw_core,
122155 const struct mlxsw_listener *listener,
....@@ -124,6 +157,9 @@
124157 void mlxsw_core_trap_unregister(struct mlxsw_core *mlxsw_core,
125158 const struct mlxsw_listener *listener,
126159 void *priv);
160
+int mlxsw_core_trap_state_set(struct mlxsw_core *mlxsw_core,
161
+ const struct mlxsw_listener *listener,
162
+ bool enabled);
127163
128164 typedef void mlxsw_reg_trans_cb_t(struct mlxsw_core *mlxsw_core, char *payload,
129165 size_t payload_len, unsigned long cb_priv);
....@@ -150,6 +186,7 @@
150186 u16 lag_id;
151187 } u;
152188 u8 lag_port_index;
189
+ u8 mirror_reason;
153190 int trap_id;
154191 };
155192
....@@ -164,24 +201,37 @@
164201 u16 lag_id, u8 local_port);
165202
166203 void *mlxsw_core_port_driver_priv(struct mlxsw_core_port *mlxsw_core_port);
167
-int mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u8 local_port);
204
+int mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u8 local_port,
205
+ u32 port_number, bool split, u32 split_port_subnumber,
206
+ bool splittable, u32 lanes,
207
+ const unsigned char *switch_id,
208
+ unsigned char switch_id_len);
168209 void mlxsw_core_port_fini(struct mlxsw_core *mlxsw_core, u8 local_port);
210
+int mlxsw_core_cpu_port_init(struct mlxsw_core *mlxsw_core,
211
+ void *port_driver_priv,
212
+ const unsigned char *switch_id,
213
+ unsigned char switch_id_len);
214
+void mlxsw_core_cpu_port_fini(struct mlxsw_core *mlxsw_core);
169215 void mlxsw_core_port_eth_set(struct mlxsw_core *mlxsw_core, u8 local_port,
170
- void *port_driver_priv, struct net_device *dev,
171
- u32 port_number, bool split,
172
- u32 split_port_subnumber);
216
+ void *port_driver_priv, struct net_device *dev);
173217 void mlxsw_core_port_ib_set(struct mlxsw_core *mlxsw_core, u8 local_port,
174218 void *port_driver_priv);
175219 void mlxsw_core_port_clear(struct mlxsw_core *mlxsw_core, u8 local_port,
176220 void *port_driver_priv);
177221 enum devlink_port_type mlxsw_core_port_type_get(struct mlxsw_core *mlxsw_core,
178222 u8 local_port);
179
-int mlxsw_core_port_get_phys_port_name(struct mlxsw_core *mlxsw_core,
180
- u8 local_port, char *name, size_t len);
223
+struct devlink_port *
224
+mlxsw_core_port_devlink_port_get(struct mlxsw_core *mlxsw_core,
225
+ u8 local_port);
226
+struct mlxsw_env *mlxsw_core_env(const struct mlxsw_core *mlxsw_core);
227
+bool mlxsw_core_is_initialized(const struct mlxsw_core *mlxsw_core);
228
+int mlxsw_core_module_max_width(struct mlxsw_core *mlxsw_core, u8 module);
181229
182230 int mlxsw_core_schedule_dw(struct delayed_work *dwork, unsigned long delay);
183231 bool mlxsw_core_schedule_work(struct work_struct *work);
184232 void mlxsw_core_flush_owq(void);
233
+int mlxsw_core_resources_query(struct mlxsw_core *mlxsw_core, char *mbox,
234
+ struct mlxsw_res *res);
185235
186236 #define MLXSW_CONFIG_PROFILE_SWID_COUNT 8
187237
....@@ -234,8 +284,11 @@
234284 struct list_head list;
235285 const char *kind;
236286 size_t priv_size;
287
+ const struct mlxsw_fw_rev *fw_req_rev;
288
+ const char *fw_filename;
237289 int (*init)(struct mlxsw_core *mlxsw_core,
238
- const struct mlxsw_bus_info *mlxsw_bus_info);
290
+ const struct mlxsw_bus_info *mlxsw_bus_info,
291
+ struct netlink_ext_ack *extack);
239292 void (*fini)(struct mlxsw_core *mlxsw_core);
240293 int (*basic_trap_groups_set)(struct mlxsw_core *mlxsw_core);
241294 int (*port_type_set)(struct mlxsw_core *mlxsw_core, u8 local_port,
....@@ -249,13 +302,14 @@
249302 struct devlink_sb_pool_info *pool_info);
250303 int (*sb_pool_set)(struct mlxsw_core *mlxsw_core,
251304 unsigned int sb_index, u16 pool_index, u32 size,
252
- enum devlink_sb_threshold_type threshold_type);
305
+ enum devlink_sb_threshold_type threshold_type,
306
+ struct netlink_ext_ack *extack);
253307 int (*sb_port_pool_get)(struct mlxsw_core_port *mlxsw_core_port,
254308 unsigned int sb_index, u16 pool_index,
255309 u32 *p_threshold);
256310 int (*sb_port_pool_set)(struct mlxsw_core_port *mlxsw_core_port,
257311 unsigned int sb_index, u16 pool_index,
258
- u32 threshold);
312
+ u32 threshold, struct netlink_ext_ack *extack);
259313 int (*sb_tc_pool_bind_get)(struct mlxsw_core_port *mlxsw_core_port,
260314 unsigned int sb_index, u16 tc_index,
261315 enum devlink_sb_pool_type pool_type,
....@@ -263,7 +317,8 @@
263317 int (*sb_tc_pool_bind_set)(struct mlxsw_core_port *mlxsw_core_port,
264318 unsigned int sb_index, u16 tc_index,
265319 enum devlink_sb_pool_type pool_type,
266
- u16 pool_index, u32 threshold);
320
+ u16 pool_index, u32 threshold,
321
+ struct netlink_ext_ack *extack);
267322 int (*sb_occ_snapshot)(struct mlxsw_core *mlxsw_core,
268323 unsigned int sb_index);
269324 int (*sb_occ_max_clear)(struct mlxsw_core *mlxsw_core,
....@@ -275,6 +330,31 @@
275330 unsigned int sb_index, u16 tc_index,
276331 enum devlink_sb_pool_type pool_type,
277332 u32 *p_cur, u32 *p_max);
333
+ int (*trap_init)(struct mlxsw_core *mlxsw_core,
334
+ const struct devlink_trap *trap, void *trap_ctx);
335
+ void (*trap_fini)(struct mlxsw_core *mlxsw_core,
336
+ const struct devlink_trap *trap, void *trap_ctx);
337
+ int (*trap_action_set)(struct mlxsw_core *mlxsw_core,
338
+ const struct devlink_trap *trap,
339
+ enum devlink_trap_action action,
340
+ struct netlink_ext_ack *extack);
341
+ int (*trap_group_init)(struct mlxsw_core *mlxsw_core,
342
+ const struct devlink_trap_group *group);
343
+ int (*trap_group_set)(struct mlxsw_core *mlxsw_core,
344
+ const struct devlink_trap_group *group,
345
+ const struct devlink_trap_policer *policer,
346
+ struct netlink_ext_ack *extack);
347
+ int (*trap_policer_init)(struct mlxsw_core *mlxsw_core,
348
+ const struct devlink_trap_policer *policer);
349
+ void (*trap_policer_fini)(struct mlxsw_core *mlxsw_core,
350
+ const struct devlink_trap_policer *policer);
351
+ int (*trap_policer_set)(struct mlxsw_core *mlxsw_core,
352
+ const struct devlink_trap_policer *policer,
353
+ u64 rate, u64 burst,
354
+ struct netlink_ext_ack *extack);
355
+ int (*trap_policer_counter_get)(struct mlxsw_core *mlxsw_core,
356
+ const struct devlink_trap_policer *policer,
357
+ u64 *p_drops);
278358 void (*txhdr_construct)(struct sk_buff *skb,
279359 const struct mlxsw_tx_info *tx_info);
280360 int (*resources_register)(struct mlxsw_core *mlxsw_core);
....@@ -282,9 +362,20 @@
282362 const struct mlxsw_config_profile *profile,
283363 u64 *p_single_size, u64 *p_double_size,
284364 u64 *p_linear_size);
365
+ int (*params_register)(struct mlxsw_core *mlxsw_core);
366
+ void (*params_unregister)(struct mlxsw_core *mlxsw_core);
367
+
368
+ /* Notify a driver that a timestamped packet was transmitted. Driver
369
+ * is responsible for freeing the passed-in SKB.
370
+ */
371
+ void (*ptp_transmitted)(struct mlxsw_core *mlxsw_core,
372
+ struct sk_buff *skb, u8 local_port);
373
+
285374 u8 txhdr_len;
286375 const struct mlxsw_config_profile *profile;
287376 bool res_query_enabled;
377
+ bool fw_fatal_enabled;
378
+ bool temp_warn_enabled;
288379 };
289380
290381 int mlxsw_core_kvd_sizes_get(struct mlxsw_core *mlxsw_core,
....@@ -292,8 +383,10 @@
292383 u64 *p_single_size, u64 *p_double_size,
293384 u64 *p_linear_size);
294385
295
-void mlxsw_core_fw_flash_start(struct mlxsw_core *mlxsw_core);
296
-void mlxsw_core_fw_flash_end(struct mlxsw_core *mlxsw_core);
386
+u32 mlxsw_core_read_frc_h(struct mlxsw_core *mlxsw_core);
387
+u32 mlxsw_core_read_frc_l(struct mlxsw_core *mlxsw_core);
388
+
389
+void mlxsw_core_emad_string_tlv_enable(struct mlxsw_core *mlxsw_core);
297390
298391 bool mlxsw_core_res_valid(struct mlxsw_core *mlxsw_core,
299392 enum mlxsw_res_id res_id);
....@@ -306,6 +399,11 @@
306399
307400 #define MLXSW_CORE_RES_GET(mlxsw_core, short_res_id) \
308401 mlxsw_core_res_get(mlxsw_core, MLXSW_RES_ID_##short_res_id)
402
+
403
+static inline struct net *mlxsw_core_net(struct mlxsw_core *mlxsw_core)
404
+{
405
+ return devlink_net(priv_to_devlink(mlxsw_core));
406
+}
309407
310408 #define MLXSW_BUS_F_TXRX BIT(0)
311409 #define MLXSW_BUS_F_RESET BIT(1)
....@@ -325,6 +423,8 @@
325423 char *in_mbox, size_t in_mbox_size,
326424 char *out_mbox, size_t out_mbox_size,
327425 u8 *p_status);
426
+ u32 (*read_frc_h)(void *bus_priv);
427
+ u32 (*read_frc_l)(void *bus_priv);
328428 u8 features;
329429 };
330430
....@@ -342,6 +442,8 @@
342442 struct mlxsw_fw_rev fw_rev;
343443 u8 vsd[MLXSW_CMD_BOARDINFO_VSD_LEN];
344444 u8 psid[MLXSW_CMD_BOARDINFO_PSID_LEN];
445
+ u8 low_frequency:1,
446
+ read_frc_capable:1;
345447 };
346448
347449 struct mlxsw_hwmon;
....@@ -392,4 +494,22 @@
392494
393495 #endif
394496
497
+enum mlxsw_devlink_param_id {
498
+ MLXSW_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
499
+ MLXSW_DEVLINK_PARAM_ID_ACL_REGION_REHASH_INTERVAL,
500
+};
501
+
502
+struct mlxsw_skb_cb {
503
+ union {
504
+ struct mlxsw_tx_info tx_info;
505
+ u32 cookie_index; /* Only used during receive */
506
+ };
507
+};
508
+
509
+static inline struct mlxsw_skb_cb *mlxsw_skb_cb(struct sk_buff *skb)
510
+{
511
+ BUILD_BUG_ON(sizeof(mlxsw_skb_cb) > sizeof(skb->cb));
512
+ return (struct mlxsw_skb_cb *) skb->cb;
513
+}
514
+
395515 #endif