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