libata: revert convert-to-block-tagging patches

This patch reverts the following three commits which convert libata to
use block layer tagging.

43a49cbdf31e812c0d8f553d433b09b421f5d52c
e013e13bf605b9e6b702adffbe2853cfc60e7806
2fca5ccf97d2c28bcfce44f5b07d85e74e3cd18e

Although using block layer tagging is the right direction, due to the
tight coupling among tag number, data structure allocation and
hardware command slot allocation, libata doesn't work correctly with
the current conversion.

The biggest problem is guaranteeing that tag 0 is always used for
non-NCQ commands. Due to the way blk-tag is implemented and how SCSI
starts and finishes requests, such guarantee can't be made. I'm not
sure whether this would actually break any low level driver but it
doesn't look like a good idea to break such assumption given the
frailty of ATA controllers.

So, for the time being, keep using the old dumb in-libata qc
allocation.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axobe <jens.axboe@oracle.com>
Cc: Jeff Garzik <jeff@garzik.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by Tejun Heo and committed by Linus Torvalds 8a8bc223 f7160c75

+65 -44
+60 -6
drivers/ata/libata-core.c
··· 1712 1712 else 1713 1713 tag = 0; 1714 1714 1715 + if (test_and_set_bit(tag, &ap->qc_allocated)) 1716 + BUG(); 1715 1717 qc = __ata_qc_from_tag(ap, tag); 1716 1718 1717 1719 qc->tag = tag; ··· 4565 4563 } 4566 4564 4567 4565 /** 4566 + * ata_qc_new - Request an available ATA command, for queueing 4567 + * @ap: Port associated with device @dev 4568 + * @dev: Device from whom we request an available command structure 4569 + * 4570 + * LOCKING: 4571 + * None. 4572 + */ 4573 + 4574 + static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap) 4575 + { 4576 + struct ata_queued_cmd *qc = NULL; 4577 + unsigned int i; 4578 + 4579 + /* no command while frozen */ 4580 + if (unlikely(ap->pflags & ATA_PFLAG_FROZEN)) 4581 + return NULL; 4582 + 4583 + /* the last tag is reserved for internal command. */ 4584 + for (i = 0; i < ATA_MAX_QUEUE - 1; i++) 4585 + if (!test_and_set_bit(i, &ap->qc_allocated)) { 4586 + qc = __ata_qc_from_tag(ap, i); 4587 + break; 4588 + } 4589 + 4590 + if (qc) 4591 + qc->tag = i; 4592 + 4593 + return qc; 4594 + } 4595 + 4596 + /** 4568 4597 * ata_qc_new_init - Request an available ATA command, and initialize it 4569 4598 * @dev: Device from whom we request an available command structure 4570 4599 * @tag: command tag ··· 4604 4571 * None. 4605 4572 */ 4606 4573 4607 - struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag) 4574 + struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev) 4608 4575 { 4609 4576 struct ata_port *ap = dev->link->ap; 4610 4577 struct ata_queued_cmd *qc; 4611 4578 4612 - if (unlikely(ap->pflags & ATA_PFLAG_FROZEN)) 4613 - return NULL; 4614 - 4615 - qc = __ata_qc_from_tag(ap, tag); 4579 + qc = ata_qc_new(ap); 4616 4580 if (qc) { 4617 4581 qc->scsicmd = NULL; 4618 4582 qc->ap = ap; 4619 4583 qc->dev = dev; 4620 - qc->tag = tag; 4621 4584 4622 4585 ata_qc_reinit(qc); 4623 4586 } 4624 4587 4625 4588 return qc; 4589 + } 4590 + 4591 + /** 4592 + * ata_qc_free - free unused ata_queued_cmd 4593 + * @qc: Command to complete 4594 + * 4595 + * Designed to free unused ata_queued_cmd object 4596 + * in case something prevents using it. 4597 + * 4598 + * LOCKING: 4599 + * spin_lock_irqsave(host lock) 4600 + */ 4601 + void ata_qc_free(struct ata_queued_cmd *qc) 4602 + { 4603 + struct ata_port *ap = qc->ap; 4604 + unsigned int tag; 4605 + 4606 + WARN_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */ 4607 + 4608 + qc->flags = 0; 4609 + tag = qc->tag; 4610 + if (likely(ata_tag_valid(tag))) { 4611 + qc->tag = ATA_TAG_POISON; 4612 + clear_bit(tag, &ap->qc_allocated); 4613 + } 4626 4614 } 4627 4615 4628 4616 void __ata_qc_complete(struct ata_queued_cmd *qc)
+2 -21
drivers/ata/libata-scsi.c
··· 709 709 { 710 710 struct ata_queued_cmd *qc; 711 711 712 - if (cmd->request->tag != -1) 713 - qc = ata_qc_new_init(dev, cmd->request->tag); 714 - else 715 - qc = ata_qc_new_init(dev, 0); 716 - 712 + qc = ata_qc_new_init(dev); 717 713 if (qc) { 718 714 qc->scsicmd = cmd; 719 715 qc->scsidone = done; ··· 1104 1108 1105 1109 depth = min(sdev->host->can_queue, ata_id_queue_depth(dev->id)); 1106 1110 depth = min(ATA_MAX_QUEUE - 1, depth); 1107 - 1108 - /* 1109 - * If this device is behind a port multiplier, we have 1110 - * to share the tag map between all devices on that PMP. 1111 - * Set up the shared tag map here and we get automatic. 1112 - */ 1113 - if (dev->link->ap->pmp_link) 1114 - scsi_init_shared_tag_map(sdev->host, ATA_MAX_QUEUE - 1); 1115 - 1116 - scsi_set_tag_type(sdev, MSG_SIMPLE_TAG); 1117 - scsi_activate_tcq(sdev, depth); 1111 + scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, depth); 1118 1112 } 1119 1113 1120 1114 return 0; ··· 1944 1958 hdr[1] |= (1 << 7); 1945 1959 1946 1960 memcpy(rbuf, hdr, sizeof(hdr)); 1947 - 1948 - /* if ncq, set tags supported */ 1949 - if (ata_id_has_ncq(args->id)) 1950 - rbuf[7] |= (1 << 1); 1951 - 1952 1961 memcpy(&rbuf[8], "ATA ", 8); 1953 1962 ata_id_string(args->id, &rbuf[16], ATA_ID_PROD, 16); 1954 1963 ata_id_string(args->id, &rbuf[32], ATA_ID_FW_REV, 4);
+2 -17
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, int tag); 77 + extern struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev); 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); 106 107 extern void ata_qc_issue(struct ata_queued_cmd *qc); 107 108 extern void __ata_qc_complete(struct ata_queued_cmd *qc); 108 109 extern int atapi_check_dma(struct ata_queued_cmd *qc); ··· 118 117 extern struct ata_port *ata_port_alloc(struct ata_host *host); 119 118 extern void ata_dev_enable_pm(struct ata_device *dev, enum link_pm policy); 120 119 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 - } 137 120 138 121 /* libata-acpi.c */ 139 122 #ifdef CONFIG_ATA_ACPI
+1
include/linux/libata.h
··· 698 698 unsigned int cbl; /* cable type; ATA_CBL_xxx */ 699 699 700 700 struct ata_queued_cmd qcmd[ATA_MAX_QUEUE]; 701 + unsigned long qc_allocated; 701 702 unsigned int qc_active; 702 703 int nr_active_links; /* #links with active qcs */ 703 704