I assume by 'discard' here you're referring to SCSI UNMAP, as anything
that supports ATA_12 or ATA_16 pass through correctly will support ATA
TRIM/DISCARD on drives that support it. If that's the case, then:
1. If SCSI UNMAP fails, it doesn't support UNMAP. This is of course
non-trivial to verify safely (we pretty much have to assume it is
supported if we have no clear indication it isn't, and then switch based
on what happens the first time we try to use it).
2. Unless there are SATL's out there that write garbage to the device or
die when sent an ATA_12 or ATA_16 pass through command encapsulating an
ATA DEVICE IDENTIFY command, this isn't an issue. Even if such SATL's
exist, they can easily be blacklisted.
3. This isn't hard, a SATL which actually supports ATA pass through will
almost always pass through the mode page unmodified.
On the note of UAS SATL's, all of them that I've seen fall into one of
four categories:
1. Supports one or both of ATA_12 or ATA_16 pass through, and supports
passing through ATA TRIM/DISCARD, but not SCSI UNMAP.
2. Supports one of ATA_12 or ATA_16 pass through, and does not support
passing through ATA TRIM/DISCARD or translating SCSI UNMAP. All devices
I've seen that fit this will modify the ATA DEVICE IDENTIFY data so it
doesn't report DISCARD support, or will simply return an error for
DISCARD requests. I haven't seen any like this that were manufactured
after UAS became standardized.
3. Supports neither ATA_12 or ATA_16 pass through, and doesn't support
UNMAP.
4. Like type 1, except it supports both pass through commands, and also
properly translates SCSI UNMAP commands (I've only ever seen one of
these, have no idea what chipset it had, and it was insanely expensive
(upside of 300 USD)).
All we really can do anything about is category 1. Category 4 works
with the current drivers, and we can't properly support it on category 2
or 3. All three devices I have right now are in category 1, I know a
number of other people in a similar situation, and it sounds like Jason
has at least one such device as well. Given that Windows does this
(I've confirmed this with a hardware USB analyzer I borrowed from a
friend), and that I've not seen anything since the UAS spec was actually
released that falls into category 2 (and if I understand the spec
correctly, such a device is actually not compliant with it anyway), I
think it's probably safe to do this in Linux and just base the check on:
1. UAS (not some other SCSI transport) without UNMAP support.
2. Supports ATA_12 or ATA_16 pass through.
3. ATA DEVICE IDENTIFY via SAT indicates that the device supports
DISCARD/TRIM.
Then we'd be matching behavior on Windows, and should probably be
relatively safe.