From 12cb5ce101abfaf74421f8cc9f196e708209eb79 Mon Sep 17 00:00:00 2001 From: Shaohua Li Date: Thu, 15 Jan 2015 17:32:27 -0800 Subject: libata: use blk taging libata uses its own tag management which is duplication and the implementation is poor. And if we switch to blk-mq, tag is build-in. It's time to switch to generic taging. The SAS driver has its own tag management, and looks we can't directly map the host controler tag to SATA tag. So I just bypassed the SAS case. I changed the code/variable name for the tag management of libata to make it self contained. Only sas will use it. Later if libsas implements its tag management, the tag management code in libata can be deleted easily. Cc: Jens Axboe Cc: Christoph Hellwig Signed-off-by: Shaohua Li Acked-by: Tejun Heo Signed-off-by: Jens Axboe --- drivers/ata/libata-core.c | 54 +++++++++++++++++++++++++++++++++++------------ drivers/ata/libata-scsi.c | 4 +++- drivers/ata/libata.h | 2 +- 3 files changed, 45 insertions(+), 15 deletions(-) (limited to 'drivers/ata') diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 5c84fb5c3372..695d33df3df5 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -1525,6 +1525,15 @@ static void ata_qc_complete_internal(struct ata_queued_cmd *qc) complete(waiting); } +static bool ata_valid_internal_tag(struct ata_port *ap, struct ata_device *dev, + unsigned int tag) +{ + if (!ap->scsi_host) + return !test_and_set_bit(tag, &ap->sas_tag_allocated); + return !dev->sdev || + !blk_queue_find_tag(dev->sdev->request_queue, tag); +} + /** * ata_exec_internal_sg - execute libata internal command * @dev: Device to which the command is sent @@ -1585,8 +1594,7 @@ unsigned ata_exec_internal_sg(struct ata_device *dev, else tag = 0; - if (test_and_set_bit(tag, &ap->qc_allocated)) - BUG(); + BUG_ON(!ata_valid_internal_tag(ap, dev, tag)); qc = __ata_qc_from_tag(ap, tag); qc->tag = tag; @@ -4737,27 +4745,23 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words) * None. */ -static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap) +static struct ata_queued_cmd *sas_ata_qc_new(struct ata_port *ap) { struct ata_queued_cmd *qc = NULL; unsigned int max_queue = ap->host->n_tags; unsigned int i, tag; - /* no command while frozen */ - if (unlikely(ap->pflags & ATA_PFLAG_FROZEN)) - return NULL; - - for (i = 0, tag = ap->last_tag + 1; i < max_queue; i++, tag++) { + for (i = 0, tag = ap->sas_last_tag + 1; i < max_queue; i++, tag++) { tag = tag < max_queue ? tag : 0; /* the last tag is reserved for internal command. */ if (tag == ATA_TAG_INTERNAL) continue; - if (!test_and_set_bit(tag, &ap->qc_allocated)) { + if (!test_and_set_bit(tag, &ap->sas_tag_allocated)) { qc = __ata_qc_from_tag(ap, tag); qc->tag = tag; - ap->last_tag = tag; + ap->sas_last_tag = tag; break; } } @@ -4765,6 +4769,24 @@ static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap) return qc; } +static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap, int blktag) +{ + struct ata_queued_cmd *qc; + + /* no command while frozen */ + if (unlikely(ap->pflags & ATA_PFLAG_FROZEN)) + return NULL; + + /* SATA will directly use block tag. libsas need its own tag management */ + if (ap->scsi_host) { + qc = __ata_qc_from_tag(ap, blktag); + qc->tag = blktag; + return qc; + } + + return sas_ata_qc_new(ap); +} + /** * ata_qc_new_init - Request an available ATA command, and initialize it * @dev: Device from whom we request an available command structure @@ -4773,12 +4795,12 @@ static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap) * None. */ -struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev) +struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int blktag) { struct ata_port *ap = dev->link->ap; struct ata_queued_cmd *qc; - qc = ata_qc_new(ap); + qc = ata_qc_new(ap, blktag); if (qc) { qc->scsicmd = NULL; qc->ap = ap; @@ -4800,6 +4822,12 @@ struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev) * LOCKING: * spin_lock_irqsave(host lock) */ +static void sas_ata_qc_free(unsigned int tag, struct ata_port *ap) +{ + if (!ap->scsi_host) + clear_bit(tag, &ap->sas_tag_allocated); +} + void ata_qc_free(struct ata_queued_cmd *qc) { struct ata_port *ap; @@ -4812,7 +4840,7 @@ void ata_qc_free(struct ata_queued_cmd *qc) tag = qc->tag; if (likely(ata_tag_valid(tag))) { qc->tag = ATA_TAG_POISON; - clear_bit(tag, &ap->qc_allocated); + sas_ata_qc_free(tag, ap); } } diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index e364e86e84d7..94339c2aed1b 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -756,7 +756,7 @@ static struct ata_queued_cmd *ata_scsi_qc_new(struct ata_device *dev, { struct ata_queued_cmd *qc; - qc = ata_qc_new_init(dev); + qc = ata_qc_new_init(dev, cmd->request->tag); if (qc) { qc->scsicmd = cmd; qc->scsidone = cmd->scsi_done; @@ -3666,6 +3666,8 @@ int ata_scsi_add_hosts(struct ata_host *host, struct scsi_host_template *sht) */ shost->max_host_blocked = 1; + scsi_init_shared_tag_map(shost, host->n_tags); + rc = scsi_add_host_with_dma(ap->scsi_host, &ap->tdev, ap->host->dev); if (rc) diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h index 5f4e0cca56ec..40405135bbb6 100644 --- a/drivers/ata/libata.h +++ b/drivers/ata/libata.h @@ -63,7 +63,7 @@ extern struct ata_link *ata_dev_phys_link(struct ata_device *dev); extern void ata_force_cbl(struct ata_port *ap); extern u64 ata_tf_to_lba(const struct ata_taskfile *tf); extern u64 ata_tf_to_lba48(const struct ata_taskfile *tf); -extern struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev); +extern struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag); extern int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev, u64 block, u32 n_block, unsigned int tf_flags, unsigned int tag); -- cgit v1.2.3 From 98bd4be1ba95f2fe7f543910792b7163a5de06eb Mon Sep 17 00:00:00 2001 From: Shaohua Li Date: Fri, 23 Jan 2015 19:52:07 -0800 Subject: 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 Signed-off-by: Jens Axboe --- drivers/ata/libata-core.c | 93 +++++++++-------------------------------------- drivers/ata/libata-scsi.c | 28 +++++++++++++- drivers/ata/libata.h | 2 + 3 files changed, 46 insertions(+), 77 deletions(-) (limited to 'drivers/ata') 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) complete(waiting); } -static bool ata_valid_internal_tag(struct ata_port *ap, struct ata_device *dev, - unsigned int tag) -{ - if (!ap->scsi_host) - return !test_and_set_bit(tag, &ap->sas_tag_allocated); - return !dev->sdev || - !blk_queue_find_tag(dev->sdev->request_queue, tag); -} - /** * ata_exec_internal_sg - execute libata internal command * @dev: Device to which the command is sent @@ -1594,7 +1585,6 @@ unsigned ata_exec_internal_sg(struct ata_device *dev, else tag = 0; - BUG_ON(!ata_valid_internal_tag(ap, dev, tag)); qc = __ata_qc_from_tag(ap, tag); qc->tag = tag; @@ -4734,80 +4724,36 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words) } /** - * ata_qc_new - Request an available ATA command, for queueing - * @ap: target port - * - * Some ATA host controllers may implement a queue depth which is less - * than ATA_MAX_QUEUE. So we shouldn't allocate a tag which is beyond - * the hardware limitation. + * ata_qc_new_init - Request an available ATA command, and initialize it + * @dev: Device from whom we request an available command structure * * LOCKING: * None. */ -static struct ata_queued_cmd *sas_ata_qc_new(struct ata_port *ap) -{ - struct ata_queued_cmd *qc = NULL; - unsigned int max_queue = ap->host->n_tags; - unsigned int i, tag; - - for (i = 0, tag = ap->sas_last_tag + 1; i < max_queue; i++, tag++) { - tag = tag < max_queue ? tag : 0; - - /* the last tag is reserved for internal command. */ - if (tag == ATA_TAG_INTERNAL) - continue; - - if (!test_and_set_bit(tag, &ap->sas_tag_allocated)) { - qc = __ata_qc_from_tag(ap, tag); - qc->tag = tag; - ap->sas_last_tag = tag; - break; - } - } - - return qc; -} - -static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap, int blktag) +struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag) { + struct ata_port *ap = dev->link->ap; struct ata_queued_cmd *qc; /* no command while frozen */ if (unlikely(ap->pflags & ATA_PFLAG_FROZEN)) return NULL; - /* SATA will directly use block tag. libsas need its own tag management */ - if (ap->scsi_host) { - qc = __ata_qc_from_tag(ap, blktag); - qc->tag = blktag; - return qc; + /* libsas case */ + if (!ap->scsi_host) { + tag = ata_sas_allocate_tag(ap); + if (tag < 0) + return NULL; } - return sas_ata_qc_new(ap); -} - -/** - * ata_qc_new_init - Request an available ATA command, and initialize it - * @dev: Device from whom we request an available command structure - * - * LOCKING: - * None. - */ - -struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int blktag) -{ - struct ata_port *ap = dev->link->ap; - struct ata_queued_cmd *qc; - - qc = ata_qc_new(ap, blktag); - if (qc) { - qc->scsicmd = NULL; - qc->ap = ap; - qc->dev = dev; + qc = __ata_qc_from_tag(ap, tag); + qc->tag = tag; + qc->scsicmd = NULL; + qc->ap = ap; + qc->dev = dev; - ata_qc_reinit(qc); - } + ata_qc_reinit(qc); return qc; } @@ -4822,12 +4768,6 @@ struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int blktag) * LOCKING: * spin_lock_irqsave(host lock) */ -static void sas_ata_qc_free(unsigned int tag, struct ata_port *ap) -{ - if (!ap->scsi_host) - clear_bit(tag, &ap->sas_tag_allocated); -} - void ata_qc_free(struct ata_queued_cmd *qc) { struct ata_port *ap; @@ -4840,7 +4780,8 @@ void ata_qc_free(struct ata_queued_cmd *qc) tag = qc->tag; if (likely(ata_tag_valid(tag))) { qc->tag = ATA_TAG_POISON; - sas_ata_qc_free(tag, ap); + if (!ap->scsi_host) + ata_sas_free_tag(tag, ap); } } 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) */ shost->max_host_blocked = 1; - scsi_init_shared_tag_map(shost, host->n_tags); + if (scsi_init_shared_tag_map(shost, host->n_tags)) + goto err_add; rc = scsi_add_host_with_dma(ap->scsi_host, &ap->tdev, ap->host->dev); @@ -4230,3 +4231,28 @@ int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap) return rc; } EXPORT_SYMBOL_GPL(ata_sas_queuecmd); + +int ata_sas_allocate_tag(struct ata_port *ap) +{ + unsigned int max_queue = ap->host->n_tags; + unsigned int i, tag; + + for (i = 0, tag = ap->sas_last_tag + 1; i < max_queue; i++, tag++) { + tag = tag < max_queue ? tag : 0; + + /* the last tag is reserved for internal command. */ + if (tag == ATA_TAG_INTERNAL) + continue; + + if (!test_and_set_bit(tag, &ap->sas_tag_allocated)) { + ap->sas_last_tag = tag; + return tag; + } + } + return -1; +} + +void ata_sas_free_tag(unsigned int tag, struct ata_port *ap) +{ + clear_bit(tag, &ap->sas_tag_allocated); +} 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); extern int ata_bus_probe(struct ata_port *ap); extern int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel, unsigned int id, u64 lun); +int ata_sas_allocate_tag(struct ata_port *ap); +void ata_sas_free_tag(unsigned int tag, struct ata_port *ap); /* libata-eh.c */ -- cgit v1.2.3 From 9269e23496ddd83b974536019cf420520df0ee7f Mon Sep 17 00:00:00 2001 From: Shaohua Li Date: Fri, 23 Jan 2015 20:17:59 -0800 Subject: libata: make sata_sil24 use fifo tag allocator libata starts using block tag now, we can use BLK_TAG_ALLOC_FIFO to solve the sata_sil24 tag bug. https://bugzilla.kernel.org/show_bug.cgi?id=87101 Cc: Christoph Hellwig Signed-off-by: Shaohua Li Acked-by: Tejun Heo Acked-by: Dan Williams Signed-off-by: Jens Axboe --- drivers/ata/sata_sil24.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/ata') diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c index d81b20ddb527..52428971ba94 100644 --- a/drivers/ata/sata_sil24.c +++ b/drivers/ata/sata_sil24.c @@ -388,6 +388,7 @@ static struct scsi_host_template sil24_sht = { .can_queue = SIL24_MAX_CMDS, .sg_tablesize = SIL24_MAX_SGE, .dma_boundary = ATA_DMA_BOUNDARY, + .tag_alloc_policy = BLK_TAG_ALLOC_FIFO, }; static struct ata_port_operations sil24_ops = { -- cgit v1.2.3