scsi: mpt3sas: Separate out RDPQ allocation to new function
authorSuganath Prabu <suganath-prabu.subramani@broadcom.com>
Thu, 23 Apr 2020 07:23:14 +0000 (03:23 -0400)
committerMartin K. Petersen <martin.petersen@oracle.com>
Fri, 24 Apr 2020 17:08:17 +0000 (13:08 -0400)
For readability separate out RDPQ allocations to new function
base_alloc_rdpq_dma_pool().

Link: https://lore.kernel.org/r/1587626596-1044-4-git-send-email-suganath-prabu.subramani@broadcom.com
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Suganath Prabu <suganath-prabu.subramani@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/mpt3sas/mpt3sas_base.c

index f0eace3..cabbdc2 100644 (file)
@@ -4939,6 +4939,49 @@ mpt3sas_check_same_4gb_region(long reply_pool_start_address, u32 pool_sz)
 }
 
 /**
+ * base_alloc_rdpq_dma_pool - Allocating DMA'able memory
+ *                     for reply queues.
+ * @ioc: per adapter object
+ * @sz: DMA Pool size
+ * Return: 0 for success, non-zero for failure.
+ */
+static int
+base_alloc_rdpq_dma_pool(struct MPT3SAS_ADAPTER *ioc, int sz)
+{
+       int i;
+       int count = ioc->rdpq_array_enable ? ioc->reply_queue_count : 1;
+
+       ioc->reply_post = kcalloc(count, sizeof(struct reply_post_struct),
+                       GFP_KERNEL);
+       if (!ioc->reply_post)
+               return -ENOMEM;
+       ioc->reply_post_free_dma_pool =
+           dma_pool_create("reply_post_free pool",
+           &ioc->pdev->dev, sz, 16, 0);
+       if (!ioc->reply_post_free_dma_pool)
+               return -ENOMEM;
+       i = 0;
+       do {
+               ioc->reply_post[i].reply_post_free =
+                   dma_pool_zalloc(ioc->reply_post_free_dma_pool,
+                   GFP_KERNEL,
+                   &ioc->reply_post[i].reply_post_free_dma);
+               if (!ioc->reply_post[i].reply_post_free)
+                       return -ENOMEM;
+               dinitprintk(ioc,
+                       ioc_info(ioc, "reply post free pool (0x%p): depth(%d),"
+                           "element_size(%d), pool_size(%d kB)\n",
+                           ioc->reply_post[i].reply_post_free,
+                           ioc->reply_post_queue_depth, 8, sz / 1024));
+               dinitprintk(ioc,
+                       ioc_info(ioc, "reply_post_free_dma = (0x%llx)\n",
+                           (u64)ioc->reply_post[i].reply_post_free_dma));
+
+       } while (ioc->rdpq_array_enable && ++i < ioc->reply_queue_count);
+       return 0;
+}
+
+/**
  * _base_allocate_memory_pools - allocate start of day memory pools
  * @ioc: per adapter object
  *
@@ -5113,41 +5156,9 @@ _base_allocate_memory_pools(struct MPT3SAS_ADAPTER *ioc)
        sz = reply_post_free_sz;
        if (_base_is_controller_msix_enabled(ioc) && !ioc->rdpq_array_enable)
                sz *= ioc->reply_queue_count;
-
-       ioc->reply_post = kcalloc((ioc->rdpq_array_enable) ?
-           (ioc->reply_queue_count):1,
-           sizeof(struct reply_post_struct), GFP_KERNEL);
-
-       if (!ioc->reply_post) {
-               ioc_err(ioc, "reply_post_free pool: kcalloc failed\n");
+       if (base_alloc_rdpq_dma_pool(ioc, sz))
                goto out;
-       }
-       ioc->reply_post_free_dma_pool = dma_pool_create("reply_post_free pool",
-           &ioc->pdev->dev, sz, 16, 0);
-       if (!ioc->reply_post_free_dma_pool) {
-               ioc_err(ioc, "reply_post_free pool: dma_pool_create failed\n");
-               goto out;
-       }
-       i = 0;
-       do {
-               ioc->reply_post[i].reply_post_free =
-                   dma_pool_zalloc(ioc->reply_post_free_dma_pool,
-                   GFP_KERNEL,
-                   &ioc->reply_post[i].reply_post_free_dma);
-               if (!ioc->reply_post[i].reply_post_free) {
-                       ioc_err(ioc, "reply_post_free pool: dma_pool_alloc failed\n");
-                       goto out;
-               }
-               dinitprintk(ioc,
-                           ioc_info(ioc, "reply post free pool (0x%p): depth(%d), element_size(%d), pool_size(%d kB)\n",
-                                    ioc->reply_post[i].reply_post_free,
-                                    ioc->reply_post_queue_depth,
-                                    8, sz / 1024));
-               dinitprintk(ioc,
-                           ioc_info(ioc, "reply_post_free_dma = (0x%llx)\n",
-                                    (u64)ioc->reply_post[i].reply_post_free_dma));
-               total_sz += sz;
-       } while (ioc->rdpq_array_enable && (++i < ioc->reply_queue_count));
+       total_sz += sz * (!ioc->rdpq_array_enable ? 1 : ioc->reply_queue_count);
 
        ioc->scsiio_depth = ioc->hba_queue_depth -
            ioc->hi_priority_depth - ioc->internal_depth;