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 struct list_head trap_policer_list;
39 const struct devlink_ops *ops;
40 struct xarray snapshot_ids;
43 struct mutex lock; /* Serializes access to devlink instance specific objects such as
44 * port, sb, dpipe, resource, params, region, traps and more.
49 char priv[0] __aligned(NETDEV_ALIGN);
52 struct devlink_port_phys_attrs {
53 u32 port_number; /* Same value as "split group".
54 * A physical port which is visible to the user
55 * for a given port flavour.
57 u32 split_subport_number; /* If the port is split, this is the number of subport. */
61 * struct devlink_port_pci_pf_attrs - devlink port's PCI PF attributes
62 * @controller: Associated controller number
63 * @pf: Associated PCI PF number for this port.
64 * @external: when set, indicates if a port is for an external controller
66 struct devlink_port_pci_pf_attrs {
73 * struct devlink_port_pci_vf_attrs - devlink port's PCI VF attributes
74 * @controller: Associated controller number
75 * @pf: Associated PCI PF number for this port.
76 * @vf: Associated PCI VF for of the PCI PF for this port.
77 * @external: when set, indicates if a port is for an external controller
79 struct devlink_port_pci_vf_attrs {
87 * struct devlink_port_attrs - devlink port object
88 * @flavour: flavour of the port
89 * @split: indicates if this is split port
90 * @splittable: indicates if the port can be split.
91 * @lanes: maximum number of lanes the port supports. 0 value is not passed to netlink.
92 * @switch_id: if the port is part of switch, this is buffer with ID, otherwise this is NULL
93 * @phys: physical port attributes
94 * @pci_pf: PCI PF port attributes
95 * @pci_vf: PCI VF port attributes
97 struct devlink_port_attrs {
101 enum devlink_port_flavour flavour;
102 struct netdev_phys_item_id switch_id;
104 struct devlink_port_phys_attrs phys;
105 struct devlink_port_pci_pf_attrs pci_pf;
106 struct devlink_port_pci_vf_attrs pci_vf;
110 struct devlink_port {
111 struct list_head list;
112 struct list_head param_list;
113 struct devlink *devlink;
116 spinlock_t type_lock; /* Protects type and type_dev
117 * pointer consistency.
119 enum devlink_port_type type;
120 enum devlink_port_type desired_type;
122 struct devlink_port_attrs attrs;
125 struct delayed_work type_warn_dw;
126 struct list_head reporter_list;
127 struct mutex reporters_lock; /* Protects reporter_list */
130 struct devlink_sb_pool_info {
131 enum devlink_sb_pool_type pool_type;
133 enum devlink_sb_threshold_type threshold_type;
138 * struct devlink_dpipe_field - dpipe field object
140 * @id: index inside the headers field array
141 * @bitwidth: bitwidth
142 * @mapping_type: mapping type
144 struct devlink_dpipe_field {
147 unsigned int bitwidth;
148 enum devlink_dpipe_field_mapping_type mapping_type;
152 * struct devlink_dpipe_header - dpipe header object
154 * @id: index, global/local detrmined by global bit
156 * @fields_count: number of fields
157 * @global: indicates if header is shared like most protocol header
160 struct devlink_dpipe_header {
163 struct devlink_dpipe_field *fields;
164 unsigned int fields_count;
169 * struct devlink_dpipe_match - represents match operation
170 * @type: type of match
171 * @header_index: header index (packets can have several headers of same
172 * type like in case of tunnels)
174 * @fieled_id: field index
176 struct devlink_dpipe_match {
177 enum devlink_dpipe_match_type type;
178 unsigned int header_index;
179 struct devlink_dpipe_header *header;
180 unsigned int field_id;
184 * struct devlink_dpipe_action - represents action operation
185 * @type: type of action
186 * @header_index: header index (packets can have several headers of same
187 * type like in case of tunnels)
189 * @fieled_id: field index
191 struct devlink_dpipe_action {
192 enum devlink_dpipe_action_type type;
193 unsigned int header_index;
194 struct devlink_dpipe_header *header;
195 unsigned int field_id;
199 * struct devlink_dpipe_value - represents value of match/action
202 * @mapping_value: in case the field has some mapping this value
203 * specified the mapping value
204 * @mapping_valid: specify if mapping value is valid
205 * @value_size: value size
209 struct devlink_dpipe_value {
211 struct devlink_dpipe_action *action;
212 struct devlink_dpipe_match *match;
214 unsigned int mapping_value;
216 unsigned int value_size;
222 * struct devlink_dpipe_entry - table entry object
223 * @index: index of the entry in the table
224 * @match_values: match values
225 * @matche_values_count: count of matches tuples
226 * @action_values: actions values
227 * @action_values_count: count of actions values
228 * @counter: value of counter
229 * @counter_valid: Specify if value is valid from hardware
231 struct devlink_dpipe_entry {
233 struct devlink_dpipe_value *match_values;
234 unsigned int match_values_count;
235 struct devlink_dpipe_value *action_values;
236 unsigned int action_values_count;
242 * struct devlink_dpipe_dump_ctx - context provided to driver in order
245 * @cmd: devlink command
247 * @nest: top attribute
250 struct devlink_dpipe_dump_ctx {
251 struct genl_info *info;
252 enum devlink_command cmd;
258 struct devlink_dpipe_table_ops;
261 * struct devlink_dpipe_table - table object
264 * @counters_enabled: indicates if counters are active
265 * @counter_control_extern: indicates if counter control is in dpipe or
267 * @resource_valid: Indicate that the resource id is valid
268 * @resource_id: relative resource this table is related to
269 * @resource_units: number of resource's unit consumed per table's entry
270 * @table_ops: table operations
273 struct devlink_dpipe_table {
275 struct list_head list;
277 bool counters_enabled;
278 bool counter_control_extern;
282 struct devlink_dpipe_table_ops *table_ops;
287 * struct devlink_dpipe_table_ops - dpipe_table ops
288 * @actions_dump - dumps all tables actions
289 * @matches_dump - dumps all tables matches
290 * @entries_dump - dumps all active entries in the table
291 * @counters_set_update - when changing the counter status hardware sync
292 * maybe needed to allocate/free counter related
294 * @size_get - get size
296 struct devlink_dpipe_table_ops {
297 int (*actions_dump)(void *priv, struct sk_buff *skb);
298 int (*matches_dump)(void *priv, struct sk_buff *skb);
299 int (*entries_dump)(void *priv, bool counters_enabled,
300 struct devlink_dpipe_dump_ctx *dump_ctx);
301 int (*counters_set_update)(void *priv, bool enable);
302 u64 (*size_get)(void *priv);
306 * struct devlink_dpipe_headers - dpipe headers
307 * @headers - header array can be shared (global bit) or driver specific
308 * @headers_count - count of headers
310 struct devlink_dpipe_headers {
311 struct devlink_dpipe_header **headers;
312 unsigned int headers_count;
316 * struct devlink_resource_size_params - resource's size parameters
317 * @size_min: minimum size which can be set
318 * @size_max: maximum size which can be set
319 * @size_granularity: size granularity
320 * @size_unit: resource's basic unit
322 struct devlink_resource_size_params {
325 u64 size_granularity;
326 enum devlink_resource_unit unit;
330 devlink_resource_size_params_init(struct devlink_resource_size_params *size_params,
331 u64 size_min, u64 size_max,
332 u64 size_granularity,
333 enum devlink_resource_unit unit)
335 size_params->size_min = size_min;
336 size_params->size_max = size_max;
337 size_params->size_granularity = size_granularity;
338 size_params->unit = unit;
341 typedef u64 devlink_resource_occ_get_t(void *priv);
344 * struct devlink_resource - devlink resource
345 * @name: name of the resource
346 * @id: id, per devlink instance
347 * @size: size of the resource
348 * @size_new: updated size of the resource, reload is needed
349 * @size_valid: valid in case the total size of the resource is valid
350 * including its children
351 * @parent: parent resource
352 * @size_params: size parameters
354 * @resource_list: list of child resources
356 struct devlink_resource {
362 struct devlink_resource *parent;
363 struct devlink_resource_size_params size_params;
364 struct list_head list;
365 struct list_head resource_list;
366 devlink_resource_occ_get_t *occ_get;
370 #define DEVLINK_RESOURCE_ID_PARENT_TOP 0
372 #define __DEVLINK_PARAM_MAX_STRING_VALUE 32
373 enum devlink_param_type {
374 DEVLINK_PARAM_TYPE_U8,
375 DEVLINK_PARAM_TYPE_U16,
376 DEVLINK_PARAM_TYPE_U32,
377 DEVLINK_PARAM_TYPE_STRING,
378 DEVLINK_PARAM_TYPE_BOOL,
381 union devlink_param_value {
385 char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];
389 struct devlink_param_gset_ctx {
390 union devlink_param_value val;
391 enum devlink_param_cmode cmode;
395 * struct devlink_param - devlink configuration parameter data
396 * @name: name of the parameter
397 * @generic: indicates if the parameter is generic or driver specific
398 * @type: parameter type
399 * @supported_cmodes: bitmap of supported configuration modes
400 * @get: get parameter value, used for runtime and permanent
401 * configuration modes
402 * @set: set parameter value, used for runtime and permanent
403 * configuration modes
404 * @validate: validate input value is applicable (within value range, etc.)
406 * This struct should be used by the driver to fill the data for
407 * a parameter it registers.
409 struct devlink_param {
413 enum devlink_param_type type;
414 unsigned long supported_cmodes;
415 int (*get)(struct devlink *devlink, u32 id,
416 struct devlink_param_gset_ctx *ctx);
417 int (*set)(struct devlink *devlink, u32 id,
418 struct devlink_param_gset_ctx *ctx);
419 int (*validate)(struct devlink *devlink, u32 id,
420 union devlink_param_value val,
421 struct netlink_ext_ack *extack);
424 struct devlink_param_item {
425 struct list_head list;
426 const struct devlink_param *param;
427 union devlink_param_value driverinit_value;
428 bool driverinit_value_valid;
432 enum devlink_param_generic_id {
433 DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
434 DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
435 DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
436 DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT,
437 DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI,
438 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
439 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
440 DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY,
441 DEVLINK_PARAM_GENERIC_ID_RESET_DEV_ON_DRV_PROBE,
442 DEVLINK_PARAM_GENERIC_ID_ENABLE_ROCE,
444 /* add new param generic ids above here*/
445 __DEVLINK_PARAM_GENERIC_ID_MAX,
446 DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
449 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
450 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
452 #define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
453 #define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
455 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
456 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
458 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable"
459 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL
461 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari"
462 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL
464 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max"
465 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32
467 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min"
468 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32
470 #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy"
471 #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8
473 #define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_NAME \
474 "reset_dev_on_drv_probe"
475 #define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_TYPE DEVLINK_PARAM_TYPE_U8
477 #define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_NAME "enable_roce"
478 #define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_TYPE DEVLINK_PARAM_TYPE_BOOL
480 #define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \
482 .id = DEVLINK_PARAM_GENERIC_ID_##_id, \
483 .name = DEVLINK_PARAM_GENERIC_##_id##_NAME, \
484 .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE, \
486 .supported_cmodes = _cmodes, \
489 .validate = _validate, \
492 #define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate) \
497 .supported_cmodes = _cmodes, \
500 .validate = _validate, \
503 /* Part number, identifier of board design */
504 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID "board.id"
505 /* Revision of board design */
506 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV "board.rev"
507 /* Maker of the board */
508 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_MANUFACTURE "board.manufacture"
510 /* Part number, identifier of asic design */
511 #define DEVLINK_INFO_VERSION_GENERIC_ASIC_ID "asic.id"
512 /* Revision of asic design */
513 #define DEVLINK_INFO_VERSION_GENERIC_ASIC_REV "asic.rev"
515 /* Overall FW version */
516 #define DEVLINK_INFO_VERSION_GENERIC_FW "fw"
517 /* Control processor FW version */
518 #define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT "fw.mgmt"
519 /* FW interface specification version */
520 #define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT_API "fw.mgmt.api"
521 /* Data path microcode controlling high-speed packet processing */
522 #define DEVLINK_INFO_VERSION_GENERIC_FW_APP "fw.app"
523 /* UNDI software version */
524 #define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI "fw.undi"
525 /* NCSI support/handler version */
526 #define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI "fw.ncsi"
527 /* FW parameter set id */
528 #define DEVLINK_INFO_VERSION_GENERIC_FW_PSID "fw.psid"
529 /* RoCE FW version */
530 #define DEVLINK_INFO_VERSION_GENERIC_FW_ROCE "fw.roce"
531 /* Firmware bundle identifier */
532 #define DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID "fw.bundle_id"
534 struct devlink_region;
535 struct devlink_info_req;
538 * struct devlink_region_ops - Region operations
540 * @destructor: callback used to free snapshot memory when deleting
541 * @snapshot: callback to request an immediate snapshot. On success,
542 * the data variable must be updated to point to the snapshot data.
543 * The function will be called while the devlink instance lock is
546 struct devlink_region_ops {
548 void (*destructor)(const void *data);
549 int (*snapshot)(struct devlink *devlink, struct netlink_ext_ack *extack,
554 struct devlink_health_reporter;
556 enum devlink_health_reporter_state {
557 DEVLINK_HEALTH_REPORTER_STATE_HEALTHY,
558 DEVLINK_HEALTH_REPORTER_STATE_ERROR,
562 * struct devlink_health_reporter_ops - Reporter operations
563 * @name: reporter name
564 * @recover: callback to recover from reported error
565 * if priv_ctx is NULL, run a full recover
566 * @dump: callback to dump an object
567 * if priv_ctx is NULL, run a full dump
568 * @diagnose: callback to diagnose the current status
571 struct devlink_health_reporter_ops {
573 int (*recover)(struct devlink_health_reporter *reporter,
574 void *priv_ctx, struct netlink_ext_ack *extack);
575 int (*dump)(struct devlink_health_reporter *reporter,
576 struct devlink_fmsg *fmsg, void *priv_ctx,
577 struct netlink_ext_ack *extack);
578 int (*diagnose)(struct devlink_health_reporter *reporter,
579 struct devlink_fmsg *fmsg,
580 struct netlink_ext_ack *extack);
584 * struct devlink_trap_policer - Immutable packet trap policer attributes.
585 * @id: Policer identifier.
586 * @init_rate: Initial rate in packets / sec.
587 * @init_burst: Initial burst size in packets.
588 * @max_rate: Maximum rate.
589 * @min_rate: Minimum rate.
590 * @max_burst: Maximum burst size.
591 * @min_burst: Minimum burst size.
593 * Describes immutable attributes of packet trap policers that drivers register
596 struct devlink_trap_policer {
607 * struct devlink_trap_group - Immutable packet trap group attributes.
608 * @name: Trap group name.
609 * @id: Trap group identifier.
610 * @generic: Whether the trap group is generic or not.
611 * @init_policer_id: Initial policer identifier.
613 * Describes immutable attributes of packet trap groups that drivers register
616 struct devlink_trap_group {
623 #define DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT BIT(0)
624 #define DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE BIT(1)
627 * struct devlink_trap - Immutable packet trap attributes.
629 * @init_action: Initial trap action.
630 * @generic: Whether the trap is generic or not.
631 * @id: Trap identifier.
633 * @init_group_id: Initial group identifier.
634 * @metadata_cap: Metadata types that can be provided by the trap.
636 * Describes immutable attributes of packet traps that drivers register with
639 struct devlink_trap {
640 enum devlink_trap_type type;
641 enum devlink_trap_action init_action;
649 /* All traps must be documented in
650 * Documentation/networking/devlink/devlink-trap.rst
652 enum devlink_trap_generic_id {
653 DEVLINK_TRAP_GENERIC_ID_SMAC_MC,
654 DEVLINK_TRAP_GENERIC_ID_VLAN_TAG_MISMATCH,
655 DEVLINK_TRAP_GENERIC_ID_INGRESS_VLAN_FILTER,
656 DEVLINK_TRAP_GENERIC_ID_INGRESS_STP_FILTER,
657 DEVLINK_TRAP_GENERIC_ID_EMPTY_TX_LIST,
658 DEVLINK_TRAP_GENERIC_ID_PORT_LOOPBACK_FILTER,
659 DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_ROUTE,
660 DEVLINK_TRAP_GENERIC_ID_TTL_ERROR,
661 DEVLINK_TRAP_GENERIC_ID_TAIL_DROP,
662 DEVLINK_TRAP_GENERIC_ID_NON_IP_PACKET,
663 DEVLINK_TRAP_GENERIC_ID_UC_DIP_MC_DMAC,
664 DEVLINK_TRAP_GENERIC_ID_DIP_LB,
665 DEVLINK_TRAP_GENERIC_ID_SIP_MC,
666 DEVLINK_TRAP_GENERIC_ID_SIP_LB,
667 DEVLINK_TRAP_GENERIC_ID_CORRUPTED_IP_HDR,
668 DEVLINK_TRAP_GENERIC_ID_IPV4_SIP_BC,
669 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_RESERVED_SCOPE,
670 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE,
671 DEVLINK_TRAP_GENERIC_ID_MTU_ERROR,
672 DEVLINK_TRAP_GENERIC_ID_UNRESOLVED_NEIGH,
673 DEVLINK_TRAP_GENERIC_ID_RPF,
674 DEVLINK_TRAP_GENERIC_ID_REJECT_ROUTE,
675 DEVLINK_TRAP_GENERIC_ID_IPV4_LPM_UNICAST_MISS,
676 DEVLINK_TRAP_GENERIC_ID_IPV6_LPM_UNICAST_MISS,
677 DEVLINK_TRAP_GENERIC_ID_NON_ROUTABLE,
678 DEVLINK_TRAP_GENERIC_ID_DECAP_ERROR,
679 DEVLINK_TRAP_GENERIC_ID_OVERLAY_SMAC_MC,
680 DEVLINK_TRAP_GENERIC_ID_INGRESS_FLOW_ACTION_DROP,
681 DEVLINK_TRAP_GENERIC_ID_EGRESS_FLOW_ACTION_DROP,
682 DEVLINK_TRAP_GENERIC_ID_STP,
683 DEVLINK_TRAP_GENERIC_ID_LACP,
684 DEVLINK_TRAP_GENERIC_ID_LLDP,
685 DEVLINK_TRAP_GENERIC_ID_IGMP_QUERY,
686 DEVLINK_TRAP_GENERIC_ID_IGMP_V1_REPORT,
687 DEVLINK_TRAP_GENERIC_ID_IGMP_V2_REPORT,
688 DEVLINK_TRAP_GENERIC_ID_IGMP_V3_REPORT,
689 DEVLINK_TRAP_GENERIC_ID_IGMP_V2_LEAVE,
690 DEVLINK_TRAP_GENERIC_ID_MLD_QUERY,
691 DEVLINK_TRAP_GENERIC_ID_MLD_V1_REPORT,
692 DEVLINK_TRAP_GENERIC_ID_MLD_V2_REPORT,
693 DEVLINK_TRAP_GENERIC_ID_MLD_V1_DONE,
694 DEVLINK_TRAP_GENERIC_ID_IPV4_DHCP,
695 DEVLINK_TRAP_GENERIC_ID_IPV6_DHCP,
696 DEVLINK_TRAP_GENERIC_ID_ARP_REQUEST,
697 DEVLINK_TRAP_GENERIC_ID_ARP_RESPONSE,
698 DEVLINK_TRAP_GENERIC_ID_ARP_OVERLAY,
699 DEVLINK_TRAP_GENERIC_ID_IPV6_NEIGH_SOLICIT,
700 DEVLINK_TRAP_GENERIC_ID_IPV6_NEIGH_ADVERT,
701 DEVLINK_TRAP_GENERIC_ID_IPV4_BFD,
702 DEVLINK_TRAP_GENERIC_ID_IPV6_BFD,
703 DEVLINK_TRAP_GENERIC_ID_IPV4_OSPF,
704 DEVLINK_TRAP_GENERIC_ID_IPV6_OSPF,
705 DEVLINK_TRAP_GENERIC_ID_IPV4_BGP,
706 DEVLINK_TRAP_GENERIC_ID_IPV6_BGP,
707 DEVLINK_TRAP_GENERIC_ID_IPV4_VRRP,
708 DEVLINK_TRAP_GENERIC_ID_IPV6_VRRP,
709 DEVLINK_TRAP_GENERIC_ID_IPV4_PIM,
710 DEVLINK_TRAP_GENERIC_ID_IPV6_PIM,
711 DEVLINK_TRAP_GENERIC_ID_UC_LB,
712 DEVLINK_TRAP_GENERIC_ID_LOCAL_ROUTE,
713 DEVLINK_TRAP_GENERIC_ID_EXTERNAL_ROUTE,
714 DEVLINK_TRAP_GENERIC_ID_IPV6_UC_DIP_LINK_LOCAL_SCOPE,
715 DEVLINK_TRAP_GENERIC_ID_IPV6_DIP_ALL_NODES,
716 DEVLINK_TRAP_GENERIC_ID_IPV6_DIP_ALL_ROUTERS,
717 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_SOLICIT,
718 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_ADVERT,
719 DEVLINK_TRAP_GENERIC_ID_IPV6_REDIRECT,
720 DEVLINK_TRAP_GENERIC_ID_IPV4_ROUTER_ALERT,
721 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_ALERT,
722 DEVLINK_TRAP_GENERIC_ID_PTP_EVENT,
723 DEVLINK_TRAP_GENERIC_ID_PTP_GENERAL,
724 DEVLINK_TRAP_GENERIC_ID_FLOW_ACTION_SAMPLE,
725 DEVLINK_TRAP_GENERIC_ID_FLOW_ACTION_TRAP,
726 DEVLINK_TRAP_GENERIC_ID_EARLY_DROP,
728 /* Add new generic trap IDs above */
729 __DEVLINK_TRAP_GENERIC_ID_MAX,
730 DEVLINK_TRAP_GENERIC_ID_MAX = __DEVLINK_TRAP_GENERIC_ID_MAX - 1,
733 /* All trap groups must be documented in
734 * Documentation/networking/devlink/devlink-trap.rst
736 enum devlink_trap_group_generic_id {
737 DEVLINK_TRAP_GROUP_GENERIC_ID_L2_DROPS,
738 DEVLINK_TRAP_GROUP_GENERIC_ID_L3_DROPS,
739 DEVLINK_TRAP_GROUP_GENERIC_ID_L3_EXCEPTIONS,
740 DEVLINK_TRAP_GROUP_GENERIC_ID_BUFFER_DROPS,
741 DEVLINK_TRAP_GROUP_GENERIC_ID_TUNNEL_DROPS,
742 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_DROPS,
743 DEVLINK_TRAP_GROUP_GENERIC_ID_STP,
744 DEVLINK_TRAP_GROUP_GENERIC_ID_LACP,
745 DEVLINK_TRAP_GROUP_GENERIC_ID_LLDP,
746 DEVLINK_TRAP_GROUP_GENERIC_ID_MC_SNOOPING,
747 DEVLINK_TRAP_GROUP_GENERIC_ID_DHCP,
748 DEVLINK_TRAP_GROUP_GENERIC_ID_NEIGH_DISCOVERY,
749 DEVLINK_TRAP_GROUP_GENERIC_ID_BFD,
750 DEVLINK_TRAP_GROUP_GENERIC_ID_OSPF,
751 DEVLINK_TRAP_GROUP_GENERIC_ID_BGP,
752 DEVLINK_TRAP_GROUP_GENERIC_ID_VRRP,
753 DEVLINK_TRAP_GROUP_GENERIC_ID_PIM,
754 DEVLINK_TRAP_GROUP_GENERIC_ID_UC_LB,
755 DEVLINK_TRAP_GROUP_GENERIC_ID_LOCAL_DELIVERY,
756 DEVLINK_TRAP_GROUP_GENERIC_ID_EXTERNAL_DELIVERY,
757 DEVLINK_TRAP_GROUP_GENERIC_ID_IPV6,
758 DEVLINK_TRAP_GROUP_GENERIC_ID_PTP_EVENT,
759 DEVLINK_TRAP_GROUP_GENERIC_ID_PTP_GENERAL,
760 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_SAMPLE,
761 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_TRAP,
763 /* Add new generic trap group IDs above */
764 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX,
765 DEVLINK_TRAP_GROUP_GENERIC_ID_MAX =
766 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX - 1,
769 #define DEVLINK_TRAP_GENERIC_NAME_SMAC_MC \
770 "source_mac_is_multicast"
771 #define DEVLINK_TRAP_GENERIC_NAME_VLAN_TAG_MISMATCH \
773 #define DEVLINK_TRAP_GENERIC_NAME_INGRESS_VLAN_FILTER \
774 "ingress_vlan_filter"
775 #define DEVLINK_TRAP_GENERIC_NAME_INGRESS_STP_FILTER \
776 "ingress_spanning_tree_filter"
777 #define DEVLINK_TRAP_GENERIC_NAME_EMPTY_TX_LIST \
779 #define DEVLINK_TRAP_GENERIC_NAME_PORT_LOOPBACK_FILTER \
780 "port_loopback_filter"
781 #define DEVLINK_TRAP_GENERIC_NAME_BLACKHOLE_ROUTE \
783 #define DEVLINK_TRAP_GENERIC_NAME_TTL_ERROR \
784 "ttl_value_is_too_small"
785 #define DEVLINK_TRAP_GENERIC_NAME_TAIL_DROP \
787 #define DEVLINK_TRAP_GENERIC_NAME_NON_IP_PACKET \
789 #define DEVLINK_TRAP_GENERIC_NAME_UC_DIP_MC_DMAC \
790 "uc_dip_over_mc_dmac"
791 #define DEVLINK_TRAP_GENERIC_NAME_DIP_LB \
792 "dip_is_loopback_address"
793 #define DEVLINK_TRAP_GENERIC_NAME_SIP_MC \
795 #define DEVLINK_TRAP_GENERIC_NAME_SIP_LB \
796 "sip_is_loopback_address"
797 #define DEVLINK_TRAP_GENERIC_NAME_CORRUPTED_IP_HDR \
798 "ip_header_corrupted"
799 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_SIP_BC \
800 "ipv4_sip_is_limited_bc"
801 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_RESERVED_SCOPE \
802 "ipv6_mc_dip_reserved_scope"
803 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE \
804 "ipv6_mc_dip_interface_local_scope"
805 #define DEVLINK_TRAP_GENERIC_NAME_MTU_ERROR \
806 "mtu_value_is_too_small"
807 #define DEVLINK_TRAP_GENERIC_NAME_UNRESOLVED_NEIGH \
809 #define DEVLINK_TRAP_GENERIC_NAME_RPF \
810 "mc_reverse_path_forwarding"
811 #define DEVLINK_TRAP_GENERIC_NAME_REJECT_ROUTE \
813 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_LPM_UNICAST_MISS \
815 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_LPM_UNICAST_MISS \
817 #define DEVLINK_TRAP_GENERIC_NAME_NON_ROUTABLE \
818 "non_routable_packet"
819 #define DEVLINK_TRAP_GENERIC_NAME_DECAP_ERROR \
821 #define DEVLINK_TRAP_GENERIC_NAME_OVERLAY_SMAC_MC \
823 #define DEVLINK_TRAP_GENERIC_NAME_INGRESS_FLOW_ACTION_DROP \
824 "ingress_flow_action_drop"
825 #define DEVLINK_TRAP_GENERIC_NAME_EGRESS_FLOW_ACTION_DROP \
826 "egress_flow_action_drop"
827 #define DEVLINK_TRAP_GENERIC_NAME_STP \
829 #define DEVLINK_TRAP_GENERIC_NAME_LACP \
831 #define DEVLINK_TRAP_GENERIC_NAME_LLDP \
833 #define DEVLINK_TRAP_GENERIC_NAME_IGMP_QUERY \
835 #define DEVLINK_TRAP_GENERIC_NAME_IGMP_V1_REPORT \
837 #define DEVLINK_TRAP_GENERIC_NAME_IGMP_V2_REPORT \
839 #define DEVLINK_TRAP_GENERIC_NAME_IGMP_V3_REPORT \
841 #define DEVLINK_TRAP_GENERIC_NAME_IGMP_V2_LEAVE \
843 #define DEVLINK_TRAP_GENERIC_NAME_MLD_QUERY \
845 #define DEVLINK_TRAP_GENERIC_NAME_MLD_V1_REPORT \
847 #define DEVLINK_TRAP_GENERIC_NAME_MLD_V2_REPORT \
849 #define DEVLINK_TRAP_GENERIC_NAME_MLD_V1_DONE \
851 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_DHCP \
853 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_DHCP \
855 #define DEVLINK_TRAP_GENERIC_NAME_ARP_REQUEST \
857 #define DEVLINK_TRAP_GENERIC_NAME_ARP_RESPONSE \
859 #define DEVLINK_TRAP_GENERIC_NAME_ARP_OVERLAY \
861 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_NEIGH_SOLICIT \
863 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_NEIGH_ADVERT \
865 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_BFD \
867 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_BFD \
869 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_OSPF \
871 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_OSPF \
873 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_BGP \
875 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_BGP \
877 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_VRRP \
879 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_VRRP \
881 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_PIM \
883 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_PIM \
885 #define DEVLINK_TRAP_GENERIC_NAME_UC_LB \
887 #define DEVLINK_TRAP_GENERIC_NAME_LOCAL_ROUTE \
889 #define DEVLINK_TRAP_GENERIC_NAME_EXTERNAL_ROUTE \
891 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_UC_DIP_LINK_LOCAL_SCOPE \
892 "ipv6_uc_dip_link_local_scope"
893 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_DIP_ALL_NODES \
895 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_DIP_ALL_ROUTERS \
896 "ipv6_dip_all_routers"
897 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_SOLICIT \
898 "ipv6_router_solicit"
899 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_ADVERT \
901 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_REDIRECT \
903 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_ROUTER_ALERT \
905 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_ALERT \
907 #define DEVLINK_TRAP_GENERIC_NAME_PTP_EVENT \
909 #define DEVLINK_TRAP_GENERIC_NAME_PTP_GENERAL \
911 #define DEVLINK_TRAP_GENERIC_NAME_FLOW_ACTION_SAMPLE \
913 #define DEVLINK_TRAP_GENERIC_NAME_FLOW_ACTION_TRAP \
915 #define DEVLINK_TRAP_GENERIC_NAME_EARLY_DROP \
918 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_L2_DROPS \
920 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_DROPS \
922 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_EXCEPTIONS \
924 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_BUFFER_DROPS \
926 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_TUNNEL_DROPS \
928 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_DROPS \
930 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_STP \
932 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_LACP \
934 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_LLDP \
936 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_MC_SNOOPING \
938 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_DHCP \
940 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_NEIGH_DISCOVERY \
942 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_BFD \
944 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_OSPF \
946 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_BGP \
948 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_VRRP \
950 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_PIM \
952 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_UC_LB \
954 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_LOCAL_DELIVERY \
956 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_EXTERNAL_DELIVERY \
958 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_IPV6 \
960 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_PTP_EVENT \
962 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_PTP_GENERAL \
964 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_SAMPLE \
966 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_TRAP \
969 #define DEVLINK_TRAP_GENERIC(_type, _init_action, _id, _group_id, \
972 .type = DEVLINK_TRAP_TYPE_##_type, \
973 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
975 .id = DEVLINK_TRAP_GENERIC_ID_##_id, \
976 .name = DEVLINK_TRAP_GENERIC_NAME_##_id, \
977 .init_group_id = _group_id, \
978 .metadata_cap = _metadata_cap, \
981 #define DEVLINK_TRAP_DRIVER(_type, _init_action, _id, _name, _group_id, \
984 .type = DEVLINK_TRAP_TYPE_##_type, \
985 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
989 .init_group_id = _group_id, \
990 .metadata_cap = _metadata_cap, \
993 #define DEVLINK_TRAP_GROUP_GENERIC(_id, _policer_id) \
995 .name = DEVLINK_TRAP_GROUP_GENERIC_NAME_##_id, \
996 .id = DEVLINK_TRAP_GROUP_GENERIC_ID_##_id, \
998 .init_policer_id = _policer_id, \
1001 #define DEVLINK_TRAP_POLICER(_id, _rate, _burst, _max_rate, _min_rate, \
1002 _max_burst, _min_burst) \
1005 .init_rate = _rate, \
1006 .init_burst = _burst, \
1007 .max_rate = _max_rate, \
1008 .min_rate = _min_rate, \
1009 .max_burst = _max_burst, \
1010 .min_burst = _min_burst, \
1013 struct devlink_ops {
1014 int (*reload_down)(struct devlink *devlink, bool netns_change,
1015 struct netlink_ext_ack *extack);
1016 int (*reload_up)(struct devlink *devlink,
1017 struct netlink_ext_ack *extack);
1018 int (*port_type_set)(struct devlink_port *devlink_port,
1019 enum devlink_port_type port_type);
1020 int (*port_split)(struct devlink *devlink, unsigned int port_index,
1021 unsigned int count, struct netlink_ext_ack *extack);
1022 int (*port_unsplit)(struct devlink *devlink, unsigned int port_index,
1023 struct netlink_ext_ack *extack);
1024 int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
1026 struct devlink_sb_pool_info *pool_info);
1027 int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
1028 u16 pool_index, u32 size,
1029 enum devlink_sb_threshold_type threshold_type,
1030 struct netlink_ext_ack *extack);
1031 int (*sb_port_pool_get)(struct devlink_port *devlink_port,
1032 unsigned int sb_index, u16 pool_index,
1034 int (*sb_port_pool_set)(struct devlink_port *devlink_port,
1035 unsigned int sb_index, u16 pool_index,
1036 u32 threshold, struct netlink_ext_ack *extack);
1037 int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
1038 unsigned int sb_index,
1040 enum devlink_sb_pool_type pool_type,
1041 u16 *p_pool_index, u32 *p_threshold);
1042 int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
1043 unsigned int sb_index,
1045 enum devlink_sb_pool_type pool_type,
1046 u16 pool_index, u32 threshold,
1047 struct netlink_ext_ack *extack);
1048 int (*sb_occ_snapshot)(struct devlink *devlink,
1049 unsigned int sb_index);
1050 int (*sb_occ_max_clear)(struct devlink *devlink,
1051 unsigned int sb_index);
1052 int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
1053 unsigned int sb_index, u16 pool_index,
1054 u32 *p_cur, u32 *p_max);
1055 int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
1056 unsigned int sb_index,
1058 enum devlink_sb_pool_type pool_type,
1059 u32 *p_cur, u32 *p_max);
1061 int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
1062 int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
1063 struct netlink_ext_ack *extack);
1064 int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
1065 int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
1066 struct netlink_ext_ack *extack);
1067 int (*eswitch_encap_mode_get)(struct devlink *devlink,
1068 enum devlink_eswitch_encap_mode *p_encap_mode);
1069 int (*eswitch_encap_mode_set)(struct devlink *devlink,
1070 enum devlink_eswitch_encap_mode encap_mode,
1071 struct netlink_ext_ack *extack);
1072 int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
1073 struct netlink_ext_ack *extack);
1074 int (*flash_update)(struct devlink *devlink, const char *file_name,
1075 const char *component,
1076 struct netlink_ext_ack *extack);
1078 * @trap_init: Trap initialization function.
1080 * Should be used by device drivers to initialize the trap in the
1081 * underlying device. Drivers should also store the provided trap
1082 * context, so that they could efficiently pass it to
1083 * devlink_trap_report() when the trap is triggered.
1085 int (*trap_init)(struct devlink *devlink,
1086 const struct devlink_trap *trap, void *trap_ctx);
1088 * @trap_fini: Trap de-initialization function.
1090 * Should be used by device drivers to de-initialize the trap in the
1091 * underlying device.
1093 void (*trap_fini)(struct devlink *devlink,
1094 const struct devlink_trap *trap, void *trap_ctx);
1096 * @trap_action_set: Trap action set function.
1098 int (*trap_action_set)(struct devlink *devlink,
1099 const struct devlink_trap *trap,
1100 enum devlink_trap_action action,
1101 struct netlink_ext_ack *extack);
1103 * @trap_group_init: Trap group initialization function.
1105 * Should be used by device drivers to initialize the trap group in the
1106 * underlying device.
1108 int (*trap_group_init)(struct devlink *devlink,
1109 const struct devlink_trap_group *group);
1111 * @trap_group_set: Trap group parameters set function.
1113 * Note: @policer can be NULL when a policer is being unbound from
1116 int (*trap_group_set)(struct devlink *devlink,
1117 const struct devlink_trap_group *group,
1118 const struct devlink_trap_policer *policer,
1119 struct netlink_ext_ack *extack);
1121 * @trap_policer_init: Trap policer initialization function.
1123 * Should be used by device drivers to initialize the trap policer in
1124 * the underlying device.
1126 int (*trap_policer_init)(struct devlink *devlink,
1127 const struct devlink_trap_policer *policer);
1129 * @trap_policer_fini: Trap policer de-initialization function.
1131 * Should be used by device drivers to de-initialize the trap policer
1132 * in the underlying device.
1134 void (*trap_policer_fini)(struct devlink *devlink,
1135 const struct devlink_trap_policer *policer);
1137 * @trap_policer_set: Trap policer parameters set function.
1139 int (*trap_policer_set)(struct devlink *devlink,
1140 const struct devlink_trap_policer *policer,
1141 u64 rate, u64 burst,
1142 struct netlink_ext_ack *extack);
1144 * @trap_policer_counter_get: Trap policer counter get function.
1146 * Should be used by device drivers to report number of packets dropped
1149 int (*trap_policer_counter_get)(struct devlink *devlink,
1150 const struct devlink_trap_policer *policer,
1153 * @port_function_hw_addr_get: Port function's hardware address get function.
1155 * Should be used by device drivers to report the hardware address of a function managed
1156 * by the devlink port. Driver should return -EOPNOTSUPP if it doesn't support port
1157 * function handling for a particular port.
1159 * Note: @extack can be NULL when port notifier queries the port function.
1161 int (*port_function_hw_addr_get)(struct devlink *devlink, struct devlink_port *port,
1162 u8 *hw_addr, int *hw_addr_len,
1163 struct netlink_ext_ack *extack);
1165 * @port_function_hw_addr_set: Port function's hardware address set function.
1167 * Should be used by device drivers to set the hardware address of a function managed
1168 * by the devlink port. Driver should return -EOPNOTSUPP if it doesn't support port
1169 * function handling for a particular port.
1171 int (*port_function_hw_addr_set)(struct devlink *devlink, struct devlink_port *port,
1172 const u8 *hw_addr, int hw_addr_len,
1173 struct netlink_ext_ack *extack);
1176 static inline void *devlink_priv(struct devlink *devlink)
1179 return &devlink->priv;
1182 static inline struct devlink *priv_to_devlink(void *priv)
1185 return container_of(priv, struct devlink, priv);
1188 static inline struct devlink_port *
1189 netdev_to_devlink_port(struct net_device *dev)
1191 if (dev->netdev_ops->ndo_get_devlink_port)
1192 return dev->netdev_ops->ndo_get_devlink_port(dev);
1196 static inline struct devlink *netdev_to_devlink(struct net_device *dev)
1198 struct devlink_port *devlink_port = netdev_to_devlink_port(dev);
1201 return devlink_port->devlink;
1207 struct net *devlink_net(const struct devlink *devlink);
1208 void devlink_net_set(struct devlink *devlink, struct net *net);
1209 struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
1210 int devlink_register(struct devlink *devlink, struct device *dev);
1211 void devlink_unregister(struct devlink *devlink);
1212 void devlink_reload_enable(struct devlink *devlink);
1213 void devlink_reload_disable(struct devlink *devlink);
1214 void devlink_free(struct devlink *devlink);
1215 int devlink_port_register(struct devlink *devlink,
1216 struct devlink_port *devlink_port,
1217 unsigned int port_index);
1218 void devlink_port_unregister(struct devlink_port *devlink_port);
1219 void devlink_port_type_eth_set(struct devlink_port *devlink_port,
1220 struct net_device *netdev);
1221 void devlink_port_type_ib_set(struct devlink_port *devlink_port,
1222 struct ib_device *ibdev);
1223 void devlink_port_type_clear(struct devlink_port *devlink_port);
1224 void devlink_port_attrs_set(struct devlink_port *devlink_port,
1225 struct devlink_port_attrs *devlink_port_attrs);
1226 void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u32 controller,
1227 u16 pf, bool external);
1228 void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 controller,
1229 u16 pf, u16 vf, bool external);
1230 int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
1231 u32 size, u16 ingress_pools_count,
1232 u16 egress_pools_count, u16 ingress_tc_count,
1233 u16 egress_tc_count);
1234 void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
1235 int devlink_dpipe_table_register(struct devlink *devlink,
1236 const char *table_name,
1237 struct devlink_dpipe_table_ops *table_ops,
1238 void *priv, bool counter_control_extern);
1239 void devlink_dpipe_table_unregister(struct devlink *devlink,
1240 const char *table_name);
1241 int devlink_dpipe_headers_register(struct devlink *devlink,
1242 struct devlink_dpipe_headers *dpipe_headers);
1243 void devlink_dpipe_headers_unregister(struct devlink *devlink);
1244 bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
1245 const char *table_name);
1246 int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
1247 int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
1248 struct devlink_dpipe_entry *entry);
1249 int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
1250 void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
1251 int devlink_dpipe_action_put(struct sk_buff *skb,
1252 struct devlink_dpipe_action *action);
1253 int devlink_dpipe_match_put(struct sk_buff *skb,
1254 struct devlink_dpipe_match *match);
1255 extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
1256 extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
1257 extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
1259 int devlink_resource_register(struct devlink *devlink,
1260 const char *resource_name,
1263 u64 parent_resource_id,
1264 const struct devlink_resource_size_params *size_params);
1265 void devlink_resources_unregister(struct devlink *devlink,
1266 struct devlink_resource *resource);
1267 int devlink_resource_size_get(struct devlink *devlink,
1269 u64 *p_resource_size);
1270 int devlink_dpipe_table_resource_set(struct devlink *devlink,
1271 const char *table_name, u64 resource_id,
1272 u64 resource_units);
1273 void devlink_resource_occ_get_register(struct devlink *devlink,
1275 devlink_resource_occ_get_t *occ_get,
1276 void *occ_get_priv);
1277 void devlink_resource_occ_get_unregister(struct devlink *devlink,
1279 int devlink_params_register(struct devlink *devlink,
1280 const struct devlink_param *params,
1281 size_t params_count);
1282 void devlink_params_unregister(struct devlink *devlink,
1283 const struct devlink_param *params,
1284 size_t params_count);
1285 void devlink_params_publish(struct devlink *devlink);
1286 void devlink_params_unpublish(struct devlink *devlink);
1287 int devlink_port_params_register(struct devlink_port *devlink_port,
1288 const struct devlink_param *params,
1289 size_t params_count);
1290 void devlink_port_params_unregister(struct devlink_port *devlink_port,
1291 const struct devlink_param *params,
1292 size_t params_count);
1293 int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
1294 union devlink_param_value *init_val);
1295 int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
1296 union devlink_param_value init_val);
1298 devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
1300 union devlink_param_value *init_val);
1301 int devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
1303 union devlink_param_value init_val);
1304 void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
1305 void devlink_port_param_value_changed(struct devlink_port *devlink_port,
1307 void devlink_param_value_str_fill(union devlink_param_value *dst_val,
1309 struct devlink_region *
1310 devlink_region_create(struct devlink *devlink,
1311 const struct devlink_region_ops *ops,
1312 u32 region_max_snapshots, u64 region_size);
1313 void devlink_region_destroy(struct devlink_region *region);
1314 int devlink_region_snapshot_id_get(struct devlink *devlink, u32 *id);
1315 void devlink_region_snapshot_id_put(struct devlink *devlink, u32 id);
1316 int devlink_region_snapshot_create(struct devlink_region *region,
1317 u8 *data, u32 snapshot_id);
1318 int devlink_info_serial_number_put(struct devlink_info_req *req,
1320 int devlink_info_driver_name_put(struct devlink_info_req *req,
1322 int devlink_info_board_serial_number_put(struct devlink_info_req *req,
1324 int devlink_info_version_fixed_put(struct devlink_info_req *req,
1325 const char *version_name,
1326 const char *version_value);
1327 int devlink_info_version_stored_put(struct devlink_info_req *req,
1328 const char *version_name,
1329 const char *version_value);
1330 int devlink_info_version_running_put(struct devlink_info_req *req,
1331 const char *version_name,
1332 const char *version_value);
1334 int devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg);
1335 int devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg);
1337 int devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name);
1338 int devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg);
1340 int devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg,
1342 int devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg);
1343 int devlink_fmsg_binary_pair_nest_start(struct devlink_fmsg *fmsg,
1345 int devlink_fmsg_binary_pair_nest_end(struct devlink_fmsg *fmsg);
1347 int devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value);
1348 int devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value);
1349 int devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value);
1350 int devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value);
1351 int devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value);
1352 int devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value,
1355 int devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name,
1357 int devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name,
1359 int devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name,
1361 int devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name,
1363 int devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,
1365 int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
1366 const void *value, u32 value_len);
1368 struct devlink_health_reporter *
1369 devlink_health_reporter_create(struct devlink *devlink,
1370 const struct devlink_health_reporter_ops *ops,
1371 u64 graceful_period, void *priv);
1373 struct devlink_health_reporter *
1374 devlink_port_health_reporter_create(struct devlink_port *port,
1375 const struct devlink_health_reporter_ops *ops,
1376 u64 graceful_period, void *priv);
1379 devlink_health_reporter_destroy(struct devlink_health_reporter *reporter);
1382 devlink_port_health_reporter_destroy(struct devlink_health_reporter *reporter);
1385 devlink_health_reporter_priv(struct devlink_health_reporter *reporter);
1386 int devlink_health_report(struct devlink_health_reporter *reporter,
1387 const char *msg, void *priv_ctx);
1389 devlink_health_reporter_state_update(struct devlink_health_reporter *reporter,
1390 enum devlink_health_reporter_state state);
1392 devlink_health_reporter_recovery_done(struct devlink_health_reporter *reporter);
1394 bool devlink_is_reload_failed(const struct devlink *devlink);
1396 void devlink_flash_update_begin_notify(struct devlink *devlink);
1397 void devlink_flash_update_end_notify(struct devlink *devlink);
1398 void devlink_flash_update_status_notify(struct devlink *devlink,
1399 const char *status_msg,
1400 const char *component,
1402 unsigned long total);
1404 int devlink_traps_register(struct devlink *devlink,
1405 const struct devlink_trap *traps,
1406 size_t traps_count, void *priv);
1407 void devlink_traps_unregister(struct devlink *devlink,
1408 const struct devlink_trap *traps,
1409 size_t traps_count);
1410 void devlink_trap_report(struct devlink *devlink, struct sk_buff *skb,
1411 void *trap_ctx, struct devlink_port *in_devlink_port,
1412 const struct flow_action_cookie *fa_cookie);
1413 void *devlink_trap_ctx_priv(void *trap_ctx);
1414 int devlink_trap_groups_register(struct devlink *devlink,
1415 const struct devlink_trap_group *groups,
1416 size_t groups_count);
1417 void devlink_trap_groups_unregister(struct devlink *devlink,
1418 const struct devlink_trap_group *groups,
1419 size_t groups_count);
1421 devlink_trap_policers_register(struct devlink *devlink,
1422 const struct devlink_trap_policer *policers,
1423 size_t policers_count);
1425 devlink_trap_policers_unregister(struct devlink *devlink,
1426 const struct devlink_trap_policer *policers,
1427 size_t policers_count);
1429 #if IS_ENABLED(CONFIG_NET_DEVLINK)
1431 void devlink_compat_running_version(struct net_device *dev,
1432 char *buf, size_t len);
1433 int devlink_compat_flash_update(struct net_device *dev, const char *file_name);
1434 int devlink_compat_phys_port_name_get(struct net_device *dev,
1435 char *name, size_t len);
1436 int devlink_compat_switch_id_get(struct net_device *dev,
1437 struct netdev_phys_item_id *ppid);
1442 devlink_compat_running_version(struct net_device *dev, char *buf, size_t len)
1447 devlink_compat_flash_update(struct net_device *dev, const char *file_name)
1453 devlink_compat_phys_port_name_get(struct net_device *dev,
1454 char *name, size_t len)
1460 devlink_compat_switch_id_get(struct net_device *dev,
1461 struct netdev_phys_item_id *ppid)
1468 #endif /* _NET_DEVLINK_H_ */