public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] ufs: mcq: Fix and cleanup unsafe macros
       [not found] <CGME20240519222604epcas2p3d427f2f5b3b0156881f6840443210931@epcas2p3.samsung.com>
@ 2024-05-19 22:14 ` Minwoo Im
  2024-05-19 22:14   ` [PATCH v2 1/2] ufs: mcq: Fix missing argument 'hba' in MCQ_OPR_OFFSET_n Minwoo Im
                     ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Minwoo Im @ 2024-05-19 22:14 UTC (permalink / raw)
  To: James E . J . Bottomley, Martin K . Petersen, Alim Akhtar,
	Avri Altman, Bart Van Assche
  Cc: linux-scsi, linux-kernel, Joel Granados, gost.dev, Minwoo Im,
	Asutosh Das

Hello,

This patch set fixes an potential bug for further usages in ufs-mcq.c and
contains a simple clean-up converting macro to an inline function.

Please review.

Thanks,

v2:
  - Fix missing argument 'hba' in MCQ_OPR_OFFSET_n by converting it to an
    inline function (Bart)
  - Added [2/2] patch to convert the remaining one macro in ufs-mcq.c to an
    inline function along with the previous patch for the sake of consistency.

Minwoo Im (2):
  ufs: mcq: Fix missing argument 'hba' in MCQ_OPR_OFFSET_n
  ufs: mcq: Convert MCQ_CFG_n to a inline function

 drivers/ufs/core/ufs-mcq.c | 35 ++++++++++++++---------------------
 include/ufs/ufshcd.h       | 13 +++++++++++++
 2 files changed, 27 insertions(+), 21 deletions(-)

-- 
2.34.1


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

* [PATCH v2 1/2] ufs: mcq: Fix missing argument 'hba' in MCQ_OPR_OFFSET_n
  2024-05-19 22:14 ` [PATCH v2 0/2] ufs: mcq: Fix and cleanup unsafe macros Minwoo Im
@ 2024-05-19 22:14   ` Minwoo Im
  2024-05-20 18:17     ` Bart Van Assche
  2024-05-19 22:14   ` [PATCH v2 2/2] ufs: mcq: Convert MCQ_CFG_n to a inline function Minwoo Im
  2024-05-31  0:46   ` [PATCH v2 0/2] ufs: mcq: Fix and cleanup unsafe macros Martin K. Petersen
  2 siblings, 1 reply; 6+ messages in thread
From: Minwoo Im @ 2024-05-19 22:14 UTC (permalink / raw)
  To: James E . J . Bottomley, Martin K . Petersen, Alim Akhtar,
	Avri Altman, Bart Van Assche
  Cc: linux-scsi, linux-kernel, Joel Granados, gost.dev, Minwoo Im,
	Asutosh Das

The MCQ_OPR_OFFSET_n macro has taken 'hba' on the caller context
without receiving 'hba' instance as an argument.  To prevent potential
bugs in future use cases, this patch added an argument 'hba'.

Fixes: 2468da61ea09 ("scsi: ufs: core: mcq: Configure operation and runtime interface")
Cc: Asutosh Das <quic_asutoshd@quicinc.com>
Signed-off-by: Minwoo Im <minwoo.im@samsung.com>
---
 drivers/ufs/core/ufs-mcq.c | 10 ++++------
 include/ufs/ufshcd.h       |  6 ++++++
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/ufs/core/ufs-mcq.c b/drivers/ufs/core/ufs-mcq.c
index 768bf87cd80d..b93ec147641c 100644
--- a/drivers/ufs/core/ufs-mcq.c
+++ b/drivers/ufs/core/ufs-mcq.c
@@ -231,8 +231,6 @@ int ufshcd_mcq_memory_alloc(struct ufs_hba *hba)
 
 /* Operation and runtime registers configuration */
 #define MCQ_CFG_n(r, i)	((r) + MCQ_QCFG_SIZE * (i))
-#define MCQ_OPR_OFFSET_n(p, i) \
-	(hba->mcq_opr[(p)].offset + hba->mcq_opr[(p)].stride * (i))
 
 static void __iomem *mcq_opr_base(struct ufs_hba *hba,
 					 enum ufshcd_mcq_opr n, int i)
@@ -343,10 +341,10 @@ void ufshcd_mcq_make_queues_operational(struct ufs_hba *hba)
 		ufsmcq_writelx(hba, upper_32_bits(hwq->sqe_dma_addr),
 			      MCQ_CFG_n(REG_SQUBA, i));
 		/* Submission Queue Doorbell Address Offset */
-		ufsmcq_writelx(hba, MCQ_OPR_OFFSET_n(OPR_SQD, i),
+		ufsmcq_writelx(hba, ufshcd_mcq_opr_offset(hba, OPR_SQD, i),
 			      MCQ_CFG_n(REG_SQDAO, i));
 		/* Submission Queue Interrupt Status Address Offset */
-		ufsmcq_writelx(hba, MCQ_OPR_OFFSET_n(OPR_SQIS, i),
+		ufsmcq_writelx(hba, ufshcd_mcq_opr_offset(hba, OPR_SQIS, i),
 			      MCQ_CFG_n(REG_SQISAO, i));
 
 		/* Completion Queue Lower Base Address */
@@ -356,10 +354,10 @@ void ufshcd_mcq_make_queues_operational(struct ufs_hba *hba)
 		ufsmcq_writelx(hba, upper_32_bits(hwq->cqe_dma_addr),
 			      MCQ_CFG_n(REG_CQUBA, i));
 		/* Completion Queue Doorbell Address Offset */
-		ufsmcq_writelx(hba, MCQ_OPR_OFFSET_n(OPR_CQD, i),
+		ufsmcq_writelx(hba, ufshcd_mcq_opr_offset(hba, OPR_CQD, i),
 			      MCQ_CFG_n(REG_CQDAO, i));
 		/* Completion Queue Interrupt Status Address Offset */
-		ufsmcq_writelx(hba, MCQ_OPR_OFFSET_n(OPR_CQIS, i),
+		ufsmcq_writelx(hba, ufshcd_mcq_opr_offset(hba, OPR_CQIS, i),
 			      MCQ_CFG_n(REG_CQISAO, i));
 
 		/* Save the base addresses for quicker access */
diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h
index a35e12f8e68b..eec7c97e3dbe 100644
--- a/include/ufs/ufshcd.h
+++ b/include/ufs/ufshcd.h
@@ -1132,6 +1132,12 @@ static inline bool is_mcq_enabled(struct ufs_hba *hba)
 	return hba->mcq_enabled;
 }
 
+static inline unsigned int ufshcd_mcq_opr_offset(struct ufs_hba *hba,
+		enum ufshcd_mcq_opr opr, int idx)
+{
+	return hba->mcq_opr[opr].offset + hba->mcq_opr[opr].stride * idx;
+}
+
 #ifdef CONFIG_SCSI_UFS_VARIABLE_SG_ENTRY_SIZE
 static inline size_t ufshcd_sg_entry_size(const struct ufs_hba *hba)
 {
-- 
2.34.1


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

* [PATCH v2 2/2] ufs: mcq: Convert MCQ_CFG_n to a inline function
  2024-05-19 22:14 ` [PATCH v2 0/2] ufs: mcq: Fix and cleanup unsafe macros Minwoo Im
  2024-05-19 22:14   ` [PATCH v2 1/2] ufs: mcq: Fix missing argument 'hba' in MCQ_OPR_OFFSET_n Minwoo Im
@ 2024-05-19 22:14   ` Minwoo Im
  2024-05-20 18:17     ` Bart Van Assche
  2024-05-31  0:46   ` [PATCH v2 0/2] ufs: mcq: Fix and cleanup unsafe macros Martin K. Petersen
  2 siblings, 1 reply; 6+ messages in thread
From: Minwoo Im @ 2024-05-19 22:14 UTC (permalink / raw)
  To: James E . J . Bottomley, Martin K . Petersen, Alim Akhtar,
	Avri Altman, Bart Van Assche
  Cc: linux-scsi, linux-kernel, Joel Granados, gost.dev, Minwoo Im,
	Asutosh Das

Unlike the previous patch, this patch does not fix any issues, but,
inline functions are much more preferred over macros, so this patch
converted MCQ_CFG_n macro in ufs-mcq to an inline function along with
the previous patch.

Signed-off-by: Minwoo Im <minwoo.im@samsung.com>
---
 drivers/ufs/core/ufs-mcq.c | 25 ++++++++++---------------
 include/ufs/ufshcd.h       |  7 +++++++
 2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/drivers/ufs/core/ufs-mcq.c b/drivers/ufs/core/ufs-mcq.c
index b93ec147641c..d15817a3900b 100644
--- a/drivers/ufs/core/ufs-mcq.c
+++ b/drivers/ufs/core/ufs-mcq.c
@@ -25,7 +25,6 @@
 #define QUEUE_ID_OFFSET 16
 
 #define MCQ_CFG_MAC_MASK	GENMASK(16, 8)
-#define MCQ_QCFG_SIZE		0x40
 #define MCQ_ENTRY_SIZE_IN_DWORD	8
 #define CQE_UCD_BA GENMASK_ULL(63, 7)
 
@@ -228,10 +227,6 @@ int ufshcd_mcq_memory_alloc(struct ufs_hba *hba)
 	return 0;
 }
 
-
-/* Operation and runtime registers configuration */
-#define MCQ_CFG_n(r, i)	((r) + MCQ_QCFG_SIZE * (i))
-
 static void __iomem *mcq_opr_base(struct ufs_hba *hba,
 					 enum ufshcd_mcq_opr n, int i)
 {
@@ -336,29 +331,29 @@ void ufshcd_mcq_make_queues_operational(struct ufs_hba *hba)
 
 		/* Submission Queue Lower Base Address */
 		ufsmcq_writelx(hba, lower_32_bits(hwq->sqe_dma_addr),
-			      MCQ_CFG_n(REG_SQLBA, i));
+			      ufshcd_mcq_cfg_offset(REG_SQLBA, i));
 		/* Submission Queue Upper Base Address */
 		ufsmcq_writelx(hba, upper_32_bits(hwq->sqe_dma_addr),
-			      MCQ_CFG_n(REG_SQUBA, i));
+			      ufshcd_mcq_cfg_offset(REG_SQUBA, i));
 		/* Submission Queue Doorbell Address Offset */
 		ufsmcq_writelx(hba, ufshcd_mcq_opr_offset(hba, OPR_SQD, i),
-			      MCQ_CFG_n(REG_SQDAO, i));
+			      ufshcd_mcq_cfg_offset(REG_SQDAO, i));
 		/* Submission Queue Interrupt Status Address Offset */
 		ufsmcq_writelx(hba, ufshcd_mcq_opr_offset(hba, OPR_SQIS, i),
-			      MCQ_CFG_n(REG_SQISAO, i));
+			      ufshcd_mcq_cfg_offset(REG_SQISAO, i));
 
 		/* Completion Queue Lower Base Address */
 		ufsmcq_writelx(hba, lower_32_bits(hwq->cqe_dma_addr),
-			      MCQ_CFG_n(REG_CQLBA, i));
+			      ufshcd_mcq_cfg_offset(REG_CQLBA, i));
 		/* Completion Queue Upper Base Address */
 		ufsmcq_writelx(hba, upper_32_bits(hwq->cqe_dma_addr),
-			      MCQ_CFG_n(REG_CQUBA, i));
+			      ufshcd_mcq_cfg_offset(REG_CQUBA, i));
 		/* Completion Queue Doorbell Address Offset */
 		ufsmcq_writelx(hba, ufshcd_mcq_opr_offset(hba, OPR_CQD, i),
-			      MCQ_CFG_n(REG_CQDAO, i));
+			      ufshcd_mcq_cfg_offset(REG_CQDAO, i));
 		/* Completion Queue Interrupt Status Address Offset */
 		ufsmcq_writelx(hba, ufshcd_mcq_opr_offset(hba, OPR_CQIS, i),
-			      MCQ_CFG_n(REG_CQISAO, i));
+			      ufshcd_mcq_cfg_offset(REG_CQISAO, i));
 
 		/* Save the base addresses for quicker access */
 		hwq->mcq_sq_head = mcq_opr_base(hba, OPR_SQD, i) + REG_SQHP;
@@ -375,7 +370,7 @@ void ufshcd_mcq_make_queues_operational(struct ufs_hba *hba)
 
 		/* Completion Queue Enable|Size to Completion Queue Attribute */
 		ufsmcq_writel(hba, (1 << QUEUE_EN_OFFSET) | qsize,
-			      MCQ_CFG_n(REG_CQATTR, i));
+			      ufshcd_mcq_cfg_offset(REG_CQATTR, i));
 
 		/*
 		 * Submission Qeueue Enable|Size|Completion Queue ID to
@@ -383,7 +378,7 @@ void ufshcd_mcq_make_queues_operational(struct ufs_hba *hba)
 		 */
 		ufsmcq_writel(hba, (1 << QUEUE_EN_OFFSET) | qsize |
 			      (i << QUEUE_ID_OFFSET),
-			      MCQ_CFG_n(REG_SQATTR, i));
+			      ufshcd_mcq_cfg_offset(REG_SQATTR, i));
 	}
 }
 EXPORT_SYMBOL_GPL(ufshcd_mcq_make_queues_operational);
diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h
index eec7c97e3dbe..94fa400b646e 100644
--- a/include/ufs/ufshcd.h
+++ b/include/ufs/ufshcd.h
@@ -1127,6 +1127,8 @@ struct ufs_hw_queue {
 	struct mutex sq_mutex;
 };
 
+#define MCQ_QCFG_SIZE		0x40
+
 static inline bool is_mcq_enabled(struct ufs_hba *hba)
 {
 	return hba->mcq_enabled;
@@ -1138,6 +1140,11 @@ static inline unsigned int ufshcd_mcq_opr_offset(struct ufs_hba *hba,
 	return hba->mcq_opr[opr].offset + hba->mcq_opr[opr].stride * idx;
 }
 
+static inline unsigned int ufshcd_mcq_cfg_offset(unsigned int reg, int idx)
+{
+	return reg + MCQ_QCFG_SIZE * idx;
+}
+
 #ifdef CONFIG_SCSI_UFS_VARIABLE_SG_ENTRY_SIZE
 static inline size_t ufshcd_sg_entry_size(const struct ufs_hba *hba)
 {
-- 
2.34.1


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

* Re: [PATCH v2 1/2] ufs: mcq: Fix missing argument 'hba' in MCQ_OPR_OFFSET_n
  2024-05-19 22:14   ` [PATCH v2 1/2] ufs: mcq: Fix missing argument 'hba' in MCQ_OPR_OFFSET_n Minwoo Im
@ 2024-05-20 18:17     ` Bart Van Assche
  0 siblings, 0 replies; 6+ messages in thread
From: Bart Van Assche @ 2024-05-20 18:17 UTC (permalink / raw)
  To: Minwoo Im, James E . J . Bottomley, Martin K . Petersen,
	Alim Akhtar, Avri Altman
  Cc: linux-scsi, linux-kernel, Joel Granados, gost.dev, Asutosh Das

On 5/19/24 15:14, Minwoo Im wrote:
> The MCQ_OPR_OFFSET_n macro has taken 'hba' on the caller context
> without receiving 'hba' instance as an argument.  To prevent potential
> bugs in future use cases, this patch added an argument 'hba'.

Reviewed-by: Bart Van Assche <bvanassche@acm.org>

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

* Re: [PATCH v2 2/2] ufs: mcq: Convert MCQ_CFG_n to a inline function
  2024-05-19 22:14   ` [PATCH v2 2/2] ufs: mcq: Convert MCQ_CFG_n to a inline function Minwoo Im
@ 2024-05-20 18:17     ` Bart Van Assche
  0 siblings, 0 replies; 6+ messages in thread
From: Bart Van Assche @ 2024-05-20 18:17 UTC (permalink / raw)
  To: Minwoo Im, James E . J . Bottomley, Martin K . Petersen,
	Alim Akhtar, Avri Altman
  Cc: linux-scsi, linux-kernel, Joel Granados, gost.dev, Asutosh Das

On 5/19/24 15:14, Minwoo Im wrote:
> Unlike the previous patch, this patch does not fix any issues, but,
> inline functions are much more preferred over macros, so this patch
> converted MCQ_CFG_n macro in ufs-mcq to an inline function along with
> the previous patch.

Reviewed-by: Bart Van Assche <bvanassche@acm.org>

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

* Re: [PATCH v2 0/2] ufs: mcq: Fix and cleanup unsafe macros
  2024-05-19 22:14 ` [PATCH v2 0/2] ufs: mcq: Fix and cleanup unsafe macros Minwoo Im
  2024-05-19 22:14   ` [PATCH v2 1/2] ufs: mcq: Fix missing argument 'hba' in MCQ_OPR_OFFSET_n Minwoo Im
  2024-05-19 22:14   ` [PATCH v2 2/2] ufs: mcq: Convert MCQ_CFG_n to a inline function Minwoo Im
@ 2024-05-31  0:46   ` Martin K. Petersen
  2 siblings, 0 replies; 6+ messages in thread
From: Martin K. Petersen @ 2024-05-31  0:46 UTC (permalink / raw)
  To: Minwoo Im
  Cc: James E . J . Bottomley, Martin K . Petersen, Alim Akhtar,
	Avri Altman, Bart Van Assche, linux-scsi, linux-kernel,
	Joel Granados, gost.dev, Asutosh Das


Minwoo,

> This patch set fixes an potential bug for further usages in ufs-mcq.c
> and contains a simple clean-up converting macro to an inline function.

Applied to 6.11/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2024-05-31  0:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CGME20240519222604epcas2p3d427f2f5b3b0156881f6840443210931@epcas2p3.samsung.com>
2024-05-19 22:14 ` [PATCH v2 0/2] ufs: mcq: Fix and cleanup unsafe macros Minwoo Im
2024-05-19 22:14   ` [PATCH v2 1/2] ufs: mcq: Fix missing argument 'hba' in MCQ_OPR_OFFSET_n Minwoo Im
2024-05-20 18:17     ` Bart Van Assche
2024-05-19 22:14   ` [PATCH v2 2/2] ufs: mcq: Convert MCQ_CFG_n to a inline function Minwoo Im
2024-05-20 18:17     ` Bart Van Assche
2024-05-31  0:46   ` [PATCH v2 0/2] ufs: mcq: Fix and cleanup unsafe macros Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox