diff mbox series

[net-next,2/4] octeontx2-pf: Add new APIs for queue memory alloc/free.

Message ID 20240903124048.14235-3-gakula@marvell.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series Refactoring RVU NIC driver | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
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 success Errors and warnings before: 7 this patch: 7
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 16 this patch: 16
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 success Errors and warnings before: 28 this patch: 28
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 103 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-09-04--00-00 (tests: 713)

Commit Message

Geetha sowjanya Sept. 3, 2024, 12:40 p.m. UTC
Group the queue(RX/TX/CQ) memory allocation and free code to single APIs.

Signed-off-by: Geetha sowjanya <gakula@marvell.com>
---
 .../marvell/octeontx2/nic/otx2_common.h       |  2 +
 .../ethernet/marvell/octeontx2/nic/otx2_pf.c  | 56 +++++++++++++------
 2 files changed, 41 insertions(+), 17 deletions(-)

Comments

Pavan Chebbi Sept. 3, 2024, 3:12 p.m. UTC | #1
On Tue, Sep 3, 2024 at 6:12 PM Geetha sowjanya <gakula@marvell.com> wrote:
>
> Group the queue(RX/TX/CQ) memory allocation and free code to single APIs.
>
> Signed-off-by: Geetha sowjanya <gakula@marvell.com>
> ---
>  .../marvell/octeontx2/nic/otx2_common.h       |  2 +
>  .../ethernet/marvell/octeontx2/nic/otx2_pf.c  | 56 +++++++++++++------
>  2 files changed, 41 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h
> index a47001a2b93f..df548aeffecf 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h
> +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h
> @@ -997,6 +997,8 @@ int otx2_pool_init(struct otx2_nic *pfvf, u16 pool_id,
>  int otx2_aura_init(struct otx2_nic *pfvf, int aura_id,
>                    int pool_id, int numptrs);
>  int otx2_init_rsrc(struct pci_dev *pdev, struct otx2_nic *pf);
> +void otx2_free_queue_mem(struct otx2_qset *qset);
> +int otx2_alloc_queue_mem(struct otx2_nic *pf);
>
>  /* RSS configuration APIs*/
>  int otx2_rss_init(struct otx2_nic *pfvf);
> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
> index 4cfeca5ca626..68addc975113 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
> @@ -1770,15 +1770,23 @@ static void otx2_dim_work(struct work_struct *w)
>         dim->state = DIM_START_MEASURE;
>  }
>
> -int otx2_open(struct net_device *netdev)
> +void otx2_free_queue_mem(struct otx2_qset *qset)
> +{
> +       kfree(qset->sq);
> +       qset->sq = NULL;
> +       kfree(qset->cq);
> +       qset->cq = NULL;
> +       kfree(qset->rq);
> +       qset->rq = NULL;
> +       kfree(qset->napi);
> +}
> +EXPORT_SYMBOL(otx2_free_queue_mem);
> +int otx2_alloc_queue_mem(struct otx2_nic *pf)
>  {
> -       struct otx2_nic *pf = netdev_priv(netdev);
> -       struct otx2_cq_poll *cq_poll = NULL;
>         struct otx2_qset *qset = &pf->qset;
> -       int err = 0, qidx, vec;
> -       char *irq_name;
> +       struct otx2_cq_poll *cq_poll;
> +       int err = -ENOMEM;
I don't see 'err' getting set to anything else. Can avoid the variable
and directly return -ENOMEM everywhere?
Geetha sowjanya Sept. 4, 2024, 5:35 a.m. UTC | #2
>-----Original Message-----
>From: Pavan Chebbi <pavan.chebbi@broadcom.com>
>Sent: Tuesday, September 3, 2024 8:42 PM
>To: Geethasowjanya Akula <gakula@marvell.com>
>Cc: netdev@vger.kernel.org; linux-kernel@vger.kernel.org; kuba@kernel.org;
>davem@davemloft.net; pabeni@redhat.com; jiri@resnulli.us;
>edumazet@google.com; Sunil Kovvuri Goutham <sgoutham@marvell.com>;
>Subbaraya Sundeep Bhatta <sbhatta@marvell.com>; Hariprasad Kelam
><hkelam@marvell.com>
>Subject: [EXTERNAL] Re: [net-next PATCH 2/4] octeontx2-pf: Add new APIs for
>queue memory alloc/free.
>
>On Tue, Sep 3, 2024 at 6:12 PM Geetha sowjanya <gakula@marvell.com>
>wrote:
>>
>> Group the queue(RX/TX/CQ) memory allocation and free code to single APIs.
>>
>> Signed-off-by: Geetha sowjanya <gakula@marvell.com>
>> ---
>>  .../marvell/octeontx2/nic/otx2_common.h       |  2 +
>>  .../ethernet/marvell/octeontx2/nic/otx2_pf.c  | 56 +++++++++++++------
>>  2 files changed, 41 insertions(+), 17 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h
>b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h
>> index a47001a2b93f..df548aeffecf 100644
>> --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h
>> +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h
>> @@ -997,6 +997,8 @@ int otx2_pool_init(struct otx2_nic *pfvf, u16 pool_id,
>>  int otx2_aura_init(struct otx2_nic *pfvf, int aura_id,
>>                    int pool_id, int numptrs);
>>  int otx2_init_rsrc(struct pci_dev *pdev, struct otx2_nic *pf);
>> +void otx2_free_queue_mem(struct otx2_qset *qset);
>> +int otx2_alloc_queue_mem(struct otx2_nic *pf);
>>
>>  /* RSS configuration APIs*/
>>  int otx2_rss_init(struct otx2_nic *pfvf);
>> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
>b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
>> index 4cfeca5ca626..68addc975113 100644
>> --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
>> +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
>> @@ -1770,15 +1770,23 @@ static void otx2_dim_work(struct work_struct
>*w)
>>         dim->state = DIM_START_MEASURE;
>>  }
>>
>> -int otx2_open(struct net_device *netdev)
>> +void otx2_free_queue_mem(struct otx2_qset *qset)
>> +{
>> +       kfree(qset->sq);
>> +       qset->sq = NULL;
>> +       kfree(qset->cq);
>> +       qset->cq = NULL;
>> +       kfree(qset->rq);
>> +       qset->rq = NULL;
>> +       kfree(qset->napi);
>> +}
>> +EXPORT_SYMBOL(otx2_free_queue_mem);
>> +int otx2_alloc_queue_mem(struct otx2_nic *pf)
>>  {
>> -       struct otx2_nic *pf = netdev_priv(netdev);
>> -       struct otx2_cq_poll *cq_poll = NULL;
>>         struct otx2_qset *qset = &pf->qset;
>> -       int err = 0, qidx, vec;
>> -       char *irq_name;
>> +       struct otx2_cq_poll *cq_poll;
>> +       int err = -ENOMEM;
>I don't see 'err' getting set to anything else. Can avoid the variable
>and directly return -ENOMEM everywhere?
Will fix it in next version.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h
index a47001a2b93f..df548aeffecf 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h
@@ -997,6 +997,8 @@  int otx2_pool_init(struct otx2_nic *pfvf, u16 pool_id,
 int otx2_aura_init(struct otx2_nic *pfvf, int aura_id,
 		   int pool_id, int numptrs);
 int otx2_init_rsrc(struct pci_dev *pdev, struct otx2_nic *pf);
+void otx2_free_queue_mem(struct otx2_qset *qset);
+int otx2_alloc_queue_mem(struct otx2_nic *pf);
 
 /* RSS configuration APIs*/
 int otx2_rss_init(struct otx2_nic *pfvf);
diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
index 4cfeca5ca626..68addc975113 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
@@ -1770,15 +1770,23 @@  static void otx2_dim_work(struct work_struct *w)
 	dim->state = DIM_START_MEASURE;
 }
 
-int otx2_open(struct net_device *netdev)
+void otx2_free_queue_mem(struct otx2_qset *qset)
+{
+	kfree(qset->sq);
+	qset->sq = NULL;
+	kfree(qset->cq);
+	qset->cq = NULL;
+	kfree(qset->rq);
+	qset->rq = NULL;
+	kfree(qset->napi);
+}
+EXPORT_SYMBOL(otx2_free_queue_mem);
+int otx2_alloc_queue_mem(struct otx2_nic *pf)
 {
-	struct otx2_nic *pf = netdev_priv(netdev);
-	struct otx2_cq_poll *cq_poll = NULL;
 	struct otx2_qset *qset = &pf->qset;
-	int err = 0, qidx, vec;
-	char *irq_name;
+	struct otx2_cq_poll *cq_poll;
+	int err = -ENOMEM;
 
-	netif_carrier_off(netdev);
 
 	/* RQ and SQs are mapped to different CQs,
 	 * so find out max CQ IRQs (i.e CINTs) needed.
@@ -1791,14 +1799,13 @@  int otx2_open(struct net_device *netdev)
 
 	qset->napi = kcalloc(pf->hw.cint_cnt, sizeof(*cq_poll), GFP_KERNEL);
 	if (!qset->napi)
-		return -ENOMEM;
+		return err;
 
 	/* CQ size of RQ */
 	qset->rqe_cnt = qset->rqe_cnt ? qset->rqe_cnt : Q_COUNT(Q_SIZE_256);
 	/* CQ size of SQ */
 	qset->sqe_cnt = qset->sqe_cnt ? qset->sqe_cnt : Q_COUNT(Q_SIZE_4K);
 
-	err = -ENOMEM;
 	qset->cq = kcalloc(pf->qset.cq_cnt,
 			   sizeof(struct otx2_cq_queue), GFP_KERNEL);
 	if (!qset->cq)
@@ -1814,6 +1821,28 @@  int otx2_open(struct net_device *netdev)
 	if (!qset->rq)
 		goto err_free_mem;
 
+	return 0;
+
+err_free_mem:
+	otx2_free_queue_mem(qset);
+	return err;
+}
+EXPORT_SYMBOL(otx2_alloc_queue_mem);
+
+int otx2_open(struct net_device *netdev)
+{
+	struct otx2_nic *pf = netdev_priv(netdev);
+	struct otx2_cq_poll *cq_poll = NULL;
+	struct otx2_qset *qset = &pf->qset;
+	int err = 0, qidx, vec;
+	char *irq_name;
+
+	netif_carrier_off(netdev);
+
+	err = otx2_alloc_queue_mem(pf);
+	if (err)
+		return err;
+
 	err = otx2_init_hw_resources(pf);
 	if (err)
 		goto err_free_mem;
@@ -1979,10 +2008,7 @@  int otx2_open(struct net_device *netdev)
 	otx2_disable_napi(pf);
 	otx2_free_hw_resources(pf);
 err_free_mem:
-	kfree(qset->sq);
-	kfree(qset->cq);
-	kfree(qset->rq);
-	kfree(qset->napi);
+	otx2_free_queue_mem(qset);
 	return err;
 }
 EXPORT_SYMBOL(otx2_open);
@@ -2047,11 +2073,7 @@  int otx2_stop(struct net_device *netdev)
 	for (qidx = 0; qidx < netdev->num_tx_queues; qidx++)
 		netdev_tx_reset_queue(netdev_get_tx_queue(netdev, qidx));
 
-
-	kfree(qset->sq);
-	kfree(qset->cq);
-	kfree(qset->rq);
-	kfree(qset->napi);
+	otx2_free_queue_mem(qset);
 	/* Do not clear RQ/SQ ringsize settings */
 	memset_startat(qset, 0, sqe_cnt);
 	return 0;