aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShaohua Li <shli@fb.com>2015-01-23 22:52:07 -0500
committerJens Axboe <axboe@fb.com>2015-01-24 19:09:47 -0500
commit98bd4be1ba95f2fe7f543910792b7163a5de06eb (patch)
treebae9c292324fe749f78b48d05585d5eca8b28c97
parent12cb5ce101abfaf74421f8cc9f196e708209eb79 (diff)
libata: move sas ata tag allocation to libata-scsi.c
Basically move the sas ata tag allocation to libata-scsi.c to make it clear these staffs are just for sas. Signed-off-by: Shaohua Li <shli@fb.com> Signed-off-by: Jens Axboe <axboe@fb.com>
-rw-r--r--drivers/ata/libata-core.c93
-rw-r--r--drivers/ata/libata-scsi.c28
-rw-r--r--drivers/ata/libata.h2
3 files changed, 46 insertions, 77 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 695d33df3df5..d626605ac8f7 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -1525,15 +1525,6 @@ static void ata_qc_complete_internal(struct ata_queued_cmd *qc)
1525 complete(waiting); 1525 complete(waiting);
1526} 1526}
1527 1527
1528static bool ata_valid_internal_tag(struct ata_port *ap, struct ata_device *dev,
1529 unsigned int tag)
1530{
1531 if (!ap->scsi_host)
1532 return !test_and_set_bit(tag, &ap->sas_tag_allocated);
1533 return !dev->sdev ||
1534 !blk_queue_find_tag(dev->sdev->request_queue, tag);
1535}
1536
1537/** 1528/**
1538 * ata_exec_internal_sg - execute libata internal command 1529 * ata_exec_internal_sg - execute libata internal command
1539 * @dev: Device to which the command is sent 1530 * @dev: Device to which the command is sent
@@ -1594,7 +1585,6 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
1594 else 1585 else
1595 tag = 0; 1586 tag = 0;
1596 1587
1597 BUG_ON(!ata_valid_internal_tag(ap, dev, tag));
1598 qc = __ata_qc_from_tag(ap, tag); 1588 qc = __ata_qc_from_tag(ap, tag);
1599 1589
1600 qc->tag = tag; 1590 qc->tag = tag;
@@ -4734,80 +4724,36 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words)
4734} 4724}
4735 4725
4736/** 4726/**
4737 * ata_qc_new - Request an available ATA command, for queueing 4727 * ata_qc_new_init - Request an available ATA command, and initialize it
4738 * @ap: target port 4728 * @dev: Device from whom we request an available command structure
4739 *
4740 * Some ATA host controllers may implement a queue depth which is less
4741 * than ATA_MAX_QUEUE. So we shouldn't allocate a tag which is beyond
4742 * the hardware limitation.
4743 * 4729 *
4744 * LOCKING: 4730 * LOCKING:
4745 * None. 4731 * None.
4746 */ 4732 */
4747 4733
4748static struct ata_queued_cmd *sas_ata_qc_new(struct ata_port *ap) 4734struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag)
4749{
4750 struct ata_queued_cmd *qc = NULL;
4751 unsigned int max_queue = ap->host->n_tags;
4752 unsigned int i, tag;
4753
4754 for (i = 0, tag = ap->sas_last_tag + 1; i < max_queue; i++, tag++) {
4755 tag = tag < max_queue ? tag : 0;
4756
4757 /* the last tag is reserved for internal command. */
4758 if (tag == ATA_TAG_INTERNAL)
4759 continue;
4760
4761 if (!test_and_set_bit(tag, &ap->sas_tag_allocated)) {
4762 qc = __ata_qc_from_tag(ap, tag);
4763 qc->tag = tag;
4764 ap->sas_last_tag = tag;
4765 break;
4766 }
4767 }
4768
4769 return qc;
4770}
4771
4772static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap, int blktag)
4773{ 4735{
4736 struct ata_port *ap = dev->link->ap;
4774 struct ata_queued_cmd *qc; 4737 struct ata_queued_cmd *qc;
4775 4738
4776 /* no command while frozen */ 4739 /* no command while frozen */
4777 if (unlikely(ap->pflags & ATA_PFLAG_FROZEN)) 4740 if (unlikely(ap->pflags & ATA_PFLAG_FROZEN))
4778 return NULL; 4741 return NULL;
4779 4742
4780 /* SATA will directly use block tag. libsas need its own tag management */ 4743 /* libsas case */
4781 if (ap->scsi_host) { 4744 if (!ap->scsi_host) {
4782 qc = __ata_qc_from_tag(ap, blktag); 4745 tag = ata_sas_allocate_tag(ap);
4783 qc->tag = blktag; 4746 if (tag < 0)
4784 return qc; 4747 return NULL;
4785 } 4748 }
4786 4749
4787 return sas_ata_qc_new(ap); 4750 qc = __ata_qc_from_tag(ap, tag);
4788} 4751 qc->tag = tag;
4789 4752 qc->scsicmd = NULL;
4790/** 4753 qc->ap = ap;
4791 * ata_qc_new_init - Request an available ATA command, and initialize it 4754 qc->dev = dev;
4792 * @dev: Device from whom we request an available command structure
4793 *
4794 * LOCKING:
4795 * None.
4796 */
4797
4798struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int blktag)
4799{
4800 struct ata_port *ap = dev->link->ap;
4801 struct ata_queued_cmd *qc;
4802
4803 qc = ata_qc_new(ap, blktag);
4804 if (qc) {
4805 qc->scsicmd = NULL;
4806 qc->ap = ap;
4807 qc->dev = dev;
4808 4755
4809 ata_qc_reinit(qc); 4756 ata_qc_reinit(qc);
4810 }
4811 4757
4812 return qc; 4758 return qc;
4813} 4759}
@@ -4822,12 +4768,6 @@ struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int blktag)
4822 * LOCKING: 4768 * LOCKING:
4823 * spin_lock_irqsave(host lock) 4769 * spin_lock_irqsave(host lock)
4824 */ 4770 */
4825static void sas_ata_qc_free(unsigned int tag, struct ata_port *ap)
4826{
4827 if (!ap->scsi_host)
4828 clear_bit(tag, &ap->sas_tag_allocated);
4829}
4830
4831void ata_qc_free(struct ata_queued_cmd *qc) 4771void ata_qc_free(struct ata_queued_cmd *qc)
4832{ 4772{
4833 struct ata_port *ap; 4773 struct ata_port *ap;
@@ -4840,7 +4780,8 @@ void ata_qc_free(struct ata_queued_cmd *qc)
4840 tag = qc->tag; 4780 tag = qc->tag;
4841 if (likely(ata_tag_valid(tag))) { 4781 if (likely(ata_tag_valid(tag))) {
4842 qc->tag = ATA_TAG_POISON; 4782 qc->tag = ATA_TAG_POISON;
4843 sas_ata_qc_free(tag, ap); 4783 if (!ap->scsi_host)
4784 ata_sas_free_tag(tag, ap);
4844 } 4785 }
4845} 4786}
4846 4787
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 94339c2aed1b..59c9d721b347 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -3666,7 +3666,8 @@ int ata_scsi_add_hosts(struct ata_host *host, struct scsi_host_template *sht)
3666 */ 3666 */
3667 shost->max_host_blocked = 1; 3667 shost->max_host_blocked = 1;
3668 3668
3669 scsi_init_shared_tag_map(shost, host->n_tags); 3669 if (scsi_init_shared_tag_map(shost, host->n_tags))
3670 goto err_add;
3670 3671
3671 rc = scsi_add_host_with_dma(ap->scsi_host, 3672 rc = scsi_add_host_with_dma(ap->scsi_host,
3672 &ap->tdev, ap->host->dev); 3673 &ap->tdev, ap->host->dev);
@@ -4230,3 +4231,28 @@ int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap)
4230 return rc; 4231 return rc;
4231} 4232}
4232EXPORT_SYMBOL_GPL(ata_sas_queuecmd); 4233EXPORT_SYMBOL_GPL(ata_sas_queuecmd);
4234
4235int ata_sas_allocate_tag(struct ata_port *ap)
4236{
4237 unsigned int max_queue = ap->host->n_tags;
4238 unsigned int i, tag;
4239
4240 for (i = 0, tag = ap->sas_last_tag + 1; i < max_queue; i++, tag++) {
4241 tag = tag < max_queue ? tag : 0;
4242
4243 /* the last tag is reserved for internal command. */
4244 if (tag == ATA_TAG_INTERNAL)
4245 continue;
4246
4247 if (!test_and_set_bit(tag, &ap->sas_tag_allocated)) {
4248 ap->sas_last_tag = tag;
4249 return tag;
4250 }
4251 }
4252 return -1;
4253}
4254
4255void ata_sas_free_tag(unsigned int tag, struct ata_port *ap)
4256{
4257 clear_bit(tag, &ap->sas_tag_allocated);
4258}
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index 40405135bbb6..8c491cd8805b 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -145,6 +145,8 @@ extern void ata_scsi_dev_rescan(struct work_struct *work);
145extern int ata_bus_probe(struct ata_port *ap); 145extern int ata_bus_probe(struct ata_port *ap);
146extern int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel, 146extern int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel,
147 unsigned int id, u64 lun); 147 unsigned int id, u64 lun);
148int ata_sas_allocate_tag(struct ata_port *ap);
149void ata_sas_free_tag(unsigned int tag, struct ata_port *ap);
148 150
149 151
150/* libata-eh.c */ 152/* libata-eh.c */