^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Driver for SanDisk SDDR-09 SmartMedia reader
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * (c) 2000, 2001 Robert Baruch (autophile@starband.net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * (c) 2002 Andries Brouwer (aeb@cwi.nl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Developed with the assistance of:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * (c) 2002 Alan Stern <stern@rowland.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * The SanDisk SDDR-09 SmartMedia reader uses the Shuttle EUSB-01 chip.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * This chip is a programmable USB controller. In the SDDR-09, it has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * been programmed to obey a certain limited set of SCSI commands.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * This driver translates the "real" SCSI commands to the SDDR-09 SCSI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * commands.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * Known vendor commands: 12 bytes, first byte is opcode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * E7: read scatter gather
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * E8: read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * E9: write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * EA: erase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * EB: reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * EC: read status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * ED: read ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * EE: write CIS (?)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * EF: compute checksum (?)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <scsi/scsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <scsi/scsi_cmnd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <scsi/scsi_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include "usb.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include "transport.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include "protocol.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include "debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include "scsiglue.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define DRV_NAME "ums-sddr09"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) MODULE_DESCRIPTION("Driver for SanDisk SDDR-09 SmartMedia reader");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) MODULE_AUTHOR("Andries Brouwer <aeb@cwi.nl>, Robert Baruch <autophile@starband.net>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) MODULE_IMPORT_NS(USB_STORAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static int usb_stor_sddr09_dpcm_init(struct us_data *us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static int usb_stor_sddr09_init(struct us_data *us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * The table of devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) vendorName, productName, useProtocol, useTransport, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) initFunction, flags) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) .driver_info = (flags) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static struct usb_device_id sddr09_usb_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) # include "unusual_sddr09.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) { } /* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) MODULE_DEVICE_TABLE(usb, sddr09_usb_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #undef UNUSUAL_DEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * The flags table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) vendor_name, product_name, use_protocol, use_transport, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) init_function, Flags) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) .vendorName = vendor_name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .productName = product_name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) .useProtocol = use_protocol, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) .useTransport = use_transport, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) .initFunction = init_function, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static struct us_unusual_dev sddr09_unusual_dev_list[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) # include "unusual_sddr09.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) { } /* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #undef UNUSUAL_DEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #define short_pack(lsb,msb) ( ((u16)(lsb)) | ( ((u16)(msb))<<8 ) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #define LSB_of(s) ((s)&0xFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) #define MSB_of(s) ((s)>>8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * First some stuff that does not belong here:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * data on SmartMedia and other cards, completely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * unrelated to this driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * Similar stuff occurs in <linux/mtd/nand_ids.h>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct nand_flash_dev {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) int model_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) int chipshift; /* 1<<cs bytes total capacity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) char pageshift; /* 1<<ps bytes in a page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) char blockshift; /* 1<<bs pages in an erase block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) char zoneshift; /* 1<<zs blocks in a zone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /* # of logical blocks is 125/128 of this */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) char pageadrlen; /* length of an address in bytes - 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * NAND Flash Manufacturer ID Codes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #define NAND_MFR_AMD 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #define NAND_MFR_NATSEMI 0x8f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #define NAND_MFR_TOSHIBA 0x98
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #define NAND_MFR_SAMSUNG 0xec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static inline char *nand_flash_manufacturer(int manuf_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) switch(manuf_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) case NAND_MFR_AMD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return "AMD";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) case NAND_MFR_NATSEMI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) return "NATSEMI";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) case NAND_MFR_TOSHIBA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) return "Toshiba";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) case NAND_MFR_SAMSUNG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return "Samsung";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) return "unknown";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * It looks like it is unnecessary to attach manufacturer to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * remaining data: SSFDC prescribes manufacturer-independent id codes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * 256 MB NAND flash has a 5-byte ID with 2nd byte 0xaa, 0xba, 0xca or 0xda.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static struct nand_flash_dev nand_flash_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /* NAND flash */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) { 0x6e, 20, 8, 4, 8, 2}, /* 1 MB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) { 0xe8, 20, 8, 4, 8, 2}, /* 1 MB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) { 0xec, 20, 8, 4, 8, 2}, /* 1 MB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) { 0x64, 21, 8, 4, 9, 2}, /* 2 MB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) { 0xea, 21, 8, 4, 9, 2}, /* 2 MB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) { 0x6b, 22, 9, 4, 9, 2}, /* 4 MB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) { 0xe3, 22, 9, 4, 9, 2}, /* 4 MB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) { 0xe5, 22, 9, 4, 9, 2}, /* 4 MB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) { 0xe6, 23, 9, 4, 10, 2}, /* 8 MB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) { 0x73, 24, 9, 5, 10, 2}, /* 16 MB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) { 0x75, 25, 9, 5, 10, 2}, /* 32 MB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) { 0x76, 26, 9, 5, 10, 3}, /* 64 MB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) { 0x79, 27, 9, 5, 10, 3}, /* 128 MB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) /* MASK ROM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) { 0x5d, 21, 9, 4, 8, 2}, /* 2 MB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) { 0xd5, 22, 9, 4, 9, 2}, /* 4 MB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) { 0xd6, 23, 9, 4, 10, 2}, /* 8 MB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) { 0x57, 24, 9, 4, 11, 2}, /* 16 MB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) { 0x58, 25, 9, 4, 12, 2}, /* 32 MB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) { 0,}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static struct nand_flash_dev *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) nand_find_id(unsigned char id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) for (i = 0; i < ARRAY_SIZE(nand_flash_ids); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if (nand_flash_ids[i].model_id == id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return &(nand_flash_ids[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * ECC computation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static unsigned char parity[256];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) static unsigned char ecc2[256];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static void nand_init_ecc(void) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) int i, j, a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) parity[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) for (i = 1; i < 256; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) parity[i] = (parity[i&(i-1)] ^ 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) for (i = 0; i < 256; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) a = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) for (j = 0; j < 8; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (i & (1<<j)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if ((j & 1) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) a ^= 0x04;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if ((j & 2) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) a ^= 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if ((j & 4) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) a ^= 0x40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) ecc2[i] = ~(a ^ (a<<1) ^ (parity[i] ? 0xa8 : 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) /* compute 3-byte ecc on 256 bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static void nand_compute_ecc(unsigned char *data, unsigned char *ecc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) int i, j, a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) unsigned char par = 0, bit, bits[8] = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /* collect 16 checksum bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) for (i = 0; i < 256; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) par ^= data[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) bit = parity[data[i]];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) for (j = 0; j < 8; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) if ((i & (1<<j)) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) bits[j] ^= bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) /* put 4+4+4 = 12 bits in the ecc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) a = (bits[3] << 6) + (bits[2] << 4) + (bits[1] << 2) + bits[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) ecc[0] = ~(a ^ (a<<1) ^ (parity[par] ? 0xaa : 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) a = (bits[7] << 6) + (bits[6] << 4) + (bits[5] << 2) + bits[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) ecc[1] = ~(a ^ (a<<1) ^ (parity[par] ? 0xaa : 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) ecc[2] = ecc2[par];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static int nand_compare_ecc(unsigned char *data, unsigned char *ecc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) return (data[0] == ecc[0] && data[1] == ecc[1] && data[2] == ecc[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static void nand_store_ecc(unsigned char *data, unsigned char *ecc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) memcpy(data, ecc, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) * The actual driver starts here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) struct sddr09_card_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) unsigned long capacity; /* Size of card in bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) int pagesize; /* Size of page in bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) int pageshift; /* log2 of pagesize */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) int blocksize; /* Size of block in pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) int blockshift; /* log2 of blocksize */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) int blockmask; /* 2^blockshift - 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) int *lba_to_pba; /* logical to physical map */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) int *pba_to_lba; /* physical to logical map */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) int lbact; /* number of available pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) #define SDDR09_WP 1 /* write protected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * On my 16MB card, control blocks have size 64 (16 real control bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * and 48 junk bytes). In reality of course the card uses 16 control bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * so the reader makes up the remaining 48. Don't know whether these numbers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * depend on the card. For now a constant.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) #define CONTROL_SHIFT 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * On my Combo CF/SM reader, the SM reader has LUN 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * (and things fail with LUN 0).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) * It seems LUN is irrelevant for others.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) #define LUN 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) #define LUNBITS (LUN << 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * LBA and PBA are unsigned ints. Special values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) #define UNDEF 0xffffffff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) #define SPARE 0xfffffffe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) #define UNUSABLE 0xfffffffd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) static const int erase_bad_lba_entries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) /* send vendor interface command (0x41) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) /* called for requests 0, 1, 8 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) sddr09_send_command(struct us_data *us,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) unsigned char request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) unsigned char direction,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) unsigned char *xfer_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) unsigned int xfer_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) unsigned int pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) unsigned char requesttype = (0x41 | direction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) // Get the receive or send control pipe number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if (direction == USB_DIR_IN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) pipe = us->recv_ctrl_pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) pipe = us->send_ctrl_pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) rc = usb_stor_ctrl_transfer(us, pipe, request, requesttype,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 0, 0, xfer_data, xfer_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) switch (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) case USB_STOR_XFER_GOOD: return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) case USB_STOR_XFER_STALLED: return -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) default: return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) sddr09_send_scsi_command(struct us_data *us,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) unsigned char *command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) unsigned int command_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) return sddr09_send_command(us, 0, USB_DIR_OUT, command, command_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * Test Unit Ready Command: 12 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) * byte 0: opcode: 00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) sddr09_test_unit_ready(struct us_data *us) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) unsigned char *command = us->iobuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) memset(command, 0, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) command[1] = LUNBITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) result = sddr09_send_scsi_command(us, command, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) usb_stor_dbg(us, "sddr09_test_unit_ready returns %d\n", result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) * Request Sense Command: 12 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) * byte 0: opcode: 03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) * byte 4: data length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) sddr09_request_sense(struct us_data *us, unsigned char *sensebuf, int buflen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) unsigned char *command = us->iobuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) memset(command, 0, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) command[0] = 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) command[1] = LUNBITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) command[4] = buflen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) result = sddr09_send_scsi_command(us, command, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) sensebuf, buflen, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) return (result == USB_STOR_XFER_GOOD ? 0 : -EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) * Read Command: 12 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) * byte 0: opcode: E8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) * byte 1: last two bits: 00: read data, 01: read blockwise control,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) * 10: read both, 11: read pagewise control.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) * It turns out we need values 20, 21, 22, 23 here (LUN 1).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) * bytes 2-5: address (interpretation depends on byte 1, see below)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) * bytes 10-11: count (idem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) * A page has 512 data bytes and 64 control bytes (16 control and 48 junk).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) * A read data command gets data in 512-byte pages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) * A read control command gets control in 64-byte chunks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) * A read both command gets data+control in 576-byte chunks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) * Blocks are groups of 32 pages, and read blockwise control jumps to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) * next block, while read pagewise control jumps to the next page after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) * reading a group of 64 control bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) * [Here 512 = 1<<pageshift, 32 = 1<<blockshift, 64 is constant?]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) * (1 MB and 2 MB cards are a bit different, but I have only a 16 MB card.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) sddr09_readX(struct us_data *us, int x, unsigned long fromaddress,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) int nr_of_pages, int bulklen, unsigned char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) int use_sg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) unsigned char *command = us->iobuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) command[0] = 0xE8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) command[1] = LUNBITS | x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) command[2] = MSB_of(fromaddress>>16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) command[3] = LSB_of(fromaddress>>16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) command[4] = MSB_of(fromaddress & 0xFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) command[5] = LSB_of(fromaddress & 0xFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) command[6] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) command[7] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) command[8] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) command[9] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) command[10] = MSB_of(nr_of_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) command[11] = LSB_of(nr_of_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) result = sddr09_send_scsi_command(us, command, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) usb_stor_dbg(us, "Result for send_control in sddr09_read2%d %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) x, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) result = usb_stor_bulk_transfer_sg(us, us->recv_bulk_pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) buf, bulklen, use_sg, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) if (result != USB_STOR_XFER_GOOD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) usb_stor_dbg(us, "Result for bulk_transfer in sddr09_read2%d %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) x, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) * Read Data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) * fromaddress counts data shorts:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) * increasing it by 256 shifts the bytestream by 512 bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) * the last 8 bits are ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) * nr_of_pages counts pages of size (1 << pageshift).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) sddr09_read20(struct us_data *us, unsigned long fromaddress,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) int nr_of_pages, int pageshift, unsigned char *buf, int use_sg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) int bulklen = nr_of_pages << pageshift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) /* The last 8 bits of fromaddress are ignored. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) return sddr09_readX(us, 0, fromaddress, nr_of_pages, bulklen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) buf, use_sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) * Read Blockwise Control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) * fromaddress gives the starting position (as in read data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) * the last 8 bits are ignored); increasing it by 32*256 shifts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) * the output stream by 64 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) * count counts control groups of size (1 << controlshift).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) * For me, controlshift = 6. Is this constant?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) * After getting one control group, jump to the next block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) * (fromaddress += 8192).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) sddr09_read21(struct us_data *us, unsigned long fromaddress,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) int count, int controlshift, unsigned char *buf, int use_sg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) int bulklen = (count << controlshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) return sddr09_readX(us, 1, fromaddress, count, bulklen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) buf, use_sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) * Read both Data and Control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) * fromaddress counts data shorts, ignoring control:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) * increasing it by 256 shifts the bytestream by 576 = 512+64 bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) * the last 8 bits are ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) * nr_of_pages counts pages of size (1 << pageshift) + (1 << controlshift).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) sddr09_read22(struct us_data *us, unsigned long fromaddress,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) int nr_of_pages, int pageshift, unsigned char *buf, int use_sg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) int bulklen = (nr_of_pages << pageshift) + (nr_of_pages << CONTROL_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) usb_stor_dbg(us, "reading %d pages, %d bytes\n", nr_of_pages, bulklen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) return sddr09_readX(us, 2, fromaddress, nr_of_pages, bulklen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) buf, use_sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) * Read Pagewise Control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) * fromaddress gives the starting position (as in read data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) * the last 8 bits are ignored); increasing it by 256 shifts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) * the output stream by 64 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) * count counts control groups of size (1 << controlshift).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) * For me, controlshift = 6. Is this constant?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) * After getting one control group, jump to the next page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) * (fromaddress += 256).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) sddr09_read23(struct us_data *us, unsigned long fromaddress,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) int count, int controlshift, unsigned char *buf, int use_sg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) int bulklen = (count << controlshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) return sddr09_readX(us, 3, fromaddress, count, bulklen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) buf, use_sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) * Erase Command: 12 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) * byte 0: opcode: EA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) * bytes 6-9: erase address (big-endian, counting shorts, sector aligned).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) * Always precisely one block is erased; bytes 2-5 and 10-11 are ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) * The byte address being erased is 2*Eaddress.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) * The CIS cannot be erased.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) sddr09_erase(struct us_data *us, unsigned long Eaddress) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) unsigned char *command = us->iobuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) usb_stor_dbg(us, "erase address %lu\n", Eaddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) memset(command, 0, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) command[0] = 0xEA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) command[1] = LUNBITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) command[6] = MSB_of(Eaddress>>16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) command[7] = LSB_of(Eaddress>>16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) command[8] = MSB_of(Eaddress & 0xFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) command[9] = LSB_of(Eaddress & 0xFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) result = sddr09_send_scsi_command(us, command, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) usb_stor_dbg(us, "Result for send_control in sddr09_erase %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) * Write CIS Command: 12 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) * byte 0: opcode: EE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) * bytes 2-5: write address in shorts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) * bytes 10-11: sector count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) * This writes at the indicated address. Don't know how it differs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) * from E9. Maybe it does not erase? However, it will also write to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) * the CIS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) * When two such commands on the same page follow each other directly,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) * the second one is not done.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) * Write Command: 12 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) * byte 0: opcode: E9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) * bytes 2-5: write address (big-endian, counting shorts, sector aligned).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) * bytes 6-9: erase address (big-endian, counting shorts, sector aligned).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) * bytes 10-11: sector count (big-endian, in 512-byte sectors).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) * If write address equals erase address, the erase is done first,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) * otherwise the write is done first. When erase address equals zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) * no erase is done?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) sddr09_writeX(struct us_data *us,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) unsigned long Waddress, unsigned long Eaddress,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) int nr_of_pages, int bulklen, unsigned char *buf, int use_sg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) unsigned char *command = us->iobuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) command[0] = 0xE9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) command[1] = LUNBITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) command[2] = MSB_of(Waddress>>16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) command[3] = LSB_of(Waddress>>16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) command[4] = MSB_of(Waddress & 0xFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) command[5] = LSB_of(Waddress & 0xFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) command[6] = MSB_of(Eaddress>>16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) command[7] = LSB_of(Eaddress>>16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) command[8] = MSB_of(Eaddress & 0xFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) command[9] = LSB_of(Eaddress & 0xFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) command[10] = MSB_of(nr_of_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) command[11] = LSB_of(nr_of_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) result = sddr09_send_scsi_command(us, command, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) usb_stor_dbg(us, "Result for send_control in sddr09_writeX %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) result = usb_stor_bulk_transfer_sg(us, us->send_bulk_pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) buf, bulklen, use_sg, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) if (result != USB_STOR_XFER_GOOD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) usb_stor_dbg(us, "Result for bulk_transfer in sddr09_writeX %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) /* erase address, write same address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) sddr09_write_inplace(struct us_data *us, unsigned long address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) int nr_of_pages, int pageshift, unsigned char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) int use_sg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) int bulklen = (nr_of_pages << pageshift) + (nr_of_pages << CONTROL_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) return sddr09_writeX(us, address, address, nr_of_pages, bulklen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) buf, use_sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) * Read Scatter Gather Command: 3+4n bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) * byte 0: opcode E7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) * byte 2: n
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) * bytes 4i-1,4i,4i+1: page address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) * byte 4i+2: page count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) * (i=1..n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) * This reads several pages from the card to a single memory buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) * The last two bits of byte 1 have the same meaning as for E8.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) sddr09_read_sg_test_only(struct us_data *us) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) unsigned char *command = us->iobuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) int result, bulklen, nsg, ct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) unsigned char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) unsigned long address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) nsg = bulklen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) command[0] = 0xE7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) command[1] = LUNBITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) command[2] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) address = 040000; ct = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) nsg++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) bulklen += (ct << 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) command[4*nsg+2] = ct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) command[4*nsg+1] = ((address >> 9) & 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) command[4*nsg+0] = ((address >> 17) & 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) command[4*nsg-1] = ((address >> 25) & 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) address = 0340000; ct = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) nsg++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) bulklen += (ct << 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) command[4*nsg+2] = ct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) command[4*nsg+1] = ((address >> 9) & 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) command[4*nsg+0] = ((address >> 17) & 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) command[4*nsg-1] = ((address >> 25) & 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) address = 01000000; ct = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) nsg++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) bulklen += (ct << 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) command[4*nsg+2] = ct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) command[4*nsg+1] = ((address >> 9) & 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) command[4*nsg+0] = ((address >> 17) & 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) command[4*nsg-1] = ((address >> 25) & 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) command[2] = nsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) result = sddr09_send_scsi_command(us, command, 4*nsg+3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) usb_stor_dbg(us, "Result for send_control in sddr09_read_sg %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) buf = kmalloc(bulklen, GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) buf, bulklen, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) if (result != USB_STOR_XFER_GOOD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) usb_stor_dbg(us, "Result for bulk_transfer in sddr09_read_sg %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) * Read Status Command: 12 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) * byte 0: opcode: EC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) * Returns 64 bytes, all zero except for the first.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) * bit 0: 1: Error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) * bit 5: 1: Suspended
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) * bit 6: 1: Ready
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) * bit 7: 1: Not write-protected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) sddr09_read_status(struct us_data *us, unsigned char *status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) unsigned char *command = us->iobuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) unsigned char *data = us->iobuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) usb_stor_dbg(us, "Reading status...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) memset(command, 0, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) command[0] = 0xEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) command[1] = LUNBITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) result = sddr09_send_scsi_command(us, command, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) data, 64, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) *status = data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) return (result == USB_STOR_XFER_GOOD ? 0 : -EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) sddr09_read_data(struct us_data *us,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) unsigned long address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) unsigned int sectors) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) struct sddr09_card_info *info = (struct sddr09_card_info *) us->extra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) unsigned char *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) unsigned int lba, maxlba, pba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) unsigned int page, pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) unsigned int len, offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) struct scatterlist *sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) // Figure out the initial LBA and page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) lba = address >> info->blockshift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) page = (address & info->blockmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) maxlba = info->capacity >> (info->pageshift + info->blockshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) if (lba >= maxlba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) // Since we only read in one block at a time, we have to create
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) // a bounce buffer and move the data a piece at a time between the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) // bounce buffer and the actual transfer buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) len = min(sectors, (unsigned int) info->blocksize) * info->pagesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) buffer = kmalloc(len, GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) if (!buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) // This could be made much more efficient by checking for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) // contiguous LBA's. Another exercise left to the student.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) sg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) while (sectors > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) /* Find number of pages we can read in this block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) pages = min(sectors, info->blocksize - page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) len = pages << info->pageshift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) /* Not overflowing capacity? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) if (lba >= maxlba) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) usb_stor_dbg(us, "Error: Requested lba %u exceeds maximum %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) lba, maxlba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) result = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) /* Find where this lba lives on disk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) pba = info->lba_to_pba[lba];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) if (pba == UNDEF) { /* this lba was never written */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) usb_stor_dbg(us, "Read %d zero pages (LBA %d) page %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) pages, lba, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) * This is not really an error. It just means
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) * that the block has never been written.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) * Instead of returning an error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) * it is better to return all zero data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) memset(buffer, 0, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) usb_stor_dbg(us, "Read %d pages, from PBA %d (LBA %d) page %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) pages, pba, lba, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) address = ((pba << info->blockshift) + page) <<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) info->pageshift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) result = sddr09_read20(us, address>>1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) pages, info->pageshift, buffer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) // Store the data in the transfer buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) usb_stor_access_xfer_buf(buffer, len, us->srb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) &sg, &offset, TO_XFER_BUF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) page = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) lba++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) sectors -= pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) kfree(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) static unsigned int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) sddr09_find_unused_pba(struct sddr09_card_info *info, unsigned int lba) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) static unsigned int lastpba = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) int zonestart, end, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) zonestart = (lba/1000) << 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) end = info->capacity >> (info->blockshift + info->pageshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) end -= zonestart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) if (end > 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) end = 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) for (i = lastpba+1; i < end; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) if (info->pba_to_lba[zonestart+i] == UNDEF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) lastpba = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) return zonestart+i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) for (i = 0; i <= lastpba; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) if (info->pba_to_lba[zonestart+i] == UNDEF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) lastpba = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) return zonestart+i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) sddr09_write_lba(struct us_data *us, unsigned int lba,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) unsigned int page, unsigned int pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) unsigned char *ptr, unsigned char *blockbuffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) struct sddr09_card_info *info = (struct sddr09_card_info *) us->extra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) unsigned long address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) unsigned int pba, lbap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) unsigned int pagelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) unsigned char *bptr, *cptr, *xptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) unsigned char ecc[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) int i, result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) lbap = ((lba % 1000) << 1) | 0x1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) if (parity[MSB_of(lbap) ^ LSB_of(lbap)])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) lbap ^= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) pba = info->lba_to_pba[lba];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) if (pba == UNDEF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) pba = sddr09_find_unused_pba(info, lba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) if (!pba) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) printk(KERN_WARNING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) "sddr09_write_lba: Out of unused blocks\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) info->pba_to_lba[pba] = lba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) info->lba_to_pba[lba] = pba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) if (pba == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) * Maybe it is impossible to write to PBA 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) * Fake success, but don't do anything.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) printk(KERN_WARNING "sddr09: avoid writing to pba 1\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) pagelen = (1 << info->pageshift) + (1 << CONTROL_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) /* read old contents */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) address = (pba << (info->pageshift + info->blockshift));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) result = sddr09_read22(us, address>>1, info->blocksize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) info->pageshift, blockbuffer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) /* check old contents and fill lba */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) for (i = 0; i < info->blocksize; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) bptr = blockbuffer + i*pagelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) cptr = bptr + info->pagesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) nand_compute_ecc(bptr, ecc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) if (!nand_compare_ecc(cptr+13, ecc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) usb_stor_dbg(us, "Warning: bad ecc in page %d- of pba %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) i, pba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) nand_store_ecc(cptr+13, ecc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) nand_compute_ecc(bptr+(info->pagesize / 2), ecc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) if (!nand_compare_ecc(cptr+8, ecc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) usb_stor_dbg(us, "Warning: bad ecc in page %d+ of pba %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) i, pba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) nand_store_ecc(cptr+8, ecc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) cptr[6] = cptr[11] = MSB_of(lbap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) cptr[7] = cptr[12] = LSB_of(lbap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) /* copy in new stuff and compute ECC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) xptr = ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) for (i = page; i < page+pages; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) bptr = blockbuffer + i*pagelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) cptr = bptr + info->pagesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) memcpy(bptr, xptr, info->pagesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) xptr += info->pagesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) nand_compute_ecc(bptr, ecc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) nand_store_ecc(cptr+13, ecc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) nand_compute_ecc(bptr+(info->pagesize / 2), ecc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) nand_store_ecc(cptr+8, ecc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) usb_stor_dbg(us, "Rewrite PBA %d (LBA %d)\n", pba, lba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) result = sddr09_write_inplace(us, address>>1, info->blocksize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) info->pageshift, blockbuffer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) usb_stor_dbg(us, "sddr09_write_inplace returns %d\n", result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) unsigned char status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) int result2 = sddr09_read_status(us, &status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) if (result2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) usb_stor_dbg(us, "cannot read status\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) else if (status != 0xc0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) usb_stor_dbg(us, "status after write: 0x%x\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) int result2 = sddr09_test_unit_ready(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) sddr09_write_data(struct us_data *us,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) unsigned long address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) unsigned int sectors) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) struct sddr09_card_info *info = (struct sddr09_card_info *) us->extra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) unsigned int lba, maxlba, page, pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) unsigned int pagelen, blocklen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) unsigned char *blockbuffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) unsigned char *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) unsigned int len, offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) struct scatterlist *sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) /* Figure out the initial LBA and page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) lba = address >> info->blockshift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) page = (address & info->blockmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) maxlba = info->capacity >> (info->pageshift + info->blockshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) if (lba >= maxlba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) * blockbuffer is used for reading in the old data, overwriting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) * with the new data, and performing ECC calculations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) * TODO: instead of doing kmalloc/kfree for each write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) * add a bufferpointer to the info structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) pagelen = (1 << info->pageshift) + (1 << CONTROL_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) blocklen = (pagelen << info->blockshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) blockbuffer = kmalloc(blocklen, GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) if (!blockbuffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) * Since we don't write the user data directly to the device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) * we have to create a bounce buffer and move the data a piece
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) * at a time between the bounce buffer and the actual transfer buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) len = min(sectors, (unsigned int) info->blocksize) * info->pagesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) buffer = kmalloc(len, GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) if (!buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) kfree(blockbuffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) sg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) while (sectors > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) /* Write as many sectors as possible in this block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) pages = min(sectors, info->blocksize - page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) len = (pages << info->pageshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) /* Not overflowing capacity? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) if (lba >= maxlba) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) usb_stor_dbg(us, "Error: Requested lba %u exceeds maximum %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) lba, maxlba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) result = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) /* Get the data from the transfer buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) usb_stor_access_xfer_buf(buffer, len, us->srb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) &sg, &offset, FROM_XFER_BUF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) result = sddr09_write_lba(us, lba, page, pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) buffer, blockbuffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) page = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) lba++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) sectors -= pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) kfree(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) kfree(blockbuffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) sddr09_read_control(struct us_data *us,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) unsigned long address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) unsigned int blocks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) unsigned char *content,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) int use_sg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) usb_stor_dbg(us, "Read control address %lu, blocks %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) address, blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) return sddr09_read21(us, address, blocks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) CONTROL_SHIFT, content, use_sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) * Read Device ID Command: 12 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) * byte 0: opcode: ED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) * Returns 2 bytes: Manufacturer ID and Device ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) * On more recent cards 3 bytes: the third byte is an option code A5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) * signifying that the secret command to read an 128-bit ID is available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) * On still more recent cards 4 bytes: the fourth byte C0 means that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) * a second read ID cmd is available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) sddr09_read_deviceID(struct us_data *us, unsigned char *deviceID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) unsigned char *command = us->iobuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) unsigned char *content = us->iobuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) int result, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) memset(command, 0, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) command[0] = 0xED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) command[1] = LUNBITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) result = sddr09_send_scsi_command(us, command, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) content, 64, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) for (i = 0; i < 4; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) deviceID[i] = content[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) return (result == USB_STOR_XFER_GOOD ? 0 : -EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) sddr09_get_wp(struct us_data *us, struct sddr09_card_info *info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) unsigned char status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) const char *wp_fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) result = sddr09_read_status(us, &status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) usb_stor_dbg(us, "read_status fails\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) if ((status & 0x80) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) info->flags |= SDDR09_WP; /* write protected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) wp_fmt = " WP";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) wp_fmt = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) usb_stor_dbg(us, "status 0x%02X%s%s%s%s\n", status, wp_fmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) status & 0x40 ? " Ready" : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) status & LUNBITS ? " Suspended" : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) status & 0x01 ? " Error" : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) * Reset Command: 12 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) * byte 0: opcode: EB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) sddr09_reset(struct us_data *us) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) unsigned char *command = us->iobuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) memset(command, 0, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) command[0] = 0xEB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) command[1] = LUNBITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) return sddr09_send_scsi_command(us, command, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) static struct nand_flash_dev *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) sddr09_get_cardinfo(struct us_data *us, unsigned char flags) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) struct nand_flash_dev *cardinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) unsigned char deviceID[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) char blurbtxt[256];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) usb_stor_dbg(us, "Reading capacity...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) result = sddr09_read_deviceID(us, deviceID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) usb_stor_dbg(us, "Result of read_deviceID is %d\n", result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) printk(KERN_WARNING "sddr09: could not read card info\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) sprintf(blurbtxt, "sddr09: Found Flash card, ID = %4ph", deviceID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) /* Byte 0 is the manufacturer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) sprintf(blurbtxt + strlen(blurbtxt),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) ": Manuf. %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) nand_flash_manufacturer(deviceID[0]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) /* Byte 1 is the device type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) cardinfo = nand_find_id(deviceID[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) if (cardinfo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) * MB or MiB? It is neither. A 16 MB card has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) * 17301504 raw bytes, of which 16384000 are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) * usable for user data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) sprintf(blurbtxt + strlen(blurbtxt),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) ", %d MB", 1<<(cardinfo->chipshift - 20));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) sprintf(blurbtxt + strlen(blurbtxt),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) ", type unrecognized");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) /* Byte 2 is code to signal availability of 128-bit ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) if (deviceID[2] == 0xa5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) sprintf(blurbtxt + strlen(blurbtxt),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) ", 128-bit ID");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) /* Byte 3 announces the availability of another read ID command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) if (deviceID[3] == 0xc0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) sprintf(blurbtxt + strlen(blurbtxt),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) ", extra cmd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) if (flags & SDDR09_WP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) sprintf(blurbtxt + strlen(blurbtxt),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) ", WP");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) printk(KERN_WARNING "%s\n", blurbtxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) return cardinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) sddr09_read_map(struct us_data *us) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) struct sddr09_card_info *info = (struct sddr09_card_info *) us->extra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) int numblocks, alloc_len, alloc_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) int i, j, result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) unsigned char *buffer, *buffer_end, *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) unsigned int lba, lbact;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) if (!info->capacity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) * size of a block is 1 << (blockshift + pageshift) bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) * divide into the total capacity to get the number of blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) numblocks = info->capacity >> (info->blockshift + info->pageshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) * read 64 bytes for every block (actually 1 << CONTROL_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) * but only use a 64 KB buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) * buffer size used must be a multiple of (1 << CONTROL_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) #define SDDR09_READ_MAP_BUFSZ 65536
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) alloc_blocks = min(numblocks, SDDR09_READ_MAP_BUFSZ >> CONTROL_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) alloc_len = (alloc_blocks << CONTROL_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) buffer = kmalloc(alloc_len, GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) if (!buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) result = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) buffer_end = buffer + alloc_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) #undef SDDR09_READ_MAP_BUFSZ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) kfree(info->lba_to_pba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) kfree(info->pba_to_lba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) info->lba_to_pba = kmalloc_array(numblocks, sizeof(int), GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) info->pba_to_lba = kmalloc_array(numblocks, sizeof(int), GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) if (info->lba_to_pba == NULL || info->pba_to_lba == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) printk(KERN_WARNING "sddr09_read_map: out of memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) result = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) for (i = 0; i < numblocks; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) info->lba_to_pba[i] = info->pba_to_lba[i] = UNDEF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) * Define lba-pba translation table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) ptr = buffer_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) for (i = 0; i < numblocks; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) ptr += (1 << CONTROL_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) if (ptr >= buffer_end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) unsigned long address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) address = i << (info->pageshift + info->blockshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) result = sddr09_read_control(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) us, address>>1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) min(alloc_blocks, numblocks - i),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) buffer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) result = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) ptr = buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) if (i == 0 || i == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) info->pba_to_lba[i] = UNUSABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) /* special PBAs have control field 0^16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) for (j = 0; j < 16; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) if (ptr[j] != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) goto nonz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) info->pba_to_lba[i] = UNUSABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) printk(KERN_WARNING "sddr09: PBA %d has no logical mapping\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) nonz:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) /* unwritten PBAs have control field FF^16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) for (j = 0; j < 16; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) if (ptr[j] != 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) goto nonff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) nonff:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) /* normal PBAs start with six FFs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) if (j < 6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) printk(KERN_WARNING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) "sddr09: PBA %d has no logical mapping: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) "reserved area = %02X%02X%02X%02X "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) "data status %02X block status %02X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) i, ptr[0], ptr[1], ptr[2], ptr[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) ptr[4], ptr[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) info->pba_to_lba[i] = UNUSABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) if ((ptr[6] >> 4) != 0x01) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) printk(KERN_WARNING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) "sddr09: PBA %d has invalid address field "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) "%02X%02X/%02X%02X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) i, ptr[6], ptr[7], ptr[11], ptr[12]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) info->pba_to_lba[i] = UNUSABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) /* check even parity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) if (parity[ptr[6] ^ ptr[7]]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) printk(KERN_WARNING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) "sddr09: Bad parity in LBA for block %d"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) " (%02X %02X)\n", i, ptr[6], ptr[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) info->pba_to_lba[i] = UNUSABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) lba = short_pack(ptr[7], ptr[6]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) lba = (lba & 0x07FF) >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) * Every 1024 physical blocks ("zone"), the LBA numbers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) * go back to zero, but are within a higher block of LBA's.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) * Also, there is a maximum of 1000 LBA's per zone.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) * In other words, in PBA 1024-2047 you will find LBA 0-999
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) * which are really LBA 1000-1999. This allows for 24 bad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) * or special physical blocks per zone.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) if (lba >= 1000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) printk(KERN_WARNING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) "sddr09: Bad low LBA %d for block %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) lba, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) goto possibly_erase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) lba += 1000*(i/0x400);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) if (info->lba_to_pba[lba] != UNDEF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) printk(KERN_WARNING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) "sddr09: LBA %d seen for PBA %d and %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) lba, info->lba_to_pba[lba], i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) goto possibly_erase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) info->pba_to_lba[i] = lba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) info->lba_to_pba[lba] = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) possibly_erase:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) if (erase_bad_lba_entries) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) unsigned long address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) address = (i << (info->pageshift + info->blockshift));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) sddr09_erase(us, address>>1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) info->pba_to_lba[i] = UNDEF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) info->pba_to_lba[i] = UNUSABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) * Approximate capacity. This is not entirely correct yet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) * since a zone with less than 1000 usable pages leads to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) * missing LBAs. Especially if it is the last zone, some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) * LBAs can be past capacity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) lbact = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) for (i = 0; i < numblocks; i += 1024) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) int ct = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) for (j = 0; j < 1024 && i+j < numblocks; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) if (info->pba_to_lba[i+j] != UNUSABLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) if (ct >= 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) info->pba_to_lba[i+j] = SPARE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) ct++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) lbact += ct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) info->lbact = lbact;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) usb_stor_dbg(us, "Found %d LBA's\n", lbact);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) if (result != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) kfree(info->lba_to_pba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) kfree(info->pba_to_lba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) info->lba_to_pba = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) info->pba_to_lba = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) kfree(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) sddr09_card_info_destructor(void *extra) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) struct sddr09_card_info *info = (struct sddr09_card_info *)extra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) kfree(info->lba_to_pba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) kfree(info->pba_to_lba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) sddr09_common_init(struct us_data *us) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) /* set the configuration -- STALL is an acceptable response here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) if (us->pusb_dev->actconfig->desc.bConfigurationValue != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) usb_stor_dbg(us, "active config #%d != 1 ??\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) us->pusb_dev->actconfig->desc.bConfigurationValue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) result = usb_reset_configuration(us->pusb_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) usb_stor_dbg(us, "Result of usb_reset_configuration is %d\n", result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) if (result == -EPIPE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) usb_stor_dbg(us, "-- stall on control interface\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) } else if (result != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) /* it's not a stall, but another error -- time to bail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) usb_stor_dbg(us, "-- Unknown error. Rejecting device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) us->extra = kzalloc(sizeof(struct sddr09_card_info), GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) if (!us->extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) us->extra_destructor = sddr09_card_info_destructor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) nand_init_ecc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) * This is needed at a very early stage. If this is not listed in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) * unusual devices list but called from here then LUN 0 of the combo reader
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) * is not recognized. But I do not know what precisely these calls do.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) usb_stor_sddr09_dpcm_init(struct us_data *us) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) unsigned char *data = us->iobuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) result = sddr09_common_init(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) result = sddr09_send_command(us, 0x01, USB_DIR_IN, data, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) usb_stor_dbg(us, "send_command fails\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) usb_stor_dbg(us, "%02X %02X\n", data[0], data[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) // get 07 02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) result = sddr09_send_command(us, 0x08, USB_DIR_IN, data, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) usb_stor_dbg(us, "2nd send_command fails\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) usb_stor_dbg(us, "%02X %02X\n", data[0], data[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) // get 07 00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) result = sddr09_request_sense(us, data, 18);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) if (result == 0 && data[2] != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) int j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) for (j=0; j<18; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) printk(" %02X", data[j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) printk("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) // get 70 00 00 00 00 00 00 * 00 00 00 00 00 00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) // 70: current command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) // sense key 0, sense code 0, extd sense code 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) // additional transfer length * = sizeof(data) - 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) // Or: 70 00 06 00 00 00 00 0b 00 00 00 00 28 00 00 00 00 00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) // sense key 06, sense code 28: unit attention,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) // not ready to ready transition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) // test unit ready
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) return 0; /* not result */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) * Transport for the Microtech DPCM-USB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) static int dpcm_transport(struct scsi_cmnd *srb, struct us_data *us)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) usb_stor_dbg(us, "LUN=%d\n", (u8)srb->device->lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) switch (srb->device->lun) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) * LUN 0 corresponds to the CompactFlash card reader.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) ret = usb_stor_CB_transport(srb, us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) * LUN 1 corresponds to the SmartMedia card reader.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) * Set the LUN to 0 (just in case).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) srb->device->lun = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) ret = sddr09_transport(srb, us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) srb->device->lun = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) usb_stor_dbg(us, "Invalid LUN %d\n", (u8)srb->device->lun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) ret = USB_STOR_TRANSPORT_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) * Transport for the Sandisk SDDR-09
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) static int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) static unsigned char sensekey = 0, sensecode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) static unsigned char havefakesense = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) int result, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) unsigned char *ptr = us->iobuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) unsigned long capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) unsigned int page, pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) struct sddr09_card_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) static unsigned char inquiry_response[8] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 0x00, 0x80, 0x00, 0x02, 0x1F, 0x00, 0x00, 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) /* note: no block descriptor support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) static unsigned char mode_page_01[19] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 0x00, 0x0F, 0x00, 0x0, 0x0, 0x0, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 0x01, 0x0A,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) info = (struct sddr09_card_info *)us->extra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) if (srb->cmnd[0] == REQUEST_SENSE && havefakesense) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) /* for a faked command, we have to follow with a faked sense */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) memset(ptr, 0, 18);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) ptr[0] = 0x70;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) ptr[2] = sensekey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) ptr[7] = 11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) ptr[12] = sensecode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) usb_stor_set_xfer_buf(ptr, 18, srb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) sensekey = sensecode = havefakesense = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) return USB_STOR_TRANSPORT_GOOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) havefakesense = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) * Dummy up a response for INQUIRY since SDDR09 doesn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) * respond to INQUIRY commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) if (srb->cmnd[0] == INQUIRY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) memcpy(ptr, inquiry_response, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) fill_inquiry_response(us, ptr, 36);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) return USB_STOR_TRANSPORT_GOOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) if (srb->cmnd[0] == READ_CAPACITY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) struct nand_flash_dev *cardinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) sddr09_get_wp(us, info); /* read WP bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) cardinfo = sddr09_get_cardinfo(us, info->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) if (!cardinfo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) /* probably no media */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) init_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) sensekey = 0x02; /* not ready */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) sensecode = 0x3a; /* medium not present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) return USB_STOR_TRANSPORT_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) info->capacity = (1 << cardinfo->chipshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) info->pageshift = cardinfo->pageshift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) info->pagesize = (1 << info->pageshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) info->blockshift = cardinfo->blockshift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) info->blocksize = (1 << info->blockshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) info->blockmask = info->blocksize - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) // map initialization, must follow get_cardinfo()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) if (sddr09_read_map(us)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) /* probably out of memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) goto init_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) // Report capacity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) capacity = (info->lbact << info->blockshift) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) ((__be32 *) ptr)[0] = cpu_to_be32(capacity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) // Report page size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) ((__be32 *) ptr)[1] = cpu_to_be32(info->pagesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) usb_stor_set_xfer_buf(ptr, 8, srb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) return USB_STOR_TRANSPORT_GOOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) if (srb->cmnd[0] == MODE_SENSE_10) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) int modepage = (srb->cmnd[2] & 0x3F);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) * They ask for the Read/Write error recovery page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) * or for all pages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) /* %% We should check DBD %% */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) if (modepage == 0x01 || modepage == 0x3F) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) usb_stor_dbg(us, "Dummy up request for mode page 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) modepage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) memcpy(ptr, mode_page_01, sizeof(mode_page_01));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) ((__be16*)ptr)[0] = cpu_to_be16(sizeof(mode_page_01) - 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) ptr[3] = (info->flags & SDDR09_WP) ? 0x80 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) usb_stor_set_xfer_buf(ptr, sizeof(mode_page_01), srb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) return USB_STOR_TRANSPORT_GOOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) sensekey = 0x05; /* illegal request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) sensecode = 0x24; /* invalid field in CDB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) return USB_STOR_TRANSPORT_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) if (srb->cmnd[0] == ALLOW_MEDIUM_REMOVAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) return USB_STOR_TRANSPORT_GOOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) havefakesense = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) if (srb->cmnd[0] == READ_10) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) page = short_pack(srb->cmnd[3], srb->cmnd[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) page <<= 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) page |= short_pack(srb->cmnd[5], srb->cmnd[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) pages = short_pack(srb->cmnd[8], srb->cmnd[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) usb_stor_dbg(us, "READ_10: read page %d pagect %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) page, pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) result = sddr09_read_data(us, page, pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) return (result == 0 ? USB_STOR_TRANSPORT_GOOD :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) USB_STOR_TRANSPORT_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) if (srb->cmnd[0] == WRITE_10) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) page = short_pack(srb->cmnd[3], srb->cmnd[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) page <<= 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) page |= short_pack(srb->cmnd[5], srb->cmnd[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) pages = short_pack(srb->cmnd[8], srb->cmnd[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) usb_stor_dbg(us, "WRITE_10: write page %d pagect %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) page, pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) result = sddr09_write_data(us, page, pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) return (result == 0 ? USB_STOR_TRANSPORT_GOOD :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) USB_STOR_TRANSPORT_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) * catch-all for all other commands, except
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) * pass TEST_UNIT_READY and REQUEST_SENSE through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) if (srb->cmnd[0] != TEST_UNIT_READY &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) srb->cmnd[0] != REQUEST_SENSE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) sensekey = 0x05; /* illegal request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) sensecode = 0x20; /* invalid command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) havefakesense = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) return USB_STOR_TRANSPORT_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) for (; srb->cmd_len<12; srb->cmd_len++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) srb->cmnd[srb->cmd_len] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) srb->cmnd[1] = LUNBITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) ptr[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) for (i=0; i<12; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) sprintf(ptr+strlen(ptr), "%02X ", srb->cmnd[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) usb_stor_dbg(us, "Send control for command %s\n", ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) result = sddr09_send_scsi_command(us, srb->cmnd, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) usb_stor_dbg(us, "sddr09_send_scsi_command returns %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) return USB_STOR_TRANSPORT_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) if (scsi_bufflen(srb) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) return USB_STOR_TRANSPORT_GOOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) if (srb->sc_data_direction == DMA_TO_DEVICE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) srb->sc_data_direction == DMA_FROM_DEVICE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) unsigned int pipe = (srb->sc_data_direction == DMA_TO_DEVICE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) ? us->send_bulk_pipe : us->recv_bulk_pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) usb_stor_dbg(us, "%s %d bytes\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) (srb->sc_data_direction == DMA_TO_DEVICE) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) "sending" : "receiving",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) scsi_bufflen(srb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) result = usb_stor_bulk_srb(us, pipe, srb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) return (result == USB_STOR_XFER_GOOD ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) USB_STOR_TRANSPORT_GOOD : USB_STOR_TRANSPORT_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) return USB_STOR_TRANSPORT_GOOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) * Initialization routine for the sddr09 subdriver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) usb_stor_sddr09_init(struct us_data *us) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) return sddr09_common_init(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) static struct scsi_host_template sddr09_host_template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) static int sddr09_probe(struct usb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) struct us_data *us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) result = usb_stor_probe1(&us, intf, id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) (id - sddr09_usb_ids) + sddr09_unusual_dev_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) &sddr09_host_template);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) if (us->protocol == USB_PR_DPCM_USB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) us->transport_name = "Control/Bulk-EUSB/SDDR09";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) us->transport = dpcm_transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) us->transport_reset = usb_stor_CB_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) us->max_lun = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) us->transport_name = "EUSB/SDDR09";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) us->transport = sddr09_transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) us->transport_reset = usb_stor_CB_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) us->max_lun = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) result = usb_stor_probe2(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) static struct usb_driver sddr09_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) .name = DRV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) .probe = sddr09_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) .disconnect = usb_stor_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) .suspend = usb_stor_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) .resume = usb_stor_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) .reset_resume = usb_stor_reset_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) .pre_reset = usb_stor_pre_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) .post_reset = usb_stor_post_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) .id_table = sddr09_usb_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) .soft_unbind = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) .no_dynamic_id = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) module_usb_stor_driver(sddr09_driver, sddr09_host_template, DRV_NAME);