bnxt_en: Refactor bnxt_rdma_aux_device_init/uninit functions
authorVikas Gupta <vikas.gupta@broadcom.com>
Tue, 9 Apr 2024 21:54:28 +0000 (14:54 -0700)
committerJakub Kicinski <kuba@kernel.org>
Thu, 11 Apr 2024 02:55:05 +0000 (19:55 -0700)
In its current form, bnxt_rdma_aux_device_init() not only initializes
the necessary data structures of the newly created aux device but also
adds the aux device into the aux bus subsytem. Refactor the logic into
separate functions, first function to initialize the aux device along
with the required resources and second, to actually add the device to
the aux bus subsytem.
This separation helps to create bnxt_en_dev much earlier and save its
resources separately.

Reviewed-by: Andy Gospodarek <andrew.gospodarek@broadcom.com>
Signed-off-by: Vikas Gupta <vikas.gupta@broadcom.com>
Signed-off-by: Michael Chan <michael.chan@broadcom.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Link: https://lore.kernel.org/r/20240409215431.41424-5-michael.chan@broadcom.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/broadcom/bnxt/bnxt.c
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.h

index 8213a37cba3e47ff0e6200011572e3736019ce47..8c24e83ba05061f9405ebbf7313eb54f95254018 100644 (file)
@@ -14786,10 +14786,13 @@ static void bnxt_remove_one(struct pci_dev *pdev)
        if (BNXT_PF(bp))
                bnxt_sriov_disable(bp);
 
-       bnxt_rdma_aux_device_uninit(bp);
+       bnxt_rdma_aux_device_del(bp);
 
        bnxt_ptp_clear(bp);
        unregister_netdev(dev);
+
+       bnxt_rdma_aux_device_uninit(bp);
+
        bnxt_free_l2_filters(bp, true);
        bnxt_free_ntp_fltrs(bp, true);
        if (BNXT_SUPPORTS_MULTI_RSS_CTX(bp))
@@ -15408,13 +15411,15 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        if (BNXT_SUPPORTS_NTUPLE_VNIC(bp))
                bnxt_init_multi_rss_ctx(bp);
 
+       bnxt_rdma_aux_device_init(bp);
+
        rc = register_netdev(dev);
        if (rc)
                goto init_err_cleanup;
 
        bnxt_dl_fw_reporters_create(bp);
 
-       bnxt_rdma_aux_device_init(bp);
+       bnxt_rdma_aux_device_add(bp);
 
        bnxt_print_device_info(bp);
 
@@ -15422,6 +15427,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 
        return 0;
 init_err_cleanup:
+       bnxt_rdma_aux_device_uninit(bp);
        bnxt_dl_unregister(bp);
 init_err_dl:
        bnxt_shutdown_tc(bp);
index cae88747b1101aa003332ee1a592fbb2df1331a1..ae2b367b1226943e4b1baf98e3449ea198dbe7e6 100644 (file)
@@ -291,7 +291,6 @@ void bnxt_rdma_aux_device_uninit(struct bnxt *bp)
 
        aux_priv = bp->aux_priv;
        adev = &aux_priv->aux_dev;
-       auxiliary_device_delete(adev);
        auxiliary_device_uninit(adev);
 }
 
@@ -309,6 +308,14 @@ static void bnxt_aux_dev_release(struct device *dev)
        bp->aux_priv = NULL;
 }
 
+void bnxt_rdma_aux_device_del(struct bnxt *bp)
+{
+       if (!bp->edev)
+               return;
+
+       auxiliary_device_delete(&bp->aux_priv->aux_dev);
+}
+
 static void bnxt_set_edev_info(struct bnxt_en_dev *edev, struct bnxt *bp)
 {
        edev->net = bp->dev;
@@ -332,6 +339,23 @@ static void bnxt_set_edev_info(struct bnxt_en_dev *edev, struct bnxt *bp)
        edev->ulp_tbl->msix_requested = bnxt_get_ulp_msix_num(bp);
 }
 
+void bnxt_rdma_aux_device_add(struct bnxt *bp)
+{
+       struct auxiliary_device *aux_dev;
+       int rc;
+
+       if (!bp->edev)
+               return;
+
+       aux_dev = &bp->aux_priv->aux_dev;
+       rc = auxiliary_device_add(aux_dev);
+       if (rc) {
+               netdev_warn(bp->dev, "Failed to add auxiliary device for ROCE\n");
+               auxiliary_device_uninit(aux_dev);
+               bp->flags &= ~BNXT_FLAG_ROCE_CAP;
+       }
+}
+
 void bnxt_rdma_aux_device_init(struct bnxt *bp)
 {
        struct auxiliary_device *aux_dev;
@@ -386,13 +410,6 @@ void bnxt_rdma_aux_device_init(struct bnxt *bp)
        bp->edev = edev;
        bnxt_set_edev_info(edev, bp);
 
-       rc = auxiliary_device_add(aux_dev);
-       if (rc) {
-               netdev_warn(bp->dev,
-                           "Failed to add auxiliary device for ROCE\n");
-               goto aux_dev_uninit;
-       }
-
        return;
 
 aux_dev_uninit:
index f8df4095399fab532c2d1e4a0082dcf2bc2e9028..ae7266ddf1679acad8b11a1aa8dd56ecd3810f6e 100644 (file)
@@ -103,6 +103,8 @@ void bnxt_ulp_irq_stop(struct bnxt *bp);
 void bnxt_ulp_irq_restart(struct bnxt *bp, int err);
 void bnxt_ulp_async_events(struct bnxt *bp, struct hwrm_async_event_cmpl *cmpl);
 void bnxt_rdma_aux_device_uninit(struct bnxt *bp);
+void bnxt_rdma_aux_device_del(struct bnxt *bp);
+void bnxt_rdma_aux_device_add(struct bnxt *bp);
 void bnxt_rdma_aux_device_init(struct bnxt *bp);
 int bnxt_register_dev(struct bnxt_en_dev *edev, struct bnxt_ulp_ops *ulp_ops,
                      void *handle);