diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c b/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c
index 8a6703afca38..ae2585508690 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c
@@ -822,7 +822,9 @@ struct net_device *fbnic_netdev_alloc(struct fbnic_dev *fbd)
netdev->hw_enc_features |= netdev->features;
netdev->features |= NETIF_F_NTUPLE;
- netdev->xdp_features = NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_RX_SG;
+ netdev->xdp_features = NETDEV_XDP_ACT_BASIC |
+ NETDEV_XDP_ACT_REDIRECT |
+ NETDEV_XDP_ACT_RX_SG;
netdev->min_mtu = IPV6_MIN_MTU;
netdev->max_mtu = FBNIC_MAX_JUMBO_FRAME_SIZE - ETH_HLEN;
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c
index 0bcee152d47c..51d573c9c5b8 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c
@@ -22,6 +22,8 @@ enum {
FBNIC_XDP_PASS = 0,
FBNIC_XDP_CONSUME,
FBNIC_XDP_TX,
+ FBNIC_XDP_REDIRECT,
+ FBNIC_XDP_REDIRECT_ERR,
FBNIC_XDP_LEN_ERR,
};
@@ -1211,6 +1213,10 @@ static struct sk_buff *fbnic_run_xdp(struct fbnic_napi_vector *nv,
return fbnic_build_skb(nv, pkt);
case XDP_TX:
return ERR_PTR(fbnic_pkt_tx(nv, pkt));
+ case XDP_REDIRECT:
+ if (xdp_do_redirect(nv->napi.dev, &pkt->buff, xdp_prog))
+ return ERR_PTR(-FBNIC_XDP_REDIRECT_ERR);
+ return ERR_PTR(-FBNIC_XDP_REDIRECT);
default:
bpf_warn_invalid_xdp_action(nv->napi.dev, xdp_prog, act);
fallthrough;
@@ -1280,6 +1286,7 @@ static int fbnic_clean_rcq(struct fbnic_napi_vector *nv,
struct fbnic_ring *rcq = &qt->cmpl;
struct fbnic_pkt_buff *pkt;
__le64 *raw_rcd, done;
+ bool redirect = false;
u32 head = rcq->head;
done = (head & (rcq->size_mask + 1)) ? cpu_to_le64(FBNIC_RCD_DONE) : 0;
@@ -1336,6 +1343,16 @@ static int fbnic_clean_rcq(struct fbnic_napi_vector *nv,
pkt_tail = nv->qt[0].sub1.tail;
} else if (PTR_ERR(skb) == -FBNIC_XDP_CONSUME) {
fbnic_put_pkt_buff(qt, pkt, 1);
+ } else if (skb == ERR_PTR(-FBNIC_XDP_REDIRECT)) {
+ redirect = true;
+ } else if (skb == ERR_PTR(-FBNIC_XDP_REDIRECT_ERR)) {
+ /* A broadcast may queue frames, then fail. XDP
+ * consumed the packet, so it also counts as
+ * received.
+ */
+ redirect = true;
+ dropped++;
+ fbnic_put_pkt_buff(qt, pkt, 1);
} else {
if (!skb)
alloc_failed++;@@ -1377,6 +1394,8 @@ static int fbnic_clean_rcq(struct fbnic_napi_vector *nv,
if (pkt_tail >= 0)
fbnic_pkt_commit_tail(nv, pkt_tail);
+ if (redirect)
+ xdp_do_flush();
/* Unmap and free processed buffers */
if (head0 >= 0)
--
2.56.0