MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / usb / storage / shuttle_usbat.c
blobc98fa393814f2a612a65d2e37a4f67f055e6ca6c
1 /* Driver for SCM Microsystems USB-ATAPI cable
3 * $Id: shuttle_usbat.c,v 1.17 2002/04/22 03:39:43 mdharm Exp $
5 * Current development and maintenance by:
6 * (c) 2000, 2001 Robert Baruch (autophile@starband.net)
8 * Developed with the assistance of:
9 * (c) 2002 Alan Stern <stern@rowland.org>
11 * Many originally ATAPI devices were slightly modified to meet the USB
12 * market by using some kind of translation from ATAPI to USB on the host,
13 * and the peripheral would translate from USB back to ATAPI.
15 * SCM Microsystems (www.scmmicro.com) makes a device, sold to OEM's only,
16 * which does the USB-to-ATAPI conversion. By obtaining the data sheet on
17 * their device under nondisclosure agreement, I have been able to write
18 * this driver for Linux.
20 * The chip used in the device can also be used for EPP and ISA translation
21 * as well. This driver is only guaranteed to work with the ATAPI
22 * translation.
24 * The only peripheral that I know of (as of 27 Mar 2001) that uses this
25 * device is the Hewlett-Packard 8200e/8210e/8230e CD-Writer Plus.
27 * This program is free software; you can redistribute it and/or modify it
28 * under the terms of the GNU General Public License as published by the
29 * Free Software Foundation; either version 2, or (at your option) any
30 * later version.
32 * This program is distributed in the hope that it will be useful, but
33 * WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
35 * General Public License for more details.
37 * You should have received a copy of the GNU General Public License along
38 * with this program; if not, write to the Free Software Foundation, Inc.,
39 * 675 Mass Ave, Cambridge, MA 02139, USA.
42 #include <linux/sched.h>
43 #include <linux/errno.h>
44 #include <linux/slab.h>
45 #include <linux/cdrom.h>
47 #include <scsi/scsi.h>
48 #include <scsi/scsi_cmnd.h>
50 #include "transport.h"
51 #include "protocol.h"
52 #include "usb.h"
53 #include "debug.h"
54 #include "shuttle_usbat.h"
56 #define short_pack(LSB,MSB) ( ((u16)(LSB)) | ( ((u16)(MSB))<<8 ) )
57 #define LSB_of(s) ((s)&0xFF)
58 #define MSB_of(s) ((s)>>8)
60 int transferred = 0;
62 static int usbat_read(struct us_data *us,
63 unsigned char access,
64 unsigned char reg,
65 unsigned char *content)
67 int result;
69 result = usb_stor_ctrl_transfer(us,
70 us->recv_ctrl_pipe,
71 access,
72 0xC0,
73 (u16)reg,
75 content,
76 1);
78 return result;
81 static int usbat_write(struct us_data *us,
82 unsigned char access,
83 unsigned char reg,
84 unsigned char content)
86 int result;
88 result = usb_stor_ctrl_transfer(us,
89 us->send_ctrl_pipe,
90 access|0x01,
91 0x40,
92 short_pack(reg, content),
94 NULL,
95 0);
97 return result;
100 static int usbat_set_shuttle_features(struct us_data *us,
101 unsigned char external_trigger,
102 unsigned char epp_control,
103 unsigned char mask_byte,
104 unsigned char test_pattern,
105 unsigned char subcountH,
106 unsigned char subcountL)
108 int result;
109 unsigned char *command = us->iobuf;
111 command[0] = 0x40;
112 command[1] = 0x81;
113 command[2] = epp_control;
114 command[3] = external_trigger;
115 command[4] = test_pattern;
116 command[5] = mask_byte;
117 command[6] = subcountL;
118 command[7] = subcountH;
120 result = usb_stor_ctrl_transfer(us,
121 us->send_ctrl_pipe,
122 0x80,
123 0x40,
126 command,
129 return result;
132 static int usbat_read_block(struct us_data *us,
133 unsigned char access,
134 unsigned char reg,
135 unsigned char *content,
136 unsigned short len,
137 int use_sg)
139 int result;
140 unsigned char *command = us->iobuf;
142 if (!len)
143 return USB_STOR_TRANSPORT_GOOD;
145 command[0] = 0xC0;
146 command[1] = access | 0x02;
147 command[2] = reg;
148 command[3] = 0;
149 command[4] = 0;
150 command[5] = 0;
151 command[6] = LSB_of(len);
152 command[7] = MSB_of(len);
154 result = usb_stor_ctrl_transfer(us,
155 us->send_ctrl_pipe,
156 0x80,
157 0x40,
160 command,
163 if (result != USB_STOR_XFER_GOOD)
164 return USB_STOR_TRANSPORT_ERROR;
166 result = usb_stor_bulk_transfer_sg(us, us->recv_bulk_pipe,
167 content, len, use_sg, NULL);
169 return (result == USB_STOR_XFER_GOOD ?
170 USB_STOR_TRANSPORT_GOOD : USB_STOR_TRANSPORT_ERROR);
174 * Block, waiting for an ATA device to become not busy or to report
175 * an error condition.
178 static int usbat_wait_not_busy(struct us_data *us, int minutes)
180 int i;
181 int result;
182 unsigned char *status = us->iobuf;
184 /* Synchronizing cache on a CDR could take a heck of a long time,
185 * but probably not more than 10 minutes or so. On the other hand,
186 * doing a full blank on a CDRW at speed 1 will take about 75
187 * minutes!
190 for (i=0; i<1200+minutes*60; i++) {
192 result = usbat_read(us, USBAT_ATA, 0x17, status);
194 if (result!=USB_STOR_XFER_GOOD)
195 return USB_STOR_TRANSPORT_ERROR;
196 if (*status & 0x01) { // check condition
197 result = usbat_read(us, USBAT_ATA, 0x10, status);
198 return USB_STOR_TRANSPORT_FAILED;
200 if (*status & 0x20) // device fault
201 return USB_STOR_TRANSPORT_FAILED;
203 if ((*status & 0x80)==0x00) { // not busy
204 US_DEBUGP("Waited not busy for %d steps\n", i);
205 return USB_STOR_TRANSPORT_GOOD;
208 if (i<500)
209 msleep(10); // 5 seconds
210 else if (i<700)
211 msleep(50); // 10 seconds
212 else if (i<1200)
213 msleep(100); // 50 seconds
214 else
215 msleep(1000); // X minutes
218 US_DEBUGP("Waited not busy for %d minutes, timing out.\n",
219 minutes);
220 return USB_STOR_TRANSPORT_FAILED;
223 static int usbat_write_block(struct us_data *us,
224 unsigned char access,
225 unsigned char reg,
226 unsigned char *content,
227 unsigned short len,
228 int use_sg, int minutes)
230 int result;
231 unsigned char *command = us->iobuf;
233 if (!len)
234 return USB_STOR_TRANSPORT_GOOD;
236 command[0] = 0x40;
237 command[1] = access | 0x03;
238 command[2] = reg;
239 command[3] = 0;
240 command[4] = 0;
241 command[5] = 0;
242 command[6] = LSB_of(len);
243 command[7] = MSB_of(len);
245 result = usb_stor_ctrl_transfer(us,
246 us->send_ctrl_pipe,
247 0x80,
248 0x40,
251 command,
254 if (result != USB_STOR_XFER_GOOD)
255 return USB_STOR_TRANSPORT_ERROR;
257 result = usb_stor_bulk_transfer_sg(us, us->send_bulk_pipe,
258 content, len, use_sg, NULL);
260 if (result != USB_STOR_XFER_GOOD)
261 return USB_STOR_TRANSPORT_ERROR;
263 return usbat_wait_not_busy(us, minutes);
266 static int usbat_rw_block_test(struct us_data *us,
267 unsigned char access,
268 unsigned char *registers,
269 unsigned char *data_out,
270 unsigned short num_registers,
271 unsigned char data_reg,
272 unsigned char status_reg,
273 unsigned char timeout,
274 unsigned char qualifier,
275 int direction,
276 unsigned char *content,
277 unsigned short len,
278 int use_sg,
279 int minutes)
281 int result;
282 unsigned int pipe = (direction == DMA_FROM_DEVICE) ?
283 us->recv_bulk_pipe : us->send_bulk_pipe;
285 // Not really sure the 0x07, 0x17, 0xfc, 0xe7 is necessary here,
286 // but that's what came out of the trace every single time.
288 unsigned char *command = us->iobuf;
289 int i, j;
290 int cmdlen;
291 unsigned char *data = us->iobuf;
292 unsigned char *status = us->iobuf;
294 BUG_ON(num_registers > US_IOBUF_SIZE/2);
296 for (i=0; i<20; i++) {
299 * The first time we send the full command, which consists
300 * of downloading the SCSI command followed by downloading
301 * the data via a write-and-test. Any other time we only
302 * send the command to download the data -- the SCSI command
303 * is still 'active' in some sense in the device.
305 * We're only going to try sending the data 10 times. After
306 * that, we just return a failure.
309 if (i==0) {
310 cmdlen = 16;
311 command[0] = 0x40;
312 command[1] = access | 0x07;
313 command[2] = 0x07;
314 command[3] = 0x17;
315 command[4] = 0xFC;
316 command[5] = 0xE7;
317 command[6] = LSB_of(num_registers*2);
318 command[7] = MSB_of(num_registers*2);
319 } else
320 cmdlen = 8;
322 command[cmdlen-8] = (direction==DMA_TO_DEVICE ? 0x40 : 0xC0);
323 command[cmdlen-7] = access |
324 (direction==DMA_TO_DEVICE ? 0x05 : 0x04);
325 command[cmdlen-6] = data_reg;
326 command[cmdlen-5] = status_reg;
327 command[cmdlen-4] = timeout;
328 command[cmdlen-3] = qualifier;
329 command[cmdlen-2] = LSB_of(len);
330 command[cmdlen-1] = MSB_of(len);
332 result = usb_stor_ctrl_transfer(us,
333 us->send_ctrl_pipe,
334 0x80,
335 0x40,
338 command,
339 cmdlen);
341 if (result != USB_STOR_XFER_GOOD)
342 return USB_STOR_TRANSPORT_ERROR;
344 if (i==0) {
346 for (j=0; j<num_registers; j++) {
347 data[j<<1] = registers[j];
348 data[1+(j<<1)] = data_out[j];
351 result = usb_stor_bulk_transfer_buf(us,
352 us->send_bulk_pipe,
353 data, num_registers*2, NULL);
355 if (result != USB_STOR_XFER_GOOD)
356 return USB_STOR_TRANSPORT_ERROR;
361 //US_DEBUGP("Transfer %s %d bytes, sg buffers %d\n",
362 // direction == DMA_TO_DEVICE ? "out" : "in",
363 // len, use_sg);
365 result = usb_stor_bulk_transfer_sg(us,
366 pipe, content, len, use_sg, NULL);
369 * If we get a stall on the bulk download, we'll retry
370 * the bulk download -- but not the SCSI command because
371 * in some sense the SCSI command is still 'active' and
372 * waiting for the data. Don't ask me why this should be;
373 * I'm only following what the Windoze driver did.
375 * Note that a stall for the test-and-read/write command means
376 * that the test failed. In this case we're testing to make
377 * sure that the device is error-free
378 * (i.e. bit 0 -- CHK -- of status is 0). The most likely
379 * hypothesis is that the USBAT chip somehow knows what
380 * the device will accept, but doesn't give the device any
381 * data until all data is received. Thus, the device would
382 * still be waiting for the first byte of data if a stall
383 * occurs, even if the stall implies that some data was
384 * transferred.
387 if (result == USB_STOR_XFER_SHORT ||
388 result == USB_STOR_XFER_STALLED) {
391 * If we're reading and we stalled, then clear
392 * the bulk output pipe only the first time.
395 if (direction==DMA_FROM_DEVICE && i==0) {
396 if (usb_stor_clear_halt(us,
397 us->send_bulk_pipe) < 0)
398 return USB_STOR_TRANSPORT_ERROR;
402 * Read status: is the device angry, or just busy?
405 result = usbat_read(us, USBAT_ATA,
406 direction==DMA_TO_DEVICE ? 0x17 : 0x0E,
407 status);
409 if (result!=USB_STOR_XFER_GOOD)
410 return USB_STOR_TRANSPORT_ERROR;
411 if (*status & 0x01) // check condition
412 return USB_STOR_TRANSPORT_FAILED;
413 if (*status & 0x20) // device fault
414 return USB_STOR_TRANSPORT_FAILED;
416 US_DEBUGP("Redoing %s\n",
417 direction==DMA_TO_DEVICE ? "write" : "read");
419 } else if (result != USB_STOR_XFER_GOOD)
420 return USB_STOR_TRANSPORT_ERROR;
421 else
422 return usbat_wait_not_busy(us, minutes);
426 US_DEBUGP("Bummer! %s bulk data 20 times failed.\n",
427 direction==DMA_TO_DEVICE ? "Writing" : "Reading");
429 return USB_STOR_TRANSPORT_FAILED;
433 * Write data to multiple registers at once. Not meant for large
434 * transfers of data!
437 static int usbat_multiple_write(struct us_data *us,
438 unsigned char access,
439 unsigned char *registers,
440 unsigned char *data_out,
441 unsigned short num_registers)
443 int result;
444 unsigned char *data = us->iobuf;
445 int i;
446 unsigned char *command = us->iobuf;
448 BUG_ON(num_registers > US_IOBUF_SIZE/2);
450 command[0] = 0x40;
451 command[1] = access | 0x07;
452 command[2] = 0;
453 command[3] = 0;
454 command[4] = 0;
455 command[5] = 0;
456 command[6] = LSB_of(num_registers*2);
457 command[7] = MSB_of(num_registers*2);
459 result = usb_stor_ctrl_transfer(us,
460 us->send_ctrl_pipe,
461 0x80,
462 0x40,
465 command,
468 if (result != USB_STOR_XFER_GOOD)
469 return USB_STOR_TRANSPORT_ERROR;
471 for (i=0; i<num_registers; i++) {
472 data[i<<1] = registers[i];
473 data[1+(i<<1)] = data_out[i];
476 result = usb_stor_bulk_transfer_buf(us,
477 us->send_bulk_pipe, data, num_registers*2, NULL);
479 if (result != USB_STOR_XFER_GOOD)
480 return USB_STOR_TRANSPORT_ERROR;
482 return usbat_wait_not_busy(us, 0);
485 static int usbat_read_user_io(struct us_data *us, unsigned char *data_flags)
487 int result;
489 result = usb_stor_ctrl_transfer(us,
490 us->recv_ctrl_pipe,
491 0x82,
492 0xC0,
495 data_flags,
498 return result;
501 static int usbat_write_user_io(struct us_data *us,
502 unsigned char enable_flags,
503 unsigned char data_flags)
505 int result;
507 result = usb_stor_ctrl_transfer(us,
508 us->send_ctrl_pipe,
509 0x82,
510 0x40,
511 short_pack(enable_flags, data_flags),
513 NULL,
516 return result;
520 * Squeeze a potentially huge (> 65535 byte) read10 command into
521 * a little ( <= 65535 byte) ATAPI pipe
524 static int usbat_handle_read10(struct us_data *us,
525 unsigned char *registers,
526 unsigned char *data,
527 struct scsi_cmnd *srb)
529 int result = USB_STOR_TRANSPORT_GOOD;
530 unsigned char *buffer;
531 unsigned int len;
532 unsigned int sector;
533 unsigned int sg_segment = 0;
534 unsigned int sg_offset = 0;
536 US_DEBUGP("handle_read10: transfersize %d\n",
537 srb->transfersize);
539 if (srb->request_bufflen < 0x10000) {
541 result = usbat_rw_block_test(us, USBAT_ATA,
542 registers, data, 19,
543 0x10, 0x17, 0xFD, 0x30,
544 DMA_FROM_DEVICE,
545 srb->request_buffer,
546 srb->request_bufflen, srb->use_sg, 1);
548 return result;
552 * Since we're requesting more data than we can handle in
553 * a single read command (max is 64k-1), we will perform
554 * multiple reads, but each read must be in multiples of
555 * a sector. Luckily the sector size is in srb->transfersize
556 * (see linux/drivers/scsi/sr.c).
559 if (data[7+0] == GPCMD_READ_CD) {
560 len = short_pack(data[7+9], data[7+8]);
561 len <<= 16;
562 len |= data[7+7];
563 US_DEBUGP("handle_read10: GPCMD_READ_CD: len %d\n", len);
564 srb->transfersize = srb->request_bufflen/len;
567 if (!srb->transfersize) {
568 srb->transfersize = 2048; /* A guess */
569 US_DEBUGP("handle_read10: transfersize 0, forcing %d\n",
570 srb->transfersize);
573 // Since we only read in one block at a time, we have to create
574 // a bounce buffer and move the data a piece at a time between the
575 // bounce buffer and the actual transfer buffer.
577 len = (65535/srb->transfersize) * srb->transfersize;
578 US_DEBUGP("Max read is %d bytes\n", len);
579 len = min(len, srb->request_bufflen);
580 buffer = kmalloc(len, GFP_NOIO);
581 if (buffer == NULL) // bloody hell!
582 return USB_STOR_TRANSPORT_FAILED;
583 sector = short_pack(data[7+3], data[7+2]);
584 sector <<= 16;
585 sector |= short_pack(data[7+5], data[7+4]);
586 transferred = 0;
588 sg_segment = 0; // for keeping track of where we are in
589 sg_offset = 0; // the scatter/gather list
591 while (transferred != srb->request_bufflen) {
593 if (len > srb->request_bufflen - transferred)
594 len = srb->request_bufflen - transferred;
596 data[3] = len&0xFF; // (cylL) = expected length (L)
597 data[4] = (len>>8)&0xFF; // (cylH) = expected length (H)
599 // Fix up the SCSI command sector and num sectors
601 data[7+2] = MSB_of(sector>>16); // SCSI command sector
602 data[7+3] = LSB_of(sector>>16);
603 data[7+4] = MSB_of(sector&0xFFFF);
604 data[7+5] = LSB_of(sector&0xFFFF);
605 if (data[7+0] == GPCMD_READ_CD)
606 data[7+6] = 0;
607 data[7+7] = MSB_of(len / srb->transfersize); // SCSI command
608 data[7+8] = LSB_of(len / srb->transfersize); // num sectors
610 result = usbat_rw_block_test(us, USBAT_ATA,
611 registers, data, 19,
612 0x10, 0x17, 0xFD, 0x30,
613 DMA_FROM_DEVICE,
614 buffer,
615 len, 0, 1);
617 if (result != USB_STOR_TRANSPORT_GOOD)
618 break;
620 // Store the data in the transfer buffer
621 usb_stor_access_xfer_buf(buffer, len, srb,
622 &sg_segment, &sg_offset, TO_XFER_BUF);
624 // Update the amount transferred and the sector number
626 transferred += len;
627 sector += len / srb->transfersize;
629 } // while transferred != srb->request_bufflen
631 kfree(buffer);
632 return result;
635 static int hp_8200e_select_and_test_registers(struct us_data *us)
637 int selector;
638 unsigned char *status = us->iobuf;
640 // try device = master, then device = slave.
642 for (selector = 0xA0; selector <= 0xB0; selector += 0x10) {
644 if (usbat_write(us, USBAT_ATA, 0x16, selector) !=
645 USB_STOR_XFER_GOOD)
646 return USB_STOR_TRANSPORT_ERROR;
648 if (usbat_read(us, USBAT_ATA, 0x17, status) !=
649 USB_STOR_XFER_GOOD)
650 return USB_STOR_TRANSPORT_ERROR;
652 if (usbat_read(us, USBAT_ATA, 0x16, status) !=
653 USB_STOR_XFER_GOOD)
654 return USB_STOR_TRANSPORT_ERROR;
656 if (usbat_read(us, USBAT_ATA, 0x14, status) !=
657 USB_STOR_XFER_GOOD)
658 return USB_STOR_TRANSPORT_ERROR;
660 if (usbat_read(us, USBAT_ATA, 0x15, status) !=
661 USB_STOR_XFER_GOOD)
662 return USB_STOR_TRANSPORT_ERROR;
664 if (usbat_write(us, USBAT_ATA, 0x14, 0x55) !=
665 USB_STOR_XFER_GOOD)
666 return USB_STOR_TRANSPORT_ERROR;
668 if (usbat_write(us, USBAT_ATA, 0x15, 0xAA) !=
669 USB_STOR_XFER_GOOD)
670 return USB_STOR_TRANSPORT_ERROR;
672 if (usbat_read(us, USBAT_ATA, 0x14, status) !=
673 USB_STOR_XFER_GOOD)
674 return USB_STOR_TRANSPORT_ERROR;
676 if (usbat_read(us, USBAT_ATA, 0x15, status) !=
677 USB_STOR_XFER_GOOD)
678 return USB_STOR_TRANSPORT_ERROR;
681 return USB_STOR_TRANSPORT_GOOD;
684 int init_8200e(struct us_data *us)
686 int result;
687 unsigned char *status = us->iobuf;
689 // Enable peripheral control signals
691 if (usbat_write_user_io(us,
692 USBAT_UIO_OE1 | USBAT_UIO_OE0,
693 USBAT_UIO_EPAD | USBAT_UIO_1) != USB_STOR_XFER_GOOD)
694 return USB_STOR_TRANSPORT_ERROR;
696 US_DEBUGP("INIT 1\n");
698 msleep(2000);
700 if (usbat_read_user_io(us, status) !=
701 USB_STOR_XFER_GOOD)
702 return USB_STOR_TRANSPORT_ERROR;
704 US_DEBUGP("INIT 2\n");
706 if (usbat_read_user_io(us, status) !=
707 USB_STOR_XFER_GOOD)
708 return USB_STOR_TRANSPORT_ERROR;
710 US_DEBUGP("INIT 3\n");
712 // Reset peripheral, enable periph control signals
713 // (bring reset signal up)
715 if (usbat_write_user_io(us,
716 USBAT_UIO_DRVRST | USBAT_UIO_OE1 | USBAT_UIO_OE0,
717 USBAT_UIO_EPAD | USBAT_UIO_1) != USB_STOR_XFER_GOOD)
718 return USB_STOR_TRANSPORT_ERROR;
720 US_DEBUGP("INIT 4\n");
722 // Enable periph control signals
723 // (bring reset signal down)
725 if (usbat_write_user_io(us,
726 USBAT_UIO_OE1 | USBAT_UIO_OE0,
727 USBAT_UIO_EPAD | USBAT_UIO_1) != USB_STOR_XFER_GOOD)
728 return USB_STOR_TRANSPORT_ERROR;
730 US_DEBUGP("INIT 5\n");
732 msleep(250);
734 // Write 0x80 to ISA port 0x3F
736 if (usbat_write(us, USBAT_ISA, 0x3F, 0x80) !=
737 USB_STOR_XFER_GOOD)
738 return USB_STOR_TRANSPORT_ERROR;
740 US_DEBUGP("INIT 6\n");
742 // Read ISA port 0x27
744 if (usbat_read(us, USBAT_ISA, 0x27, status) !=
745 USB_STOR_XFER_GOOD)
746 return USB_STOR_TRANSPORT_ERROR;
748 US_DEBUGP("INIT 7\n");
750 if (usbat_read_user_io(us, status) !=
751 USB_STOR_XFER_GOOD)
752 return USB_STOR_TRANSPORT_ERROR;
754 US_DEBUGP("INIT 8\n");
756 if ( (result = hp_8200e_select_and_test_registers(us)) !=
757 USB_STOR_TRANSPORT_GOOD)
758 return result;
760 US_DEBUGP("INIT 9\n");
762 if (usbat_read_user_io(us, status) !=
763 USB_STOR_XFER_GOOD)
764 return USB_STOR_TRANSPORT_ERROR;
766 US_DEBUGP("INIT 10\n");
768 // Enable periph control signals and card detect
770 if (usbat_write_user_io(us,
771 USBAT_UIO_ACKD |USBAT_UIO_OE1 | USBAT_UIO_OE0,
772 USBAT_UIO_EPAD | USBAT_UIO_1) != USB_STOR_XFER_GOOD)
773 return USB_STOR_TRANSPORT_ERROR;
775 US_DEBUGP("INIT 11\n");
777 if (usbat_read_user_io(us, status) !=
778 USB_STOR_XFER_GOOD)
779 return USB_STOR_TRANSPORT_ERROR;
781 US_DEBUGP("INIT 12\n");
783 msleep(1400);
785 if (usbat_read_user_io(us, status) !=
786 USB_STOR_XFER_GOOD)
787 return USB_STOR_TRANSPORT_ERROR;
789 US_DEBUGP("INIT 13\n");
791 if ( (result = hp_8200e_select_and_test_registers(us)) !=
792 USB_STOR_TRANSPORT_GOOD)
793 return result;
795 US_DEBUGP("INIT 14\n");
797 if (usbat_set_shuttle_features(us,
798 0x83, 0x00, 0x88, 0x08, 0x15, 0x14) !=
799 USB_STOR_XFER_GOOD)
800 return USB_STOR_TRANSPORT_ERROR;
802 US_DEBUGP("INIT 15\n");
804 return USB_STOR_TRANSPORT_GOOD;
808 * Transport for the HP 8200e
810 int hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us)
812 int result;
813 unsigned char *status = us->iobuf;
814 unsigned char registers[32];
815 unsigned char data[32];
816 unsigned int len;
817 int i;
818 char string[64];
820 len = srb->request_bufflen;
822 /* Send A0 (ATA PACKET COMMAND).
823 Note: I guess we're never going to get any of the ATA
824 commands... just ATA Packet Commands.
827 registers[0] = 0x11;
828 registers[1] = 0x12;
829 registers[2] = 0x13;
830 registers[3] = 0x14;
831 registers[4] = 0x15;
832 registers[5] = 0x16;
833 registers[6] = 0x17;
834 data[0] = 0x00;
835 data[1] = 0x00;
836 data[2] = 0x00;
837 data[3] = len&0xFF; // (cylL) = expected length (L)
838 data[4] = (len>>8)&0xFF; // (cylH) = expected length (H)
839 data[5] = 0xB0; // (device sel) = slave
840 data[6] = 0xA0; // (command) = ATA PACKET COMMAND
842 for (i=7; i<19; i++) {
843 registers[i] = 0x10;
844 data[i] = (i-7 >= srb->cmd_len) ? 0 : srb->cmnd[i-7];
847 result = usbat_read(us, USBAT_ATA, 0x17, status);
848 US_DEBUGP("Status = %02X\n", *status);
849 if (result != USB_STOR_XFER_GOOD)
850 return USB_STOR_TRANSPORT_ERROR;
851 if (srb->cmnd[0] == TEST_UNIT_READY)
852 transferred = 0;
854 if (srb->sc_data_direction == DMA_TO_DEVICE) {
856 result = usbat_rw_block_test(us, USBAT_ATA,
857 registers, data, 19,
858 0x10, 0x17, 0xFD, 0x30,
859 DMA_TO_DEVICE,
860 srb->request_buffer,
861 len, srb->use_sg, 10);
863 if (result == USB_STOR_TRANSPORT_GOOD) {
864 transferred += len;
865 US_DEBUGP("Wrote %08X bytes\n", transferred);
868 return result;
870 } else if (srb->cmnd[0] == READ_10 ||
871 srb->cmnd[0] == GPCMD_READ_CD) {
873 return usbat_handle_read10(us, registers, data, srb);
877 if (len > 0xFFFF) {
878 US_DEBUGP("Error: len = %08X... what do I do now?\n",
879 len);
880 return USB_STOR_TRANSPORT_ERROR;
883 if ( (result = usbat_multiple_write(us,
884 USBAT_ATA,
885 registers, data, 7)) != USB_STOR_TRANSPORT_GOOD) {
886 return result;
889 // Write the 12-byte command header.
891 // If the command is BLANK then set the timer for 75 minutes.
892 // Otherwise set it for 10 minutes.
894 // NOTE: THE 8200 DOCUMENTATION STATES THAT BLANKING A CDRW
895 // AT SPEED 4 IS UNRELIABLE!!!
897 if ( (result = usbat_write_block(us,
898 USBAT_ATA, 0x10, srb->cmnd, 12, 0,
899 srb->cmnd[0]==GPCMD_BLANK ? 75 : 10)) !=
900 USB_STOR_TRANSPORT_GOOD) {
901 return result;
904 // If there is response data to be read in
905 // then do it here.
907 if (len != 0 && (srb->sc_data_direction == DMA_FROM_DEVICE)) {
909 // How many bytes to read in? Check cylL register
911 if (usbat_read(us, USBAT_ATA, 0x14, status) !=
912 USB_STOR_XFER_GOOD) {
913 return USB_STOR_TRANSPORT_ERROR;
916 if (len > 0xFF) { // need to read cylH also
917 len = *status;
918 if (usbat_read(us, USBAT_ATA, 0x15, status) !=
919 USB_STOR_XFER_GOOD) {
920 return USB_STOR_TRANSPORT_ERROR;
922 len += ((unsigned int) *status)<<8;
924 else
925 len = *status;
928 result = usbat_read_block(us, USBAT_ATA, 0x10,
929 srb->request_buffer, len, srb->use_sg);
931 /* Debug-print the first 32 bytes of the transfer */
933 if (!srb->use_sg) {
934 string[0] = 0;
935 for (i=0; i<len && i<32; i++) {
936 sprintf(string+strlen(string), "%02X ",
937 ((unsigned char *)srb->request_buffer)[i]);
938 if ((i%16)==15) {
939 US_DEBUGP("%s\n", string);
940 string[0] = 0;
943 if (string[0]!=0)
944 US_DEBUGP("%s\n", string);
948 return result;