diff mbox

[06/15] mpt3sas: Enhanced handling of Sense Buffer.

Message ID 1522402644-3016-7-git-send-email-chaitra.basappa@broadcom.com (mailing list archive)
State Changes Requested
Headers show

Commit Message

Chaitra P B March 30, 2018, 9:37 a.m. UTC
Enhanced DMA allocation for Sense Buffer, if the allocation does not fit
within same 4GB.Introduced is_MSB_are_same function to check if allocted
buffer within 4GB range or not.

Signed-off-by: Chaitra P B <chaitra.basappa@broadcom.com>
Signed-off-by: Suganath Prabu S <suganath-prabu.subramani@broadcom.com>
---
 drivers/scsi/mpt3sas/mpt3sas_base.c | 57 +++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

Comments

Bart Van Assche March 30, 2018, 4:15 p.m. UTC | #1
On Fri, 2018-03-30 at 15:07 +0530, Chaitra P B wrote:
> +	if (((reply_pool_start_address / bit_divisor_16) / (bit_divisor_16)) ==

> +		((reply_pool_end_address / bit_divisor_16) / bit_divisor_16))

> +		return 1;

> +	else

> +		return 0;


Please use upper_32_bits() instead of open-coding it. I think that the above
check could be rewritten as follows:

	return upper_32_bits(reply_pool_start_address) ==
	       upper_32_bits(reply_pool_end_address);

Thanks,

Bart.
Chaitra P B April 2, 2018, 7:25 a.m. UTC | #2
Bart,
 Agreed with below changes, we will be posting the patches soon.

-----Original Message-----
From: Bart Van Assche [mailto:Bart.VanAssche@wdc.com]
Sent: Friday, March 30, 2018 9:46 PM
To: chaitra.basappa@broadcom.com; linux-scsi@vger.kernel.org
Cc: Sathya.Prakash@broadcom.com; suganath-prabu.subramani@broadcom.com;
sreekanth.reddy@broadcom.com
Subject: Re: [PATCH 06/15] mpt3sas: Enhanced handling of Sense Buffer.

On Fri, 2018-03-30 at 15:07 +0530, Chaitra P B wrote:
> +	if (((reply_pool_start_address / bit_divisor_16) / (bit_divisor_16)) ==
> +		((reply_pool_end_address / bit_divisor_16) / bit_divisor_16))
> +		return 1;
> +	else
> +		return 0;

Please use upper_32_bits() instead of open-coding it. I think that the above
check could be rewritten as follows:

	return upper_32_bits(reply_pool_start_address) ==
	       upper_32_bits(reply_pool_end_address);

Thanks,

Bart.
diff mbox

Patch

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 701e1e7..7f3b684 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -4205,6 +4205,32 @@  _base_release_memory_pools(struct MPT3SAS_ADAPTER *ioc)
 }
 
 /**
+ * is_MSB_are_same - 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
+ *
+ * Returns 1 if reply queues in a set have a same upper 32bits
+ * in their base memory address,
+ * else 0
+ */
+
+static int
+is_MSB_are_same(long reply_pool_start_address, u32 pool_sz)
+{
+	long reply_pool_end_address;
+	unsigned long bit_divisor_16 = 0x10000;
+
+	reply_pool_end_address = reply_pool_start_address + pool_sz;
+
+	if (((reply_pool_start_address / bit_divisor_16) / (bit_divisor_16)) ==
+		((reply_pool_end_address / bit_divisor_16) / bit_divisor_16))
+		return 1;
+	else
+		return 0;
+}
+
+/**
  * _base_allocate_memory_pools - allocate start of day memory pools
  * @ioc: per adapter object
  *
@@ -4664,6 +4690,37 @@  _base_allocate_memory_pools(struct MPT3SAS_ADAPTER *ioc)
 		    ioc->name);
 		goto out;
 	}
+	/* sense buffer requires to be in same 4 gb region.
+	 * Below function will check the same.
+	 * In case of failure, new pci pool will be created with updated
+	 * alignment. Older allocation and pool will be destroyed.
+	 * Alignment will be used such a way that next allocation if
+	 * success, will always meet same 4gb region requirement.
+	 * 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)) {
+		//Release Sense pool & Reallocate
+		dma_pool_free(ioc->sense_dma_pool, ioc->sense, ioc->sense_dma);
+		dma_pool_destroy(ioc->sense_dma_pool);
+		ioc->sense = NULL;
+
+		ioc->sense_dma_pool =
+			dma_pool_create("sense pool", &ioc->pdev->dev, sz,
+						roundup_pow_of_two(sz), 0);
+		if (!ioc->sense_dma_pool) {
+			pr_err(MPT3SAS_FMT "sense pool: pci_pool_create failed\n",
+					ioc->name);
+			goto out;
+		}
+		ioc->sense = dma_pool_alloc(ioc->sense_dma_pool, GFP_KERNEL,
+				&ioc->sense_dma);
+		if (!ioc->sense) {
+			pr_err(MPT3SAS_FMT "sense pool: pci_pool_alloc failed\n",
+					ioc->name);
+			goto out;
+		}
+	}
 	dinitprintk(ioc, pr_info(MPT3SAS_FMT
 	    "sense pool(0x%p): depth(%d), element_size(%d), pool_size"
 	    "(%d kB)\n", ioc->name, ioc->sense, ioc->scsiio_depth,