All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V3] scsi: ufs: Add specific callback for setting DMA mask
       [not found] <CGME20180520023633epcas2p333689dfc3c9f94c15018e33f69c751cb@epcas2p3.samsung.com>
@ 2018-05-20  2:24 ` Alim Akhtar
  2018-05-20 14:21   ` Bart Van Assche
  0 siblings, 1 reply; 5+ messages in thread
From: Alim Akhtar @ 2018-05-20  2:24 UTC (permalink / raw)
  To: linux-scsi, linux-kernel
  Cc: jejb, martin.petersen, subhashj, vinholikatti, shaik.ameer, alim.akhtar

Currently DMA mask for UFS HCI is set by reading CAP register's
[64AS] bit. Some HCI controller like Exynos support 36-bit bus address.
This works perfectly fine with DMA mask set as 64 in case there is no
IOMMU attached to HCI.
In case if HCI is behind an IOMMU, setting DMA mask as 64 bit won't
work as HCI has only 36bit addressing and SMMU has created mapping of
64 bit and as the device truncates the address, its mapping will not
be found by iommu.
To resolve such issues, let the variant driver sets its own DMA mask.

Signed-off-by: Alim Akhtar <alim.akhtar@samsung.com>
---
 drivers/scsi/ufs/ufshcd.c | 3 +++
 drivers/scsi/ufs/ufshcd.h | 2 ++
 2 files changed, 5 insertions(+)

I am not sure if there are other ways available to handle such cases.
The IOMMU I am talking about is arm-smmu and it DT binding does not
give much idea about handling such cases.
Have tested this patch with HCI controller with IOMMU attached.

Changes Since V1: 
	- Fixed build issue as reported by Kbuild test robot.

Changes Since V2: 
	- Remove RFC tag as suggested by Subhash.

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index a355d98..9a1374e 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -7781,6 +7781,9 @@ EXPORT_SYMBOL_GPL(ufshcd_dealloc_host);
  */
 static int ufshcd_set_dma_mask(struct ufs_hba *hba)
 {
+	if (hba->vops && hba->vops->set_dma_mask)
+		return hba->vops->set_dma_mask(hba);
+
 	if (hba->capabilities & MASK_64_ADDRESSING_SUPPORT) {
 		if (!dma_set_mask_and_coherent(hba->dev, DMA_BIT_MASK(64)))
 			return 0;
diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
index 1332e54..89c6dae 100644
--- a/drivers/scsi/ufs/ufshcd.h
+++ b/drivers/scsi/ufs/ufshcd.h
@@ -297,6 +297,7 @@ struct ufs_pwr_mode_info {
  * @resume: called during host controller PM callback
  * @dbg_register_dump: used to dump controller debug information
  * @phy_initialization: used to initialize phys
+ * @set_dma_mask: used to set variant specific DMA mask
  */
 struct ufs_hba_variant_ops {
 	const char *name;
@@ -325,6 +326,7 @@ struct ufs_hba_variant_ops {
 	int     (*resume)(struct ufs_hba *, enum ufs_pm_op);
 	void	(*dbg_register_dump)(struct ufs_hba *hba);
 	int	(*phy_initialization)(struct ufs_hba *);
+	int	(*set_dma_mask)(struct ufs_hba *hba);
 };
 
 /* clock gating state  */
-- 
2.7.4

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

* Re: [PATCH V3] scsi: ufs: Add specific callback for setting DMA mask
  2018-05-20  2:24 ` [PATCH V3] scsi: ufs: Add specific callback for setting DMA mask Alim Akhtar
@ 2018-05-20 14:21   ` Bart Van Assche
  2018-05-28  6:35     ` Alim Akhtar
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Van Assche @ 2018-05-20 14:21 UTC (permalink / raw)
  To: linux-scsi, alim.akhtar, linux-kernel
  Cc: jejb, subhashj, martin.petersen, vinholikatti, shaik.ameer

On Sun, 2018-05-20 at 07:54 +0530, Alim Akhtar wrote:
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> index a355d98..9a1374e 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -7781,6 +7781,9 @@ EXPORT_SYMBOL_GPL(ufshcd_dealloc_host);
>   */
>  static int ufshcd_set_dma_mask(struct ufs_hba *hba)
>  {
> +	if (hba->vops && hba->vops->set_dma_mask)
> +		return hba->vops->set_dma_mask(hba);
> +
>  	if (hba->capabilities & MASK_64_ADDRESSING_SUPPORT) {
>  		if (!dma_set_mask_and_coherent(hba->dev, DMA_BIT_MASK(64)))
>  			return 0;
> diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
> index 1332e54..89c6dae 100644
> --- a/drivers/scsi/ufs/ufshcd.h
> +++ b/drivers/scsi/ufs/ufshcd.h
> @@ -297,6 +297,7 @@ struct ufs_pwr_mode_info {
>   * @resume: called during host controller PM callback
>   * @dbg_register_dump: used to dump controller debug information
>   * @phy_initialization: used to initialize phys
> + * @set_dma_mask: used to set variant specific DMA mask
>   */
>  struct ufs_hba_variant_ops {
>  	const char *name;
> @@ -325,6 +326,7 @@ struct ufs_hba_variant_ops {
>  	int     (*resume)(struct ufs_hba *, enum ufs_pm_op);
>  	void	(*dbg_register_dump)(struct ufs_hba *hba);
>  	int	(*phy_initialization)(struct ufs_hba *);
> +	int	(*set_dma_mask)(struct ufs_hba *hba);
>  };

I want to see the code that sets the .set_dma_mask callback function. Where
is it? If it is outside the upstream kernel, please consider to send it
upstream before making changes like this. Adding support for out-of-tree
kernel code is frowned upon big time in the kernel community.

Bart.

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

* Re: [PATCH V3] scsi: ufs: Add specific callback for setting DMA mask
  2018-05-20 14:21   ` Bart Van Assche
@ 2018-05-28  6:35     ` Alim Akhtar
  0 siblings, 0 replies; 5+ messages in thread
From: Alim Akhtar @ 2018-05-28  6:35 UTC (permalink / raw)
  To: Bart Van Assche, linux-scsi, linux-kernel
  Cc: jejb, subhashj, martin.petersen, vinholikatti, shaik.ameer

Hi Bart

On 05/20/2018 07:51 PM, Bart Van Assche wrote:
> On Sun, 2018-05-20 at 07:54 +0530, Alim Akhtar wrote:
>> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
>> index a355d98..9a1374e 100644
>> --- a/drivers/scsi/ufs/ufshcd.c
>> +++ b/drivers/scsi/ufs/ufshcd.c
>> @@ -7781,6 +7781,9 @@ EXPORT_SYMBOL_GPL(ufshcd_dealloc_host);
>>    */
>>   static int ufshcd_set_dma_mask(struct ufs_hba *hba)
>>   {
>> +	if (hba->vops && hba->vops->set_dma_mask)
>> +		return hba->vops->set_dma_mask(hba);
>> +
>>   	if (hba->capabilities & MASK_64_ADDRESSING_SUPPORT) {
>>   		if (!dma_set_mask_and_coherent(hba->dev, DMA_BIT_MASK(64)))
>>   			return 0;
>> diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
>> index 1332e54..89c6dae 100644
>> --- a/drivers/scsi/ufs/ufshcd.h
>> +++ b/drivers/scsi/ufs/ufshcd.h
>> @@ -297,6 +297,7 @@ struct ufs_pwr_mode_info {
>>    * @resume: called during host controller PM callback
>>    * @dbg_register_dump: used to dump controller debug information
>>    * @phy_initialization: used to initialize phys
>> + * @set_dma_mask: used to set variant specific DMA mask
>>    */
>>   struct ufs_hba_variant_ops {
>>   	const char *name;
>> @@ -325,6 +326,7 @@ struct ufs_hba_variant_ops {
>>   	int     (*resume)(struct ufs_hba *, enum ufs_pm_op);
>>   	void	(*dbg_register_dump)(struct ufs_hba *hba);
>>   	int	(*phy_initialization)(struct ufs_hba *);
>> +	int	(*set_dma_mask)(struct ufs_hba *hba);
>>   };
> 
> I want to see the code that sets the .set_dma_mask callback function. Where
> is it? If it is outside the upstream kernel, please consider to send it
> upstream before making changes like this. Adding support for out-of-tree
> kernel code is frowned upon big time in the kernel community.
> 
Thanks for review and feedback.
Ok, I will include this patch with the series which uses this particular 
patch set.
Thanks!

> Bart.
> 
> 
> 

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

* Re: [PATCH V3] scsi: ufs: Add specific callback for setting DMA mask
  2018-05-20  2:11 ` Bharat Uppal
@ 2018-05-20  2:20   ` Alim Akhtar
  0 siblings, 0 replies; 5+ messages in thread
From: Alim Akhtar @ 2018-05-20  2:20 UTC (permalink / raw)
  To: linux-scsi, linux-kernel
  Cc: jejb, martin.petersen, subhashj, vinholikatti, shaik.ameer

Hi All
Please ignore the below patch, sorry for the noise.
Will send updated patch soon.

Regards,
Alim

On 05/20/2018 07:41 AM, Bharat Uppal wrote:
> From: Alim Akhtar <alim.akhtar@samsung.com>
> 
> Currently DMA mask for UFS HCI is set by reading CAP register's
> [64AS] bit. Some HCI controller like Exynos support 36-bit bus address.
> This works perfectly fine with DMA mask set as 64 in case there is no
> IOMMU attached to HCI.
> In case if HCI is behind an IOMMU, setting DMA mask as 64 bit won't
> work as HCI has only 36bit addressing and SMMU has created mapping of
> 64 bit and as the device truncates the address, its mapping will not
> be found by iommu.
> To resolve such issues, let the variant driver sets its own DMA mask.
> 
> Signed-off-by: Alim Akhtar <alim.akhtar@samsung.com>
> ---
>   drivers/scsi/ufs/ufshcd.c | 3 +++
>   drivers/scsi/ufs/ufshcd.h | 2 ++
>   2 files changed, 5 insertions(+)
> 
> I am not sure if there are other ways available to handle such cases.
> The IOMMU I am talking about is arm-smmu and it DT binding does not
> give much idea about handling such cases.
> Have tested this patch with HCI controller with IOMMU attached.
> 
> Changes Since V1:
> 	- Fixed build issue as reported by Kbuild test robot.
> 
> Changes Since V2:
> 	- Remove RFC tag as suggested by Subhash.
> 
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> index a355d98..9a1374e 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -7781,6 +7781,9 @@ EXPORT_SYMBOL_GPL(ufshcd_dealloc_host);
>    */
>   static int ufshcd_set_dma_mask(struct ufs_hba *hba)
>   {
> +	if (hba->vops && hba->vops->set_dma_mask)
> +		return hba->vops->set_dma_mask(hba);
> +
>   	if (hba->capabilities & MASK_64_ADDRESSING_SUPPORT) {
>   		if (!dma_set_mask_and_coherent(hba->dev, DMA_BIT_MASK(64)))
>   			return 0;
> diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
> index 1332e54..89c6dae 100644
> --- a/drivers/scsi/ufs/ufshcd.h
> +++ b/drivers/scsi/ufs/ufshcd.h
> @@ -297,6 +297,7 @@ struct ufs_pwr_mode_info {
>    * @resume: called during host controller PM callback
>    * @dbg_register_dump: used to dump controller debug information
>    * @phy_initialization: used to initialize phys
> + * @set_dma_mask: used to set variant specific DMA mask
>    */
>   struct ufs_hba_variant_ops {
>   	const char *name;
> @@ -325,6 +326,7 @@ struct ufs_hba_variant_ops {
>   	int     (*resume)(struct ufs_hba *, enum ufs_pm_op);
>   	void	(*dbg_register_dump)(struct ufs_hba *hba);
>   	int	(*phy_initialization)(struct ufs_hba *);
> +	int	(*set_dma_mask)(struct ufs_hba *hba);
>   };
>   
>   /* clock gating state  */
> 

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

* [PATCH V3] scsi: ufs: Add specific callback for setting DMA mask
       [not found] <CGME20180520022321epcas1p4b0084a15aca3e5aea02700e272149ef3@epcas1p4.samsung.com>
@ 2018-05-20  2:11 ` Bharat Uppal
  2018-05-20  2:20   ` Alim Akhtar
  0 siblings, 1 reply; 5+ messages in thread
From: Bharat Uppal @ 2018-05-20  2:11 UTC (permalink / raw)
  To: linux-scsi, linux-kernel
  Cc: jejb, martin.petersen, subhashj, vinholikatti, shaik.ameer, alim.akhtar

From: Alim Akhtar <alim.akhtar@samsung.com>

Currently DMA mask for UFS HCI is set by reading CAP register's
[64AS] bit. Some HCI controller like Exynos support 36-bit bus address.
This works perfectly fine with DMA mask set as 64 in case there is no
IOMMU attached to HCI.
In case if HCI is behind an IOMMU, setting DMA mask as 64 bit won't
work as HCI has only 36bit addressing and SMMU has created mapping of
64 bit and as the device truncates the address, its mapping will not
be found by iommu.
To resolve such issues, let the variant driver sets its own DMA mask.

Signed-off-by: Alim Akhtar <alim.akhtar@samsung.com>
---
 drivers/scsi/ufs/ufshcd.c | 3 +++
 drivers/scsi/ufs/ufshcd.h | 2 ++
 2 files changed, 5 insertions(+)

I am not sure if there are other ways available to handle such cases.
The IOMMU I am talking about is arm-smmu and it DT binding does not
give much idea about handling such cases.
Have tested this patch with HCI controller with IOMMU attached.

Changes Since V1: 
	- Fixed build issue as reported by Kbuild test robot.

Changes Since V2: 
	- Remove RFC tag as suggested by Subhash.

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index a355d98..9a1374e 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -7781,6 +7781,9 @@ EXPORT_SYMBOL_GPL(ufshcd_dealloc_host);
  */
 static int ufshcd_set_dma_mask(struct ufs_hba *hba)
 {
+	if (hba->vops && hba->vops->set_dma_mask)
+		return hba->vops->set_dma_mask(hba);
+
 	if (hba->capabilities & MASK_64_ADDRESSING_SUPPORT) {
 		if (!dma_set_mask_and_coherent(hba->dev, DMA_BIT_MASK(64)))
 			return 0;
diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
index 1332e54..89c6dae 100644
--- a/drivers/scsi/ufs/ufshcd.h
+++ b/drivers/scsi/ufs/ufshcd.h
@@ -297,6 +297,7 @@ struct ufs_pwr_mode_info {
  * @resume: called during host controller PM callback
  * @dbg_register_dump: used to dump controller debug information
  * @phy_initialization: used to initialize phys
+ * @set_dma_mask: used to set variant specific DMA mask
  */
 struct ufs_hba_variant_ops {
 	const char *name;
@@ -325,6 +326,7 @@ struct ufs_hba_variant_ops {
 	int     (*resume)(struct ufs_hba *, enum ufs_pm_op);
 	void	(*dbg_register_dump)(struct ufs_hba *hba);
 	int	(*phy_initialization)(struct ufs_hba *);
+	int	(*set_dma_mask)(struct ufs_hba *hba);
 };
 
 /* clock gating state  */
-- 
2.7.4

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

end of thread, other threads:[~2018-05-28  6:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20180520023633epcas2p333689dfc3c9f94c15018e33f69c751cb@epcas2p3.samsung.com>
2018-05-20  2:24 ` [PATCH V3] scsi: ufs: Add specific callback for setting DMA mask Alim Akhtar
2018-05-20 14:21   ` Bart Van Assche
2018-05-28  6:35     ` Alim Akhtar
     [not found] <CGME20180520022321epcas1p4b0084a15aca3e5aea02700e272149ef3@epcas1p4.samsung.com>
2018-05-20  2:11 ` Bharat Uppal
2018-05-20  2:20   ` Alim Akhtar

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.