[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a642dc060b484d98bc728eb1f4b5c600@AcuMS.aculab.com>
Date: Wed, 28 Mar 2018 11:30:54 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Benjamin Herrenschmidt' <benh@...nel.crashing.org>,
Will Deacon <will.deacon@....com>
CC: Linus Torvalds <torvalds@...ux-foundation.org>,
Alexander Duyck <alexander.duyck@...il.com>,
Sinan Kaya <okaya@...eaurora.org>,
Arnd Bergmann <arnd@...db.de>, Jason Gunthorpe <jgg@...pe.ca>,
Oliver <oohall@...il.com>,
"open list:LINUX FOR POWERPC (32-BIT AND 64-BIT)"
<linuxppc-dev@...ts.ozlabs.org>,
"linux-rdma@...r.kernel.org" <linux-rdma@...r.kernel.org>,
"Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>
Subject: RE: RFC on writel and writel_relaxed
From: Benjamin Herrenschmidt
> Sent: 28 March 2018 10:56
...
> For example, let's say I have a device with a reset bit and the spec
> says the reset bit needs to be set for at least 10us.
>
> This is wrong:
>
> writel(1, RESET_REG);
> usleep(10);
> writel(0, RESET_REG);
>
> Because of write posting, the first write might arrive to the device
> right before the second one.
>
> The typical "fix" is to turn that into:
>
> writel(1, RESET_REG);
> readl(RESET_REG); /* Flush posted writes */
Would a writel(1, RESET_REG) here provide enough synchronsiation?
> usleep(10);
> writel(0, RESET_REG);
>
> *However* the issue here, at least on power, is that the CPU can issue
> that readl but doesn't necessarily wait for it to complete (ie, the
> data to return), before proceeding to the usleep. Now a usleep contains
> a bunch of loads and stores and is probably fine, but a udelay which
> just loops on the timebase may not be.
>
> Thus we may still violate the timing requirement.
I've seem that sort of code (with udelay() and no read back) quite often.
How many were in linux I don't know.
For small delays I usually fix it by repeated writes (of the same value)
to the device register. That can guarantee very short intervals.
The only time I've actually seen buffered writes break timing was
between a 286 and an 8859 interrupt controller.
If you wrote to the mask then enabled interrupts the first IACK cycle
could be too close to write and break the cycle recovery time.
That clobbered most of the interrupt controller registers.
That probably affected every 286 board ever built!
Not sure how much software added the required extra bus cycle.
> What we did inside readl, with the twi;isync sequence (which basically
> means, trap on return value with "trap never" as a condition, followed
> by isync that ensures all excpetion conditions are resolved), is force
> the CPU to "consume" the data from the read before moving on.
>
> This effectively makes readl fully synchronous (we would probably avoid
> that if we were to implement a readl_relaxed).
I've always wondered exactly what the twi;isync were for - always seemed
very heavy handed for most mmio reads.
Particularly if you are doing mmio reads from a data fifo.
Perhaps there should be a writel_wait() that is allowed to do a read back
for such code paths?
David
Powered by blists - more mailing lists