diff mbox series

[net-next,1/4] octeontx2-pf: Defines common API for HW resources configuration

Message ID 20240903124048.14235-2-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, 186 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
Defines new API "otx2_init_rsrc" and moves the HW blocks
NIX/NPA resources configuration code under this API. So, that
it can be used by the RVU representor driver that has similar
resources of RVU NIC.

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

Comments

Jiri Pirko Sept. 3, 2024, 2:55 p.m. UTC | #1
Tue, Sep 03, 2024 at 02:40:45PM CEST, gakula@marvell.com wrote:
>Defines new API "otx2_init_rsrc" and moves the HW blocks

s/Defines/Define/ (in subject of the patch as well)
s/moves/move/

Otherwise that patch looks ok.


>NIX/NPA resources configuration code under this API. So, that
>it can be used by the RVU representor driver that has similar
>resources of RVU NIC.
>
>Signed-off-by: Geetha sowjanya <gakula@marvell.com>
Pavan Chebbi Sept. 3, 2024, 2:57 p.m. UTC | #2
On Tue, Sep 3, 2024 at 6:11 PM Geetha sowjanya <gakula@marvell.com> wrote:
>
> -
>         /* Assign default mac address */
>         otx2_get_mac_from_af(netdev);
>
> @@ -3118,11 +3141,8 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>         if (test_bit(CN10K_LMTST, &pf->hw.cap_flag))
>                 qmem_free(pf->dev, pf->dync_lmt);
>         otx2_detach_resources(&pf->mbox);
Isn't some of this unwinding/cleanup already moved to the new
function? Looks like duplicate code to me.

> -err_disable_mbox_intr:
>         otx2_disable_mbox_intr(pf);
> -err_mbox_destroy:
>         otx2_pfaf_mbox_destroy(pf);
> -err_free_irq_vectors:
>         pci_free_irq_vectors(hw->pdev);
>  err_free_netdev:
>         pci_set_drvdata(pdev, NULL);
> --
> 2.25.1
>
>
Geetha sowjanya Sept. 4, 2024, 5:48 a.m. UTC | #3
>-----Original Message-----
>From: Pavan Chebbi <pavan.chebbi@broadcom.com>
>Sent: Tuesday, September 3, 2024 8:27 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 1/4] octeontx2-pf: Defines common
>API for HW resources configuration
>
>On Tue, Sep 3, 2024 at 6:11 PM Geetha sowjanya <gakula@marvell.com>
>wrote:
>>
>> -
>>         /* Assign default mac address */
>>         otx2_get_mac_from_af(netdev);
>>
>> @@ -3118,11 +3141,8 @@ static int otx2_probe(struct pci_dev *pdev, const
>struct pci_device_id *id)
>>         if (test_bit(CN10K_LMTST, &pf->hw.cap_flag))
>>                 qmem_free(pf->dev, pf->dync_lmt);
>>         otx2_detach_resources(&pf->mbox);
>Isn't some of this unwinding/cleanup already moved to the new
>function? Looks like duplicate code to me.
No. If the otx2_probe () fails in any of the function after " otx2_init_rsrc()" function call.
Then below code cleanup the resources allocated.
>
>> -err_disable_mbox_intr:
>>         otx2_disable_mbox_intr(pf);
>> -err_mbox_destroy:
>>         otx2_pfaf_mbox_destroy(pf);
>> -err_free_irq_vectors:
>>         pci_free_irq_vectors(hw->pdev);
>>  err_free_netdev:
>>         pci_set_drvdata(pdev, NULL);
>> --
>> 2.25.1
>>
>>
Pavan Chebbi Sept. 4, 2024, 6:18 a.m. UTC | #4
On Wed, Sep 4, 2024 at 11:18 AM Geethasowjanya Akula <gakula@marvell.com> wrote:
>
>
>
> >-----Original Message-----
> >From: Pavan Chebbi <pavan.chebbi@broadcom.com>
> >Sent: Tuesday, September 3, 2024 8:27 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 1/4] octeontx2-pf: Defines common
> >API for HW resources configuration
> >
> >On Tue, Sep 3, 2024 at 6:11 PM Geetha sowjanya <gakula@marvell.com>
> >wrote:
> >>
> >> -
> >>         /* Assign default mac address */
> >>         otx2_get_mac_from_af(netdev);
> >>
> >> @@ -3118,11 +3141,8 @@ static int otx2_probe(struct pci_dev *pdev, const
> >struct pci_device_id *id)
> >>         if (test_bit(CN10K_LMTST, &pf->hw.cap_flag))
> >>                 qmem_free(pf->dev, pf->dync_lmt);
> >>         otx2_detach_resources(&pf->mbox);
> >Isn't some of this unwinding/cleanup already moved to the new
> >function? Looks like duplicate code to me.
> No. If the otx2_probe () fails in any of the function after " otx2_init_rsrc()" function call.
> Then below code cleanup the resources allocated.

Ack. I missed to see that otx2_init_rsrc() is being carved out in
order to be called independently also.

> >
> >> -err_disable_mbox_intr:
> >>         otx2_disable_mbox_intr(pf);
> >> -err_mbox_destroy:
> >>         otx2_pfaf_mbox_destroy(pf);
> >> -err_free_irq_vectors:
> >>         pci_free_irq_vectors(hw->pdev);
> >>  err_free_netdev:
> >>         pci_set_drvdata(pdev, NULL);
> >> --
> >> 2.25.1
> >>
> >>
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 f27a3456ae64..a47001a2b93f 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h
@@ -996,6 +996,7 @@  int otx2_pool_init(struct otx2_nic *pfvf, u16 pool_id,
 		   int stack_pages, int numptrs, int buf_size, int type);
 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);
 
 /* 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 5492dea547a1..4cfeca5ca626 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
@@ -2872,6 +2872,88 @@  static void otx2_sriov_vfcfg_cleanup(struct otx2_nic *pf)
 	}
 }
 
+int otx2_init_rsrc(struct pci_dev *pdev, struct otx2_nic *pf)
+{
+	struct device *dev = &pdev->dev;
+	struct otx2_hw *hw = &pf->hw;
+	int num_vec, err;
+
+	num_vec = pci_msix_vec_count(pdev);
+	hw->irq_name = devm_kmalloc_array(&hw->pdev->dev, num_vec, NAME_SIZE,
+					  GFP_KERNEL);
+	if (!hw->irq_name)
+		return -ENOMEM;
+
+	hw->affinity_mask = devm_kcalloc(&hw->pdev->dev, num_vec,
+					 sizeof(cpumask_var_t), GFP_KERNEL);
+	if (!hw->affinity_mask)
+		return -ENOMEM;
+
+	/* Map CSRs */
+	pf->reg_base = pcim_iomap(pdev, PCI_CFG_REG_BAR_NUM, 0);
+	if (!pf->reg_base) {
+		dev_err(dev, "Unable to map physical function CSRs, aborting\n");
+		return -ENOMEM;
+	}
+
+	err = otx2_check_pf_usable(pf);
+	if (err)
+		return err;
+
+	err = pci_alloc_irq_vectors(hw->pdev, RVU_PF_INT_VEC_CNT,
+				    RVU_PF_INT_VEC_CNT, PCI_IRQ_MSIX);
+	if (err < 0) {
+		dev_err(dev, "%s: Failed to alloc %d IRQ vectors\n",
+			__func__, num_vec);
+		return err;
+	}
+
+	otx2_setup_dev_hw_settings(pf);
+
+	/* Init PF <=> AF mailbox stuff */
+	err = otx2_pfaf_mbox_init(pf);
+	if (err)
+		goto err_free_irq_vectors;
+
+	/* Register mailbox interrupt */
+	err = otx2_register_mbox_intr(pf, true);
+	if (err)
+		goto err_mbox_destroy;
+
+	/* Request AF to attach NPA and NIX LFs to this PF.
+	 * NIX and NPA LFs are needed for this PF to function as a NIC.
+	 */
+	err = otx2_attach_npa_nix(pf);
+	if (err)
+		goto err_disable_mbox_intr;
+
+	err = otx2_realloc_msix_vectors(pf);
+	if (err)
+		goto err_detach_rsrc;
+
+	err = cn10k_lmtst_init(pf);
+	if (err)
+		goto err_detach_rsrc;
+
+	return 0;
+
+err_detach_rsrc:
+	if (pf->hw.lmt_info)
+		free_percpu(pf->hw.lmt_info);
+	if (test_bit(CN10K_LMTST, &pf->hw.cap_flag))
+		qmem_free(pf->dev, pf->dync_lmt);
+	otx2_detach_resources(&pf->mbox);
+err_disable_mbox_intr:
+	otx2_disable_mbox_intr(pf);
+err_mbox_destroy:
+	otx2_pfaf_mbox_destroy(pf);
+err_free_irq_vectors:
+	pci_free_irq_vectors(hw->pdev);
+
+	return err;
+}
+EXPORT_SYMBOL(otx2_init_rsrc);
+
 static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
 	struct device *dev = &pdev->dev;
@@ -2879,7 +2961,6 @@  static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	struct net_device *netdev;
 	struct otx2_nic *pf;
 	struct otx2_hw *hw;
-	int num_vec;
 
 	err = pcim_enable_device(pdev);
 	if (err) {
@@ -2930,72 +3011,14 @@  static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	/* Use CQE of 128 byte descriptor size by default */
 	hw->xqe_size = 128;
 
-	num_vec = pci_msix_vec_count(pdev);
-	hw->irq_name = devm_kmalloc_array(&hw->pdev->dev, num_vec, NAME_SIZE,
-					  GFP_KERNEL);
-	if (!hw->irq_name) {
-		err = -ENOMEM;
-		goto err_free_netdev;
-	}
-
-	hw->affinity_mask = devm_kcalloc(&hw->pdev->dev, num_vec,
-					 sizeof(cpumask_var_t), GFP_KERNEL);
-	if (!hw->affinity_mask) {
-		err = -ENOMEM;
-		goto err_free_netdev;
-	}
-
-	/* Map CSRs */
-	pf->reg_base = pcim_iomap(pdev, PCI_CFG_REG_BAR_NUM, 0);
-	if (!pf->reg_base) {
-		dev_err(dev, "Unable to map physical function CSRs, aborting\n");
-		err = -ENOMEM;
-		goto err_free_netdev;
-	}
-
-	err = otx2_check_pf_usable(pf);
+	err = otx2_init_rsrc(pdev, pf);
 	if (err)
 		goto err_free_netdev;
 
-	err = pci_alloc_irq_vectors(hw->pdev, RVU_PF_INT_VEC_CNT,
-				    RVU_PF_INT_VEC_CNT, PCI_IRQ_MSIX);
-	if (err < 0) {
-		dev_err(dev, "%s: Failed to alloc %d IRQ vectors\n",
-			__func__, num_vec);
-		goto err_free_netdev;
-	}
-
-	otx2_setup_dev_hw_settings(pf);
-
-	/* Init PF <=> AF mailbox stuff */
-	err = otx2_pfaf_mbox_init(pf);
-	if (err)
-		goto err_free_irq_vectors;
-
-	/* Register mailbox interrupt */
-	err = otx2_register_mbox_intr(pf, true);
-	if (err)
-		goto err_mbox_destroy;
-
-	/* Request AF to attach NPA and NIX LFs to this PF.
-	 * NIX and NPA LFs are needed for this PF to function as a NIC.
-	 */
-	err = otx2_attach_npa_nix(pf);
-	if (err)
-		goto err_disable_mbox_intr;
-
-	err = otx2_realloc_msix_vectors(pf);
-	if (err)
-		goto err_detach_rsrc;
-
 	err = otx2_set_real_num_queues(netdev, hw->tx_queues, hw->rx_queues);
 	if (err)
 		goto err_detach_rsrc;
 
-	err = cn10k_lmtst_init(pf);
-	if (err)
-		goto err_detach_rsrc;
-
 	/* Assign default mac address */
 	otx2_get_mac_from_af(netdev);
 
@@ -3118,11 +3141,8 @@  static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	if (test_bit(CN10K_LMTST, &pf->hw.cap_flag))
 		qmem_free(pf->dev, pf->dync_lmt);
 	otx2_detach_resources(&pf->mbox);
-err_disable_mbox_intr:
 	otx2_disable_mbox_intr(pf);
-err_mbox_destroy:
 	otx2_pfaf_mbox_destroy(pf);
-err_free_irq_vectors:
 	pci_free_irq_vectors(hw->pdev);
 err_free_netdev:
 	pci_set_drvdata(pdev, NULL);