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