usb.h 7.0 KB

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