All of lore.kernel.org
 help / color / mirror / Atom feed
* [v1 0/5] mpt3sas: Fix changing coherent mask after allocation
@ 2020-04-15 13:25 Suganath Prabu
  2020-04-15 13:25 ` [v1 1/5] mpt3sas: Don't change the dma coherent mask after allocations Suganath Prabu
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Suganath Prabu @ 2020-04-15 13:25 UTC (permalink / raw)
  To: linux-scsi; +Cc: hch, Sathya.Prakash, sreekanth.reddy, Suganath Prabu S

From: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>

* Set the coherent dma mask to 64 bit and then allocate RDPQ pools,
make sure that each of the RDPQ pools satisfies the 4gb boundary
restriction. if any of the RDPQ pool doesn't satisfies this
restriction then deallocate the pools and reallocate them after
changing the coherent dma mask to 32 bit.
* With this there is no need to change DMA coherent
mask when there are outstanding allocations in mpt3sas.
* Code-Refactoring

Suganath Prabu S (5):
  mpt3sas: Don't change the dma coherent mask after      allocations
  mpt3sas: Rename function name is_MSB_are_same
  mpt3sas: Separate out RDPQ allocation to new function.
  mpt3sas: Handle RDPQ DMA allocation in same 4G region
  mpt3sas: Update mpt3sas version to 33.101.00.00

 drivers/scsi/mpt3sas/mpt3sas_base.c | 279 +++++++++++++++++++++---------------
 drivers/scsi/mpt3sas/mpt3sas_base.h |   9 +-
 2 files changed, 171 insertions(+), 117 deletions(-)

-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [v1 1/5] mpt3sas: Don't change the dma coherent mask after  allocations
  2020-04-15 13:25 [v1 0/5] mpt3sas: Fix changing coherent mask after allocation Suganath Prabu
@ 2020-04-15 13:25 ` Suganath Prabu
  2020-04-22  6:34   ` Christoph Hellwig
  2020-04-15 13:25 ` [v1 2/5] mpt3sas: Rename function name is_MSB_are_same Suganath Prabu
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Suganath Prabu @ 2020-04-15 13:25 UTC (permalink / raw)
  To: linux-scsi; +Cc: hch, Sathya.Prakash, sreekanth.reddy, Suganath Prabu S

From: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>

Currently driver is initially setting the dma coherent mask to 32 bit
and then after allocating the Reply Descriptor Post Queues(RDPQ) pools
it changes the dma coherent mask to 64/63 according to HBA generation.

But the DMA layer does not allow changing the DMA coherent mask after
there are outstanding allocations.

So, updating the driver to stop changing the dma coherent mask after
allocations.

Rename ioc variable "dma_mask" to "is_dma_32bit" and use it to set 32
bit DMA.
---
v1 Change log:
1) Incorporated the review comments from Christoph Hellwig

Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
---
 drivers/scsi/mpt3sas/mpt3sas_base.c | 83 ++++++++++++++-----------------------
 drivers/scsi/mpt3sas/mpt3sas_base.h |  4 +-
 2 files changed, 32 insertions(+), 55 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 663782b..8e937c8 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -2806,55 +2806,40 @@ _base_build_sg_ieee(struct MPT3SAS_ADAPTER *ioc, void *psge,
 static int
 _base_config_dma_addressing(struct MPT3SAS_ADAPTER *ioc, struct pci_dev *pdev)
 {
-	u64 required_mask, coherent_mask;
 	struct sysinfo s;
-	/* Set 63 bit DMA mask for all SAS3 and SAS35 controllers */
-	int dma_mask = (ioc->hba_mpi_version_belonged > MPI2_VERSION) ? 63 : 64;
+	char *desc = "64";
+	u64 consistent_dma_mask = DMA_BIT_MASK(64);
+	u64 required_mask = dma_get_required_mask(&pdev->dev);
 
-	if (ioc->is_mcpu_endpoint)
-		goto try_32bit;
-
-	required_mask = dma_get_required_mask(&pdev->dev);
-	if (sizeof(dma_addr_t) == 4 || required_mask == 32)
-		goto try_32bit;
-
-	if (ioc->dma_mask)
-		coherent_mask = DMA_BIT_MASK(dma_mask);
-	else
-		coherent_mask = DMA_BIT_MASK(32);
-
-	if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(dma_mask)) ||
-	    dma_set_coherent_mask(&pdev->dev, coherent_mask))
+	if (ioc->is_mcpu_endpoint || ioc->is_dma_32bit ||
+	    sizeof(dma_addr_t) == 4 || required_mask == DMA_BIT_MASK(32))
 		goto try_32bit;
-
-	ioc->base_add_sg_single = &_base_add_sg_single_64;
-	ioc->sge_size = sizeof(Mpi2SGESimple64_t);
-	ioc->dma_mask = dma_mask;
-	goto out;
-
- try_32bit:
-	if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)))
+	/*
+	 * Set 63 bit DMA mask for all SAS3 and SAS35 controllers
+	 */
+	if (ioc->hba_mpi_version_belonged > MPI2_VERSION) {
+		consistent_dma_mask = DMA_BIT_MASK(63);
+		desc = "63";
+	}
+	if (!dma_set_mask(&pdev->dev, consistent_dma_mask) &&
+	    !dma_set_coherent_mask(&pdev->dev, consistent_dma_mask)) {
+		ioc->base_add_sg_single = &_base_add_sg_single_64;
+		ioc->sge_size = sizeof(Mpi2SGESimple64_t);
+		goto out;
+	}
+try_32bit:
+	if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))
+	    && !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32))) {
+		ioc->base_add_sg_single = &_base_add_sg_single_32;
+		ioc->sge_size = sizeof(Mpi2SGESimple32_t);
+		desc = "32";
+	} else
 		return -ENODEV;
-
-	ioc->base_add_sg_single = &_base_add_sg_single_32;
-	ioc->sge_size = sizeof(Mpi2SGESimple32_t);
-	ioc->dma_mask = 32;
- out:
+out:
 	si_meminfo(&s);
-	ioc_info(ioc, "%d BIT PCI BUS DMA ADDRESSING SUPPORTED, total mem (%ld kB)\n",
-		 ioc->dma_mask, convert_to_kb(s.totalram));
-
-	return 0;
-}
-
-static int
-_base_change_consistent_dma_mask(struct MPT3SAS_ADAPTER *ioc,
-				      struct pci_dev *pdev)
-{
-	if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(ioc->dma_mask))) {
-		if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))
-			return -ENODEV;
-	}
+	ioc_info(ioc,
+		"%s BIT PCI BUS DMA ADDRESSING SUPPORTED, total mem (%ld kB)\n",
+		desc, convert_to_kb(s.totalram));
 	return 0;
 }
 
@@ -5169,14 +5154,6 @@ _base_allocate_memory_pools(struct MPT3SAS_ADAPTER *ioc)
 		total_sz += sz;
 	} while (ioc->rdpq_array_enable && (++i < ioc->reply_queue_count));
 
-	if (ioc->dma_mask > 32) {
-		if (_base_change_consistent_dma_mask(ioc, ioc->pdev) != 0) {
-			ioc_warn(ioc, "no suitable consistent DMA mask for %s\n",
-				 pci_name(ioc->pdev));
-			goto out;
-		}
-	}
-
 	ioc->scsiio_depth = ioc->hba_queue_depth -
 	    ioc->hi_priority_depth - ioc->internal_depth;
 
@@ -7158,7 +7135,7 @@ mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc)
 	ioc->smp_affinity_enable = smp_affinity_enable;
 
 	ioc->rdpq_array_enable_assigned = 0;
-	ioc->dma_mask = 0;
+	ioc->is_dma_32bit = 0;
 	if (ioc->is_aero_ioc)
 		ioc->base_readl = &_base_readl_aero;
 	else
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h
index e719715..396ac96 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.h
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.h
@@ -1026,7 +1026,7 @@ typedef void (*MPT3SAS_FLUSH_RUNNING_CMDS)(struct MPT3SAS_ADAPTER *ioc);
  * @ir_firmware: IR firmware present
  * @bars: bitmask of BAR's that must be configured
  * @mask_interrupts: ignore interrupt
- * @dma_mask: used to set the consistent dma mask
+ * @is_dma_32bit: used to set the consistent dma mask
  * @pci_access_mutex: Mutex to synchronize ioctl, sysfs show path and
  *			pci resource handling
  * @fault_reset_work_q_name: fw fault work queue
@@ -1205,7 +1205,7 @@ struct MPT3SAS_ADAPTER {
 	u8		ir_firmware;
 	int		bars;
 	u8		mask_interrupts;
-	int		dma_mask;
+	int		is_dma_32bit;
 
 	/* fw fault handler */
 	char		fault_reset_work_q_name[20];
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [v1 2/5] mpt3sas: Rename function name is_MSB_are_same
  2020-04-15 13:25 [v1 0/5] mpt3sas: Fix changing coherent mask after allocation Suganath Prabu
  2020-04-15 13:25 ` [v1 1/5] mpt3sas: Don't change the dma coherent mask after allocations Suganath Prabu
@ 2020-04-15 13:25 ` Suganath Prabu
  2020-04-22  6:34   ` Christoph Hellwig
  2020-04-15 13:25 ` [v1 3/5] mpt3sas: Separate out RDPQ allocation to new function Suganath Prabu
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Suganath Prabu @ 2020-04-15 13:25 UTC (permalink / raw)
  To: linux-scsi; +Cc: hch, Sathya.Prakash, sreekanth.reddy, Suganath Prabu S

From: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>

Renamed is_MSB_are_same() to mpt3sas_check_same_4gb_region()
for better readability.

Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
---
 drivers/scsi/mpt3sas/mpt3sas_base.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 8e937c8..7f7b5af 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -4920,7 +4920,7 @@ _base_release_memory_pools(struct MPT3SAS_ADAPTER *ioc)
 }
 
 /**
- * is_MSB_are_same - checks whether all reply queues in a set are
+ * mpt3sas_check_same_4gb_region - checks whether all reply queues in a set are
  *	having same upper 32bits in their base memory address.
  * @reply_pool_start_address: Base address of a reply queue set
  * @pool_sz: Size of single Reply Descriptor Post Queues pool size
@@ -4930,7 +4930,7 @@ _base_release_memory_pools(struct MPT3SAS_ADAPTER *ioc)
  */
 
 static int
-is_MSB_are_same(long reply_pool_start_address, u32 pool_sz)
+mpt3sas_check_same_4gb_region(long reply_pool_start_address, u32 pool_sz)
 {
 	long reply_pool_end_address;
 
@@ -5382,7 +5382,7 @@ _base_allocate_memory_pools(struct MPT3SAS_ADAPTER *ioc)
 	 * Actual requirement is not alignment, but we need start and end of
 	 * DMA address must have same upper 32 bit address.
 	 */
-	if (!is_MSB_are_same((long)ioc->sense, sz)) {
+	if (!mpt3sas_check_same_4gb_region((long)ioc->sense, sz)) {
 		//Release Sense pool & Reallocate
 		dma_pool_free(ioc->sense_dma_pool, ioc->sense, ioc->sense_dma);
 		dma_pool_destroy(ioc->sense_dma_pool);
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [v1 3/5] mpt3sas: Separate out RDPQ allocation to new function.
  2020-04-15 13:25 [v1 0/5] mpt3sas: Fix changing coherent mask after allocation Suganath Prabu
  2020-04-15 13:25 ` [v1 1/5] mpt3sas: Don't change the dma coherent mask after allocations Suganath Prabu
  2020-04-15 13:25 ` [v1 2/5] mpt3sas: Rename function name is_MSB_are_same Suganath Prabu
@ 2020-04-15 13:25 ` Suganath Prabu
  2020-04-22  6:39   ` Christoph Hellwig
  2020-04-15 13:25 ` [v1 4/5] mpt3sas: Handle RDPQ DMA allocation in same 4G region Suganath Prabu
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Suganath Prabu @ 2020-04-15 13:25 UTC (permalink / raw)
  To: linux-scsi; +Cc: hch, Sathya.Prakash, sreekanth.reddy, Suganath Prabu S

From: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>

For readability separate out RDPQ allocations to new function
base_alloc_rdpq_dma_pool().

Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
---
 drivers/scsi/mpt3sas/mpt3sas_base.c | 85 ++++++++++++++++++++++---------------
 1 file changed, 51 insertions(+), 34 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 7f7b5af..27c829e 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -4944,6 +4944,55 @@ 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;
+
+	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");
+		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) {
+		ioc_err(ioc, "reply_post_free pool: dma_pool_create failed\n");
+		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) {
+			ioc_err(ioc, "reply_post_free pool: dma_pool_alloc failed\n");
+			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
  *
@@ -5118,41 +5167,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;
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [v1 4/5] mpt3sas: Handle RDPQ DMA allocation in same 4G region
  2020-04-15 13:25 [v1 0/5] mpt3sas: Fix changing coherent mask after allocation Suganath Prabu
                   ` (2 preceding siblings ...)
  2020-04-15 13:25 ` [v1 3/5] mpt3sas: Separate out RDPQ allocation to new function Suganath Prabu
@ 2020-04-15 13:25 ` Suganath Prabu
  2020-04-22  6:41   ` Christoph Hellwig
  2020-04-15 13:25 ` [v1 5/5] mpt3sas: Update mpt3sas version to 33.101.00.00 Suganath Prabu
  2020-04-22  3:36 ` [v1 0/5] mpt3sas: Fix changing coherent mask after allocation Martin K. Petersen
  5 siblings, 1 reply; 13+ messages in thread
From: Suganath Prabu @ 2020-04-15 13:25 UTC (permalink / raw)
  To: linux-scsi; +Cc: hch, Sathya.Prakash, sreekanth.reddy, Suganath Prabu S

From: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>

For INVADER_SERIES each set of 8 reply queues (0 - 7, 8 - 15,..) and
VENTURA_SERIES each set of 16 reply queues (0 - 15, 16 - 31,..) should
be within 4 GB boundary. Driver uses limitation of VENTURA_SERIES to
manage INVADER_SERIES as well. So here driver is allocating the DMA able
memory for RDPQ's accordingly.

1) At driver load, set DMA Mask to 64 and allocate memory for RDPQ's.
2) Check if allocated resources for RDPQ are in the same 4GB range.
3) If #2 is true, continue with 64 bit DMA and go to #6
4) If #2 is false, then free all the resources from #1.
5) Set DMA mask to 32 and allocate RDPQ's.
6) Proceed with driver loading and other allocations
---
v1 Change log:
1) Use one dma pool for RDPQ's, thus removes the logic of using second
dma pool with align.

Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
---
 drivers/scsi/mpt3sas/mpt3sas_base.c | 153 +++++++++++++++++++++++++-----------
 drivers/scsi/mpt3sas/mpt3sas_base.h |   1 +
 2 files changed, 107 insertions(+), 47 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 27c829e..add23d7 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -3345,7 +3345,6 @@ mpt3sas_base_map_resources(struct MPT3SAS_ADAPTER *ioc)
 
 	pci_set_master(pdev);
 
-
 	if (_base_config_dma_addressing(ioc, pdev) != 0) {
 		ioc_warn(ioc, "no suitable DMA mask for %s\n", pci_name(pdev));
 		r = -ENODEV;
@@ -4812,8 +4811,8 @@ _base_release_memory_pools(struct MPT3SAS_ADAPTER *ioc)
 {
 	int i = 0;
 	int j = 0;
+	int dma_alloc_count = 0;
 	struct chain_tracker *ct;
-	struct reply_post_struct *rps;
 
 	dexitprintk(ioc, ioc_info(ioc, "%s\n", __func__));
 
@@ -4855,29 +4854,34 @@ _base_release_memory_pools(struct MPT3SAS_ADAPTER *ioc)
 	}
 
 	if (ioc->reply_post) {
-		do {
-			rps = &ioc->reply_post[i];
-			if (rps->reply_post_free) {
-				dma_pool_free(
-				    ioc->reply_post_free_dma_pool,
-				    rps->reply_post_free,
-				    rps->reply_post_free_dma);
-				dexitprintk(ioc,
-					    ioc_info(ioc, "reply_post_free_pool(0x%p): free\n",
-						     rps->reply_post_free));
-				rps->reply_post_free = NULL;
+		dma_alloc_count = DIV_ROUND_UP(ioc->reply_queue_count,
+				RDPQ_MAX_INDEX_IN_ONE_CHUNK);
+		for (i = 0; i < ioc->reply_queue_count; i++) {
+			if (i % RDPQ_MAX_INDEX_IN_ONE_CHUNK == 0
+			    && dma_alloc_count) {
+				if (ioc->reply_post[i].reply_post_free) {
+					dma_pool_free(
+					    ioc->reply_post_free_dma_pool,
+					    ioc->reply_post[i].reply_post_free,
+					ioc->reply_post[i].reply_post_free_dma);
+					dexitprintk(ioc, ioc_info(ioc,
+					   "reply_post_free_pool(0x%p): free\n",
+					   ioc->reply_post[i].reply_post_free));
+					ioc->reply_post[i].reply_post_free =
+									NULL;
+				}
+				--dma_alloc_count;
 			}
-		} while (ioc->rdpq_array_enable &&
-			   (++i < ioc->reply_queue_count));
+		}
+		dma_pool_destroy(ioc->reply_post_free_dma_pool);
 		if (ioc->reply_post_free_array &&
 			ioc->rdpq_array_enable) {
 			dma_pool_free(ioc->reply_post_free_array_dma_pool,
-				ioc->reply_post_free_array,
-				ioc->reply_post_free_array_dma);
+			    ioc->reply_post_free_array,
+			    ioc->reply_post_free_array_dma);
 			ioc->reply_post_free_array = NULL;
 		}
 		dma_pool_destroy(ioc->reply_post_free_array_dma_pool);
-		dma_pool_destroy(ioc->reply_post_free_dma_pool);
 		kfree(ioc->reply_post);
 	}
 
@@ -4953,42 +4957,82 @@ mpt3sas_check_same_4gb_region(long reply_pool_start_address, u32 pool_sz)
 static int
 base_alloc_rdpq_dma_pool(struct MPT3SAS_ADAPTER *ioc, int sz)
 {
-	int i;
+	int i = 0;
+	u32 dma_alloc_count = 0;
+	int reply_post_free_sz = ioc->reply_post_queue_depth *
+		sizeof(Mpi2DefaultReplyDescriptor_t);
 
 	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");
 		return -ENOMEM;
 	}
-	ioc->reply_post_free_dma_pool = dma_pool_create("reply_post_free pool",
-			&ioc->pdev->dev, sz, 16, 0);
+	/*
+	 *  For INVADER_SERIES each set of 8 reply queues(0-7, 8-15, ..) and
+	 *  VENTURA_SERIES each set of 16 reply queues(0-15, 16-31, ..) should
+	 *  be within 4GB boundary i.e reply queues in a set must have same
+	 *  upper 32-bits in their memory address. so here driver is allocating
+	 *  the DMA'able memory for reply queues according.
+	 *  Driver uses limitation of
+	 *  VENTURA_SERIES to manage INVADER_SERIES as well.
+	 */
+	dma_alloc_count = DIV_ROUND_UP(ioc->reply_queue_count,
+				RDPQ_MAX_INDEX_IN_ONE_CHUNK);
+	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");
 		return -ENOMEM;
 	}
-	i = 0;
-	do {
-		ioc->reply_post[i].reply_post_free =
-			dma_pool_zalloc(ioc->reply_post_free_dma_pool,
+	for (i = 0; i < ioc->reply_queue_count; i++) {
+		if ((i % RDPQ_MAX_INDEX_IN_ONE_CHUNK == 0) && dma_alloc_count) {
+			ioc->reply_post[i].reply_post_free =
+			    dma_pool_alloc(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");
-			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));
+			if (!ioc->reply_post[i].reply_post_free) {
+				ioc_err(ioc, "reply_post_free pool: "
+				    "dma_pool_alloc failed\n");
+				return -ENOMEM;
+			}
+			/*
+			 * Each set of RDPQ pool must satisfy 4gb boundary
+			 * restriction.
+			 * 1) Check if allocated resources for RDPQ pool are in
+			 *	the same 4GB range.
+			 * 2) If #1 is true, continue with 64 bit DMA.
+			 * 3) If #1 is false, return 1. which means free all the
+			 * resources and set DMA mask to 32 and allocate.
+			 */
+			if (!mpt3sas_check_same_4gb_region(
+				(long)ioc->reply_post[i].reply_post_free, sz)) {
+				dinitprintk(ioc,
+				    ioc_err(ioc, "bad Replypost free pool(0x%p)"
+				    "reply_post_free_dma = (0x%llx)\n",
+				    ioc->reply_post[i].reply_post_free,
+				    (unsigned long long)
+				    ioc->reply_post[i].reply_post_free_dma));
+				return -EAGAIN;
+			}
+			memset(ioc->reply_post[i].reply_post_free, 0,
+						RDPQ_MAX_INDEX_IN_ONE_CHUNK *
+						reply_post_free_sz);
+			dma_alloc_count--;
 
-	} while (ioc->rdpq_array_enable && (++i < ioc->reply_queue_count));
+		} else {
+			ioc->reply_post[i].reply_post_free =
+			    (Mpi2ReplyDescriptorsUnion_t *)
+			    ((long)ioc->reply_post[i-1].reply_post_free
+			    + reply_post_free_sz);
+			ioc->reply_post[i].reply_post_free_dma =
+			    (dma_addr_t)
+			    (ioc->reply_post[i-1].reply_post_free_dma +
+			    reply_post_free_sz);
+		}
+	}
 	return 0;
 }
 
@@ -5006,10 +5050,12 @@ _base_allocate_memory_pools(struct MPT3SAS_ADAPTER *ioc)
 	u16 chains_needed_per_io;
 	u32 sz, total_sz, reply_post_free_sz, reply_post_free_array_sz;
 	u32 retry_sz;
+	u32 rdpq_sz = 0;
 	u16 max_request_credit, nvme_blocks_needed;
 	unsigned short sg_tablesize;
 	u16 sge_size;
 	int i, j;
+	int ret = 0;
 	struct chain_tracker *ct;
 
 	dinitprintk(ioc, ioc_info(ioc, "%s\n", __func__));
@@ -5163,14 +5209,28 @@ _base_allocate_memory_pools(struct MPT3SAS_ADAPTER *ioc)
 	/* reply post queue, 16 byte align */
 	reply_post_free_sz = ioc->reply_post_queue_depth *
 	    sizeof(Mpi2DefaultReplyDescriptor_t);
-
-	sz = reply_post_free_sz;
+	rdpq_sz = reply_post_free_sz * RDPQ_MAX_INDEX_IN_ONE_CHUNK;
 	if (_base_is_controller_msix_enabled(ioc) && !ioc->rdpq_array_enable)
-		sz *= ioc->reply_queue_count;
-	if (base_alloc_rdpq_dma_pool(ioc, sz))
-		goto out;
-	total_sz += sz * (!ioc->rdpq_array_enable ? 1 : ioc->reply_queue_count);
-
+		rdpq_sz = reply_post_free_sz * ioc->reply_queue_count;
+	ret = base_alloc_rdpq_dma_pool(ioc, rdpq_sz);
+	if (ret == -EAGAIN) {
+		/*
+		 * Free allocated bad RDPQ memory pools.
+		 * Change dma coherent mask to 32 bit and reallocate RDPQ
+		 */
+		_base_release_memory_pools(ioc);
+		ioc->is_dma_32bit = 1;
+		if (_base_config_dma_addressing(ioc, ioc->pdev) != 0) {
+			ioc_err(ioc,
+			    "32 DMA mask failed %s\n", pci_name(ioc->pdev));
+			return -ENODEV;
+		}
+		if (base_alloc_rdpq_dma_pool(ioc, rdpq_sz))
+			return -ENOMEM;
+	} else if (ret == -ENOMEM)
+		return -ENOMEM;
+	total_sz = rdpq_sz * (!ioc->rdpq_array_enable ? 1 :
+	    DIV_ROUND_UP(ioc->reply_queue_count, RDPQ_MAX_INDEX_IN_ONE_CHUNK));
 	ioc->scsiio_depth = ioc->hba_queue_depth -
 	    ioc->hi_priority_depth - ioc->internal_depth;
 
@@ -5182,7 +5242,6 @@ _base_allocate_memory_pools(struct MPT3SAS_ADAPTER *ioc)
 		    ioc_info(ioc, "scsi host: can_queue depth (%d)\n",
 			     ioc->shost->can_queue));
 
-
 	/* contiguous pool for request and chains, 16 byte align, one extra "
 	 * "frame for smid=0
 	 */
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h
index 396ac96..99724a7 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.h
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.h
@@ -367,6 +367,7 @@ struct mpt3sas_nvme_cmd {
 #define MPT3SAS_HIGH_IOPS_REPLY_QUEUES		8
 #define MPT3SAS_HIGH_IOPS_BATCH_COUNT		16
 #define MPT3SAS_GEN35_MAX_MSIX_QUEUES		128
+#define RDPQ_MAX_INDEX_IN_ONE_CHUNK		16
 
 /* OEM Specific Flags will come from OEM specific header files */
 struct Mpi2ManufacturingPage10_t {
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [v1 5/5] mpt3sas: Update mpt3sas version to 33.101.00.00
  2020-04-15 13:25 [v1 0/5] mpt3sas: Fix changing coherent mask after allocation Suganath Prabu
                   ` (3 preceding siblings ...)
  2020-04-15 13:25 ` [v1 4/5] mpt3sas: Handle RDPQ DMA allocation in same 4G region Suganath Prabu
@ 2020-04-15 13:25 ` Suganath Prabu
  2020-04-22  3:36 ` [v1 0/5] mpt3sas: Fix changing coherent mask after allocation Martin K. Petersen
  5 siblings, 0 replies; 13+ messages in thread
From: Suganath Prabu @ 2020-04-15 13:25 UTC (permalink / raw)
  To: linux-scsi; +Cc: hch, Sathya.Prakash, sreekanth.reddy, Suganath Prabu S

From: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>

Update mpt3sas driver version from 33.100.00.00 to
33.101.00.00

Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
---
 drivers/scsi/mpt3sas/mpt3sas_base.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h
index 99724a7..c136157 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.h
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.h
@@ -76,9 +76,9 @@
 #define MPT3SAS_DRIVER_NAME		"mpt3sas"
 #define MPT3SAS_AUTHOR "Avago Technologies <MPT-FusionLinux.pdl@avagotech.com>"
 #define MPT3SAS_DESCRIPTION	"LSI MPT Fusion SAS 3.0 Device Driver"
-#define MPT3SAS_DRIVER_VERSION		"33.100.00.00"
+#define MPT3SAS_DRIVER_VERSION		"33.101.00.00"
 #define MPT3SAS_MAJOR_VERSION		33
-#define MPT3SAS_MINOR_VERSION		100
+#define MPT3SAS_MINOR_VERSION		101
 #define MPT3SAS_BUILD_VERSION		0
 #define MPT3SAS_RELEASE_VERSION	00
 
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [v1 0/5] mpt3sas: Fix changing coherent mask after allocation
  2020-04-15 13:25 [v1 0/5] mpt3sas: Fix changing coherent mask after allocation Suganath Prabu
                   ` (4 preceding siblings ...)
  2020-04-15 13:25 ` [v1 5/5] mpt3sas: Update mpt3sas version to 33.101.00.00 Suganath Prabu
@ 2020-04-22  3:36 ` Martin K. Petersen
  5 siblings, 0 replies; 13+ messages in thread
From: Martin K. Petersen @ 2020-04-22  3:36 UTC (permalink / raw)
  To: hch; +Cc: linux-scsi, Sathya.Prakash, sreekanth.reddy, Suganath Prabu


Christoph,

Please review, thanks!

> * Set the coherent dma mask to 64 bit and then allocate RDPQ pools,
> make sure that each of the RDPQ pools satisfies the 4gb boundary
> restriction. if any of the RDPQ pool doesn't satisfies this
> restriction then deallocate the pools and reallocate them after
> changing the coherent dma mask to 32 bit.
> * With this there is no need to change DMA coherent
> mask when there are outstanding allocations in mpt3sas.
> * Code-Refactoring
>
> Suganath Prabu S (5):
>   mpt3sas: Don't change the dma coherent mask after      allocations
>   mpt3sas: Rename function name is_MSB_are_same
>   mpt3sas: Separate out RDPQ allocation to new function.
>   mpt3sas: Handle RDPQ DMA allocation in same 4G region
>   mpt3sas: Update mpt3sas version to 33.101.00.00
>
>  drivers/scsi/mpt3sas/mpt3sas_base.c | 279 +++++++++++++++++++++---------------
>  drivers/scsi/mpt3sas/mpt3sas_base.h |   9 +-
>  2 files changed, 171 insertions(+), 117 deletions(-)

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [v1 1/5] mpt3sas: Don't change the dma coherent mask after allocations
  2020-04-15 13:25 ` [v1 1/5] mpt3sas: Don't change the dma coherent mask after allocations Suganath Prabu
@ 2020-04-22  6:34   ` Christoph Hellwig
  2020-04-22  9:19     ` Suganath Prabu Subramani
  0 siblings, 1 reply; 13+ messages in thread
From: Christoph Hellwig @ 2020-04-22  6:34 UTC (permalink / raw)
  To: Suganath Prabu; +Cc: linux-scsi, hch, Sathya.Prakash, sreekanth.reddy

On Wed, Apr 15, 2020 at 09:25:21AM -0400, Suganath Prabu wrote:
> From: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
> 
> Currently driver is initially setting the dma coherent mask to 32 bit
> and then after allocating the Reply Descriptor Post Queues(RDPQ) pools
> it changes the dma coherent mask to 64/63 according to HBA generation.
> 
> But the DMA layer does not allow changing the DMA coherent mask after
> there are outstanding allocations.
> 
> So, updating the driver to stop changing the dma coherent mask after
> allocations.
> 
> Rename ioc variable "dma_mask" to "is_dma_32bit" and use it to set 32
> bit DMA.
> ---
> v1 Change log:
> 1) Incorporated the review comments from Christoph Hellwig
> 
> Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>

I still don't see why you don't simply take my original patch instead.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [v1 2/5] mpt3sas: Rename function name is_MSB_are_same
  2020-04-15 13:25 ` [v1 2/5] mpt3sas: Rename function name is_MSB_are_same Suganath Prabu
@ 2020-04-22  6:34   ` Christoph Hellwig
  0 siblings, 0 replies; 13+ messages in thread
From: Christoph Hellwig @ 2020-04-22  6:34 UTC (permalink / raw)
  To: Suganath Prabu; +Cc: linux-scsi, hch, Sathya.Prakash, sreekanth.reddy

On Wed, Apr 15, 2020 at 09:25:22AM -0400, Suganath Prabu wrote:
> From: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
> 
> Renamed is_MSB_are_same() to mpt3sas_check_same_4gb_region()
> for better readability.

s/Rename function name is_MSB_are_same/rename is_MSB_are_same/rename/

Otherwise looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [v1 3/5] mpt3sas: Separate out RDPQ allocation to new function.
  2020-04-15 13:25 ` [v1 3/5] mpt3sas: Separate out RDPQ allocation to new function Suganath Prabu
@ 2020-04-22  6:39   ` Christoph Hellwig
  0 siblings, 0 replies; 13+ messages in thread
From: Christoph Hellwig @ 2020-04-22  6:39 UTC (permalink / raw)
  To: Suganath Prabu; +Cc: linux-scsi, hch, Sathya.Prakash, sreekanth.reddy

On Wed, Apr 15, 2020 at 09:25:23AM -0400, Suganath Prabu wrote:
> From: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
> 
> For readability separate out RDPQ allocations to new function
> base_alloc_rdpq_dma_pool().
> 
> Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
> ---
>  drivers/scsi/mpt3sas/mpt3sas_base.c | 85 ++++++++++++++++++++++---------------
>  1 file changed, 51 insertions(+), 34 deletions(-)
> 
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
> index 7f7b5af..27c829e 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_base.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
> @@ -4944,6 +4944,55 @@ 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;
> +
> +	ioc->reply_post = kcalloc((ioc->rdpq_array_enable) ?
> +	    (ioc->reply_queue_count):1,
> +	    sizeof(struct reply_post_struct), GFP_KERNEL);

Odd use of whitespaces.  Also this would benefit from a little
untangling as well:

	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) {
> +		ioc_err(ioc, "reply_post_free pool: kcalloc failed\n");
> +		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) {
> +		ioc_err(ioc, "reply_post_free pool: dma_pool_create failed\n");
> +		return -ENOMEM;

We normally don't print error messages for memory allocation failures,
as the allocator already prints one including a stack trace.

Same for additional allocations below.

> +	} while (ioc->rdpq_array_enable && (++i < ioc->reply_queue_count));

no need for the inner braces.

> +	total_sz += sz * (!ioc->rdpq_array_enable ? 1 : ioc->reply_queue_count);

	if (ioc->rdpq_array_enable)
		total_sz += sz * ioc->reply_queue_count;
	else
		total_sz += sz;

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [v1 4/5] mpt3sas: Handle RDPQ DMA allocation in same 4G region
  2020-04-15 13:25 ` [v1 4/5] mpt3sas: Handle RDPQ DMA allocation in same 4G region Suganath Prabu
@ 2020-04-22  6:41   ` Christoph Hellwig
  0 siblings, 0 replies; 13+ messages in thread
From: Christoph Hellwig @ 2020-04-22  6:41 UTC (permalink / raw)
  To: Suganath Prabu; +Cc: linux-scsi, hch, Sathya.Prakash, sreekanth.reddy

On Wed, Apr 15, 2020 at 09:25:24AM -0400, Suganath Prabu wrote:
> From: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
> 
> For INVADER_SERIES each set of 8 reply queues (0 - 7, 8 - 15,..) and
> VENTURA_SERIES each set of 16 reply queues (0 - 15, 16 - 31,..) should
> be within 4 GB boundary. Driver uses limitation of VENTURA_SERIES to
> manage INVADER_SERIES as well. So here driver is allocating the DMA able
> memory for RDPQ's accordingly.
> 
> 1) At driver load, set DMA Mask to 64 and allocate memory for RDPQ's.
> 2) Check if allocated resources for RDPQ are in the same 4GB range.
> 3) If #2 is true, continue with 64 bit DMA and go to #6
> 4) If #2 is false, then free all the resources from #1.
> 5) Set DMA mask to 32 and allocate RDPQ's.
> 6) Proceed with driver loading and other allocations
> ---
> v1 Change log:
> 1) Use one dma pool for RDPQ's, thus removes the logic of using second
> dma pool with align.
> 
> Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
> ---
>  drivers/scsi/mpt3sas/mpt3sas_base.c | 153 +++++++++++++++++++++++++-----------
>  drivers/scsi/mpt3sas/mpt3sas_base.h |   1 +
>  2 files changed, 107 insertions(+), 47 deletions(-)
> 
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
> index 27c829e..add23d7 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_base.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
> @@ -3345,7 +3345,6 @@ mpt3sas_base_map_resources(struct MPT3SAS_ADAPTER *ioc)
>  
>  	pci_set_master(pdev);
>  
> -
>  	if (_base_config_dma_addressing(ioc, pdev) != 0) {

Unrelated spurious whitespace change.

Otherwise looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [v1 1/5] mpt3sas: Don't change the dma coherent mask after allocations
  2020-04-22  6:34   ` Christoph Hellwig
@ 2020-04-22  9:19     ` Suganath Prabu Subramani
  2020-04-22 17:18       ` Christoph Hellwig
  0 siblings, 1 reply; 13+ messages in thread
From: Suganath Prabu Subramani @ 2020-04-22  9:19 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-scsi, Sathya Prakash Veerichetty, Sreekanth Reddy

Hi Christoph,

Your original patch always set the dma coherent mask to 32bit.
But in this patch set, we first set the dma coherent to 64bit, if RDPQ
pools crosses
the 4gb boundary then we change it to 32 bit.
Like your original patch we will simplify.

Thanks,
Suganath


On Wed, Apr 22, 2020 at 12:04 PM Christoph Hellwig <hch@infradead.org> wrote:
>
> On Wed, Apr 15, 2020 at 09:25:21AM -0400, Suganath Prabu wrote:
> > From: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
> >
> > Currently driver is initially setting the dma coherent mask to 32 bit
> > and then after allocating the Reply Descriptor Post Queues(RDPQ) pools
> > it changes the dma coherent mask to 64/63 according to HBA generation.
> >
> > But the DMA layer does not allow changing the DMA coherent mask after
> > there are outstanding allocations.
> >
> > So, updating the driver to stop changing the dma coherent mask after
> > allocations.
> >
> > Rename ioc variable "dma_mask" to "is_dma_32bit" and use it to set 32
> > bit DMA.
> > ---
> > v1 Change log:
> > 1) Incorporated the review comments from Christoph Hellwig
> >
> > Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
>
> I still don't see why you don't simply take my original patch instead.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [v1 1/5] mpt3sas: Don't change the dma coherent mask after allocations
  2020-04-22  9:19     ` Suganath Prabu Subramani
@ 2020-04-22 17:18       ` Christoph Hellwig
  0 siblings, 0 replies; 13+ messages in thread
From: Christoph Hellwig @ 2020-04-22 17:18 UTC (permalink / raw)
  To: Suganath Prabu Subramani
  Cc: Christoph Hellwig, linux-scsi, Sathya Prakash Veerichetty,
	Sreekanth Reddy

On Wed, Apr 22, 2020 at 02:49:42PM +0530, Suganath Prabu Subramani wrote:
> Hi Christoph,
> 
> Your original patch always set the dma coherent mask to 32bit.
> But in this patch set, we first set the dma coherent to 64bit, if RDPQ
> pools crosses
> the 4gb boundary then we change it to 32 bit.
> Like your original patch we will simplify.

This is however missing most of the cleanups.  Also the is_dma_32bit
flag is unused in this patch.  So I don't think it should be added
here, but only when used.  It should then also use a bool type
and be named use_32bit_dma.

When reworking your patch using all criteria I still end up with
something looking a lot like my original one, with the only big
difference that is also forces a 32-bit DMA streaming mask for
all the limited devices, which actually looks wrong to me:

---
From 5253b88eba38dbf50cbbe5f34c8f5b4c345cca57 Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <hch@lst.de>
Date: Wed, 22 Apr 2020 19:18:00 +0200
Subject: mpt3sas: don't change the dma coherent mask after allocations

The DMA layer does not allow changing the DMA coherent mask after
there are outstanding allocations.  Stop doing that and always
use a 32-bit coherent DMA mask in mpt3sas.

Reported-by: Abdul Haleem <abdhalee@linux.vnet.ibm.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/scsi/mpt3sas/mpt3sas_base.c | 71 ++++++++---------------------
 drivers/scsi/mpt3sas/mpt3sas_base.h |  2 -
 2 files changed, 20 insertions(+), 53 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 663782bb790d..3072599a187a 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -2806,55 +2806,33 @@ _base_build_sg_ieee(struct MPT3SAS_ADAPTER *ioc, void *psge,
 static int
 _base_config_dma_addressing(struct MPT3SAS_ADAPTER *ioc, struct pci_dev *pdev)
 {
-	u64 required_mask, coherent_mask;
 	struct sysinfo s;
-	/* Set 63 bit DMA mask for all SAS3 and SAS35 controllers */
-	int dma_mask = (ioc->hba_mpi_version_belonged > MPI2_VERSION) ? 63 : 64;
-
-	if (ioc->is_mcpu_endpoint)
-		goto try_32bit;
+	int dma_bits;
 
-	required_mask = dma_get_required_mask(&pdev->dev);
-	if (sizeof(dma_addr_t) == 4 || required_mask == 32)
-		goto try_32bit;
-
-	if (ioc->dma_mask)
-		coherent_mask = DMA_BIT_MASK(dma_mask);
+	if (ioc->is_mcpu_endpoint || sizeof(dma_addr_t) == 4 ||
+	    dma_get_required_mask(&pdev->dev) <= DMA_BIT_MASK(32))
+		dma_bits = 32;
+	/* Set 63 bit DMA mask for all SAS3 and SAS35 controllers */
+	else if (ioc->hba_mpi_version_belonged > MPI2_VERSION)
+		dma_bits = 63;
 	else
-		coherent_mask = DMA_BIT_MASK(32);
-
-	if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(dma_mask)) ||
-	    dma_set_coherent_mask(&pdev->dev, coherent_mask))
-		goto try_32bit;
+		dma_bits = 64;
 
-	ioc->base_add_sg_single = &_base_add_sg_single_64;
-	ioc->sge_size = sizeof(Mpi2SGESimple64_t);
-	ioc->dma_mask = dma_mask;
-	goto out;
-
- try_32bit:
-	if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)))
+	if (dma_set_mask_and_coherent(&pdev->dev, dma_bits))
 		return -ENODEV;
 
-	ioc->base_add_sg_single = &_base_add_sg_single_32;
-	ioc->sge_size = sizeof(Mpi2SGESimple32_t);
-	ioc->dma_mask = 32;
- out:
-	si_meminfo(&s);
-	ioc_info(ioc, "%d BIT PCI BUS DMA ADDRESSING SUPPORTED, total mem (%ld kB)\n",
-		 ioc->dma_mask, convert_to_kb(s.totalram));
-
-	return 0;
-}
-
-static int
-_base_change_consistent_dma_mask(struct MPT3SAS_ADAPTER *ioc,
-				      struct pci_dev *pdev)
-{
-	if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(ioc->dma_mask))) {
-		if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))
-			return -ENODEV;
+	if (dma_bits > 32) {
+		ioc->base_add_sg_single = &_base_add_sg_single_64;
+		ioc->sge_size = sizeof(Mpi2SGESimple64_t);
+	} else {
+		ioc->base_add_sg_single = &_base_add_sg_single_32;
+		ioc->sge_size = sizeof(Mpi2SGESimple32_t);
 	}
+
+	si_meminfo(&s);
+	ioc_info(ioc,
+		"%d BIT PCI BUS DMA ADDRESSING SUPPORTED, total mem (%ld kB)\n",
+		dma_bits, convert_to_kb(s.totalram));
 	return 0;
 }
 
@@ -5169,14 +5147,6 @@ _base_allocate_memory_pools(struct MPT3SAS_ADAPTER *ioc)
 		total_sz += sz;
 	} while (ioc->rdpq_array_enable && (++i < ioc->reply_queue_count));
 
-	if (ioc->dma_mask > 32) {
-		if (_base_change_consistent_dma_mask(ioc, ioc->pdev) != 0) {
-			ioc_warn(ioc, "no suitable consistent DMA mask for %s\n",
-				 pci_name(ioc->pdev));
-			goto out;
-		}
-	}
-
 	ioc->scsiio_depth = ioc->hba_queue_depth -
 	    ioc->hi_priority_depth - ioc->internal_depth;
 
@@ -7158,7 +7128,6 @@ mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc)
 	ioc->smp_affinity_enable = smp_affinity_enable;
 
 	ioc->rdpq_array_enable_assigned = 0;
-	ioc->dma_mask = 0;
 	if (ioc->is_aero_ioc)
 		ioc->base_readl = &_base_readl_aero;
 	else
diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h
index e7197150721f..caae04086539 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.h
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.h
@@ -1026,7 +1026,6 @@ typedef void (*MPT3SAS_FLUSH_RUNNING_CMDS)(struct MPT3SAS_ADAPTER *ioc);
  * @ir_firmware: IR firmware present
  * @bars: bitmask of BAR's that must be configured
  * @mask_interrupts: ignore interrupt
- * @dma_mask: used to set the consistent dma mask
  * @pci_access_mutex: Mutex to synchronize ioctl, sysfs show path and
  *			pci resource handling
  * @fault_reset_work_q_name: fw fault work queue
@@ -1205,7 +1204,6 @@ struct MPT3SAS_ADAPTER {
 	u8		ir_firmware;
 	int		bars;
 	u8		mask_interrupts;
-	int		dma_mask;
 
 	/* fw fault handler */
 	char		fault_reset_work_q_name[20];
-- 
2.26.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-04-22 17:18 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-15 13:25 [v1 0/5] mpt3sas: Fix changing coherent mask after allocation Suganath Prabu
2020-04-15 13:25 ` [v1 1/5] mpt3sas: Don't change the dma coherent mask after allocations Suganath Prabu
2020-04-22  6:34   ` Christoph Hellwig
2020-04-22  9:19     ` Suganath Prabu Subramani
2020-04-22 17:18       ` Christoph Hellwig
2020-04-15 13:25 ` [v1 2/5] mpt3sas: Rename function name is_MSB_are_same Suganath Prabu
2020-04-22  6:34   ` Christoph Hellwig
2020-04-15 13:25 ` [v1 3/5] mpt3sas: Separate out RDPQ allocation to new function Suganath Prabu
2020-04-22  6:39   ` Christoph Hellwig
2020-04-15 13:25 ` [v1 4/5] mpt3sas: Handle RDPQ DMA allocation in same 4G region Suganath Prabu
2020-04-22  6:41   ` Christoph Hellwig
2020-04-15 13:25 ` [v1 5/5] mpt3sas: Update mpt3sas version to 33.101.00.00 Suganath Prabu
2020-04-22  3:36 ` [v1 0/5] mpt3sas: Fix changing coherent mask after allocation Martin K. Petersen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.