Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* Special Initializers for certain USB Mass Storage devices |
2 | * | |
3 | * $Id: initializers.c,v 1.2 2000/09/06 22:35:57 mdharm Exp $ | |
4 | * | |
5 | * Current development and maintenance by: | |
6 | * (c) 1999, 2000 Matthew Dharm (mdharm-usb@one-eyed-alien.net) | |
7 | * | |
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. | |
13 | * | |
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. | |
18 | * | |
19 | * Also, for certain devices, the interrupt endpoint is used to convey | |
20 | * status of a command. | |
21 | * | |
22 | * Please see http://www.one-eyed-alien.net/~mdharm/linux-usb for more | |
23 | * information about this driver. | |
24 | * | |
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 | |
28 | * later version. | |
29 | * | |
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. | |
34 | * | |
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. | |
38 | */ | |
39 | ||
40 | #include <linux/sched.h> | |
41 | #include <linux/errno.h> | |
42 | ||
43 | #include "usb.h" | |
44 | #include "initializers.h" | |
45 | #include "debug.h" | |
46 | #include "transport.h" | |
47 | ||
abb02fdf MD |
48 | #define RIO_MSC 0x08 |
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 | |
53 | ||
1da177e4 LT |
54 | /* This places the Shuttle/SCM USB<->SCSI bridge devices in multi-target |
55 | * mode */ | |
56 | int usb_stor_euscsi_init(struct us_data *us) | |
57 | { | |
58 | int result; | |
59 | ||
60 | US_DEBUGP("Attempting to init eUSCSI bridge...\n"); | |
61 | us->iobuf[0] = 0x1; | |
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); | |
66 | ||
67 | return 0; | |
68 | } | |
69 | ||
70 | /* This function is required to activate all four slots on the UCR-61S2B | |
71 | * flash reader */ | |
72 | int usb_stor_ucr61s2b_init(struct us_data *us) | |
73 | { | |
74 | struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap*) us->iobuf; | |
75 | struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap*) us->iobuf; | |
76 | int res, partial; | |
77 | static char init_string[] = "\xec\x0a\x06\x00$PCCHIPS"; | |
78 | ||
79 | US_DEBUGP("Sending UCR-61S2B initialization packet...\n"); | |
80 | ||
81 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); | |
82 | bcb->Tag = 0; | |
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); | |
88 | ||
89 | res = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, bcb, | |
90 | US_BULK_CB_WRAP_LEN, &partial); | |
91 | if(res) | |
92 | return res; | |
93 | ||
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); | |
97 | ||
98 | return (res ? -1 : 0); | |
99 | } | |
abb02fdf MD |
100 | |
101 | /* Place the Rio Karma into mass storage mode. | |
102 | * | |
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. | |
106 | * | |
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) | |
111 | { | |
112 | int result, partial; | |
113 | char *recv; | |
114 | unsigned long timeout; | |
115 | ||
116 | // us->iobuf is big enough to hold cmd but not receive | |
117 | if (!(recv = kmalloc(RIO_RECV_LEN, GFP_KERNEL))) | |
118 | goto die_nomem; | |
119 | ||
120 | US_DEBUGP("Initializing Karma...\n"); | |
121 | ||
122 | memset(us->iobuf, 0, RIO_SEND_LEN); | |
123 | memcpy(us->iobuf, RIOP_INIT, RIOP_INIT_LEN); | |
124 | ||
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) | |
128 | goto die; | |
129 | ||
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) | |
133 | goto die; | |
134 | ||
135 | us->iobuf[4] = 0x80; | |
136 | us->iobuf[5] = 0; | |
137 | timeout = jiffies + msecs_to_jiffies(3000); | |
138 | for (;;) { | |
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) | |
143 | goto die; | |
144 | ||
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) | |
148 | goto die; | |
149 | ||
150 | if (recv[5] == RIO_MSC) | |
151 | break; | |
152 | if (time_after(jiffies, timeout)) | |
153 | goto die; | |
154 | msleep(10); | |
155 | } | |
156 | US_DEBUGP("Karma initialized.\n"); | |
157 | kfree(recv); | |
158 | return 0; | |
159 | ||
160 | die: | |
161 | kfree(recv); | |
162 | die_nomem: | |
163 | US_DEBUGP("Could not initialize karma.\n"); | |
164 | return USB_STOR_TRANSPORT_FAILED; | |
165 | } | |
166 |