26 #include <linux/errno.h>
27 #include <linux/module.h>
28 #include <linux/slab.h>
30 #include <scsi/scsi.h>
45 #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
46 vendorName, productName, useProtocol, useTransport, \
47 initFunction, flags) \
48 { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
49 .driver_info = (flags) }
62 #define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
63 vendor_name, product_name, use_protocol, use_transport, \
64 init_function, Flags) \
66 .vendorName = vendor_name, \
67 .productName = product_name, \
68 .useProtocol = use_protocol, \
69 .useTransport = use_transport, \
70 .initFunction = init_function, \
81 #define short_pack(lsb,msb) ( ((u16)(lsb)) | ( ((u16)(msb))<<8 ) )
82 #define LSB_of(s) ((s)&0xFF)
83 #define MSB_of(s) ((s)>>8)
86 #define set_sense_info(sk, asc, ascq) \
88 info->sense_data[2] = sk; \
89 info->sense_data[12] = asc; \
90 info->sense_data[13] = ascq; \
112 #define NOT_ALLOCATED 0xffffffff
113 #define BAD_BLOCK 0xffff
114 #define CIS_BLOCK 0x400
115 #define UNUSED_BLOCK 0x3ff
119 unsigned char *
data,
unsigned int len) {
134 static int sddr55_status(
struct us_data *us)
145 result = sddr55_bulk_transport(us,
148 US_DEBUGP(
"Result for send_command in status %d\n",
156 result = sddr55_bulk_transport(us,
183 result = sddr55_bulk_transport(us,
195 static int sddr55_read_data(
struct us_data *us,
201 unsigned char *command = us->
iobuf;
202 unsigned char *status = us->
iobuf;
209 unsigned short pages;
239 US_DEBUGP(
"Read %02X pages, from PBA %04X"
240 " (LBA %04X) page %02X\n",
241 pages, pba, lba, page);
261 result = sddr55_bulk_transport(us,
264 US_DEBUGP(
"Result for send_command in read_data %d\n",
273 result = sddr55_bulk_transport(us,
282 result = sddr55_bulk_transport(us,
291 if (status[0] == 0xff && status[1] == 0x4) {
315 static int sddr55_write_data(
struct us_data *us,
318 unsigned short sectors) {
321 unsigned char *command = us->
iobuf;
322 unsigned char *status = us->
iobuf;
327 unsigned int new_pba;
330 unsigned short pages;
345 len =
min((
unsigned int) sectors, (
unsigned int) info->
blocksize >>
353 while (sectors > 0) {
371 US_DEBUGP(
"Write %02X pages, to PBA %04X"
372 " (LBA %04X) page %02X\n",
373 pages, pba, lba, page);
385 pba = (lba / 1000) * 1024;
398 for (
i = 0;
i < max_pba;
i++, pba++) {
401 if (found_count++ > 16)
410 US_DEBUGP(
"Couldn't find unallocated block\n");
417 US_DEBUGP(
"Allocating PBA %04X for LBA %04X\n", pba, lba);
430 command[0] =
LSB_of(lba % 1000);
431 command[6] =
MSB_of(lba % 1000);
438 result = sddr55_bulk_transport(us,
442 US_DEBUGP(
"Result for send_command in write_data %d\n",
452 result = sddr55_bulk_transport(us,
456 US_DEBUGP(
"Result for send_data in write_data %d\n",
469 US_DEBUGP(
"Result for get_status in write_data %d\n",
478 new_pba = (status[3] + (status[4] << 8) + (status[5] << 16))
482 if (status[0] == 0xff && status[1] == 0x4) {
490 US_DEBUGP(
"Updating maps for LBA %04X: old PBA %04X, new PBA %04X\n",
499 printk(
KERN_ERR "sddr55 error: new PBA %04X already in use for LBA %04X\n",
521 static int sddr55_read_deviceID(
struct us_data *us,
522 unsigned char *manufacturerID,
523 unsigned char *deviceID) {
526 unsigned char *command = us->
iobuf;
527 unsigned char *content = us->
iobuf;
532 result = sddr55_bulk_transport(us,
DMA_TO_DEVICE, command, 8);
534 US_DEBUGP(
"Result of send_control for device ID is %d\n",
540 result = sddr55_bulk_transport(us,
546 *manufacturerID = content[0];
547 *deviceID = content[1];
549 if (content[0] != 0xff) {
550 result = sddr55_bulk_transport(us,
558 static int sddr55_reset(
struct us_data *us)
564 static unsigned long sddr55_get_capacity(
struct us_data *us) {
573 result = sddr55_read_deviceID(us,
577 US_DEBUGP(
"Result of read_deviceID is %d\n",
583 US_DEBUGP(
"Device ID = %02X\n", deviceID);
584 US_DEBUGP(
"Manuf ID = %02X\n", manufacturerID);
648 static int sddr55_read_map(
struct us_data *us) {
653 unsigned char *command = us->
iobuf;
656 unsigned short max_lba;
671 command[6] = numblocks * 2 / 256;
674 result = sddr55_bulk_transport(us,
DMA_TO_DEVICE, command, 8);
681 result = sddr55_bulk_transport(us,
DMA_FROM_DEVICE, buffer, numblocks * 2);
720 for (i=0; i<numblocks; i++) {
723 lba =
short_pack(buffer[i * 2], buffer[i * 2 + 1]);
743 if (lba >= max_lba) {
750 "sddr55: map inconsistency at LBA %04X\n",
755 if (lba<0x10 || (lba>=0x3E0 && lba<0x3EF))
756 US_DEBUGP(
"LBA %04X <-> PBA %04X\n", lba, i);
766 static void sddr55_card_info_destructor(
void *
extra) {
783 static unsigned char inquiry_response[8] = {
784 0x00, 0x80, 0x00, 0x02, 0x1F, 0x00, 0x00, 0x00
787 static unsigned char mode_page_01[20] = {
788 0x0, 0x12, 0x00, 0x80, 0x0, 0x0, 0x0, 0x0,
790 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
797 unsigned short pages;
828 memcpy(ptr, inquiry_response, 8);
839 result = sddr55_status (us);
841 result = sddr55_status (us);
859 capacity = sddr55_get_capacity(us);
874 capacity = (capacity / 256) * 250;
890 memcpy(ptr, mode_page_01,
sizeof mode_page_01);
894 if ( (srb->
cmnd[2] & 0x3F) == 0x01 ) {
896 "SDDR55: Dummy up request for mode page 1\n");
899 }
else if ( (srb->
cmnd[2] & 0x3F) == 0x3F ) {
901 "SDDR55: Dummy up request for all mode pages\n");
912 "SDDR55: %s medium removal. Not that I can do"
913 " anything about it...\n",
914 (srb->
cmnd[4]&0x03) ?
"Prevent" :
"Allow");
938 US_DEBUGP(
"Error: Requested LBA %04X exceeds maximum "
949 US_DEBUGP(
"WRITE_10: write block %04X (LBA %04X) page %01X"
951 pba, lba, page, pages);
953 return sddr55_write_data(us, lba, page, pages);
955 US_DEBUGP(
"READ_10: read block %04X (LBA %04X) page %01X"
957 pba, lba, page, pages);
959 return sddr55_read_data(us, lba, page, pages);
985 (
id - sddr55_usb_ids) + sddr55_unusual_dev_list);
998 static struct usb_driver sddr55_driver = {
999 .name =
"ums-sddr55",
1000 .probe = sddr55_probe,
1007 .id_table = sddr55_usb_ids,