]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
octeontx2-pf: Define common API for HW resources configuration
authorGeetha sowjanya <gakula@marvell.com>
Wed, 23 Oct 2024 16:18:40 +0000 (21:48 +0530)
committerJakub Kicinski <kuba@kernel.org>
Thu, 31 Oct 2024 00:50:32 +0000 (17:50 -0700)
Define new API "otx2_init_rsrc" and move 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>
Reviewed-by: Jiri Pirko <jiri@resnulli.us>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20241023161843.15543-2-gakula@marvell.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c

index f27a3456ae64fe575d30e187411ba27b0480719a..a47001a2b93f980f7d0deaa67ba1c44d5a337264 100644 (file)
@@ -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);
index 5492dea547a190e2f64c9d866e62c7eaa535f9b7..180a16b42ac3be7c76216893b1a907389c5bc4ae 100644 (file)
@@ -2872,6 +2872,87 @@ 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;
+}
+
 static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
        struct device *dev = &pdev->dev;
@@ -2879,7 +2960,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 +3010,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 +3140,8 @@ err_detach_rsrc:
        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);