]>
Commit | Line | Data |
---|---|---|
2874c5fd | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
bfcd3a46 JP |
2 | /* |
3 | * include/net/devlink.h - Network physical device Netlink interface | |
4 | * Copyright (c) 2016 Mellanox Technologies. All rights reserved. | |
5 | * Copyright (c) 2016 Jiri Pirko <jiri@mellanox.com> | |
bfcd3a46 JP |
6 | */ |
7 | #ifndef _NET_DEVLINK_H_ | |
8 | #define _NET_DEVLINK_H_ | |
9 | ||
10 | #include <linux/device.h> | |
11 | #include <linux/slab.h> | |
12 | #include <linux/gfp.h> | |
13 | #include <linux/list.h> | |
14 | #include <linux/netdevice.h> | |
b8f97554 | 15 | #include <linux/spinlock.h> |
136bf27f | 16 | #include <linux/workqueue.h> |
bfcd3a46 JP |
17 | #include <net/net_namespace.h> |
18 | #include <uapi/linux/devlink.h> | |
19 | ||
20 | struct devlink_ops; | |
21 | ||
22 | struct devlink { | |
23 | struct list_head list; | |
24 | struct list_head port_list; | |
bf797471 | 25 | struct list_head sb_list; |
1555d204 | 26 | struct list_head dpipe_table_list; |
d9f9b9a4 | 27 | struct list_head resource_list; |
eabaef18 | 28 | struct list_head param_list; |
b16ebe92 | 29 | struct list_head region_list; |
ccadfa44 | 30 | u32 snapshot_id; |
a0bdcc59 | 31 | struct list_head reporter_list; |
b587bdaf | 32 | struct mutex reporters_lock; /* protects reporter_list */ |
1555d204 | 33 | struct devlink_dpipe_headers *dpipe_headers; |
bfcd3a46 JP |
34 | const struct devlink_ops *ops; |
35 | struct device *dev; | |
36 | possible_net_t _net; | |
2406e7e5 | 37 | struct mutex lock; |
bfcd3a46 JP |
38 | char priv[0] __aligned(NETDEV_ALIGN); |
39 | }; | |
40 | ||
b9ffcbaf | 41 | struct devlink_port_attrs { |
407dd706 | 42 | u8 set:1, |
bec5267c JP |
43 | split:1, |
44 | switch_port:1; | |
5ec1380a | 45 | enum devlink_port_flavour flavour; |
b9ffcbaf | 46 | u32 port_number; /* same value as "split group" */ |
b9ffcbaf | 47 | u32 split_subport_number; |
bec5267c | 48 | struct netdev_phys_item_id switch_id; |
b9ffcbaf JP |
49 | }; |
50 | ||
bfcd3a46 JP |
51 | struct devlink_port { |
52 | struct list_head list; | |
39e6160e | 53 | struct list_head param_list; |
bfcd3a46 JP |
54 | struct devlink *devlink; |
55 | unsigned index; | |
56 | bool registered; | |
b8f97554 JP |
57 | spinlock_t type_lock; /* Protects type and type_dev |
58 | * pointer consistency. | |
59 | */ | |
bfcd3a46 JP |
60 | enum devlink_port_type type; |
61 | enum devlink_port_type desired_type; | |
62 | void *type_dev; | |
b9ffcbaf | 63 | struct devlink_port_attrs attrs; |
136bf27f | 64 | struct delayed_work type_warn_dw; |
bfcd3a46 JP |
65 | }; |
66 | ||
bf797471 JP |
67 | struct devlink_sb_pool_info { |
68 | enum devlink_sb_pool_type pool_type; | |
69 | u32 size; | |
70 | enum devlink_sb_threshold_type threshold_type; | |
bff5731d | 71 | u32 cell_size; |
bf797471 JP |
72 | }; |
73 | ||
1555d204 AS |
74 | /** |
75 | * struct devlink_dpipe_field - dpipe field object | |
76 | * @name: field name | |
77 | * @id: index inside the headers field array | |
78 | * @bitwidth: bitwidth | |
79 | * @mapping_type: mapping type | |
80 | */ | |
81 | struct devlink_dpipe_field { | |
82 | const char *name; | |
83 | unsigned int id; | |
84 | unsigned int bitwidth; | |
85 | enum devlink_dpipe_field_mapping_type mapping_type; | |
86 | }; | |
87 | ||
88 | /** | |
89 | * struct devlink_dpipe_header - dpipe header object | |
90 | * @name: header name | |
91 | * @id: index, global/local detrmined by global bit | |
92 | * @fields: fields | |
93 | * @fields_count: number of fields | |
94 | * @global: indicates if header is shared like most protocol header | |
95 | * or driver specific | |
96 | */ | |
97 | struct devlink_dpipe_header { | |
98 | const char *name; | |
99 | unsigned int id; | |
100 | struct devlink_dpipe_field *fields; | |
101 | unsigned int fields_count; | |
102 | bool global; | |
103 | }; | |
104 | ||
105 | /** | |
106 | * struct devlink_dpipe_match - represents match operation | |
107 | * @type: type of match | |
108 | * @header_index: header index (packets can have several headers of same | |
109 | * type like in case of tunnels) | |
110 | * @header: header | |
111 | * @fieled_id: field index | |
112 | */ | |
113 | struct devlink_dpipe_match { | |
114 | enum devlink_dpipe_match_type type; | |
115 | unsigned int header_index; | |
116 | struct devlink_dpipe_header *header; | |
117 | unsigned int field_id; | |
118 | }; | |
119 | ||
120 | /** | |
121 | * struct devlink_dpipe_action - represents action operation | |
122 | * @type: type of action | |
123 | * @header_index: header index (packets can have several headers of same | |
124 | * type like in case of tunnels) | |
125 | * @header: header | |
126 | * @fieled_id: field index | |
127 | */ | |
128 | struct devlink_dpipe_action { | |
129 | enum devlink_dpipe_action_type type; | |
130 | unsigned int header_index; | |
131 | struct devlink_dpipe_header *header; | |
132 | unsigned int field_id; | |
133 | }; | |
134 | ||
135 | /** | |
136 | * struct devlink_dpipe_value - represents value of match/action | |
137 | * @action: action | |
138 | * @match: match | |
139 | * @mapping_value: in case the field has some mapping this value | |
140 | * specified the mapping value | |
141 | * @mapping_valid: specify if mapping value is valid | |
142 | * @value_size: value size | |
143 | * @value: value | |
144 | * @mask: bit mask | |
145 | */ | |
146 | struct devlink_dpipe_value { | |
147 | union { | |
148 | struct devlink_dpipe_action *action; | |
149 | struct devlink_dpipe_match *match; | |
150 | }; | |
151 | unsigned int mapping_value; | |
152 | bool mapping_valid; | |
153 | unsigned int value_size; | |
154 | void *value; | |
155 | void *mask; | |
156 | }; | |
157 | ||
158 | /** | |
159 | * struct devlink_dpipe_entry - table entry object | |
160 | * @index: index of the entry in the table | |
161 | * @match_values: match values | |
162 | * @matche_values_count: count of matches tuples | |
163 | * @action_values: actions values | |
164 | * @action_values_count: count of actions values | |
165 | * @counter: value of counter | |
166 | * @counter_valid: Specify if value is valid from hardware | |
167 | */ | |
168 | struct devlink_dpipe_entry { | |
169 | u64 index; | |
170 | struct devlink_dpipe_value *match_values; | |
171 | unsigned int match_values_count; | |
172 | struct devlink_dpipe_value *action_values; | |
173 | unsigned int action_values_count; | |
174 | u64 counter; | |
175 | bool counter_valid; | |
176 | }; | |
177 | ||
178 | /** | |
179 | * struct devlink_dpipe_dump_ctx - context provided to driver in order | |
180 | * to dump | |
181 | * @info: info | |
182 | * @cmd: devlink command | |
183 | * @skb: skb | |
184 | * @nest: top attribute | |
185 | * @hdr: hdr | |
186 | */ | |
187 | struct devlink_dpipe_dump_ctx { | |
188 | struct genl_info *info; | |
189 | enum devlink_command cmd; | |
190 | struct sk_buff *skb; | |
191 | struct nlattr *nest; | |
192 | void *hdr; | |
193 | }; | |
194 | ||
195 | struct devlink_dpipe_table_ops; | |
196 | ||
197 | /** | |
198 | * struct devlink_dpipe_table - table object | |
199 | * @priv: private | |
200 | * @name: table name | |
1555d204 AS |
201 | * @counters_enabled: indicates if counters are active |
202 | * @counter_control_extern: indicates if counter control is in dpipe or | |
203 | * external tool | |
56dc7cd0 AS |
204 | * @resource_valid: Indicate that the resource id is valid |
205 | * @resource_id: relative resource this table is related to | |
206 | * @resource_units: number of resource's unit consumed per table's entry | |
1555d204 AS |
207 | * @table_ops: table operations |
208 | * @rcu: rcu | |
209 | */ | |
210 | struct devlink_dpipe_table { | |
211 | void *priv; | |
212 | struct list_head list; | |
213 | const char *name; | |
1555d204 AS |
214 | bool counters_enabled; |
215 | bool counter_control_extern; | |
56dc7cd0 AS |
216 | bool resource_valid; |
217 | u64 resource_id; | |
218 | u64 resource_units; | |
1555d204 AS |
219 | struct devlink_dpipe_table_ops *table_ops; |
220 | struct rcu_head rcu; | |
221 | }; | |
222 | ||
223 | /** | |
224 | * struct devlink_dpipe_table_ops - dpipe_table ops | |
225 | * @actions_dump - dumps all tables actions | |
226 | * @matches_dump - dumps all tables matches | |
227 | * @entries_dump - dumps all active entries in the table | |
228 | * @counters_set_update - when changing the counter status hardware sync | |
229 | * maybe needed to allocate/free counter related | |
230 | * resources | |
ffd3cdcc | 231 | * @size_get - get size |
1555d204 AS |
232 | */ |
233 | struct devlink_dpipe_table_ops { | |
234 | int (*actions_dump)(void *priv, struct sk_buff *skb); | |
235 | int (*matches_dump)(void *priv, struct sk_buff *skb); | |
236 | int (*entries_dump)(void *priv, bool counters_enabled, | |
237 | struct devlink_dpipe_dump_ctx *dump_ctx); | |
238 | int (*counters_set_update)(void *priv, bool enable); | |
ffd3cdcc | 239 | u64 (*size_get)(void *priv); |
1555d204 AS |
240 | }; |
241 | ||
242 | /** | |
243 | * struct devlink_dpipe_headers - dpipe headers | |
244 | * @headers - header array can be shared (global bit) or driver specific | |
245 | * @headers_count - count of headers | |
246 | */ | |
247 | struct devlink_dpipe_headers { | |
248 | struct devlink_dpipe_header **headers; | |
249 | unsigned int headers_count; | |
250 | }; | |
251 | ||
d9f9b9a4 AS |
252 | /** |
253 | * struct devlink_resource_size_params - resource's size parameters | |
254 | * @size_min: minimum size which can be set | |
255 | * @size_max: maximum size which can be set | |
256 | * @size_granularity: size granularity | |
257 | * @size_unit: resource's basic unit | |
258 | */ | |
259 | struct devlink_resource_size_params { | |
260 | u64 size_min; | |
261 | u64 size_max; | |
262 | u64 size_granularity; | |
263 | enum devlink_resource_unit unit; | |
264 | }; | |
265 | ||
77d27096 JP |
266 | static inline void |
267 | devlink_resource_size_params_init(struct devlink_resource_size_params *size_params, | |
268 | u64 size_min, u64 size_max, | |
269 | u64 size_granularity, | |
270 | enum devlink_resource_unit unit) | |
271 | { | |
272 | size_params->size_min = size_min; | |
273 | size_params->size_max = size_max; | |
274 | size_params->size_granularity = size_granularity; | |
275 | size_params->unit = unit; | |
276 | } | |
277 | ||
fc56be47 JP |
278 | typedef u64 devlink_resource_occ_get_t(void *priv); |
279 | ||
d9f9b9a4 AS |
280 | /** |
281 | * struct devlink_resource - devlink resource | |
282 | * @name: name of the resource | |
283 | * @id: id, per devlink instance | |
284 | * @size: size of the resource | |
285 | * @size_new: updated size of the resource, reload is needed | |
286 | * @size_valid: valid in case the total size of the resource is valid | |
287 | * including its children | |
288 | * @parent: parent resource | |
289 | * @size_params: size parameters | |
290 | * @list: parent list | |
291 | * @resource_list: list of child resources | |
d9f9b9a4 AS |
292 | */ |
293 | struct devlink_resource { | |
294 | const char *name; | |
295 | u64 id; | |
296 | u64 size; | |
297 | u64 size_new; | |
298 | bool size_valid; | |
299 | struct devlink_resource *parent; | |
77d27096 | 300 | struct devlink_resource_size_params size_params; |
d9f9b9a4 AS |
301 | struct list_head list; |
302 | struct list_head resource_list; | |
fc56be47 JP |
303 | devlink_resource_occ_get_t *occ_get; |
304 | void *occ_get_priv; | |
d9f9b9a4 AS |
305 | }; |
306 | ||
307 | #define DEVLINK_RESOURCE_ID_PARENT_TOP 0 | |
308 | ||
bde74ad1 | 309 | #define __DEVLINK_PARAM_MAX_STRING_VALUE 32 |
eabaef18 MS |
310 | enum devlink_param_type { |
311 | DEVLINK_PARAM_TYPE_U8, | |
312 | DEVLINK_PARAM_TYPE_U16, | |
313 | DEVLINK_PARAM_TYPE_U32, | |
314 | DEVLINK_PARAM_TYPE_STRING, | |
315 | DEVLINK_PARAM_TYPE_BOOL, | |
316 | }; | |
317 | ||
318 | union devlink_param_value { | |
319 | u8 vu8; | |
320 | u16 vu16; | |
321 | u32 vu32; | |
bde74ad1 | 322 | char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE]; |
eabaef18 MS |
323 | bool vbool; |
324 | }; | |
325 | ||
326 | struct devlink_param_gset_ctx { | |
327 | union devlink_param_value val; | |
328 | enum devlink_param_cmode cmode; | |
329 | }; | |
330 | ||
331 | /** | |
332 | * struct devlink_param - devlink configuration parameter data | |
333 | * @name: name of the parameter | |
334 | * @generic: indicates if the parameter is generic or driver specific | |
335 | * @type: parameter type | |
336 | * @supported_cmodes: bitmap of supported configuration modes | |
337 | * @get: get parameter value, used for runtime and permanent | |
338 | * configuration modes | |
339 | * @set: set parameter value, used for runtime and permanent | |
340 | * configuration modes | |
e3b7ca18 | 341 | * @validate: validate input value is applicable (within value range, etc.) |
eabaef18 MS |
342 | * |
343 | * This struct should be used by the driver to fill the data for | |
344 | * a parameter it registers. | |
345 | */ | |
346 | struct devlink_param { | |
347 | u32 id; | |
348 | const char *name; | |
349 | bool generic; | |
350 | enum devlink_param_type type; | |
351 | unsigned long supported_cmodes; | |
352 | int (*get)(struct devlink *devlink, u32 id, | |
353 | struct devlink_param_gset_ctx *ctx); | |
354 | int (*set)(struct devlink *devlink, u32 id, | |
355 | struct devlink_param_gset_ctx *ctx); | |
e3b7ca18 MS |
356 | int (*validate)(struct devlink *devlink, u32 id, |
357 | union devlink_param_value val, | |
358 | struct netlink_ext_ack *extack); | |
eabaef18 MS |
359 | }; |
360 | ||
361 | struct devlink_param_item { | |
362 | struct list_head list; | |
363 | const struct devlink_param *param; | |
364 | union devlink_param_value driverinit_value; | |
365 | bool driverinit_value_valid; | |
7c62cfb8 | 366 | bool published; |
eabaef18 MS |
367 | }; |
368 | ||
369 | enum devlink_param_generic_id { | |
036467c3 MS |
370 | DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET, |
371 | DEVLINK_PARAM_GENERIC_ID_MAX_MACS, | |
f567bcda | 372 | DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV, |
f6a69885 | 373 | DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT, |
e3b51061 | 374 | DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI, |
f61cba42 | 375 | DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX, |
16511789 | 376 | DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN, |
846e980a | 377 | DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY, |
eabaef18 MS |
378 | |
379 | /* add new param generic ids above here*/ | |
380 | __DEVLINK_PARAM_GENERIC_ID_MAX, | |
381 | DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1, | |
382 | }; | |
383 | ||
036467c3 MS |
384 | #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset" |
385 | #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL | |
386 | ||
387 | #define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs" | |
388 | #define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32 | |
389 | ||
f567bcda VV |
390 | #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov" |
391 | #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL | |
392 | ||
f6a69885 AV |
393 | #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable" |
394 | #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL | |
395 | ||
e3b51061 VV |
396 | #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari" |
397 | #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL | |
398 | ||
f61cba42 VV |
399 | #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max" |
400 | #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32 | |
401 | ||
16511789 VV |
402 | #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min" |
403 | #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32 | |
404 | ||
846e980a ST |
405 | #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy" |
406 | #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8 | |
407 | ||
036467c3 MS |
408 | #define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \ |
409 | { \ | |
410 | .id = DEVLINK_PARAM_GENERIC_ID_##_id, \ | |
411 | .name = DEVLINK_PARAM_GENERIC_##_id##_NAME, \ | |
412 | .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE, \ | |
413 | .generic = true, \ | |
414 | .supported_cmodes = _cmodes, \ | |
415 | .get = _get, \ | |
416 | .set = _set, \ | |
417 | .validate = _validate, \ | |
418 | } | |
419 | ||
420 | #define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate) \ | |
421 | { \ | |
422 | .id = _id, \ | |
423 | .name = _name, \ | |
424 | .type = _type, \ | |
425 | .supported_cmodes = _cmodes, \ | |
426 | .get = _get, \ | |
427 | .set = _set, \ | |
428 | .validate = _validate, \ | |
429 | } | |
430 | ||
785bd550 JK |
431 | /* Part number, identifier of board design */ |
432 | #define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID "board.id" | |
433 | /* Revision of board design */ | |
434 | #define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV "board.rev" | |
14fd1901 JK |
435 | /* Maker of the board */ |
436 | #define DEVLINK_INFO_VERSION_GENERIC_BOARD_MANUFACTURE "board.manufacture" | |
785bd550 JK |
437 | |
438 | /* Control processor FW version */ | |
439 | #define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT "fw.mgmt" | |
440 | /* Data path microcode controlling high-speed packet processing */ | |
441 | #define DEVLINK_INFO_VERSION_GENERIC_FW_APP "fw.app" | |
442 | /* UNDI software version */ | |
443 | #define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI "fw.undi" | |
444 | /* NCSI support/handler version */ | |
445 | #define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI "fw.ncsi" | |
446 | ||
b16ebe92 | 447 | struct devlink_region; |
f9cf2288 | 448 | struct devlink_info_req; |
b16ebe92 | 449 | |
d7e52722 AV |
450 | typedef void devlink_snapshot_data_dest_t(const void *data); |
451 | ||
1db64e87 | 452 | struct devlink_fmsg; |
a0bdcc59 EBE |
453 | struct devlink_health_reporter; |
454 | ||
3167b27a EBE |
455 | enum devlink_health_reporter_state { |
456 | DEVLINK_HEALTH_REPORTER_STATE_HEALTHY, | |
457 | DEVLINK_HEALTH_REPORTER_STATE_ERROR, | |
458 | }; | |
459 | ||
a0bdcc59 EBE |
460 | /** |
461 | * struct devlink_health_reporter_ops - Reporter operations | |
462 | * @name: reporter name | |
463 | * @recover: callback to recover from reported error | |
464 | * if priv_ctx is NULL, run a full recover | |
465 | * @dump: callback to dump an object | |
466 | * if priv_ctx is NULL, run a full dump | |
467 | * @diagnose: callback to diagnose the current status | |
468 | */ | |
469 | ||
470 | struct devlink_health_reporter_ops { | |
471 | char *name; | |
472 | int (*recover)(struct devlink_health_reporter *reporter, | |
473 | void *priv_ctx); | |
474 | int (*dump)(struct devlink_health_reporter *reporter, | |
475 | struct devlink_fmsg *fmsg, void *priv_ctx); | |
476 | int (*diagnose)(struct devlink_health_reporter *reporter, | |
477 | struct devlink_fmsg *fmsg); | |
478 | }; | |
1db64e87 | 479 | |
bfcd3a46 | 480 | struct devlink_ops { |
ac0fc8a1 | 481 | int (*reload)(struct devlink *devlink, struct netlink_ext_ack *extack); |
bfcd3a46 JP |
482 | int (*port_type_set)(struct devlink_port *devlink_port, |
483 | enum devlink_port_type port_type); | |
484 | int (*port_split)(struct devlink *devlink, unsigned int port_index, | |
ac0fc8a1 DA |
485 | unsigned int count, struct netlink_ext_ack *extack); |
486 | int (*port_unsplit)(struct devlink *devlink, unsigned int port_index, | |
487 | struct netlink_ext_ack *extack); | |
bf797471 JP |
488 | int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index, |
489 | u16 pool_index, | |
490 | struct devlink_sb_pool_info *pool_info); | |
491 | int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index, | |
492 | u16 pool_index, u32 size, | |
f2ad1a52 IS |
493 | enum devlink_sb_threshold_type threshold_type, |
494 | struct netlink_ext_ack *extack); | |
bf797471 JP |
495 | int (*sb_port_pool_get)(struct devlink_port *devlink_port, |
496 | unsigned int sb_index, u16 pool_index, | |
497 | u32 *p_threshold); | |
498 | int (*sb_port_pool_set)(struct devlink_port *devlink_port, | |
499 | unsigned int sb_index, u16 pool_index, | |
f2ad1a52 | 500 | u32 threshold, struct netlink_ext_ack *extack); |
bf797471 JP |
501 | int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port, |
502 | unsigned int sb_index, | |
503 | u16 tc_index, | |
504 | enum devlink_sb_pool_type pool_type, | |
505 | u16 *p_pool_index, u32 *p_threshold); | |
506 | int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port, | |
507 | unsigned int sb_index, | |
508 | u16 tc_index, | |
509 | enum devlink_sb_pool_type pool_type, | |
f2ad1a52 IS |
510 | u16 pool_index, u32 threshold, |
511 | struct netlink_ext_ack *extack); | |
df38dafd JP |
512 | int (*sb_occ_snapshot)(struct devlink *devlink, |
513 | unsigned int sb_index); | |
514 | int (*sb_occ_max_clear)(struct devlink *devlink, | |
515 | unsigned int sb_index); | |
516 | int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port, | |
517 | unsigned int sb_index, u16 pool_index, | |
518 | u32 *p_cur, u32 *p_max); | |
519 | int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port, | |
520 | unsigned int sb_index, | |
521 | u16 tc_index, | |
522 | enum devlink_sb_pool_type pool_type, | |
523 | u32 *p_cur, u32 *p_max); | |
08f4b591 OG |
524 | |
525 | int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode); | |
db7ff19e EB |
526 | int (*eswitch_mode_set)(struct devlink *devlink, u16 mode, |
527 | struct netlink_ext_ack *extack); | |
59bfde01 | 528 | int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode); |
db7ff19e EB |
529 | int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode, |
530 | struct netlink_ext_ack *extack); | |
98fdbea5 LR |
531 | int (*eswitch_encap_mode_get)(struct devlink *devlink, |
532 | enum devlink_eswitch_encap_mode *p_encap_mode); | |
533 | int (*eswitch_encap_mode_set)(struct devlink *devlink, | |
534 | enum devlink_eswitch_encap_mode encap_mode, | |
db7ff19e | 535 | struct netlink_ext_ack *extack); |
f9cf2288 JK |
536 | int (*info_get)(struct devlink *devlink, struct devlink_info_req *req, |
537 | struct netlink_ext_ack *extack); | |
76726ccb JK |
538 | int (*flash_update)(struct devlink *devlink, const char *file_name, |
539 | const char *component, | |
540 | struct netlink_ext_ack *extack); | |
bfcd3a46 JP |
541 | }; |
542 | ||
543 | static inline void *devlink_priv(struct devlink *devlink) | |
544 | { | |
545 | BUG_ON(!devlink); | |
546 | return &devlink->priv; | |
547 | } | |
548 | ||
549 | static inline struct devlink *priv_to_devlink(void *priv) | |
550 | { | |
551 | BUG_ON(!priv); | |
552 | return container_of(priv, struct devlink, priv); | |
553 | } | |
554 | ||
5dc37bb9 JP |
555 | static inline struct devlink_port * |
556 | netdev_to_devlink_port(struct net_device *dev) | |
557 | { | |
558 | if (dev->netdev_ops->ndo_get_devlink_port) | |
559 | return dev->netdev_ops->ndo_get_devlink_port(dev); | |
560 | return NULL; | |
561 | } | |
562 | ||
b473b0d2 JK |
563 | static inline struct devlink *netdev_to_devlink(struct net_device *dev) |
564 | { | |
5dc37bb9 JP |
565 | struct devlink_port *devlink_port = netdev_to_devlink_port(dev); |
566 | ||
567 | if (devlink_port) | |
568 | return devlink_port->devlink; | |
b473b0d2 JK |
569 | return NULL; |
570 | } | |
571 | ||
bfcd3a46 JP |
572 | struct ib_device; |
573 | ||
bfcd3a46 JP |
574 | struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size); |
575 | int devlink_register(struct devlink *devlink, struct device *dev); | |
576 | void devlink_unregister(struct devlink *devlink); | |
577 | void devlink_free(struct devlink *devlink); | |
578 | int devlink_port_register(struct devlink *devlink, | |
579 | struct devlink_port *devlink_port, | |
580 | unsigned int port_index); | |
581 | void devlink_port_unregister(struct devlink_port *devlink_port); | |
582 | void devlink_port_type_eth_set(struct devlink_port *devlink_port, | |
583 | struct net_device *netdev); | |
584 | void devlink_port_type_ib_set(struct devlink_port *devlink_port, | |
585 | struct ib_device *ibdev); | |
586 | void devlink_port_type_clear(struct devlink_port *devlink_port); | |
b9ffcbaf | 587 | void devlink_port_attrs_set(struct devlink_port *devlink_port, |
5ec1380a | 588 | enum devlink_port_flavour flavour, |
b9ffcbaf | 589 | u32 port_number, bool split, |
bec5267c JP |
590 | u32 split_subport_number, |
591 | const unsigned char *switch_id, | |
592 | unsigned char switch_id_len); | |
bf797471 JP |
593 | int devlink_sb_register(struct devlink *devlink, unsigned int sb_index, |
594 | u32 size, u16 ingress_pools_count, | |
595 | u16 egress_pools_count, u16 ingress_tc_count, | |
596 | u16 egress_tc_count); | |
597 | void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index); | |
1555d204 AS |
598 | int devlink_dpipe_table_register(struct devlink *devlink, |
599 | const char *table_name, | |
600 | struct devlink_dpipe_table_ops *table_ops, | |
ffd3cdcc | 601 | void *priv, bool counter_control_extern); |
1555d204 AS |
602 | void devlink_dpipe_table_unregister(struct devlink *devlink, |
603 | const char *table_name); | |
604 | int devlink_dpipe_headers_register(struct devlink *devlink, | |
605 | struct devlink_dpipe_headers *dpipe_headers); | |
606 | void devlink_dpipe_headers_unregister(struct devlink *devlink); | |
607 | bool devlink_dpipe_table_counter_enabled(struct devlink *devlink, | |
608 | const char *table_name); | |
609 | int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx); | |
610 | int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx, | |
611 | struct devlink_dpipe_entry *entry); | |
612 | int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx); | |
35807324 | 613 | void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry); |
1555d204 AS |
614 | int devlink_dpipe_action_put(struct sk_buff *skb, |
615 | struct devlink_dpipe_action *action); | |
616 | int devlink_dpipe_match_put(struct sk_buff *skb, | |
617 | struct devlink_dpipe_match *match); | |
11770091 | 618 | extern struct devlink_dpipe_header devlink_dpipe_header_ethernet; |
3fb886ec | 619 | extern struct devlink_dpipe_header devlink_dpipe_header_ipv4; |
1797f5b3 | 620 | extern struct devlink_dpipe_header devlink_dpipe_header_ipv6; |
bfcd3a46 | 621 | |
d9f9b9a4 AS |
622 | int devlink_resource_register(struct devlink *devlink, |
623 | const char *resource_name, | |
d9f9b9a4 AS |
624 | u64 resource_size, |
625 | u64 resource_id, | |
626 | u64 parent_resource_id, | |
fc56be47 | 627 | const struct devlink_resource_size_params *size_params); |
d9f9b9a4 AS |
628 | void devlink_resources_unregister(struct devlink *devlink, |
629 | struct devlink_resource *resource); | |
630 | int devlink_resource_size_get(struct devlink *devlink, | |
631 | u64 resource_id, | |
632 | u64 *p_resource_size); | |
56dc7cd0 AS |
633 | int devlink_dpipe_table_resource_set(struct devlink *devlink, |
634 | const char *table_name, u64 resource_id, | |
635 | u64 resource_units); | |
fc56be47 JP |
636 | void devlink_resource_occ_get_register(struct devlink *devlink, |
637 | u64 resource_id, | |
638 | devlink_resource_occ_get_t *occ_get, | |
639 | void *occ_get_priv); | |
640 | void devlink_resource_occ_get_unregister(struct devlink *devlink, | |
641 | u64 resource_id); | |
eabaef18 MS |
642 | int devlink_params_register(struct devlink *devlink, |
643 | const struct devlink_param *params, | |
644 | size_t params_count); | |
645 | void devlink_params_unregister(struct devlink *devlink, | |
646 | const struct devlink_param *params, | |
647 | size_t params_count); | |
7c62cfb8 JP |
648 | void devlink_params_publish(struct devlink *devlink); |
649 | void devlink_params_unpublish(struct devlink *devlink); | |
39e6160e VV |
650 | int devlink_port_params_register(struct devlink_port *devlink_port, |
651 | const struct devlink_param *params, | |
652 | size_t params_count); | |
653 | void devlink_port_params_unregister(struct devlink_port *devlink_port, | |
654 | const struct devlink_param *params, | |
655 | size_t params_count); | |
ec01aeb1 MS |
656 | int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id, |
657 | union devlink_param_value *init_val); | |
658 | int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id, | |
659 | union devlink_param_value init_val); | |
ffd19b9a VV |
660 | int |
661 | devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port, | |
662 | u32 param_id, | |
663 | union devlink_param_value *init_val); | |
5473a7bd VV |
664 | int devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port, |
665 | u32 param_id, | |
666 | union devlink_param_value init_val); | |
ea601e17 | 667 | void devlink_param_value_changed(struct devlink *devlink, u32 param_id); |
c1e5786d VV |
668 | void devlink_port_param_value_changed(struct devlink_port *devlink_port, |
669 | u32 param_id); | |
bde74ad1 MS |
670 | void devlink_param_value_str_fill(union devlink_param_value *dst_val, |
671 | const char *src); | |
b16ebe92 AV |
672 | struct devlink_region *devlink_region_create(struct devlink *devlink, |
673 | const char *region_name, | |
674 | u32 region_max_snapshots, | |
675 | u64 region_size); | |
676 | void devlink_region_destroy(struct devlink_region *region); | |
ccadfa44 | 677 | u32 devlink_region_shapshot_id_get(struct devlink *devlink); |
d7e52722 AV |
678 | int devlink_region_snapshot_create(struct devlink_region *region, u64 data_len, |
679 | u8 *data, u32 snapshot_id, | |
680 | devlink_snapshot_data_dest_t *data_destructor); | |
f9cf2288 JK |
681 | int devlink_info_serial_number_put(struct devlink_info_req *req, |
682 | const char *sn); | |
683 | int devlink_info_driver_name_put(struct devlink_info_req *req, | |
684 | const char *name); | |
fc6fae7d JK |
685 | int devlink_info_version_fixed_put(struct devlink_info_req *req, |
686 | const char *version_name, | |
687 | const char *version_value); | |
688 | int devlink_info_version_stored_put(struct devlink_info_req *req, | |
689 | const char *version_name, | |
690 | const char *version_value); | |
691 | int devlink_info_version_running_put(struct devlink_info_req *req, | |
692 | const char *version_name, | |
693 | const char *version_value); | |
d9f9b9a4 | 694 | |
1db64e87 EBE |
695 | int devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg); |
696 | int devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg); | |
697 | ||
698 | int devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name); | |
699 | int devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg); | |
700 | ||
701 | int devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg, | |
702 | const char *name); | |
703 | int devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg); | |
704 | ||
705 | int devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value); | |
706 | int devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value); | |
707 | int devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value); | |
708 | int devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value); | |
709 | int devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value); | |
710 | int devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value, | |
711 | u16 value_len); | |
712 | ||
713 | int devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name, | |
714 | bool value); | |
715 | int devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name, | |
716 | u8 value); | |
717 | int devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name, | |
718 | u32 value); | |
719 | int devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name, | |
720 | u64 value); | |
721 | int devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name, | |
722 | const char *value); | |
723 | int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name, | |
724 | const void *value, u16 value_len); | |
725 | ||
a0bdcc59 EBE |
726 | struct devlink_health_reporter * |
727 | devlink_health_reporter_create(struct devlink *devlink, | |
728 | const struct devlink_health_reporter_ops *ops, | |
729 | u64 graceful_period, bool auto_recover, | |
730 | void *priv); | |
731 | void | |
732 | devlink_health_reporter_destroy(struct devlink_health_reporter *reporter); | |
733 | ||
734 | void * | |
735 | devlink_health_reporter_priv(struct devlink_health_reporter *reporter); | |
c8e1da0b EBE |
736 | int devlink_health_report(struct devlink_health_reporter *reporter, |
737 | const char *msg, void *priv_ctx); | |
3167b27a EBE |
738 | void |
739 | devlink_health_reporter_state_update(struct devlink_health_reporter *reporter, | |
740 | enum devlink_health_reporter_state state); | |
a0bdcc59 | 741 | |
191ed202 JP |
742 | void devlink_flash_update_begin_notify(struct devlink *devlink); |
743 | void devlink_flash_update_end_notify(struct devlink *devlink); | |
744 | void devlink_flash_update_status_notify(struct devlink *devlink, | |
745 | const char *status_msg, | |
746 | const char *component, | |
747 | unsigned long done, | |
748 | unsigned long total); | |
749 | ||
f6b19b35 JP |
750 | #if IS_ENABLED(CONFIG_NET_DEVLINK) |
751 | ||
f4b6bcc7 JK |
752 | void devlink_compat_running_version(struct net_device *dev, |
753 | char *buf, size_t len); | |
754 | int devlink_compat_flash_update(struct net_device *dev, const char *file_name); | |
af3836df JP |
755 | int devlink_compat_phys_port_name_get(struct net_device *dev, |
756 | char *name, size_t len); | |
7e1146e8 JP |
757 | int devlink_compat_switch_id_get(struct net_device *dev, |
758 | struct netdev_phys_item_id *ppid); | |
f4b6bcc7 | 759 | |
bfcd3a46 JP |
760 | #else |
761 | ||
ddb6e99e JK |
762 | static inline void |
763 | devlink_compat_running_version(struct net_device *dev, char *buf, size_t len) | |
764 | { | |
765 | } | |
4eceba17 JK |
766 | |
767 | static inline int | |
768 | devlink_compat_flash_update(struct net_device *dev, const char *file_name) | |
769 | { | |
770 | return -EOPNOTSUPP; | |
771 | } | |
f6b19b35 | 772 | |
af3836df JP |
773 | static inline int |
774 | devlink_compat_phys_port_name_get(struct net_device *dev, | |
775 | char *name, size_t len) | |
776 | { | |
777 | return -EOPNOTSUPP; | |
778 | } | |
779 | ||
7e1146e8 JP |
780 | static inline int |
781 | devlink_compat_switch_id_get(struct net_device *dev, | |
782 | struct netdev_phys_item_id *ppid) | |
783 | { | |
784 | return -EOPNOTSUPP; | |
785 | } | |
786 | ||
ddb6e99e JK |
787 | #endif |
788 | ||
bfcd3a46 | 789 | #endif /* _NET_DEVLINK_H_ */ |