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.c120
1 files changed, 93 insertions, 27 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 8cb0b360bfd8..4214bfb13bbd 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -612,7 +612,7 @@ u64 ata_tf_read_block(struct ata_taskfile *tf, struct ata_device *dev)
612 if (tf->flags & ATA_TFLAG_LBA48) { 612 if (tf->flags & ATA_TFLAG_LBA48) {
613 block |= (u64)tf->hob_lbah << 40; 613 block |= (u64)tf->hob_lbah << 40;
614 block |= (u64)tf->hob_lbam << 32; 614 block |= (u64)tf->hob_lbam << 32;
615 block |= tf->hob_lbal << 24; 615 block |= (u64)tf->hob_lbal << 24;
616 } else 616 } else
617 block |= (tf->device & 0xf) << 24; 617 block |= (tf->device & 0xf) << 24;
618 618
@@ -1268,7 +1268,7 @@ u64 ata_tf_to_lba48(const struct ata_taskfile *tf)
1268 1268
1269 sectors |= ((u64)(tf->hob_lbah & 0xff)) << 40; 1269 sectors |= ((u64)(tf->hob_lbah & 0xff)) << 40;
1270 sectors |= ((u64)(tf->hob_lbam & 0xff)) << 32; 1270 sectors |= ((u64)(tf->hob_lbam & 0xff)) << 32;
1271 sectors |= (tf->hob_lbal & 0xff) << 24; 1271 sectors |= ((u64)(tf->hob_lbal & 0xff)) << 24;
1272 sectors |= (tf->lbah & 0xff) << 16; 1272 sectors |= (tf->lbah & 0xff) << 16;
1273 sectors |= (tf->lbam & 0xff) << 8; 1273 sectors |= (tf->lbam & 0xff) << 8;
1274 sectors |= (tf->lbal & 0xff); 1274 sectors |= (tf->lbal & 0xff);
@@ -1602,7 +1602,6 @@ unsigned long ata_id_xfermask(const u16 *id)
1602/** 1602/**
1603 * ata_pio_queue_task - Queue port_task 1603 * ata_pio_queue_task - Queue port_task
1604 * @ap: The ata_port to queue port_task for 1604 * @ap: The ata_port to queue port_task for
1605 * @fn: workqueue function to be scheduled
1606 * @data: data for @fn to use 1605 * @data: data for @fn to use
1607 * @delay: delay time in msecs for workqueue function 1606 * @delay: delay time in msecs for workqueue function
1608 * 1607 *
@@ -1713,6 +1712,8 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
1713 else 1712 else
1714 tag = 0; 1713 tag = 0;
1715 1714
1715 if (test_and_set_bit(tag, &ap->qc_allocated))
1716 BUG();
1716 qc = __ata_qc_from_tag(ap, tag); 1717 qc = __ata_qc_from_tag(ap, tag);
1717 1718
1718 qc->tag = tag; 1719 qc->tag = tag;
@@ -2159,6 +2160,10 @@ retry:
2159static inline u8 ata_dev_knobble(struct ata_device *dev) 2160static inline u8 ata_dev_knobble(struct ata_device *dev)
2160{ 2161{
2161 struct ata_port *ap = dev->link->ap; 2162 struct ata_port *ap = dev->link->ap;
2163
2164 if (ata_dev_blacklisted(dev) & ATA_HORKAGE_BRIDGE_OK)
2165 return 0;
2166
2162 return ((ap->cbl == ATA_CBL_SATA) && (!ata_id_is_sata(dev->id))); 2167 return ((ap->cbl == ATA_CBL_SATA) && (!ata_id_is_sata(dev->id)));
2163} 2168}
2164 2169
@@ -4021,6 +4026,7 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
4021 4026
4022 /* Weird ATAPI devices */ 4027 /* Weird ATAPI devices */
4023 { "TORiSAN DVD-ROM DRD-N216", NULL, ATA_HORKAGE_MAX_SEC_128 }, 4028 { "TORiSAN DVD-ROM DRD-N216", NULL, ATA_HORKAGE_MAX_SEC_128 },
4029 { "QUANTUM DAT DAT72-000", NULL, ATA_HORKAGE_ATAPI_MOD16_DMA },
4024 4030
4025 /* Devices we expect to fail diagnostics */ 4031 /* Devices we expect to fail diagnostics */
4026 4032
@@ -4063,6 +4069,9 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
4063 { "TSSTcorp CDDVDW SH-S202N", "SB00", ATA_HORKAGE_IVB, }, 4069 { "TSSTcorp CDDVDW SH-S202N", "SB00", ATA_HORKAGE_IVB, },
4064 { "TSSTcorp CDDVDW SH-S202N", "SB01", ATA_HORKAGE_IVB, }, 4070 { "TSSTcorp CDDVDW SH-S202N", "SB01", ATA_HORKAGE_IVB, },
4065 4071
4072 /* Devices that do not need bridging limits applied */
4073 { "MTRON MSP-SATA*", NULL, ATA_HORKAGE_BRIDGE_OK, },
4074
4066 /* End Marker */ 4075 /* End Marker */
4067 { } 4076 { }
4068}; 4077};
@@ -4156,29 +4165,33 @@ static int cable_is_40wire(struct ata_port *ap)
4156 struct ata_link *link; 4165 struct ata_link *link;
4157 struct ata_device *dev; 4166 struct ata_device *dev;
4158 4167
4159 /* If the controller thinks we are 40 wire, we are */ 4168 /* If the controller thinks we are 40 wire, we are. */
4160 if (ap->cbl == ATA_CBL_PATA40) 4169 if (ap->cbl == ATA_CBL_PATA40)
4161 return 1; 4170 return 1;
4162 /* If the controller thinks we are 80 wire, we are */ 4171
4172 /* If the controller thinks we are 80 wire, we are. */
4163 if (ap->cbl == ATA_CBL_PATA80 || ap->cbl == ATA_CBL_SATA) 4173 if (ap->cbl == ATA_CBL_PATA80 || ap->cbl == ATA_CBL_SATA)
4164 return 0; 4174 return 0;
4165 /* If the system is known to be 40 wire short cable (eg laptop), 4175
4166 then we allow 80 wire modes even if the drive isn't sure */ 4176 /* If the system is known to be 40 wire short cable (eg
4177 * laptop), then we allow 80 wire modes even if the drive
4178 * isn't sure.
4179 */
4167 if (ap->cbl == ATA_CBL_PATA40_SHORT) 4180 if (ap->cbl == ATA_CBL_PATA40_SHORT)
4168 return 0; 4181 return 0;
4169 /* If the controller doesn't know we scan 4182
4170 4183 /* If the controller doesn't know, we scan.
4171 - Note: We look for all 40 wire detects at this point. 4184 *
4172 Any 80 wire detect is taken to be 80 wire cable 4185 * Note: We look for all 40 wire detects at this point. Any
4173 because 4186 * 80 wire detect is taken to be 80 wire cable because
4174 - In many setups only the one drive (slave if present) 4187 * - in many setups only the one drive (slave if present) will
4175 will give a valid detect 4188 * give a valid detect
4176 - If you have a non detect capable drive you don't 4189 * - if you have a non detect capable drive you don't want it
4177 want it to colour the choice 4190 * to colour the choice
4178 */ 4191 */
4179 ata_port_for_each_link(link, ap) { 4192 ata_port_for_each_link(link, ap) {
4180 ata_link_for_each_dev(dev, link) { 4193 ata_link_for_each_dev(dev, link) {
4181 if (!ata_is_40wire(dev)) 4194 if (ata_dev_enabled(dev) && !ata_is_40wire(dev))
4182 return 0; 4195 return 0;
4183 } 4196 }
4184 } 4197 }
@@ -4434,7 +4447,8 @@ int atapi_check_dma(struct ata_queued_cmd *qc)
4434 /* Don't allow DMA if it isn't multiple of 16 bytes. Quite a 4447 /* Don't allow DMA if it isn't multiple of 16 bytes. Quite a
4435 * few ATAPI devices choke on such DMA requests. 4448 * few ATAPI devices choke on such DMA requests.
4436 */ 4449 */
4437 if (unlikely(qc->nbytes & 15)) 4450 if (!(qc->dev->horkage & ATA_HORKAGE_ATAPI_MOD16_DMA) &&
4451 unlikely(qc->nbytes & 15))
4438 return 1; 4452 return 1;
4439 4453
4440 if (ap->ops->check_atapi_dma) 4454 if (ap->ops->check_atapi_dma)
@@ -4551,27 +4565,55 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words)
4551} 4565}
4552 4566
4553/** 4567/**
4554 * ata_qc_new_init - Request an available ATA command, and initialize it 4568 * ata_qc_new - Request an available ATA command, for queueing
4569 * @ap: Port associated with device @dev
4555 * @dev: Device from whom we request an available command structure 4570 * @dev: Device from whom we request an available command structure
4556 * 4571 *
4557 * LOCKING: 4572 * LOCKING:
4558 * None. 4573 * None.
4559 */ 4574 */
4560 4575
4561struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag) 4576static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap)
4562{ 4577{
4563 struct ata_port *ap = dev->link->ap; 4578 struct ata_queued_cmd *qc = NULL;
4564 struct ata_queued_cmd *qc; 4579 unsigned int i;
4565 4580
4581 /* no command while frozen */
4566 if (unlikely(ap->pflags & ATA_PFLAG_FROZEN)) 4582 if (unlikely(ap->pflags & ATA_PFLAG_FROZEN))
4567 return NULL; 4583 return NULL;
4568 4584
4569 qc = __ata_qc_from_tag(ap, tag); 4585 /* the last tag is reserved for internal command. */
4586 for (i = 0; i < ATA_MAX_QUEUE - 1; i++)
4587 if (!test_and_set_bit(i, &ap->qc_allocated)) {
4588 qc = __ata_qc_from_tag(ap, i);
4589 break;
4590 }
4591
4592 if (qc)
4593 qc->tag = i;
4594
4595 return qc;
4596}
4597
4598/**
4599 * ata_qc_new_init - Request an available ATA command, and initialize it
4600 * @dev: Device from whom we request an available command structure
4601 * @tag: command tag
4602 *
4603 * LOCKING:
4604 * None.
4605 */
4606
4607struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev)
4608{
4609 struct ata_port *ap = dev->link->ap;
4610 struct ata_queued_cmd *qc;
4611
4612 qc = ata_qc_new(ap);
4570 if (qc) { 4613 if (qc) {
4571 qc->scsicmd = NULL; 4614 qc->scsicmd = NULL;
4572 qc->ap = ap; 4615 qc->ap = ap;
4573 qc->dev = dev; 4616 qc->dev = dev;
4574 qc->tag = tag;
4575 4617
4576 ata_qc_reinit(qc); 4618 ata_qc_reinit(qc);
4577 } 4619 }
@@ -4579,6 +4621,31 @@ struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag)
4579 return qc; 4621 return qc;
4580} 4622}
4581 4623
4624/**
4625 * ata_qc_free - free unused ata_queued_cmd
4626 * @qc: Command to complete
4627 *
4628 * Designed to free unused ata_queued_cmd object
4629 * in case something prevents using it.
4630 *
4631 * LOCKING:
4632 * spin_lock_irqsave(host lock)
4633 */
4634void ata_qc_free(struct ata_queued_cmd *qc)
4635{
4636 struct ata_port *ap = qc->ap;
4637 unsigned int tag;
4638
4639 WARN_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
4640
4641 qc->flags = 0;
4642 tag = qc->tag;
4643 if (likely(ata_tag_valid(tag))) {
4644 qc->tag = ATA_TAG_POISON;
4645 clear_bit(tag, &ap->qc_allocated);
4646 }
4647}
4648
4582void __ata_qc_complete(struct ata_queued_cmd *qc) 4649void __ata_qc_complete(struct ata_queued_cmd *qc)
4583{ 4650{
4584 struct ata_port *ap = qc->ap; 4651 struct ata_port *ap = qc->ap;
@@ -4643,7 +4710,6 @@ static void ata_verify_xfer(struct ata_queued_cmd *qc)
4643/** 4710/**
4644 * ata_qc_complete - Complete an active ATA command 4711 * ata_qc_complete - Complete an active ATA command
4645 * @qc: Command to complete 4712 * @qc: Command to complete
4646 * @err_mask: ATA Status register contents
4647 * 4713 *
4648 * Indicate to the mid and upper layers that an ATA 4714 * Indicate to the mid and upper layers that an ATA
4649 * command has completed, with either an ok or not-ok status. 4715 * command has completed, with either an ok or not-ok status.
@@ -5924,7 +5990,7 @@ static void ata_port_detach(struct ata_port *ap)
5924 * to us. Restore SControl and disable all existing devices. 5990 * to us. Restore SControl and disable all existing devices.
5925 */ 5991 */
5926 __ata_port_for_each_link(link, ap) { 5992 __ata_port_for_each_link(link, ap) {
5927 sata_scr_write(link, SCR_CONTROL, link->saved_scontrol); 5993 sata_scr_write(link, SCR_CONTROL, link->saved_scontrol & 0xff0);
5928 ata_link_for_each_dev(dev, link) 5994 ata_link_for_each_dev(dev, link)
5929 ata_dev_disable(dev); 5995 ata_dev_disable(dev);
5930 } 5996 }