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>
26 struct list_head list;
27 struct list_head port_list;
28 struct list_head sb_list;
29 struct list_head dpipe_table_list;
30 struct list_head resource_list;
31 struct list_head param_list;
32 struct list_head region_list;
33 struct list_head reporter_list;
34 struct mutex reporters_lock; /* protects reporter_list */
35 struct devlink_dpipe_headers *dpipe_headers;
36 struct list_head trap_list;
37 struct list_head trap_group_list;
38 const struct devlink_ops *ops;
39 struct xarray snapshot_ids;
46 char priv[0] __aligned(NETDEV_ALIGN);
49 struct devlink_port_phys_attrs {
50 u32 port_number; /* Same value as "split group".
51 * A physical port which is visible to the user
52 * for a given port flavour.
54 u32 split_subport_number;
57 struct devlink_port_pci_pf_attrs {
58 u16 pf; /* Associated PCI PF for this port. */
61 struct devlink_port_pci_vf_attrs {
62 u16 pf; /* Associated PCI PF for this port. */
63 u16 vf; /* Associated PCI VF for of the PCI PF for this port. */
66 struct devlink_port_attrs {
70 enum devlink_port_flavour flavour;
71 struct netdev_phys_item_id switch_id;
73 struct devlink_port_phys_attrs phys;
74 struct devlink_port_pci_pf_attrs pci_pf;
75 struct devlink_port_pci_vf_attrs pci_vf;
80 struct list_head list;
81 struct list_head param_list;
82 struct devlink *devlink;
85 spinlock_t type_lock; /* Protects type and type_dev
86 * pointer consistency.
88 enum devlink_port_type type;
89 enum devlink_port_type desired_type;
91 struct devlink_port_attrs attrs;
92 struct delayed_work type_warn_dw;
95 struct devlink_sb_pool_info {
96 enum devlink_sb_pool_type pool_type;
98 enum devlink_sb_threshold_type threshold_type;
103 * struct devlink_dpipe_field - dpipe field object
105 * @id: index inside the headers field array
106 * @bitwidth: bitwidth
107 * @mapping_type: mapping type
109 struct devlink_dpipe_field {
112 unsigned int bitwidth;
113 enum devlink_dpipe_field_mapping_type mapping_type;
117 * struct devlink_dpipe_header - dpipe header object
119 * @id: index, global/local detrmined by global bit
121 * @fields_count: number of fields
122 * @global: indicates if header is shared like most protocol header
125 struct devlink_dpipe_header {
128 struct devlink_dpipe_field *fields;
129 unsigned int fields_count;
134 * struct devlink_dpipe_match - represents match operation
135 * @type: type of match
136 * @header_index: header index (packets can have several headers of same
137 * type like in case of tunnels)
139 * @fieled_id: field index
141 struct devlink_dpipe_match {
142 enum devlink_dpipe_match_type type;
143 unsigned int header_index;
144 struct devlink_dpipe_header *header;
145 unsigned int field_id;
149 * struct devlink_dpipe_action - represents action operation
150 * @type: type of action
151 * @header_index: header index (packets can have several headers of same
152 * type like in case of tunnels)
154 * @fieled_id: field index
156 struct devlink_dpipe_action {
157 enum devlink_dpipe_action_type type;
158 unsigned int header_index;
159 struct devlink_dpipe_header *header;
160 unsigned int field_id;
164 * struct devlink_dpipe_value - represents value of match/action
167 * @mapping_value: in case the field has some mapping this value
168 * specified the mapping value
169 * @mapping_valid: specify if mapping value is valid
170 * @value_size: value size
174 struct devlink_dpipe_value {
176 struct devlink_dpipe_action *action;
177 struct devlink_dpipe_match *match;
179 unsigned int mapping_value;
181 unsigned int value_size;
187 * struct devlink_dpipe_entry - table entry object
188 * @index: index of the entry in the table
189 * @match_values: match values
190 * @matche_values_count: count of matches tuples
191 * @action_values: actions values
192 * @action_values_count: count of actions values
193 * @counter: value of counter
194 * @counter_valid: Specify if value is valid from hardware
196 struct devlink_dpipe_entry {
198 struct devlink_dpipe_value *match_values;
199 unsigned int match_values_count;
200 struct devlink_dpipe_value *action_values;
201 unsigned int action_values_count;
207 * struct devlink_dpipe_dump_ctx - context provided to driver in order
210 * @cmd: devlink command
212 * @nest: top attribute
215 struct devlink_dpipe_dump_ctx {
216 struct genl_info *info;
217 enum devlink_command cmd;
223 struct devlink_dpipe_table_ops;
226 * struct devlink_dpipe_table - table object
229 * @counters_enabled: indicates if counters are active
230 * @counter_control_extern: indicates if counter control is in dpipe or
232 * @resource_valid: Indicate that the resource id is valid
233 * @resource_id: relative resource this table is related to
234 * @resource_units: number of resource's unit consumed per table's entry
235 * @table_ops: table operations
238 struct devlink_dpipe_table {
240 struct list_head list;
242 bool counters_enabled;
243 bool counter_control_extern;
247 struct devlink_dpipe_table_ops *table_ops;
252 * struct devlink_dpipe_table_ops - dpipe_table ops
253 * @actions_dump - dumps all tables actions
254 * @matches_dump - dumps all tables matches
255 * @entries_dump - dumps all active entries in the table
256 * @counters_set_update - when changing the counter status hardware sync
257 * maybe needed to allocate/free counter related
259 * @size_get - get size
261 struct devlink_dpipe_table_ops {
262 int (*actions_dump)(void *priv, struct sk_buff *skb);
263 int (*matches_dump)(void *priv, struct sk_buff *skb);
264 int (*entries_dump)(void *priv, bool counters_enabled,
265 struct devlink_dpipe_dump_ctx *dump_ctx);
266 int (*counters_set_update)(void *priv, bool enable);
267 u64 (*size_get)(void *priv);
271 * struct devlink_dpipe_headers - dpipe headers
272 * @headers - header array can be shared (global bit) or driver specific
273 * @headers_count - count of headers
275 struct devlink_dpipe_headers {
276 struct devlink_dpipe_header **headers;
277 unsigned int headers_count;
281 * struct devlink_resource_size_params - resource's size parameters
282 * @size_min: minimum size which can be set
283 * @size_max: maximum size which can be set
284 * @size_granularity: size granularity
285 * @size_unit: resource's basic unit
287 struct devlink_resource_size_params {
290 u64 size_granularity;
291 enum devlink_resource_unit unit;
295 devlink_resource_size_params_init(struct devlink_resource_size_params *size_params,
296 u64 size_min, u64 size_max,
297 u64 size_granularity,
298 enum devlink_resource_unit unit)
300 size_params->size_min = size_min;
301 size_params->size_max = size_max;
302 size_params->size_granularity = size_granularity;
303 size_params->unit = unit;
306 typedef u64 devlink_resource_occ_get_t(void *priv);
309 * struct devlink_resource - devlink resource
310 * @name: name of the resource
311 * @id: id, per devlink instance
312 * @size: size of the resource
313 * @size_new: updated size of the resource, reload is needed
314 * @size_valid: valid in case the total size of the resource is valid
315 * including its children
316 * @parent: parent resource
317 * @size_params: size parameters
319 * @resource_list: list of child resources
321 struct devlink_resource {
327 struct devlink_resource *parent;
328 struct devlink_resource_size_params size_params;
329 struct list_head list;
330 struct list_head resource_list;
331 devlink_resource_occ_get_t *occ_get;
335 #define DEVLINK_RESOURCE_ID_PARENT_TOP 0
337 #define __DEVLINK_PARAM_MAX_STRING_VALUE 32
338 enum devlink_param_type {
339 DEVLINK_PARAM_TYPE_U8,
340 DEVLINK_PARAM_TYPE_U16,
341 DEVLINK_PARAM_TYPE_U32,
342 DEVLINK_PARAM_TYPE_STRING,
343 DEVLINK_PARAM_TYPE_BOOL,
346 union devlink_param_value {
350 char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];
354 struct devlink_param_gset_ctx {
355 union devlink_param_value val;
356 enum devlink_param_cmode cmode;
360 * struct devlink_param - devlink configuration parameter data
361 * @name: name of the parameter
362 * @generic: indicates if the parameter is generic or driver specific
363 * @type: parameter type
364 * @supported_cmodes: bitmap of supported configuration modes
365 * @get: get parameter value, used for runtime and permanent
366 * configuration modes
367 * @set: set parameter value, used for runtime and permanent
368 * configuration modes
369 * @validate: validate input value is applicable (within value range, etc.)
371 * This struct should be used by the driver to fill the data for
372 * a parameter it registers.
374 struct devlink_param {
378 enum devlink_param_type type;
379 unsigned long supported_cmodes;
380 int (*get)(struct devlink *devlink, u32 id,
381 struct devlink_param_gset_ctx *ctx);
382 int (*set)(struct devlink *devlink, u32 id,
383 struct devlink_param_gset_ctx *ctx);
384 int (*validate)(struct devlink *devlink, u32 id,
385 union devlink_param_value val,
386 struct netlink_ext_ack *extack);
389 struct devlink_param_item {
390 struct list_head list;
391 const struct devlink_param *param;
392 union devlink_param_value driverinit_value;
393 bool driverinit_value_valid;
397 enum devlink_param_generic_id {
398 DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
399 DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
400 DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
401 DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT,
402 DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI,
403 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
404 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
405 DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY,
406 DEVLINK_PARAM_GENERIC_ID_RESET_DEV_ON_DRV_PROBE,
407 DEVLINK_PARAM_GENERIC_ID_ENABLE_ROCE,
409 /* add new param generic ids above here*/
410 __DEVLINK_PARAM_GENERIC_ID_MAX,
411 DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
414 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
415 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
417 #define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
418 #define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
420 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
421 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
423 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable"
424 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL
426 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari"
427 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL
429 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max"
430 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32
432 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min"
433 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32
435 #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy"
436 #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8
438 #define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_NAME \
439 "reset_dev_on_drv_probe"
440 #define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_TYPE DEVLINK_PARAM_TYPE_U8
442 #define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_NAME "enable_roce"
443 #define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_TYPE DEVLINK_PARAM_TYPE_BOOL
445 #define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \
447 .id = DEVLINK_PARAM_GENERIC_ID_##_id, \
448 .name = DEVLINK_PARAM_GENERIC_##_id##_NAME, \
449 .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE, \
451 .supported_cmodes = _cmodes, \
454 .validate = _validate, \
457 #define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate) \
462 .supported_cmodes = _cmodes, \
465 .validate = _validate, \
468 /* Part number, identifier of board design */
469 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID "board.id"
470 /* Revision of board design */
471 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV "board.rev"
472 /* Maker of the board */
473 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_MANUFACTURE "board.manufacture"
475 /* Part number, identifier of asic design */
476 #define DEVLINK_INFO_VERSION_GENERIC_ASIC_ID "asic.id"
477 /* Revision of asic design */
478 #define DEVLINK_INFO_VERSION_GENERIC_ASIC_REV "asic.rev"
480 /* Overall FW version */
481 #define DEVLINK_INFO_VERSION_GENERIC_FW "fw"
482 /* Control processor FW version */
483 #define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT "fw.mgmt"
484 /* FW interface specification version */
485 #define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT_API "fw.mgmt.api"
486 /* Data path microcode controlling high-speed packet processing */
487 #define DEVLINK_INFO_VERSION_GENERIC_FW_APP "fw.app"
488 /* UNDI software version */
489 #define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI "fw.undi"
490 /* NCSI support/handler version */
491 #define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI "fw.ncsi"
492 /* FW parameter set id */
493 #define DEVLINK_INFO_VERSION_GENERIC_FW_PSID "fw.psid"
494 /* RoCE FW version */
495 #define DEVLINK_INFO_VERSION_GENERIC_FW_ROCE "fw.roce"
496 /* Firmware bundle identifier */
497 #define DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID "fw.bundle_id"
499 struct devlink_region;
500 struct devlink_info_req;
503 * struct devlink_region_ops - Region operations
505 * @destructor: callback used to free snapshot memory when deleting
506 * @snapshot: callback to request an immediate snapshot. On success,
507 * the data variable must be updated to point to the snapshot data.
508 * The function will be called while the devlink instance lock is
511 struct devlink_region_ops {
513 void (*destructor)(const void *data);
514 int (*snapshot)(struct devlink *devlink, struct netlink_ext_ack *extack,
519 struct devlink_health_reporter;
521 enum devlink_health_reporter_state {
522 DEVLINK_HEALTH_REPORTER_STATE_HEALTHY,
523 DEVLINK_HEALTH_REPORTER_STATE_ERROR,
527 * struct devlink_health_reporter_ops - Reporter operations
528 * @name: reporter name
529 * @recover: callback to recover from reported error
530 * if priv_ctx is NULL, run a full recover
531 * @dump: callback to dump an object
532 * if priv_ctx is NULL, run a full dump
533 * @diagnose: callback to diagnose the current status
536 struct devlink_health_reporter_ops {
538 int (*recover)(struct devlink_health_reporter *reporter,
539 void *priv_ctx, struct netlink_ext_ack *extack);
540 int (*dump)(struct devlink_health_reporter *reporter,
541 struct devlink_fmsg *fmsg, void *priv_ctx,
542 struct netlink_ext_ack *extack);
543 int (*diagnose)(struct devlink_health_reporter *reporter,
544 struct devlink_fmsg *fmsg,
545 struct netlink_ext_ack *extack);
549 * struct devlink_trap_group - Immutable packet trap group attributes.
550 * @name: Trap group name.
551 * @id: Trap group identifier.
552 * @generic: Whether the trap group is generic or not.
554 * Describes immutable attributes of packet trap groups that drivers register
557 struct devlink_trap_group {
563 #define DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT BIT(0)
564 #define DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE BIT(1)
567 * struct devlink_trap - Immutable packet trap attributes.
569 * @init_action: Initial trap action.
570 * @generic: Whether the trap is generic or not.
571 * @id: Trap identifier.
573 * @init_group_id: Initial group identifier.
574 * @metadata_cap: Metadata types that can be provided by the trap.
576 * Describes immutable attributes of packet traps that drivers register with
579 struct devlink_trap {
580 enum devlink_trap_type type;
581 enum devlink_trap_action init_action;
589 /* All traps must be documented in
590 * Documentation/networking/devlink/devlink-trap.rst
592 enum devlink_trap_generic_id {
593 DEVLINK_TRAP_GENERIC_ID_SMAC_MC,
594 DEVLINK_TRAP_GENERIC_ID_VLAN_TAG_MISMATCH,
595 DEVLINK_TRAP_GENERIC_ID_INGRESS_VLAN_FILTER,
596 DEVLINK_TRAP_GENERIC_ID_INGRESS_STP_FILTER,
597 DEVLINK_TRAP_GENERIC_ID_EMPTY_TX_LIST,
598 DEVLINK_TRAP_GENERIC_ID_PORT_LOOPBACK_FILTER,
599 DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_ROUTE,
600 DEVLINK_TRAP_GENERIC_ID_TTL_ERROR,
601 DEVLINK_TRAP_GENERIC_ID_TAIL_DROP,
602 DEVLINK_TRAP_GENERIC_ID_NON_IP_PACKET,
603 DEVLINK_TRAP_GENERIC_ID_UC_DIP_MC_DMAC,
604 DEVLINK_TRAP_GENERIC_ID_DIP_LB,
605 DEVLINK_TRAP_GENERIC_ID_SIP_MC,
606 DEVLINK_TRAP_GENERIC_ID_SIP_LB,
607 DEVLINK_TRAP_GENERIC_ID_CORRUPTED_IP_HDR,
608 DEVLINK_TRAP_GENERIC_ID_IPV4_SIP_BC,
609 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_RESERVED_SCOPE,
610 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE,
611 DEVLINK_TRAP_GENERIC_ID_MTU_ERROR,
612 DEVLINK_TRAP_GENERIC_ID_UNRESOLVED_NEIGH,
613 DEVLINK_TRAP_GENERIC_ID_RPF,
614 DEVLINK_TRAP_GENERIC_ID_REJECT_ROUTE,
615 DEVLINK_TRAP_GENERIC_ID_IPV4_LPM_UNICAST_MISS,
616 DEVLINK_TRAP_GENERIC_ID_IPV6_LPM_UNICAST_MISS,
617 DEVLINK_TRAP_GENERIC_ID_NON_ROUTABLE,
618 DEVLINK_TRAP_GENERIC_ID_DECAP_ERROR,
619 DEVLINK_TRAP_GENERIC_ID_OVERLAY_SMAC_MC,
620 DEVLINK_TRAP_GENERIC_ID_INGRESS_FLOW_ACTION_DROP,
621 DEVLINK_TRAP_GENERIC_ID_EGRESS_FLOW_ACTION_DROP,
623 /* Add new generic trap IDs above */
624 __DEVLINK_TRAP_GENERIC_ID_MAX,
625 DEVLINK_TRAP_GENERIC_ID_MAX = __DEVLINK_TRAP_GENERIC_ID_MAX - 1,
628 /* All trap groups must be documented in
629 * Documentation/networking/devlink/devlink-trap.rst
631 enum devlink_trap_group_generic_id {
632 DEVLINK_TRAP_GROUP_GENERIC_ID_L2_DROPS,
633 DEVLINK_TRAP_GROUP_GENERIC_ID_L3_DROPS,
634 DEVLINK_TRAP_GROUP_GENERIC_ID_BUFFER_DROPS,
635 DEVLINK_TRAP_GROUP_GENERIC_ID_TUNNEL_DROPS,
636 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_DROPS,
638 /* Add new generic trap group IDs above */
639 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX,
640 DEVLINK_TRAP_GROUP_GENERIC_ID_MAX =
641 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX - 1,
644 #define DEVLINK_TRAP_GENERIC_NAME_SMAC_MC \
645 "source_mac_is_multicast"
646 #define DEVLINK_TRAP_GENERIC_NAME_VLAN_TAG_MISMATCH \
648 #define DEVLINK_TRAP_GENERIC_NAME_INGRESS_VLAN_FILTER \
649 "ingress_vlan_filter"
650 #define DEVLINK_TRAP_GENERIC_NAME_INGRESS_STP_FILTER \
651 "ingress_spanning_tree_filter"
652 #define DEVLINK_TRAP_GENERIC_NAME_EMPTY_TX_LIST \
654 #define DEVLINK_TRAP_GENERIC_NAME_PORT_LOOPBACK_FILTER \
655 "port_loopback_filter"
656 #define DEVLINK_TRAP_GENERIC_NAME_BLACKHOLE_ROUTE \
658 #define DEVLINK_TRAP_GENERIC_NAME_TTL_ERROR \
659 "ttl_value_is_too_small"
660 #define DEVLINK_TRAP_GENERIC_NAME_TAIL_DROP \
662 #define DEVLINK_TRAP_GENERIC_NAME_NON_IP_PACKET \
664 #define DEVLINK_TRAP_GENERIC_NAME_UC_DIP_MC_DMAC \
665 "uc_dip_over_mc_dmac"
666 #define DEVLINK_TRAP_GENERIC_NAME_DIP_LB \
667 "dip_is_loopback_address"
668 #define DEVLINK_TRAP_GENERIC_NAME_SIP_MC \
670 #define DEVLINK_TRAP_GENERIC_NAME_SIP_LB \
671 "sip_is_loopback_address"
672 #define DEVLINK_TRAP_GENERIC_NAME_CORRUPTED_IP_HDR \
673 "ip_header_corrupted"
674 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_SIP_BC \
675 "ipv4_sip_is_limited_bc"
676 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_RESERVED_SCOPE \
677 "ipv6_mc_dip_reserved_scope"
678 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE \
679 "ipv6_mc_dip_interface_local_scope"
680 #define DEVLINK_TRAP_GENERIC_NAME_MTU_ERROR \
681 "mtu_value_is_too_small"
682 #define DEVLINK_TRAP_GENERIC_NAME_UNRESOLVED_NEIGH \
684 #define DEVLINK_TRAP_GENERIC_NAME_RPF \
685 "mc_reverse_path_forwarding"
686 #define DEVLINK_TRAP_GENERIC_NAME_REJECT_ROUTE \
688 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_LPM_UNICAST_MISS \
690 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_LPM_UNICAST_MISS \
692 #define DEVLINK_TRAP_GENERIC_NAME_NON_ROUTABLE \
693 "non_routable_packet"
694 #define DEVLINK_TRAP_GENERIC_NAME_DECAP_ERROR \
696 #define DEVLINK_TRAP_GENERIC_NAME_OVERLAY_SMAC_MC \
698 #define DEVLINK_TRAP_GENERIC_NAME_INGRESS_FLOW_ACTION_DROP \
699 "ingress_flow_action_drop"
700 #define DEVLINK_TRAP_GENERIC_NAME_EGRESS_FLOW_ACTION_DROP \
701 "egress_flow_action_drop"
703 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_L2_DROPS \
705 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_DROPS \
707 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_BUFFER_DROPS \
709 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_TUNNEL_DROPS \
711 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_DROPS \
714 #define DEVLINK_TRAP_GENERIC(_type, _init_action, _id, _group_id, \
717 .type = DEVLINK_TRAP_TYPE_##_type, \
718 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
720 .id = DEVLINK_TRAP_GENERIC_ID_##_id, \
721 .name = DEVLINK_TRAP_GENERIC_NAME_##_id, \
722 .init_group_id = _group_id, \
723 .metadata_cap = _metadata_cap, \
726 #define DEVLINK_TRAP_DRIVER(_type, _init_action, _id, _name, _group_id, \
729 .type = DEVLINK_TRAP_TYPE_##_type, \
730 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
734 .init_group_id = _group_id, \
735 .metadata_cap = _metadata_cap, \
738 #define DEVLINK_TRAP_GROUP_GENERIC(_id) \
740 .name = DEVLINK_TRAP_GROUP_GENERIC_NAME_##_id, \
741 .id = DEVLINK_TRAP_GROUP_GENERIC_ID_##_id, \
746 int (*reload_down)(struct devlink *devlink, bool netns_change,
747 struct netlink_ext_ack *extack);
748 int (*reload_up)(struct devlink *devlink,
749 struct netlink_ext_ack *extack);
750 int (*port_type_set)(struct devlink_port *devlink_port,
751 enum devlink_port_type port_type);
752 int (*port_split)(struct devlink *devlink, unsigned int port_index,
753 unsigned int count, struct netlink_ext_ack *extack);
754 int (*port_unsplit)(struct devlink *devlink, unsigned int port_index,
755 struct netlink_ext_ack *extack);
756 int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
758 struct devlink_sb_pool_info *pool_info);
759 int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
760 u16 pool_index, u32 size,
761 enum devlink_sb_threshold_type threshold_type,
762 struct netlink_ext_ack *extack);
763 int (*sb_port_pool_get)(struct devlink_port *devlink_port,
764 unsigned int sb_index, u16 pool_index,
766 int (*sb_port_pool_set)(struct devlink_port *devlink_port,
767 unsigned int sb_index, u16 pool_index,
768 u32 threshold, struct netlink_ext_ack *extack);
769 int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
770 unsigned int sb_index,
772 enum devlink_sb_pool_type pool_type,
773 u16 *p_pool_index, u32 *p_threshold);
774 int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
775 unsigned int sb_index,
777 enum devlink_sb_pool_type pool_type,
778 u16 pool_index, u32 threshold,
779 struct netlink_ext_ack *extack);
780 int (*sb_occ_snapshot)(struct devlink *devlink,
781 unsigned int sb_index);
782 int (*sb_occ_max_clear)(struct devlink *devlink,
783 unsigned int sb_index);
784 int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
785 unsigned int sb_index, u16 pool_index,
786 u32 *p_cur, u32 *p_max);
787 int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
788 unsigned int sb_index,
790 enum devlink_sb_pool_type pool_type,
791 u32 *p_cur, u32 *p_max);
793 int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
794 int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
795 struct netlink_ext_ack *extack);
796 int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
797 int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
798 struct netlink_ext_ack *extack);
799 int (*eswitch_encap_mode_get)(struct devlink *devlink,
800 enum devlink_eswitch_encap_mode *p_encap_mode);
801 int (*eswitch_encap_mode_set)(struct devlink *devlink,
802 enum devlink_eswitch_encap_mode encap_mode,
803 struct netlink_ext_ack *extack);
804 int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
805 struct netlink_ext_ack *extack);
806 int (*flash_update)(struct devlink *devlink, const char *file_name,
807 const char *component,
808 struct netlink_ext_ack *extack);
810 * @trap_init: Trap initialization function.
812 * Should be used by device drivers to initialize the trap in the
813 * underlying device. Drivers should also store the provided trap
814 * context, so that they could efficiently pass it to
815 * devlink_trap_report() when the trap is triggered.
817 int (*trap_init)(struct devlink *devlink,
818 const struct devlink_trap *trap, void *trap_ctx);
820 * @trap_fini: Trap de-initialization function.
822 * Should be used by device drivers to de-initialize the trap in the
825 void (*trap_fini)(struct devlink *devlink,
826 const struct devlink_trap *trap, void *trap_ctx);
828 * @trap_action_set: Trap action set function.
830 int (*trap_action_set)(struct devlink *devlink,
831 const struct devlink_trap *trap,
832 enum devlink_trap_action action);
834 * @trap_group_init: Trap group initialization function.
836 * Should be used by device drivers to initialize the trap group in the
839 int (*trap_group_init)(struct devlink *devlink,
840 const struct devlink_trap_group *group);
843 static inline void *devlink_priv(struct devlink *devlink)
846 return &devlink->priv;
849 static inline struct devlink *priv_to_devlink(void *priv)
852 return container_of(priv, struct devlink, priv);
855 static inline struct devlink_port *
856 netdev_to_devlink_port(struct net_device *dev)
858 if (dev->netdev_ops->ndo_get_devlink_port)
859 return dev->netdev_ops->ndo_get_devlink_port(dev);
863 static inline struct devlink *netdev_to_devlink(struct net_device *dev)
865 struct devlink_port *devlink_port = netdev_to_devlink_port(dev);
868 return devlink_port->devlink;
874 struct net *devlink_net(const struct devlink *devlink);
875 void devlink_net_set(struct devlink *devlink, struct net *net);
876 struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
877 int devlink_register(struct devlink *devlink, struct device *dev);
878 void devlink_unregister(struct devlink *devlink);
879 void devlink_reload_enable(struct devlink *devlink);
880 void devlink_reload_disable(struct devlink *devlink);
881 void devlink_free(struct devlink *devlink);
882 int devlink_port_register(struct devlink *devlink,
883 struct devlink_port *devlink_port,
884 unsigned int port_index);
885 void devlink_port_unregister(struct devlink_port *devlink_port);
886 void devlink_port_type_eth_set(struct devlink_port *devlink_port,
887 struct net_device *netdev);
888 void devlink_port_type_ib_set(struct devlink_port *devlink_port,
889 struct ib_device *ibdev);
890 void devlink_port_type_clear(struct devlink_port *devlink_port);
891 void devlink_port_attrs_set(struct devlink_port *devlink_port,
892 enum devlink_port_flavour flavour,
893 u32 port_number, bool split,
894 u32 split_subport_number,
895 const unsigned char *switch_id,
896 unsigned char switch_id_len);
897 void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
898 const unsigned char *switch_id,
899 unsigned char switch_id_len, u16 pf);
900 void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
901 const unsigned char *switch_id,
902 unsigned char switch_id_len,
904 int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
905 u32 size, u16 ingress_pools_count,
906 u16 egress_pools_count, u16 ingress_tc_count,
907 u16 egress_tc_count);
908 void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
909 int devlink_dpipe_table_register(struct devlink *devlink,
910 const char *table_name,
911 struct devlink_dpipe_table_ops *table_ops,
912 void *priv, bool counter_control_extern);
913 void devlink_dpipe_table_unregister(struct devlink *devlink,
914 const char *table_name);
915 int devlink_dpipe_headers_register(struct devlink *devlink,
916 struct devlink_dpipe_headers *dpipe_headers);
917 void devlink_dpipe_headers_unregister(struct devlink *devlink);
918 bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
919 const char *table_name);
920 int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
921 int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
922 struct devlink_dpipe_entry *entry);
923 int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
924 void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
925 int devlink_dpipe_action_put(struct sk_buff *skb,
926 struct devlink_dpipe_action *action);
927 int devlink_dpipe_match_put(struct sk_buff *skb,
928 struct devlink_dpipe_match *match);
929 extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
930 extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
931 extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
933 int devlink_resource_register(struct devlink *devlink,
934 const char *resource_name,
937 u64 parent_resource_id,
938 const struct devlink_resource_size_params *size_params);
939 void devlink_resources_unregister(struct devlink *devlink,
940 struct devlink_resource *resource);
941 int devlink_resource_size_get(struct devlink *devlink,
943 u64 *p_resource_size);
944 int devlink_dpipe_table_resource_set(struct devlink *devlink,
945 const char *table_name, u64 resource_id,
947 void devlink_resource_occ_get_register(struct devlink *devlink,
949 devlink_resource_occ_get_t *occ_get,
951 void devlink_resource_occ_get_unregister(struct devlink *devlink,
953 int devlink_params_register(struct devlink *devlink,
954 const struct devlink_param *params,
955 size_t params_count);
956 void devlink_params_unregister(struct devlink *devlink,
957 const struct devlink_param *params,
958 size_t params_count);
959 void devlink_params_publish(struct devlink *devlink);
960 void devlink_params_unpublish(struct devlink *devlink);
961 int devlink_port_params_register(struct devlink_port *devlink_port,
962 const struct devlink_param *params,
963 size_t params_count);
964 void devlink_port_params_unregister(struct devlink_port *devlink_port,
965 const struct devlink_param *params,
966 size_t params_count);
967 int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
968 union devlink_param_value *init_val);
969 int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
970 union devlink_param_value init_val);
972 devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
974 union devlink_param_value *init_val);
975 int devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
977 union devlink_param_value init_val);
978 void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
979 void devlink_port_param_value_changed(struct devlink_port *devlink_port,
981 void devlink_param_value_str_fill(union devlink_param_value *dst_val,
983 struct devlink_region *
984 devlink_region_create(struct devlink *devlink,
985 const struct devlink_region_ops *ops,
986 u32 region_max_snapshots, u64 region_size);
987 void devlink_region_destroy(struct devlink_region *region);
988 int devlink_region_snapshot_id_get(struct devlink *devlink, u32 *id);
989 void devlink_region_snapshot_id_put(struct devlink *devlink, u32 id);
990 int devlink_region_snapshot_create(struct devlink_region *region,
991 u8 *data, u32 snapshot_id);
992 int devlink_info_serial_number_put(struct devlink_info_req *req,
994 int devlink_info_driver_name_put(struct devlink_info_req *req,
996 int devlink_info_version_fixed_put(struct devlink_info_req *req,
997 const char *version_name,
998 const char *version_value);
999 int devlink_info_version_stored_put(struct devlink_info_req *req,
1000 const char *version_name,
1001 const char *version_value);
1002 int devlink_info_version_running_put(struct devlink_info_req *req,
1003 const char *version_name,
1004 const char *version_value);
1006 int devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg);
1007 int devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg);
1009 int devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name);
1010 int devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg);
1012 int devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg,
1014 int devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg);
1015 int devlink_fmsg_binary_pair_nest_start(struct devlink_fmsg *fmsg,
1017 int devlink_fmsg_binary_pair_nest_end(struct devlink_fmsg *fmsg);
1019 int devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value);
1020 int devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value);
1021 int devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value);
1022 int devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value);
1023 int devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value);
1024 int devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value,
1027 int devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name,
1029 int devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name,
1031 int devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name,
1033 int devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name,
1035 int devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,
1037 int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
1038 const void *value, u32 value_len);
1040 struct devlink_health_reporter *
1041 devlink_health_reporter_create(struct devlink *devlink,
1042 const struct devlink_health_reporter_ops *ops,
1043 u64 graceful_period, void *priv);
1045 devlink_health_reporter_destroy(struct devlink_health_reporter *reporter);
1048 devlink_health_reporter_priv(struct devlink_health_reporter *reporter);
1049 int devlink_health_report(struct devlink_health_reporter *reporter,
1050 const char *msg, void *priv_ctx);
1052 devlink_health_reporter_state_update(struct devlink_health_reporter *reporter,
1053 enum devlink_health_reporter_state state);
1055 devlink_health_reporter_recovery_done(struct devlink_health_reporter *reporter);
1057 bool devlink_is_reload_failed(const struct devlink *devlink);
1059 void devlink_flash_update_begin_notify(struct devlink *devlink);
1060 void devlink_flash_update_end_notify(struct devlink *devlink);
1061 void devlink_flash_update_status_notify(struct devlink *devlink,
1062 const char *status_msg,
1063 const char *component,
1065 unsigned long total);
1067 int devlink_traps_register(struct devlink *devlink,
1068 const struct devlink_trap *traps,
1069 size_t traps_count, void *priv);
1070 void devlink_traps_unregister(struct devlink *devlink,
1071 const struct devlink_trap *traps,
1072 size_t traps_count);
1073 void devlink_trap_report(struct devlink *devlink, struct sk_buff *skb,
1074 void *trap_ctx, struct devlink_port *in_devlink_port,
1075 const struct flow_action_cookie *fa_cookie);
1076 void *devlink_trap_ctx_priv(void *trap_ctx);
1077 int devlink_trap_groups_register(struct devlink *devlink,
1078 const struct devlink_trap_group *groups,
1079 size_t groups_count);
1080 void devlink_trap_groups_unregister(struct devlink *devlink,
1081 const struct devlink_trap_group *groups,
1082 size_t groups_count);
1084 #if IS_ENABLED(CONFIG_NET_DEVLINK)
1086 void devlink_compat_running_version(struct net_device *dev,
1087 char *buf, size_t len);
1088 int devlink_compat_flash_update(struct net_device *dev, const char *file_name);
1089 int devlink_compat_phys_port_name_get(struct net_device *dev,
1090 char *name, size_t len);
1091 int devlink_compat_switch_id_get(struct net_device *dev,
1092 struct netdev_phys_item_id *ppid);
1097 devlink_compat_running_version(struct net_device *dev, char *buf, size_t len)
1102 devlink_compat_flash_update(struct net_device *dev, const char *file_name)
1108 devlink_compat_phys_port_name_get(struct net_device *dev,
1109 char *name, size_t len)
1115 devlink_compat_switch_id_get(struct net_device *dev,
1116 struct netdev_phys_item_id *ppid)
1123 #endif /* _NET_DEVLINK_H_ */