Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0-or-later */
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>
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>
15#include <linux/spinlock.h>
16#include <linux/workqueue.h>
17#include <linux/refcount.h>
18#include <net/net_namespace.h>
19#include <net/flow_offload.h>
20#include <uapi/linux/devlink.h>
21#include <linux/xarray.h>
22#include <linux/firmware.h>
23
24struct devlink;
25struct devlink_linecard;
26
27struct devlink_port_phys_attrs {
28 u32 port_number; /* Same value as "split group".
29 * A physical port which is visible to the user
30 * for a given port flavour.
31 */
32 u32 split_subport_number; /* If the port is split, this is the number of subport. */
33};
34
35/**
36 * struct devlink_port_pci_pf_attrs - devlink port's PCI PF attributes
37 * @controller: Associated controller number
38 * @pf: associated PCI function number for the devlink port instance
39 * @external: when set, indicates if a port is for an external controller
40 */
41struct devlink_port_pci_pf_attrs {
42 u32 controller;
43 u16 pf;
44 u8 external:1;
45};
46
47/**
48 * struct devlink_port_pci_vf_attrs - devlink port's PCI VF attributes
49 * @controller: Associated controller number
50 * @pf: associated PCI function number for the devlink port instance
51 * @vf: associated PCI VF number of a PF for the devlink port instance;
52 * VF number starts from 0 for the first PCI virtual function
53 * @external: when set, indicates if a port is for an external controller
54 */
55struct devlink_port_pci_vf_attrs {
56 u32 controller;
57 u16 pf;
58 u16 vf;
59 u8 external:1;
60};
61
62/**
63 * struct devlink_port_pci_sf_attrs - devlink port's PCI SF attributes
64 * @controller: Associated controller number
65 * @sf: associated SF number of a PF for the devlink port instance
66 * @pf: associated PCI function number for the devlink port instance
67 * @external: when set, indicates if a port is for an external controller
68 */
69struct devlink_port_pci_sf_attrs {
70 u32 controller;
71 u32 sf;
72 u16 pf;
73 u8 external:1;
74};
75
76/**
77 * struct devlink_port_attrs - devlink port object
78 * @flavour: flavour of the port
79 * @split: indicates if this is split port
80 * @splittable: indicates if the port can be split.
81 * @no_phys_port_name: skip automatic phys_port_name generation; for
82 * compatibility only, newly added driver/port instance
83 * should never set this.
84 * @lanes: maximum number of lanes the port supports. 0 value is not passed to netlink.
85 * @switch_id: if the port is part of switch, this is buffer with ID, otherwise this is NULL
86 * @phys: physical port attributes
87 * @pci_pf: PCI PF port attributes
88 * @pci_vf: PCI VF port attributes
89 * @pci_sf: PCI SF port attributes
90 */
91struct devlink_port_attrs {
92 u8 split:1,
93 splittable:1,
94 no_phys_port_name:1;
95 u32 lanes;
96 enum devlink_port_flavour flavour;
97 struct netdev_phys_item_id switch_id;
98 union {
99 struct devlink_port_phys_attrs phys;
100 struct devlink_port_pci_pf_attrs pci_pf;
101 struct devlink_port_pci_vf_attrs pci_vf;
102 struct devlink_port_pci_sf_attrs pci_sf;
103 };
104};
105
106struct devlink_rate {
107 struct list_head list;
108 enum devlink_rate_type type;
109 struct devlink *devlink;
110 void *priv;
111 u64 tx_share;
112 u64 tx_max;
113
114 struct devlink_rate *parent;
115 union {
116 struct devlink_port *devlink_port;
117 struct {
118 char *name;
119 refcount_t refcnt;
120 };
121 };
122
123 u32 tx_priority;
124 u32 tx_weight;
125
126 u32 tc_bw[DEVLINK_RATE_TCS_MAX];
127};
128
129struct devlink_port {
130 struct list_head list;
131 struct list_head region_list;
132 struct list_head resource_list;
133 struct devlink *devlink;
134 const struct devlink_port_ops *ops;
135 unsigned int index;
136 spinlock_t type_lock; /* Protects type and type_eth/ib
137 * structures consistency.
138 */
139 enum devlink_port_type type;
140 enum devlink_port_type desired_type;
141 union {
142 struct {
143 struct net_device *netdev;
144 int ifindex;
145 char ifname[IFNAMSIZ];
146 } type_eth;
147 struct {
148 struct ib_device *ibdev;
149 } type_ib;
150 };
151 struct devlink_port_attrs attrs;
152 u8 attrs_set:1,
153 switch_port:1,
154 registered:1,
155 initialized:1;
156 struct delayed_work type_warn_dw;
157 struct list_head reporter_list;
158
159 struct devlink_rate *devlink_rate;
160 struct devlink_linecard *linecard;
161 u32 rel_index;
162};
163
164struct devlink_port_new_attrs {
165 enum devlink_port_flavour flavour;
166 unsigned int port_index;
167 u32 controller;
168 u32 sfnum;
169 u16 pfnum;
170 u8 port_index_valid:1,
171 controller_valid:1,
172 sfnum_valid:1;
173};
174
175/**
176 * struct devlink_linecard_ops - Linecard operations
177 * @provision: callback to provision the linecard slot with certain
178 * type of linecard. As a result of this operation,
179 * driver is expected to eventually (could be after
180 * the function call returns) call one of:
181 * devlink_linecard_provision_set()
182 * devlink_linecard_provision_fail()
183 * @unprovision: callback to unprovision the linecard slot. As a result
184 * of this operation, driver is expected to eventually
185 * (could be after the function call returns) call
186 * devlink_linecard_provision_clear()
187 * devlink_linecard_provision_fail()
188 * @same_provision: callback to ask the driver if linecard is already
189 * provisioned in the same way user asks this linecard to be
190 * provisioned.
191 * @types_count: callback to get number of supported types
192 * @types_get: callback to get next type in list
193 */
194struct devlink_linecard_ops {
195 int (*provision)(struct devlink_linecard *linecard, void *priv,
196 const char *type, const void *type_priv,
197 struct netlink_ext_ack *extack);
198 int (*unprovision)(struct devlink_linecard *linecard, void *priv,
199 struct netlink_ext_ack *extack);
200 bool (*same_provision)(struct devlink_linecard *linecard, void *priv,
201 const char *type, const void *type_priv);
202 unsigned int (*types_count)(struct devlink_linecard *linecard,
203 void *priv);
204 void (*types_get)(struct devlink_linecard *linecard,
205 void *priv, unsigned int index, const char **type,
206 const void **type_priv);
207};
208
209struct devlink_sb_pool_info {
210 enum devlink_sb_pool_type pool_type;
211 u32 size;
212 enum devlink_sb_threshold_type threshold_type;
213 u32 cell_size;
214};
215
216/**
217 * struct devlink_dpipe_field - dpipe field object
218 * @name: field name
219 * @id: index inside the headers field array
220 * @bitwidth: bitwidth
221 * @mapping_type: mapping type
222 */
223struct devlink_dpipe_field {
224 const char *name;
225 unsigned int id;
226 unsigned int bitwidth;
227 enum devlink_dpipe_field_mapping_type mapping_type;
228};
229
230/**
231 * struct devlink_dpipe_header - dpipe header object
232 * @name: header name
233 * @id: index, global/local determined by global bit
234 * @fields: fields
235 * @fields_count: number of fields
236 * @global: indicates if header is shared like most protocol header
237 * or driver specific
238 */
239struct devlink_dpipe_header {
240 const char *name;
241 unsigned int id;
242 struct devlink_dpipe_field *fields;
243 unsigned int fields_count;
244 bool global;
245};
246
247/**
248 * struct devlink_dpipe_match - represents match operation
249 * @type: type of match
250 * @header_index: header index (packets can have several headers of same
251 * type like in case of tunnels)
252 * @header: header
253 * @field_id: field index
254 */
255struct devlink_dpipe_match {
256 enum devlink_dpipe_match_type type;
257 unsigned int header_index;
258 struct devlink_dpipe_header *header;
259 unsigned int field_id;
260};
261
262/**
263 * struct devlink_dpipe_action - represents action operation
264 * @type: type of action
265 * @header_index: header index (packets can have several headers of same
266 * type like in case of tunnels)
267 * @header: header
268 * @field_id: field index
269 */
270struct devlink_dpipe_action {
271 enum devlink_dpipe_action_type type;
272 unsigned int header_index;
273 struct devlink_dpipe_header *header;
274 unsigned int field_id;
275};
276
277/**
278 * struct devlink_dpipe_value - represents value of match/action
279 * @action: action
280 * @match: match
281 * @mapping_value: in case the field has some mapping this value
282 * specified the mapping value
283 * @mapping_valid: specify if mapping value is valid
284 * @value_size: value size
285 * @value: value
286 * @mask: bit mask
287 */
288struct devlink_dpipe_value {
289 union {
290 struct devlink_dpipe_action *action;
291 struct devlink_dpipe_match *match;
292 };
293 unsigned int mapping_value;
294 bool mapping_valid;
295 unsigned int value_size;
296 void *value;
297 void *mask;
298};
299
300/**
301 * struct devlink_dpipe_entry - table entry object
302 * @index: index of the entry in the table
303 * @match_values: match values
304 * @match_values_count: count of matches tuples
305 * @action_values: actions values
306 * @action_values_count: count of actions values
307 * @counter: value of counter
308 * @counter_valid: Specify if value is valid from hardware
309 */
310struct devlink_dpipe_entry {
311 u64 index;
312 struct devlink_dpipe_value *match_values;
313 unsigned int match_values_count;
314 struct devlink_dpipe_value *action_values;
315 unsigned int action_values_count;
316 u64 counter;
317 bool counter_valid;
318};
319
320/**
321 * struct devlink_dpipe_dump_ctx - context provided to driver in order
322 * to dump
323 * @info: info
324 * @cmd: devlink command
325 * @skb: skb
326 * @nest: top attribute
327 * @hdr: hdr
328 */
329struct devlink_dpipe_dump_ctx {
330 struct genl_info *info;
331 enum devlink_command cmd;
332 struct sk_buff *skb;
333 struct nlattr *nest;
334 void *hdr;
335};
336
337struct devlink_dpipe_table_ops;
338
339/**
340 * struct devlink_dpipe_table - table object
341 * @priv: private
342 * @name: table name
343 * @counters_enabled: indicates if counters are active
344 * @counter_control_extern: indicates if counter control is in dpipe or
345 * external tool
346 * @resource_valid: Indicate that the resource id is valid
347 * @resource_id: relative resource this table is related to
348 * @resource_units: number of resource's unit consumed per table's entry
349 * @table_ops: table operations
350 * @rcu: rcu
351 */
352struct devlink_dpipe_table {
353 void *priv;
354 /* private: */
355 struct list_head list;
356 /* public: */
357 const char *name;
358 bool counters_enabled;
359 bool counter_control_extern;
360 bool resource_valid;
361 u64 resource_id;
362 u64 resource_units;
363 const struct devlink_dpipe_table_ops *table_ops;
364 struct rcu_head rcu;
365};
366
367/**
368 * struct devlink_dpipe_table_ops - dpipe_table ops
369 * @actions_dump: dumps all tables actions
370 * @matches_dump: dumps all tables matches
371 * @entries_dump: dumps all active entries in the table
372 * @counters_set_update: when changing the counter status hardware sync
373 * maybe needed to allocate/free counter related
374 * resources
375 * @size_get: get size
376 */
377struct devlink_dpipe_table_ops {
378 int (*actions_dump)(void *priv, struct sk_buff *skb);
379 int (*matches_dump)(void *priv, struct sk_buff *skb);
380 int (*entries_dump)(void *priv, bool counters_enabled,
381 struct devlink_dpipe_dump_ctx *dump_ctx);
382 int (*counters_set_update)(void *priv, bool enable);
383 u64 (*size_get)(void *priv);
384};
385
386/**
387 * struct devlink_dpipe_headers - dpipe headers
388 * @headers: header array can be shared (global bit) or driver specific
389 * @headers_count: count of headers
390 */
391struct devlink_dpipe_headers {
392 struct devlink_dpipe_header **headers;
393 unsigned int headers_count;
394};
395
396/**
397 * struct devlink_resource_size_params - resource's size parameters
398 * @size_min: minimum size which can be set
399 * @size_max: maximum size which can be set
400 * @size_granularity: size granularity
401 * @unit: resource's basic unit
402 */
403struct devlink_resource_size_params {
404 u64 size_min;
405 u64 size_max;
406 u64 size_granularity;
407 enum devlink_resource_unit unit;
408};
409
410static inline void
411devlink_resource_size_params_init(struct devlink_resource_size_params *size_params,
412 u64 size_min, u64 size_max,
413 u64 size_granularity,
414 enum devlink_resource_unit unit)
415{
416 size_params->size_min = size_min;
417 size_params->size_max = size_max;
418 size_params->size_granularity = size_granularity;
419 size_params->unit = unit;
420}
421
422typedef u64 devlink_resource_occ_get_t(void *priv);
423
424#define DEVLINK_RESOURCE_ID_PARENT_TOP 0
425
426#define DEVLINK_RESOURCE_GENERIC_NAME_PORTS "physical_ports"
427
428#define __DEVLINK_PARAM_MAX_STRING_VALUE 32
429enum devlink_param_type {
430 DEVLINK_PARAM_TYPE_U8 = DEVLINK_VAR_ATTR_TYPE_U8,
431 DEVLINK_PARAM_TYPE_U16 = DEVLINK_VAR_ATTR_TYPE_U16,
432 DEVLINK_PARAM_TYPE_U32 = DEVLINK_VAR_ATTR_TYPE_U32,
433 DEVLINK_PARAM_TYPE_U64 = DEVLINK_VAR_ATTR_TYPE_U64,
434 DEVLINK_PARAM_TYPE_STRING = DEVLINK_VAR_ATTR_TYPE_STRING,
435 DEVLINK_PARAM_TYPE_BOOL = DEVLINK_VAR_ATTR_TYPE_FLAG,
436};
437
438union devlink_param_value {
439 u8 vu8;
440 u16 vu16;
441 u32 vu32;
442 u64 vu64;
443 char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];
444 bool vbool;
445};
446
447struct devlink_param_gset_ctx {
448 union devlink_param_value val;
449 enum devlink_param_cmode cmode;
450};
451
452/**
453 * struct devlink_flash_notify - devlink dev flash notify data
454 * @status_msg: current status string
455 * @component: firmware component being updated
456 * @done: amount of work completed of total amount
457 * @total: amount of work expected to be done
458 * @timeout: expected max timeout in seconds
459 *
460 * These are values to be given to userland to be displayed in order
461 * to show current activity in a firmware update process.
462 */
463struct devlink_flash_notify {
464 const char *status_msg;
465 const char *component;
466 unsigned long done;
467 unsigned long total;
468 unsigned long timeout;
469};
470
471/**
472 * struct devlink_param - devlink configuration parameter data
473 * @id: devlink parameter id number
474 * @name: name of the parameter
475 * @generic: indicates if the parameter is generic or driver specific
476 * @type: parameter type
477 * @supported_cmodes: bitmap of supported configuration modes
478 * @get: get parameter value, used for runtime and permanent
479 * configuration modes
480 * @set: set parameter value, used for runtime and permanent
481 * configuration modes
482 * @validate: validate input value is applicable (within value range, etc.)
483 * @get_default: get parameter default value, used for runtime and permanent
484 * configuration modes
485 * @reset_default: reset parameter to default value, used for runtime and permanent
486 * configuration modes
487 *
488 * This struct should be used by the driver to fill the data for
489 * a parameter it registers.
490 */
491struct devlink_param {
492 u32 id;
493 const char *name;
494 bool generic;
495 enum devlink_param_type type;
496 unsigned long supported_cmodes;
497 int (*get)(struct devlink *devlink, u32 id,
498 struct devlink_param_gset_ctx *ctx,
499 struct netlink_ext_ack *extack);
500 int (*set)(struct devlink *devlink, u32 id,
501 struct devlink_param_gset_ctx *ctx,
502 struct netlink_ext_ack *extack);
503 int (*validate)(struct devlink *devlink, u32 id,
504 union devlink_param_value val,
505 struct netlink_ext_ack *extack);
506 int (*get_default)(struct devlink *devlink, u32 id,
507 struct devlink_param_gset_ctx *ctx,
508 struct netlink_ext_ack *extack);
509 int (*reset_default)(struct devlink *devlink, u32 id,
510 enum devlink_param_cmode cmode,
511 struct netlink_ext_ack *extack);
512};
513
514struct devlink_param_item {
515 struct list_head list;
516 const struct devlink_param *param;
517 union devlink_param_value driverinit_value;
518 bool driverinit_value_valid;
519 union devlink_param_value driverinit_value_new; /* Not reachable
520 * until reload.
521 */
522 bool driverinit_value_new_valid;
523 union devlink_param_value driverinit_default;
524};
525
526enum devlink_param_generic_id {
527 DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
528 DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
529 DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
530 DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT,
531 DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI,
532 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
533 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
534 DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY,
535 DEVLINK_PARAM_GENERIC_ID_RESET_DEV_ON_DRV_PROBE,
536 DEVLINK_PARAM_GENERIC_ID_ENABLE_ROCE,
537 DEVLINK_PARAM_GENERIC_ID_ENABLE_REMOTE_DEV_RESET,
538 DEVLINK_PARAM_GENERIC_ID_ENABLE_ETH,
539 DEVLINK_PARAM_GENERIC_ID_ENABLE_RDMA,
540 DEVLINK_PARAM_GENERIC_ID_ENABLE_VNET,
541 DEVLINK_PARAM_GENERIC_ID_ENABLE_IWARP,
542 DEVLINK_PARAM_GENERIC_ID_IO_EQ_SIZE,
543 DEVLINK_PARAM_GENERIC_ID_EVENT_EQ_SIZE,
544 DEVLINK_PARAM_GENERIC_ID_ENABLE_PHC,
545 DEVLINK_PARAM_GENERIC_ID_CLOCK_ID,
546 DEVLINK_PARAM_GENERIC_ID_TOTAL_VFS,
547 DEVLINK_PARAM_GENERIC_ID_NUM_DOORBELLS,
548 DEVLINK_PARAM_GENERIC_ID_MAX_MAC_PER_VF,
549
550 /* add new param generic ids above here*/
551 __DEVLINK_PARAM_GENERIC_ID_MAX,
552 DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
553};
554
555#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
556#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
557
558#define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
559#define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
560
561#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
562#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
563
564#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable"
565#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL
566
567#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari"
568#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL
569
570#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max"
571#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32
572
573#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min"
574#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32
575
576#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy"
577#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8
578
579#define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_NAME \
580 "reset_dev_on_drv_probe"
581#define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_TYPE DEVLINK_PARAM_TYPE_U8
582
583#define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_NAME "enable_roce"
584#define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_TYPE DEVLINK_PARAM_TYPE_BOOL
585
586#define DEVLINK_PARAM_GENERIC_ENABLE_REMOTE_DEV_RESET_NAME "enable_remote_dev_reset"
587#define DEVLINK_PARAM_GENERIC_ENABLE_REMOTE_DEV_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
588
589#define DEVLINK_PARAM_GENERIC_ENABLE_ETH_NAME "enable_eth"
590#define DEVLINK_PARAM_GENERIC_ENABLE_ETH_TYPE DEVLINK_PARAM_TYPE_BOOL
591
592#define DEVLINK_PARAM_GENERIC_ENABLE_RDMA_NAME "enable_rdma"
593#define DEVLINK_PARAM_GENERIC_ENABLE_RDMA_TYPE DEVLINK_PARAM_TYPE_BOOL
594
595#define DEVLINK_PARAM_GENERIC_ENABLE_VNET_NAME "enable_vnet"
596#define DEVLINK_PARAM_GENERIC_ENABLE_VNET_TYPE DEVLINK_PARAM_TYPE_BOOL
597
598#define DEVLINK_PARAM_GENERIC_ENABLE_IWARP_NAME "enable_iwarp"
599#define DEVLINK_PARAM_GENERIC_ENABLE_IWARP_TYPE DEVLINK_PARAM_TYPE_BOOL
600
601#define DEVLINK_PARAM_GENERIC_IO_EQ_SIZE_NAME "io_eq_size"
602#define DEVLINK_PARAM_GENERIC_IO_EQ_SIZE_TYPE DEVLINK_PARAM_TYPE_U32
603
604#define DEVLINK_PARAM_GENERIC_EVENT_EQ_SIZE_NAME "event_eq_size"
605#define DEVLINK_PARAM_GENERIC_EVENT_EQ_SIZE_TYPE DEVLINK_PARAM_TYPE_U32
606
607#define DEVLINK_PARAM_GENERIC_ENABLE_PHC_NAME "enable_phc"
608#define DEVLINK_PARAM_GENERIC_ENABLE_PHC_TYPE DEVLINK_PARAM_TYPE_BOOL
609
610#define DEVLINK_PARAM_GENERIC_CLOCK_ID_NAME "clock_id"
611#define DEVLINK_PARAM_GENERIC_CLOCK_ID_TYPE DEVLINK_PARAM_TYPE_U64
612
613#define DEVLINK_PARAM_GENERIC_TOTAL_VFS_NAME "total_vfs"
614#define DEVLINK_PARAM_GENERIC_TOTAL_VFS_TYPE DEVLINK_PARAM_TYPE_U32
615
616#define DEVLINK_PARAM_GENERIC_NUM_DOORBELLS_NAME "num_doorbells"
617#define DEVLINK_PARAM_GENERIC_NUM_DOORBELLS_TYPE DEVLINK_PARAM_TYPE_U32
618
619#define DEVLINK_PARAM_GENERIC_MAX_MAC_PER_VF_NAME "max_mac_per_vf"
620#define DEVLINK_PARAM_GENERIC_MAX_MAC_PER_VF_TYPE DEVLINK_PARAM_TYPE_U32
621
622#define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \
623{ \
624 .id = DEVLINK_PARAM_GENERIC_ID_##_id, \
625 .name = DEVLINK_PARAM_GENERIC_##_id##_NAME, \
626 .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE, \
627 .generic = true, \
628 .supported_cmodes = _cmodes, \
629 .get = _get, \
630 .set = _set, \
631 .validate = _validate, \
632}
633
634#define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate) \
635{ \
636 .id = _id, \
637 .name = _name, \
638 .type = _type, \
639 .supported_cmodes = _cmodes, \
640 .get = _get, \
641 .set = _set, \
642 .validate = _validate, \
643}
644
645#define DEVLINK_PARAM_GENERIC_WITH_DEFAULTS(_id, _cmodes, _get, _set, \
646 _validate, _get_default, \
647 _reset_default) \
648{ \
649 .id = DEVLINK_PARAM_GENERIC_ID_##_id, \
650 .name = DEVLINK_PARAM_GENERIC_##_id##_NAME, \
651 .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE, \
652 .generic = true, \
653 .supported_cmodes = _cmodes, \
654 .get = _get, \
655 .set = _set, \
656 .validate = _validate, \
657 .get_default = _get_default, \
658 .reset_default = _reset_default, \
659}
660
661#define DEVLINK_PARAM_DRIVER_WITH_DEFAULTS(_id, _name, _type, _cmodes, \
662 _get, _set, _validate, \
663 _get_default, _reset_default) \
664{ \
665 .id = _id, \
666 .name = _name, \
667 .type = _type, \
668 .supported_cmodes = _cmodes, \
669 .get = _get, \
670 .set = _set, \
671 .validate = _validate, \
672 .get_default = _get_default, \
673 .reset_default = _reset_default, \
674}
675
676/* Identifier of board design */
677#define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID "board.id"
678/* Revision of board design */
679#define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV "board.rev"
680/* Maker of the board */
681#define DEVLINK_INFO_VERSION_GENERIC_BOARD_MANUFACTURE "board.manufacture"
682/* Part number of the board and its components */
683#define DEVLINK_INFO_VERSION_GENERIC_BOARD_PART_NUMBER "board.part_number"
684
685/* Part number, identifier of asic design */
686#define DEVLINK_INFO_VERSION_GENERIC_ASIC_ID "asic.id"
687/* Revision of asic design */
688#define DEVLINK_INFO_VERSION_GENERIC_ASIC_REV "asic.rev"
689
690/* Overall FW version */
691#define DEVLINK_INFO_VERSION_GENERIC_FW "fw"
692/* Control processor FW version */
693#define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT "fw.mgmt"
694/* FW interface specification version */
695#define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT_API "fw.mgmt.api"
696/* Data path microcode controlling high-speed packet processing */
697#define DEVLINK_INFO_VERSION_GENERIC_FW_APP "fw.app"
698/* UNDI software version */
699#define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI "fw.undi"
700/* NCSI support/handler version */
701#define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI "fw.ncsi"
702/* FW parameter set id */
703#define DEVLINK_INFO_VERSION_GENERIC_FW_PSID "fw.psid"
704/* RoCE FW version */
705#define DEVLINK_INFO_VERSION_GENERIC_FW_ROCE "fw.roce"
706/* Firmware bundle identifier */
707#define DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID "fw.bundle_id"
708/* Bootloader */
709#define DEVLINK_INFO_VERSION_GENERIC_FW_BOOTLOADER "fw.bootloader"
710
711/**
712 * struct devlink_flash_update_params - Flash Update parameters
713 * @fw: pointer to the firmware data to update from
714 * @component: the flash component to update
715 * @overwrite_mask: which types of flash update are supported (may be %0)
716 *
717 * With the exception of fw, drivers must opt-in to parameters by
718 * setting the appropriate bit in the supported_flash_update_params field in
719 * their devlink_ops structure.
720 */
721struct devlink_flash_update_params {
722 const struct firmware *fw;
723 const char *component;
724 u32 overwrite_mask;
725};
726
727#define DEVLINK_SUPPORT_FLASH_UPDATE_OVERWRITE_MASK BIT(0)
728
729struct devlink_region;
730struct devlink_info_req;
731
732/**
733 * struct devlink_region_ops - Region operations
734 * @name: region name
735 * @destructor: callback used to free snapshot memory when deleting
736 * @snapshot: callback to request an immediate snapshot. On success,
737 * the data variable must be updated to point to the snapshot data.
738 * The function will be called while the devlink instance lock is
739 * held.
740 * @read: callback to directly read a portion of the region. On success,
741 * the data pointer will be updated with the contents of the
742 * requested portion of the region. The function will be called
743 * while the devlink instance lock is held.
744 * @priv: Pointer to driver private data for the region operation
745 */
746struct devlink_region_ops {
747 const char *name;
748 void (*destructor)(const void *data);
749 int (*snapshot)(struct devlink *devlink,
750 const struct devlink_region_ops *ops,
751 struct netlink_ext_ack *extack,
752 u8 **data);
753 int (*read)(struct devlink *devlink,
754 const struct devlink_region_ops *ops,
755 struct netlink_ext_ack *extack,
756 u64 offset, u32 size, u8 *data);
757 void *priv;
758};
759
760/**
761 * struct devlink_port_region_ops - Region operations for a port
762 * @name: region name
763 * @destructor: callback used to free snapshot memory when deleting
764 * @snapshot: callback to request an immediate snapshot. On success,
765 * the data variable must be updated to point to the snapshot data.
766 * The function will be called while the devlink instance lock is
767 * held.
768 * @read: callback to directly read a portion of the region. On success,
769 * the data pointer will be updated with the contents of the
770 * requested portion of the region. The function will be called
771 * while the devlink instance lock is held.
772 * @priv: Pointer to driver private data for the region operation
773 */
774struct devlink_port_region_ops {
775 const char *name;
776 void (*destructor)(const void *data);
777 int (*snapshot)(struct devlink_port *port,
778 const struct devlink_port_region_ops *ops,
779 struct netlink_ext_ack *extack,
780 u8 **data);
781 int (*read)(struct devlink_port *port,
782 const struct devlink_port_region_ops *ops,
783 struct netlink_ext_ack *extack,
784 u64 offset, u32 size, u8 *data);
785 void *priv;
786};
787
788struct devlink_fmsg;
789struct devlink_health_reporter;
790
791enum devlink_health_reporter_state {
792 DEVLINK_HEALTH_REPORTER_STATE_HEALTHY,
793 DEVLINK_HEALTH_REPORTER_STATE_ERROR,
794};
795
796/**
797 * struct devlink_health_reporter_ops - Reporter operations
798 * @name: reporter name
799 * @recover: callback to recover from reported error
800 * if priv_ctx is NULL, run a full recover
801 * @dump: callback to dump an object
802 * if priv_ctx is NULL, run a full dump
803 * @diagnose: callback to diagnose the current status
804 * @test: callback to trigger a test event
805 * @default_graceful_period: default min time (in msec)
806 * between recovery attempts
807 * @default_burst_period: default time (in msec) for
808 * error recoveries before starting the grace period
809 */
810
811struct devlink_health_reporter_ops {
812 char *name;
813 int (*recover)(struct devlink_health_reporter *reporter,
814 void *priv_ctx, struct netlink_ext_ack *extack);
815 int (*dump)(struct devlink_health_reporter *reporter,
816 struct devlink_fmsg *fmsg, void *priv_ctx,
817 struct netlink_ext_ack *extack);
818 int (*diagnose)(struct devlink_health_reporter *reporter,
819 struct devlink_fmsg *fmsg,
820 struct netlink_ext_ack *extack);
821 int (*test)(struct devlink_health_reporter *reporter,
822 struct netlink_ext_ack *extack);
823 u64 default_graceful_period;
824 u64 default_burst_period;
825};
826
827/**
828 * struct devlink_trap_metadata - Packet trap metadata.
829 * @trap_name: Trap name.
830 * @trap_group_name: Trap group name.
831 * @input_dev: Input netdevice.
832 * @dev_tracker: refcount tracker for @input_dev.
833 * @fa_cookie: Flow action user cookie.
834 * @trap_type: Trap type.
835 */
836struct devlink_trap_metadata {
837 const char *trap_name;
838 const char *trap_group_name;
839
840 struct net_device *input_dev;
841 netdevice_tracker dev_tracker;
842
843 const struct flow_action_cookie *fa_cookie;
844 enum devlink_trap_type trap_type;
845};
846
847/**
848 * struct devlink_trap_policer - Immutable packet trap policer attributes.
849 * @id: Policer identifier.
850 * @init_rate: Initial rate in packets / sec.
851 * @init_burst: Initial burst size in packets.
852 * @max_rate: Maximum rate.
853 * @min_rate: Minimum rate.
854 * @max_burst: Maximum burst size.
855 * @min_burst: Minimum burst size.
856 *
857 * Describes immutable attributes of packet trap policers that drivers register
858 * with devlink.
859 */
860struct devlink_trap_policer {
861 u32 id;
862 u64 init_rate;
863 u64 init_burst;
864 u64 max_rate;
865 u64 min_rate;
866 u64 max_burst;
867 u64 min_burst;
868};
869
870/**
871 * struct devlink_trap_group - Immutable packet trap group attributes.
872 * @name: Trap group name.
873 * @id: Trap group identifier.
874 * @generic: Whether the trap group is generic or not.
875 * @init_policer_id: Initial policer identifier.
876 *
877 * Describes immutable attributes of packet trap groups that drivers register
878 * with devlink.
879 */
880struct devlink_trap_group {
881 const char *name;
882 u16 id;
883 bool generic;
884 u32 init_policer_id;
885};
886
887#define DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT BIT(0)
888#define DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE BIT(1)
889
890/**
891 * struct devlink_trap - Immutable packet trap attributes.
892 * @type: Trap type.
893 * @init_action: Initial trap action.
894 * @generic: Whether the trap is generic or not.
895 * @id: Trap identifier.
896 * @name: Trap name.
897 * @init_group_id: Initial group identifier.
898 * @metadata_cap: Metadata types that can be provided by the trap.
899 *
900 * Describes immutable attributes of packet traps that drivers register with
901 * devlink.
902 */
903struct devlink_trap {
904 enum devlink_trap_type type;
905 enum devlink_trap_action init_action;
906 bool generic;
907 u16 id;
908 const char *name;
909 u16 init_group_id;
910 u32 metadata_cap;
911};
912
913/* All traps must be documented in
914 * Documentation/networking/devlink/devlink-trap.rst
915 */
916enum devlink_trap_generic_id {
917 DEVLINK_TRAP_GENERIC_ID_SMAC_MC,
918 DEVLINK_TRAP_GENERIC_ID_VLAN_TAG_MISMATCH,
919 DEVLINK_TRAP_GENERIC_ID_INGRESS_VLAN_FILTER,
920 DEVLINK_TRAP_GENERIC_ID_INGRESS_STP_FILTER,
921 DEVLINK_TRAP_GENERIC_ID_EMPTY_TX_LIST,
922 DEVLINK_TRAP_GENERIC_ID_PORT_LOOPBACK_FILTER,
923 DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_ROUTE,
924 DEVLINK_TRAP_GENERIC_ID_TTL_ERROR,
925 DEVLINK_TRAP_GENERIC_ID_TAIL_DROP,
926 DEVLINK_TRAP_GENERIC_ID_NON_IP_PACKET,
927 DEVLINK_TRAP_GENERIC_ID_UC_DIP_MC_DMAC,
928 DEVLINK_TRAP_GENERIC_ID_DIP_LB,
929 DEVLINK_TRAP_GENERIC_ID_SIP_MC,
930 DEVLINK_TRAP_GENERIC_ID_SIP_LB,
931 DEVLINK_TRAP_GENERIC_ID_CORRUPTED_IP_HDR,
932 DEVLINK_TRAP_GENERIC_ID_IPV4_SIP_BC,
933 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_RESERVED_SCOPE,
934 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE,
935 DEVLINK_TRAP_GENERIC_ID_MTU_ERROR,
936 DEVLINK_TRAP_GENERIC_ID_UNRESOLVED_NEIGH,
937 DEVLINK_TRAP_GENERIC_ID_RPF,
938 DEVLINK_TRAP_GENERIC_ID_REJECT_ROUTE,
939 DEVLINK_TRAP_GENERIC_ID_IPV4_LPM_UNICAST_MISS,
940 DEVLINK_TRAP_GENERIC_ID_IPV6_LPM_UNICAST_MISS,
941 DEVLINK_TRAP_GENERIC_ID_NON_ROUTABLE,
942 DEVLINK_TRAP_GENERIC_ID_DECAP_ERROR,
943 DEVLINK_TRAP_GENERIC_ID_OVERLAY_SMAC_MC,
944 DEVLINK_TRAP_GENERIC_ID_INGRESS_FLOW_ACTION_DROP,
945 DEVLINK_TRAP_GENERIC_ID_EGRESS_FLOW_ACTION_DROP,
946 DEVLINK_TRAP_GENERIC_ID_STP,
947 DEVLINK_TRAP_GENERIC_ID_LACP,
948 DEVLINK_TRAP_GENERIC_ID_LLDP,
949 DEVLINK_TRAP_GENERIC_ID_IGMP_QUERY,
950 DEVLINK_TRAP_GENERIC_ID_IGMP_V1_REPORT,
951 DEVLINK_TRAP_GENERIC_ID_IGMP_V2_REPORT,
952 DEVLINK_TRAP_GENERIC_ID_IGMP_V3_REPORT,
953 DEVLINK_TRAP_GENERIC_ID_IGMP_V2_LEAVE,
954 DEVLINK_TRAP_GENERIC_ID_MLD_QUERY,
955 DEVLINK_TRAP_GENERIC_ID_MLD_V1_REPORT,
956 DEVLINK_TRAP_GENERIC_ID_MLD_V2_REPORT,
957 DEVLINK_TRAP_GENERIC_ID_MLD_V1_DONE,
958 DEVLINK_TRAP_GENERIC_ID_IPV4_DHCP,
959 DEVLINK_TRAP_GENERIC_ID_IPV6_DHCP,
960 DEVLINK_TRAP_GENERIC_ID_ARP_REQUEST,
961 DEVLINK_TRAP_GENERIC_ID_ARP_RESPONSE,
962 DEVLINK_TRAP_GENERIC_ID_ARP_OVERLAY,
963 DEVLINK_TRAP_GENERIC_ID_IPV6_NEIGH_SOLICIT,
964 DEVLINK_TRAP_GENERIC_ID_IPV6_NEIGH_ADVERT,
965 DEVLINK_TRAP_GENERIC_ID_IPV4_BFD,
966 DEVLINK_TRAP_GENERIC_ID_IPV6_BFD,
967 DEVLINK_TRAP_GENERIC_ID_IPV4_OSPF,
968 DEVLINK_TRAP_GENERIC_ID_IPV6_OSPF,
969 DEVLINK_TRAP_GENERIC_ID_IPV4_BGP,
970 DEVLINK_TRAP_GENERIC_ID_IPV6_BGP,
971 DEVLINK_TRAP_GENERIC_ID_IPV4_VRRP,
972 DEVLINK_TRAP_GENERIC_ID_IPV6_VRRP,
973 DEVLINK_TRAP_GENERIC_ID_IPV4_PIM,
974 DEVLINK_TRAP_GENERIC_ID_IPV6_PIM,
975 DEVLINK_TRAP_GENERIC_ID_UC_LB,
976 DEVLINK_TRAP_GENERIC_ID_LOCAL_ROUTE,
977 DEVLINK_TRAP_GENERIC_ID_EXTERNAL_ROUTE,
978 DEVLINK_TRAP_GENERIC_ID_IPV6_UC_DIP_LINK_LOCAL_SCOPE,
979 DEVLINK_TRAP_GENERIC_ID_IPV6_DIP_ALL_NODES,
980 DEVLINK_TRAP_GENERIC_ID_IPV6_DIP_ALL_ROUTERS,
981 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_SOLICIT,
982 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_ADVERT,
983 DEVLINK_TRAP_GENERIC_ID_IPV6_REDIRECT,
984 DEVLINK_TRAP_GENERIC_ID_IPV4_ROUTER_ALERT,
985 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_ALERT,
986 DEVLINK_TRAP_GENERIC_ID_PTP_EVENT,
987 DEVLINK_TRAP_GENERIC_ID_PTP_GENERAL,
988 DEVLINK_TRAP_GENERIC_ID_FLOW_ACTION_SAMPLE,
989 DEVLINK_TRAP_GENERIC_ID_FLOW_ACTION_TRAP,
990 DEVLINK_TRAP_GENERIC_ID_EARLY_DROP,
991 DEVLINK_TRAP_GENERIC_ID_VXLAN_PARSING,
992 DEVLINK_TRAP_GENERIC_ID_LLC_SNAP_PARSING,
993 DEVLINK_TRAP_GENERIC_ID_VLAN_PARSING,
994 DEVLINK_TRAP_GENERIC_ID_PPPOE_PPP_PARSING,
995 DEVLINK_TRAP_GENERIC_ID_MPLS_PARSING,
996 DEVLINK_TRAP_GENERIC_ID_ARP_PARSING,
997 DEVLINK_TRAP_GENERIC_ID_IP_1_PARSING,
998 DEVLINK_TRAP_GENERIC_ID_IP_N_PARSING,
999 DEVLINK_TRAP_GENERIC_ID_GRE_PARSING,
1000 DEVLINK_TRAP_GENERIC_ID_UDP_PARSING,
1001 DEVLINK_TRAP_GENERIC_ID_TCP_PARSING,
1002 DEVLINK_TRAP_GENERIC_ID_IPSEC_PARSING,
1003 DEVLINK_TRAP_GENERIC_ID_SCTP_PARSING,
1004 DEVLINK_TRAP_GENERIC_ID_DCCP_PARSING,
1005 DEVLINK_TRAP_GENERIC_ID_GTP_PARSING,
1006 DEVLINK_TRAP_GENERIC_ID_ESP_PARSING,
1007 DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_NEXTHOP,
1008 DEVLINK_TRAP_GENERIC_ID_DMAC_FILTER,
1009 DEVLINK_TRAP_GENERIC_ID_EAPOL,
1010 DEVLINK_TRAP_GENERIC_ID_LOCKED_PORT,
1011
1012 /* Add new generic trap IDs above */
1013 __DEVLINK_TRAP_GENERIC_ID_MAX,
1014 DEVLINK_TRAP_GENERIC_ID_MAX = __DEVLINK_TRAP_GENERIC_ID_MAX - 1,
1015};
1016
1017/* All trap groups must be documented in
1018 * Documentation/networking/devlink/devlink-trap.rst
1019 */
1020enum devlink_trap_group_generic_id {
1021 DEVLINK_TRAP_GROUP_GENERIC_ID_L2_DROPS,
1022 DEVLINK_TRAP_GROUP_GENERIC_ID_L3_DROPS,
1023 DEVLINK_TRAP_GROUP_GENERIC_ID_L3_EXCEPTIONS,
1024 DEVLINK_TRAP_GROUP_GENERIC_ID_BUFFER_DROPS,
1025 DEVLINK_TRAP_GROUP_GENERIC_ID_TUNNEL_DROPS,
1026 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_DROPS,
1027 DEVLINK_TRAP_GROUP_GENERIC_ID_STP,
1028 DEVLINK_TRAP_GROUP_GENERIC_ID_LACP,
1029 DEVLINK_TRAP_GROUP_GENERIC_ID_LLDP,
1030 DEVLINK_TRAP_GROUP_GENERIC_ID_MC_SNOOPING,
1031 DEVLINK_TRAP_GROUP_GENERIC_ID_DHCP,
1032 DEVLINK_TRAP_GROUP_GENERIC_ID_NEIGH_DISCOVERY,
1033 DEVLINK_TRAP_GROUP_GENERIC_ID_BFD,
1034 DEVLINK_TRAP_GROUP_GENERIC_ID_OSPF,
1035 DEVLINK_TRAP_GROUP_GENERIC_ID_BGP,
1036 DEVLINK_TRAP_GROUP_GENERIC_ID_VRRP,
1037 DEVLINK_TRAP_GROUP_GENERIC_ID_PIM,
1038 DEVLINK_TRAP_GROUP_GENERIC_ID_UC_LB,
1039 DEVLINK_TRAP_GROUP_GENERIC_ID_LOCAL_DELIVERY,
1040 DEVLINK_TRAP_GROUP_GENERIC_ID_EXTERNAL_DELIVERY,
1041 DEVLINK_TRAP_GROUP_GENERIC_ID_IPV6,
1042 DEVLINK_TRAP_GROUP_GENERIC_ID_PTP_EVENT,
1043 DEVLINK_TRAP_GROUP_GENERIC_ID_PTP_GENERAL,
1044 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_SAMPLE,
1045 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_TRAP,
1046 DEVLINK_TRAP_GROUP_GENERIC_ID_PARSER_ERROR_DROPS,
1047 DEVLINK_TRAP_GROUP_GENERIC_ID_EAPOL,
1048
1049 /* Add new generic trap group IDs above */
1050 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX,
1051 DEVLINK_TRAP_GROUP_GENERIC_ID_MAX =
1052 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX - 1,
1053};
1054
1055#define DEVLINK_TRAP_GENERIC_NAME_SMAC_MC \
1056 "source_mac_is_multicast"
1057#define DEVLINK_TRAP_GENERIC_NAME_VLAN_TAG_MISMATCH \
1058 "vlan_tag_mismatch"
1059#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_VLAN_FILTER \
1060 "ingress_vlan_filter"
1061#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_STP_FILTER \
1062 "ingress_spanning_tree_filter"
1063#define DEVLINK_TRAP_GENERIC_NAME_EMPTY_TX_LIST \
1064 "port_list_is_empty"
1065#define DEVLINK_TRAP_GENERIC_NAME_PORT_LOOPBACK_FILTER \
1066 "port_loopback_filter"
1067#define DEVLINK_TRAP_GENERIC_NAME_BLACKHOLE_ROUTE \
1068 "blackhole_route"
1069#define DEVLINK_TRAP_GENERIC_NAME_TTL_ERROR \
1070 "ttl_value_is_too_small"
1071#define DEVLINK_TRAP_GENERIC_NAME_TAIL_DROP \
1072 "tail_drop"
1073#define DEVLINK_TRAP_GENERIC_NAME_NON_IP_PACKET \
1074 "non_ip"
1075#define DEVLINK_TRAP_GENERIC_NAME_UC_DIP_MC_DMAC \
1076 "uc_dip_over_mc_dmac"
1077#define DEVLINK_TRAP_GENERIC_NAME_DIP_LB \
1078 "dip_is_loopback_address"
1079#define DEVLINK_TRAP_GENERIC_NAME_SIP_MC \
1080 "sip_is_mc"
1081#define DEVLINK_TRAP_GENERIC_NAME_SIP_LB \
1082 "sip_is_loopback_address"
1083#define DEVLINK_TRAP_GENERIC_NAME_CORRUPTED_IP_HDR \
1084 "ip_header_corrupted"
1085#define DEVLINK_TRAP_GENERIC_NAME_IPV4_SIP_BC \
1086 "ipv4_sip_is_limited_bc"
1087#define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_RESERVED_SCOPE \
1088 "ipv6_mc_dip_reserved_scope"
1089#define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE \
1090 "ipv6_mc_dip_interface_local_scope"
1091#define DEVLINK_TRAP_GENERIC_NAME_MTU_ERROR \
1092 "mtu_value_is_too_small"
1093#define DEVLINK_TRAP_GENERIC_NAME_UNRESOLVED_NEIGH \
1094 "unresolved_neigh"
1095#define DEVLINK_TRAP_GENERIC_NAME_RPF \
1096 "mc_reverse_path_forwarding"
1097#define DEVLINK_TRAP_GENERIC_NAME_REJECT_ROUTE \
1098 "reject_route"
1099#define DEVLINK_TRAP_GENERIC_NAME_IPV4_LPM_UNICAST_MISS \
1100 "ipv4_lpm_miss"
1101#define DEVLINK_TRAP_GENERIC_NAME_IPV6_LPM_UNICAST_MISS \
1102 "ipv6_lpm_miss"
1103#define DEVLINK_TRAP_GENERIC_NAME_NON_ROUTABLE \
1104 "non_routable_packet"
1105#define DEVLINK_TRAP_GENERIC_NAME_DECAP_ERROR \
1106 "decap_error"
1107#define DEVLINK_TRAP_GENERIC_NAME_OVERLAY_SMAC_MC \
1108 "overlay_smac_is_mc"
1109#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_FLOW_ACTION_DROP \
1110 "ingress_flow_action_drop"
1111#define DEVLINK_TRAP_GENERIC_NAME_EGRESS_FLOW_ACTION_DROP \
1112 "egress_flow_action_drop"
1113#define DEVLINK_TRAP_GENERIC_NAME_STP \
1114 "stp"
1115#define DEVLINK_TRAP_GENERIC_NAME_LACP \
1116 "lacp"
1117#define DEVLINK_TRAP_GENERIC_NAME_LLDP \
1118 "lldp"
1119#define DEVLINK_TRAP_GENERIC_NAME_IGMP_QUERY \
1120 "igmp_query"
1121#define DEVLINK_TRAP_GENERIC_NAME_IGMP_V1_REPORT \
1122 "igmp_v1_report"
1123#define DEVLINK_TRAP_GENERIC_NAME_IGMP_V2_REPORT \
1124 "igmp_v2_report"
1125#define DEVLINK_TRAP_GENERIC_NAME_IGMP_V3_REPORT \
1126 "igmp_v3_report"
1127#define DEVLINK_TRAP_GENERIC_NAME_IGMP_V2_LEAVE \
1128 "igmp_v2_leave"
1129#define DEVLINK_TRAP_GENERIC_NAME_MLD_QUERY \
1130 "mld_query"
1131#define DEVLINK_TRAP_GENERIC_NAME_MLD_V1_REPORT \
1132 "mld_v1_report"
1133#define DEVLINK_TRAP_GENERIC_NAME_MLD_V2_REPORT \
1134 "mld_v2_report"
1135#define DEVLINK_TRAP_GENERIC_NAME_MLD_V1_DONE \
1136 "mld_v1_done"
1137#define DEVLINK_TRAP_GENERIC_NAME_IPV4_DHCP \
1138 "ipv4_dhcp"
1139#define DEVLINK_TRAP_GENERIC_NAME_IPV6_DHCP \
1140 "ipv6_dhcp"
1141#define DEVLINK_TRAP_GENERIC_NAME_ARP_REQUEST \
1142 "arp_request"
1143#define DEVLINK_TRAP_GENERIC_NAME_ARP_RESPONSE \
1144 "arp_response"
1145#define DEVLINK_TRAP_GENERIC_NAME_ARP_OVERLAY \
1146 "arp_overlay"
1147#define DEVLINK_TRAP_GENERIC_NAME_IPV6_NEIGH_SOLICIT \
1148 "ipv6_neigh_solicit"
1149#define DEVLINK_TRAP_GENERIC_NAME_IPV6_NEIGH_ADVERT \
1150 "ipv6_neigh_advert"
1151#define DEVLINK_TRAP_GENERIC_NAME_IPV4_BFD \
1152 "ipv4_bfd"
1153#define DEVLINK_TRAP_GENERIC_NAME_IPV6_BFD \
1154 "ipv6_bfd"
1155#define DEVLINK_TRAP_GENERIC_NAME_IPV4_OSPF \
1156 "ipv4_ospf"
1157#define DEVLINK_TRAP_GENERIC_NAME_IPV6_OSPF \
1158 "ipv6_ospf"
1159#define DEVLINK_TRAP_GENERIC_NAME_IPV4_BGP \
1160 "ipv4_bgp"
1161#define DEVLINK_TRAP_GENERIC_NAME_IPV6_BGP \
1162 "ipv6_bgp"
1163#define DEVLINK_TRAP_GENERIC_NAME_IPV4_VRRP \
1164 "ipv4_vrrp"
1165#define DEVLINK_TRAP_GENERIC_NAME_IPV6_VRRP \
1166 "ipv6_vrrp"
1167#define DEVLINK_TRAP_GENERIC_NAME_IPV4_PIM \
1168 "ipv4_pim"
1169#define DEVLINK_TRAP_GENERIC_NAME_IPV6_PIM \
1170 "ipv6_pim"
1171#define DEVLINK_TRAP_GENERIC_NAME_UC_LB \
1172 "uc_loopback"
1173#define DEVLINK_TRAP_GENERIC_NAME_LOCAL_ROUTE \
1174 "local_route"
1175#define DEVLINK_TRAP_GENERIC_NAME_EXTERNAL_ROUTE \
1176 "external_route"
1177#define DEVLINK_TRAP_GENERIC_NAME_IPV6_UC_DIP_LINK_LOCAL_SCOPE \
1178 "ipv6_uc_dip_link_local_scope"
1179#define DEVLINK_TRAP_GENERIC_NAME_IPV6_DIP_ALL_NODES \
1180 "ipv6_dip_all_nodes"
1181#define DEVLINK_TRAP_GENERIC_NAME_IPV6_DIP_ALL_ROUTERS \
1182 "ipv6_dip_all_routers"
1183#define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_SOLICIT \
1184 "ipv6_router_solicit"
1185#define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_ADVERT \
1186 "ipv6_router_advert"
1187#define DEVLINK_TRAP_GENERIC_NAME_IPV6_REDIRECT \
1188 "ipv6_redirect"
1189#define DEVLINK_TRAP_GENERIC_NAME_IPV4_ROUTER_ALERT \
1190 "ipv4_router_alert"
1191#define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_ALERT \
1192 "ipv6_router_alert"
1193#define DEVLINK_TRAP_GENERIC_NAME_PTP_EVENT \
1194 "ptp_event"
1195#define DEVLINK_TRAP_GENERIC_NAME_PTP_GENERAL \
1196 "ptp_general"
1197#define DEVLINK_TRAP_GENERIC_NAME_FLOW_ACTION_SAMPLE \
1198 "flow_action_sample"
1199#define DEVLINK_TRAP_GENERIC_NAME_FLOW_ACTION_TRAP \
1200 "flow_action_trap"
1201#define DEVLINK_TRAP_GENERIC_NAME_EARLY_DROP \
1202 "early_drop"
1203#define DEVLINK_TRAP_GENERIC_NAME_VXLAN_PARSING \
1204 "vxlan_parsing"
1205#define DEVLINK_TRAP_GENERIC_NAME_LLC_SNAP_PARSING \
1206 "llc_snap_parsing"
1207#define DEVLINK_TRAP_GENERIC_NAME_VLAN_PARSING \
1208 "vlan_parsing"
1209#define DEVLINK_TRAP_GENERIC_NAME_PPPOE_PPP_PARSING \
1210 "pppoe_ppp_parsing"
1211#define DEVLINK_TRAP_GENERIC_NAME_MPLS_PARSING \
1212 "mpls_parsing"
1213#define DEVLINK_TRAP_GENERIC_NAME_ARP_PARSING \
1214 "arp_parsing"
1215#define DEVLINK_TRAP_GENERIC_NAME_IP_1_PARSING \
1216 "ip_1_parsing"
1217#define DEVLINK_TRAP_GENERIC_NAME_IP_N_PARSING \
1218 "ip_n_parsing"
1219#define DEVLINK_TRAP_GENERIC_NAME_GRE_PARSING \
1220 "gre_parsing"
1221#define DEVLINK_TRAP_GENERIC_NAME_UDP_PARSING \
1222 "udp_parsing"
1223#define DEVLINK_TRAP_GENERIC_NAME_TCP_PARSING \
1224 "tcp_parsing"
1225#define DEVLINK_TRAP_GENERIC_NAME_IPSEC_PARSING \
1226 "ipsec_parsing"
1227#define DEVLINK_TRAP_GENERIC_NAME_SCTP_PARSING \
1228 "sctp_parsing"
1229#define DEVLINK_TRAP_GENERIC_NAME_DCCP_PARSING \
1230 "dccp_parsing"
1231#define DEVLINK_TRAP_GENERIC_NAME_GTP_PARSING \
1232 "gtp_parsing"
1233#define DEVLINK_TRAP_GENERIC_NAME_ESP_PARSING \
1234 "esp_parsing"
1235#define DEVLINK_TRAP_GENERIC_NAME_BLACKHOLE_NEXTHOP \
1236 "blackhole_nexthop"
1237#define DEVLINK_TRAP_GENERIC_NAME_DMAC_FILTER \
1238 "dmac_filter"
1239#define DEVLINK_TRAP_GENERIC_NAME_EAPOL \
1240 "eapol"
1241#define DEVLINK_TRAP_GENERIC_NAME_LOCKED_PORT \
1242 "locked_port"
1243
1244#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L2_DROPS \
1245 "l2_drops"
1246#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_DROPS \
1247 "l3_drops"
1248#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_EXCEPTIONS \
1249 "l3_exceptions"
1250#define DEVLINK_TRAP_GROUP_GENERIC_NAME_BUFFER_DROPS \
1251 "buffer_drops"
1252#define DEVLINK_TRAP_GROUP_GENERIC_NAME_TUNNEL_DROPS \
1253 "tunnel_drops"
1254#define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_DROPS \
1255 "acl_drops"
1256#define DEVLINK_TRAP_GROUP_GENERIC_NAME_STP \
1257 "stp"
1258#define DEVLINK_TRAP_GROUP_GENERIC_NAME_LACP \
1259 "lacp"
1260#define DEVLINK_TRAP_GROUP_GENERIC_NAME_LLDP \
1261 "lldp"
1262#define DEVLINK_TRAP_GROUP_GENERIC_NAME_MC_SNOOPING \
1263 "mc_snooping"
1264#define DEVLINK_TRAP_GROUP_GENERIC_NAME_DHCP \
1265 "dhcp"
1266#define DEVLINK_TRAP_GROUP_GENERIC_NAME_NEIGH_DISCOVERY \
1267 "neigh_discovery"
1268#define DEVLINK_TRAP_GROUP_GENERIC_NAME_BFD \
1269 "bfd"
1270#define DEVLINK_TRAP_GROUP_GENERIC_NAME_OSPF \
1271 "ospf"
1272#define DEVLINK_TRAP_GROUP_GENERIC_NAME_BGP \
1273 "bgp"
1274#define DEVLINK_TRAP_GROUP_GENERIC_NAME_VRRP \
1275 "vrrp"
1276#define DEVLINK_TRAP_GROUP_GENERIC_NAME_PIM \
1277 "pim"
1278#define DEVLINK_TRAP_GROUP_GENERIC_NAME_UC_LB \
1279 "uc_loopback"
1280#define DEVLINK_TRAP_GROUP_GENERIC_NAME_LOCAL_DELIVERY \
1281 "local_delivery"
1282#define DEVLINK_TRAP_GROUP_GENERIC_NAME_EXTERNAL_DELIVERY \
1283 "external_delivery"
1284#define DEVLINK_TRAP_GROUP_GENERIC_NAME_IPV6 \
1285 "ipv6"
1286#define DEVLINK_TRAP_GROUP_GENERIC_NAME_PTP_EVENT \
1287 "ptp_event"
1288#define DEVLINK_TRAP_GROUP_GENERIC_NAME_PTP_GENERAL \
1289 "ptp_general"
1290#define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_SAMPLE \
1291 "acl_sample"
1292#define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_TRAP \
1293 "acl_trap"
1294#define DEVLINK_TRAP_GROUP_GENERIC_NAME_PARSER_ERROR_DROPS \
1295 "parser_error_drops"
1296#define DEVLINK_TRAP_GROUP_GENERIC_NAME_EAPOL \
1297 "eapol"
1298
1299#define DEVLINK_TRAP_GENERIC(_type, _init_action, _id, _group_id, \
1300 _metadata_cap) \
1301 { \
1302 .type = DEVLINK_TRAP_TYPE_##_type, \
1303 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
1304 .generic = true, \
1305 .id = DEVLINK_TRAP_GENERIC_ID_##_id, \
1306 .name = DEVLINK_TRAP_GENERIC_NAME_##_id, \
1307 .init_group_id = _group_id, \
1308 .metadata_cap = _metadata_cap, \
1309 }
1310
1311#define DEVLINK_TRAP_DRIVER(_type, _init_action, _id, _name, _group_id, \
1312 _metadata_cap) \
1313 { \
1314 .type = DEVLINK_TRAP_TYPE_##_type, \
1315 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
1316 .generic = false, \
1317 .id = _id, \
1318 .name = _name, \
1319 .init_group_id = _group_id, \
1320 .metadata_cap = _metadata_cap, \
1321 }
1322
1323#define DEVLINK_TRAP_GROUP_GENERIC(_id, _policer_id) \
1324 { \
1325 .name = DEVLINK_TRAP_GROUP_GENERIC_NAME_##_id, \
1326 .id = DEVLINK_TRAP_GROUP_GENERIC_ID_##_id, \
1327 .generic = true, \
1328 .init_policer_id = _policer_id, \
1329 }
1330
1331#define DEVLINK_TRAP_POLICER(_id, _rate, _burst, _max_rate, _min_rate, \
1332 _max_burst, _min_burst) \
1333 { \
1334 .id = _id, \
1335 .init_rate = _rate, \
1336 .init_burst = _burst, \
1337 .max_rate = _max_rate, \
1338 .min_rate = _min_rate, \
1339 .max_burst = _max_burst, \
1340 .min_burst = _min_burst, \
1341 }
1342
1343#define devlink_fmsg_put(fmsg, name, value) ( \
1344 _Generic((value), \
1345 bool : devlink_fmsg_bool_pair_put, \
1346 u8 : devlink_fmsg_u8_pair_put, \
1347 u16 : devlink_fmsg_u32_pair_put, \
1348 u32 : devlink_fmsg_u32_pair_put, \
1349 u64 : devlink_fmsg_u64_pair_put, \
1350 int : devlink_fmsg_u32_pair_put, \
1351 char * : devlink_fmsg_string_pair_put, \
1352 const char * : devlink_fmsg_string_pair_put) \
1353 (fmsg, name, (value)))
1354
1355enum {
1356 /* device supports reload operations */
1357 DEVLINK_F_RELOAD = 1UL << 0,
1358};
1359
1360struct devlink_ops {
1361 /**
1362 * @supported_flash_update_params:
1363 * mask of parameters supported by the driver's .flash_update
1364 * implementation.
1365 */
1366 u32 supported_flash_update_params;
1367 unsigned long reload_actions;
1368 unsigned long reload_limits;
1369 int (*reload_down)(struct devlink *devlink, bool netns_change,
1370 enum devlink_reload_action action,
1371 enum devlink_reload_limit limit,
1372 struct netlink_ext_ack *extack);
1373 int (*reload_up)(struct devlink *devlink, enum devlink_reload_action action,
1374 enum devlink_reload_limit limit, u32 *actions_performed,
1375 struct netlink_ext_ack *extack);
1376 int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
1377 u16 pool_index,
1378 struct devlink_sb_pool_info *pool_info);
1379 int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
1380 u16 pool_index, u32 size,
1381 enum devlink_sb_threshold_type threshold_type,
1382 struct netlink_ext_ack *extack);
1383 int (*sb_port_pool_get)(struct devlink_port *devlink_port,
1384 unsigned int sb_index, u16 pool_index,
1385 u32 *p_threshold);
1386 int (*sb_port_pool_set)(struct devlink_port *devlink_port,
1387 unsigned int sb_index, u16 pool_index,
1388 u32 threshold, struct netlink_ext_ack *extack);
1389 int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
1390 unsigned int sb_index,
1391 u16 tc_index,
1392 enum devlink_sb_pool_type pool_type,
1393 u16 *p_pool_index, u32 *p_threshold);
1394 int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
1395 unsigned int sb_index,
1396 u16 tc_index,
1397 enum devlink_sb_pool_type pool_type,
1398 u16 pool_index, u32 threshold,
1399 struct netlink_ext_ack *extack);
1400 int (*sb_occ_snapshot)(struct devlink *devlink,
1401 unsigned int sb_index);
1402 int (*sb_occ_max_clear)(struct devlink *devlink,
1403 unsigned int sb_index);
1404 int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
1405 unsigned int sb_index, u16 pool_index,
1406 u32 *p_cur, u32 *p_max);
1407 int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
1408 unsigned int sb_index,
1409 u16 tc_index,
1410 enum devlink_sb_pool_type pool_type,
1411 u32 *p_cur, u32 *p_max);
1412
1413 int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
1414 int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
1415 struct netlink_ext_ack *extack);
1416 int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
1417 int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
1418 struct netlink_ext_ack *extack);
1419 int (*eswitch_encap_mode_get)(struct devlink *devlink,
1420 enum devlink_eswitch_encap_mode *p_encap_mode);
1421 int (*eswitch_encap_mode_set)(struct devlink *devlink,
1422 enum devlink_eswitch_encap_mode encap_mode,
1423 struct netlink_ext_ack *extack);
1424 int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
1425 struct netlink_ext_ack *extack);
1426 /**
1427 * @flash_update: Device flash update function
1428 *
1429 * Used to perform a flash update for the device. The set of
1430 * parameters supported by the driver should be set in
1431 * supported_flash_update_params.
1432 */
1433 int (*flash_update)(struct devlink *devlink,
1434 struct devlink_flash_update_params *params,
1435 struct netlink_ext_ack *extack);
1436 /**
1437 * @trap_init: Trap initialization function.
1438 *
1439 * Should be used by device drivers to initialize the trap in the
1440 * underlying device. Drivers should also store the provided trap
1441 * context, so that they could efficiently pass it to
1442 * devlink_trap_report() when the trap is triggered.
1443 */
1444 int (*trap_init)(struct devlink *devlink,
1445 const struct devlink_trap *trap, void *trap_ctx);
1446 /**
1447 * @trap_fini: Trap de-initialization function.
1448 *
1449 * Should be used by device drivers to de-initialize the trap in the
1450 * underlying device.
1451 */
1452 void (*trap_fini)(struct devlink *devlink,
1453 const struct devlink_trap *trap, void *trap_ctx);
1454 /**
1455 * @trap_action_set: Trap action set function.
1456 */
1457 int (*trap_action_set)(struct devlink *devlink,
1458 const struct devlink_trap *trap,
1459 enum devlink_trap_action action,
1460 struct netlink_ext_ack *extack);
1461 /**
1462 * @trap_group_init: Trap group initialization function.
1463 *
1464 * Should be used by device drivers to initialize the trap group in the
1465 * underlying device.
1466 */
1467 int (*trap_group_init)(struct devlink *devlink,
1468 const struct devlink_trap_group *group);
1469 /**
1470 * @trap_group_set: Trap group parameters set function.
1471 *
1472 * Note: @policer can be NULL when a policer is being unbound from
1473 * @group.
1474 */
1475 int (*trap_group_set)(struct devlink *devlink,
1476 const struct devlink_trap_group *group,
1477 const struct devlink_trap_policer *policer,
1478 struct netlink_ext_ack *extack);
1479 /**
1480 * @trap_group_action_set: Trap group action set function.
1481 *
1482 * If this callback is populated, it will take precedence over looping
1483 * over all traps in a group and calling .trap_action_set().
1484 */
1485 int (*trap_group_action_set)(struct devlink *devlink,
1486 const struct devlink_trap_group *group,
1487 enum devlink_trap_action action,
1488 struct netlink_ext_ack *extack);
1489 /**
1490 * @trap_drop_counter_get: Trap drop counter get function.
1491 *
1492 * Should be used by device drivers to report number of packets
1493 * that have been dropped, and cannot be passed to the devlink
1494 * subsystem by the underlying device.
1495 */
1496 int (*trap_drop_counter_get)(struct devlink *devlink,
1497 const struct devlink_trap *trap,
1498 u64 *p_drops);
1499 /**
1500 * @trap_policer_init: Trap policer initialization function.
1501 *
1502 * Should be used by device drivers to initialize the trap policer in
1503 * the underlying device.
1504 */
1505 int (*trap_policer_init)(struct devlink *devlink,
1506 const struct devlink_trap_policer *policer);
1507 /**
1508 * @trap_policer_fini: Trap policer de-initialization function.
1509 *
1510 * Should be used by device drivers to de-initialize the trap policer
1511 * in the underlying device.
1512 */
1513 void (*trap_policer_fini)(struct devlink *devlink,
1514 const struct devlink_trap_policer *policer);
1515 /**
1516 * @trap_policer_set: Trap policer parameters set function.
1517 */
1518 int (*trap_policer_set)(struct devlink *devlink,
1519 const struct devlink_trap_policer *policer,
1520 u64 rate, u64 burst,
1521 struct netlink_ext_ack *extack);
1522 /**
1523 * @trap_policer_counter_get: Trap policer counter get function.
1524 *
1525 * Should be used by device drivers to report number of packets dropped
1526 * by the policer.
1527 */
1528 int (*trap_policer_counter_get)(struct devlink *devlink,
1529 const struct devlink_trap_policer *policer,
1530 u64 *p_drops);
1531 /**
1532 * port_new() - Add a new port function of a specified flavor
1533 * @devlink: Devlink instance
1534 * @attrs: attributes of the new port
1535 * @extack: extack for reporting error messages
1536 * @devlink_port: pointer to store new devlink port pointer
1537 *
1538 * Devlink core will call this device driver function upon user request
1539 * to create a new port function of a specified flavor and optional
1540 * attributes
1541 *
1542 * Notes:
1543 * - On success, drivers must register a port with devlink core
1544 *
1545 * Return: 0 on success, negative value otherwise.
1546 */
1547 int (*port_new)(struct devlink *devlink,
1548 const struct devlink_port_new_attrs *attrs,
1549 struct netlink_ext_ack *extack,
1550 struct devlink_port **devlink_port);
1551
1552 /**
1553 * Rate control callbacks.
1554 */
1555 int (*rate_leaf_tx_share_set)(struct devlink_rate *devlink_rate, void *priv,
1556 u64 tx_share, struct netlink_ext_ack *extack);
1557 int (*rate_leaf_tx_max_set)(struct devlink_rate *devlink_rate, void *priv,
1558 u64 tx_max, struct netlink_ext_ack *extack);
1559 int (*rate_leaf_tx_priority_set)(struct devlink_rate *devlink_rate, void *priv,
1560 u32 tx_priority, struct netlink_ext_ack *extack);
1561 int (*rate_leaf_tx_weight_set)(struct devlink_rate *devlink_rate, void *priv,
1562 u32 tx_weight, struct netlink_ext_ack *extack);
1563 int (*rate_leaf_tc_bw_set)(struct devlink_rate *devlink_rate,
1564 void *priv, u32 *tc_bw,
1565 struct netlink_ext_ack *extack);
1566 int (*rate_node_tx_share_set)(struct devlink_rate *devlink_rate, void *priv,
1567 u64 tx_share, struct netlink_ext_ack *extack);
1568 int (*rate_node_tx_max_set)(struct devlink_rate *devlink_rate, void *priv,
1569 u64 tx_max, struct netlink_ext_ack *extack);
1570 int (*rate_node_tx_priority_set)(struct devlink_rate *devlink_rate, void *priv,
1571 u32 tx_priority, struct netlink_ext_ack *extack);
1572 int (*rate_node_tx_weight_set)(struct devlink_rate *devlink_rate, void *priv,
1573 u32 tx_weight, struct netlink_ext_ack *extack);
1574 int (*rate_node_tc_bw_set)(struct devlink_rate *devlink_rate,
1575 void *priv, u32 *tc_bw,
1576 struct netlink_ext_ack *extack);
1577 int (*rate_node_new)(struct devlink_rate *rate_node, void **priv,
1578 struct netlink_ext_ack *extack);
1579 int (*rate_node_del)(struct devlink_rate *rate_node, void *priv,
1580 struct netlink_ext_ack *extack);
1581 int (*rate_leaf_parent_set)(struct devlink_rate *child,
1582 struct devlink_rate *parent,
1583 void *priv_child, void *priv_parent,
1584 struct netlink_ext_ack *extack);
1585 int (*rate_node_parent_set)(struct devlink_rate *child,
1586 struct devlink_rate *parent,
1587 void *priv_child, void *priv_parent,
1588 struct netlink_ext_ack *extack);
1589 /**
1590 * selftests_check() - queries if selftest is supported
1591 * @devlink: devlink instance
1592 * @id: test index
1593 * @extack: extack for reporting error messages
1594 *
1595 * Return: true if test is supported by the driver
1596 */
1597 bool (*selftest_check)(struct devlink *devlink, unsigned int id,
1598 struct netlink_ext_ack *extack);
1599 /**
1600 * selftest_run() - Runs a selftest
1601 * @devlink: devlink instance
1602 * @id: test index
1603 * @extack: extack for reporting error messages
1604 *
1605 * Return: status of the test
1606 */
1607 enum devlink_selftest_status
1608 (*selftest_run)(struct devlink *devlink, unsigned int id,
1609 struct netlink_ext_ack *extack);
1610};
1611
1612void *devlink_priv(struct devlink *devlink);
1613struct devlink *priv_to_devlink(void *priv);
1614struct device *devlink_to_dev(const struct devlink *devlink);
1615const char *devlink_bus_name(const struct devlink *devlink);
1616const char *devlink_dev_name(const struct devlink *devlink);
1617const char *devlink_dev_driver_name(const struct devlink *devlink);
1618
1619/* Devlink instance explicit locking */
1620void devl_lock(struct devlink *devlink);
1621int devl_trylock(struct devlink *devlink);
1622void devl_unlock(struct devlink *devlink);
1623void devl_assert_locked(struct devlink *devlink);
1624bool devl_lock_is_held(struct devlink *devlink);
1625DEFINE_GUARD(devl, struct devlink *, devl_lock(_T), devl_unlock(_T));
1626
1627struct ib_device;
1628
1629struct net *devlink_net(const struct devlink *devlink);
1630/* This call is intended for software devices that can create
1631 * devlink instances in other namespaces than init_net.
1632 *
1633 * Drivers that operate on real HW must use devlink_alloc() instead.
1634 */
1635struct devlink *devlink_alloc_ns(const struct devlink_ops *ops,
1636 size_t priv_size, struct net *net,
1637 struct device *dev);
1638static inline struct devlink *devlink_alloc(const struct devlink_ops *ops,
1639 size_t priv_size,
1640 struct device *dev)
1641{
1642 return devlink_alloc_ns(ops, priv_size, &init_net, dev);
1643}
1644
1645int devl_register(struct devlink *devlink);
1646void devl_unregister(struct devlink *devlink);
1647void devlink_register(struct devlink *devlink);
1648void devlink_unregister(struct devlink *devlink);
1649void devlink_free(struct devlink *devlink);
1650
1651struct devlink *devlink_shd_get(const char *id,
1652 const struct devlink_ops *ops,
1653 size_t priv_size,
1654 const struct device_driver *driver);
1655void devlink_shd_put(struct devlink *devlink);
1656void *devlink_shd_get_priv(struct devlink *devlink);
1657
1658/**
1659 * struct devlink_port_ops - Port operations
1660 * @port_split: Callback used to split the port into multiple ones.
1661 * @port_unsplit: Callback used to unsplit the port group back into
1662 * a single port.
1663 * @port_type_set: Callback used to set a type of a port.
1664 * @port_del: Callback used to delete selected port along with related function.
1665 * Devlink core calls this upon user request to delete
1666 * a port previously created by devlink_ops->port_new().
1667 * @port_fn_hw_addr_get: Callback used to set port function's hardware address.
1668 * Should be used by device drivers to report
1669 * the hardware address of a function managed
1670 * by the devlink port.
1671 * @port_fn_hw_addr_set: Callback used to set port function's hardware address.
1672 * Should be used by device drivers to set the hardware
1673 * address of a function managed by the devlink port.
1674 * @port_fn_roce_get: Callback used to get port function's RoCE capability.
1675 * Should be used by device drivers to report
1676 * the current state of RoCE capability of a function
1677 * managed by the devlink port.
1678 * @port_fn_roce_set: Callback used to set port function's RoCE capability.
1679 * Should be used by device drivers to enable/disable
1680 * RoCE capability of a function managed
1681 * by the devlink port.
1682 * @port_fn_migratable_get: Callback used to get port function's migratable
1683 * capability. Should be used by device drivers
1684 * to report the current state of migratable capability
1685 * of a function managed by the devlink port.
1686 * @port_fn_migratable_set: Callback used to set port function's migratable
1687 * capability. Should be used by device drivers
1688 * to enable/disable migratable capability of
1689 * a function managed by the devlink port.
1690 * @port_fn_state_get: Callback used to get port function's state.
1691 * Should be used by device drivers to report
1692 * the current admin and operational state of a
1693 * function managed by the devlink port.
1694 * @port_fn_state_set: Callback used to get port function's state.
1695 * Should be used by device drivers set
1696 * the admin state of a function managed
1697 * by the devlink port.
1698 * @port_fn_ipsec_crypto_get: Callback used to get port function's ipsec_crypto
1699 * capability. Should be used by device drivers
1700 * to report the current state of ipsec_crypto
1701 * capability of a function managed by the devlink
1702 * port.
1703 * @port_fn_ipsec_crypto_set: Callback used to set port function's ipsec_crypto
1704 * capability. Should be used by device drivers to
1705 * enable/disable ipsec_crypto capability of a
1706 * function managed by the devlink port.
1707 * @port_fn_ipsec_packet_get: Callback used to get port function's ipsec_packet
1708 * capability. Should be used by device drivers
1709 * to report the current state of ipsec_packet
1710 * capability of a function managed by the devlink
1711 * port.
1712 * @port_fn_ipsec_packet_set: Callback used to set port function's ipsec_packet
1713 * capability. Should be used by device drivers to
1714 * enable/disable ipsec_packet capability of a
1715 * function managed by the devlink port.
1716 * @port_fn_max_io_eqs_get: Callback used to get port function's maximum number
1717 * of event queues. Should be used by device drivers to
1718 * report the maximum event queues of a function
1719 * managed by the devlink port.
1720 * @port_fn_max_io_eqs_set: Callback used to set port function's maximum number
1721 * of event queues. Should be used by device drivers to
1722 * configure maximum number of event queues
1723 * of a function managed by the devlink port.
1724 *
1725 * Note: Driver should return -EOPNOTSUPP if it doesn't support
1726 * port function (@port_fn_*) handling for a particular port.
1727 */
1728struct devlink_port_ops {
1729 int (*port_split)(struct devlink *devlink, struct devlink_port *port,
1730 unsigned int count, struct netlink_ext_ack *extack);
1731 int (*port_unsplit)(struct devlink *devlink, struct devlink_port *port,
1732 struct netlink_ext_ack *extack);
1733 int (*port_type_set)(struct devlink_port *devlink_port,
1734 enum devlink_port_type port_type);
1735 int (*port_del)(struct devlink *devlink, struct devlink_port *port,
1736 struct netlink_ext_ack *extack);
1737 int (*port_fn_hw_addr_get)(struct devlink_port *port, u8 *hw_addr,
1738 int *hw_addr_len,
1739 struct netlink_ext_ack *extack);
1740 int (*port_fn_hw_addr_set)(struct devlink_port *port,
1741 const u8 *hw_addr, int hw_addr_len,
1742 struct netlink_ext_ack *extack);
1743 int (*port_fn_roce_get)(struct devlink_port *devlink_port,
1744 bool *is_enable,
1745 struct netlink_ext_ack *extack);
1746 int (*port_fn_roce_set)(struct devlink_port *devlink_port,
1747 bool enable, struct netlink_ext_ack *extack);
1748 int (*port_fn_migratable_get)(struct devlink_port *devlink_port,
1749 bool *is_enable,
1750 struct netlink_ext_ack *extack);
1751 int (*port_fn_migratable_set)(struct devlink_port *devlink_port,
1752 bool enable,
1753 struct netlink_ext_ack *extack);
1754 int (*port_fn_state_get)(struct devlink_port *port,
1755 enum devlink_port_fn_state *state,
1756 enum devlink_port_fn_opstate *opstate,
1757 struct netlink_ext_ack *extack);
1758 int (*port_fn_state_set)(struct devlink_port *port,
1759 enum devlink_port_fn_state state,
1760 struct netlink_ext_ack *extack);
1761 int (*port_fn_ipsec_crypto_get)(struct devlink_port *devlink_port,
1762 bool *is_enable,
1763 struct netlink_ext_ack *extack);
1764 int (*port_fn_ipsec_crypto_set)(struct devlink_port *devlink_port,
1765 bool enable,
1766 struct netlink_ext_ack *extack);
1767 int (*port_fn_ipsec_packet_get)(struct devlink_port *devlink_port,
1768 bool *is_enable,
1769 struct netlink_ext_ack *extack);
1770 int (*port_fn_ipsec_packet_set)(struct devlink_port *devlink_port,
1771 bool enable,
1772 struct netlink_ext_ack *extack);
1773 int (*port_fn_max_io_eqs_get)(struct devlink_port *devlink_port,
1774 u32 *max_eqs,
1775 struct netlink_ext_ack *extack);
1776 int (*port_fn_max_io_eqs_set)(struct devlink_port *devlink_port,
1777 u32 max_eqs,
1778 struct netlink_ext_ack *extack);
1779};
1780
1781void devlink_port_init(struct devlink *devlink,
1782 struct devlink_port *devlink_port);
1783void devlink_port_fini(struct devlink_port *devlink_port);
1784
1785int devl_port_register_with_ops(struct devlink *devlink,
1786 struct devlink_port *devlink_port,
1787 unsigned int port_index,
1788 const struct devlink_port_ops *ops);
1789
1790static inline int devl_port_register(struct devlink *devlink,
1791 struct devlink_port *devlink_port,
1792 unsigned int port_index)
1793{
1794 return devl_port_register_with_ops(devlink, devlink_port,
1795 port_index, NULL);
1796}
1797
1798int devlink_port_register_with_ops(struct devlink *devlink,
1799 struct devlink_port *devlink_port,
1800 unsigned int port_index,
1801 const struct devlink_port_ops *ops);
1802
1803static inline int devlink_port_register(struct devlink *devlink,
1804 struct devlink_port *devlink_port,
1805 unsigned int port_index)
1806{
1807 return devlink_port_register_with_ops(devlink, devlink_port,
1808 port_index, NULL);
1809}
1810
1811void devl_port_unregister(struct devlink_port *devlink_port);
1812void devlink_port_unregister(struct devlink_port *devlink_port);
1813void devlink_port_type_eth_set(struct devlink_port *devlink_port);
1814void devlink_port_type_ib_set(struct devlink_port *devlink_port,
1815 struct ib_device *ibdev);
1816void devlink_port_type_clear(struct devlink_port *devlink_port);
1817void devlink_port_attrs_set(struct devlink_port *devlink_port,
1818 const struct devlink_port_attrs *attrs);
1819void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u32 controller,
1820 u16 pf, bool external);
1821void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 controller,
1822 u16 pf, u16 vf, bool external);
1823void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port,
1824 u32 controller, u16 pf, u32 sf,
1825 bool external);
1826int devl_port_fn_devlink_set(struct devlink_port *devlink_port,
1827 struct devlink *fn_devlink);
1828struct devlink_rate *
1829devl_rate_node_create(struct devlink *devlink, void *priv, char *node_name,
1830 struct devlink_rate *parent);
1831int
1832devl_rate_leaf_create(struct devlink_port *devlink_port, void *priv,
1833 struct devlink_rate *parent);
1834void devl_rate_leaf_destroy(struct devlink_port *devlink_port);
1835void devl_rate_nodes_destroy(struct devlink *devlink);
1836void devlink_port_linecard_set(struct devlink_port *devlink_port,
1837 struct devlink_linecard *linecard);
1838struct devlink_linecard *
1839devl_linecard_create(struct devlink *devlink, unsigned int linecard_index,
1840 const struct devlink_linecard_ops *ops, void *priv);
1841void devl_linecard_destroy(struct devlink_linecard *linecard);
1842void devlink_linecard_provision_set(struct devlink_linecard *linecard,
1843 const char *type);
1844void devlink_linecard_provision_clear(struct devlink_linecard *linecard);
1845void devlink_linecard_provision_fail(struct devlink_linecard *linecard);
1846void devlink_linecard_activate(struct devlink_linecard *linecard);
1847void devlink_linecard_deactivate(struct devlink_linecard *linecard);
1848int devlink_linecard_nested_dl_set(struct devlink_linecard *linecard,
1849 struct devlink *nested_devlink);
1850int devl_sb_register(struct devlink *devlink, unsigned int sb_index,
1851 u32 size, u16 ingress_pools_count,
1852 u16 egress_pools_count, u16 ingress_tc_count,
1853 u16 egress_tc_count);
1854int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
1855 u32 size, u16 ingress_pools_count,
1856 u16 egress_pools_count, u16 ingress_tc_count,
1857 u16 egress_tc_count);
1858void devl_sb_unregister(struct devlink *devlink, unsigned int sb_index);
1859void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
1860int devl_dpipe_table_register(struct devlink *devlink,
1861 const char *table_name,
1862 const struct devlink_dpipe_table_ops *table_ops,
1863 void *priv, bool counter_control_extern);
1864void devl_dpipe_table_unregister(struct devlink *devlink,
1865 const char *table_name);
1866void devl_dpipe_headers_register(struct devlink *devlink,
1867 struct devlink_dpipe_headers *dpipe_headers);
1868void devl_dpipe_headers_unregister(struct devlink *devlink);
1869bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
1870 const char *table_name);
1871int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
1872int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
1873 struct devlink_dpipe_entry *entry);
1874int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
1875void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
1876int devlink_dpipe_action_put(struct sk_buff *skb,
1877 struct devlink_dpipe_action *action);
1878int devlink_dpipe_match_put(struct sk_buff *skb,
1879 struct devlink_dpipe_match *match);
1880extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
1881extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
1882extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
1883
1884int devl_resource_register(struct devlink *devlink,
1885 const char *resource_name,
1886 u64 resource_size,
1887 u64 resource_id,
1888 u64 parent_resource_id,
1889 const struct devlink_resource_size_params *params);
1890void devl_resources_unregister(struct devlink *devlink);
1891void devlink_resources_unregister(struct devlink *devlink);
1892int devl_resource_size_get(struct devlink *devlink,
1893 u64 resource_id,
1894 u64 *p_resource_size);
1895int
1896devl_port_resource_register(struct devlink_port *devlink_port,
1897 const char *resource_name,
1898 u64 resource_size, u64 resource_id,
1899 u64 parent_resource_id,
1900 const struct devlink_resource_size_params *params);
1901void devl_port_resources_unregister(struct devlink_port *devlink_port);
1902int devl_dpipe_table_resource_set(struct devlink *devlink,
1903 const char *table_name, u64 resource_id,
1904 u64 resource_units);
1905void devl_resource_occ_get_register(struct devlink *devlink,
1906 u64 resource_id,
1907 devlink_resource_occ_get_t *occ_get,
1908 void *occ_get_priv);
1909void devl_resource_occ_get_unregister(struct devlink *devlink,
1910 u64 resource_id);
1911int devl_params_register(struct devlink *devlink,
1912 const struct devlink_param *params,
1913 size_t params_count);
1914int devlink_params_register(struct devlink *devlink,
1915 const struct devlink_param *params,
1916 size_t params_count);
1917void devl_params_unregister(struct devlink *devlink,
1918 const struct devlink_param *params,
1919 size_t params_count);
1920void devlink_params_unregister(struct devlink *devlink,
1921 const struct devlink_param *params,
1922 size_t params_count);
1923int devl_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
1924 union devlink_param_value *val);
1925void devl_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
1926 union devlink_param_value init_val);
1927void devl_param_value_changed(struct devlink *devlink, u32 param_id);
1928struct devlink_region *devl_region_create(struct devlink *devlink,
1929 const struct devlink_region_ops *ops,
1930 u32 region_max_snapshots,
1931 u64 region_size);
1932struct devlink_region *
1933devlink_region_create(struct devlink *devlink,
1934 const struct devlink_region_ops *ops,
1935 u32 region_max_snapshots, u64 region_size);
1936struct devlink_region *
1937devlink_port_region_create(struct devlink_port *port,
1938 const struct devlink_port_region_ops *ops,
1939 u32 region_max_snapshots, u64 region_size);
1940void devl_region_destroy(struct devlink_region *region);
1941void devlink_region_destroy(struct devlink_region *region);
1942int devlink_region_snapshot_id_get(struct devlink *devlink, u32 *id);
1943void devlink_region_snapshot_id_put(struct devlink *devlink, u32 id);
1944int devlink_region_snapshot_create(struct devlink_region *region,
1945 u8 *data, u32 snapshot_id);
1946int devlink_info_serial_number_put(struct devlink_info_req *req,
1947 const char *sn);
1948int devlink_info_board_serial_number_put(struct devlink_info_req *req,
1949 const char *bsn);
1950
1951enum devlink_info_version_type {
1952 DEVLINK_INFO_VERSION_TYPE_NONE,
1953 DEVLINK_INFO_VERSION_TYPE_COMPONENT, /* May be used as flash update
1954 * component by name.
1955 */
1956};
1957
1958int devlink_info_version_fixed_put(struct devlink_info_req *req,
1959 const char *version_name,
1960 const char *version_value);
1961int devlink_info_version_stored_put(struct devlink_info_req *req,
1962 const char *version_name,
1963 const char *version_value);
1964int devlink_info_version_stored_put_ext(struct devlink_info_req *req,
1965 const char *version_name,
1966 const char *version_value,
1967 enum devlink_info_version_type version_type);
1968int devlink_info_version_running_put(struct devlink_info_req *req,
1969 const char *version_name,
1970 const char *version_value);
1971int devlink_info_version_running_put_ext(struct devlink_info_req *req,
1972 const char *version_name,
1973 const char *version_value,
1974 enum devlink_info_version_type version_type);
1975
1976void devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg);
1977void devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg);
1978
1979void devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name);
1980void devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg);
1981
1982void devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg,
1983 const char *name);
1984void devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg);
1985void devlink_fmsg_binary_pair_nest_start(struct devlink_fmsg *fmsg,
1986 const char *name);
1987void devlink_fmsg_binary_pair_nest_end(struct devlink_fmsg *fmsg);
1988
1989void devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value);
1990void devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value);
1991void devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value,
1992 u16 value_len);
1993
1994void devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name,
1995 bool value);
1996void devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name,
1997 u8 value);
1998void devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name,
1999 u32 value);
2000void devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name,
2001 u64 value);
2002void devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,
2003 const char *value);
2004void devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
2005 const void *value, u32 value_len);
2006
2007struct devlink_health_reporter *
2008devl_port_health_reporter_create(struct devlink_port *port,
2009 const struct devlink_health_reporter_ops *ops,
2010 void *priv);
2011
2012struct devlink_health_reporter *
2013devlink_port_health_reporter_create(struct devlink_port *port,
2014 const struct devlink_health_reporter_ops *ops,
2015 void *priv);
2016
2017struct devlink_health_reporter *
2018devl_health_reporter_create(struct devlink *devlink,
2019 const struct devlink_health_reporter_ops *ops,
2020 void *priv);
2021
2022struct devlink_health_reporter *
2023devlink_health_reporter_create(struct devlink *devlink,
2024 const struct devlink_health_reporter_ops *ops,
2025 void *priv);
2026
2027void
2028devl_health_reporter_destroy(struct devlink_health_reporter *reporter);
2029
2030void
2031devlink_health_reporter_destroy(struct devlink_health_reporter *reporter);
2032
2033void *
2034devlink_health_reporter_priv(struct devlink_health_reporter *reporter);
2035int devlink_health_report(struct devlink_health_reporter *reporter,
2036 const char *msg, void *priv_ctx);
2037void
2038devlink_health_reporter_state_update(struct devlink_health_reporter *reporter,
2039 enum devlink_health_reporter_state state);
2040void
2041devlink_health_reporter_recovery_done(struct devlink_health_reporter *reporter);
2042
2043int devl_nested_devlink_set(struct devlink *devlink,
2044 struct devlink *nested_devlink);
2045bool devlink_is_reload_failed(const struct devlink *devlink);
2046void devlink_remote_reload_actions_performed(struct devlink *devlink,
2047 enum devlink_reload_limit limit,
2048 u32 actions_performed);
2049
2050void devlink_flash_update_status_notify(struct devlink *devlink,
2051 const char *status_msg,
2052 const char *component,
2053 unsigned long done,
2054 unsigned long total);
2055void devlink_flash_update_timeout_notify(struct devlink *devlink,
2056 const char *status_msg,
2057 const char *component,
2058 unsigned long timeout);
2059
2060int devl_traps_register(struct devlink *devlink,
2061 const struct devlink_trap *traps,
2062 size_t traps_count, void *priv);
2063int devlink_traps_register(struct devlink *devlink,
2064 const struct devlink_trap *traps,
2065 size_t traps_count, void *priv);
2066void devl_traps_unregister(struct devlink *devlink,
2067 const struct devlink_trap *traps,
2068 size_t traps_count);
2069void devlink_traps_unregister(struct devlink *devlink,
2070 const struct devlink_trap *traps,
2071 size_t traps_count);
2072void devlink_trap_report(struct devlink *devlink, struct sk_buff *skb,
2073 void *trap_ctx, struct devlink_port *in_devlink_port,
2074 const struct flow_action_cookie *fa_cookie);
2075void *devlink_trap_ctx_priv(void *trap_ctx);
2076int devl_trap_groups_register(struct devlink *devlink,
2077 const struct devlink_trap_group *groups,
2078 size_t groups_count);
2079int devlink_trap_groups_register(struct devlink *devlink,
2080 const struct devlink_trap_group *groups,
2081 size_t groups_count);
2082void devl_trap_groups_unregister(struct devlink *devlink,
2083 const struct devlink_trap_group *groups,
2084 size_t groups_count);
2085void devlink_trap_groups_unregister(struct devlink *devlink,
2086 const struct devlink_trap_group *groups,
2087 size_t groups_count);
2088int
2089devl_trap_policers_register(struct devlink *devlink,
2090 const struct devlink_trap_policer *policers,
2091 size_t policers_count);
2092void
2093devl_trap_policers_unregister(struct devlink *devlink,
2094 const struct devlink_trap_policer *policers,
2095 size_t policers_count);
2096
2097#if IS_ENABLED(CONFIG_NET_DEVLINK)
2098
2099struct devlink *__must_check devlink_try_get(struct devlink *devlink);
2100void devlink_put(struct devlink *devlink);
2101
2102void devlink_compat_running_version(struct devlink *devlink,
2103 char *buf, size_t len);
2104int devlink_compat_flash_update(struct devlink *devlink, const char *file_name);
2105int devlink_compat_phys_port_name_get(struct net_device *dev,
2106 char *name, size_t len);
2107int devlink_compat_switch_id_get(struct net_device *dev,
2108 struct netdev_phys_item_id *ppid);
2109
2110int devlink_nl_port_handle_fill(struct sk_buff *msg, struct devlink_port *devlink_port);
2111size_t devlink_nl_port_handle_size(struct devlink_port *devlink_port);
2112void devlink_fmsg_dump_skb(struct devlink_fmsg *fmsg, const struct sk_buff *skb);
2113
2114#else
2115
2116static inline struct devlink *devlink_try_get(struct devlink *devlink)
2117{
2118 return NULL;
2119}
2120
2121static inline void devlink_put(struct devlink *devlink)
2122{
2123}
2124
2125static inline void
2126devlink_compat_running_version(struct devlink *devlink, char *buf, size_t len)
2127{
2128}
2129
2130static inline int
2131devlink_compat_flash_update(struct devlink *devlink, const char *file_name)
2132{
2133 return -EOPNOTSUPP;
2134}
2135
2136static inline int
2137devlink_compat_phys_port_name_get(struct net_device *dev,
2138 char *name, size_t len)
2139{
2140 return -EOPNOTSUPP;
2141}
2142
2143static inline int
2144devlink_compat_switch_id_get(struct net_device *dev,
2145 struct netdev_phys_item_id *ppid)
2146{
2147 return -EOPNOTSUPP;
2148}
2149
2150static inline int
2151devlink_nl_port_handle_fill(struct sk_buff *msg, struct devlink_port *devlink_port)
2152{
2153 return 0;
2154}
2155
2156static inline size_t devlink_nl_port_handle_size(struct devlink_port *devlink_port)
2157{
2158 return 0;
2159}
2160
2161#endif
2162
2163#endif /* _NET_DEVLINK_H_ */