]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
nfp: bpf: use extack support to improve debugging
authorQuentin Monnet <quentin.monnet@netronome.com>
Sat, 20 Jan 2018 01:44:50 +0000 (17:44 -0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 22 Jan 2018 21:28:32 +0000 (16:28 -0500)
Use the recently added extack support for eBPF offload in the driver.

Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/netronome/nfp/bpf/main.c
drivers/net/ethernet/netronome/nfp/bpf/main.h
drivers/net/ethernet/netronome/nfp/bpf/offload.c

index b755c9164ab98312edaed3634496c1b533fdcaab..b3206855535a8210bd7bc8d1549db07d98536646 100644 (file)
@@ -70,7 +70,7 @@ nfp_bpf_xdp_offload(struct nfp_app *app, struct nfp_net *nn,
        if (prog && running && !xdp_running)
                return -EBUSY;
 
-       ret = nfp_net_bpf_offload(nn, prog, running);
+       ret = nfp_net_bpf_offload(nn, prog, running, extack);
        /* Stop offload if replace not possible */
        if (ret && prog)
                nfp_bpf_xdp_offload(app, nn, NULL, extack);
@@ -125,17 +125,31 @@ static int nfp_bpf_setup_tc_block_cb(enum tc_setup_type type,
        struct nfp_bpf_vnic *bv;
        int err;
 
-       if (type != TC_SETUP_CLSBPF ||
-           !tc_can_offload(nn->dp.netdev) ||
-           !nfp_net_ebpf_capable(nn) ||
-           cls_bpf->common.protocol != htons(ETH_P_ALL) ||
-           cls_bpf->common.chain_index)
+       if (type != TC_SETUP_CLSBPF) {
+               NL_SET_ERR_MSG_MOD(cls_bpf->common.extack,
+                                  "only offload of BPF classifiers supported");
+               return -EOPNOTSUPP;
+       }
+       if (!tc_can_offload_extack(nn->dp.netdev, cls_bpf->common.extack))
+               return -EOPNOTSUPP;
+       if (!nfp_net_ebpf_capable(nn)) {
+               NL_SET_ERR_MSG_MOD(cls_bpf->common.extack,
+                                  "NFP firmware does not support eBPF offload");
+               return -EOPNOTSUPP;
+       }
+       if (cls_bpf->common.protocol != htons(ETH_P_ALL)) {
+               NL_SET_ERR_MSG_MOD(cls_bpf->common.extack,
+                                  "only ETH_P_ALL supported as filter protocol");
+               return -EOPNOTSUPP;
+       }
+       if (cls_bpf->common.chain_index)
                return -EOPNOTSUPP;
 
        /* Only support TC direct action */
        if (!cls_bpf->exts_integrated ||
            tcf_exts_has_actions(cls_bpf->exts)) {
-               nn_err(nn, "only direct action with no legacy actions supported\n");
+               NL_SET_ERR_MSG_MOD(cls_bpf->common.extack,
+                                  "only direct action with no legacy actions supported");
                return -EOPNOTSUPP;
        }
 
@@ -152,7 +166,8 @@ static int nfp_bpf_setup_tc_block_cb(enum tc_setup_type type,
                        return 0;
        }
 
-       err = nfp_net_bpf_offload(nn, cls_bpf->prog, oldprog);
+       err = nfp_net_bpf_offload(nn, cls_bpf->prog, oldprog,
+                                 cls_bpf->common.extack);
        if (err)
                return err;
 
index c476bca15ba405cb3c8c771b546c2d54298ed982..424fe8338105ec5d056b837bef63e150343ac8a7 100644 (file)
@@ -335,7 +335,7 @@ struct nfp_net;
 int nfp_ndo_bpf(struct nfp_app *app, struct nfp_net *nn,
                struct netdev_bpf *bpf);
 int nfp_net_bpf_offload(struct nfp_net *nn, struct bpf_prog *prog,
-                       bool old_prog);
+                       bool old_prog, struct netlink_ext_ack *extack);
 
 struct nfp_insn_meta *
 nfp_bpf_goto_meta(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta,
index 1a357aacc444bc2f5bb0d5095863f44eca0157e1..0a7732385469564ca4870cee2c95ee0db7ef9eef 100644 (file)
@@ -281,7 +281,9 @@ int nfp_ndo_bpf(struct nfp_app *app, struct nfp_net *nn, struct netdev_bpf *bpf)
        }
 }
 
-static int nfp_net_bpf_load(struct nfp_net *nn, struct bpf_prog *prog)
+static int
+nfp_net_bpf_load(struct nfp_net *nn, struct bpf_prog *prog,
+                struct netlink_ext_ack *extack)
 {
        struct nfp_prog *nfp_prog = prog->aux->offload->dev_priv;
        unsigned int max_mtu;
@@ -291,7 +293,7 @@ static int nfp_net_bpf_load(struct nfp_net *nn, struct bpf_prog *prog)
 
        max_mtu = nn_readb(nn, NFP_NET_CFG_BPF_INL_MTU) * 64 - 32;
        if (max_mtu < nn->dp.netdev->mtu) {
-               nn_info(nn, "BPF offload not supported with MTU larger than HW packet split boundary\n");
+               NL_SET_ERR_MSG_MOD(extack, "BPF offload not supported with MTU larger than HW packet split boundary");
                return -EOPNOTSUPP;
        }
 
@@ -313,7 +315,8 @@ static int nfp_net_bpf_load(struct nfp_net *nn, struct bpf_prog *prog)
        /* Load up the JITed code */
        err = nfp_net_reconfig(nn, NFP_NET_CFG_UPDATE_BPF);
        if (err)
-               nn_err(nn, "FW command error while loading BPF: %d\n", err);
+               NL_SET_ERR_MSG_MOD(extack,
+                                  "FW command error while loading BPF");
 
        dma_unmap_single(nn->dp.dev, dma_addr, nfp_prog->prog_len * sizeof(u64),
                         DMA_TO_DEVICE);
@@ -322,7 +325,8 @@ static int nfp_net_bpf_load(struct nfp_net *nn, struct bpf_prog *prog)
        return err;
 }
 
-static void nfp_net_bpf_start(struct nfp_net *nn)
+static void
+nfp_net_bpf_start(struct nfp_net *nn, struct netlink_ext_ack *extack)
 {
        int err;
 
@@ -331,7 +335,8 @@ static void nfp_net_bpf_start(struct nfp_net *nn)
        nn_writel(nn, NFP_NET_CFG_CTRL, nn->dp.ctrl);
        err = nfp_net_reconfig(nn, NFP_NET_CFG_UPDATE_GEN);
        if (err)
-               nn_err(nn, "FW command error while enabling BPF: %d\n", err);
+               NL_SET_ERR_MSG_MOD(extack,
+                                  "FW command error while enabling BPF");
 }
 
 static int nfp_net_bpf_stop(struct nfp_net *nn)
@@ -346,7 +351,7 @@ static int nfp_net_bpf_stop(struct nfp_net *nn)
 }
 
 int nfp_net_bpf_offload(struct nfp_net *nn, struct bpf_prog *prog,
-                       bool old_prog)
+                       bool old_prog, struct netlink_ext_ack *extack)
 {
        int err;
 
@@ -364,7 +369,8 @@ int nfp_net_bpf_offload(struct nfp_net *nn, struct bpf_prog *prog,
 
                cap = nn_readb(nn, NFP_NET_CFG_BPF_CAP);
                if (!(cap & NFP_NET_BPF_CAP_RELO)) {
-                       nn_err(nn, "FW does not support live reload\n");
+                       NL_SET_ERR_MSG_MOD(extack,
+                                          "FW does not support live reload");
                        return -EBUSY;
                }
        }
@@ -376,12 +382,12 @@ int nfp_net_bpf_offload(struct nfp_net *nn, struct bpf_prog *prog,
        if (old_prog && !prog)
                return nfp_net_bpf_stop(nn);
 
-       err = nfp_net_bpf_load(nn, prog);
+       err = nfp_net_bpf_load(nn, prog, extack);
        if (err)
                return err;
 
        if (!old_prog)
-               nfp_net_bpf_start(nn);
+               nfp_net_bpf_start(nn, extack);
 
        return 0;
 }