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