Commit 975bc99a authored by Michael Chan's avatar Michael Chan Committed by David S. Miller

bnxt_en: Refactor bnxt_free_rx_skbs().

bnxt_free_rx_skbs() frees all the allocated buffers and SKBs for
every RX ring.  Refactor this function by calling a new function
bnxt_free_one_rx_ring_skbs() to free these buffers on one specified
RX ring at a time.  This is preparation work for resetting one RX
ring during run-time.
Reviewed-by: default avatarPavan Chebbi <pavan.chebbi@broadcom.com>
Signed-off-by: default avatarMichael Chan <michael.chan@broadcom.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent fc8864e0
...@@ -2540,93 +2540,91 @@ static void bnxt_free_tx_skbs(struct bnxt *bp) ...@@ -2540,93 +2540,91 @@ static void bnxt_free_tx_skbs(struct bnxt *bp)
} }
} }
static void bnxt_free_rx_skbs(struct bnxt *bp) static void bnxt_free_one_rx_ring_skbs(struct bnxt *bp, int ring_nr)
{ {
int i, max_idx, max_agg_idx; struct bnxt_rx_ring_info *rxr = &bp->rx_ring[ring_nr];
struct pci_dev *pdev = bp->pdev; struct pci_dev *pdev = bp->pdev;
struct bnxt_tpa_idx_map *map;
if (!bp->rx_ring) int i, max_idx, max_agg_idx;
return;
max_idx = bp->rx_nr_pages * RX_DESC_CNT; max_idx = bp->rx_nr_pages * RX_DESC_CNT;
max_agg_idx = bp->rx_agg_nr_pages * RX_DESC_CNT; max_agg_idx = bp->rx_agg_nr_pages * RX_DESC_CNT;
for (i = 0; i < bp->rx_nr_rings; i++) { if (!rxr->rx_tpa)
struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; goto skip_rx_tpa_free;
struct bnxt_tpa_idx_map *map;
int j;
if (rxr->rx_tpa) {
for (j = 0; j < bp->max_tpa; j++) {
struct bnxt_tpa_info *tpa_info =
&rxr->rx_tpa[j];
u8 *data = tpa_info->data;
if (!data) for (i = 0; i < bp->max_tpa; i++) {
continue; struct bnxt_tpa_info *tpa_info = &rxr->rx_tpa[i];
u8 *data = tpa_info->data;
dma_unmap_single_attrs(&pdev->dev, if (!data)
tpa_info->mapping, continue;
bp->rx_buf_use_size,
bp->rx_dir,
DMA_ATTR_WEAK_ORDERING);
tpa_info->data = NULL; dma_unmap_single_attrs(&pdev->dev, tpa_info->mapping,
bp->rx_buf_use_size, bp->rx_dir,
DMA_ATTR_WEAK_ORDERING);
kfree(data); tpa_info->data = NULL;
}
}
for (j = 0; j < max_idx; j++) { kfree(data);
struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[j]; }
dma_addr_t mapping = rx_buf->mapping;
void *data = rx_buf->data;
if (!data) skip_rx_tpa_free:
continue; for (i = 0; i < max_idx; i++) {
struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[i];
dma_addr_t mapping = rx_buf->mapping;
void *data = rx_buf->data;
rx_buf->data = NULL; if (!data)
continue;
if (BNXT_RX_PAGE_MODE(bp)) { rx_buf->data = NULL;
mapping -= bp->rx_dma_offset; if (BNXT_RX_PAGE_MODE(bp)) {
dma_unmap_page_attrs(&pdev->dev, mapping, mapping -= bp->rx_dma_offset;
PAGE_SIZE, bp->rx_dir, dma_unmap_page_attrs(&pdev->dev, mapping, PAGE_SIZE,
DMA_ATTR_WEAK_ORDERING); bp->rx_dir,
page_pool_recycle_direct(rxr->page_pool, data); DMA_ATTR_WEAK_ORDERING);
} else { page_pool_recycle_direct(rxr->page_pool, data);
dma_unmap_single_attrs(&pdev->dev, mapping, } else {
bp->rx_buf_use_size, dma_unmap_single_attrs(&pdev->dev, mapping,
bp->rx_dir, bp->rx_buf_use_size, bp->rx_dir,
DMA_ATTR_WEAK_ORDERING); DMA_ATTR_WEAK_ORDERING);
kfree(data); kfree(data);
}
} }
}
for (i = 0; i < max_agg_idx; i++) {
struct bnxt_sw_rx_agg_bd *rx_agg_buf = &rxr->rx_agg_ring[i];
struct page *page = rx_agg_buf->page;
for (j = 0; j < max_agg_idx; j++) { if (!page)
struct bnxt_sw_rx_agg_bd *rx_agg_buf = continue;
&rxr->rx_agg_ring[j];
struct page *page = rx_agg_buf->page;
if (!page)
continue;
dma_unmap_page_attrs(&pdev->dev, rx_agg_buf->mapping, dma_unmap_page_attrs(&pdev->dev, rx_agg_buf->mapping,
BNXT_RX_PAGE_SIZE, BNXT_RX_PAGE_SIZE, PCI_DMA_FROMDEVICE,
PCI_DMA_FROMDEVICE, DMA_ATTR_WEAK_ORDERING);
DMA_ATTR_WEAK_ORDERING);
rx_agg_buf->page = NULL; rx_agg_buf->page = NULL;
__clear_bit(j, rxr->rx_agg_bmap); __clear_bit(i, rxr->rx_agg_bmap);
__free_page(page); __free_page(page);
} }
if (rxr->rx_page) { if (rxr->rx_page) {
__free_page(rxr->rx_page); __free_page(rxr->rx_page);
rxr->rx_page = NULL; rxr->rx_page = NULL;
}
map = rxr->rx_tpa_idx_map;
if (map)
memset(map->agg_idx_bmap, 0, sizeof(map->agg_idx_bmap));
} }
map = rxr->rx_tpa_idx_map;
if (map)
memset(map->agg_idx_bmap, 0, sizeof(map->agg_idx_bmap));
}
static void bnxt_free_rx_skbs(struct bnxt *bp)
{
int i;
if (!bp->rx_ring)
return;
for (i = 0; i < bp->rx_nr_rings; i++)
bnxt_free_one_rx_ring_skbs(bp, i);
} }
static void bnxt_free_skbs(struct bnxt *bp) static void bnxt_free_skbs(struct bnxt *bp)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment