devlink: add .trap_group_action_set() callback
authorIoana Ciornei <ioana.ciornei@nxp.com>
Thu, 1 Oct 2020 15:11:46 +0000 (18:11 +0300)
committerDavid S. Miller <davem@davemloft.net>
Fri, 2 Oct 2020 23:31:56 +0000 (16:31 -0700)
Add a new devlink callback, .trap_group_action_set(), which can be used
by device drivers which do not support controlling the action (drop,
trap) on each trap but rather on the entire group trap.
If this new callback is populated, it will take precedence over the
.trap_action_set() callback when the user requests a change of all the
traps in a group.

Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/devlink.h
net/core/devlink.c

index 1f5004a5c9f9897b2b5cb86682dd1c924790e162..89ede1ce3a3a3431292cff484fbe6ebd727749d1 100644 (file)
@@ -1242,6 +1242,16 @@ struct devlink_ops {
                              const struct devlink_trap_group *group,
                              const struct devlink_trap_policer *policer,
                              struct netlink_ext_ack *extack);
+       /**
+        * @trap_group_action_set: Trap group action set function.
+        *
+        * If this callback is populated, it will take precedence over looping
+        * over all traps in a group and calling .trap_action_set().
+        */
+       int (*trap_group_action_set)(struct devlink *devlink,
+                                    const struct devlink_trap_group *group,
+                                    enum devlink_trap_action action,
+                                    struct netlink_ext_ack *extack);
        /**
         * @trap_policer_init: Trap policer initialization function.
         *
index 523bd8686866bf9a315f3b934a05e2b0029c9987..2a95f7f27a544da340f6d5c47f8743729348e50b 100644 (file)
@@ -6720,6 +6720,24 @@ __devlink_trap_group_action_set(struct devlink *devlink,
        struct devlink_trap_item *trap_item;
        int err;
 
+       if (devlink->ops->trap_group_action_set) {
+               err = devlink->ops->trap_group_action_set(devlink, group_item->group,
+                                                         trap_action, extack);
+               if (err)
+                       return err;
+
+               list_for_each_entry(trap_item, &devlink->trap_list, list) {
+                       if (strcmp(trap_item->group_item->group->name, group_name))
+                               continue;
+                       if (trap_item->action != trap_action &&
+                           trap_item->trap->type != DEVLINK_TRAP_TYPE_DROP)
+                               continue;
+                       trap_item->action = trap_action;
+               }
+
+               return 0;
+       }
+
        list_for_each_entry(trap_item, &devlink->trap_list, list) {
                if (strcmp(trap_item->group_item->group->name, group_name))
                        continue;