diff options
Diffstat (limited to 'include/net/devlink.h')
-rw-r--r-- | include/net/devlink.h | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/include/net/devlink.h b/include/net/devlink.h index 451268f64880..7f43c48f54cd 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/netdevice.h> | 14 | #include <linux/netdevice.h> |
15 | #include <linux/spinlock.h> | 15 | #include <linux/spinlock.h> |
16 | #include <linux/workqueue.h> | 16 | #include <linux/workqueue.h> |
17 | #include <linux/refcount.h> | ||
17 | #include <net/net_namespace.h> | 18 | #include <net/net_namespace.h> |
18 | #include <uapi/linux/devlink.h> | 19 | #include <uapi/linux/devlink.h> |
19 | 20 | ||
@@ -31,6 +32,8 @@ struct devlink { | |||
31 | struct list_head reporter_list; | 32 | struct list_head reporter_list; |
32 | struct mutex reporters_lock; /* protects reporter_list */ | 33 | struct mutex reporters_lock; /* protects reporter_list */ |
33 | struct devlink_dpipe_headers *dpipe_headers; | 34 | struct devlink_dpipe_headers *dpipe_headers; |
35 | struct list_head trap_list; | ||
36 | struct list_head trap_group_list; | ||
34 | const struct devlink_ops *ops; | 37 | const struct devlink_ops *ops; |
35 | struct device *dev; | 38 | struct device *dev; |
36 | possible_net_t _net; | 39 | possible_net_t _net; |
@@ -497,6 +500,135 @@ struct devlink_health_reporter_ops { | |||
497 | struct devlink_fmsg *fmsg); | 500 | struct devlink_fmsg *fmsg); |
498 | }; | 501 | }; |
499 | 502 | ||
503 | /** | ||
504 | * struct devlink_trap_group - Immutable packet trap group attributes. | ||
505 | * @name: Trap group name. | ||
506 | * @id: Trap group identifier. | ||
507 | * @generic: Whether the trap group is generic or not. | ||
508 | * | ||
509 | * Describes immutable attributes of packet trap groups that drivers register | ||
510 | * with devlink. | ||
511 | */ | ||
512 | struct devlink_trap_group { | ||
513 | const char *name; | ||
514 | u16 id; | ||
515 | bool generic; | ||
516 | }; | ||
517 | |||
518 | #define DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT BIT(0) | ||
519 | |||
520 | /** | ||
521 | * struct devlink_trap - Immutable packet trap attributes. | ||
522 | * @type: Trap type. | ||
523 | * @init_action: Initial trap action. | ||
524 | * @generic: Whether the trap is generic or not. | ||
525 | * @id: Trap identifier. | ||
526 | * @name: Trap name. | ||
527 | * @group: Immutable packet trap group attributes. | ||
528 | * @metadata_cap: Metadata types that can be provided by the trap. | ||
529 | * | ||
530 | * Describes immutable attributes of packet traps that drivers register with | ||
531 | * devlink. | ||
532 | */ | ||
533 | struct devlink_trap { | ||
534 | enum devlink_trap_type type; | ||
535 | enum devlink_trap_action init_action; | ||
536 | bool generic; | ||
537 | u16 id; | ||
538 | const char *name; | ||
539 | struct devlink_trap_group group; | ||
540 | u32 metadata_cap; | ||
541 | }; | ||
542 | |||
543 | /* All traps must be documented in | ||
544 | * Documentation/networking/devlink-trap.rst | ||
545 | */ | ||
546 | enum devlink_trap_generic_id { | ||
547 | DEVLINK_TRAP_GENERIC_ID_SMAC_MC, | ||
548 | DEVLINK_TRAP_GENERIC_ID_VLAN_TAG_MISMATCH, | ||
549 | DEVLINK_TRAP_GENERIC_ID_INGRESS_VLAN_FILTER, | ||
550 | DEVLINK_TRAP_GENERIC_ID_INGRESS_STP_FILTER, | ||
551 | DEVLINK_TRAP_GENERIC_ID_EMPTY_TX_LIST, | ||
552 | DEVLINK_TRAP_GENERIC_ID_PORT_LOOPBACK_FILTER, | ||
553 | DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_ROUTE, | ||
554 | DEVLINK_TRAP_GENERIC_ID_TTL_ERROR, | ||
555 | DEVLINK_TRAP_GENERIC_ID_TAIL_DROP, | ||
556 | |||
557 | /* Add new generic trap IDs above */ | ||
558 | __DEVLINK_TRAP_GENERIC_ID_MAX, | ||
559 | DEVLINK_TRAP_GENERIC_ID_MAX = __DEVLINK_TRAP_GENERIC_ID_MAX - 1, | ||
560 | }; | ||
561 | |||
562 | /* All trap groups must be documented in | ||
563 | * Documentation/networking/devlink-trap.rst | ||
564 | */ | ||
565 | enum devlink_trap_group_generic_id { | ||
566 | DEVLINK_TRAP_GROUP_GENERIC_ID_L2_DROPS, | ||
567 | DEVLINK_TRAP_GROUP_GENERIC_ID_L3_DROPS, | ||
568 | DEVLINK_TRAP_GROUP_GENERIC_ID_BUFFER_DROPS, | ||
569 | |||
570 | /* Add new generic trap group IDs above */ | ||
571 | __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX, | ||
572 | DEVLINK_TRAP_GROUP_GENERIC_ID_MAX = | ||
573 | __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX - 1, | ||
574 | }; | ||
575 | |||
576 | #define DEVLINK_TRAP_GENERIC_NAME_SMAC_MC \ | ||
577 | "source_mac_is_multicast" | ||
578 | #define DEVLINK_TRAP_GENERIC_NAME_VLAN_TAG_MISMATCH \ | ||
579 | "vlan_tag_mismatch" | ||
580 | #define DEVLINK_TRAP_GENERIC_NAME_INGRESS_VLAN_FILTER \ | ||
581 | "ingress_vlan_filter" | ||
582 | #define DEVLINK_TRAP_GENERIC_NAME_INGRESS_STP_FILTER \ | ||
583 | "ingress_spanning_tree_filter" | ||
584 | #define DEVLINK_TRAP_GENERIC_NAME_EMPTY_TX_LIST \ | ||
585 | "port_list_is_empty" | ||
586 | #define DEVLINK_TRAP_GENERIC_NAME_PORT_LOOPBACK_FILTER \ | ||
587 | "port_loopback_filter" | ||
588 | #define DEVLINK_TRAP_GENERIC_NAME_BLACKHOLE_ROUTE \ | ||
589 | "blackhole_route" | ||
590 | #define DEVLINK_TRAP_GENERIC_NAME_TTL_ERROR \ | ||
591 | "ttl_value_is_too_small" | ||
592 | #define DEVLINK_TRAP_GENERIC_NAME_TAIL_DROP \ | ||
593 | "tail_drop" | ||
594 | |||
595 | #define DEVLINK_TRAP_GROUP_GENERIC_NAME_L2_DROPS \ | ||
596 | "l2_drops" | ||
597 | #define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_DROPS \ | ||
598 | "l3_drops" | ||
599 | #define DEVLINK_TRAP_GROUP_GENERIC_NAME_BUFFER_DROPS \ | ||
600 | "buffer_drops" | ||
601 | |||
602 | #define DEVLINK_TRAP_GENERIC(_type, _init_action, _id, _group, _metadata_cap) \ | ||
603 | { \ | ||
604 | .type = DEVLINK_TRAP_TYPE_##_type, \ | ||
605 | .init_action = DEVLINK_TRAP_ACTION_##_init_action, \ | ||
606 | .generic = true, \ | ||
607 | .id = DEVLINK_TRAP_GENERIC_ID_##_id, \ | ||
608 | .name = DEVLINK_TRAP_GENERIC_NAME_##_id, \ | ||
609 | .group = _group, \ | ||
610 | .metadata_cap = _metadata_cap, \ | ||
611 | } | ||
612 | |||
613 | #define DEVLINK_TRAP_DRIVER(_type, _init_action, _id, _name, _group, \ | ||
614 | _metadata_cap) \ | ||
615 | { \ | ||
616 | .type = DEVLINK_TRAP_TYPE_##_type, \ | ||
617 | .init_action = DEVLINK_TRAP_ACTION_##_init_action, \ | ||
618 | .generic = false, \ | ||
619 | .id = _id, \ | ||
620 | .name = _name, \ | ||
621 | .group = _group, \ | ||
622 | .metadata_cap = _metadata_cap, \ | ||
623 | } | ||
624 | |||
625 | #define DEVLINK_TRAP_GROUP_GENERIC(_id) \ | ||
626 | { \ | ||
627 | .name = DEVLINK_TRAP_GROUP_GENERIC_NAME_##_id, \ | ||
628 | .id = DEVLINK_TRAP_GROUP_GENERIC_ID_##_id, \ | ||
629 | .generic = true, \ | ||
630 | } | ||
631 | |||
500 | struct devlink_ops { | 632 | struct devlink_ops { |
501 | int (*reload)(struct devlink *devlink, struct netlink_ext_ack *extack); | 633 | int (*reload)(struct devlink *devlink, struct netlink_ext_ack *extack); |
502 | int (*port_type_set)(struct devlink_port *devlink_port, | 634 | int (*port_type_set)(struct devlink_port *devlink_port, |
@@ -558,6 +690,38 @@ struct devlink_ops { | |||
558 | int (*flash_update)(struct devlink *devlink, const char *file_name, | 690 | int (*flash_update)(struct devlink *devlink, const char *file_name, |
559 | const char *component, | 691 | const char *component, |
560 | struct netlink_ext_ack *extack); | 692 | struct netlink_ext_ack *extack); |
693 | /** | ||
694 | * @trap_init: Trap initialization function. | ||
695 | * | ||
696 | * Should be used by device drivers to initialize the trap in the | ||
697 | * underlying device. Drivers should also store the provided trap | ||
698 | * context, so that they could efficiently pass it to | ||
699 | * devlink_trap_report() when the trap is triggered. | ||
700 | */ | ||
701 | int (*trap_init)(struct devlink *devlink, | ||
702 | const struct devlink_trap *trap, void *trap_ctx); | ||
703 | /** | ||
704 | * @trap_fini: Trap de-initialization function. | ||
705 | * | ||
706 | * Should be used by device drivers to de-initialize the trap in the | ||
707 | * underlying device. | ||
708 | */ | ||
709 | void (*trap_fini)(struct devlink *devlink, | ||
710 | const struct devlink_trap *trap, void *trap_ctx); | ||
711 | /** | ||
712 | * @trap_action_set: Trap action set function. | ||
713 | */ | ||
714 | int (*trap_action_set)(struct devlink *devlink, | ||
715 | const struct devlink_trap *trap, | ||
716 | enum devlink_trap_action action); | ||
717 | /** | ||
718 | * @trap_group_init: Trap group initialization function. | ||
719 | * | ||
720 | * Should be used by device drivers to initialize the trap group in the | ||
721 | * underlying device. | ||
722 | */ | ||
723 | int (*trap_group_init)(struct devlink *devlink, | ||
724 | const struct devlink_trap_group *group); | ||
561 | }; | 725 | }; |
562 | 726 | ||
563 | static inline void *devlink_priv(struct devlink *devlink) | 727 | static inline void *devlink_priv(struct devlink *devlink) |
@@ -774,6 +938,17 @@ void devlink_flash_update_status_notify(struct devlink *devlink, | |||
774 | unsigned long done, | 938 | unsigned long done, |
775 | unsigned long total); | 939 | unsigned long total); |
776 | 940 | ||
941 | int devlink_traps_register(struct devlink *devlink, | ||
942 | const struct devlink_trap *traps, | ||
943 | size_t traps_count, void *priv); | ||
944 | void devlink_traps_unregister(struct devlink *devlink, | ||
945 | const struct devlink_trap *traps, | ||
946 | size_t traps_count); | ||
947 | void devlink_trap_report(struct devlink *devlink, | ||
948 | struct sk_buff *skb, void *trap_ctx, | ||
949 | struct devlink_port *in_devlink_port); | ||
950 | void *devlink_trap_ctx_priv(void *trap_ctx); | ||
951 | |||
777 | #if IS_ENABLED(CONFIG_NET_DEVLINK) | 952 | #if IS_ENABLED(CONFIG_NET_DEVLINK) |
778 | 953 | ||
779 | void devlink_compat_running_version(struct net_device *dev, | 954 | void devlink_compat_running_version(struct net_device *dev, |