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 <uapi/linux/devlink.h>
24 struct list_head list;
25 struct list_head port_list;
26 struct list_head sb_list;
27 struct list_head dpipe_table_list;
28 struct list_head resource_list;
29 struct list_head param_list;
30 struct list_head region_list;
32 struct list_head reporter_list;
33 struct mutex reporters_lock; /* protects reporter_list */
34 struct devlink_dpipe_headers *dpipe_headers;
35 struct list_head trap_list;
36 struct list_head trap_group_list;
37 const struct devlink_ops *ops;
44 char priv[0] __aligned(NETDEV_ALIGN);
47 struct devlink_port_phys_attrs {
48 u32 port_number; /* Same value as "split group".
49 * A physical port which is visible to the user
50 * for a given port flavour.
52 u32 split_subport_number;
55 struct devlink_port_pci_pf_attrs {
56 u16 pf; /* Associated PCI PF for this port. */
59 struct devlink_port_pci_vf_attrs {
60 u16 pf; /* Associated PCI PF for this port. */
61 u16 vf; /* Associated PCI VF for of the PCI PF for this port. */
64 struct devlink_port_attrs {
68 enum devlink_port_flavour flavour;
69 struct netdev_phys_item_id switch_id;
71 struct devlink_port_phys_attrs phys;
72 struct devlink_port_pci_pf_attrs pci_pf;
73 struct devlink_port_pci_vf_attrs pci_vf;
78 struct list_head list;
79 struct list_head param_list;
80 struct devlink *devlink;
83 spinlock_t type_lock; /* Protects type and type_dev
84 * pointer consistency.
86 enum devlink_port_type type;
87 enum devlink_port_type desired_type;
89 struct devlink_port_attrs attrs;
90 struct delayed_work type_warn_dw;
93 struct devlink_sb_pool_info {
94 enum devlink_sb_pool_type pool_type;
96 enum devlink_sb_threshold_type threshold_type;
101 * struct devlink_dpipe_field - dpipe field object
103 * @id: index inside the headers field array
104 * @bitwidth: bitwidth
105 * @mapping_type: mapping type
107 struct devlink_dpipe_field {
110 unsigned int bitwidth;
111 enum devlink_dpipe_field_mapping_type mapping_type;
115 * struct devlink_dpipe_header - dpipe header object
117 * @id: index, global/local detrmined by global bit
119 * @fields_count: number of fields
120 * @global: indicates if header is shared like most protocol header
123 struct devlink_dpipe_header {
126 struct devlink_dpipe_field *fields;
127 unsigned int fields_count;
132 * struct devlink_dpipe_match - represents match operation
133 * @type: type of match
134 * @header_index: header index (packets can have several headers of same
135 * type like in case of tunnels)
137 * @fieled_id: field index
139 struct devlink_dpipe_match {
140 enum devlink_dpipe_match_type type;
141 unsigned int header_index;
142 struct devlink_dpipe_header *header;
143 unsigned int field_id;
147 * struct devlink_dpipe_action - represents action operation
148 * @type: type of action
149 * @header_index: header index (packets can have several headers of same
150 * type like in case of tunnels)
152 * @fieled_id: field index
154 struct devlink_dpipe_action {
155 enum devlink_dpipe_action_type type;
156 unsigned int header_index;
157 struct devlink_dpipe_header *header;
158 unsigned int field_id;
162 * struct devlink_dpipe_value - represents value of match/action
165 * @mapping_value: in case the field has some mapping this value
166 * specified the mapping value
167 * @mapping_valid: specify if mapping value is valid
168 * @value_size: value size
172 struct devlink_dpipe_value {
174 struct devlink_dpipe_action *action;
175 struct devlink_dpipe_match *match;
177 unsigned int mapping_value;
179 unsigned int value_size;
185 * struct devlink_dpipe_entry - table entry object
186 * @index: index of the entry in the table
187 * @match_values: match values
188 * @matche_values_count: count of matches tuples
189 * @action_values: actions values
190 * @action_values_count: count of actions values
191 * @counter: value of counter
192 * @counter_valid: Specify if value is valid from hardware
194 struct devlink_dpipe_entry {
196 struct devlink_dpipe_value *match_values;
197 unsigned int match_values_count;
198 struct devlink_dpipe_value *action_values;
199 unsigned int action_values_count;
205 * struct devlink_dpipe_dump_ctx - context provided to driver in order
208 * @cmd: devlink command
210 * @nest: top attribute
213 struct devlink_dpipe_dump_ctx {
214 struct genl_info *info;
215 enum devlink_command cmd;
221 struct devlink_dpipe_table_ops;
224 * struct devlink_dpipe_table - table object
227 * @counters_enabled: indicates if counters are active
228 * @counter_control_extern: indicates if counter control is in dpipe or
230 * @resource_valid: Indicate that the resource id is valid
231 * @resource_id: relative resource this table is related to
232 * @resource_units: number of resource's unit consumed per table's entry
233 * @table_ops: table operations
236 struct devlink_dpipe_table {
238 struct list_head list;
240 bool counters_enabled;
241 bool counter_control_extern;
245 struct devlink_dpipe_table_ops *table_ops;
250 * struct devlink_dpipe_table_ops - dpipe_table ops
251 * @actions_dump - dumps all tables actions
252 * @matches_dump - dumps all tables matches
253 * @entries_dump - dumps all active entries in the table
254 * @counters_set_update - when changing the counter status hardware sync
255 * maybe needed to allocate/free counter related
257 * @size_get - get size
259 struct devlink_dpipe_table_ops {
260 int (*actions_dump)(void *priv, struct sk_buff *skb);
261 int (*matches_dump)(void *priv, struct sk_buff *skb);
262 int (*entries_dump)(void *priv, bool counters_enabled,
263 struct devlink_dpipe_dump_ctx *dump_ctx);
264 int (*counters_set_update)(void *priv, bool enable);
265 u64 (*size_get)(void *priv);
269 * struct devlink_dpipe_headers - dpipe headers
270 * @headers - header array can be shared (global bit) or driver specific
271 * @headers_count - count of headers
273 struct devlink_dpipe_headers {
274 struct devlink_dpipe_header **headers;
275 unsigned int headers_count;
279 * struct devlink_resource_size_params - resource's size parameters
280 * @size_min: minimum size which can be set
281 * @size_max: maximum size which can be set
282 * @size_granularity: size granularity
283 * @size_unit: resource's basic unit
285 struct devlink_resource_size_params {
288 u64 size_granularity;
289 enum devlink_resource_unit unit;
293 devlink_resource_size_params_init(struct devlink_resource_size_params *size_params,
294 u64 size_min, u64 size_max,
295 u64 size_granularity,
296 enum devlink_resource_unit unit)
298 size_params->size_min = size_min;
299 size_params->size_max = size_max;
300 size_params->size_granularity = size_granularity;
301 size_params->unit = unit;
304 typedef u64 devlink_resource_occ_get_t(void *priv);
307 * struct devlink_resource - devlink resource
308 * @name: name of the resource
309 * @id: id, per devlink instance
310 * @size: size of the resource
311 * @size_new: updated size of the resource, reload is needed
312 * @size_valid: valid in case the total size of the resource is valid
313 * including its children
314 * @parent: parent resource
315 * @size_params: size parameters
317 * @resource_list: list of child resources
319 struct devlink_resource {
325 struct devlink_resource *parent;
326 struct devlink_resource_size_params size_params;
327 struct list_head list;
328 struct list_head resource_list;
329 devlink_resource_occ_get_t *occ_get;
333 #define DEVLINK_RESOURCE_ID_PARENT_TOP 0
335 #define __DEVLINK_PARAM_MAX_STRING_VALUE 32
336 enum devlink_param_type {
337 DEVLINK_PARAM_TYPE_U8,
338 DEVLINK_PARAM_TYPE_U16,
339 DEVLINK_PARAM_TYPE_U32,
340 DEVLINK_PARAM_TYPE_STRING,
341 DEVLINK_PARAM_TYPE_BOOL,
344 union devlink_param_value {
348 char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];
352 struct devlink_param_gset_ctx {
353 union devlink_param_value val;
354 enum devlink_param_cmode cmode;
358 * struct devlink_param - devlink configuration parameter data
359 * @name: name of the parameter
360 * @generic: indicates if the parameter is generic or driver specific
361 * @type: parameter type
362 * @supported_cmodes: bitmap of supported configuration modes
363 * @get: get parameter value, used for runtime and permanent
364 * configuration modes
365 * @set: set parameter value, used for runtime and permanent
366 * configuration modes
367 * @validate: validate input value is applicable (within value range, etc.)
369 * This struct should be used by the driver to fill the data for
370 * a parameter it registers.
372 struct devlink_param {
376 enum devlink_param_type type;
377 unsigned long supported_cmodes;
378 int (*get)(struct devlink *devlink, u32 id,
379 struct devlink_param_gset_ctx *ctx);
380 int (*set)(struct devlink *devlink, u32 id,
381 struct devlink_param_gset_ctx *ctx);
382 int (*validate)(struct devlink *devlink, u32 id,
383 union devlink_param_value val,
384 struct netlink_ext_ack *extack);
387 struct devlink_param_item {
388 struct list_head list;
389 const struct devlink_param *param;
390 union devlink_param_value driverinit_value;
391 bool driverinit_value_valid;
395 enum devlink_param_generic_id {
396 DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
397 DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
398 DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
399 DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT,
400 DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI,
401 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
402 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
403 DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY,
404 DEVLINK_PARAM_GENERIC_ID_RESET_DEV_ON_DRV_PROBE,
405 DEVLINK_PARAM_GENERIC_ID_ENABLE_ROCE,
407 /* add new param generic ids above here*/
408 __DEVLINK_PARAM_GENERIC_ID_MAX,
409 DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
412 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
413 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
415 #define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
416 #define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
418 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
419 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
421 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable"
422 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL
424 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari"
425 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL
427 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max"
428 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32
430 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min"
431 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32
433 #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy"
434 #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8
436 #define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_NAME \
437 "reset_dev_on_drv_probe"
438 #define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_TYPE DEVLINK_PARAM_TYPE_U8
440 #define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_NAME "enable_roce"
441 #define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_TYPE DEVLINK_PARAM_TYPE_BOOL
443 #define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \
445 .id = DEVLINK_PARAM_GENERIC_ID_##_id, \
446 .name = DEVLINK_PARAM_GENERIC_##_id##_NAME, \
447 .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE, \
449 .supported_cmodes = _cmodes, \
452 .validate = _validate, \
455 #define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate) \
460 .supported_cmodes = _cmodes, \
463 .validate = _validate, \
466 /* Part number, identifier of board design */
467 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID "board.id"
468 /* Revision of board design */
469 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV "board.rev"
470 /* Maker of the board */
471 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_MANUFACTURE "board.manufacture"
473 /* Part number, identifier of asic design */
474 #define DEVLINK_INFO_VERSION_GENERIC_ASIC_ID "asic.id"
475 /* Revision of asic design */
476 #define DEVLINK_INFO_VERSION_GENERIC_ASIC_REV "asic.rev"
478 /* Overall FW version */
479 #define DEVLINK_INFO_VERSION_GENERIC_FW "fw"
480 /* Control processor FW version */
481 #define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT "fw.mgmt"
482 /* Data path microcode controlling high-speed packet processing */
483 #define DEVLINK_INFO_VERSION_GENERIC_FW_APP "fw.app"
484 /* UNDI software version */
485 #define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI "fw.undi"
486 /* NCSI support/handler version */
487 #define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI "fw.ncsi"
489 struct devlink_region;
490 struct devlink_info_req;
492 typedef void devlink_snapshot_data_dest_t(const void *data);
495 struct devlink_health_reporter;
497 enum devlink_health_reporter_state {
498 DEVLINK_HEALTH_REPORTER_STATE_HEALTHY,
499 DEVLINK_HEALTH_REPORTER_STATE_ERROR,
503 * struct devlink_health_reporter_ops - Reporter operations
504 * @name: reporter name
505 * @recover: callback to recover from reported error
506 * if priv_ctx is NULL, run a full recover
507 * @dump: callback to dump an object
508 * if priv_ctx is NULL, run a full dump
509 * @diagnose: callback to diagnose the current status
512 struct devlink_health_reporter_ops {
514 int (*recover)(struct devlink_health_reporter *reporter,
515 void *priv_ctx, struct netlink_ext_ack *extack);
516 int (*dump)(struct devlink_health_reporter *reporter,
517 struct devlink_fmsg *fmsg, void *priv_ctx,
518 struct netlink_ext_ack *extack);
519 int (*diagnose)(struct devlink_health_reporter *reporter,
520 struct devlink_fmsg *fmsg,
521 struct netlink_ext_ack *extack);
525 * struct devlink_trap_group - Immutable packet trap group attributes.
526 * @name: Trap group name.
527 * @id: Trap group identifier.
528 * @generic: Whether the trap group is generic or not.
530 * Describes immutable attributes of packet trap groups that drivers register
533 struct devlink_trap_group {
539 #define DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT BIT(0)
542 * struct devlink_trap - Immutable packet trap attributes.
544 * @init_action: Initial trap action.
545 * @generic: Whether the trap is generic or not.
546 * @id: Trap identifier.
548 * @group: Immutable packet trap group attributes.
549 * @metadata_cap: Metadata types that can be provided by the trap.
551 * Describes immutable attributes of packet traps that drivers register with
554 struct devlink_trap {
555 enum devlink_trap_type type;
556 enum devlink_trap_action init_action;
560 struct devlink_trap_group group;
564 /* All traps must be documented in
565 * Documentation/networking/devlink-trap.rst
567 enum devlink_trap_generic_id {
568 DEVLINK_TRAP_GENERIC_ID_SMAC_MC,
569 DEVLINK_TRAP_GENERIC_ID_VLAN_TAG_MISMATCH,
570 DEVLINK_TRAP_GENERIC_ID_INGRESS_VLAN_FILTER,
571 DEVLINK_TRAP_GENERIC_ID_INGRESS_STP_FILTER,
572 DEVLINK_TRAP_GENERIC_ID_EMPTY_TX_LIST,
573 DEVLINK_TRAP_GENERIC_ID_PORT_LOOPBACK_FILTER,
574 DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_ROUTE,
575 DEVLINK_TRAP_GENERIC_ID_TTL_ERROR,
576 DEVLINK_TRAP_GENERIC_ID_TAIL_DROP,
577 DEVLINK_TRAP_GENERIC_ID_NON_IP_PACKET,
578 DEVLINK_TRAP_GENERIC_ID_UC_DIP_MC_DMAC,
579 DEVLINK_TRAP_GENERIC_ID_DIP_LB,
580 DEVLINK_TRAP_GENERIC_ID_SIP_MC,
581 DEVLINK_TRAP_GENERIC_ID_SIP_LB,
582 DEVLINK_TRAP_GENERIC_ID_CORRUPTED_IP_HDR,
583 DEVLINK_TRAP_GENERIC_ID_IPV4_SIP_BC,
584 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_RESERVED_SCOPE,
585 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE,
586 DEVLINK_TRAP_GENERIC_ID_MTU_ERROR,
587 DEVLINK_TRAP_GENERIC_ID_UNRESOLVED_NEIGH,
588 DEVLINK_TRAP_GENERIC_ID_RPF,
589 DEVLINK_TRAP_GENERIC_ID_REJECT_ROUTE,
590 DEVLINK_TRAP_GENERIC_ID_IPV4_LPM_UNICAST_MISS,
591 DEVLINK_TRAP_GENERIC_ID_IPV6_LPM_UNICAST_MISS,
593 /* Add new generic trap IDs above */
594 __DEVLINK_TRAP_GENERIC_ID_MAX,
595 DEVLINK_TRAP_GENERIC_ID_MAX = __DEVLINK_TRAP_GENERIC_ID_MAX - 1,
598 /* All trap groups must be documented in
599 * Documentation/networking/devlink-trap.rst
601 enum devlink_trap_group_generic_id {
602 DEVLINK_TRAP_GROUP_GENERIC_ID_L2_DROPS,
603 DEVLINK_TRAP_GROUP_GENERIC_ID_L3_DROPS,
604 DEVLINK_TRAP_GROUP_GENERIC_ID_BUFFER_DROPS,
606 /* Add new generic trap group IDs above */
607 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX,
608 DEVLINK_TRAP_GROUP_GENERIC_ID_MAX =
609 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX - 1,
612 #define DEVLINK_TRAP_GENERIC_NAME_SMAC_MC \
613 "source_mac_is_multicast"
614 #define DEVLINK_TRAP_GENERIC_NAME_VLAN_TAG_MISMATCH \
616 #define DEVLINK_TRAP_GENERIC_NAME_INGRESS_VLAN_FILTER \
617 "ingress_vlan_filter"
618 #define DEVLINK_TRAP_GENERIC_NAME_INGRESS_STP_FILTER \
619 "ingress_spanning_tree_filter"
620 #define DEVLINK_TRAP_GENERIC_NAME_EMPTY_TX_LIST \
622 #define DEVLINK_TRAP_GENERIC_NAME_PORT_LOOPBACK_FILTER \
623 "port_loopback_filter"
624 #define DEVLINK_TRAP_GENERIC_NAME_BLACKHOLE_ROUTE \
626 #define DEVLINK_TRAP_GENERIC_NAME_TTL_ERROR \
627 "ttl_value_is_too_small"
628 #define DEVLINK_TRAP_GENERIC_NAME_TAIL_DROP \
630 #define DEVLINK_TRAP_GENERIC_NAME_NON_IP_PACKET \
632 #define DEVLINK_TRAP_GENERIC_NAME_UC_DIP_MC_DMAC \
633 "uc_dip_over_mc_dmac"
634 #define DEVLINK_TRAP_GENERIC_NAME_DIP_LB \
635 "dip_is_loopback_address"
636 #define DEVLINK_TRAP_GENERIC_NAME_SIP_MC \
638 #define DEVLINK_TRAP_GENERIC_NAME_SIP_LB \
639 "sip_is_loopback_address"
640 #define DEVLINK_TRAP_GENERIC_NAME_CORRUPTED_IP_HDR \
641 "ip_header_corrupted"
642 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_SIP_BC \
643 "ipv4_sip_is_limited_bc"
644 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_RESERVED_SCOPE \
645 "ipv6_mc_dip_reserved_scope"
646 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE \
647 "ipv6_mc_dip_interface_local_scope"
648 #define DEVLINK_TRAP_GENERIC_NAME_MTU_ERROR \
649 "mtu_value_is_too_small"
650 #define DEVLINK_TRAP_GENERIC_NAME_UNRESOLVED_NEIGH \
652 #define DEVLINK_TRAP_GENERIC_NAME_RPF \
653 "mc_reverse_path_forwarding"
654 #define DEVLINK_TRAP_GENERIC_NAME_REJECT_ROUTE \
656 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_LPM_UNICAST_MISS \
658 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_LPM_UNICAST_MISS \
661 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_L2_DROPS \
663 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_DROPS \
665 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_BUFFER_DROPS \
668 #define DEVLINK_TRAP_GENERIC(_type, _init_action, _id, _group, _metadata_cap) \
670 .type = DEVLINK_TRAP_TYPE_##_type, \
671 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
673 .id = DEVLINK_TRAP_GENERIC_ID_##_id, \
674 .name = DEVLINK_TRAP_GENERIC_NAME_##_id, \
676 .metadata_cap = _metadata_cap, \
679 #define DEVLINK_TRAP_DRIVER(_type, _init_action, _id, _name, _group, \
682 .type = DEVLINK_TRAP_TYPE_##_type, \
683 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
688 .metadata_cap = _metadata_cap, \
691 #define DEVLINK_TRAP_GROUP_GENERIC(_id) \
693 .name = DEVLINK_TRAP_GROUP_GENERIC_NAME_##_id, \
694 .id = DEVLINK_TRAP_GROUP_GENERIC_ID_##_id, \
699 int (*reload_down)(struct devlink *devlink, bool netns_change,
700 struct netlink_ext_ack *extack);
701 int (*reload_up)(struct devlink *devlink,
702 struct netlink_ext_ack *extack);
703 int (*port_type_set)(struct devlink_port *devlink_port,
704 enum devlink_port_type port_type);
705 int (*port_split)(struct devlink *devlink, unsigned int port_index,
706 unsigned int count, struct netlink_ext_ack *extack);
707 int (*port_unsplit)(struct devlink *devlink, unsigned int port_index,
708 struct netlink_ext_ack *extack);
709 int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
711 struct devlink_sb_pool_info *pool_info);
712 int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
713 u16 pool_index, u32 size,
714 enum devlink_sb_threshold_type threshold_type,
715 struct netlink_ext_ack *extack);
716 int (*sb_port_pool_get)(struct devlink_port *devlink_port,
717 unsigned int sb_index, u16 pool_index,
719 int (*sb_port_pool_set)(struct devlink_port *devlink_port,
720 unsigned int sb_index, u16 pool_index,
721 u32 threshold, struct netlink_ext_ack *extack);
722 int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
723 unsigned int sb_index,
725 enum devlink_sb_pool_type pool_type,
726 u16 *p_pool_index, u32 *p_threshold);
727 int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
728 unsigned int sb_index,
730 enum devlink_sb_pool_type pool_type,
731 u16 pool_index, u32 threshold,
732 struct netlink_ext_ack *extack);
733 int (*sb_occ_snapshot)(struct devlink *devlink,
734 unsigned int sb_index);
735 int (*sb_occ_max_clear)(struct devlink *devlink,
736 unsigned int sb_index);
737 int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
738 unsigned int sb_index, u16 pool_index,
739 u32 *p_cur, u32 *p_max);
740 int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
741 unsigned int sb_index,
743 enum devlink_sb_pool_type pool_type,
744 u32 *p_cur, u32 *p_max);
746 int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
747 int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
748 struct netlink_ext_ack *extack);
749 int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
750 int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
751 struct netlink_ext_ack *extack);
752 int (*eswitch_encap_mode_get)(struct devlink *devlink,
753 enum devlink_eswitch_encap_mode *p_encap_mode);
754 int (*eswitch_encap_mode_set)(struct devlink *devlink,
755 enum devlink_eswitch_encap_mode encap_mode,
756 struct netlink_ext_ack *extack);
757 int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
758 struct netlink_ext_ack *extack);
759 int (*flash_update)(struct devlink *devlink, const char *file_name,
760 const char *component,
761 struct netlink_ext_ack *extack);
763 * @trap_init: Trap initialization function.
765 * Should be used by device drivers to initialize the trap in the
766 * underlying device. Drivers should also store the provided trap
767 * context, so that they could efficiently pass it to
768 * devlink_trap_report() when the trap is triggered.
770 int (*trap_init)(struct devlink *devlink,
771 const struct devlink_trap *trap, void *trap_ctx);
773 * @trap_fini: Trap de-initialization function.
775 * Should be used by device drivers to de-initialize the trap in the
778 void (*trap_fini)(struct devlink *devlink,
779 const struct devlink_trap *trap, void *trap_ctx);
781 * @trap_action_set: Trap action set function.
783 int (*trap_action_set)(struct devlink *devlink,
784 const struct devlink_trap *trap,
785 enum devlink_trap_action action);
787 * @trap_group_init: Trap group initialization function.
789 * Should be used by device drivers to initialize the trap group in the
792 int (*trap_group_init)(struct devlink *devlink,
793 const struct devlink_trap_group *group);
796 static inline void *devlink_priv(struct devlink *devlink)
799 return &devlink->priv;
802 static inline struct devlink *priv_to_devlink(void *priv)
805 return container_of(priv, struct devlink, priv);
808 static inline struct devlink_port *
809 netdev_to_devlink_port(struct net_device *dev)
811 if (dev->netdev_ops->ndo_get_devlink_port)
812 return dev->netdev_ops->ndo_get_devlink_port(dev);
816 static inline struct devlink *netdev_to_devlink(struct net_device *dev)
818 struct devlink_port *devlink_port = netdev_to_devlink_port(dev);
821 return devlink_port->devlink;
827 struct net *devlink_net(const struct devlink *devlink);
828 void devlink_net_set(struct devlink *devlink, struct net *net);
829 struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
830 int devlink_register(struct devlink *devlink, struct device *dev);
831 void devlink_unregister(struct devlink *devlink);
832 void devlink_reload_enable(struct devlink *devlink);
833 void devlink_reload_disable(struct devlink *devlink);
834 void devlink_free(struct devlink *devlink);
835 int devlink_port_register(struct devlink *devlink,
836 struct devlink_port *devlink_port,
837 unsigned int port_index);
838 void devlink_port_unregister(struct devlink_port *devlink_port);
839 void devlink_port_type_eth_set(struct devlink_port *devlink_port,
840 struct net_device *netdev);
841 void devlink_port_type_ib_set(struct devlink_port *devlink_port,
842 struct ib_device *ibdev);
843 void devlink_port_type_clear(struct devlink_port *devlink_port);
844 void devlink_port_attrs_set(struct devlink_port *devlink_port,
845 enum devlink_port_flavour flavour,
846 u32 port_number, bool split,
847 u32 split_subport_number,
848 const unsigned char *switch_id,
849 unsigned char switch_id_len);
850 void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
851 const unsigned char *switch_id,
852 unsigned char switch_id_len, u16 pf);
853 void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
854 const unsigned char *switch_id,
855 unsigned char switch_id_len,
857 int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
858 u32 size, u16 ingress_pools_count,
859 u16 egress_pools_count, u16 ingress_tc_count,
860 u16 egress_tc_count);
861 void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
862 int devlink_dpipe_table_register(struct devlink *devlink,
863 const char *table_name,
864 struct devlink_dpipe_table_ops *table_ops,
865 void *priv, bool counter_control_extern);
866 void devlink_dpipe_table_unregister(struct devlink *devlink,
867 const char *table_name);
868 int devlink_dpipe_headers_register(struct devlink *devlink,
869 struct devlink_dpipe_headers *dpipe_headers);
870 void devlink_dpipe_headers_unregister(struct devlink *devlink);
871 bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
872 const char *table_name);
873 int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
874 int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
875 struct devlink_dpipe_entry *entry);
876 int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
877 void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
878 int devlink_dpipe_action_put(struct sk_buff *skb,
879 struct devlink_dpipe_action *action);
880 int devlink_dpipe_match_put(struct sk_buff *skb,
881 struct devlink_dpipe_match *match);
882 extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
883 extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
884 extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
886 int devlink_resource_register(struct devlink *devlink,
887 const char *resource_name,
890 u64 parent_resource_id,
891 const struct devlink_resource_size_params *size_params);
892 void devlink_resources_unregister(struct devlink *devlink,
893 struct devlink_resource *resource);
894 int devlink_resource_size_get(struct devlink *devlink,
896 u64 *p_resource_size);
897 int devlink_dpipe_table_resource_set(struct devlink *devlink,
898 const char *table_name, u64 resource_id,
900 void devlink_resource_occ_get_register(struct devlink *devlink,
902 devlink_resource_occ_get_t *occ_get,
904 void devlink_resource_occ_get_unregister(struct devlink *devlink,
906 int devlink_params_register(struct devlink *devlink,
907 const struct devlink_param *params,
908 size_t params_count);
909 void devlink_params_unregister(struct devlink *devlink,
910 const struct devlink_param *params,
911 size_t params_count);
912 void devlink_params_publish(struct devlink *devlink);
913 void devlink_params_unpublish(struct devlink *devlink);
914 int devlink_port_params_register(struct devlink_port *devlink_port,
915 const struct devlink_param *params,
916 size_t params_count);
917 void devlink_port_params_unregister(struct devlink_port *devlink_port,
918 const struct devlink_param *params,
919 size_t params_count);
920 int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
921 union devlink_param_value *init_val);
922 int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
923 union devlink_param_value init_val);
925 devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
927 union devlink_param_value *init_val);
928 int devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
930 union devlink_param_value init_val);
931 void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
932 void devlink_port_param_value_changed(struct devlink_port *devlink_port,
934 void devlink_param_value_str_fill(union devlink_param_value *dst_val,
936 struct devlink_region *devlink_region_create(struct devlink *devlink,
937 const char *region_name,
938 u32 region_max_snapshots,
940 void devlink_region_destroy(struct devlink_region *region);
941 u32 devlink_region_shapshot_id_get(struct devlink *devlink);
942 int devlink_region_snapshot_create(struct devlink_region *region,
943 u8 *data, u32 snapshot_id,
944 devlink_snapshot_data_dest_t *data_destructor);
945 int devlink_info_serial_number_put(struct devlink_info_req *req,
947 int devlink_info_driver_name_put(struct devlink_info_req *req,
949 int devlink_info_version_fixed_put(struct devlink_info_req *req,
950 const char *version_name,
951 const char *version_value);
952 int devlink_info_version_stored_put(struct devlink_info_req *req,
953 const char *version_name,
954 const char *version_value);
955 int devlink_info_version_running_put(struct devlink_info_req *req,
956 const char *version_name,
957 const char *version_value);
959 int devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg);
960 int devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg);
962 int devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name);
963 int devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg);
965 int devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg,
967 int devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg);
969 int devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value);
970 int devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value);
971 int devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value);
972 int devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value);
973 int devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value);
975 int devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name,
977 int devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name,
979 int devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name,
981 int devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name,
983 int devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,
985 int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
986 const void *value, u32 value_len);
988 struct devlink_health_reporter *
989 devlink_health_reporter_create(struct devlink *devlink,
990 const struct devlink_health_reporter_ops *ops,
991 u64 graceful_period, bool auto_recover,
994 devlink_health_reporter_destroy(struct devlink_health_reporter *reporter);
997 devlink_health_reporter_priv(struct devlink_health_reporter *reporter);
998 int devlink_health_report(struct devlink_health_reporter *reporter,
999 const char *msg, void *priv_ctx);
1001 devlink_health_reporter_state_update(struct devlink_health_reporter *reporter,
1002 enum devlink_health_reporter_state state);
1004 bool devlink_is_reload_failed(const struct devlink *devlink);
1006 void devlink_flash_update_begin_notify(struct devlink *devlink);
1007 void devlink_flash_update_end_notify(struct devlink *devlink);
1008 void devlink_flash_update_status_notify(struct devlink *devlink,
1009 const char *status_msg,
1010 const char *component,
1012 unsigned long total);
1014 int devlink_traps_register(struct devlink *devlink,
1015 const struct devlink_trap *traps,
1016 size_t traps_count, void *priv);
1017 void devlink_traps_unregister(struct devlink *devlink,
1018 const struct devlink_trap *traps,
1019 size_t traps_count);
1020 void devlink_trap_report(struct devlink *devlink,
1021 struct sk_buff *skb, void *trap_ctx,
1022 struct devlink_port *in_devlink_port);
1023 void *devlink_trap_ctx_priv(void *trap_ctx);
1025 #if IS_ENABLED(CONFIG_NET_DEVLINK)
1027 void devlink_compat_running_version(struct net_device *dev,
1028 char *buf, size_t len);
1029 int devlink_compat_flash_update(struct net_device *dev, const char *file_name);
1030 int devlink_compat_phys_port_name_get(struct net_device *dev,
1031 char *name, size_t len);
1032 int devlink_compat_switch_id_get(struct net_device *dev,
1033 struct netdev_phys_item_id *ppid);
1038 devlink_compat_running_version(struct net_device *dev, char *buf, size_t len)
1043 devlink_compat_flash_update(struct net_device *dev, const char *file_name)
1049 devlink_compat_phys_port_name_get(struct net_device *dev,
1050 char *name, size_t len)
1056 devlink_compat_switch_id_get(struct net_device *dev,
1057 struct netdev_phys_item_id *ppid)
1064 #endif /* _NET_DEVLINK_H_ */