Skip to content

Commit

Permalink
net: fec: add initial XDP support
Browse files Browse the repository at this point in the history
This patch adds the initial XDP support to Freescale driver. It supports
XDP_PASS, XDP_DROP and XDP_REDIRECT actions. Upcoming patches will add
support for XDP_TX and Zero Copy features.

This patch also optimizes the RX buffers by using the page pool, which
uses one frame per page for easy management. In the future, it can be
further improved to use two frames per page.

This patch has been tested with the sample apps of "xdpsock" and "xdp2" in
samples/bpf directory for both SKB and Native (XDP) mode. The following
are the testing result comparing with the XDP skb-mode.

 # xdpsock -i eth0
 sock0@eth0:0 rxdrop xdp-drv
                   pps            pkts           1.00
 rx                 198798         1040011
 tx                 0              0

 # xdpsock -S -i eth0         // skb-mode
 sock0@eth0:0 rxdrop xdp-skb
                    pps            pkts           1.00
 rx                 95638          717251
 tx                 0              0

 # xdp2 eth0
 proto 0:     475362 pkt/s
 proto 0:     475549 pkt/s
 proto 0:     475480 pkt/s
 proto 0:     143258 pkt/s

 # xdp2 -S eth0    // skb-mode
 proto 17:      56468 pkt/s
 proto 17:      71999 pkt/s
 proto 17:      72000 pkt/s
 proto 17:      71988 pkt/s

Signed-off-by: Shenwei Wang <shenwei.wang@nxp.com>
  • Loading branch information
Shenwei Wang authored and intel-lab-lkp committed Sep 28, 2022
1 parent b9a5cbf commit 0ef976d
Show file tree
Hide file tree
Showing 2 changed files with 393 additions and 55 deletions.
34 changes: 32 additions & 2 deletions drivers/net/ethernet/freescale/fec.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,10 @@ struct bufdesc_ex {
* the skbuffer directly.
*/

#define FEC_ENET_XDP_HEADROOM (512) /* XDP_PACKET_HEADROOM + NET_IP_ALIGN) */

#define FEC_ENET_RX_PAGES 256
#define FEC_ENET_RX_FRSIZE 2048
#define FEC_ENET_RX_FRSIZE (PAGE_SIZE - FEC_ENET_XDP_HEADROOM)
#define FEC_ENET_RX_FRPPG (PAGE_SIZE / FEC_ENET_RX_FRSIZE)
#define RX_RING_SIZE (FEC_ENET_RX_FRPPG * FEC_ENET_RX_PAGES)
#define FEC_ENET_TX_FRSIZE 2048
Expand Down Expand Up @@ -517,6 +519,22 @@ struct bufdesc_prop {
unsigned char dsize_log2;
};

struct fec_enet_priv_txrx_info {
int offset;
struct page *page;
struct sk_buff *skb;
};

struct fec_enet_xdp_stats {
u64 xdp_pass;
u64 xdp_drop;
u64 xdp_xmit;
u64 xdp_redirect;
u64 xdp_xmit_err;
u64 xdp_tx;
u64 xdp_tx_err;
};

struct fec_enet_priv_tx_q {
struct bufdesc_prop bd;
unsigned char *tx_bounce[TX_RING_SIZE];
Expand All @@ -532,7 +550,15 @@ struct fec_enet_priv_tx_q {

struct fec_enet_priv_rx_q {
struct bufdesc_prop bd;
struct sk_buff *rx_skbuff[RX_RING_SIZE];
struct fec_enet_priv_txrx_info rx_skb_info[RX_RING_SIZE];

/* page_pool */
struct page_pool *page_pool;
struct xdp_rxq_info xdp_rxq;
struct fec_enet_xdp_stats stats;

/* rx queue number, in the range 0-7 */
u8 id;
};

struct fec_stop_mode_gpr {
Expand Down Expand Up @@ -644,6 +670,10 @@ struct fec_enet_private {

struct imx_sc_ipc *ipc_handle;

/* XDP BPF Program */
unsigned long *af_xdp_zc_qps;
struct bpf_prog *xdp_prog;

u64 ethtool_stats[];
};

Expand Down
Loading

0 comments on commit 0ef976d

Please sign in to comment.