Lines Matching +full:wp +full:- +full:content

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
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");
114 char pageadrlen; /* length of an address in bytes - 1 */
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.
193 parity[i] = (parity[i&(i-1)] ^ 1); in nand_init_ecc()
211 /* compute 3-byte ecc on 256 bytes */
253 int blockmask; /* 2^blockshift - 1 */
301 pipe = us->recv_ctrl_pipe; in sddr09_send_command()
303 pipe = us->send_ctrl_pipe; in sddr09_send_command()
309 case USB_STOR_XFER_STALLED: return -EPIPE; in sddr09_send_command()
310 default: return -EIO; in sddr09_send_command()
328 unsigned char *command = us->iobuf;
349 unsigned char *command = us->iobuf; 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()
372 * bytes 2-5: address (interpretation depends on byte 1, see below)
373 * bytes 10-11: count (idem)
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.
393 unsigned char *command = us->iobuf; in sddr09_readX()
417 result = usb_stor_bulk_transfer_sg(us, us->recv_bulk_pipe, in sddr09_readX()
423 return -EIO; in sddr09_readX()
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()
548 * bytes 2-5: write address in shorts
549 * bytes 10-11: sector count
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()
602 result = usb_stor_bulk_transfer_sg(us, us->send_bulk_pipe, in sddr09_writeX()
608 return -EIO; in sddr09_writeX()
628 * bytes 4i-1,4i,4i+1: page address
637 unsigned char *command = us->iobuf;
652 command[4*nsg-1] = ((address >> 25) & 0xFF);
660 command[4*nsg-1] = ((address >> 25) & 0xFF);
668 command[4*nsg-1] = ((address >> 25) & 0xFF);
682 return -ENOMEM;
684 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
690 return -EIO;
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()
725 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, 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()
755 len = min(sectors, (unsigned int) info->blocksize) * info->pagesize; in sddr09_read_data()
758 return -ENOMEM; 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()
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()
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()
842 if (info->pba_to_lba[zonestart+i] == UNDEF) { in sddr09_find_unused_pba()
855 struct sddr09_card_info *info = (struct sddr09_card_info *) us->extra; 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()
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()
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()
932 result = sddr09_write_inplace(us, address>>1, info->blocksize, in sddr09_write_lba()
933 info->pageshift, blockbuffer, 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()
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()
1000 len = min(sectors, (unsigned int) info->blocksize) * info->pagesize; in sddr09_write_data()
1004 return -ENOMEM; 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()
1037 sectors -= pages; in sddr09_write_data()
1050 unsigned char *content, in sddr09_read_control() argument
1057 CONTROL_SHIFT, content, use_sg); in sddr09_read_control()
1066 * signifying that the secret command to read an 128-bit ID is available.
1072 unsigned char *command = us->iobuf; in sddr09_read_deviceID()
1073 unsigned char *content = us->iobuf; in sddr09_read_deviceID() local
1084 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, in sddr09_read_deviceID()
1085 content, 64, NULL); in sddr09_read_deviceID()
1088 deviceID[i] = content[i]; in sddr09_read_deviceID()
1090 return (result == USB_STOR_XFER_GOOD ? 0 : -EIO); in sddr09_read_deviceID()
1105 info->flags |= SDDR09_WP; /* write protected */ in sddr09_get_wp()
1106 wp_fmt = " WP"; in sddr09_get_wp()
1126 unsigned char *command = us->iobuf;
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()
1178 ", 128-bit ID"); in sddr09_get_cardinfo()
1189 ", WP"); 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()
1213 numblocks = info->capacity >> (info->blockshift + info->pageshift); 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()
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()
1257 address = i << (info->pageshift + info->blockshift); in sddr09_read_map()
1260 min(alloc_blocks, numblocks - i), in sddr09_read_map()
1263 result = -1; in sddr09_read_map()
1270 info->pba_to_lba[i] = UNUSABLE; in sddr09_read_map()
1278 info->pba_to_lba[i] = UNUSABLE; in sddr09_read_map()
1299 info->pba_to_lba[i] = UNUSABLE; in sddr09_read_map()
1308 info->pba_to_lba[i] = UNUSABLE; in sddr09_read_map()
1317 info->pba_to_lba[i] = UNUSABLE; 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()
1342 if (info->lba_to_pba[lba] != UNDEF) { 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()
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()
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()
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()
1423 if (result == -EPIPE) { in sddr09_common_init()
1424 usb_stor_dbg(us, "-- stall on control interface\n"); 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()
1449 unsigned char *data = us->iobuf; in usb_stor_sddr09_dpcm_init()
1482 // additional transfer length * = sizeof(data) - 7 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()
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
1542 unsigned char *ptr = us->iobuf; 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()
1580 if (srb->cmnd[0] == INQUIRY) { in sddr09_transport()
1586 if (srb->cmnd[0] == READ_CAPACITY) { in sddr09_transport()
1589 sddr09_get_wp(us, info); /* read WP bit */ in sddr09_transport()
1591 cardinfo = sddr09_get_cardinfo(us, info->flags); 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()
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()
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()
1651 if (srb->cmnd[0] == ALLOW_MEDIUM_REMOVAL) 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()
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()
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()
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()
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()
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()
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()