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.c68
1 files changed, 61 insertions, 7 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 622350d9b2e3..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
@@ -1712,6 +1712,8 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
1712 else 1712 else
1713 tag = 0; 1713 tag = 0;
1714 1714
1715 if (test_and_set_bit(tag, &ap->qc_allocated))
1716 BUG();
1715 qc = __ata_qc_from_tag(ap, tag); 1717 qc = __ata_qc_from_tag(ap, tag);
1716 1718
1717 qc->tag = tag; 1719 qc->tag = tag;
@@ -4563,6 +4565,37 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words)
4563} 4565}
4564 4566
4565/** 4567/**
4568 * ata_qc_new - Request an available ATA command, for queueing
4569 * @ap: Port associated with device @dev
4570 * @dev: Device from whom we request an available command structure
4571 *
4572 * LOCKING:
4573 * None.
4574 */
4575
4576static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap)
4577{
4578 struct ata_queued_cmd *qc = NULL;
4579 unsigned int i;
4580
4581 /* no command while frozen */
4582 if (unlikely(ap->pflags & ATA_PFLAG_FROZEN))
4583 return NULL;
4584
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/**
4566 * ata_qc_new_init - Request an available ATA command, and initialize it 4599 * ata_qc_new_init - Request an available ATA command, and initialize it
4567 * @dev: Device from whom we request an available command structure 4600 * @dev: Device from whom we request an available command structure
4568 * @tag: command tag 4601 * @tag: command tag
@@ -4571,20 +4604,16 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words)
4571 * None. 4604 * None.
4572 */ 4605 */
4573 4606
4574struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag) 4607struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev)
4575{ 4608{
4576 struct ata_port *ap = dev->link->ap; 4609 struct ata_port *ap = dev->link->ap;
4577 struct ata_queued_cmd *qc; 4610 struct ata_queued_cmd *qc;
4578 4611
4579 if (unlikely(ap->pflags & ATA_PFLAG_FROZEN)) 4612 qc = ata_qc_new(ap);
4580 return NULL;
4581
4582 qc = __ata_qc_from_tag(ap, tag);
4583 if (qc) { 4613 if (qc) {
4584 qc->scsicmd = NULL; 4614 qc->scsicmd = NULL;
4585 qc->ap = ap; 4615 qc->ap = ap;
4586 qc->dev = dev; 4616 qc->dev = dev;
4587 qc->tag = tag;
4588 4617
4589 ata_qc_reinit(qc); 4618 ata_qc_reinit(qc);
4590 } 4619 }
@@ -4592,6 +4621,31 @@ struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag)
4592 return qc; 4621 return qc;
4593} 4622}
4594 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
4595void __ata_qc_complete(struct ata_queued_cmd *qc) 4649void __ata_qc_complete(struct ata_queued_cmd *qc)
4596{ 4650{
4597 struct ata_port *ap = qc->ap; 4651 struct ata_port *ap = qc->ap;