diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/scsi/libata-scsi.c | 651 | ||||
-rw-r--r-- | drivers/scsi/libata.h | 3 |
2 files changed, 549 insertions, 105 deletions
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c index 416ba67ba9ee..072b6e5b139e 100644 --- a/drivers/scsi/libata-scsi.c +++ b/drivers/scsi/libata-scsi.c | |||
@@ -29,10 +29,13 @@ | |||
29 | #include "scsi.h" | 29 | #include "scsi.h" |
30 | #include <scsi/scsi_host.h> | 30 | #include <scsi/scsi_host.h> |
31 | #include <linux/libata.h> | 31 | #include <linux/libata.h> |
32 | #include <linux/hdreg.h> | ||
32 | #include <asm/uaccess.h> | 33 | #include <asm/uaccess.h> |
33 | 34 | ||
34 | #include "libata.h" | 35 | #include "libata.h" |
35 | 36 | ||
37 | #define SECTOR_SIZE 512 | ||
38 | |||
36 | typedef unsigned int (*ata_xlat_func_t)(struct ata_queued_cmd *qc, u8 *scsicmd); | 39 | typedef unsigned int (*ata_xlat_func_t)(struct ata_queued_cmd *qc, u8 *scsicmd); |
37 | static struct ata_device * | 40 | static struct ata_device * |
38 | ata_scsi_find_dev(struct ata_port *ap, struct scsi_device *scsidev); | 41 | ata_scsi_find_dev(struct ata_port *ap, struct scsi_device *scsidev); |
@@ -67,6 +70,148 @@ int ata_std_bios_param(struct scsi_device *sdev, struct block_device *bdev, | |||
67 | return 0; | 70 | return 0; |
68 | } | 71 | } |
69 | 72 | ||
73 | /** | ||
74 | * ata_cmd_ioctl - Handler for HDIO_DRIVE_CMD ioctl | ||
75 | * @dev: Device to whom we are issuing command | ||
76 | * @arg: User provided data for issuing command | ||
77 | * | ||
78 | * LOCKING: | ||
79 | * Defined by the SCSI layer. We don't really care. | ||
80 | * | ||
81 | * RETURNS: | ||
82 | * Zero on success, negative errno on error. | ||
83 | */ | ||
84 | |||
85 | int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg) | ||
86 | { | ||
87 | int rc = 0; | ||
88 | u8 scsi_cmd[MAX_COMMAND_SIZE]; | ||
89 | u8 args[4], *argbuf = NULL; | ||
90 | int argsize = 0; | ||
91 | struct scsi_request *sreq; | ||
92 | |||
93 | if (NULL == (void *)arg) | ||
94 | return -EINVAL; | ||
95 | |||
96 | if (copy_from_user(args, arg, sizeof(args))) | ||
97 | return -EFAULT; | ||
98 | |||
99 | sreq = scsi_allocate_request(scsidev, GFP_KERNEL); | ||
100 | if (!sreq) | ||
101 | return -EINTR; | ||
102 | |||
103 | memset(scsi_cmd, 0, sizeof(scsi_cmd)); | ||
104 | |||
105 | if (args[3]) { | ||
106 | argsize = SECTOR_SIZE * args[3]; | ||
107 | argbuf = kmalloc(argsize, GFP_KERNEL); | ||
108 | if (argbuf == NULL) | ||
109 | return -ENOMEM; | ||
110 | |||
111 | scsi_cmd[1] = (4 << 1); /* PIO Data-in */ | ||
112 | scsi_cmd[2] = 0x0e; /* no off.line or cc, read from dev, | ||
113 | block count in sector count field */ | ||
114 | sreq->sr_data_direction = DMA_FROM_DEVICE; | ||
115 | } else { | ||
116 | scsi_cmd[1] = (3 << 1); /* Non-data */ | ||
117 | /* scsi_cmd[2] is already 0 -- no off.line, cc, or data xfer */ | ||
118 | sreq->sr_data_direction = DMA_NONE; | ||
119 | } | ||
120 | |||
121 | scsi_cmd[0] = ATA_16; | ||
122 | |||
123 | scsi_cmd[4] = args[2]; | ||
124 | if (args[0] == WIN_SMART) { /* hack -- ide driver does this too... */ | ||
125 | scsi_cmd[6] = args[3]; | ||
126 | scsi_cmd[8] = args[1]; | ||
127 | scsi_cmd[10] = 0x4f; | ||
128 | scsi_cmd[12] = 0xc2; | ||
129 | } else { | ||
130 | scsi_cmd[6] = args[1]; | ||
131 | } | ||
132 | scsi_cmd[14] = args[0]; | ||
133 | |||
134 | /* Good values for timeout and retries? Values below | ||
135 | from scsi_ioctl_send_command() for default case... */ | ||
136 | scsi_wait_req(sreq, scsi_cmd, argbuf, argsize, (10*HZ), 5); | ||
137 | |||
138 | if (sreq->sr_result) { | ||
139 | rc = -EIO; | ||
140 | goto error; | ||
141 | } | ||
142 | |||
143 | /* Need code to retrieve data from check condition? */ | ||
144 | |||
145 | if ((argbuf) | ||
146 | && copy_to_user((void *)(arg + sizeof(args)), argbuf, argsize)) | ||
147 | rc = -EFAULT; | ||
148 | error: | ||
149 | scsi_release_request(sreq); | ||
150 | |||
151 | if (argbuf) | ||
152 | kfree(argbuf); | ||
153 | |||
154 | return rc; | ||
155 | } | ||
156 | |||
157 | /** | ||
158 | * ata_task_ioctl - Handler for HDIO_DRIVE_TASK ioctl | ||
159 | * @dev: Device to whom we are issuing command | ||
160 | * @arg: User provided data for issuing command | ||
161 | * | ||
162 | * LOCKING: | ||
163 | * Defined by the SCSI layer. We don't really care. | ||
164 | * | ||
165 | * RETURNS: | ||
166 | * Zero on success, negative errno on error. | ||
167 | */ | ||
168 | int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg) | ||
169 | { | ||
170 | int rc = 0; | ||
171 | u8 scsi_cmd[MAX_COMMAND_SIZE]; | ||
172 | u8 args[7]; | ||
173 | struct scsi_request *sreq; | ||
174 | |||
175 | if (NULL == (void *)arg) | ||
176 | return -EINVAL; | ||
177 | |||
178 | if (copy_from_user(args, arg, sizeof(args))) | ||
179 | return -EFAULT; | ||
180 | |||
181 | memset(scsi_cmd, 0, sizeof(scsi_cmd)); | ||
182 | scsi_cmd[0] = ATA_16; | ||
183 | scsi_cmd[1] = (3 << 1); /* Non-data */ | ||
184 | /* scsi_cmd[2] is already 0 -- no off.line, cc, or data xfer */ | ||
185 | scsi_cmd[4] = args[1]; | ||
186 | scsi_cmd[6] = args[2]; | ||
187 | scsi_cmd[8] = args[3]; | ||
188 | scsi_cmd[10] = args[4]; | ||
189 | scsi_cmd[12] = args[5]; | ||
190 | scsi_cmd[14] = args[0]; | ||
191 | |||
192 | sreq = scsi_allocate_request(scsidev, GFP_KERNEL); | ||
193 | if (!sreq) { | ||
194 | rc = -EINTR; | ||
195 | goto error; | ||
196 | } | ||
197 | |||
198 | sreq->sr_data_direction = DMA_NONE; | ||
199 | /* Good values for timeout and retries? Values below | ||
200 | from scsi_ioctl_send_command() for default case... */ | ||
201 | scsi_wait_req(sreq, scsi_cmd, NULL, 0, (10*HZ), 5); | ||
202 | |||
203 | if (sreq->sr_result) { | ||
204 | rc = -EIO; | ||
205 | goto error; | ||
206 | } | ||
207 | |||
208 | /* Need code to retrieve data from check condition? */ | ||
209 | |||
210 | error: | ||
211 | scsi_release_request(sreq); | ||
212 | return rc; | ||
213 | } | ||
214 | |||
70 | int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg) | 215 | int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg) |
71 | { | 216 | { |
72 | struct ata_port *ap; | 217 | struct ata_port *ap; |
@@ -96,6 +241,16 @@ int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg) | |||
96 | return -EINVAL; | 241 | return -EINVAL; |
97 | return 0; | 242 | return 0; |
98 | 243 | ||
244 | case HDIO_DRIVE_CMD: | ||
245 | if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) | ||
246 | return -EACCES; | ||
247 | return ata_cmd_ioctl(scsidev, arg); | ||
248 | |||
249 | case HDIO_DRIVE_TASK: | ||
250 | if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) | ||
251 | return -EACCES; | ||
252 | return ata_task_ioctl(scsidev, arg); | ||
253 | |||
99 | default: | 254 | default: |
100 | rc = -ENOTTY; | 255 | rc = -ENOTTY; |
101 | break; | 256 | break; |
@@ -154,24 +309,69 @@ struct ata_queued_cmd *ata_scsi_qc_new(struct ata_port *ap, | |||
154 | } | 309 | } |
155 | 310 | ||
156 | /** | 311 | /** |
312 | * ata_dump_status - user friendly display of error info | ||
313 | * @id: id of the port in question | ||
314 | * @tf: ptr to filled out taskfile | ||
315 | * | ||
316 | * Decode and dump the ATA error/status registers for the user so | ||
317 | * that they have some idea what really happened at the non | ||
318 | * make-believe layer. | ||
319 | * | ||
320 | * LOCKING: | ||
321 | * inherited from caller | ||
322 | */ | ||
323 | void ata_dump_status(unsigned id, struct ata_taskfile *tf) | ||
324 | { | ||
325 | u8 stat = tf->command, err = tf->feature; | ||
326 | |||
327 | printk(KERN_WARNING "ata%u: status=0x%02x { ", id, stat); | ||
328 | if (stat & ATA_BUSY) { | ||
329 | printk("Busy }\n"); /* Data is not valid in this case */ | ||
330 | } else { | ||
331 | if (stat & 0x40) printk("DriveReady "); | ||
332 | if (stat & 0x20) printk("DeviceFault "); | ||
333 | if (stat & 0x10) printk("SeekComplete "); | ||
334 | if (stat & 0x08) printk("DataRequest "); | ||
335 | if (stat & 0x04) printk("CorrectedError "); | ||
336 | if (stat & 0x02) printk("Index "); | ||
337 | if (stat & 0x01) printk("Error "); | ||
338 | printk("}\n"); | ||
339 | |||
340 | if (err) { | ||
341 | printk(KERN_WARNING "ata%u: error=0x%02x { ", id, err); | ||
342 | if (err & 0x04) printk("DriveStatusError "); | ||
343 | if (err & 0x80) { | ||
344 | if (err & 0x04) printk("BadCRC "); | ||
345 | else printk("Sector "); | ||
346 | } | ||
347 | if (err & 0x40) printk("UncorrectableError "); | ||
348 | if (err & 0x10) printk("SectorIdNotFound "); | ||
349 | if (err & 0x02) printk("TrackZeroNotFound "); | ||
350 | if (err & 0x01) printk("AddrMarkNotFound "); | ||
351 | printk("}\n"); | ||
352 | } | ||
353 | } | ||
354 | } | ||
355 | |||
356 | /** | ||
157 | * ata_to_sense_error - convert ATA error to SCSI error | 357 | * ata_to_sense_error - convert ATA error to SCSI error |
158 | * @qc: Command that we are erroring out | ||
159 | * @drv_stat: value contained in ATA status register | 358 | * @drv_stat: value contained in ATA status register |
359 | * @drv_err: value contained in ATA error register | ||
360 | * @sk: the sense key we'll fill out | ||
361 | * @asc: the additional sense code we'll fill out | ||
362 | * @ascq: the additional sense code qualifier we'll fill out | ||
160 | * | 363 | * |
161 | * Converts an ATA error into a SCSI error. While we are at it | 364 | * Converts an ATA error into a SCSI error. Fill out pointers to |
162 | * we decode and dump the ATA error for the user so that they | 365 | * SK, ASC, and ASCQ bytes for later use in fixed or descriptor |
163 | * have some idea what really happened at the non make-believe | 366 | * format sense blocks. |
164 | * layer. | ||
165 | * | 367 | * |
166 | * LOCKING: | 368 | * LOCKING: |
167 | * spin_lock_irqsave(host_set lock) | 369 | * spin_lock_irqsave(host_set lock) |
168 | */ | 370 | */ |
169 | 371 | void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc, | |
170 | void ata_to_sense_error(struct ata_queued_cmd *qc, u8 drv_stat) | 372 | u8 *ascq) |
171 | { | 373 | { |
172 | struct scsi_cmnd *cmd = qc->scsicmd; | 374 | int i; |
173 | u8 err = 0; | ||
174 | unsigned char *sb = cmd->sense_buffer; | ||
175 | /* Based on the 3ware driver translation table */ | 375 | /* Based on the 3ware driver translation table */ |
176 | static unsigned char sense_table[][4] = { | 376 | static unsigned char sense_table[][4] = { |
177 | /* BBD|ECC|ID|MAR */ | 377 | /* BBD|ECC|ID|MAR */ |
@@ -212,105 +412,183 @@ void ata_to_sense_error(struct ata_queued_cmd *qc, u8 drv_stat) | |||
212 | {0x04, RECOVERED_ERROR, 0x11, 0x00}, // Recovered ECC error Medium error, recovered | 412 | {0x04, RECOVERED_ERROR, 0x11, 0x00}, // Recovered ECC error Medium error, recovered |
213 | {0xFF, 0xFF, 0xFF, 0xFF}, // END mark | 413 | {0xFF, 0xFF, 0xFF, 0xFF}, // END mark |
214 | }; | 414 | }; |
215 | int i = 0; | ||
216 | |||
217 | cmd->result = SAM_STAT_CHECK_CONDITION; | ||
218 | 415 | ||
219 | /* | 416 | /* |
220 | * Is this an error we can process/parse | 417 | * Is this an error we can process/parse |
221 | */ | 418 | */ |
222 | 419 | if (drv_stat & ATA_BUSY) { | |
223 | if(drv_stat & ATA_ERR) | 420 | drv_err = 0; /* Ignore the err bits, they're invalid */ |
224 | /* Read the err bits */ | ||
225 | err = ata_chk_err(qc->ap); | ||
226 | |||
227 | /* Display the ATA level error info */ | ||
228 | |||
229 | printk(KERN_WARNING "ata%u: status=0x%02x { ", qc->ap->id, drv_stat); | ||
230 | if(drv_stat & 0x80) | ||
231 | { | ||
232 | printk("Busy "); | ||
233 | err = 0; /* Data is not valid in this case */ | ||
234 | } | 421 | } |
235 | else { | 422 | |
236 | if(drv_stat & 0x40) printk("DriveReady "); | 423 | if (drv_err) { |
237 | if(drv_stat & 0x20) printk("DeviceFault "); | 424 | /* Look for drv_err */ |
238 | if(drv_stat & 0x10) printk("SeekComplete "); | 425 | for (i = 0; sense_table[i][0] != 0xFF; i++) { |
239 | if(drv_stat & 0x08) printk("DataRequest "); | 426 | /* Look for best matches first */ |
240 | if(drv_stat & 0x04) printk("CorrectedError "); | 427 | if ((sense_table[i][0] & drv_err) == |
241 | if(drv_stat & 0x02) printk("Index "); | 428 | sense_table[i][0]) { |
242 | if(drv_stat & 0x01) printk("Error "); | 429 | *sk = sense_table[i][1]; |
430 | *asc = sense_table[i][2]; | ||
431 | *ascq = sense_table[i][3]; | ||
432 | goto translate_done; | ||
433 | } | ||
434 | } | ||
435 | /* No immediate match */ | ||
436 | printk(KERN_WARNING "ata%u: no sense translation for " | ||
437 | "error 0x%02x\n", id, drv_err); | ||
243 | } | 438 | } |
244 | printk("}\n"); | 439 | |
245 | 440 | /* Fall back to interpreting status bits */ | |
246 | if(err) | 441 | for (i = 0; stat_table[i][0] != 0xFF; i++) { |
247 | { | 442 | if (stat_table[i][0] & drv_stat) { |
248 | printk(KERN_WARNING "ata%u: error=0x%02x { ", qc->ap->id, err); | 443 | *sk = stat_table[i][1]; |
249 | if(err & 0x04) printk("DriveStatusError "); | 444 | *asc = stat_table[i][2]; |
250 | if(err & 0x80) | 445 | *ascq = stat_table[i][3]; |
251 | { | 446 | goto translate_done; |
252 | if(err & 0x04) | ||
253 | printk("BadCRC "); | ||
254 | else | ||
255 | printk("Sector "); | ||
256 | } | 447 | } |
257 | if(err & 0x40) printk("UncorrectableError "); | 448 | } |
258 | if(err & 0x10) printk("SectorIdNotFound "); | 449 | /* No error? Undecoded? */ |
259 | if(err & 0x02) printk("TrackZeroNotFound "); | 450 | printk(KERN_WARNING "ata%u: no sense translation for status: 0x%02x\n", |
260 | if(err & 0x01) printk("AddrMarkNotFound "); | 451 | id, drv_stat); |
261 | printk("}\n"); | 452 | |
453 | /* For our last chance pick, use medium read error because | ||
454 | * it's much more common than an ATA drive telling you a write | ||
455 | * has failed. | ||
456 | */ | ||
457 | *sk = MEDIUM_ERROR; | ||
458 | *asc = 0x11; /* "unrecovered read error" */ | ||
459 | *ascq = 0x04; /* "auto-reallocation failed" */ | ||
460 | |||
461 | translate_done: | ||
462 | printk(KERN_ERR "ata%u: translated ATA stat/err 0x%02x/%02x to " | ||
463 | "SCSI SK/ASC/ASCQ 0x%x/%02x/%02x\n", id, drv_stat, drv_err, | ||
464 | *sk, *asc, *ascq); | ||
465 | return; | ||
466 | } | ||
467 | |||
468 | /* | ||
469 | * ata_gen_ata_desc_sense - Generate check condition sense block. | ||
470 | * @qc: Command that completed. | ||
471 | * | ||
472 | * This function is specific to the ATA descriptor format sense | ||
473 | * block specified for the ATA pass through commands. Regardless | ||
474 | * of whether the command errored or not, return a sense | ||
475 | * block. Copy all controller registers into the sense | ||
476 | * block. Clear sense key, ASC & ASCQ if there is no error. | ||
477 | * | ||
478 | * LOCKING: | ||
479 | * spin_lock_irqsave(host_set lock) | ||
480 | */ | ||
481 | void ata_gen_ata_desc_sense(struct ata_queued_cmd *qc) | ||
482 | { | ||
483 | struct scsi_cmnd *cmd = qc->scsicmd; | ||
484 | struct ata_taskfile *tf = &qc->tf; | ||
485 | unsigned char *sb = cmd->sense_buffer; | ||
486 | unsigned char *desc = sb + 8; | ||
487 | |||
488 | memset(sb, 0, SCSI_SENSE_BUFFERSIZE); | ||
489 | |||
490 | cmd->result = SAM_STAT_CHECK_CONDITION; | ||
491 | |||
492 | /* | ||
493 | * Read the controller registers. | ||
494 | */ | ||
495 | assert(NULL != qc->ap->ops->tf_read); | ||
496 | qc->ap->ops->tf_read(qc->ap, tf); | ||
262 | 497 | ||
263 | /* Should we dump sector info here too ?? */ | 498 | /* |
499 | * Use ata_to_sense_error() to map status register bits | ||
500 | * onto sense key, asc & ascq. | ||
501 | */ | ||
502 | if (unlikely(tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ))) { | ||
503 | ata_to_sense_error(qc->ap->id, tf->command, tf->feature, | ||
504 | &sb[1], &sb[2], &sb[3]); | ||
505 | sb[1] &= 0x0f; | ||
264 | } | 506 | } |
265 | 507 | ||
508 | /* | ||
509 | * Sense data is current and format is descriptor. | ||
510 | */ | ||
511 | sb[0] = 0x72; | ||
512 | |||
513 | desc[0] = 0x09; | ||
266 | 514 | ||
267 | /* Look for err */ | 515 | /* |
268 | while(sense_table[i][0] != 0xFF) | 516 | * Set length of additional sense data. |
269 | { | 517 | * Since we only populate descriptor 0, the total |
270 | /* Look for best matches first */ | 518 | * length is the same (fixed) length as descriptor 0. |
271 | if((sense_table[i][0] & err) == sense_table[i][0]) | 519 | */ |
272 | { | 520 | desc[1] = sb[7] = 14; |
273 | sb[0] = 0x70; | 521 | |
274 | sb[2] = sense_table[i][1]; | 522 | /* |
275 | sb[7] = 0x0a; | 523 | * Copy registers into sense buffer. |
276 | sb[12] = sense_table[i][2]; | 524 | */ |
277 | sb[13] = sense_table[i][3]; | 525 | desc[2] = 0x00; |
278 | return; | 526 | desc[3] = tf->feature; /* == error reg */ |
279 | } | 527 | desc[5] = tf->nsect; |
280 | i++; | 528 | desc[7] = tf->lbal; |
529 | desc[9] = tf->lbam; | ||
530 | desc[11] = tf->lbah; | ||
531 | desc[12] = tf->device; | ||
532 | desc[13] = tf->command; /* == status reg */ | ||
533 | |||
534 | /* | ||
535 | * Fill in Extend bit, and the high order bytes | ||
536 | * if applicable. | ||
537 | */ | ||
538 | if (tf->flags & ATA_TFLAG_LBA48) { | ||
539 | desc[2] |= 0x01; | ||
540 | desc[4] = tf->hob_nsect; | ||
541 | desc[6] = tf->hob_lbal; | ||
542 | desc[8] = tf->hob_lbam; | ||
543 | desc[10] = tf->hob_lbah; | ||
281 | } | 544 | } |
282 | /* No immediate match */ | 545 | } |
283 | if(err) | ||
284 | printk(KERN_DEBUG "ata%u: no sense translation for 0x%02x\n", qc->ap->id, err); | ||
285 | 546 | ||
286 | i = 0; | 547 | /** |
287 | /* Fall back to interpreting status bits */ | 548 | * ata_gen_fixed_sense - generate a SCSI fixed sense block |
288 | while(stat_table[i][0] != 0xFF) | 549 | * @qc: Command that we are erroring out |
289 | { | 550 | * |
290 | if(stat_table[i][0] & drv_stat) | 551 | * Leverage ata_to_sense_error() to give us the codes. Fit our |
291 | { | 552 | * LBA in here if there's room. |
292 | sb[0] = 0x70; | 553 | * |
293 | sb[2] = stat_table[i][1]; | 554 | * LOCKING: |
294 | sb[7] = 0x0a; | 555 | * inherited from caller |
295 | sb[12] = stat_table[i][2]; | 556 | */ |
296 | sb[13] = stat_table[i][3]; | 557 | void ata_gen_fixed_sense(struct ata_queued_cmd *qc) |
297 | return; | 558 | { |
298 | } | 559 | struct scsi_cmnd *cmd = qc->scsicmd; |
299 | i++; | 560 | struct ata_taskfile *tf = &qc->tf; |
561 | unsigned char *sb = cmd->sense_buffer; | ||
562 | |||
563 | memset(sb, 0, SCSI_SENSE_BUFFERSIZE); | ||
564 | |||
565 | cmd->result = SAM_STAT_CHECK_CONDITION; | ||
566 | |||
567 | /* | ||
568 | * Read the controller registers. | ||
569 | */ | ||
570 | assert(NULL != qc->ap->ops->tf_read); | ||
571 | qc->ap->ops->tf_read(qc->ap, tf); | ||
572 | |||
573 | /* | ||
574 | * Use ata_to_sense_error() to map status register bits | ||
575 | * onto sense key, asc & ascq. | ||
576 | */ | ||
577 | if (unlikely(tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ))) { | ||
578 | ata_to_sense_error(qc->ap->id, tf->command, tf->feature, | ||
579 | &sb[2], &sb[12], &sb[13]); | ||
580 | sb[2] &= 0x0f; | ||
300 | } | 581 | } |
301 | /* No error ?? */ | ||
302 | printk(KERN_ERR "ata%u: called with no error (%02X)!\n", qc->ap->id, drv_stat); | ||
303 | /* additional-sense-code[-qualifier] */ | ||
304 | 582 | ||
305 | sb[0] = 0x70; | 583 | sb[0] = 0x70; |
306 | sb[2] = MEDIUM_ERROR; | 584 | sb[7] = 0x0a; |
307 | sb[7] = 0x0A; | 585 | if (tf->flags & ATA_TFLAG_LBA && !(tf->flags & ATA_TFLAG_LBA48)) { |
308 | if (cmd->sc_data_direction == DMA_FROM_DEVICE) { | 586 | /* A small (28b) LBA will fit in the 32b info field */ |
309 | sb[12] = 0x11; /* "unrecovered read error" */ | 587 | sb[0] |= 0x80; /* set valid bit */ |
310 | sb[13] = 0x04; | 588 | sb[3] = tf->device & 0x0f; |
311 | } else { | 589 | sb[4] = tf->lbah; |
312 | sb[12] = 0x0C; /* "write error - */ | 590 | sb[5] = tf->lbam; |
313 | sb[13] = 0x02; /* auto-reallocation failed" */ | 591 | sb[6] = tf->lbal; |
314 | } | 592 | } |
315 | } | 593 | } |
316 | 594 | ||
@@ -629,11 +907,36 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, u8 *scsicmd) | |||
629 | static int ata_scsi_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) | 907 | static int ata_scsi_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) |
630 | { | 908 | { |
631 | struct scsi_cmnd *cmd = qc->scsicmd; | 909 | struct scsi_cmnd *cmd = qc->scsicmd; |
910 | int need_sense = drv_stat & (ATA_ERR | ATA_BUSY | ATA_DRQ); | ||
911 | |||
912 | /* For ATA pass thru (SAT) commands, generate a sense block if | ||
913 | * user mandated it or if there's an error. Note that if we | ||
914 | * generate because the user forced us to, a check condition | ||
915 | * is generated and the ATA register values are returned | ||
916 | * whether the command completed successfully or not. If there | ||
917 | * was no error, SK, ASC and ASCQ will all be zero. | ||
918 | */ | ||
919 | if (((cmd->cmnd[0] == ATA_16) || (cmd->cmnd[0] == ATA_12)) && | ||
920 | ((cmd->cmnd[2] & 0x20) || need_sense)) { | ||
921 | ata_gen_ata_desc_sense(qc); | ||
922 | } else { | ||
923 | if (!need_sense) { | ||
924 | cmd->result = SAM_STAT_GOOD; | ||
925 | } else { | ||
926 | /* TODO: decide which descriptor format to use | ||
927 | * for 48b LBA devices and call that here | ||
928 | * instead of the fixed desc, which is only | ||
929 | * good for smaller LBA (and maybe CHS?) | ||
930 | * devices. | ||
931 | */ | ||
932 | ata_gen_fixed_sense(qc); | ||
933 | } | ||
934 | } | ||
632 | 935 | ||
633 | if (unlikely(drv_stat & (ATA_ERR | ATA_BUSY | ATA_DRQ))) | 936 | if (need_sense) { |
634 | ata_to_sense_error(qc, drv_stat); | 937 | /* The ata_gen_..._sense routines fill in tf */ |
635 | else | 938 | ata_dump_status(qc->ap->id, &qc->tf); |
636 | cmd->result = SAM_STAT_GOOD; | 939 | } |
637 | 940 | ||
638 | qc->scsidone(cmd); | 941 | qc->scsidone(cmd); |
639 | 942 | ||
@@ -674,8 +977,8 @@ static void ata_scsi_translate(struct ata_port *ap, struct ata_device *dev, | |||
674 | return; | 977 | return; |
675 | 978 | ||
676 | /* data is present; dma-map it */ | 979 | /* data is present; dma-map it */ |
677 | if (cmd->sc_data_direction == DMA_FROM_DEVICE || | 980 | if (cmd->sc_data_direction == SCSI_DATA_READ || |
678 | cmd->sc_data_direction == DMA_TO_DEVICE) { | 981 | cmd->sc_data_direction == SCSI_DATA_WRITE) { |
679 | if (unlikely(cmd->request_bufflen < 1)) { | 982 | if (unlikely(cmd->request_bufflen < 1)) { |
680 | printk(KERN_WARNING "ata%u(%u): WARNING: zero len r/w req\n", | 983 | printk(KERN_WARNING "ata%u(%u): WARNING: zero len r/w req\n", |
681 | ap->id, dev->devno); | 984 | ap->id, dev->devno); |
@@ -695,7 +998,6 @@ static void ata_scsi_translate(struct ata_port *ap, struct ata_device *dev, | |||
695 | 998 | ||
696 | if (xlat_func(qc, scsicmd)) | 999 | if (xlat_func(qc, scsicmd)) |
697 | goto err_out; | 1000 | goto err_out; |
698 | |||
699 | /* select device, send command to hardware */ | 1001 | /* select device, send command to hardware */ |
700 | if (ata_qc_issue(qc)) | 1002 | if (ata_qc_issue(qc)) |
701 | goto err_out; | 1003 | goto err_out; |
@@ -1307,7 +1609,7 @@ static unsigned int atapi_xlat(struct ata_queued_cmd *qc, u8 *scsicmd) | |||
1307 | struct scsi_cmnd *cmd = qc->scsicmd; | 1609 | struct scsi_cmnd *cmd = qc->scsicmd; |
1308 | struct ata_device *dev = qc->dev; | 1610 | struct ata_device *dev = qc->dev; |
1309 | int using_pio = (dev->flags & ATA_DFLAG_PIO); | 1611 | int using_pio = (dev->flags & ATA_DFLAG_PIO); |
1310 | int nodata = (cmd->sc_data_direction == DMA_NONE); | 1612 | int nodata = (cmd->sc_data_direction == SCSI_DATA_NONE); |
1311 | 1613 | ||
1312 | if (!using_pio) | 1614 | if (!using_pio) |
1313 | /* Check whether ATAPI DMA is safe */ | 1615 | /* Check whether ATAPI DMA is safe */ |
@@ -1319,7 +1621,7 @@ static unsigned int atapi_xlat(struct ata_queued_cmd *qc, u8 *scsicmd) | |||
1319 | qc->complete_fn = atapi_qc_complete; | 1621 | qc->complete_fn = atapi_qc_complete; |
1320 | 1622 | ||
1321 | qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; | 1623 | qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
1322 | if (cmd->sc_data_direction == DMA_TO_DEVICE) { | 1624 | if (cmd->sc_data_direction == SCSI_DATA_WRITE) { |
1323 | qc->tf.flags |= ATA_TFLAG_WRITE; | 1625 | qc->tf.flags |= ATA_TFLAG_WRITE; |
1324 | DPRINTK("direction: write\n"); | 1626 | DPRINTK("direction: write\n"); |
1325 | } | 1627 | } |
@@ -1343,7 +1645,7 @@ static unsigned int atapi_xlat(struct ata_queued_cmd *qc, u8 *scsicmd) | |||
1343 | 1645 | ||
1344 | #ifdef ATAPI_ENABLE_DMADIR | 1646 | #ifdef ATAPI_ENABLE_DMADIR |
1345 | /* some SATA bridges need us to indicate data xfer direction */ | 1647 | /* some SATA bridges need us to indicate data xfer direction */ |
1346 | if (cmd->sc_data_direction != DMA_TO_DEVICE) | 1648 | if (cmd->sc_data_direction != SCSI_DATA_WRITE) |
1347 | qc->tf.feature |= ATAPI_DMADIR; | 1649 | qc->tf.feature |= ATAPI_DMADIR; |
1348 | #endif | 1650 | #endif |
1349 | } | 1651 | } |
@@ -1396,6 +1698,143 @@ ata_scsi_find_dev(struct ata_port *ap, struct scsi_device *scsidev) | |||
1396 | return dev; | 1698 | return dev; |
1397 | } | 1699 | } |
1398 | 1700 | ||
1701 | /* | ||
1702 | * ata_scsi_map_proto - Map pass-thru protocol value to taskfile value. | ||
1703 | * @byte1: Byte 1 from pass-thru CDB. | ||
1704 | * | ||
1705 | * RETURNS: | ||
1706 | * ATA_PROT_UNKNOWN if mapping failed/unimplemented, protocol otherwise. | ||
1707 | */ | ||
1708 | static u8 | ||
1709 | ata_scsi_map_proto(u8 byte1) | ||
1710 | { | ||
1711 | switch((byte1 & 0x1e) >> 1) { | ||
1712 | case 3: /* Non-data */ | ||
1713 | return ATA_PROT_NODATA; | ||
1714 | |||
1715 | case 6: /* DMA */ | ||
1716 | return ATA_PROT_DMA; | ||
1717 | |||
1718 | case 4: /* PIO Data-in */ | ||
1719 | case 5: /* PIO Data-out */ | ||
1720 | if (byte1 & 0xe0) { | ||
1721 | return ATA_PROT_PIO_MULT; | ||
1722 | } | ||
1723 | return ATA_PROT_PIO; | ||
1724 | |||
1725 | case 10: /* Device Reset */ | ||
1726 | case 0: /* Hard Reset */ | ||
1727 | case 1: /* SRST */ | ||
1728 | case 2: /* Bus Idle */ | ||
1729 | case 7: /* Packet */ | ||
1730 | case 8: /* DMA Queued */ | ||
1731 | case 9: /* Device Diagnostic */ | ||
1732 | case 11: /* UDMA Data-in */ | ||
1733 | case 12: /* UDMA Data-Out */ | ||
1734 | case 13: /* FPDMA */ | ||
1735 | default: /* Reserved */ | ||
1736 | break; | ||
1737 | } | ||
1738 | |||
1739 | return ATA_PROT_UNKNOWN; | ||
1740 | } | ||
1741 | |||
1742 | /** | ||
1743 | * ata_scsi_pass_thru - convert ATA pass-thru CDB to taskfile | ||
1744 | * @qc: command structure to be initialized | ||
1745 | * @cmd: SCSI command to convert | ||
1746 | * | ||
1747 | * Handles either 12 or 16-byte versions of the CDB. | ||
1748 | * | ||
1749 | * RETURNS: | ||
1750 | * Zero on success, non-zero on failure. | ||
1751 | */ | ||
1752 | static unsigned int | ||
1753 | ata_scsi_pass_thru(struct ata_queued_cmd *qc, u8 *scsicmd) | ||
1754 | { | ||
1755 | struct ata_taskfile *tf = &(qc->tf); | ||
1756 | struct scsi_cmnd *cmd = qc->scsicmd; | ||
1757 | |||
1758 | if ((tf->protocol = ata_scsi_map_proto(scsicmd[1])) == ATA_PROT_UNKNOWN) | ||
1759 | return 1; | ||
1760 | |||
1761 | /* | ||
1762 | * 12 and 16 byte CDBs use different offsets to | ||
1763 | * provide the various register values. | ||
1764 | */ | ||
1765 | if (scsicmd[0] == ATA_16) { | ||
1766 | /* | ||
1767 | * 16-byte CDB - may contain extended commands. | ||
1768 | * | ||
1769 | * If that is the case, copy the upper byte register values. | ||
1770 | */ | ||
1771 | if (scsicmd[1] & 0x01) { | ||
1772 | tf->hob_feature = scsicmd[3]; | ||
1773 | tf->hob_nsect = scsicmd[5]; | ||
1774 | tf->hob_lbal = scsicmd[7]; | ||
1775 | tf->hob_lbam = scsicmd[9]; | ||
1776 | tf->hob_lbah = scsicmd[11]; | ||
1777 | tf->flags |= ATA_TFLAG_LBA48; | ||
1778 | } else | ||
1779 | tf->flags &= ~ATA_TFLAG_LBA48; | ||
1780 | |||
1781 | /* | ||
1782 | * Always copy low byte, device and command registers. | ||
1783 | */ | ||
1784 | tf->feature = scsicmd[4]; | ||
1785 | tf->nsect = scsicmd[6]; | ||
1786 | tf->lbal = scsicmd[8]; | ||
1787 | tf->lbam = scsicmd[10]; | ||
1788 | tf->lbah = scsicmd[12]; | ||
1789 | tf->device = scsicmd[13]; | ||
1790 | tf->command = scsicmd[14]; | ||
1791 | } else { | ||
1792 | /* | ||
1793 | * 12-byte CDB - incapable of extended commands. | ||
1794 | */ | ||
1795 | tf->flags &= ~ATA_TFLAG_LBA48; | ||
1796 | |||
1797 | tf->feature = scsicmd[3]; | ||
1798 | tf->nsect = scsicmd[4]; | ||
1799 | tf->lbal = scsicmd[5]; | ||
1800 | tf->lbam = scsicmd[6]; | ||
1801 | tf->lbah = scsicmd[7]; | ||
1802 | tf->device = scsicmd[8]; | ||
1803 | tf->command = scsicmd[9]; | ||
1804 | } | ||
1805 | |||
1806 | /* | ||
1807 | * Filter SET_FEATURES - XFER MODE command -- otherwise, | ||
1808 | * SET_FEATURES - XFER MODE must be preceded/succeeded | ||
1809 | * by an update to hardware-specific registers for each | ||
1810 | * controller (i.e. the reason for ->set_piomode(), | ||
1811 | * ->set_dmamode(), and ->post_set_mode() hooks). | ||
1812 | */ | ||
1813 | if ((tf->command == ATA_CMD_SET_FEATURES) | ||
1814 | && (tf->feature == SETFEATURES_XFER)) | ||
1815 | return 1; | ||
1816 | |||
1817 | /* | ||
1818 | * Set flags so that all registers will be written, | ||
1819 | * and pass on write indication (used for PIO/DMA | ||
1820 | * setup.) | ||
1821 | */ | ||
1822 | tf->flags |= (ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE); | ||
1823 | |||
1824 | if (cmd->sc_data_direction == SCSI_DATA_WRITE) | ||
1825 | tf->flags |= ATA_TFLAG_WRITE; | ||
1826 | |||
1827 | /* | ||
1828 | * Set transfer length. | ||
1829 | * | ||
1830 | * TODO: find out if we need to do more here to | ||
1831 | * cover scatter/gather case. | ||
1832 | */ | ||
1833 | qc->nsect = cmd->bufflen / ATA_SECT_SIZE; | ||
1834 | |||
1835 | return 0; | ||
1836 | } | ||
1837 | |||
1399 | /** | 1838 | /** |
1400 | * ata_get_xlat_func - check if SCSI to ATA translation is possible | 1839 | * ata_get_xlat_func - check if SCSI to ATA translation is possible |
1401 | * @dev: ATA device | 1840 | * @dev: ATA device |
@@ -1428,6 +1867,10 @@ static inline ata_xlat_func_t ata_get_xlat_func(struct ata_device *dev, u8 cmd) | |||
1428 | case VERIFY: | 1867 | case VERIFY: |
1429 | case VERIFY_16: | 1868 | case VERIFY_16: |
1430 | return ata_scsi_verify_xlat; | 1869 | return ata_scsi_verify_xlat; |
1870 | |||
1871 | case ATA_12: | ||
1872 | case ATA_16: | ||
1873 | return ata_scsi_pass_thru; | ||
1431 | } | 1874 | } |
1432 | 1875 | ||
1433 | return NULL; | 1876 | return NULL; |
@@ -1584,7 +2027,7 @@ void ata_scsi_simulate(u16 *id, | |||
1584 | ata_scsi_rbuf_fill(&args, ata_scsiop_report_luns); | 2027 | ata_scsi_rbuf_fill(&args, ata_scsiop_report_luns); |
1585 | break; | 2028 | break; |
1586 | 2029 | ||
1587 | /* mandantory commands we haven't implemented yet */ | 2030 | /* mandatory commands we haven't implemented yet */ |
1588 | case REQUEST_SENSE: | 2031 | case REQUEST_SENSE: |
1589 | 2032 | ||
1590 | /* all other commands */ | 2033 | /* all other commands */ |
diff --git a/drivers/scsi/libata.h b/drivers/scsi/libata.h index 6518226b8f87..c595f5f58c16 100644 --- a/drivers/scsi/libata.h +++ b/drivers/scsi/libata.h | |||
@@ -44,10 +44,11 @@ extern void ata_dev_select(struct ata_port *ap, unsigned int device, | |||
44 | unsigned int wait, unsigned int can_sleep); | 44 | unsigned int wait, unsigned int can_sleep); |
45 | extern void ata_tf_to_host_nolock(struct ata_port *ap, struct ata_taskfile *tf); | 45 | extern void ata_tf_to_host_nolock(struct ata_port *ap, struct ata_taskfile *tf); |
46 | extern void swap_buf_le16(u16 *buf, unsigned int buf_words); | 46 | extern void swap_buf_le16(u16 *buf, unsigned int buf_words); |
47 | extern int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg); | ||
48 | extern int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg); | ||
47 | 49 | ||
48 | 50 | ||
49 | /* libata-scsi.c */ | 51 | /* libata-scsi.c */ |
50 | extern void ata_to_sense_error(struct ata_queued_cmd *qc, u8 drv_stat); | ||
51 | extern int ata_scsi_error(struct Scsi_Host *host); | 52 | extern int ata_scsi_error(struct Scsi_Host *host); |
52 | extern unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf, | 53 | extern unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf, |
53 | unsigned int buflen); | 54 | unsigned int buflen); |