1 /* Special Initializers for certain USB Mass Storage devices
3 * $Id: initializers.c,v 1.2 2000/09/06 22:35:57 mdharm Exp $
5 * Current development and maintenance by:
6 * (c) 1999, 2000 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
8 * This driver is based on the 'USB Mass Storage Class' document. This
9 * describes in detail the protocol used to communicate with such
10 * devices. Clearly, the designers had SCSI and ATAPI commands in
11 * mind when they created this document. The commands are all very
12 * similar to commands in the SCSI-II and ATAPI specifications.
14 * It is important to note that in a number of cases this class
15 * exhibits class-specific exemptions from the USB specification.
16 * Notably the usage of NAK, STALL and ACK differs from the norm, in
17 * that they are used to communicate wait, failed and OK on commands.
19 * Also, for certain devices, the interrupt endpoint is used to convey
20 * status of a command.
22 * Please see http://www.one-eyed-alien.net/~mdharm/linux-usb for more
23 * information about this driver.
25 * This program is free software; you can redistribute it and/or modify it
26 * under the terms of the GNU General Public License as published by the
27 * Free Software Foundation; either version 2, or (at your option) any
30 * This program is distributed in the hope that it will be useful, but
31 * WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33 * General Public License for more details.
35 * You should have received a copy of the GNU General Public License along
36 * with this program; if not, write to the Free Software Foundation, Inc.,
37 * 675 Mass Ave, Cambridge, MA 02139, USA.
40 #include <linux/sched.h>
41 #include <linux/errno.h>
44 #include "initializers.h"
46 #include "transport.h"
49 #define RIOP_INIT "RIOP\x00\x01\x08"
50 #define RIOP_INIT_LEN 7
51 #define RIO_SEND_LEN 40
52 #define RIO_RECV_LEN 0x200
54 /* This places the Shuttle/SCM USB<->SCSI bridge devices in multi-target
56 int usb_stor_euscsi_init(struct us_data *us)
60 US_DEBUGP("Attempting to init eUSCSI bridge...\n");
62 result = usb_stor_control_msg(us, us->send_ctrl_pipe,
63 0x0C, USB_RECIP_INTERFACE | USB_TYPE_VENDOR,
64 0x01, 0x0, us->iobuf, 0x1, 5*HZ);
65 US_DEBUGP("-- result is %d\n", result);
70 /* This function is required to activate all four slots on the UCR-61S2B
72 int usb_stor_ucr61s2b_init(struct us_data *us)
74 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap*) us->iobuf;
75 struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap*) us->iobuf;
77 static char init_string[] = "\xec\x0a\x06\x00$PCCHIPS";
79 US_DEBUGP("Sending UCR-61S2B initialization packet...\n");
81 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
83 bcb->DataTransferLength = cpu_to_le32(0);
84 bcb->Flags = bcb->Lun = 0;
85 bcb->Length = sizeof(init_string) - 1;
86 memset(bcb->CDB, 0, sizeof(bcb->CDB));
87 memcpy(bcb->CDB, init_string, sizeof(init_string) - 1);
89 res = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, bcb,
90 US_BULK_CB_WRAP_LEN, &partial);
94 US_DEBUGP("Getting status packet...\n");
95 res = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs,
96 US_BULK_CS_WRAP_LEN, &partial);
98 return (res ? -1 : 0);
101 /* Place the Rio Karma into mass storage mode.
103 * The initialization begins by sending 40 bytes starting
104 * RIOP\x00\x01\x08\x00, which the device will ack with a 512-byte
105 * packet with the high four bits set and everything else null.
107 * Next, we send RIOP\x80\x00\x08\x00. Each time, a 512 byte response
108 * must be read, but we must loop until byte 5 in the response is 0x08,
109 * indicating success. */
110 int rio_karma_init(struct us_data *us)
114 unsigned long timeout;
116 // us->iobuf is big enough to hold cmd but not receive
117 if (!(recv = kmalloc(RIO_RECV_LEN, GFP_KERNEL)))
120 US_DEBUGP("Initializing Karma...\n");
122 memset(us->iobuf, 0, RIO_SEND_LEN);
123 memcpy(us->iobuf, RIOP_INIT, RIOP_INIT_LEN);
125 result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
126 us->iobuf, RIO_SEND_LEN, &partial);
127 if (result != USB_STOR_XFER_GOOD)
130 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
131 recv, RIO_RECV_LEN, &partial);
132 if (result != USB_STOR_XFER_GOOD)
137 timeout = jiffies + msecs_to_jiffies(3000);
139 US_DEBUGP("Sending init command\n");
140 result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
141 us->iobuf, RIO_SEND_LEN, &partial);
142 if (result != USB_STOR_XFER_GOOD)
145 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
146 recv, RIO_RECV_LEN, &partial);
147 if (result != USB_STOR_XFER_GOOD)
150 if (recv[5] == RIO_MSC)
152 if (time_after(jiffies, timeout))
156 US_DEBUGP("Karma initialized.\n");
163 US_DEBUGP("Could not initialize karma.\n");
164 return USB_STOR_TRANSPORT_FAILED;