public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Mika Westerberg <mika.westerberg@linux.intel.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Olliver Schinagl <oliver@schinagl.nl>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Andreas Noever <andreas.noever@gmail.com>,
	Michael Jamet <michael.jamet@intel.com>,
	Yehezkel Bernat <YehezkelShB@gmail.com>
Subject: [PATCH v1 2/2] thunderbolt: Make use of ioread32_poll_timeout()
Date: Thu, 30 Mar 2023 17:14:13 +0300	[thread overview]
Message-ID: <20230330141413.25569-2-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20230330141413.25569-1-andriy.shevchenko@linux.intel.com>

Instead of open coding the same routine switch the code to use
ioread32_poll_timeout().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/thunderbolt/nhi.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c
index d76e923fbc6a..d0bf11b40131 100644
--- a/drivers/thunderbolt/nhi.c
+++ b/drivers/thunderbolt/nhi.c
@@ -16,8 +16,8 @@
 #include <linux/dma-mapping.h>
 #include <linux/interrupt.h>
 #include <linux/iommu.h>
+#include <linux/iopoll.h>
 #include <linux/module.h>
-#include <linux/delay.h>
 #include <linux/property.h>
 #include <linux/string_helpers.h>
 
@@ -40,7 +40,7 @@
 #define MSIX_MIN_VECS		6
 #define MSIX_MAX_VECS		16
 
-#define NHI_MAILBOX_TIMEOUT	500 /* ms */
+#define NHI_MAILBOX_TIMEOUT_US	500000
 
 /* Host interface quirks */
 #define QUIRK_AUTO_CLEAR_INT	BIT(0)
@@ -830,8 +830,8 @@ EXPORT_SYMBOL_GPL(tb_ring_free);
  */
 int nhi_mailbox_cmd(struct tb_nhi *nhi, enum nhi_mailbox_cmd cmd, u32 data)
 {
-	ktime_t timeout;
 	u32 val;
+	int ret;
 
 	iowrite32(data, nhi->iobase + REG_INMAIL_DATA);
 
@@ -840,16 +840,12 @@ int nhi_mailbox_cmd(struct tb_nhi *nhi, enum nhi_mailbox_cmd cmd, u32 data)
 	val |= REG_INMAIL_OP_REQUEST | cmd;
 	iowrite32(val, nhi->iobase + REG_INMAIL_CMD);
 
-	timeout = ktime_add_ms(ktime_get(), NHI_MAILBOX_TIMEOUT);
-	do {
-		val = ioread32(nhi->iobase + REG_INMAIL_CMD);
-		if (!(val & REG_INMAIL_OP_REQUEST))
-			break;
-		usleep_range(10, 20);
-	} while (ktime_before(ktime_get(), timeout));
+	ret = ioread32_poll_timeout(nhi->iobase + REG_INMAIL_CMD,
+				    val, !(val & REG_INMAIL_OP_REQUEST),
+				    40, NHI_MAILBOX_TIMEOUT_US);
+	if (ret)
+		return ret;
 
-	if (val & REG_INMAIL_OP_REQUEST)
-		return -ETIMEDOUT;
 	if (val & REG_INMAIL_ERROR)
 		return -EIO;
 
-- 
2.40.0.1.gaa8946217a0b


  reply	other threads:[~2023-03-30 14:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-30 14:14 [PATCH v1 1/2] iopoll: Introduce ioreadXX_poll_timeout() macros Andy Shevchenko
2023-03-30 14:14 ` Andy Shevchenko [this message]
2023-03-31  8:12 ` Olliver Schinagl
2023-04-05  8:58   ` Andy Shevchenko
2023-04-05  9:41     ` Mika Westerberg
2023-04-05 11:15       ` Andy Shevchenko
2023-04-05 11:18         ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230330141413.25569-2-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=YehezkelShB@gmail.com \
    --cc=andreas.noever@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=michael.jamet@intel.com \
    --cc=mika.westerberg@linux.intel.com \
    --cc=oliver@schinagl.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox