diff mbox series

[2/3] i2c: qcom-geni: Propagate GENI_ABORT_DONE to geni_i2c_abort_xfer()

Message ID 20220717035027.2135106-3-bjorn.andersson@linaro.org (mailing list archive)
State Not Applicable
Headers show
Series i2c: qcom-geni: Make it possible to run i2cdetect | expand

Commit Message

Bjorn Andersson July 17, 2022, 3:50 a.m. UTC
Waiting for M_CMD_ABORT_EN in geni_i2c_abort_xfer() races with the
interrupt handler which will read and clear the abort bit, the result is
that every abort attempt takes 1 second and is followed by a message
about the abort having times out.

Introduce a new state variable to carry the abort_done state from the
interrupt handler back to geni_i2c_abort_xfer().

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
---
 drivers/i2c/busses/i2c-qcom-geni.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

Comments

Vinod Koul July 18, 2022, 5:36 a.m. UTC | #1
On 16-07-22, 20:50, Bjorn Andersson wrote:
> Waiting for M_CMD_ABORT_EN in geni_i2c_abort_xfer() races with the
> interrupt handler which will read and clear the abort bit, the result is
> that every abort attempt takes 1 second and is followed by a message
> about the abort having times out.
> 
> Introduce a new state variable to carry the abort_done state from the
> interrupt handler back to geni_i2c_abort_xfer().

Reviewed-by: Vinod Koul <vkoul@kernel.org>
Andrew Halaney July 19, 2022, 8:50 p.m. UTC | #2
On Sat, Jul 16, 2022 at 08:50:26PM -0700, Bjorn Andersson wrote:
> Waiting for M_CMD_ABORT_EN in geni_i2c_abort_xfer() races with the
> interrupt handler which will read and clear the abort bit, the result is
> that every abort attempt takes 1 second and is followed by a message
> about the abort having times out.
> 
> Introduce a new state variable to carry the abort_done state from the
> interrupt handler back to geni_i2c_abort_xfer().
> 
> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> ---
>  drivers/i2c/busses/i2c-qcom-geni.c | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c
> index 3bec7c782824..e212e7ae7ad2 100644
> --- a/drivers/i2c/busses/i2c-qcom-geni.c
> +++ b/drivers/i2c/busses/i2c-qcom-geni.c
> @@ -97,6 +97,7 @@ struct geni_i2c_dev {
>  	struct dma_chan *tx_c;
>  	struct dma_chan *rx_c;
>  	bool gpi_mode;
> +	bool abort_done;
>  };
>  
>  struct geni_i2c_err_log {
> @@ -203,9 +204,14 @@ static void geni_i2c_err(struct geni_i2c_dev *gi2c, int err)
>  		dev_dbg(gi2c->se.dev, "len:%d, slv-addr:0x%x, RD/WR:%d\n",
>  			gi2c->cur->len, gi2c->cur->addr, gi2c->cur->flags);
>  
> -	if (err != NACK && err != GENI_ABORT_DONE) {
> +	switch (err) {
> +	case GENI_ABORT_DONE:
> +		gi2c->abort_done = true;
> +		break;
> +	default:
>  		dev_err(gi2c->se.dev, "%s\n", gi2c_log[err].msg);
>  		geni_i2c_err_misc(gi2c);
> +		break;
>  	}
>  }
>  

If I'm reading this right this changes the behavior on a NACK error now,
right? Was that intentional?

Otherwise looks good to me.

> @@ -311,21 +317,21 @@ static irqreturn_t geni_i2c_irq(int irq, void *dev)
>  
>  static void geni_i2c_abort_xfer(struct geni_i2c_dev *gi2c)
>  {
> -	u32 val;
>  	unsigned long time_left = ABORT_TIMEOUT;
>  	unsigned long flags;
>  
>  	spin_lock_irqsave(&gi2c->lock, flags);
>  	geni_i2c_err(gi2c, GENI_TIMEOUT);
>  	gi2c->cur = NULL;
> +	gi2c->abort_done = false;
>  	geni_se_abort_m_cmd(&gi2c->se);
>  	spin_unlock_irqrestore(&gi2c->lock, flags);
> +
>  	do {
>  		time_left = wait_for_completion_timeout(&gi2c->done, time_left);
> -		val = readl_relaxed(gi2c->se.base + SE_GENI_M_IRQ_STATUS);
> -	} while (!(val & M_CMD_ABORT_EN) && time_left);
> +	} while (!gi2c->abort_done && time_left);
>  
> -	if (!(val & M_CMD_ABORT_EN))
> +	if (!time_left)
>  		dev_err(gi2c->se.dev, "Timeout abort_m_cmd\n");
>  }
>  
> -- 
> 2.35.1
>
Andrew Halaney July 19, 2022, 8:57 p.m. UTC | #3
On Tue, Jul 19, 2022 at 03:50:54PM -0500, Andrew Halaney wrote:
> On Sat, Jul 16, 2022 at 08:50:26PM -0700, Bjorn Andersson wrote:
> > Waiting for M_CMD_ABORT_EN in geni_i2c_abort_xfer() races with the
> > interrupt handler which will read and clear the abort bit, the result is
> > that every abort attempt takes 1 second and is followed by a message
> > about the abort having times out.
> > 
> > Introduce a new state variable to carry the abort_done state from the
> > interrupt handler back to geni_i2c_abort_xfer().
> > 
> > Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> > ---
> >  drivers/i2c/busses/i2c-qcom-geni.c | 16 +++++++++++-----
> >  1 file changed, 11 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c
> > index 3bec7c782824..e212e7ae7ad2 100644
> > --- a/drivers/i2c/busses/i2c-qcom-geni.c
> > +++ b/drivers/i2c/busses/i2c-qcom-geni.c
> > @@ -97,6 +97,7 @@ struct geni_i2c_dev {
> >  	struct dma_chan *tx_c;
> >  	struct dma_chan *rx_c;
> >  	bool gpi_mode;
> > +	bool abort_done;
> >  };
> >  
> >  struct geni_i2c_err_log {
> > @@ -203,9 +204,14 @@ static void geni_i2c_err(struct geni_i2c_dev *gi2c, int err)
> >  		dev_dbg(gi2c->se.dev, "len:%d, slv-addr:0x%x, RD/WR:%d\n",
> >  			gi2c->cur->len, gi2c->cur->addr, gi2c->cur->flags);
> >  
> > -	if (err != NACK && err != GENI_ABORT_DONE) {
> > +	switch (err) {
> > +	case GENI_ABORT_DONE:
> > +		gi2c->abort_done = true;
> > +		break;
> > +	default:
> >  		dev_err(gi2c->se.dev, "%s\n", gi2c_log[err].msg);
> >  		geni_i2c_err_misc(gi2c);
> > +		break;
> >  	}
> >  }
> >  
> 
> If I'm reading this right this changes the behavior on a NACK error now,
> right? Was that intentional?
> 
> Otherwise looks good to me.
> 

Hmmm (I should really review the whole series before hitting send :P ),
it seems you cleaned the NACK stuff up in the next patch in the series.

I guess one more thing, does this patch deserve a Fixes: tag? If so
might be nice to make NACK not so loud in this patch in case it gets
backported without the next patch.

Thanks,
Andrew

> > @@ -311,21 +317,21 @@ static irqreturn_t geni_i2c_irq(int irq, void *dev)
> >  
> >  static void geni_i2c_abort_xfer(struct geni_i2c_dev *gi2c)
> >  {
> > -	u32 val;
> >  	unsigned long time_left = ABORT_TIMEOUT;
> >  	unsigned long flags;
> >  
> >  	spin_lock_irqsave(&gi2c->lock, flags);
> >  	geni_i2c_err(gi2c, GENI_TIMEOUT);
> >  	gi2c->cur = NULL;
> > +	gi2c->abort_done = false;
> >  	geni_se_abort_m_cmd(&gi2c->se);
> >  	spin_unlock_irqrestore(&gi2c->lock, flags);
> > +
> >  	do {
> >  		time_left = wait_for_completion_timeout(&gi2c->done, time_left);
> > -		val = readl_relaxed(gi2c->se.base + SE_GENI_M_IRQ_STATUS);
> > -	} while (!(val & M_CMD_ABORT_EN) && time_left);
> > +	} while (!gi2c->abort_done && time_left);
> >  
> > -	if (!(val & M_CMD_ABORT_EN))
> > +	if (!time_left)
> >  		dev_err(gi2c->se.dev, "Timeout abort_m_cmd\n");
> >  }
> >  
> > -- 
> > 2.35.1
> >
Wolfram Sang July 24, 2022, 5:15 a.m. UTC | #4
> I guess one more thing, does this patch deserve a Fixes: tag? If so
> might be nice to make NACK not so loud in this patch in case it gets
> backported without the next patch.

I squashed the two patches to keep the NACK behaviour and ease
backporting.
Wolfram Sang July 24, 2022, 5:15 a.m. UTC | #5
On Sat, Jul 16, 2022 at 08:50:26PM -0700, Bjorn Andersson wrote:
> Waiting for M_CMD_ABORT_EN in geni_i2c_abort_xfer() races with the
> interrupt handler which will read and clear the abort bit, the result is
> that every abort attempt takes 1 second and is followed by a message
> about the abort having times out.
> 
> Introduce a new state variable to carry the abort_done state from the
> interrupt handler back to geni_i2c_abort_xfer().
> 
> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>

Applied to for-next, thanks!
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c
index 3bec7c782824..e212e7ae7ad2 100644
--- a/drivers/i2c/busses/i2c-qcom-geni.c
+++ b/drivers/i2c/busses/i2c-qcom-geni.c
@@ -97,6 +97,7 @@  struct geni_i2c_dev {
 	struct dma_chan *tx_c;
 	struct dma_chan *rx_c;
 	bool gpi_mode;
+	bool abort_done;
 };
 
 struct geni_i2c_err_log {
@@ -203,9 +204,14 @@  static void geni_i2c_err(struct geni_i2c_dev *gi2c, int err)
 		dev_dbg(gi2c->se.dev, "len:%d, slv-addr:0x%x, RD/WR:%d\n",
 			gi2c->cur->len, gi2c->cur->addr, gi2c->cur->flags);
 
-	if (err != NACK && err != GENI_ABORT_DONE) {
+	switch (err) {
+	case GENI_ABORT_DONE:
+		gi2c->abort_done = true;
+		break;
+	default:
 		dev_err(gi2c->se.dev, "%s\n", gi2c_log[err].msg);
 		geni_i2c_err_misc(gi2c);
+		break;
 	}
 }
 
@@ -311,21 +317,21 @@  static irqreturn_t geni_i2c_irq(int irq, void *dev)
 
 static void geni_i2c_abort_xfer(struct geni_i2c_dev *gi2c)
 {
-	u32 val;
 	unsigned long time_left = ABORT_TIMEOUT;
 	unsigned long flags;
 
 	spin_lock_irqsave(&gi2c->lock, flags);
 	geni_i2c_err(gi2c, GENI_TIMEOUT);
 	gi2c->cur = NULL;
+	gi2c->abort_done = false;
 	geni_se_abort_m_cmd(&gi2c->se);
 	spin_unlock_irqrestore(&gi2c->lock, flags);
+
 	do {
 		time_left = wait_for_completion_timeout(&gi2c->done, time_left);
-		val = readl_relaxed(gi2c->se.base + SE_GENI_M_IRQ_STATUS);
-	} while (!(val & M_CMD_ABORT_EN) && time_left);
+	} while (!gi2c->abort_done && time_left);
 
-	if (!(val & M_CMD_ABORT_EN))
+	if (!time_left)
 		dev_err(gi2c->se.dev, "Timeout abort_m_cmd\n");
 }