diff options
Diffstat (limited to 'drivers/ata/libata-scsi.c')
-rw-r--r-- | drivers/ata/libata-scsi.c | 74 |
1 files changed, 55 insertions, 19 deletions
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index c02c490122dc..f888babc8283 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c | |||
@@ -826,30 +826,61 @@ static void ata_scsi_sdev_config(struct scsi_device *sdev) | |||
826 | sdev->max_device_blocked = 1; | 826 | sdev->max_device_blocked = 1; |
827 | } | 827 | } |
828 | 828 | ||
829 | static void ata_scsi_dev_config(struct scsi_device *sdev, | 829 | /** |
830 | struct ata_device *dev) | 830 | * atapi_drain_needed - Check whether data transfer may overflow |
831 | * @rq: request to be checked | ||
832 | * | ||
833 | * ATAPI commands which transfer variable length data to host | ||
834 | * might overflow due to application error or hardare bug. This | ||
835 | * function checks whether overflow should be drained and ignored | ||
836 | * for @request. | ||
837 | * | ||
838 | * LOCKING: | ||
839 | * None. | ||
840 | * | ||
841 | * RETURNS: | ||
842 | * 1 if ; otherwise, 0. | ||
843 | */ | ||
844 | static int atapi_drain_needed(struct request *rq) | ||
845 | { | ||
846 | if (likely(!blk_pc_request(rq))) | ||
847 | return 0; | ||
848 | |||
849 | if (!rq->data_len || (rq->cmd_flags & REQ_RW)) | ||
850 | return 0; | ||
851 | |||
852 | return atapi_cmd_type(rq->cmd[0]) == ATAPI_MISC; | ||
853 | } | ||
854 | |||
855 | static int ata_scsi_dev_config(struct scsi_device *sdev, | ||
856 | struct ata_device *dev) | ||
831 | { | 857 | { |
832 | /* configure max sectors */ | 858 | /* configure max sectors */ |
833 | blk_queue_max_sectors(sdev->request_queue, dev->max_sectors); | 859 | blk_queue_max_sectors(sdev->request_queue, dev->max_sectors); |
834 | 860 | ||
835 | /* SATA DMA transfers must be multiples of 4 byte, so | ||
836 | * we need to pad ATAPI transfers using an extra sg. | ||
837 | * Decrement max hw segments accordingly. | ||
838 | */ | ||
839 | if (dev->class == ATA_DEV_ATAPI) { | 861 | if (dev->class == ATA_DEV_ATAPI) { |
840 | struct request_queue *q = sdev->request_queue; | 862 | struct request_queue *q = sdev->request_queue; |
841 | blk_queue_max_hw_segments(q, q->max_hw_segments - 1); | 863 | void *buf; |
842 | 864 | ||
843 | /* set the min alignment */ | 865 | /* set the min alignment */ |
844 | blk_queue_update_dma_alignment(sdev->request_queue, | 866 | blk_queue_update_dma_alignment(sdev->request_queue, |
845 | ATA_DMA_PAD_SZ - 1); | 867 | ATA_DMA_PAD_SZ - 1); |
846 | } else | 868 | |
869 | /* configure draining */ | ||
870 | buf = kmalloc(ATAPI_MAX_DRAIN, q->bounce_gfp | GFP_KERNEL); | ||
871 | if (!buf) { | ||
872 | ata_dev_printk(dev, KERN_ERR, | ||
873 | "drain buffer allocation failed\n"); | ||
874 | return -ENOMEM; | ||
875 | } | ||
876 | |||
877 | blk_queue_dma_drain(q, atapi_drain_needed, buf, ATAPI_MAX_DRAIN); | ||
878 | } else { | ||
847 | /* ATA devices must be sector aligned */ | 879 | /* ATA devices must be sector aligned */ |
848 | blk_queue_update_dma_alignment(sdev->request_queue, | 880 | blk_queue_update_dma_alignment(sdev->request_queue, |
849 | ATA_SECT_SIZE - 1); | 881 | ATA_SECT_SIZE - 1); |
850 | |||
851 | if (dev->class == ATA_DEV_ATA) | ||
852 | sdev->manage_start_stop = 1; | 882 | sdev->manage_start_stop = 1; |
883 | } | ||
853 | 884 | ||
854 | if (dev->flags & ATA_DFLAG_AN) | 885 | if (dev->flags & ATA_DFLAG_AN) |
855 | set_bit(SDEV_EVT_MEDIA_CHANGE, sdev->supported_events); | 886 | set_bit(SDEV_EVT_MEDIA_CHANGE, sdev->supported_events); |
@@ -861,6 +892,8 @@ static void ata_scsi_dev_config(struct scsi_device *sdev, | |||
861 | depth = min(ATA_MAX_QUEUE - 1, depth); | 892 | depth = min(ATA_MAX_QUEUE - 1, depth); |
862 | scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, depth); | 893 | scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, depth); |
863 | } | 894 | } |
895 | |||
896 | return 0; | ||
864 | } | 897 | } |
865 | 898 | ||
866 | /** | 899 | /** |
@@ -879,13 +912,14 @@ int ata_scsi_slave_config(struct scsi_device *sdev) | |||
879 | { | 912 | { |
880 | struct ata_port *ap = ata_shost_to_port(sdev->host); | 913 | struct ata_port *ap = ata_shost_to_port(sdev->host); |
881 | struct ata_device *dev = __ata_scsi_find_dev(ap, sdev); | 914 | struct ata_device *dev = __ata_scsi_find_dev(ap, sdev); |
915 | int rc = 0; | ||
882 | 916 | ||
883 | ata_scsi_sdev_config(sdev); | 917 | ata_scsi_sdev_config(sdev); |
884 | 918 | ||
885 | if (dev) | 919 | if (dev) |
886 | ata_scsi_dev_config(sdev, dev); | 920 | rc = ata_scsi_dev_config(sdev, dev); |
887 | 921 | ||
888 | return 0; | 922 | return rc; |
889 | } | 923 | } |
890 | 924 | ||
891 | /** | 925 | /** |
@@ -905,6 +939,7 @@ int ata_scsi_slave_config(struct scsi_device *sdev) | |||
905 | void ata_scsi_slave_destroy(struct scsi_device *sdev) | 939 | void ata_scsi_slave_destroy(struct scsi_device *sdev) |
906 | { | 940 | { |
907 | struct ata_port *ap = ata_shost_to_port(sdev->host); | 941 | struct ata_port *ap = ata_shost_to_port(sdev->host); |
942 | struct request_queue *q = sdev->request_queue; | ||
908 | unsigned long flags; | 943 | unsigned long flags; |
909 | struct ata_device *dev; | 944 | struct ata_device *dev; |
910 | 945 | ||
@@ -920,6 +955,10 @@ void ata_scsi_slave_destroy(struct scsi_device *sdev) | |||
920 | ata_port_schedule_eh(ap); | 955 | ata_port_schedule_eh(ap); |
921 | } | 956 | } |
922 | spin_unlock_irqrestore(ap->lock, flags); | 957 | spin_unlock_irqrestore(ap->lock, flags); |
958 | |||
959 | kfree(q->dma_drain_buffer); | ||
960 | q->dma_drain_buffer = NULL; | ||
961 | q->dma_drain_size = 0; | ||
923 | } | 962 | } |
924 | 963 | ||
925 | /** | 964 | /** |
@@ -1862,7 +1901,7 @@ unsigned int ata_scsiop_inq_83(struct ata_scsi_args *args, u8 *rbuf, | |||
1862 | * spin_lock_irqsave(host lock) | 1901 | * spin_lock_irqsave(host lock) |
1863 | */ | 1902 | */ |
1864 | 1903 | ||
1865 | unsigned int ata_scsiop_inq_89(struct ata_scsi_args *args, u8 *rbuf, | 1904 | static unsigned int ata_scsiop_inq_89(struct ata_scsi_args *args, u8 *rbuf, |
1866 | unsigned int buflen) | 1905 | unsigned int buflen) |
1867 | { | 1906 | { |
1868 | u8 pbuf[60]; | 1907 | u8 pbuf[60]; |
@@ -2500,7 +2539,7 @@ static unsigned int atapi_xlat(struct ata_queued_cmd *qc) | |||
2500 | * want to set it properly, and for DMA where it is | 2539 | * want to set it properly, and for DMA where it is |
2501 | * effectively meaningless. | 2540 | * effectively meaningless. |
2502 | */ | 2541 | */ |
2503 | nbytes = min(qc->nbytes, (unsigned int)63 * 1024); | 2542 | nbytes = min(scmd->request->raw_data_len, (unsigned int)63 * 1024); |
2504 | 2543 | ||
2505 | /* Most ATAPI devices which honor transfer chunk size don't | 2544 | /* Most ATAPI devices which honor transfer chunk size don't |
2506 | * behave according to the spec when odd chunk size which | 2545 | * behave according to the spec when odd chunk size which |
@@ -3555,7 +3594,7 @@ EXPORT_SYMBOL_GPL(ata_sas_port_alloc); | |||
3555 | * @ap: Port to initialize | 3594 | * @ap: Port to initialize |
3556 | * | 3595 | * |
3557 | * Called just after data structures for each port are | 3596 | * Called just after data structures for each port are |
3558 | * initialized. Allocates DMA pad. | 3597 | * initialized. |
3559 | * | 3598 | * |
3560 | * May be used as the port_start() entry in ata_port_operations. | 3599 | * May be used as the port_start() entry in ata_port_operations. |
3561 | * | 3600 | * |
@@ -3564,7 +3603,7 @@ EXPORT_SYMBOL_GPL(ata_sas_port_alloc); | |||
3564 | */ | 3603 | */ |
3565 | int ata_sas_port_start(struct ata_port *ap) | 3604 | int ata_sas_port_start(struct ata_port *ap) |
3566 | { | 3605 | { |
3567 | return ata_pad_alloc(ap, ap->dev); | 3606 | return 0; |
3568 | } | 3607 | } |
3569 | EXPORT_SYMBOL_GPL(ata_sas_port_start); | 3608 | EXPORT_SYMBOL_GPL(ata_sas_port_start); |
3570 | 3609 | ||
@@ -3572,8 +3611,6 @@ EXPORT_SYMBOL_GPL(ata_sas_port_start); | |||
3572 | * ata_port_stop - Undo ata_sas_port_start() | 3611 | * ata_port_stop - Undo ata_sas_port_start() |
3573 | * @ap: Port to shut down | 3612 | * @ap: Port to shut down |
3574 | * | 3613 | * |
3575 | * Frees the DMA pad. | ||
3576 | * | ||
3577 | * May be used as the port_stop() entry in ata_port_operations. | 3614 | * May be used as the port_stop() entry in ata_port_operations. |
3578 | * | 3615 | * |
3579 | * LOCKING: | 3616 | * LOCKING: |
@@ -3582,7 +3619,6 @@ EXPORT_SYMBOL_GPL(ata_sas_port_start); | |||
3582 | 3619 | ||
3583 | void ata_sas_port_stop(struct ata_port *ap) | 3620 | void ata_sas_port_stop(struct ata_port *ap) |
3584 | { | 3621 | { |
3585 | ata_pad_free(ap, ap->dev); | ||
3586 | } | 3622 | } |
3587 | EXPORT_SYMBOL_GPL(ata_sas_port_stop); | 3623 | EXPORT_SYMBOL_GPL(ata_sas_port_stop); |
3588 | 3624 | ||