xref: /openbmc/linux/drivers/usb/storage/jumpshot.c (revision a9fb6d05d59c9e118ad8c355adfdf88c970c61bc)
1 /* Driver for Lexar "Jumpshot" Compact Flash reader
2  *
3  * jumpshot driver v0.1:
4  *
5  * First release
6  *
7  * Current development and maintenance by:
8  *   (c) 2000 Jimmie Mayfield (mayfield+usb@sackheads.org)
9  *
10  *   Many thanks to Robert Baruch for the SanDisk SmartMedia reader driver
11  *   which I used as a template for this driver.
12  *
13  *   Some bugfixes and scatter-gather code by Gregory P. Smith
14  *   (greg-usb@electricrain.com)
15  *
16  *   Fix for media change by Joerg Schneider (js@joergschneider.com)
17  *
18  * Developed with the assistance of:
19  *
20  *   (C) 2002 Alan Stern <stern@rowland.org>
21  *
22  * This program is free software; you can redistribute it and/or modify it
23  * under the terms of the GNU General Public License as published by the
24  * Free Software Foundation; either version 2, or (at your option) any
25  * later version.
26  *
27  * This program is distributed in the hope that it will be useful, but
28  * WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
30  * General Public License for more details.
31  *
32  * You should have received a copy of the GNU General Public License along
33  * with this program; if not, write to the Free Software Foundation, Inc.,
34  * 675 Mass Ave, Cambridge, MA 02139, USA.
35  */
36 
37  /*
38   * This driver attempts to support the Lexar Jumpshot USB CompactFlash
39   * reader.  Like many other USB CompactFlash readers, the Jumpshot contains
40   * a USB-to-ATA chip.
41   *
42   * This driver supports reading and writing.  If you're truly paranoid,
43   * however, you can force the driver into a write-protected state by setting
44   * the WP enable bits in jumpshot_handle_mode_sense.  See the comments
45   * in that routine.
46   */
47 
48 #include <linux/errno.h>
49 #include <linux/module.h>
50 #include <linux/slab.h>
51 
52 #include <scsi/scsi.h>
53 #include <scsi/scsi_cmnd.h>
54 
55 #include "usb.h"
56 #include "transport.h"
57 #include "protocol.h"
58 #include "debug.h"
59 
60 
61 /*
62  * The table of devices
63  */
64 #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
65 		    vendorName, productName, useProtocol, useTransport, \
66 		    initFunction, flags) \
67 { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
68   .driver_info = (flags)|(USB_US_TYPE_STOR<<24) }
69 
70 struct usb_device_id jumpshot_usb_ids[] = {
71 #	include "unusual_jumpshot.h"
72 	{ }		/* Terminating entry */
73 };
74 MODULE_DEVICE_TABLE(usb, jumpshot_usb_ids);
75 
76 #undef UNUSUAL_DEV
77 
78 /*
79  * The flags table
80  */
81 #define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
82 		    vendor_name, product_name, use_protocol, use_transport, \
83 		    init_function, Flags) \
84 { \
85 	.vendorName = vendor_name,	\
86 	.productName = product_name,	\
87 	.useProtocol = use_protocol,	\
88 	.useTransport = use_transport,	\
89 	.initFunction = init_function,	\
90 }
91 
92 static struct us_unusual_dev jumpshot_unusual_dev_list[] = {
93 #	include "unusual_jumpshot.h"
94 	{ }		/* Terminating entry */
95 };
96 
97 #undef UNUSUAL_DEV
98 
99 
100 struct jumpshot_info {
101    unsigned long   sectors;     /* total sector count */
102    unsigned long   ssize;       /* sector size in bytes */
103 
104    /* the following aren't used yet */
105    unsigned char   sense_key;
106    unsigned long   sense_asc;   /* additional sense code */
107    unsigned long   sense_ascq;  /* additional sense code qualifier */
108 };
109 
110 static inline int jumpshot_bulk_read(struct us_data *us,
111 				     unsigned char *data,
112 				     unsigned int len)
113 {
114 	if (len == 0)
115 		return USB_STOR_XFER_GOOD;
116 
117 	US_DEBUGP("jumpshot_bulk_read:  len = %d\n", len);
118 	return usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
119 			data, len, NULL);
120 }
121 
122 
123 static inline int jumpshot_bulk_write(struct us_data *us,
124 				      unsigned char *data,
125 				      unsigned int len)
126 {
127 	if (len == 0)
128 		return USB_STOR_XFER_GOOD;
129 
130 	US_DEBUGP("jumpshot_bulk_write:  len = %d\n", len);
131 	return usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
132 			data, len, NULL);
133 }
134 
135 
136 static int jumpshot_get_status(struct us_data  *us)
137 {
138 	int rc;
139 
140 	if (!us)
141 		return USB_STOR_TRANSPORT_ERROR;
142 
143 	// send the setup
144 	rc = usb_stor_ctrl_transfer(us, us->recv_ctrl_pipe,
145 				   0, 0xA0, 0, 7, us->iobuf, 1);
146 
147 	if (rc != USB_STOR_XFER_GOOD)
148 		return USB_STOR_TRANSPORT_ERROR;
149 
150 	if (us->iobuf[0] != 0x50) {
151 		US_DEBUGP("jumpshot_get_status:  0x%2x\n",
152 			  us->iobuf[0]);
153 		return USB_STOR_TRANSPORT_ERROR;
154 	}
155 
156 	return USB_STOR_TRANSPORT_GOOD;
157 }
158 
159 static int jumpshot_read_data(struct us_data *us,
160 			      struct jumpshot_info *info,
161 			      u32 sector,
162 			      u32 sectors)
163 {
164 	unsigned char *command = us->iobuf;
165 	unsigned char *buffer;
166 	unsigned char  thistime;
167 	unsigned int totallen, alloclen;
168 	int len, result;
169 	unsigned int sg_offset = 0;
170 	struct scatterlist *sg = NULL;
171 
172 	// we're working in LBA mode.  according to the ATA spec,
173 	// we can support up to 28-bit addressing.  I don't know if Jumpshot
174 	// supports beyond 24-bit addressing.  It's kind of hard to test
175 	// since it requires > 8GB CF card.
176 
177 	if (sector > 0x0FFFFFFF)
178 		return USB_STOR_TRANSPORT_ERROR;
179 
180 	totallen = sectors * info->ssize;
181 
182 	// Since we don't read more than 64 KB at a time, we have to create
183 	// a bounce buffer and move the data a piece at a time between the
184 	// bounce buffer and the actual transfer buffer.
185 
186 	alloclen = min(totallen, 65536u);
187 	buffer = kmalloc(alloclen, GFP_NOIO);
188 	if (buffer == NULL)
189 		return USB_STOR_TRANSPORT_ERROR;
190 
191 	do {
192 		// loop, never allocate or transfer more than 64k at once
193 		// (min(128k, 255*info->ssize) is the real limit)
194 		len = min(totallen, alloclen);
195 		thistime = (len / info->ssize) & 0xff;
196 
197 		command[0] = 0;
198 		command[1] = thistime;
199 		command[2] = sector & 0xFF;
200 		command[3] = (sector >>  8) & 0xFF;
201 		command[4] = (sector >> 16) & 0xFF;
202 
203 		command[5] = 0xE0 | ((sector >> 24) & 0x0F);
204 		command[6] = 0x20;
205 
206 		// send the setup + command
207 		result = usb_stor_ctrl_transfer(us, us->send_ctrl_pipe,
208 					       0, 0x20, 0, 1, command, 7);
209 		if (result != USB_STOR_XFER_GOOD)
210 			goto leave;
211 
212 		// read the result
213 		result = jumpshot_bulk_read(us, buffer, len);
214 		if (result != USB_STOR_XFER_GOOD)
215 			goto leave;
216 
217 		US_DEBUGP("jumpshot_read_data:  %d bytes\n", len);
218 
219 		// Store the data in the transfer buffer
220 		usb_stor_access_xfer_buf(buffer, len, us->srb,
221 				 &sg, &sg_offset, TO_XFER_BUF);
222 
223 		sector += thistime;
224 		totallen -= len;
225 	} while (totallen > 0);
226 
227 	kfree(buffer);
228 	return USB_STOR_TRANSPORT_GOOD;
229 
230  leave:
231 	kfree(buffer);
232 	return USB_STOR_TRANSPORT_ERROR;
233 }
234 
235 
236 static int jumpshot_write_data(struct us_data *us,
237 			       struct jumpshot_info *info,
238 			       u32 sector,
239 			       u32 sectors)
240 {
241 	unsigned char *command = us->iobuf;
242 	unsigned char *buffer;
243 	unsigned char  thistime;
244 	unsigned int totallen, alloclen;
245 	int len, result, waitcount;
246 	unsigned int sg_offset = 0;
247 	struct scatterlist *sg = NULL;
248 
249 	// we're working in LBA mode.  according to the ATA spec,
250 	// we can support up to 28-bit addressing.  I don't know if Jumpshot
251 	// supports beyond 24-bit addressing.  It's kind of hard to test
252 	// since it requires > 8GB CF card.
253 	//
254 	if (sector > 0x0FFFFFFF)
255 		return USB_STOR_TRANSPORT_ERROR;
256 
257 	totallen = sectors * info->ssize;
258 
259 	// Since we don't write more than 64 KB at a time, we have to create
260 	// a bounce buffer and move the data a piece at a time between the
261 	// bounce buffer and the actual transfer buffer.
262 
263 	alloclen = min(totallen, 65536u);
264 	buffer = kmalloc(alloclen, GFP_NOIO);
265 	if (buffer == NULL)
266 		return USB_STOR_TRANSPORT_ERROR;
267 
268 	do {
269 		// loop, never allocate or transfer more than 64k at once
270 		// (min(128k, 255*info->ssize) is the real limit)
271 
272 		len = min(totallen, alloclen);
273 		thistime = (len / info->ssize) & 0xff;
274 
275 		// Get the data from the transfer buffer
276 		usb_stor_access_xfer_buf(buffer, len, us->srb,
277 				&sg, &sg_offset, FROM_XFER_BUF);
278 
279 		command[0] = 0;
280 		command[1] = thistime;
281 		command[2] = sector & 0xFF;
282 		command[3] = (sector >>  8) & 0xFF;
283 		command[4] = (sector >> 16) & 0xFF;
284 
285 		command[5] = 0xE0 | ((sector >> 24) & 0x0F);
286 		command[6] = 0x30;
287 
288 		// send the setup + command
289 		result = usb_stor_ctrl_transfer(us, us->send_ctrl_pipe,
290 			0, 0x20, 0, 1, command, 7);
291 		if (result != USB_STOR_XFER_GOOD)
292 			goto leave;
293 
294 		// send the data
295 		result = jumpshot_bulk_write(us, buffer, len);
296 		if (result != USB_STOR_XFER_GOOD)
297 			goto leave;
298 
299 		// read the result.  apparently the bulk write can complete
300 		// before the jumpshot drive is finished writing.  so we loop
301 		// here until we get a good return code
302 		waitcount = 0;
303 		do {
304 			result = jumpshot_get_status(us);
305 			if (result != USB_STOR_TRANSPORT_GOOD) {
306 				// I have not experimented to find the smallest value.
307 				//
308 				msleep(50);
309 			}
310 		} while ((result != USB_STOR_TRANSPORT_GOOD) && (waitcount < 10));
311 
312 		if (result != USB_STOR_TRANSPORT_GOOD)
313 			US_DEBUGP("jumpshot_write_data:  Gah!  Waitcount = 10.  Bad write!?\n");
314 
315 		sector += thistime;
316 		totallen -= len;
317 	} while (totallen > 0);
318 
319 	kfree(buffer);
320 	return result;
321 
322  leave:
323 	kfree(buffer);
324 	return USB_STOR_TRANSPORT_ERROR;
325 }
326 
327 static int jumpshot_id_device(struct us_data *us,
328 			      struct jumpshot_info *info)
329 {
330 	unsigned char *command = us->iobuf;
331 	unsigned char *reply;
332 	int 	 rc;
333 
334 	if (!us || !info)
335 		return USB_STOR_TRANSPORT_ERROR;
336 
337 	command[0] = 0xE0;
338 	command[1] = 0xEC;
339 	reply = kmalloc(512, GFP_NOIO);
340 	if (!reply)
341 		return USB_STOR_TRANSPORT_ERROR;
342 
343 	// send the setup
344 	rc = usb_stor_ctrl_transfer(us, us->send_ctrl_pipe,
345 				   0, 0x20, 0, 6, command, 2);
346 
347 	if (rc != USB_STOR_XFER_GOOD) {
348 		US_DEBUGP("jumpshot_id_device:  Gah! "
349 			  "send_control for read_capacity failed\n");
350 		rc = USB_STOR_TRANSPORT_ERROR;
351 		goto leave;
352 	}
353 
354 	// read the reply
355 	rc = jumpshot_bulk_read(us, reply, 512);
356 	if (rc != USB_STOR_XFER_GOOD) {
357 		rc = USB_STOR_TRANSPORT_ERROR;
358 		goto leave;
359 	}
360 
361 	info->sectors = ((u32)(reply[117]) << 24) |
362 			((u32)(reply[116]) << 16) |
363 			((u32)(reply[115]) <<  8) |
364 			((u32)(reply[114])      );
365 
366 	rc = USB_STOR_TRANSPORT_GOOD;
367 
368  leave:
369 	kfree(reply);
370 	return rc;
371 }
372 
373 static int jumpshot_handle_mode_sense(struct us_data *us,
374 				      struct scsi_cmnd * srb,
375 				      int sense_6)
376 {
377 	static unsigned char rw_err_page[12] = {
378 		0x1, 0xA, 0x21, 1, 0, 0, 0, 0, 1, 0, 0, 0
379 	};
380 	static unsigned char cache_page[12] = {
381 		0x8, 0xA, 0x1, 0, 0, 0, 0, 0, 0, 0, 0, 0
382 	};
383 	static unsigned char rbac_page[12] = {
384 		0x1B, 0xA, 0, 0x81, 0, 0, 0, 0, 0, 0, 0, 0
385 	};
386 	static unsigned char timer_page[8] = {
387 		0x1C, 0x6, 0, 0, 0, 0
388 	};
389 	unsigned char pc, page_code;
390 	unsigned int i = 0;
391 	struct jumpshot_info *info = (struct jumpshot_info *) (us->extra);
392 	unsigned char *ptr = us->iobuf;
393 
394 	pc = srb->cmnd[2] >> 6;
395 	page_code = srb->cmnd[2] & 0x3F;
396 
397 	switch (pc) {
398 	   case 0x0:
399 		US_DEBUGP("jumpshot_handle_mode_sense:  Current values\n");
400 		break;
401 	   case 0x1:
402 		US_DEBUGP("jumpshot_handle_mode_sense:  Changeable values\n");
403 		break;
404 	   case 0x2:
405 		US_DEBUGP("jumpshot_handle_mode_sense:  Default values\n");
406 		break;
407 	   case 0x3:
408 		US_DEBUGP("jumpshot_handle_mode_sense:  Saves values\n");
409 		break;
410 	}
411 
412 	memset(ptr, 0, 8);
413 	if (sense_6) {
414 		ptr[2] = 0x00;		// WP enable: 0x80
415 		i = 4;
416 	} else {
417 		ptr[3] = 0x00;		// WP enable: 0x80
418 		i = 8;
419 	}
420 
421 	switch (page_code) {
422 	   case 0x0:
423 		// vendor-specific mode
424 		info->sense_key = 0x05;
425 		info->sense_asc = 0x24;
426 		info->sense_ascq = 0x00;
427 		return USB_STOR_TRANSPORT_FAILED;
428 
429 	   case 0x1:
430 		memcpy(ptr + i, rw_err_page, sizeof(rw_err_page));
431 		i += sizeof(rw_err_page);
432 		break;
433 
434 	   case 0x8:
435 		memcpy(ptr + i, cache_page, sizeof(cache_page));
436 		i += sizeof(cache_page);
437 		break;
438 
439 	   case 0x1B:
440 		memcpy(ptr + i, rbac_page, sizeof(rbac_page));
441 		i += sizeof(rbac_page);
442 		break;
443 
444 	   case 0x1C:
445 		memcpy(ptr + i, timer_page, sizeof(timer_page));
446 		i += sizeof(timer_page);
447 		break;
448 
449 	   case 0x3F:
450 		memcpy(ptr + i, timer_page, sizeof(timer_page));
451 		i += sizeof(timer_page);
452 		memcpy(ptr + i, rbac_page, sizeof(rbac_page));
453 		i += sizeof(rbac_page);
454 		memcpy(ptr + i, cache_page, sizeof(cache_page));
455 		i += sizeof(cache_page);
456 		memcpy(ptr + i, rw_err_page, sizeof(rw_err_page));
457 		i += sizeof(rw_err_page);
458 		break;
459 	}
460 
461 	if (sense_6)
462 		ptr[0] = i - 1;
463 	else
464 		((__be16 *) ptr)[0] = cpu_to_be16(i - 2);
465 	usb_stor_set_xfer_buf(ptr, i, srb);
466 
467 	return USB_STOR_TRANSPORT_GOOD;
468 }
469 
470 
471 static void jumpshot_info_destructor(void *extra)
472 {
473 	// this routine is a placeholder...
474 	// currently, we don't allocate any extra blocks so we're okay
475 }
476 
477 
478 
479 // Transport for the Lexar 'Jumpshot'
480 //
481 static int jumpshot_transport(struct scsi_cmnd *srb, struct us_data *us)
482 {
483 	struct jumpshot_info *info;
484 	int rc;
485 	unsigned long block, blocks;
486 	unsigned char *ptr = us->iobuf;
487 	static unsigned char inquiry_response[8] = {
488 		0x00, 0x80, 0x00, 0x01, 0x1F, 0x00, 0x00, 0x00
489 	};
490 
491 	if (!us->extra) {
492 		us->extra = kzalloc(sizeof(struct jumpshot_info), GFP_NOIO);
493 		if (!us->extra) {
494 			US_DEBUGP("jumpshot_transport:  Gah! Can't allocate storage for jumpshot info struct!\n");
495 			return USB_STOR_TRANSPORT_ERROR;
496 		}
497 		us->extra_destructor = jumpshot_info_destructor;
498 	}
499 
500 	info = (struct jumpshot_info *) (us->extra);
501 
502 	if (srb->cmnd[0] == INQUIRY) {
503 		US_DEBUGP("jumpshot_transport:  INQUIRY.  Returning bogus response.\n");
504 		memcpy(ptr, inquiry_response, sizeof(inquiry_response));
505 		fill_inquiry_response(us, ptr, 36);
506 		return USB_STOR_TRANSPORT_GOOD;
507 	}
508 
509 	if (srb->cmnd[0] == READ_CAPACITY) {
510 		info->ssize = 0x200;  // hard coded 512 byte sectors as per ATA spec
511 
512 		rc = jumpshot_get_status(us);
513 		if (rc != USB_STOR_TRANSPORT_GOOD)
514 			return rc;
515 
516 		rc = jumpshot_id_device(us, info);
517 		if (rc != USB_STOR_TRANSPORT_GOOD)
518 			return rc;
519 
520 		US_DEBUGP("jumpshot_transport:  READ_CAPACITY:  %ld sectors, %ld bytes per sector\n",
521 			  info->sectors, info->ssize);
522 
523 		// build the reply
524 		//
525 		((__be32 *) ptr)[0] = cpu_to_be32(info->sectors - 1);
526 		((__be32 *) ptr)[1] = cpu_to_be32(info->ssize);
527 		usb_stor_set_xfer_buf(ptr, 8, srb);
528 
529 		return USB_STOR_TRANSPORT_GOOD;
530 	}
531 
532 	if (srb->cmnd[0] == MODE_SELECT_10) {
533 		US_DEBUGP("jumpshot_transport:  Gah! MODE_SELECT_10.\n");
534 		return USB_STOR_TRANSPORT_ERROR;
535 	}
536 
537 	if (srb->cmnd[0] == READ_10) {
538 		block = ((u32)(srb->cmnd[2]) << 24) | ((u32)(srb->cmnd[3]) << 16) |
539 			((u32)(srb->cmnd[4]) <<  8) | ((u32)(srb->cmnd[5]));
540 
541 		blocks = ((u32)(srb->cmnd[7]) << 8) | ((u32)(srb->cmnd[8]));
542 
543 		US_DEBUGP("jumpshot_transport:  READ_10: read block 0x%04lx  count %ld\n", block, blocks);
544 		return jumpshot_read_data(us, info, block, blocks);
545 	}
546 
547 	if (srb->cmnd[0] == READ_12) {
548 		// I don't think we'll ever see a READ_12 but support it anyway...
549 		//
550 		block = ((u32)(srb->cmnd[2]) << 24) | ((u32)(srb->cmnd[3]) << 16) |
551 			((u32)(srb->cmnd[4]) <<  8) | ((u32)(srb->cmnd[5]));
552 
553 		blocks = ((u32)(srb->cmnd[6]) << 24) | ((u32)(srb->cmnd[7]) << 16) |
554 			 ((u32)(srb->cmnd[8]) <<  8) | ((u32)(srb->cmnd[9]));
555 
556 		US_DEBUGP("jumpshot_transport:  READ_12: read block 0x%04lx  count %ld\n", block, blocks);
557 		return jumpshot_read_data(us, info, block, blocks);
558 	}
559 
560 	if (srb->cmnd[0] == WRITE_10) {
561 		block = ((u32)(srb->cmnd[2]) << 24) | ((u32)(srb->cmnd[3]) << 16) |
562 			((u32)(srb->cmnd[4]) <<  8) | ((u32)(srb->cmnd[5]));
563 
564 		blocks = ((u32)(srb->cmnd[7]) << 8) | ((u32)(srb->cmnd[8]));
565 
566 		US_DEBUGP("jumpshot_transport:  WRITE_10: write block 0x%04lx  count %ld\n", block, blocks);
567 		return jumpshot_write_data(us, info, block, blocks);
568 	}
569 
570 	if (srb->cmnd[0] == WRITE_12) {
571 		// I don't think we'll ever see a WRITE_12 but support it anyway...
572 		//
573 		block = ((u32)(srb->cmnd[2]) << 24) | ((u32)(srb->cmnd[3]) << 16) |
574 			((u32)(srb->cmnd[4]) <<  8) | ((u32)(srb->cmnd[5]));
575 
576 		blocks = ((u32)(srb->cmnd[6]) << 24) | ((u32)(srb->cmnd[7]) << 16) |
577 			 ((u32)(srb->cmnd[8]) <<  8) | ((u32)(srb->cmnd[9]));
578 
579 		US_DEBUGP("jumpshot_transport:  WRITE_12: write block 0x%04lx  count %ld\n", block, blocks);
580 		return jumpshot_write_data(us, info, block, blocks);
581 	}
582 
583 
584 	if (srb->cmnd[0] == TEST_UNIT_READY) {
585 		US_DEBUGP("jumpshot_transport:  TEST_UNIT_READY.\n");
586 		return jumpshot_get_status(us);
587 	}
588 
589 	if (srb->cmnd[0] == REQUEST_SENSE) {
590 		US_DEBUGP("jumpshot_transport:  REQUEST_SENSE.\n");
591 
592 		memset(ptr, 0, 18);
593 		ptr[0] = 0xF0;
594 		ptr[2] = info->sense_key;
595 		ptr[7] = 11;
596 		ptr[12] = info->sense_asc;
597 		ptr[13] = info->sense_ascq;
598 		usb_stor_set_xfer_buf(ptr, 18, srb);
599 
600 		return USB_STOR_TRANSPORT_GOOD;
601 	}
602 
603 	if (srb->cmnd[0] == MODE_SENSE) {
604 		US_DEBUGP("jumpshot_transport:  MODE_SENSE_6 detected\n");
605 		return jumpshot_handle_mode_sense(us, srb, 1);
606 	}
607 
608 	if (srb->cmnd[0] == MODE_SENSE_10) {
609 		US_DEBUGP("jumpshot_transport:  MODE_SENSE_10 detected\n");
610 		return jumpshot_handle_mode_sense(us, srb, 0);
611 	}
612 
613 	if (srb->cmnd[0] == ALLOW_MEDIUM_REMOVAL) {
614 		// sure.  whatever.  not like we can stop the user from popping
615 		// the media out of the device (no locking doors, etc)
616 		//
617 		return USB_STOR_TRANSPORT_GOOD;
618 	}
619 
620 	if (srb->cmnd[0] == START_STOP) {
621 		/* this is used by sd.c'check_scsidisk_media_change to detect
622 		   media change */
623 		US_DEBUGP("jumpshot_transport:  START_STOP.\n");
624 		/* the first jumpshot_id_device after a media change returns
625 		   an error (determined experimentally) */
626 		rc = jumpshot_id_device(us, info);
627 		if (rc == USB_STOR_TRANSPORT_GOOD) {
628 			info->sense_key = NO_SENSE;
629 			srb->result = SUCCESS;
630 		} else {
631 			info->sense_key = UNIT_ATTENTION;
632 			srb->result = SAM_STAT_CHECK_CONDITION;
633 		}
634 		return rc;
635 	}
636 
637 	US_DEBUGP("jumpshot_transport:  Gah! Unknown command: %d (0x%x)\n",
638 		  srb->cmnd[0], srb->cmnd[0]);
639 	info->sense_key = 0x05;
640 	info->sense_asc = 0x20;
641 	info->sense_ascq = 0x00;
642 	return USB_STOR_TRANSPORT_FAILED;
643 }
644 
645 static int jumpshot_probe(struct usb_interface *intf,
646 			 const struct usb_device_id *id)
647 {
648 	struct us_data *us;
649 	int result;
650 
651 	result = usb_stor_probe1(&us, intf, id,
652 			(id - jumpshot_usb_ids) + jumpshot_unusual_dev_list);
653 	if (result)
654 		return result;
655 
656 	us->transport_name  = "Lexar Jumpshot Control/Bulk";
657 	us->transport = jumpshot_transport;
658 	us->transport_reset = usb_stor_Bulk_reset;
659 	us->max_lun = 1;
660 
661 	result = usb_stor_probe2(us);
662 	return result;
663 }
664 
665 static struct usb_driver jumpshot_driver = {
666 	.name =		"ums-jumpshot",
667 	.probe =	jumpshot_probe,
668 	.disconnect =	usb_stor_disconnect,
669 	.suspend =	usb_stor_suspend,
670 	.resume =	usb_stor_resume,
671 	.reset_resume =	usb_stor_reset_resume,
672 	.pre_reset =	usb_stor_pre_reset,
673 	.post_reset =	usb_stor_post_reset,
674 	.id_table =	jumpshot_usb_ids,
675 	.soft_unbind =	1,
676 };
677 
678 static int __init jumpshot_init(void)
679 {
680 	return usb_register(&jumpshot_driver);
681 }
682 
683 static void __exit jumpshot_exit(void)
684 {
685 	usb_deregister(&jumpshot_driver);
686 }
687 
688 module_init(jumpshot_init);
689 module_exit(jumpshot_exit);
690