diff mbox series

[RFC,net-next,v2,7/9] bnxt: add helpers for allocating rx ring mem

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

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 926 this patch: 929
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang fail Errors and warnings before: 937 this patch: 941
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 939 this patch: 942
netdev/checkpatch warning WARNING: line length of 81 exceeds 80 columns WARNING: line length of 84 exceeds 80 columns WARNING: line length of 88 exceeds 80 columns WARNING: line length of 91 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 2 this patch: 2
netdev/source_inline success Was 0 now: 0

Commit Message

David Wei May 2, 2024, 4:54 a.m. UTC
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(+)

Comments

Simon Horman May 4, 2024, 12:34 p.m. UTC | #1
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.
David Wei May 6, 2024, 12:42 a.m. UTC | #2
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 mbox series

Patch

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);