2018-08-09 06:41:55

by George Cherian

[permalink] [raw]
Subject: [PATCH v2] i2c: xlp9xx: Fix case where SSIF read transaction completes early

During ipmi stress tests we see occasional failure of transactions
at the boot time. This happens in the case of a I2C_M_RECV_LEN
transactions, when the read transfer completes (with the initial
read length of 34) before the driver gets a chance to handle interrupts.

The current driver code expects at least 2 interrupts for I2C_M_RECV_LEN
transactions. The length is updated during the first interrupt, and the
buffer contents are only copied during subsequent interrupts. In case of
just one interrupt, we will complete the transaction without copying
out the bytes from RX fifo.

Update the code to drain the RX fifo after the length update,
so that the transaction completes correctly in all cases.

Signed-off-by: George Cherian <[email protected]>
---
drivers/i2c/busses/i2c-xlp9xx.c | 41 ++++++++++++++++++++++++++++-------------
1 file changed, 28 insertions(+), 13 deletions(-)

diff --git a/drivers/i2c/busses/i2c-xlp9xx.c b/drivers/i2c/busses/i2c-xlp9xx.c
index 1f41a4f..7134f72 100644
--- a/drivers/i2c/busses/i2c-xlp9xx.c
+++ b/drivers/i2c/busses/i2c-xlp9xx.c
@@ -191,28 +191,43 @@ static void xlp9xx_i2c_drain_rx_fifo(struct xlp9xx_i2c_dev *priv)
if (priv->len_recv) {
/* read length byte */
rlen = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_MRXFIFO);
+
+ /*
+ * We expect at least 2 interrupts for I2C_M_RECV_LEN
+ * transactions. The length is updated during the first
+ * interrupt, and the buffer contents are only copied
+ * during subsequent interrupts. If in case the interrupts
+ * get merged we would complete the transaction without
+ * copying out the bytes from RX fifo. To avoid this now we
+ * drain the fifo as and when data is available.
+ * We drained the rlen byte already, decrement total length
+ * by one.
+ */
+
+ len--;
if (rlen > I2C_SMBUS_BLOCK_MAX || rlen == 0) {
rlen = 0; /*abort transfer */
priv->msg_buf_remaining = 0;
priv->msg_len = 0;
- } else {
- *buf++ = rlen;
- if (priv->client_pec)
- ++rlen; /* account for error check byte */
- /* update remaining bytes and message length */
- priv->msg_buf_remaining = rlen;
- priv->msg_len = rlen + 1;
+ xlp9xx_i2c_update_rlen(priv);
+ return;
}
+
+ *buf++ = rlen;
+ if (priv->client_pec)
+ ++rlen; /* account for error check byte */
+ /* update remaining bytes and message length */
+ priv->msg_buf_remaining = rlen;
+ priv->msg_len = rlen + 1;
xlp9xx_i2c_update_rlen(priv);
priv->len_recv = false;
- } else {
- len = min(priv->msg_buf_remaining, len);
- for (i = 0; i < len; i++, buf++)
- *buf = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_MRXFIFO);
-
- priv->msg_buf_remaining -= len;
}

+ len = min(priv->msg_buf_remaining, len);
+ for (i = 0; i < len; i++, buf++)
+ *buf = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_MRXFIFO);
+
+ priv->msg_buf_remaining -= len;
priv->msg_buf = buf;

if (priv->msg_buf_remaining)
--
1.8.3.1



2018-08-09 15:41:13

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH v2] i2c: xlp9xx: Fix case where SSIF read transaction completes early

On Wed, Aug 08, 2018 at 11:36:48PM -0700, George Cherian wrote:
> During ipmi stress tests we see occasional failure of transactions
> at the boot time. This happens in the case of a I2C_M_RECV_LEN
> transactions, when the read transfer completes (with the initial
> read length of 34) before the driver gets a chance to handle interrupts.
>
> The current driver code expects at least 2 interrupts for I2C_M_RECV_LEN
> transactions. The length is updated during the first interrupt, and the
> buffer contents are only copied during subsequent interrupts. In case of
> just one interrupt, we will complete the transaction without copying
> out the bytes from RX fifo.
>
> Update the code to drain the RX fifo after the length update,
> so that the transaction completes correctly in all cases.
>
> Signed-off-by: George Cherian <[email protected]>

Applied to for-current, thanks!


Attachments:
(No filename) (912.00 B)
signature.asc (849.00 B)
Download all attachments

2018-08-09 15:44:42

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH v2] i2c: xlp9xx: Fix case where SSIF read transaction completes early

On Thu, Aug 09, 2018 at 05:39:59PM +0200, Wolfram Sang wrote:
> On Wed, Aug 08, 2018 at 11:36:48PM -0700, George Cherian wrote:
> > During ipmi stress tests we see occasional failure of transactions
> > at the boot time. This happens in the case of a I2C_M_RECV_LEN
> > transactions, when the read transfer completes (with the initial
> > read length of 34) before the driver gets a chance to handle interrupts.
> >
> > The current driver code expects at least 2 interrupts for I2C_M_RECV_LEN
> > transactions. The length is updated during the first interrupt, and the
> > buffer contents are only copied during subsequent interrupts. In case of
> > just one interrupt, we will complete the transaction without copying
> > out the bytes from RX fifo.
> >
> > Update the code to drain the RX fifo after the length update,
> > so that the transaction completes correctly in all cases.
> >
> > Signed-off-by: George Cherian <[email protected]>
>
> Applied to for-current, thanks!

...and added stable.


Attachments:
(No filename) (1.01 kB)
signature.asc (849.00 B)
Download all attachments