diff options
Diffstat (limited to 'drivers/ata/libata-scsi.c')
-rw-r--r-- | drivers/ata/libata-scsi.c | 75 |
1 files changed, 56 insertions, 19 deletions
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 1cea18f62abc..0562b0a49f3b 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 | /** |
@@ -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 |
@@ -2543,7 +2582,8 @@ static unsigned int atapi_xlat(struct ata_queued_cmd *qc) | |||
2543 | qc->tf.protocol = ATAPI_PROT_DMA; | 2582 | qc->tf.protocol = ATAPI_PROT_DMA; |
2544 | qc->tf.feature |= ATAPI_PKT_DMA; | 2583 | qc->tf.feature |= ATAPI_PKT_DMA; |
2545 | 2584 | ||
2546 | if (atapi_dmadir && (scmd->sc_data_direction != DMA_TO_DEVICE)) | 2585 | if ((dev->flags & ATA_DFLAG_DMADIR) && |
2586 | (scmd->sc_data_direction != DMA_TO_DEVICE)) | ||
2547 | /* some SATA bridges need us to indicate data xfer direction */ | 2587 | /* some SATA bridges need us to indicate data xfer direction */ |
2548 | qc->tf.feature |= ATAPI_DMADIR; | 2588 | qc->tf.feature |= ATAPI_DMADIR; |
2549 | } | 2589 | } |
@@ -3555,7 +3595,7 @@ EXPORT_SYMBOL_GPL(ata_sas_port_alloc); | |||
3555 | * @ap: Port to initialize | 3595 | * @ap: Port to initialize |
3556 | * | 3596 | * |
3557 | * Called just after data structures for each port are | 3597 | * Called just after data structures for each port are |
3558 | * initialized. Allocates DMA pad. | 3598 | * initialized. |
3559 | * | 3599 | * |
3560 | * May be used as the port_start() entry in ata_port_operations. | 3600 | * May be used as the port_start() entry in ata_port_operations. |
3561 | * | 3601 | * |
@@ -3564,7 +3604,7 @@ EXPORT_SYMBOL_GPL(ata_sas_port_alloc); | |||
3564 | */ | 3604 | */ |
3565 | int ata_sas_port_start(struct ata_port *ap) | 3605 | int ata_sas_port_start(struct ata_port *ap) |
3566 | { | 3606 | { |
3567 | return ata_pad_alloc(ap, ap->dev); | 3607 | return 0; |
3568 | } | 3608 | } |
3569 | EXPORT_SYMBOL_GPL(ata_sas_port_start); | 3609 | EXPORT_SYMBOL_GPL(ata_sas_port_start); |
3570 | 3610 | ||
@@ -3572,8 +3612,6 @@ EXPORT_SYMBOL_GPL(ata_sas_port_start); | |||
3572 | * ata_port_stop - Undo ata_sas_port_start() | 3612 | * ata_port_stop - Undo ata_sas_port_start() |
3573 | * @ap: Port to shut down | 3613 | * @ap: Port to shut down |
3574 | * | 3614 | * |
3575 | * Frees the DMA pad. | ||
3576 | * | ||
3577 | * May be used as the port_stop() entry in ata_port_operations. | 3615 | * May be used as the port_stop() entry in ata_port_operations. |
3578 | * | 3616 | * |
3579 | * LOCKING: | 3617 | * LOCKING: |
@@ -3582,7 +3620,6 @@ EXPORT_SYMBOL_GPL(ata_sas_port_start); | |||
3582 | 3620 | ||
3583 | void ata_sas_port_stop(struct ata_port *ap) | 3621 | void ata_sas_port_stop(struct ata_port *ap) |
3584 | { | 3622 | { |
3585 | ata_pad_free(ap, ap->dev); | ||
3586 | } | 3623 | } |
3587 | EXPORT_SYMBOL_GPL(ata_sas_port_stop); | 3624 | EXPORT_SYMBOL_GPL(ata_sas_port_stop); |
3588 | 3625 | ||