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.c79
1 files changed, 35 insertions, 44 deletions
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
index a1259b242b8e..628191bfd990 100644
--- a/drivers/scsi/libata-scsi.c
+++ b/drivers/scsi/libata-scsi.c
@@ -256,7 +256,7 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg)
256 scsi_cmd[14] = args[0]; 256 scsi_cmd[14] = args[0];
257 257
258 /* Good values for timeout and retries? Values below 258 /* Good values for timeout and retries? Values below
259 from scsi_ioctl_send_command() for default case... */ 259 from scsi_ioctl_send_command() for default case... */
260 if (scsi_execute_req(scsidev, scsi_cmd, DMA_NONE, NULL, 0, &sshdr, 260 if (scsi_execute_req(scsidev, scsi_cmd, DMA_NONE, NULL, 0, &sshdr,
261 (10*HZ), 5)) 261 (10*HZ), 5))
262 rc = -EIO; 262 rc = -EIO;
@@ -267,20 +267,8 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg)
267 267
268int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg) 268int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg)
269{ 269{
270 struct ata_port *ap;
271 struct ata_device *dev;
272 int val = -EINVAL, rc = -EINVAL; 270 int val = -EINVAL, rc = -EINVAL;
273 271
274 ap = (struct ata_port *) &scsidev->host->hostdata[0];
275 if (!ap)
276 goto out;
277
278 dev = ata_scsi_find_dev(ap, scsidev);
279 if (!dev) {
280 rc = -ENODEV;
281 goto out;
282 }
283
284 switch (cmd) { 272 switch (cmd) {
285 case ATA_IOC_GET_IO32: 273 case ATA_IOC_GET_IO32:
286 val = 0; 274 val = 0;
@@ -309,7 +297,6 @@ int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg)
309 break; 297 break;
310 } 298 }
311 299
312out:
313 return rc; 300 return rc;
314} 301}
315 302
@@ -414,12 +401,12 @@ int ata_scsi_device_resume(struct scsi_device *sdev)
414 return ata_device_resume(ap, dev); 401 return ata_device_resume(ap, dev);
415} 402}
416 403
417int ata_scsi_device_suspend(struct scsi_device *sdev) 404int ata_scsi_device_suspend(struct scsi_device *sdev, pm_message_t state)
418{ 405{
419 struct ata_port *ap = (struct ata_port *) &sdev->host->hostdata[0]; 406 struct ata_port *ap = (struct ata_port *) &sdev->host->hostdata[0];
420 struct ata_device *dev = &ap->device[sdev->id]; 407 struct ata_device *dev = &ap->device[sdev->id];
421 408
422 return ata_device_suspend(ap, dev); 409 return ata_device_suspend(ap, dev, state);
423} 410}
424 411
425/** 412/**
@@ -438,7 +425,7 @@ int ata_scsi_device_suspend(struct scsi_device *sdev)
438 * LOCKING: 425 * LOCKING:
439 * spin_lock_irqsave(host_set lock) 426 * spin_lock_irqsave(host_set lock)
440 */ 427 */
441void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc, 428void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc,
442 u8 *ascq) 429 u8 *ascq)
443{ 430{
444 int i; 431 int i;
@@ -495,7 +482,7 @@ void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc,
495 /* Look for drv_err */ 482 /* Look for drv_err */
496 for (i = 0; sense_table[i][0] != 0xFF; i++) { 483 for (i = 0; sense_table[i][0] != 0xFF; i++) {
497 /* Look for best matches first */ 484 /* Look for best matches first */
498 if ((sense_table[i][0] & drv_err) == 485 if ((sense_table[i][0] & drv_err) ==
499 sense_table[i][0]) { 486 sense_table[i][0]) {
500 *sk = sense_table[i][1]; 487 *sk = sense_table[i][1];
501 *asc = sense_table[i][2]; 488 *asc = sense_table[i][2];
@@ -518,7 +505,7 @@ void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc,
518 } 505 }
519 } 506 }
520 /* No error? Undecoded? */ 507 /* No error? Undecoded? */
521 printk(KERN_WARNING "ata%u: no sense translation for status: 0x%02x\n", 508 printk(KERN_WARNING "ata%u: no sense translation for status: 0x%02x\n",
522 id, drv_stat); 509 id, drv_stat);
523 510
524 /* We need a sensible error return here, which is tricky, and one 511 /* We need a sensible error return here, which is tricky, and one
@@ -1150,14 +1137,14 @@ static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, const u8 *sc
1150 1137
1151 DPRINTK("block %u track %u cyl %u head %u sect %u\n", 1138 DPRINTK("block %u track %u cyl %u head %u sect %u\n",
1152 (u32)block, track, cyl, head, sect); 1139 (u32)block, track, cyl, head, sect);
1153 1140
1154 /* Check whether the converted CHS can fit. 1141 /* Check whether the converted CHS can fit.
1155 Cylinder: 0-65535 1142 Cylinder: 0-65535
1156 Head: 0-15 1143 Head: 0-15
1157 Sector: 1-255*/ 1144 Sector: 1-255*/
1158 if ((cyl >> 16) || (head >> 4) || (sect >> 8) || (!sect)) 1145 if ((cyl >> 16) || (head >> 4) || (sect >> 8) || (!sect))
1159 goto out_of_range; 1146 goto out_of_range;
1160 1147
1161 tf->command = ATA_CMD_VERIFY; 1148 tf->command = ATA_CMD_VERIFY;
1162 tf->nsect = n_block & 0xff; /* Sector count 0 means 256 sectors */ 1149 tf->nsect = n_block & 0xff; /* Sector count 0 means 256 sectors */
1163 tf->lbal = sect; 1150 tf->lbal = sect;
@@ -1289,7 +1276,7 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm
1289 tf->lbal = block & 0xff; 1276 tf->lbal = block & 0xff;
1290 1277
1291 tf->device |= ATA_LBA; 1278 tf->device |= ATA_LBA;
1292 } else { 1279 } else {
1293 /* CHS */ 1280 /* CHS */
1294 u32 sect, head, cyl, track; 1281 u32 sect, head, cyl, track;
1295 1282
@@ -1309,8 +1296,8 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm
1309 DPRINTK("block %u track %u cyl %u head %u sect %u\n", 1296 DPRINTK("block %u track %u cyl %u head %u sect %u\n",
1310 (u32)block, track, cyl, head, sect); 1297 (u32)block, track, cyl, head, sect);
1311 1298
1312 /* Check whether the converted CHS can fit. 1299 /* Check whether the converted CHS can fit.
1313 Cylinder: 0-65535 1300 Cylinder: 0-65535
1314 Head: 0-15 1301 Head: 0-15
1315 Sector: 1-255*/ 1302 Sector: 1-255*/
1316 if ((cyl >> 16) || (head >> 4) || (sect >> 8) || (!sect)) 1303 if ((cyl >> 16) || (head >> 4) || (sect >> 8) || (!sect))
@@ -1697,7 +1684,7 @@ unsigned int ata_scsiop_inq_83(struct ata_scsi_args *args, u8 *rbuf,
1697 1684
1698 if (buflen > (ATA_SERNO_LEN + num + 3)) { 1685 if (buflen > (ATA_SERNO_LEN + num + 3)) {
1699 /* piv=0, assoc=lu, code_set=ACSII, designator=vendor */ 1686 /* piv=0, assoc=lu, code_set=ACSII, designator=vendor */
1700 rbuf[num + 0] = 2; 1687 rbuf[num + 0] = 2;
1701 rbuf[num + 3] = ATA_SERNO_LEN; 1688 rbuf[num + 3] = ATA_SERNO_LEN;
1702 num += 4; 1689 num += 4;
1703 ata_id_string(args->id, (unsigned char *) rbuf + num, 1690 ata_id_string(args->id, (unsigned char *) rbuf + num,
@@ -1707,8 +1694,8 @@ unsigned int ata_scsiop_inq_83(struct ata_scsi_args *args, u8 *rbuf,
1707 if (buflen > (sat_model_serial_desc_len + num + 3)) { 1694 if (buflen > (sat_model_serial_desc_len + num + 3)) {
1708 /* SAT defined lu model and serial numbers descriptor */ 1695 /* SAT defined lu model and serial numbers descriptor */
1709 /* piv=0, assoc=lu, code_set=ACSII, designator=t10 vendor id */ 1696 /* piv=0, assoc=lu, code_set=ACSII, designator=t10 vendor id */
1710 rbuf[num + 0] = 2; 1697 rbuf[num + 0] = 2;
1711 rbuf[num + 1] = 1; 1698 rbuf[num + 1] = 1;
1712 rbuf[num + 3] = sat_model_serial_desc_len; 1699 rbuf[num + 3] = sat_model_serial_desc_len;
1713 num += 4; 1700 num += 4;
1714 memcpy(rbuf + num, "ATA ", 8); 1701 memcpy(rbuf + num, "ATA ", 8);
@@ -2597,6 +2584,21 @@ static inline void ata_scsi_dump_cdb(struct ata_port *ap,
2597#endif 2584#endif
2598} 2585}
2599 2586
2587static inline void __ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *),
2588 struct ata_port *ap, struct ata_device *dev)
2589{
2590 if (dev->class == ATA_DEV_ATA) {
2591 ata_xlat_func_t xlat_func = ata_get_xlat_func(dev,
2592 cmd->cmnd[0]);
2593
2594 if (xlat_func)
2595 ata_scsi_translate(ap, dev, cmd, done, xlat_func);
2596 else
2597 ata_scsi_simulate(ap, dev, cmd, done);
2598 } else
2599 ata_scsi_translate(ap, dev, cmd, done, atapi_xlat);
2600}
2601
2600/** 2602/**
2601 * ata_scsi_queuecmd - Issue SCSI cdb to libata-managed device 2603 * ata_scsi_queuecmd - Issue SCSI cdb to libata-managed device
2602 * @cmd: SCSI command to be sent 2604 * @cmd: SCSI command to be sent
@@ -2631,24 +2633,13 @@ int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
2631 ata_scsi_dump_cdb(ap, cmd); 2633 ata_scsi_dump_cdb(ap, cmd);
2632 2634
2633 dev = ata_scsi_find_dev(ap, scsidev); 2635 dev = ata_scsi_find_dev(ap, scsidev);
2634 if (unlikely(!dev)) { 2636 if (likely(dev))
2637 __ata_scsi_queuecmd(cmd, done, ap, dev);
2638 else {
2635 cmd->result = (DID_BAD_TARGET << 16); 2639 cmd->result = (DID_BAD_TARGET << 16);
2636 done(cmd); 2640 done(cmd);
2637 goto out_unlock;
2638 } 2641 }
2639 2642
2640 if (dev->class == ATA_DEV_ATA) {
2641 ata_xlat_func_t xlat_func = ata_get_xlat_func(dev,
2642 cmd->cmnd[0]);
2643
2644 if (xlat_func)
2645 ata_scsi_translate(ap, dev, cmd, done, xlat_func);
2646 else
2647 ata_scsi_simulate(ap, dev, cmd, done);
2648 } else
2649 ata_scsi_translate(ap, dev, cmd, done, atapi_xlat);
2650
2651out_unlock:
2652 spin_unlock(&ap->host_set->lock); 2643 spin_unlock(&ap->host_set->lock);
2653 spin_lock(shost->host_lock); 2644 spin_lock(shost->host_lock);
2654 return 0; 2645 return 0;