diff options
Diffstat (limited to 'drivers/ata/libata-scsi.c')
-rw-r--r-- | drivers/ata/libata-scsi.c | 119 |
1 files changed, 114 insertions, 5 deletions
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index b4ee28dec521..0088cdeb0b1e 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c | |||
@@ -33,6 +33,7 @@ | |||
33 | * | 33 | * |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #include <linux/slab.h> | ||
36 | #include <linux/kernel.h> | 37 | #include <linux/kernel.h> |
37 | #include <linux/blkdev.h> | 38 | #include <linux/blkdev.h> |
38 | #include <linux/spinlock.h> | 39 | #include <linux/spinlock.h> |
@@ -47,6 +48,7 @@ | |||
47 | #include <linux/hdreg.h> | 48 | #include <linux/hdreg.h> |
48 | #include <linux/uaccess.h> | 49 | #include <linux/uaccess.h> |
49 | #include <linux/suspend.h> | 50 | #include <linux/suspend.h> |
51 | #include <asm/unaligned.h> | ||
50 | 52 | ||
51 | #include "libata.h" | 53 | #include "libata.h" |
52 | 54 | ||
@@ -154,8 +156,7 @@ static ssize_t ata_scsi_lpm_put(struct device *dev, | |||
154 | */ | 156 | */ |
155 | for (i = 1; i < ARRAY_SIZE(link_pm_policy); i++) { | 157 | for (i = 1; i < ARRAY_SIZE(link_pm_policy); i++) { |
156 | const int len = strlen(link_pm_policy[i].name); | 158 | const int len = strlen(link_pm_policy[i].name); |
157 | if (strncmp(link_pm_policy[i].name, buf, len) == 0 && | 159 | if (strncmp(link_pm_policy[i].name, buf, len) == 0) { |
158 | buf[len] == '\n') { | ||
159 | policy = link_pm_policy[i].value; | 160 | policy = link_pm_policy[i].value; |
160 | break; | 161 | break; |
161 | } | 162 | } |
@@ -1097,7 +1098,7 @@ static int ata_scsi_dev_config(struct scsi_device *sdev, | |||
1097 | dev->flags |= ATA_DFLAG_NO_UNLOAD; | 1098 | dev->flags |= ATA_DFLAG_NO_UNLOAD; |
1098 | 1099 | ||
1099 | /* configure max sectors */ | 1100 | /* configure max sectors */ |
1100 | blk_queue_max_sectors(sdev->request_queue, dev->max_sectors); | 1101 | blk_queue_max_hw_sectors(sdev->request_queue, dev->max_sectors); |
1101 | 1102 | ||
1102 | if (dev->class == ATA_DEV_ATAPI) { | 1103 | if (dev->class == ATA_DEV_ATAPI) { |
1103 | struct request_queue *q = sdev->request_queue; | 1104 | struct request_queue *q = sdev->request_queue; |
@@ -1208,6 +1209,7 @@ void ata_scsi_slave_destroy(struct scsi_device *sdev) | |||
1208 | * ata_scsi_change_queue_depth - SCSI callback for queue depth config | 1209 | * ata_scsi_change_queue_depth - SCSI callback for queue depth config |
1209 | * @sdev: SCSI device to configure queue depth for | 1210 | * @sdev: SCSI device to configure queue depth for |
1210 | * @queue_depth: new queue depth | 1211 | * @queue_depth: new queue depth |
1212 | * @reason: calling context | ||
1211 | * | 1213 | * |
1212 | * This is libata standard hostt->change_queue_depth callback. | 1214 | * This is libata standard hostt->change_queue_depth callback. |
1213 | * SCSI will call into this callback when user tries to set queue | 1215 | * SCSI will call into this callback when user tries to set queue |
@@ -1219,12 +1221,16 @@ void ata_scsi_slave_destroy(struct scsi_device *sdev) | |||
1219 | * RETURNS: | 1221 | * RETURNS: |
1220 | * Newly configured queue depth. | 1222 | * Newly configured queue depth. |
1221 | */ | 1223 | */ |
1222 | int ata_scsi_change_queue_depth(struct scsi_device *sdev, int queue_depth) | 1224 | int ata_scsi_change_queue_depth(struct scsi_device *sdev, int queue_depth, |
1225 | int reason) | ||
1223 | { | 1226 | { |
1224 | struct ata_port *ap = ata_shost_to_port(sdev->host); | 1227 | struct ata_port *ap = ata_shost_to_port(sdev->host); |
1225 | struct ata_device *dev; | 1228 | struct ata_device *dev; |
1226 | unsigned long flags; | 1229 | unsigned long flags; |
1227 | 1230 | ||
1231 | if (reason != SCSI_QDEPTH_DEFAULT) | ||
1232 | return -EOPNOTSUPP; | ||
1233 | |||
1228 | if (queue_depth < 1 || queue_depth == sdev->queue_depth) | 1234 | if (queue_depth < 1 || queue_depth == sdev->queue_depth) |
1229 | return sdev->queue_depth; | 1235 | return sdev->queue_depth; |
1230 | 1236 | ||
@@ -1964,6 +1970,7 @@ static unsigned int ata_scsiop_inq_00(struct ata_scsi_args *args, u8 *rbuf) | |||
1964 | 0x80, /* page 0x80, unit serial no page */ | 1970 | 0x80, /* page 0x80, unit serial no page */ |
1965 | 0x83, /* page 0x83, device ident page */ | 1971 | 0x83, /* page 0x83, device ident page */ |
1966 | 0x89, /* page 0x89, ata info page */ | 1972 | 0x89, /* page 0x89, ata info page */ |
1973 | 0xb0, /* page 0xb0, block limits page */ | ||
1967 | 0xb1, /* page 0xb1, block device characteristics page */ | 1974 | 0xb1, /* page 0xb1, block device characteristics page */ |
1968 | }; | 1975 | }; |
1969 | 1976 | ||
@@ -2085,6 +2092,43 @@ static unsigned int ata_scsiop_inq_89(struct ata_scsi_args *args, u8 *rbuf) | |||
2085 | return 0; | 2092 | return 0; |
2086 | } | 2093 | } |
2087 | 2094 | ||
2095 | static unsigned int ata_scsiop_inq_b0(struct ata_scsi_args *args, u8 *rbuf) | ||
2096 | { | ||
2097 | u32 min_io_sectors; | ||
2098 | |||
2099 | rbuf[1] = 0xb0; | ||
2100 | rbuf[3] = 0x3c; /* required VPD size with unmap support */ | ||
2101 | |||
2102 | /* | ||
2103 | * Optimal transfer length granularity. | ||
2104 | * | ||
2105 | * This is always one physical block, but for disks with a smaller | ||
2106 | * logical than physical sector size we need to figure out what the | ||
2107 | * latter is. | ||
2108 | */ | ||
2109 | if (ata_id_has_large_logical_sectors(args->id)) | ||
2110 | min_io_sectors = ata_id_logical_per_physical_sectors(args->id); | ||
2111 | else | ||
2112 | min_io_sectors = 1; | ||
2113 | put_unaligned_be16(min_io_sectors, &rbuf[6]); | ||
2114 | |||
2115 | /* | ||
2116 | * Optimal unmap granularity. | ||
2117 | * | ||
2118 | * The ATA spec doesn't even know about a granularity or alignment | ||
2119 | * for the TRIM command. We can leave away most of the unmap related | ||
2120 | * VPD page entries, but we have specifify a granularity to signal | ||
2121 | * that we support some form of unmap - in thise case via WRITE SAME | ||
2122 | * with the unmap bit set. | ||
2123 | */ | ||
2124 | if (ata_id_has_trim(args->id)) { | ||
2125 | put_unaligned_be32(65535 * 512 / 8, &rbuf[20]); | ||
2126 | put_unaligned_be32(1, &rbuf[28]); | ||
2127 | } | ||
2128 | |||
2129 | return 0; | ||
2130 | } | ||
2131 | |||
2088 | static unsigned int ata_scsiop_inq_b1(struct ata_scsi_args *args, u8 *rbuf) | 2132 | static unsigned int ata_scsiop_inq_b1(struct ata_scsi_args *args, u8 *rbuf) |
2089 | { | 2133 | { |
2090 | int form_factor = ata_id_form_factor(args->id); | 2134 | int form_factor = ata_id_form_factor(args->id); |
@@ -2374,6 +2418,13 @@ static unsigned int ata_scsiop_read_cap(struct ata_scsi_args *args, u8 *rbuf) | |||
2374 | rbuf[13] = log_per_phys; | 2418 | rbuf[13] = log_per_phys; |
2375 | rbuf[14] = (lowest_aligned >> 8) & 0x3f; | 2419 | rbuf[14] = (lowest_aligned >> 8) & 0x3f; |
2376 | rbuf[15] = lowest_aligned; | 2420 | rbuf[15] = lowest_aligned; |
2421 | |||
2422 | if (ata_id_has_trim(args->id)) { | ||
2423 | rbuf[14] |= 0x80; /* TPE */ | ||
2424 | |||
2425 | if (ata_id_has_zero_after_trim(args->id)) | ||
2426 | rbuf[14] |= 0x40; /* TPRZ */ | ||
2427 | } | ||
2377 | } | 2428 | } |
2378 | 2429 | ||
2379 | return 0; | 2430 | return 0; |
@@ -2825,7 +2876,7 @@ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc) | |||
2825 | * write indication (used for PIO/DMA setup), result TF is | 2876 | * write indication (used for PIO/DMA setup), result TF is |
2826 | * copied back and we don't whine too much about its failure. | 2877 | * copied back and we don't whine too much about its failure. |
2827 | */ | 2878 | */ |
2828 | tf->flags = ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; | 2879 | tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
2829 | if (scmd->sc_data_direction == DMA_TO_DEVICE) | 2880 | if (scmd->sc_data_direction == DMA_TO_DEVICE) |
2830 | tf->flags |= ATA_TFLAG_WRITE; | 2881 | tf->flags |= ATA_TFLAG_WRITE; |
2831 | 2882 | ||
@@ -2896,6 +2947,58 @@ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc) | |||
2896 | return 1; | 2947 | return 1; |
2897 | } | 2948 | } |
2898 | 2949 | ||
2950 | static unsigned int ata_scsi_write_same_xlat(struct ata_queued_cmd *qc) | ||
2951 | { | ||
2952 | struct ata_taskfile *tf = &qc->tf; | ||
2953 | struct scsi_cmnd *scmd = qc->scsicmd; | ||
2954 | struct ata_device *dev = qc->dev; | ||
2955 | const u8 *cdb = scmd->cmnd; | ||
2956 | u64 block; | ||
2957 | u32 n_block; | ||
2958 | u32 size; | ||
2959 | void *buf; | ||
2960 | |||
2961 | /* we may not issue DMA commands if no DMA mode is set */ | ||
2962 | if (unlikely(!dev->dma_mode)) | ||
2963 | goto invalid_fld; | ||
2964 | |||
2965 | if (unlikely(scmd->cmd_len < 16)) | ||
2966 | goto invalid_fld; | ||
2967 | scsi_16_lba_len(cdb, &block, &n_block); | ||
2968 | |||
2969 | /* for now we only support WRITE SAME with the unmap bit set */ | ||
2970 | if (unlikely(!(cdb[1] & 0x8))) | ||
2971 | goto invalid_fld; | ||
2972 | |||
2973 | /* | ||
2974 | * WRITE SAME always has a sector sized buffer as payload, this | ||
2975 | * should never be a multiple entry S/G list. | ||
2976 | */ | ||
2977 | if (!scsi_sg_count(scmd)) | ||
2978 | goto invalid_fld; | ||
2979 | |||
2980 | buf = page_address(sg_page(scsi_sglist(scmd))); | ||
2981 | size = ata_set_lba_range_entries(buf, 512, block, n_block); | ||
2982 | |||
2983 | tf->protocol = ATA_PROT_DMA; | ||
2984 | tf->hob_feature = 0; | ||
2985 | tf->feature = ATA_DSM_TRIM; | ||
2986 | tf->hob_nsect = (size / 512) >> 8; | ||
2987 | tf->nsect = size / 512; | ||
2988 | tf->command = ATA_CMD_DSM; | ||
2989 | tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48 | | ||
2990 | ATA_TFLAG_WRITE; | ||
2991 | |||
2992 | ata_qc_set_pc_nbytes(qc); | ||
2993 | |||
2994 | return 0; | ||
2995 | |||
2996 | invalid_fld: | ||
2997 | ata_scsi_set_sense(scmd, ILLEGAL_REQUEST, 0x24, 0x00); | ||
2998 | /* "Invalid field in cdb" */ | ||
2999 | return 1; | ||
3000 | } | ||
3001 | |||
2899 | /** | 3002 | /** |
2900 | * ata_get_xlat_func - check if SCSI to ATA translation is possible | 3003 | * ata_get_xlat_func - check if SCSI to ATA translation is possible |
2901 | * @dev: ATA device | 3004 | * @dev: ATA device |
@@ -2920,6 +3023,9 @@ static inline ata_xlat_func_t ata_get_xlat_func(struct ata_device *dev, u8 cmd) | |||
2920 | case WRITE_16: | 3023 | case WRITE_16: |
2921 | return ata_scsi_rw_xlat; | 3024 | return ata_scsi_rw_xlat; |
2922 | 3025 | ||
3026 | case WRITE_SAME_16: | ||
3027 | return ata_scsi_write_same_xlat; | ||
3028 | |||
2923 | case SYNCHRONIZE_CACHE: | 3029 | case SYNCHRONIZE_CACHE: |
2924 | if (ata_try_flush_cache(dev)) | 3030 | if (ata_try_flush_cache(dev)) |
2925 | return ata_scsi_flush_xlat; | 3031 | return ata_scsi_flush_xlat; |
@@ -3109,6 +3215,9 @@ void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd, | |||
3109 | case 0x89: | 3215 | case 0x89: |
3110 | ata_scsi_rbuf_fill(&args, ata_scsiop_inq_89); | 3216 | ata_scsi_rbuf_fill(&args, ata_scsiop_inq_89); |
3111 | break; | 3217 | break; |
3218 | case 0xb0: | ||
3219 | ata_scsi_rbuf_fill(&args, ata_scsiop_inq_b0); | ||
3220 | break; | ||
3112 | case 0xb1: | 3221 | case 0xb1: |
3113 | ata_scsi_rbuf_fill(&args, ata_scsiop_inq_b1); | 3222 | ata_scsi_rbuf_fill(&args, ata_scsiop_inq_b1); |
3114 | break; | 3223 | break; |