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