libata: switch to using block layer tagging support

libata currently has a pretty dumb ATA_MAX_QUEUE loop for finding
a free tag to use. Instead of fixing that up, convert libata to
using block layer tagging - gets rid of code in libata, and is also
much faster.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by Jens Axboe and committed by Linus Torvalds 2fca5ccf 332edc2f

+31 -65
+6 -60
drivers/ata/libata-core.c
··· 1713 1713 else 1714 1714 tag = 0; 1715 1715 1716 - if (test_and_set_bit(tag, &ap->qc_allocated)) 1717 - BUG(); 1718 1716 qc = __ata_qc_from_tag(ap, tag); 1719 1717 1720 1718 qc->tag = tag; ··· 4551 4553 } 4552 4554 4553 4555 /** 4554 - * ata_qc_new - Request an available ATA command, for queueing 4555 - * @ap: Port associated with device @dev 4556 - * @dev: Device from whom we request an available command structure 4557 - * 4558 - * LOCKING: 4559 - * None. 4560 - */ 4561 - 4562 - static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap) 4563 - { 4564 - struct ata_queued_cmd *qc = NULL; 4565 - unsigned int i; 4566 - 4567 - /* no command while frozen */ 4568 - if (unlikely(ap->pflags & ATA_PFLAG_FROZEN)) 4569 - return NULL; 4570 - 4571 - /* the last tag is reserved for internal command. */ 4572 - for (i = 0; i < ATA_MAX_QUEUE - 1; i++) 4573 - if (!test_and_set_bit(i, &ap->qc_allocated)) { 4574 - qc = __ata_qc_from_tag(ap, i); 4575 - break; 4576 - } 4577 - 4578 - if (qc) 4579 - qc->tag = i; 4580 - 4581 - return qc; 4582 - } 4583 - 4584 - /** 4585 4556 * ata_qc_new_init - Request an available ATA command, and initialize it 4586 4557 * @dev: Device from whom we request an available command structure 4587 4558 * ··· 4558 4591 * None. 4559 4592 */ 4560 4593 4561 - struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev) 4594 + struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag) 4562 4595 { 4563 4596 struct ata_port *ap = dev->link->ap; 4564 4597 struct ata_queued_cmd *qc; 4565 4598 4566 - qc = ata_qc_new(ap); 4599 + if (unlikely(ap->pflags & ATA_PFLAG_FROZEN)) 4600 + return NULL; 4601 + 4602 + qc = __ata_qc_from_tag(ap, tag); 4567 4603 if (qc) { 4568 4604 qc->scsicmd = NULL; 4569 4605 qc->ap = ap; 4570 4606 qc->dev = dev; 4607 + qc->tag = tag; 4571 4608 4572 4609 ata_qc_reinit(qc); 4573 4610 } 4574 4611 4575 4612 return qc; 4576 - } 4577 - 4578 - /** 4579 - * ata_qc_free - free unused ata_queued_cmd 4580 - * @qc: Command to complete 4581 - * 4582 - * Designed to free unused ata_queued_cmd object 4583 - * in case something prevents using it. 4584 - * 4585 - * LOCKING: 4586 - * spin_lock_irqsave(host lock) 4587 - */ 4588 - void ata_qc_free(struct ata_queued_cmd *qc) 4589 - { 4590 - struct ata_port *ap = qc->ap; 4591 - unsigned int tag; 4592 - 4593 - WARN_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */ 4594 - 4595 - qc->flags = 0; 4596 - tag = qc->tag; 4597 - if (likely(ata_tag_valid(tag))) { 4598 - qc->tag = ATA_TAG_POISON; 4599 - clear_bit(tag, &ap->qc_allocated); 4600 - } 4601 4613 } 4602 4614 4603 4615 void __ata_qc_complete(struct ata_queued_cmd *qc)
+8 -2
drivers/ata/libata-scsi.c
··· 708 708 { 709 709 struct ata_queued_cmd *qc; 710 710 711 - qc = ata_qc_new_init(dev); 711 + qc = ata_qc_new_init(dev, cmd->request->tag); 712 712 if (qc) { 713 713 qc->scsicmd = cmd; 714 714 qc->scsidone = done; ··· 1103 1103 1104 1104 depth = min(sdev->host->can_queue, ata_id_queue_depth(dev->id)); 1105 1105 depth = min(ATA_MAX_QUEUE - 1, depth); 1106 - scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, depth); 1106 + scsi_set_tag_type(sdev, MSG_SIMPLE_TAG); 1107 + scsi_activate_tcq(sdev, depth); 1107 1108 } 1108 1109 1109 1110 return 0; ··· 1944 1943 hdr[1] |= (1 << 7); 1945 1944 1946 1945 memcpy(rbuf, hdr, sizeof(hdr)); 1946 + 1947 + /* if ncq, set tags supported */ 1948 + if (ata_id_has_ncq(args->id)) 1949 + rbuf[7] |= (1 << 1); 1950 + 1947 1951 memcpy(&rbuf[8], "ATA ", 8); 1948 1952 ata_id_string(args->id, &rbuf[16], ATA_ID_PROD, 16); 1949 1953 ata_id_string(args->id, &rbuf[32], ATA_ID_FW_REV, 4);
+17 -2
drivers/ata/libata.h
··· 74 74 extern void ata_force_cbl(struct ata_port *ap); 75 75 extern u64 ata_tf_to_lba(const struct ata_taskfile *tf); 76 76 extern u64 ata_tf_to_lba48(const struct ata_taskfile *tf); 77 - extern struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev); 77 + extern struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag); 78 78 extern int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev, 79 79 u64 block, u32 n_block, unsigned int tf_flags, 80 80 unsigned int tag); ··· 103 103 extern int sata_down_spd_limit(struct ata_link *link); 104 104 extern int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel); 105 105 extern void ata_sg_clean(struct ata_queued_cmd *qc); 106 - extern void ata_qc_free(struct ata_queued_cmd *qc); 107 106 extern void ata_qc_issue(struct ata_queued_cmd *qc); 108 107 extern void __ata_qc_complete(struct ata_queued_cmd *qc); 109 108 extern int atapi_check_dma(struct ata_queued_cmd *qc); ··· 117 118 extern struct ata_port *ata_port_alloc(struct ata_host *host); 118 119 extern void ata_dev_enable_pm(struct ata_device *dev, enum link_pm policy); 119 120 extern void ata_lpm_schedule(struct ata_port *ap, enum link_pm); 121 + 122 + /** 123 + * ata_qc_free - free unused ata_queued_cmd 124 + * @qc: Command to complete 125 + * 126 + * Designed to free unused ata_queued_cmd object 127 + * in case something prevents using it. 128 + * 129 + * LOCKING: 130 + * spin_lock_irqsave(host lock) 131 + */ 132 + static inline void ata_qc_free(struct ata_queued_cmd *qc) 133 + { 134 + qc->flags = 0; 135 + qc->tag = ATA_TAG_POISON; 136 + } 120 137 121 138 /* libata-acpi.c */ 122 139 #ifdef CONFIG_ATA_ACPI
-1
include/linux/libata.h
··· 695 695 unsigned int cbl; /* cable type; ATA_CBL_xxx */ 696 696 697 697 struct ata_queued_cmd qcmd[ATA_MAX_QUEUE]; 698 - unsigned long qc_allocated; 699 698 unsigned int qc_active; 700 699 int nr_active_links; /* #links with active qcs */ 701 700