1 /* Driver for SCM Microsystems USB-ATAPI cable
3 * $Id: shuttle_usbat.c,v 1.11 2000/11/13 22:29:36 mdharm Exp $
5 * Current development and maintenance by:
6 * (c) 2000 Robert Baruch (autophile@dol.net)
8 * Many originally ATAPI devices were slightly modified to meet the USB
9 * market by using some kind of translation from ATAPI to USB on the host,
10 * and the peripheral would translate from USB back to ATAPI.
12 * SCM Microsystems (www.scmmicro.com) makes a device, sold to OEM's only,
13 * which does the USB-to-ATAPI conversion. By obtaining the data sheet on
14 * their device under nondisclosure agreement, I have been able to write
15 * this driver for Linux.
17 * The chip used in the device can also be used for EPP and ISA translation
18 * as well. This driver is only guaranteed to work with the ATAPI
21 * The only peripheral that I know of (as of 8 Sep 2000) that uses this
22 * device is the Hewlett-Packard 8200e/8210e CD-Writer Plus.
24 * This program is free software; you can redistribute it and/or modify it
25 * under the terms of the GNU General Public License as published by the
26 * Free Software Foundation; either version 2, or (at your option) any
29 * This program is distributed in the hope that it will be useful, but
30 * WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32 * General Public License for more details.
34 * You should have received a copy of the GNU General Public License along
35 * with this program; if not, write to the Free Software Foundation, Inc.,
36 * 675 Mass Ave, Cambridge, MA 02139, USA.
39 #include "transport.h"
43 #include "shuttle_usbat.h"
45 #include <linux/sched.h>
46 #include <linux/errno.h>
47 #include <linux/malloc.h>
49 extern int usb_stor_control_msg(struct us_data
*us
, unsigned int pipe
,
50 u8 request
, u8 requesttype
, u16 value
, u16 index
,
51 void *data
, u16 size
);
52 extern int usb_stor_bulk_msg(struct us_data
*us
, void *data
, int pipe
,
53 unsigned int len
, unsigned int *act_len
);
55 #define short_pack(LSB,MSB) ( ((u16)(LSB)) | ( ((u16)(MSB))<<8 ) )
56 #define LSB_of(s) ((s)&0xFF)
57 #define MSB_of(s) ((s)>>8)
62 * Send a control message and wait for the response.
64 * us - the pointer to the us_data structure for the device to use
66 * request - the URB Setup Packet's first 6 bytes. The first byte always
67 * corresponds to the request type, and the second byte always corresponds
68 * to the request. The other 4 bytes do not correspond to value and index,
69 * since they are used in a custom way by the SCM protocol.
71 * xfer_data - a buffer from which to get, or to which to store, any data
72 * that gets send or received, respectively, with the URB. Even though
73 * it looks like we allocate a buffer in this code for the data, xfer_data
74 * must contain enough allocated space.
76 * xfer_len - the number of bytes to send or receive with the URB.
80 static int usbat_send_control(struct us_data
*us
,
82 unsigned char request
,
83 unsigned char requesttype
,
86 unsigned char *xfer_data
,
87 unsigned int xfer_len
) {
91 // Send the URB to the device and wait for a response.
93 /* Why are request and request type reversed in this call? */
95 result
= usb_stor_control_msg(us
, pipe
,
96 request
, requesttype
, value
, index
,
100 // Check the return code for the command.
103 /* if the command was aborted, indicate that */
104 if (result
== -ENOENT
)
105 return USB_STOR_TRANSPORT_ABORTED
;
107 /* a stall is a fatal condition from the device */
108 if (result
== -EPIPE
) {
109 US_DEBUGP("-- Stall on control pipe. Clearing\n");
110 result
= usb_clear_halt(us
->pusb_dev
, pipe
);
111 US_DEBUGP("-- usb_clear_halt() returns %d\n", result
);
112 return USB_STOR_TRANSPORT_FAILED
;
115 /* Uh oh... serious problem here */
116 return USB_STOR_TRANSPORT_ERROR
;
119 return USB_STOR_TRANSPORT_GOOD
;
122 static int usbat_raw_bulk(struct us_data
*us
,
125 unsigned short len
) {
131 if (direction
== SCSI_DATA_READ
)
132 pipe
= usb_rcvbulkpipe(us
->pusb_dev
, us
->ep_in
);
134 pipe
= usb_sndbulkpipe(us
->pusb_dev
, us
->ep_out
);
136 result
= usb_stor_bulk_msg(us
, data
, pipe
, len
, &act_len
);
138 /* if we stall, we need to clear it before we go on */
139 if (result
== -EPIPE
) {
140 US_DEBUGP("EPIPE: clearing endpoint halt for"
141 " pipe 0x%x, stalled at %d bytes\n",
143 usb_clear_halt(us
->pusb_dev
, pipe
);
148 /* NAK - that means we've retried a few times already */
149 if (result
== -ETIMEDOUT
) {
150 US_DEBUGP("usbat_raw_bulk():"
152 return US_BULK_TRANSFER_FAILED
;
155 /* -ENOENT -- we canceled this transfer */
156 if (result
== -ENOENT
) {
157 US_DEBUGP("usbat_raw_bulk():"
158 " transfer aborted\n");
159 return US_BULK_TRANSFER_ABORTED
;
162 if (result
== -EPIPE
) {
163 US_DEBUGP("usbat_raw_bulk():"
164 " output pipe stalled\n");
165 return US_BULK_TRANSFER_SHORT
;
168 /* the catch-all case */
169 US_DEBUGP("us_transfer_partial(): unknown error\n");
170 return US_BULK_TRANSFER_FAILED
;
173 if (act_len
!= len
) {
174 US_DEBUGP("Warning: Transferred only %d bytes\n",
176 return US_BULK_TRANSFER_SHORT
;
179 US_DEBUGP("Transferred %s %d of %d bytes\n",
180 direction
==SCSI_DATA_READ
? "in" : "out", act_len
, len
);
182 return US_BULK_TRANSFER_GOOD
;
186 * Note: direction must be set if command_len == 0.
189 static int usbat_bulk_transport(struct us_data
*us
,
190 unsigned char *command
,
191 unsigned short command_len
,
197 int result
= USB_STOR_TRANSPORT_GOOD
;
200 struct scatterlist
*sg
;
203 return USB_STOR_TRANSPORT_GOOD
;
205 /* transfer the data payload for the command, if there is any */
207 if (command_len
!= 0)
208 direction
= (command
[0]&0x80) ? SCSI_DATA_READ
:
212 result
= usbat_raw_bulk(us
, direction
, data
, len
);
214 sg
= (struct scatterlist
*)data
;
215 for (i
=0; i
<use_sg
&& transferred
<len
; i
++) {
216 result
= usbat_raw_bulk(us
, direction
,
218 len
-transferred
> sg
[i
].length
?
219 sg
[i
].length
: len
-transferred
);
220 if (result
!=US_BULK_TRANSFER_GOOD
)
222 transferred
+= sg
[i
].length
;
229 int usbat_read(struct us_data
*us
,
230 unsigned char access
,
232 unsigned char *content
) {
236 result
= usbat_send_control(us
,
237 usb_rcvctrlpipe(us
->pusb_dev
,0),
248 int usbat_write(struct us_data
*us
,
249 unsigned char access
,
251 unsigned char content
) {
255 result
= usbat_send_control(us
,
256 usb_sndctrlpipe(us
->pusb_dev
,0),
259 short_pack(reg
, content
),
267 int usbat_set_shuttle_features(struct us_data
*us
,
268 unsigned char external_trigger
,
269 unsigned char epp_control
,
270 unsigned char mask_byte
,
271 unsigned char test_pattern
,
272 unsigned char subcountH
,
273 unsigned char subcountL
) {
276 unsigned char command
[8] = {
277 0x40, 0x81, epp_control
, external_trigger
,
278 test_pattern
, mask_byte
, subcountL
, subcountH
281 result
= usbat_send_control(us
,
282 usb_sndctrlpipe(us
->pusb_dev
,0),
293 int usbat_read_block(struct us_data
*us
,
294 unsigned char access
,
296 unsigned char *content
,
301 unsigned char command
[8] = {
302 0xC0, access
|0x02, reg
, 0x00, 0x00, 0x00,
303 LSB_of(len
), MSB_of(len
)
306 result
= usbat_send_control(us
,
307 usb_sndctrlpipe(us
->pusb_dev
,0),
315 if (result
!= USB_STOR_TRANSPORT_GOOD
)
318 result
= usbat_bulk_transport(us
,
319 NULL
, 0, SCSI_DATA_READ
, content
, len
, use_sg
);
325 * Block, waiting for an ATA device to become not busy or to report
326 * an error condition.
329 int usbat_wait_not_busy(struct us_data
*us
, int minutes
) {
333 unsigned char status
;
335 /* Synchronizing cache on a CDR could take a heck of a long time,
336 * but probably not more than 10 minutes or so. On the other hand,
337 * doing a full blank on a CDRW at speed 1 will take about 75
341 for (i
=0; i
<1200+minutes
*60; i
++) {
343 result
= usbat_read(us
, USBAT_ATA
, 0x17, &status
);
345 if (result
!=USB_STOR_TRANSPORT_GOOD
)
347 if (status
&0x01) // check condition
348 return USB_STOR_TRANSPORT_FAILED
;
349 if (status
&0x20) // device fault
350 return USB_STOR_TRANSPORT_FAILED
;
352 if ((status
&0x80)!=0x80) { // not busy
353 US_DEBUGP("Waited not busy for %d steps\n", i
);
354 return USB_STOR_TRANSPORT_GOOD
;
358 wait_ms(10); // 5 seconds
360 wait_ms(50); // 10 seconds
362 wait_ms(100); // 50 seconds
364 wait_ms(1000); // X minutes
367 US_DEBUGP("Waited not busy for %d minutes, timing out.\n",
369 return USB_STOR_TRANSPORT_FAILED
;
372 int usbat_write_block(struct us_data
*us
,
373 unsigned char access
,
375 unsigned char *content
,
381 unsigned char command
[8] = {
382 0x40, access
|0x03, reg
, 0x00, 0x00, 0x00,
383 LSB_of(len
), MSB_of(len
)
386 result
= usbat_send_control(us
,
387 usb_sndctrlpipe(us
->pusb_dev
,0),
395 if (result
!= USB_STOR_TRANSPORT_GOOD
)
398 result
= usbat_bulk_transport(us
,
399 NULL
, 0, SCSI_DATA_WRITE
, content
, len
, use_sg
);
401 if (result
!= USB_STOR_TRANSPORT_GOOD
)
404 return usbat_wait_not_busy(us
, minutes
);
407 int usbat_rw_block_test(struct us_data
*us
,
408 unsigned char access
,
409 unsigned char *registers
,
410 unsigned char *data_out
,
411 unsigned short num_registers
,
412 unsigned char data_reg
,
413 unsigned char status_reg
,
414 unsigned char timeout
,
415 unsigned char qualifier
,
417 unsigned char *content
,
424 // Not really sure the 0x07, 0x17, 0xfc, 0xe7 is necessary here,
425 // but that's what came out of the trace every single time.
427 unsigned char command
[16] = {
428 0x40, access
|0x07, 0x07, 0x17, 0xfc, 0xe7,
429 LSB_of(num_registers
*2), MSB_of(num_registers
*2),
430 (direction
==SCSI_DATA_WRITE
? 0x40 : 0xC0),
431 access
|(direction
==SCSI_DATA_WRITE
? 0x05 : 0x04),
432 data_reg
, status_reg
,
433 timeout
, qualifier
, LSB_of(len
), MSB_of(len
)
437 unsigned char data
[num_registers
*2];
438 unsigned char status
;
440 for (i
=0; i
<num_registers
; i
++) {
441 data
[i
<<1] = registers
[i
];
442 data
[1+(i
<<1)] = data_out
[i
];
445 for (i
=0; i
<20; i
++) {
448 * The first time we send the full command, which consists
449 * of downloading the SCSI command followed by downloading
450 * the data via a write-and-test. Any other time we only
451 * send the command to download the data -- the SCSI command
452 * is still 'active' in some sense in the device.
454 * We're only going to try sending the data 10 times. After
455 * that, we just return a failure.
458 result
= usbat_send_control(us
,
459 usb_sndctrlpipe(us
->pusb_dev
,0),
464 (i
==0 ? command
: command
+8),
467 if (result
!= USB_STOR_TRANSPORT_GOOD
)
472 result
= usbat_bulk_transport(us
,
473 NULL
, 0, SCSI_DATA_WRITE
,
474 data
, num_registers
*2, 0);
476 if (result
!=USB_STOR_TRANSPORT_GOOD
)
482 //US_DEBUGP("Transfer %s %d bytes, sg buffers %d\n",
483 // direction == SCSI_DATA_WRITE ? "out" : "in",
486 result
= usbat_bulk_transport(us
,
487 NULL
, 0, direction
, content
, len
, use_sg
);
490 * If we get a stall on the bulk download, we'll retry
491 * the bulk download -- but not the SCSI command because
492 * in some sense the SCSI command is still 'active' and
493 * waiting for the data. Don't ask me why this should be;
494 * I'm only following what the Windoze driver did.
496 * Note that a stall for the test-and-read/write command means
497 * that the test failed. In this case we're testing to make
498 * sure that the device is error-free
499 * (i.e. bit 0 -- CHK -- of status is 0). The most likely
500 * hypothesis is that the USBAT chip somehow knows what
501 * the device will accept, but doesn't give the device any
502 * data until all data is received. Thus, the device would
503 * still be waiting for the first byte of data if a stall
504 * occurs, even if the stall implies that some data was
508 if (result
== US_BULK_TRANSFER_SHORT
) {
511 * If we're reading and we stalled, then clear
512 * the bulk output pipe only the first time.
515 if (direction
==SCSI_DATA_READ
&& i
==0)
516 usb_clear_halt(us
->pusb_dev
,
517 usb_sndbulkpipe(us
->pusb_dev
,
520 * Read status: is the device angry, or just busy?
523 result
= usbat_read(us
, USBAT_ATA
,
524 direction
==SCSI_DATA_WRITE
? 0x17 : 0x0E,
527 if (result
!=USB_STOR_TRANSPORT_GOOD
)
529 if (status
&0x01) // check condition
530 return USB_STOR_TRANSPORT_FAILED
;
531 if (status
&0x20) // device fault
532 return USB_STOR_TRANSPORT_FAILED
;
534 US_DEBUGP("Redoing %s\n",
535 direction
==SCSI_DATA_WRITE
? "write" : "read");
537 } else if (result
!= US_BULK_TRANSFER_GOOD
)
540 return usbat_wait_not_busy(us
, minutes
);
544 US_DEBUGP("Bummer! %s bulk data 20 times failed.\n",
545 direction
==SCSI_DATA_WRITE
? "Writing" : "Reading");
547 return USB_STOR_TRANSPORT_FAILED
;
551 * Write data to multiple registers at once. Not meant for large
555 int usbat_multiple_write(struct us_data
*us
,
556 unsigned char access
,
557 unsigned char *registers
,
558 unsigned char *data_out
,
559 unsigned short num_registers
) {
562 unsigned char data
[num_registers
*2];
564 unsigned char command
[8] = {
565 0x40, access
|0x07, 0x00, 0x00, 0x00, 0x00,
566 LSB_of(num_registers
*2), MSB_of(num_registers
*2)
569 for (i
=0; i
<num_registers
; i
++) {
570 data
[i
<<1] = registers
[i
];
571 data
[1+(i
<<1)] = data_out
[i
];
574 result
= usbat_send_control(us
,
575 usb_sndctrlpipe(us
->pusb_dev
,0),
583 if (result
!= USB_STOR_TRANSPORT_GOOD
)
586 result
= usbat_bulk_transport(us
,
587 NULL
, 0, SCSI_DATA_WRITE
, data
, num_registers
*2, 0);
589 if (result
!=USB_STOR_TRANSPORT_GOOD
)
592 return usbat_wait_not_busy(us
, 0);
595 int usbat_read_user_io(struct us_data
*us
,
596 unsigned char *data_flags
) {
600 result
= usbat_send_control(us
,
601 usb_rcvctrlpipe(us
->pusb_dev
,0),
612 int usbat_write_user_io(struct us_data
*us
,
613 unsigned char enable_flags
,
614 unsigned char data_flags
) {
618 result
= usbat_send_control(us
,
619 usb_sndctrlpipe(us
->pusb_dev
,0),
622 short_pack(enable_flags
, data_flags
),
631 * Squeeze a potentially huge (> 65535 byte) read10 command into
632 * a little ( <= 65535 byte) ATAPI pipe
635 int usbat_handle_read10(struct us_data
*us
,
636 unsigned char *registers
,
640 int result
= USB_STOR_TRANSPORT_GOOD
;
641 unsigned char *buffer
;
645 struct scatterlist
*sg
= NULL
;
649 US_DEBUGP("handle_read10: transfersize %d\n",
652 if (srb
->request_bufflen
< 0x10000) {
654 result
= usbat_rw_block_test(us
, USBAT_ATA
,
656 0x10, 0x17, 0xFD, 0x30,
659 srb
->request_bufflen
, srb
->use_sg
, 1);
665 * Since we're requesting more data than we can handle in
666 * a single read command (max is 64k-1), we will perform
667 * multiple reads, but each read must be in multiples of
668 * a sector. Luckily the sector size is in srb->transfersize
669 * (see linux/drivers/scsi/sr.c).
672 if (data
[7+0] == GPCMD_READ_CD
) {
673 len
= short_pack(data
[7+9], data
[7+8]);
676 srb
->transfersize
= srb
->request_bufflen
/len
;
680 len
= (65535/srb
->transfersize
) * srb
->transfersize
;
681 US_DEBUGP("Max read is %d bytes\n", len
);
682 buffer
= kmalloc(len
, GFP_KERNEL
);
683 if (buffer
== NULL
) // bloody hell!
684 return USB_STOR_TRANSPORT_FAILED
;
685 sector
= short_pack(data
[7+3], data
[7+2]);
687 sector
|= short_pack(data
[7+5], data
[7+4]);
691 sg
= (struct scatterlist
*)srb
->request_buffer
;
692 sg_segment
= 0; // for keeping track of where we are in
693 sg_offset
= 0; // the scatter/gather list
696 while (transferred
!= srb
->request_bufflen
) {
698 if (len
> srb
->request_bufflen
- transferred
)
699 len
= srb
->request_bufflen
- transferred
;
701 data
[3] = len
&0xFF; // (cylL) = expected length (L)
702 data
[4] = (len
>>8)&0xFF; // (cylH) = expected length (H)
704 // Fix up the SCSI command sector and num sectors
706 data
[7+2] = MSB_of(sector
>>16); // SCSI command sector
707 data
[7+3] = LSB_of(sector
>>16);
708 data
[7+4] = MSB_of(sector
&0xFFFF);
709 data
[7+5] = LSB_of(sector
&0xFFFF);
710 if (data
[7+0] == GPCMD_READ_CD
)
712 data
[7+7] = MSB_of(len
/ srb
->transfersize
); // SCSI command
713 data
[7+8] = LSB_of(len
/ srb
->transfersize
); // num sectors
715 result
= usbat_rw_block_test(us
, USBAT_ATA
,
717 0x10, 0x17, 0xFD, 0x30,
722 if (result
!= USB_STOR_TRANSPORT_GOOD
)
725 // Transfer the received data into the srb buffer
728 memcpy(srb
->request_buffer
+transferred
, buffer
, len
);
733 sg
[sg_segment
].length
-sg_offset
) {
734 memcpy(sg
[sg_segment
].address
+ sg_offset
,
736 sg
[sg_segment
].length
- sg_offset
);
738 sg
[sg_segment
].length
-sg_offset
;
742 memcpy(sg
[sg_segment
].address
+ sg_offset
,
745 sg_offset
+= (len
- amount
);
751 // Update the amount transferred and the sector number
754 sector
+= len
/ srb
->transfersize
;
756 } // while transferred != srb->request_bufflen
762 static int hp_8200e_select_and_test_registers(struct us_data
*us
) {
766 unsigned char status
;
768 // try device = master, then device = slave.
770 for (selector
= 0xA0; selector
<= 0xB0; selector
+= 0x10) {
772 if ( (result
= usbat_write(us
, USBAT_ATA
, 0x16, selector
)) !=
773 USB_STOR_TRANSPORT_GOOD
)
776 if ( (result
= usbat_read(us
, USBAT_ATA
, 0x17, &status
)) !=
777 USB_STOR_TRANSPORT_GOOD
)
780 if ( (result
= usbat_read(us
, USBAT_ATA
, 0x16, &status
)) !=
781 USB_STOR_TRANSPORT_GOOD
)
784 if ( (result
= usbat_read(us
, USBAT_ATA
, 0x14, &status
)) !=
785 USB_STOR_TRANSPORT_GOOD
)
788 if ( (result
= usbat_read(us
, USBAT_ATA
, 0x15, &status
)) !=
789 USB_STOR_TRANSPORT_GOOD
)
792 if ( (result
= usbat_write(us
, USBAT_ATA
, 0x14, 0x55)) !=
793 USB_STOR_TRANSPORT_GOOD
)
796 if ( (result
= usbat_write(us
, USBAT_ATA
, 0x15, 0xAA)) !=
797 USB_STOR_TRANSPORT_GOOD
)
800 if ( (result
= usbat_read(us
, USBAT_ATA
, 0x14, &status
)) !=
801 USB_STOR_TRANSPORT_GOOD
)
804 if ( (result
= usbat_read(us
, USBAT_ATA
, 0x15, &status
)) !=
805 USB_STOR_TRANSPORT_GOOD
)
812 int init_8200e(struct us_data
*us
) {
815 unsigned char status
;
817 // Enable peripheral control signals
819 if ( (result
= usbat_write_user_io(us
,
820 USBAT_UIO_OE1
| USBAT_UIO_OE0
,
821 USBAT_UIO_EPAD
| USBAT_UIO_1
)) != USB_STOR_TRANSPORT_GOOD
)
824 US_DEBUGP("INIT 1\n");
828 if ( (result
= usbat_read_user_io(us
, &status
)) !=
829 USB_STOR_TRANSPORT_GOOD
)
832 US_DEBUGP("INIT 2\n");
834 if ( (result
= usbat_read_user_io(us
, &status
)) !=
835 USB_STOR_TRANSPORT_GOOD
)
838 US_DEBUGP("INIT 3\n");
840 // Reset peripheral, enable periph control signals
841 // (bring reset signal up)
843 if ( (result
= usbat_write_user_io(us
,
844 USBAT_UIO_DRVRST
| USBAT_UIO_OE1
| USBAT_UIO_OE0
,
845 USBAT_UIO_EPAD
| USBAT_UIO_1
)) != USB_STOR_TRANSPORT_GOOD
)
848 US_DEBUGP("INIT 4\n");
850 // Enable periph control signals
851 // (bring reset signal down)
853 if ( (result
= usbat_write_user_io(us
,
854 USBAT_UIO_OE1
| USBAT_UIO_OE0
,
855 USBAT_UIO_EPAD
| USBAT_UIO_1
)) != USB_STOR_TRANSPORT_GOOD
)
858 US_DEBUGP("INIT 5\n");
862 // Write 0x80 to ISA port 0x3F
864 if ( (result
= usbat_write(us
, USBAT_ISA
, 0x3F, 0x80)) !=
865 USB_STOR_TRANSPORT_GOOD
)
868 US_DEBUGP("INIT 6\n");
870 // Read ISA port 0x27
872 if ( (result
= usbat_read(us
, USBAT_ISA
, 0x27, &status
)) !=
873 USB_STOR_TRANSPORT_GOOD
)
876 US_DEBUGP("INIT 7\n");
878 if ( (result
= usbat_read_user_io(us
, &status
)) !=
879 USB_STOR_TRANSPORT_GOOD
)
882 US_DEBUGP("INIT 8\n");
884 if ( (result
= hp_8200e_select_and_test_registers(us
)) !=
885 USB_STOR_TRANSPORT_GOOD
)
888 US_DEBUGP("INIT 9\n");
890 if ( (result
= usbat_read_user_io(us
, &status
)) !=
891 USB_STOR_TRANSPORT_GOOD
)
894 US_DEBUGP("INIT 10\n");
896 // Enable periph control signals and card detect
898 if ( (result
= usbat_write_user_io(us
,
899 USBAT_UIO_ACKD
|USBAT_UIO_OE1
| USBAT_UIO_OE0
,
900 USBAT_UIO_EPAD
| USBAT_UIO_1
)) != USB_STOR_TRANSPORT_GOOD
)
903 US_DEBUGP("INIT 11\n");
905 if ( (result
= usbat_read_user_io(us
, &status
)) !=
906 USB_STOR_TRANSPORT_GOOD
)
909 US_DEBUGP("INIT 12\n");
913 if ( (result
= usbat_read_user_io(us
, &status
)) !=
914 USB_STOR_TRANSPORT_GOOD
)
917 US_DEBUGP("INIT 13\n");
919 if ( (result
= hp_8200e_select_and_test_registers(us
)) !=
920 USB_STOR_TRANSPORT_GOOD
)
923 US_DEBUGP("INIT 14\n");
925 if ( (result
= usbat_set_shuttle_features(us
,
926 0x83, 0x00, 0x88, 0x08, 0x15, 0x14)) !=
927 USB_STOR_TRANSPORT_GOOD
)
930 US_DEBUGP("INIT 15\n");
936 * Transport for the HP 8200e
938 int hp8200e_transport(Scsi_Cmnd
*srb
, struct us_data
*us
)
941 unsigned char status
;
942 unsigned char registers
[32];
943 unsigned char data
[32];
948 len
= srb
->request_bufflen
;
950 /* Send A0 (ATA PACKET COMMAND).
951 Note: I guess we're never going to get any of the ATA
952 commands... just ATA Packet Commands.
965 data
[3] = len
&0xFF; // (cylL) = expected length (L)
966 data
[4] = (len
>>8)&0xFF; // (cylH) = expected length (H)
967 data
[5] = 0xB0; // (device sel) = slave
968 data
[6] = 0xA0; // (command) = ATA PACKET COMMAND
970 for (i
=7; i
<19; i
++) {
972 data
[i
] = (i
-7 >= srb
->cmd_len
) ? 0 : srb
->cmnd
[i
-7];
975 if (srb
->cmnd
[0] == TEST_UNIT_READY
)
978 if (srb
->sc_data_direction
== SCSI_DATA_WRITE
) {
980 result
= usbat_rw_block_test(us
, USBAT_ATA
,
982 0x10, 0x17, 0xFD, 0x30,
985 len
, srb
->use_sg
, 10);
987 if (result
== USB_STOR_TRANSPORT_GOOD
) {
989 US_DEBUGP("Wrote %08X bytes\n", transferred
);
994 } else if (srb
->cmnd
[0] == READ_10
||
995 srb
->cmnd
[0] == GPCMD_READ_CD
) {
997 return usbat_handle_read10(us
, registers
, data
, srb
);
1002 US_DEBUGP("Error: len = %08X... what do I do now?\n",
1004 return USB_STOR_TRANSPORT_ERROR
;
1007 if ( (result
= usbat_multiple_write(us
,
1009 registers
, data
, 7)) != USB_STOR_TRANSPORT_GOOD
) {
1013 // Write the 12-byte command header.
1015 // If the command is BLANK then set the timer for 75 minutes.
1016 // Otherwise set it for 10 minutes.
1018 // NOTE: THE 8200 DOCUMENTATION STATES THAT BLANKING A CDRW
1019 // AT SPEED 4 IS UNRELIABLE!!!
1021 if ( (result
= usbat_write_block(us
,
1022 USBAT_ATA
, 0x10, srb
->cmnd
, 12, 0,
1023 srb
->cmnd
[0]==GPCMD_BLANK
? 75 : 10)) !=
1024 USB_STOR_TRANSPORT_GOOD
) {
1028 // If there is response data to be read in
1031 if (len
!= 0 && (srb
->sc_data_direction
== SCSI_DATA_READ
)) {
1033 // How many bytes to read in? Check cylL register
1035 if ( (result
= usbat_read(us
, USBAT_ATA
, 0x14, &status
)) !=
1036 USB_STOR_TRANSPORT_GOOD
) {
1040 if (len
>0xFF) { // need to read cylH also
1042 if ( (result
= usbat_read(us
, USBAT_ATA
, 0x15,
1044 USB_STOR_TRANSPORT_GOOD
) {
1047 len
+= ((unsigned int)status
)<<8;
1053 result
= usbat_read_block(us
, USBAT_ATA
, 0x10,
1054 srb
->request_buffer
, len
, srb
->use_sg
);
1056 /* Debug-print the first 32 bytes of the transfer */
1060 for (i
=0; i
<len
&& i
<32; i
++) {
1061 sprintf(string
+strlen(string
), "%02X ",
1062 ((unsigned char *)srb
->request_buffer
)[i
]);
1064 US_DEBUGP("%s\n", string
);
1069 US_DEBUGP("%s\n", string
);