Skip to content

Commit a0ccd25

Browse files
bzolnieraxboe
authored andcommitted
ata: move ata_eh_analyze_ncq_error() & co. to libata-sata.c
* move ata_eh_analyze_ncq_error() and ata_eh_read_log_10h() to libata-sata.c * add static inline for ata_eh_analyze_ncq_error() for CONFIG_SATA_HOST=n case (link->sactive is non-zero only if NCQ commands are actually queued so empty function body is sufficient) Code size savings on m68k arch using (modified) atari_defconfig: text data bss dec hex filename before: 16164 18 0 16182 3f36 drivers/ata/libata-eh.o after: 15446 18 0 15464 3c68 drivers/ata/libata-eh.o Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent a695de2 commit a0ccd25

3 files changed

Lines changed: 133 additions & 132 deletions

File tree

‎drivers/ata/libata-eh.c‎

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,62 +1351,6 @@ static const char *ata_err_string(unsigned int err_mask)
13511351
return "unknown error";
13521352
}
13531353

1354-
/**
1355-
* ata_eh_read_log_10h - Read log page 10h for NCQ error details
1356-
* @dev: Device to read log page 10h from
1357-
* @tag: Resulting tag of the failed command
1358-
* @tf: Resulting taskfile registers of the failed command
1359-
*
1360-
* Read log page 10h to obtain NCQ error details and clear error
1361-
* condition.
1362-
*
1363-
* LOCKING:
1364-
* Kernel thread context (may sleep).
1365-
*
1366-
* RETURNS:
1367-
* 0 on success, -errno otherwise.
1368-
*/
1369-
static int ata_eh_read_log_10h(struct ata_device *dev,
1370-
int *tag, struct ata_taskfile *tf)
1371-
{
1372-
u8 *buf = dev->link->ap->sector_buf;
1373-
unsigned int err_mask;
1374-
u8 csum;
1375-
int i;
1376-
1377-
err_mask = ata_read_log_page(dev, ATA_LOG_SATA_NCQ, 0, buf, 1);
1378-
if (err_mask)
1379-
return -EIO;
1380-
1381-
csum = 0;
1382-
for (i = 0; i < ATA_SECT_SIZE; i++)
1383-
csum += buf[i];
1384-
if (csum)
1385-
ata_dev_warn(dev, "invalid checksum 0x%x on log page 10h\n",
1386-
csum);
1387-
1388-
if (buf[0] & 0x80)
1389-
return -ENOENT;
1390-
1391-
*tag = buf[0] & 0x1f;
1392-
1393-
tf->command = buf[2];
1394-
tf->feature = buf[3];
1395-
tf->lbal = buf[4];
1396-
tf->lbam = buf[5];
1397-
tf->lbah = buf[6];
1398-
tf->device = buf[7];
1399-
tf->hob_lbal = buf[8];
1400-
tf->hob_lbam = buf[9];
1401-
tf->hob_lbah = buf[10];
1402-
tf->nsect = buf[12];
1403-
tf->hob_nsect = buf[13];
1404-
if (dev->class == ATA_DEV_ZAC && ata_id_has_ncq_autosense(dev->id))
1405-
tf->auxiliary = buf[14] << 16 | buf[15] << 8 | buf[16];
1406-
1407-
return 0;
1408-
}
1409-
14101354
/**
14111355
* atapi_eh_tur - perform ATAPI TEST_UNIT_READY
14121356
* @dev: target ATAPI device
@@ -1590,81 +1534,6 @@ static void ata_eh_analyze_serror(struct ata_link *link)
15901534
ehc->i.action |= action;
15911535
}
15921536

1593-
/**
1594-
* ata_eh_analyze_ncq_error - analyze NCQ error
1595-
* @link: ATA link to analyze NCQ error for
1596-
*
1597-
* Read log page 10h, determine the offending qc and acquire
1598-
* error status TF. For NCQ device errors, all LLDDs have to do
1599-
* is setting AC_ERR_DEV in ehi->err_mask. This function takes
1600-
* care of the rest.
1601-
*
1602-
* LOCKING:
1603-
* Kernel thread context (may sleep).
1604-
*/
1605-
void ata_eh_analyze_ncq_error(struct ata_link *link)
1606-
{
1607-
struct ata_port *ap = link->ap;
1608-
struct ata_eh_context *ehc = &link->eh_context;
1609-
struct ata_device *dev = link->device;
1610-
struct ata_queued_cmd *qc;
1611-
struct ata_taskfile tf;
1612-
int tag, rc;
1613-
1614-
/* if frozen, we can't do much */
1615-
if (ap->pflags & ATA_PFLAG_FROZEN)
1616-
return;
1617-
1618-
/* is it NCQ device error? */
1619-
if (!link->sactive || !(ehc->i.err_mask & AC_ERR_DEV))
1620-
return;
1621-
1622-
/* has LLDD analyzed already? */
1623-
ata_qc_for_each_raw(ap, qc, tag) {
1624-
if (!(qc->flags & ATA_QCFLAG_FAILED))
1625-
continue;
1626-
1627-
if (qc->err_mask)
1628-
return;
1629-
}
1630-
1631-
/* okay, this error is ours */
1632-
memset(&tf, 0, sizeof(tf));
1633-
rc = ata_eh_read_log_10h(dev, &tag, &tf);
1634-
if (rc) {
1635-
ata_link_err(link, "failed to read log page 10h (errno=%d)\n",
1636-
rc);
1637-
return;
1638-
}
1639-
1640-
if (!(link->sactive & (1 << tag))) {
1641-
ata_link_err(link, "log page 10h reported inactive tag %d\n",
1642-
tag);
1643-
return;
1644-
}
1645-
1646-
/* we've got the perpetrator, condemn it */
1647-
qc = __ata_qc_from_tag(ap, tag);
1648-
memcpy(&qc->result_tf, &tf, sizeof(tf));
1649-
qc->result_tf.flags = ATA_TFLAG_ISADDR | ATA_TFLAG_LBA | ATA_TFLAG_LBA48;
1650-
qc->err_mask |= AC_ERR_DEV | AC_ERR_NCQ;
1651-
if (dev->class == ATA_DEV_ZAC &&
1652-
((qc->result_tf.command & ATA_SENSE) || qc->result_tf.auxiliary)) {
1653-
char sense_key, asc, ascq;
1654-
1655-
sense_key = (qc->result_tf.auxiliary >> 16) & 0xff;
1656-
asc = (qc->result_tf.auxiliary >> 8) & 0xff;
1657-
ascq = qc->result_tf.auxiliary & 0xff;
1658-
ata_scsi_set_sense(dev, qc->scsicmd, sense_key, asc, ascq);
1659-
ata_scsi_set_sense_information(dev, qc->scsicmd,
1660-
&qc->result_tf);
1661-
qc->flags |= ATA_QCFLAG_SENSE_VALID;
1662-
}
1663-
1664-
ehc->i.err_mask &= ~AC_ERR_DEV;
1665-
}
1666-
EXPORT_SYMBOL_GPL(ata_eh_analyze_ncq_error);
1667-
16681537
/**
16691538
* ata_eh_analyze_tf - analyze taskfile of a failed qc
16701539
* @qc: qc to analyze

‎drivers/ata/libata-sata.c‎

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,3 +1350,134 @@ int sata_async_notification(struct ata_port *ap)
13501350
}
13511351
}
13521352
EXPORT_SYMBOL_GPL(sata_async_notification);
1353+
1354+
/**
1355+
* ata_eh_read_log_10h - Read log page 10h for NCQ error details
1356+
* @dev: Device to read log page 10h from
1357+
* @tag: Resulting tag of the failed command
1358+
* @tf: Resulting taskfile registers of the failed command
1359+
*
1360+
* Read log page 10h to obtain NCQ error details and clear error
1361+
* condition.
1362+
*
1363+
* LOCKING:
1364+
* Kernel thread context (may sleep).
1365+
*
1366+
* RETURNS:
1367+
* 0 on success, -errno otherwise.
1368+
*/
1369+
static int ata_eh_read_log_10h(struct ata_device *dev,
1370+
int *tag, struct ata_taskfile *tf)
1371+
{
1372+
u8 *buf = dev->link->ap->sector_buf;
1373+
unsigned int err_mask;
1374+
u8 csum;
1375+
int i;
1376+
1377+
err_mask = ata_read_log_page(dev, ATA_LOG_SATA_NCQ, 0, buf, 1);
1378+
if (err_mask)
1379+
return -EIO;
1380+
1381+
csum = 0;
1382+
for (i = 0; i < ATA_SECT_SIZE; i++)
1383+
csum += buf[i];
1384+
if (csum)
1385+
ata_dev_warn(dev, "invalid checksum 0x%x on log page 10h\n",
1386+
csum);
1387+
1388+
if (buf[0] & 0x80)
1389+
return -ENOENT;
1390+
1391+
*tag = buf[0] & 0x1f;
1392+
1393+
tf->command = buf[2];
1394+
tf->feature = buf[3];
1395+
tf->lbal = buf[4];
1396+
tf->lbam = buf[5];
1397+
tf->lbah = buf[6];
1398+
tf->device = buf[7];
1399+
tf->hob_lbal = buf[8];
1400+
tf->hob_lbam = buf[9];
1401+
tf->hob_lbah = buf[10];
1402+
tf->nsect = buf[12];
1403+
tf->hob_nsect = buf[13];
1404+
if (dev->class == ATA_DEV_ZAC && ata_id_has_ncq_autosense(dev->id))
1405+
tf->auxiliary = buf[14] << 16 | buf[15] << 8 | buf[16];
1406+
1407+
return 0;
1408+
}
1409+
1410+
/**
1411+
* ata_eh_analyze_ncq_error - analyze NCQ error
1412+
* @link: ATA link to analyze NCQ error for
1413+
*
1414+
* Read log page 10h, determine the offending qc and acquire
1415+
* error status TF. For NCQ device errors, all LLDDs have to do
1416+
* is setting AC_ERR_DEV in ehi->err_mask. This function takes
1417+
* care of the rest.
1418+
*
1419+
* LOCKING:
1420+
* Kernel thread context (may sleep).
1421+
*/
1422+
void ata_eh_analyze_ncq_error(struct ata_link *link)
1423+
{
1424+
struct ata_port *ap = link->ap;
1425+
struct ata_eh_context *ehc = &link->eh_context;
1426+
struct ata_device *dev = link->device;
1427+
struct ata_queued_cmd *qc;
1428+
struct ata_taskfile tf;
1429+
int tag, rc;
1430+
1431+
/* if frozen, we can't do much */
1432+
if (ap->pflags & ATA_PFLAG_FROZEN)
1433+
return;
1434+
1435+
/* is it NCQ device error? */
1436+
if (!link->sactive || !(ehc->i.err_mask & AC_ERR_DEV))
1437+
return;
1438+
1439+
/* has LLDD analyzed already? */
1440+
ata_qc_for_each_raw(ap, qc, tag) {
1441+
if (!(qc->flags & ATA_QCFLAG_FAILED))
1442+
continue;
1443+
1444+
if (qc->err_mask)
1445+
return;
1446+
}
1447+
1448+
/* okay, this error is ours */
1449+
memset(&tf, 0, sizeof(tf));
1450+
rc = ata_eh_read_log_10h(dev, &tag, &tf);
1451+
if (rc) {
1452+
ata_link_err(link, "failed to read log page 10h (errno=%d)\n",
1453+
rc);
1454+
return;
1455+
}
1456+
1457+
if (!(link->sactive & (1 << tag))) {
1458+
ata_link_err(link, "log page 10h reported inactive tag %d\n",
1459+
tag);
1460+
return;
1461+
}
1462+
1463+
/* we've got the perpetrator, condemn it */
1464+
qc = __ata_qc_from_tag(ap, tag);
1465+
memcpy(&qc->result_tf, &tf, sizeof(tf));
1466+
qc->result_tf.flags = ATA_TFLAG_ISADDR | ATA_TFLAG_LBA | ATA_TFLAG_LBA48;
1467+
qc->err_mask |= AC_ERR_DEV | AC_ERR_NCQ;
1468+
if (dev->class == ATA_DEV_ZAC &&
1469+
((qc->result_tf.command & ATA_SENSE) || qc->result_tf.auxiliary)) {
1470+
char sense_key, asc, ascq;
1471+
1472+
sense_key = (qc->result_tf.auxiliary >> 16) & 0xff;
1473+
asc = (qc->result_tf.auxiliary >> 8) & 0xff;
1474+
ascq = qc->result_tf.auxiliary & 0xff;
1475+
ata_scsi_set_sense(dev, qc->scsicmd, sense_key, asc, ascq);
1476+
ata_scsi_set_sense_information(dev, qc->scsicmd,
1477+
&qc->result_tf);
1478+
qc->flags |= ATA_QCFLAG_SENSE_VALID;
1479+
}
1480+
1481+
ehc->i.err_mask &= ~AC_ERR_DEV;
1482+
}
1483+
EXPORT_SYMBOL_GPL(ata_eh_analyze_ncq_error);

‎include/linux/libata.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,7 @@ extern int sata_link_hardreset(struct ata_link *link,
11811181
bool *online, int (*check_ready)(struct ata_link *));
11821182
extern int sata_link_resume(struct ata_link *link, const unsigned long *params,
11831183
unsigned long deadline);
1184+
extern void ata_eh_analyze_ncq_error(struct ata_link *link);
11841185
#else
11851186
static inline const unsigned long *
11861187
sata_ehc_deb_timing(struct ata_eh_context *ehc)
@@ -1217,6 +1218,7 @@ static inline int sata_link_resume(struct ata_link *link,
12171218
{
12181219
return -EOPNOTSUPP;
12191220
}
1221+
static inline void ata_eh_analyze_ncq_error(struct ata_link *link) { }
12201222
#endif
12211223
extern int sata_link_debounce(struct ata_link *link,
12221224
const unsigned long *params, unsigned long deadline);
@@ -1339,7 +1341,6 @@ extern void ata_eh_thaw_port(struct ata_port *ap);
13391341

13401342
extern void ata_eh_qc_complete(struct ata_queued_cmd *qc);
13411343
extern void ata_eh_qc_retry(struct ata_queued_cmd *qc);
1342-
extern void ata_eh_analyze_ncq_error(struct ata_link *link);
13431344

13441345
extern void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
13451346
ata_reset_fn_t softreset, ata_reset_fn_t hardreset,

0 commit comments

Comments
 (0)