]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/net/devlink.h
devlink: Change devlink_reload_supported() param type
[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 20#include <uapi/linux/devlink.h>
12102436 21#include <linux/xarray.h>
bfcd3a46
JP
22
23struct devlink_ops;
24
25struct devlink {
26 struct list_head list;
27 struct list_head port_list;
bf797471 28 struct list_head sb_list;
1555d204 29 struct list_head dpipe_table_list;
d9f9b9a4 30 struct list_head resource_list;
eabaef18 31 struct list_head param_list;
b16ebe92 32 struct list_head region_list;
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;
1e8c6619 38 struct list_head trap_policer_list;
bfcd3a46 39 const struct devlink_ops *ops;
12102436 40 struct xarray snapshot_ids;
bfcd3a46
JP
41 struct device *dev;
42 possible_net_t _net;
336ce1c9
PP
43 struct mutex lock; /* Serializes access to devlink instance specific objects such as
44 * port, sb, dpipe, resource, params, region, traps and more.
45 */
a0c76345
JP
46 u8 reload_failed:1,
47 reload_enabled:1,
48 registered:1;
bfcd3a46
JP
49 char priv[0] __aligned(NETDEV_ALIGN);
50};
51
378ef01b
PP
52struct devlink_port_phys_attrs {
53 u32 port_number; /* Same value as "split group".
54 * A physical port which is visible to the user
55 * for a given port flavour.
56 */
71ad8d55 57 u32 split_subport_number; /* If the port is split, this is the number of subport. */
378ef01b
PP
58};
59
ff03e63a
PP
60/**
61 * struct devlink_port_pci_pf_attrs - devlink port's PCI PF attributes
3a2d9588 62 * @controller: Associated controller number
ff03e63a 63 * @pf: Associated PCI PF number for this port.
05b595e9 64 * @external: when set, indicates if a port is for an external controller
ff03e63a 65 */
98fd2d65 66struct devlink_port_pci_pf_attrs {
3a2d9588 67 u32 controller;
ff03e63a 68 u16 pf;
05b595e9 69 u8 external:1;
98fd2d65
PP
70};
71
ff03e63a
PP
72/**
73 * struct devlink_port_pci_vf_attrs - devlink port's PCI VF attributes
3a2d9588 74 * @controller: Associated controller number
ff03e63a
PP
75 * @pf: Associated PCI PF number for this port.
76 * @vf: Associated PCI VF for of the PCI PF for this port.
05b595e9 77 * @external: when set, indicates if a port is for an external controller
ff03e63a 78 */
e41b6bf3 79struct devlink_port_pci_vf_attrs {
3a2d9588 80 u32 controller;
ff03e63a
PP
81 u16 pf;
82 u16 vf;
05b595e9 83 u8 external:1;
e41b6bf3
PP
84};
85
71ad8d55
DR
86/**
87 * struct devlink_port_attrs - devlink port object
88 * @flavour: flavour of the port
89 * @split: indicates if this is split port
a0f49b54 90 * @splittable: indicates if the port can be split.
a21cf0a8 91 * @lanes: maximum number of lanes the port supports. 0 value is not passed to netlink.
71ad8d55 92 * @switch_id: if the port is part of switch, this is buffer with ID, otherwise this is NULL
2efbe6ae
PP
93 * @phys: physical port attributes
94 * @pci_pf: PCI PF port attributes
95 * @pci_vf: PCI VF port attributes
71ad8d55 96 */
b9ffcbaf 97struct devlink_port_attrs {
a0f49b54
DR
98 u8 split:1,
99 splittable:1;
a21cf0a8 100 u32 lanes;
5ec1380a 101 enum devlink_port_flavour flavour;
bec5267c 102 struct netdev_phys_item_id switch_id;
378ef01b
PP
103 union {
104 struct devlink_port_phys_attrs phys;
98fd2d65 105 struct devlink_port_pci_pf_attrs pci_pf;
e41b6bf3 106 struct devlink_port_pci_vf_attrs pci_vf;
378ef01b 107 };
b9ffcbaf
JP
108};
109
bfcd3a46
JP
110struct devlink_port {
111 struct list_head list;
39e6160e 112 struct list_head param_list;
544e7c33 113 struct list_head region_list;
bfcd3a46 114 struct devlink *devlink;
c7282b50 115 unsigned int index;
bfcd3a46 116 bool registered;
b8f97554
JP
117 spinlock_t type_lock; /* Protects type and type_dev
118 * pointer consistency.
119 */
bfcd3a46
JP
120 enum devlink_port_type type;
121 enum devlink_port_type desired_type;
122 void *type_dev;
b9ffcbaf 123 struct devlink_port_attrs attrs;
46737a19
DR
124 u8 attrs_set:1,
125 switch_port:1;
136bf27f 126 struct delayed_work type_warn_dw;
f4f54166
VT
127 struct list_head reporter_list;
128 struct mutex reporters_lock; /* Protects reporter_list */
bfcd3a46
JP
129};
130
bf797471
JP
131struct devlink_sb_pool_info {
132 enum devlink_sb_pool_type pool_type;
133 u32 size;
134 enum devlink_sb_threshold_type threshold_type;
bff5731d 135 u32 cell_size;
bf797471
JP
136};
137
1555d204
AS
138/**
139 * struct devlink_dpipe_field - dpipe field object
140 * @name: field name
141 * @id: index inside the headers field array
142 * @bitwidth: bitwidth
143 * @mapping_type: mapping type
144 */
145struct devlink_dpipe_field {
146 const char *name;
147 unsigned int id;
148 unsigned int bitwidth;
149 enum devlink_dpipe_field_mapping_type mapping_type;
150};
151
152/**
153 * struct devlink_dpipe_header - dpipe header object
154 * @name: header name
155 * @id: index, global/local detrmined by global bit
156 * @fields: fields
157 * @fields_count: number of fields
158 * @global: indicates if header is shared like most protocol header
159 * or driver specific
160 */
161struct devlink_dpipe_header {
162 const char *name;
163 unsigned int id;
164 struct devlink_dpipe_field *fields;
165 unsigned int fields_count;
166 bool global;
167};
168
169/**
170 * struct devlink_dpipe_match - represents match operation
171 * @type: type of match
172 * @header_index: header index (packets can have several headers of same
173 * type like in case of tunnels)
174 * @header: header
175 * @fieled_id: field index
176 */
177struct devlink_dpipe_match {
178 enum devlink_dpipe_match_type type;
179 unsigned int header_index;
180 struct devlink_dpipe_header *header;
181 unsigned int field_id;
182};
183
184/**
185 * struct devlink_dpipe_action - represents action operation
186 * @type: type of action
187 * @header_index: header index (packets can have several headers of same
188 * type like in case of tunnels)
189 * @header: header
190 * @fieled_id: field index
191 */
192struct devlink_dpipe_action {
193 enum devlink_dpipe_action_type type;
194 unsigned int header_index;
195 struct devlink_dpipe_header *header;
196 unsigned int field_id;
197};
198
199/**
200 * struct devlink_dpipe_value - represents value of match/action
201 * @action: action
202 * @match: match
203 * @mapping_value: in case the field has some mapping this value
204 * specified the mapping value
205 * @mapping_valid: specify if mapping value is valid
206 * @value_size: value size
207 * @value: value
208 * @mask: bit mask
209 */
210struct devlink_dpipe_value {
211 union {
212 struct devlink_dpipe_action *action;
213 struct devlink_dpipe_match *match;
214 };
215 unsigned int mapping_value;
216 bool mapping_valid;
217 unsigned int value_size;
218 void *value;
219 void *mask;
220};
221
222/**
223 * struct devlink_dpipe_entry - table entry object
224 * @index: index of the entry in the table
225 * @match_values: match values
226 * @matche_values_count: count of matches tuples
227 * @action_values: actions values
228 * @action_values_count: count of actions values
229 * @counter: value of counter
230 * @counter_valid: Specify if value is valid from hardware
231 */
232struct devlink_dpipe_entry {
233 u64 index;
234 struct devlink_dpipe_value *match_values;
235 unsigned int match_values_count;
236 struct devlink_dpipe_value *action_values;
237 unsigned int action_values_count;
238 u64 counter;
239 bool counter_valid;
240};
241
242/**
243 * struct devlink_dpipe_dump_ctx - context provided to driver in order
244 * to dump
245 * @info: info
246 * @cmd: devlink command
247 * @skb: skb
248 * @nest: top attribute
249 * @hdr: hdr
250 */
251struct devlink_dpipe_dump_ctx {
252 struct genl_info *info;
253 enum devlink_command cmd;
254 struct sk_buff *skb;
255 struct nlattr *nest;
256 void *hdr;
257};
258
259struct devlink_dpipe_table_ops;
260
261/**
262 * struct devlink_dpipe_table - table object
263 * @priv: private
264 * @name: table name
1555d204
AS
265 * @counters_enabled: indicates if counters are active
266 * @counter_control_extern: indicates if counter control is in dpipe or
267 * external tool
56dc7cd0
AS
268 * @resource_valid: Indicate that the resource id is valid
269 * @resource_id: relative resource this table is related to
270 * @resource_units: number of resource's unit consumed per table's entry
1555d204
AS
271 * @table_ops: table operations
272 * @rcu: rcu
273 */
274struct devlink_dpipe_table {
275 void *priv;
276 struct list_head list;
277 const char *name;
1555d204
AS
278 bool counters_enabled;
279 bool counter_control_extern;
56dc7cd0
AS
280 bool resource_valid;
281 u64 resource_id;
282 u64 resource_units;
1555d204
AS
283 struct devlink_dpipe_table_ops *table_ops;
284 struct rcu_head rcu;
285};
286
287/**
288 * struct devlink_dpipe_table_ops - dpipe_table ops
289 * @actions_dump - dumps all tables actions
290 * @matches_dump - dumps all tables matches
291 * @entries_dump - dumps all active entries in the table
292 * @counters_set_update - when changing the counter status hardware sync
293 * maybe needed to allocate/free counter related
294 * resources
ffd3cdcc 295 * @size_get - get size
1555d204
AS
296 */
297struct devlink_dpipe_table_ops {
298 int (*actions_dump)(void *priv, struct sk_buff *skb);
299 int (*matches_dump)(void *priv, struct sk_buff *skb);
300 int (*entries_dump)(void *priv, bool counters_enabled,
301 struct devlink_dpipe_dump_ctx *dump_ctx);
302 int (*counters_set_update)(void *priv, bool enable);
ffd3cdcc 303 u64 (*size_get)(void *priv);
1555d204
AS
304};
305
306/**
307 * struct devlink_dpipe_headers - dpipe headers
308 * @headers - header array can be shared (global bit) or driver specific
309 * @headers_count - count of headers
310 */
311struct devlink_dpipe_headers {
312 struct devlink_dpipe_header **headers;
313 unsigned int headers_count;
314};
315
d9f9b9a4
AS
316/**
317 * struct devlink_resource_size_params - resource's size parameters
318 * @size_min: minimum size which can be set
319 * @size_max: maximum size which can be set
320 * @size_granularity: size granularity
321 * @size_unit: resource's basic unit
322 */
323struct devlink_resource_size_params {
324 u64 size_min;
325 u64 size_max;
326 u64 size_granularity;
327 enum devlink_resource_unit unit;
328};
329
77d27096
JP
330static inline void
331devlink_resource_size_params_init(struct devlink_resource_size_params *size_params,
332 u64 size_min, u64 size_max,
333 u64 size_granularity,
334 enum devlink_resource_unit unit)
335{
336 size_params->size_min = size_min;
337 size_params->size_max = size_max;
338 size_params->size_granularity = size_granularity;
339 size_params->unit = unit;
340}
341
fc56be47
JP
342typedef u64 devlink_resource_occ_get_t(void *priv);
343
d9f9b9a4
AS
344/**
345 * struct devlink_resource - devlink resource
346 * @name: name of the resource
347 * @id: id, per devlink instance
348 * @size: size of the resource
349 * @size_new: updated size of the resource, reload is needed
350 * @size_valid: valid in case the total size of the resource is valid
351 * including its children
352 * @parent: parent resource
353 * @size_params: size parameters
354 * @list: parent list
355 * @resource_list: list of child resources
d9f9b9a4
AS
356 */
357struct devlink_resource {
358 const char *name;
359 u64 id;
360 u64 size;
361 u64 size_new;
362 bool size_valid;
363 struct devlink_resource *parent;
77d27096 364 struct devlink_resource_size_params size_params;
d9f9b9a4
AS
365 struct list_head list;
366 struct list_head resource_list;
fc56be47
JP
367 devlink_resource_occ_get_t *occ_get;
368 void *occ_get_priv;
d9f9b9a4
AS
369};
370
371#define DEVLINK_RESOURCE_ID_PARENT_TOP 0
372
bde74ad1 373#define __DEVLINK_PARAM_MAX_STRING_VALUE 32
eabaef18
MS
374enum devlink_param_type {
375 DEVLINK_PARAM_TYPE_U8,
376 DEVLINK_PARAM_TYPE_U16,
377 DEVLINK_PARAM_TYPE_U32,
378 DEVLINK_PARAM_TYPE_STRING,
379 DEVLINK_PARAM_TYPE_BOOL,
380};
381
382union devlink_param_value {
383 u8 vu8;
384 u16 vu16;
385 u32 vu32;
bde74ad1 386 char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];
eabaef18
MS
387 bool vbool;
388};
389
390struct devlink_param_gset_ctx {
391 union devlink_param_value val;
392 enum devlink_param_cmode cmode;
393};
394
6700acc5
SN
395/**
396 * struct devlink_flash_notify - devlink dev flash notify data
397 * @status_msg: current status string
398 * @component: firmware component being updated
399 * @done: amount of work completed of total amount
400 * @total: amount of work expected to be done
401 * @timeout: expected max timeout in seconds
402 *
403 * These are values to be given to userland to be displayed in order
404 * to show current activity in a firmware update process.
405 */
406struct devlink_flash_notify {
407 const char *status_msg;
408 const char *component;
409 unsigned long done;
410 unsigned long total;
411 unsigned long timeout;
412};
413
eabaef18
MS
414/**
415 * struct devlink_param - devlink configuration parameter data
416 * @name: name of the parameter
417 * @generic: indicates if the parameter is generic or driver specific
418 * @type: parameter type
419 * @supported_cmodes: bitmap of supported configuration modes
420 * @get: get parameter value, used for runtime and permanent
421 * configuration modes
422 * @set: set parameter value, used for runtime and permanent
423 * configuration modes
e3b7ca18 424 * @validate: validate input value is applicable (within value range, etc.)
eabaef18
MS
425 *
426 * This struct should be used by the driver to fill the data for
427 * a parameter it registers.
428 */
429struct devlink_param {
430 u32 id;
431 const char *name;
432 bool generic;
433 enum devlink_param_type type;
434 unsigned long supported_cmodes;
435 int (*get)(struct devlink *devlink, u32 id,
436 struct devlink_param_gset_ctx *ctx);
437 int (*set)(struct devlink *devlink, u32 id,
438 struct devlink_param_gset_ctx *ctx);
e3b7ca18
MS
439 int (*validate)(struct devlink *devlink, u32 id,
440 union devlink_param_value val,
441 struct netlink_ext_ack *extack);
eabaef18
MS
442};
443
444struct devlink_param_item {
445 struct list_head list;
446 const struct devlink_param *param;
447 union devlink_param_value driverinit_value;
448 bool driverinit_value_valid;
7c62cfb8 449 bool published;
eabaef18
MS
450};
451
452enum devlink_param_generic_id {
036467c3
MS
453 DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
454 DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
f567bcda 455 DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
f6a69885 456 DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT,
e3b51061 457 DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI,
f61cba42 458 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
16511789 459 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
846e980a 460 DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY,
5bbd21df 461 DEVLINK_PARAM_GENERIC_ID_RESET_DEV_ON_DRV_PROBE,
6c7295e1 462 DEVLINK_PARAM_GENERIC_ID_ENABLE_ROCE,
eabaef18
MS
463
464 /* add new param generic ids above here*/
465 __DEVLINK_PARAM_GENERIC_ID_MAX,
466 DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
467};
468
036467c3
MS
469#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
470#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
471
472#define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
473#define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
474
f567bcda
VV
475#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
476#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
477
f6a69885
AV
478#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable"
479#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL
480
e3b51061
VV
481#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari"
482#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL
483
f61cba42
VV
484#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max"
485#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32
486
16511789
VV
487#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min"
488#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32
489
846e980a
ST
490#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy"
491#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8
492
5bbd21df
DM
493#define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_NAME \
494 "reset_dev_on_drv_probe"
495#define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_TYPE DEVLINK_PARAM_TYPE_U8
496
6c7295e1
MG
497#define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_NAME "enable_roce"
498#define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_TYPE DEVLINK_PARAM_TYPE_BOOL
499
036467c3
MS
500#define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \
501{ \
502 .id = DEVLINK_PARAM_GENERIC_ID_##_id, \
503 .name = DEVLINK_PARAM_GENERIC_##_id##_NAME, \
504 .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE, \
505 .generic = true, \
506 .supported_cmodes = _cmodes, \
507 .get = _get, \
508 .set = _set, \
509 .validate = _validate, \
510}
511
512#define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate) \
513{ \
514 .id = _id, \
515 .name = _name, \
516 .type = _type, \
517 .supported_cmodes = _cmodes, \
518 .get = _get, \
519 .set = _set, \
520 .validate = _validate, \
521}
522
785bd550
JK
523/* Part number, identifier of board design */
524#define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID "board.id"
525/* Revision of board design */
526#define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV "board.rev"
14fd1901
JK
527/* Maker of the board */
528#define DEVLINK_INFO_VERSION_GENERIC_BOARD_MANUFACTURE "board.manufacture"
785bd550 529
7d5aa9a5
SN
530/* Part number, identifier of asic design */
531#define DEVLINK_INFO_VERSION_GENERIC_ASIC_ID "asic.id"
532/* Revision of asic design */
533#define DEVLINK_INFO_VERSION_GENERIC_ASIC_REV "asic.rev"
534
535/* Overall FW version */
536#define DEVLINK_INFO_VERSION_GENERIC_FW "fw"
785bd550
JK
537/* Control processor FW version */
538#define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT "fw.mgmt"
2d9eade8
VV
539/* FW interface specification version */
540#define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT_API "fw.mgmt.api"
785bd550
JK
541/* Data path microcode controlling high-speed packet processing */
542#define DEVLINK_INFO_VERSION_GENERIC_FW_APP "fw.app"
543/* UNDI software version */
544#define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI "fw.undi"
545/* NCSI support/handler version */
546#define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI "fw.ncsi"
468672b2
JK
547/* FW parameter set id */
548#define DEVLINK_INFO_VERSION_GENERIC_FW_PSID "fw.psid"
41c0d917
VV
549/* RoCE FW version */
550#define DEVLINK_INFO_VERSION_GENERIC_FW_ROCE "fw.roce"
c90977a3
JK
551/* Firmware bundle identifier */
552#define DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID "fw.bundle_id"
785bd550 553
bc75c054
JK
554/**
555 * struct devlink_flash_update_params - Flash Update parameters
556 * @file_name: the name of the flash firmware file to update from
557 * @component: the flash component to update
558 *
559 * With the exception of file_name, drivers must opt-in to parameters by
560 * setting the appropriate bit in the supported_flash_update_params field in
561 * their devlink_ops structure.
562 */
563struct devlink_flash_update_params {
564 const char *file_name;
565 const char *component;
5d5b4128 566 u32 overwrite_mask;
bc75c054
JK
567};
568
5d5b4128
JK
569#define DEVLINK_SUPPORT_FLASH_UPDATE_COMPONENT BIT(0)
570#define DEVLINK_SUPPORT_FLASH_UPDATE_OVERWRITE_MASK BIT(1)
22ec3d23 571
b16ebe92 572struct devlink_region;
f9cf2288 573struct devlink_info_req;
b16ebe92 574
e8937681
JK
575/**
576 * struct devlink_region_ops - Region operations
577 * @name: region name
a0a09f6b 578 * @destructor: callback used to free snapshot memory when deleting
b9a17abf
JK
579 * @snapshot: callback to request an immediate snapshot. On success,
580 * the data variable must be updated to point to the snapshot data.
581 * The function will be called while the devlink instance lock is
582 * held.
e14e05e7 583 * @priv: Pointer to driver private data for the region operation
e8937681
JK
584 */
585struct devlink_region_ops {
586 const char *name;
a0a09f6b 587 void (*destructor)(const void *data);
d4602a9f
AL
588 int (*snapshot)(struct devlink *devlink,
589 const struct devlink_region_ops *ops,
590 struct netlink_ext_ack *extack,
b9a17abf 591 u8 **data);
e14e05e7 592 void *priv;
e8937681
JK
593};
594
544e7c33
AL
595/**
596 * struct devlink_port_region_ops - Region operations for a port
597 * @name: region name
598 * @destructor: callback used to free snapshot memory when deleting
599 * @snapshot: callback to request an immediate snapshot. On success,
600 * the data variable must be updated to point to the snapshot data.
601 * The function will be called while the devlink instance lock is
602 * held.
603 * @priv: Pointer to driver private data for the region operation
604 */
605struct devlink_port_region_ops {
606 const char *name;
607 void (*destructor)(const void *data);
608 int (*snapshot)(struct devlink_port *port,
609 const struct devlink_port_region_ops *ops,
610 struct netlink_ext_ack *extack,
611 u8 **data);
612 void *priv;
613};
614
1db64e87 615struct devlink_fmsg;
a0bdcc59
EBE
616struct devlink_health_reporter;
617
3167b27a
EBE
618enum devlink_health_reporter_state {
619 DEVLINK_HEALTH_REPORTER_STATE_HEALTHY,
620 DEVLINK_HEALTH_REPORTER_STATE_ERROR,
621};
622
a0bdcc59
EBE
623/**
624 * struct devlink_health_reporter_ops - Reporter operations
625 * @name: reporter name
626 * @recover: callback to recover from reported error
627 * if priv_ctx is NULL, run a full recover
628 * @dump: callback to dump an object
629 * if priv_ctx is NULL, run a full dump
630 * @diagnose: callback to diagnose the current status
e2ce94dc 631 * @test: callback to trigger a test event
a0bdcc59
EBE
632 */
633
634struct devlink_health_reporter_ops {
635 char *name;
636 int (*recover)(struct devlink_health_reporter *reporter,
e7a98105 637 void *priv_ctx, struct netlink_ext_ack *extack);
a0bdcc59 638 int (*dump)(struct devlink_health_reporter *reporter,
e7a98105
JP
639 struct devlink_fmsg *fmsg, void *priv_ctx,
640 struct netlink_ext_ack *extack);
a0bdcc59 641 int (*diagnose)(struct devlink_health_reporter *reporter,
e7a98105
JP
642 struct devlink_fmsg *fmsg,
643 struct netlink_ext_ack *extack);
e2ce94dc
JP
644 int (*test)(struct devlink_health_reporter *reporter,
645 struct netlink_ext_ack *extack);
a0bdcc59 646};
1db64e87 647
5b88823b
IS
648/**
649 * struct devlink_trap_metadata - Packet trap metadata.
650 * @trap_name: Trap name.
651 * @trap_group_name: Trap group name.
652 * @input_dev: Input netdevice.
653 * @fa_cookie: Flow action user cookie.
93e15596 654 * @trap_type: Trap type.
5b88823b
IS
655 */
656struct devlink_trap_metadata {
657 const char *trap_name;
658 const char *trap_group_name;
659 struct net_device *input_dev;
660 const struct flow_action_cookie *fa_cookie;
93e15596 661 enum devlink_trap_type trap_type;
5b88823b
IS
662};
663
1e8c6619
IS
664/**
665 * struct devlink_trap_policer - Immutable packet trap policer attributes.
666 * @id: Policer identifier.
667 * @init_rate: Initial rate in packets / sec.
668 * @init_burst: Initial burst size in packets.
669 * @max_rate: Maximum rate.
670 * @min_rate: Minimum rate.
671 * @max_burst: Maximum burst size.
672 * @min_burst: Minimum burst size.
673 *
674 * Describes immutable attributes of packet trap policers that drivers register
675 * with devlink.
676 */
677struct devlink_trap_policer {
678 u32 id;
679 u64 init_rate;
680 u64 init_burst;
681 u64 max_rate;
682 u64 min_rate;
683 u64 max_burst;
684 u64 min_burst;
685};
686
0f420b6c
IS
687/**
688 * struct devlink_trap_group - Immutable packet trap group attributes.
689 * @name: Trap group name.
690 * @id: Trap group identifier.
691 * @generic: Whether the trap group is generic or not.
f9f54392 692 * @init_policer_id: Initial policer identifier.
0f420b6c
IS
693 *
694 * Describes immutable attributes of packet trap groups that drivers register
695 * with devlink.
696 */
697struct devlink_trap_group {
698 const char *name;
699 u16 id;
700 bool generic;
f9f54392 701 u32 init_policer_id;
0f420b6c
IS
702};
703
704#define DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT BIT(0)
85b0589e 705#define DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE BIT(1)
0f420b6c
IS
706
707/**
708 * struct devlink_trap - Immutable packet trap attributes.
709 * @type: Trap type.
710 * @init_action: Initial trap action.
711 * @generic: Whether the trap is generic or not.
712 * @id: Trap identifier.
713 * @name: Trap name.
107f1678 714 * @init_group_id: Initial group identifier.
0f420b6c
IS
715 * @metadata_cap: Metadata types that can be provided by the trap.
716 *
717 * Describes immutable attributes of packet traps that drivers register with
718 * devlink.
719 */
720struct devlink_trap {
721 enum devlink_trap_type type;
722 enum devlink_trap_action init_action;
723 bool generic;
724 u16 id;
725 const char *name;
107f1678 726 u16 init_group_id;
0f420b6c
IS
727 u32 metadata_cap;
728};
729
f3047ca0 730/* All traps must be documented in
f4bdd710 731 * Documentation/networking/devlink/devlink-trap.rst
f3047ca0 732 */
0f420b6c 733enum devlink_trap_generic_id {
391203ab
IS
734 DEVLINK_TRAP_GENERIC_ID_SMAC_MC,
735 DEVLINK_TRAP_GENERIC_ID_VLAN_TAG_MISMATCH,
736 DEVLINK_TRAP_GENERIC_ID_INGRESS_VLAN_FILTER,
737 DEVLINK_TRAP_GENERIC_ID_INGRESS_STP_FILTER,
738 DEVLINK_TRAP_GENERIC_ID_EMPTY_TX_LIST,
739 DEVLINK_TRAP_GENERIC_ID_PORT_LOOPBACK_FILTER,
740 DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_ROUTE,
741 DEVLINK_TRAP_GENERIC_ID_TTL_ERROR,
742 DEVLINK_TRAP_GENERIC_ID_TAIL_DROP,
6896cc4d
AC
743 DEVLINK_TRAP_GENERIC_ID_NON_IP_PACKET,
744 DEVLINK_TRAP_GENERIC_ID_UC_DIP_MC_DMAC,
745 DEVLINK_TRAP_GENERIC_ID_DIP_LB,
746 DEVLINK_TRAP_GENERIC_ID_SIP_MC,
747 DEVLINK_TRAP_GENERIC_ID_SIP_LB,
748 DEVLINK_TRAP_GENERIC_ID_CORRUPTED_IP_HDR,
749 DEVLINK_TRAP_GENERIC_ID_IPV4_SIP_BC,
750 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_RESERVED_SCOPE,
751 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE,
3b063ae5
AC
752 DEVLINK_TRAP_GENERIC_ID_MTU_ERROR,
753 DEVLINK_TRAP_GENERIC_ID_UNRESOLVED_NEIGH,
754 DEVLINK_TRAP_GENERIC_ID_RPF,
755 DEVLINK_TRAP_GENERIC_ID_REJECT_ROUTE,
756 DEVLINK_TRAP_GENERIC_ID_IPV4_LPM_UNICAST_MISS,
757 DEVLINK_TRAP_GENERIC_ID_IPV6_LPM_UNICAST_MISS,
95f0ead8 758 DEVLINK_TRAP_GENERIC_ID_NON_ROUTABLE,
13c056ec 759 DEVLINK_TRAP_GENERIC_ID_DECAP_ERROR,
c3cae491 760 DEVLINK_TRAP_GENERIC_ID_OVERLAY_SMAC_MC,
ecd942a0
JP
761 DEVLINK_TRAP_GENERIC_ID_INGRESS_FLOW_ACTION_DROP,
762 DEVLINK_TRAP_GENERIC_ID_EGRESS_FLOW_ACTION_DROP,
515eac67
IS
763 DEVLINK_TRAP_GENERIC_ID_STP,
764 DEVLINK_TRAP_GENERIC_ID_LACP,
765 DEVLINK_TRAP_GENERIC_ID_LLDP,
766 DEVLINK_TRAP_GENERIC_ID_IGMP_QUERY,
767 DEVLINK_TRAP_GENERIC_ID_IGMP_V1_REPORT,
768 DEVLINK_TRAP_GENERIC_ID_IGMP_V2_REPORT,
769 DEVLINK_TRAP_GENERIC_ID_IGMP_V3_REPORT,
770 DEVLINK_TRAP_GENERIC_ID_IGMP_V2_LEAVE,
771 DEVLINK_TRAP_GENERIC_ID_MLD_QUERY,
772 DEVLINK_TRAP_GENERIC_ID_MLD_V1_REPORT,
773 DEVLINK_TRAP_GENERIC_ID_MLD_V2_REPORT,
774 DEVLINK_TRAP_GENERIC_ID_MLD_V1_DONE,
d77cfd16
IS
775 DEVLINK_TRAP_GENERIC_ID_IPV4_DHCP,
776 DEVLINK_TRAP_GENERIC_ID_IPV6_DHCP,
777 DEVLINK_TRAP_GENERIC_ID_ARP_REQUEST,
778 DEVLINK_TRAP_GENERIC_ID_ARP_RESPONSE,
779 DEVLINK_TRAP_GENERIC_ID_ARP_OVERLAY,
780 DEVLINK_TRAP_GENERIC_ID_IPV6_NEIGH_SOLICIT,
781 DEVLINK_TRAP_GENERIC_ID_IPV6_NEIGH_ADVERT,
782 DEVLINK_TRAP_GENERIC_ID_IPV4_BFD,
783 DEVLINK_TRAP_GENERIC_ID_IPV6_BFD,
784 DEVLINK_TRAP_GENERIC_ID_IPV4_OSPF,
785 DEVLINK_TRAP_GENERIC_ID_IPV6_OSPF,
786 DEVLINK_TRAP_GENERIC_ID_IPV4_BGP,
787 DEVLINK_TRAP_GENERIC_ID_IPV6_BGP,
788 DEVLINK_TRAP_GENERIC_ID_IPV4_VRRP,
789 DEVLINK_TRAP_GENERIC_ID_IPV6_VRRP,
790 DEVLINK_TRAP_GENERIC_ID_IPV4_PIM,
791 DEVLINK_TRAP_GENERIC_ID_IPV6_PIM,
792 DEVLINK_TRAP_GENERIC_ID_UC_LB,
793 DEVLINK_TRAP_GENERIC_ID_LOCAL_ROUTE,
794 DEVLINK_TRAP_GENERIC_ID_EXTERNAL_ROUTE,
795 DEVLINK_TRAP_GENERIC_ID_IPV6_UC_DIP_LINK_LOCAL_SCOPE,
796 DEVLINK_TRAP_GENERIC_ID_IPV6_DIP_ALL_NODES,
797 DEVLINK_TRAP_GENERIC_ID_IPV6_DIP_ALL_ROUTERS,
798 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_SOLICIT,
799 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_ADVERT,
800 DEVLINK_TRAP_GENERIC_ID_IPV6_REDIRECT,
801 DEVLINK_TRAP_GENERIC_ID_IPV4_ROUTER_ALERT,
802 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_ALERT,
803 DEVLINK_TRAP_GENERIC_ID_PTP_EVENT,
804 DEVLINK_TRAP_GENERIC_ID_PTP_GENERAL,
5eb18a2b
IS
805 DEVLINK_TRAP_GENERIC_ID_FLOW_ACTION_SAMPLE,
806 DEVLINK_TRAP_GENERIC_ID_FLOW_ACTION_TRAP,
08e335f6 807 DEVLINK_TRAP_GENERIC_ID_EARLY_DROP,
10c24eb2
IC
808 DEVLINK_TRAP_GENERIC_ID_VXLAN_PARSING,
809 DEVLINK_TRAP_GENERIC_ID_LLC_SNAP_PARSING,
810 DEVLINK_TRAP_GENERIC_ID_VLAN_PARSING,
811 DEVLINK_TRAP_GENERIC_ID_PPPOE_PPP_PARSING,
812 DEVLINK_TRAP_GENERIC_ID_MPLS_PARSING,
813 DEVLINK_TRAP_GENERIC_ID_ARP_PARSING,
814 DEVLINK_TRAP_GENERIC_ID_IP_1_PARSING,
815 DEVLINK_TRAP_GENERIC_ID_IP_N_PARSING,
816 DEVLINK_TRAP_GENERIC_ID_GRE_PARSING,
817 DEVLINK_TRAP_GENERIC_ID_UDP_PARSING,
818 DEVLINK_TRAP_GENERIC_ID_TCP_PARSING,
819 DEVLINK_TRAP_GENERIC_ID_IPSEC_PARSING,
820 DEVLINK_TRAP_GENERIC_ID_SCTP_PARSING,
821 DEVLINK_TRAP_GENERIC_ID_DCCP_PARSING,
822 DEVLINK_TRAP_GENERIC_ID_GTP_PARSING,
823 DEVLINK_TRAP_GENERIC_ID_ESP_PARSING,
391203ab 824
0f420b6c
IS
825 /* Add new generic trap IDs above */
826 __DEVLINK_TRAP_GENERIC_ID_MAX,
827 DEVLINK_TRAP_GENERIC_ID_MAX = __DEVLINK_TRAP_GENERIC_ID_MAX - 1,
828};
829
f3047ca0 830/* All trap groups must be documented in
f4bdd710 831 * Documentation/networking/devlink/devlink-trap.rst
f3047ca0 832 */
0f420b6c 833enum devlink_trap_group_generic_id {
391203ab
IS
834 DEVLINK_TRAP_GROUP_GENERIC_ID_L2_DROPS,
835 DEVLINK_TRAP_GROUP_GENERIC_ID_L3_DROPS,
678eb199 836 DEVLINK_TRAP_GROUP_GENERIC_ID_L3_EXCEPTIONS,
391203ab 837 DEVLINK_TRAP_GROUP_GENERIC_ID_BUFFER_DROPS,
13c056ec 838 DEVLINK_TRAP_GROUP_GENERIC_ID_TUNNEL_DROPS,
ecd942a0 839 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_DROPS,
515eac67
IS
840 DEVLINK_TRAP_GROUP_GENERIC_ID_STP,
841 DEVLINK_TRAP_GROUP_GENERIC_ID_LACP,
842 DEVLINK_TRAP_GROUP_GENERIC_ID_LLDP,
843 DEVLINK_TRAP_GROUP_GENERIC_ID_MC_SNOOPING,
d77cfd16
IS
844 DEVLINK_TRAP_GROUP_GENERIC_ID_DHCP,
845 DEVLINK_TRAP_GROUP_GENERIC_ID_NEIGH_DISCOVERY,
846 DEVLINK_TRAP_GROUP_GENERIC_ID_BFD,
847 DEVLINK_TRAP_GROUP_GENERIC_ID_OSPF,
848 DEVLINK_TRAP_GROUP_GENERIC_ID_BGP,
849 DEVLINK_TRAP_GROUP_GENERIC_ID_VRRP,
850 DEVLINK_TRAP_GROUP_GENERIC_ID_PIM,
851 DEVLINK_TRAP_GROUP_GENERIC_ID_UC_LB,
852 DEVLINK_TRAP_GROUP_GENERIC_ID_LOCAL_DELIVERY,
ec4f5b36 853 DEVLINK_TRAP_GROUP_GENERIC_ID_EXTERNAL_DELIVERY,
d77cfd16
IS
854 DEVLINK_TRAP_GROUP_GENERIC_ID_IPV6,
855 DEVLINK_TRAP_GROUP_GENERIC_ID_PTP_EVENT,
856 DEVLINK_TRAP_GROUP_GENERIC_ID_PTP_GENERAL,
5eb18a2b
IS
857 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_SAMPLE,
858 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_TRAP,
10c24eb2 859 DEVLINK_TRAP_GROUP_GENERIC_ID_PARSER_ERROR_DROPS,
391203ab 860
0f420b6c
IS
861 /* Add new generic trap group IDs above */
862 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX,
863 DEVLINK_TRAP_GROUP_GENERIC_ID_MAX =
864 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX - 1,
865};
866
391203ab
IS
867#define DEVLINK_TRAP_GENERIC_NAME_SMAC_MC \
868 "source_mac_is_multicast"
869#define DEVLINK_TRAP_GENERIC_NAME_VLAN_TAG_MISMATCH \
870 "vlan_tag_mismatch"
871#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_VLAN_FILTER \
872 "ingress_vlan_filter"
873#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_STP_FILTER \
874 "ingress_spanning_tree_filter"
875#define DEVLINK_TRAP_GENERIC_NAME_EMPTY_TX_LIST \
876 "port_list_is_empty"
877#define DEVLINK_TRAP_GENERIC_NAME_PORT_LOOPBACK_FILTER \
878 "port_loopback_filter"
879#define DEVLINK_TRAP_GENERIC_NAME_BLACKHOLE_ROUTE \
880 "blackhole_route"
881#define DEVLINK_TRAP_GENERIC_NAME_TTL_ERROR \
882 "ttl_value_is_too_small"
883#define DEVLINK_TRAP_GENERIC_NAME_TAIL_DROP \
884 "tail_drop"
6896cc4d
AC
885#define DEVLINK_TRAP_GENERIC_NAME_NON_IP_PACKET \
886 "non_ip"
887#define DEVLINK_TRAP_GENERIC_NAME_UC_DIP_MC_DMAC \
888 "uc_dip_over_mc_dmac"
889#define DEVLINK_TRAP_GENERIC_NAME_DIP_LB \
890 "dip_is_loopback_address"
891#define DEVLINK_TRAP_GENERIC_NAME_SIP_MC \
892 "sip_is_mc"
893#define DEVLINK_TRAP_GENERIC_NAME_SIP_LB \
894 "sip_is_loopback_address"
895#define DEVLINK_TRAP_GENERIC_NAME_CORRUPTED_IP_HDR \
896 "ip_header_corrupted"
897#define DEVLINK_TRAP_GENERIC_NAME_IPV4_SIP_BC \
898 "ipv4_sip_is_limited_bc"
899#define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_RESERVED_SCOPE \
900 "ipv6_mc_dip_reserved_scope"
901#define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE \
902 "ipv6_mc_dip_interface_local_scope"
3b063ae5
AC
903#define DEVLINK_TRAP_GENERIC_NAME_MTU_ERROR \
904 "mtu_value_is_too_small"
905#define DEVLINK_TRAP_GENERIC_NAME_UNRESOLVED_NEIGH \
906 "unresolved_neigh"
907#define DEVLINK_TRAP_GENERIC_NAME_RPF \
908 "mc_reverse_path_forwarding"
909#define DEVLINK_TRAP_GENERIC_NAME_REJECT_ROUTE \
910 "reject_route"
911#define DEVLINK_TRAP_GENERIC_NAME_IPV4_LPM_UNICAST_MISS \
912 "ipv4_lpm_miss"
913#define DEVLINK_TRAP_GENERIC_NAME_IPV6_LPM_UNICAST_MISS \
914 "ipv6_lpm_miss"
95f0ead8
AC
915#define DEVLINK_TRAP_GENERIC_NAME_NON_ROUTABLE \
916 "non_routable_packet"
13c056ec
AC
917#define DEVLINK_TRAP_GENERIC_NAME_DECAP_ERROR \
918 "decap_error"
c3cae491
AC
919#define DEVLINK_TRAP_GENERIC_NAME_OVERLAY_SMAC_MC \
920 "overlay_smac_is_mc"
ecd942a0
JP
921#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_FLOW_ACTION_DROP \
922 "ingress_flow_action_drop"
923#define DEVLINK_TRAP_GENERIC_NAME_EGRESS_FLOW_ACTION_DROP \
924 "egress_flow_action_drop"
515eac67
IS
925#define DEVLINK_TRAP_GENERIC_NAME_STP \
926 "stp"
927#define DEVLINK_TRAP_GENERIC_NAME_LACP \
928 "lacp"
929#define DEVLINK_TRAP_GENERIC_NAME_LLDP \
930 "lldp"
931#define DEVLINK_TRAP_GENERIC_NAME_IGMP_QUERY \
932 "igmp_query"
933#define DEVLINK_TRAP_GENERIC_NAME_IGMP_V1_REPORT \
934 "igmp_v1_report"
935#define DEVLINK_TRAP_GENERIC_NAME_IGMP_V2_REPORT \
936 "igmp_v2_report"
937#define DEVLINK_TRAP_GENERIC_NAME_IGMP_V3_REPORT \
938 "igmp_v3_report"
939#define DEVLINK_TRAP_GENERIC_NAME_IGMP_V2_LEAVE \
940 "igmp_v2_leave"
941#define DEVLINK_TRAP_GENERIC_NAME_MLD_QUERY \
942 "mld_query"
943#define DEVLINK_TRAP_GENERIC_NAME_MLD_V1_REPORT \
944 "mld_v1_report"
945#define DEVLINK_TRAP_GENERIC_NAME_MLD_V2_REPORT \
946 "mld_v2_report"
947#define DEVLINK_TRAP_GENERIC_NAME_MLD_V1_DONE \
948 "mld_v1_done"
d77cfd16
IS
949#define DEVLINK_TRAP_GENERIC_NAME_IPV4_DHCP \
950 "ipv4_dhcp"
951#define DEVLINK_TRAP_GENERIC_NAME_IPV6_DHCP \
952 "ipv6_dhcp"
953#define DEVLINK_TRAP_GENERIC_NAME_ARP_REQUEST \
954 "arp_request"
955#define DEVLINK_TRAP_GENERIC_NAME_ARP_RESPONSE \
956 "arp_response"
957#define DEVLINK_TRAP_GENERIC_NAME_ARP_OVERLAY \
958 "arp_overlay"
959#define DEVLINK_TRAP_GENERIC_NAME_IPV6_NEIGH_SOLICIT \
960 "ipv6_neigh_solicit"
961#define DEVLINK_TRAP_GENERIC_NAME_IPV6_NEIGH_ADVERT \
962 "ipv6_neigh_advert"
963#define DEVLINK_TRAP_GENERIC_NAME_IPV4_BFD \
964 "ipv4_bfd"
965#define DEVLINK_TRAP_GENERIC_NAME_IPV6_BFD \
966 "ipv6_bfd"
967#define DEVLINK_TRAP_GENERIC_NAME_IPV4_OSPF \
968 "ipv4_ospf"
969#define DEVLINK_TRAP_GENERIC_NAME_IPV6_OSPF \
970 "ipv6_ospf"
971#define DEVLINK_TRAP_GENERIC_NAME_IPV4_BGP \
972 "ipv4_bgp"
973#define DEVLINK_TRAP_GENERIC_NAME_IPV6_BGP \
974 "ipv6_bgp"
975#define DEVLINK_TRAP_GENERIC_NAME_IPV4_VRRP \
976 "ipv4_vrrp"
977#define DEVLINK_TRAP_GENERIC_NAME_IPV6_VRRP \
978 "ipv6_vrrp"
979#define DEVLINK_TRAP_GENERIC_NAME_IPV4_PIM \
980 "ipv4_pim"
981#define DEVLINK_TRAP_GENERIC_NAME_IPV6_PIM \
982 "ipv6_pim"
983#define DEVLINK_TRAP_GENERIC_NAME_UC_LB \
984 "uc_loopback"
985#define DEVLINK_TRAP_GENERIC_NAME_LOCAL_ROUTE \
986 "local_route"
987#define DEVLINK_TRAP_GENERIC_NAME_EXTERNAL_ROUTE \
988 "external_route"
989#define DEVLINK_TRAP_GENERIC_NAME_IPV6_UC_DIP_LINK_LOCAL_SCOPE \
990 "ipv6_uc_dip_link_local_scope"
991#define DEVLINK_TRAP_GENERIC_NAME_IPV6_DIP_ALL_NODES \
992 "ipv6_dip_all_nodes"
993#define DEVLINK_TRAP_GENERIC_NAME_IPV6_DIP_ALL_ROUTERS \
994 "ipv6_dip_all_routers"
995#define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_SOLICIT \
996 "ipv6_router_solicit"
997#define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_ADVERT \
998 "ipv6_router_advert"
999#define DEVLINK_TRAP_GENERIC_NAME_IPV6_REDIRECT \
1000 "ipv6_redirect"
1001#define DEVLINK_TRAP_GENERIC_NAME_IPV4_ROUTER_ALERT \
1002 "ipv4_router_alert"
1003#define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_ALERT \
1004 "ipv6_router_alert"
1005#define DEVLINK_TRAP_GENERIC_NAME_PTP_EVENT \
1006 "ptp_event"
1007#define DEVLINK_TRAP_GENERIC_NAME_PTP_GENERAL \
1008 "ptp_general"
5eb18a2b
IS
1009#define DEVLINK_TRAP_GENERIC_NAME_FLOW_ACTION_SAMPLE \
1010 "flow_action_sample"
1011#define DEVLINK_TRAP_GENERIC_NAME_FLOW_ACTION_TRAP \
1012 "flow_action_trap"
08e335f6
AC
1013#define DEVLINK_TRAP_GENERIC_NAME_EARLY_DROP \
1014 "early_drop"
10c24eb2
IC
1015#define DEVLINK_TRAP_GENERIC_NAME_VXLAN_PARSING \
1016 "vxlan_parsing"
1017#define DEVLINK_TRAP_GENERIC_NAME_LLC_SNAP_PARSING \
1018 "llc_snap_parsing"
1019#define DEVLINK_TRAP_GENERIC_NAME_VLAN_PARSING \
1020 "vlan_parsing"
1021#define DEVLINK_TRAP_GENERIC_NAME_PPPOE_PPP_PARSING \
1022 "pppoe_ppp_parsing"
1023#define DEVLINK_TRAP_GENERIC_NAME_MPLS_PARSING \
1024 "mpls_parsing"
1025#define DEVLINK_TRAP_GENERIC_NAME_ARP_PARSING \
1026 "arp_parsing"
1027#define DEVLINK_TRAP_GENERIC_NAME_IP_1_PARSING \
1028 "ip_1_parsing"
1029#define DEVLINK_TRAP_GENERIC_NAME_IP_N_PARSING \
1030 "ip_n_parsing"
1031#define DEVLINK_TRAP_GENERIC_NAME_GRE_PARSING \
1032 "gre_parsing"
1033#define DEVLINK_TRAP_GENERIC_NAME_UDP_PARSING \
1034 "udp_parsing"
1035#define DEVLINK_TRAP_GENERIC_NAME_TCP_PARSING \
1036 "tcp_parsing"
1037#define DEVLINK_TRAP_GENERIC_NAME_IPSEC_PARSING \
1038 "ipsec_parsing"
1039#define DEVLINK_TRAP_GENERIC_NAME_SCTP_PARSING \
1040 "sctp_parsing"
1041#define DEVLINK_TRAP_GENERIC_NAME_DCCP_PARSING \
1042 "dccp_parsing"
1043#define DEVLINK_TRAP_GENERIC_NAME_GTP_PARSING \
1044 "gtp_parsing"
1045#define DEVLINK_TRAP_GENERIC_NAME_ESP_PARSING \
1046 "esp_parsing"
1047
391203ab
IS
1048
1049#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L2_DROPS \
1050 "l2_drops"
1051#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_DROPS \
1052 "l3_drops"
678eb199
IS
1053#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_EXCEPTIONS \
1054 "l3_exceptions"
391203ab
IS
1055#define DEVLINK_TRAP_GROUP_GENERIC_NAME_BUFFER_DROPS \
1056 "buffer_drops"
13c056ec
AC
1057#define DEVLINK_TRAP_GROUP_GENERIC_NAME_TUNNEL_DROPS \
1058 "tunnel_drops"
ecd942a0
JP
1059#define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_DROPS \
1060 "acl_drops"
515eac67
IS
1061#define DEVLINK_TRAP_GROUP_GENERIC_NAME_STP \
1062 "stp"
1063#define DEVLINK_TRAP_GROUP_GENERIC_NAME_LACP \
1064 "lacp"
1065#define DEVLINK_TRAP_GROUP_GENERIC_NAME_LLDP \
1066 "lldp"
1067#define DEVLINK_TRAP_GROUP_GENERIC_NAME_MC_SNOOPING \
1068 "mc_snooping"
d77cfd16
IS
1069#define DEVLINK_TRAP_GROUP_GENERIC_NAME_DHCP \
1070 "dhcp"
1071#define DEVLINK_TRAP_GROUP_GENERIC_NAME_NEIGH_DISCOVERY \
1072 "neigh_discovery"
1073#define DEVLINK_TRAP_GROUP_GENERIC_NAME_BFD \
1074 "bfd"
1075#define DEVLINK_TRAP_GROUP_GENERIC_NAME_OSPF \
1076 "ospf"
1077#define DEVLINK_TRAP_GROUP_GENERIC_NAME_BGP \
1078 "bgp"
1079#define DEVLINK_TRAP_GROUP_GENERIC_NAME_VRRP \
1080 "vrrp"
1081#define DEVLINK_TRAP_GROUP_GENERIC_NAME_PIM \
1082 "pim"
1083#define DEVLINK_TRAP_GROUP_GENERIC_NAME_UC_LB \
1084 "uc_loopback"
1085#define DEVLINK_TRAP_GROUP_GENERIC_NAME_LOCAL_DELIVERY \
1086 "local_delivery"
ec4f5b36
IS
1087#define DEVLINK_TRAP_GROUP_GENERIC_NAME_EXTERNAL_DELIVERY \
1088 "external_delivery"
d77cfd16
IS
1089#define DEVLINK_TRAP_GROUP_GENERIC_NAME_IPV6 \
1090 "ipv6"
1091#define DEVLINK_TRAP_GROUP_GENERIC_NAME_PTP_EVENT \
1092 "ptp_event"
1093#define DEVLINK_TRAP_GROUP_GENERIC_NAME_PTP_GENERAL \
1094 "ptp_general"
5eb18a2b
IS
1095#define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_SAMPLE \
1096 "acl_sample"
1097#define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_TRAP \
1098 "acl_trap"
10c24eb2
IC
1099#define DEVLINK_TRAP_GROUP_GENERIC_NAME_PARSER_ERROR_DROPS \
1100 "parser_error_drops"
391203ab 1101
107f1678
IS
1102#define DEVLINK_TRAP_GENERIC(_type, _init_action, _id, _group_id, \
1103 _metadata_cap) \
0f420b6c
IS
1104 { \
1105 .type = DEVLINK_TRAP_TYPE_##_type, \
1106 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
1107 .generic = true, \
1108 .id = DEVLINK_TRAP_GENERIC_ID_##_id, \
1109 .name = DEVLINK_TRAP_GENERIC_NAME_##_id, \
107f1678 1110 .init_group_id = _group_id, \
0f420b6c
IS
1111 .metadata_cap = _metadata_cap, \
1112 }
1113
107f1678 1114#define DEVLINK_TRAP_DRIVER(_type, _init_action, _id, _name, _group_id, \
0f420b6c
IS
1115 _metadata_cap) \
1116 { \
1117 .type = DEVLINK_TRAP_TYPE_##_type, \
1118 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
1119 .generic = false, \
1120 .id = _id, \
1121 .name = _name, \
107f1678 1122 .init_group_id = _group_id, \
0f420b6c
IS
1123 .metadata_cap = _metadata_cap, \
1124 }
1125
f9f54392 1126#define DEVLINK_TRAP_GROUP_GENERIC(_id, _policer_id) \
0f420b6c
IS
1127 { \
1128 .name = DEVLINK_TRAP_GROUP_GENERIC_NAME_##_id, \
1129 .id = DEVLINK_TRAP_GROUP_GENERIC_ID_##_id, \
1130 .generic = true, \
f9f54392 1131 .init_policer_id = _policer_id, \
0f420b6c
IS
1132 }
1133
1e8c6619
IS
1134#define DEVLINK_TRAP_POLICER(_id, _rate, _burst, _max_rate, _min_rate, \
1135 _max_burst, _min_burst) \
1136 { \
1137 .id = _id, \
1138 .init_rate = _rate, \
1139 .init_burst = _burst, \
1140 .max_rate = _max_rate, \
1141 .min_rate = _min_rate, \
1142 .max_burst = _max_burst, \
1143 .min_burst = _min_burst, \
1144 }
1145
bfcd3a46 1146struct devlink_ops {
22ec3d23
JK
1147 /**
1148 * @supported_flash_update_params:
1149 * mask of parameters supported by the driver's .flash_update
1150 * implemementation.
1151 */
1152 u32 supported_flash_update_params;
070c63f2 1153 int (*reload_down)(struct devlink *devlink, bool netns_change,
97691069
JP
1154 struct netlink_ext_ack *extack);
1155 int (*reload_up)(struct devlink *devlink,
1156 struct netlink_ext_ack *extack);
bfcd3a46
JP
1157 int (*port_type_set)(struct devlink_port *devlink_port,
1158 enum devlink_port_type port_type);
1159 int (*port_split)(struct devlink *devlink, unsigned int port_index,
ac0fc8a1
DA
1160 unsigned int count, struct netlink_ext_ack *extack);
1161 int (*port_unsplit)(struct devlink *devlink, unsigned int port_index,
1162 struct netlink_ext_ack *extack);
bf797471
JP
1163 int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
1164 u16 pool_index,
1165 struct devlink_sb_pool_info *pool_info);
1166 int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
1167 u16 pool_index, u32 size,
f2ad1a52
IS
1168 enum devlink_sb_threshold_type threshold_type,
1169 struct netlink_ext_ack *extack);
bf797471
JP
1170 int (*sb_port_pool_get)(struct devlink_port *devlink_port,
1171 unsigned int sb_index, u16 pool_index,
1172 u32 *p_threshold);
1173 int (*sb_port_pool_set)(struct devlink_port *devlink_port,
1174 unsigned int sb_index, u16 pool_index,
f2ad1a52 1175 u32 threshold, struct netlink_ext_ack *extack);
bf797471
JP
1176 int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
1177 unsigned int sb_index,
1178 u16 tc_index,
1179 enum devlink_sb_pool_type pool_type,
1180 u16 *p_pool_index, u32 *p_threshold);
1181 int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
1182 unsigned int sb_index,
1183 u16 tc_index,
1184 enum devlink_sb_pool_type pool_type,
f2ad1a52
IS
1185 u16 pool_index, u32 threshold,
1186 struct netlink_ext_ack *extack);
df38dafd
JP
1187 int (*sb_occ_snapshot)(struct devlink *devlink,
1188 unsigned int sb_index);
1189 int (*sb_occ_max_clear)(struct devlink *devlink,
1190 unsigned int sb_index);
1191 int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
1192 unsigned int sb_index, u16 pool_index,
1193 u32 *p_cur, u32 *p_max);
1194 int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
1195 unsigned int sb_index,
1196 u16 tc_index,
1197 enum devlink_sb_pool_type pool_type,
1198 u32 *p_cur, u32 *p_max);
08f4b591
OG
1199
1200 int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
db7ff19e
EB
1201 int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
1202 struct netlink_ext_ack *extack);
59bfde01 1203 int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
db7ff19e
EB
1204 int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
1205 struct netlink_ext_ack *extack);
98fdbea5
LR
1206 int (*eswitch_encap_mode_get)(struct devlink *devlink,
1207 enum devlink_eswitch_encap_mode *p_encap_mode);
1208 int (*eswitch_encap_mode_set)(struct devlink *devlink,
1209 enum devlink_eswitch_encap_mode encap_mode,
db7ff19e 1210 struct netlink_ext_ack *extack);
f9cf2288
JK
1211 int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
1212 struct netlink_ext_ack *extack);
22ec3d23
JK
1213 /**
1214 * @flash_update: Device flash update function
1215 *
1216 * Used to perform a flash update for the device. The set of
1217 * parameters supported by the driver should be set in
1218 * supported_flash_update_params.
1219 */
bc75c054
JK
1220 int (*flash_update)(struct devlink *devlink,
1221 struct devlink_flash_update_params *params,
76726ccb 1222 struct netlink_ext_ack *extack);
0f420b6c
IS
1223 /**
1224 * @trap_init: Trap initialization function.
1225 *
1226 * Should be used by device drivers to initialize the trap in the
1227 * underlying device. Drivers should also store the provided trap
1228 * context, so that they could efficiently pass it to
1229 * devlink_trap_report() when the trap is triggered.
1230 */
1231 int (*trap_init)(struct devlink *devlink,
1232 const struct devlink_trap *trap, void *trap_ctx);
1233 /**
1234 * @trap_fini: Trap de-initialization function.
1235 *
1236 * Should be used by device drivers to de-initialize the trap in the
1237 * underlying device.
1238 */
1239 void (*trap_fini)(struct devlink *devlink,
1240 const struct devlink_trap *trap, void *trap_ctx);
1241 /**
1242 * @trap_action_set: Trap action set function.
1243 */
1244 int (*trap_action_set)(struct devlink *devlink,
1245 const struct devlink_trap *trap,
c88e11e0
IS
1246 enum devlink_trap_action action,
1247 struct netlink_ext_ack *extack);
0f420b6c
IS
1248 /**
1249 * @trap_group_init: Trap group initialization function.
1250 *
1251 * Should be used by device drivers to initialize the trap group in the
1252 * underlying device.
1253 */
1254 int (*trap_group_init)(struct devlink *devlink,
1255 const struct devlink_trap_group *group);
c064875a
IS
1256 /**
1257 * @trap_group_set: Trap group parameters set function.
1258 *
1259 * Note: @policer can be NULL when a policer is being unbound from
1260 * @group.
1261 */
1262 int (*trap_group_set)(struct devlink *devlink,
1263 const struct devlink_trap_group *group,
c88e11e0
IS
1264 const struct devlink_trap_policer *policer,
1265 struct netlink_ext_ack *extack);
c50bf2be
IC
1266 /**
1267 * @trap_group_action_set: Trap group action set function.
1268 *
1269 * If this callback is populated, it will take precedence over looping
1270 * over all traps in a group and calling .trap_action_set().
1271 */
1272 int (*trap_group_action_set)(struct devlink *devlink,
1273 const struct devlink_trap_group *group,
1274 enum devlink_trap_action action,
1275 struct netlink_ext_ack *extack);
1e8c6619
IS
1276 /**
1277 * @trap_policer_init: Trap policer initialization function.
1278 *
1279 * Should be used by device drivers to initialize the trap policer in
1280 * the underlying device.
1281 */
1282 int (*trap_policer_init)(struct devlink *devlink,
1283 const struct devlink_trap_policer *policer);
1284 /**
1285 * @trap_policer_fini: Trap policer de-initialization function.
1286 *
1287 * Should be used by device drivers to de-initialize the trap policer
1288 * in the underlying device.
1289 */
1290 void (*trap_policer_fini)(struct devlink *devlink,
1291 const struct devlink_trap_policer *policer);
1292 /**
1293 * @trap_policer_set: Trap policer parameters set function.
1294 */
1295 int (*trap_policer_set)(struct devlink *devlink,
1296 const struct devlink_trap_policer *policer,
1297 u64 rate, u64 burst,
1298 struct netlink_ext_ack *extack);
1299 /**
1300 * @trap_policer_counter_get: Trap policer counter get function.
1301 *
1302 * Should be used by device drivers to report number of packets dropped
1303 * by the policer.
1304 */
1305 int (*trap_policer_counter_get)(struct devlink *devlink,
1306 const struct devlink_trap_policer *policer,
1307 u64 *p_drops);
2a916ecc
PP
1308 /**
1309 * @port_function_hw_addr_get: Port function's hardware address get function.
1310 *
1311 * Should be used by device drivers to report the hardware address of a function managed
1312 * by the devlink port. Driver should return -EOPNOTSUPP if it doesn't support port
1313 * function handling for a particular port.
1314 *
1315 * Note: @extack can be NULL when port notifier queries the port function.
1316 */
1317 int (*port_function_hw_addr_get)(struct devlink *devlink, struct devlink_port *port,
1318 u8 *hw_addr, int *hw_addr_len,
1319 struct netlink_ext_ack *extack);
a1e8ae90
PP
1320 /**
1321 * @port_function_hw_addr_set: Port function's hardware address set function.
1322 *
1323 * Should be used by device drivers to set the hardware address of a function managed
1324 * by the devlink port. Driver should return -EOPNOTSUPP if it doesn't support port
1325 * function handling for a particular port.
1326 */
1327 int (*port_function_hw_addr_set)(struct devlink *devlink, struct devlink_port *port,
1328 const u8 *hw_addr, int hw_addr_len,
1329 struct netlink_ext_ack *extack);
bfcd3a46
JP
1330};
1331
1332static inline void *devlink_priv(struct devlink *devlink)
1333{
1334 BUG_ON(!devlink);
1335 return &devlink->priv;
1336}
1337
1338static inline struct devlink *priv_to_devlink(void *priv)
1339{
1340 BUG_ON(!priv);
1341 return container_of(priv, struct devlink, priv);
1342}
1343
5dc37bb9
JP
1344static inline struct devlink_port *
1345netdev_to_devlink_port(struct net_device *dev)
1346{
1347 if (dev->netdev_ops->ndo_get_devlink_port)
1348 return dev->netdev_ops->ndo_get_devlink_port(dev);
1349 return NULL;
1350}
1351
b473b0d2
JK
1352static inline struct devlink *netdev_to_devlink(struct net_device *dev)
1353{
5dc37bb9
JP
1354 struct devlink_port *devlink_port = netdev_to_devlink_port(dev);
1355
1356 if (devlink_port)
1357 return devlink_port->devlink;
b473b0d2
JK
1358 return NULL;
1359}
1360
bfcd3a46
JP
1361struct ib_device;
1362
471f894f 1363struct net *devlink_net(const struct devlink *devlink);
8273fd84 1364void devlink_net_set(struct devlink *devlink, struct net *net);
bfcd3a46
JP
1365struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
1366int devlink_register(struct devlink *devlink, struct device *dev);
1367void devlink_unregister(struct devlink *devlink);
a0c76345
JP
1368void devlink_reload_enable(struct devlink *devlink);
1369void devlink_reload_disable(struct devlink *devlink);
bfcd3a46
JP
1370void devlink_free(struct devlink *devlink);
1371int devlink_port_register(struct devlink *devlink,
1372 struct devlink_port *devlink_port,
1373 unsigned int port_index);
1374void devlink_port_unregister(struct devlink_port *devlink_port);
1375void devlink_port_type_eth_set(struct devlink_port *devlink_port,
1376 struct net_device *netdev);
1377void devlink_port_type_ib_set(struct devlink_port *devlink_port,
1378 struct ib_device *ibdev);
1379void devlink_port_type_clear(struct devlink_port *devlink_port);
b9ffcbaf 1380void devlink_port_attrs_set(struct devlink_port *devlink_port,
71ad8d55 1381 struct devlink_port_attrs *devlink_port_attrs);
3a2d9588
PP
1382void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u32 controller,
1383 u16 pf, bool external);
1384void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 controller,
05b595e9 1385 u16 pf, u16 vf, bool external);
bf797471
JP
1386int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
1387 u32 size, u16 ingress_pools_count,
1388 u16 egress_pools_count, u16 ingress_tc_count,
1389 u16 egress_tc_count);
1390void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
1555d204
AS
1391int devlink_dpipe_table_register(struct devlink *devlink,
1392 const char *table_name,
1393 struct devlink_dpipe_table_ops *table_ops,
ffd3cdcc 1394 void *priv, bool counter_control_extern);
1555d204
AS
1395void devlink_dpipe_table_unregister(struct devlink *devlink,
1396 const char *table_name);
1397int devlink_dpipe_headers_register(struct devlink *devlink,
1398 struct devlink_dpipe_headers *dpipe_headers);
1399void devlink_dpipe_headers_unregister(struct devlink *devlink);
1400bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
1401 const char *table_name);
1402int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
1403int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
1404 struct devlink_dpipe_entry *entry);
1405int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
35807324 1406void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
1555d204
AS
1407int devlink_dpipe_action_put(struct sk_buff *skb,
1408 struct devlink_dpipe_action *action);
1409int devlink_dpipe_match_put(struct sk_buff *skb,
1410 struct devlink_dpipe_match *match);
11770091 1411extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
3fb886ec 1412extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
1797f5b3 1413extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
bfcd3a46 1414
d9f9b9a4
AS
1415int devlink_resource_register(struct devlink *devlink,
1416 const char *resource_name,
d9f9b9a4
AS
1417 u64 resource_size,
1418 u64 resource_id,
1419 u64 parent_resource_id,
fc56be47 1420 const struct devlink_resource_size_params *size_params);
d9f9b9a4
AS
1421void devlink_resources_unregister(struct devlink *devlink,
1422 struct devlink_resource *resource);
1423int devlink_resource_size_get(struct devlink *devlink,
1424 u64 resource_id,
1425 u64 *p_resource_size);
56dc7cd0
AS
1426int devlink_dpipe_table_resource_set(struct devlink *devlink,
1427 const char *table_name, u64 resource_id,
1428 u64 resource_units);
fc56be47
JP
1429void devlink_resource_occ_get_register(struct devlink *devlink,
1430 u64 resource_id,
1431 devlink_resource_occ_get_t *occ_get,
1432 void *occ_get_priv);
1433void devlink_resource_occ_get_unregister(struct devlink *devlink,
1434 u64 resource_id);
eabaef18
MS
1435int devlink_params_register(struct devlink *devlink,
1436 const struct devlink_param *params,
1437 size_t params_count);
1438void devlink_params_unregister(struct devlink *devlink,
1439 const struct devlink_param *params,
1440 size_t params_count);
7c62cfb8
JP
1441void devlink_params_publish(struct devlink *devlink);
1442void devlink_params_unpublish(struct devlink *devlink);
39e6160e
VV
1443int devlink_port_params_register(struct devlink_port *devlink_port,
1444 const struct devlink_param *params,
1445 size_t params_count);
1446void devlink_port_params_unregister(struct devlink_port *devlink_port,
1447 const struct devlink_param *params,
1448 size_t params_count);
ec01aeb1
MS
1449int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
1450 union devlink_param_value *init_val);
1451int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
1452 union devlink_param_value init_val);
ffd19b9a
VV
1453int
1454devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
1455 u32 param_id,
1456 union devlink_param_value *init_val);
5473a7bd
VV
1457int devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
1458 u32 param_id,
1459 union devlink_param_value init_val);
ea601e17 1460void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
c1e5786d
VV
1461void devlink_port_param_value_changed(struct devlink_port *devlink_port,
1462 u32 param_id);
bde74ad1
MS
1463void devlink_param_value_str_fill(union devlink_param_value *dst_val,
1464 const char *src);
e8937681
JK
1465struct devlink_region *
1466devlink_region_create(struct devlink *devlink,
1467 const struct devlink_region_ops *ops,
1468 u32 region_max_snapshots, u64 region_size);
544e7c33
AL
1469struct devlink_region *
1470devlink_port_region_create(struct devlink_port *port,
1471 const struct devlink_port_region_ops *ops,
1472 u32 region_max_snapshots, u64 region_size);
b16ebe92 1473void devlink_region_destroy(struct devlink_region *region);
544e7c33
AL
1474void devlink_port_region_destroy(struct devlink_region *region);
1475
7ef19d3b 1476int devlink_region_snapshot_id_get(struct devlink *devlink, u32 *id);
12102436 1477void devlink_region_snapshot_id_put(struct devlink *devlink, u32 id);
3a5e5234 1478int devlink_region_snapshot_create(struct devlink_region *region,
a0a09f6b 1479 u8 *data, u32 snapshot_id);
f9cf2288
JK
1480int devlink_info_serial_number_put(struct devlink_info_req *req,
1481 const char *sn);
1482int devlink_info_driver_name_put(struct devlink_info_req *req,
1483 const char *name);
b5872cd0
VV
1484int devlink_info_board_serial_number_put(struct devlink_info_req *req,
1485 const char *bsn);
fc6fae7d
JK
1486int devlink_info_version_fixed_put(struct devlink_info_req *req,
1487 const char *version_name,
1488 const char *version_value);
1489int devlink_info_version_stored_put(struct devlink_info_req *req,
1490 const char *version_name,
1491 const char *version_value);
1492int devlink_info_version_running_put(struct devlink_info_req *req,
1493 const char *version_name,
1494 const char *version_value);
d9f9b9a4 1495
1db64e87
EBE
1496int devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg);
1497int devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg);
1498
1499int devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name);
1500int devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg);
1501
1502int devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg,
1503 const char *name);
1504int devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg);
573ed90a
AL
1505int devlink_fmsg_binary_pair_nest_start(struct devlink_fmsg *fmsg,
1506 const char *name);
1507int devlink_fmsg_binary_pair_nest_end(struct devlink_fmsg *fmsg);
1db64e87
EBE
1508
1509int devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value);
1510int devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value);
1511int devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value);
1512int devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value);
1513int devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value);
573ed90a
AL
1514int devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value,
1515 u16 value_len);
1db64e87
EBE
1516
1517int devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name,
1518 bool value);
1519int devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name,
1520 u8 value);
1521int devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name,
1522 u32 value);
1523int devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name,
1524 u64 value);
1525int devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,
1526 const char *value);
1527int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
e2cde864 1528 const void *value, u32 value_len);
1db64e87 1529
a0bdcc59
EBE
1530struct devlink_health_reporter *
1531devlink_health_reporter_create(struct devlink *devlink,
1532 const struct devlink_health_reporter_ops *ops,
ba7d16c7 1533 u64 graceful_period, void *priv);
15c724b9
VT
1534
1535struct devlink_health_reporter *
1536devlink_port_health_reporter_create(struct devlink_port *port,
1537 const struct devlink_health_reporter_ops *ops,
1538 u64 graceful_period, void *priv);
1539
a0bdcc59
EBE
1540void
1541devlink_health_reporter_destroy(struct devlink_health_reporter *reporter);
1542
15c724b9
VT
1543void
1544devlink_port_health_reporter_destroy(struct devlink_health_reporter *reporter);
1545
a0bdcc59
EBE
1546void *
1547devlink_health_reporter_priv(struct devlink_health_reporter *reporter);
c8e1da0b
EBE
1548int devlink_health_report(struct devlink_health_reporter *reporter,
1549 const char *msg, void *priv_ctx);
3167b27a
EBE
1550void
1551devlink_health_reporter_state_update(struct devlink_health_reporter *reporter,
1552 enum devlink_health_reporter_state state);
6181e5cb
VG
1553void
1554devlink_health_reporter_recovery_done(struct devlink_health_reporter *reporter);
a0bdcc59 1555
2670ac26
JP
1556bool devlink_is_reload_failed(const struct devlink *devlink);
1557
191ed202
JP
1558void devlink_flash_update_begin_notify(struct devlink *devlink);
1559void devlink_flash_update_end_notify(struct devlink *devlink);
1560void devlink_flash_update_status_notify(struct devlink *devlink,
1561 const char *status_msg,
1562 const char *component,
1563 unsigned long done,
1564 unsigned long total);
f92970c6
SN
1565void devlink_flash_update_timeout_notify(struct devlink *devlink,
1566 const char *status_msg,
1567 const char *component,
1568 unsigned long timeout);
191ed202 1569
0f420b6c
IS
1570int devlink_traps_register(struct devlink *devlink,
1571 const struct devlink_trap *traps,
1572 size_t traps_count, void *priv);
1573void devlink_traps_unregister(struct devlink *devlink,
1574 const struct devlink_trap *traps,
1575 size_t traps_count);
5a2e106c
JP
1576void devlink_trap_report(struct devlink *devlink, struct sk_buff *skb,
1577 void *trap_ctx, struct devlink_port *in_devlink_port,
1578 const struct flow_action_cookie *fa_cookie);
0f420b6c 1579void *devlink_trap_ctx_priv(void *trap_ctx);
95ad9555
IS
1580int devlink_trap_groups_register(struct devlink *devlink,
1581 const struct devlink_trap_group *groups,
1582 size_t groups_count);
1583void devlink_trap_groups_unregister(struct devlink *devlink,
1584 const struct devlink_trap_group *groups,
1585 size_t groups_count);
1e8c6619
IS
1586int
1587devlink_trap_policers_register(struct devlink *devlink,
1588 const struct devlink_trap_policer *policers,
1589 size_t policers_count);
1590void
1591devlink_trap_policers_unregister(struct devlink *devlink,
1592 const struct devlink_trap_policer *policers,
1593 size_t policers_count);
0f420b6c 1594
f6b19b35
JP
1595#if IS_ENABLED(CONFIG_NET_DEVLINK)
1596
f4b6bcc7
JK
1597void devlink_compat_running_version(struct net_device *dev,
1598 char *buf, size_t len);
1599int devlink_compat_flash_update(struct net_device *dev, const char *file_name);
af3836df
JP
1600int devlink_compat_phys_port_name_get(struct net_device *dev,
1601 char *name, size_t len);
7e1146e8
JP
1602int devlink_compat_switch_id_get(struct net_device *dev,
1603 struct netdev_phys_item_id *ppid);
f4b6bcc7 1604
bfcd3a46
JP
1605#else
1606
ddb6e99e
JK
1607static inline void
1608devlink_compat_running_version(struct net_device *dev, char *buf, size_t len)
1609{
1610}
4eceba17
JK
1611
1612static inline int
1613devlink_compat_flash_update(struct net_device *dev, const char *file_name)
1614{
1615 return -EOPNOTSUPP;
1616}
f6b19b35 1617
af3836df
JP
1618static inline int
1619devlink_compat_phys_port_name_get(struct net_device *dev,
1620 char *name, size_t len)
1621{
1622 return -EOPNOTSUPP;
1623}
1624
7e1146e8
JP
1625static inline int
1626devlink_compat_switch_id_get(struct net_device *dev,
1627 struct netdev_phys_item_id *ppid)
1628{
1629 return -EOPNOTSUPP;
1630}
1631
ddb6e99e
JK
1632#endif
1633
bfcd3a46 1634#endif /* _NET_DEVLINK_H_ */