WLAN from SDIO to SPI: battle plan

Werner Almesberger werner at openmoko.org
Wed Aug 27 14:50:18 CEST 2008

Andy Green wrote:
> http://warmcat.com/_wp/2007/05/25/the-alignment-monster/

Ah yes, good old misalignment, a non-x86 classic ;-)

This one is a lot more interesting, though. Not only does it mean that
at least some (perfectly aligned) accesses to registers done in this
way will produce the kind of wildly incorrect results Dennis has found,
but it also means that even accesses to registers that may happen to be
byte-accessible may cause all sorts of races.

A few examples:

- if an access clears interrupts, this may cause interrupts to be lost

- if an access starts a transmit or receive action, this may cause
  stray transmissions and/or data to be lost (particularly if there's a
  delay between accesses, e.g., cause by some interrupt)

- if the item being read can be updated aynchronously, e.g., a counter,
  part of the value may wrap around while the rest doesn't

And so on. Every single case is an extremely hard to find and
potentially lethal race condition. This construct is phantasically
evil !

I looked around a bit: qi is clean. At least the old Mokopatches
were clean as well, except for a few uses of "packed" in the AR6K
driver, but these are probably okay since they're not used to access
registers. u-boot has lots of them, particularly in include/s3c24x0.h

They're all commented out - except in the case of SPI.

Dennis, if you remove that "__attribute__((__packed__))" from
S3C24X0_SPI_CHANNEL in include/s3c24x0.h, does your original code work
then ?

- Werner

More information about the openmoko-kernel mailing list