Message ID | 20240502045410.3524155-8-dw@davidwei.uk (mailing list archive) |
---|---|
State | RFC |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | bnxt: implement queue api | expand |
On Wed, May 01, 2024 at 09:54:08PM -0700, David Wei wrote: > Add several helper functions for allocating rx ring memory. These are > mostly taken from existing functions, but with unnecessary bits stripped > out such that only allocations are done. > > Signed-off-by: David Wei <dw@davidwei.uk> > --- > drivers/net/ethernet/broadcom/bnxt/bnxt.c | 87 +++++++++++++++++++++++ > 1 file changed, 87 insertions(+) > > diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c > index b0a8d14b7319..21c1a7cb70ab 100644 > --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c > +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c > @@ -14845,6 +14845,93 @@ static const struct netdev_stat_ops bnxt_stat_ops = { > .get_base_stats = bnxt_get_base_stats, > }; > > +static int __bnxt_alloc_rx_desc_ring(struct pci_dev *pdev, struct bnxt_ring_mem_info *rmem) > +{ > + int i, rc; > + > + for (i = 0; i < rmem->nr_pages; i++) { > + rmem->pg_arr[i] = dma_alloc_coherent(&pdev->dev, > + rmem->page_size, > + &rmem->dma_arr[i], > + GFP_KERNEL); > + if (!rmem->pg_arr[i]) { > + rc = -ENOMEM; > + goto err_free; > + } > + } > + > + return 0; > + > +err_free: > + while (i--) { > + dma_free_coherent(&pdev->dev, rmem->page_size, > + rmem->pg_arr[i], rmem->dma_arr[i]); > + rmem->pg_arr[i] = NULL; > + } > + return rc; > +} > + > +static int bnxt_alloc_rx_ring_struct(struct bnxt *bp, struct bnxt_ring_struct *ring) Hi David, W=1 builds fail because this and other functions introduced by this patch are unused. I agree that it is nice to split up changes into discrete patches. But in this case the change isn't really discrete. So perhaps it is best to add helper functions in the same patch where they are first used.
On 2024-05-04 05:34, Simon Horman wrote: > On Wed, May 01, 2024 at 09:54:08PM -0700, David Wei wrote: >> Add several helper functions for allocating rx ring memory. These are >> mostly taken from existing functions, but with unnecessary bits stripped >> out such that only allocations are done. >> >> Signed-off-by: David Wei <dw@davidwei.uk> >> --- >> drivers/net/ethernet/broadcom/bnxt/bnxt.c | 87 +++++++++++++++++++++++ >> 1 file changed, 87 insertions(+) >> >> diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c >> index b0a8d14b7319..21c1a7cb70ab 100644 >> --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c >> +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c >> @@ -14845,6 +14845,93 @@ static const struct netdev_stat_ops bnxt_stat_ops = { >> .get_base_stats = bnxt_get_base_stats, >> }; >> >> +static int __bnxt_alloc_rx_desc_ring(struct pci_dev *pdev, struct bnxt_ring_mem_info *rmem) >> +{ >> + int i, rc; >> + >> + for (i = 0; i < rmem->nr_pages; i++) { >> + rmem->pg_arr[i] = dma_alloc_coherent(&pdev->dev, >> + rmem->page_size, >> + &rmem->dma_arr[i], >> + GFP_KERNEL); >> + if (!rmem->pg_arr[i]) { >> + rc = -ENOMEM; >> + goto err_free; >> + } >> + } >> + >> + return 0; >> + >> +err_free: >> + while (i--) { >> + dma_free_coherent(&pdev->dev, rmem->page_size, >> + rmem->pg_arr[i], rmem->dma_arr[i]); >> + rmem->pg_arr[i] = NULL; >> + } >> + return rc; >> +} >> + >> +static int bnxt_alloc_rx_ring_struct(struct bnxt *bp, struct bnxt_ring_struct *ring) > > Hi David, > > W=1 builds fail because this and other functions introduced by > this patch are unused. I agree that it is nice to split up changes > into discrete patches. But in this case the change isn't really discrete. > So perhaps it is best to add helper functions in the same patch > where they are first used. Okay, I'll squash it with the patch that uses these functions. Thanks.
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index b0a8d14b7319..21c1a7cb70ab 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -14845,6 +14845,93 @@ static const struct netdev_stat_ops bnxt_stat_ops = { .get_base_stats = bnxt_get_base_stats, }; +static int __bnxt_alloc_rx_desc_ring(struct pci_dev *pdev, struct bnxt_ring_mem_info *rmem) +{ + int i, rc; + + for (i = 0; i < rmem->nr_pages; i++) { + rmem->pg_arr[i] = dma_alloc_coherent(&pdev->dev, + rmem->page_size, + &rmem->dma_arr[i], + GFP_KERNEL); + if (!rmem->pg_arr[i]) { + rc = -ENOMEM; + goto err_free; + } + } + + return 0; + +err_free: + while (i--) { + dma_free_coherent(&pdev->dev, rmem->page_size, + rmem->pg_arr[i], rmem->dma_arr[i]); + rmem->pg_arr[i] = NULL; + } + return rc; +} + +static int bnxt_alloc_rx_ring_struct(struct bnxt *bp, struct bnxt_ring_struct *ring) +{ + struct bnxt_ring_mem_info *rmem; + int rc; + + rmem = &ring->ring_mem; + rc = __bnxt_alloc_rx_desc_ring(bp->pdev, rmem); + if (rc) + return rc; + + *rmem->vmem = vzalloc(rmem->vmem_size); + if (!(*rmem->vmem)) { + rc = -ENOMEM; + goto err_free; + } + + return 0; + +err_free: + bnxt_free_ring(bp, rmem); + return rc; +} + +static int bnxt_alloc_rx_agg_bmap(struct bnxt *bp, struct bnxt_rx_ring_info *rxr) +{ + u16 mem_size; + + rxr->rx_agg_bmap_size = bp->rx_agg_ring_mask + 1; + mem_size = rxr->rx_agg_bmap_size / 8; + rxr->rx_agg_bmap = kzalloc(mem_size, GFP_KERNEL); + if (!rxr->rx_agg_bmap) + return -ENOMEM; + + return 0; +} + +static void bnxt_init_rx_ring_rxbd_pages(struct bnxt *bp, struct bnxt_rx_ring_info *rxr) +{ + struct bnxt_ring_struct *ring; + u32 type; + + type = (bp->rx_buf_use_size << RX_BD_LEN_SHIFT) | + RX_BD_TYPE_RX_PACKET_BD | RX_BD_FLAGS_EOP; + + if (NET_IP_ALIGN == 2) + type |= RX_BD_FLAGS_SOP; + + ring = &rxr->rx_ring_struct; + ring->fw_ring_id = INVALID_HW_RING_ID; + bnxt_init_rxbd_pages(ring, type); + + ring = &rxr->rx_agg_ring_struct; + ring->fw_ring_id = INVALID_HW_RING_ID; + if ((bp->flags & BNXT_FLAG_AGG_RINGS)) { + type = ((u32)BNXT_RX_PAGE_SIZE << RX_BD_LEN_SHIFT) | + RX_BD_TYPE_RX_AGG_BD | RX_BD_FLAGS_SOP; + + bnxt_init_rxbd_pages(ring, type); + } +} + static void *bnxt_queue_mem_alloc(struct net_device *dev, int idx) { struct bnxt *bp = netdev_priv(dev);
Add several helper functions for allocating rx ring memory. These are mostly taken from existing functions, but with unnecessary bits stripped out such that only allocations are done. Signed-off-by: David Wei <dw@davidwei.uk> --- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 87 +++++++++++++++++++++++ 1 file changed, 87 insertions(+)