scsi: fnic: Add and use fnic number
authorKaran Tilak Kumar <kartilak@cisco.com>
Mon, 11 Dec 2023 17:36:06 +0000 (09:36 -0800)
committerMartin K. Petersen <martin.petersen@oracle.com>
Thu, 14 Dec 2023 03:11:33 +0000 (22:11 -0500)
Add fnic_num in fnic.h to identify fnic in a multi-fnic environment.
Increment and set the fnic number during driver load in fnic_probe.
Replace the host number with fnic number in debugfs.

Reviewed-by: Sesidhar Baddela <sebaddel@cisco.com>
Reviewed-by: Arulprabhu Ponnusamy <arulponn@cisco.com>
Signed-off-by: Karan Tilak Kumar <kartilak@cisco.com>
Link: https://lore.kernel.org/r/20231211173617.932990-3-kartilak@cisco.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/fnic/fnic.h
drivers/scsi/fnic/fnic_main.c

index 22cef283b2b97e8da5bf35a82cfb7c4f63da710a..721a31a03628a16561c5bba40247f57e71596187 100644 (file)
@@ -216,6 +216,7 @@ struct fnic_event {
 
 /* Per-instance private data structure */
 struct fnic {
+       int fnic_num;
        struct fc_lport *lport;
        struct fcoe_ctlr ctlr;          /* FIP FCoE controller structure */
        struct vnic_dev_bar bar0;
index f27f9319e0b2e748d3a2094c4e9341c388500183..3044723e125ea6bea88b071ef6eba14a39dce358 100644 (file)
@@ -39,6 +39,7 @@ static struct kmem_cache *fnic_sgl_cache[FNIC_SGL_NUM_CACHES];
 static struct kmem_cache *fnic_io_req_cache;
 static LIST_HEAD(fnic_list);
 static DEFINE_SPINLOCK(fnic_list_lock);
+static DEFINE_IDA(fnic_ida);
 
 /* Supported devices by fnic module */
 static struct pci_device_id fnic_id_table[] = {
@@ -583,7 +584,8 @@ static int fnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        struct fc_lport *lp;
        struct fnic *fnic;
        mempool_t *pool;
-       int err;
+       int err = 0;
+       int fnic_id = 0;
        int i;
        unsigned long flags;
 
@@ -597,8 +599,16 @@ static int fnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
                err = -ENOMEM;
                goto err_out;
        }
+
        host = lp->host;
        fnic = lport_priv(lp);
+
+       fnic_id = ida_alloc(&fnic_ida, GFP_KERNEL);
+       if (fnic_id < 0) {
+               pr_err("Unable to alloc fnic ID\n");
+               err = fnic_id;
+               goto err_out_ida_alloc;
+       }
        fnic->lport = lp;
        fnic->ctlr.lp = lp;
 
@@ -608,7 +618,7 @@ static int fnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
                 host->host_no);
 
        host->transportt = fnic_fc_transport;
-
+       fnic->fnic_num = fnic_id;
        fnic_stats_debugfs_init(fnic);
 
        /* Setup PCI resources */
@@ -951,6 +961,8 @@ err_out_disable_device:
        pci_disable_device(pdev);
 err_out_free_hba:
        fnic_stats_debugfs_remove(fnic);
+       ida_free(&fnic_ida, fnic->fnic_num);
+err_out_ida_alloc:
        scsi_host_put(lp->host);
 err_out:
        return err;
@@ -1031,6 +1043,7 @@ static void fnic_remove(struct pci_dev *pdev)
        fnic_iounmap(fnic);
        pci_release_regions(pdev);
        pci_disable_device(pdev);
+       ida_free(&fnic_ida, fnic->fnic_num);
        scsi_host_put(lp->host);
 }
 
@@ -1168,6 +1181,7 @@ static void __exit fnic_cleanup_module(void)
        fnic_trace_free();
        fnic_fc_trace_free();
        fnic_debugfs_terminate();
+       ida_destroy(&fnic_ida);
 }
 
 module_init(fnic_init_module);