aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/scsi/libata-scsi.c644
-rw-r--r--drivers/scsi/libata.h3
2 files changed, 556 insertions, 91 deletions
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
index 58858886d751..b761bd1b9717 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, const u8 *scsicmd); 50typedef unsigned int (*ata_xlat_func_t)(struct ata_queued_cmd *qc, const u8 *scsicmd);
48static struct ata_device * 51static struct ata_device *
49ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev); 52ata_scsi_find_dev(struct ata_port *ap, const 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);
278 511
279 /* Should we dump sector info here too ?? */ 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);
519
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
@@ -871,11 +1163,36 @@ nothing_to_do:
871static int ata_scsi_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) 1163static int ata_scsi_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat)
872{ 1164{
873 struct scsi_cmnd *cmd = qc->scsicmd; 1165 struct scsi_cmnd *cmd = qc->scsicmd;
1166 int need_sense = drv_stat & (ATA_ERR | ATA_BUSY | ATA_DRQ);
1167
1168 /* For ATA pass thru (SAT) commands, generate a sense block if
1169 * user mandated it or if there's an error. Note that if we
1170 * generate because the user forced us to, a check condition
1171 * is generated and the ATA register values are returned
1172 * whether the command completed successfully or not. If there
1173 * was no error, SK, ASC and ASCQ will all be zero.
1174 */
1175 if (((cmd->cmnd[0] == ATA_16) || (cmd->cmnd[0] == ATA_12)) &&
1176 ((cmd->cmnd[2] & 0x20) || need_sense)) {
1177 ata_gen_ata_desc_sense(qc);
1178 } else {
1179 if (!need_sense) {
1180 cmd->result = SAM_STAT_GOOD;
1181 } else {
1182 /* TODO: decide which descriptor format to use
1183 * for 48b LBA devices and call that here
1184 * instead of the fixed desc, which is only
1185 * good for smaller LBA (and maybe CHS?)
1186 * devices.
1187 */
1188 ata_gen_fixed_sense(qc);
1189 }
1190 }
874 1191
875 if (unlikely(drv_stat & (ATA_ERR | ATA_BUSY | ATA_DRQ))) 1192 if (need_sense) {
876 ata_to_sense_error(qc, drv_stat); 1193 /* The ata_gen_..._sense routines fill in tf */
877 else 1194 ata_dump_status(qc->ap->id, &qc->tf);
878 cmd->result = SAM_STAT_GOOD; 1195 }
879 1196
880 qc->scsidone(cmd); 1197 qc->scsidone(cmd);
881 1198
@@ -1623,7 +1940,12 @@ static int atapi_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat)
1623 VPRINTK("ENTER, drv_stat == 0x%x\n", drv_stat); 1940 VPRINTK("ENTER, drv_stat == 0x%x\n", drv_stat);
1624 1941
1625 if (unlikely(drv_stat & (ATA_BUSY | ATA_DRQ))) 1942 if (unlikely(drv_stat & (ATA_BUSY | ATA_DRQ)))
1626 ata_to_sense_error(qc, drv_stat); 1943 /* FIXME: not quite right; we don't want the
1944 * translation of taskfile registers into
1945 * a sense descriptors, since that's only
1946 * correct for ATA, not ATAPI
1947 */
1948 ata_gen_ata_desc_sense(qc);
1627 1949
1628 else if (unlikely(drv_stat & ATA_ERR)) { 1950 else if (unlikely(drv_stat & ATA_ERR)) {
1629 DPRINTK("request check condition\n"); 1951 DPRINTK("request check condition\n");
@@ -1782,6 +2104,143 @@ ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev)
1782 return dev; 2104 return dev;
1783} 2105}
1784 2106
2107/*
2108 * ata_scsi_map_proto - Map pass-thru protocol value to taskfile value.
2109 * @byte1: Byte 1 from pass-thru CDB.
2110 *
2111 * RETURNS:
2112 * ATA_PROT_UNKNOWN if mapping failed/unimplemented, protocol otherwise.
2113 */
2114static u8
2115ata_scsi_map_proto(u8 byte1)
2116{
2117 switch((byte1 & 0x1e) >> 1) {
2118 case 3: /* Non-data */
2119 return ATA_PROT_NODATA;
2120
2121 case 6: /* DMA */
2122 return ATA_PROT_DMA;
2123
2124 case 4: /* PIO Data-in */
2125 case 5: /* PIO Data-out */
2126 if (byte1 & 0xe0) {
2127 return ATA_PROT_PIO_MULT;
2128 }
2129 return ATA_PROT_PIO;
2130
2131 case 10: /* Device Reset */
2132 case 0: /* Hard Reset */
2133 case 1: /* SRST */
2134 case 2: /* Bus Idle */
2135 case 7: /* Packet */
2136 case 8: /* DMA Queued */
2137 case 9: /* Device Diagnostic */
2138 case 11: /* UDMA Data-in */
2139 case 12: /* UDMA Data-Out */
2140 case 13: /* FPDMA */
2141 default: /* Reserved */
2142 break;
2143 }
2144
2145 return ATA_PROT_UNKNOWN;
2146}
2147
2148/**
2149 * ata_scsi_pass_thru - convert ATA pass-thru CDB to taskfile
2150 * @qc: command structure to be initialized
2151 * @cmd: SCSI command to convert
2152 *
2153 * Handles either 12 or 16-byte versions of the CDB.
2154 *
2155 * RETURNS:
2156 * Zero on success, non-zero on failure.
2157 */
2158static unsigned int
2159ata_scsi_pass_thru(struct ata_queued_cmd *qc, u8 *scsicmd)
2160{
2161 struct ata_taskfile *tf = &(qc->tf);
2162 struct scsi_cmnd *cmd = qc->scsicmd;
2163
2164 if ((tf->protocol = ata_scsi_map_proto(scsicmd[1])) == ATA_PROT_UNKNOWN)
2165 return 1;
2166
2167 /*
2168 * 12 and 16 byte CDBs use different offsets to
2169 * provide the various register values.
2170 */
2171 if (scsicmd[0] == ATA_16) {
2172 /*
2173 * 16-byte CDB - may contain extended commands.
2174 *
2175 * If that is the case, copy the upper byte register values.
2176 */
2177 if (scsicmd[1] & 0x01) {
2178 tf->hob_feature = scsicmd[3];
2179 tf->hob_nsect = scsicmd[5];
2180 tf->hob_lbal = scsicmd[7];
2181 tf->hob_lbam = scsicmd[9];
2182 tf->hob_lbah = scsicmd[11];
2183 tf->flags |= ATA_TFLAG_LBA48;
2184 } else
2185 tf->flags &= ~ATA_TFLAG_LBA48;
2186
2187 /*
2188 * Always copy low byte, device and command registers.
2189 */
2190 tf->feature = scsicmd[4];
2191 tf->nsect = scsicmd[6];
2192 tf->lbal = scsicmd[8];
2193 tf->lbam = scsicmd[10];
2194 tf->lbah = scsicmd[12];
2195 tf->device = scsicmd[13];
2196 tf->command = scsicmd[14];
2197 } else {
2198 /*
2199 * 12-byte CDB - incapable of extended commands.
2200 */
2201 tf->flags &= ~ATA_TFLAG_LBA48;
2202
2203 tf->feature = scsicmd[3];
2204 tf->nsect = scsicmd[4];
2205 tf->lbal = scsicmd[5];
2206 tf->lbam = scsicmd[6];
2207 tf->lbah = scsicmd[7];
2208 tf->device = scsicmd[8];
2209 tf->command = scsicmd[9];
2210 }
2211
2212 /*
2213 * Filter SET_FEATURES - XFER MODE command -- otherwise,
2214 * SET_FEATURES - XFER MODE must be preceded/succeeded
2215 * by an update to hardware-specific registers for each
2216 * controller (i.e. the reason for ->set_piomode(),
2217 * ->set_dmamode(), and ->post_set_mode() hooks).
2218 */
2219 if ((tf->command == ATA_CMD_SET_FEATURES)
2220 && (tf->feature == SETFEATURES_XFER))
2221 return 1;
2222
2223 /*
2224 * Set flags so that all registers will be written,
2225 * and pass on write indication (used for PIO/DMA
2226 * setup.)
2227 */
2228 tf->flags |= (ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE);
2229
2230 if (cmd->sc_data_direction == DMA_TO_DEVICE)
2231 tf->flags |= ATA_TFLAG_WRITE;
2232
2233 /*
2234 * Set transfer length.
2235 *
2236 * TODO: find out if we need to do more here to
2237 * cover scatter/gather case.
2238 */
2239 qc->nsect = cmd->bufflen / ATA_SECT_SIZE;
2240
2241 return 0;
2242}
2243
1785/** 2244/**
1786 * ata_get_xlat_func - check if SCSI to ATA translation is possible 2245 * ata_get_xlat_func - check if SCSI to ATA translation is possible
1787 * @dev: ATA device 2246 * @dev: ATA device
@@ -1814,6 +2273,11 @@ static inline ata_xlat_func_t ata_get_xlat_func(struct ata_device *dev, u8 cmd)
1814 case VERIFY: 2273 case VERIFY:
1815 case VERIFY_16: 2274 case VERIFY_16:
1816 return ata_scsi_verify_xlat; 2275 return ata_scsi_verify_xlat;
2276
2277 case ATA_12:
2278 case ATA_16:
2279 return ata_scsi_pass_thru;
2280
1817 case START_STOP: 2281 case START_STOP:
1818 return ata_scsi_start_stop_xlat; 2282 return ata_scsi_start_stop_xlat;
1819 } 2283 }
@@ -1972,7 +2436,7 @@ void ata_scsi_simulate(u16 *id,
1972 ata_scsi_rbuf_fill(&args, ata_scsiop_report_luns); 2436 ata_scsi_rbuf_fill(&args, ata_scsiop_report_luns);
1973 break; 2437 break;
1974 2438
1975 /* mandantory commands we haven't implemented yet */ 2439 /* mandatory commands we haven't implemented yet */
1976 case REQUEST_SENSE: 2440 case REQUEST_SENSE:
1977 2441
1978 /* all other commands */ 2442 /* all other commands */
diff --git a/drivers/scsi/libata.h b/drivers/scsi/libata.h
index 3d60190584ba..65c264b91136 100644
--- a/drivers/scsi/libata.h
+++ b/drivers/scsi/libata.h
@@ -50,13 +50,14 @@ extern void ata_dev_select(struct ata_port *ap, unsigned int device,
50 unsigned int wait, unsigned int can_sleep); 50 unsigned int wait, unsigned int can_sleep);
51extern void ata_tf_to_host_nolock(struct ata_port *ap, const struct ata_taskfile *tf); 51extern void ata_tf_to_host_nolock(struct ata_port *ap, const struct ata_taskfile *tf);
52extern void swap_buf_le16(u16 *buf, unsigned int buf_words); 52extern void swap_buf_le16(u16 *buf, unsigned int buf_words);
53extern int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg);
54extern int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg);
53 55
54 56
55/* libata-scsi.c */ 57/* libata-scsi.c */
56extern void atapi_request_sense(struct ata_port *ap, struct ata_device *dev, 58extern void atapi_request_sense(struct ata_port *ap, struct ata_device *dev,
57 struct scsi_cmnd *cmd); 59 struct scsi_cmnd *cmd);
58extern void ata_scsi_scan_host(struct ata_port *ap); 60extern void ata_scsi_scan_host(struct ata_port *ap);
59extern void ata_to_sense_error(struct ata_queued_cmd *qc, u8 drv_stat);
60extern int ata_scsi_error(struct Scsi_Host *host); 61extern int ata_scsi_error(struct Scsi_Host *host);
61extern unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf, 62extern unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf,
62 unsigned int buflen); 63 unsigned int buflen);