Skip to contentSkip to conversation

Enable DMA clustering in the UFS driver

PATCH Superseded Bart Van Assche 4 participants 11 messages Jan 6, 2023 – Jan 12, 2023

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Bart Van Assche

author reviewer
#0 lore raw

cover Enable DMA clustering in the UFS driver

Hi Martin,

The third patch in this series enables DMA clustering in the UFS driver since UFS host controllers support DMA clustering. The first two patches fix bugs in the Exynos host controller driver.

Please consider this patch series for the next merge window.

Thanks,

Bart.

Bart Van Assche (3):
scsi: ufs: Exynos: Fix DMA alignment for PAGE_SIZE != 4096
scsi: ufs: Exynos: Fix the maximum segment size
scsi: ufs: Enable DMA clustering

 drivers/ufs/core/ufshcd.c     |  5 ++---
 drivers/ufs/host/ufs-exynos.c | 12 +++++++++---
 include/ufs/ufshcd.h          |  4 ++--
 3 files changed, 13 insertions(+), 8 deletions(-)
author reviewer
#1 lore raw

PATCH 1/3 scsi: ufs: Exynos: Fix DMA alignment for PAGE_SIZE != 4096

The Exynos UFS controller only supports scatter/gather list elements that are aligned on a 4 KiB boundary. Fix DMA alignment in case PAGE_SIZE != 4096. Rename UFSHCD_QUIRK_ALIGN_SG_WITH_PAGE_SIZE into UFSHCD_QUIRK_4KB_DMA_ALIGNMENT.

Cc Kiwoong Kim <[email protected]>
Fixes 2b2bfc8aa519 ("scsi: ufs: Introduce a quirk to allow only page-aligned sg entries")
---
 drivers/ufs/core/ufshcd.c     | 4 ++--
 drivers/ufs/host/ufs-exynos.c | 2 +-
 include/ufs/ufshcd.h          | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/ufs/core/ufshcd.c +2 -2
index 99ca5b035028..be18edf4ef7f 100644
@@ -5029,8 +5029,8 @@ static int ufshcd_slave_configure(struct scsi_device *sdev)
 	ufshcd_hpb_configure(hba, sdev);
 
 	blk_queue_update_dma_pad(q, PRDT_DATA_BYTE_COUNT_PAD - 1);
-	if (hba->quirks & UFSHCD_QUIRK_ALIGN_SG_WITH_PAGE_SIZE)
-		blk_queue_update_dma_alignment(q, PAGE_SIZE - 1);
+	if (hba->quirks & UFSHCD_QUIRK_4KB_DMA_ALIGNMENT)
+		blk_queue_update_dma_alignment(q, 4096 - 1);
 	/*
 	 * Block runtime-pm until all consumers are added.
 	 * Refer ufshcd_setup_links().
drivers/ufs/host/ufs-exynos.c +1 -1
index c3628a8645a5..3cdac89a28b8 100644
@@ -1673,7 +1673,7 @@ static const struct exynos_ufs_drv_data exynos_ufs_drvs = {
 				  UFSHCD_QUIRK_BROKEN_OCS_FATAL_ERROR |
 				  UFSHCI_QUIRK_SKIP_MANUAL_WB_FLUSH_CTRL |
 				  UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING |
-				  UFSHCD_QUIRK_ALIGN_SG_WITH_PAGE_SIZE,
+				  UFSHCD_QUIRK_4KB_DMA_ALIGNMENT,
 	.opts			= EXYNOS_UFS_OPT_HAS_APB_CLK_CTRL |
 				  EXYNOS_UFS_OPT_BROKEN_AUTO_CLK_CTRL |
 				  EXYNOS_UFS_OPT_BROKEN_RX_SEL_IDX |
include/ufs/ufshcd.h +2 -2
index dd5912b4db77..583611444f12 100644
@@ -567,9 +567,9 @@ enum ufshcd_quirks {
 	UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING = 1 << 13,
 
 	/*
-	 * This quirk allows only sg entries aligned with page size.
+	 * Align DMA SG entries on a 4 KiB boundary.
 	 */
-	UFSHCD_QUIRK_ALIGN_SG_WITH_PAGE_SIZE		= 1 << 14,
+	UFSHCD_QUIRK_4KB_DMA_ALIGNMENT			= 1 << 14,
 
 	/*
 	 * This quirk needs to be enabled if the host controller does not
maintainer Reviewed-by Tested-by on v1 1/3
#2 lore raw

RE: [PATCH 1/3] scsi: ufs: Exynos: Fix DMA alignment for PAGE_SIZE != 4096

Hi Bart

Quoted 18 lines

-----Original Message-----
From: Bart Van Assche [mailto:[email protected]]
Sent: Saturday, January 7, 2023 3:28 AM
To: Martin K . Petersen <[email protected]>
Cc: Jaegeuk Kim <[email protected]>; Avri Altman <[email protected]>; Adrian Hunter <[email protected]>; linux- [email protected]; Bart Van Assche <[email protected]>; Kiwoong Kim <[email protected]>; James E.J. Bottomley <[email protected]>; Krzysztof Kozlowski <[email protected]>; Bean Huo <[email protected]>; Stanley Chu <[email protected]>; Jinyoung Choi <[email protected]>; Chanho Park <[email protected]>; Alim Akhtar <[email protected]>; Arthur Simchaev <[email protected]>; Keoseong Park <[email protected]>; Yoshihiro Shimoda <[email protected]>
Subject: [PATCH 1/3] scsi: ufs: Exynos: Fix DMA alignment for PAGE_SIZE != 4096

Quoted 1 line

The Exynos UFS controller only supports scatter/gather list elements that

are

Quoted 6 lines

aligned on a 4 KiB boundary. Fix DMA alignment in case PAGE_SIZE != 4096. Rename UFSHCD_QUIRK_ALIGN_SG_WITH_PAGE_SIZE into UFSHCD_QUIRK_4KB_DMA_ALIGNMENT.

Cc Kiwoong Kim <[email protected]>
Fixes 2b2bfc8aa519 ("scsi: ufs: Introduce a quirk to allow only

page-aligned sg

Quoted 3 lines

entries")

---

Thanks!

Tested on platforms containing Exynos HCI, so feel free to add

Quoted 58 lines
drivers/ufs/core/ufshcd.c     | 4 ++--
drivers/ufs/host/ufs-exynos.c | 2 +-
include/ufs/ufshcd.h          | 4 ++--
3 files changed, 5 insertions(+), 5 deletions(-)
drivers/ufs/core/ufshcd.c index renamed from drivers/ufs/core/ufshcd.c +0 -0

99ca5b035028..be18edf4ef7f 100644

drivers/ufs/core/ufshcd.c +2 -2
@@ -5029,8 +5029,8 @@ static int ufshcd_slave_configure(struct scsi_device
 *sdev)
 	ufshcd_hpb_configure(hba, sdev);
 
 	blk_queue_update_dma_pad(q, PRDT_DATA_BYTE_COUNT_PAD -
 1);
-	if (hba->quirks & UFSHCD_QUIRK_ALIGN_SG_WITH_PAGE_SIZE)
-		blk_queue_update_dma_alignment(q, PAGE_SIZE - 1);
+	if (hba->quirks & UFSHCD_QUIRK_4KB_DMA_ALIGNMENT)
+		blk_queue_update_dma_alignment(q, 4096 - 1);
 	/*

* Block runtime-pm until all consumers are added.
* Refer ufshcd_setup_links().

drivers/ufs/host/ufs-exynos.c +0 -0
index c3628a8645a5..3cdac89a28b8 100644
@@ -1673,7 +1673,7 @@ static const struct exynos_ufs_drv_data
 exynos_ufs_drvs = {
 

UFSHCD_QUIRK_BROKEN_OCS_FATAL_ERROR |

UFSHCI_QUIRK_SKIP_MANUAL_WB_FLUSH_CTRL |

UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING |
-
UFSHCD_QUIRK_ALIGN_SG_WITH_PAGE_SIZE,

drivers/ufs/host/ufs-exynos.c +1 -0
+				  UFSHCD_QUIRK_4KB_DMA_ALIGNMENT,
	.opts			= EXYNOS_UFS_OPT_HAS_APB_CLK_CTRL |

EXYNOS_UFS_OPT_BROKEN_AUTO_CLK_CTRL |
EXYNOS_UFS_OPT_BROKEN_RX_SEL_IDX |

include/ufs/ufshcd.h index renamed from include/ufs/ufshcd.h +0 -0

dd5912b4db77..583611444f12 100644

include/ufs/ufshcd.h +2 -2
@@ -567,9 +567,9 @@ enum ufshcd_quirks {
 	UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING = 1 << 13,
 
 	/*
-	 * This quirk allows only sg entries aligned with page size.
+	 * Align DMA SG entries on a 4 KiB boundary.
 	 */
-	UFSHCD_QUIRK_ALIGN_SG_WITH_PAGE_SIZE		= 1 << 14,
+	UFSHCD_QUIRK_4KB_DMA_ALIGNMENT			= 1 <<
 14,
 
 	/*

* This quirk needs to be enabled if the host controller does not

author reviewer
#3 lore raw

PATCH 2/3 scsi: ufs: Exynos: Fix the maximum segment size

In reply to Bart Van Assche

Prepare for enabling DMA clustering and also for supporting PAGE_SIZE != 4096 by declaring explicitly that the maximum segment size is 4096 bytes for Exynos UFS host controllers.

---
 drivers/ufs/host/ufs-exynos.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/ufs/host/ufs-exynos.c +8 -2
index 3cdac89a28b8..821c000ca6b0 100644
@@ -1586,15 +1586,21 @@ static int exynos_ufs_probe(struct platform_device *pdev)
 	const struct ufs_hba_variant_ops *vops = &ufs_hba_exynos_ops;
 	const struct exynos_ufs_drv_data *drv_data =
 		device_get_match_data(dev);
+	struct ufs_hba *hba;
 
 	if (drv_data && drv_data->vops)
 		vops = drv_data->vops;
 
 	err = ufshcd_pltfrm_init(pdev, vops);
-	if (err)
+	if (err) {
 		dev_err(dev, "ufshcd_pltfrm_init() failed %d\n", err);
+		return err;
+	}
+
+	hba = dev_get_drvdata(dev);
+	hba->host->max_segment_size = 4096;
 
-	return err;
+	return 0;
 }
 
 static int exynos_ufs_remove(struct platform_device *pdev)
maintainer Reviewed-by Tested-by on v1 2/3
#4 lore raw

RE: [PATCH 2/3] scsi: ufs: Exynos: Fix the maximum segment size

Hi Bart

Quoted 13 lines

-----Original Message-----
From: Bart Van Assche [mailto:[email protected]]
Sent: Saturday, January 7, 2023 3:28 AM
To: Martin K . Petersen <[email protected]>
Cc: Jaegeuk Kim <[email protected]>; Avri Altman <[email protected]>; Adrian Hunter <[email protected]>; linux- [email protected]; Bart Van Assche <[email protected]>; Kiwoong Kim <[email protected]>; James E.J. Bottomley <[email protected]>; Krzysztof Kozlowski <[email protected]>; Chanho Park <[email protected]>; Alim Akhtar <[email protected]>; Bean Huo <[email protected]>
Subject: [PATCH 2/3] scsi: ufs: Exynos: Fix the maximum segment size

Quoted 2 lines

Prepare for enabling DMA clustering and also for supporting PAGE_SIZE != 4096 by declaring explicitly that the maximum segment size is 4096 bytes

for

Quoted 5 lines

Exynos UFS host controllers.

---

Thanks!

Tested on platforms containing Exynos HCI, so feel free to add

For some reason, I didn't receive you patch-3/3 in my inbox.

Quoted 32 lines

drivers/ufs/host/ufs-exynos.c | 10 ++++++++--

1 file changed, 8 insertions(+), 2 deletions(-)
drivers/ufs/host/ufs-exynos.c +8 -2
index 3cdac89a28b8..821c000ca6b0 100644
@@ -1586,15 +1586,21 @@ static int exynos_ufs_probe(struct
 platform_device *pdev)
 	const struct ufs_hba_variant_ops *vops = &ufs_hba_exynos_ops;
 	const struct exynos_ufs_drv_data *drv_data =
 		device_get_match_data(dev);
+	struct ufs_hba *hba;
 
 	if (drv_data && drv_data->vops)
 		vops = drv_data->vops;
 
 	err = ufshcd_pltfrm_init(pdev, vops);
-	if (err)
+	if (err) {
 		dev_err(dev, "ufshcd_pltfrm_init() failed %d\n", err);
+		return err;
+	}
+
+	hba = dev_get_drvdata(dev);
+	hba->host->max_segment_size = 4096;
 
-	return err;
+	return 0;
 }
 

static int exynos_ufs_remove(struct platform_device *pdev)

author reviewer
#5 lore raw

Re: [PATCH 2/3] scsi: ufs: Exynos: Fix the maximum segment size

Quoted 1 line · Alim Akhtar

For some reason, I didn't receive you patch-3/3 in my inbox.

That's unfortunate. That's probably because I use a shell script to generate the Cc-list for UFS driver patches:

scripts/get_maintainer.pl --no-git --no-l --no-r --no-roles --no-rolestats "${1:-&STDIN}"

Anyway, patch 3/3 is available here: https://lore.kernel.org/linux-scsi/[email protected]/

Bart.

author reviewer
#6 lore raw

PATCH 3/3 scsi: ufs: Enable DMA clustering

In reply to Bart Van Assche

All UFS host controllers support DMA clustering. Hence enable DMA clustering.

Note: without patch "Exynos: Fix the maximum segment size", this patch breaks support for the Exynos controller.

---
 drivers/ufs/core/ufshcd.c | 1 -
 1 file changed, 1 deletion(-)
drivers/ufs/core/ufshcd.c +0 -1
index be18edf4ef7f..fe83fdda8d23 100644
@@ -8429,7 +8429,6 @@ static struct scsi_host_template ufshcd_driver_template = {
 	.max_host_blocked	= 1,
 	.track_queue_depth	= 1,
 	.sdev_groups		= ufshcd_driver_groups,
-	.dma_boundary		= PAGE_SIZE - 1,
 	.rpm_autosuspend_delay	= RPM_AUTOSUSPEND_DELAY_MS,
 };
 
reviewer
#7 lore raw

RE: [PATCH 3/3] scsi: ufs: Enable DMA clustering

Quoted 15 lines

All UFS host controllers support DMA clustering. Hence enable DMA clustering.

Note: without patch "Exynos: Fix the maximum segment size", this patch breaks support for the Exynos controller.

---
 drivers/ufs/core/ufshcd.c | 1 -
 1 file changed, 1 deletion(-)
drivers/ufs/core/ufshcd.c index renamed from drivers/ufs/core/ufshcd.c +0 -0

be18edf4ef7f..fe83fdda8d23 100644

drivers/ufs/core/ufshcd.c static struct scsi_host_template · line 8433

Quoted 5 lines
drivers/ufs/core/ufshcd.c +0 -1
@@ -8429,7 +8429,6 @@ static struct scsi_host_template
 ufshcd_driver_template = {
        .max_host_blocked       = 1,
        .track_queue_depth      = 1,
        .sdev_groups            = ufshcd_driver_groups,
-       .dma_boundary           = PAGE_SIZE - 1,

Isn't DBC <= 256KB implies that for a boundary?

Thanks,
Avri

Quoted 1 line
drivers/ufs/core/ufshcd.c +0 -0
        .rpm_autosuspend_delay  = RPM_AUTOSUSPEND_DELAY_MS,  };
author reviewer
#8 lore raw

Re: [PATCH 3/3] scsi: ufs: Enable DMA clustering

Quoted 10 lines · Avri Altman
Quoted 10 lines

All UFS host controllers support DMA clustering. Hence enable DMA clustering.

Note: without patch "Exynos: Fix the maximum segment size", this patch breaks support for the Exynos controller.

---
  drivers/ufs/core/ufshcd.c | 1 -
  1 file changed, 1 deletion(-)
Quoted 12 lines

drivers/ufs/core/ufshcd.c static struct scsi_host_template · line 8433

Quoted 10 lines
drivers/ufs/core/ufshcd.c index renamed from drivers/ufs/core/ufshcd.c +0 -0

be18edf4ef7f..fe83fdda8d23 100644

drivers/ufs/core/ufshcd.c +0 -1
@@ -8429,7 +8429,6 @@ static struct scsi_host_template
 ufshcd_driver_template = {
         .max_host_blocked       = 1,
         .track_queue_depth      = 1,
         .sdev_groups            = ufshcd_driver_groups,
-       .dma_boundary           = PAGE_SIZE - 1,

Isn't DBC <= 256KB implies that for a boundary?

Hi Avri,

I don't think so. I think that the 256 KiB limit for the PRDT corresponds to the max_segment_size parameter. The dma_boundary parameter represents a boundary that must not be crossed by DMA scatter/gather lists. I'm not aware of any restrictions on DMA scatter/gather lists for UFS controllers other than the 256 KiB limit for a single PRDT and a limitation to 32-bits addresses for controllers that only support 32-bits DMA. The latter restriction is already handled by ufshcd_set_dma_mask().

Bart.

Acked-by on v1 3/3
#9 lore raw

Re: [PATCH 3/3] scsi: ufs: Enable DMA clustering

In reply to Bart Van Assche
Quoted 2 lines · Bart Van Assche

All UFS host controllers support DMA clustering. Hence enable DMA clustering.

The patch history of ufshcd.c seems to suggest the dma_boundary setting was never intentional, but was inherited by default.

However, I guess it is not impossible that removing the setting exposes issues for existing controllers.

I suggest perhaps expanding upon the commit message and the cc list so more people will be aware of the change.

Possibly worth including the explanation in your reply to Avri concerning PRDT 256K DBC limit

Quoted 5 lines

Note: without patch "Exynos: Fix the maximum segment size", this patch breaks support for the Exynos controller.

Otherwise:

Quoted 16 lines
---
 drivers/ufs/core/ufshcd.c | 1 -
 1 file changed, 1 deletion(-)
drivers/ufs/core/ufshcd.c +0 -1
index be18edf4ef7f..fe83fdda8d23 100644
@@ -8429,7 +8429,6 @@ static struct scsi_host_template ufshcd_driver_template = {
 	.max_host_blocked	= 1,
 	.track_queue_depth	= 1,
 	.sdev_groups		= ufshcd_driver_groups,
-	.dma_boundary		= PAGE_SIZE - 1,
 	.rpm_autosuspend_delay	= RPM_AUTOSUSPEND_DELAY_MS,
 };
 
author reviewer
#10 lore raw

Re: [PATCH 3/3] scsi: ufs: Enable DMA clustering

Quoted 17 lines · Adrian Hunter
Quoted 2 lines · Bart Van Assche

All UFS host controllers support DMA clustering. Hence enable DMA clustering.

The patch history of ufshcd.c seems to suggest the dma_boundary setting was never intentional, but was inherited by default.

However, I guess it is not impossible that removing the setting exposes issues for existing controllers.

I suggest perhaps expanding upon the commit message and the cc list so more people will be aware of the change.

Possibly worth including the explanation in your reply to Avri concerning PRDT 256K DBC limit

Quoted 1 line
Quoted 8 lines
Quoted 4 lines

Note: without patch "Exynos: Fix the maximum segment size", this patch breaks support for the Exynos controller.

Otherwise:

Hi Adrian,

I will make the requested changes.

Thanks for the review!

Bart.