xdp: add HW offload mode flag for installing programs
authorJakub Kicinski <jakub.kicinski@netronome.com>
Thu, 22 Jun 2017 01:25:04 +0000 (18:25 -0700)
committerDavid S. Miller <davem@davemloft.net>
Fri, 23 Jun 2017 17:42:19 +0000 (13:42 -0400)
Add an installation-time flag for requesting that the program
be installed only if it can be offloaded to HW.

Internally new command for ndo_xdp is added, this way we avoid
putting checks into drivers since they all return -EINVAL on
an unknown command.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/netdevice.h
include/uapi/linux/if_link.h
net/core/dev.c
net/core/rtnetlink.c

index b194817631ded71ce77e84c0127b73878fd3cea4..a838591aad28616d851d52b67436cc4c167d5ea2 100644 (file)
@@ -807,6 +807,7 @@ enum xdp_netdev_command {
         * when it is no longer used.
         */
        XDP_SETUP_PROG,
+       XDP_SETUP_PROG_HW,
        /* Check if a bpf program is set on the device.  The callee should
         * return true if a program is currently attached and running.
         */
index dd88375a6580268fe996282bbfd4f5e7a3c4b109..ce777ec88e1eccaf37dcf807804cb340c8c2b72d 100644 (file)
@@ -891,9 +891,12 @@ enum {
 #define XDP_FLAGS_UPDATE_IF_NOEXIST    (1U << 0)
 #define XDP_FLAGS_SKB_MODE             (1U << 1)
 #define XDP_FLAGS_DRV_MODE             (1U << 2)
+#define XDP_FLAGS_HW_MODE              (1U << 3)
+#define XDP_FLAGS_MODES                        (XDP_FLAGS_SKB_MODE | \
+                                        XDP_FLAGS_DRV_MODE | \
+                                        XDP_FLAGS_HW_MODE)
 #define XDP_FLAGS_MASK                 (XDP_FLAGS_UPDATE_IF_NOEXIST | \
-                                        XDP_FLAGS_SKB_MODE | \
-                                        XDP_FLAGS_DRV_MODE)
+                                        XDP_FLAGS_MODES)
 
 /* These are stored into IFLA_XDP_ATTACHED on dump. */
 enum {
index 09f9e99f4a3ee6df6a7e44f01c28a5dce806402b..cd885e9e336378845239464407f842a67b9f9308 100644 (file)
@@ -6957,7 +6957,10 @@ static int dev_xdp_install(struct net_device *dev, xdp_op_t xdp_op,
        struct netdev_xdp xdp;
 
        memset(&xdp, 0, sizeof(xdp));
-       xdp.command = XDP_SETUP_PROG;
+       if (flags & XDP_FLAGS_HW_MODE)
+               xdp.command = XDP_SETUP_PROG_HW;
+       else
+               xdp.command = XDP_SETUP_PROG;
        xdp.extack = extack;
        xdp.flags = flags;
        xdp.prog = prog;
@@ -6985,7 +6988,7 @@ int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack,
        ASSERT_RTNL();
 
        xdp_op = xdp_chk = ops->ndo_xdp;
-       if (!xdp_op && (flags & XDP_FLAGS_DRV_MODE))
+       if (!xdp_op && (flags & (XDP_FLAGS_DRV_MODE | XDP_FLAGS_HW_MODE)))
                return -EOPNOTSUPP;
        if (!xdp_op || (flags & XDP_FLAGS_SKB_MODE))
                xdp_op = generic_xdp_install;
index 8da89c1136e5026c4a3953508da4b2765be2844c..a5bedd03a63ed094ab65091779a91acd9cea37c4 100644 (file)
@@ -16,6 +16,7 @@
  *     Vitaly E. Lavrov                RTA_OK arithmetics was wrong.
  */
 
+#include <linux/bitops.h>
 #include <linux/errno.h>
 #include <linux/module.h>
 #include <linux/types.h>
@@ -2253,8 +2254,7 @@ static int do_setlink(const struct sk_buff *skb,
                                err = -EINVAL;
                                goto errout;
                        }
-                       if ((xdp_flags & XDP_FLAGS_SKB_MODE) &&
-                           (xdp_flags & XDP_FLAGS_DRV_MODE)) {
+                       if (hweight32(xdp_flags & XDP_FLAGS_MODES) > 1) {
                                err = -EINVAL;
                                goto errout;
                        }