aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/scsi/libata-scsi.c646
-rw-r--r--drivers/scsi/libata.h3
-rw-r--r--include/scsi/scsi.h3
3 files changed, 552 insertions, 100 deletions
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
index 104fd9a63e73..98057563a3cc 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);
@@ -78,6 +81,148 @@ int ata_std_bios_param(struct scsi_device *sdev, struct block_device *bdev,
78 return 0; 81 return 0;
79} 82}
80 83
84/**
85 * ata_cmd_ioctl - Handler for HDIO_DRIVE_CMD ioctl
86 * @dev: Device to whom we are issuing command
87 * @arg: User provided data for issuing command
88 *
89 * LOCKING:
90 * Defined by the SCSI layer. We don't really care.
91 *
92 * RETURNS:
93 * Zero on success, negative errno on error.
94 */
95
96int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg)
97{
98 int rc = 0;
99 u8 scsi_cmd[MAX_COMMAND_SIZE];
100 u8 args[4], *argbuf = NULL;
101 int argsize = 0;
102 struct scsi_request *sreq;
103
104 if (NULL == (void *)arg)
105 return -EINVAL;
106
107 if (copy_from_user(args, arg, sizeof(args)))
108 return -EFAULT;
109
110 sreq = scsi_allocate_request(scsidev, GFP_KERNEL);
111 if (!sreq)
112 return -EINTR;
113
114 memset(scsi_cmd, 0, sizeof(scsi_cmd));
115
116 if (args[3]) {
117 argsize = SECTOR_SIZE * args[3];
118 argbuf = kmalloc(argsize, GFP_KERNEL);
119 if (argbuf == NULL)
120 return -ENOMEM;
121
122 scsi_cmd[1] = (4 << 1); /* PIO Data-in */
123 scsi_cmd[2] = 0x0e; /* no off.line or cc, read from dev,
124 block count in sector count field */
125 sreq->sr_data_direction = DMA_FROM_DEVICE;
126 } else {
127 scsi_cmd[1] = (3 << 1); /* Non-data */
128 /* scsi_cmd[2] is already 0 -- no off.line, cc, or data xfer */
129 sreq->sr_data_direction = DMA_NONE;
130 }
131
132 scsi_cmd[0] = ATA_16;
133
134 scsi_cmd[4] = args[2];
135 if (args[0] == WIN_SMART) { /* hack -- ide driver does this too... */
136 scsi_cmd[6] = args[3];
137 scsi_cmd[8] = args[1];
138 scsi_cmd[10] = 0x4f;
139 scsi_cmd[12] = 0xc2;
140 } else {
141 scsi_cmd[6] = args[1];
142 }
143 scsi_cmd[14] = args[0];
144
145 /* Good values for timeout and retries? Values below
146 from scsi_ioctl_send_command() for default case... */
147 scsi_wait_req(sreq, scsi_cmd, argbuf, argsize, (10*HZ), 5);
148
149 if (sreq->sr_result) {
150 rc = -EIO;
151 goto error;
152 }
153
154 /* Need code to retrieve data from check condition? */
155
156 if ((argbuf)
157 && copy_to_user((void *)(arg + sizeof(args)), argbuf, argsize))
158 rc = -EFAULT;
159error:
160 scsi_release_request(sreq);
161
162 if (argbuf)
163 kfree(argbuf);
164
165 return rc;
166}
167
168/**
169 * ata_task_ioctl - Handler for HDIO_DRIVE_TASK ioctl
170 * @dev: Device to whom we are issuing command
171 * @arg: User provided data for issuing command
172 *
173 * LOCKING:
174 * Defined by the SCSI layer. We don't really care.
175 *
176 * RETURNS:
177 * Zero on success, negative errno on error.
178 */
179int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg)
180{
181 int rc = 0;
182 u8 scsi_cmd[MAX_COMMAND_SIZE];
183 u8 args[7];
184 struct scsi_request *sreq;
185
186 if (NULL == (void *)arg)
187 return -EINVAL;
188
189 if (copy_from_user(args, arg, sizeof(args)))
190 return -EFAULT;
191
192 memset(scsi_cmd, 0, sizeof(scsi_cmd));
193 scsi_cmd[0] = ATA_16;
194 scsi_cmd[1] = (3 << 1); /* Non-data */
195 /* scsi_cmd[2] is already 0 -- no off.line, cc, or data xfer */
196 scsi_cmd[4] = args[1];
197 scsi_cmd[6] = args[2];
198 scsi_cmd[8] = args[3];
199 scsi_cmd[10] = args[4];
200 scsi_cmd[12] = args[5];
201 scsi_cmd[14] = args[0];
202
203 sreq = scsi_allocate_request(scsidev, GFP_KERNEL);
204 if (!sreq) {
205 rc = -EINTR;
206 goto error;
207 }
208
209 sreq->sr_data_direction = DMA_NONE;
210 /* Good values for timeout and retries? Values below
211 from scsi_ioctl_send_command() for default case... */
212 scsi_wait_req(sreq, scsi_cmd, NULL, 0, (10*HZ), 5);
213
214 if (sreq->sr_result) {
215 rc = -EIO;
216 goto error;
217 }
218
219 /* Need code to retrieve data from check condition? */
220
221error:
222 scsi_release_request(sreq);
223 return rc;
224}
225
81int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg) 226int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg)
82{ 227{
83 struct ata_port *ap; 228 struct ata_port *ap;
@@ -107,6 +252,16 @@ int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg)
107 return -EINVAL; 252 return -EINVAL;
108 return 0; 253 return 0;
109 254
255 case HDIO_DRIVE_CMD:
256 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
257 return -EACCES;
258 return ata_cmd_ioctl(scsidev, arg);
259
260 case HDIO_DRIVE_TASK:
261 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
262 return -EACCES;
263 return ata_task_ioctl(scsidev, arg);
264
110 default: 265 default:
111 rc = -ENOTTY; 266 rc = -ENOTTY;
112 break; 267 break;
@@ -165,24 +320,69 @@ struct ata_queued_cmd *ata_scsi_qc_new(struct ata_port *ap,
165} 320}
166 321
167/** 322/**
323 * ata_dump_status - user friendly display of error info
324 * @id: id of the port in question
325 * @tf: ptr to filled out taskfile
326 *
327 * Decode and dump the ATA error/status registers for the user so
328 * that they have some idea what really happened at the non
329 * make-believe layer.
330 *
331 * LOCKING:
332 * inherited from caller
333 */
334void ata_dump_status(unsigned id, struct ata_taskfile *tf)
335{
336 u8 stat = tf->command, err = tf->feature;
337
338 printk(KERN_WARNING "ata%u: status=0x%02x { ", id, stat);
339 if (stat & ATA_BUSY) {
340 printk("Busy }\n"); /* Data is not valid in this case */
341 } else {
342 if (stat & 0x40) printk("DriveReady ");
343 if (stat & 0x20) printk("DeviceFault ");
344 if (stat & 0x10) printk("SeekComplete ");
345 if (stat & 0x08) printk("DataRequest ");
346 if (stat & 0x04) printk("CorrectedError ");
347 if (stat & 0x02) printk("Index ");
348 if (stat & 0x01) printk("Error ");
349 printk("}\n");
350
351 if (err) {
352 printk(KERN_WARNING "ata%u: error=0x%02x { ", id, err);
353 if (err & 0x04) printk("DriveStatusError ");
354 if (err & 0x80) {
355 if (err & 0x04) printk("BadCRC ");
356 else printk("Sector ");
357 }
358 if (err & 0x40) printk("UncorrectableError ");
359 if (err & 0x10) printk("SectorIdNotFound ");
360 if (err & 0x02) printk("TrackZeroNotFound ");
361 if (err & 0x01) printk("AddrMarkNotFound ");
362 printk("}\n");
363 }
364 }
365}
366
367/**
168 * ata_to_sense_error - convert ATA error to SCSI error 368 * ata_to_sense_error - convert ATA error to SCSI error
169 * @qc: Command that we are erroring out
170 * @drv_stat: value contained in ATA status register 369 * @drv_stat: value contained in ATA status register
370 * @drv_err: value contained in ATA error register
371 * @sk: the sense key we'll fill out
372 * @asc: the additional sense code we'll fill out
373 * @ascq: the additional sense code qualifier we'll fill out
171 * 374 *
172 * Converts an ATA error into a SCSI error. While we are at it 375 * Converts an ATA error into a SCSI error. Fill out pointers to
173 * we decode and dump the ATA error for the user so that they 376 * SK, ASC, and ASCQ bytes for later use in fixed or descriptor
174 * have some idea what really happened at the non make-believe 377 * format sense blocks.
175 * layer.
176 * 378 *
177 * LOCKING: 379 * LOCKING:
178 * spin_lock_irqsave(host_set lock) 380 * spin_lock_irqsave(host_set lock)
179 */ 381 */
180 382void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc,
181void ata_to_sense_error(struct ata_queued_cmd *qc, u8 drv_stat) 383 u8 *ascq)
182{ 384{
183 struct scsi_cmnd *cmd = qc->scsicmd; 385 int i;
184 u8 err = 0;
185 unsigned char *sb = cmd->sense_buffer;
186 /* Based on the 3ware driver translation table */ 386 /* Based on the 3ware driver translation table */
187 static unsigned char sense_table[][4] = { 387 static unsigned char sense_table[][4] = {
188 /* BBD|ECC|ID|MAR */ 388 /* BBD|ECC|ID|MAR */
@@ -223,105 +423,187 @@ void ata_to_sense_error(struct ata_queued_cmd *qc, u8 drv_stat)
223 {0x04, RECOVERED_ERROR, 0x11, 0x00}, // Recovered ECC error Medium error, recovered 423 {0x04, RECOVERED_ERROR, 0x11, 0x00}, // Recovered ECC error Medium error, recovered
224 {0xFF, 0xFF, 0xFF, 0xFF}, // END mark 424 {0xFF, 0xFF, 0xFF, 0xFF}, // END mark
225 }; 425 };
226 int i = 0;
227
228 cmd->result = SAM_STAT_CHECK_CONDITION;
229 426
230 /* 427 /*
231 * Is this an error we can process/parse 428 * Is this an error we can process/parse
232 */ 429 */
233 430 if (drv_stat & ATA_BUSY) {
234 if(drv_stat & ATA_ERR) 431 drv_err = 0; /* Ignore the err bits, they're invalid */
235 /* Read the err bits */
236 err = ata_chk_err(qc->ap);
237
238 /* Display the ATA level error info */
239
240 printk(KERN_WARNING "ata%u: status=0x%02x { ", qc->ap->id, drv_stat);
241 if(drv_stat & 0x80)
242 {
243 printk("Busy ");
244 err = 0; /* Data is not valid in this case */
245 } 432 }
246 else { 433
247 if(drv_stat & 0x40) printk("DriveReady "); 434 if (drv_err) {
248 if(drv_stat & 0x20) printk("DeviceFault "); 435 /* Look for drv_err */
249 if(drv_stat & 0x10) printk("SeekComplete "); 436 for (i = 0; sense_table[i][0] != 0xFF; i++) {
250 if(drv_stat & 0x08) printk("DataRequest "); 437 /* Look for best matches first */
251 if(drv_stat & 0x04) printk("CorrectedError "); 438 if ((sense_table[i][0] & drv_err) ==
252 if(drv_stat & 0x02) printk("Index "); 439 sense_table[i][0]) {
253 if(drv_stat & 0x01) printk("Error "); 440 *sk = sense_table[i][1];
441 *asc = sense_table[i][2];
442 *ascq = sense_table[i][3];
443 goto translate_done;
444 }
445 }
446 /* No immediate match */
447 printk(KERN_WARNING "ata%u: no sense translation for "
448 "error 0x%02x\n", id, drv_err);
254 } 449 }
255 printk("}\n"); 450
256 451 /* Fall back to interpreting status bits */
257 if(err) 452 for (i = 0; stat_table[i][0] != 0xFF; i++) {
258 { 453 if (stat_table[i][0] & drv_stat) {
259 printk(KERN_WARNING "ata%u: error=0x%02x { ", qc->ap->id, err); 454 *sk = stat_table[i][1];
260 if(err & 0x04) printk("DriveStatusError "); 455 *asc = stat_table[i][2];
261 if(err & 0x80) 456 *ascq = stat_table[i][3];
262 { 457 goto translate_done;
263 if(err & 0x04)
264 printk("BadCRC ");
265 else
266 printk("Sector ");
267 } 458 }
268 if(err & 0x40) printk("UncorrectableError "); 459 }
269 if(err & 0x10) printk("SectorIdNotFound "); 460 /* No error? Undecoded? */
270 if(err & 0x02) printk("TrackZeroNotFound "); 461 printk(KERN_WARNING "ata%u: no sense translation for status: 0x%02x\n",
271 if(err & 0x01) printk("AddrMarkNotFound "); 462 id, drv_stat);
272 printk("}\n"); 463
464 /* For our last chance pick, use medium read error because
465 * it's much more common than an ATA drive telling you a write
466 * has failed.
467 */
468 *sk = MEDIUM_ERROR;
469 *asc = 0x11; /* "unrecovered read error" */
470 *ascq = 0x04; /* "auto-reallocation failed" */
471
472 translate_done:
473 printk(KERN_ERR "ata%u: translated ATA stat/err 0x%02x/%02x to "
474 "SCSI SK/ASC/ASCQ 0x%x/%02x/%02x\n", id, drv_stat, drv_err,
475 *sk, *asc, *ascq);
476 return;
477}
478
479/*
480 * ata_gen_ata_desc_sense - Generate check condition sense block.
481 * @qc: Command that completed.
482 *
483 * This function is specific to the ATA descriptor format sense
484 * block specified for the ATA pass through commands. Regardless
485 * of whether the command errored or not, return a sense
486 * block. Copy all controller registers into the sense
487 * block. Clear sense key, ASC & ASCQ if there is no error.
488 *
489 * LOCKING:
490 * spin_lock_irqsave(host_set lock)
491 */
492void ata_gen_ata_desc_sense(struct ata_queued_cmd *qc)
493{
494 struct scsi_cmnd *cmd = qc->scsicmd;
495 struct ata_taskfile *tf = &qc->tf;
496 unsigned char *sb = cmd->sense_buffer;
497 unsigned char *desc = sb + 8;
498
499 memset(sb, 0, SCSI_SENSE_BUFFERSIZE);
273 500
274 /* Should we dump sector info here too ?? */ 501 cmd->result = SAM_STAT_CHECK_CONDITION;
502
503 /*
504 * Read the controller registers.
505 */
506 assert(NULL != qc->ap->ops->tf_read);
507 qc->ap->ops->tf_read(qc->ap, tf);
508
509 /*
510 * Use ata_to_sense_error() to map status register bits
511 * onto sense key, asc & ascq.
512 */
513 if (unlikely(tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ))) {
514 ata_to_sense_error(qc->ap->id, tf->command, tf->feature,
515 &sb[1], &sb[2], &sb[3]);
516 sb[1] &= 0x0f;
275 } 517 }
276 518
519 /*
520 * Sense data is current and format is descriptor.
521 */
522 sb[0] = 0x72;
277 523
278 /* Look for err */ 524 desc[0] = 0x09;
279 while(sense_table[i][0] != 0xFF) 525
280 { 526 /*
281 /* Look for best matches first */ 527 * Set length of additional sense data.
282 if((sense_table[i][0] & err) == sense_table[i][0]) 528 * Since we only populate descriptor 0, the total
283 { 529 * length is the same (fixed) length as descriptor 0.
284 sb[0] = 0x70; 530 */
285 sb[2] = sense_table[i][1]; 531 desc[1] = sb[7] = 14;
286 sb[7] = 0x0a; 532
287 sb[12] = sense_table[i][2]; 533 /*
288 sb[13] = sense_table[i][3]; 534 * Copy registers into sense buffer.
289 return; 535 */
290 } 536 desc[2] = 0x00;
291 i++; 537 desc[3] = tf->feature; /* == error reg */
538 desc[5] = tf->nsect;
539 desc[7] = tf->lbal;
540 desc[9] = tf->lbam;
541 desc[11] = tf->lbah;
542 desc[12] = tf->device;
543 desc[13] = tf->command; /* == status reg */
544
545 /*
546 * Fill in Extend bit, and the high order bytes
547 * if applicable.
548 */
549 if (tf->flags & ATA_TFLAG_LBA48) {
550 desc[2] |= 0x01;
551 desc[4] = tf->hob_nsect;
552 desc[6] = tf->hob_lbal;
553 desc[8] = tf->hob_lbam;
554 desc[10] = tf->hob_lbah;
292 } 555 }
293 /* No immediate match */ 556}
294 if(err)
295 printk(KERN_DEBUG "ata%u: no sense translation for 0x%02x\n", qc->ap->id, err);
296 557
297 i = 0; 558/**
298 /* Fall back to interpreting status bits */ 559 * ata_gen_fixed_sense - generate a SCSI fixed sense block
299 while(stat_table[i][0] != 0xFF) 560 * @qc: Command that we are erroring out
300 { 561 *
301 if(stat_table[i][0] & drv_stat) 562 * Leverage ata_to_sense_error() to give us the codes. Fit our
302 { 563 * LBA in here if there's room.
303 sb[0] = 0x70; 564 *
304 sb[2] = stat_table[i][1]; 565 * LOCKING:
305 sb[7] = 0x0a; 566 * inherited from caller
306 sb[12] = stat_table[i][2]; 567 */
307 sb[13] = stat_table[i][3]; 568void ata_gen_fixed_sense(struct ata_queued_cmd *qc)
308 return; 569{
309 } 570 struct scsi_cmnd *cmd = qc->scsicmd;
310 i++; 571 struct ata_taskfile *tf = &qc->tf;
572 unsigned char *sb = cmd->sense_buffer;
573
574 memset(sb, 0, SCSI_SENSE_BUFFERSIZE);
575
576 cmd->result = SAM_STAT_CHECK_CONDITION;
577
578 /*
579 * Read the controller registers.
580 */
581 assert(NULL != qc->ap->ops->tf_read);
582 qc->ap->ops->tf_read(qc->ap, tf);
583
584 /*
585 * Use ata_to_sense_error() to map status register bits
586 * onto sense key, asc & ascq.
587 */
588 if (unlikely(tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ))) {
589 ata_to_sense_error(qc->ap->id, tf->command, tf->feature,
590 &sb[2], &sb[12], &sb[13]);
591 sb[2] &= 0x0f;
311 } 592 }
312 /* No error ?? */
313 printk(KERN_ERR "ata%u: called with no error (%02X)!\n", qc->ap->id, drv_stat);
314 /* additional-sense-code[-qualifier] */
315 593
316 sb[0] = 0x70; 594 sb[0] = 0x70;
317 sb[2] = MEDIUM_ERROR; 595 sb[7] = 0x0a;
318 sb[7] = 0x0A; 596
319 if (cmd->sc_data_direction == DMA_FROM_DEVICE) { 597#if 0 /* when C/H/S support is merged */
320 sb[12] = 0x11; /* "unrecovered read error" */ 598 if (tf->flags & ATA_TFLAG_LBA && !(tf->flags & ATA_TFLAG_LBA48)) {
321 sb[13] = 0x04; 599#endif
322 } else { 600 if (!(tf->flags & ATA_TFLAG_LBA48)) {
323 sb[12] = 0x0C; /* "write error - */ 601 /* A small (28b) LBA will fit in the 32b info field */
324 sb[13] = 0x02; /* auto-reallocation failed" */ 602 sb[0] |= 0x80; /* set valid bit */
603 sb[3] = tf->device & 0x0f;
604 sb[4] = tf->lbah;
605 sb[5] = tf->lbam;
606 sb[6] = tf->lbal;
325 } 607 }
326} 608}
327 609
@@ -705,11 +987,36 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, u8 *scsicmd)
705static int ata_scsi_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) 987static int ata_scsi_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat)
706{ 988{
707 struct scsi_cmnd *cmd = qc->scsicmd; 989 struct scsi_cmnd *cmd = qc->scsicmd;
990 int need_sense = drv_stat & (ATA_ERR | ATA_BUSY | ATA_DRQ);
991
992 /* For ATA pass thru (SAT) commands, generate a sense block if
993 * user mandated it or if there's an error. Note that if we
994 * generate because the user forced us to, a check condition
995 * is generated and the ATA register values are returned
996 * whether the command completed successfully or not. If there
997 * was no error, SK, ASC and ASCQ will all be zero.
998 */
999 if (((cmd->cmnd[0] == ATA_16) || (cmd->cmnd[0] == ATA_12)) &&
1000 ((cmd->cmnd[2] & 0x20) || need_sense)) {
1001 ata_gen_ata_desc_sense(qc);
1002 } else {
1003 if (!need_sense) {
1004 cmd->result = SAM_STAT_GOOD;
1005 } else {
1006 /* TODO: decide which descriptor format to use
1007 * for 48b LBA devices and call that here
1008 * instead of the fixed desc, which is only
1009 * good for smaller LBA (and maybe CHS?)
1010 * devices.
1011 */
1012 ata_gen_fixed_sense(qc);
1013 }
1014 }
708 1015
709 if (unlikely(drv_stat & (ATA_ERR | ATA_BUSY | ATA_DRQ))) 1016 if (need_sense) {
710 ata_to_sense_error(qc, drv_stat); 1017 /* The ata_gen_..._sense routines fill in tf */
711 else 1018 ata_dump_status(qc->ap->id, &qc->tf);
712 cmd->result = SAM_STAT_GOOD; 1019 }
713 1020
714 qc->scsidone(cmd); 1021 qc->scsidone(cmd);
715 1022
@@ -771,7 +1078,6 @@ static void ata_scsi_translate(struct ata_port *ap, struct ata_device *dev,
771 1078
772 if (xlat_func(qc, scsicmd)) 1079 if (xlat_func(qc, scsicmd))
773 goto err_out; 1080 goto err_out;
774
775 /* select device, send command to hardware */ 1081 /* select device, send command to hardware */
776 if (ata_qc_issue(qc)) 1082 if (ata_qc_issue(qc))
777 goto err_out; 1083 goto err_out;
@@ -1478,6 +1784,143 @@ ata_scsi_find_dev(struct ata_port *ap, struct scsi_device *scsidev)
1478 return dev; 1784 return dev;
1479} 1785}
1480 1786
1787/*
1788 * ata_scsi_map_proto - Map pass-thru protocol value to taskfile value.
1789 * @byte1: Byte 1 from pass-thru CDB.
1790 *
1791 * RETURNS:
1792 * ATA_PROT_UNKNOWN if mapping failed/unimplemented, protocol otherwise.
1793 */
1794static u8
1795ata_scsi_map_proto(u8 byte1)
1796{
1797 switch((byte1 & 0x1e) >> 1) {
1798 case 3: /* Non-data */
1799 return ATA_PROT_NODATA;
1800
1801 case 6: /* DMA */
1802 return ATA_PROT_DMA;
1803
1804 case 4: /* PIO Data-in */
1805 case 5: /* PIO Data-out */
1806 if (byte1 & 0xe0) {
1807 return ATA_PROT_PIO_MULT;
1808 }
1809 return ATA_PROT_PIO;
1810
1811 case 10: /* Device Reset */
1812 case 0: /* Hard Reset */
1813 case 1: /* SRST */
1814 case 2: /* Bus Idle */
1815 case 7: /* Packet */
1816 case 8: /* DMA Queued */
1817 case 9: /* Device Diagnostic */
1818 case 11: /* UDMA Data-in */
1819 case 12: /* UDMA Data-Out */
1820 case 13: /* FPDMA */
1821 default: /* Reserved */
1822 break;
1823 }
1824
1825 return ATA_PROT_UNKNOWN;
1826}
1827
1828/**
1829 * ata_scsi_pass_thru - convert ATA pass-thru CDB to taskfile
1830 * @qc: command structure to be initialized
1831 * @cmd: SCSI command to convert
1832 *
1833 * Handles either 12 or 16-byte versions of the CDB.
1834 *
1835 * RETURNS:
1836 * Zero on success, non-zero on failure.
1837 */
1838static unsigned int
1839ata_scsi_pass_thru(struct ata_queued_cmd *qc, u8 *scsicmd)
1840{
1841 struct ata_taskfile *tf = &(qc->tf);
1842 struct scsi_cmnd *cmd = qc->scsicmd;
1843
1844 if ((tf->protocol = ata_scsi_map_proto(scsicmd[1])) == ATA_PROT_UNKNOWN)
1845 return 1;
1846
1847 /*
1848 * 12 and 16 byte CDBs use different offsets to
1849 * provide the various register values.
1850 */
1851 if (scsicmd[0] == ATA_16) {
1852 /*
1853 * 16-byte CDB - may contain extended commands.
1854 *
1855 * If that is the case, copy the upper byte register values.
1856 */
1857 if (scsicmd[1] & 0x01) {
1858 tf->hob_feature = scsicmd[3];
1859 tf->hob_nsect = scsicmd[5];
1860 tf->hob_lbal = scsicmd[7];
1861 tf->hob_lbam = scsicmd[9];
1862 tf->hob_lbah = scsicmd[11];
1863 tf->flags |= ATA_TFLAG_LBA48;
1864 } else
1865 tf->flags &= ~ATA_TFLAG_LBA48;
1866
1867 /*
1868 * Always copy low byte, device and command registers.
1869 */
1870 tf->feature = scsicmd[4];
1871 tf->nsect = scsicmd[6];
1872 tf->lbal = scsicmd[8];
1873 tf->lbam = scsicmd[10];
1874 tf->lbah = scsicmd[12];
1875 tf->device = scsicmd[13];
1876 tf->command = scsicmd[14];
1877 } else {
1878 /*
1879 * 12-byte CDB - incapable of extended commands.
1880 */
1881 tf->flags &= ~ATA_TFLAG_LBA48;
1882
1883 tf->feature = scsicmd[3];
1884 tf->nsect = scsicmd[4];
1885 tf->lbal = scsicmd[5];
1886 tf->lbam = scsicmd[6];
1887 tf->lbah = scsicmd[7];
1888 tf->device = scsicmd[8];
1889 tf->command = scsicmd[9];
1890 }
1891
1892 /*
1893 * Filter SET_FEATURES - XFER MODE command -- otherwise,
1894 * SET_FEATURES - XFER MODE must be preceded/succeeded
1895 * by an update to hardware-specific registers for each
1896 * controller (i.e. the reason for ->set_piomode(),
1897 * ->set_dmamode(), and ->post_set_mode() hooks).
1898 */
1899 if ((tf->command == ATA_CMD_SET_FEATURES)
1900 && (tf->feature == SETFEATURES_XFER))
1901 return 1;
1902
1903 /*
1904 * Set flags so that all registers will be written,
1905 * and pass on write indication (used for PIO/DMA
1906 * setup.)
1907 */
1908 tf->flags |= (ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE);
1909
1910 if (cmd->sc_data_direction == DMA_TO_DEVICE)
1911 tf->flags |= ATA_TFLAG_WRITE;
1912
1913 /*
1914 * Set transfer length.
1915 *
1916 * TODO: find out if we need to do more here to
1917 * cover scatter/gather case.
1918 */
1919 qc->nsect = cmd->bufflen / ATA_SECT_SIZE;
1920
1921 return 0;
1922}
1923
1481/** 1924/**
1482 * ata_get_xlat_func - check if SCSI to ATA translation is possible 1925 * ata_get_xlat_func - check if SCSI to ATA translation is possible
1483 * @dev: ATA device 1926 * @dev: ATA device
@@ -1510,6 +1953,11 @@ static inline ata_xlat_func_t ata_get_xlat_func(struct ata_device *dev, u8 cmd)
1510 case VERIFY: 1953 case VERIFY:
1511 case VERIFY_16: 1954 case VERIFY_16:
1512 return ata_scsi_verify_xlat; 1955 return ata_scsi_verify_xlat;
1956
1957 case ATA_12:
1958 case ATA_16:
1959 return ata_scsi_pass_thru;
1960
1513 case START_STOP: 1961 case START_STOP:
1514 return ata_scsi_start_stop_xlat; 1962 return ata_scsi_start_stop_xlat;
1515 } 1963 }
@@ -1668,7 +2116,7 @@ void ata_scsi_simulate(u16 *id,
1668 ata_scsi_rbuf_fill(&args, ata_scsiop_report_luns); 2116 ata_scsi_rbuf_fill(&args, ata_scsiop_report_luns);
1669 break; 2117 break;
1670 2118
1671 /* mandantory commands we haven't implemented yet */ 2119 /* mandatory commands we haven't implemented yet */
1672 case REQUEST_SENSE: 2120 case REQUEST_SENSE:
1673 2121
1674 /* all other commands */ 2122 /* all other commands */
diff --git a/drivers/scsi/libata.h b/drivers/scsi/libata.h
index d608b3a0f6fe..0f1db892f6aa 100644
--- a/drivers/scsi/libata.h
+++ b/drivers/scsi/libata.h
@@ -48,10 +48,11 @@ extern void ata_dev_select(struct ata_port *ap, unsigned int device,
48 unsigned int wait, unsigned int can_sleep); 48 unsigned int wait, unsigned int can_sleep);
49extern void ata_tf_to_host_nolock(struct ata_port *ap, struct ata_taskfile *tf); 49extern void ata_tf_to_host_nolock(struct ata_port *ap, struct ata_taskfile *tf);
50extern void swap_buf_le16(u16 *buf, unsigned int buf_words); 50extern void swap_buf_le16(u16 *buf, unsigned int buf_words);
51extern int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg);
52extern int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg);
51 53
52 54
53/* libata-scsi.c */ 55/* libata-scsi.c */
54extern void ata_to_sense_error(struct ata_queued_cmd *qc, u8 drv_stat);
55extern int ata_scsi_error(struct Scsi_Host *host); 56extern int ata_scsi_error(struct Scsi_Host *host);
56extern unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf, 57extern unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf,
57 unsigned int buflen); 58 unsigned int buflen);
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
index b361172b576c..6cb1e2788d8b 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -116,6 +116,9 @@ extern const char *const scsi_device_types[MAX_SCSI_DEVICE_CODE];
116/* values for service action in */ 116/* values for service action in */
117#define SAI_READ_CAPACITY_16 0x10 117#define SAI_READ_CAPACITY_16 0x10
118 118
119/* Values for T10/04-262r7 */
120#define ATA_16 0x85 /* 16-byte pass-thru */
121#define ATA_12 0xa1 /* 12-byte pass-thru */
119 122
120/* 123/*
121 * SCSI Architecture Model (SAM) Status codes. Taken from SAM-3 draft 124 * SCSI Architecture Model (SAM) Status codes. Taken from SAM-3 draft