scsi: ibmvfc: Init/free event pool during queue allocation/free
authorTyrel Datwyler <tyreld@linux.ibm.com>
Thu, 14 Jan 2021 20:31:30 +0000 (14:31 -0600)
committerMartin K. Petersen <martin.petersen@oracle.com>
Fri, 15 Jan 2021 03:27:43 +0000 (22:27 -0500)
The event pool and CRQ used to be separate entities of the adapter host
structure and as such were allocated and freed independently of each
other. Recent work as defined a generic queue structure with an event pool
specific to each queue. As such the event pool for each queue shouldn't be
allocated/freed independently, but instead performed as part of the queue
allocation/free routines.

Move the calls to ibmvfc_event_pool_{init|free} into
ibmvfc_{alloc|free}_queue respectively. The only functional change here is
that the CRQ cannot be released in ibmvfc_remove until after the event pool
has been successfully purged since releasing the queue will also free the
event pool.

Link: https://lore.kernel.org/r/20210114203148.246656-4-tyreld@linux.ibm.com
Reviewed-by: Brian King <brking@linux.vnet.ibm.com>
Signed-off-by: Tyrel Datwyler <tyreld@linux.ibm.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/ibmvscsi/ibmvfc.c

index 445d5d5bccb6d68e14efe01ee4e543e44bea603b..82f4dc5635f03481246a4ee98d7ceb8d274ac27c 100644 (file)
@@ -807,6 +807,8 @@ static void ibmvfc_free_queue(struct ibmvfc_host *vhost,
        dma_unmap_single(dev, queue->msg_token, PAGE_SIZE, DMA_BIDIRECTIONAL);
        free_page((unsigned long)queue->msgs.handle);
        queue->msgs.handle = NULL;
+
+       ibmvfc_free_event_pool(vhost, queue);
 }
 
 /**
@@ -5019,6 +5021,10 @@ static int ibmvfc_alloc_queue(struct ibmvfc_host *vhost,
        switch (fmt) {
        case IBMVFC_CRQ_FMT:
                fmt_size = sizeof(*queue->msgs.crq);
+               if (ibmvfc_init_event_pool(vhost, queue)) {
+                       dev_err(dev, "Couldn't initialize event pool.\n");
+                       return -ENOMEM;
+               }
                break;
        case IBMVFC_ASYNC_FMT:
                fmt_size = sizeof(*queue->msgs.async);
@@ -5333,13 +5339,8 @@ static int ibmvfc_probe(struct vio_dev *vdev, const struct vio_device_id *id)
                goto kill_kthread;
        }
 
-       if ((rc = ibmvfc_init_event_pool(vhost, &vhost->crq))) {
-               dev_err(dev, "Couldn't initialize event pool. rc=%d\n", rc);
-               goto release_crq;
-       }
-
        if ((rc = scsi_add_host(shost, dev)))
-               goto release_event_pool;
+               goto release_crq;
 
        fc_host_dev_loss_tmo(shost) = IBMVFC_DEV_LOSS_TMO;
 
@@ -5362,8 +5363,6 @@ static int ibmvfc_probe(struct vio_dev *vdev, const struct vio_device_id *id)
 
 remove_shost:
        scsi_remove_host(shost);
-release_event_pool:
-       ibmvfc_free_event_pool(vhost, &vhost->crq);
 release_crq:
        ibmvfc_release_crq_queue(vhost);
 kill_kthread:
@@ -5398,7 +5397,6 @@ static int ibmvfc_remove(struct vio_dev *vdev)
        spin_unlock_irqrestore(vhost->host->host_lock, flags);
 
        ibmvfc_wait_while_resetting(vhost);
-       ibmvfc_release_crq_queue(vhost);
        kthread_stop(vhost->work_thread);
        fc_remove_host(vhost->host);
        scsi_remove_host(vhost->host);
@@ -5408,7 +5406,7 @@ static int ibmvfc_remove(struct vio_dev *vdev)
        list_splice_init(&vhost->purge, &purge);
        spin_unlock_irqrestore(vhost->host->host_lock, flags);
        ibmvfc_complete_purge(&purge);
-       ibmvfc_free_event_pool(vhost, &vhost->crq);
+       ibmvfc_release_crq_queue(vhost);
 
        ibmvfc_free_mem(vhost);
        spin_lock(&ibmvfc_driver_lock);