aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata/libata-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ata/libata-core.c')
-rw-r--r--drivers/ata/libata-core.c101
1 files changed, 73 insertions, 28 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index e4dea8623a..4753a1831d 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
@@ -622,6 +623,7 @@ void ata_dev_disable(struct ata_device *dev)
622 if (ata_dev_enabled(dev)) { 623 if (ata_dev_enabled(dev)) {
623 if (ata_msg_drv(dev->link->ap)) 624 if (ata_msg_drv(dev->link->ap))
624 ata_dev_printk(dev, KERN_WARNING, "disabled\n"); 625 ata_dev_printk(dev, KERN_WARNING, "disabled\n");
626 ata_acpi_on_disable(dev);
625 ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO0 | 627 ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO0 |
626 ATA_DNXFER_QUIET); 628 ATA_DNXFER_QUIET);
627 dev->class++; 629 dev->class++;
@@ -3923,6 +3925,7 @@ void ata_std_postreset(struct ata_link *link, unsigned int *classes)
3923 /* clear SError */ 3925 /* clear SError */
3924 if (sata_scr_read(link, SCR_ERROR, &serror) == 0) 3926 if (sata_scr_read(link, SCR_ERROR, &serror) == 0)
3925 sata_scr_write(link, SCR_ERROR, serror); 3927 sata_scr_write(link, SCR_ERROR, serror);
3928 link->eh_info.serror = 0;
3926 3929
3927 /* is double-select really necessary? */ 3930 /* is double-select really necessary? */
3928 if (classes[0] != ATA_DEV_NONE) 3931 if (classes[0] != ATA_DEV_NONE)
@@ -4149,6 +4152,7 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
4149 { "HITACHI HDS7250SASUN500G*", NULL, ATA_HORKAGE_NONCQ }, 4152 { "HITACHI HDS7250SASUN500G*", NULL, ATA_HORKAGE_NONCQ },
4150 { "HITACHI HDS7225SBSUN250G*", NULL, ATA_HORKAGE_NONCQ }, 4153 { "HITACHI HDS7225SBSUN250G*", NULL, ATA_HORKAGE_NONCQ },
4151 { "ST380817AS", "3.42", ATA_HORKAGE_NONCQ }, 4154 { "ST380817AS", "3.42", ATA_HORKAGE_NONCQ },
4155 { "ST3160023AS", "3.42", ATA_HORKAGE_NONCQ },
4152 4156
4153 /* Blacklist entries taken from Silicon Image 3124/3132 4157 /* Blacklist entries taken from Silicon Image 3124/3132
4154 Windows driver .inf file - also several Linux problem reports */ 4158 Windows driver .inf file - also several Linux problem reports */
@@ -4649,6 +4653,43 @@ int ata_check_atapi_dma(struct ata_queued_cmd *qc)
4649} 4653}
4650 4654
4651/** 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 */
4670static 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/**
4652 * 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
4653 * @qc: ATA command in question 4694 * @qc: ATA command in question
4654 * 4695 *
@@ -5136,23 +5177,19 @@ static void atapi_send_cdb(struct ata_port *ap, struct ata_queued_cmd *qc)
5136 * Inherited from caller. 5177 * Inherited from caller.
5137 * 5178 *
5138 */ 5179 */
5139 5180static int __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes)
5140static void __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes)
5141{ 5181{
5142 int do_write = (qc->tf.flags & ATA_TFLAG_WRITE); 5182 int do_write = (qc->tf.flags & ATA_TFLAG_WRITE);
5143 struct scatterlist *sg = qc->__sg;
5144 struct scatterlist *lsg = sg_last(qc->__sg, qc->n_elem);
5145 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;
5146 struct page *page; 5186 struct page *page;
5147 unsigned char *buf; 5187 unsigned char *buf;
5148 unsigned int offset, count; 5188 unsigned int offset, count;
5149 int no_more_sg = 0;
5150
5151 if (qc->curbytes + bytes >= qc->nbytes)
5152 ap->hsm_task_state = HSM_ST_LAST;
5153 5189
5154next_sg: 5190next_sg:
5155 if (unlikely(no_more_sg)) { 5191 sg = qc->cursg;
5192 if (unlikely(!sg)) {
5156 /* 5193 /*
5157 * The end of qc->sg is reached and the device expects 5194 * The end of qc->sg is reached and the device expects
5158 * more data to transfer. In order not to overrun qc->sg 5195 * more data to transfer. In order not to overrun qc->sg
@@ -5161,21 +5198,28 @@ next_sg:
5161 * - for write case, padding zero data to the device 5198 * - for write case, padding zero data to the device
5162 */ 5199 */
5163 u16 pad_buf[1] = { 0 }; 5200 u16 pad_buf[1] = { 0 };
5164 unsigned int words = bytes >> 1;
5165 unsigned int i; 5201 unsigned int i;
5166 5202
5167 if (words) /* warning if bytes > 1 */ 5203 if (bytes > qc->curbytes - qc->nbytes + ATAPI_MAX_DRAIN) {
5168 ata_dev_printk(qc->dev, KERN_WARNING, 5204 ata_ehi_push_desc(ehi, "too much trailing data "
5169 "%u bytes trailing data\n", bytes); 5205 "buf=%u cur=%u bytes=%u",
5206 qc->nbytes, qc->curbytes, bytes);
5207 return -1;
5208 }
5170 5209
5171 for (i = 0; i < words; i++) 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);
5215
5216 for (i = 0; i < (bytes + 1) / 2; i++)
5172 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);
5173 5218
5174 ap->hsm_task_state = HSM_ST_LAST; 5219 qc->curbytes += bytes;
5175 return;
5176 }
5177 5220
5178 sg = qc->cursg; 5221 return 0;
5222 }
5179 5223
5180 page = sg_page(sg); 5224 page = sg_page(sg);
5181 offset = sg->offset + qc->cursg_ofs; 5225 offset = sg->offset + qc->cursg_ofs;
@@ -5210,19 +5254,20 @@ next_sg:
5210 } 5254 }
5211 5255
5212 bytes -= count; 5256 bytes -= count;
5257 if ((count & 1) && bytes)
5258 bytes--;
5213 qc->curbytes += count; 5259 qc->curbytes += count;
5214 qc->cursg_ofs += count; 5260 qc->cursg_ofs += count;
5215 5261
5216 if (qc->cursg_ofs == sg->length) { 5262 if (qc->cursg_ofs == sg->length) {
5217 if (qc->cursg == lsg)
5218 no_more_sg = 1;
5219
5220 qc->cursg = sg_next(qc->cursg); 5263 qc->cursg = sg_next(qc->cursg);
5221 qc->cursg_ofs = 0; 5264 qc->cursg_ofs = 0;
5222 } 5265 }
5223 5266
5224 if (bytes) 5267 if (bytes)
5225 goto next_sg; 5268 goto next_sg;
5269
5270 return 0;
5226} 5271}
5227 5272
5228/** 5273/**
@@ -5265,7 +5310,8 @@ static void atapi_pio_bytes(struct ata_queued_cmd *qc)
5265 5310
5266 VPRINTK("ata%u: xfering %d bytes\n", ap->print_id, bytes); 5311 VPRINTK("ata%u: xfering %d bytes\n", ap->print_id, bytes);
5267 5312
5268 __atapi_pio_bytes(qc, bytes); 5313 if (__atapi_pio_bytes(qc, bytes))
5314 goto err_out;
5269 ata_altstatus(ap); /* flush */ 5315 ata_altstatus(ap); /* flush */
5270 5316
5271 return; 5317 return;
@@ -7208,18 +7254,14 @@ static void ata_port_detach(struct ata_port *ap)
7208 7254
7209 ata_port_wait_eh(ap); 7255 ata_port_wait_eh(ap);
7210 7256
7211 /* EH is now guaranteed to see UNLOADING, so no new device 7257 /* EH is now guaranteed to see UNLOADING - EH context belongs
7212 * will be attached. Disable all existing devices. 7258 * to us. Disable all existing devices.
7213 */ 7259 */
7214 spin_lock_irqsave(ap->lock, flags);
7215
7216 ata_port_for_each_link(link, ap) { 7260 ata_port_for_each_link(link, ap) {
7217 ata_link_for_each_dev(dev, link) 7261 ata_link_for_each_dev(dev, link)
7218 ata_dev_disable(dev); 7262 ata_dev_disable(dev);
7219 } 7263 }
7220 7264
7221 spin_unlock_irqrestore(ap->lock, flags);
7222
7223 /* Final freeze & EH. All in-flight commands are aborted. EH 7265 /* Final freeze & EH. All in-flight commands are aborted. EH
7224 * will be skipped and retrials will be terminated with bad 7266 * will be skipped and retrials will be terminated with bad
7225 * target. 7267 * target.
@@ -7251,6 +7293,9 @@ void ata_host_detach(struct ata_host *host)
7251 7293
7252 for (i = 0; i < host->n_ports; i++) 7294 for (i = 0; i < host->n_ports; i++)
7253 ata_port_detach(host->ports[i]); 7295 ata_port_detach(host->ports[i]);
7296
7297 /* the host is dead now, dissociate ACPI */
7298 ata_acpi_dissociate(host);
7254} 7299}
7255 7300
7256/** 7301/**