Merge branch 'for-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/libata
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 6 Jun 2018 00:01:41 +0000 (17:01 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 6 Jun 2018 00:01:41 +0000 (17:01 -0700)
Pull libata updates from Tejun Heo:

 - libata has always been limiting the maximum queue depth to 31, with
   one entry set aside mostly for historical reasons. This didn't use to
   make much difference but Jens found out that modern hard drives can
   actually perform measurably better with the extra one queue depth.
   Jens updated libata core so that it can make use of full 32 queue
   depth

 - Damien updated command retry logic in error handling so that it
   doesn't unnecessarily retry when upper layer (SCSI) is gonna handle
   them

 - A couple misc changes

* 'for-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/libata:
  sata_fsl: use the right type for tag bitshift
  ahci: enable full queue depth of 32
  libata: don't clamp queue depth to ATA_MAX_QUEUE - 1
  libata: add extra internal command
  sata_nv: set host can_queue count appropriately
  libata: remove assumption that ATA_MAX_QUEUE - 1 is the max
  libata: use ata_tag_internal() consistently
  libata: bump ->qc_active to a 64-bit type
  libata: convert core and drivers to ->hw_tag usage
  libata: introduce notion of separate hardware tags
  libata: Fix command retry decision
  libata: Honor RQF_QUIET flag
  libata: Make ata_dev_set_mode() less verbose
  libata: Fix ata_err_string()
  libata: Fix comment typo in ata_eh_analyze_tf()
  sata_nv: don't use block layer bounce buffer
  ata: hpt37x: Convert to use match_string() helper

1  2 
drivers/ata/ahci.h
drivers/ata/libahci.c
drivers/ata/libata-core.c
drivers/ata/libata-eh.c
drivers/ata/sata_sil24.c
include/linux/libata.h

diff --combined drivers/ata/ahci.h
@@@ -350,6 -350,7 +350,6 @@@ struct ahci_host_priv 
        u32                     em_msg_type;    /* EM message type */
        bool                    got_runtime_pm; /* Did we do pm_runtime_get? */
        struct clk              *clks[AHCI_MAX_CLKS]; /* Optional */
 -      struct reset_control    *rsts;          /* Optional */
        struct regulator        **target_pwrs;  /* Optional */
        /*
         * If platform uses PHYs. There is a 1:1 relation between the port number and
         * be overridden anytime before the host is activated.
         */
        void                    (*start_engine)(struct ata_port *ap);
 +      /*
 +       * Optional ahci_stop_engine override, if not set this gets set to the
 +       * default ahci_stop_engine during ahci_save_initial_config, this can
 +       * be overridden anytime before the host is activated.
 +       */
 +      int                     (*stop_engine)(struct ata_port *ap);
 +
        irqreturn_t             (*irq_handler)(int irq, void *dev_instance);
  
        /* only required for per-port MSI(-X) support */
@@@ -390,7 -384,7 +390,7 @@@ extern struct device_attribute *ahci_sd
   */
  #define AHCI_SHT(drv_name)                                            \
        ATA_NCQ_SHT(drv_name),                                          \
-       .can_queue              = AHCI_MAX_CMDS - 1,                    \
+       .can_queue              = AHCI_MAX_CMDS,                        \
        .sg_tablesize           = AHCI_MAX_SG,                          \
        .dma_boundary           = AHCI_DMA_BOUNDARY,                    \
        .shost_attrs            = ahci_shost_attrs,                     \
diff --combined drivers/ata/libahci.c
@@@ -560,9 -560,6 +560,9 @@@ void ahci_save_initial_config(struct de
        if (!hpriv->start_engine)
                hpriv->start_engine = ahci_start_engine;
  
 +      if (!hpriv->stop_engine)
 +              hpriv->stop_engine = ahci_stop_engine;
 +
        if (!hpriv->irq_handler)
                hpriv->irq_handler = ahci_single_level_irq_intr;
  }
@@@ -900,10 -897,9 +900,10 @@@ static void ahci_start_port(struct ata_
  static int ahci_deinit_port(struct ata_port *ap, const char **emsg)
  {
        int rc;
 +      struct ahci_host_priv *hpriv = ap->host->private_data;
  
        /* disable DMA */
 -      rc = ahci_stop_engine(ap);
 +      rc = hpriv->stop_engine(ap);
        if (rc) {
                *emsg = "failed to stop engine";
                return rc;
@@@ -1314,7 -1310,7 +1314,7 @@@ int ahci_kick_engine(struct ata_port *a
        int busy, rc;
  
        /* stop engine */
 -      rc = ahci_stop_engine(ap);
 +      rc = hpriv->stop_engine(ap);
        if (rc)
                goto out_restart;
  
@@@ -1553,7 -1549,7 +1553,7 @@@ int ahci_do_hardreset(struct ata_link *
  
        DPRINTK("ENTER\n");
  
 -      ahci_stop_engine(ap);
 +      hpriv->stop_engine(ap);
  
        /* clear D2H reception area to properly wait for D2H FIS */
        ata_tf_init(link->device, &tf);
@@@ -1649,7 -1645,7 +1649,7 @@@ static void ahci_qc_prep(struct ata_que
         * Fill in command table information.  First, the header,
         * a SATA Register - Host to Device command FIS.
         */
-       cmd_tbl = pp->cmd_tbl + qc->tag * AHCI_CMD_TBL_SZ;
+       cmd_tbl = pp->cmd_tbl + qc->hw_tag * AHCI_CMD_TBL_SZ;
  
        ata_tf_to_fis(&qc->tf, qc->dev->link->pmp, 1, cmd_tbl);
        if (is_atapi) {
        if (is_atapi)
                opts |= AHCI_CMD_ATAPI | AHCI_CMD_PREFETCH;
  
-       ahci_fill_cmd_slot(pp, qc->tag, opts);
+       ahci_fill_cmd_slot(pp, qc->hw_tag, opts);
  }
  
  static void ahci_fbs_dec_intr(struct ata_port *ap)
@@@ -2006,7 -2002,7 +2006,7 @@@ unsigned int ahci_qc_issue(struct ata_q
        pp->active_link = qc->dev->link;
  
        if (ata_is_ncq(qc->tf.protocol))
-               writel(1 << qc->tag, port_mmio + PORT_SCR_ACT);
+               writel(1 << qc->hw_tag, port_mmio + PORT_SCR_ACT);
  
        if (pp->fbs_enabled && pp->fbs_last_dev != qc->dev->link->pmp) {
                u32 fbs = readl(port_mmio + PORT_FBS);
                pp->fbs_last_dev = qc->dev->link->pmp;
        }
  
-       writel(1 << qc->tag, port_mmio + PORT_CMD_ISSUE);
+       writel(1 << qc->hw_tag, port_mmio + PORT_CMD_ISSUE);
  
        ahci_sw_activity(qc->dev->link);
  
@@@ -2079,14 -2075,14 +2079,14 @@@ void ahci_error_handler(struct ata_por
  
        if (!(ap->pflags & ATA_PFLAG_FROZEN)) {
                /* restart engine */
 -              ahci_stop_engine(ap);
 +              hpriv->stop_engine(ap);
                hpriv->start_engine(ap);
        }
  
        sata_pmp_error_handler(ap);
  
        if (!ata_dev_enabled(ap->link.device))
 -              ahci_stop_engine(ap);
 +              hpriv->stop_engine(ap);
  }
  EXPORT_SYMBOL_GPL(ahci_error_handler);
  
@@@ -2133,7 -2129,7 +2133,7 @@@ static void ahci_set_aggressive_devslp(
                return;
  
        /* set DITO, MDAT, DETO and enable DevSlp, need to stop engine first */
 -      rc = ahci_stop_engine(ap);
 +      rc = hpriv->stop_engine(ap);
        if (rc)
                return;
  
@@@ -2193,7 -2189,7 +2193,7 @@@ static void ahci_enable_fbs(struct ata_
                return;
        }
  
 -      rc = ahci_stop_engine(ap);
 +      rc = hpriv->stop_engine(ap);
        if (rc)
                return;
  
@@@ -2226,7 -2222,7 +2226,7 @@@ static void ahci_disable_fbs(struct ata
                return;
        }
  
 -      rc = ahci_stop_engine(ap);
 +      rc = hpriv->stop_engine(ap);
        if (rc)
                return;
  
@@@ -759,7 -759,7 +759,7 @@@ int ata_build_rw_tf(struct ata_taskfil
        tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
        tf->flags |= tf_flags;
  
-       if (ata_ncq_enabled(dev) && likely(tag != ATA_TAG_INTERNAL)) {
+       if (ata_ncq_enabled(dev) && !ata_tag_internal(tag)) {
                /* yay, NCQ */
                if (!lba_48_ok(block, n_block))
                        return -ERANGE;
@@@ -1570,8 -1570,9 +1570,9 @@@ unsigned ata_exec_internal_sg(struct at
        u8 command = tf->command;
        int auto_timeout = 0;
        struct ata_queued_cmd *qc;
-       unsigned int tag, preempted_tag;
-       u32 preempted_sactive, preempted_qc_active;
+       unsigned int preempted_tag;
+       u32 preempted_sactive;
+       u64 preempted_qc_active;
        int preempted_nr_active_links;
        DECLARE_COMPLETION_ONSTACK(wait);
        unsigned long flags;
        }
  
        /* initialize internal qc */
+       qc = __ata_qc_from_tag(ap, ATA_TAG_INTERNAL);
  
-       /* XXX: Tag 0 is used for drivers with legacy EH as some
-        * drivers choke if any other tag is given.  This breaks
-        * ata_tag_internal() test for those drivers.  Don't use new
-        * EH stuff without converting to it.
-        */
-       if (ap->ops->error_handler)
-               tag = ATA_TAG_INTERNAL;
-       else
-               tag = 0;
-       qc = __ata_qc_from_tag(ap, tag);
-       qc->tag = tag;
+       qc->tag = ATA_TAG_INTERNAL;
+       qc->hw_tag = 0;
        qc->scsicmd = NULL;
        qc->ap = ap;
        qc->dev = dev;
@@@ -2295,7 -2286,7 +2286,7 @@@ static int ata_dev_config_ncq(struct at
                return 0;
        }
        if (ap->flags & ATA_FLAG_NCQ) {
-               hdepth = min(ap->scsi_host->can_queue, ATA_MAX_QUEUE - 1);
+               hdepth = min(ap->scsi_host->can_queue, ATA_MAX_QUEUE);
                dev->flags |= ATA_DFLAG_NCQ;
        }
  
@@@ -3573,9 -3564,11 +3564,11 @@@ static int ata_dev_set_mode(struct ata_
        DPRINTK("xfer_shift=%u, xfer_mode=0x%x\n",
                dev->xfer_shift, (int)dev->xfer_mode);
  
-       ata_dev_info(dev, "configured for %s%s\n",
-                    ata_mode_string(ata_xfer_mode2mask(dev->xfer_mode)),
-                    dev_err_whine);
+       if (!(ehc->i.flags & ATA_EHI_QUIET) ||
+           ehc->i.flags & ATA_EHI_DID_HARDRESET)
+               ata_dev_info(dev, "configured for %s%s\n",
+                            ata_mode_string(ata_xfer_mode2mask(dev->xfer_mode)),
+                            dev_err_whine);
  
        return 0;
  
@@@ -4493,10 -4486,6 +4486,10 @@@ static const struct ata_blacklist_entr
        /* https://bugzilla.kernel.org/show_bug.cgi?id=15573 */
        { "C300-CTFDDAC128MAG", "0001",         ATA_HORKAGE_NONCQ, },
  
 +      /* Some Sandisk SSDs lock up hard with NCQ enabled.  Reported on
 +         SD7SN6S256G and SD8SN8U256G */
 +      { "SanDisk SD[78]SN*G", NULL,           ATA_HORKAGE_NONCQ, },
 +
        /* devices which puke on READ_NATIVE_MAX */
        { "HDS724040KLSA80",    "KFAOA20N",     ATA_HORKAGE_BROKEN_HPA, },
        { "WDC WD3200JD-00KLB0", "WD-WCAMR1130137", ATA_HORKAGE_BROKEN_HPA },
                                                ATA_HORKAGE_ZERO_AFTER_TRIM |
                                                ATA_HORKAGE_NOLPM, },
  
 +      /* These specific Samsung models/firmware-revs do not handle LPM well */
 +      { "SAMSUNG MZMPC128HBFU-000MV", "CXM14M1Q", ATA_HORKAGE_NOLPM, },
 +      { "SAMSUNG SSD PM830 mSATA *",  "CXM13D1Q", ATA_HORKAGE_NOLPM, },
 +
        /* devices that don't properly handle queued TRIM commands */
 +      { "Micron_M500IT_*",            "MU01", ATA_HORKAGE_NO_NCQ_TRIM |
 +                                              ATA_HORKAGE_ZERO_AFTER_TRIM, },
        { "Micron_M500_*",              NULL,   ATA_HORKAGE_NO_NCQ_TRIM |
                                                ATA_HORKAGE_ZERO_AFTER_TRIM, },
        { "Crucial_CT*M500*",           NULL,   ATA_HORKAGE_NO_NCQ_TRIM |
@@@ -5133,7 -5116,7 +5126,7 @@@ struct ata_queued_cmd *ata_qc_new_init(
        }
  
        qc = __ata_qc_from_tag(ap, tag);
-       qc->tag = tag;
+       qc->tag = qc->hw_tag = tag;
        qc->scsicmd = NULL;
        qc->ap = ap;
        qc->dev = dev;
@@@ -5163,7 -5146,7 +5156,7 @@@ void ata_qc_free(struct ata_queued_cmd 
  
        qc->flags = 0;
        tag = qc->tag;
-       if (likely(ata_tag_valid(tag))) {
+       if (ata_tag_valid(tag)) {
                qc->tag = ATA_TAG_POISON;
                if (ap->flags & ATA_FLAG_SAS_HOST)
                        ata_sas_free_tag(tag, ap);
@@@ -5185,7 -5168,7 +5178,7 @@@ void __ata_qc_complete(struct ata_queue
  
        /* command should be marked inactive atomically with qc completion */
        if (ata_is_ncq(qc->tf.protocol)) {
-               link->sactive &= ~(1 << qc->tag);
+               link->sactive &= ~(1 << qc->hw_tag);
                if (!link->sactive)
                        ap->nr_active_links--;
        } else {
         * is called. (when rc != 0 and atapi request sense is needed)
         */
        qc->flags &= ~ATA_QCFLAG_ACTIVE;
-       ap->qc_active &= ~(1 << qc->tag);
+       ap->qc_active &= ~(1ULL << qc->tag);
  
        /* call completion callback */
        qc->complete_fn(qc);
@@@ -5360,29 -5343,29 +5353,29 @@@ void ata_qc_complete(struct ata_queued_
   *    RETURNS:
   *    Number of completed commands on success, -errno otherwise.
   */
- int ata_qc_complete_multiple(struct ata_port *ap, u32 qc_active)
+ int ata_qc_complete_multiple(struct ata_port *ap, u64 qc_active)
  {
        int nr_done = 0;
-       u32 done_mask;
+       u64 done_mask;
  
        done_mask = ap->qc_active ^ qc_active;
  
        if (unlikely(done_mask & qc_active)) {
-               ata_port_err(ap, "illegal qc_active transition (%08x->%08x)\n",
+               ata_port_err(ap, "illegal qc_active transition (%08llx->%08llx)\n",
                             ap->qc_active, qc_active);
                return -EINVAL;
        }
  
        while (done_mask) {
                struct ata_queued_cmd *qc;
-               unsigned int tag = __ffs(done_mask);
+               unsigned int tag = __ffs64(done_mask);
  
                qc = ata_qc_from_tag(ap, tag);
                if (qc) {
                        ata_qc_complete(qc);
                        nr_done++;
                }
-               done_mask &= ~(1 << tag);
+               done_mask &= ~(1ULL << tag);
        }
  
        return nr_done;
@@@ -5413,11 -5396,11 +5406,11 @@@ void ata_qc_issue(struct ata_queued_cm
        WARN_ON_ONCE(ap->ops->error_handler && ata_tag_valid(link->active_tag));
  
        if (ata_is_ncq(prot)) {
-               WARN_ON_ONCE(link->sactive & (1 << qc->tag));
+               WARN_ON_ONCE(link->sactive & (1 << qc->hw_tag));
  
                if (!link->sactive)
                        ap->nr_active_links++;
-               link->sactive |= 1 << qc->tag;
+               link->sactive |= 1 << qc->hw_tag;
        } else {
                WARN_ON_ONCE(link->sactive);
  
        }
  
        qc->flags |= ATA_QCFLAG_ACTIVE;
-       ap->qc_active |= 1 << qc->tag;
+       ap->qc_active |= 1ULL << qc->tag;
  
        /*
         * We guarantee to LLDs that they will have at least one
@@@ -6425,7 -6408,7 +6418,7 @@@ void ata_host_init(struct ata_host *hos
  {
        spin_lock_init(&host->lock);
        mutex_init(&host->eh_mutex);
-       host->n_tags = ATA_MAX_QUEUE - 1;
+       host->n_tags = ATA_MAX_QUEUE;
        host->dev = dev;
        host->ops = ops;
  }
@@@ -6507,7 -6490,7 +6500,7 @@@ int ata_host_register(struct ata_host *
  {
        int i, rc;
  
-       host->n_tags = clamp(sht->can_queue, 1, ATA_MAX_QUEUE - 1);
+       host->n_tags = clamp(sht->can_queue, 1, ATA_MAX_QUEUE);
  
        /* host must have been started */
        if (!(host->flags & ATA_HOST_STARTED)) {
diff --combined drivers/ata/libata-eh.c
@@@ -175,8 -175,8 +175,8 @@@ static void ata_eh_handle_port_resume(s
  { }
  #endif /* CONFIG_PM */
  
 -static void __ata_ehi_pushv_desc(struct ata_eh_info *ehi, const char *fmt,
 -                               va_list args)
 +static __printf(2, 0) void __ata_ehi_pushv_desc(struct ata_eh_info *ehi,
 +                               const char *fmt, va_list args)
  {
        ehi->desc_len += vscnprintf(ehi->desc + ehi->desc_len,
                                     ATA_EH_DESC_LEN - ehi->desc_len,
@@@ -500,6 -500,57 +500,6 @@@ void ata_eh_release(struct ata_port *ap
        mutex_unlock(&ap->host->eh_mutex);
  }
  
 -/**
 - *    ata_scsi_timed_out - SCSI layer time out callback
 - *    @cmd: timed out SCSI command
 - *
 - *    Handles SCSI layer timeout.  We race with normal completion of
 - *    the qc for @cmd.  If the qc is already gone, we lose and let
 - *    the scsi command finish (EH_HANDLED).  Otherwise, the qc has
 - *    timed out and EH should be invoked.  Prevent ata_qc_complete()
 - *    from finishing it by setting EH_SCHEDULED and return
 - *    EH_NOT_HANDLED.
 - *
 - *    TODO: kill this function once old EH is gone.
 - *
 - *    LOCKING:
 - *    Called from timer context
 - *
 - *    RETURNS:
 - *    EH_HANDLED or EH_NOT_HANDLED
 - */
 -enum blk_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd)
 -{
 -      struct Scsi_Host *host = cmd->device->host;
 -      struct ata_port *ap = ata_shost_to_port(host);
 -      unsigned long flags;
 -      struct ata_queued_cmd *qc;
 -      enum blk_eh_timer_return ret;
 -
 -      DPRINTK("ENTER\n");
 -
 -      if (ap->ops->error_handler) {
 -              ret = BLK_EH_NOT_HANDLED;
 -              goto out;
 -      }
 -
 -      ret = BLK_EH_HANDLED;
 -      spin_lock_irqsave(ap->lock, flags);
 -      qc = ata_qc_from_tag(ap, ap->link.active_tag);
 -      if (qc) {
 -              WARN_ON(qc->scsicmd != cmd);
 -              qc->flags |= ATA_QCFLAG_EH_SCHEDULED;
 -              qc->err_mask |= AC_ERR_TIMEOUT;
 -              ret = BLK_EH_NOT_HANDLED;
 -      }
 -      spin_unlock_irqrestore(ap->lock, flags);
 -
 - out:
 -      DPRINTK("EXIT, ret=%d\n", ret);
 -      return ret;
 -}
 -EXPORT_SYMBOL(ata_scsi_timed_out);
 -
  static void ata_eh_unload(struct ata_port *ap)
  {
        struct ata_link *link;
@@@ -822,9 -873,12 +822,12 @@@ static int ata_eh_nr_in_flight(struct a
        int nr = 0;
  
        /* count only non-internal commands */
-       for (tag = 0; tag < ATA_MAX_QUEUE - 1; tag++)
+       for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
+               if (ata_tag_internal(tag))
+                       continue;
                if (ata_qc_from_tag(ap, tag))
                        nr++;
+       }
  
        return nr;
  }
@@@ -849,7 -903,7 +852,7 @@@ void ata_eh_fastdrain_timerfn(struct ti
                /* No progress during the last interval, tag all
                 * in-flight qcs as timed out and freeze the port.
                 */
-               for (tag = 0; tag < ATA_MAX_QUEUE - 1; tag++) {
+               for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
                        struct ata_queued_cmd *qc = ata_qc_from_tag(ap, tag);
                        if (qc)
                                qc->err_mask |= AC_ERR_TIMEOUT;
@@@ -1003,7 -1057,8 +1006,8 @@@ static int ata_do_link_abort(struct ata
        /* we're gonna abort all commands, no need for fast drain */
        ata_eh_set_pending(ap, 0);
  
-       for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
+       /* include internal tag in iteration */
+       for (tag = 0; tag <= ATA_MAX_QUEUE; tag++) {
                struct ata_queued_cmd *qc = ata_qc_from_tag(ap, tag);
  
                if (qc && (!link || qc->dev->link == link)) {
@@@ -1432,6 -1487,10 +1436,10 @@@ static const char *ata_err_string(unsig
                return "invalid argument";
        if (err_mask & AC_ERR_DEV)
                return "device error";
+       if (err_mask & AC_ERR_NCQ)
+               return "NCQ error";
+       if (err_mask & AC_ERR_NODEV_HINT)
+               return "Polling detection error";
        return "unknown error";
  }
  
@@@ -1815,10 -1874,10 +1823,10 @@@ static unsigned int ata_eh_analyze_tf(s
        if (qc->flags & ATA_QCFLAG_SENSE_VALID) {
                int ret = scsi_check_sense(qc->scsicmd);
                /*
-                * SUCCESS here means that the sense code could
+                * SUCCESS here means that the sense code could be
                 * evaluated and should be passed to the upper layers
                 * for correct evaluation.
-                * FAILED means the sense code could not interpreted
+                * FAILED means the sense code could not be interpreted
                 * and the device would need to be reset.
                 * NEEDS_RETRY and ADD_TO_MLQUEUE means that the
                 * command would need to be retried.
@@@ -2098,6 -2157,21 +2106,21 @@@ static inline int ata_eh_worth_retry(st
        return qc->err_mask != AC_ERR_DEV;  /* retry if not dev error */
  }
  
+ /**
+  *      ata_eh_quiet - check if we need to be quiet about a command error
+  *      @qc: qc to check
+  *
+  *      Look at the qc flags anbd its scsi command request flags to determine
+  *      if we need to be quiet about the command failure.
+  */
+ static inline bool ata_eh_quiet(struct ata_queued_cmd *qc)
+ {
+       if (qc->scsicmd &&
+           qc->scsicmd->request->rq_flags & RQF_QUIET)
+               qc->flags |= ATA_QCFLAG_QUIET;
+       return qc->flags & ATA_QCFLAG_QUIET;
+ }
  /**
   *    ata_eh_link_autopsy - analyze error and determine recovery action
   *    @link: host link to perform autopsy on
@@@ -2115,7 -2189,7 +2138,7 @@@ static void ata_eh_link_autopsy(struct 
        struct ata_eh_context *ehc = &link->eh_context;
        struct ata_device *dev;
        unsigned int all_err_mask = 0, eflags = 0;
-       int tag;
+       int tag, nr_failed = 0, nr_quiet = 0;
        u32 serror;
        int rc;
  
                if (qc->err_mask & ~AC_ERR_OTHER)
                        qc->err_mask &= ~AC_ERR_OTHER;
  
-               /* SENSE_VALID trumps dev/unknown error and revalidation */
+               /*
+                * SENSE_VALID trumps dev/unknown error and revalidation. Upper
+                * layers will determine whether the command is worth retrying
+                * based on the sense data and device class/type. Otherwise,
+                * determine directly if the command is worth retrying using its
+                * error mask and flags.
+                */
                if (qc->flags & ATA_QCFLAG_SENSE_VALID)
                        qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_OTHER);
-               /* determine whether the command is worth retrying */
-               if (ata_eh_worth_retry(qc))
+               else if (ata_eh_worth_retry(qc))
                        qc->flags |= ATA_QCFLAG_RETRY;
  
                /* accumulate error info */
                if (qc->flags & ATA_QCFLAG_IO)
                        eflags |= ATA_EFLAG_IS_IO;
                trace_ata_eh_link_autopsy_qc(qc);
+               /* Count quiet errors */
+               if (ata_eh_quiet(qc))
+                       nr_quiet++;
+               nr_failed++;
        }
  
+       /* If all failed commands requested silence, then be quiet */
+       if (nr_quiet == nr_failed)
+               ehc->i.flags |= ATA_EHI_QUIET;
        /* enforce default EH actions */
        if (ap->pflags & ATA_PFLAG_FROZEN ||
            all_err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT))
diff --combined drivers/ata/sata_sil24.c
@@@ -285,13 -285,13 +285,13 @@@ static const struct sil24_cerr_info 
        [PORT_CERR_INCONSISTENT] = { AC_ERR_HSM, ATA_EH_RESET,
                                     "protocol mismatch" },
        [PORT_CERR_DIRECTION]   = { AC_ERR_HSM, ATA_EH_RESET,
 -                                  "data directon mismatch" },
 +                                  "data direction mismatch" },
        [PORT_CERR_UNDERRUN]    = { AC_ERR_HSM, ATA_EH_RESET,
                                    "ran out of SGEs while writing" },
        [PORT_CERR_OVERRUN]     = { AC_ERR_HSM, ATA_EH_RESET,
                                    "ran out of SGEs while reading" },
        [PORT_CERR_PKT_PROT]    = { AC_ERR_HSM, ATA_EH_RESET,
 -                                  "invalid data directon for ATAPI CDB" },
 +                                  "invalid data direction for ATAPI CDB" },
        [PORT_CERR_SGT_BOUNDARY] = { AC_ERR_SYSTEM, ATA_EH_RESET,
                                     "SGT not on qword boundary" },
        [PORT_CERR_SGT_TGTABRT] = { AC_ERR_HOST_BUS, ATA_EH_RESET,
@@@ -849,7 -849,7 +849,7 @@@ static void sil24_qc_prep(struct ata_qu
        struct sil24_sge *sge;
        u16 ctrl = 0;
  
-       cb = &pp->cmd_block[sil24_tag(qc->tag)];
+       cb = &pp->cmd_block[sil24_tag(qc->hw_tag)];
  
        if (!ata_is_atapi(qc->tf.protocol)) {
                prb = &cb->ata.prb;
@@@ -891,7 -891,7 +891,7 @@@ static unsigned int sil24_qc_issue(stru
        struct ata_port *ap = qc->ap;
        struct sil24_port_priv *pp = ap->private_data;
        void __iomem *port = sil24_port_base(ap);
-       unsigned int tag = sil24_tag(qc->tag);
+       unsigned int tag = sil24_tag(qc->hw_tag);
        dma_addr_t paddr;
        void __iomem *activate;
  
  
  static bool sil24_qc_fill_rtf(struct ata_queued_cmd *qc)
  {
-       sil24_read_tf(qc->ap, qc->tag, &qc->result_tf);
+       sil24_read_tf(qc->ap, qc->hw_tag, &qc->result_tf);
        return true;
  }
  
diff --combined include/linux/libata.h
@@@ -125,9 -125,8 +125,8 @@@ enum 
        LIBATA_MAX_PRD          = ATA_MAX_PRD / 2,
        LIBATA_DUMB_MAX_PRD     = ATA_MAX_PRD / 4,      /* Worst case */
        ATA_DEF_QUEUE           = 1,
-       /* tag ATA_MAX_QUEUE - 1 is reserved for internal commands */
        ATA_MAX_QUEUE           = 32,
-       ATA_TAG_INTERNAL        = ATA_MAX_QUEUE - 1,
+       ATA_TAG_INTERNAL        = ATA_MAX_QUEUE,
        ATA_SHORT_PAUSE         = 16,
  
        ATAPI_MAX_DRAIN         = 16 << 10,
@@@ -637,7 -636,8 +636,8 @@@ struct ata_queued_cmd 
        u8                      cdb[ATAPI_CDB_LEN];
  
        unsigned long           flags;          /* ATA_QCFLAG_xxx */
-       unsigned int            tag;
+       unsigned int            tag;            /* libata core tag */
+       unsigned int            hw_tag;         /* driver tag */
        unsigned int            n_elem;
        unsigned int            orig_n_elem;
  
@@@ -849,9 -849,9 +849,9 @@@ struct ata_port 
        unsigned int            udma_mask;
        unsigned int            cbl;    /* cable type; ATA_CBL_xxx */
  
-       struct ata_queued_cmd   qcmd[ATA_MAX_QUEUE];
+       struct ata_queued_cmd   qcmd[ATA_MAX_QUEUE + 1];
        unsigned long           sas_tag_allocated; /* for sas tag allocation only */
-       unsigned int            qc_active;
+       u64                     qc_active;
        int                     nr_active_links; /* #links with active qcs */
        unsigned int            sas_last_tag;   /* track next tag hw expects */
  
@@@ -1133,6 -1133,7 +1133,6 @@@ extern int ata_sas_port_start(struct at
  extern void ata_sas_port_stop(struct ata_port *ap);
  extern int ata_sas_slave_configure(struct scsi_device *, struct ata_port *);
  extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap);
 -extern enum blk_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd);
  extern int sata_scr_valid(struct ata_link *link);
  extern int sata_scr_read(struct ata_link *link, int reg, u32 *val);
  extern int sata_scr_write(struct ata_link *link, int reg, u32 val);
@@@ -1183,7 -1184,7 +1183,7 @@@ extern void ata_id_c_string(const u16 *
  extern unsigned int ata_do_dev_read_id(struct ata_device *dev,
                                        struct ata_taskfile *tf, u16 *id);
  extern void ata_qc_complete(struct ata_queued_cmd *qc);
- extern int ata_qc_complete_multiple(struct ata_port *ap, u32 qc_active);
+ extern int ata_qc_complete_multiple(struct ata_port *ap, u64 qc_active);
  extern void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd);
  extern int ata_std_bios_param(struct scsi_device *sdev,
                              struct block_device *bdev,
@@@ -1358,6 -1359,7 +1358,6 @@@ extern struct device_attribute *ata_com
        .proc_name              = drv_name,                     \
        .slave_configure        = ata_scsi_slave_config,        \
        .slave_destroy          = ata_scsi_slave_destroy,       \
 -      .eh_timed_out           = ata_scsi_timed_out,           \
        .bios_param             = ata_std_bios_param,           \
        .unlock_native_capacity = ata_scsi_unlock_native_capacity, \
        .sdev_attrs             = ata_common_sdev_attrs
@@@ -1483,14 -1485,14 +1483,14 @@@ extern void ata_port_pbar_desc(struct a
                               const char *name);
  #endif
  
- static inline unsigned int ata_tag_valid(unsigned int tag)
+ static inline bool ata_tag_internal(unsigned int tag)
  {
-       return (tag < ATA_MAX_QUEUE) ? 1 : 0;
+       return tag == ATA_TAG_INTERNAL;
  }
  
- static inline unsigned int ata_tag_internal(unsigned int tag)
+ static inline bool ata_tag_valid(unsigned int tag)
  {
-       return tag == ATA_TAG_INTERNAL;
+       return tag < ATA_MAX_QUEUE || ata_tag_internal(tag);
  }
  
  /*
@@@ -1653,7 -1655,7 +1653,7 @@@ static inline void ata_qc_set_polling(s
  static inline struct ata_queued_cmd *__ata_qc_from_tag(struct ata_port *ap,
                                                       unsigned int tag)
  {
-       if (likely(ata_tag_valid(tag)))
+       if (ata_tag_valid(tag))
                return &ap->qcmd[tag];
        return NULL;
  }