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.c146
1 files changed, 75 insertions, 71 deletions
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
index bb30fcdc9297..2282c04fee46 100644
--- a/drivers/scsi/libata-scsi.c
+++ b/drivers/scsi/libata-scsi.c
@@ -38,6 +38,7 @@
38#include <linux/spinlock.h> 38#include <linux/spinlock.h>
39#include <scsi/scsi.h> 39#include <scsi/scsi.h>
40#include <scsi/scsi_host.h> 40#include <scsi/scsi_host.h>
41#include <scsi/scsi_eh.h>
41#include <scsi/scsi_device.h> 42#include <scsi/scsi_device.h>
42#include <scsi/scsi_request.h> 43#include <scsi/scsi_request.h>
43#include <linux/libata.h> 44#include <linux/libata.h>
@@ -147,7 +148,8 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg)
147 u8 scsi_cmd[MAX_COMMAND_SIZE]; 148 u8 scsi_cmd[MAX_COMMAND_SIZE];
148 u8 args[4], *argbuf = NULL; 149 u8 args[4], *argbuf = NULL;
149 int argsize = 0; 150 int argsize = 0;
150 struct scsi_request *sreq; 151 struct scsi_sense_hdr sshdr;
152 enum dma_data_direction data_dir;
151 153
152 if (NULL == (void *)arg) 154 if (NULL == (void *)arg)
153 return -EINVAL; 155 return -EINVAL;
@@ -155,10 +157,6 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg)
155 if (copy_from_user(args, arg, sizeof(args))) 157 if (copy_from_user(args, arg, sizeof(args)))
156 return -EFAULT; 158 return -EFAULT;
157 159
158 sreq = scsi_allocate_request(scsidev, GFP_KERNEL);
159 if (!sreq)
160 return -EINTR;
161
162 memset(scsi_cmd, 0, sizeof(scsi_cmd)); 160 memset(scsi_cmd, 0, sizeof(scsi_cmd));
163 161
164 if (args[3]) { 162 if (args[3]) {
@@ -172,11 +170,11 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg)
172 scsi_cmd[1] = (4 << 1); /* PIO Data-in */ 170 scsi_cmd[1] = (4 << 1); /* PIO Data-in */
173 scsi_cmd[2] = 0x0e; /* no off.line or cc, read from dev, 171 scsi_cmd[2] = 0x0e; /* no off.line or cc, read from dev,
174 block count in sector count field */ 172 block count in sector count field */
175 sreq->sr_data_direction = DMA_FROM_DEVICE; 173 data_dir = DMA_FROM_DEVICE;
176 } else { 174 } else {
177 scsi_cmd[1] = (3 << 1); /* Non-data */ 175 scsi_cmd[1] = (3 << 1); /* Non-data */
178 /* scsi_cmd[2] is already 0 -- no off.line, cc, or data xfer */ 176 /* scsi_cmd[2] is already 0 -- no off.line, cc, or data xfer */
179 sreq->sr_data_direction = DMA_NONE; 177 data_dir = DMA_NONE;
180 } 178 }
181 179
182 scsi_cmd[0] = ATA_16; 180 scsi_cmd[0] = ATA_16;
@@ -194,9 +192,8 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg)
194 192
195 /* Good values for timeout and retries? Values below 193 /* Good values for timeout and retries? Values below
196 from scsi_ioctl_send_command() for default case... */ 194 from scsi_ioctl_send_command() for default case... */
197 scsi_wait_req(sreq, scsi_cmd, argbuf, argsize, (10*HZ), 5); 195 if (scsi_execute_req(scsidev, scsi_cmd, data_dir, argbuf, argsize,
198 196 &sshdr, (10*HZ), 5)) {
199 if (sreq->sr_result) {
200 rc = -EIO; 197 rc = -EIO;
201 goto error; 198 goto error;
202 } 199 }
@@ -207,8 +204,6 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg)
207 && copy_to_user((void *)(arg + sizeof(args)), argbuf, argsize)) 204 && copy_to_user((void *)(arg + sizeof(args)), argbuf, argsize))
208 rc = -EFAULT; 205 rc = -EFAULT;
209error: 206error:
210 scsi_release_request(sreq);
211
212 if (argbuf) 207 if (argbuf)
213 kfree(argbuf); 208 kfree(argbuf);
214 209
@@ -231,7 +226,7 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg)
231 int rc = 0; 226 int rc = 0;
232 u8 scsi_cmd[MAX_COMMAND_SIZE]; 227 u8 scsi_cmd[MAX_COMMAND_SIZE];
233 u8 args[7]; 228 u8 args[7];
234 struct scsi_request *sreq; 229 struct scsi_sense_hdr sshdr;
235 230
236 if (NULL == (void *)arg) 231 if (NULL == (void *)arg)
237 return -EINVAL; 232 return -EINVAL;
@@ -250,26 +245,13 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg)
250 scsi_cmd[12] = args[5]; 245 scsi_cmd[12] = args[5];
251 scsi_cmd[14] = args[0]; 246 scsi_cmd[14] = args[0];
252 247
253 sreq = scsi_allocate_request(scsidev, GFP_KERNEL);
254 if (!sreq) {
255 rc = -EINTR;
256 goto error;
257 }
258
259 sreq->sr_data_direction = DMA_NONE;
260 /* Good values for timeout and retries? Values below 248 /* Good values for timeout and retries? Values below
261 from scsi_ioctl_send_command() for default case... */ 249 from scsi_ioctl_send_command() for default case... */
262 scsi_wait_req(sreq, scsi_cmd, NULL, 0, (10*HZ), 5); 250 if (scsi_execute_req(scsidev, scsi_cmd, DMA_NONE, NULL, 0, &sshdr,
263 251 (10*HZ), 5))
264 if (sreq->sr_result) {
265 rc = -EIO; 252 rc = -EIO;
266 goto error;
267 }
268 253
269 /* Need code to retrieve data from check condition? */ 254 /* Need code to retrieve data from check condition? */
270
271error:
272 scsi_release_request(sreq);
273 return rc; 255 return rc;
274} 256}
275 257
@@ -1129,6 +1111,8 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm
1129 * length 0 means transfer 0 block of data. 1111 * length 0 means transfer 0 block of data.
1130 * However, for ATA R/W commands, sector count 0 means 1112 * However, for ATA R/W commands, sector count 0 means
1131 * 256 or 65536 sectors, not 0 sectors as in SCSI. 1113 * 256 or 65536 sectors, not 0 sectors as in SCSI.
1114 *
1115 * WARNING: one or two older ATA drives treat 0 as 0...
1132 */ 1116 */
1133 goto nothing_to_do; 1117 goto nothing_to_do;
1134 1118
@@ -1971,22 +1955,44 @@ void ata_scsi_badcmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *), u8
1971 done(cmd); 1955 done(cmd);
1972} 1956}
1973 1957
1974void atapi_request_sense(struct ata_port *ap, struct ata_device *dev, 1958static int atapi_sense_complete(struct ata_queued_cmd *qc,unsigned int err_mask)
1975 struct scsi_cmnd *cmd)
1976{ 1959{
1977 DECLARE_COMPLETION(wait); 1960 if (err_mask && ((err_mask & AC_ERR_DEV) == 0))
1978 struct ata_queued_cmd *qc; 1961 /* FIXME: not quite right; we don't want the
1979 unsigned long flags; 1962 * translation of taskfile registers into
1980 int rc; 1963 * a sense descriptors, since that's only
1964 * correct for ATA, not ATAPI
1965 */
1966 ata_gen_ata_desc_sense(qc);
1981 1967
1982 DPRINTK("ATAPI request sense\n"); 1968 qc->scsidone(qc->scsicmd);
1969 return 0;
1970}
1983 1971
1984 qc = ata_qc_new_init(ap, dev); 1972/* is it pointless to prefer PIO for "safety reasons"? */
1985 BUG_ON(qc == NULL); 1973static inline int ata_pio_use_silly(struct ata_port *ap)
1974{
1975 return (ap->flags & ATA_FLAG_PIO_DMA);
1976}
1977
1978static void atapi_request_sense(struct ata_queued_cmd *qc)
1979{
1980 struct ata_port *ap = qc->ap;
1981 struct scsi_cmnd *cmd = qc->scsicmd;
1982
1983 DPRINTK("ATAPI request sense\n");
1986 1984
1987 /* FIXME: is this needed? */ 1985 /* FIXME: is this needed? */
1988 memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer)); 1986 memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
1989 1987
1988 ap->ops->tf_read(ap, &qc->tf);
1989
1990 /* fill these in, for the case where they are -not- overwritten */
1991 cmd->sense_buffer[0] = 0x70;
1992 cmd->sense_buffer[2] = qc->tf.feature >> 4;
1993
1994 ata_qc_reinit(qc);
1995
1990 ata_sg_init_one(qc, cmd->sense_buffer, sizeof(cmd->sense_buffer)); 1996 ata_sg_init_one(qc, cmd->sense_buffer, sizeof(cmd->sense_buffer));
1991 qc->dma_dir = DMA_FROM_DEVICE; 1997 qc->dma_dir = DMA_FROM_DEVICE;
1992 1998
@@ -1997,22 +2003,20 @@ void atapi_request_sense(struct ata_port *ap, struct ata_device *dev,
1997 qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; 2003 qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
1998 qc->tf.command = ATA_CMD_PACKET; 2004 qc->tf.command = ATA_CMD_PACKET;
1999 2005
2000 qc->tf.protocol = ATA_PROT_ATAPI; 2006 if (ata_pio_use_silly(ap)) {
2001 qc->tf.lbam = (8 * 1024) & 0xff; 2007 qc->tf.protocol = ATA_PROT_ATAPI_DMA;
2002 qc->tf.lbah = (8 * 1024) >> 8; 2008 qc->tf.feature |= ATAPI_PKT_DMA;
2009 } else {
2010 qc->tf.protocol = ATA_PROT_ATAPI;
2011 qc->tf.lbam = (8 * 1024) & 0xff;
2012 qc->tf.lbah = (8 * 1024) >> 8;
2013 }
2003 qc->nbytes = SCSI_SENSE_BUFFERSIZE; 2014 qc->nbytes = SCSI_SENSE_BUFFERSIZE;
2004 2015
2005 qc->waiting = &wait; 2016 qc->complete_fn = atapi_sense_complete;
2006 qc->complete_fn = ata_qc_complete_noop;
2007
2008 spin_lock_irqsave(&ap->host_set->lock, flags);
2009 rc = ata_qc_issue(qc);
2010 spin_unlock_irqrestore(&ap->host_set->lock, flags);
2011 2017
2012 if (rc) 2018 if (ata_qc_issue(qc))
2013 ata_port_disable(ap); 2019 ata_qc_complete(qc, AC_ERR_OTHER);
2014 else
2015 wait_for_completion(&wait);
2016 2020
2017 DPRINTK("EXIT\n"); 2021 DPRINTK("EXIT\n");
2018} 2022}
@@ -2024,19 +2028,8 @@ static int atapi_qc_complete(struct ata_queued_cmd *qc, unsigned int err_mask)
2024 VPRINTK("ENTER, err_mask 0x%X\n", err_mask); 2028 VPRINTK("ENTER, err_mask 0x%X\n", err_mask);
2025 2029
2026 if (unlikely(err_mask & AC_ERR_DEV)) { 2030 if (unlikely(err_mask & AC_ERR_DEV)) {
2027 DPRINTK("request check condition\n");
2028
2029 /* FIXME: command completion with check condition
2030 * but no sense causes the error handler to run,
2031 * which then issues REQUEST SENSE, fills in the sense
2032 * buffer, and completes the command (for the second
2033 * time). We need to issue REQUEST SENSE some other
2034 * way, to avoid completing the command twice.
2035 */
2036 cmd->result = SAM_STAT_CHECK_CONDITION; 2031 cmd->result = SAM_STAT_CHECK_CONDITION;
2037 2032 atapi_request_sense(qc);
2038 qc->scsidone(cmd);
2039
2040 return 1; 2033 return 1;
2041 } 2034 }
2042 2035
@@ -2051,7 +2044,7 @@ static int atapi_qc_complete(struct ata_queued_cmd *qc, unsigned int err_mask)
2051 else { 2044 else {
2052 u8 *scsicmd = cmd->cmnd; 2045 u8 *scsicmd = cmd->cmnd;
2053 2046
2054 if (scsicmd[0] == INQUIRY) { 2047 if ((scsicmd[0] == INQUIRY) && ((scsicmd[1] & 0x03) == 0)) {
2055 u8 *buf = NULL; 2048 u8 *buf = NULL;
2056 unsigned int buflen; 2049 unsigned int buflen;
2057 2050
@@ -2065,9 +2058,6 @@ static int atapi_qc_complete(struct ata_queued_cmd *qc, unsigned int err_mask)
2065 * device. 2) Ensure response data format / ATAPI information 2058 * device. 2) Ensure response data format / ATAPI information
2066 * are always correct. 2059 * are always correct.
2067 */ 2060 */
2068 /* FIXME: do we ever override EVPD pages and the like, with
2069 * this code?
2070 */
2071 if (buf[2] == 0) { 2061 if (buf[2] == 0) {
2072 buf[2] = 0x5; 2062 buf[2] = 0x5;
2073 buf[3] = 0x32; 2063 buf[3] = 0x32;
@@ -2180,9 +2170,12 @@ ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev)
2180 if (unlikely(!ata_dev_present(dev))) 2170 if (unlikely(!ata_dev_present(dev)))
2181 return NULL; 2171 return NULL;
2182 2172
2183 if (!atapi_enabled) { 2173 if (!atapi_enabled || (ap->flags & ATA_FLAG_NO_ATAPI)) {
2184 if (unlikely(dev->class == ATA_DEV_ATAPI)) 2174 if (unlikely(dev->class == ATA_DEV_ATAPI)) {
2175 printk(KERN_WARNING "ata%u(%u): WARNING: ATAPI is %s, device ignored.\n",
2176 ap->id, dev->devno, atapi_enabled ? "not supported with this driver" : "disabled");
2185 return NULL; 2177 return NULL;
2178 }
2186 } 2179 }
2187 2180
2188 return dev; 2181 return dev;
@@ -2246,7 +2239,7 @@ ata_scsi_pass_thru(struct ata_queued_cmd *qc, const u8 *scsicmd)
2246 struct scsi_cmnd *cmd = qc->scsicmd; 2239 struct scsi_cmnd *cmd = qc->scsicmd;
2247 2240
2248 if ((tf->protocol = ata_scsi_map_proto(scsicmd[1])) == ATA_PROT_UNKNOWN) 2241 if ((tf->protocol = ata_scsi_map_proto(scsicmd[1])) == ATA_PROT_UNKNOWN)
2249 return 1; 2242 goto invalid_fld;
2250 2243
2251 /* 2244 /*
2252 * 12 and 16 byte CDBs use different offsets to 2245 * 12 and 16 byte CDBs use different offsets to
@@ -2292,6 +2285,12 @@ ata_scsi_pass_thru(struct ata_queued_cmd *qc, const u8 *scsicmd)
2292 tf->device = scsicmd[8]; 2285 tf->device = scsicmd[8];
2293 tf->command = scsicmd[9]; 2286 tf->command = scsicmd[9];
2294 } 2287 }
2288 /*
2289 * If slave is possible, enforce correct master/slave bit
2290 */
2291 if (qc->ap->flags & ATA_FLAG_SLAVE_POSS)
2292 tf->device = qc->dev->devno ?
2293 tf->device | ATA_DEV1 : tf->device & ~ATA_DEV1;
2295 2294
2296 /* 2295 /*
2297 * Filter SET_FEATURES - XFER MODE command -- otherwise, 2296 * Filter SET_FEATURES - XFER MODE command -- otherwise,
@@ -2302,7 +2301,7 @@ ata_scsi_pass_thru(struct ata_queued_cmd *qc, const u8 *scsicmd)
2302 */ 2301 */
2303 if ((tf->command == ATA_CMD_SET_FEATURES) 2302 if ((tf->command == ATA_CMD_SET_FEATURES)
2304 && (tf->feature == SETFEATURES_XFER)) 2303 && (tf->feature == SETFEATURES_XFER))
2305 return 1; 2304 goto invalid_fld;
2306 2305
2307 /* 2306 /*
2308 * Set flags so that all registers will be written, 2307 * Set flags so that all registers will be written,
@@ -2323,6 +2322,11 @@ ata_scsi_pass_thru(struct ata_queued_cmd *qc, const u8 *scsicmd)
2323 qc->nsect = cmd->bufflen / ATA_SECT_SIZE; 2322 qc->nsect = cmd->bufflen / ATA_SECT_SIZE;
2324 2323
2325 return 0; 2324 return 0;
2325
2326 invalid_fld:
2327 ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x24, 0x00);
2328 /* "Invalid field in cdb" */
2329 return 1;
2326} 2330}
2327 2331
2328/** 2332/**