aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/storage
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/storage')
-rw-r--r--drivers/usb/storage/Kconfig3
-rw-r--r--drivers/usb/storage/onetouch.c99
-rw-r--r--drivers/usb/storage/shuttle_usbat.c314
-rw-r--r--drivers/usb/storage/shuttle_usbat.h66
-rw-r--r--drivers/usb/storage/transport.c6
-rw-r--r--drivers/usb/storage/transport.h2
-rw-r--r--drivers/usb/storage/unusual_devs.h44
-rw-r--r--drivers/usb/storage/usb.c163
-rw-r--r--drivers/usb/storage/usb.h5
9 files changed, 396 insertions, 306 deletions
diff --git a/drivers/usb/storage/Kconfig b/drivers/usb/storage/Kconfig
index bb9819cc8826..1a9679f76f5a 100644
--- a/drivers/usb/storage/Kconfig
+++ b/drivers/usb/storage/Kconfig
@@ -2,7 +2,8 @@
2# USB Storage driver configuration 2# USB Storage driver configuration
3# 3#
4 4
5comment "NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support' may also be needed; see USB_STORAGE Help for more information" 5comment "NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'"
6comment "may also be needed; see USB_STORAGE Help for more information"
6 depends on USB 7 depends on USB
7 8
8config USB_STORAGE 9config USB_STORAGE
diff --git a/drivers/usb/storage/onetouch.c b/drivers/usb/storage/onetouch.c
index 2c9402dc702b..89401a59f952 100644
--- a/drivers/usb/storage/onetouch.c
+++ b/drivers/usb/storage/onetouch.c
@@ -5,7 +5,7 @@
5 * Copyright (c) 2005 Nick Sillik <n.sillik@temple.edu> 5 * Copyright (c) 2005 Nick Sillik <n.sillik@temple.edu>
6 * 6 *
7 * Initial work by: 7 * Initial work by:
8 * Copyright (c) 2003 Erik Thyren <erth7411@student.uu.se> 8 * Copyright (c) 2003 Erik Thyren <erth7411@student.uu.se>
9 * 9 *
10 * Based on usbmouse.c (Vojtech Pavlik) and xpad.c (Marko Friedemann) 10 * Based on usbmouse.c (Vojtech Pavlik) and xpad.c (Marko Friedemann)
11 * 11 *
@@ -46,7 +46,7 @@ void onetouch_release_input(void *onetouch_);
46struct usb_onetouch { 46struct usb_onetouch {
47 char name[128]; 47 char name[128];
48 char phys[64]; 48 char phys[64];
49 struct input_dev dev; /* input device interface */ 49 struct input_dev *dev; /* input device interface */
50 struct usb_device *udev; /* usb device */ 50 struct usb_device *udev; /* usb device */
51 51
52 struct urb *irq; /* urb for interrupt in report */ 52 struct urb *irq; /* urb for interrupt in report */
@@ -58,7 +58,7 @@ static void usb_onetouch_irq(struct urb *urb, struct pt_regs *regs)
58{ 58{
59 struct usb_onetouch *onetouch = urb->context; 59 struct usb_onetouch *onetouch = urb->context;
60 signed char *data = onetouch->data; 60 signed char *data = onetouch->data;
61 struct input_dev *dev = &onetouch->dev; 61 struct input_dev *dev = onetouch->dev;
62 int status; 62 int status;
63 63
64 switch (urb->status) { 64 switch (urb->status) {
@@ -74,11 +74,9 @@ static void usb_onetouch_irq(struct urb *urb, struct pt_regs *regs)
74 } 74 }
75 75
76 input_regs(dev, regs); 76 input_regs(dev, regs);
77 77 input_report_key(dev, ONETOUCH_BUTTON, data[0] & 0x02);
78 input_report_key(&onetouch->dev, ONETOUCH_BUTTON,
79 data[0] & 0x02);
80
81 input_sync(dev); 78 input_sync(dev);
79
82resubmit: 80resubmit:
83 status = usb_submit_urb (urb, SLAB_ATOMIC); 81 status = usb_submit_urb (urb, SLAB_ATOMIC);
84 if (status) 82 if (status)
@@ -113,8 +111,8 @@ int onetouch_connect_input(struct us_data *ss)
113 struct usb_host_interface *interface; 111 struct usb_host_interface *interface;
114 struct usb_endpoint_descriptor *endpoint; 112 struct usb_endpoint_descriptor *endpoint;
115 struct usb_onetouch *onetouch; 113 struct usb_onetouch *onetouch;
114 struct input_dev *input_dev;
116 int pipe, maxp; 115 int pipe, maxp;
117 char path[64];
118 116
119 interface = ss->pusb_intf->cur_altsetting; 117 interface = ss->pusb_intf->cur_altsetting;
120 118
@@ -122,62 +120,62 @@ int onetouch_connect_input(struct us_data *ss)
122 return -ENODEV; 120 return -ENODEV;
123 121
124 endpoint = &interface->endpoint[2].desc; 122 endpoint = &interface->endpoint[2].desc;
125 if(!(endpoint->bEndpointAddress & USB_DIR_IN)) 123 if (!(endpoint->bEndpointAddress & USB_DIR_IN))
126 return -ENODEV; 124 return -ENODEV;
127 if((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) 125 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
128 != USB_ENDPOINT_XFER_INT) 126 != USB_ENDPOINT_XFER_INT)
129 return -ENODEV; 127 return -ENODEV;
130 128
131 pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress); 129 pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress);
132 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe)); 130 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
133 131
134 if (!(onetouch = kcalloc(1, sizeof(struct usb_onetouch), GFP_KERNEL))) 132 onetouch = kzalloc(sizeof(struct usb_onetouch), GFP_KERNEL);
135 return -ENOMEM; 133 input_dev = input_allocate_device();
134 if (!onetouch || !input_dev)
135 goto fail1;
136 136
137 onetouch->data = usb_buffer_alloc(udev, ONETOUCH_PKT_LEN, 137 onetouch->data = usb_buffer_alloc(udev, ONETOUCH_PKT_LEN,
138 SLAB_ATOMIC, &onetouch->data_dma); 138 SLAB_ATOMIC, &onetouch->data_dma);
139 if (!onetouch->data){ 139 if (!onetouch->data)
140 kfree(onetouch); 140 goto fail1;
141 return -ENOMEM;
142 }
143 141
144 onetouch->irq = usb_alloc_urb(0, GFP_KERNEL); 142 onetouch->irq = usb_alloc_urb(0, GFP_KERNEL);
145 if (!onetouch->irq){ 143 if (!onetouch->irq)
146 kfree(onetouch); 144 goto fail2;
147 usb_buffer_free(udev, ONETOUCH_PKT_LEN,
148 onetouch->data, onetouch->data_dma);
149 return -ENODEV;
150 }
151
152 145
153 onetouch->udev = udev; 146 onetouch->udev = udev;
147 onetouch->dev = input_dev;
154 148
155 set_bit(EV_KEY, onetouch->dev.evbit); 149 if (udev->manufacturer)
156 set_bit(ONETOUCH_BUTTON, onetouch->dev.keybit); 150 strlcpy(onetouch->name, udev->manufacturer,
157 clear_bit(0, onetouch->dev.keybit); 151 sizeof(onetouch->name));
152 if (udev->product) {
153 if (udev->manufacturer)
154 strlcat(onetouch->name, " ", sizeof(onetouch->name));
155 strlcat(onetouch->name, udev->product, sizeof(onetouch->name));
156 }
158 157
159 onetouch->dev.private = onetouch; 158 if (!strlen(onetouch->name))
160 onetouch->dev.open = usb_onetouch_open; 159 snprintf(onetouch->name, sizeof(onetouch->name),
161 onetouch->dev.close = usb_onetouch_close; 160 "Maxtor Onetouch %04x:%04x",
161 le16_to_cpu(udev->descriptor.idVendor),
162 le16_to_cpu(udev->descriptor.idProduct));
162 163
163 usb_make_path(udev, path, sizeof(path)); 164 usb_make_path(udev, onetouch->phys, sizeof(onetouch->phys));
164 sprintf(onetouch->phys, "%s/input0", path); 165 strlcat(onetouch->phys, "/input0", sizeof(onetouch->phys));
165 166
166 onetouch->dev.name = onetouch->name; 167 input_dev->name = onetouch->name;
167 onetouch->dev.phys = onetouch->phys; 168 input_dev->phys = onetouch->phys;
169 usb_to_input_id(udev, &input_dev->id);
170 input_dev->cdev.dev = &udev->dev;
168 171
169 usb_to_input_id(udev, &onetouch->dev.id); 172 set_bit(EV_KEY, input_dev->evbit);
173 set_bit(ONETOUCH_BUTTON, input_dev->keybit);
174 clear_bit(0, input_dev->keybit);
170 175
171 onetouch->dev.dev = &udev->dev; 176 input_dev->private = onetouch;
172 177 input_dev->open = usb_onetouch_open;
173 if (udev->manufacturer) 178 input_dev->close = usb_onetouch_close;
174 strcat(onetouch->name, udev->manufacturer);
175 if (udev->product)
176 sprintf(onetouch->name, "%s %s", onetouch->name,
177 udev->product);
178 if (!strlen(onetouch->name))
179 sprintf(onetouch->name, "Maxtor Onetouch %04x:%04x",
180 onetouch->dev.id.vendor, onetouch->dev.id.product);
181 179
182 usb_fill_int_urb(onetouch->irq, udev, pipe, onetouch->data, 180 usb_fill_int_urb(onetouch->irq, udev, pipe, onetouch->data,
183 (maxp > 8 ? 8 : maxp), 181 (maxp > 8 ? 8 : maxp),
@@ -188,10 +186,15 @@ int onetouch_connect_input(struct us_data *ss)
188 ss->extra_destructor = onetouch_release_input; 186 ss->extra_destructor = onetouch_release_input;
189 ss->extra = onetouch; 187 ss->extra = onetouch;
190 188
191 input_register_device(&onetouch->dev); 189 input_register_device(onetouch->dev);
192 printk(KERN_INFO "usb-input: %s on %s\n", onetouch->dev.name, path);
193 190
194 return 0; 191 return 0;
192
193 fail2: usb_buffer_free(udev, ONETOUCH_PKT_LEN,
194 onetouch->data, onetouch->data_dma);
195 fail1: kfree(onetouch);
196 input_free_device(input_dev);
197 return -ENOMEM;
195} 198}
196 199
197void onetouch_release_input(void *onetouch_) 200void onetouch_release_input(void *onetouch_)
@@ -200,11 +203,9 @@ void onetouch_release_input(void *onetouch_)
200 203
201 if (onetouch) { 204 if (onetouch) {
202 usb_kill_urb(onetouch->irq); 205 usb_kill_urb(onetouch->irq);
203 input_unregister_device(&onetouch->dev); 206 input_unregister_device(onetouch->dev);
204 usb_free_urb(onetouch->irq); 207 usb_free_urb(onetouch->irq);
205 usb_buffer_free(onetouch->udev, ONETOUCH_PKT_LEN, 208 usb_buffer_free(onetouch->udev, ONETOUCH_PKT_LEN,
206 onetouch->data, onetouch->data_dma); 209 onetouch->data, onetouch->data_dma);
207 printk(KERN_INFO "usb-input: deregistering %s\n",
208 onetouch->dev.name);
209 } 210 }
210} 211}
diff --git a/drivers/usb/storage/shuttle_usbat.c b/drivers/usb/storage/shuttle_usbat.c
index 356342c6e7a2..33c55a6261bb 100644
--- a/drivers/usb/storage/shuttle_usbat.c
+++ b/drivers/usb/storage/shuttle_usbat.c
@@ -1,4 +1,4 @@
1/* Driver for SCM Microsystems USB-ATAPI cable 1/* Driver for SCM Microsystems (a.k.a. Shuttle) USB-ATAPI cable
2 * 2 *
3 * $Id: shuttle_usbat.c,v 1.17 2002/04/22 03:39:43 mdharm Exp $ 3 * $Id: shuttle_usbat.c,v 1.17 2002/04/22 03:39:43 mdharm Exp $
4 * 4 *
@@ -67,10 +67,10 @@ static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us);
67static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us); 67static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us);
68 68
69/* 69/*
70 * Convenience function to produce an ATAPI read/write sectors command 70 * Convenience function to produce an ATA read/write sectors command
71 * Use cmd=0x20 for read, cmd=0x30 for write 71 * Use cmd=0x20 for read, cmd=0x30 for write
72 */ 72 */
73static void usbat_pack_atapi_sector_cmd(unsigned char *buf, 73static void usbat_pack_ata_sector_cmd(unsigned char *buf,
74 unsigned char thistime, 74 unsigned char thistime,
75 u32 sector, unsigned char cmd) 75 u32 sector, unsigned char cmd)
76{ 76{
@@ -196,10 +196,12 @@ static int usbat_check_status(struct us_data *us)
196 if (rc != USB_STOR_XFER_GOOD) 196 if (rc != USB_STOR_XFER_GOOD)
197 return USB_STOR_TRANSPORT_FAILED; 197 return USB_STOR_TRANSPORT_FAILED;
198 198
199 if (*reply & 0x01 && *reply != 0x51) // error/check condition (0x51 is ok) 199 /* error/check condition (0x51 is ok) */
200 if (*reply & 0x01 && *reply != 0x51)
200 return USB_STOR_TRANSPORT_FAILED; 201 return USB_STOR_TRANSPORT_FAILED;
201 202
202 if (*reply & 0x20) // device fault 203 /* device fault */
204 if (*reply & 0x20)
203 return USB_STOR_TRANSPORT_FAILED; 205 return USB_STOR_TRANSPORT_FAILED;
204 206
205 return USB_STOR_TRANSPORT_GOOD; 207 return USB_STOR_TRANSPORT_GOOD;
@@ -222,29 +224,39 @@ static int usbat_set_shuttle_features(struct us_data *us,
222 command[0] = 0x40; 224 command[0] = 0x40;
223 command[1] = USBAT_CMD_SET_FEAT; 225 command[1] = USBAT_CMD_SET_FEAT;
224 226
225 // The only bit relevant to ATA access is bit 6 227 /*
226 // which defines 8 bit data access (set) or 16 bit (unset) 228 * The only bit relevant to ATA access is bit 6
229 * which defines 8 bit data access (set) or 16 bit (unset)
230 */
227 command[2] = epp_control; 231 command[2] = epp_control;
228 232
229 // If FCQ is set in the qualifier (defined in R/W cmd), then bits U0, U1, 233 /*
230 // ET1 and ET2 define an external event to be checked for on event of a 234 * If FCQ is set in the qualifier (defined in R/W cmd), then bits U0, U1,
231 // _read_blocks or _write_blocks operation. The read/write will not take 235 * ET1 and ET2 define an external event to be checked for on event of a
232 // place unless the defined trigger signal is active. 236 * _read_blocks or _write_blocks operation. The read/write will not take
237 * place unless the defined trigger signal is active.
238 */
233 command[3] = external_trigger; 239 command[3] = external_trigger;
234 240
235 // The resultant byte of the mask operation (see mask_byte) is compared for 241 /*
236 // equivalence with this test pattern. If equal, the read/write will take 242 * The resultant byte of the mask operation (see mask_byte) is compared for
237 // place. 243 * equivalence with this test pattern. If equal, the read/write will take
244 * place.
245 */
238 command[4] = test_pattern; 246 command[4] = test_pattern;
239 247
240 // This value is logically ANDed with the status register field specified 248 /*
241 // in the read/write command. 249 * This value is logically ANDed with the status register field specified
250 * in the read/write command.
251 */
242 command[5] = mask_byte; 252 command[5] = mask_byte;
243 253
244 // If ALQ is set in the qualifier, this field contains the address of the 254 /*
245 // registers where the byte count should be read for transferring the data. 255 * If ALQ is set in the qualifier, this field contains the address of the
246 // If ALQ is not set, then this field contains the number of bytes to be 256 * registers where the byte count should be read for transferring the data.
247 // transferred. 257 * If ALQ is not set, then this field contains the number of bytes to be
258 * transferred.
259 */
248 command[6] = subcountL; 260 command[6] = subcountL;
249 command[7] = subcountH; 261 command[7] = subcountH;
250 262
@@ -273,26 +285,26 @@ static int usbat_wait_not_busy(struct us_data *us, int minutes)
273 285
274 if (result!=USB_STOR_XFER_GOOD) 286 if (result!=USB_STOR_XFER_GOOD)
275 return USB_STOR_TRANSPORT_ERROR; 287 return USB_STOR_TRANSPORT_ERROR;
276 if (*status & 0x01) { // check condition 288 if (*status & 0x01) { /* check condition */
277 result = usbat_read(us, USBAT_ATA, 0x10, status); 289 result = usbat_read(us, USBAT_ATA, 0x10, status);
278 return USB_STOR_TRANSPORT_FAILED; 290 return USB_STOR_TRANSPORT_FAILED;
279 } 291 }
280 if (*status & 0x20) // device fault 292 if (*status & 0x20) /* device fault */
281 return USB_STOR_TRANSPORT_FAILED; 293 return USB_STOR_TRANSPORT_FAILED;
282 294
283 if ((*status & 0x80)==0x00) { // not busy 295 if ((*status & 0x80)==0x00) { /* not busy */
284 US_DEBUGP("Waited not busy for %d steps\n", i); 296 US_DEBUGP("Waited not busy for %d steps\n", i);
285 return USB_STOR_TRANSPORT_GOOD; 297 return USB_STOR_TRANSPORT_GOOD;
286 } 298 }
287 299
288 if (i<500) 300 if (i<500)
289 msleep(10); // 5 seconds 301 msleep(10); /* 5 seconds */
290 else if (i<700) 302 else if (i<700)
291 msleep(50); // 10 seconds 303 msleep(50); /* 10 seconds */
292 else if (i<1200) 304 else if (i<1200)
293 msleep(100); // 50 seconds 305 msleep(100); /* 50 seconds */
294 else 306 else
295 msleep(1000); // X minutes 307 msleep(1000); /* X minutes */
296 } 308 }
297 309
298 US_DEBUGP("Waited not busy for %d minutes, timing out.\n", 310 US_DEBUGP("Waited not busy for %d minutes, timing out.\n",
@@ -412,9 +424,12 @@ static int usbat_hp8200e_rw_block_test(struct us_data *us,
412 424
413 if (i==0) { 425 if (i==0) {
414 cmdlen = 16; 426 cmdlen = 16;
415 // Write to multiple registers 427 /*
416 // Not really sure the 0x07, 0x17, 0xfc, 0xe7 is necessary here, 428 * Write to multiple registers
417 // but that's what came out of the trace every single time. 429 * Not really sure the 0x07, 0x17, 0xfc, 0xe7 is
430 * necessary here, but that's what came out of the
431 * trace every single time.
432 */
418 command[0] = 0x40; 433 command[0] = 0x40;
419 command[1] = access | USBAT_CMD_WRITE_REGS; 434 command[1] = access | USBAT_CMD_WRITE_REGS;
420 command[2] = 0x07; 435 command[2] = 0x07;
@@ -426,7 +441,7 @@ static int usbat_hp8200e_rw_block_test(struct us_data *us,
426 } else 441 } else
427 cmdlen = 8; 442 cmdlen = 8;
428 443
429 // Conditionally read or write blocks 444 /* Conditionally read or write blocks */
430 command[cmdlen-8] = (direction==DMA_TO_DEVICE ? 0x40 : 0xC0); 445 command[cmdlen-8] = (direction==DMA_TO_DEVICE ? 0x40 : 0xC0);
431 command[cmdlen-7] = access | 446 command[cmdlen-7] = access |
432 (direction==DMA_TO_DEVICE ? 447 (direction==DMA_TO_DEVICE ?
@@ -456,11 +471,6 @@ static int usbat_hp8200e_rw_block_test(struct us_data *us,
456 471
457 } 472 }
458 473
459
460 //US_DEBUGP("Transfer %s %d bytes, sg buffers %d\n",
461 // direction == DMA_TO_DEVICE ? "out" : "in",
462 // len, use_sg);
463
464 result = usb_stor_bulk_transfer_sg(us, 474 result = usb_stor_bulk_transfer_sg(us,
465 pipe, content, len, use_sg, NULL); 475 pipe, content, len, use_sg, NULL);
466 476
@@ -508,9 +518,9 @@ static int usbat_hp8200e_rw_block_test(struct us_data *us,
508 518
509 if (result!=USB_STOR_XFER_GOOD) 519 if (result!=USB_STOR_XFER_GOOD)
510 return USB_STOR_TRANSPORT_ERROR; 520 return USB_STOR_TRANSPORT_ERROR;
511 if (*status & 0x01) // check condition 521 if (*status & 0x01) /* check condition */
512 return USB_STOR_TRANSPORT_FAILED; 522 return USB_STOR_TRANSPORT_FAILED;
513 if (*status & 0x20) // device fault 523 if (*status & 0x20) /* device fault */
514 return USB_STOR_TRANSPORT_FAILED; 524 return USB_STOR_TRANSPORT_FAILED;
515 525
516 US_DEBUGP("Redoing %s\n", 526 US_DEBUGP("Redoing %s\n",
@@ -547,32 +557,32 @@ static int usbat_multiple_write(struct us_data *us,
547 557
548 BUG_ON(num_registers > US_IOBUF_SIZE/2); 558 BUG_ON(num_registers > US_IOBUF_SIZE/2);
549 559
550 // Write to multiple registers, ATA access 560 /* Write to multiple registers, ATA access */
551 command[0] = 0x40; 561 command[0] = 0x40;
552 command[1] = USBAT_ATA | USBAT_CMD_WRITE_REGS; 562 command[1] = USBAT_ATA | USBAT_CMD_WRITE_REGS;
553 563
554 // No relevance 564 /* No relevance */
555 command[2] = 0; 565 command[2] = 0;
556 command[3] = 0; 566 command[3] = 0;
557 command[4] = 0; 567 command[4] = 0;
558 command[5] = 0; 568 command[5] = 0;
559 569
560 // Number of bytes to be transferred (incl. addresses and data) 570 /* Number of bytes to be transferred (incl. addresses and data) */
561 command[6] = LSB_of(num_registers*2); 571 command[6] = LSB_of(num_registers*2);
562 command[7] = MSB_of(num_registers*2); 572 command[7] = MSB_of(num_registers*2);
563 573
564 // The setup command 574 /* The setup command */
565 result = usbat_execute_command(us, command, 8); 575 result = usbat_execute_command(us, command, 8);
566 if (result != USB_STOR_XFER_GOOD) 576 if (result != USB_STOR_XFER_GOOD)
567 return USB_STOR_TRANSPORT_ERROR; 577 return USB_STOR_TRANSPORT_ERROR;
568 578
569 // Create the reg/data, reg/data sequence 579 /* Create the reg/data, reg/data sequence */
570 for (i=0; i<num_registers; i++) { 580 for (i=0; i<num_registers; i++) {
571 data[i<<1] = registers[i]; 581 data[i<<1] = registers[i];
572 data[1+(i<<1)] = data_out[i]; 582 data[1+(i<<1)] = data_out[i];
573 } 583 }
574 584
575 // Send the data 585 /* Send the data */
576 result = usbat_bulk_write(us, data, num_registers*2); 586 result = usbat_bulk_write(us, data, num_registers*2);
577 if (result != USB_STOR_XFER_GOOD) 587 if (result != USB_STOR_XFER_GOOD)
578 return USB_STOR_TRANSPORT_ERROR; 588 return USB_STOR_TRANSPORT_ERROR;
@@ -606,17 +616,17 @@ static int usbat_read_blocks(struct us_data *us,
606 command[1] = USBAT_ATA | USBAT_CMD_COND_READ_BLOCK; 616 command[1] = USBAT_ATA | USBAT_CMD_COND_READ_BLOCK;
607 command[2] = USBAT_ATA_DATA; 617 command[2] = USBAT_ATA_DATA;
608 command[3] = USBAT_ATA_STATUS; 618 command[3] = USBAT_ATA_STATUS;
609 command[4] = 0xFD; // Timeout (ms); 619 command[4] = 0xFD; /* Timeout (ms); */
610 command[5] = USBAT_QUAL_FCQ; 620 command[5] = USBAT_QUAL_FCQ;
611 command[6] = LSB_of(len); 621 command[6] = LSB_of(len);
612 command[7] = MSB_of(len); 622 command[7] = MSB_of(len);
613 623
614 // Multiple block read setup command 624 /* Multiple block read setup command */
615 result = usbat_execute_command(us, command, 8); 625 result = usbat_execute_command(us, command, 8);
616 if (result != USB_STOR_XFER_GOOD) 626 if (result != USB_STOR_XFER_GOOD)
617 return USB_STOR_TRANSPORT_FAILED; 627 return USB_STOR_TRANSPORT_FAILED;
618 628
619 // Read the blocks we just asked for 629 /* Read the blocks we just asked for */
620 result = usbat_bulk_read(us, buffer, len); 630 result = usbat_bulk_read(us, buffer, len);
621 if (result != USB_STOR_XFER_GOOD) 631 if (result != USB_STOR_XFER_GOOD)
622 return USB_STOR_TRANSPORT_FAILED; 632 return USB_STOR_TRANSPORT_FAILED;
@@ -647,17 +657,17 @@ static int usbat_write_blocks(struct us_data *us,
647 command[1] = USBAT_ATA | USBAT_CMD_COND_WRITE_BLOCK; 657 command[1] = USBAT_ATA | USBAT_CMD_COND_WRITE_BLOCK;
648 command[2] = USBAT_ATA_DATA; 658 command[2] = USBAT_ATA_DATA;
649 command[3] = USBAT_ATA_STATUS; 659 command[3] = USBAT_ATA_STATUS;
650 command[4] = 0xFD; // Timeout (ms) 660 command[4] = 0xFD; /* Timeout (ms) */
651 command[5] = USBAT_QUAL_FCQ; 661 command[5] = USBAT_QUAL_FCQ;
652 command[6] = LSB_of(len); 662 command[6] = LSB_of(len);
653 command[7] = MSB_of(len); 663 command[7] = MSB_of(len);
654 664
655 // Multiple block write setup command 665 /* Multiple block write setup command */
656 result = usbat_execute_command(us, command, 8); 666 result = usbat_execute_command(us, command, 8);
657 if (result != USB_STOR_XFER_GOOD) 667 if (result != USB_STOR_XFER_GOOD)
658 return USB_STOR_TRANSPORT_FAILED; 668 return USB_STOR_TRANSPORT_FAILED;
659 669
660 // Write the data 670 /* Write the data */
661 result = usbat_bulk_write(us, buffer, len); 671 result = usbat_bulk_write(us, buffer, len);
662 if (result != USB_STOR_XFER_GOOD) 672 if (result != USB_STOR_XFER_GOOD)
663 return USB_STOR_TRANSPORT_FAILED; 673 return USB_STOR_TRANSPORT_FAILED;
@@ -711,16 +721,20 @@ static int usbat_device_reset(struct us_data *us)
711{ 721{
712 int rc; 722 int rc;
713 723
714 // Reset peripheral, enable peripheral control signals 724 /*
715 // (bring reset signal up) 725 * Reset peripheral, enable peripheral control signals
726 * (bring reset signal up)
727 */
716 rc = usbat_write_user_io(us, 728 rc = usbat_write_user_io(us,
717 USBAT_UIO_DRVRST | USBAT_UIO_OE1 | USBAT_UIO_OE0, 729 USBAT_UIO_DRVRST | USBAT_UIO_OE1 | USBAT_UIO_OE0,
718 USBAT_UIO_EPAD | USBAT_UIO_1); 730 USBAT_UIO_EPAD | USBAT_UIO_1);
719 if (rc != USB_STOR_XFER_GOOD) 731 if (rc != USB_STOR_XFER_GOOD)
720 return USB_STOR_TRANSPORT_ERROR; 732 return USB_STOR_TRANSPORT_ERROR;
721 733
722 // Enable peripheral control signals 734 /*
723 // (bring reset signal down) 735 * Enable peripheral control signals
736 * (bring reset signal down)
737 */
724 rc = usbat_write_user_io(us, 738 rc = usbat_write_user_io(us,
725 USBAT_UIO_OE1 | USBAT_UIO_OE0, 739 USBAT_UIO_OE1 | USBAT_UIO_OE0,
726 USBAT_UIO_EPAD | USBAT_UIO_1); 740 USBAT_UIO_EPAD | USBAT_UIO_1);
@@ -737,7 +751,7 @@ static int usbat_device_enable_cdt(struct us_data *us)
737{ 751{
738 int rc; 752 int rc;
739 753
740 // Enable peripheral control signals and card detect 754 /* Enable peripheral control signals and card detect */
741 rc = usbat_write_user_io(us, 755 rc = usbat_write_user_io(us,
742 USBAT_UIO_ACKD | USBAT_UIO_OE1 | USBAT_UIO_OE0, 756 USBAT_UIO_ACKD | USBAT_UIO_OE1 | USBAT_UIO_OE0,
743 USBAT_UIO_EPAD | USBAT_UIO_1); 757 USBAT_UIO_EPAD | USBAT_UIO_1);
@@ -786,7 +800,7 @@ static int usbat_flash_check_media(struct us_data *us,
786 if (rc != USB_STOR_XFER_GOOD) 800 if (rc != USB_STOR_XFER_GOOD)
787 return USB_STOR_TRANSPORT_ERROR; 801 return USB_STOR_TRANSPORT_ERROR;
788 802
789 // Check for media existence 803 /* Check for media existence */
790 rc = usbat_flash_check_media_present(uio); 804 rc = usbat_flash_check_media_present(uio);
791 if (rc == USBAT_FLASH_MEDIA_NONE) { 805 if (rc == USBAT_FLASH_MEDIA_NONE) {
792 info->sense_key = 0x02; 806 info->sense_key = 0x02;
@@ -795,11 +809,11 @@ static int usbat_flash_check_media(struct us_data *us,
795 return USB_STOR_TRANSPORT_FAILED; 809 return USB_STOR_TRANSPORT_FAILED;
796 } 810 }
797 811
798 // Check for media change 812 /* Check for media change */
799 rc = usbat_flash_check_media_changed(uio); 813 rc = usbat_flash_check_media_changed(uio);
800 if (rc == USBAT_FLASH_MEDIA_CHANGED) { 814 if (rc == USBAT_FLASH_MEDIA_CHANGED) {
801 815
802 // Reset and re-enable card detect 816 /* Reset and re-enable card detect */
803 rc = usbat_device_reset(us); 817 rc = usbat_device_reset(us);
804 if (rc != USB_STOR_TRANSPORT_GOOD) 818 if (rc != USB_STOR_TRANSPORT_GOOD)
805 return rc; 819 return rc;
@@ -855,15 +869,15 @@ static int usbat_identify_device(struct us_data *us,
855 if (rc != USB_STOR_XFER_GOOD) 869 if (rc != USB_STOR_XFER_GOOD)
856 return USB_STOR_TRANSPORT_ERROR; 870 return USB_STOR_TRANSPORT_ERROR;
857 871
858 // Check for error bit 872 /* Check for error bit, or if the command 'fell through' */
859 if (status & 0x01) { 873 if (status == 0xA1 || !(status & 0x01)) {
860 // Device is a CompactFlash reader/writer 874 /* Device is HP 8200 */
861 US_DEBUGP("usbat_identify_device: Detected Flash reader/writer\n");
862 info->devicetype = USBAT_DEV_FLASH;
863 } else {
864 // Device is HP 8200
865 US_DEBUGP("usbat_identify_device: Detected HP8200 CDRW\n"); 875 US_DEBUGP("usbat_identify_device: Detected HP8200 CDRW\n");
866 info->devicetype = USBAT_DEV_HP8200; 876 info->devicetype = USBAT_DEV_HP8200;
877 } else {
878 /* Device is a CompactFlash reader/writer */
879 US_DEBUGP("usbat_identify_device: Detected Flash reader/writer\n");
880 info->devicetype = USBAT_DEV_FLASH;
867 } 881 }
868 882
869 return USB_STOR_TRANSPORT_GOOD; 883 return USB_STOR_TRANSPORT_GOOD;
@@ -916,7 +930,7 @@ static int usbat_flash_get_sector_count(struct us_data *us,
916 if (!reply) 930 if (!reply)
917 return USB_STOR_TRANSPORT_ERROR; 931 return USB_STOR_TRANSPORT_ERROR;
918 932
919 // ATAPI command : IDENTIFY DEVICE 933 /* ATA command : IDENTIFY DEVICE */
920 rc = usbat_multiple_write(us, registers, command, 3); 934 rc = usbat_multiple_write(us, registers, command, 3);
921 if (rc != USB_STOR_XFER_GOOD) { 935 if (rc != USB_STOR_XFER_GOOD) {
922 US_DEBUGP("usbat_flash_get_sector_count: Gah! identify_device failed\n"); 936 US_DEBUGP("usbat_flash_get_sector_count: Gah! identify_device failed\n");
@@ -924,7 +938,7 @@ static int usbat_flash_get_sector_count(struct us_data *us,
924 goto leave; 938 goto leave;
925 } 939 }
926 940
927 // Read device status 941 /* Read device status */
928 if (usbat_get_status(us, &status) != USB_STOR_XFER_GOOD) { 942 if (usbat_get_status(us, &status) != USB_STOR_XFER_GOOD) {
929 rc = USB_STOR_TRANSPORT_ERROR; 943 rc = USB_STOR_TRANSPORT_ERROR;
930 goto leave; 944 goto leave;
@@ -932,7 +946,7 @@ static int usbat_flash_get_sector_count(struct us_data *us,
932 946
933 msleep(100); 947 msleep(100);
934 948
935 // Read the device identification data 949 /* Read the device identification data */
936 rc = usbat_read_block(us, reply, 512); 950 rc = usbat_read_block(us, reply, 512);
937 if (rc != USB_STOR_TRANSPORT_GOOD) 951 if (rc != USB_STOR_TRANSPORT_GOOD)
938 goto leave; 952 goto leave;
@@ -977,19 +991,23 @@ static int usbat_flash_read_data(struct us_data *us,
977 if (result != USB_STOR_TRANSPORT_GOOD) 991 if (result != USB_STOR_TRANSPORT_GOOD)
978 return result; 992 return result;
979 993
980 // we're working in LBA mode. according to the ATA spec, 994 /*
981 // we can support up to 28-bit addressing. I don't know if Jumpshot 995 * we're working in LBA mode. according to the ATA spec,
982 // supports beyond 24-bit addressing. It's kind of hard to test 996 * we can support up to 28-bit addressing. I don't know if Jumpshot
983 // since it requires > 8GB CF card. 997 * supports beyond 24-bit addressing. It's kind of hard to test
998 * since it requires > 8GB CF card.
999 */
984 1000
985 if (sector > 0x0FFFFFFF) 1001 if (sector > 0x0FFFFFFF)
986 return USB_STOR_TRANSPORT_ERROR; 1002 return USB_STOR_TRANSPORT_ERROR;
987 1003
988 totallen = sectors * info->ssize; 1004 totallen = sectors * info->ssize;
989 1005
990 // Since we don't read more than 64 KB at a time, we have to create 1006 /*
991 // a bounce buffer and move the data a piece at a time between the 1007 * Since we don't read more than 64 KB at a time, we have to create
992 // bounce buffer and the actual transfer buffer. 1008 * a bounce buffer and move the data a piece at a time between the
1009 * bounce buffer and the actual transfer buffer.
1010 */
993 1011
994 alloclen = min(totallen, 65536u); 1012 alloclen = min(totallen, 65536u);
995 buffer = kmalloc(alloclen, GFP_NOIO); 1013 buffer = kmalloc(alloclen, GFP_NOIO);
@@ -997,27 +1015,29 @@ static int usbat_flash_read_data(struct us_data *us,
997 return USB_STOR_TRANSPORT_ERROR; 1015 return USB_STOR_TRANSPORT_ERROR;
998 1016
999 do { 1017 do {
1000 // loop, never allocate or transfer more than 64k at once 1018 /*
1001 // (min(128k, 255*info->ssize) is the real limit) 1019 * loop, never allocate or transfer more than 64k at once
1020 * (min(128k, 255*info->ssize) is the real limit)
1021 */
1002 len = min(totallen, alloclen); 1022 len = min(totallen, alloclen);
1003 thistime = (len / info->ssize) & 0xff; 1023 thistime = (len / info->ssize) & 0xff;
1004 1024
1005 // ATAPI command 0x20 (READ SECTORS) 1025 /* ATA command 0x20 (READ SECTORS) */
1006 usbat_pack_atapi_sector_cmd(command, thistime, sector, 0x20); 1026 usbat_pack_ata_sector_cmd(command, thistime, sector, 0x20);
1007 1027
1008 // Write/execute ATAPI read command 1028 /* Write/execute ATA read command */
1009 result = usbat_multiple_write(us, registers, command, 7); 1029 result = usbat_multiple_write(us, registers, command, 7);
1010 if (result != USB_STOR_TRANSPORT_GOOD) 1030 if (result != USB_STOR_TRANSPORT_GOOD)
1011 goto leave; 1031 goto leave;
1012 1032
1013 // Read the data we just requested 1033 /* Read the data we just requested */
1014 result = usbat_read_blocks(us, buffer, len); 1034 result = usbat_read_blocks(us, buffer, len);
1015 if (result != USB_STOR_TRANSPORT_GOOD) 1035 if (result != USB_STOR_TRANSPORT_GOOD)
1016 goto leave; 1036 goto leave;
1017 1037
1018 US_DEBUGP("usbat_flash_read_data: %d bytes\n", len); 1038 US_DEBUGP("usbat_flash_read_data: %d bytes\n", len);
1019 1039
1020 // Store the data in the transfer buffer 1040 /* Store the data in the transfer buffer */
1021 usb_stor_access_xfer_buf(buffer, len, us->srb, 1041 usb_stor_access_xfer_buf(buffer, len, us->srb,
1022 &sg_idx, &sg_offset, TO_XFER_BUF); 1042 &sg_idx, &sg_offset, TO_XFER_BUF);
1023 1043
@@ -1061,19 +1081,23 @@ static int usbat_flash_write_data(struct us_data *us,
1061 if (result != USB_STOR_TRANSPORT_GOOD) 1081 if (result != USB_STOR_TRANSPORT_GOOD)
1062 return result; 1082 return result;
1063 1083
1064 // we're working in LBA mode. according to the ATA spec, 1084 /*
1065 // we can support up to 28-bit addressing. I don't know if Jumpshot 1085 * we're working in LBA mode. according to the ATA spec,
1066 // supports beyond 24-bit addressing. It's kind of hard to test 1086 * we can support up to 28-bit addressing. I don't know if the device
1067 // since it requires > 8GB CF card. 1087 * supports beyond 24-bit addressing. It's kind of hard to test
1088 * since it requires > 8GB media.
1089 */
1068 1090
1069 if (sector > 0x0FFFFFFF) 1091 if (sector > 0x0FFFFFFF)
1070 return USB_STOR_TRANSPORT_ERROR; 1092 return USB_STOR_TRANSPORT_ERROR;
1071 1093
1072 totallen = sectors * info->ssize; 1094 totallen = sectors * info->ssize;
1073 1095
1074 // Since we don't write more than 64 KB at a time, we have to create 1096 /*
1075 // a bounce buffer and move the data a piece at a time between the 1097 * Since we don't write more than 64 KB at a time, we have to create
1076 // bounce buffer and the actual transfer buffer. 1098 * a bounce buffer and move the data a piece at a time between the
1099 * bounce buffer and the actual transfer buffer.
1100 */
1077 1101
1078 alloclen = min(totallen, 65536u); 1102 alloclen = min(totallen, 65536u);
1079 buffer = kmalloc(alloclen, GFP_NOIO); 1103 buffer = kmalloc(alloclen, GFP_NOIO);
@@ -1081,24 +1105,26 @@ static int usbat_flash_write_data(struct us_data *us,
1081 return USB_STOR_TRANSPORT_ERROR; 1105 return USB_STOR_TRANSPORT_ERROR;
1082 1106
1083 do { 1107 do {
1084 // loop, never allocate or transfer more than 64k at once 1108 /*
1085 // (min(128k, 255*info->ssize) is the real limit) 1109 * loop, never allocate or transfer more than 64k at once
1110 * (min(128k, 255*info->ssize) is the real limit)
1111 */
1086 len = min(totallen, alloclen); 1112 len = min(totallen, alloclen);
1087 thistime = (len / info->ssize) & 0xff; 1113 thistime = (len / info->ssize) & 0xff;
1088 1114
1089 // Get the data from the transfer buffer 1115 /* Get the data from the transfer buffer */
1090 usb_stor_access_xfer_buf(buffer, len, us->srb, 1116 usb_stor_access_xfer_buf(buffer, len, us->srb,
1091 &sg_idx, &sg_offset, FROM_XFER_BUF); 1117 &sg_idx, &sg_offset, FROM_XFER_BUF);
1092 1118
1093 // ATAPI command 0x30 (WRITE SECTORS) 1119 /* ATA command 0x30 (WRITE SECTORS) */
1094 usbat_pack_atapi_sector_cmd(command, thistime, sector, 0x30); 1120 usbat_pack_ata_sector_cmd(command, thistime, sector, 0x30);
1095 1121
1096 // Write/execute ATAPI write command 1122 /* Write/execute ATA write command */
1097 result = usbat_multiple_write(us, registers, command, 7); 1123 result = usbat_multiple_write(us, registers, command, 7);
1098 if (result != USB_STOR_TRANSPORT_GOOD) 1124 if (result != USB_STOR_TRANSPORT_GOOD)
1099 goto leave; 1125 goto leave;
1100 1126
1101 // Write the data 1127 /* Write the data */
1102 result = usbat_write_blocks(us, buffer, len); 1128 result = usbat_write_blocks(us, buffer, len);
1103 if (result != USB_STOR_TRANSPORT_GOOD) 1129 if (result != USB_STOR_TRANSPORT_GOOD)
1104 goto leave; 1130 goto leave;
@@ -1169,42 +1195,44 @@ static int usbat_hp8200e_handle_read10(struct us_data *us,
1169 srb->transfersize); 1195 srb->transfersize);
1170 } 1196 }
1171 1197
1172 // Since we only read in one block at a time, we have to create 1198 /*
1173 // a bounce buffer and move the data a piece at a time between the 1199 * Since we only read in one block at a time, we have to create
1174 // bounce buffer and the actual transfer buffer. 1200 * a bounce buffer and move the data a piece at a time between the
1201 * bounce buffer and the actual transfer buffer.
1202 */
1175 1203
1176 len = (65535/srb->transfersize) * srb->transfersize; 1204 len = (65535/srb->transfersize) * srb->transfersize;
1177 US_DEBUGP("Max read is %d bytes\n", len); 1205 US_DEBUGP("Max read is %d bytes\n", len);
1178 len = min(len, srb->request_bufflen); 1206 len = min(len, srb->request_bufflen);
1179 buffer = kmalloc(len, GFP_NOIO); 1207 buffer = kmalloc(len, GFP_NOIO);
1180 if (buffer == NULL) // bloody hell! 1208 if (buffer == NULL) /* bloody hell! */
1181 return USB_STOR_TRANSPORT_FAILED; 1209 return USB_STOR_TRANSPORT_FAILED;
1182 sector = short_pack(data[7+3], data[7+2]); 1210 sector = short_pack(data[7+3], data[7+2]);
1183 sector <<= 16; 1211 sector <<= 16;
1184 sector |= short_pack(data[7+5], data[7+4]); 1212 sector |= short_pack(data[7+5], data[7+4]);
1185 transferred = 0; 1213 transferred = 0;
1186 1214
1187 sg_segment = 0; // for keeping track of where we are in 1215 sg_segment = 0; /* for keeping track of where we are in */
1188 sg_offset = 0; // the scatter/gather list 1216 sg_offset = 0; /* the scatter/gather list */
1189 1217
1190 while (transferred != srb->request_bufflen) { 1218 while (transferred != srb->request_bufflen) {
1191 1219
1192 if (len > srb->request_bufflen - transferred) 1220 if (len > srb->request_bufflen - transferred)
1193 len = srb->request_bufflen - transferred; 1221 len = srb->request_bufflen - transferred;
1194 1222
1195 data[3] = len&0xFF; // (cylL) = expected length (L) 1223 data[3] = len&0xFF; /* (cylL) = expected length (L) */
1196 data[4] = (len>>8)&0xFF; // (cylH) = expected length (H) 1224 data[4] = (len>>8)&0xFF; /* (cylH) = expected length (H) */
1197 1225
1198 // Fix up the SCSI command sector and num sectors 1226 /* Fix up the SCSI command sector and num sectors */
1199 1227
1200 data[7+2] = MSB_of(sector>>16); // SCSI command sector 1228 data[7+2] = MSB_of(sector>>16); /* SCSI command sector */
1201 data[7+3] = LSB_of(sector>>16); 1229 data[7+3] = LSB_of(sector>>16);
1202 data[7+4] = MSB_of(sector&0xFFFF); 1230 data[7+4] = MSB_of(sector&0xFFFF);
1203 data[7+5] = LSB_of(sector&0xFFFF); 1231 data[7+5] = LSB_of(sector&0xFFFF);
1204 if (data[7+0] == GPCMD_READ_CD) 1232 if (data[7+0] == GPCMD_READ_CD)
1205 data[7+6] = 0; 1233 data[7+6] = 0;
1206 data[7+7] = MSB_of(len / srb->transfersize); // SCSI command 1234 data[7+7] = MSB_of(len / srb->transfersize); /* SCSI command */
1207 data[7+8] = LSB_of(len / srb->transfersize); // num sectors 1235 data[7+8] = LSB_of(len / srb->transfersize); /* num sectors */
1208 1236
1209 result = usbat_hp8200e_rw_block_test(us, USBAT_ATA, 1237 result = usbat_hp8200e_rw_block_test(us, USBAT_ATA,
1210 registers, data, 19, 1238 registers, data, 19,
@@ -1217,16 +1245,16 @@ static int usbat_hp8200e_handle_read10(struct us_data *us,
1217 if (result != USB_STOR_TRANSPORT_GOOD) 1245 if (result != USB_STOR_TRANSPORT_GOOD)
1218 break; 1246 break;
1219 1247
1220 // Store the data in the transfer buffer 1248 /* Store the data in the transfer buffer */
1221 usb_stor_access_xfer_buf(buffer, len, srb, 1249 usb_stor_access_xfer_buf(buffer, len, srb,
1222 &sg_segment, &sg_offset, TO_XFER_BUF); 1250 &sg_segment, &sg_offset, TO_XFER_BUF);
1223 1251
1224 // Update the amount transferred and the sector number 1252 /* Update the amount transferred and the sector number */
1225 1253
1226 transferred += len; 1254 transferred += len;
1227 sector += len / srb->transfersize; 1255 sector += len / srb->transfersize;
1228 1256
1229 } // while transferred != srb->request_bufflen 1257 } /* while transferred != srb->request_bufflen */
1230 1258
1231 kfree(buffer); 1259 kfree(buffer);
1232 return result; 1260 return result;
@@ -1237,7 +1265,7 @@ static int usbat_select_and_test_registers(struct us_data *us)
1237 int selector; 1265 int selector;
1238 unsigned char *status = us->iobuf; 1266 unsigned char *status = us->iobuf;
1239 1267
1240 // try device = master, then device = slave. 1268 /* try device = master, then device = slave. */
1241 for (selector = 0xA0; selector <= 0xB0; selector += 0x10) { 1269 for (selector = 0xA0; selector <= 0xB0; selector += 0x10) {
1242 if (usbat_write(us, USBAT_ATA, USBAT_ATA_DEVICE, selector) != 1270 if (usbat_write(us, USBAT_ATA, USBAT_ATA_DEVICE, selector) !=
1243 USB_STOR_XFER_GOOD) 1271 USB_STOR_XFER_GOOD)
@@ -1298,7 +1326,7 @@ int init_usbat(struct us_data *us)
1298 memset(us->extra, 0, sizeof(struct usbat_info)); 1326 memset(us->extra, 0, sizeof(struct usbat_info));
1299 info = (struct usbat_info *) (us->extra); 1327 info = (struct usbat_info *) (us->extra);
1300 1328
1301 // Enable peripheral control signals 1329 /* Enable peripheral control signals */
1302 rc = usbat_write_user_io(us, 1330 rc = usbat_write_user_io(us,
1303 USBAT_UIO_OE1 | USBAT_UIO_OE0, 1331 USBAT_UIO_OE1 | USBAT_UIO_OE0,
1304 USBAT_UIO_EPAD | USBAT_UIO_1); 1332 USBAT_UIO_EPAD | USBAT_UIO_1);
@@ -1337,7 +1365,7 @@ int init_usbat(struct us_data *us)
1337 1365
1338 US_DEBUGP("INIT 5\n"); 1366 US_DEBUGP("INIT 5\n");
1339 1367
1340 // Enable peripheral control signals and card detect 1368 /* Enable peripheral control signals and card detect */
1341 rc = usbat_device_enable_cdt(us); 1369 rc = usbat_device_enable_cdt(us);
1342 if (rc != USB_STOR_TRANSPORT_GOOD) 1370 if (rc != USB_STOR_TRANSPORT_GOOD)
1343 return rc; 1371 return rc;
@@ -1364,7 +1392,7 @@ int init_usbat(struct us_data *us)
1364 1392
1365 US_DEBUGP("INIT 9\n"); 1393 US_DEBUGP("INIT 9\n");
1366 1394
1367 // At this point, we need to detect which device we are using 1395 /* At this point, we need to detect which device we are using */
1368 if (usbat_set_transport(us, info)) 1396 if (usbat_set_transport(us, info))
1369 return USB_STOR_TRANSPORT_ERROR; 1397 return USB_STOR_TRANSPORT_ERROR;
1370 1398
@@ -1414,10 +1442,10 @@ static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us)
1414 data[0] = 0x00; 1442 data[0] = 0x00;
1415 data[1] = 0x00; 1443 data[1] = 0x00;
1416 data[2] = 0x00; 1444 data[2] = 0x00;
1417 data[3] = len&0xFF; // (cylL) = expected length (L) 1445 data[3] = len&0xFF; /* (cylL) = expected length (L) */
1418 data[4] = (len>>8)&0xFF; // (cylH) = expected length (H) 1446 data[4] = (len>>8)&0xFF; /* (cylH) = expected length (H) */
1419 data[5] = 0xB0; // (device sel) = slave 1447 data[5] = 0xB0; /* (device sel) = slave */
1420 data[6] = 0xA0; // (command) = ATA PACKET COMMAND 1448 data[6] = 0xA0; /* (command) = ATA PACKET COMMAND */
1421 1449
1422 for (i=7; i<19; i++) { 1450 for (i=7; i<19; i++) {
1423 registers[i] = 0x10; 1451 registers[i] = 0x10;
@@ -1466,13 +1494,15 @@ static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us)
1466 return result; 1494 return result;
1467 } 1495 }
1468 1496
1469 // Write the 12-byte command header. 1497 /*
1470 1498 * Write the 12-byte command header.
1471 // If the command is BLANK then set the timer for 75 minutes. 1499 *
1472 // Otherwise set it for 10 minutes. 1500 * If the command is BLANK then set the timer for 75 minutes.
1473 1501 * Otherwise set it for 10 minutes.
1474 // NOTE: THE 8200 DOCUMENTATION STATES THAT BLANKING A CDRW 1502 *
1475 // AT SPEED 4 IS UNRELIABLE!!! 1503 * NOTE: THE 8200 DOCUMENTATION STATES THAT BLANKING A CDRW
1504 * AT SPEED 4 IS UNRELIABLE!!!
1505 */
1476 1506
1477 if ( (result = usbat_write_block(us, 1507 if ( (result = usbat_write_block(us,
1478 USBAT_ATA, srb->cmnd, 12, 1508 USBAT_ATA, srb->cmnd, 12,
@@ -1481,19 +1511,18 @@ static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us)
1481 return result; 1511 return result;
1482 } 1512 }
1483 1513
1484 // If there is response data to be read in 1514 /* If there is response data to be read in then do it here. */
1485 // then do it here.
1486 1515
1487 if (len != 0 && (srb->sc_data_direction == DMA_FROM_DEVICE)) { 1516 if (len != 0 && (srb->sc_data_direction == DMA_FROM_DEVICE)) {
1488 1517
1489 // How many bytes to read in? Check cylL register 1518 /* How many bytes to read in? Check cylL register */
1490 1519
1491 if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_ME, status) != 1520 if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_ME, status) !=
1492 USB_STOR_XFER_GOOD) { 1521 USB_STOR_XFER_GOOD) {
1493 return USB_STOR_TRANSPORT_ERROR; 1522 return USB_STOR_TRANSPORT_ERROR;
1494 } 1523 }
1495 1524
1496 if (len > 0xFF) { // need to read cylH also 1525 if (len > 0xFF) { /* need to read cylH also */
1497 len = *status; 1526 len = *status;
1498 if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_HI, status) != 1527 if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_HI, status) !=
1499 USB_STOR_XFER_GOOD) { 1528 USB_STOR_XFER_GOOD) {
@@ -1556,13 +1585,16 @@ static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us)
1556 if (rc != USB_STOR_TRANSPORT_GOOD) 1585 if (rc != USB_STOR_TRANSPORT_GOOD)
1557 return rc; 1586 return rc;
1558 1587
1559 info->ssize = 0x200; // hard coded 512 byte sectors as per ATA spec 1588 /* hard coded 512 byte sectors as per ATA spec */
1589 info->ssize = 0x200;
1560 US_DEBUGP("usbat_flash_transport: READ_CAPACITY: %ld sectors, %ld bytes per sector\n", 1590 US_DEBUGP("usbat_flash_transport: READ_CAPACITY: %ld sectors, %ld bytes per sector\n",
1561 info->sectors, info->ssize); 1591 info->sectors, info->ssize);
1562 1592
1563 // build the reply 1593 /*
1564 // note: must return the sector number of the last sector, 1594 * build the reply
1565 // *not* the total number of sectors 1595 * note: must return the sector number of the last sector,
1596 * *not* the total number of sectors
1597 */
1566 ((__be32 *) ptr)[0] = cpu_to_be32(info->sectors - 1); 1598 ((__be32 *) ptr)[0] = cpu_to_be32(info->sectors - 1);
1567 ((__be32 *) ptr)[1] = cpu_to_be32(info->ssize); 1599 ((__be32 *) ptr)[1] = cpu_to_be32(info->ssize);
1568 usb_stor_set_xfer_buf(ptr, 8, srb); 1600 usb_stor_set_xfer_buf(ptr, 8, srb);
@@ -1586,7 +1618,9 @@ static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us)
1586 } 1618 }
1587 1619
1588 if (srb->cmnd[0] == READ_12) { 1620 if (srb->cmnd[0] == READ_12) {
1589 // I don't think we'll ever see a READ_12 but support it anyway... 1621 /*
1622 * I don't think we'll ever see a READ_12 but support it anyway
1623 */
1590 block = ((u32)(srb->cmnd[2]) << 24) | ((u32)(srb->cmnd[3]) << 16) | 1624 block = ((u32)(srb->cmnd[2]) << 24) | ((u32)(srb->cmnd[3]) << 16) |
1591 ((u32)(srb->cmnd[4]) << 8) | ((u32)(srb->cmnd[5])); 1625 ((u32)(srb->cmnd[4]) << 8) | ((u32)(srb->cmnd[5]));
1592 1626
@@ -1608,7 +1642,9 @@ static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us)
1608 } 1642 }
1609 1643
1610 if (srb->cmnd[0] == WRITE_12) { 1644 if (srb->cmnd[0] == WRITE_12) {
1611 // I don't think we'll ever see a WRITE_12 but support it anyway... 1645 /*
1646 * I don't think we'll ever see a WRITE_12 but support it anyway
1647 */
1612 block = ((u32)(srb->cmnd[2]) << 24) | ((u32)(srb->cmnd[3]) << 16) | 1648 block = ((u32)(srb->cmnd[2]) << 24) | ((u32)(srb->cmnd[3]) << 16) |
1613 ((u32)(srb->cmnd[4]) << 8) | ((u32)(srb->cmnd[5])); 1649 ((u32)(srb->cmnd[4]) << 8) | ((u32)(srb->cmnd[5]));
1614 1650
@@ -1645,8 +1681,10 @@ static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us)
1645 } 1681 }
1646 1682
1647 if (srb->cmnd[0] == ALLOW_MEDIUM_REMOVAL) { 1683 if (srb->cmnd[0] == ALLOW_MEDIUM_REMOVAL) {
1648 // sure. whatever. not like we can stop the user from popping 1684 /*
1649 // the media out of the device (no locking doors, etc) 1685 * sure. whatever. not like we can stop the user from popping
1686 * the media out of the device (no locking doors, etc)
1687 */
1650 return USB_STOR_TRANSPORT_GOOD; 1688 return USB_STOR_TRANSPORT_GOOD;
1651 } 1689 }
1652 1690
diff --git a/drivers/usb/storage/shuttle_usbat.h b/drivers/usb/storage/shuttle_usbat.h
index 5b8e867e2ae5..25e7d8b340b8 100644
--- a/drivers/usb/storage/shuttle_usbat.h
+++ b/drivers/usb/storage/shuttle_usbat.h
@@ -55,8 +55,8 @@
55#define USBAT_UIO_WRITE 0 55#define USBAT_UIO_WRITE 0
56 56
57/* Qualifier bits */ 57/* Qualifier bits */
58#define USBAT_QUAL_FCQ 0x20 // full compare 58#define USBAT_QUAL_FCQ 0x20 /* full compare */
59#define USBAT_QUAL_ALQ 0x10 // auto load subcount 59#define USBAT_QUAL_ALQ 0x10 /* auto load subcount */
60 60
61/* USBAT Flash Media status types */ 61/* USBAT Flash Media status types */
62#define USBAT_FLASH_MEDIA_NONE 0 62#define USBAT_FLASH_MEDIA_NONE 0
@@ -67,39 +67,39 @@
67#define USBAT_FLASH_MEDIA_CHANGED 1 67#define USBAT_FLASH_MEDIA_CHANGED 1
68 68
69/* USBAT ATA registers */ 69/* USBAT ATA registers */
70#define USBAT_ATA_DATA 0x10 // read/write data (R/W) 70#define USBAT_ATA_DATA 0x10 /* read/write data (R/W) */
71#define USBAT_ATA_FEATURES 0x11 // set features (W) 71#define USBAT_ATA_FEATURES 0x11 /* set features (W) */
72#define USBAT_ATA_ERROR 0x11 // error (R) 72#define USBAT_ATA_ERROR 0x11 /* error (R) */
73#define USBAT_ATA_SECCNT 0x12 // sector count (R/W) 73#define USBAT_ATA_SECCNT 0x12 /* sector count (R/W) */
74#define USBAT_ATA_SECNUM 0x13 // sector number (R/W) 74#define USBAT_ATA_SECNUM 0x13 /* sector number (R/W) */
75#define USBAT_ATA_LBA_ME 0x14 // cylinder low (R/W) 75#define USBAT_ATA_LBA_ME 0x14 /* cylinder low (R/W) */
76#define USBAT_ATA_LBA_HI 0x15 // cylinder high (R/W) 76#define USBAT_ATA_LBA_HI 0x15 /* cylinder high (R/W) */
77#define USBAT_ATA_DEVICE 0x16 // head/device selection (R/W) 77#define USBAT_ATA_DEVICE 0x16 /* head/device selection (R/W) */
78#define USBAT_ATA_STATUS 0x17 // device status (R) 78#define USBAT_ATA_STATUS 0x17 /* device status (R) */
79#define USBAT_ATA_CMD 0x17 // device command (W) 79#define USBAT_ATA_CMD 0x17 /* device command (W) */
80#define USBAT_ATA_ALTSTATUS 0x0E // status (no clear IRQ) (R) 80#define USBAT_ATA_ALTSTATUS 0x0E /* status (no clear IRQ) (R) */
81 81
82/* USBAT User I/O Data registers */ 82/* USBAT User I/O Data registers */
83#define USBAT_UIO_EPAD 0x80 // Enable Peripheral Control Signals 83#define USBAT_UIO_EPAD 0x80 /* Enable Peripheral Control Signals */
84#define USBAT_UIO_CDT 0x40 // Card Detect (Read Only) 84#define USBAT_UIO_CDT 0x40 /* Card Detect (Read Only) */
85 // CDT = ACKD & !UI1 & !UI0 85 /* CDT = ACKD & !UI1 & !UI0 */
86#define USBAT_UIO_1 0x20 // I/O 1 86#define USBAT_UIO_1 0x20 /* I/O 1 */
87#define USBAT_UIO_0 0x10 // I/O 0 87#define USBAT_UIO_0 0x10 /* I/O 0 */
88#define USBAT_UIO_EPP_ATA 0x08 // 1=EPP mode, 0=ATA mode 88#define USBAT_UIO_EPP_ATA 0x08 /* 1=EPP mode, 0=ATA mode */
89#define USBAT_UIO_UI1 0x04 // Input 1 89#define USBAT_UIO_UI1 0x04 /* Input 1 */
90#define USBAT_UIO_UI0 0x02 // Input 0 90#define USBAT_UIO_UI0 0x02 /* Input 0 */
91#define USBAT_UIO_INTR_ACK 0x01 // Interrupt (ATA & ISA)/Acknowledge (EPP) 91#define USBAT_UIO_INTR_ACK 0x01 /* Interrupt (ATA/ISA)/Acknowledge (EPP) */
92 92
93/* USBAT User I/O Enable registers */ 93/* USBAT User I/O Enable registers */
94#define USBAT_UIO_DRVRST 0x80 // Reset Peripheral 94#define USBAT_UIO_DRVRST 0x80 /* Reset Peripheral */
95#define USBAT_UIO_ACKD 0x40 // Enable Card Detect 95#define USBAT_UIO_ACKD 0x40 /* Enable Card Detect */
96#define USBAT_UIO_OE1 0x20 // I/O 1 set=output/clr=input 96#define USBAT_UIO_OE1 0x20 /* I/O 1 set=output/clr=input */
97 // If ACKD=1, set OE1 to 1 also. 97 /* If ACKD=1, set OE1 to 1 also. */
98#define USBAT_UIO_OE0 0x10 // I/O 0 set=output/clr=input 98#define USBAT_UIO_OE0 0x10 /* I/O 0 set=output/clr=input */
99#define USBAT_UIO_ADPRST 0x01 // Reset SCM chip 99#define USBAT_UIO_ADPRST 0x01 /* Reset SCM chip */
100 100
101/* USBAT Features */ 101/* USBAT Features */
102#define USBAT_FEAT_ETEN 0x80 // External trigger enable 102#define USBAT_FEAT_ETEN 0x80 /* External trigger enable */
103#define USBAT_FEAT_U1 0x08 103#define USBAT_FEAT_U1 0x08
104#define USBAT_FEAT_U0 0x04 104#define USBAT_FEAT_U0 0x04
105#define USBAT_FEAT_ET1 0x02 105#define USBAT_FEAT_ET1 0x02
@@ -112,12 +112,12 @@ struct usbat_info {
112 int devicetype; 112 int devicetype;
113 113
114 /* Used for Flash readers only */ 114 /* Used for Flash readers only */
115 unsigned long sectors; // total sector count 115 unsigned long sectors; /* total sector count */
116 unsigned long ssize; // sector size in bytes 116 unsigned long ssize; /* sector size in bytes */
117 117
118 unsigned char sense_key; 118 unsigned char sense_key;
119 unsigned long sense_asc; // additional sense code 119 unsigned long sense_asc; /* additional sense code */
120 unsigned long sense_ascq; // additional sense code qualifier 120 unsigned long sense_ascq; /* additional sense code qualifier */
121}; 121};
122 122
123#endif 123#endif
diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index c1ba5301ebfc..7ca896a342e3 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -636,11 +636,11 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
636 636
637 /* use the new buffer we have */ 637 /* use the new buffer we have */
638 old_request_buffer = srb->request_buffer; 638 old_request_buffer = srb->request_buffer;
639 srb->request_buffer = srb->sense_buffer; 639 srb->request_buffer = us->sensebuf;
640 640
641 /* set the buffer length for transfer */ 641 /* set the buffer length for transfer */
642 old_request_bufflen = srb->request_bufflen; 642 old_request_bufflen = srb->request_bufflen;
643 srb->request_bufflen = 18; 643 srb->request_bufflen = US_SENSE_SIZE;
644 644
645 /* set up for no scatter-gather use */ 645 /* set up for no scatter-gather use */
646 old_sg = srb->use_sg; 646 old_sg = srb->use_sg;
@@ -652,6 +652,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
652 temp_result = us->transport(us->srb, us); 652 temp_result = us->transport(us->srb, us);
653 653
654 /* let's clean up right away */ 654 /* let's clean up right away */
655 memcpy(srb->sense_buffer, us->sensebuf, US_SENSE_SIZE);
655 srb->resid = old_resid; 656 srb->resid = old_resid;
656 srb->request_buffer = old_request_buffer; 657 srb->request_buffer = old_request_buffer;
657 srb->request_bufflen = old_request_bufflen; 658 srb->request_bufflen = old_request_bufflen;
@@ -923,6 +924,7 @@ int usb_stor_Bulk_max_lun(struct us_data *us)
923 int result; 924 int result;
924 925
925 /* issue the command */ 926 /* issue the command */
927 us->iobuf[0] = 0;
926 result = usb_stor_control_msg(us, us->recv_ctrl_pipe, 928 result = usb_stor_control_msg(us, us->recv_ctrl_pipe,
927 US_BULK_GET_MAX_LUN, 929 US_BULK_GET_MAX_LUN,
928 USB_DIR_IN | USB_TYPE_CLASS | 930 USB_DIR_IN | USB_TYPE_CLASS |
diff --git a/drivers/usb/storage/transport.h b/drivers/usb/storage/transport.h
index 8d9e0663f8fe..0a362cc781ad 100644
--- a/drivers/usb/storage/transport.h
+++ b/drivers/usb/storage/transport.h
@@ -50,7 +50,7 @@
50#define US_PR_CB 0x01 /* Control/Bulk w/o interrupt */ 50#define US_PR_CB 0x01 /* Control/Bulk w/o interrupt */
51#define US_PR_BULK 0x50 /* bulk only */ 51#define US_PR_BULK 0x50 /* bulk only */
52#ifdef CONFIG_USB_STORAGE_USBAT 52#ifdef CONFIG_USB_STORAGE_USBAT
53#define US_PR_SCM_ATAPI 0x80 /* SCM-ATAPI bridge */ 53#define US_PR_USBAT 0x80 /* SCM-ATAPI bridge */
54#endif 54#endif
55#ifdef CONFIG_USB_STORAGE_SDDR09 55#ifdef CONFIG_USB_STORAGE_SDDR09
56#define US_PR_EUSB_SDDR09 0x81 /* SCM-SCSI bridge for SDDR-09 */ 56#define US_PR_EUSB_SDDR09 0x81 /* SCM-SCSI bridge for SDDR-09 */
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index b79dad1b598c..9e926a8f2116 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -71,12 +71,12 @@ UNUSUAL_DEV( 0x03f0, 0x0107, 0x0200, 0x0200,
71UNUSUAL_DEV( 0x03f0, 0x0207, 0x0001, 0x0001, 71UNUSUAL_DEV( 0x03f0, 0x0207, 0x0001, 0x0001,
72 "HP", 72 "HP",
73 "CD-Writer+ 8200e", 73 "CD-Writer+ 8200e",
74 US_SC_8070, US_PR_SCM_ATAPI, init_usbat, 0), 74 US_SC_8070, US_PR_USBAT, init_usbat, 0),
75 75
76UNUSUAL_DEV( 0x03f0, 0x0307, 0x0001, 0x0001, 76UNUSUAL_DEV( 0x03f0, 0x0307, 0x0001, 0x0001,
77 "HP", 77 "HP",
78 "CD-Writer+ CD-4e", 78 "CD-Writer+ CD-4e",
79 US_SC_8070, US_PR_SCM_ATAPI, init_usbat, 0), 79 US_SC_8070, US_PR_USBAT, init_usbat, 0),
80#endif 80#endif
81 81
82/* Patch submitted by Mihnea-Costin Grigore <mihnea@zulu.ro> */ 82/* Patch submitted by Mihnea-Costin Grigore <mihnea@zulu.ro> */
@@ -106,6 +106,13 @@ UNUSUAL_DEV( 0x0411, 0x001c, 0x0113, 0x0113,
106 US_SC_DEVICE, US_PR_DEVICE, NULL, 106 US_SC_DEVICE, US_PR_DEVICE, NULL,
107 US_FL_FIX_INQUIRY ), 107 US_FL_FIX_INQUIRY ),
108 108
109/* Reported by Stefan Werner <dustbln@gmx.de> */
110UNUSUAL_DEV( 0x0419, 0xaaf6, 0x0100, 0x0100,
111 "TrekStor",
112 "i.Beat Joy 2.0",
113 US_SC_DEVICE, US_PR_DEVICE, NULL,
114 US_FL_IGNORE_RESIDUE ),
115
109/* Reported by Olaf Hering <olh@suse.de> from novell bug #105878 */ 116/* Reported by Olaf Hering <olh@suse.de> from novell bug #105878 */
110UNUSUAL_DEV( 0x0424, 0x0fdc, 0x0210, 0x0210, 117UNUSUAL_DEV( 0x0424, 0x0fdc, 0x0210, 0x0210,
111 "SMSC", 118 "SMSC",
@@ -244,6 +251,13 @@ UNUSUAL_DEV( 0x04da, 0x2372, 0x0000, 0x9999,
244 US_SC_DEVICE, US_PR_DEVICE, NULL, 251 US_SC_DEVICE, US_PR_DEVICE, NULL,
245 US_FL_FIX_CAPACITY | US_FL_NOT_LOCKABLE ), 252 US_FL_FIX_CAPACITY | US_FL_NOT_LOCKABLE ),
246 253
254/* Reported by Simeon Simeonov <simeonov_2000@yahoo.com> */
255UNUSUAL_DEV( 0x04da, 0x2373, 0x0000, 0x9999,
256 "LEICA",
257 "D-LUX Camera",
258 US_SC_DEVICE, US_PR_DEVICE, NULL,
259 US_FL_FIX_CAPACITY | US_FL_NOT_LOCKABLE ),
260
247/* Most of the following entries were developed with the help of 261/* Most of the following entries were developed with the help of
248 * Shuttle/SCM directly. 262 * Shuttle/SCM directly.
249 */ 263 */
@@ -333,9 +347,9 @@ UNUSUAL_DEV( 0x04fc, 0x80c2, 0x0100, 0x0100,
333 347
334#ifdef CONFIG_USB_STORAGE_USBAT 348#ifdef CONFIG_USB_STORAGE_USBAT
335UNUSUAL_DEV( 0x04e6, 0x1010, 0x0000, 0x9999, 349UNUSUAL_DEV( 0x04e6, 0x1010, 0x0000, 0x9999,
336 "SCM", 350 "Shuttle/SCM",
337 "SCM USBAT-02", 351 "USBAT-02",
338 US_SC_SCSI, US_PR_SCM_ATAPI, init_usbat, 352 US_SC_SCSI, US_PR_USBAT, init_usbat,
339 US_FL_SINGLE_LUN), 353 US_FL_SINGLE_LUN),
340#endif 354#endif
341 355
@@ -598,6 +612,16 @@ UNUSUAL_DEV( 0x05ac, 0x1205, 0x0000, 0x9999,
598 US_SC_DEVICE, US_PR_DEVICE, NULL, 612 US_SC_DEVICE, US_PR_DEVICE, NULL,
599 US_FL_FIX_CAPACITY ), 613 US_FL_FIX_CAPACITY ),
600 614
615/*
616 * Reported by Tyson Vinson <lornoss@gmail.com>
617 * This particular productId is the iPod Nano
618 */
619UNUSUAL_DEV( 0x05ac, 0x120a, 0x0000, 0x9999,
620 "Apple",
621 "iPod",
622 US_SC_DEVICE, US_PR_DEVICE, NULL,
623 US_FL_FIX_CAPACITY ),
624
601#ifdef CONFIG_USB_STORAGE_JUMPSHOT 625#ifdef CONFIG_USB_STORAGE_JUMPSHOT
602UNUSUAL_DEV( 0x05dc, 0x0001, 0x0000, 0x0001, 626UNUSUAL_DEV( 0x05dc, 0x0001, 0x0000, 0x0001,
603 "Lexar", 627 "Lexar",
@@ -702,6 +726,14 @@ UNUSUAL_DEV( 0x0781, 0x0001, 0x0200, 0x0200,
702 US_SC_SCSI, US_PR_CB, NULL, 726 US_SC_SCSI, US_PR_CB, NULL,
703 US_FL_SINGLE_LUN ), 727 US_FL_SINGLE_LUN ),
704 728
729#ifdef CONFIG_USB_STORAGE_USBAT
730UNUSUAL_DEV( 0x0781, 0x0005, 0x0005, 0x0005,
731 "Sandisk",
732 "ImageMate SDDR-05b",
733 US_SC_SCSI, US_PR_USBAT, init_usbat,
734 US_FL_SINGLE_LUN ),
735#endif
736
705UNUSUAL_DEV( 0x0781, 0x0100, 0x0100, 0x0100, 737UNUSUAL_DEV( 0x0781, 0x0100, 0x0100, 0x0100,
706 "Sandisk", 738 "Sandisk",
707 "ImageMate SDDR-12", 739 "ImageMate SDDR-12",
@@ -724,7 +756,7 @@ UNUSUAL_DEV( 0x07ab, 0xfc01, 0x0000, 0x9999,
724#endif 756#endif
725 757
726/* Reported by Eero Volotinen <eero@ping-viini.org> */ 758/* Reported by Eero Volotinen <eero@ping-viini.org> */
727UNUSUAL_DEV( 0x07ab, 0xfccd, 0x0406, 0x0406, 759UNUSUAL_DEV( 0x07ab, 0xfccd, 0x0000, 0x9999,
728 "Freecom Technologies", 760 "Freecom Technologies",
729 "FHD-Classic", 761 "FHD-Classic",
730 US_SC_DEVICE, US_PR_DEVICE, NULL, 762 US_SC_DEVICE, US_PR_DEVICE, NULL,
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index f9a9bfa1aef5..3847ebed2aa4 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -54,6 +54,7 @@
54#include <linux/module.h> 54#include <linux/module.h>
55#include <linux/init.h> 55#include <linux/init.h>
56#include <linux/slab.h> 56#include <linux/slab.h>
57#include <linux/kthread.h>
57 58
58#include <scsi/scsi.h> 59#include <scsi/scsi.h>
59#include <scsi/scsi_cmnd.h> 60#include <scsi/scsi_cmnd.h>
@@ -111,11 +112,6 @@ static atomic_t total_threads = ATOMIC_INIT(0);
111static DECLARE_COMPLETION(threads_gone); 112static DECLARE_COMPLETION(threads_gone);
112 113
113 114
114static int storage_probe(struct usb_interface *iface,
115 const struct usb_device_id *id);
116
117static void storage_disconnect(struct usb_interface *iface);
118
119/* The entries in this table, except for final ones here 115/* The entries in this table, except for final ones here
120 * (USB_MASS_STORAGE_CLASS and the empty entry), correspond, 116 * (USB_MASS_STORAGE_CLASS and the empty entry), correspond,
121 * line for line with the entries of us_unsuaul_dev_list[]. 117 * line for line with the entries of us_unsuaul_dev_list[].
@@ -233,13 +229,40 @@ static struct us_unusual_dev us_unusual_dev_list[] = {
233 { NULL } 229 { NULL }
234}; 230};
235 231
236static struct usb_driver usb_storage_driver = { 232
237 .owner = THIS_MODULE, 233#ifdef CONFIG_PM /* Minimal support for suspend and resume */
238 .name = "usb-storage", 234
239 .probe = storage_probe, 235static int storage_suspend(struct usb_interface *iface, pm_message_t message)
240 .disconnect = storage_disconnect, 236{
241 .id_table = storage_usb_ids, 237 struct us_data *us = usb_get_intfdata(iface);
242}; 238
239 /* Wait until no command is running */
240 down(&us->dev_semaphore);
241
242 US_DEBUGP("%s\n", __FUNCTION__);
243 iface->dev.power.power_state.event = message.event;
244
245 /* When runtime PM is working, we'll set a flag to indicate
246 * whether we should autoresume when a SCSI request arrives. */
247
248 up(&us->dev_semaphore);
249 return 0;
250}
251
252static int storage_resume(struct usb_interface *iface)
253{
254 struct us_data *us = usb_get_intfdata(iface);
255
256 down(&us->dev_semaphore);
257
258 US_DEBUGP("%s\n", __FUNCTION__);
259 iface->dev.power.power_state.event = PM_EVENT_ON;
260
261 up(&us->dev_semaphore);
262 return 0;
263}
264
265#endif /* CONFIG_PM */
243 266
244/* 267/*
245 * fill_inquiry_response takes an unsigned char array (which must 268 * fill_inquiry_response takes an unsigned char array (which must
@@ -288,22 +311,7 @@ static int usb_stor_control_thread(void * __us)
288 struct us_data *us = (struct us_data *)__us; 311 struct us_data *us = (struct us_data *)__us;
289 struct Scsi_Host *host = us_to_host(us); 312 struct Scsi_Host *host = us_to_host(us);
290 313
291 lock_kernel();
292
293 /*
294 * This thread doesn't need any user-level access,
295 * so get rid of all our resources.
296 */
297 daemonize("usb-storage");
298 current->flags |= PF_NOFREEZE; 314 current->flags |= PF_NOFREEZE;
299 unlock_kernel();
300
301 /* acquire a reference to the host, so it won't be deallocated
302 * until we're ready to exit */
303 scsi_host_get(host);
304
305 /* signal that we've started the thread */
306 complete(&(us->notify));
307 315
308 for(;;) { 316 for(;;) {
309 US_DEBUGP("*** thread sleeping.\n"); 317 US_DEBUGP("*** thread sleeping.\n");
@@ -467,6 +475,12 @@ static int associate_dev(struct us_data *us, struct usb_interface *intf)
467 US_DEBUGP("I/O buffer allocation failed\n"); 475 US_DEBUGP("I/O buffer allocation failed\n");
468 return -ENOMEM; 476 return -ENOMEM;
469 } 477 }
478
479 us->sensebuf = kmalloc(US_SENSE_SIZE, GFP_KERNEL);
480 if (!us->sensebuf) {
481 US_DEBUGP("Sense buffer allocation failed\n");
482 return -ENOMEM;
483 }
470 return 0; 484 return 0;
471} 485}
472 486
@@ -555,8 +569,8 @@ static int get_transport(struct us_data *us)
555 break; 569 break;
556 570
557#ifdef CONFIG_USB_STORAGE_USBAT 571#ifdef CONFIG_USB_STORAGE_USBAT
558 case US_PR_SCM_ATAPI: 572 case US_PR_USBAT:
559 us->transport_name = "SCM/ATAPI"; 573 us->transport_name = "Shuttle USBAT";
560 us->transport = usbat_transport; 574 us->transport = usbat_transport;
561 us->transport_reset = usb_stor_CB_reset; 575 us->transport_reset = usb_stor_CB_reset;
562 us->max_lun = 1; 576 us->max_lun = 1;
@@ -740,6 +754,7 @@ static int get_pipes(struct us_data *us)
740static int usb_stor_acquire_resources(struct us_data *us) 754static int usb_stor_acquire_resources(struct us_data *us)
741{ 755{
742 int p; 756 int p;
757 struct task_struct *th;
743 758
744 us->current_urb = usb_alloc_urb(0, GFP_KERNEL); 759 us->current_urb = usb_alloc_urb(0, GFP_KERNEL);
745 if (!us->current_urb) { 760 if (!us->current_urb) {
@@ -747,38 +762,28 @@ static int usb_stor_acquire_resources(struct us_data *us)
747 return -ENOMEM; 762 return -ENOMEM;
748 } 763 }
749 764
750 /* Lock the device while we carry out the next two operations */
751 down(&us->dev_semaphore);
752
753 /* For bulk-only devices, determine the max LUN value */
754 if (us->protocol == US_PR_BULK) {
755 p = usb_stor_Bulk_max_lun(us);
756 if (p < 0) {
757 up(&us->dev_semaphore);
758 return p;
759 }
760 us->max_lun = p;
761 }
762
763 /* Just before we start our control thread, initialize 765 /* Just before we start our control thread, initialize
764 * the device if it needs initialization */ 766 * the device if it needs initialization */
765 if (us->unusual_dev->initFunction) 767 if (us->unusual_dev->initFunction) {
766 us->unusual_dev->initFunction(us); 768 p = us->unusual_dev->initFunction(us);
767 769 if (p)
768 up(&us->dev_semaphore); 770 return p;
771 }
769 772
770 /* Start up our control thread */ 773 /* Start up our control thread */
771 p = kernel_thread(usb_stor_control_thread, us, CLONE_VM); 774 th = kthread_create(usb_stor_control_thread, us, "usb-storage");
772 if (p < 0) { 775 if (IS_ERR(th)) {
773 printk(KERN_WARNING USB_STORAGE 776 printk(KERN_WARNING USB_STORAGE
774 "Unable to start control thread\n"); 777 "Unable to start control thread\n");
775 return p; 778 return PTR_ERR(th);
776 } 779 }
777 us->pid = p;
778 atomic_inc(&total_threads);
779 780
780 /* Wait for the thread to start */ 781 /* Take a reference to the host for the control thread and
781 wait_for_completion(&(us->notify)); 782 * count it among all the threads we have launched. Then
783 * start it up. */
784 scsi_host_get(us_to_host(us));
785 atomic_inc(&total_threads);
786 wake_up_process(th);
782 787
783 return 0; 788 return 0;
784} 789}
@@ -812,6 +817,8 @@ static void dissociate_dev(struct us_data *us)
812{ 817{
813 US_DEBUGP("-- %s\n", __FUNCTION__); 818 US_DEBUGP("-- %s\n", __FUNCTION__);
814 819
820 kfree(us->sensebuf);
821
815 /* Free the device-related DMA-mapped buffers */ 822 /* Free the device-related DMA-mapped buffers */
816 if (us->cr) 823 if (us->cr)
817 usb_buffer_free(us->pusb_dev, sizeof(*us->cr), us->cr, 824 usb_buffer_free(us->pusb_dev, sizeof(*us->cr), us->cr,
@@ -872,21 +879,6 @@ static int usb_stor_scan_thread(void * __us)
872{ 879{
873 struct us_data *us = (struct us_data *)__us; 880 struct us_data *us = (struct us_data *)__us;
874 881
875 /*
876 * This thread doesn't need any user-level access,
877 * so get rid of all our resources.
878 */
879 lock_kernel();
880 daemonize("usb-stor-scan");
881 unlock_kernel();
882
883 /* Acquire a reference to the host, so it won't be deallocated
884 * until we're ready to exit */
885 scsi_host_get(us_to_host(us));
886
887 /* Signal that we've started the thread */
888 complete(&(us->notify));
889
890 printk(KERN_DEBUG 882 printk(KERN_DEBUG
891 "usb-storage: device found at %d\n", us->pusb_dev->devnum); 883 "usb-storage: device found at %d\n", us->pusb_dev->devnum);
892 884
@@ -904,6 +896,14 @@ retry:
904 896
905 /* If the device is still connected, perform the scanning */ 897 /* If the device is still connected, perform the scanning */
906 if (!test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { 898 if (!test_bit(US_FLIDX_DISCONNECTING, &us->flags)) {
899
900 /* For bulk-only devices, determine the max LUN value */
901 if (us->protocol == US_PR_BULK &&
902 !(us->flags & US_FL_SINGLE_LUN)) {
903 down(&us->dev_semaphore);
904 us->max_lun = usb_stor_Bulk_max_lun(us);
905 up(&us->dev_semaphore);
906 }
907 scsi_scan_host(us_to_host(us)); 907 scsi_scan_host(us_to_host(us));
908 printk(KERN_DEBUG "usb-storage: device scan complete\n"); 908 printk(KERN_DEBUG "usb-storage: device scan complete\n");
909 909
@@ -923,6 +923,7 @@ static int storage_probe(struct usb_interface *intf,
923 struct us_data *us; 923 struct us_data *us;
924 const int id_index = id - storage_usb_ids; 924 const int id_index = id - storage_usb_ids;
925 int result; 925 int result;
926 struct task_struct *th;
926 927
927 US_DEBUGP("USB Mass Storage device detected\n"); 928 US_DEBUGP("USB Mass Storage device detected\n");
928 929
@@ -1003,17 +1004,21 @@ static int storage_probe(struct usb_interface *intf,
1003 } 1004 }
1004 1005
1005 /* Start up the thread for delayed SCSI-device scanning */ 1006 /* Start up the thread for delayed SCSI-device scanning */
1006 result = kernel_thread(usb_stor_scan_thread, us, CLONE_VM); 1007 th = kthread_create(usb_stor_scan_thread, us, "usb-stor-scan");
1007 if (result < 0) { 1008 if (IS_ERR(th)) {
1008 printk(KERN_WARNING USB_STORAGE 1009 printk(KERN_WARNING USB_STORAGE
1009 "Unable to start the device-scanning thread\n"); 1010 "Unable to start the device-scanning thread\n");
1010 quiesce_and_remove_host(us); 1011 quiesce_and_remove_host(us);
1012 result = PTR_ERR(th);
1011 goto BadDevice; 1013 goto BadDevice;
1012 } 1014 }
1013 atomic_inc(&total_threads);
1014 1015
1015 /* Wait for the thread to start */ 1016 /* Take a reference to the host for the scanning thread and
1016 wait_for_completion(&(us->notify)); 1017 * count it among all the threads we have launched. Then
1018 * start it up. */
1019 scsi_host_get(us_to_host(us));
1020 atomic_inc(&total_threads);
1021 wake_up_process(th);
1017 1022
1018 return 0; 1023 return 0;
1019 1024
@@ -1038,6 +1043,18 @@ static void storage_disconnect(struct usb_interface *intf)
1038 * Initialization and registration 1043 * Initialization and registration
1039 ***********************************************************************/ 1044 ***********************************************************************/
1040 1045
1046static struct usb_driver usb_storage_driver = {
1047 .owner = THIS_MODULE,
1048 .name = "usb-storage",
1049 .probe = storage_probe,
1050 .disconnect = storage_disconnect,
1051#ifdef CONFIG_PM
1052 .suspend = storage_suspend,
1053 .resume = storage_resume,
1054#endif
1055 .id_table = storage_usb_ids,
1056};
1057
1041static int __init usb_stor_init(void) 1058static int __init usb_stor_init(void)
1042{ 1059{
1043 int retval; 1060 int retval;
diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
index a195adae57b6..98b09711a739 100644
--- a/drivers/usb/storage/usb.h
+++ b/drivers/usb/storage/usb.h
@@ -117,6 +117,7 @@ enum { US_DO_ALL_FLAGS };
117 */ 117 */
118 118
119#define US_IOBUF_SIZE 64 /* Size of the DMA-mapped I/O buffer */ 119#define US_IOBUF_SIZE 64 /* Size of the DMA-mapped I/O buffer */
120#define US_SENSE_SIZE 18 /* Size of the autosense data buffer */
120 121
121typedef int (*trans_cmnd)(struct scsi_cmnd *, struct us_data*); 122typedef int (*trans_cmnd)(struct scsi_cmnd *, struct us_data*);
122typedef int (*trans_reset)(struct us_data*); 123typedef int (*trans_reset)(struct us_data*);
@@ -160,14 +161,12 @@ struct us_data {
160 struct scsi_cmnd *srb; /* current srb */ 161 struct scsi_cmnd *srb; /* current srb */
161 unsigned int tag; /* current dCBWTag */ 162 unsigned int tag; /* current dCBWTag */
162 163
163 /* thread information */
164 int pid; /* control thread */
165
166 /* control and bulk communications data */ 164 /* control and bulk communications data */
167 struct urb *current_urb; /* USB requests */ 165 struct urb *current_urb; /* USB requests */
168 struct usb_ctrlrequest *cr; /* control requests */ 166 struct usb_ctrlrequest *cr; /* control requests */
169 struct usb_sg_request current_sg; /* scatter-gather req. */ 167 struct usb_sg_request current_sg; /* scatter-gather req. */
170 unsigned char *iobuf; /* I/O buffer */ 168 unsigned char *iobuf; /* I/O buffer */
169 unsigned char *sensebuf; /* sense data buffer */
171 dma_addr_t cr_dma; /* buffer DMA addresses */ 170 dma_addr_t cr_dma; /* buffer DMA addresses */
172 dma_addr_t iobuf_dma; 171 dma_addr_t iobuf_dma;
173 172