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