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