[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAD=FV=UgGNy2MkYsf5jjL-fcSsqz0vNYsdrpd4hcfG=7tuJcGQ@mail.gmail.com>
Date: Thu, 17 Dec 2020 13:45:18 -0800
From: Doug Anderson <dianders@...omium.org>
To: Stephen Boyd <swboyd@...omium.org>
Cc: Mark Brown <broonie@...nel.org>, msavaliy@....qualcomm.com,
Akash Asthana <akashast@...eaurora.org>,
Roja Rani Yarubandi <rojay@...eaurora.org>,
Alok Chauhan <alokc@...eaurora.org>,
Andy Gross <agross@...nel.org>,
Bjorn Andersson <bjorn.andersson@...aro.org>,
Dilip Kota <dkota@...eaurora.org>,
Girish Mahadevan <girishm@...eaurora.org>,
linux-arm-msm <linux-arm-msm@...r.kernel.org>,
LKML <linux-kernel@...r.kernel.org>,
linux-spi <linux-spi@...r.kernel.org>
Subject: Re: [PATCH v2 2/4] spi: spi-geni-qcom: Fail new xfers if
xfer/cancel/abort pending
Hi,
On Wed, Dec 16, 2020 at 8:21 PM Stephen Boyd <swboyd@...omium.org> wrote:
>
> Quoting Douglas Anderson (2020-12-16 14:41:50)
> > If we got a timeout when trying to send an abort command then it means
> > that we just got 3 timeouts in a row:
> >
> > 1. The original timeout that caused handle_fifo_timeout() to be
> > called.
> > 2. A one second timeout waiting for the cancel command to finish.
> > 3. A one second timeout waiting for the abort command to finish.
> >
> > SPI is clocked by the controller, so nothing (aside from a hardware
> > fault or a totally broken sequencer) should be causing the actual
> > commands to fail in hardware. However, even though the hardware
> > itself is not expected to fail (and it'd be hard to predict how we
> > should handle things if it did), it's easy to hit the timeout case by
> > simply blocking our interrupt handler from running for a long period
> > of time. Obviously the system is in pretty bad shape if a interrupt
> > handler is blocked for > 2 seconds, but there are certainly bugs (even
> > bugs in other unrelated drivers) that can make this happen.
> >
> > Let's make things a bit more robust against this case. If we fail to
> > abort we'll set a flag and then we'll block all future transfers until
> > we have no more interrupts pending.
>
> Why can't we forcibly roll the ball forward and clear the irq if it's a
> cancel/abort that's pending? Basically tell the hardware that we
> understand it did the job and canceled things out but our sad little CPU
> didn't run that irq handler yet. Here have a cookie and get ready for
> the next transfer.
>
> if (M_CMD_CANCEL_EN || M_CMD_ABORT_EN) /* but not the other irqs like CMD_DONE or refill fifos */
> writel(M_CMD_CANCEL_EN | M_CMD_ABORT_EN, se->base + SE_GENI_M_IRQ_CLEAR);
>
> This would let us limp along and try to send another transfer in the
> case that we timed out but the transfer went through by servicing our
> own interrupt.
A few problems:
1. The cancel and abort are commands and they generate a "done"
interrupt along with their "cancel" and/or "abort". Clearing the
cancel/abort without the done will leave things in a much more
confused state.
2. If we timed out all the way down then there's probably _also_
interrupts for the previous transfer still pending. Those would also
need to be cleared. ...and we'd need to disable watermarks / read
pending data.
3. Even if we tried to solve all that, we're probably still in
terrible shape. Sure, we could try to start another transfer, but if
the previous one failed because the interrupt handler was blocked then
the next one is just going to fail too so all the extra complexity we
just added to handle this was likely wasted.
The whole fact that you need to send little packets to the sequencer
(and wait for an interrupt to tell you that it got your packet) for
every last thing really doesn't work super well and it's just
especially bad for chip select.
> > +static bool spi_geni_is_abort_still_pending(struct spi_geni_master *mas)
> > +{
> > + struct geni_se *se = &mas->se;
> > + u32 m_irq, m_irq_en;
> > +
> > + if (!mas->abort_failed)
> > + return false;
> > +
> > + /*
> > + * The only known case where a transfer times out and then a cancel
> > + * times out then an abort times out is if something is blocking our
> > + * interrupt handler from running. Avoid starting any new transfers
> > + * until that sorts itself out.
> > + */
> > + m_irq = readl(se->base + SE_GENI_M_IRQ_STATUS);
> > + m_irq_en = readl(se->base + SE_GENI_M_IRQ_EN);
>
> I suppose this could race with the irq handler. Maybe we should grab the
> irq lock around the register reads so we can synchronize with the irq
> handler and save a fail?
I don't _think_ it'll matter a whole lot but it also won't hurt, so sure.
-Doug
Powered by blists - more mailing lists