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.c637
1 files changed, 548 insertions, 89 deletions
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
index c64169ca7ff0..698203bf4f69 100644
--- a/drivers/scsi/libata-scsi.c
+++ b/drivers/scsi/libata-scsi.c
@@ -40,10 +40,13 @@
40#include "scsi.h" 40#include "scsi.h"
41#include <scsi/scsi_host.h> 41#include <scsi/scsi_host.h>
42#include <linux/libata.h> 42#include <linux/libata.h>
43#include <linux/hdreg.h>
43#include <asm/uaccess.h> 44#include <asm/uaccess.h>
44 45
45#include "libata.h" 46#include "libata.h"
46 47
48#define SECTOR_SIZE 512
49
47typedef unsigned int (*ata_xlat_func_t)(struct ata_queued_cmd *qc, u8 *scsicmd); 50typedef unsigned int (*ata_xlat_func_t)(struct ata_queued_cmd *qc, u8 *scsicmd);
48static struct ata_device * 51static struct ata_device *
49ata_scsi_find_dev(struct ata_port *ap, struct scsi_device *scsidev); 52ata_scsi_find_dev(struct ata_port *ap, struct scsi_device *scsidev);
@@ -86,6 +89,150 @@ int ata_std_bios_param(struct scsi_device *sdev, struct block_device *bdev,
86 return 0; 89 return 0;
87} 90}
88 91
92/**
93 * ata_cmd_ioctl - Handler for HDIO_DRIVE_CMD ioctl
94 * @dev: Device to whom we are issuing command
95 * @arg: User provided data for issuing command
96 *
97 * LOCKING:
98 * Defined by the SCSI layer. We don't really care.
99 *
100 * RETURNS:
101 * Zero on success, negative errno on error.
102 */
103
104int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg)
105{
106 int rc = 0;
107 u8 scsi_cmd[MAX_COMMAND_SIZE];
108 u8 args[4], *argbuf = NULL;
109 int argsize = 0;
110 struct scsi_request *sreq;
111
112 if (NULL == (void *)arg)
113 return -EINVAL;
114
115 if (copy_from_user(args, arg, sizeof(args)))
116 return -EFAULT;
117
118 sreq = scsi_allocate_request(scsidev, GFP_KERNEL);
119 if (!sreq)
120 return -EINTR;
121
122 memset(scsi_cmd, 0, sizeof(scsi_cmd));
123
124 if (args[3]) {
125 argsize = SECTOR_SIZE * args[3];
126 argbuf = kmalloc(argsize, GFP_KERNEL);
127 if (argbuf == NULL) {
128 rc = -ENOMEM;
129 goto error;
130 }
131
132 scsi_cmd[1] = (4 << 1); /* PIO Data-in */
133 scsi_cmd[2] = 0x0e; /* no off.line or cc, read from dev,
134 block count in sector count field */
135 sreq->sr_data_direction = DMA_FROM_DEVICE;
136 } else {
137 scsi_cmd[1] = (3 << 1); /* Non-data */
138 /* scsi_cmd[2] is already 0 -- no off.line, cc, or data xfer */
139 sreq->sr_data_direction = DMA_NONE;
140 }
141
142 scsi_cmd[0] = ATA_16;
143
144 scsi_cmd[4] = args[2];
145 if (args[0] == WIN_SMART) { /* hack -- ide driver does this too... */
146 scsi_cmd[6] = args[3];
147 scsi_cmd[8] = args[1];
148 scsi_cmd[10] = 0x4f;
149 scsi_cmd[12] = 0xc2;
150 } else {
151 scsi_cmd[6] = args[1];
152 }
153 scsi_cmd[14] = args[0];
154
155 /* Good values for timeout and retries? Values below
156 from scsi_ioctl_send_command() for default case... */
157 scsi_wait_req(sreq, scsi_cmd, argbuf, argsize, (10*HZ), 5);
158
159 if (sreq->sr_result) {
160 rc = -EIO;
161 goto error;
162 }
163
164 /* Need code to retrieve data from check condition? */
165
166 if ((argbuf)
167 && copy_to_user((void *)(arg + sizeof(args)), argbuf, argsize))
168 rc = -EFAULT;
169error:
170 scsi_release_request(sreq);
171
172 if (argbuf)
173 kfree(argbuf);
174
175 return rc;
176}
177
178/**
179 * ata_task_ioctl - Handler for HDIO_DRIVE_TASK ioctl
180 * @dev: Device to whom we are issuing command
181 * @arg: User provided data for issuing command
182 *
183 * LOCKING:
184 * Defined by the SCSI layer. We don't really care.
185 *
186 * RETURNS:
187 * Zero on success, negative errno on error.
188 */
189int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg)
190{
191 int rc = 0;
192 u8 scsi_cmd[MAX_COMMAND_SIZE];
193 u8 args[7];
194 struct scsi_request *sreq;
195
196 if (NULL == (void *)arg)
197 return -EINVAL;
198
199 if (copy_from_user(args, arg, sizeof(args)))
200 return -EFAULT;
201
202 memset(scsi_cmd, 0, sizeof(scsi_cmd));
203 scsi_cmd[0] = ATA_16;
204 scsi_cmd[1] = (3 << 1); /* Non-data */
205 /* scsi_cmd[2] is already 0 -- no off.line, cc, or data xfer */
206 scsi_cmd[4] = args[1];
207 scsi_cmd[6] = args[2];
208 scsi_cmd[8] = args[3];
209 scsi_cmd[10] = args[4];
210 scsi_cmd[12] = args[5];
211 scsi_cmd[14] = args[0];
212
213 sreq = scsi_allocate_request(scsidev, GFP_KERNEL);
214 if (!sreq) {
215 rc = -EINTR;
216 goto error;
217 }
218
219 sreq->sr_data_direction = DMA_NONE;
220 /* Good values for timeout and retries? Values below
221 from scsi_ioctl_send_command() for default case... */
222 scsi_wait_req(sreq, scsi_cmd, NULL, 0, (10*HZ), 5);
223
224 if (sreq->sr_result) {
225 rc = -EIO;
226 goto error;
227 }
228
229 /* Need code to retrieve data from check condition? */
230
231error:
232 scsi_release_request(sreq);
233 return rc;
234}
235
89int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg) 236int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg)
90{ 237{
91 struct ata_port *ap; 238 struct ata_port *ap;
@@ -115,6 +262,16 @@ int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg)
115 return -EINVAL; 262 return -EINVAL;
116 return 0; 263 return 0;
117 264
265 case HDIO_DRIVE_CMD:
266 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
267 return -EACCES;
268 return ata_cmd_ioctl(scsidev, arg);
269
270 case HDIO_DRIVE_TASK:
271 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
272 return -EACCES;
273 return ata_task_ioctl(scsidev, arg);
274
118 default: 275 default:
119 rc = -ENOTTY; 276 rc = -ENOTTY;
120 break; 277 break;
@@ -173,23 +330,70 @@ struct ata_queued_cmd *ata_scsi_qc_new(struct ata_port *ap,
173} 330}
174 331
175/** 332/**
333 * ata_dump_status - user friendly display of error info
334 * @id: id of the port in question
335 * @tf: ptr to filled out taskfile
336 *
337 * Decode and dump the ATA error/status registers for the user so
338 * that they have some idea what really happened at the non
339 * make-believe layer.
340 *
341 * LOCKING:
342 * inherited from caller
343 */
344void ata_dump_status(unsigned id, struct ata_taskfile *tf)
345{
346 u8 stat = tf->command, err = tf->feature;
347
348 printk(KERN_WARNING "ata%u: status=0x%02x { ", id, stat);
349 if (stat & ATA_BUSY) {
350 printk("Busy }\n"); /* Data is not valid in this case */
351 } else {
352 if (stat & 0x40) printk("DriveReady ");
353 if (stat & 0x20) printk("DeviceFault ");
354 if (stat & 0x10) printk("SeekComplete ");
355 if (stat & 0x08) printk("DataRequest ");
356 if (stat & 0x04) printk("CorrectedError ");
357 if (stat & 0x02) printk("Index ");
358 if (stat & 0x01) printk("Error ");
359 printk("}\n");
360
361 if (err) {
362 printk(KERN_WARNING "ata%u: error=0x%02x { ", id, err);
363 if (err & 0x04) printk("DriveStatusError ");
364 if (err & 0x80) {
365 if (err & 0x04) printk("BadCRC ");
366 else printk("Sector ");
367 }
368 if (err & 0x40) printk("UncorrectableError ");
369 if (err & 0x10) printk("SectorIdNotFound ");
370 if (err & 0x02) printk("TrackZeroNotFound ");
371 if (err & 0x01) printk("AddrMarkNotFound ");
372 printk("}\n");
373 }
374 }
375}
376
377/**
176 * ata_to_sense_error - convert ATA error to SCSI error 378 * ata_to_sense_error - convert ATA error to SCSI error
177 * @qc: Command that we are erroring out
178 * @drv_stat: value contained in ATA status register 379 * @drv_stat: value contained in ATA status register
380 * @drv_err: value contained in ATA error register
381 * @sk: the sense key we'll fill out
382 * @asc: the additional sense code we'll fill out
383 * @ascq: the additional sense code qualifier we'll fill out
179 * 384 *
180 * Converts an ATA error into a SCSI error. While we are at it 385 * Converts an ATA error into a SCSI error. Fill out pointers to
181 * we decode and dump the ATA error for the user so that they 386 * SK, ASC, and ASCQ bytes for later use in fixed or descriptor
182 * have some idea what really happened at the non make-believe 387 * format sense blocks.
183 * layer.
184 * 388 *
185 * LOCKING: 389 * LOCKING:
186 * spin_lock_irqsave(host_set lock) 390 * spin_lock_irqsave(host_set lock)
187 */ 391 */
188 392void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc,
189void ata_to_sense_error(struct ata_queued_cmd *qc, u8 drv_stat) 393 u8 *ascq)
190{ 394{
191 struct scsi_cmnd *cmd = qc->scsicmd; 395 int i;
192 u8 err = 0; 396
193 /* Based on the 3ware driver translation table */ 397 /* Based on the 3ware driver translation table */
194 static unsigned char sense_table[][4] = { 398 static unsigned char sense_table[][4] = {
195 /* BBD|ECC|ID|MAR */ 399 /* BBD|ECC|ID|MAR */
@@ -230,96 +434,184 @@ void ata_to_sense_error(struct ata_queued_cmd *qc, u8 drv_stat)
230 {0x04, RECOVERED_ERROR, 0x11, 0x00}, // Recovered ECC error Medium error, recovered 434 {0x04, RECOVERED_ERROR, 0x11, 0x00}, // Recovered ECC error Medium error, recovered
231 {0xFF, 0xFF, 0xFF, 0xFF}, // END mark 435 {0xFF, 0xFF, 0xFF, 0xFF}, // END mark
232 }; 436 };
233 int i = 0;
234 437
235 /* 438 /*
236 * Is this an error we can process/parse 439 * Is this an error we can process/parse
237 */ 440 */
238 441 if (drv_stat & ATA_BUSY) {
239 if(drv_stat & ATA_ERR) 442 drv_err = 0; /* Ignore the err bits, they're invalid */
240 /* Read the err bits */
241 err = ata_chk_err(qc->ap);
242
243 /* Display the ATA level error info */
244
245 printk(KERN_WARNING "ata%u: status=0x%02x { ", qc->ap->id, drv_stat);
246 if(drv_stat & 0x80)
247 {
248 printk("Busy ");
249 err = 0; /* Data is not valid in this case */
250 } 443 }
251 else { 444
252 if(drv_stat & 0x40) printk("DriveReady "); 445 if (drv_err) {
253 if(drv_stat & 0x20) printk("DeviceFault "); 446 /* Look for drv_err */
254 if(drv_stat & 0x10) printk("SeekComplete "); 447 for (i = 0; sense_table[i][0] != 0xFF; i++) {
255 if(drv_stat & 0x08) printk("DataRequest "); 448 /* Look for best matches first */
256 if(drv_stat & 0x04) printk("CorrectedError "); 449 if ((sense_table[i][0] & drv_err) ==
257 if(drv_stat & 0x02) printk("Index "); 450 sense_table[i][0]) {
258 if(drv_stat & 0x01) printk("Error "); 451 *sk = sense_table[i][1];
452 *asc = sense_table[i][2];
453 *ascq = sense_table[i][3];
454 goto translate_done;
455 }
456 }
457 /* No immediate match */
458 printk(KERN_WARNING "ata%u: no sense translation for "
459 "error 0x%02x\n", id, drv_err);
259 } 460 }
260 printk("}\n"); 461
261 462 /* Fall back to interpreting status bits */
262 if(err) 463 for (i = 0; stat_table[i][0] != 0xFF; i++) {
263 { 464 if (stat_table[i][0] & drv_stat) {
264 printk(KERN_WARNING "ata%u: error=0x%02x { ", qc->ap->id, err); 465 *sk = stat_table[i][1];
265 if(err & 0x04) printk("DriveStatusError "); 466 *asc = stat_table[i][2];
266 if(err & 0x80) 467 *ascq = stat_table[i][3];
267 { 468 goto translate_done;
268 if(err & 0x04)
269 printk("BadCRC ");
270 else
271 printk("Sector ");
272 } 469 }
273 if(err & 0x40) printk("UncorrectableError "); 470 }
274 if(err & 0x10) printk("SectorIdNotFound "); 471 /* No error? Undecoded? */
275 if(err & 0x02) printk("TrackZeroNotFound "); 472 printk(KERN_WARNING "ata%u: no sense translation for status: 0x%02x\n",
276 if(err & 0x01) printk("AddrMarkNotFound "); 473 id, drv_stat);
277 printk("}\n"); 474
475 /* For our last chance pick, use medium read error because
476 * it's much more common than an ATA drive telling you a write
477 * has failed.
478 */
479 *sk = MEDIUM_ERROR;
480 *asc = 0x11; /* "unrecovered read error" */
481 *ascq = 0x04; /* "auto-reallocation failed" */
482
483 translate_done:
484 printk(KERN_ERR "ata%u: translated ATA stat/err 0x%02x/%02x to "
485 "SCSI SK/ASC/ASCQ 0x%x/%02x/%02x\n", id, drv_stat, drv_err,
486 *sk, *asc, *ascq);
487 return;
488}
489
490/*
491 * ata_gen_ata_desc_sense - Generate check condition sense block.
492 * @qc: Command that completed.
493 *
494 * This function is specific to the ATA descriptor format sense
495 * block specified for the ATA pass through commands. Regardless
496 * of whether the command errored or not, return a sense
497 * block. Copy all controller registers into the sense
498 * block. Clear sense key, ASC & ASCQ if there is no error.
499 *
500 * LOCKING:
501 * spin_lock_irqsave(host_set lock)
502 */
503void ata_gen_ata_desc_sense(struct ata_queued_cmd *qc)
504{
505 struct scsi_cmnd *cmd = qc->scsicmd;
506 struct ata_taskfile *tf = &qc->tf;
507 unsigned char *sb = cmd->sense_buffer;
508 unsigned char *desc = sb + 8;
509
510 memset(sb, 0, SCSI_SENSE_BUFFERSIZE);
511
512 cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
513
514 /*
515 * Read the controller registers.
516 */
517 assert(NULL != qc->ap->ops->tf_read);
518 qc->ap->ops->tf_read(qc->ap, tf);
278 519
279 /* Should we dump sector info here too ?? */ 520 /*
521 * Use ata_to_sense_error() to map status register bits
522 * onto sense key, asc & ascq.
523 */
524 if (unlikely(tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ))) {
525 ata_to_sense_error(qc->ap->id, tf->command, tf->feature,
526 &sb[1], &sb[2], &sb[3]);
527 sb[1] &= 0x0f;
280 } 528 }
281 529
530 /*
531 * Sense data is current and format is descriptor.
532 */
533 sb[0] = 0x72;
282 534
283 /* Look for err */ 535 desc[0] = 0x09;
284 while(sense_table[i][0] != 0xFF) 536
285 { 537 /*
286 /* Look for best matches first */ 538 * Set length of additional sense data.
287 if((sense_table[i][0] & err) == sense_table[i][0]) 539 * Since we only populate descriptor 0, the total
288 { 540 * length is the same (fixed) length as descriptor 0.
289 ata_scsi_set_sense(cmd, sense_table[i][1] /* sk */, 541 */
290 sense_table[i][2] /* asc */, 542 desc[1] = sb[7] = 14;
291 sense_table[i][3] /* ascq */ ); 543
292 return; 544 /*
293 } 545 * Copy registers into sense buffer.
294 i++; 546 */
547 desc[2] = 0x00;
548 desc[3] = tf->feature; /* == error reg */
549 desc[5] = tf->nsect;
550 desc[7] = tf->lbal;
551 desc[9] = tf->lbam;
552 desc[11] = tf->lbah;
553 desc[12] = tf->device;
554 desc[13] = tf->command; /* == status reg */
555
556 /*
557 * Fill in Extend bit, and the high order bytes
558 * if applicable.
559 */
560 if (tf->flags & ATA_TFLAG_LBA48) {
561 desc[2] |= 0x01;
562 desc[4] = tf->hob_nsect;
563 desc[6] = tf->hob_lbal;
564 desc[8] = tf->hob_lbam;
565 desc[10] = tf->hob_lbah;
295 } 566 }
296 /* No immediate match */ 567}
297 if(err)
298 printk(KERN_DEBUG "ata%u: no sense translation for 0x%02x\n", qc->ap->id, err);
299 568
300 i = 0; 569/**
301 /* Fall back to interpreting status bits */ 570 * ata_gen_fixed_sense - generate a SCSI fixed sense block
302 while(stat_table[i][0] != 0xFF) 571 * @qc: Command that we are erroring out
303 { 572 *
304 if(stat_table[i][0] & drv_stat) 573 * Leverage ata_to_sense_error() to give us the codes. Fit our
305 { 574 * LBA in here if there's room.
306 ata_scsi_set_sense(cmd, sense_table[i][1] /* sk */, 575 *
307 sense_table[i][2] /* asc */, 576 * LOCKING:
308 sense_table[i][3] /* ascq */ ); 577 * inherited from caller
309 return; 578 */
310 } 579void ata_gen_fixed_sense(struct ata_queued_cmd *qc)
311 i++; 580{
581 struct scsi_cmnd *cmd = qc->scsicmd;
582 struct ata_taskfile *tf = &qc->tf;
583 unsigned char *sb = cmd->sense_buffer;
584
585 memset(sb, 0, SCSI_SENSE_BUFFERSIZE);
586
587 cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
588
589 /*
590 * Read the controller registers.
591 */
592 assert(NULL != qc->ap->ops->tf_read);
593 qc->ap->ops->tf_read(qc->ap, tf);
594
595 /*
596 * Use ata_to_sense_error() to map status register bits
597 * onto sense key, asc & ascq.
598 */
599 if (unlikely(tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ))) {
600 ata_to_sense_error(qc->ap->id, tf->command, tf->feature,
601 &sb[2], &sb[12], &sb[13]);
602 sb[2] &= 0x0f;
312 } 603 }
313 /* No error ?? */
314 printk(KERN_ERR "ata%u: called with no error (%02X)!\n", qc->ap->id, drv_stat);
315 /* additional-sense-code[-qualifier] */
316 604
317 if (cmd->sc_data_direction == DMA_FROM_DEVICE) { 605 sb[0] = 0x70;
318 ata_scsi_set_sense(cmd, MEDIUM_ERROR, 0x11, 0x4); 606 sb[7] = 0x0a;
319 /* "unrecovered read error" */ 607
320 } else { 608 if (tf->flags & ATA_TFLAG_LBA && !(tf->flags & ATA_TFLAG_LBA48)) {
321 ata_scsi_set_sense(cmd, MEDIUM_ERROR, 0xc, 0x2); 609 /* A small (28b) LBA will fit in the 32b info field */
322 /* "write error - auto-reallocation failed" */ 610 sb[0] |= 0x80; /* set valid bit */
611 sb[3] = tf->device & 0x0f;
612 sb[4] = tf->lbah;
613 sb[5] = tf->lbam;
614 sb[6] = tf->lbal;
323 } 615 }
324} 616}
325 617
@@ -864,11 +1156,36 @@ nothing_to_do:
864static int ata_scsi_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) 1156static int ata_scsi_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat)
865{ 1157{
866 struct scsi_cmnd *cmd = qc->scsicmd; 1158 struct scsi_cmnd *cmd = qc->scsicmd;
1159 int need_sense = drv_stat & (ATA_ERR | ATA_BUSY | ATA_DRQ);
1160
1161 /* For ATA pass thru (SAT) commands, generate a sense block if
1162 * user mandated it or if there's an error. Note that if we
1163 * generate because the user forced us to, a check condition
1164 * is generated and the ATA register values are returned
1165 * whether the command completed successfully or not. If there
1166 * was no error, SK, ASC and ASCQ will all be zero.
1167 */
1168 if (((cmd->cmnd[0] == ATA_16) || (cmd->cmnd[0] == ATA_12)) &&
1169 ((cmd->cmnd[2] & 0x20) || need_sense)) {
1170 ata_gen_ata_desc_sense(qc);
1171 } else {
1172 if (!need_sense) {
1173 cmd->result = SAM_STAT_GOOD;
1174 } else {
1175 /* TODO: decide which descriptor format to use
1176 * for 48b LBA devices and call that here
1177 * instead of the fixed desc, which is only
1178 * good for smaller LBA (and maybe CHS?)
1179 * devices.
1180 */
1181 ata_gen_fixed_sense(qc);
1182 }
1183 }
867 1184
868 if (unlikely(drv_stat & (ATA_ERR | ATA_BUSY | ATA_DRQ))) 1185 if (need_sense) {
869 ata_to_sense_error(qc, drv_stat); 1186 /* The ata_gen_..._sense routines fill in tf */
870 else 1187 ata_dump_status(qc->ap->id, &qc->tf);
871 cmd->result = SAM_STAT_GOOD; 1188 }
872 1189
873 qc->scsidone(cmd); 1190 qc->scsidone(cmd);
874 1191
@@ -1775,6 +2092,143 @@ ata_scsi_find_dev(struct ata_port *ap, struct scsi_device *scsidev)
1775 return dev; 2092 return dev;
1776} 2093}
1777 2094
2095/*
2096 * ata_scsi_map_proto - Map pass-thru protocol value to taskfile value.
2097 * @byte1: Byte 1 from pass-thru CDB.
2098 *
2099 * RETURNS:
2100 * ATA_PROT_UNKNOWN if mapping failed/unimplemented, protocol otherwise.
2101 */
2102static u8
2103ata_scsi_map_proto(u8 byte1)
2104{
2105 switch((byte1 & 0x1e) >> 1) {
2106 case 3: /* Non-data */
2107 return ATA_PROT_NODATA;
2108
2109 case 6: /* DMA */
2110 return ATA_PROT_DMA;
2111
2112 case 4: /* PIO Data-in */
2113 case 5: /* PIO Data-out */
2114 if (byte1 & 0xe0) {
2115 return ATA_PROT_PIO_MULT;
2116 }
2117 return ATA_PROT_PIO;
2118
2119 case 10: /* Device Reset */
2120 case 0: /* Hard Reset */
2121 case 1: /* SRST */
2122 case 2: /* Bus Idle */
2123 case 7: /* Packet */
2124 case 8: /* DMA Queued */
2125 case 9: /* Device Diagnostic */
2126 case 11: /* UDMA Data-in */
2127 case 12: /* UDMA Data-Out */
2128 case 13: /* FPDMA */
2129 default: /* Reserved */
2130 break;
2131 }
2132
2133 return ATA_PROT_UNKNOWN;
2134}
2135
2136/**
2137 * ata_scsi_pass_thru - convert ATA pass-thru CDB to taskfile
2138 * @qc: command structure to be initialized
2139 * @cmd: SCSI command to convert
2140 *
2141 * Handles either 12 or 16-byte versions of the CDB.
2142 *
2143 * RETURNS:
2144 * Zero on success, non-zero on failure.
2145 */
2146static unsigned int
2147ata_scsi_pass_thru(struct ata_queued_cmd *qc, u8 *scsicmd)
2148{
2149 struct ata_taskfile *tf = &(qc->tf);
2150 struct scsi_cmnd *cmd = qc->scsicmd;
2151
2152 if ((tf->protocol = ata_scsi_map_proto(scsicmd[1])) == ATA_PROT_UNKNOWN)
2153 return 1;
2154
2155 /*
2156 * 12 and 16 byte CDBs use different offsets to
2157 * provide the various register values.
2158 */
2159 if (scsicmd[0] == ATA_16) {
2160 /*
2161 * 16-byte CDB - may contain extended commands.
2162 *
2163 * If that is the case, copy the upper byte register values.
2164 */
2165 if (scsicmd[1] & 0x01) {
2166 tf->hob_feature = scsicmd[3];
2167 tf->hob_nsect = scsicmd[5];
2168 tf->hob_lbal = scsicmd[7];
2169 tf->hob_lbam = scsicmd[9];
2170 tf->hob_lbah = scsicmd[11];
2171 tf->flags |= ATA_TFLAG_LBA48;
2172 } else
2173 tf->flags &= ~ATA_TFLAG_LBA48;
2174
2175 /*
2176 * Always copy low byte, device and command registers.
2177 */
2178 tf->feature = scsicmd[4];
2179 tf->nsect = scsicmd[6];
2180 tf->lbal = scsicmd[8];
2181 tf->lbam = scsicmd[10];
2182 tf->lbah = scsicmd[12];
2183 tf->device = scsicmd[13];
2184 tf->command = scsicmd[14];
2185 } else {
2186 /*
2187 * 12-byte CDB - incapable of extended commands.
2188 */
2189 tf->flags &= ~ATA_TFLAG_LBA48;
2190
2191 tf->feature = scsicmd[3];
2192 tf->nsect = scsicmd[4];
2193 tf->lbal = scsicmd[5];
2194 tf->lbam = scsicmd[6];
2195 tf->lbah = scsicmd[7];
2196 tf->device = scsicmd[8];
2197 tf->command = scsicmd[9];
2198 }
2199
2200 /*
2201 * Filter SET_FEATURES - XFER MODE command -- otherwise,
2202 * SET_FEATURES - XFER MODE must be preceded/succeeded
2203 * by an update to hardware-specific registers for each
2204 * controller (i.e. the reason for ->set_piomode(),
2205 * ->set_dmamode(), and ->post_set_mode() hooks).
2206 */
2207 if ((tf->command == ATA_CMD_SET_FEATURES)
2208 && (tf->feature == SETFEATURES_XFER))
2209 return 1;
2210
2211 /*
2212 * Set flags so that all registers will be written,
2213 * and pass on write indication (used for PIO/DMA
2214 * setup.)
2215 */
2216 tf->flags |= (ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE);
2217
2218 if (cmd->sc_data_direction == DMA_TO_DEVICE)
2219 tf->flags |= ATA_TFLAG_WRITE;
2220
2221 /*
2222 * Set transfer length.
2223 *
2224 * TODO: find out if we need to do more here to
2225 * cover scatter/gather case.
2226 */
2227 qc->nsect = cmd->bufflen / ATA_SECT_SIZE;
2228
2229 return 0;
2230}
2231
1778/** 2232/**
1779 * ata_get_xlat_func - check if SCSI to ATA translation is possible 2233 * ata_get_xlat_func - check if SCSI to ATA translation is possible
1780 * @dev: ATA device 2234 * @dev: ATA device
@@ -1807,6 +2261,11 @@ static inline ata_xlat_func_t ata_get_xlat_func(struct ata_device *dev, u8 cmd)
1807 case VERIFY: 2261 case VERIFY:
1808 case VERIFY_16: 2262 case VERIFY_16:
1809 return ata_scsi_verify_xlat; 2263 return ata_scsi_verify_xlat;
2264
2265 case ATA_12:
2266 case ATA_16:
2267 return ata_scsi_pass_thru;
2268
1810 case START_STOP: 2269 case START_STOP:
1811 return ata_scsi_start_stop_xlat; 2270 return ata_scsi_start_stop_xlat;
1812 } 2271 }
@@ -1965,7 +2424,7 @@ void ata_scsi_simulate(u16 *id,
1965 ata_scsi_rbuf_fill(&args, ata_scsiop_report_luns); 2424 ata_scsi_rbuf_fill(&args, ata_scsiop_report_luns);
1966 break; 2425 break;
1967 2426
1968 /* mandantory commands we haven't implemented yet */ 2427 /* mandatory commands we haven't implemented yet */
1969 case REQUEST_SENSE: 2428 case REQUEST_SENSE:
1970 2429
1971 /* all other commands */ 2430 /* all other commands */