diff options
author | Tejun Heo <htejun@gmail.com> | 2007-12-11 22:21:52 -0500 |
---|---|---|
committer | Jeff Garzik <jeff@garzik.org> | 2007-12-17 20:43:28 -0500 |
commit | 140b5e59119a172a91b5fa13d54ca4f79bbefee1 (patch) | |
tree | ebc04fbd143756d7ef80e870cd9ae214d2607047 /drivers/ata | |
parent | f2dfc1a12bb1a029df62b018a8e1882e91041025 (diff) |
libata: fix ATAPI draining
With ATAPI transfer chunk size properly programmed, libata PIO HSM
should be able to handle full spurious data chunks. Also, it's a good
idea to suppress trailing data warning for misc ATAPI commands as
there can be many of them per command - for example, if the chunk size
is 16 and the drive tries to transfer 510 bytes, there can be 31
trailing data messages.
This patch makes the following updates to libata ATAPI PIO HSM
implementation.
* Make it drain full spurious chunks.
* Suppress trailing data warning message for misc commands.
* Put limit on how many bytes can be drained.
* If odd, round up consumed bytes and the number of bytes to be
drained. This gets the number of bytes to drain right for drivers
which do 16bit PIO.
This patch is partial backport of improve-ATAPI-data-xfer patchset
pending for #upstream.
Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'drivers/ata')
-rw-r--r-- | drivers/ata/libata-core.c | 87 |
1 files changed, 65 insertions, 22 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 4af939a00e54..4753a1831dbc 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c | |||
@@ -64,6 +64,7 @@ | |||
64 | #include <linux/libata.h> | 64 | #include <linux/libata.h> |
65 | #include <asm/semaphore.h> | 65 | #include <asm/semaphore.h> |
66 | #include <asm/byteorder.h> | 66 | #include <asm/byteorder.h> |
67 | #include <linux/cdrom.h> | ||
67 | 68 | ||
68 | #include "libata.h" | 69 | #include "libata.h" |
69 | 70 | ||
@@ -4652,6 +4653,43 @@ int ata_check_atapi_dma(struct ata_queued_cmd *qc) | |||
4652 | } | 4653 | } |
4653 | 4654 | ||
4654 | /** | 4655 | /** |
4656 | * atapi_qc_may_overflow - Check whether data transfer may overflow | ||
4657 | * @qc: ATA command in question | ||
4658 | * | ||
4659 | * ATAPI commands which transfer variable length data to host | ||
4660 | * might overflow due to application error or hardare bug. This | ||
4661 | * function checks whether overflow should be drained and ignored | ||
4662 | * for @qc. | ||
4663 | * | ||
4664 | * LOCKING: | ||
4665 | * None. | ||
4666 | * | ||
4667 | * RETURNS: | ||
4668 | * 1 if @qc may overflow; otherwise, 0. | ||
4669 | */ | ||
4670 | static int atapi_qc_may_overflow(struct ata_queued_cmd *qc) | ||
4671 | { | ||
4672 | if (qc->tf.protocol != ATA_PROT_ATAPI && | ||
4673 | qc->tf.protocol != ATA_PROT_ATAPI_DMA) | ||
4674 | return 0; | ||
4675 | |||
4676 | if (qc->tf.flags & ATA_TFLAG_WRITE) | ||
4677 | return 0; | ||
4678 | |||
4679 | switch (qc->cdb[0]) { | ||
4680 | case READ_10: | ||
4681 | case READ_12: | ||
4682 | case WRITE_10: | ||
4683 | case WRITE_12: | ||
4684 | case GPCMD_READ_CD: | ||
4685 | case GPCMD_READ_CD_MSF: | ||
4686 | return 0; | ||
4687 | } | ||
4688 | |||
4689 | return 1; | ||
4690 | } | ||
4691 | |||
4692 | /** | ||
4655 | * ata_std_qc_defer - Check whether a qc needs to be deferred | 4693 | * ata_std_qc_defer - Check whether a qc needs to be deferred |
4656 | * @qc: ATA command in question | 4694 | * @qc: ATA command in question |
4657 | * | 4695 | * |
@@ -5139,23 +5177,19 @@ static void atapi_send_cdb(struct ata_port *ap, struct ata_queued_cmd *qc) | |||
5139 | * Inherited from caller. | 5177 | * Inherited from caller. |
5140 | * | 5178 | * |
5141 | */ | 5179 | */ |
5142 | 5180 | static int __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes) | |
5143 | static void __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes) | ||
5144 | { | 5181 | { |
5145 | int do_write = (qc->tf.flags & ATA_TFLAG_WRITE); | 5182 | int do_write = (qc->tf.flags & ATA_TFLAG_WRITE); |
5146 | struct scatterlist *sg = qc->__sg; | ||
5147 | struct scatterlist *lsg = sg_last(qc->__sg, qc->n_elem); | ||
5148 | struct ata_port *ap = qc->ap; | 5183 | struct ata_port *ap = qc->ap; |
5184 | struct ata_eh_info *ehi = &qc->dev->link->eh_info; | ||
5185 | struct scatterlist *sg; | ||
5149 | struct page *page; | 5186 | struct page *page; |
5150 | unsigned char *buf; | 5187 | unsigned char *buf; |
5151 | unsigned int offset, count; | 5188 | unsigned int offset, count; |
5152 | int no_more_sg = 0; | ||
5153 | |||
5154 | if (qc->curbytes + bytes >= qc->nbytes) | ||
5155 | ap->hsm_task_state = HSM_ST_LAST; | ||
5156 | 5189 | ||
5157 | next_sg: | 5190 | next_sg: |
5158 | if (unlikely(no_more_sg)) { | 5191 | sg = qc->cursg; |
5192 | if (unlikely(!sg)) { | ||
5159 | /* | 5193 | /* |
5160 | * The end of qc->sg is reached and the device expects | 5194 | * The end of qc->sg is reached and the device expects |
5161 | * more data to transfer. In order not to overrun qc->sg | 5195 | * more data to transfer. In order not to overrun qc->sg |
@@ -5164,21 +5198,28 @@ next_sg: | |||
5164 | * - for write case, padding zero data to the device | 5198 | * - for write case, padding zero data to the device |
5165 | */ | 5199 | */ |
5166 | u16 pad_buf[1] = { 0 }; | 5200 | u16 pad_buf[1] = { 0 }; |
5167 | unsigned int words = bytes >> 1; | ||
5168 | unsigned int i; | 5201 | unsigned int i; |
5169 | 5202 | ||
5170 | if (words) /* warning if bytes > 1 */ | 5203 | if (bytes > qc->curbytes - qc->nbytes + ATAPI_MAX_DRAIN) { |
5171 | ata_dev_printk(qc->dev, KERN_WARNING, | 5204 | ata_ehi_push_desc(ehi, "too much trailing data " |
5172 | "%u bytes trailing data\n", bytes); | 5205 | "buf=%u cur=%u bytes=%u", |
5206 | qc->nbytes, qc->curbytes, bytes); | ||
5207 | return -1; | ||
5208 | } | ||
5209 | |||
5210 | /* overflow is exptected for misc ATAPI commands */ | ||
5211 | if (bytes && !atapi_qc_may_overflow(qc)) | ||
5212 | ata_dev_printk(qc->dev, KERN_WARNING, "ATAPI %u bytes " | ||
5213 | "trailing data (cdb=%02x nbytes=%u)\n", | ||
5214 | bytes, qc->cdb[0], qc->nbytes); | ||
5173 | 5215 | ||
5174 | for (i = 0; i < words; i++) | 5216 | for (i = 0; i < (bytes + 1) / 2; i++) |
5175 | ap->ops->data_xfer(qc->dev, (unsigned char *)pad_buf, 2, do_write); | 5217 | ap->ops->data_xfer(qc->dev, (unsigned char *)pad_buf, 2, do_write); |
5176 | 5218 | ||
5177 | ap->hsm_task_state = HSM_ST_LAST; | 5219 | qc->curbytes += bytes; |
5178 | return; | ||
5179 | } | ||
5180 | 5220 | ||
5181 | sg = qc->cursg; | 5221 | return 0; |
5222 | } | ||
5182 | 5223 | ||
5183 | page = sg_page(sg); | 5224 | page = sg_page(sg); |
5184 | offset = sg->offset + qc->cursg_ofs; | 5225 | offset = sg->offset + qc->cursg_ofs; |
@@ -5213,19 +5254,20 @@ next_sg: | |||
5213 | } | 5254 | } |
5214 | 5255 | ||
5215 | bytes -= count; | 5256 | bytes -= count; |
5257 | if ((count & 1) && bytes) | ||
5258 | bytes--; | ||
5216 | qc->curbytes += count; | 5259 | qc->curbytes += count; |
5217 | qc->cursg_ofs += count; | 5260 | qc->cursg_ofs += count; |
5218 | 5261 | ||
5219 | if (qc->cursg_ofs == sg->length) { | 5262 | if (qc->cursg_ofs == sg->length) { |
5220 | if (qc->cursg == lsg) | ||
5221 | no_more_sg = 1; | ||
5222 | |||
5223 | qc->cursg = sg_next(qc->cursg); | 5263 | qc->cursg = sg_next(qc->cursg); |
5224 | qc->cursg_ofs = 0; | 5264 | qc->cursg_ofs = 0; |
5225 | } | 5265 | } |
5226 | 5266 | ||
5227 | if (bytes) | 5267 | if (bytes) |
5228 | goto next_sg; | 5268 | goto next_sg; |
5269 | |||
5270 | return 0; | ||
5229 | } | 5271 | } |
5230 | 5272 | ||
5231 | /** | 5273 | /** |
@@ -5268,7 +5310,8 @@ static void atapi_pio_bytes(struct ata_queued_cmd *qc) | |||
5268 | 5310 | ||
5269 | VPRINTK("ata%u: xfering %d bytes\n", ap->print_id, bytes); | 5311 | VPRINTK("ata%u: xfering %d bytes\n", ap->print_id, bytes); |
5270 | 5312 | ||
5271 | __atapi_pio_bytes(qc, bytes); | 5313 | if (__atapi_pio_bytes(qc, bytes)) |
5314 | goto err_out; | ||
5272 | ata_altstatus(ap); /* flush */ | 5315 | ata_altstatus(ap); /* flush */ |
5273 | 5316 | ||
5274 | return; | 5317 | return; |