linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: ufs: Do not open code read_poll_timeout
@ 2024-09-19 11:24 Avri Altman
  2024-09-20 18:23 ` Bart Van Assche
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Avri Altman @ 2024-09-19 11:24 UTC (permalink / raw)
  To: Martin K . Petersen
  Cc: linux-scsi, linux-kernel, Bart Van Assche, Avri Altman

ufshcd_wait_for_register practically does just that - replace with
read_poll_timeout.

Signed-off-by: Avri Altman <avri.altman@wdc.com>
---
 drivers/ufs/core/ufshcd.c | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 8ea5a82503a9..e9d06fab5f45 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -739,25 +739,15 @@ EXPORT_SYMBOL_GPL(ufshcd_delay_us);
  * Return: -ETIMEDOUT on error, zero on success.
  */
 static int ufshcd_wait_for_register(struct ufs_hba *hba, u32 reg, u32 mask,
-				u32 val, unsigned long interval_us,
-				unsigned long timeout_ms)
+				    u32 val, unsigned long interval_us,
+				    unsigned long timeout_ms)
 {
-	int err = 0;
-	unsigned long timeout = jiffies + msecs_to_jiffies(timeout_ms);
-
-	/* ignore bits that we don't intend to wait on */
-	val = val & mask;
+	u32 v;
 
-	while ((ufshcd_readl(hba, reg) & mask) != val) {
-		usleep_range(interval_us, interval_us + 50);
-		if (time_after(jiffies, timeout)) {
-			if ((ufshcd_readl(hba, reg) & mask) != val)
-				err = -ETIMEDOUT;
-			break;
-		}
-	}
+	val &= mask; /* ignore bits that we don't intend to wait on */
 
-	return err;
+	return read_poll_timeout(ufshcd_readl, v, (v & mask) == val,
+				 interval_us, timeout_ms * 1000, false, hba, reg);
 }
 
 /**
-- 
2.25.1


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

* Re: [PATCH] scsi: ufs: Do not open code read_poll_timeout
  2024-09-19 11:24 [PATCH] scsi: ufs: Do not open code read_poll_timeout Avri Altman
@ 2024-09-20 18:23 ` Bart Van Assche
  2024-09-20 19:00   ` Avri Altman
  2024-09-20 19:38 ` Bart Van Assche
  2024-10-04  1:49 ` Martin K. Petersen
  2 siblings, 1 reply; 6+ messages in thread
From: Bart Van Assche @ 2024-09-20 18:23 UTC (permalink / raw)
  To: Avri Altman, Martin K . Petersen; +Cc: linux-scsi, linux-kernel

On 9/19/24 4:24 AM, Avri Altman wrote:
> ufshcd_wait_for_register practically does just that - replace with
> read_poll_timeout.
> 
> Signed-off-by: Avri Altman <avri.altman@wdc.com>
> ---
>   drivers/ufs/core/ufshcd.c | 22 ++++++----------------
>   1 file changed, 6 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index 8ea5a82503a9..e9d06fab5f45 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -739,25 +739,15 @@ EXPORT_SYMBOL_GPL(ufshcd_delay_us);
>    * Return: -ETIMEDOUT on error, zero on success.
>    */
>   static int ufshcd_wait_for_register(struct ufs_hba *hba, u32 reg, u32 mask,
> -				u32 val, unsigned long interval_us,
> -				unsigned long timeout_ms)
> +				    u32 val, unsigned long interval_us,
> +				    unsigned long timeout_ms)
>   {
> -	int err = 0;
> -	unsigned long timeout = jiffies + msecs_to_jiffies(timeout_ms);
> -
> -	/* ignore bits that we don't intend to wait on */
> -	val = val & mask;
> +	u32 v;
>   
> -	while ((ufshcd_readl(hba, reg) & mask) != val) {
> -		usleep_range(interval_us, interval_us + 50);
> -		if (time_after(jiffies, timeout)) {
> -			if ((ufshcd_readl(hba, reg) & mask) != val)
> -				err = -ETIMEDOUT;
> -			break;
> -		}
> -	}
> +	val &= mask; /* ignore bits that we don't intend to wait on */
>   
> -	return err;
> +	return read_poll_timeout(ufshcd_readl, v, (v & mask) == val,
> +				 interval_us, timeout_ms * 1000, false, hba, reg);
>   }
>   
>   /**

Has it been considered to remove the ufshcd_wait_for_register() function
and to use read_poll_timeout() directly in the
ufshcd_wait_for_register() callers? The above patch makes
ufshcd_wait_for_register() so short that it's probably better to remove
this function entirely.

Thanks,

Bart.

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

* RE: [PATCH] scsi: ufs: Do not open code read_poll_timeout
  2024-09-20 18:23 ` Bart Van Assche
@ 2024-09-20 19:00   ` Avri Altman
  2024-09-20 19:38     ` Bart Van Assche
  0 siblings, 1 reply; 6+ messages in thread
From: Avri Altman @ 2024-09-20 19:00 UTC (permalink / raw)
  To: Bart Van Assche, Martin K . Petersen
  Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org

> Has it been considered to remove the ufshcd_wait_for_register() function and
> to use read_poll_timeout() directly in the
> ufshcd_wait_for_register() callers? The above patch makes
> ufshcd_wait_for_register() so short that it's probably better to remove this
> function entirely.
Yes - I thought about it.
I think that the wait_for_register makes it much clearer what the function actually does,
And for that reason, only, it worth keeping the function name.
However, if it’s a must I can remove it as you suggested.

Thanks,
Avri

> 
> Thanks,
> 
> Bart.


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

* Re: [PATCH] scsi: ufs: Do not open code read_poll_timeout
  2024-09-19 11:24 [PATCH] scsi: ufs: Do not open code read_poll_timeout Avri Altman
  2024-09-20 18:23 ` Bart Van Assche
@ 2024-09-20 19:38 ` Bart Van Assche
  2024-10-04  1:49 ` Martin K. Petersen
  2 siblings, 0 replies; 6+ messages in thread
From: Bart Van Assche @ 2024-09-20 19:38 UTC (permalink / raw)
  To: Avri Altman, Martin K . Petersen; +Cc: linux-scsi, linux-kernel

On 9/19/24 4:24 AM, Avri Altman wrote:
> ufshcd_wait_for_register practically does just that - replace with
> read_poll_timeout.

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

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

* Re: [PATCH] scsi: ufs: Do not open code read_poll_timeout
  2024-09-20 19:00   ` Avri Altman
@ 2024-09-20 19:38     ` Bart Van Assche
  0 siblings, 0 replies; 6+ messages in thread
From: Bart Van Assche @ 2024-09-20 19:38 UTC (permalink / raw)
  To: Avri Altman, Martin K . Petersen
  Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org

On 9/20/24 12:00 PM, Avri Altman wrote:
> I think that the wait_for_register makes it much clearer what the function actually does,
> And for that reason, only, it worth keeping the function name.

That makes sense to me.

Thanks,

Bart.


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

* Re: [PATCH] scsi: ufs: Do not open code read_poll_timeout
  2024-09-19 11:24 [PATCH] scsi: ufs: Do not open code read_poll_timeout Avri Altman
  2024-09-20 18:23 ` Bart Van Assche
  2024-09-20 19:38 ` Bart Van Assche
@ 2024-10-04  1:49 ` Martin K. Petersen
  2 siblings, 0 replies; 6+ messages in thread
From: Martin K. Petersen @ 2024-10-04  1:49 UTC (permalink / raw)
  To: Avri Altman
  Cc: Martin K . Petersen, linux-scsi, linux-kernel, Bart Van Assche


Avri,

> ufshcd_wait_for_register practically does just that - replace with
> read_poll_timeout.

Applied to 6.13/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2024-10-04  1:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-19 11:24 [PATCH] scsi: ufs: Do not open code read_poll_timeout Avri Altman
2024-09-20 18:23 ` Bart Van Assche
2024-09-20 19:00   ` Avri Altman
2024-09-20 19:38     ` Bart Van Assche
2024-09-20 19:38 ` Bart Van Assche
2024-10-04  1:49 ` 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;
as well as URLs for NNTP newsgroup(s).