Skip to content

Commit a1e031f

Browse files
camelia-groza-NXPkuba-moo
authored andcommitted
dpaa_eth: add XDP_REDIRECT support
After transmission, the frame is returned on confirmation queues for cleanup. For this, store a backpointer to the xdp_frame in the private reserved area at the start of the TX buffer. No TX batching support is implemented at this time. Acked-by: Madalin Bucur <[email protected]> Signed-off-by: Camelia Groza <[email protected]> Reviewed-by: Maciej Fijalkowski <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent d57e57d commit a1e031f

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

drivers/net/ethernet/freescale/dpaa/dpaa_eth.c

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2305,8 +2305,11 @@ static int dpaa_eth_poll(struct napi_struct *napi, int budget)
23052305
{
23062306
struct dpaa_napi_portal *np =
23072307
container_of(napi, struct dpaa_napi_portal, napi);
2308+
int cleaned;
23082309

2309-
int cleaned = qman_p_poll_dqrr(np->p, budget);
2310+
np->xdp_act = 0;
2311+
2312+
cleaned = qman_p_poll_dqrr(np->p, budget);
23102313

23112314
if (cleaned < budget) {
23122315
napi_complete_done(napi, cleaned);
@@ -2315,6 +2318,9 @@ static int dpaa_eth_poll(struct napi_struct *napi, int budget)
23152318
qman_p_irqsource_add(np->p, QM_PIRQ_DQRI);
23162319
}
23172320

2321+
if (np->xdp_act & XDP_REDIRECT)
2322+
xdp_do_flush();
2323+
23182324
return cleaned;
23192325
}
23202326

@@ -2457,6 +2463,7 @@ static u32 dpaa_run_xdp(struct dpaa_priv *priv, struct qm_fd *fd, void *vaddr,
24572463
struct xdp_frame *xdpf;
24582464
struct xdp_buff xdp;
24592465
u32 xdp_act;
2466+
int err;
24602467

24612468
rcu_read_lock();
24622469

@@ -2497,6 +2504,17 @@ static u32 dpaa_run_xdp(struct dpaa_priv *priv, struct qm_fd *fd, void *vaddr,
24972504
if (dpaa_xdp_xmit_frame(priv->net_dev, xdpf))
24982505
xdp_return_frame_rx_napi(xdpf);
24992506

2507+
break;
2508+
case XDP_REDIRECT:
2509+
/* Allow redirect to use the full headroom */
2510+
xdp.data_hard_start = vaddr;
2511+
xdp.frame_sz = DPAA_BP_RAW_SIZE;
2512+
2513+
err = xdp_do_redirect(priv->net_dev, &xdp, xdp_prog);
2514+
if (err) {
2515+
trace_xdp_exception(priv->net_dev, xdp_prog, xdp_act);
2516+
free_pages((unsigned long)vaddr, 0);
2517+
}
25002518
break;
25012519
default:
25022520
bpf_warn_invalid_xdp_action(xdp_act);
@@ -2527,6 +2545,7 @@ static enum qman_cb_dqrr_result rx_default_dqrr(struct qman_portal *portal,
25272545
struct dpaa_percpu_priv *percpu_priv;
25282546
const struct qm_fd *fd = &dq->fd;
25292547
dma_addr_t addr = qm_fd_addr(fd);
2548+
struct dpaa_napi_portal *np;
25302549
enum qm_fd_format fd_format;
25312550
struct net_device *net_dev;
25322551
u32 fd_status, hash_offset;
@@ -2541,6 +2560,7 @@ static enum qman_cb_dqrr_result rx_default_dqrr(struct qman_portal *portal,
25412560
u32 hash;
25422561
u64 ns;
25432562

2563+
np = container_of(&portal, struct dpaa_napi_portal, p);
25442564
dpaa_fq = container_of(fq, struct dpaa_fq, fq_base);
25452565
fd_status = be32_to_cpu(fd->status);
25462566
fd_format = qm_fd_get_format(fd);
@@ -2614,6 +2634,7 @@ static enum qman_cb_dqrr_result rx_default_dqrr(struct qman_portal *portal,
26142634
if (likely(fd_format == qm_fd_contig)) {
26152635
xdp_act = dpaa_run_xdp(priv, (struct qm_fd *)fd, vaddr,
26162636
dpaa_fq, &xdp_meta_len);
2637+
np->xdp_act |= xdp_act;
26172638
if (xdp_act != XDP_PASS) {
26182639
percpu_stats->rx_packets++;
26192640
percpu_stats->rx_bytes += qm_fd_get_length(fd);
@@ -2946,6 +2967,30 @@ static int dpaa_xdp(struct net_device *net_dev, struct netdev_bpf *xdp)
29462967
}
29472968
}
29482969

2970+
static int dpaa_xdp_xmit(struct net_device *net_dev, int n,
2971+
struct xdp_frame **frames, u32 flags)
2972+
{
2973+
struct xdp_frame *xdpf;
2974+
int i, err, drops = 0;
2975+
2976+
if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK))
2977+
return -EINVAL;
2978+
2979+
if (!netif_running(net_dev))
2980+
return -ENETDOWN;
2981+
2982+
for (i = 0; i < n; i++) {
2983+
xdpf = frames[i];
2984+
err = dpaa_xdp_xmit_frame(net_dev, xdpf);
2985+
if (err) {
2986+
xdp_return_frame_rx_napi(xdpf);
2987+
drops++;
2988+
}
2989+
}
2990+
2991+
return n - drops;
2992+
}
2993+
29492994
static int dpaa_ts_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
29502995
{
29512996
struct dpaa_priv *priv = netdev_priv(dev);
@@ -3014,6 +3059,7 @@ static const struct net_device_ops dpaa_ops = {
30143059
.ndo_setup_tc = dpaa_setup_tc,
30153060
.ndo_change_mtu = dpaa_change_mtu,
30163061
.ndo_bpf = dpaa_xdp,
3062+
.ndo_xdp_xmit = dpaa_xdp_xmit,
30173063
};
30183064

30193065
static int dpaa_napi_add(struct net_device *net_dev)

drivers/net/ethernet/freescale/dpaa/dpaa_eth.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ struct dpaa_napi_portal {
127127
struct napi_struct napi;
128128
struct qman_portal *p;
129129
bool down;
130+
int xdp_act;
130131
};
131132

132133
struct dpaa_percpu_priv {

0 commit comments

Comments
 (0)