Skip to content

Commit 0bbddb8

Browse files
committed
Merge branch 'for-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/libata
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
2 parents 476d9ff + 88e1009 commit 0bbddb8

File tree

13 files changed

+177
-162
lines changed

13 files changed

+177
-162
lines changed

drivers/ata/acard-ahci.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ static void acard_ahci_qc_prep(struct ata_queued_cmd *qc)
271271
* Fill in command table information. First, the header,
272272
* a SATA Register - Host to Device command FIS.
273273
*/
274-
cmd_tbl = pp->cmd_tbl + qc->tag * AHCI_CMD_TBL_SZ;
274+
cmd_tbl = pp->cmd_tbl + qc->hw_tag * AHCI_CMD_TBL_SZ;
275275

276276
ata_tf_to_fis(&qc->tf, qc->dev->link->pmp, 1, cmd_tbl);
277277
if (is_atapi) {
@@ -294,7 +294,7 @@ static void acard_ahci_qc_prep(struct ata_queued_cmd *qc)
294294
if (is_atapi)
295295
opts |= AHCI_CMD_ATAPI | AHCI_CMD_PREFETCH;
296296

297-
ahci_fill_cmd_slot(pp, qc->tag, opts);
297+
ahci_fill_cmd_slot(pp, qc->hw_tag, opts);
298298
}
299299

300300
static bool acard_ahci_qc_fill_rtf(struct ata_queued_cmd *qc)

drivers/ata/ahci.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ extern struct device_attribute *ahci_sdev_attrs[];
390390
*/
391391
#define AHCI_SHT(drv_name) \
392392
ATA_NCQ_SHT(drv_name), \
393-
.can_queue = AHCI_MAX_CMDS - 1, \
393+
.can_queue = AHCI_MAX_CMDS, \
394394
.sg_tablesize = AHCI_MAX_SG, \
395395
.dma_boundary = AHCI_DMA_BOUNDARY, \
396396
.shost_attrs = ahci_shost_attrs, \

drivers/ata/libahci.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,7 @@ static void ahci_qc_prep(struct ata_queued_cmd *qc)
16491649
* Fill in command table information. First, the header,
16501650
* a SATA Register - Host to Device command FIS.
16511651
*/
1652-
cmd_tbl = pp->cmd_tbl + qc->tag * AHCI_CMD_TBL_SZ;
1652+
cmd_tbl = pp->cmd_tbl + qc->hw_tag * AHCI_CMD_TBL_SZ;
16531653

16541654
ata_tf_to_fis(&qc->tf, qc->dev->link->pmp, 1, cmd_tbl);
16551655
if (is_atapi) {
@@ -1670,7 +1670,7 @@ static void ahci_qc_prep(struct ata_queued_cmd *qc)
16701670
if (is_atapi)
16711671
opts |= AHCI_CMD_ATAPI | AHCI_CMD_PREFETCH;
16721672

1673-
ahci_fill_cmd_slot(pp, qc->tag, opts);
1673+
ahci_fill_cmd_slot(pp, qc->hw_tag, opts);
16741674
}
16751675

16761676
static void ahci_fbs_dec_intr(struct ata_port *ap)
@@ -2006,7 +2006,7 @@ unsigned int ahci_qc_issue(struct ata_queued_cmd *qc)
20062006
pp->active_link = qc->dev->link;
20072007

20082008
if (ata_is_ncq(qc->tf.protocol))
2009-
writel(1 << qc->tag, port_mmio + PORT_SCR_ACT);
2009+
writel(1 << qc->hw_tag, port_mmio + PORT_SCR_ACT);
20102010

20112011
if (pp->fbs_enabled && pp->fbs_last_dev != qc->dev->link->pmp) {
20122012
u32 fbs = readl(port_mmio + PORT_FBS);
@@ -2016,7 +2016,7 @@ unsigned int ahci_qc_issue(struct ata_queued_cmd *qc)
20162016
pp->fbs_last_dev = qc->dev->link->pmp;
20172017
}
20182018

2019-
writel(1 << qc->tag, port_mmio + PORT_CMD_ISSUE);
2019+
writel(1 << qc->hw_tag, port_mmio + PORT_CMD_ISSUE);
20202020

20212021
ahci_sw_activity(qc->dev->link);
20222022

drivers/ata/libata-core.c

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev,
759759
tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
760760
tf->flags |= tf_flags;
761761

762-
if (ata_ncq_enabled(dev) && likely(tag != ATA_TAG_INTERNAL)) {
762+
if (ata_ncq_enabled(dev) && !ata_tag_internal(tag)) {
763763
/* yay, NCQ */
764764
if (!lba_48_ok(block, n_block))
765765
return -ERANGE;
@@ -1570,8 +1570,9 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
15701570
u8 command = tf->command;
15711571
int auto_timeout = 0;
15721572
struct ata_queued_cmd *qc;
1573-
unsigned int tag, preempted_tag;
1574-
u32 preempted_sactive, preempted_qc_active;
1573+
unsigned int preempted_tag;
1574+
u32 preempted_sactive;
1575+
u64 preempted_qc_active;
15751576
int preempted_nr_active_links;
15761577
DECLARE_COMPLETION_ONSTACK(wait);
15771578
unsigned long flags;
@@ -1587,20 +1588,10 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
15871588
}
15881589

15891590
/* initialize internal qc */
1591+
qc = __ata_qc_from_tag(ap, ATA_TAG_INTERNAL);
15901592

1591-
/* XXX: Tag 0 is used for drivers with legacy EH as some
1592-
* drivers choke if any other tag is given. This breaks
1593-
* ata_tag_internal() test for those drivers. Don't use new
1594-
* EH stuff without converting to it.
1595-
*/
1596-
if (ap->ops->error_handler)
1597-
tag = ATA_TAG_INTERNAL;
1598-
else
1599-
tag = 0;
1600-
1601-
qc = __ata_qc_from_tag(ap, tag);
1602-
1603-
qc->tag = tag;
1593+
qc->tag = ATA_TAG_INTERNAL;
1594+
qc->hw_tag = 0;
16041595
qc->scsicmd = NULL;
16051596
qc->ap = ap;
16061597
qc->dev = dev;
@@ -2295,7 +2286,7 @@ static int ata_dev_config_ncq(struct ata_device *dev,
22952286
return 0;
22962287
}
22972288
if (ap->flags & ATA_FLAG_NCQ) {
2298-
hdepth = min(ap->scsi_host->can_queue, ATA_MAX_QUEUE - 1);
2289+
hdepth = min(ap->scsi_host->can_queue, ATA_MAX_QUEUE);
22992290
dev->flags |= ATA_DFLAG_NCQ;
23002291
}
23012292

@@ -3573,9 +3564,11 @@ static int ata_dev_set_mode(struct ata_device *dev)
35733564
DPRINTK("xfer_shift=%u, xfer_mode=0x%x\n",
35743565
dev->xfer_shift, (int)dev->xfer_mode);
35753566

3576-
ata_dev_info(dev, "configured for %s%s\n",
3577-
ata_mode_string(ata_xfer_mode2mask(dev->xfer_mode)),
3578-
dev_err_whine);
3567+
if (!(ehc->i.flags & ATA_EHI_QUIET) ||
3568+
ehc->i.flags & ATA_EHI_DID_HARDRESET)
3569+
ata_dev_info(dev, "configured for %s%s\n",
3570+
ata_mode_string(ata_xfer_mode2mask(dev->xfer_mode)),
3571+
dev_err_whine);
35793572

35803573
return 0;
35813574

@@ -5133,7 +5126,7 @@ struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag)
51335126
}
51345127

51355128
qc = __ata_qc_from_tag(ap, tag);
5136-
qc->tag = tag;
5129+
qc->tag = qc->hw_tag = tag;
51375130
qc->scsicmd = NULL;
51385131
qc->ap = ap;
51395132
qc->dev = dev;
@@ -5163,7 +5156,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
51635156

51645157
qc->flags = 0;
51655158
tag = qc->tag;
5166-
if (likely(ata_tag_valid(tag))) {
5159+
if (ata_tag_valid(tag)) {
51675160
qc->tag = ATA_TAG_POISON;
51685161
if (ap->flags & ATA_FLAG_SAS_HOST)
51695162
ata_sas_free_tag(tag, ap);
@@ -5185,7 +5178,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
51855178

51865179
/* command should be marked inactive atomically with qc completion */
51875180
if (ata_is_ncq(qc->tf.protocol)) {
5188-
link->sactive &= ~(1 << qc->tag);
5181+
link->sactive &= ~(1 << qc->hw_tag);
51895182
if (!link->sactive)
51905183
ap->nr_active_links--;
51915184
} else {
@@ -5203,7 +5196,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
52035196
* is called. (when rc != 0 and atapi request sense is needed)
52045197
*/
52055198
qc->flags &= ~ATA_QCFLAG_ACTIVE;
5206-
ap->qc_active &= ~(1 << qc->tag);
5199+
ap->qc_active &= ~(1ULL << qc->tag);
52075200

52085201
/* call completion callback */
52095202
qc->complete_fn(qc);
@@ -5360,29 +5353,29 @@ void ata_qc_complete(struct ata_queued_cmd *qc)
53605353
* RETURNS:
53615354
* Number of completed commands on success, -errno otherwise.
53625355
*/
5363-
int ata_qc_complete_multiple(struct ata_port *ap, u32 qc_active)
5356+
int ata_qc_complete_multiple(struct ata_port *ap, u64 qc_active)
53645357
{
53655358
int nr_done = 0;
5366-
u32 done_mask;
5359+
u64 done_mask;
53675360

53685361
done_mask = ap->qc_active ^ qc_active;
53695362

53705363
if (unlikely(done_mask & qc_active)) {
5371-
ata_port_err(ap, "illegal qc_active transition (%08x->%08x)\n",
5364+
ata_port_err(ap, "illegal qc_active transition (%08llx->%08llx)\n",
53725365
ap->qc_active, qc_active);
53735366
return -EINVAL;
53745367
}
53755368

53765369
while (done_mask) {
53775370
struct ata_queued_cmd *qc;
5378-
unsigned int tag = __ffs(done_mask);
5371+
unsigned int tag = __ffs64(done_mask);
53795372

53805373
qc = ata_qc_from_tag(ap, tag);
53815374
if (qc) {
53825375
ata_qc_complete(qc);
53835376
nr_done++;
53845377
}
5385-
done_mask &= ~(1 << tag);
5378+
done_mask &= ~(1ULL << tag);
53865379
}
53875380

53885381
return nr_done;
@@ -5413,11 +5406,11 @@ void ata_qc_issue(struct ata_queued_cmd *qc)
54135406
WARN_ON_ONCE(ap->ops->error_handler && ata_tag_valid(link->active_tag));
54145407

54155408
if (ata_is_ncq(prot)) {
5416-
WARN_ON_ONCE(link->sactive & (1 << qc->tag));
5409+
WARN_ON_ONCE(link->sactive & (1 << qc->hw_tag));
54175410

54185411
if (!link->sactive)
54195412
ap->nr_active_links++;
5420-
link->sactive |= 1 << qc->tag;
5413+
link->sactive |= 1 << qc->hw_tag;
54215414
} else {
54225415
WARN_ON_ONCE(link->sactive);
54235416

@@ -5426,7 +5419,7 @@ void ata_qc_issue(struct ata_queued_cmd *qc)
54265419
}
54275420

54285421
qc->flags |= ATA_QCFLAG_ACTIVE;
5429-
ap->qc_active |= 1 << qc->tag;
5422+
ap->qc_active |= 1ULL << qc->tag;
54305423

54315424
/*
54325425
* We guarantee to LLDs that they will have at least one
@@ -6425,7 +6418,7 @@ void ata_host_init(struct ata_host *host, struct device *dev,
64256418
{
64266419
spin_lock_init(&host->lock);
64276420
mutex_init(&host->eh_mutex);
6428-
host->n_tags = ATA_MAX_QUEUE - 1;
6421+
host->n_tags = ATA_MAX_QUEUE;
64296422
host->dev = dev;
64306423
host->ops = ops;
64316424
}
@@ -6507,7 +6500,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
65076500
{
65086501
int i, rc;
65096502

6510-
host->n_tags = clamp(sht->can_queue, 1, ATA_MAX_QUEUE - 1);
6503+
host->n_tags = clamp(sht->can_queue, 1, ATA_MAX_QUEUE);
65116504

65126505
/* host must have been started */
65136506
if (!(host->flags & ATA_HOST_STARTED)) {

drivers/ata/libata-eh.c

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -822,9 +822,12 @@ static int ata_eh_nr_in_flight(struct ata_port *ap)
822822
int nr = 0;
823823

824824
/* count only non-internal commands */
825-
for (tag = 0; tag < ATA_MAX_QUEUE - 1; tag++)
825+
for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
826+
if (ata_tag_internal(tag))
827+
continue;
826828
if (ata_qc_from_tag(ap, tag))
827829
nr++;
830+
}
828831

829832
return nr;
830833
}
@@ -849,7 +852,7 @@ void ata_eh_fastdrain_timerfn(struct timer_list *t)
849852
/* No progress during the last interval, tag all
850853
* in-flight qcs as timed out and freeze the port.
851854
*/
852-
for (tag = 0; tag < ATA_MAX_QUEUE - 1; tag++) {
855+
for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
853856
struct ata_queued_cmd *qc = ata_qc_from_tag(ap, tag);
854857
if (qc)
855858
qc->err_mask |= AC_ERR_TIMEOUT;
@@ -1003,7 +1006,8 @@ static int ata_do_link_abort(struct ata_port *ap, struct ata_link *link)
10031006
/* we're gonna abort all commands, no need for fast drain */
10041007
ata_eh_set_pending(ap, 0);
10051008

1006-
for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
1009+
/* include internal tag in iteration */
1010+
for (tag = 0; tag <= ATA_MAX_QUEUE; tag++) {
10071011
struct ata_queued_cmd *qc = ata_qc_from_tag(ap, tag);
10081012

10091013
if (qc && (!link || qc->dev->link == link)) {
@@ -1432,6 +1436,10 @@ static const char *ata_err_string(unsigned int err_mask)
14321436
return "invalid argument";
14331437
if (err_mask & AC_ERR_DEV)
14341438
return "device error";
1439+
if (err_mask & AC_ERR_NCQ)
1440+
return "NCQ error";
1441+
if (err_mask & AC_ERR_NODEV_HINT)
1442+
return "Polling detection error";
14351443
return "unknown error";
14361444
}
14371445

@@ -1815,10 +1823,10 @@ static unsigned int ata_eh_analyze_tf(struct ata_queued_cmd *qc,
18151823
if (qc->flags & ATA_QCFLAG_SENSE_VALID) {
18161824
int ret = scsi_check_sense(qc->scsicmd);
18171825
/*
1818-
* SUCCESS here means that the sense code could
1826+
* SUCCESS here means that the sense code could be
18191827
* evaluated and should be passed to the upper layers
18201828
* for correct evaluation.
1821-
* FAILED means the sense code could not interpreted
1829+
* FAILED means the sense code could not be interpreted
18221830
* and the device would need to be reset.
18231831
* NEEDS_RETRY and ADD_TO_MLQUEUE means that the
18241832
* command would need to be retried.
@@ -2098,6 +2106,21 @@ static inline int ata_eh_worth_retry(struct ata_queued_cmd *qc)
20982106
return qc->err_mask != AC_ERR_DEV; /* retry if not dev error */
20992107
}
21002108

2109+
/**
2110+
* ata_eh_quiet - check if we need to be quiet about a command error
2111+
* @qc: qc to check
2112+
*
2113+
* Look at the qc flags anbd its scsi command request flags to determine
2114+
* if we need to be quiet about the command failure.
2115+
*/
2116+
static inline bool ata_eh_quiet(struct ata_queued_cmd *qc)
2117+
{
2118+
if (qc->scsicmd &&
2119+
qc->scsicmd->request->rq_flags & RQF_QUIET)
2120+
qc->flags |= ATA_QCFLAG_QUIET;
2121+
return qc->flags & ATA_QCFLAG_QUIET;
2122+
}
2123+
21012124
/**
21022125
* ata_eh_link_autopsy - analyze error and determine recovery action
21032126
* @link: host link to perform autopsy on
@@ -2115,7 +2138,7 @@ static void ata_eh_link_autopsy(struct ata_link *link)
21152138
struct ata_eh_context *ehc = &link->eh_context;
21162139
struct ata_device *dev;
21172140
unsigned int all_err_mask = 0, eflags = 0;
2118-
int tag;
2141+
int tag, nr_failed = 0, nr_quiet = 0;
21192142
u32 serror;
21202143
int rc;
21212144

@@ -2167,12 +2190,16 @@ static void ata_eh_link_autopsy(struct ata_link *link)
21672190
if (qc->err_mask & ~AC_ERR_OTHER)
21682191
qc->err_mask &= ~AC_ERR_OTHER;
21692192

2170-
/* SENSE_VALID trumps dev/unknown error and revalidation */
2193+
/*
2194+
* SENSE_VALID trumps dev/unknown error and revalidation. Upper
2195+
* layers will determine whether the command is worth retrying
2196+
* based on the sense data and device class/type. Otherwise,
2197+
* determine directly if the command is worth retrying using its
2198+
* error mask and flags.
2199+
*/
21712200
if (qc->flags & ATA_QCFLAG_SENSE_VALID)
21722201
qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_OTHER);
2173-
2174-
/* determine whether the command is worth retrying */
2175-
if (ata_eh_worth_retry(qc))
2202+
else if (ata_eh_worth_retry(qc))
21762203
qc->flags |= ATA_QCFLAG_RETRY;
21772204

21782205
/* accumulate error info */
@@ -2181,8 +2208,17 @@ static void ata_eh_link_autopsy(struct ata_link *link)
21812208
if (qc->flags & ATA_QCFLAG_IO)
21822209
eflags |= ATA_EFLAG_IS_IO;
21832210
trace_ata_eh_link_autopsy_qc(qc);
2211+
2212+
/* Count quiet errors */
2213+
if (ata_eh_quiet(qc))
2214+
nr_quiet++;
2215+
nr_failed++;
21842216
}
21852217

2218+
/* If all failed commands requested silence, then be quiet */
2219+
if (nr_quiet == nr_failed)
2220+
ehc->i.flags |= ATA_EHI_QUIET;
2221+
21862222
/* enforce default EH actions */
21872223
if (ap->pflags & ATA_PFLAG_FROZEN ||
21882224
all_err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT))

0 commit comments

Comments
 (0)