devlink: Only pass packet trap group identifier in trap structure
authorIdo Schimmel <idosch@mellanox.com>
Sun, 22 Mar 2020 18:48:30 +0000 (20:48 +0200)
committerDavid S. Miller <davem@davemloft.net>
Tue, 24 Mar 2020 04:40:40 +0000 (21:40 -0700)
Packet trap groups are now explicitly registered by drivers and not
implicitly registered when the packet traps are registered. Therefore,
there is no need to encode entire group structure the trap is associated
with inside the trap structure.

Instead, only pass the group identifier. Refer to it as initial group
identifier, as future patches will allow user space to move traps
between groups.

Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
drivers/net/netdevsim/dev.c
include/net/devlink.h
net/core/devlink.c

index cf3891609d5c270270599dabcbf37683e57a08ee..727f6ef243df3b45fe1886923418b8867cdbad94 100644 (file)
@@ -132,23 +132,23 @@ static void mlxsw_sp_rx_exception_listener(struct sk_buff *skb, u8 local_port,
 
 #define MLXSW_SP_TRAP_DROP(_id, _group_id)                                   \
        DEVLINK_TRAP_GENERIC(DROP, DROP, _id,                                 \
-                            DEVLINK_TRAP_GROUP_GENERIC(_group_id),           \
+                            DEVLINK_TRAP_GROUP_GENERIC_ID_##_group_id,       \
                             MLXSW_SP_TRAP_METADATA)
 
 #define MLXSW_SP_TRAP_DROP_EXT(_id, _group_id, _metadata)                    \
        DEVLINK_TRAP_GENERIC(DROP, DROP, _id,                                 \
-                            DEVLINK_TRAP_GROUP_GENERIC(_group_id),           \
+                            DEVLINK_TRAP_GROUP_GENERIC_ID_##_group_id,       \
                             MLXSW_SP_TRAP_METADATA | (_metadata))
 
 #define MLXSW_SP_TRAP_DRIVER_DROP(_id, _group_id)                            \
        DEVLINK_TRAP_DRIVER(DROP, DROP, DEVLINK_MLXSW_TRAP_ID_##_id,          \
                            DEVLINK_MLXSW_TRAP_NAME_##_id,                    \
-                           DEVLINK_TRAP_GROUP_GENERIC(_group_id),            \
+                           DEVLINK_TRAP_GROUP_GENERIC_ID_##_group_id,        \
                            MLXSW_SP_TRAP_METADATA)
 
 #define MLXSW_SP_TRAP_EXCEPTION(_id, _group_id)                      \
        DEVLINK_TRAP_GENERIC(EXCEPTION, TRAP, _id,                            \
-                            DEVLINK_TRAP_GROUP_GENERIC(_group_id),           \
+                            DEVLINK_TRAP_GROUP_GENERIC_ID_##_group_id,       \
                             MLXSW_SP_TRAP_METADATA)
 
 #define MLXSW_SP_RXL_DISCARD(_id, _group_id)                                 \
index edeb61ddc8bcb5348874d694a775f1901c61ccf3..7bfd0622cef1595a7a83d7c315f37863ba879705 100644 (file)
@@ -381,20 +381,20 @@ enum {
 
 #define NSIM_TRAP_DROP(_id, _group_id)                                       \
        DEVLINK_TRAP_GENERIC(DROP, DROP, _id,                                 \
-                            DEVLINK_TRAP_GROUP_GENERIC(_group_id),           \
+                            DEVLINK_TRAP_GROUP_GENERIC_ID_##_group_id,       \
                             NSIM_TRAP_METADATA)
 #define NSIM_TRAP_DROP_EXT(_id, _group_id, _metadata)                        \
        DEVLINK_TRAP_GENERIC(DROP, DROP, _id,                                 \
-                            DEVLINK_TRAP_GROUP_GENERIC(_group_id),           \
+                            DEVLINK_TRAP_GROUP_GENERIC_ID_##_group_id,       \
                             NSIM_TRAP_METADATA | (_metadata))
 #define NSIM_TRAP_EXCEPTION(_id, _group_id)                                  \
        DEVLINK_TRAP_GENERIC(EXCEPTION, TRAP, _id,                            \
-                            DEVLINK_TRAP_GROUP_GENERIC(_group_id),           \
+                            DEVLINK_TRAP_GROUP_GENERIC_ID_##_group_id,       \
                             NSIM_TRAP_METADATA)
 #define NSIM_TRAP_DRIVER_EXCEPTION(_id, _group_id)                           \
        DEVLINK_TRAP_DRIVER(EXCEPTION, TRAP, NSIM_TRAP_ID_##_id,              \
                            NSIM_TRAP_NAME_##_id,                             \
-                           DEVLINK_TRAP_GROUP_GENERIC(_group_id),            \
+                           DEVLINK_TRAP_GROUP_GENERIC_ID_##_group_id,        \
                            NSIM_TRAP_METADATA)
 
 static const struct devlink_trap_group nsim_trap_groups_arr[] = {
index f8bdf43f694c97084940b64626ee8ae3cef9c246..37230e23b5b075e2790c2343e2d79bbc1f94fa97 100644 (file)
@@ -553,7 +553,7 @@ struct devlink_trap_group {
  * @generic: Whether the trap is generic or not.
  * @id: Trap identifier.
  * @name: Trap name.
- * @group: Immutable packet trap group attributes.
+ * @init_group_id: Initial group identifier.
  * @metadata_cap: Metadata types that can be provided by the trap.
  *
  * Describes immutable attributes of packet traps that drivers register with
@@ -565,7 +565,7 @@ struct devlink_trap {
        bool generic;
        u16 id;
        const char *name;
-       struct devlink_trap_group group;
+       u16 init_group_id;
        u32 metadata_cap;
 };
 
@@ -694,18 +694,19 @@ enum devlink_trap_group_generic_id {
 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_DROPS \
        "acl_drops"
 
-#define DEVLINK_TRAP_GENERIC(_type, _init_action, _id, _group, _metadata_cap) \
+#define DEVLINK_TRAP_GENERIC(_type, _init_action, _id, _group_id,            \
+                            _metadata_cap)                                   \
        {                                                                     \
                .type = DEVLINK_TRAP_TYPE_##_type,                            \
                .init_action = DEVLINK_TRAP_ACTION_##_init_action,            \
                .generic = true,                                              \
                .id = DEVLINK_TRAP_GENERIC_ID_##_id,                          \
                .name = DEVLINK_TRAP_GENERIC_NAME_##_id,                      \
-               .group = _group,                                              \
+               .init_group_id = _group_id,                                   \
                .metadata_cap = _metadata_cap,                                \
        }
 
-#define DEVLINK_TRAP_DRIVER(_type, _init_action, _id, _name, _group,         \
+#define DEVLINK_TRAP_DRIVER(_type, _init_action, _id, _name, _group_id,              \
                            _metadata_cap)                                    \
        {                                                                     \
                .type = DEVLINK_TRAP_TYPE_##_type,                            \
@@ -713,7 +714,7 @@ enum devlink_trap_group_generic_id {
                .generic = false,                                             \
                .id = _id,                                                    \
                .name = _name,                                                \
-               .group = _group,                                              \
+               .init_group_id = _group_id,                                   \
                .metadata_cap = _metadata_cap,                                \
        }
 
index a35285a48b02eb0a066a4e444e2c6e93650d13e0..73bb8fbe3393a1d92c7fccc3fee74330d0a9abb0 100644 (file)
@@ -5815,6 +5815,19 @@ devlink_trap_group_item_lookup(struct devlink *devlink, const char *name)
        return NULL;
 }
 
+static struct devlink_trap_group_item *
+devlink_trap_group_item_lookup_by_id(struct devlink *devlink, u16 id)
+{
+       struct devlink_trap_group_item *group_item;
+
+       list_for_each_entry(group_item, &devlink->trap_group_list, list) {
+               if (group_item->group->id == id)
+                       return group_item;
+       }
+
+       return NULL;
+}
+
 static struct devlink_trap_group_item *
 devlink_trap_group_item_get_from_info(struct devlink *devlink,
                                      struct genl_info *info)
@@ -5953,7 +5966,7 @@ __devlink_trap_group_action_set(struct devlink *devlink,
        int err;
 
        list_for_each_entry(trap_item, &devlink->trap_list, list) {
-               if (strcmp(trap_item->trap->group.name, group_name))
+               if (strcmp(trap_item->group_item->group->name, group_name))
                        continue;
                err = __devlink_trap_action_set(devlink, trap_item,
                                                trap_action, extack);
@@ -7864,7 +7877,7 @@ static int devlink_trap_driver_verify(const struct devlink_trap *trap)
 
 static int devlink_trap_verify(const struct devlink_trap *trap)
 {
-       if (!trap || !trap->name || !trap->group.name)
+       if (!trap || !trap->name)
                return -EINVAL;
 
        if (trap->generic)
@@ -7939,10 +7952,10 @@ static int
 devlink_trap_item_group_link(struct devlink *devlink,
                             struct devlink_trap_item *trap_item)
 {
-       const struct devlink_trap *trap = trap_item->trap;
+       u16 group_id = trap_item->trap->init_group_id;
        struct devlink_trap_group_item *group_item;
 
-       group_item = devlink_trap_group_item_lookup(devlink, trap->group.name);
+       group_item = devlink_trap_group_item_lookup_by_id(devlink, group_id);
        if (WARN_ON_ONCE(!group_item))
                return -EINVAL;