aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/libata-scsi.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/libata-scsi.c')
-rw-r--r--drivers/scsi/libata-scsi.c72
1 files changed, 55 insertions, 17 deletions
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
index 2282c04fee46..cfbceb504718 100644
--- a/drivers/scsi/libata-scsi.c
+++ b/drivers/scsi/libata-scsi.c
@@ -396,6 +396,22 @@ void ata_dump_status(unsigned id, struct ata_taskfile *tf)
396 } 396 }
397} 397}
398 398
399int ata_scsi_device_resume(struct scsi_device *sdev)
400{
401 struct ata_port *ap = (struct ata_port *) &sdev->host->hostdata[0];
402 struct ata_device *dev = &ap->device[sdev->id];
403
404 return ata_device_resume(ap, dev);
405}
406
407int ata_scsi_device_suspend(struct scsi_device *sdev)
408{
409 struct ata_port *ap = (struct ata_port *) &sdev->host->hostdata[0];
410 struct ata_device *dev = &ap->device[sdev->id];
411
412 return ata_device_suspend(ap, dev);
413}
414
399/** 415/**
400 * ata_to_sense_error - convert ATA error to SCSI error 416 * ata_to_sense_error - convert ATA error to SCSI error
401 * @id: ATA device number 417 * @id: ATA device number
@@ -418,7 +434,7 @@ void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc,
418 int i; 434 int i;
419 435
420 /* Based on the 3ware driver translation table */ 436 /* Based on the 3ware driver translation table */
421 static unsigned char sense_table[][4] = { 437 static const unsigned char sense_table[][4] = {
422 /* BBD|ECC|ID|MAR */ 438 /* BBD|ECC|ID|MAR */
423 {0xd1, ABORTED_COMMAND, 0x00, 0x00}, // Device busy Aborted command 439 {0xd1, ABORTED_COMMAND, 0x00, 0x00}, // Device busy Aborted command
424 /* BBD|ECC|ID */ 440 /* BBD|ECC|ID */
@@ -449,7 +465,7 @@ void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc,
449 {0x80, MEDIUM_ERROR, 0x11, 0x04}, // Block marked bad Medium error, unrecovered read error 465 {0x80, MEDIUM_ERROR, 0x11, 0x04}, // Block marked bad Medium error, unrecovered read error
450 {0xFF, 0xFF, 0xFF, 0xFF}, // END mark 466 {0xFF, 0xFF, 0xFF, 0xFF}, // END mark
451 }; 467 };
452 static unsigned char stat_table[][4] = { 468 static const unsigned char stat_table[][4] = {
453 /* Must be first because BUSY means no other bits valid */ 469 /* Must be first because BUSY means no other bits valid */
454 {0x80, ABORTED_COMMAND, 0x47, 0x00}, // Busy, fake parity for now 470 {0x80, ABORTED_COMMAND, 0x47, 0x00}, // Busy, fake parity for now
455 {0x20, HARDWARE_ERROR, 0x00, 0x00}, // Device fault 471 {0x20, HARDWARE_ERROR, 0x00, 0x00}, // Device fault
@@ -1080,11 +1096,13 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm
1080 scsicmd[0] == WRITE_16) 1096 scsicmd[0] == WRITE_16)
1081 tf->flags |= ATA_TFLAG_WRITE; 1097 tf->flags |= ATA_TFLAG_WRITE;
1082 1098
1083 /* Calculate the SCSI LBA and transfer length. */ 1099 /* Calculate the SCSI LBA, transfer length and FUA. */
1084 switch (scsicmd[0]) { 1100 switch (scsicmd[0]) {
1085 case READ_10: 1101 case READ_10:
1086 case WRITE_10: 1102 case WRITE_10:
1087 scsi_10_lba_len(scsicmd, &block, &n_block); 1103 scsi_10_lba_len(scsicmd, &block, &n_block);
1104 if (unlikely(scsicmd[1] & (1 << 3)))
1105 tf->flags |= ATA_TFLAG_FUA;
1088 break; 1106 break;
1089 case READ_6: 1107 case READ_6:
1090 case WRITE_6: 1108 case WRITE_6:
@@ -1099,6 +1117,8 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm
1099 case READ_16: 1117 case READ_16:
1100 case WRITE_16: 1118 case WRITE_16:
1101 scsi_16_lba_len(scsicmd, &block, &n_block); 1119 scsi_16_lba_len(scsicmd, &block, &n_block);
1120 if (unlikely(scsicmd[1] & (1 << 3)))
1121 tf->flags |= ATA_TFLAG_FUA;
1102 break; 1122 break;
1103 default: 1123 default:
1104 DPRINTK("no-byte command\n"); 1124 DPRINTK("no-byte command\n");
@@ -1142,7 +1162,8 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm
1142 tf->device |= (block >> 24) & 0xf; 1162 tf->device |= (block >> 24) & 0xf;
1143 } 1163 }
1144 1164
1145 ata_rwcmd_protocol(qc); 1165 if (unlikely(ata_rwcmd_protocol(qc) < 0))
1166 goto invalid_fld;
1146 1167
1147 qc->nsect = n_block; 1168 qc->nsect = n_block;
1148 tf->nsect = n_block & 0xff; 1169 tf->nsect = n_block & 0xff;
@@ -1160,7 +1181,8 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm
1160 if ((block >> 28) || (n_block > 256)) 1181 if ((block >> 28) || (n_block > 256))
1161 goto out_of_range; 1182 goto out_of_range;
1162 1183
1163 ata_rwcmd_protocol(qc); 1184 if (unlikely(ata_rwcmd_protocol(qc) < 0))
1185 goto invalid_fld;
1164 1186
1165 /* Convert LBA to CHS */ 1187 /* Convert LBA to CHS */
1166 track = (u32)block / dev->sectors; 1188 track = (u32)block / dev->sectors;
@@ -1203,12 +1225,11 @@ nothing_to_do:
1203 return 1; 1225 return 1;
1204} 1226}
1205 1227
1206static int ata_scsi_qc_complete(struct ata_queued_cmd *qc, 1228static int ata_scsi_qc_complete(struct ata_queued_cmd *qc)
1207 unsigned int err_mask)
1208{ 1229{
1209 struct scsi_cmnd *cmd = qc->scsicmd; 1230 struct scsi_cmnd *cmd = qc->scsicmd;
1210 u8 *cdb = cmd->cmnd; 1231 u8 *cdb = cmd->cmnd;
1211 int need_sense = (err_mask != 0); 1232 int need_sense = (qc->err_mask != 0);
1212 1233
1213 /* For ATA pass thru (SAT) commands, generate a sense block if 1234 /* For ATA pass thru (SAT) commands, generate a sense block if
1214 * user mandated it or if there's an error. Note that if we 1235 * user mandated it or if there's an error. Note that if we
@@ -1532,7 +1553,7 @@ unsigned int ata_scsiop_inq_80(struct ata_scsi_args *args, u8 *rbuf,
1532 return 0; 1553 return 0;
1533} 1554}
1534 1555
1535static const char *inq_83_str = "Linux ATA-SCSI simulator"; 1556static const char * const inq_83_str = "Linux ATA-SCSI simulator";
1536 1557
1537/** 1558/**
1538 * ata_scsiop_inq_83 - Simulate INQUIRY EVPD page 83, device identity 1559 * ata_scsiop_inq_83 - Simulate INQUIRY EVPD page 83, device identity
@@ -1696,6 +1717,7 @@ static unsigned int ata_msense_rw_recovery(u8 **ptr_io, const u8 *last)
1696unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf, 1717unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf,
1697 unsigned int buflen) 1718 unsigned int buflen)
1698{ 1719{
1720 struct ata_device *dev = args->dev;
1699 u8 *scsicmd = args->cmd->cmnd, *p, *last; 1721 u8 *scsicmd = args->cmd->cmnd, *p, *last;
1700 const u8 sat_blk_desc[] = { 1722 const u8 sat_blk_desc[] = {
1701 0, 0, 0, 0, /* number of blocks: sat unspecified */ 1723 0, 0, 0, 0, /* number of blocks: sat unspecified */
@@ -1704,6 +1726,7 @@ unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf,
1704 }; 1726 };
1705 u8 pg, spg; 1727 u8 pg, spg;
1706 unsigned int ebd, page_control, six_byte, output_len, alloc_len, minlen; 1728 unsigned int ebd, page_control, six_byte, output_len, alloc_len, minlen;
1729 u8 dpofua;
1707 1730
1708 VPRINTK("ENTER\n"); 1731 VPRINTK("ENTER\n");
1709 1732
@@ -1772,9 +1795,17 @@ unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf,
1772 1795
1773 if (minlen < 1) 1796 if (minlen < 1)
1774 return 0; 1797 return 0;
1798
1799 dpofua = 0;
1800 if (ata_id_has_fua(args->id) && dev->flags & ATA_DFLAG_LBA48 &&
1801 (!(dev->flags & ATA_DFLAG_PIO) || dev->multi_count))
1802 dpofua = 1 << 4;
1803
1775 if (six_byte) { 1804 if (six_byte) {
1776 output_len--; 1805 output_len--;
1777 rbuf[0] = output_len; 1806 rbuf[0] = output_len;
1807 if (minlen > 2)
1808 rbuf[2] |= dpofua;
1778 if (ebd) { 1809 if (ebd) {
1779 if (minlen > 3) 1810 if (minlen > 3)
1780 rbuf[3] = sizeof(sat_blk_desc); 1811 rbuf[3] = sizeof(sat_blk_desc);
@@ -1787,6 +1818,8 @@ unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf,
1787 rbuf[0] = output_len >> 8; 1818 rbuf[0] = output_len >> 8;
1788 if (minlen > 1) 1819 if (minlen > 1)
1789 rbuf[1] = output_len; 1820 rbuf[1] = output_len;
1821 if (minlen > 3)
1822 rbuf[3] |= dpofua;
1790 if (ebd) { 1823 if (ebd) {
1791 if (minlen > 7) 1824 if (minlen > 7)
1792 rbuf[7] = sizeof(sat_blk_desc); 1825 rbuf[7] = sizeof(sat_blk_desc);
@@ -1955,9 +1988,9 @@ void ata_scsi_badcmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *), u8
1955 done(cmd); 1988 done(cmd);
1956} 1989}
1957 1990
1958static int atapi_sense_complete(struct ata_queued_cmd *qc,unsigned int err_mask) 1991static int atapi_sense_complete(struct ata_queued_cmd *qc)
1959{ 1992{
1960 if (err_mask && ((err_mask & AC_ERR_DEV) == 0)) 1993 if (qc->err_mask && ((qc->err_mask & AC_ERR_DEV) == 0))
1961 /* FIXME: not quite right; we don't want the 1994 /* FIXME: not quite right; we don't want the
1962 * translation of taskfile registers into 1995 * translation of taskfile registers into
1963 * a sense descriptors, since that's only 1996 * a sense descriptors, since that's only
@@ -2015,15 +2048,18 @@ static void atapi_request_sense(struct ata_queued_cmd *qc)
2015 2048
2016 qc->complete_fn = atapi_sense_complete; 2049 qc->complete_fn = atapi_sense_complete;
2017 2050
2018 if (ata_qc_issue(qc)) 2051 if (ata_qc_issue(qc)) {
2019 ata_qc_complete(qc, AC_ERR_OTHER); 2052 qc->err_mask |= AC_ERR_OTHER;
2053 ata_qc_complete(qc);
2054 }
2020 2055
2021 DPRINTK("EXIT\n"); 2056 DPRINTK("EXIT\n");
2022} 2057}
2023 2058
2024static int atapi_qc_complete(struct ata_queued_cmd *qc, unsigned int err_mask) 2059static int atapi_qc_complete(struct ata_queued_cmd *qc)
2025{ 2060{
2026 struct scsi_cmnd *cmd = qc->scsicmd; 2061 struct scsi_cmnd *cmd = qc->scsicmd;
2062 unsigned int err_mask = qc->err_mask;
2027 2063
2028 VPRINTK("ENTER, err_mask 0x%X\n", err_mask); 2064 VPRINTK("ENTER, err_mask 0x%X\n", err_mask);
2029 2065
@@ -2444,7 +2480,7 @@ int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
2444 if (xlat_func) 2480 if (xlat_func)
2445 ata_scsi_translate(ap, dev, cmd, done, xlat_func); 2481 ata_scsi_translate(ap, dev, cmd, done, xlat_func);
2446 else 2482 else
2447 ata_scsi_simulate(dev->id, cmd, done); 2483 ata_scsi_simulate(ap, dev, cmd, done);
2448 } else 2484 } else
2449 ata_scsi_translate(ap, dev, cmd, done, atapi_xlat); 2485 ata_scsi_translate(ap, dev, cmd, done, atapi_xlat);
2450 2486
@@ -2467,14 +2503,16 @@ out_unlock:
2467 * spin_lock_irqsave(host_set lock) 2503 * spin_lock_irqsave(host_set lock)
2468 */ 2504 */
2469 2505
2470void ata_scsi_simulate(u16 *id, 2506void ata_scsi_simulate(struct ata_port *ap, struct ata_device *dev,
2471 struct scsi_cmnd *cmd, 2507 struct scsi_cmnd *cmd,
2472 void (*done)(struct scsi_cmnd *)) 2508 void (*done)(struct scsi_cmnd *))
2473{ 2509{
2474 struct ata_scsi_args args; 2510 struct ata_scsi_args args;
2475 const u8 *scsicmd = cmd->cmnd; 2511 const u8 *scsicmd = cmd->cmnd;
2476 2512
2477 args.id = id; 2513 args.ap = ap;
2514 args.dev = dev;
2515 args.id = dev->id;
2478 args.cmd = cmd; 2516 args.cmd = cmd;
2479 args.done = done; 2517 args.done = done;
2480 2518