1 /* SPDX-License-Identifier: GPL-2.0-or-later */
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>
7 #ifndef _NET_DEVLINK_H_
8 #define _NET_DEVLINK_H_
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>
23 #define DEVLINK_RELOAD_STATS_ARRAY_SIZE \
24 (__DEVLINK_RELOAD_LIMIT_MAX * __DEVLINK_RELOAD_ACTION_MAX)
26 struct devlink_dev_stats {
27 u32 reload_stats[DEVLINK_RELOAD_STATS_ARRAY_SIZE];
28 u32 remote_reload_stats[DEVLINK_RELOAD_STATS_ARRAY_SIZE];
34 struct list_head list;
35 struct list_head port_list;
36 struct list_head sb_list;
37 struct list_head dpipe_table_list;
38 struct list_head resource_list;
39 struct list_head param_list;
40 struct list_head region_list;
41 struct list_head reporter_list;
42 struct mutex reporters_lock; /* protects reporter_list */
43 struct devlink_dpipe_headers *dpipe_headers;
44 struct list_head trap_list;
45 struct list_head trap_group_list;
46 struct list_head trap_policer_list;
47 const struct devlink_ops *ops;
48 struct xarray snapshot_ids;
49 struct devlink_dev_stats stats;
52 struct mutex lock; /* Serializes access to devlink instance specific objects such as
53 * port, sb, dpipe, resource, params, region, traps and more.
58 char priv[0] __aligned(NETDEV_ALIGN);
61 struct devlink_port_phys_attrs {
62 u32 port_number; /* Same value as "split group".
63 * A physical port which is visible to the user
64 * for a given port flavour.
66 u32 split_subport_number; /* If the port is split, this is the number of subport. */
70 * struct devlink_port_pci_pf_attrs - devlink port's PCI PF attributes
71 * @controller: Associated controller number
72 * @pf: Associated PCI PF number for this port.
73 * @external: when set, indicates if a port is for an external controller
75 struct devlink_port_pci_pf_attrs {
82 * struct devlink_port_pci_vf_attrs - devlink port's PCI VF attributes
83 * @controller: Associated controller number
84 * @pf: Associated PCI PF number for this port.
85 * @vf: Associated PCI VF for of the PCI PF for this port.
86 * @external: when set, indicates if a port is for an external controller
88 struct devlink_port_pci_vf_attrs {
96 * struct devlink_port_attrs - devlink port object
97 * @flavour: flavour of the port
98 * @split: indicates if this is split port
99 * @splittable: indicates if the port can be split.
100 * @lanes: maximum number of lanes the port supports. 0 value is not passed to netlink.
101 * @switch_id: if the port is part of switch, this is buffer with ID, otherwise this is NULL
102 * @phys: physical port attributes
103 * @pci_pf: PCI PF port attributes
104 * @pci_vf: PCI VF port attributes
106 struct devlink_port_attrs {
110 enum devlink_port_flavour flavour;
111 struct netdev_phys_item_id switch_id;
113 struct devlink_port_phys_attrs phys;
114 struct devlink_port_pci_pf_attrs pci_pf;
115 struct devlink_port_pci_vf_attrs pci_vf;
119 struct devlink_port {
120 struct list_head list;
121 struct list_head param_list;
122 struct list_head region_list;
123 struct devlink *devlink;
126 spinlock_t type_lock; /* Protects type and type_dev
127 * pointer consistency.
129 enum devlink_port_type type;
130 enum devlink_port_type desired_type;
132 struct devlink_port_attrs attrs;
135 struct delayed_work type_warn_dw;
136 struct list_head reporter_list;
137 struct mutex reporters_lock; /* Protects reporter_list */
140 struct devlink_sb_pool_info {
141 enum devlink_sb_pool_type pool_type;
143 enum devlink_sb_threshold_type threshold_type;
148 * struct devlink_dpipe_field - dpipe field object
150 * @id: index inside the headers field array
151 * @bitwidth: bitwidth
152 * @mapping_type: mapping type
154 struct devlink_dpipe_field {
157 unsigned int bitwidth;
158 enum devlink_dpipe_field_mapping_type mapping_type;
162 * struct devlink_dpipe_header - dpipe header object
164 * @id: index, global/local detrmined by global bit
166 * @fields_count: number of fields
167 * @global: indicates if header is shared like most protocol header
170 struct devlink_dpipe_header {
173 struct devlink_dpipe_field *fields;
174 unsigned int fields_count;
179 * struct devlink_dpipe_match - represents match operation
180 * @type: type of match
181 * @header_index: header index (packets can have several headers of same
182 * type like in case of tunnels)
184 * @fieled_id: field index
186 struct devlink_dpipe_match {
187 enum devlink_dpipe_match_type type;
188 unsigned int header_index;
189 struct devlink_dpipe_header *header;
190 unsigned int field_id;
194 * struct devlink_dpipe_action - represents action operation
195 * @type: type of action
196 * @header_index: header index (packets can have several headers of same
197 * type like in case of tunnels)
199 * @fieled_id: field index
201 struct devlink_dpipe_action {
202 enum devlink_dpipe_action_type type;
203 unsigned int header_index;
204 struct devlink_dpipe_header *header;
205 unsigned int field_id;
209 * struct devlink_dpipe_value - represents value of match/action
212 * @mapping_value: in case the field has some mapping this value
213 * specified the mapping value
214 * @mapping_valid: specify if mapping value is valid
215 * @value_size: value size
219 struct devlink_dpipe_value {
221 struct devlink_dpipe_action *action;
222 struct devlink_dpipe_match *match;
224 unsigned int mapping_value;
226 unsigned int value_size;
232 * struct devlink_dpipe_entry - table entry object
233 * @index: index of the entry in the table
234 * @match_values: match values
235 * @matche_values_count: count of matches tuples
236 * @action_values: actions values
237 * @action_values_count: count of actions values
238 * @counter: value of counter
239 * @counter_valid: Specify if value is valid from hardware
241 struct devlink_dpipe_entry {
243 struct devlink_dpipe_value *match_values;
244 unsigned int match_values_count;
245 struct devlink_dpipe_value *action_values;
246 unsigned int action_values_count;
252 * struct devlink_dpipe_dump_ctx - context provided to driver in order
255 * @cmd: devlink command
257 * @nest: top attribute
260 struct devlink_dpipe_dump_ctx {
261 struct genl_info *info;
262 enum devlink_command cmd;
268 struct devlink_dpipe_table_ops;
271 * struct devlink_dpipe_table - table object
274 * @counters_enabled: indicates if counters are active
275 * @counter_control_extern: indicates if counter control is in dpipe or
277 * @resource_valid: Indicate that the resource id is valid
278 * @resource_id: relative resource this table is related to
279 * @resource_units: number of resource's unit consumed per table's entry
280 * @table_ops: table operations
283 struct devlink_dpipe_table {
285 struct list_head list;
287 bool counters_enabled;
288 bool counter_control_extern;
292 struct devlink_dpipe_table_ops *table_ops;
297 * struct devlink_dpipe_table_ops - dpipe_table ops
298 * @actions_dump - dumps all tables actions
299 * @matches_dump - dumps all tables matches
300 * @entries_dump - dumps all active entries in the table
301 * @counters_set_update - when changing the counter status hardware sync
302 * maybe needed to allocate/free counter related
304 * @size_get - get size
306 struct devlink_dpipe_table_ops {
307 int (*actions_dump)(void *priv, struct sk_buff *skb);
308 int (*matches_dump)(void *priv, struct sk_buff *skb);
309 int (*entries_dump)(void *priv, bool counters_enabled,
310 struct devlink_dpipe_dump_ctx *dump_ctx);
311 int (*counters_set_update)(void *priv, bool enable);
312 u64 (*size_get)(void *priv);
316 * struct devlink_dpipe_headers - dpipe headers
317 * @headers - header array can be shared (global bit) or driver specific
318 * @headers_count - count of headers
320 struct devlink_dpipe_headers {
321 struct devlink_dpipe_header **headers;
322 unsigned int headers_count;
326 * struct devlink_resource_size_params - resource's size parameters
327 * @size_min: minimum size which can be set
328 * @size_max: maximum size which can be set
329 * @size_granularity: size granularity
330 * @size_unit: resource's basic unit
332 struct devlink_resource_size_params {
335 u64 size_granularity;
336 enum devlink_resource_unit unit;
340 devlink_resource_size_params_init(struct devlink_resource_size_params *size_params,
341 u64 size_min, u64 size_max,
342 u64 size_granularity,
343 enum devlink_resource_unit unit)
345 size_params->size_min = size_min;
346 size_params->size_max = size_max;
347 size_params->size_granularity = size_granularity;
348 size_params->unit = unit;
351 typedef u64 devlink_resource_occ_get_t(void *priv);
354 * struct devlink_resource - devlink resource
355 * @name: name of the resource
356 * @id: id, per devlink instance
357 * @size: size of the resource
358 * @size_new: updated size of the resource, reload is needed
359 * @size_valid: valid in case the total size of the resource is valid
360 * including its children
361 * @parent: parent resource
362 * @size_params: size parameters
364 * @resource_list: list of child resources
366 struct devlink_resource {
372 struct devlink_resource *parent;
373 struct devlink_resource_size_params size_params;
374 struct list_head list;
375 struct list_head resource_list;
376 devlink_resource_occ_get_t *occ_get;
380 #define DEVLINK_RESOURCE_ID_PARENT_TOP 0
382 #define __DEVLINK_PARAM_MAX_STRING_VALUE 32
383 enum devlink_param_type {
384 DEVLINK_PARAM_TYPE_U8,
385 DEVLINK_PARAM_TYPE_U16,
386 DEVLINK_PARAM_TYPE_U32,
387 DEVLINK_PARAM_TYPE_STRING,
388 DEVLINK_PARAM_TYPE_BOOL,
391 union devlink_param_value {
395 char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];
399 struct devlink_param_gset_ctx {
400 union devlink_param_value val;
401 enum devlink_param_cmode cmode;
405 * struct devlink_flash_notify - devlink dev flash notify data
406 * @status_msg: current status string
407 * @component: firmware component being updated
408 * @done: amount of work completed of total amount
409 * @total: amount of work expected to be done
410 * @timeout: expected max timeout in seconds
412 * These are values to be given to userland to be displayed in order
413 * to show current activity in a firmware update process.
415 struct devlink_flash_notify {
416 const char *status_msg;
417 const char *component;
420 unsigned long timeout;
424 * struct devlink_param - devlink configuration parameter data
425 * @name: name of the parameter
426 * @generic: indicates if the parameter is generic or driver specific
427 * @type: parameter type
428 * @supported_cmodes: bitmap of supported configuration modes
429 * @get: get parameter value, used for runtime and permanent
430 * configuration modes
431 * @set: set parameter value, used for runtime and permanent
432 * configuration modes
433 * @validate: validate input value is applicable (within value range, etc.)
435 * This struct should be used by the driver to fill the data for
436 * a parameter it registers.
438 struct devlink_param {
442 enum devlink_param_type type;
443 unsigned long supported_cmodes;
444 int (*get)(struct devlink *devlink, u32 id,
445 struct devlink_param_gset_ctx *ctx);
446 int (*set)(struct devlink *devlink, u32 id,
447 struct devlink_param_gset_ctx *ctx);
448 int (*validate)(struct devlink *devlink, u32 id,
449 union devlink_param_value val,
450 struct netlink_ext_ack *extack);
453 struct devlink_param_item {
454 struct list_head list;
455 const struct devlink_param *param;
456 union devlink_param_value driverinit_value;
457 bool driverinit_value_valid;
461 enum devlink_param_generic_id {
462 DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
463 DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
464 DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
465 DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT,
466 DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI,
467 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
468 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
469 DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY,
470 DEVLINK_PARAM_GENERIC_ID_RESET_DEV_ON_DRV_PROBE,
471 DEVLINK_PARAM_GENERIC_ID_ENABLE_ROCE,
472 DEVLINK_PARAM_GENERIC_ID_ENABLE_REMOTE_DEV_RESET,
474 /* add new param generic ids above here*/
475 __DEVLINK_PARAM_GENERIC_ID_MAX,
476 DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
479 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
480 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
482 #define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
483 #define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
485 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
486 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
488 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable"
489 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL
491 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari"
492 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL
494 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max"
495 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32
497 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min"
498 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32
500 #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy"
501 #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8
503 #define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_NAME \
504 "reset_dev_on_drv_probe"
505 #define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_TYPE DEVLINK_PARAM_TYPE_U8
507 #define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_NAME "enable_roce"
508 #define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_TYPE DEVLINK_PARAM_TYPE_BOOL
510 #define DEVLINK_PARAM_GENERIC_ENABLE_REMOTE_DEV_RESET_NAME "enable_remote_dev_reset"
511 #define DEVLINK_PARAM_GENERIC_ENABLE_REMOTE_DEV_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
513 #define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \
515 .id = DEVLINK_PARAM_GENERIC_ID_##_id, \
516 .name = DEVLINK_PARAM_GENERIC_##_id##_NAME, \
517 .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE, \
519 .supported_cmodes = _cmodes, \
522 .validate = _validate, \
525 #define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate) \
530 .supported_cmodes = _cmodes, \
533 .validate = _validate, \
536 /* Part number, identifier of board design */
537 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID "board.id"
538 /* Revision of board design */
539 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV "board.rev"
540 /* Maker of the board */
541 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_MANUFACTURE "board.manufacture"
543 /* Part number, identifier of asic design */
544 #define DEVLINK_INFO_VERSION_GENERIC_ASIC_ID "asic.id"
545 /* Revision of asic design */
546 #define DEVLINK_INFO_VERSION_GENERIC_ASIC_REV "asic.rev"
548 /* Overall FW version */
549 #define DEVLINK_INFO_VERSION_GENERIC_FW "fw"
550 /* Control processor FW version */
551 #define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT "fw.mgmt"
552 /* FW interface specification version */
553 #define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT_API "fw.mgmt.api"
554 /* Data path microcode controlling high-speed packet processing */
555 #define DEVLINK_INFO_VERSION_GENERIC_FW_APP "fw.app"
556 /* UNDI software version */
557 #define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI "fw.undi"
558 /* NCSI support/handler version */
559 #define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI "fw.ncsi"
560 /* FW parameter set id */
561 #define DEVLINK_INFO_VERSION_GENERIC_FW_PSID "fw.psid"
562 /* RoCE FW version */
563 #define DEVLINK_INFO_VERSION_GENERIC_FW_ROCE "fw.roce"
564 /* Firmware bundle identifier */
565 #define DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID "fw.bundle_id"
568 * struct devlink_flash_update_params - Flash Update parameters
569 * @file_name: the name of the flash firmware file to update from
570 * @component: the flash component to update
572 * With the exception of file_name, drivers must opt-in to parameters by
573 * setting the appropriate bit in the supported_flash_update_params field in
574 * their devlink_ops structure.
576 struct devlink_flash_update_params {
577 const char *file_name;
578 const char *component;
582 #define DEVLINK_SUPPORT_FLASH_UPDATE_COMPONENT BIT(0)
583 #define DEVLINK_SUPPORT_FLASH_UPDATE_OVERWRITE_MASK BIT(1)
585 struct devlink_region;
586 struct devlink_info_req;
589 * struct devlink_region_ops - Region operations
591 * @destructor: callback used to free snapshot memory when deleting
592 * @snapshot: callback to request an immediate snapshot. On success,
593 * the data variable must be updated to point to the snapshot data.
594 * The function will be called while the devlink instance lock is
596 * @priv: Pointer to driver private data for the region operation
598 struct devlink_region_ops {
600 void (*destructor)(const void *data);
601 int (*snapshot)(struct devlink *devlink,
602 const struct devlink_region_ops *ops,
603 struct netlink_ext_ack *extack,
609 * struct devlink_port_region_ops - Region operations for a port
611 * @destructor: callback used to free snapshot memory when deleting
612 * @snapshot: callback to request an immediate snapshot. On success,
613 * the data variable must be updated to point to the snapshot data.
614 * The function will be called while the devlink instance lock is
616 * @priv: Pointer to driver private data for the region operation
618 struct devlink_port_region_ops {
620 void (*destructor)(const void *data);
621 int (*snapshot)(struct devlink_port *port,
622 const struct devlink_port_region_ops *ops,
623 struct netlink_ext_ack *extack,
629 struct devlink_health_reporter;
631 enum devlink_health_reporter_state {
632 DEVLINK_HEALTH_REPORTER_STATE_HEALTHY,
633 DEVLINK_HEALTH_REPORTER_STATE_ERROR,
637 * struct devlink_health_reporter_ops - Reporter operations
638 * @name: reporter name
639 * @recover: callback to recover from reported error
640 * if priv_ctx is NULL, run a full recover
641 * @dump: callback to dump an object
642 * if priv_ctx is NULL, run a full dump
643 * @diagnose: callback to diagnose the current status
644 * @test: callback to trigger a test event
647 struct devlink_health_reporter_ops {
649 int (*recover)(struct devlink_health_reporter *reporter,
650 void *priv_ctx, struct netlink_ext_ack *extack);
651 int (*dump)(struct devlink_health_reporter *reporter,
652 struct devlink_fmsg *fmsg, void *priv_ctx,
653 struct netlink_ext_ack *extack);
654 int (*diagnose)(struct devlink_health_reporter *reporter,
655 struct devlink_fmsg *fmsg,
656 struct netlink_ext_ack *extack);
657 int (*test)(struct devlink_health_reporter *reporter,
658 struct netlink_ext_ack *extack);
662 * struct devlink_trap_metadata - Packet trap metadata.
663 * @trap_name: Trap name.
664 * @trap_group_name: Trap group name.
665 * @input_dev: Input netdevice.
666 * @fa_cookie: Flow action user cookie.
667 * @trap_type: Trap type.
669 struct devlink_trap_metadata {
670 const char *trap_name;
671 const char *trap_group_name;
672 struct net_device *input_dev;
673 const struct flow_action_cookie *fa_cookie;
674 enum devlink_trap_type trap_type;
678 * struct devlink_trap_policer - Immutable packet trap policer attributes.
679 * @id: Policer identifier.
680 * @init_rate: Initial rate in packets / sec.
681 * @init_burst: Initial burst size in packets.
682 * @max_rate: Maximum rate.
683 * @min_rate: Minimum rate.
684 * @max_burst: Maximum burst size.
685 * @min_burst: Minimum burst size.
687 * Describes immutable attributes of packet trap policers that drivers register
690 struct devlink_trap_policer {
701 * struct devlink_trap_group - Immutable packet trap group attributes.
702 * @name: Trap group name.
703 * @id: Trap group identifier.
704 * @generic: Whether the trap group is generic or not.
705 * @init_policer_id: Initial policer identifier.
707 * Describes immutable attributes of packet trap groups that drivers register
710 struct devlink_trap_group {
717 #define DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT BIT(0)
718 #define DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE BIT(1)
721 * struct devlink_trap - Immutable packet trap attributes.
723 * @init_action: Initial trap action.
724 * @generic: Whether the trap is generic or not.
725 * @id: Trap identifier.
727 * @init_group_id: Initial group identifier.
728 * @metadata_cap: Metadata types that can be provided by the trap.
730 * Describes immutable attributes of packet traps that drivers register with
733 struct devlink_trap {
734 enum devlink_trap_type type;
735 enum devlink_trap_action init_action;
743 /* All traps must be documented in
744 * Documentation/networking/devlink/devlink-trap.rst
746 enum devlink_trap_generic_id {
747 DEVLINK_TRAP_GENERIC_ID_SMAC_MC,
748 DEVLINK_TRAP_GENERIC_ID_VLAN_TAG_MISMATCH,
749 DEVLINK_TRAP_GENERIC_ID_INGRESS_VLAN_FILTER,
750 DEVLINK_TRAP_GENERIC_ID_INGRESS_STP_FILTER,
751 DEVLINK_TRAP_GENERIC_ID_EMPTY_TX_LIST,
752 DEVLINK_TRAP_GENERIC_ID_PORT_LOOPBACK_FILTER,
753 DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_ROUTE,
754 DEVLINK_TRAP_GENERIC_ID_TTL_ERROR,
755 DEVLINK_TRAP_GENERIC_ID_TAIL_DROP,
756 DEVLINK_TRAP_GENERIC_ID_NON_IP_PACKET,
757 DEVLINK_TRAP_GENERIC_ID_UC_DIP_MC_DMAC,
758 DEVLINK_TRAP_GENERIC_ID_DIP_LB,
759 DEVLINK_TRAP_GENERIC_ID_SIP_MC,
760 DEVLINK_TRAP_GENERIC_ID_SIP_LB,
761 DEVLINK_TRAP_GENERIC_ID_CORRUPTED_IP_HDR,
762 DEVLINK_TRAP_GENERIC_ID_IPV4_SIP_BC,
763 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_RESERVED_SCOPE,
764 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE,
765 DEVLINK_TRAP_GENERIC_ID_MTU_ERROR,
766 DEVLINK_TRAP_GENERIC_ID_UNRESOLVED_NEIGH,
767 DEVLINK_TRAP_GENERIC_ID_RPF,
768 DEVLINK_TRAP_GENERIC_ID_REJECT_ROUTE,
769 DEVLINK_TRAP_GENERIC_ID_IPV4_LPM_UNICAST_MISS,
770 DEVLINK_TRAP_GENERIC_ID_IPV6_LPM_UNICAST_MISS,
771 DEVLINK_TRAP_GENERIC_ID_NON_ROUTABLE,
772 DEVLINK_TRAP_GENERIC_ID_DECAP_ERROR,
773 DEVLINK_TRAP_GENERIC_ID_OVERLAY_SMAC_MC,
774 DEVLINK_TRAP_GENERIC_ID_INGRESS_FLOW_ACTION_DROP,
775 DEVLINK_TRAP_GENERIC_ID_EGRESS_FLOW_ACTION_DROP,
776 DEVLINK_TRAP_GENERIC_ID_STP,
777 DEVLINK_TRAP_GENERIC_ID_LACP,
778 DEVLINK_TRAP_GENERIC_ID_LLDP,
779 DEVLINK_TRAP_GENERIC_ID_IGMP_QUERY,
780 DEVLINK_TRAP_GENERIC_ID_IGMP_V1_REPORT,
781 DEVLINK_TRAP_GENERIC_ID_IGMP_V2_REPORT,
782 DEVLINK_TRAP_GENERIC_ID_IGMP_V3_REPORT,
783 DEVLINK_TRAP_GENERIC_ID_IGMP_V2_LEAVE,
784 DEVLINK_TRAP_GENERIC_ID_MLD_QUERY,
785 DEVLINK_TRAP_GENERIC_ID_MLD_V1_REPORT,
786 DEVLINK_TRAP_GENERIC_ID_MLD_V2_REPORT,
787 DEVLINK_TRAP_GENERIC_ID_MLD_V1_DONE,
788 DEVLINK_TRAP_GENERIC_ID_IPV4_DHCP,
789 DEVLINK_TRAP_GENERIC_ID_IPV6_DHCP,
790 DEVLINK_TRAP_GENERIC_ID_ARP_REQUEST,
791 DEVLINK_TRAP_GENERIC_ID_ARP_RESPONSE,
792 DEVLINK_TRAP_GENERIC_ID_ARP_OVERLAY,
793 DEVLINK_TRAP_GENERIC_ID_IPV6_NEIGH_SOLICIT,
794 DEVLINK_TRAP_GENERIC_ID_IPV6_NEIGH_ADVERT,
795 DEVLINK_TRAP_GENERIC_ID_IPV4_BFD,
796 DEVLINK_TRAP_GENERIC_ID_IPV6_BFD,
797 DEVLINK_TRAP_GENERIC_ID_IPV4_OSPF,
798 DEVLINK_TRAP_GENERIC_ID_IPV6_OSPF,
799 DEVLINK_TRAP_GENERIC_ID_IPV4_BGP,
800 DEVLINK_TRAP_GENERIC_ID_IPV6_BGP,
801 DEVLINK_TRAP_GENERIC_ID_IPV4_VRRP,
802 DEVLINK_TRAP_GENERIC_ID_IPV6_VRRP,
803 DEVLINK_TRAP_GENERIC_ID_IPV4_PIM,
804 DEVLINK_TRAP_GENERIC_ID_IPV6_PIM,
805 DEVLINK_TRAP_GENERIC_ID_UC_LB,
806 DEVLINK_TRAP_GENERIC_ID_LOCAL_ROUTE,
807 DEVLINK_TRAP_GENERIC_ID_EXTERNAL_ROUTE,
808 DEVLINK_TRAP_GENERIC_ID_IPV6_UC_DIP_LINK_LOCAL_SCOPE,
809 DEVLINK_TRAP_GENERIC_ID_IPV6_DIP_ALL_NODES,
810 DEVLINK_TRAP_GENERIC_ID_IPV6_DIP_ALL_ROUTERS,
811 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_SOLICIT,
812 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_ADVERT,
813 DEVLINK_TRAP_GENERIC_ID_IPV6_REDIRECT,
814 DEVLINK_TRAP_GENERIC_ID_IPV4_ROUTER_ALERT,
815 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_ALERT,
816 DEVLINK_TRAP_GENERIC_ID_PTP_EVENT,
817 DEVLINK_TRAP_GENERIC_ID_PTP_GENERAL,
818 DEVLINK_TRAP_GENERIC_ID_FLOW_ACTION_SAMPLE,
819 DEVLINK_TRAP_GENERIC_ID_FLOW_ACTION_TRAP,
820 DEVLINK_TRAP_GENERIC_ID_EARLY_DROP,
821 DEVLINK_TRAP_GENERIC_ID_VXLAN_PARSING,
822 DEVLINK_TRAP_GENERIC_ID_LLC_SNAP_PARSING,
823 DEVLINK_TRAP_GENERIC_ID_VLAN_PARSING,
824 DEVLINK_TRAP_GENERIC_ID_PPPOE_PPP_PARSING,
825 DEVLINK_TRAP_GENERIC_ID_MPLS_PARSING,
826 DEVLINK_TRAP_GENERIC_ID_ARP_PARSING,
827 DEVLINK_TRAP_GENERIC_ID_IP_1_PARSING,
828 DEVLINK_TRAP_GENERIC_ID_IP_N_PARSING,
829 DEVLINK_TRAP_GENERIC_ID_GRE_PARSING,
830 DEVLINK_TRAP_GENERIC_ID_UDP_PARSING,
831 DEVLINK_TRAP_GENERIC_ID_TCP_PARSING,
832 DEVLINK_TRAP_GENERIC_ID_IPSEC_PARSING,
833 DEVLINK_TRAP_GENERIC_ID_SCTP_PARSING,
834 DEVLINK_TRAP_GENERIC_ID_DCCP_PARSING,
835 DEVLINK_TRAP_GENERIC_ID_GTP_PARSING,
836 DEVLINK_TRAP_GENERIC_ID_ESP_PARSING,
838 /* Add new generic trap IDs above */
839 __DEVLINK_TRAP_GENERIC_ID_MAX,
840 DEVLINK_TRAP_GENERIC_ID_MAX = __DEVLINK_TRAP_GENERIC_ID_MAX - 1,
843 /* All trap groups must be documented in
844 * Documentation/networking/devlink/devlink-trap.rst
846 enum devlink_trap_group_generic_id {
847 DEVLINK_TRAP_GROUP_GENERIC_ID_L2_DROPS,
848 DEVLINK_TRAP_GROUP_GENERIC_ID_L3_DROPS,
849 DEVLINK_TRAP_GROUP_GENERIC_ID_L3_EXCEPTIONS,
850 DEVLINK_TRAP_GROUP_GENERIC_ID_BUFFER_DROPS,
851 DEVLINK_TRAP_GROUP_GENERIC_ID_TUNNEL_DROPS,
852 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_DROPS,
853 DEVLINK_TRAP_GROUP_GENERIC_ID_STP,
854 DEVLINK_TRAP_GROUP_GENERIC_ID_LACP,
855 DEVLINK_TRAP_GROUP_GENERIC_ID_LLDP,
856 DEVLINK_TRAP_GROUP_GENERIC_ID_MC_SNOOPING,
857 DEVLINK_TRAP_GROUP_GENERIC_ID_DHCP,
858 DEVLINK_TRAP_GROUP_GENERIC_ID_NEIGH_DISCOVERY,
859 DEVLINK_TRAP_GROUP_GENERIC_ID_BFD,
860 DEVLINK_TRAP_GROUP_GENERIC_ID_OSPF,
861 DEVLINK_TRAP_GROUP_GENERIC_ID_BGP,
862 DEVLINK_TRAP_GROUP_GENERIC_ID_VRRP,
863 DEVLINK_TRAP_GROUP_GENERIC_ID_PIM,
864 DEVLINK_TRAP_GROUP_GENERIC_ID_UC_LB,
865 DEVLINK_TRAP_GROUP_GENERIC_ID_LOCAL_DELIVERY,
866 DEVLINK_TRAP_GROUP_GENERIC_ID_EXTERNAL_DELIVERY,
867 DEVLINK_TRAP_GROUP_GENERIC_ID_IPV6,
868 DEVLINK_TRAP_GROUP_GENERIC_ID_PTP_EVENT,
869 DEVLINK_TRAP_GROUP_GENERIC_ID_PTP_GENERAL,
870 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_SAMPLE,
871 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_TRAP,
872 DEVLINK_TRAP_GROUP_GENERIC_ID_PARSER_ERROR_DROPS,
874 /* Add new generic trap group IDs above */
875 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX,
876 DEVLINK_TRAP_GROUP_GENERIC_ID_MAX =
877 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX - 1,
880 #define DEVLINK_TRAP_GENERIC_NAME_SMAC_MC \
881 "source_mac_is_multicast"
882 #define DEVLINK_TRAP_GENERIC_NAME_VLAN_TAG_MISMATCH \
884 #define DEVLINK_TRAP_GENERIC_NAME_INGRESS_VLAN_FILTER \
885 "ingress_vlan_filter"
886 #define DEVLINK_TRAP_GENERIC_NAME_INGRESS_STP_FILTER \
887 "ingress_spanning_tree_filter"
888 #define DEVLINK_TRAP_GENERIC_NAME_EMPTY_TX_LIST \
890 #define DEVLINK_TRAP_GENERIC_NAME_PORT_LOOPBACK_FILTER \
891 "port_loopback_filter"
892 #define DEVLINK_TRAP_GENERIC_NAME_BLACKHOLE_ROUTE \
894 #define DEVLINK_TRAP_GENERIC_NAME_TTL_ERROR \
895 "ttl_value_is_too_small"
896 #define DEVLINK_TRAP_GENERIC_NAME_TAIL_DROP \
898 #define DEVLINK_TRAP_GENERIC_NAME_NON_IP_PACKET \
900 #define DEVLINK_TRAP_GENERIC_NAME_UC_DIP_MC_DMAC \
901 "uc_dip_over_mc_dmac"
902 #define DEVLINK_TRAP_GENERIC_NAME_DIP_LB \
903 "dip_is_loopback_address"
904 #define DEVLINK_TRAP_GENERIC_NAME_SIP_MC \
906 #define DEVLINK_TRAP_GENERIC_NAME_SIP_LB \
907 "sip_is_loopback_address"
908 #define DEVLINK_TRAP_GENERIC_NAME_CORRUPTED_IP_HDR \
909 "ip_header_corrupted"
910 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_SIP_BC \
911 "ipv4_sip_is_limited_bc"
912 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_RESERVED_SCOPE \
913 "ipv6_mc_dip_reserved_scope"
914 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE \
915 "ipv6_mc_dip_interface_local_scope"
916 #define DEVLINK_TRAP_GENERIC_NAME_MTU_ERROR \
917 "mtu_value_is_too_small"
918 #define DEVLINK_TRAP_GENERIC_NAME_UNRESOLVED_NEIGH \
920 #define DEVLINK_TRAP_GENERIC_NAME_RPF \
921 "mc_reverse_path_forwarding"
922 #define DEVLINK_TRAP_GENERIC_NAME_REJECT_ROUTE \
924 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_LPM_UNICAST_MISS \
926 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_LPM_UNICAST_MISS \
928 #define DEVLINK_TRAP_GENERIC_NAME_NON_ROUTABLE \
929 "non_routable_packet"
930 #define DEVLINK_TRAP_GENERIC_NAME_DECAP_ERROR \
932 #define DEVLINK_TRAP_GENERIC_NAME_OVERLAY_SMAC_MC \
934 #define DEVLINK_TRAP_GENERIC_NAME_INGRESS_FLOW_ACTION_DROP \
935 "ingress_flow_action_drop"
936 #define DEVLINK_TRAP_GENERIC_NAME_EGRESS_FLOW_ACTION_DROP \
937 "egress_flow_action_drop"
938 #define DEVLINK_TRAP_GENERIC_NAME_STP \
940 #define DEVLINK_TRAP_GENERIC_NAME_LACP \
942 #define DEVLINK_TRAP_GENERIC_NAME_LLDP \
944 #define DEVLINK_TRAP_GENERIC_NAME_IGMP_QUERY \
946 #define DEVLINK_TRAP_GENERIC_NAME_IGMP_V1_REPORT \
948 #define DEVLINK_TRAP_GENERIC_NAME_IGMP_V2_REPORT \
950 #define DEVLINK_TRAP_GENERIC_NAME_IGMP_V3_REPORT \
952 #define DEVLINK_TRAP_GENERIC_NAME_IGMP_V2_LEAVE \
954 #define DEVLINK_TRAP_GENERIC_NAME_MLD_QUERY \
956 #define DEVLINK_TRAP_GENERIC_NAME_MLD_V1_REPORT \
958 #define DEVLINK_TRAP_GENERIC_NAME_MLD_V2_REPORT \
960 #define DEVLINK_TRAP_GENERIC_NAME_MLD_V1_DONE \
962 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_DHCP \
964 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_DHCP \
966 #define DEVLINK_TRAP_GENERIC_NAME_ARP_REQUEST \
968 #define DEVLINK_TRAP_GENERIC_NAME_ARP_RESPONSE \
970 #define DEVLINK_TRAP_GENERIC_NAME_ARP_OVERLAY \
972 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_NEIGH_SOLICIT \
974 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_NEIGH_ADVERT \
976 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_BFD \
978 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_BFD \
980 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_OSPF \
982 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_OSPF \
984 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_BGP \
986 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_BGP \
988 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_VRRP \
990 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_VRRP \
992 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_PIM \
994 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_PIM \
996 #define DEVLINK_TRAP_GENERIC_NAME_UC_LB \
998 #define DEVLINK_TRAP_GENERIC_NAME_LOCAL_ROUTE \
1000 #define DEVLINK_TRAP_GENERIC_NAME_EXTERNAL_ROUTE \
1002 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_UC_DIP_LINK_LOCAL_SCOPE \
1003 "ipv6_uc_dip_link_local_scope"
1004 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_DIP_ALL_NODES \
1005 "ipv6_dip_all_nodes"
1006 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_DIP_ALL_ROUTERS \
1007 "ipv6_dip_all_routers"
1008 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_SOLICIT \
1009 "ipv6_router_solicit"
1010 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_ADVERT \
1011 "ipv6_router_advert"
1012 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_REDIRECT \
1014 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_ROUTER_ALERT \
1016 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_ALERT \
1018 #define DEVLINK_TRAP_GENERIC_NAME_PTP_EVENT \
1020 #define DEVLINK_TRAP_GENERIC_NAME_PTP_GENERAL \
1022 #define DEVLINK_TRAP_GENERIC_NAME_FLOW_ACTION_SAMPLE \
1023 "flow_action_sample"
1024 #define DEVLINK_TRAP_GENERIC_NAME_FLOW_ACTION_TRAP \
1026 #define DEVLINK_TRAP_GENERIC_NAME_EARLY_DROP \
1028 #define DEVLINK_TRAP_GENERIC_NAME_VXLAN_PARSING \
1030 #define DEVLINK_TRAP_GENERIC_NAME_LLC_SNAP_PARSING \
1032 #define DEVLINK_TRAP_GENERIC_NAME_VLAN_PARSING \
1034 #define DEVLINK_TRAP_GENERIC_NAME_PPPOE_PPP_PARSING \
1036 #define DEVLINK_TRAP_GENERIC_NAME_MPLS_PARSING \
1038 #define DEVLINK_TRAP_GENERIC_NAME_ARP_PARSING \
1040 #define DEVLINK_TRAP_GENERIC_NAME_IP_1_PARSING \
1042 #define DEVLINK_TRAP_GENERIC_NAME_IP_N_PARSING \
1044 #define DEVLINK_TRAP_GENERIC_NAME_GRE_PARSING \
1046 #define DEVLINK_TRAP_GENERIC_NAME_UDP_PARSING \
1048 #define DEVLINK_TRAP_GENERIC_NAME_TCP_PARSING \
1050 #define DEVLINK_TRAP_GENERIC_NAME_IPSEC_PARSING \
1052 #define DEVLINK_TRAP_GENERIC_NAME_SCTP_PARSING \
1054 #define DEVLINK_TRAP_GENERIC_NAME_DCCP_PARSING \
1056 #define DEVLINK_TRAP_GENERIC_NAME_GTP_PARSING \
1058 #define DEVLINK_TRAP_GENERIC_NAME_ESP_PARSING \
1062 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_L2_DROPS \
1064 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_DROPS \
1066 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_EXCEPTIONS \
1068 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_BUFFER_DROPS \
1070 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_TUNNEL_DROPS \
1072 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_DROPS \
1074 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_STP \
1076 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_LACP \
1078 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_LLDP \
1080 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_MC_SNOOPING \
1082 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_DHCP \
1084 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_NEIGH_DISCOVERY \
1086 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_BFD \
1088 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_OSPF \
1090 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_BGP \
1092 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_VRRP \
1094 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_PIM \
1096 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_UC_LB \
1098 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_LOCAL_DELIVERY \
1100 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_EXTERNAL_DELIVERY \
1102 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_IPV6 \
1104 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_PTP_EVENT \
1106 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_PTP_GENERAL \
1108 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_SAMPLE \
1110 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_TRAP \
1112 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_PARSER_ERROR_DROPS \
1113 "parser_error_drops"
1115 #define DEVLINK_TRAP_GENERIC(_type, _init_action, _id, _group_id, \
1118 .type = DEVLINK_TRAP_TYPE_##_type, \
1119 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
1121 .id = DEVLINK_TRAP_GENERIC_ID_##_id, \
1122 .name = DEVLINK_TRAP_GENERIC_NAME_##_id, \
1123 .init_group_id = _group_id, \
1124 .metadata_cap = _metadata_cap, \
1127 #define DEVLINK_TRAP_DRIVER(_type, _init_action, _id, _name, _group_id, \
1130 .type = DEVLINK_TRAP_TYPE_##_type, \
1131 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
1135 .init_group_id = _group_id, \
1136 .metadata_cap = _metadata_cap, \
1139 #define DEVLINK_TRAP_GROUP_GENERIC(_id, _policer_id) \
1141 .name = DEVLINK_TRAP_GROUP_GENERIC_NAME_##_id, \
1142 .id = DEVLINK_TRAP_GROUP_GENERIC_ID_##_id, \
1144 .init_policer_id = _policer_id, \
1147 #define DEVLINK_TRAP_POLICER(_id, _rate, _burst, _max_rate, _min_rate, \
1148 _max_burst, _min_burst) \
1151 .init_rate = _rate, \
1152 .init_burst = _burst, \
1153 .max_rate = _max_rate, \
1154 .min_rate = _min_rate, \
1155 .max_burst = _max_burst, \
1156 .min_burst = _min_burst, \
1159 struct devlink_ops {
1161 * @supported_flash_update_params:
1162 * mask of parameters supported by the driver's .flash_update
1165 u32 supported_flash_update_params;
1166 unsigned long reload_actions;
1167 unsigned long reload_limits;
1168 int (*reload_down)(struct devlink *devlink, bool netns_change,
1169 enum devlink_reload_action action,
1170 enum devlink_reload_limit limit,
1171 struct netlink_ext_ack *extack);
1172 int (*reload_up)(struct devlink *devlink, enum devlink_reload_action action,
1173 enum devlink_reload_limit limit, u32 *actions_performed,
1174 struct netlink_ext_ack *extack);
1175 int (*port_type_set)(struct devlink_port *devlink_port,
1176 enum devlink_port_type port_type);
1177 int (*port_split)(struct devlink *devlink, unsigned int port_index,
1178 unsigned int count, struct netlink_ext_ack *extack);
1179 int (*port_unsplit)(struct devlink *devlink, unsigned int port_index,
1180 struct netlink_ext_ack *extack);
1181 int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
1183 struct devlink_sb_pool_info *pool_info);
1184 int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
1185 u16 pool_index, u32 size,
1186 enum devlink_sb_threshold_type threshold_type,
1187 struct netlink_ext_ack *extack);
1188 int (*sb_port_pool_get)(struct devlink_port *devlink_port,
1189 unsigned int sb_index, u16 pool_index,
1191 int (*sb_port_pool_set)(struct devlink_port *devlink_port,
1192 unsigned int sb_index, u16 pool_index,
1193 u32 threshold, struct netlink_ext_ack *extack);
1194 int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
1195 unsigned int sb_index,
1197 enum devlink_sb_pool_type pool_type,
1198 u16 *p_pool_index, u32 *p_threshold);
1199 int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
1200 unsigned int sb_index,
1202 enum devlink_sb_pool_type pool_type,
1203 u16 pool_index, u32 threshold,
1204 struct netlink_ext_ack *extack);
1205 int (*sb_occ_snapshot)(struct devlink *devlink,
1206 unsigned int sb_index);
1207 int (*sb_occ_max_clear)(struct devlink *devlink,
1208 unsigned int sb_index);
1209 int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
1210 unsigned int sb_index, u16 pool_index,
1211 u32 *p_cur, u32 *p_max);
1212 int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
1213 unsigned int sb_index,
1215 enum devlink_sb_pool_type pool_type,
1216 u32 *p_cur, u32 *p_max);
1218 int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
1219 int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
1220 struct netlink_ext_ack *extack);
1221 int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
1222 int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
1223 struct netlink_ext_ack *extack);
1224 int (*eswitch_encap_mode_get)(struct devlink *devlink,
1225 enum devlink_eswitch_encap_mode *p_encap_mode);
1226 int (*eswitch_encap_mode_set)(struct devlink *devlink,
1227 enum devlink_eswitch_encap_mode encap_mode,
1228 struct netlink_ext_ack *extack);
1229 int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
1230 struct netlink_ext_ack *extack);
1232 * @flash_update: Device flash update function
1234 * Used to perform a flash update for the device. The set of
1235 * parameters supported by the driver should be set in
1236 * supported_flash_update_params.
1238 int (*flash_update)(struct devlink *devlink,
1239 struct devlink_flash_update_params *params,
1240 struct netlink_ext_ack *extack);
1242 * @trap_init: Trap initialization function.
1244 * Should be used by device drivers to initialize the trap in the
1245 * underlying device. Drivers should also store the provided trap
1246 * context, so that they could efficiently pass it to
1247 * devlink_trap_report() when the trap is triggered.
1249 int (*trap_init)(struct devlink *devlink,
1250 const struct devlink_trap *trap, void *trap_ctx);
1252 * @trap_fini: Trap de-initialization function.
1254 * Should be used by device drivers to de-initialize the trap in the
1255 * underlying device.
1257 void (*trap_fini)(struct devlink *devlink,
1258 const struct devlink_trap *trap, void *trap_ctx);
1260 * @trap_action_set: Trap action set function.
1262 int (*trap_action_set)(struct devlink *devlink,
1263 const struct devlink_trap *trap,
1264 enum devlink_trap_action action,
1265 struct netlink_ext_ack *extack);
1267 * @trap_group_init: Trap group initialization function.
1269 * Should be used by device drivers to initialize the trap group in the
1270 * underlying device.
1272 int (*trap_group_init)(struct devlink *devlink,
1273 const struct devlink_trap_group *group);
1275 * @trap_group_set: Trap group parameters set function.
1277 * Note: @policer can be NULL when a policer is being unbound from
1280 int (*trap_group_set)(struct devlink *devlink,
1281 const struct devlink_trap_group *group,
1282 const struct devlink_trap_policer *policer,
1283 struct netlink_ext_ack *extack);
1285 * @trap_group_action_set: Trap group action set function.
1287 * If this callback is populated, it will take precedence over looping
1288 * over all traps in a group and calling .trap_action_set().
1290 int (*trap_group_action_set)(struct devlink *devlink,
1291 const struct devlink_trap_group *group,
1292 enum devlink_trap_action action,
1293 struct netlink_ext_ack *extack);
1295 * @trap_policer_init: Trap policer initialization function.
1297 * Should be used by device drivers to initialize the trap policer in
1298 * the underlying device.
1300 int (*trap_policer_init)(struct devlink *devlink,
1301 const struct devlink_trap_policer *policer);
1303 * @trap_policer_fini: Trap policer de-initialization function.
1305 * Should be used by device drivers to de-initialize the trap policer
1306 * in the underlying device.
1308 void (*trap_policer_fini)(struct devlink *devlink,
1309 const struct devlink_trap_policer *policer);
1311 * @trap_policer_set: Trap policer parameters set function.
1313 int (*trap_policer_set)(struct devlink *devlink,
1314 const struct devlink_trap_policer *policer,
1315 u64 rate, u64 burst,
1316 struct netlink_ext_ack *extack);
1318 * @trap_policer_counter_get: Trap policer counter get function.
1320 * Should be used by device drivers to report number of packets dropped
1323 int (*trap_policer_counter_get)(struct devlink *devlink,
1324 const struct devlink_trap_policer *policer,
1327 * @port_function_hw_addr_get: Port function's hardware address get function.
1329 * Should be used by device drivers to report the hardware address of a function managed
1330 * by the devlink port. Driver should return -EOPNOTSUPP if it doesn't support port
1331 * function handling for a particular port.
1333 * Note: @extack can be NULL when port notifier queries the port function.
1335 int (*port_function_hw_addr_get)(struct devlink *devlink, struct devlink_port *port,
1336 u8 *hw_addr, int *hw_addr_len,
1337 struct netlink_ext_ack *extack);
1339 * @port_function_hw_addr_set: Port function's hardware address set function.
1341 * Should be used by device drivers to set the hardware address of a function managed
1342 * by the devlink port. Driver should return -EOPNOTSUPP if it doesn't support port
1343 * function handling for a particular port.
1345 int (*port_function_hw_addr_set)(struct devlink *devlink, struct devlink_port *port,
1346 const u8 *hw_addr, int hw_addr_len,
1347 struct netlink_ext_ack *extack);
1350 static inline void *devlink_priv(struct devlink *devlink)
1353 return &devlink->priv;
1356 static inline struct devlink *priv_to_devlink(void *priv)
1359 return container_of(priv, struct devlink, priv);
1362 static inline struct devlink_port *
1363 netdev_to_devlink_port(struct net_device *dev)
1365 if (dev->netdev_ops->ndo_get_devlink_port)
1366 return dev->netdev_ops->ndo_get_devlink_port(dev);
1370 static inline struct devlink *netdev_to_devlink(struct net_device *dev)
1372 struct devlink_port *devlink_port = netdev_to_devlink_port(dev);
1375 return devlink_port->devlink;
1381 struct net *devlink_net(const struct devlink *devlink);
1382 void devlink_net_set(struct devlink *devlink, struct net *net);
1383 struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
1384 int devlink_register(struct devlink *devlink, struct device *dev);
1385 void devlink_unregister(struct devlink *devlink);
1386 void devlink_reload_enable(struct devlink *devlink);
1387 void devlink_reload_disable(struct devlink *devlink);
1388 void devlink_free(struct devlink *devlink);
1389 int devlink_port_register(struct devlink *devlink,
1390 struct devlink_port *devlink_port,
1391 unsigned int port_index);
1392 void devlink_port_unregister(struct devlink_port *devlink_port);
1393 void devlink_port_type_eth_set(struct devlink_port *devlink_port,
1394 struct net_device *netdev);
1395 void devlink_port_type_ib_set(struct devlink_port *devlink_port,
1396 struct ib_device *ibdev);
1397 void devlink_port_type_clear(struct devlink_port *devlink_port);
1398 void devlink_port_attrs_set(struct devlink_port *devlink_port,
1399 struct devlink_port_attrs *devlink_port_attrs);
1400 void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u32 controller,
1401 u16 pf, bool external);
1402 void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 controller,
1403 u16 pf, u16 vf, bool external);
1404 int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
1405 u32 size, u16 ingress_pools_count,
1406 u16 egress_pools_count, u16 ingress_tc_count,
1407 u16 egress_tc_count);
1408 void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
1409 int devlink_dpipe_table_register(struct devlink *devlink,
1410 const char *table_name,
1411 struct devlink_dpipe_table_ops *table_ops,
1412 void *priv, bool counter_control_extern);
1413 void devlink_dpipe_table_unregister(struct devlink *devlink,
1414 const char *table_name);
1415 int devlink_dpipe_headers_register(struct devlink *devlink,
1416 struct devlink_dpipe_headers *dpipe_headers);
1417 void devlink_dpipe_headers_unregister(struct devlink *devlink);
1418 bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
1419 const char *table_name);
1420 int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
1421 int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
1422 struct devlink_dpipe_entry *entry);
1423 int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
1424 void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
1425 int devlink_dpipe_action_put(struct sk_buff *skb,
1426 struct devlink_dpipe_action *action);
1427 int devlink_dpipe_match_put(struct sk_buff *skb,
1428 struct devlink_dpipe_match *match);
1429 extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
1430 extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
1431 extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
1433 int devlink_resource_register(struct devlink *devlink,
1434 const char *resource_name,
1437 u64 parent_resource_id,
1438 const struct devlink_resource_size_params *size_params);
1439 void devlink_resources_unregister(struct devlink *devlink,
1440 struct devlink_resource *resource);
1441 int devlink_resource_size_get(struct devlink *devlink,
1443 u64 *p_resource_size);
1444 int devlink_dpipe_table_resource_set(struct devlink *devlink,
1445 const char *table_name, u64 resource_id,
1446 u64 resource_units);
1447 void devlink_resource_occ_get_register(struct devlink *devlink,
1449 devlink_resource_occ_get_t *occ_get,
1450 void *occ_get_priv);
1451 void devlink_resource_occ_get_unregister(struct devlink *devlink,
1453 int devlink_params_register(struct devlink *devlink,
1454 const struct devlink_param *params,
1455 size_t params_count);
1456 void devlink_params_unregister(struct devlink *devlink,
1457 const struct devlink_param *params,
1458 size_t params_count);
1459 void devlink_params_publish(struct devlink *devlink);
1460 void devlink_params_unpublish(struct devlink *devlink);
1461 int devlink_port_params_register(struct devlink_port *devlink_port,
1462 const struct devlink_param *params,
1463 size_t params_count);
1464 void devlink_port_params_unregister(struct devlink_port *devlink_port,
1465 const struct devlink_param *params,
1466 size_t params_count);
1467 int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
1468 union devlink_param_value *init_val);
1469 int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
1470 union devlink_param_value init_val);
1472 devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
1474 union devlink_param_value *init_val);
1475 int devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
1477 union devlink_param_value init_val);
1478 void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
1479 void devlink_port_param_value_changed(struct devlink_port *devlink_port,
1481 void devlink_param_value_str_fill(union devlink_param_value *dst_val,
1483 struct devlink_region *
1484 devlink_region_create(struct devlink *devlink,
1485 const struct devlink_region_ops *ops,
1486 u32 region_max_snapshots, u64 region_size);
1487 struct devlink_region *
1488 devlink_port_region_create(struct devlink_port *port,
1489 const struct devlink_port_region_ops *ops,
1490 u32 region_max_snapshots, u64 region_size);
1491 void devlink_region_destroy(struct devlink_region *region);
1492 void devlink_port_region_destroy(struct devlink_region *region);
1494 int devlink_region_snapshot_id_get(struct devlink *devlink, u32 *id);
1495 void devlink_region_snapshot_id_put(struct devlink *devlink, u32 id);
1496 int devlink_region_snapshot_create(struct devlink_region *region,
1497 u8 *data, u32 snapshot_id);
1498 int devlink_info_serial_number_put(struct devlink_info_req *req,
1500 int devlink_info_driver_name_put(struct devlink_info_req *req,
1502 int devlink_info_board_serial_number_put(struct devlink_info_req *req,
1504 int devlink_info_version_fixed_put(struct devlink_info_req *req,
1505 const char *version_name,
1506 const char *version_value);
1507 int devlink_info_version_stored_put(struct devlink_info_req *req,
1508 const char *version_name,
1509 const char *version_value);
1510 int devlink_info_version_running_put(struct devlink_info_req *req,
1511 const char *version_name,
1512 const char *version_value);
1514 int devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg);
1515 int devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg);
1517 int devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name);
1518 int devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg);
1520 int devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg,
1522 int devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg);
1523 int devlink_fmsg_binary_pair_nest_start(struct devlink_fmsg *fmsg,
1525 int devlink_fmsg_binary_pair_nest_end(struct devlink_fmsg *fmsg);
1527 int devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value);
1528 int devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value);
1529 int devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value);
1530 int devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value);
1531 int devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value);
1532 int devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value,
1535 int devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name,
1537 int devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name,
1539 int devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name,
1541 int devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name,
1543 int devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,
1545 int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
1546 const void *value, u32 value_len);
1548 struct devlink_health_reporter *
1549 devlink_health_reporter_create(struct devlink *devlink,
1550 const struct devlink_health_reporter_ops *ops,
1551 u64 graceful_period, void *priv);
1553 struct devlink_health_reporter *
1554 devlink_port_health_reporter_create(struct devlink_port *port,
1555 const struct devlink_health_reporter_ops *ops,
1556 u64 graceful_period, void *priv);
1559 devlink_health_reporter_destroy(struct devlink_health_reporter *reporter);
1562 devlink_port_health_reporter_destroy(struct devlink_health_reporter *reporter);
1565 devlink_health_reporter_priv(struct devlink_health_reporter *reporter);
1566 int devlink_health_report(struct devlink_health_reporter *reporter,
1567 const char *msg, void *priv_ctx);
1569 devlink_health_reporter_state_update(struct devlink_health_reporter *reporter,
1570 enum devlink_health_reporter_state state);
1572 devlink_health_reporter_recovery_done(struct devlink_health_reporter *reporter);
1574 bool devlink_is_reload_failed(const struct devlink *devlink);
1575 void devlink_remote_reload_actions_performed(struct devlink *devlink,
1576 enum devlink_reload_limit limit,
1577 u32 actions_performed);
1579 void devlink_flash_update_begin_notify(struct devlink *devlink);
1580 void devlink_flash_update_end_notify(struct devlink *devlink);
1581 void devlink_flash_update_status_notify(struct devlink *devlink,
1582 const char *status_msg,
1583 const char *component,
1585 unsigned long total);
1586 void devlink_flash_update_timeout_notify(struct devlink *devlink,
1587 const char *status_msg,
1588 const char *component,
1589 unsigned long timeout);
1591 int devlink_traps_register(struct devlink *devlink,
1592 const struct devlink_trap *traps,
1593 size_t traps_count, void *priv);
1594 void devlink_traps_unregister(struct devlink *devlink,
1595 const struct devlink_trap *traps,
1596 size_t traps_count);
1597 void devlink_trap_report(struct devlink *devlink, struct sk_buff *skb,
1598 void *trap_ctx, struct devlink_port *in_devlink_port,
1599 const struct flow_action_cookie *fa_cookie);
1600 void *devlink_trap_ctx_priv(void *trap_ctx);
1601 int devlink_trap_groups_register(struct devlink *devlink,
1602 const struct devlink_trap_group *groups,
1603 size_t groups_count);
1604 void devlink_trap_groups_unregister(struct devlink *devlink,
1605 const struct devlink_trap_group *groups,
1606 size_t groups_count);
1608 devlink_trap_policers_register(struct devlink *devlink,
1609 const struct devlink_trap_policer *policers,
1610 size_t policers_count);
1612 devlink_trap_policers_unregister(struct devlink *devlink,
1613 const struct devlink_trap_policer *policers,
1614 size_t policers_count);
1616 #if IS_ENABLED(CONFIG_NET_DEVLINK)
1618 void devlink_compat_running_version(struct net_device *dev,
1619 char *buf, size_t len);
1620 int devlink_compat_flash_update(struct net_device *dev, const char *file_name);
1621 int devlink_compat_phys_port_name_get(struct net_device *dev,
1622 char *name, size_t len);
1623 int devlink_compat_switch_id_get(struct net_device *dev,
1624 struct netdev_phys_item_id *ppid);
1629 devlink_compat_running_version(struct net_device *dev, char *buf, size_t len)
1634 devlink_compat_flash_update(struct net_device *dev, const char *file_name)
1640 devlink_compat_phys_port_name_get(struct net_device *dev,
1641 char *name, size_t len)
1647 devlink_compat_switch_id_get(struct net_device *dev,
1648 struct netdev_phys_item_id *ppid)
1655 #endif /* _NET_DEVLINK_H_ */