Skip to content

Commit

Permalink
Merge branch 'bnxt_en-XDP_REDIRECT'
Browse files Browse the repository at this point in the history
Michael Chan says:

====================
bnxt_en: Add XDP_REDIRECT support.

This patch series adds XDP_REDIRECT support by Andy Gospodarek.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Jul 8, 2019
2 parents aa6be2b + 322b87c commit 107d3ce
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 29 deletions.
1 change: 1 addition & 0 deletions drivers/net/ethernet/broadcom/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ config BNXT
select FW_LOADER
select LIBCRC32C
select NET_DEVLINK
select PAGE_POOL
---help---
This driver supports Broadcom NetXtreme-C/E 10/25/40/50 gigabit
Ethernet cards. To compile this driver as a module, choose M here:
Expand Down
72 changes: 66 additions & 6 deletions drivers/net/ethernet/broadcom/bnxt/bnxt.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include <net/pkt_cls.h>
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#include <net/page_pool.h>

#include "bnxt_hsi.h"
#include "bnxt.h"
Expand Down Expand Up @@ -668,19 +669,20 @@ static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts)
}

static struct page *__bnxt_alloc_rx_page(struct bnxt *bp, dma_addr_t *mapping,
struct bnxt_rx_ring_info *rxr,
gfp_t gfp)
{
struct device *dev = &bp->pdev->dev;
struct page *page;

page = alloc_page(gfp);
page = page_pool_dev_alloc_pages(rxr->page_pool);
if (!page)
return NULL;

*mapping = dma_map_page_attrs(dev, page, 0, PAGE_SIZE, bp->rx_dir,
DMA_ATTR_WEAK_ORDERING);
if (dma_mapping_error(dev, *mapping)) {
__free_page(page);
page_pool_recycle_direct(rxr->page_pool, page);
return NULL;
}
*mapping += bp->rx_dma_offset;
Expand Down Expand Up @@ -716,7 +718,8 @@ int bnxt_alloc_rx_data(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
dma_addr_t mapping;

if (BNXT_RX_PAGE_MODE(bp)) {
struct page *page = __bnxt_alloc_rx_page(bp, &mapping, gfp);
struct page *page =
__bnxt_alloc_rx_page(bp, &mapping, rxr, gfp);

if (!page)
return -ENOMEM;
Expand Down Expand Up @@ -1989,6 +1992,9 @@ static int __bnxt_poll_work(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
}
}

if (event & BNXT_REDIRECT_EVENT)
xdp_do_flush_map();

if (event & BNXT_TX_EVENT) {
struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
u16 prod = txr->tx_prod;
Expand Down Expand Up @@ -2254,9 +2260,23 @@ static void bnxt_free_tx_skbs(struct bnxt *bp)

for (j = 0; j < max_idx;) {
struct bnxt_sw_tx_bd *tx_buf = &txr->tx_buf_ring[j];
struct sk_buff *skb = tx_buf->skb;
struct sk_buff *skb;
int k, last;

if (i < bp->tx_nr_rings_xdp &&
tx_buf->action == XDP_REDIRECT) {
dma_unmap_single(&pdev->dev,
dma_unmap_addr(tx_buf, mapping),
dma_unmap_len(tx_buf, len),
PCI_DMA_TODEVICE);
xdp_return_frame(tx_buf->xdpf);
tx_buf->action = 0;
tx_buf->xdpf = NULL;
j++;
continue;
}

skb = tx_buf->skb;
if (!skb) {
j++;
continue;
Expand Down Expand Up @@ -2343,7 +2363,7 @@ static void bnxt_free_rx_skbs(struct bnxt *bp)
dma_unmap_page_attrs(&pdev->dev, mapping,
PAGE_SIZE, bp->rx_dir,
DMA_ATTR_WEAK_ORDERING);
__free_page(data);
page_pool_recycle_direct(rxr->page_pool, data);
} else {
dma_unmap_single_attrs(&pdev->dev, mapping,
bp->rx_buf_use_size,
Expand Down Expand Up @@ -2480,6 +2500,8 @@ static void bnxt_free_rx_rings(struct bnxt *bp)
if (xdp_rxq_info_is_reg(&rxr->xdp_rxq))
xdp_rxq_info_unreg(&rxr->xdp_rxq);

rxr->page_pool = NULL;

kfree(rxr->rx_tpa);
rxr->rx_tpa = NULL;

Expand All @@ -2494,6 +2516,26 @@ static void bnxt_free_rx_rings(struct bnxt *bp)
}
}

static int bnxt_alloc_rx_page_pool(struct bnxt *bp,
struct bnxt_rx_ring_info *rxr)
{
struct page_pool_params pp = { 0 };

pp.pool_size = bp->rx_ring_size;
pp.nid = dev_to_node(&bp->pdev->dev);
pp.dev = &bp->pdev->dev;
pp.dma_dir = DMA_BIDIRECTIONAL;

rxr->page_pool = page_pool_create(&pp);
if (IS_ERR(rxr->page_pool)) {
int err = PTR_ERR(rxr->page_pool);

rxr->page_pool = NULL;
return err;
}
return 0;
}

static int bnxt_alloc_rx_rings(struct bnxt *bp)
{
int i, rc, agg_rings = 0, tpa_rings = 0;
Expand All @@ -2513,9 +2555,26 @@ static int bnxt_alloc_rx_rings(struct bnxt *bp)

ring = &rxr->rx_ring_struct;

rc = bnxt_alloc_rx_page_pool(bp, rxr);
if (rc)
return rc;

rc = xdp_rxq_info_reg(&rxr->xdp_rxq, bp->dev, i);
if (rc < 0)
if (rc < 0) {
page_pool_free(rxr->page_pool);
rxr->page_pool = NULL;
return rc;
}

rc = xdp_rxq_info_reg_mem_model(&rxr->xdp_rxq,
MEM_TYPE_PAGE_POOL,
rxr->page_pool);
if (rc) {
xdp_rxq_info_unreg(&rxr->xdp_rxq);
page_pool_free(rxr->page_pool);
rxr->page_pool = NULL;
return rc;
}

rc = bnxt_alloc_ring(bp, &ring->ring_mem);
if (rc)
Expand Down Expand Up @@ -10233,6 +10292,7 @@ static const struct net_device_ops bnxt_netdev_ops = {
.ndo_udp_tunnel_add = bnxt_udp_tunnel_add,
.ndo_udp_tunnel_del = bnxt_udp_tunnel_del,
.ndo_bpf = bnxt_xdp,
.ndo_xdp_xmit = bnxt_xdp_xmit,
.ndo_bridge_getlink = bnxt_bridge_getlink,
.ndo_bridge_setlink = bnxt_bridge_setlink,
.ndo_get_devlink_port = bnxt_get_devlink_port,
Expand Down
17 changes: 13 additions & 4 deletions drivers/net/ethernet/broadcom/bnxt/bnxt.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <net/xdp.h>
#include <linux/dim.h>

struct page_pool;

struct tx_bd {
__le32 tx_bd_len_flags_type;
#define TX_BD_TYPE (0x3f << 0)
Expand Down Expand Up @@ -587,15 +589,21 @@ struct nqe_cn {
#define BNXT_HWRM_CHNL_CHIMP 0
#define BNXT_HWRM_CHNL_KONG 1

#define BNXT_RX_EVENT 1
#define BNXT_AGG_EVENT 2
#define BNXT_TX_EVENT 4
#define BNXT_RX_EVENT 1
#define BNXT_AGG_EVENT 2
#define BNXT_TX_EVENT 4
#define BNXT_REDIRECT_EVENT 8

struct bnxt_sw_tx_bd {
struct sk_buff *skb;
union {
struct sk_buff *skb;
struct xdp_frame *xdpf;
};
DEFINE_DMA_UNMAP_ADDR(mapping);
DEFINE_DMA_UNMAP_LEN(len);
u8 is_gso;
u8 is_push;
u8 action;
union {
unsigned short nr_frags;
u16 rx_prod;
Expand Down Expand Up @@ -793,6 +801,7 @@ struct bnxt_rx_ring_info {
struct bnxt_ring_struct rx_ring_struct;
struct bnxt_ring_struct rx_agg_ring_struct;
struct xdp_rxq_info xdp_rxq;
struct page_pool *page_pool;
};

struct bnxt_cp_ring_info {
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -2799,7 +2799,7 @@ static int bnxt_run_loopback(struct bnxt *bp)
dev_kfree_skb(skb);
return -EIO;
}
bnxt_xmit_xdp(bp, txr, map, pkt_size, 0);
bnxt_xmit_bd(bp, txr, map, pkt_size);

/* Sync BD data before updating doorbell */
wmb();
Expand Down
Loading

0 comments on commit 107d3ce

Please sign in to comment.