diff options
author | Tejun Heo <htejun@gmail.com> | 2007-11-26 06:58:02 -0500 |
---|---|---|
committer | Jeff Garzik <jeff@garzik.org> | 2007-11-26 11:03:40 -0500 |
commit | e190222d04cb1119c62876ac87cf9b9403ba3bd5 (patch) | |
tree | e7aabe0c306f4f5b169c06d0829258717953cc5a /drivers/ata/libata-scsi.c | |
parent | dc86f6d4183c79a08fa01c08dd2191895c0c7eb0 (diff) |
libata: bump transfer chunk size if it's odd
None of the drives I have follows what the standard says about
transfer chunk size. Of the four SATA and six PATA ATAPI devices
tested, four ignore transfer chunk size completely and the ones which
honor it don't behave according to the spec when it's odd.
According to the spec, transfer chunk size can be odd if the amount of
data to transfer equals or is smaller than the chunk size and the
device can indicate the same odd number and transfer the whole thing
at one go with a pad byte appended. However, in reality, none of the
drives I have does that. They all indicate and transfer even number
of bytes one byte shorter than the chunk size first; then indicate and
transfer two bytes, which is clearly out of spec.
In addition to unnecessary second PIO data phase, this also creates a
weird problem when combined with SATA controllers which perform PIO
via DMA. Some of these controllers use actualy number of bytes
received to update DMA pointer so chunks which are sized 4n + 2 makes
DMA pointer off by two bytes. This causes data corruption and buffer
overruns.
This patch rounds nbytes up to the nearest even number such that ATAPI
devices don't split data transfer for the last odd byte. This
shouldn't confuse controllers which depend on transfer chunk size as
devices will report the rounded-up number, actually transfer that much
and padding buffer is there to receive them.
Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'drivers/ata/libata-scsi.c')
-rw-r--r-- | drivers/ata/libata-scsi.c | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index a45f6ac3b245..a883bb03d4c7 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c | |||
@@ -2485,11 +2485,40 @@ static unsigned int atapi_xlat(struct ata_queued_cmd *qc) | |||
2485 | if (!using_pio && ata_check_atapi_dma(qc)) | 2485 | if (!using_pio && ata_check_atapi_dma(qc)) |
2486 | using_pio = 1; | 2486 | using_pio = 1; |
2487 | 2487 | ||
2488 | /* Some controller variants snoop this value for Packet transfers | 2488 | /* Some controller variants snoop this value for Packet |
2489 | to do state machine and FIFO management. Thus we want to set it | 2489 | * transfers to do state machine and FIFO management. Thus we |
2490 | properly, and for DMA where it is effectively meaningless */ | 2490 | * want to set it properly, and for DMA where it is |
2491 | * effectively meaningless. | ||
2492 | */ | ||
2491 | nbytes = min(qc->nbytes, (unsigned int)63 * 1024); | 2493 | nbytes = min(qc->nbytes, (unsigned int)63 * 1024); |
2492 | 2494 | ||
2495 | /* Most ATAPI devices which honor transfer chunk size don't | ||
2496 | * behave according to the spec when odd chunk size which | ||
2497 | * matches the transfer length is specified. If the number of | ||
2498 | * bytes to transfer is 2n+1. According to the spec, what | ||
2499 | * should happen is to indicate that 2n+1 is going to be | ||
2500 | * transferred and transfer 2n+2 bytes where the last byte is | ||
2501 | * padding. | ||
2502 | * | ||
2503 | * In practice, this doesn't happen. ATAPI devices first | ||
2504 | * indicate and transfer 2n bytes and then indicate and | ||
2505 | * transfer 2 bytes where the last byte is padding. | ||
2506 | * | ||
2507 | * This inconsistency confuses several controllers which | ||
2508 | * perform PIO using DMA such as Intel AHCIs and sil3124/32. | ||
2509 | * These controllers use actual number of transferred bytes to | ||
2510 | * update DMA poitner and transfer of 4n+2 bytes make those | ||
2511 | * controller push DMA pointer by 4n+4 bytes because SATA data | ||
2512 | * FISes are aligned to 4 bytes. This causes data corruption | ||
2513 | * and buffer overrun. | ||
2514 | * | ||
2515 | * Always setting nbytes to even number solves this problem | ||
2516 | * because then ATAPI devices don't have to split data at 2n | ||
2517 | * boundaries. | ||
2518 | */ | ||
2519 | if (nbytes & 0x1) | ||
2520 | nbytes++; | ||
2521 | |||
2493 | qc->tf.lbam = (nbytes & 0xFF); | 2522 | qc->tf.lbam = (nbytes & 0xFF); |
2494 | qc->tf.lbah = (nbytes >> 8); | 2523 | qc->tf.lbah = (nbytes >> 8); |
2495 | 2524 | ||