This works for most PATA ATAPI devices. Most devices detect reversed transfer and terminate the command promptly. But this doesn't seem to be true for SATA device. Many just hang and time out commands with the wrong transfer direction. If you consider that most early SATA ATAPI devices are actually PATA + bridge, this is sorta inevitable. The PATA-SATA bridge cannot issue D2H FIS to abort the command by itself. It's just mirroring the status of PATA side and PATA side doesn't know SATA protocol mismatch has occurred.
So, IDENTIFY w/ write-DMA protocol times out after quite some seconds. This is where things go worse from bad. SATA controllers which have shadow TF registers don't handle timeout conditions very well, especially when they're waiting for data transfer. They basically hold the PCI bus and hang till the transfer completes (which never happens). That's where the hard lock up comes from.
Jens, I think we need to match block sg's behavior to SCSI's. Monty, the timeout and hard lock up are due to hardware restrictions. Kernel and libata can't do much about it. So, please find other way to detect interface.