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.c140
1 files changed, 87 insertions, 53 deletions
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
index bd9f2176f79a..a1259b242b8e 100644
--- a/drivers/scsi/libata-scsi.c
+++ b/drivers/scsi/libata-scsi.c
@@ -521,13 +521,11 @@ void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc,
521 printk(KERN_WARNING "ata%u: no sense translation for status: 0x%02x\n", 521 printk(KERN_WARNING "ata%u: no sense translation for status: 0x%02x\n",
522 id, drv_stat); 522 id, drv_stat);
523 523
524 /* For our last chance pick, use medium read error because 524 /* We need a sensible error return here, which is tricky, and one
525 * it's much more common than an ATA drive telling you a write 525 that won't cause people to do things like return a disk wrongly */
526 * has failed. 526 *sk = ABORTED_COMMAND;
527 */ 527 *asc = 0x00;
528 *sk = MEDIUM_ERROR; 528 *ascq = 0x00;
529 *asc = 0x11; /* "unrecovered read error" */
530 *ascq = 0x04; /* "auto-reallocation failed" */
531 529
532 translate_done: 530 translate_done:
533 printk(KERN_ERR "ata%u: translated ATA stat/err 0x%02x/%02x to " 531 printk(KERN_ERR "ata%u: translated ATA stat/err 0x%02x/%02x to "
@@ -672,6 +670,41 @@ void ata_gen_fixed_sense(struct ata_queued_cmd *qc)
672 } 670 }
673} 671}
674 672
673static void ata_scsi_sdev_config(struct scsi_device *sdev)
674{
675 sdev->use_10_for_rw = 1;
676 sdev->use_10_for_ms = 1;
677}
678
679static void ata_scsi_dev_config(struct scsi_device *sdev,
680 struct ata_device *dev)
681{
682 unsigned int max_sectors;
683
684 /* TODO: 2048 is an arbitrary number, not the
685 * hardware maximum. This should be increased to
686 * 65534 when Jens Axboe's patch for dynamically
687 * determining max_sectors is merged.
688 */
689 max_sectors = ATA_MAX_SECTORS;
690 if (dev->flags & ATA_DFLAG_LBA48)
691 max_sectors = 2048;
692 if (dev->max_sectors)
693 max_sectors = dev->max_sectors;
694
695 blk_queue_max_sectors(sdev->request_queue, max_sectors);
696
697 /*
698 * SATA DMA transfers must be multiples of 4 byte, so
699 * we need to pad ATAPI transfers using an extra sg.
700 * Decrement max hw segments accordingly.
701 */
702 if (dev->class == ATA_DEV_ATAPI) {
703 request_queue_t *q = sdev->request_queue;
704 blk_queue_max_hw_segments(q, q->max_hw_segments - 1);
705 }
706}
707
675/** 708/**
676 * ata_scsi_slave_config - Set SCSI device attributes 709 * ata_scsi_slave_config - Set SCSI device attributes
677 * @sdev: SCSI device to examine 710 * @sdev: SCSI device to examine
@@ -686,41 +719,18 @@ void ata_gen_fixed_sense(struct ata_queued_cmd *qc)
686 719
687int ata_scsi_slave_config(struct scsi_device *sdev) 720int ata_scsi_slave_config(struct scsi_device *sdev)
688{ 721{
689 sdev->use_10_for_rw = 1; 722 ata_scsi_sdev_config(sdev);
690 sdev->use_10_for_ms = 1;
691 723
692 blk_queue_max_phys_segments(sdev->request_queue, LIBATA_MAX_PRD); 724 blk_queue_max_phys_segments(sdev->request_queue, LIBATA_MAX_PRD);
693 725
694 if (sdev->id < ATA_MAX_DEVICES) { 726 if (sdev->id < ATA_MAX_DEVICES) {
695 struct ata_port *ap; 727 struct ata_port *ap;
696 struct ata_device *dev; 728 struct ata_device *dev;
697 unsigned int max_sectors;
698 729
699 ap = (struct ata_port *) &sdev->host->hostdata[0]; 730 ap = (struct ata_port *) &sdev->host->hostdata[0];
700 dev = &ap->device[sdev->id]; 731 dev = &ap->device[sdev->id];
701 732
702 /* TODO: 2048 is an arbitrary number, not the 733 ata_scsi_dev_config(sdev, dev);
703 * hardware maximum. This should be increased to
704 * 65534 when Jens Axboe's patch for dynamically
705 * determining max_sectors is merged.
706 */
707 max_sectors = ATA_MAX_SECTORS;
708 if (dev->flags & ATA_DFLAG_LBA48)
709 max_sectors = 2048;
710 if (dev->max_sectors)
711 max_sectors = dev->max_sectors;
712
713 blk_queue_max_sectors(sdev->request_queue, max_sectors);
714
715 /*
716 * SATA DMA transfers must be multiples of 4 byte, so
717 * we need to pad ATAPI transfers using an extra sg.
718 * Decrement max hw segments accordingly.
719 */
720 if (dev->class == ATA_DEV_ATAPI) {
721 request_queue_t *q = sdev->request_queue;
722 blk_queue_max_hw_segments(q, q->max_hw_segments - 1);
723 }
724 } 734 }
725 735
726 return 0; /* scsi layer doesn't check return value, sigh */ 736 return 0; /* scsi layer doesn't check return value, sigh */
@@ -1552,7 +1562,7 @@ void ata_scsi_rbuf_fill(struct ata_scsi_args *args,
1552 * @buflen: Response buffer length. 1562 * @buflen: Response buffer length.
1553 * 1563 *
1554 * Returns standard device identification data associated 1564 * Returns standard device identification data associated
1555 * with non-EVPD INQUIRY command output. 1565 * with non-VPD INQUIRY command output.
1556 * 1566 *
1557 * LOCKING: 1567 * LOCKING:
1558 * spin_lock_irqsave(host_set lock) 1568 * spin_lock_irqsave(host_set lock)
@@ -1603,12 +1613,12 @@ unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf,
1603} 1613}
1604 1614
1605/** 1615/**
1606 * ata_scsiop_inq_00 - Simulate INQUIRY EVPD page 0, list of pages 1616 * ata_scsiop_inq_00 - Simulate INQUIRY VPD page 0, list of pages
1607 * @args: device IDENTIFY data / SCSI command of interest. 1617 * @args: device IDENTIFY data / SCSI command of interest.
1608 * @rbuf: Response buffer, to which simulated SCSI cmd output is sent. 1618 * @rbuf: Response buffer, to which simulated SCSI cmd output is sent.
1609 * @buflen: Response buffer length. 1619 * @buflen: Response buffer length.
1610 * 1620 *
1611 * Returns list of inquiry EVPD pages available. 1621 * Returns list of inquiry VPD pages available.
1612 * 1622 *
1613 * LOCKING: 1623 * LOCKING:
1614 * spin_lock_irqsave(host_set lock) 1624 * spin_lock_irqsave(host_set lock)
@@ -1622,7 +1632,7 @@ unsigned int ata_scsiop_inq_00(struct ata_scsi_args *args, u8 *rbuf,
1622 0x80, /* page 0x80, unit serial no page */ 1632 0x80, /* page 0x80, unit serial no page */
1623 0x83 /* page 0x83, device ident page */ 1633 0x83 /* page 0x83, device ident page */
1624 }; 1634 };
1625 rbuf[3] = sizeof(pages); /* number of supported EVPD pages */ 1635 rbuf[3] = sizeof(pages); /* number of supported VPD pages */
1626 1636
1627 if (buflen > 6) 1637 if (buflen > 6)
1628 memcpy(rbuf + 4, pages, sizeof(pages)); 1638 memcpy(rbuf + 4, pages, sizeof(pages));
@@ -1631,7 +1641,7 @@ unsigned int ata_scsiop_inq_00(struct ata_scsi_args *args, u8 *rbuf,
1631} 1641}
1632 1642
1633/** 1643/**
1634 * ata_scsiop_inq_80 - Simulate INQUIRY EVPD page 80, device serial number 1644 * ata_scsiop_inq_80 - Simulate INQUIRY VPD page 80, device serial number
1635 * @args: device IDENTIFY data / SCSI command of interest. 1645 * @args: device IDENTIFY data / SCSI command of interest.
1636 * @rbuf: Response buffer, to which simulated SCSI cmd output is sent. 1646 * @rbuf: Response buffer, to which simulated SCSI cmd output is sent.
1637 * @buflen: Response buffer length. 1647 * @buflen: Response buffer length.
@@ -1660,16 +1670,16 @@ unsigned int ata_scsiop_inq_80(struct ata_scsi_args *args, u8 *rbuf,
1660 return 0; 1670 return 0;
1661} 1671}
1662 1672
1663static const char * const inq_83_str = "Linux ATA-SCSI simulator";
1664
1665/** 1673/**
1666 * ata_scsiop_inq_83 - Simulate INQUIRY EVPD page 83, device identity 1674 * ata_scsiop_inq_83 - Simulate INQUIRY VPD page 83, device identity
1667 * @args: device IDENTIFY data / SCSI command of interest. 1675 * @args: device IDENTIFY data / SCSI command of interest.
1668 * @rbuf: Response buffer, to which simulated SCSI cmd output is sent. 1676 * @rbuf: Response buffer, to which simulated SCSI cmd output is sent.
1669 * @buflen: Response buffer length. 1677 * @buflen: Response buffer length.
1670 * 1678 *
1671 * Returns device identification. Currently hardcoded to 1679 * Yields two logical unit device identification designators:
1672 * return "Linux ATA-SCSI simulator". 1680 * - vendor specific ASCII containing the ATA serial number
1681 * - SAT defined "t10 vendor id based" containing ASCII vendor
1682 * name ("ATA "), model and serial numbers.
1673 * 1683 *
1674 * LOCKING: 1684 * LOCKING:
1675 * spin_lock_irqsave(host_set lock) 1685 * spin_lock_irqsave(host_set lock)
@@ -1678,16 +1688,39 @@ static const char * const inq_83_str = "Linux ATA-SCSI simulator";
1678unsigned int ata_scsiop_inq_83(struct ata_scsi_args *args, u8 *rbuf, 1688unsigned int ata_scsiop_inq_83(struct ata_scsi_args *args, u8 *rbuf,
1679 unsigned int buflen) 1689 unsigned int buflen)
1680{ 1690{
1681 rbuf[1] = 0x83; /* this page code */ 1691 int num;
1682 rbuf[3] = 4 + strlen(inq_83_str); /* page len */ 1692 const int sat_model_serial_desc_len = 68;
1693 const int ata_model_byte_len = 40;
1683 1694
1684 /* our one and only identification descriptor (vendor-specific) */ 1695 rbuf[1] = 0x83; /* this page code */
1685 if (buflen > (strlen(inq_83_str) + 4 + 4 - 1)) { 1696 num = 4;
1686 rbuf[4 + 0] = 2; /* code set: ASCII */ 1697
1687 rbuf[4 + 3] = strlen(inq_83_str); 1698 if (buflen > (ATA_SERNO_LEN + num + 3)) {
1688 memcpy(rbuf + 4 + 4, inq_83_str, strlen(inq_83_str)); 1699 /* piv=0, assoc=lu, code_set=ACSII, designator=vendor */
1700 rbuf[num + 0] = 2;
1701 rbuf[num + 3] = ATA_SERNO_LEN;
1702 num += 4;
1703 ata_id_string(args->id, (unsigned char *) rbuf + num,
1704 ATA_ID_SERNO_OFS, ATA_SERNO_LEN);
1705 num += ATA_SERNO_LEN;
1689 } 1706 }
1690 1707 if (buflen > (sat_model_serial_desc_len + num + 3)) {
1708 /* SAT defined lu model and serial numbers descriptor */
1709 /* piv=0, assoc=lu, code_set=ACSII, designator=t10 vendor id */
1710 rbuf[num + 0] = 2;
1711 rbuf[num + 1] = 1;
1712 rbuf[num + 3] = sat_model_serial_desc_len;
1713 num += 4;
1714 memcpy(rbuf + num, "ATA ", 8);
1715 num += 8;
1716 ata_id_string(args->id, (unsigned char *) rbuf + num,
1717 ATA_ID_PROD_OFS, ata_model_byte_len);
1718 num += ata_model_byte_len;
1719 ata_id_string(args->id, (unsigned char *) rbuf + num,
1720 ATA_ID_SERNO_OFS, ATA_SERNO_LEN);
1721 num += ATA_SERNO_LEN;
1722 }
1723 rbuf[3] = num - 4; /* page len (assume less than 256 bytes) */
1691 return 0; 1724 return 0;
1692} 1725}
1693 1726
@@ -2366,9 +2399,6 @@ ata_scsi_map_proto(u8 byte1)
2366 2399
2367 case 4: /* PIO Data-in */ 2400 case 4: /* PIO Data-in */
2368 case 5: /* PIO Data-out */ 2401 case 5: /* PIO Data-out */
2369 if (byte1 & 0xe0) {
2370 return ATA_PROT_PIO_MULT;
2371 }
2372 return ATA_PROT_PIO; 2402 return ATA_PROT_PIO;
2373 2403
2374 case 10: /* Device Reset */ 2404 case 10: /* Device Reset */
@@ -2407,6 +2437,10 @@ ata_scsi_pass_thru(struct ata_queued_cmd *qc, const u8 *scsicmd)
2407 if ((tf->protocol = ata_scsi_map_proto(scsicmd[1])) == ATA_PROT_UNKNOWN) 2437 if ((tf->protocol = ata_scsi_map_proto(scsicmd[1])) == ATA_PROT_UNKNOWN)
2408 goto invalid_fld; 2438 goto invalid_fld;
2409 2439
2440 if (scsicmd[1] & 0xe0)
2441 /* PIO multi not supported yet */
2442 goto invalid_fld;
2443
2410 /* 2444 /*
2411 * 12 and 16 byte CDBs use different offsets to 2445 * 12 and 16 byte CDBs use different offsets to
2412 * provide the various register values. 2446 * provide the various register values.