Amarjargal Gundjalam | 1557a64 | 2013-05-17 01:06:05 -0700 | [diff] [blame] | 1 | /* Driver for USB Mass Storage compliant devices */ |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 2 | |
| 3 | #ifndef _USB_H_ |
| 4 | #define _USB_H_ |
| 5 | |
| 6 | #include <linux/usb.h> |
| 7 | #include <linux/usb_usual.h> |
| 8 | #include <linux/blkdev.h> |
| 9 | #include <linux/completion.h> |
| 10 | #include <linux/mutex.h> |
| 11 | #include <scsi/scsi_host.h> |
| 12 | #include "common.h" |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 13 | |
| 14 | struct us_data; |
| 15 | struct scsi_cmnd; |
| 16 | |
| 17 | /* |
| 18 | * Unusual device list definitions |
| 19 | */ |
| 20 | |
| 21 | struct us_unusual_dev { |
Johannes Schilling | 0ea8a16 | 2013-06-06 18:10:50 +0200 | [diff] [blame] | 22 | const char *vendorName; |
| 23 | const char *productName; |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 24 | __u8 useProtocol; |
| 25 | __u8 useTransport; |
| 26 | int (*initFunction)(struct us_data *); |
| 27 | }; |
| 28 | |
Amarjargal Gundjalam | 1557a64 | 2013-05-17 01:06:05 -0700 | [diff] [blame] | 29 | /* EnE HW Register */ |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 30 | #define REG_CARD_STATUS 0xFF83 |
| 31 | #define REG_HW_TRAP1 0xFF89 |
| 32 | |
Amarjargal Gundjalam | 1557a64 | 2013-05-17 01:06:05 -0700 | [diff] [blame] | 33 | /* SRB Status. Refers /usr/include/wine/wine/wnaspi32.h & SCSI sense key */ |
| 34 | #define SS_SUCCESS 0x00 /* No Sense */ |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 35 | #define SS_NOT_READY 0x02 |
| 36 | #define SS_MEDIUM_ERR 0x03 |
| 37 | #define SS_HW_ERR 0x04 |
| 38 | #define SS_ILLEGAL_REQUEST 0x05 |
| 39 | #define SS_UNIT_ATTENTION 0x06 |
| 40 | |
Amarjargal Gundjalam | 1557a64 | 2013-05-17 01:06:05 -0700 | [diff] [blame] | 41 | /* ENE Load FW Pattern */ |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 42 | #define SD_INIT1_PATTERN 1 |
| 43 | #define SD_INIT2_PATTERN 2 |
| 44 | #define SD_RW_PATTERN 3 |
| 45 | #define MS_INIT_PATTERN 4 |
| 46 | #define MSP_RW_PATTERN 5 |
| 47 | #define MS_RW_PATTERN 6 |
| 48 | #define SM_INIT_PATTERN 7 |
| 49 | #define SM_RW_PATTERN 8 |
| 50 | |
| 51 | #define FDIR_WRITE 0 |
| 52 | #define FDIR_READ 1 |
| 53 | |
Johannes Schilling | 8be8804 | 2013-06-06 18:10:45 +0200 | [diff] [blame] | 54 | struct keucr_sd_status { |
Amarjargal Gundjalam | 5a5097a | 2013-05-17 01:06:19 -0700 | [diff] [blame] | 55 | BYTE Insert:1; |
| 56 | BYTE Ready:1; |
| 57 | BYTE MediaChange:1; |
| 58 | BYTE IsMMC:1; |
| 59 | BYTE HiCapacity:1; |
| 60 | BYTE HiSpeed:1; |
| 61 | BYTE WtP:1; |
| 62 | BYTE Reserved:1; |
Johannes Schilling | 8be8804 | 2013-06-06 18:10:45 +0200 | [diff] [blame] | 63 | }; |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 64 | |
Johannes Schilling | 8be8804 | 2013-06-06 18:10:45 +0200 | [diff] [blame] | 65 | struct keucr_ms_status { |
Amarjargal Gundjalam | 5a5097a | 2013-05-17 01:06:19 -0700 | [diff] [blame] | 66 | BYTE Insert:1; |
| 67 | BYTE Ready:1; |
| 68 | BYTE MediaChange:1; |
| 69 | BYTE IsMSPro:1; |
| 70 | BYTE IsMSPHG:1; |
| 71 | BYTE Reserved1:1; |
| 72 | BYTE WtP:1; |
| 73 | BYTE Reserved2:1; |
Johannes Schilling | 8be8804 | 2013-06-06 18:10:45 +0200 | [diff] [blame] | 74 | }; |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 75 | |
Johannes Schilling | 8be8804 | 2013-06-06 18:10:45 +0200 | [diff] [blame] | 76 | struct keucr_sm_status { |
Amarjargal Gundjalam | 5a5097a | 2013-05-17 01:06:19 -0700 | [diff] [blame] | 77 | BYTE Insert:1; |
| 78 | BYTE Ready:1; |
| 79 | BYTE MediaChange:1; |
| 80 | BYTE Reserved:3; |
| 81 | BYTE WtP:1; |
| 82 | BYTE IsMS:1; |
Johannes Schilling | 8be8804 | 2013-06-06 18:10:45 +0200 | [diff] [blame] | 83 | }; |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 84 | |
Amarjargal Gundjalam | 1557a64 | 2013-05-17 01:06:05 -0700 | [diff] [blame] | 85 | /* SD Block Length */ |
| 86 | #define SD_BLOCK_LEN 9 /* 2^9 = 512 Bytes, |
| 87 | The HW maximum read/write data length */ |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 88 | |
| 89 | /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */ |
| 90 | #define US_FLIDX_URB_ACTIVE 0 /* current_urb is in use */ |
| 91 | #define US_FLIDX_SG_ACTIVE 1 /* current_sg is in use */ |
| 92 | #define US_FLIDX_ABORTING 2 /* abort is in progress */ |
| 93 | #define US_FLIDX_DISCONNECTING 3 /* disconnect in progress */ |
| 94 | #define US_FLIDX_RESETTING 4 /* device reset in progress */ |
| 95 | #define US_FLIDX_TIMED_OUT 5 /* SCSI midlayer timed out */ |
| 96 | #define US_FLIDX_DONT_SCAN 6 /* don't scan (disconnect) */ |
| 97 | |
| 98 | |
| 99 | #define USB_STOR_STRING_LEN 32 |
| 100 | |
| 101 | /* |
| 102 | * We provide a DMA-mapped I/O buffer for use with small USB transfers. |
| 103 | * It turns out that CB[I] needs a 12-byte buffer and Bulk-only needs a |
| 104 | * 31-byte buffer. But Freecom needs a 64-byte buffer, so that's the |
| 105 | * size we'll allocate. |
| 106 | */ |
| 107 | |
| 108 | #define US_IOBUF_SIZE 64 /* Size of the DMA-mapped I/O buffer */ |
| 109 | #define US_SENSE_SIZE 18 /* Size of the autosense data buffer */ |
| 110 | |
Johannes Schilling | 0ea8a16 | 2013-06-06 18:10:50 +0200 | [diff] [blame] | 111 | typedef int (*trans_cmnd)(struct scsi_cmnd *, struct us_data *); |
| 112 | typedef int (*trans_reset)(struct us_data *); |
| 113 | typedef void (*proto_cmnd)(struct scsi_cmnd *, struct us_data *); |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 114 | typedef void (*extra_data_destructor)(void *); /* extra data destructor */ |
| 115 | typedef void (*pm_hook)(struct us_data *, int); /* power management hook */ |
| 116 | |
| 117 | #define US_SUSPEND 0 |
| 118 | #define US_RESUME 1 |
| 119 | |
| 120 | /* we allocate one of these for every device that we remember */ |
| 121 | struct us_data { |
| 122 | /* The device we're working with |
| 123 | * It's important to note: |
| 124 | * (o) you must hold dev_mutex to change pusb_dev |
| 125 | */ |
| 126 | struct mutex dev_mutex; /* protect pusb_dev */ |
| 127 | struct usb_device *pusb_dev; /* this usb_device */ |
| 128 | struct usb_interface *pusb_intf; /* this interface */ |
| 129 | struct us_unusual_dev *unusual_dev; /* device-filter entry */ |
| 130 | unsigned long fflags; /* fixed flags from filter */ |
| 131 | unsigned long dflags; /* dynamic atomic bitflags */ |
| 132 | unsigned int send_bulk_pipe; /* cached pipe values */ |
| 133 | unsigned int recv_bulk_pipe; |
| 134 | unsigned int send_ctrl_pipe; |
| 135 | unsigned int recv_ctrl_pipe; |
| 136 | unsigned int recv_intr_pipe; |
| 137 | |
| 138 | /* information about the device */ |
| 139 | char *transport_name; |
| 140 | char *protocol_name; |
| 141 | __le32 bcs_signature; |
| 142 | u8 subclass; |
| 143 | u8 protocol; |
| 144 | u8 max_lun; |
| 145 | |
| 146 | u8 ifnum; /* interface number */ |
| 147 | u8 ep_bInterval; /* interrupt interval */ |
| 148 | |
| 149 | /* function pointers for this device */ |
| 150 | trans_cmnd transport; /* transport function */ |
| 151 | trans_reset transport_reset; /* transport device reset */ |
| 152 | proto_cmnd proto_handler; /* protocol handler */ |
| 153 | |
| 154 | /* SCSI interfaces */ |
| 155 | struct scsi_cmnd *srb; /* current srb */ |
| 156 | unsigned int tag; /* current dCBWTag */ |
| 157 | |
| 158 | /* control and bulk communications data */ |
| 159 | struct urb *current_urb; /* USB requests */ |
| 160 | struct usb_ctrlrequest *cr; /* control requests */ |
| 161 | struct usb_sg_request current_sg; /* scatter-gather req. */ |
| 162 | unsigned char *iobuf; /* I/O buffer */ |
| 163 | unsigned char *sensebuf; /* sense data buffer */ |
| 164 | dma_addr_t cr_dma; /* buffer DMA addresses */ |
| 165 | dma_addr_t iobuf_dma; |
| 166 | struct task_struct *ctl_thread; /* the control thread */ |
| 167 | |
| 168 | /* mutual exclusion and synchronization structures */ |
| 169 | struct completion cmnd_ready; /* to sleep thread on */ |
| 170 | struct completion notify; /* thread begin/end */ |
| 171 | wait_queue_head_t delay_wait; /* wait during scan, reset */ |
| 172 | struct completion scanning_done; /* wait for scan thread */ |
| 173 | |
| 174 | /* subdriver information */ |
| 175 | void *extra; /* Any extra data */ |
| 176 | extra_data_destructor extra_destructor;/* extra data destructor */ |
| 177 | #ifdef CONFIG_PM |
| 178 | pm_hook suspend_resume_hook; |
| 179 | #endif |
Amarjargal Gundjalam | 1557a64 | 2013-05-17 01:06:05 -0700 | [diff] [blame] | 180 | /* for 6250 code */ |
Johannes Schilling | 8be8804 | 2013-06-06 18:10:45 +0200 | [diff] [blame] | 181 | struct keucr_sd_status SD_Status; |
| 182 | struct keucr_ms_status MS_Status; |
| 183 | struct keucr_sm_status SM_Status; |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 184 | |
Amarjargal Gundjalam | 1557a64 | 2013-05-17 01:06:05 -0700 | [diff] [blame] | 185 | /* ----- SD Control Data ---------------- */ |
| 186 | /* SD_REGISTER SD_Regs; */ |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 187 | WORD SD_Block_Mult; |
| 188 | BYTE SD_READ_BL_LEN; |
| 189 | WORD SD_C_SIZE; |
| 190 | BYTE SD_C_SIZE_MULT; |
| 191 | |
Amarjargal Gundjalam | 1557a64 | 2013-05-17 01:06:05 -0700 | [diff] [blame] | 192 | /* SD/MMC New spec. */ |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 193 | BYTE SD_SPEC_VER; |
| 194 | BYTE SD_CSD_VER; |
| 195 | BYTE SD20_HIGH_CAPACITY; |
| 196 | DWORD HC_C_SIZE; |
| 197 | BYTE MMC_SPEC_VER; |
| 198 | BYTE MMC_BusWidth; |
| 199 | BYTE MMC_HIGH_CAPACITY; |
Amarjargal Gundjalam | 4f3fff7 | 2013-05-17 01:06:36 -0700 | [diff] [blame] | 200 | |
Amarjargal Gundjalam | 1557a64 | 2013-05-17 01:06:05 -0700 | [diff] [blame] | 201 | /* ----- MS Control Data ---------------- */ |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 202 | BOOLEAN MS_SWWP; |
| 203 | DWORD MSP_TotalBlock; |
Cho, Yu-Chen | 20c3d7f | 2011-07-07 11:27:14 +0800 | [diff] [blame] | 204 | /* MS_LibControl MS_Lib; */ |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 205 | BOOLEAN MS_IsRWPage; |
| 206 | WORD MS_Model; |
| 207 | |
Amarjargal Gundjalam | 1557a64 | 2013-05-17 01:06:05 -0700 | [diff] [blame] | 208 | /* ----- SM Control Data ---------------- */ |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 209 | BYTE SM_DeviceID; |
| 210 | BYTE SM_CardID; |
| 211 | |
| 212 | PBYTE testbuf; |
| 213 | BYTE BIN_FLAG; |
| 214 | DWORD bl_num; |
| 215 | int SrbStatus; |
Amarjargal Gundjalam | 4f3fff7 | 2013-05-17 01:06:36 -0700 | [diff] [blame] | 216 | |
Amarjargal Gundjalam | 1557a64 | 2013-05-17 01:06:05 -0700 | [diff] [blame] | 217 | /* ------Power Managerment --------------- */ |
Johannes Schilling | 0ea8a16 | 2013-06-06 18:10:50 +0200 | [diff] [blame] | 218 | BOOLEAN Power_IsResum; |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 219 | }; |
| 220 | |
| 221 | /* Convert between us_data and the corresponding Scsi_Host */ |
Amarjargal Gundjalam | c41d74c | 2013-05-17 01:03:41 -0700 | [diff] [blame] | 222 | static inline struct Scsi_Host *us_to_host(struct us_data *us) |
| 223 | { |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 224 | return container_of((void *) us, struct Scsi_Host, hostdata); |
| 225 | } |
Amarjargal Gundjalam | c41d74c | 2013-05-17 01:03:41 -0700 | [diff] [blame] | 226 | static inline struct us_data *host_to_us(struct Scsi_Host *host) |
| 227 | { |
Al Cho | 126bb03 | 2010-09-08 00:42:32 -0700 | [diff] [blame] | 228 | return (struct us_data *) host->hostdata; |
| 229 | } |
| 230 | |
| 231 | /* Function to fill an inquiry response. See usb.c for details */ |
| 232 | extern void fill_inquiry_response(struct us_data *us, |
| 233 | unsigned char *data, unsigned int data_len); |
| 234 | |
| 235 | /* The scsi_lock() and scsi_unlock() macros protect the sm_state and the |
| 236 | * single queue element srb for write access */ |
| 237 | #define scsi_unlock(host) spin_unlock_irq(host->host_lock) |
| 238 | #define scsi_lock(host) spin_lock_irq(host->host_lock) |
| 239 | |
| 240 | #endif |