Skip to content

Commit 6453073

Browse files
jrfastabdavem330
authored andcommitted
ixgbe: add initial support for xdp redirect
There are optimizations we can add after the basic feature is enabled. But, for now keep the patch simple. Signed-off-by: John Fastabend <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Acked-by: Jesper Dangaard Brouer <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6103aa9 commit 6453073

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c

+40-1
Original file line numberDiff line numberDiff line change
@@ -2214,7 +2214,7 @@ static struct sk_buff *ixgbe_run_xdp(struct ixgbe_adapter *adapter,
22142214
struct ixgbe_ring *rx_ring,
22152215
struct xdp_buff *xdp)
22162216
{
2217-
int result = IXGBE_XDP_PASS;
2217+
int err, result = IXGBE_XDP_PASS;
22182218
struct bpf_prog *xdp_prog;
22192219
u32 act;
22202220

@@ -2231,6 +2231,13 @@ static struct sk_buff *ixgbe_run_xdp(struct ixgbe_adapter *adapter,
22312231
case XDP_TX:
22322232
result = ixgbe_xmit_xdp_ring(adapter, xdp);
22332233
break;
2234+
case XDP_REDIRECT:
2235+
err = xdp_do_redirect(adapter->netdev, xdp);
2236+
if (!err)
2237+
result = IXGBE_XDP_TX;
2238+
else
2239+
result = IXGBE_XDP_CONSUMED;
2240+
break;
22342241
default:
22352242
bpf_warn_invalid_xdp_action(act);
22362243
/* fallthrough */
@@ -9823,6 +9830,37 @@ static int ixgbe_xdp(struct net_device *dev, struct netdev_xdp *xdp)
98239830
}
98249831
}
98259832

9833+
static int ixgbe_xdp_xmit(struct net_device *dev, struct xdp_buff *xdp)
9834+
{
9835+
struct ixgbe_adapter *adapter = netdev_priv(dev);
9836+
struct ixgbe_ring *ring;
9837+
int err;
9838+
9839+
if (unlikely(test_bit(__IXGBE_DOWN, &adapter->state)))
9840+
return -EINVAL;
9841+
9842+
/* During program transitions its possible adapter->xdp_prog is assigned
9843+
* but ring has not been configured yet. In this case simply abort xmit.
9844+
*/
9845+
ring = adapter->xdp_prog ? adapter->xdp_ring[smp_processor_id()] : NULL;
9846+
if (unlikely(!ring))
9847+
return -EINVAL;
9848+
9849+
err = ixgbe_xmit_xdp_ring(adapter, xdp);
9850+
if (err != IXGBE_XDP_TX)
9851+
return -ENOMEM;
9852+
9853+
/* Force memory writes to complete before letting h/w know there
9854+
* are new descriptors to fetch.
9855+
*/
9856+
wmb();
9857+
9858+
ring = adapter->xdp_ring[smp_processor_id()];
9859+
writel(ring->next_to_use, ring->tail);
9860+
9861+
return 0;
9862+
}
9863+
98269864
static const struct net_device_ops ixgbe_netdev_ops = {
98279865
.ndo_open = ixgbe_open,
98289866
.ndo_stop = ixgbe_close,
@@ -9869,6 +9907,7 @@ static const struct net_device_ops ixgbe_netdev_ops = {
98699907
.ndo_udp_tunnel_del = ixgbe_del_udp_tunnel_port,
98709908
.ndo_features_check = ixgbe_features_check,
98719909
.ndo_xdp = ixgbe_xdp,
9910+
.ndo_xdp_xmit = ixgbe_xdp_xmit,
98729911
};
98739912

98749913
/**

0 commit comments

Comments
 (0)