diff options
Diffstat (limited to 'drivers/ata/libata-scsi.c')
-rw-r--r-- | drivers/ata/libata-scsi.c | 328 |
1 files changed, 112 insertions, 216 deletions
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 47ea111d5ac..8eaace94d96 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c | |||
@@ -671,7 +671,7 @@ void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc, | |||
671 | } | 671 | } |
672 | 672 | ||
673 | /* | 673 | /* |
674 | * ata_gen_ata_desc_sense - Generate check condition sense block. | 674 | * ata_gen_passthru_sense - Generate check condition sense block. |
675 | * @qc: Command that completed. | 675 | * @qc: Command that completed. |
676 | * | 676 | * |
677 | * This function is specific to the ATA descriptor format sense | 677 | * This function is specific to the ATA descriptor format sense |
@@ -681,9 +681,9 @@ void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc, | |||
681 | * block. Clear sense key, ASC & ASCQ if there is no error. | 681 | * block. Clear sense key, ASC & ASCQ if there is no error. |
682 | * | 682 | * |
683 | * LOCKING: | 683 | * LOCKING: |
684 | * spin_lock_irqsave(host lock) | 684 | * None. |
685 | */ | 685 | */ |
686 | void ata_gen_ata_desc_sense(struct ata_queued_cmd *qc) | 686 | static void ata_gen_passthru_sense(struct ata_queued_cmd *qc) |
687 | { | 687 | { |
688 | struct scsi_cmnd *cmd = qc->scsicmd; | 688 | struct scsi_cmnd *cmd = qc->scsicmd; |
689 | struct ata_taskfile *tf = &qc->result_tf; | 689 | struct ata_taskfile *tf = &qc->result_tf; |
@@ -713,12 +713,9 @@ void ata_gen_ata_desc_sense(struct ata_queued_cmd *qc) | |||
713 | 713 | ||
714 | desc[0] = 0x09; | 714 | desc[0] = 0x09; |
715 | 715 | ||
716 | /* | 716 | /* set length of additional sense data */ |
717 | * Set length of additional sense data. | 717 | sb[7] = 14; |
718 | * Since we only populate descriptor 0, the total | 718 | desc[1] = 12; |
719 | * length is the same (fixed) length as descriptor 0. | ||
720 | */ | ||
721 | desc[1] = sb[7] = 14; | ||
722 | 719 | ||
723 | /* | 720 | /* |
724 | * Copy registers into sense buffer. | 721 | * Copy registers into sense buffer. |
@@ -746,56 +743,56 @@ void ata_gen_ata_desc_sense(struct ata_queued_cmd *qc) | |||
746 | } | 743 | } |
747 | 744 | ||
748 | /** | 745 | /** |
749 | * ata_gen_fixed_sense - generate a SCSI fixed sense block | 746 | * ata_gen_ata_sense - generate a SCSI fixed sense block |
750 | * @qc: Command that we are erroring out | 747 | * @qc: Command that we are erroring out |
751 | * | 748 | * |
752 | * Leverage ata_to_sense_error() to give us the codes. Fit our | 749 | * Generate sense block for a failed ATA command @qc. Descriptor |
753 | * LBA in here if there's room. | 750 | * format is used to accomodate LBA48 block address. |
754 | * | 751 | * |
755 | * LOCKING: | 752 | * LOCKING: |
756 | * inherited from caller | 753 | * None. |
757 | */ | 754 | */ |
758 | void ata_gen_fixed_sense(struct ata_queued_cmd *qc) | 755 | static void ata_gen_ata_sense(struct ata_queued_cmd *qc) |
759 | { | 756 | { |
757 | struct ata_device *dev = qc->dev; | ||
760 | struct scsi_cmnd *cmd = qc->scsicmd; | 758 | struct scsi_cmnd *cmd = qc->scsicmd; |
761 | struct ata_taskfile *tf = &qc->result_tf; | 759 | struct ata_taskfile *tf = &qc->result_tf; |
762 | unsigned char *sb = cmd->sense_buffer; | 760 | unsigned char *sb = cmd->sense_buffer; |
761 | unsigned char *desc = sb + 8; | ||
763 | int verbose = qc->ap->ops->error_handler == NULL; | 762 | int verbose = qc->ap->ops->error_handler == NULL; |
763 | u64 block; | ||
764 | 764 | ||
765 | memset(sb, 0, SCSI_SENSE_BUFFERSIZE); | 765 | memset(sb, 0, SCSI_SENSE_BUFFERSIZE); |
766 | 766 | ||
767 | cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; | 767 | cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; |
768 | 768 | ||
769 | /* | 769 | /* sense data is current and format is descriptor */ |
770 | * Use ata_to_sense_error() to map status register bits | 770 | sb[0] = 0x72; |
771 | |||
772 | /* Use ata_to_sense_error() to map status register bits | ||
771 | * onto sense key, asc & ascq. | 773 | * onto sense key, asc & ascq. |
772 | */ | 774 | */ |
773 | if (qc->err_mask || | 775 | if (qc->err_mask || |
774 | tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) { | 776 | tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) { |
775 | ata_to_sense_error(qc->ap->id, tf->command, tf->feature, | 777 | ata_to_sense_error(qc->ap->id, tf->command, tf->feature, |
776 | &sb[2], &sb[12], &sb[13], verbose); | 778 | &sb[1], &sb[2], &sb[3], verbose); |
777 | sb[2] &= 0x0f; | 779 | sb[1] &= 0x0f; |
778 | } | 780 | } |
779 | 781 | ||
780 | sb[0] = 0x70; | 782 | block = ata_tf_read_block(&qc->result_tf, dev); |
781 | sb[7] = 0x0a; | ||
782 | |||
783 | if (tf->flags & ATA_TFLAG_LBA48) { | ||
784 | /* TODO: find solution for LBA48 descriptors */ | ||
785 | } | ||
786 | 783 | ||
787 | else if (tf->flags & ATA_TFLAG_LBA) { | 784 | /* information sense data descriptor */ |
788 | /* A small (28b) LBA will fit in the 32b info field */ | 785 | sb[7] = 12; |
789 | sb[0] |= 0x80; /* set valid bit */ | 786 | desc[0] = 0x00; |
790 | sb[3] = tf->device & 0x0f; | 787 | desc[1] = 10; |
791 | sb[4] = tf->lbah; | ||
792 | sb[5] = tf->lbam; | ||
793 | sb[6] = tf->lbal; | ||
794 | } | ||
795 | 788 | ||
796 | else { | 789 | desc[2] |= 0x80; /* valid */ |
797 | /* TODO: C/H/S */ | 790 | desc[6] = block >> 40; |
798 | } | 791 | desc[7] = block >> 32; |
792 | desc[8] = block >> 24; | ||
793 | desc[9] = block >> 16; | ||
794 | desc[10] = block >> 8; | ||
795 | desc[11] = block; | ||
799 | } | 796 | } |
800 | 797 | ||
801 | static void ata_scsi_sdev_config(struct scsi_device *sdev) | 798 | static void ata_scsi_sdev_config(struct scsi_device *sdev) |
@@ -807,23 +804,10 @@ static void ata_scsi_sdev_config(struct scsi_device *sdev) | |||
807 | static void ata_scsi_dev_config(struct scsi_device *sdev, | 804 | static void ata_scsi_dev_config(struct scsi_device *sdev, |
808 | struct ata_device *dev) | 805 | struct ata_device *dev) |
809 | { | 806 | { |
810 | unsigned int max_sectors; | 807 | /* configure max sectors */ |
811 | 808 | blk_queue_max_sectors(sdev->request_queue, dev->max_sectors); | |
812 | /* TODO: 2048 is an arbitrary number, not the | ||
813 | * hardware maximum. This should be increased to | ||
814 | * 65534 when Jens Axboe's patch for dynamically | ||
815 | * determining max_sectors is merged. | ||
816 | */ | ||
817 | max_sectors = ATA_MAX_SECTORS; | ||
818 | if (dev->flags & ATA_DFLAG_LBA48) | ||
819 | max_sectors = ATA_MAX_SECTORS_LBA48; | ||
820 | if (dev->max_sectors) | ||
821 | max_sectors = dev->max_sectors; | ||
822 | 809 | ||
823 | blk_queue_max_sectors(sdev->request_queue, max_sectors); | 810 | /* SATA DMA transfers must be multiples of 4 byte, so |
824 | |||
825 | /* | ||
826 | * SATA DMA transfers must be multiples of 4 byte, so | ||
827 | * we need to pad ATAPI transfers using an extra sg. | 811 | * we need to pad ATAPI transfers using an extra sg. |
828 | * Decrement max hw segments accordingly. | 812 | * Decrement max hw segments accordingly. |
829 | */ | 813 | */ |
@@ -1040,8 +1024,7 @@ static unsigned int ata_scsi_flush_xlat(struct ata_queued_cmd *qc, const u8 *scs | |||
1040 | tf->flags |= ATA_TFLAG_DEVICE; | 1024 | tf->flags |= ATA_TFLAG_DEVICE; |
1041 | tf->protocol = ATA_PROT_NODATA; | 1025 | tf->protocol = ATA_PROT_NODATA; |
1042 | 1026 | ||
1043 | if ((qc->dev->flags & ATA_DFLAG_LBA48) && | 1027 | if (qc->dev->flags & ATA_DFLAG_FLUSH_EXT) |
1044 | (ata_id_has_flush_ext(qc->dev->id))) | ||
1045 | tf->command = ATA_CMD_FLUSH_EXT; | 1028 | tf->command = ATA_CMD_FLUSH_EXT; |
1046 | else | 1029 | else |
1047 | tf->command = ATA_CMD_FLUSH; | 1030 | tf->command = ATA_CMD_FLUSH; |
@@ -1282,17 +1265,14 @@ nothing_to_do: | |||
1282 | 1265 | ||
1283 | static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicmd) | 1266 | static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicmd) |
1284 | { | 1267 | { |
1285 | struct ata_taskfile *tf = &qc->tf; | 1268 | unsigned int tf_flags = 0; |
1286 | struct ata_device *dev = qc->dev; | ||
1287 | u64 block; | 1269 | u64 block; |
1288 | u32 n_block; | 1270 | u32 n_block; |
1289 | 1271 | int rc; | |
1290 | qc->flags |= ATA_QCFLAG_IO; | ||
1291 | tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; | ||
1292 | 1272 | ||
1293 | if (scsicmd[0] == WRITE_10 || scsicmd[0] == WRITE_6 || | 1273 | if (scsicmd[0] == WRITE_10 || scsicmd[0] == WRITE_6 || |
1294 | scsicmd[0] == WRITE_16) | 1274 | scsicmd[0] == WRITE_16) |
1295 | tf->flags |= ATA_TFLAG_WRITE; | 1275 | tf_flags |= ATA_TFLAG_WRITE; |
1296 | 1276 | ||
1297 | /* Calculate the SCSI LBA, transfer length and FUA. */ | 1277 | /* Calculate the SCSI LBA, transfer length and FUA. */ |
1298 | switch (scsicmd[0]) { | 1278 | switch (scsicmd[0]) { |
@@ -1300,7 +1280,7 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm | |||
1300 | case WRITE_10: | 1280 | case WRITE_10: |
1301 | scsi_10_lba_len(scsicmd, &block, &n_block); | 1281 | scsi_10_lba_len(scsicmd, &block, &n_block); |
1302 | if (unlikely(scsicmd[1] & (1 << 3))) | 1282 | if (unlikely(scsicmd[1] & (1 << 3))) |
1303 | tf->flags |= ATA_TFLAG_FUA; | 1283 | tf_flags |= ATA_TFLAG_FUA; |
1304 | break; | 1284 | break; |
1305 | case READ_6: | 1285 | case READ_6: |
1306 | case WRITE_6: | 1286 | case WRITE_6: |
@@ -1316,7 +1296,7 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm | |||
1316 | case WRITE_16: | 1296 | case WRITE_16: |
1317 | scsi_16_lba_len(scsicmd, &block, &n_block); | 1297 | scsi_16_lba_len(scsicmd, &block, &n_block); |
1318 | if (unlikely(scsicmd[1] & (1 << 3))) | 1298 | if (unlikely(scsicmd[1] & (1 << 3))) |
1319 | tf->flags |= ATA_TFLAG_FUA; | 1299 | tf_flags |= ATA_TFLAG_FUA; |
1320 | break; | 1300 | break; |
1321 | default: | 1301 | default: |
1322 | DPRINTK("no-byte command\n"); | 1302 | DPRINTK("no-byte command\n"); |
@@ -1334,106 +1314,17 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm | |||
1334 | */ | 1314 | */ |
1335 | goto nothing_to_do; | 1315 | goto nothing_to_do; |
1336 | 1316 | ||
1337 | if ((dev->flags & (ATA_DFLAG_PIO | ATA_DFLAG_NCQ_OFF | | 1317 | qc->flags |= ATA_QCFLAG_IO; |
1338 | ATA_DFLAG_NCQ)) == ATA_DFLAG_NCQ) { | 1318 | qc->nsect = n_block; |
1339 | /* yay, NCQ */ | ||
1340 | if (!lba_48_ok(block, n_block)) | ||
1341 | goto out_of_range; | ||
1342 | |||
1343 | tf->protocol = ATA_PROT_NCQ; | ||
1344 | tf->flags |= ATA_TFLAG_LBA | ATA_TFLAG_LBA48; | ||
1345 | |||
1346 | if (tf->flags & ATA_TFLAG_WRITE) | ||
1347 | tf->command = ATA_CMD_FPDMA_WRITE; | ||
1348 | else | ||
1349 | tf->command = ATA_CMD_FPDMA_READ; | ||
1350 | |||
1351 | qc->nsect = n_block; | ||
1352 | |||
1353 | tf->nsect = qc->tag << 3; | ||
1354 | tf->hob_feature = (n_block >> 8) & 0xff; | ||
1355 | tf->feature = n_block & 0xff; | ||
1356 | |||
1357 | tf->hob_lbah = (block >> 40) & 0xff; | ||
1358 | tf->hob_lbam = (block >> 32) & 0xff; | ||
1359 | tf->hob_lbal = (block >> 24) & 0xff; | ||
1360 | tf->lbah = (block >> 16) & 0xff; | ||
1361 | tf->lbam = (block >> 8) & 0xff; | ||
1362 | tf->lbal = block & 0xff; | ||
1363 | |||
1364 | tf->device = 1 << 6; | ||
1365 | if (tf->flags & ATA_TFLAG_FUA) | ||
1366 | tf->device |= 1 << 7; | ||
1367 | } else if (dev->flags & ATA_DFLAG_LBA) { | ||
1368 | tf->flags |= ATA_TFLAG_LBA; | ||
1369 | |||
1370 | if (lba_28_ok(block, n_block)) { | ||
1371 | /* use LBA28 */ | ||
1372 | tf->device |= (block >> 24) & 0xf; | ||
1373 | } else if (lba_48_ok(block, n_block)) { | ||
1374 | if (!(dev->flags & ATA_DFLAG_LBA48)) | ||
1375 | goto out_of_range; | ||
1376 | |||
1377 | /* use LBA48 */ | ||
1378 | tf->flags |= ATA_TFLAG_LBA48; | ||
1379 | |||
1380 | tf->hob_nsect = (n_block >> 8) & 0xff; | ||
1381 | |||
1382 | tf->hob_lbah = (block >> 40) & 0xff; | ||
1383 | tf->hob_lbam = (block >> 32) & 0xff; | ||
1384 | tf->hob_lbal = (block >> 24) & 0xff; | ||
1385 | } else | ||
1386 | /* request too large even for LBA48 */ | ||
1387 | goto out_of_range; | ||
1388 | |||
1389 | if (unlikely(ata_rwcmd_protocol(qc) < 0)) | ||
1390 | goto invalid_fld; | ||
1391 | |||
1392 | qc->nsect = n_block; | ||
1393 | tf->nsect = n_block & 0xff; | ||
1394 | |||
1395 | tf->lbah = (block >> 16) & 0xff; | ||
1396 | tf->lbam = (block >> 8) & 0xff; | ||
1397 | tf->lbal = block & 0xff; | ||
1398 | |||
1399 | tf->device |= ATA_LBA; | ||
1400 | } else { | ||
1401 | /* CHS */ | ||
1402 | u32 sect, head, cyl, track; | ||
1403 | |||
1404 | /* The request -may- be too large for CHS addressing. */ | ||
1405 | if (!lba_28_ok(block, n_block)) | ||
1406 | goto out_of_range; | ||
1407 | |||
1408 | if (unlikely(ata_rwcmd_protocol(qc) < 0)) | ||
1409 | goto invalid_fld; | ||
1410 | |||
1411 | /* Convert LBA to CHS */ | ||
1412 | track = (u32)block / dev->sectors; | ||
1413 | cyl = track / dev->heads; | ||
1414 | head = track % dev->heads; | ||
1415 | sect = (u32)block % dev->sectors + 1; | ||
1416 | |||
1417 | DPRINTK("block %u track %u cyl %u head %u sect %u\n", | ||
1418 | (u32)block, track, cyl, head, sect); | ||
1419 | |||
1420 | /* Check whether the converted CHS can fit. | ||
1421 | Cylinder: 0-65535 | ||
1422 | Head: 0-15 | ||
1423 | Sector: 1-255*/ | ||
1424 | if ((cyl >> 16) || (head >> 4) || (sect >> 8) || (!sect)) | ||
1425 | goto out_of_range; | ||
1426 | |||
1427 | qc->nsect = n_block; | ||
1428 | tf->nsect = n_block & 0xff; /* Sector count 0 means 256 sectors */ | ||
1429 | tf->lbal = sect; | ||
1430 | tf->lbam = cyl; | ||
1431 | tf->lbah = cyl >> 8; | ||
1432 | tf->device |= head; | ||
1433 | } | ||
1434 | 1319 | ||
1435 | return 0; | 1320 | rc = ata_build_rw_tf(&qc->tf, qc->dev, block, n_block, tf_flags, |
1321 | qc->tag); | ||
1322 | if (likely(rc == 0)) | ||
1323 | return 0; | ||
1436 | 1324 | ||
1325 | if (rc == -ERANGE) | ||
1326 | goto out_of_range; | ||
1327 | /* treat all other errors as -EINVAL, fall through */ | ||
1437 | invalid_fld: | 1328 | invalid_fld: |
1438 | ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x24, 0x0); | 1329 | ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x24, 0x0); |
1439 | /* "Invalid field in cbd" */ | 1330 | /* "Invalid field in cbd" */ |
@@ -1477,7 +1368,7 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc) | |||
1477 | */ | 1368 | */ |
1478 | if (((cdb[0] == ATA_16) || (cdb[0] == ATA_12)) && | 1369 | if (((cdb[0] == ATA_16) || (cdb[0] == ATA_12)) && |
1479 | ((cdb[2] & 0x20) || need_sense)) { | 1370 | ((cdb[2] & 0x20) || need_sense)) { |
1480 | ata_gen_ata_desc_sense(qc); | 1371 | ata_gen_passthru_sense(qc); |
1481 | } else { | 1372 | } else { |
1482 | if (!need_sense) { | 1373 | if (!need_sense) { |
1483 | cmd->result = SAM_STAT_GOOD; | 1374 | cmd->result = SAM_STAT_GOOD; |
@@ -1488,7 +1379,7 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc) | |||
1488 | * good for smaller LBA (and maybe CHS?) | 1379 | * good for smaller LBA (and maybe CHS?) |
1489 | * devices. | 1380 | * devices. |
1490 | */ | 1381 | */ |
1491 | ata_gen_fixed_sense(qc); | 1382 | ata_gen_ata_sense(qc); |
1492 | } | 1383 | } |
1493 | } | 1384 | } |
1494 | 1385 | ||
@@ -1715,6 +1606,22 @@ void ata_scsi_rbuf_fill(struct ata_scsi_args *args, | |||
1715 | } | 1606 | } |
1716 | 1607 | ||
1717 | /** | 1608 | /** |
1609 | * ATA_SCSI_RBUF_SET - helper to set values in SCSI response buffer | ||
1610 | * @idx: byte index into SCSI response buffer | ||
1611 | * @val: value to set | ||
1612 | * | ||
1613 | * To be used by SCSI command simulator functions. This macros | ||
1614 | * expects two local variables, u8 *rbuf and unsigned int buflen, | ||
1615 | * are in scope. | ||
1616 | * | ||
1617 | * LOCKING: | ||
1618 | * None. | ||
1619 | */ | ||
1620 | #define ATA_SCSI_RBUF_SET(idx, val) do { \ | ||
1621 | if ((idx) < buflen) rbuf[(idx)] = (u8)(val); \ | ||
1622 | } while (0) | ||
1623 | |||
1624 | /** | ||
1718 | * ata_scsiop_inq_std - Simulate INQUIRY command | 1625 | * ata_scsiop_inq_std - Simulate INQUIRY command |
1719 | * @args: device IDENTIFY data / SCSI command of interest. | 1626 | * @args: device IDENTIFY data / SCSI command of interest. |
1720 | * @rbuf: Response buffer, to which simulated SCSI cmd output is sent. | 1627 | * @rbuf: Response buffer, to which simulated SCSI cmd output is sent. |
@@ -2173,67 +2080,42 @@ saving_not_supp: | |||
2173 | * Simulate READ CAPACITY commands. | 2080 | * Simulate READ CAPACITY commands. |
2174 | * | 2081 | * |
2175 | * LOCKING: | 2082 | * LOCKING: |
2176 | * spin_lock_irqsave(host lock) | 2083 | * None. |
2177 | */ | 2084 | */ |
2178 | |||
2179 | unsigned int ata_scsiop_read_cap(struct ata_scsi_args *args, u8 *rbuf, | 2085 | unsigned int ata_scsiop_read_cap(struct ata_scsi_args *args, u8 *rbuf, |
2180 | unsigned int buflen) | 2086 | unsigned int buflen) |
2181 | { | 2087 | { |
2182 | u64 n_sectors; | 2088 | u64 last_lba = args->dev->n_sectors - 1; /* LBA of the last block */ |
2183 | u32 tmp; | ||
2184 | 2089 | ||
2185 | VPRINTK("ENTER\n"); | 2090 | VPRINTK("ENTER\n"); |
2186 | 2091 | ||
2187 | if (ata_id_has_lba(args->id)) { | ||
2188 | if (ata_id_has_lba48(args->id)) | ||
2189 | n_sectors = ata_id_u64(args->id, 100); | ||
2190 | else | ||
2191 | n_sectors = ata_id_u32(args->id, 60); | ||
2192 | } else { | ||
2193 | /* CHS default translation */ | ||
2194 | n_sectors = args->id[1] * args->id[3] * args->id[6]; | ||
2195 | |||
2196 | if (ata_id_current_chs_valid(args->id)) | ||
2197 | /* CHS current translation */ | ||
2198 | n_sectors = ata_id_u32(args->id, 57); | ||
2199 | } | ||
2200 | |||
2201 | n_sectors--; /* ATA TotalUserSectors - 1 */ | ||
2202 | |||
2203 | if (args->cmd->cmnd[0] == READ_CAPACITY) { | 2092 | if (args->cmd->cmnd[0] == READ_CAPACITY) { |
2204 | if( n_sectors >= 0xffffffffULL ) | 2093 | if (last_lba >= 0xffffffffULL) |
2205 | tmp = 0xffffffff ; /* Return max count on overflow */ | 2094 | last_lba = 0xffffffff; |
2206 | else | ||
2207 | tmp = n_sectors ; | ||
2208 | 2095 | ||
2209 | /* sector count, 32-bit */ | 2096 | /* sector count, 32-bit */ |
2210 | rbuf[0] = tmp >> (8 * 3); | 2097 | ATA_SCSI_RBUF_SET(0, last_lba >> (8 * 3)); |
2211 | rbuf[1] = tmp >> (8 * 2); | 2098 | ATA_SCSI_RBUF_SET(1, last_lba >> (8 * 2)); |
2212 | rbuf[2] = tmp >> (8 * 1); | 2099 | ATA_SCSI_RBUF_SET(2, last_lba >> (8 * 1)); |
2213 | rbuf[3] = tmp; | 2100 | ATA_SCSI_RBUF_SET(3, last_lba); |
2214 | 2101 | ||
2215 | /* sector size */ | 2102 | /* sector size */ |
2216 | tmp = ATA_SECT_SIZE; | 2103 | ATA_SCSI_RBUF_SET(6, ATA_SECT_SIZE >> 8); |
2217 | rbuf[6] = tmp >> 8; | 2104 | ATA_SCSI_RBUF_SET(7, ATA_SECT_SIZE); |
2218 | rbuf[7] = tmp; | ||
2219 | |||
2220 | } else { | 2105 | } else { |
2221 | /* sector count, 64-bit */ | 2106 | /* sector count, 64-bit */ |
2222 | tmp = n_sectors >> (8 * 4); | 2107 | ATA_SCSI_RBUF_SET(0, last_lba >> (8 * 7)); |
2223 | rbuf[2] = tmp >> (8 * 3); | 2108 | ATA_SCSI_RBUF_SET(1, last_lba >> (8 * 6)); |
2224 | rbuf[3] = tmp >> (8 * 2); | 2109 | ATA_SCSI_RBUF_SET(2, last_lba >> (8 * 5)); |
2225 | rbuf[4] = tmp >> (8 * 1); | 2110 | ATA_SCSI_RBUF_SET(3, last_lba >> (8 * 4)); |
2226 | rbuf[5] = tmp; | 2111 | ATA_SCSI_RBUF_SET(4, last_lba >> (8 * 3)); |
2227 | tmp = n_sectors; | 2112 | ATA_SCSI_RBUF_SET(5, last_lba >> (8 * 2)); |
2228 | rbuf[6] = tmp >> (8 * 3); | 2113 | ATA_SCSI_RBUF_SET(6, last_lba >> (8 * 1)); |
2229 | rbuf[7] = tmp >> (8 * 2); | 2114 | ATA_SCSI_RBUF_SET(7, last_lba); |
2230 | rbuf[8] = tmp >> (8 * 1); | ||
2231 | rbuf[9] = tmp; | ||
2232 | 2115 | ||
2233 | /* sector size */ | 2116 | /* sector size */ |
2234 | tmp = ATA_SECT_SIZE; | 2117 | ATA_SCSI_RBUF_SET(10, ATA_SECT_SIZE >> 8); |
2235 | rbuf[12] = tmp >> 8; | 2118 | ATA_SCSI_RBUF_SET(11, ATA_SECT_SIZE); |
2236 | rbuf[13] = tmp; | ||
2237 | } | 2119 | } |
2238 | 2120 | ||
2239 | return 0; | 2121 | return 0; |
@@ -2319,7 +2201,7 @@ static void atapi_sense_complete(struct ata_queued_cmd *qc) | |||
2319 | * a sense descriptors, since that's only | 2201 | * a sense descriptors, since that's only |
2320 | * correct for ATA, not ATAPI | 2202 | * correct for ATA, not ATAPI |
2321 | */ | 2203 | */ |
2322 | ata_gen_ata_desc_sense(qc); | 2204 | ata_gen_passthru_sense(qc); |
2323 | } | 2205 | } |
2324 | 2206 | ||
2325 | qc->scsidone(qc->scsicmd); | 2207 | qc->scsidone(qc->scsicmd); |
@@ -2394,7 +2276,7 @@ static void atapi_qc_complete(struct ata_queued_cmd *qc) | |||
2394 | * sense descriptors, since that's only | 2276 | * sense descriptors, since that's only |
2395 | * correct for ATA, not ATAPI | 2277 | * correct for ATA, not ATAPI |
2396 | */ | 2278 | */ |
2397 | ata_gen_ata_desc_sense(qc); | 2279 | ata_gen_passthru_sense(qc); |
2398 | } | 2280 | } |
2399 | 2281 | ||
2400 | /* SCSI EH automatically locks door if sdev->locked is | 2282 | /* SCSI EH automatically locks door if sdev->locked is |
@@ -2427,7 +2309,7 @@ static void atapi_qc_complete(struct ata_queued_cmd *qc) | |||
2427 | * a sense descriptors, since that's only | 2309 | * a sense descriptors, since that's only |
2428 | * correct for ATA, not ATAPI | 2310 | * correct for ATA, not ATAPI |
2429 | */ | 2311 | */ |
2430 | ata_gen_ata_desc_sense(qc); | 2312 | ata_gen_passthru_sense(qc); |
2431 | } else { | 2313 | } else { |
2432 | u8 *scsicmd = cmd->cmnd; | 2314 | u8 *scsicmd = cmd->cmnd; |
2433 | 2315 | ||
@@ -3182,10 +3064,12 @@ static int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel, | |||
3182 | rc = -EINVAL; | 3064 | rc = -EINVAL; |
3183 | } | 3065 | } |
3184 | 3066 | ||
3185 | if (rc == 0) | 3067 | if (rc == 0) { |
3186 | ata_port_schedule_eh(ap); | 3068 | ata_port_schedule_eh(ap); |
3187 | 3069 | spin_unlock_irqrestore(ap->lock, flags); | |
3188 | spin_unlock_irqrestore(ap->lock, flags); | 3070 | ata_port_wait_eh(ap); |
3071 | } else | ||
3072 | spin_unlock_irqrestore(ap->lock, flags); | ||
3189 | 3073 | ||
3190 | return rc; | 3074 | return rc; |
3191 | } | 3075 | } |
@@ -3205,15 +3089,27 @@ static int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel, | |||
3205 | void ata_scsi_dev_rescan(void *data) | 3089 | void ata_scsi_dev_rescan(void *data) |
3206 | { | 3090 | { |
3207 | struct ata_port *ap = data; | 3091 | struct ata_port *ap = data; |
3208 | struct ata_device *dev; | 3092 | unsigned long flags; |
3209 | unsigned int i; | 3093 | unsigned int i; |
3210 | 3094 | ||
3095 | spin_lock_irqsave(ap->lock, flags); | ||
3096 | |||
3211 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 3097 | for (i = 0; i < ATA_MAX_DEVICES; i++) { |
3212 | dev = &ap->device[i]; | 3098 | struct ata_device *dev = &ap->device[i]; |
3099 | struct scsi_device *sdev = dev->sdev; | ||
3213 | 3100 | ||
3214 | if (ata_dev_enabled(dev) && dev->sdev) | 3101 | if (!ata_dev_enabled(dev) || !sdev) |
3215 | scsi_rescan_device(&(dev->sdev->sdev_gendev)); | 3102 | continue; |
3103 | if (scsi_device_get(sdev)) | ||
3104 | continue; | ||
3105 | |||
3106 | spin_unlock_irqrestore(ap->lock, flags); | ||
3107 | scsi_rescan_device(&(sdev->sdev_gendev)); | ||
3108 | scsi_device_put(sdev); | ||
3109 | spin_lock_irqsave(ap->lock, flags); | ||
3216 | } | 3110 | } |
3111 | |||
3112 | spin_unlock_irqrestore(ap->lock, flags); | ||
3217 | } | 3113 | } |
3218 | 3114 | ||
3219 | /** | 3115 | /** |