aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/ata/libata-core.c21
-rw-r--r--include/linux/libata.h1
2 files changed, 14 insertions, 8 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index f2a6020366e1..73c5d0410d47 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -4794,21 +4794,26 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words)
4794static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap) 4794static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap)
4795{ 4795{
4796 struct ata_queued_cmd *qc = NULL; 4796 struct ata_queued_cmd *qc = NULL;
4797 unsigned int i; 4797 unsigned int i, tag;
4798 4798
4799 /* no command while frozen */ 4799 /* no command while frozen */
4800 if (unlikely(ap->pflags & ATA_PFLAG_FROZEN)) 4800 if (unlikely(ap->pflags & ATA_PFLAG_FROZEN))
4801 return NULL; 4801 return NULL;
4802 4802
4803 /* the last tag is reserved for internal command. */ 4803 for (i = 0; i < ATA_MAX_QUEUE; i++) {
4804 for (i = 0; i < ATA_MAX_QUEUE - 1; i++) 4804 tag = (i + ap->last_tag + 1) % ATA_MAX_QUEUE;
4805 if (!test_and_set_bit(i, &ap->qc_allocated)) { 4805
4806 qc = __ata_qc_from_tag(ap, i); 4806 /* the last tag is reserved for internal command. */
4807 if (tag == ATA_TAG_INTERNAL)
4808 continue;
4809
4810 if (!test_and_set_bit(tag, &ap->qc_allocated)) {
4811 qc = __ata_qc_from_tag(ap, tag);
4812 qc->tag = tag;
4813 ap->last_tag = tag;
4807 break; 4814 break;
4808 } 4815 }
4809 4816 }
4810 if (qc)
4811 qc->tag = i;
4812 4817
4813 return qc; 4818 return qc;
4814} 4819}
diff --git a/include/linux/libata.h b/include/linux/libata.h
index 1de36be64df4..5ab4e3a76721 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -822,6 +822,7 @@ struct ata_port {
822 unsigned long qc_allocated; 822 unsigned long qc_allocated;
823 unsigned int qc_active; 823 unsigned int qc_active;
824 int nr_active_links; /* #links with active qcs */ 824 int nr_active_links; /* #links with active qcs */
825 unsigned int last_tag; /* track next tag hw expects */
825 826
826 struct ata_link link; /* host default link */ 827 struct ata_link link; /* host default link */
827 struct ata_link *slave_link; /* see ata_slave_link_init() */ 828 struct ata_link *slave_link; /* see ata_slave_link_init() */