Lines Matching +full:1 +full:- +full:9 +full:a +full:- +full:d
1 // SPDX-License-Identifier: GPL-2.0+
3 * Driver for Alauda-based card readers
8 * The 'Alauda' is a chip manufacturered by RATOC for OEM use.
10 * Alauda implements a vendor-specific command set to access two media reader
14 * The driver was developed through reverse-engineering, with the help of the
16 * (very old) vendor-supplied GPL sma03 driver.
34 #define DRV_NAME "ums-alauda"
36 MODULE_DESCRIPTION("Driver for Alauda-based card readers");
63 * Bulk opcodes (byte 1)
114 #define MEDIA_PORT(us) us->srb->device->lun
115 #define MEDIA_INFO(us) ((struct alauda_info *)us->extra)->port[MEDIA_PORT(us)]
169 unsigned char chipshift; /* 1<<cs bytes total capacity */
170 unsigned char pageshift; /* 1<<ps bytes in a page */
171 unsigned char blockshift; /* 1<<bs pages per block */
172 unsigned char zoneshift; /* 1<<zs blocks per zone */
177 { 0x6e, 20, 8, 4, 8}, /* 1 MB */
178 { 0xe8, 20, 8, 4, 8}, /* 1 MB */
179 { 0xec, 20, 8, 4, 8}, /* 1 MB */
180 { 0x64, 21, 8, 4, 9}, /* 2 MB */
181 { 0xea, 21, 8, 4, 9}, /* 2 MB */
182 { 0x6b, 22, 9, 4, 9}, /* 4 MB */
183 { 0xe3, 22, 9, 4, 9}, /* 4 MB */
184 { 0xe5, 22, 9, 4, 9}, /* 4 MB */
185 { 0xe6, 23, 9, 4, 10}, /* 8 MB */
186 { 0x73, 24, 9, 5, 10}, /* 16 MB */
187 { 0x75, 25, 9, 5, 10}, /* 32 MB */
188 { 0x76, 26, 9, 5, 10}, /* 64 MB */
189 { 0x79, 27, 9, 5, 10}, /* 128 MB */
190 { 0x71, 28, 9, 5, 10}, /* 256 MB */
193 { 0x5d, 21, 9, 4, 8}, /* 2 MB */
194 { 0xd5, 22, 9, 4, 9}, /* 4 MB */
195 { 0xd6, 23, 9, 4, 10}, /* 8 MB */
196 { 0x57, 24, 9, 4, 11}, /* 16 MB */
197 { 0x58, 25, 9, 4, 12}, /* 32 MB */
220 int i, j, a; in nand_init_ecc() local
223 for (i = 1; i < 256; i++) in nand_init_ecc()
224 parity[i] = (parity[i&(i-1)] ^ 1); in nand_init_ecc()
227 a = 0; in nand_init_ecc()
229 if (i & (1<<j)) { in nand_init_ecc()
230 if ((j & 1) == 0) in nand_init_ecc()
231 a ^= 0x04; in nand_init_ecc()
233 a ^= 0x10; in nand_init_ecc()
235 a ^= 0x40; in nand_init_ecc()
238 ecc2[i] = ~(a ^ (a<<1) ^ (parity[i] ? 0xa8 : 0)); in nand_init_ecc()
242 /* compute 3-byte ecc on 256 bytes */
245 int i, j, a; in nand_compute_ecc() local
253 if ((i & (1<<j)) == 0) in nand_compute_ecc()
258 a = (bits[3] << 6) + (bits[2] << 4) + (bits[1] << 2) + bits[0]; in nand_compute_ecc()
259 ecc[0] = ~(a ^ (a<<1) ^ (parity[par] ? 0xaa : 0)); in nand_compute_ecc()
261 a = (bits[7] << 6) + (bits[6] << 4) + (bits[5] << 2) + bits[4]; in nand_compute_ecc()
262 ecc[1] = ~(a ^ (a<<1) ^ (parity[par] ? 0xaa : 0)); in nand_compute_ecc()
269 return (data[0] == ecc[0] && data[1] == ecc[1] && data[2] == ecc[2]); in nand_compare_ecc()
282 * Forget our PBA <---> LBA mappings for a particular port
286 unsigned int shift = media_info->zoneshift in alauda_free_maps()
287 + media_info->blockshift + media_info->pageshift; in alauda_free_maps()
288 unsigned int num_zones = media_info->capacity >> shift; in alauda_free_maps()
291 if (media_info->lba_to_pba != NULL) in alauda_free_maps()
293 kfree(media_info->lba_to_pba[i]); in alauda_free_maps()
294 media_info->lba_to_pba[i] = NULL; in alauda_free_maps()
297 if (media_info->pba_to_lba != NULL) in alauda_free_maps()
299 kfree(media_info->pba_to_lba[i]); in alauda_free_maps()
300 media_info->pba_to_lba[i] = NULL; in alauda_free_maps()
318 rc = usb_stor_ctrl_transfer(us, us->recv_ctrl_pipe, in alauda_get_media_status()
319 command, 0xc0, 0, 1, data, 2); in alauda_get_media_status()
321 usb_stor_dbg(us, "Media status %02X %02X\n", data[0], data[1]); in alauda_get_media_status()
339 return usb_stor_ctrl_transfer(us, us->send_ctrl_pipe, in alauda_ack_media()
340 command, 0x40, 0, 1, NULL, 0); in alauda_ack_media()
344 * Retrieves a 4-byte media signature, which indicates manufacturer, capacity,
356 return usb_stor_ctrl_transfer(us, us->recv_ctrl_pipe, in alauda_get_media_signature()
365 unsigned char *command = us->iobuf; in alauda_reset_media()
367 memset(command, 0, 9); in alauda_reset_media()
369 command[1] = ALAUDA_BULK_RESET_MEDIA; in alauda_reset_media()
372 return usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, in alauda_reset_media()
373 command, 9, NULL); in alauda_reset_media()
381 unsigned char *data = us->iobuf; in alauda_init_media()
393 ready = 1; in alauda_init_media()
415 media_info = alauda_card_find_id(data[1]); in alauda_init_media()
422 MEDIA_INFO(us).capacity = 1 << media_info->chipshift; in alauda_init_media()
426 MEDIA_INFO(us).pageshift = media_info->pageshift; in alauda_init_media()
427 MEDIA_INFO(us).blockshift = media_info->blockshift; in alauda_init_media()
428 MEDIA_INFO(us).zoneshift = media_info->zoneshift; in alauda_init_media()
430 MEDIA_INFO(us).pagesize = 1 << media_info->pageshift; in alauda_init_media()
431 MEDIA_INFO(us).blocksize = 1 << media_info->blockshift; in alauda_init_media()
432 MEDIA_INFO(us).zonesize = 1 << media_info->zoneshift; in alauda_init_media()
434 MEDIA_INFO(us).uzonesize = ((1 << media_info->zoneshift) / 128) * 125; in alauda_init_media()
435 MEDIA_INFO(us).blockmask = MEDIA_INFO(us).blocksize - 1; in alauda_init_media()
454 struct alauda_info *info = (struct alauda_info *) us->extra; in alauda_check_media()
461 || ((status[1] & 0x01) == 0)) { in alauda_check_media()
464 info->sense_key = 0x02; in alauda_check_media()
465 info->sense_asc = 0x3A; in alauda_check_media()
466 info->sense_ascq = 0x00; in alauda_check_media()
476 info->sense_key = UNIT_ATTENTION; in alauda_check_media()
477 info->sense_asc = 0x28; in alauda_check_media()
478 info->sense_ascq = 0x00; in alauda_check_media()
498 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, in alauda_check_status2()
499 command, 9, NULL); in alauda_check_status2()
503 rc = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, in alauda_check_status2()
516 * Gets the redundancy data for the first page of a PBA
527 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, in alauda_get_redu_data()
528 command, 9, NULL); in alauda_get_redu_data()
532 return usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, in alauda_get_redu_data()
537 * Finds the first unused PBA in a zone
543 u16 *pba_to_lba = info->pba_to_lba[zone]; in alauda_find_unused_pba()
546 for (i = 0; i < info->zonesize; i++) in alauda_find_unused_pba()
548 return (zone << info->zoneshift) + i; in alauda_find_unused_pba()
554 * Reads the redundancy data for all PBA's in a zone
555 * Produces lba <--> pba mappings
559 unsigned char *data = us->iobuf; in alauda_read_map()
574 usb_stor_dbg(us, "Mapping blocks for zone %d\n", zone); in alauda_read_map()
594 usb_stor_dbg(us, "PBA %d has no logical mapping\n", blocknum); in alauda_read_map()
607 …usb_stor_dbg(us, "PBA %d has no logical mapping: reserved area = %02X%02X%02X%02X data status %02X… in alauda_read_map()
609 data[0], data[1], data[2], data[3], in alauda_read_map()
616 usb_stor_dbg(us, "PBA %d has invalid address field %02X%02X/%02X%02X\n", in alauda_read_map()
626 "alauda_read_map: Bad parity in LBA for block %d" in alauda_read_map()
633 lba_offset = (lba_offset & 0x07FF) >> 1; in alauda_read_map()
638 * go back to zero, but are within a higher block of LBA's. in alauda_read_map()
639 * Also, there is a maximum of 1000 LBA's per zone. in alauda_read_map()
640 * In other words, in PBA 1024-2047 you will find LBA 0-999 in alauda_read_map()
641 * which are really LBA 1000-1999. This allows for 24 bad in alauda_read_map()
647 "alauda_read_map: Bad low LBA %d for block %d\n", in alauda_read_map()
655 "LBA %d seen for PBA %d and %d\n", in alauda_read_map()
678 * Checks to see whether we have already mapped a certain zone
700 usb_stor_dbg(us, "Erasing PBA %d\n", pba); in alauda_erase_block()
702 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, in alauda_erase_block()
703 command, 9, NULL); in alauda_erase_block()
707 rc = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, in alauda_erase_block()
712 usb_stor_dbg(us, "Erase result: %02X %02X\n", buf[0], buf[1]); in alauda_erase_block()
717 * Reads data from a certain offset page inside a PBA, including interleaved
729 usb_stor_dbg(us, "pba %d page %d count %d\n", pba, page, pages); in alauda_read_block_raw()
731 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, in alauda_read_block_raw()
732 command, 9, NULL); in alauda_read_block_raw()
736 return usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, in alauda_read_block_raw()
741 * Reads data from a certain offset page inside a PBA, excluding redundancy
774 struct alauda_info *info = (struct alauda_info *) us->extra; in alauda_write_block()
780 usb_stor_dbg(us, "pba %d\n", pba); in alauda_write_block()
782 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, in alauda_write_block()
783 command, 9, NULL); in alauda_write_block()
787 rc = usb_stor_bulk_transfer_buf(us, info->wr_ep, data, in alauda_write_block()
797 * Write some data to a specific LBA.
818 if (pba == 1) { in alauda_write_lba()
820 * Maybe it is impossible to write to PBA 1. in alauda_write_lba()
824 "alauda_write_lba: avoid writing to pba 1\n"); in alauda_write_lba()
845 lbap = (lba_offset << 1) | 0x1000; in alauda_write_lba()
847 lbap ^= 1; in alauda_write_lba()
855 usb_stor_dbg(us, "Warning: bad ecc in page %d- of pba %d\n", in alauda_write_lba()
861 usb_stor_dbg(us, "Warning: bad ecc in page %d+ of pba %d\n", in alauda_write_lba()
886 new_pba_offset = new_pba - (zone * zonesize); in alauda_write_lba()
889 usb_stor_dbg(us, "Remapped LBA %d to PBA %d\n", lba, new_pba); in alauda_write_lba()
892 unsigned int pba_offset = pba - (zone * zonesize); in alauda_write_lba()
903 * Read data from a specific sector address
920 * Since we only read in one block at a time, we have to create in alauda_read_data()
921 * a bounce buffer and move the data a piece at a time between the in alauda_read_data()
943 unsigned int lba_offset = lba - (zone * uzonesize); in alauda_read_data()
957 pages = min(sectors, blocksize - page); in alauda_read_data()
964 usb_stor_dbg(us, "Read %d zero pages (LBA %d) page %d\n", in alauda_read_data()
976 usb_stor_dbg(us, "Read %d pages, from PBA %d (LBA %d) page %d\n", in alauda_read_data()
985 usb_stor_access_xfer_buf(buffer, len, us->srb, in alauda_read_data()
990 sectors -= pages; in alauda_read_data()
998 * Write data to a specific sector address
1015 * we have to create a bounce buffer and move the data a piece in alauda_write_data()
1016 * at a time between the bounce buffer and the actual transfer buffer. in alauda_write_data()
1025 * We also need a temporary block buffer, where we read in the old data, in alauda_write_data()
1045 unsigned int pages = min(sectors, blocksize - page); in alauda_write_data()
1057 usb_stor_access_xfer_buf(buffer, len, us->srb, in alauda_write_data()
1067 sectors -= pages; in alauda_write_data()
1088 struct alauda_media_info *media_info = &info->port[port]; in alauda_info_destructor()
1091 kfree(media_info->lba_to_pba); in alauda_info_destructor()
1092 kfree(media_info->pba_to_lba); in alauda_info_destructor()
1097 * Initialize alauda_info struct and find the data-write endpoint
1102 struct usb_host_interface *altsetting = us->pusb_intf->cur_altsetting; in init_alauda()
1105 us->extra = kzalloc(sizeof(struct alauda_info), GFP_NOIO); in init_alauda()
1106 if (!us->extra) in init_alauda()
1107 return -ENOMEM; in init_alauda()
1109 info = (struct alauda_info *) us->extra; in init_alauda()
1110 us->extra_destructor = alauda_info_destructor; in init_alauda()
1112 info->wr_ep = usb_sndbulkpipe(us->pusb_dev, in init_alauda()
1113 altsetting->endpoint[0].desc.bEndpointAddress in init_alauda()
1122 struct alauda_info *info = (struct alauda_info *) us->extra; in alauda_transport()
1123 unsigned char *ptr = us->iobuf; in alauda_transport()
1128 if (srb->cmnd[0] == INQUIRY) { in alauda_transport()
1129 usb_stor_dbg(us, "INQUIRY - Returning bogus response\n"); in alauda_transport()
1135 if (srb->cmnd[0] == TEST_UNIT_READY) { in alauda_transport()
1140 if (srb->cmnd[0] == READ_CAPACITY) { in alauda_transport()
1155 ((__be32 *) ptr)[0] = cpu_to_be32(capacity - 1); in alauda_transport()
1156 ((__be32 *) ptr)[1] = cpu_to_be32(512); in alauda_transport()
1162 if (srb->cmnd[0] == READ_10) { in alauda_transport()
1169 page = short_pack(srb->cmnd[3], srb->cmnd[2]); in alauda_transport()
1171 page |= short_pack(srb->cmnd[5], srb->cmnd[4]); in alauda_transport()
1172 pages = short_pack(srb->cmnd[8], srb->cmnd[7]); in alauda_transport()
1174 usb_stor_dbg(us, "READ_10: page %d pagect %d\n", page, pages); in alauda_transport()
1179 if (srb->cmnd[0] == WRITE_10) { in alauda_transport()
1186 page = short_pack(srb->cmnd[3], srb->cmnd[2]); in alauda_transport()
1188 page |= short_pack(srb->cmnd[5], srb->cmnd[4]); in alauda_transport()
1189 pages = short_pack(srb->cmnd[8], srb->cmnd[7]); in alauda_transport()
1191 usb_stor_dbg(us, "WRITE_10: page %d pagect %d\n", page, pages); in alauda_transport()
1196 if (srb->cmnd[0] == REQUEST_SENSE) { in alauda_transport()
1201 ptr[2] = info->sense_key; in alauda_transport()
1203 ptr[12] = info->sense_asc; in alauda_transport()
1204 ptr[13] = info->sense_ascq; in alauda_transport()
1210 if (srb->cmnd[0] == ALLOW_MEDIUM_REMOVAL) { in alauda_transport()
1218 usb_stor_dbg(us, "Gah! Unknown command: %d (0x%x)\n", in alauda_transport()
1219 srb->cmnd[0], srb->cmnd[0]); in alauda_transport()
1220 info->sense_key = 0x05; in alauda_transport()
1221 info->sense_asc = 0x20; in alauda_transport()
1222 info->sense_ascq = 0x00; in alauda_transport()
1235 (id - alauda_usb_ids) + alauda_unusual_dev_list, in alauda_probe()
1240 us->transport_name = "Alauda Control/Bulk"; in alauda_probe()
1241 us->transport = alauda_transport; in alauda_probe()
1242 us->transport_reset = usb_stor_Bulk_reset; in alauda_probe()
1243 us->max_lun = 1; in alauda_probe()
1259 .soft_unbind = 1,
1260 .no_dynamic_id = 1,