diff options
author | James Bottomley <James.Bottomley@HansenPartnership.com> | 2008-02-19 05:36:57 -0500 |
---|---|---|
committer | Jens Axboe <jens.axboe@oracle.com> | 2008-02-19 05:36:57 -0500 |
commit | fa2fc7f4813bfec1ae3232d49e3befbd601e8a6f (patch) | |
tree | f5598bd35f38812318da493cc027238a2256e036 /drivers/ata/libata-core.c | |
parent | dde2020754aeb14e17052d61784dcb37f252aac2 (diff) |
libata: implement drain buffers
This just updates the libata slave configure routine to take advantage
of the block layer drain buffers. It also adjusts the size lengths in
the atapi code to add the drain buffer to the DMA length so the driver
knows it can rely on it.
I suspect I should also be checking for AHCI as well as ATA_DEV_ATAPI,
but I couldn't see how to do that easily.
tj: * atapi_drain_needed() added such that draining is applied to only
misc ATAPI commands.
* q->bounce_gfp used when allocating drain buffer.
* Now duplicate ATAPI PIO drain logic dropped.
* ata_dev_printk() used instead of sdev_printk().
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'drivers/ata/libata-core.c')
-rw-r--r-- | drivers/ata/libata-core.c | 56 |
1 files changed, 4 insertions, 52 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 3587ac3fe3f3..def3682f416a 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c | |||
@@ -4642,28 +4642,6 @@ int ata_check_atapi_dma(struct ata_queued_cmd *qc) | |||
4642 | } | 4642 | } |
4643 | 4643 | ||
4644 | /** | 4644 | /** |
4645 | * atapi_qc_may_overflow - Check whether data transfer may overflow | ||
4646 | * @qc: ATA command in question | ||
4647 | * | ||
4648 | * ATAPI commands which transfer variable length data to host | ||
4649 | * might overflow due to application error or hardare bug. This | ||
4650 | * function checks whether overflow should be drained and ignored | ||
4651 | * for @qc. | ||
4652 | * | ||
4653 | * LOCKING: | ||
4654 | * None. | ||
4655 | * | ||
4656 | * RETURNS: | ||
4657 | * 1 if @qc may overflow; otherwise, 0. | ||
4658 | */ | ||
4659 | static int atapi_qc_may_overflow(struct ata_queued_cmd *qc) | ||
4660 | { | ||
4661 | return ata_is_atapi(qc->tf.protocol) && ata_is_data(qc->tf.protocol) && | ||
4662 | atapi_cmd_type(qc->cdb[0]) == ATAPI_MISC && | ||
4663 | !(qc->tf.flags & ATA_TFLAG_WRITE); | ||
4664 | } | ||
4665 | |||
4666 | /** | ||
4667 | * ata_std_qc_defer - Check whether a qc needs to be deferred | 4645 | * ata_std_qc_defer - Check whether a qc needs to be deferred |
4668 | * @qc: ATA command in question | 4646 | * @qc: ATA command in question |
4669 | * | 4647 | * |
@@ -5026,36 +5004,10 @@ static int __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes) | |||
5026 | next_sg: | 5004 | next_sg: |
5027 | sg = qc->cursg; | 5005 | sg = qc->cursg; |
5028 | if (unlikely(!sg)) { | 5006 | if (unlikely(!sg)) { |
5029 | /* | 5007 | ata_ehi_push_desc(ehi, "unexpected or too much trailing data " |
5030 | * The end of qc->sg is reached and the device expects | 5008 | "buf=%u cur=%u bytes=%u", |
5031 | * more data to transfer. In order not to overrun qc->sg | 5009 | qc->nbytes, qc->curbytes, bytes); |
5032 | * and fulfill length specified in the byte count register, | 5010 | return -1; |
5033 | * - for read case, discard trailing data from the device | ||
5034 | * - for write case, padding zero data to the device | ||
5035 | */ | ||
5036 | u16 pad_buf[1] = { 0 }; | ||
5037 | |||
5038 | if (qc->curbytes + bytes > qc->nbytes + ATAPI_MAX_DRAIN) { | ||
5039 | ata_ehi_push_desc(ehi, "too much trailing data " | ||
5040 | "buf=%u cur=%u bytes=%u", | ||
5041 | qc->nbytes, qc->curbytes, bytes); | ||
5042 | return -1; | ||
5043 | } | ||
5044 | |||
5045 | /* allow overflow only for misc ATAPI commands */ | ||
5046 | if (!atapi_qc_may_overflow(qc)) { | ||
5047 | ata_ehi_push_desc(ehi, "unexpected trailing data " | ||
5048 | "%u bytes", bytes); | ||
5049 | return -1; | ||
5050 | } | ||
5051 | |||
5052 | consumed = 0; | ||
5053 | while (consumed < bytes) | ||
5054 | consumed += ap->ops->data_xfer(dev, | ||
5055 | (unsigned char *)pad_buf, 2, rw); | ||
5056 | |||
5057 | qc->curbytes += bytes; | ||
5058 | return 0; | ||
5059 | } | 5011 | } |
5060 | 5012 | ||
5061 | page = sg_page(sg); | 5013 | page = sg_page(sg); |