All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Glauber <jglauber@cavium.com>
To: Wolfram Sang <wsa@the-dreams.de>
Cc: linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org,
	ddaney@caviumnetworks.com, Peter Swain <pswain@cavium.com>,
	Jan Glauber <jglauber@cavium.com>
Subject: [Resend PATCH 07/10] i2c-octeon: Faster operation when IFLG signals late
Date: Mon, 29 Feb 2016 14:46:14 +0100	[thread overview]
Message-ID: <9a33135d05d6b084754fb1953e2351a9c69c537f.1456752497.git.jglauber@cavium.com> (raw)
In-Reply-To: <cover.1456752497.git.jglauber@cavium.com>
In-Reply-To: <cover.1456752497.git.jglauber@cavium.com>

From: Peter Swain <pswain@cavium.com>

Some versions can deliver low-level twsi irq before twsi_ctl.iflg
is set, leading to timeout-driven i/o.
When an irq signals event, but woken task does not see the expected
twsi_ctl.iflg, re-check about 80uS later.

EEPROM reads on 100kHz i2c now measure ~5.2kB/s, about 1/2 what's
achievable, and much better than the worst-case 100 bytes/sec before.

Signed-off-by: Peter Swain <pswain@cavium.com>
Signed-off-by: Jan Glauber <jglauber@cavium.com>
Acked-by: David Daney <ddaney@caviumnetworks.com>
---
 drivers/i2c/busses/i2c-octeon.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-octeon.c b/drivers/i2c/busses/i2c-octeon.c
index bb15a9c..e3552e5 100644
--- a/drivers/i2c/busses/i2c-octeon.c
+++ b/drivers/i2c/busses/i2c-octeon.c
@@ -130,6 +130,14 @@ static int timeout = 2;
 module_param(timeout, int, 0444);
 MODULE_PARM_DESC(timeout, "Low-level device timeout (ms)");
 
+/*
+ * On some hardware IFLG is not visible in TWSI_CTL until after low-level IRQ,
+ * so re-sample CTL a short time later to avoid stalls.
+ */
+static int irq_early_us = 80;
+module_param(irq_early_us, int, 0644);
+MODULE_PARM_DESC(irq_early_us, "Re-poll for IFLG after IRQ (us)");
+
 static void writeqflush(u64 val, void __iomem *addr)
 {
 	__raw_writeq(val, addr);
@@ -343,6 +351,26 @@ static int octeon_i2c_test_iflg(struct octeon_i2c *i2c)
 	return (octeon_i2c_read_ctl(i2c) & TWSI_CTL_IFLG) != 0;
 }
 
+/*
+ * Wait-helper which addresses the delayed-IFLAG problem by re-polling for
+ * missing TWSI_CTL[IFLG] a few us later, when irq has signalled an event,
+ * but none found. Skip this re-poll on the first (non-wakeup) call.
+ */
+static int poll_iflg(struct octeon_i2c *i2c, int *first_p)
+{
+	int iflg = octeon_i2c_test_iflg(i2c);
+
+	if (iflg)
+		return 1;
+	if (*first_p)
+		*first_p = 0;
+	else {
+		usleep_range(irq_early_us, 2 * irq_early_us);
+		iflg = octeon_i2c_test_iflg(i2c);
+	}
+	return iflg;
+}
+
 /**
  * octeon_i2c_wait - wait for the IFLG to be set
  * @i2c: The struct octeon_i2c
@@ -351,10 +379,11 @@ static int octeon_i2c_test_iflg(struct octeon_i2c *i2c)
  */
 static int octeon_i2c_wait(struct octeon_i2c *i2c)
 {
+	int first = 1;
 	long result;
 
 	i2c->int_en(i2c);
-	result = wait_event_timeout(i2c->queue, octeon_i2c_test_iflg(i2c),
+	result = wait_event_timeout(i2c->queue, poll_iflg(i2c, &first),
 				    i2c->adap.timeout);
 	i2c->int_dis(i2c);
 	if (!result) {
-- 
1.9.1

  parent reply	other threads:[~2016-02-29 13:48 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-29 13:46 [Resend PATCH 00/10] i2c-octeon and i2c-thunderx drivers Jan Glauber
2016-02-29 13:46 ` [Resend PATCH 01/10] i2c-octeon: Cleanup i2c-octeon driver Jan Glauber
2016-02-29 13:46 ` [Resend PATCH 02/10] i2c-octeon: Support I2C_M_RECV_LEN Jan Glauber
2016-02-29 13:46 ` [Resend PATCH 03/10] i2c-octeon: Enable high-level controller and improve on bus contention Jan Glauber
2016-02-29 13:46 ` [Resend PATCH 04/10] dt-bindings: i2c: add Octeon cn78xx TWSI Jan Glauber
2016-02-29 13:46 ` [Resend PATCH 05/10] i2c-octeon: Add support for cn78XX chips Jan Glauber
2016-02-29 13:46 ` [Resend PATCH 06/10] i2c-octeon: Flush TWSI writes with readback Jan Glauber
2016-02-29 13:46 ` Jan Glauber [this message]
2016-02-29 13:46 ` [Resend PATCH 08/10] i2c-octeon: Add workaround for chips with broken irqs Jan Glauber
2016-02-29 13:46 ` [Resend PATCH 09/10] i2c: split i2c-octeon driver and add ThunderX support Jan Glauber
2016-02-29 14:55   ` kbuild test robot
2016-02-29 14:55     ` kbuild test robot
2016-03-01 13:53   ` [PATCH] i2c-thunderx: fix compile error for x86_64 Jan Glauber
2016-03-01 17:02     ` David Daney
2016-03-01 17:02       ` David Daney
2016-02-29 13:46 ` [Resend PATCH 10/10] i2c: thunderx: add smbus support Jan Glauber

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=9a33135d05d6b084754fb1953e2351a9c69c537f.1456752497.git.jglauber@cavium.com \
    --to=jglauber@cavium.com \
    --cc=ddaney@caviumnetworks.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pswain@cavium.com \
    --cc=wsa@the-dreams.de \
    /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 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.