]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/net/devlink.h
devlink: Stop reference counting packet trap groups
[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>
0f420b6c 17#include <linux/refcount.h>
bfcd3a46 18#include <net/net_namespace.h>
5a2e106c 19#include <net/flow_offload.h>
bfcd3a46
JP
20#include <uapi/linux/devlink.h>
21
22struct devlink_ops;
23
24struct devlink {
25 struct list_head list;
26 struct list_head port_list;
bf797471 27 struct list_head sb_list;
1555d204 28 struct list_head dpipe_table_list;
d9f9b9a4 29 struct list_head resource_list;
eabaef18 30 struct list_head param_list;
b16ebe92 31 struct list_head region_list;
ccadfa44 32 u32 snapshot_id;
a0bdcc59 33 struct list_head reporter_list;
b587bdaf 34 struct mutex reporters_lock; /* protects reporter_list */
1555d204 35 struct devlink_dpipe_headers *dpipe_headers;
0f420b6c
IS
36 struct list_head trap_list;
37 struct list_head trap_group_list;
bfcd3a46
JP
38 const struct devlink_ops *ops;
39 struct device *dev;
40 possible_net_t _net;
2406e7e5 41 struct mutex lock;
a0c76345
JP
42 u8 reload_failed:1,
43 reload_enabled:1,
44 registered:1;
bfcd3a46
JP
45 char priv[0] __aligned(NETDEV_ALIGN);
46};
47
378ef01b
PP
48struct devlink_port_phys_attrs {
49 u32 port_number; /* Same value as "split group".
50 * A physical port which is visible to the user
51 * for a given port flavour.
52 */
53 u32 split_subport_number;
54};
55
98fd2d65
PP
56struct devlink_port_pci_pf_attrs {
57 u16 pf; /* Associated PCI PF for this port. */
58};
59
e41b6bf3
PP
60struct devlink_port_pci_vf_attrs {
61 u16 pf; /* Associated PCI PF for this port. */
62 u16 vf; /* Associated PCI VF for of the PCI PF for this port. */
63};
64
b9ffcbaf 65struct devlink_port_attrs {
407dd706 66 u8 set:1,
bec5267c
JP
67 split:1,
68 switch_port:1;
5ec1380a 69 enum devlink_port_flavour flavour;
bec5267c 70 struct netdev_phys_item_id switch_id;
378ef01b
PP
71 union {
72 struct devlink_port_phys_attrs phys;
98fd2d65 73 struct devlink_port_pci_pf_attrs pci_pf;
e41b6bf3 74 struct devlink_port_pci_vf_attrs pci_vf;
378ef01b 75 };
b9ffcbaf
JP
76};
77
bfcd3a46
JP
78struct devlink_port {
79 struct list_head list;
39e6160e 80 struct list_head param_list;
bfcd3a46 81 struct devlink *devlink;
c7282b50 82 unsigned int index;
bfcd3a46 83 bool registered;
b8f97554
JP
84 spinlock_t type_lock; /* Protects type and type_dev
85 * pointer consistency.
86 */
bfcd3a46
JP
87 enum devlink_port_type type;
88 enum devlink_port_type desired_type;
89 void *type_dev;
b9ffcbaf 90 struct devlink_port_attrs attrs;
136bf27f 91 struct delayed_work type_warn_dw;
bfcd3a46
JP
92};
93
bf797471
JP
94struct devlink_sb_pool_info {
95 enum devlink_sb_pool_type pool_type;
96 u32 size;
97 enum devlink_sb_threshold_type threshold_type;
bff5731d 98 u32 cell_size;
bf797471
JP
99};
100
1555d204
AS
101/**
102 * struct devlink_dpipe_field - dpipe field object
103 * @name: field name
104 * @id: index inside the headers field array
105 * @bitwidth: bitwidth
106 * @mapping_type: mapping type
107 */
108struct devlink_dpipe_field {
109 const char *name;
110 unsigned int id;
111 unsigned int bitwidth;
112 enum devlink_dpipe_field_mapping_type mapping_type;
113};
114
115/**
116 * struct devlink_dpipe_header - dpipe header object
117 * @name: header name
118 * @id: index, global/local detrmined by global bit
119 * @fields: fields
120 * @fields_count: number of fields
121 * @global: indicates if header is shared like most protocol header
122 * or driver specific
123 */
124struct devlink_dpipe_header {
125 const char *name;
126 unsigned int id;
127 struct devlink_dpipe_field *fields;
128 unsigned int fields_count;
129 bool global;
130};
131
132/**
133 * struct devlink_dpipe_match - represents match operation
134 * @type: type of match
135 * @header_index: header index (packets can have several headers of same
136 * type like in case of tunnels)
137 * @header: header
138 * @fieled_id: field index
139 */
140struct devlink_dpipe_match {
141 enum devlink_dpipe_match_type type;
142 unsigned int header_index;
143 struct devlink_dpipe_header *header;
144 unsigned int field_id;
145};
146
147/**
148 * struct devlink_dpipe_action - represents action operation
149 * @type: type of action
150 * @header_index: header index (packets can have several headers of same
151 * type like in case of tunnels)
152 * @header: header
153 * @fieled_id: field index
154 */
155struct devlink_dpipe_action {
156 enum devlink_dpipe_action_type type;
157 unsigned int header_index;
158 struct devlink_dpipe_header *header;
159 unsigned int field_id;
160};
161
162/**
163 * struct devlink_dpipe_value - represents value of match/action
164 * @action: action
165 * @match: match
166 * @mapping_value: in case the field has some mapping this value
167 * specified the mapping value
168 * @mapping_valid: specify if mapping value is valid
169 * @value_size: value size
170 * @value: value
171 * @mask: bit mask
172 */
173struct devlink_dpipe_value {
174 union {
175 struct devlink_dpipe_action *action;
176 struct devlink_dpipe_match *match;
177 };
178 unsigned int mapping_value;
179 bool mapping_valid;
180 unsigned int value_size;
181 void *value;
182 void *mask;
183};
184
185/**
186 * struct devlink_dpipe_entry - table entry object
187 * @index: index of the entry in the table
188 * @match_values: match values
189 * @matche_values_count: count of matches tuples
190 * @action_values: actions values
191 * @action_values_count: count of actions values
192 * @counter: value of counter
193 * @counter_valid: Specify if value is valid from hardware
194 */
195struct devlink_dpipe_entry {
196 u64 index;
197 struct devlink_dpipe_value *match_values;
198 unsigned int match_values_count;
199 struct devlink_dpipe_value *action_values;
200 unsigned int action_values_count;
201 u64 counter;
202 bool counter_valid;
203};
204
205/**
206 * struct devlink_dpipe_dump_ctx - context provided to driver in order
207 * to dump
208 * @info: info
209 * @cmd: devlink command
210 * @skb: skb
211 * @nest: top attribute
212 * @hdr: hdr
213 */
214struct devlink_dpipe_dump_ctx {
215 struct genl_info *info;
216 enum devlink_command cmd;
217 struct sk_buff *skb;
218 struct nlattr *nest;
219 void *hdr;
220};
221
222struct devlink_dpipe_table_ops;
223
224/**
225 * struct devlink_dpipe_table - table object
226 * @priv: private
227 * @name: table name
1555d204
AS
228 * @counters_enabled: indicates if counters are active
229 * @counter_control_extern: indicates if counter control is in dpipe or
230 * external tool
56dc7cd0
AS
231 * @resource_valid: Indicate that the resource id is valid
232 * @resource_id: relative resource this table is related to
233 * @resource_units: number of resource's unit consumed per table's entry
1555d204
AS
234 * @table_ops: table operations
235 * @rcu: rcu
236 */
237struct devlink_dpipe_table {
238 void *priv;
239 struct list_head list;
240 const char *name;
1555d204
AS
241 bool counters_enabled;
242 bool counter_control_extern;
56dc7cd0
AS
243 bool resource_valid;
244 u64 resource_id;
245 u64 resource_units;
1555d204
AS
246 struct devlink_dpipe_table_ops *table_ops;
247 struct rcu_head rcu;
248};
249
250/**
251 * struct devlink_dpipe_table_ops - dpipe_table ops
252 * @actions_dump - dumps all tables actions
253 * @matches_dump - dumps all tables matches
254 * @entries_dump - dumps all active entries in the table
255 * @counters_set_update - when changing the counter status hardware sync
256 * maybe needed to allocate/free counter related
257 * resources
ffd3cdcc 258 * @size_get - get size
1555d204
AS
259 */
260struct devlink_dpipe_table_ops {
261 int (*actions_dump)(void *priv, struct sk_buff *skb);
262 int (*matches_dump)(void *priv, struct sk_buff *skb);
263 int (*entries_dump)(void *priv, bool counters_enabled,
264 struct devlink_dpipe_dump_ctx *dump_ctx);
265 int (*counters_set_update)(void *priv, bool enable);
ffd3cdcc 266 u64 (*size_get)(void *priv);
1555d204
AS
267};
268
269/**
270 * struct devlink_dpipe_headers - dpipe headers
271 * @headers - header array can be shared (global bit) or driver specific
272 * @headers_count - count of headers
273 */
274struct devlink_dpipe_headers {
275 struct devlink_dpipe_header **headers;
276 unsigned int headers_count;
277};
278
d9f9b9a4
AS
279/**
280 * struct devlink_resource_size_params - resource's size parameters
281 * @size_min: minimum size which can be set
282 * @size_max: maximum size which can be set
283 * @size_granularity: size granularity
284 * @size_unit: resource's basic unit
285 */
286struct devlink_resource_size_params {
287 u64 size_min;
288 u64 size_max;
289 u64 size_granularity;
290 enum devlink_resource_unit unit;
291};
292
77d27096
JP
293static inline void
294devlink_resource_size_params_init(struct devlink_resource_size_params *size_params,
295 u64 size_min, u64 size_max,
296 u64 size_granularity,
297 enum devlink_resource_unit unit)
298{
299 size_params->size_min = size_min;
300 size_params->size_max = size_max;
301 size_params->size_granularity = size_granularity;
302 size_params->unit = unit;
303}
304
fc56be47
JP
305typedef u64 devlink_resource_occ_get_t(void *priv);
306
d9f9b9a4
AS
307/**
308 * struct devlink_resource - devlink resource
309 * @name: name of the resource
310 * @id: id, per devlink instance
311 * @size: size of the resource
312 * @size_new: updated size of the resource, reload is needed
313 * @size_valid: valid in case the total size of the resource is valid
314 * including its children
315 * @parent: parent resource
316 * @size_params: size parameters
317 * @list: parent list
318 * @resource_list: list of child resources
d9f9b9a4
AS
319 */
320struct devlink_resource {
321 const char *name;
322 u64 id;
323 u64 size;
324 u64 size_new;
325 bool size_valid;
326 struct devlink_resource *parent;
77d27096 327 struct devlink_resource_size_params size_params;
d9f9b9a4
AS
328 struct list_head list;
329 struct list_head resource_list;
fc56be47
JP
330 devlink_resource_occ_get_t *occ_get;
331 void *occ_get_priv;
d9f9b9a4
AS
332};
333
334#define DEVLINK_RESOURCE_ID_PARENT_TOP 0
335
bde74ad1 336#define __DEVLINK_PARAM_MAX_STRING_VALUE 32
eabaef18
MS
337enum devlink_param_type {
338 DEVLINK_PARAM_TYPE_U8,
339 DEVLINK_PARAM_TYPE_U16,
340 DEVLINK_PARAM_TYPE_U32,
341 DEVLINK_PARAM_TYPE_STRING,
342 DEVLINK_PARAM_TYPE_BOOL,
343};
344
345union devlink_param_value {
346 u8 vu8;
347 u16 vu16;
348 u32 vu32;
bde74ad1 349 char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];
eabaef18
MS
350 bool vbool;
351};
352
353struct devlink_param_gset_ctx {
354 union devlink_param_value val;
355 enum devlink_param_cmode cmode;
356};
357
358/**
359 * struct devlink_param - devlink configuration parameter data
360 * @name: name of the parameter
361 * @generic: indicates if the parameter is generic or driver specific
362 * @type: parameter type
363 * @supported_cmodes: bitmap of supported configuration modes
364 * @get: get parameter value, used for runtime and permanent
365 * configuration modes
366 * @set: set parameter value, used for runtime and permanent
367 * configuration modes
e3b7ca18 368 * @validate: validate input value is applicable (within value range, etc.)
eabaef18
MS
369 *
370 * This struct should be used by the driver to fill the data for
371 * a parameter it registers.
372 */
373struct devlink_param {
374 u32 id;
375 const char *name;
376 bool generic;
377 enum devlink_param_type type;
378 unsigned long supported_cmodes;
379 int (*get)(struct devlink *devlink, u32 id,
380 struct devlink_param_gset_ctx *ctx);
381 int (*set)(struct devlink *devlink, u32 id,
382 struct devlink_param_gset_ctx *ctx);
e3b7ca18
MS
383 int (*validate)(struct devlink *devlink, u32 id,
384 union devlink_param_value val,
385 struct netlink_ext_ack *extack);
eabaef18
MS
386};
387
388struct devlink_param_item {
389 struct list_head list;
390 const struct devlink_param *param;
391 union devlink_param_value driverinit_value;
392 bool driverinit_value_valid;
7c62cfb8 393 bool published;
eabaef18
MS
394};
395
396enum devlink_param_generic_id {
036467c3
MS
397 DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
398 DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
f567bcda 399 DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
f6a69885 400 DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT,
e3b51061 401 DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI,
f61cba42 402 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
16511789 403 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
846e980a 404 DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY,
5bbd21df 405 DEVLINK_PARAM_GENERIC_ID_RESET_DEV_ON_DRV_PROBE,
6c7295e1 406 DEVLINK_PARAM_GENERIC_ID_ENABLE_ROCE,
eabaef18
MS
407
408 /* add new param generic ids above here*/
409 __DEVLINK_PARAM_GENERIC_ID_MAX,
410 DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
411};
412
036467c3
MS
413#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
414#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
415
416#define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
417#define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
418
f567bcda
VV
419#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
420#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
421
f6a69885
AV
422#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable"
423#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL
424
e3b51061
VV
425#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari"
426#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL
427
f61cba42
VV
428#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max"
429#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32
430
16511789
VV
431#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min"
432#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32
433
846e980a
ST
434#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy"
435#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8
436
5bbd21df
DM
437#define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_NAME \
438 "reset_dev_on_drv_probe"
439#define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_TYPE DEVLINK_PARAM_TYPE_U8
440
6c7295e1
MG
441#define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_NAME "enable_roce"
442#define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_TYPE DEVLINK_PARAM_TYPE_BOOL
443
036467c3
MS
444#define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \
445{ \
446 .id = DEVLINK_PARAM_GENERIC_ID_##_id, \
447 .name = DEVLINK_PARAM_GENERIC_##_id##_NAME, \
448 .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE, \
449 .generic = true, \
450 .supported_cmodes = _cmodes, \
451 .get = _get, \
452 .set = _set, \
453 .validate = _validate, \
454}
455
456#define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate) \
457{ \
458 .id = _id, \
459 .name = _name, \
460 .type = _type, \
461 .supported_cmodes = _cmodes, \
462 .get = _get, \
463 .set = _set, \
464 .validate = _validate, \
465}
466
785bd550
JK
467/* Part number, identifier of board design */
468#define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID "board.id"
469/* Revision of board design */
470#define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV "board.rev"
14fd1901
JK
471/* Maker of the board */
472#define DEVLINK_INFO_VERSION_GENERIC_BOARD_MANUFACTURE "board.manufacture"
785bd550 473
7d5aa9a5
SN
474/* Part number, identifier of asic design */
475#define DEVLINK_INFO_VERSION_GENERIC_ASIC_ID "asic.id"
476/* Revision of asic design */
477#define DEVLINK_INFO_VERSION_GENERIC_ASIC_REV "asic.rev"
478
479/* Overall FW version */
480#define DEVLINK_INFO_VERSION_GENERIC_FW "fw"
785bd550
JK
481/* Control processor FW version */
482#define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT "fw.mgmt"
483/* Data path microcode controlling high-speed packet processing */
484#define DEVLINK_INFO_VERSION_GENERIC_FW_APP "fw.app"
485/* UNDI software version */
486#define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI "fw.undi"
487/* NCSI support/handler version */
488#define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI "fw.ncsi"
468672b2
JK
489/* FW parameter set id */
490#define DEVLINK_INFO_VERSION_GENERIC_FW_PSID "fw.psid"
41c0d917
VV
491/* RoCE FW version */
492#define DEVLINK_INFO_VERSION_GENERIC_FW_ROCE "fw.roce"
c90977a3
JK
493/* Firmware bundle identifier */
494#define DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID "fw.bundle_id"
785bd550 495
b16ebe92 496struct devlink_region;
f9cf2288 497struct devlink_info_req;
b16ebe92 498
d7e52722
AV
499typedef void devlink_snapshot_data_dest_t(const void *data);
500
1db64e87 501struct devlink_fmsg;
a0bdcc59
EBE
502struct devlink_health_reporter;
503
3167b27a
EBE
504enum devlink_health_reporter_state {
505 DEVLINK_HEALTH_REPORTER_STATE_HEALTHY,
506 DEVLINK_HEALTH_REPORTER_STATE_ERROR,
507};
508
a0bdcc59
EBE
509/**
510 * struct devlink_health_reporter_ops - Reporter operations
511 * @name: reporter name
512 * @recover: callback to recover from reported error
513 * if priv_ctx is NULL, run a full recover
514 * @dump: callback to dump an object
515 * if priv_ctx is NULL, run a full dump
516 * @diagnose: callback to diagnose the current status
517 */
518
519struct devlink_health_reporter_ops {
520 char *name;
521 int (*recover)(struct devlink_health_reporter *reporter,
e7a98105 522 void *priv_ctx, struct netlink_ext_ack *extack);
a0bdcc59 523 int (*dump)(struct devlink_health_reporter *reporter,
e7a98105
JP
524 struct devlink_fmsg *fmsg, void *priv_ctx,
525 struct netlink_ext_ack *extack);
a0bdcc59 526 int (*diagnose)(struct devlink_health_reporter *reporter,
e7a98105
JP
527 struct devlink_fmsg *fmsg,
528 struct netlink_ext_ack *extack);
a0bdcc59 529};
1db64e87 530
0f420b6c
IS
531/**
532 * struct devlink_trap_group - Immutable packet trap group attributes.
533 * @name: Trap group name.
534 * @id: Trap group identifier.
535 * @generic: Whether the trap group is generic or not.
536 *
537 * Describes immutable attributes of packet trap groups that drivers register
538 * with devlink.
539 */
540struct devlink_trap_group {
541 const char *name;
542 u16 id;
543 bool generic;
544};
545
546#define DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT BIT(0)
85b0589e 547#define DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE BIT(1)
0f420b6c
IS
548
549/**
550 * struct devlink_trap - Immutable packet trap attributes.
551 * @type: Trap type.
552 * @init_action: Initial trap action.
553 * @generic: Whether the trap is generic or not.
554 * @id: Trap identifier.
555 * @name: Trap name.
556 * @group: Immutable packet trap group attributes.
557 * @metadata_cap: Metadata types that can be provided by the trap.
558 *
559 * Describes immutable attributes of packet traps that drivers register with
560 * devlink.
561 */
562struct devlink_trap {
563 enum devlink_trap_type type;
564 enum devlink_trap_action init_action;
565 bool generic;
566 u16 id;
567 const char *name;
568 struct devlink_trap_group group;
569 u32 metadata_cap;
570};
571
f3047ca0 572/* All traps must be documented in
f4bdd710 573 * Documentation/networking/devlink/devlink-trap.rst
f3047ca0 574 */
0f420b6c 575enum devlink_trap_generic_id {
391203ab
IS
576 DEVLINK_TRAP_GENERIC_ID_SMAC_MC,
577 DEVLINK_TRAP_GENERIC_ID_VLAN_TAG_MISMATCH,
578 DEVLINK_TRAP_GENERIC_ID_INGRESS_VLAN_FILTER,
579 DEVLINK_TRAP_GENERIC_ID_INGRESS_STP_FILTER,
580 DEVLINK_TRAP_GENERIC_ID_EMPTY_TX_LIST,
581 DEVLINK_TRAP_GENERIC_ID_PORT_LOOPBACK_FILTER,
582 DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_ROUTE,
583 DEVLINK_TRAP_GENERIC_ID_TTL_ERROR,
584 DEVLINK_TRAP_GENERIC_ID_TAIL_DROP,
6896cc4d
AC
585 DEVLINK_TRAP_GENERIC_ID_NON_IP_PACKET,
586 DEVLINK_TRAP_GENERIC_ID_UC_DIP_MC_DMAC,
587 DEVLINK_TRAP_GENERIC_ID_DIP_LB,
588 DEVLINK_TRAP_GENERIC_ID_SIP_MC,
589 DEVLINK_TRAP_GENERIC_ID_SIP_LB,
590 DEVLINK_TRAP_GENERIC_ID_CORRUPTED_IP_HDR,
591 DEVLINK_TRAP_GENERIC_ID_IPV4_SIP_BC,
592 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_RESERVED_SCOPE,
593 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE,
3b063ae5
AC
594 DEVLINK_TRAP_GENERIC_ID_MTU_ERROR,
595 DEVLINK_TRAP_GENERIC_ID_UNRESOLVED_NEIGH,
596 DEVLINK_TRAP_GENERIC_ID_RPF,
597 DEVLINK_TRAP_GENERIC_ID_REJECT_ROUTE,
598 DEVLINK_TRAP_GENERIC_ID_IPV4_LPM_UNICAST_MISS,
599 DEVLINK_TRAP_GENERIC_ID_IPV6_LPM_UNICAST_MISS,
95f0ead8 600 DEVLINK_TRAP_GENERIC_ID_NON_ROUTABLE,
13c056ec 601 DEVLINK_TRAP_GENERIC_ID_DECAP_ERROR,
c3cae491 602 DEVLINK_TRAP_GENERIC_ID_OVERLAY_SMAC_MC,
ecd942a0
JP
603 DEVLINK_TRAP_GENERIC_ID_INGRESS_FLOW_ACTION_DROP,
604 DEVLINK_TRAP_GENERIC_ID_EGRESS_FLOW_ACTION_DROP,
391203ab 605
0f420b6c
IS
606 /* Add new generic trap IDs above */
607 __DEVLINK_TRAP_GENERIC_ID_MAX,
608 DEVLINK_TRAP_GENERIC_ID_MAX = __DEVLINK_TRAP_GENERIC_ID_MAX - 1,
609};
610
f3047ca0 611/* All trap groups must be documented in
f4bdd710 612 * Documentation/networking/devlink/devlink-trap.rst
f3047ca0 613 */
0f420b6c 614enum devlink_trap_group_generic_id {
391203ab
IS
615 DEVLINK_TRAP_GROUP_GENERIC_ID_L2_DROPS,
616 DEVLINK_TRAP_GROUP_GENERIC_ID_L3_DROPS,
617 DEVLINK_TRAP_GROUP_GENERIC_ID_BUFFER_DROPS,
13c056ec 618 DEVLINK_TRAP_GROUP_GENERIC_ID_TUNNEL_DROPS,
ecd942a0 619 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_DROPS,
391203ab 620
0f420b6c
IS
621 /* Add new generic trap group IDs above */
622 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX,
623 DEVLINK_TRAP_GROUP_GENERIC_ID_MAX =
624 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX - 1,
625};
626
391203ab
IS
627#define DEVLINK_TRAP_GENERIC_NAME_SMAC_MC \
628 "source_mac_is_multicast"
629#define DEVLINK_TRAP_GENERIC_NAME_VLAN_TAG_MISMATCH \
630 "vlan_tag_mismatch"
631#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_VLAN_FILTER \
632 "ingress_vlan_filter"
633#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_STP_FILTER \
634 "ingress_spanning_tree_filter"
635#define DEVLINK_TRAP_GENERIC_NAME_EMPTY_TX_LIST \
636 "port_list_is_empty"
637#define DEVLINK_TRAP_GENERIC_NAME_PORT_LOOPBACK_FILTER \
638 "port_loopback_filter"
639#define DEVLINK_TRAP_GENERIC_NAME_BLACKHOLE_ROUTE \
640 "blackhole_route"
641#define DEVLINK_TRAP_GENERIC_NAME_TTL_ERROR \
642 "ttl_value_is_too_small"
643#define DEVLINK_TRAP_GENERIC_NAME_TAIL_DROP \
644 "tail_drop"
6896cc4d
AC
645#define DEVLINK_TRAP_GENERIC_NAME_NON_IP_PACKET \
646 "non_ip"
647#define DEVLINK_TRAP_GENERIC_NAME_UC_DIP_MC_DMAC \
648 "uc_dip_over_mc_dmac"
649#define DEVLINK_TRAP_GENERIC_NAME_DIP_LB \
650 "dip_is_loopback_address"
651#define DEVLINK_TRAP_GENERIC_NAME_SIP_MC \
652 "sip_is_mc"
653#define DEVLINK_TRAP_GENERIC_NAME_SIP_LB \
654 "sip_is_loopback_address"
655#define DEVLINK_TRAP_GENERIC_NAME_CORRUPTED_IP_HDR \
656 "ip_header_corrupted"
657#define DEVLINK_TRAP_GENERIC_NAME_IPV4_SIP_BC \
658 "ipv4_sip_is_limited_bc"
659#define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_RESERVED_SCOPE \
660 "ipv6_mc_dip_reserved_scope"
661#define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE \
662 "ipv6_mc_dip_interface_local_scope"
3b063ae5
AC
663#define DEVLINK_TRAP_GENERIC_NAME_MTU_ERROR \
664 "mtu_value_is_too_small"
665#define DEVLINK_TRAP_GENERIC_NAME_UNRESOLVED_NEIGH \
666 "unresolved_neigh"
667#define DEVLINK_TRAP_GENERIC_NAME_RPF \
668 "mc_reverse_path_forwarding"
669#define DEVLINK_TRAP_GENERIC_NAME_REJECT_ROUTE \
670 "reject_route"
671#define DEVLINK_TRAP_GENERIC_NAME_IPV4_LPM_UNICAST_MISS \
672 "ipv4_lpm_miss"
673#define DEVLINK_TRAP_GENERIC_NAME_IPV6_LPM_UNICAST_MISS \
674 "ipv6_lpm_miss"
95f0ead8
AC
675#define DEVLINK_TRAP_GENERIC_NAME_NON_ROUTABLE \
676 "non_routable_packet"
13c056ec
AC
677#define DEVLINK_TRAP_GENERIC_NAME_DECAP_ERROR \
678 "decap_error"
c3cae491
AC
679#define DEVLINK_TRAP_GENERIC_NAME_OVERLAY_SMAC_MC \
680 "overlay_smac_is_mc"
ecd942a0
JP
681#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_FLOW_ACTION_DROP \
682 "ingress_flow_action_drop"
683#define DEVLINK_TRAP_GENERIC_NAME_EGRESS_FLOW_ACTION_DROP \
684 "egress_flow_action_drop"
391203ab
IS
685
686#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L2_DROPS \
687 "l2_drops"
688#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_DROPS \
689 "l3_drops"
690#define DEVLINK_TRAP_GROUP_GENERIC_NAME_BUFFER_DROPS \
691 "buffer_drops"
13c056ec
AC
692#define DEVLINK_TRAP_GROUP_GENERIC_NAME_TUNNEL_DROPS \
693 "tunnel_drops"
ecd942a0
JP
694#define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_DROPS \
695 "acl_drops"
391203ab 696
0f420b6c
IS
697#define DEVLINK_TRAP_GENERIC(_type, _init_action, _id, _group, _metadata_cap) \
698 { \
699 .type = DEVLINK_TRAP_TYPE_##_type, \
700 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
701 .generic = true, \
702 .id = DEVLINK_TRAP_GENERIC_ID_##_id, \
703 .name = DEVLINK_TRAP_GENERIC_NAME_##_id, \
704 .group = _group, \
705 .metadata_cap = _metadata_cap, \
706 }
707
708#define DEVLINK_TRAP_DRIVER(_type, _init_action, _id, _name, _group, \
709 _metadata_cap) \
710 { \
711 .type = DEVLINK_TRAP_TYPE_##_type, \
712 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
713 .generic = false, \
714 .id = _id, \
715 .name = _name, \
716 .group = _group, \
717 .metadata_cap = _metadata_cap, \
718 }
719
720#define DEVLINK_TRAP_GROUP_GENERIC(_id) \
721 { \
722 .name = DEVLINK_TRAP_GROUP_GENERIC_NAME_##_id, \
723 .id = DEVLINK_TRAP_GROUP_GENERIC_ID_##_id, \
724 .generic = true, \
725 }
726
bfcd3a46 727struct devlink_ops {
070c63f2 728 int (*reload_down)(struct devlink *devlink, bool netns_change,
97691069
JP
729 struct netlink_ext_ack *extack);
730 int (*reload_up)(struct devlink *devlink,
731 struct netlink_ext_ack *extack);
bfcd3a46
JP
732 int (*port_type_set)(struct devlink_port *devlink_port,
733 enum devlink_port_type port_type);
734 int (*port_split)(struct devlink *devlink, unsigned int port_index,
ac0fc8a1
DA
735 unsigned int count, struct netlink_ext_ack *extack);
736 int (*port_unsplit)(struct devlink *devlink, unsigned int port_index,
737 struct netlink_ext_ack *extack);
bf797471
JP
738 int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
739 u16 pool_index,
740 struct devlink_sb_pool_info *pool_info);
741 int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
742 u16 pool_index, u32 size,
f2ad1a52
IS
743 enum devlink_sb_threshold_type threshold_type,
744 struct netlink_ext_ack *extack);
bf797471
JP
745 int (*sb_port_pool_get)(struct devlink_port *devlink_port,
746 unsigned int sb_index, u16 pool_index,
747 u32 *p_threshold);
748 int (*sb_port_pool_set)(struct devlink_port *devlink_port,
749 unsigned int sb_index, u16 pool_index,
f2ad1a52 750 u32 threshold, struct netlink_ext_ack *extack);
bf797471
JP
751 int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
752 unsigned int sb_index,
753 u16 tc_index,
754 enum devlink_sb_pool_type pool_type,
755 u16 *p_pool_index, u32 *p_threshold);
756 int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
757 unsigned int sb_index,
758 u16 tc_index,
759 enum devlink_sb_pool_type pool_type,
f2ad1a52
IS
760 u16 pool_index, u32 threshold,
761 struct netlink_ext_ack *extack);
df38dafd
JP
762 int (*sb_occ_snapshot)(struct devlink *devlink,
763 unsigned int sb_index);
764 int (*sb_occ_max_clear)(struct devlink *devlink,
765 unsigned int sb_index);
766 int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
767 unsigned int sb_index, u16 pool_index,
768 u32 *p_cur, u32 *p_max);
769 int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
770 unsigned int sb_index,
771 u16 tc_index,
772 enum devlink_sb_pool_type pool_type,
773 u32 *p_cur, u32 *p_max);
08f4b591
OG
774
775 int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
db7ff19e
EB
776 int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
777 struct netlink_ext_ack *extack);
59bfde01 778 int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
db7ff19e
EB
779 int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
780 struct netlink_ext_ack *extack);
98fdbea5
LR
781 int (*eswitch_encap_mode_get)(struct devlink *devlink,
782 enum devlink_eswitch_encap_mode *p_encap_mode);
783 int (*eswitch_encap_mode_set)(struct devlink *devlink,
784 enum devlink_eswitch_encap_mode encap_mode,
db7ff19e 785 struct netlink_ext_ack *extack);
f9cf2288
JK
786 int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
787 struct netlink_ext_ack *extack);
76726ccb
JK
788 int (*flash_update)(struct devlink *devlink, const char *file_name,
789 const char *component,
790 struct netlink_ext_ack *extack);
0f420b6c
IS
791 /**
792 * @trap_init: Trap initialization function.
793 *
794 * Should be used by device drivers to initialize the trap in the
795 * underlying device. Drivers should also store the provided trap
796 * context, so that they could efficiently pass it to
797 * devlink_trap_report() when the trap is triggered.
798 */
799 int (*trap_init)(struct devlink *devlink,
800 const struct devlink_trap *trap, void *trap_ctx);
801 /**
802 * @trap_fini: Trap de-initialization function.
803 *
804 * Should be used by device drivers to de-initialize the trap in the
805 * underlying device.
806 */
807 void (*trap_fini)(struct devlink *devlink,
808 const struct devlink_trap *trap, void *trap_ctx);
809 /**
810 * @trap_action_set: Trap action set function.
811 */
812 int (*trap_action_set)(struct devlink *devlink,
813 const struct devlink_trap *trap,
814 enum devlink_trap_action action);
815 /**
816 * @trap_group_init: Trap group initialization function.
817 *
818 * Should be used by device drivers to initialize the trap group in the
819 * underlying device.
820 */
821 int (*trap_group_init)(struct devlink *devlink,
822 const struct devlink_trap_group *group);
bfcd3a46
JP
823};
824
825static inline void *devlink_priv(struct devlink *devlink)
826{
827 BUG_ON(!devlink);
828 return &devlink->priv;
829}
830
831static inline struct devlink *priv_to_devlink(void *priv)
832{
833 BUG_ON(!priv);
834 return container_of(priv, struct devlink, priv);
835}
836
5dc37bb9
JP
837static inline struct devlink_port *
838netdev_to_devlink_port(struct net_device *dev)
839{
840 if (dev->netdev_ops->ndo_get_devlink_port)
841 return dev->netdev_ops->ndo_get_devlink_port(dev);
842 return NULL;
843}
844
b473b0d2
JK
845static inline struct devlink *netdev_to_devlink(struct net_device *dev)
846{
5dc37bb9
JP
847 struct devlink_port *devlink_port = netdev_to_devlink_port(dev);
848
849 if (devlink_port)
850 return devlink_port->devlink;
b473b0d2
JK
851 return NULL;
852}
853
bfcd3a46
JP
854struct ib_device;
855
471f894f 856struct net *devlink_net(const struct devlink *devlink);
8273fd84 857void devlink_net_set(struct devlink *devlink, struct net *net);
bfcd3a46
JP
858struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
859int devlink_register(struct devlink *devlink, struct device *dev);
860void devlink_unregister(struct devlink *devlink);
a0c76345
JP
861void devlink_reload_enable(struct devlink *devlink);
862void devlink_reload_disable(struct devlink *devlink);
bfcd3a46
JP
863void devlink_free(struct devlink *devlink);
864int devlink_port_register(struct devlink *devlink,
865 struct devlink_port *devlink_port,
866 unsigned int port_index);
867void devlink_port_unregister(struct devlink_port *devlink_port);
868void devlink_port_type_eth_set(struct devlink_port *devlink_port,
869 struct net_device *netdev);
870void devlink_port_type_ib_set(struct devlink_port *devlink_port,
871 struct ib_device *ibdev);
872void devlink_port_type_clear(struct devlink_port *devlink_port);
b9ffcbaf 873void devlink_port_attrs_set(struct devlink_port *devlink_port,
5ec1380a 874 enum devlink_port_flavour flavour,
b9ffcbaf 875 u32 port_number, bool split,
bec5267c
JP
876 u32 split_subport_number,
877 const unsigned char *switch_id,
878 unsigned char switch_id_len);
98fd2d65
PP
879void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
880 const unsigned char *switch_id,
881 unsigned char switch_id_len, u16 pf);
e41b6bf3
PP
882void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
883 const unsigned char *switch_id,
884 unsigned char switch_id_len,
885 u16 pf, u16 vf);
bf797471
JP
886int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
887 u32 size, u16 ingress_pools_count,
888 u16 egress_pools_count, u16 ingress_tc_count,
889 u16 egress_tc_count);
890void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
1555d204
AS
891int devlink_dpipe_table_register(struct devlink *devlink,
892 const char *table_name,
893 struct devlink_dpipe_table_ops *table_ops,
ffd3cdcc 894 void *priv, bool counter_control_extern);
1555d204
AS
895void devlink_dpipe_table_unregister(struct devlink *devlink,
896 const char *table_name);
897int devlink_dpipe_headers_register(struct devlink *devlink,
898 struct devlink_dpipe_headers *dpipe_headers);
899void devlink_dpipe_headers_unregister(struct devlink *devlink);
900bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
901 const char *table_name);
902int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
903int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
904 struct devlink_dpipe_entry *entry);
905int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
35807324 906void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
1555d204
AS
907int devlink_dpipe_action_put(struct sk_buff *skb,
908 struct devlink_dpipe_action *action);
909int devlink_dpipe_match_put(struct sk_buff *skb,
910 struct devlink_dpipe_match *match);
11770091 911extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
3fb886ec 912extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
1797f5b3 913extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
bfcd3a46 914
d9f9b9a4
AS
915int devlink_resource_register(struct devlink *devlink,
916 const char *resource_name,
d9f9b9a4
AS
917 u64 resource_size,
918 u64 resource_id,
919 u64 parent_resource_id,
fc56be47 920 const struct devlink_resource_size_params *size_params);
d9f9b9a4
AS
921void devlink_resources_unregister(struct devlink *devlink,
922 struct devlink_resource *resource);
923int devlink_resource_size_get(struct devlink *devlink,
924 u64 resource_id,
925 u64 *p_resource_size);
56dc7cd0
AS
926int devlink_dpipe_table_resource_set(struct devlink *devlink,
927 const char *table_name, u64 resource_id,
928 u64 resource_units);
fc56be47
JP
929void devlink_resource_occ_get_register(struct devlink *devlink,
930 u64 resource_id,
931 devlink_resource_occ_get_t *occ_get,
932 void *occ_get_priv);
933void devlink_resource_occ_get_unregister(struct devlink *devlink,
934 u64 resource_id);
eabaef18
MS
935int devlink_params_register(struct devlink *devlink,
936 const struct devlink_param *params,
937 size_t params_count);
938void devlink_params_unregister(struct devlink *devlink,
939 const struct devlink_param *params,
940 size_t params_count);
7c62cfb8
JP
941void devlink_params_publish(struct devlink *devlink);
942void devlink_params_unpublish(struct devlink *devlink);
39e6160e
VV
943int devlink_port_params_register(struct devlink_port *devlink_port,
944 const struct devlink_param *params,
945 size_t params_count);
946void devlink_port_params_unregister(struct devlink_port *devlink_port,
947 const struct devlink_param *params,
948 size_t params_count);
ec01aeb1
MS
949int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
950 union devlink_param_value *init_val);
951int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
952 union devlink_param_value init_val);
ffd19b9a
VV
953int
954devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
955 u32 param_id,
956 union devlink_param_value *init_val);
5473a7bd
VV
957int devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
958 u32 param_id,
959 union devlink_param_value init_val);
ea601e17 960void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
c1e5786d
VV
961void devlink_port_param_value_changed(struct devlink_port *devlink_port,
962 u32 param_id);
bde74ad1
MS
963void devlink_param_value_str_fill(union devlink_param_value *dst_val,
964 const char *src);
b16ebe92
AV
965struct devlink_region *devlink_region_create(struct devlink *devlink,
966 const char *region_name,
967 u32 region_max_snapshots,
968 u64 region_size);
969void devlink_region_destroy(struct devlink_region *region);
b0efcae5 970u32 devlink_region_snapshot_id_get(struct devlink *devlink);
3a5e5234 971int devlink_region_snapshot_create(struct devlink_region *region,
d7e52722
AV
972 u8 *data, u32 snapshot_id,
973 devlink_snapshot_data_dest_t *data_destructor);
f9cf2288
JK
974int devlink_info_serial_number_put(struct devlink_info_req *req,
975 const char *sn);
976int devlink_info_driver_name_put(struct devlink_info_req *req,
977 const char *name);
fc6fae7d
JK
978int devlink_info_version_fixed_put(struct devlink_info_req *req,
979 const char *version_name,
980 const char *version_value);
981int devlink_info_version_stored_put(struct devlink_info_req *req,
982 const char *version_name,
983 const char *version_value);
984int devlink_info_version_running_put(struct devlink_info_req *req,
985 const char *version_name,
986 const char *version_value);
d9f9b9a4 987
1db64e87
EBE
988int devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg);
989int devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg);
990
991int devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name);
992int devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg);
993
994int devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg,
995 const char *name);
996int devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg);
573ed90a
AL
997int devlink_fmsg_binary_pair_nest_start(struct devlink_fmsg *fmsg,
998 const char *name);
999int devlink_fmsg_binary_pair_nest_end(struct devlink_fmsg *fmsg);
1db64e87
EBE
1000
1001int devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value);
1002int devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value);
1003int devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value);
1004int devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value);
1005int devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value);
573ed90a
AL
1006int devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value,
1007 u16 value_len);
1db64e87
EBE
1008
1009int devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name,
1010 bool value);
1011int devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name,
1012 u8 value);
1013int devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name,
1014 u32 value);
1015int devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name,
1016 u64 value);
1017int devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,
1018 const char *value);
1019int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
e2cde864 1020 const void *value, u32 value_len);
1db64e87 1021
a0bdcc59
EBE
1022struct devlink_health_reporter *
1023devlink_health_reporter_create(struct devlink *devlink,
1024 const struct devlink_health_reporter_ops *ops,
1025 u64 graceful_period, bool auto_recover,
1026 void *priv);
1027void
1028devlink_health_reporter_destroy(struct devlink_health_reporter *reporter);
1029
1030void *
1031devlink_health_reporter_priv(struct devlink_health_reporter *reporter);
c8e1da0b
EBE
1032int devlink_health_report(struct devlink_health_reporter *reporter,
1033 const char *msg, void *priv_ctx);
3167b27a
EBE
1034void
1035devlink_health_reporter_state_update(struct devlink_health_reporter *reporter,
1036 enum devlink_health_reporter_state state);
6181e5cb
VG
1037void
1038devlink_health_reporter_recovery_done(struct devlink_health_reporter *reporter);
a0bdcc59 1039
2670ac26
JP
1040bool devlink_is_reload_failed(const struct devlink *devlink);
1041
191ed202
JP
1042void devlink_flash_update_begin_notify(struct devlink *devlink);
1043void devlink_flash_update_end_notify(struct devlink *devlink);
1044void devlink_flash_update_status_notify(struct devlink *devlink,
1045 const char *status_msg,
1046 const char *component,
1047 unsigned long done,
1048 unsigned long total);
1049
0f420b6c
IS
1050int devlink_traps_register(struct devlink *devlink,
1051 const struct devlink_trap *traps,
1052 size_t traps_count, void *priv);
1053void devlink_traps_unregister(struct devlink *devlink,
1054 const struct devlink_trap *traps,
1055 size_t traps_count);
5a2e106c
JP
1056void devlink_trap_report(struct devlink *devlink, struct sk_buff *skb,
1057 void *trap_ctx, struct devlink_port *in_devlink_port,
1058 const struct flow_action_cookie *fa_cookie);
0f420b6c 1059void *devlink_trap_ctx_priv(void *trap_ctx);
95ad9555
IS
1060int devlink_trap_groups_register(struct devlink *devlink,
1061 const struct devlink_trap_group *groups,
1062 size_t groups_count);
1063void devlink_trap_groups_unregister(struct devlink *devlink,
1064 const struct devlink_trap_group *groups,
1065 size_t groups_count);
0f420b6c 1066
f6b19b35
JP
1067#if IS_ENABLED(CONFIG_NET_DEVLINK)
1068
f4b6bcc7
JK
1069void devlink_compat_running_version(struct net_device *dev,
1070 char *buf, size_t len);
1071int devlink_compat_flash_update(struct net_device *dev, const char *file_name);
af3836df
JP
1072int devlink_compat_phys_port_name_get(struct net_device *dev,
1073 char *name, size_t len);
7e1146e8
JP
1074int devlink_compat_switch_id_get(struct net_device *dev,
1075 struct netdev_phys_item_id *ppid);
f4b6bcc7 1076
bfcd3a46
JP
1077#else
1078
ddb6e99e
JK
1079static inline void
1080devlink_compat_running_version(struct net_device *dev, char *buf, size_t len)
1081{
1082}
4eceba17
JK
1083
1084static inline int
1085devlink_compat_flash_update(struct net_device *dev, const char *file_name)
1086{
1087 return -EOPNOTSUPP;
1088}
f6b19b35 1089
af3836df
JP
1090static inline int
1091devlink_compat_phys_port_name_get(struct net_device *dev,
1092 char *name, size_t len)
1093{
1094 return -EOPNOTSUPP;
1095}
1096
7e1146e8
JP
1097static inline int
1098devlink_compat_switch_id_get(struct net_device *dev,
1099 struct netdev_phys_item_id *ppid)
1100{
1101 return -EOPNOTSUPP;
1102}
1103
ddb6e99e
JK
1104#endif
1105
bfcd3a46 1106#endif /* _NET_DEVLINK_H_ */