devlink: report error once U32_MAX snapshot ids have been used
[linux-block.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
e8937681
JK
499/**
500 * struct devlink_region_ops - Region operations
501 * @name: region name
a0a09f6b 502 * @destructor: callback used to free snapshot memory when deleting
e8937681
JK
503 */
504struct devlink_region_ops {
505 const char *name;
a0a09f6b 506 void (*destructor)(const void *data);
e8937681
JK
507};
508
1db64e87 509struct devlink_fmsg;
a0bdcc59
EBE
510struct devlink_health_reporter;
511
3167b27a
EBE
512enum devlink_health_reporter_state {
513 DEVLINK_HEALTH_REPORTER_STATE_HEALTHY,
514 DEVLINK_HEALTH_REPORTER_STATE_ERROR,
515};
516
a0bdcc59
EBE
517/**
518 * struct devlink_health_reporter_ops - Reporter operations
519 * @name: reporter name
520 * @recover: callback to recover from reported error
521 * if priv_ctx is NULL, run a full recover
522 * @dump: callback to dump an object
523 * if priv_ctx is NULL, run a full dump
524 * @diagnose: callback to diagnose the current status
525 */
526
527struct devlink_health_reporter_ops {
528 char *name;
529 int (*recover)(struct devlink_health_reporter *reporter,
e7a98105 530 void *priv_ctx, struct netlink_ext_ack *extack);
a0bdcc59 531 int (*dump)(struct devlink_health_reporter *reporter,
e7a98105
JP
532 struct devlink_fmsg *fmsg, void *priv_ctx,
533 struct netlink_ext_ack *extack);
a0bdcc59 534 int (*diagnose)(struct devlink_health_reporter *reporter,
e7a98105
JP
535 struct devlink_fmsg *fmsg,
536 struct netlink_ext_ack *extack);
a0bdcc59 537};
1db64e87 538
0f420b6c
IS
539/**
540 * struct devlink_trap_group - Immutable packet trap group attributes.
541 * @name: Trap group name.
542 * @id: Trap group identifier.
543 * @generic: Whether the trap group is generic or not.
544 *
545 * Describes immutable attributes of packet trap groups that drivers register
546 * with devlink.
547 */
548struct devlink_trap_group {
549 const char *name;
550 u16 id;
551 bool generic;
552};
553
554#define DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT BIT(0)
85b0589e 555#define DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE BIT(1)
0f420b6c
IS
556
557/**
558 * struct devlink_trap - Immutable packet trap attributes.
559 * @type: Trap type.
560 * @init_action: Initial trap action.
561 * @generic: Whether the trap is generic or not.
562 * @id: Trap identifier.
563 * @name: Trap name.
107f1678 564 * @init_group_id: Initial group identifier.
0f420b6c
IS
565 * @metadata_cap: Metadata types that can be provided by the trap.
566 *
567 * Describes immutable attributes of packet traps that drivers register with
568 * devlink.
569 */
570struct devlink_trap {
571 enum devlink_trap_type type;
572 enum devlink_trap_action init_action;
573 bool generic;
574 u16 id;
575 const char *name;
107f1678 576 u16 init_group_id;
0f420b6c
IS
577 u32 metadata_cap;
578};
579
f3047ca0 580/* All traps must be documented in
f4bdd710 581 * Documentation/networking/devlink/devlink-trap.rst
f3047ca0 582 */
0f420b6c 583enum devlink_trap_generic_id {
391203ab
IS
584 DEVLINK_TRAP_GENERIC_ID_SMAC_MC,
585 DEVLINK_TRAP_GENERIC_ID_VLAN_TAG_MISMATCH,
586 DEVLINK_TRAP_GENERIC_ID_INGRESS_VLAN_FILTER,
587 DEVLINK_TRAP_GENERIC_ID_INGRESS_STP_FILTER,
588 DEVLINK_TRAP_GENERIC_ID_EMPTY_TX_LIST,
589 DEVLINK_TRAP_GENERIC_ID_PORT_LOOPBACK_FILTER,
590 DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_ROUTE,
591 DEVLINK_TRAP_GENERIC_ID_TTL_ERROR,
592 DEVLINK_TRAP_GENERIC_ID_TAIL_DROP,
6896cc4d
AC
593 DEVLINK_TRAP_GENERIC_ID_NON_IP_PACKET,
594 DEVLINK_TRAP_GENERIC_ID_UC_DIP_MC_DMAC,
595 DEVLINK_TRAP_GENERIC_ID_DIP_LB,
596 DEVLINK_TRAP_GENERIC_ID_SIP_MC,
597 DEVLINK_TRAP_GENERIC_ID_SIP_LB,
598 DEVLINK_TRAP_GENERIC_ID_CORRUPTED_IP_HDR,
599 DEVLINK_TRAP_GENERIC_ID_IPV4_SIP_BC,
600 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_RESERVED_SCOPE,
601 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE,
3b063ae5
AC
602 DEVLINK_TRAP_GENERIC_ID_MTU_ERROR,
603 DEVLINK_TRAP_GENERIC_ID_UNRESOLVED_NEIGH,
604 DEVLINK_TRAP_GENERIC_ID_RPF,
605 DEVLINK_TRAP_GENERIC_ID_REJECT_ROUTE,
606 DEVLINK_TRAP_GENERIC_ID_IPV4_LPM_UNICAST_MISS,
607 DEVLINK_TRAP_GENERIC_ID_IPV6_LPM_UNICAST_MISS,
95f0ead8 608 DEVLINK_TRAP_GENERIC_ID_NON_ROUTABLE,
13c056ec 609 DEVLINK_TRAP_GENERIC_ID_DECAP_ERROR,
c3cae491 610 DEVLINK_TRAP_GENERIC_ID_OVERLAY_SMAC_MC,
ecd942a0
JP
611 DEVLINK_TRAP_GENERIC_ID_INGRESS_FLOW_ACTION_DROP,
612 DEVLINK_TRAP_GENERIC_ID_EGRESS_FLOW_ACTION_DROP,
391203ab 613
0f420b6c
IS
614 /* Add new generic trap IDs above */
615 __DEVLINK_TRAP_GENERIC_ID_MAX,
616 DEVLINK_TRAP_GENERIC_ID_MAX = __DEVLINK_TRAP_GENERIC_ID_MAX - 1,
617};
618
f3047ca0 619/* All trap groups must be documented in
f4bdd710 620 * Documentation/networking/devlink/devlink-trap.rst
f3047ca0 621 */
0f420b6c 622enum devlink_trap_group_generic_id {
391203ab
IS
623 DEVLINK_TRAP_GROUP_GENERIC_ID_L2_DROPS,
624 DEVLINK_TRAP_GROUP_GENERIC_ID_L3_DROPS,
625 DEVLINK_TRAP_GROUP_GENERIC_ID_BUFFER_DROPS,
13c056ec 626 DEVLINK_TRAP_GROUP_GENERIC_ID_TUNNEL_DROPS,
ecd942a0 627 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_DROPS,
391203ab 628
0f420b6c
IS
629 /* Add new generic trap group IDs above */
630 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX,
631 DEVLINK_TRAP_GROUP_GENERIC_ID_MAX =
632 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX - 1,
633};
634
391203ab
IS
635#define DEVLINK_TRAP_GENERIC_NAME_SMAC_MC \
636 "source_mac_is_multicast"
637#define DEVLINK_TRAP_GENERIC_NAME_VLAN_TAG_MISMATCH \
638 "vlan_tag_mismatch"
639#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_VLAN_FILTER \
640 "ingress_vlan_filter"
641#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_STP_FILTER \
642 "ingress_spanning_tree_filter"
643#define DEVLINK_TRAP_GENERIC_NAME_EMPTY_TX_LIST \
644 "port_list_is_empty"
645#define DEVLINK_TRAP_GENERIC_NAME_PORT_LOOPBACK_FILTER \
646 "port_loopback_filter"
647#define DEVLINK_TRAP_GENERIC_NAME_BLACKHOLE_ROUTE \
648 "blackhole_route"
649#define DEVLINK_TRAP_GENERIC_NAME_TTL_ERROR \
650 "ttl_value_is_too_small"
651#define DEVLINK_TRAP_GENERIC_NAME_TAIL_DROP \
652 "tail_drop"
6896cc4d
AC
653#define DEVLINK_TRAP_GENERIC_NAME_NON_IP_PACKET \
654 "non_ip"
655#define DEVLINK_TRAP_GENERIC_NAME_UC_DIP_MC_DMAC \
656 "uc_dip_over_mc_dmac"
657#define DEVLINK_TRAP_GENERIC_NAME_DIP_LB \
658 "dip_is_loopback_address"
659#define DEVLINK_TRAP_GENERIC_NAME_SIP_MC \
660 "sip_is_mc"
661#define DEVLINK_TRAP_GENERIC_NAME_SIP_LB \
662 "sip_is_loopback_address"
663#define DEVLINK_TRAP_GENERIC_NAME_CORRUPTED_IP_HDR \
664 "ip_header_corrupted"
665#define DEVLINK_TRAP_GENERIC_NAME_IPV4_SIP_BC \
666 "ipv4_sip_is_limited_bc"
667#define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_RESERVED_SCOPE \
668 "ipv6_mc_dip_reserved_scope"
669#define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE \
670 "ipv6_mc_dip_interface_local_scope"
3b063ae5
AC
671#define DEVLINK_TRAP_GENERIC_NAME_MTU_ERROR \
672 "mtu_value_is_too_small"
673#define DEVLINK_TRAP_GENERIC_NAME_UNRESOLVED_NEIGH \
674 "unresolved_neigh"
675#define DEVLINK_TRAP_GENERIC_NAME_RPF \
676 "mc_reverse_path_forwarding"
677#define DEVLINK_TRAP_GENERIC_NAME_REJECT_ROUTE \
678 "reject_route"
679#define DEVLINK_TRAP_GENERIC_NAME_IPV4_LPM_UNICAST_MISS \
680 "ipv4_lpm_miss"
681#define DEVLINK_TRAP_GENERIC_NAME_IPV6_LPM_UNICAST_MISS \
682 "ipv6_lpm_miss"
95f0ead8
AC
683#define DEVLINK_TRAP_GENERIC_NAME_NON_ROUTABLE \
684 "non_routable_packet"
13c056ec
AC
685#define DEVLINK_TRAP_GENERIC_NAME_DECAP_ERROR \
686 "decap_error"
c3cae491
AC
687#define DEVLINK_TRAP_GENERIC_NAME_OVERLAY_SMAC_MC \
688 "overlay_smac_is_mc"
ecd942a0
JP
689#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_FLOW_ACTION_DROP \
690 "ingress_flow_action_drop"
691#define DEVLINK_TRAP_GENERIC_NAME_EGRESS_FLOW_ACTION_DROP \
692 "egress_flow_action_drop"
391203ab
IS
693
694#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L2_DROPS \
695 "l2_drops"
696#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_DROPS \
697 "l3_drops"
698#define DEVLINK_TRAP_GROUP_GENERIC_NAME_BUFFER_DROPS \
699 "buffer_drops"
13c056ec
AC
700#define DEVLINK_TRAP_GROUP_GENERIC_NAME_TUNNEL_DROPS \
701 "tunnel_drops"
ecd942a0
JP
702#define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_DROPS \
703 "acl_drops"
391203ab 704
107f1678
IS
705#define DEVLINK_TRAP_GENERIC(_type, _init_action, _id, _group_id, \
706 _metadata_cap) \
0f420b6c
IS
707 { \
708 .type = DEVLINK_TRAP_TYPE_##_type, \
709 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
710 .generic = true, \
711 .id = DEVLINK_TRAP_GENERIC_ID_##_id, \
712 .name = DEVLINK_TRAP_GENERIC_NAME_##_id, \
107f1678 713 .init_group_id = _group_id, \
0f420b6c
IS
714 .metadata_cap = _metadata_cap, \
715 }
716
107f1678 717#define DEVLINK_TRAP_DRIVER(_type, _init_action, _id, _name, _group_id, \
0f420b6c
IS
718 _metadata_cap) \
719 { \
720 .type = DEVLINK_TRAP_TYPE_##_type, \
721 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
722 .generic = false, \
723 .id = _id, \
724 .name = _name, \
107f1678 725 .init_group_id = _group_id, \
0f420b6c
IS
726 .metadata_cap = _metadata_cap, \
727 }
728
729#define DEVLINK_TRAP_GROUP_GENERIC(_id) \
730 { \
731 .name = DEVLINK_TRAP_GROUP_GENERIC_NAME_##_id, \
732 .id = DEVLINK_TRAP_GROUP_GENERIC_ID_##_id, \
733 .generic = true, \
734 }
735
bfcd3a46 736struct devlink_ops {
070c63f2 737 int (*reload_down)(struct devlink *devlink, bool netns_change,
97691069
JP
738 struct netlink_ext_ack *extack);
739 int (*reload_up)(struct devlink *devlink,
740 struct netlink_ext_ack *extack);
bfcd3a46
JP
741 int (*port_type_set)(struct devlink_port *devlink_port,
742 enum devlink_port_type port_type);
743 int (*port_split)(struct devlink *devlink, unsigned int port_index,
ac0fc8a1
DA
744 unsigned int count, struct netlink_ext_ack *extack);
745 int (*port_unsplit)(struct devlink *devlink, unsigned int port_index,
746 struct netlink_ext_ack *extack);
bf797471
JP
747 int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
748 u16 pool_index,
749 struct devlink_sb_pool_info *pool_info);
750 int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
751 u16 pool_index, u32 size,
f2ad1a52
IS
752 enum devlink_sb_threshold_type threshold_type,
753 struct netlink_ext_ack *extack);
bf797471
JP
754 int (*sb_port_pool_get)(struct devlink_port *devlink_port,
755 unsigned int sb_index, u16 pool_index,
756 u32 *p_threshold);
757 int (*sb_port_pool_set)(struct devlink_port *devlink_port,
758 unsigned int sb_index, u16 pool_index,
f2ad1a52 759 u32 threshold, struct netlink_ext_ack *extack);
bf797471
JP
760 int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
761 unsigned int sb_index,
762 u16 tc_index,
763 enum devlink_sb_pool_type pool_type,
764 u16 *p_pool_index, u32 *p_threshold);
765 int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
766 unsigned int sb_index,
767 u16 tc_index,
768 enum devlink_sb_pool_type pool_type,
f2ad1a52
IS
769 u16 pool_index, u32 threshold,
770 struct netlink_ext_ack *extack);
df38dafd
JP
771 int (*sb_occ_snapshot)(struct devlink *devlink,
772 unsigned int sb_index);
773 int (*sb_occ_max_clear)(struct devlink *devlink,
774 unsigned int sb_index);
775 int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
776 unsigned int sb_index, u16 pool_index,
777 u32 *p_cur, u32 *p_max);
778 int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
779 unsigned int sb_index,
780 u16 tc_index,
781 enum devlink_sb_pool_type pool_type,
782 u32 *p_cur, u32 *p_max);
08f4b591
OG
783
784 int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
db7ff19e
EB
785 int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
786 struct netlink_ext_ack *extack);
59bfde01 787 int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
db7ff19e
EB
788 int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
789 struct netlink_ext_ack *extack);
98fdbea5
LR
790 int (*eswitch_encap_mode_get)(struct devlink *devlink,
791 enum devlink_eswitch_encap_mode *p_encap_mode);
792 int (*eswitch_encap_mode_set)(struct devlink *devlink,
793 enum devlink_eswitch_encap_mode encap_mode,
db7ff19e 794 struct netlink_ext_ack *extack);
f9cf2288
JK
795 int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
796 struct netlink_ext_ack *extack);
76726ccb
JK
797 int (*flash_update)(struct devlink *devlink, const char *file_name,
798 const char *component,
799 struct netlink_ext_ack *extack);
0f420b6c
IS
800 /**
801 * @trap_init: Trap initialization function.
802 *
803 * Should be used by device drivers to initialize the trap in the
804 * underlying device. Drivers should also store the provided trap
805 * context, so that they could efficiently pass it to
806 * devlink_trap_report() when the trap is triggered.
807 */
808 int (*trap_init)(struct devlink *devlink,
809 const struct devlink_trap *trap, void *trap_ctx);
810 /**
811 * @trap_fini: Trap de-initialization function.
812 *
813 * Should be used by device drivers to de-initialize the trap in the
814 * underlying device.
815 */
816 void (*trap_fini)(struct devlink *devlink,
817 const struct devlink_trap *trap, void *trap_ctx);
818 /**
819 * @trap_action_set: Trap action set function.
820 */
821 int (*trap_action_set)(struct devlink *devlink,
822 const struct devlink_trap *trap,
823 enum devlink_trap_action action);
824 /**
825 * @trap_group_init: Trap group initialization function.
826 *
827 * Should be used by device drivers to initialize the trap group in the
828 * underlying device.
829 */
830 int (*trap_group_init)(struct devlink *devlink,
831 const struct devlink_trap_group *group);
bfcd3a46
JP
832};
833
834static inline void *devlink_priv(struct devlink *devlink)
835{
836 BUG_ON(!devlink);
837 return &devlink->priv;
838}
839
840static inline struct devlink *priv_to_devlink(void *priv)
841{
842 BUG_ON(!priv);
843 return container_of(priv, struct devlink, priv);
844}
845
5dc37bb9
JP
846static inline struct devlink_port *
847netdev_to_devlink_port(struct net_device *dev)
848{
849 if (dev->netdev_ops->ndo_get_devlink_port)
850 return dev->netdev_ops->ndo_get_devlink_port(dev);
851 return NULL;
852}
853
b473b0d2
JK
854static inline struct devlink *netdev_to_devlink(struct net_device *dev)
855{
5dc37bb9
JP
856 struct devlink_port *devlink_port = netdev_to_devlink_port(dev);
857
858 if (devlink_port)
859 return devlink_port->devlink;
b473b0d2
JK
860 return NULL;
861}
862
bfcd3a46
JP
863struct ib_device;
864
471f894f 865struct net *devlink_net(const struct devlink *devlink);
8273fd84 866void devlink_net_set(struct devlink *devlink, struct net *net);
bfcd3a46
JP
867struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
868int devlink_register(struct devlink *devlink, struct device *dev);
869void devlink_unregister(struct devlink *devlink);
a0c76345
JP
870void devlink_reload_enable(struct devlink *devlink);
871void devlink_reload_disable(struct devlink *devlink);
bfcd3a46
JP
872void devlink_free(struct devlink *devlink);
873int devlink_port_register(struct devlink *devlink,
874 struct devlink_port *devlink_port,
875 unsigned int port_index);
876void devlink_port_unregister(struct devlink_port *devlink_port);
877void devlink_port_type_eth_set(struct devlink_port *devlink_port,
878 struct net_device *netdev);
879void devlink_port_type_ib_set(struct devlink_port *devlink_port,
880 struct ib_device *ibdev);
881void devlink_port_type_clear(struct devlink_port *devlink_port);
b9ffcbaf 882void devlink_port_attrs_set(struct devlink_port *devlink_port,
5ec1380a 883 enum devlink_port_flavour flavour,
b9ffcbaf 884 u32 port_number, bool split,
bec5267c
JP
885 u32 split_subport_number,
886 const unsigned char *switch_id,
887 unsigned char switch_id_len);
98fd2d65
PP
888void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
889 const unsigned char *switch_id,
890 unsigned char switch_id_len, u16 pf);
e41b6bf3
PP
891void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
892 const unsigned char *switch_id,
893 unsigned char switch_id_len,
894 u16 pf, u16 vf);
bf797471
JP
895int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
896 u32 size, u16 ingress_pools_count,
897 u16 egress_pools_count, u16 ingress_tc_count,
898 u16 egress_tc_count);
899void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
1555d204
AS
900int devlink_dpipe_table_register(struct devlink *devlink,
901 const char *table_name,
902 struct devlink_dpipe_table_ops *table_ops,
ffd3cdcc 903 void *priv, bool counter_control_extern);
1555d204
AS
904void devlink_dpipe_table_unregister(struct devlink *devlink,
905 const char *table_name);
906int devlink_dpipe_headers_register(struct devlink *devlink,
907 struct devlink_dpipe_headers *dpipe_headers);
908void devlink_dpipe_headers_unregister(struct devlink *devlink);
909bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
910 const char *table_name);
911int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
912int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
913 struct devlink_dpipe_entry *entry);
914int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
35807324 915void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
1555d204
AS
916int devlink_dpipe_action_put(struct sk_buff *skb,
917 struct devlink_dpipe_action *action);
918int devlink_dpipe_match_put(struct sk_buff *skb,
919 struct devlink_dpipe_match *match);
11770091 920extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
3fb886ec 921extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
1797f5b3 922extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
bfcd3a46 923
d9f9b9a4
AS
924int devlink_resource_register(struct devlink *devlink,
925 const char *resource_name,
d9f9b9a4
AS
926 u64 resource_size,
927 u64 resource_id,
928 u64 parent_resource_id,
fc56be47 929 const struct devlink_resource_size_params *size_params);
d9f9b9a4
AS
930void devlink_resources_unregister(struct devlink *devlink,
931 struct devlink_resource *resource);
932int devlink_resource_size_get(struct devlink *devlink,
933 u64 resource_id,
934 u64 *p_resource_size);
56dc7cd0
AS
935int devlink_dpipe_table_resource_set(struct devlink *devlink,
936 const char *table_name, u64 resource_id,
937 u64 resource_units);
fc56be47
JP
938void devlink_resource_occ_get_register(struct devlink *devlink,
939 u64 resource_id,
940 devlink_resource_occ_get_t *occ_get,
941 void *occ_get_priv);
942void devlink_resource_occ_get_unregister(struct devlink *devlink,
943 u64 resource_id);
eabaef18
MS
944int devlink_params_register(struct devlink *devlink,
945 const struct devlink_param *params,
946 size_t params_count);
947void devlink_params_unregister(struct devlink *devlink,
948 const struct devlink_param *params,
949 size_t params_count);
7c62cfb8
JP
950void devlink_params_publish(struct devlink *devlink);
951void devlink_params_unpublish(struct devlink *devlink);
39e6160e
VV
952int devlink_port_params_register(struct devlink_port *devlink_port,
953 const struct devlink_param *params,
954 size_t params_count);
955void devlink_port_params_unregister(struct devlink_port *devlink_port,
956 const struct devlink_param *params,
957 size_t params_count);
ec01aeb1
MS
958int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
959 union devlink_param_value *init_val);
960int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
961 union devlink_param_value init_val);
ffd19b9a
VV
962int
963devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
964 u32 param_id,
965 union devlink_param_value *init_val);
5473a7bd
VV
966int devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
967 u32 param_id,
968 union devlink_param_value init_val);
ea601e17 969void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
c1e5786d
VV
970void devlink_port_param_value_changed(struct devlink_port *devlink_port,
971 u32 param_id);
bde74ad1
MS
972void devlink_param_value_str_fill(union devlink_param_value *dst_val,
973 const char *src);
e8937681
JK
974struct devlink_region *
975devlink_region_create(struct devlink *devlink,
976 const struct devlink_region_ops *ops,
977 u32 region_max_snapshots, u64 region_size);
b16ebe92 978void devlink_region_destroy(struct devlink_region *region);
7ef19d3b 979int devlink_region_snapshot_id_get(struct devlink *devlink, u32 *id);
3a5e5234 980int devlink_region_snapshot_create(struct devlink_region *region,
a0a09f6b 981 u8 *data, u32 snapshot_id);
f9cf2288
JK
982int devlink_info_serial_number_put(struct devlink_info_req *req,
983 const char *sn);
984int devlink_info_driver_name_put(struct devlink_info_req *req,
985 const char *name);
fc6fae7d
JK
986int devlink_info_version_fixed_put(struct devlink_info_req *req,
987 const char *version_name,
988 const char *version_value);
989int devlink_info_version_stored_put(struct devlink_info_req *req,
990 const char *version_name,
991 const char *version_value);
992int devlink_info_version_running_put(struct devlink_info_req *req,
993 const char *version_name,
994 const char *version_value);
d9f9b9a4 995
1db64e87
EBE
996int devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg);
997int devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg);
998
999int devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name);
1000int devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg);
1001
1002int devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg,
1003 const char *name);
1004int devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg);
573ed90a
AL
1005int devlink_fmsg_binary_pair_nest_start(struct devlink_fmsg *fmsg,
1006 const char *name);
1007int devlink_fmsg_binary_pair_nest_end(struct devlink_fmsg *fmsg);
1db64e87
EBE
1008
1009int devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value);
1010int devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value);
1011int devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value);
1012int devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value);
1013int devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value);
573ed90a
AL
1014int devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value,
1015 u16 value_len);
1db64e87
EBE
1016
1017int devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name,
1018 bool value);
1019int devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name,
1020 u8 value);
1021int devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name,
1022 u32 value);
1023int devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name,
1024 u64 value);
1025int devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,
1026 const char *value);
1027int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
e2cde864 1028 const void *value, u32 value_len);
1db64e87 1029
a0bdcc59
EBE
1030struct devlink_health_reporter *
1031devlink_health_reporter_create(struct devlink *devlink,
1032 const struct devlink_health_reporter_ops *ops,
1033 u64 graceful_period, bool auto_recover,
1034 void *priv);
1035void
1036devlink_health_reporter_destroy(struct devlink_health_reporter *reporter);
1037
1038void *
1039devlink_health_reporter_priv(struct devlink_health_reporter *reporter);
c8e1da0b
EBE
1040int devlink_health_report(struct devlink_health_reporter *reporter,
1041 const char *msg, void *priv_ctx);
3167b27a
EBE
1042void
1043devlink_health_reporter_state_update(struct devlink_health_reporter *reporter,
1044 enum devlink_health_reporter_state state);
6181e5cb
VG
1045void
1046devlink_health_reporter_recovery_done(struct devlink_health_reporter *reporter);
a0bdcc59 1047
2670ac26
JP
1048bool devlink_is_reload_failed(const struct devlink *devlink);
1049
191ed202
JP
1050void devlink_flash_update_begin_notify(struct devlink *devlink);
1051void devlink_flash_update_end_notify(struct devlink *devlink);
1052void devlink_flash_update_status_notify(struct devlink *devlink,
1053 const char *status_msg,
1054 const char *component,
1055 unsigned long done,
1056 unsigned long total);
1057
0f420b6c
IS
1058int devlink_traps_register(struct devlink *devlink,
1059 const struct devlink_trap *traps,
1060 size_t traps_count, void *priv);
1061void devlink_traps_unregister(struct devlink *devlink,
1062 const struct devlink_trap *traps,
1063 size_t traps_count);
5a2e106c
JP
1064void devlink_trap_report(struct devlink *devlink, struct sk_buff *skb,
1065 void *trap_ctx, struct devlink_port *in_devlink_port,
1066 const struct flow_action_cookie *fa_cookie);
0f420b6c 1067void *devlink_trap_ctx_priv(void *trap_ctx);
95ad9555
IS
1068int devlink_trap_groups_register(struct devlink *devlink,
1069 const struct devlink_trap_group *groups,
1070 size_t groups_count);
1071void devlink_trap_groups_unregister(struct devlink *devlink,
1072 const struct devlink_trap_group *groups,
1073 size_t groups_count);
0f420b6c 1074
f6b19b35
JP
1075#if IS_ENABLED(CONFIG_NET_DEVLINK)
1076
f4b6bcc7
JK
1077void devlink_compat_running_version(struct net_device *dev,
1078 char *buf, size_t len);
1079int devlink_compat_flash_update(struct net_device *dev, const char *file_name);
af3836df
JP
1080int devlink_compat_phys_port_name_get(struct net_device *dev,
1081 char *name, size_t len);
7e1146e8
JP
1082int devlink_compat_switch_id_get(struct net_device *dev,
1083 struct netdev_phys_item_id *ppid);
f4b6bcc7 1084
bfcd3a46
JP
1085#else
1086
ddb6e99e
JK
1087static inline void
1088devlink_compat_running_version(struct net_device *dev, char *buf, size_t len)
1089{
1090}
4eceba17
JK
1091
1092static inline int
1093devlink_compat_flash_update(struct net_device *dev, const char *file_name)
1094{
1095 return -EOPNOTSUPP;
1096}
f6b19b35 1097
af3836df
JP
1098static inline int
1099devlink_compat_phys_port_name_get(struct net_device *dev,
1100 char *name, size_t len)
1101{
1102 return -EOPNOTSUPP;
1103}
1104
7e1146e8
JP
1105static inline int
1106devlink_compat_switch_id_get(struct net_device *dev,
1107 struct netdev_phys_item_id *ppid)
1108{
1109 return -EOPNOTSUPP;
1110}
1111
ddb6e99e
JK
1112#endif
1113
bfcd3a46 1114#endif /* _NET_DEVLINK_H_ */