Merge branch 'for-3.20/drivers' of git://git.kernel.dk/linux-block
[linux-drm-fsl-dcu.git] / drivers / ata / libata-core.c
index 4b0d5e71858e28e198f626be41cdaeb87aab2f08..4c35f0822d06e54dd5399a285d22cbcfe174b115 100644 (file)
@@ -1585,8 +1585,6 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
        else
                tag = 0;
 
-       if (test_and_set_bit(tag, &ap->qc_allocated))
-               BUG();
        qc = __ata_qc_from_tag(ap, tag);
 
        qc->tag = tag;
@@ -4722,69 +4720,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 *ata_qc_new(struct ata_port *ap)
+struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag)
 {
-       struct ata_queued_cmd *qc = NULL;
-       unsigned int max_queue = ap->host->n_tags;
-       unsigned int i, 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;
 
-       for (i = 0, tag = ap->last_tag + 1; i < max_queue; i++, tag++) {
-               if (ap->flags & ATA_FLAG_LOWTAG)
-                       tag = i;
-               else
-                       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)) {
-                       qc = __ata_qc_from_tag(ap, tag);
-                       qc->tag = tag;
-                       ap->last_tag = tag;
-                       break;
-               }
+       /* libsas case */
+       if (!ap->scsi_host) {
+               tag = ata_sas_allocate_tag(ap);
+               if (tag < 0)
+                       return NULL;
        }
 
-       return qc;
-}
-
-/**
- *     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)
-{
-       struct ata_port *ap = dev->link->ap;
-       struct ata_queued_cmd *qc;
-
-       qc = ata_qc_new(ap);
-       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;
 }
@@ -4811,7 +4776,8 @@ 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);
+               if (!ap->scsi_host)
+                       ata_sas_free_tag(tag, ap);
        }
 }