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.c70
1 files changed, 18 insertions, 52 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 4b0d5e71858e..4c35f0822d06 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -1585,8 +1585,6 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
1585 else 1585 else
1586 tag = 0; 1586 tag = 0;
1587 1587
1588 if (test_and_set_bit(tag, &ap->qc_allocated))
1589 BUG();
1590 qc = __ata_qc_from_tag(ap, tag); 1588 qc = __ata_qc_from_tag(ap, tag);
1591 1589
1592 qc->tag = tag; 1590 qc->tag = tag;
@@ -4722,69 +4720,36 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words)
4722} 4720}
4723 4721
4724/** 4722/**
4725 * ata_qc_new - Request an available ATA command, for queueing 4723 * ata_qc_new_init - Request an available ATA command, and initialize it
4726 * @ap: target port 4724 * @dev: Device from whom we request an available command structure
4727 *
4728 * Some ATA host controllers may implement a queue depth which is less
4729 * than ATA_MAX_QUEUE. So we shouldn't allocate a tag which is beyond
4730 * the hardware limitation.
4731 * 4725 *
4732 * LOCKING: 4726 * LOCKING:
4733 * None. 4727 * None.
4734 */ 4728 */
4735 4729
4736static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap) 4730struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag)
4737{ 4731{
4738 struct ata_queued_cmd *qc = NULL; 4732 struct ata_port *ap = dev->link->ap;
4739 unsigned int max_queue = ap->host->n_tags; 4733 struct ata_queued_cmd *qc;
4740 unsigned int i, tag;
4741 4734
4742 /* no command while frozen */ 4735 /* no command while frozen */
4743 if (unlikely(ap->pflags & ATA_PFLAG_FROZEN)) 4736 if (unlikely(ap->pflags & ATA_PFLAG_FROZEN))
4744 return NULL; 4737 return NULL;
4745 4738
4746 for (i = 0, tag = ap->last_tag + 1; i < max_queue; i++, tag++) { 4739 /* libsas case */
4747 if (ap->flags & ATA_FLAG_LOWTAG) 4740 if (!ap->scsi_host) {
4748 tag = i; 4741 tag = ata_sas_allocate_tag(ap);
4749 else 4742 if (tag < 0)
4750 tag = tag < max_queue ? tag : 0; 4743 return NULL;
4751
4752 /* the last tag is reserved for internal command. */
4753 if (tag == ATA_TAG_INTERNAL)
4754 continue;
4755
4756 if (!test_and_set_bit(tag, &ap->qc_allocated)) {
4757 qc = __ata_qc_from_tag(ap, tag);
4758 qc->tag = tag;
4759 ap->last_tag = tag;
4760 break;
4761 }
4762 } 4744 }
4763 4745
4764 return qc; 4746 qc = __ata_qc_from_tag(ap, tag);
4765} 4747 qc->tag = tag;
4766 4748 qc->scsicmd = NULL;
4767/** 4749 qc->ap = ap;
4768 * ata_qc_new_init - Request an available ATA command, and initialize it 4750 qc->dev = dev;
4769 * @dev: Device from whom we request an available command structure
4770 *
4771 * LOCKING:
4772 * None.
4773 */
4774
4775struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev)
4776{
4777 struct ata_port *ap = dev->link->ap;
4778 struct ata_queued_cmd *qc;
4779
4780 qc = ata_qc_new(ap);
4781 if (qc) {
4782 qc->scsicmd = NULL;
4783 qc->ap = ap;
4784 qc->dev = dev;
4785 4751
4786 ata_qc_reinit(qc); 4752 ata_qc_reinit(qc);
4787 }
4788 4753
4789 return qc; 4754 return qc;
4790} 4755}
@@ -4811,7 +4776,8 @@ void ata_qc_free(struct ata_queued_cmd *qc)
4811 tag = qc->tag; 4776 tag = qc->tag;
4812 if (likely(ata_tag_valid(tag))) { 4777 if (likely(ata_tag_valid(tag))) {
4813 qc->tag = ATA_TAG_POISON; 4778 qc->tag = ATA_TAG_POISON;
4814 clear_bit(tag, &ap->qc_allocated); 4779 if (!ap->scsi_host)
4780 ata_sas_free_tag(tag, ap);
4815 } 4781 }
4816} 4782}
4817 4783