Lines Matching +full:0 +full:- +full:9 +full:a +full:- +full:d

1 // SPDX-License-Identifier: GPL-2.0+
3 * Driver for SanDisk SDDR-09 SmartMedia reader
10 * The SanDisk SDDR-09 SmartMedia reader uses the Shuttle EUSB-01 chip.
11 * This chip is a programmable USB controller. In the SDDR-09, it has
12 * been programmed to obey a certain limited set of SCSI commands.
13 * This driver translates the "real" SCSI commands to the SDDR-09 SCSI
45 #define DRV_NAME "ums-sddr09"
47 MODULE_DESCRIPTION("Driver for SanDisk SDDR-09 SmartMedia reader");
97 #define LSB_of(s) ((s)&0xFF)
110 char pageshift; /* 1<<ps bytes in a page */
112 char zoneshift; /* 1<<zs blocks in a zone */
114 char pageadrlen; /* length of an address in bytes - 1 */
120 #define NAND_MFR_AMD 0x01
121 #define NAND_MFR_NATSEMI 0x8f
122 #define NAND_MFR_TOSHIBA 0x98
123 #define NAND_MFR_SAMSUNG 0xec
142 * remaining data: SSFDC prescribes manufacturer-independent id codes.
144 * 256 MB NAND flash has a 5-byte ID with 2nd byte 0xaa, 0xba, 0xca or 0xda.
149 { 0x6e, 20, 8, 4, 8, 2}, /* 1 MB */
150 { 0xe8, 20, 8, 4, 8, 2}, /* 1 MB */
151 { 0xec, 20, 8, 4, 8, 2}, /* 1 MB */
152 { 0x64, 21, 8, 4, 9, 2}, /* 2 MB */
153 { 0xea, 21, 8, 4, 9, 2}, /* 2 MB */
154 { 0x6b, 22, 9, 4, 9, 2}, /* 4 MB */
155 { 0xe3, 22, 9, 4, 9, 2}, /* 4 MB */
156 { 0xe5, 22, 9, 4, 9, 2}, /* 4 MB */
157 { 0xe6, 23, 9, 4, 10, 2}, /* 8 MB */
158 { 0x73, 24, 9, 5, 10, 2}, /* 16 MB */
159 { 0x75, 25, 9, 5, 10, 2}, /* 32 MB */
160 { 0x76, 26, 9, 5, 10, 3}, /* 64 MB */
161 { 0x79, 27, 9, 5, 10, 3}, /* 128 MB */
164 { 0x5d, 21, 9, 4, 8, 2}, /* 2 MB */
165 { 0xd5, 22, 9, 4, 9, 2}, /* 4 MB */
166 { 0xd6, 23, 9, 4, 10, 2}, /* 8 MB */
167 { 0x57, 24, 9, 4, 11, 2}, /* 16 MB */
168 { 0x58, 25, 9, 4, 12, 2}, /* 32 MB */
169 { 0,}
176 for (i = 0; i < ARRAY_SIZE(nand_flash_ids); i++) in nand_find_id()
189 int i, j, a; in nand_init_ecc() local
191 parity[0] = 0; in nand_init_ecc()
193 parity[i] = (parity[i&(i-1)] ^ 1); in nand_init_ecc()
195 for (i = 0; i < 256; i++) { in nand_init_ecc()
196 a = 0; in nand_init_ecc()
197 for (j = 0; j < 8; j++) { in nand_init_ecc()
199 if ((j & 1) == 0) in nand_init_ecc()
200 a ^= 0x04; in nand_init_ecc()
201 if ((j & 2) == 0) in nand_init_ecc()
202 a ^= 0x10; in nand_init_ecc()
203 if ((j & 4) == 0) in nand_init_ecc()
204 a ^= 0x40; in nand_init_ecc()
207 ecc2[i] = ~(a ^ (a<<1) ^ (parity[i] ? 0xa8 : 0)); in nand_init_ecc()
211 /* compute 3-byte ecc on 256 bytes */
213 int i, j, a; in nand_compute_ecc() local
214 unsigned char par = 0, bit, bits[8] = {0}; in nand_compute_ecc()
217 for (i = 0; i < 256; i++) { in nand_compute_ecc()
220 for (j = 0; j < 8; j++) in nand_compute_ecc()
221 if ((i & (1<<j)) == 0) in nand_compute_ecc()
226 a = (bits[3] << 6) + (bits[2] << 4) + (bits[1] << 2) + bits[0]; in nand_compute_ecc()
227 ecc[0] = ~(a ^ (a<<1) ^ (parity[par] ? 0xaa : 0)); in nand_compute_ecc()
229 a = (bits[7] << 6) + (bits[6] << 4) + (bits[5] << 2) + bits[4]; in nand_compute_ecc()
230 ecc[1] = ~(a ^ (a<<1) ^ (parity[par] ? 0xaa : 0)); in nand_compute_ecc()
236 return (data[0] == ecc[0] && data[1] == ecc[1] && data[2] == ecc[2]); in nand_compare_ecc()
253 int blockmask; /* 2^blockshift - 1 */
265 * depend on the card. For now a constant.
271 * (and things fail with LUN 0).
280 #define UNDEF 0xffffffff
281 #define SPARE 0xfffffffe
282 #define UNUSABLE 0xfffffffd
284 static const int erase_bad_lba_entries = 0;
286 /* send vendor interface command (0x41) */
287 /* called for requests 0, 1, 8 */
295 unsigned char requesttype = (0x41 | direction); in sddr09_send_command()
301 pipe = us->recv_ctrl_pipe; in sddr09_send_command()
303 pipe = us->send_ctrl_pipe; in sddr09_send_command()
306 0, 0, xfer_data, xfer_len); in sddr09_send_command()
308 case USB_STOR_XFER_GOOD: return 0; in sddr09_send_command()
309 case USB_STOR_XFER_STALLED: return -EPIPE; in sddr09_send_command()
310 default: return -EIO; in sddr09_send_command()
318 return sddr09_send_command(us, 0, USB_DIR_OUT, command, command_len); in sddr09_send_scsi_command()
321 #if 0
324 * byte 0: opcode: 00
328 unsigned char *command = us->iobuf;
331 memset(command, 0, 6);
336 usb_stor_dbg(us, "sddr09_test_unit_ready returns %d\n", result);
344 * byte 0: opcode: 03
349 unsigned char *command = us->iobuf; in sddr09_request_sense()
352 memset(command, 0, 12); in sddr09_request_sense()
353 command[0] = 0x03; in sddr09_request_sense()
361 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, in sddr09_request_sense()
363 return (result == USB_STOR_XFER_GOOD ? 0 : -EIO); in sddr09_request_sense()
368 * byte 0: opcode: E8
372 * bytes 2-5: address (interpretation depends on byte 1, see below)
373 * bytes 10-11: count (idem)
375 * A page has 512 data bytes and 64 control bytes (16 control and 48 junk).
376 * A read data command gets data in 512-byte pages.
377 * A read control command gets control in 64-byte chunks.
378 * A read both command gets data+control in 576-byte chunks.
382 * reading a group of 64 control bytes.
385 * (1 MB and 2 MB cards are a bit different, but I have only a 16 MB card.)
393 unsigned char *command = us->iobuf; in sddr09_readX()
396 command[0] = 0xE8; in sddr09_readX()
400 command[4] = MSB_of(fromaddress & 0xFFFF); in sddr09_readX()
401 command[5] = LSB_of(fromaddress & 0xFFFF); in sddr09_readX()
402 command[6] = 0; in sddr09_readX()
403 command[7] = 0; in sddr09_readX()
404 command[8] = 0; in sddr09_readX()
405 command[9] = 0; in sddr09_readX()
412 usb_stor_dbg(us, "Result for send_control in sddr09_read2%d %d\n", in sddr09_readX()
417 result = usb_stor_bulk_transfer_sg(us, us->recv_bulk_pipe, in sddr09_readX()
421 usb_stor_dbg(us, "Result for bulk_transfer in sddr09_read2%d %d\n", in sddr09_readX()
423 return -EIO; in sddr09_readX()
425 return 0; in sddr09_readX()
443 return sddr09_readX(us, 0, fromaddress, nr_of_pages, bulklen, in sddr09_read20()
483 usb_stor_dbg(us, "reading %d pages, %d bytes\n", nr_of_pages, bulklen); in sddr09_read22()
488 #if 0
514 * byte 0: opcode: EA
515 * bytes 6-9: erase address (big-endian, counting shorts, sector aligned).
517 * Always precisely one block is erased; bytes 2-5 and 10-11 are ignored.
523 unsigned char *command = us->iobuf; in sddr09_erase()
528 memset(command, 0, 12); in sddr09_erase()
529 command[0] = 0xEA; in sddr09_erase()
533 command[8] = MSB_of(Eaddress & 0xFFFF); in sddr09_erase()
534 command[9] = LSB_of(Eaddress & 0xFFFF); in sddr09_erase()
539 usb_stor_dbg(us, "Result for send_control in sddr09_erase %d\n", in sddr09_erase()
547 * byte 0: opcode: EE
548 * bytes 2-5: write address in shorts
549 * bytes 10-11: sector count
561 * byte 0: opcode: E9
562 * bytes 2-5: write address (big-endian, counting shorts, sector aligned).
563 * bytes 6-9: erase address (big-endian, counting shorts, sector aligned).
564 * bytes 10-11: sector count (big-endian, in 512-byte sectors).
575 unsigned char *command = us->iobuf; in sddr09_writeX()
578 command[0] = 0xE9; in sddr09_writeX()
583 command[4] = MSB_of(Waddress & 0xFFFF); in sddr09_writeX()
584 command[5] = LSB_of(Waddress & 0xFFFF); in sddr09_writeX()
588 command[8] = MSB_of(Eaddress & 0xFFFF); in sddr09_writeX()
589 command[9] = LSB_of(Eaddress & 0xFFFF); in sddr09_writeX()
597 usb_stor_dbg(us, "Result for send_control in sddr09_writeX %d\n", in sddr09_writeX()
602 result = usb_stor_bulk_transfer_sg(us, us->send_bulk_pipe, in sddr09_writeX()
606 usb_stor_dbg(us, "Result for bulk_transfer in sddr09_writeX %d\n", in sddr09_writeX()
608 return -EIO; in sddr09_writeX()
610 return 0; in sddr09_writeX()
623 #if 0
626 * byte 0: opcode E7
628 * bytes 4i-1,4i,4i+1: page address
632 * This reads several pages from the card to a single memory buffer.
637 unsigned char *command = us->iobuf;
642 nsg = bulklen = 0;
643 command[0] = 0xE7;
645 command[2] = 0;
648 bulklen += (ct << 9);
650 command[4*nsg+1] = ((address >> 9) & 0xFF);
651 command[4*nsg+0] = ((address >> 17) & 0xFF);
652 command[4*nsg-1] = ((address >> 25) & 0xFF);
656 bulklen += (ct << 9);
658 command[4*nsg+1] = ((address >> 9) & 0xFF);
659 command[4*nsg+0] = ((address >> 17) & 0xFF);
660 command[4*nsg-1] = ((address >> 25) & 0xFF);
664 bulklen += (ct << 9);
666 command[4*nsg+1] = ((address >> 9) & 0xFF);
667 command[4*nsg+0] = ((address >> 17) & 0xFF);
668 command[4*nsg-1] = ((address >> 25) & 0xFF);
675 usb_stor_dbg(us, "Result for send_control in sddr09_read_sg %d\n",
682 return -ENOMEM;
684 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
688 usb_stor_dbg(us, "Result for bulk_transfer in sddr09_read_sg %d\n",
690 return -EIO;
693 return 0;
699 * byte 0: opcode: EC
702 * bit 0: 1: Error
705 * bit 7: 1: Not write-protected
711 unsigned char *command = us->iobuf; in sddr09_read_status()
712 unsigned char *data = us->iobuf; in sddr09_read_status()
717 memset(command, 0, 12); in sddr09_read_status()
718 command[0] = 0xEC; in sddr09_read_status()
725 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, in sddr09_read_status()
727 *status = data[0]; in sddr09_read_status()
728 return (result == USB_STOR_XFER_GOOD ? 0 : -EIO); in sddr09_read_status()
736 struct sddr09_card_info *info = (struct sddr09_card_info *) us->extra; in sddr09_read_data()
745 lba = address >> info->blockshift; in sddr09_read_data()
746 page = (address & info->blockmask); in sddr09_read_data()
747 maxlba = info->capacity >> (info->pageshift + info->blockshift); in sddr09_read_data()
749 return -EIO; in sddr09_read_data()
751 // Since we only read in one block at a time, we have to create in sddr09_read_data()
752 // a bounce buffer and move the data a piece at a time between the in sddr09_read_data()
755 len = min(sectors, (unsigned int) info->blocksize) * info->pagesize; in sddr09_read_data()
758 return -ENOMEM; in sddr09_read_data()
763 result = 0; in sddr09_read_data()
764 offset = 0; in sddr09_read_data()
767 while (sectors > 0) { in sddr09_read_data()
770 pages = min(sectors, info->blocksize - page); in sddr09_read_data()
771 len = pages << info->pageshift; in sddr09_read_data()
777 result = -EIO; in sddr09_read_data()
782 pba = info->lba_to_pba[lba]; in sddr09_read_data()
786 usb_stor_dbg(us, "Read %d zero pages (LBA %d) page %d\n", in sddr09_read_data()
796 memset(buffer, 0, len); in sddr09_read_data()
799 usb_stor_dbg(us, "Read %d pages, from PBA %d (LBA %d) page %d\n", in sddr09_read_data()
802 address = ((pba << info->blockshift) + page) << in sddr09_read_data()
803 info->pageshift; in sddr09_read_data()
806 pages, info->pageshift, buffer, 0); in sddr09_read_data()
812 usb_stor_access_xfer_buf(buffer, len, us->srb, in sddr09_read_data()
815 page = 0; in sddr09_read_data()
817 sectors -= pages; in sddr09_read_data()
830 end = info->capacity >> (info->blockshift + info->pageshift); in sddr09_find_unused_pba()
831 end -= zonestart; in sddr09_find_unused_pba()
836 if (info->pba_to_lba[zonestart+i] == UNDEF) { in sddr09_find_unused_pba()
841 for (i = 0; i <= lastpba; i++) { in sddr09_find_unused_pba()
842 if (info->pba_to_lba[zonestart+i] == UNDEF) { in sddr09_find_unused_pba()
847 return 0; in sddr09_find_unused_pba()
855 struct sddr09_card_info *info = (struct sddr09_card_info *) us->extra; in sddr09_write_lba()
863 lbap = ((lba % 1000) << 1) | 0x1000; in sddr09_write_lba()
866 pba = info->lba_to_pba[lba]; in sddr09_write_lba()
873 return -ENOSPC; in sddr09_write_lba()
875 info->pba_to_lba[pba] = lba; in sddr09_write_lba()
876 info->lba_to_pba[lba] = pba; in sddr09_write_lba()
885 return 0; in sddr09_write_lba()
888 pagelen = (1 << info->pageshift) + (1 << CONTROL_SHIFT); in sddr09_write_lba()
891 address = (pba << (info->pageshift + info->blockshift)); in sddr09_write_lba()
892 result = sddr09_read22(us, address>>1, info->blocksize, in sddr09_write_lba()
893 info->pageshift, blockbuffer, 0); in sddr09_write_lba()
898 for (i = 0; i < info->blocksize; i++) { in sddr09_write_lba()
900 cptr = bptr + info->pagesize; in sddr09_write_lba()
903 usb_stor_dbg(us, "Warning: bad ecc in page %d- of pba %d\n", in sddr09_write_lba()
907 nand_compute_ecc(bptr+(info->pagesize / 2), ecc); in sddr09_write_lba()
909 usb_stor_dbg(us, "Warning: bad ecc in page %d+ of pba %d\n", in sddr09_write_lba()
921 cptr = bptr + info->pagesize; in sddr09_write_lba()
922 memcpy(bptr, xptr, info->pagesize); in sddr09_write_lba()
923 xptr += info->pagesize; in sddr09_write_lba()
926 nand_compute_ecc(bptr+(info->pagesize / 2), ecc); in sddr09_write_lba()
930 usb_stor_dbg(us, "Rewrite PBA %d (LBA %d)\n", pba, lba); in sddr09_write_lba()
932 result = sddr09_write_inplace(us, address>>1, info->blocksize, in sddr09_write_lba()
933 info->pageshift, blockbuffer, 0); in sddr09_write_lba()
935 usb_stor_dbg(us, "sddr09_write_inplace returns %d\n", result); in sddr09_write_lba()
937 #if 0 in sddr09_write_lba()
939 unsigned char status = 0; in sddr09_write_lba()
943 else if (status != 0xc0) in sddr09_write_lba()
944 usb_stor_dbg(us, "status after write: 0x%x\n", status); in sddr09_write_lba()
948 #if 0 in sddr09_write_lba()
962 struct sddr09_card_info *info = (struct sddr09_card_info *) us->extra; in sddr09_write_data()
972 lba = address >> info->blockshift; in sddr09_write_data()
973 page = (address & info->blockmask); in sddr09_write_data()
974 maxlba = info->capacity >> (info->pageshift + info->blockshift); in sddr09_write_data()
976 return -EIO; in sddr09_write_data()
985 * add a bufferpointer to the info structure in sddr09_write_data()
988 pagelen = (1 << info->pageshift) + (1 << CONTROL_SHIFT); in sddr09_write_data()
989 blocklen = (pagelen << info->blockshift); in sddr09_write_data()
992 return -ENOMEM; in sddr09_write_data()
996 * we have to create a bounce buffer and move the data a piece in sddr09_write_data()
997 * at a time between the bounce buffer and the actual transfer buffer. in sddr09_write_data()
1000 len = min(sectors, (unsigned int) info->blocksize) * info->pagesize; in sddr09_write_data()
1004 return -ENOMEM; in sddr09_write_data()
1007 result = 0; in sddr09_write_data()
1008 offset = 0; in sddr09_write_data()
1011 while (sectors > 0) { in sddr09_write_data()
1015 pages = min(sectors, info->blocksize - page); in sddr09_write_data()
1016 len = (pages << info->pageshift); in sddr09_write_data()
1022 result = -EIO; in sddr09_write_data()
1027 usb_stor_access_xfer_buf(buffer, len, us->srb, in sddr09_write_data()
1035 page = 0; in sddr09_write_data()
1037 sectors -= pages; in sddr09_write_data()
1053 usb_stor_dbg(us, "Read control address %lu, blocks %d\n", in sddr09_read_control()
1062 * byte 0: opcode: ED
1066 * signifying that the secret command to read an 128-bit ID is available.
1068 * a second read ID cmd is available.
1072 unsigned char *command = us->iobuf; in sddr09_read_deviceID()
1073 unsigned char *content = us->iobuf; in sddr09_read_deviceID()
1076 memset(command, 0, 12); in sddr09_read_deviceID()
1077 command[0] = 0xED; in sddr09_read_deviceID()
1084 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, in sddr09_read_deviceID()
1087 for (i = 0; i < 4; i++) in sddr09_read_deviceID()
1090 return (result == USB_STOR_XFER_GOOD ? 0 : -EIO); in sddr09_read_deviceID()
1104 if ((status & 0x80) == 0) { in sddr09_get_wp()
1105 info->flags |= SDDR09_WP; /* write protected */ in sddr09_get_wp()
1110 usb_stor_dbg(us, "status 0x%02X%s%s%s%s\n", status, wp_fmt, in sddr09_get_wp()
1111 status & 0x40 ? " Ready" : "", in sddr09_get_wp()
1113 status & 0x01 ? " Error" : ""); in sddr09_get_wp()
1115 return 0; in sddr09_get_wp()
1118 #if 0
1121 * byte 0: opcode: EB
1126 unsigned char *command = us->iobuf;
1128 memset(command, 0, 12);
1129 command[0] = 0xEB;
1148 usb_stor_dbg(us, "Result of read_deviceID is %d\n", result); in sddr09_get_cardinfo()
1155 /* Byte 0 is the manufacturer */ in sddr09_get_cardinfo()
1158 nand_flash_manufacturer(deviceID[0])); in sddr09_get_cardinfo()
1164 * MB or MiB? It is neither. A 16 MB card has in sddr09_get_cardinfo()
1169 ", %d MB", 1<<(cardinfo->chipshift - 20)); in sddr09_get_cardinfo()
1175 /* Byte 2 is code to signal availability of 128-bit ID */ in sddr09_get_cardinfo()
1176 if (deviceID[2] == 0xa5) { in sddr09_get_cardinfo()
1178 ", 128-bit ID"); in sddr09_get_cardinfo()
1182 if (deviceID[3] == 0xc0) { in sddr09_get_cardinfo()
1199 struct sddr09_card_info *info = (struct sddr09_card_info *) us->extra; in sddr09_read_map()
1205 if (!info->capacity) in sddr09_read_map()
1206 return -1; in sddr09_read_map()
1209 * size of a block is 1 << (blockshift + pageshift) bytes in sddr09_read_map()
1213 numblocks = info->capacity >> (info->blockshift + info->pageshift); in sddr09_read_map()
1217 * but only use a 64 KB buffer in sddr09_read_map()
1218 * buffer size used must be a multiple of (1 << CONTROL_SHIFT) in sddr09_read_map()
1226 result = -1; in sddr09_read_map()
1233 kfree(info->lba_to_pba); in sddr09_read_map()
1234 kfree(info->pba_to_lba); in sddr09_read_map()
1235 info->lba_to_pba = kmalloc_array(numblocks, sizeof(int), GFP_NOIO); in sddr09_read_map()
1236 info->pba_to_lba = kmalloc_array(numblocks, sizeof(int), GFP_NOIO); in sddr09_read_map()
1238 if (info->lba_to_pba == NULL || info->pba_to_lba == NULL) { in sddr09_read_map()
1240 result = -1; in sddr09_read_map()
1244 for (i = 0; i < numblocks; i++) in sddr09_read_map()
1245 info->lba_to_pba[i] = info->pba_to_lba[i] = UNDEF; in sddr09_read_map()
1248 * Define lba-pba translation table in sddr09_read_map()
1252 for (i = 0; i < numblocks; i++) { in sddr09_read_map()
1257 address = i << (info->pageshift + info->blockshift); in sddr09_read_map()
1260 min(alloc_blocks, numblocks - i), in sddr09_read_map()
1261 buffer, 0); in sddr09_read_map()
1263 result = -1; in sddr09_read_map()
1269 if (i == 0 || i == 1) { in sddr09_read_map()
1270 info->pba_to_lba[i] = UNUSABLE; in sddr09_read_map()
1274 /* special PBAs have control field 0^16 */ in sddr09_read_map()
1275 for (j = 0; j < 16; j++) in sddr09_read_map()
1276 if (ptr[j] != 0) in sddr09_read_map()
1278 info->pba_to_lba[i] = UNUSABLE; in sddr09_read_map()
1279 printk(KERN_WARNING "sddr09: PBA %d has no logical mapping\n", in sddr09_read_map()
1285 for (j = 0; j < 16; j++) in sddr09_read_map()
1286 if (ptr[j] != 0xff) in sddr09_read_map()
1294 "sddr09: PBA %d has no logical mapping: " in sddr09_read_map()
1297 i, ptr[0], ptr[1], ptr[2], ptr[3], in sddr09_read_map()
1299 info->pba_to_lba[i] = UNUSABLE; in sddr09_read_map()
1303 if ((ptr[6] >> 4) != 0x01) { in sddr09_read_map()
1305 "sddr09: PBA %d has invalid address field " in sddr09_read_map()
1308 info->pba_to_lba[i] = UNUSABLE; in sddr09_read_map()
1315 "sddr09: Bad parity in LBA for block %d" in sddr09_read_map()
1317 info->pba_to_lba[i] = UNUSABLE; in sddr09_read_map()
1322 lba = (lba & 0x07FF) >> 1; in sddr09_read_map()
1326 * go back to zero, but are within a higher block of LBA's. in sddr09_read_map()
1327 * Also, there is a maximum of 1000 LBA's per zone. in sddr09_read_map()
1328 * In other words, in PBA 1024-2047 you will find LBA 0-999 in sddr09_read_map()
1329 * which are really LBA 1000-1999. This allows for 24 bad in sddr09_read_map()
1335 "sddr09: Bad low LBA %d for block %d\n", in sddr09_read_map()
1340 lba += 1000*(i/0x400); in sddr09_read_map()
1342 if (info->lba_to_pba[lba] != UNDEF) { in sddr09_read_map()
1344 "sddr09: LBA %d seen for PBA %d and %d\n", in sddr09_read_map()
1345 lba, info->lba_to_pba[lba], i); in sddr09_read_map()
1349 info->pba_to_lba[i] = lba; in sddr09_read_map()
1350 info->lba_to_pba[lba] = i; in sddr09_read_map()
1357 address = (i << (info->pageshift + info->blockshift)); in sddr09_read_map()
1359 info->pba_to_lba[i] = UNDEF; in sddr09_read_map()
1361 info->pba_to_lba[i] = UNUSABLE; in sddr09_read_map()
1366 * since a zone with less than 1000 usable pages leads to in sddr09_read_map()
1370 lbact = 0; in sddr09_read_map()
1371 for (i = 0; i < numblocks; i += 1024) { in sddr09_read_map()
1372 int ct = 0; in sddr09_read_map()
1374 for (j = 0; j < 1024 && i+j < numblocks; j++) { in sddr09_read_map()
1375 if (info->pba_to_lba[i+j] != UNUSABLE) { in sddr09_read_map()
1377 info->pba_to_lba[i+j] = SPARE; in sddr09_read_map()
1384 info->lbact = lbact; in sddr09_read_map()
1385 usb_stor_dbg(us, "Found %d LBA's\n", lbact); in sddr09_read_map()
1386 result = 0; in sddr09_read_map()
1389 if (result != 0) { in sddr09_read_map()
1390 kfree(info->lba_to_pba); in sddr09_read_map()
1391 kfree(info->pba_to_lba); in sddr09_read_map()
1392 info->lba_to_pba = NULL; in sddr09_read_map()
1393 info->pba_to_lba = NULL; in sddr09_read_map()
1406 kfree(info->lba_to_pba); in sddr09_card_info_destructor()
1407 kfree(info->pba_to_lba); in sddr09_card_info_destructor()
1414 /* set the configuration -- STALL is an acceptable response here */ in sddr09_common_init()
1415 if (us->pusb_dev->actconfig->desc.bConfigurationValue != 1) { in sddr09_common_init()
1416 usb_stor_dbg(us, "active config #%d != 1 ??\n", in sddr09_common_init()
1417 us->pusb_dev->actconfig->desc.bConfigurationValue); in sddr09_common_init()
1418 return -EINVAL; in sddr09_common_init()
1421 result = usb_reset_configuration(us->pusb_dev); in sddr09_common_init()
1422 usb_stor_dbg(us, "Result of usb_reset_configuration is %d\n", result); in sddr09_common_init()
1423 if (result == -EPIPE) { in sddr09_common_init()
1424 usb_stor_dbg(us, "-- stall on control interface\n"); in sddr09_common_init()
1425 } else if (result != 0) { in sddr09_common_init()
1426 /* it's not a stall, but another error -- time to bail */ in sddr09_common_init()
1427 usb_stor_dbg(us, "-- Unknown error. Rejecting device\n"); in sddr09_common_init()
1428 return -EINVAL; in sddr09_common_init()
1431 us->extra = kzalloc(sizeof(struct sddr09_card_info), GFP_NOIO); in sddr09_common_init()
1432 if (!us->extra) in sddr09_common_init()
1433 return -ENOMEM; in sddr09_common_init()
1434 us->extra_destructor = sddr09_card_info_destructor; in sddr09_common_init()
1437 return 0; in sddr09_common_init()
1442 * This is needed at a very early stage. If this is not listed in the
1443 * unusual devices list but called from here then LUN 0 of the combo reader
1449 unsigned char *data = us->iobuf; in usb_stor_sddr09_dpcm_init()
1455 result = sddr09_send_command(us, 0x01, USB_DIR_IN, data, 2); in usb_stor_sddr09_dpcm_init()
1461 usb_stor_dbg(us, "%02X %02X\n", data[0], data[1]); in usb_stor_sddr09_dpcm_init()
1464 result = sddr09_send_command(us, 0x08, USB_DIR_IN, data, 2); in usb_stor_sddr09_dpcm_init()
1470 usb_stor_dbg(us, "%02X %02X\n", data[0], data[1]); in usb_stor_sddr09_dpcm_init()
1474 if (result == 0 && data[2] != 0) { in usb_stor_sddr09_dpcm_init()
1476 for (j=0; j<18; j++) in usb_stor_sddr09_dpcm_init()
1481 // sense key 0, sense code 0, extd sense code 0 in usb_stor_sddr09_dpcm_init()
1482 // additional transfer length * = sizeof(data) - 7 in usb_stor_sddr09_dpcm_init()
1483 // Or: 70 00 06 00 00 00 00 0b 00 00 00 00 28 00 00 00 00 00 in usb_stor_sddr09_dpcm_init()
1490 return 0; /* not result */ in usb_stor_sddr09_dpcm_init()
1494 * Transport for the Microtech DPCM-USB
1500 usb_stor_dbg(us, "LUN=%d\n", (u8)srb->device->lun); in dpcm_transport()
1502 switch (srb->device->lun) { in dpcm_transport()
1503 case 0: in dpcm_transport()
1506 * LUN 0 corresponds to the CompactFlash card reader. in dpcm_transport()
1518 * Set the LUN to 0 (just in case). in dpcm_transport()
1520 srb->device->lun = 0; in dpcm_transport()
1522 srb->device->lun = 1; in dpcm_transport()
1526 usb_stor_dbg(us, "Invalid LUN %d\n", (u8)srb->device->lun); in dpcm_transport()
1535 * Transport for the Sandisk SDDR-09
1539 static unsigned char sensekey = 0, sensecode = 0; in sddr09_transport()
1540 static unsigned char havefakesense = 0; in sddr09_transport()
1542 unsigned char *ptr = us->iobuf; in sddr09_transport()
1549 0x00, 0x80, 0x00, 0x02, 0x1F, 0x00, 0x00, 0x00 in sddr09_transport()
1554 0x00, 0x0F, 0x00, 0x0, 0x0, 0x0, 0x00, in sddr09_transport()
1555 0x01, 0x0A, in sddr09_transport()
1556 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 in sddr09_transport()
1559 info = (struct sddr09_card_info *)us->extra; in sddr09_transport()
1561 if (srb->cmnd[0] == REQUEST_SENSE && havefakesense) { in sddr09_transport()
1562 /* for a faked command, we have to follow with a faked sense */ in sddr09_transport()
1563 memset(ptr, 0, 18); in sddr09_transport()
1564 ptr[0] = 0x70; in sddr09_transport()
1569 sensekey = sensecode = havefakesense = 0; in sddr09_transport()
1576 * Dummy up a response for INQUIRY since SDDR09 doesn't in sddr09_transport()
1580 if (srb->cmnd[0] == INQUIRY) { in sddr09_transport()
1586 if (srb->cmnd[0] == READ_CAPACITY) { in sddr09_transport()
1591 cardinfo = sddr09_get_cardinfo(us, info->flags); in sddr09_transport()
1595 sensekey = 0x02; /* not ready */ in sddr09_transport()
1596 sensecode = 0x3a; /* medium not present */ in sddr09_transport()
1600 info->capacity = (1 << cardinfo->chipshift); in sddr09_transport()
1601 info->pageshift = cardinfo->pageshift; in sddr09_transport()
1602 info->pagesize = (1 << info->pageshift); in sddr09_transport()
1603 info->blockshift = cardinfo->blockshift; in sddr09_transport()
1604 info->blocksize = (1 << info->blockshift); in sddr09_transport()
1605 info->blockmask = info->blocksize - 1; in sddr09_transport()
1615 capacity = (info->lbact << info->blockshift) - 1; in sddr09_transport()
1617 ((__be32 *) ptr)[0] = cpu_to_be32(capacity); in sddr09_transport()
1621 ((__be32 *) ptr)[1] = cpu_to_be32(info->pagesize); in sddr09_transport()
1627 if (srb->cmnd[0] == MODE_SENSE_10) { in sddr09_transport()
1628 int modepage = (srb->cmnd[2] & 0x3F); in sddr09_transport()
1635 if (modepage == 0x01 || modepage == 0x3F) { in sddr09_transport()
1636 usb_stor_dbg(us, "Dummy up request for mode page 0x%x\n", in sddr09_transport()
1640 ((__be16*)ptr)[0] = cpu_to_be16(sizeof(mode_page_01) - 2); in sddr09_transport()
1641 ptr[3] = (info->flags & SDDR09_WP) ? 0x80 : 0; in sddr09_transport()
1646 sensekey = 0x05; /* illegal request */ in sddr09_transport()
1647 sensecode = 0x24; /* invalid field in CDB */ in sddr09_transport()
1651 if (srb->cmnd[0] == ALLOW_MEDIUM_REMOVAL) in sddr09_transport()
1654 havefakesense = 0; in sddr09_transport()
1656 if (srb->cmnd[0] == READ_10) { in sddr09_transport()
1658 page = short_pack(srb->cmnd[3], srb->cmnd[2]); in sddr09_transport()
1660 page |= short_pack(srb->cmnd[5], srb->cmnd[4]); in sddr09_transport()
1661 pages = short_pack(srb->cmnd[8], srb->cmnd[7]); in sddr09_transport()
1663 usb_stor_dbg(us, "READ_10: read page %d pagect %d\n", in sddr09_transport()
1667 return (result == 0 ? USB_STOR_TRANSPORT_GOOD : in sddr09_transport()
1671 if (srb->cmnd[0] == WRITE_10) { in sddr09_transport()
1673 page = short_pack(srb->cmnd[3], srb->cmnd[2]); in sddr09_transport()
1675 page |= short_pack(srb->cmnd[5], srb->cmnd[4]); in sddr09_transport()
1676 pages = short_pack(srb->cmnd[8], srb->cmnd[7]); in sddr09_transport()
1678 usb_stor_dbg(us, "WRITE_10: write page %d pagect %d\n", in sddr09_transport()
1682 return (result == 0 ? USB_STOR_TRANSPORT_GOOD : in sddr09_transport()
1687 * catch-all for all other commands, except in sddr09_transport()
1690 if (srb->cmnd[0] != TEST_UNIT_READY && in sddr09_transport()
1691 srb->cmnd[0] != REQUEST_SENSE) { in sddr09_transport()
1692 sensekey = 0x05; /* illegal request */ in sddr09_transport()
1693 sensecode = 0x20; /* invalid command */ in sddr09_transport()
1698 for (; srb->cmd_len<12; srb->cmd_len++) in sddr09_transport()
1699 srb->cmnd[srb->cmd_len] = 0; in sddr09_transport()
1701 srb->cmnd[1] = LUNBITS; in sddr09_transport()
1703 ptr[0] = 0; in sddr09_transport()
1704 for (i=0; i<12; i++) in sddr09_transport()
1705 sprintf(ptr+strlen(ptr), "%02X ", srb->cmnd[i]); in sddr09_transport()
1709 result = sddr09_send_scsi_command(us, srb->cmnd, 12); in sddr09_transport()
1711 usb_stor_dbg(us, "sddr09_send_scsi_command returns %d\n", in sddr09_transport()
1716 if (scsi_bufflen(srb) == 0) in sddr09_transport()
1719 if (srb->sc_data_direction == DMA_TO_DEVICE || in sddr09_transport()
1720 srb->sc_data_direction == DMA_FROM_DEVICE) { in sddr09_transport()
1721 unsigned int pipe = (srb->sc_data_direction == DMA_TO_DEVICE) in sddr09_transport()
1722 ? us->send_bulk_pipe : us->recv_bulk_pipe; in sddr09_transport()
1724 usb_stor_dbg(us, "%s %d bytes\n", in sddr09_transport()
1725 (srb->sc_data_direction == DMA_TO_DEVICE) ? in sddr09_transport()
1755 (id - sddr09_usb_ids) + sddr09_unusual_dev_list, in sddr09_probe()
1760 if (us->protocol == USB_PR_DPCM_USB) { in sddr09_probe()
1761 us->transport_name = "Control/Bulk-EUSB/SDDR09"; in sddr09_probe()
1762 us->transport = dpcm_transport; in sddr09_probe()
1763 us->transport_reset = usb_stor_CB_reset; in sddr09_probe()
1764 us->max_lun = 1; in sddr09_probe()
1766 us->transport_name = "EUSB/SDDR09"; in sddr09_probe()
1767 us->transport = sddr09_transport; in sddr09_probe()
1768 us->transport_reset = usb_stor_CB_reset; in sddr09_probe()
1769 us->max_lun = 0; in sddr09_probe()