usb.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /* Driver for USB Mass Storage compliant devices
  2. * Main Header File
  3. *
  4. * $Id: usb.h,v 1.21 2002/04/21 02:57:59 mdharm Exp $
  5. *
  6. * Current development and maintenance by:
  7. * (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
  8. *
  9. * Initial work by:
  10. * (c) 1999 Michael Gee (michael@linuxspecific.com)
  11. *
  12. * This driver is based on the 'USB Mass Storage Class' document. This
  13. * describes in detail the protocol used to communicate with such
  14. * devices. Clearly, the designers had SCSI and ATAPI commands in
  15. * mind when they created this document. The commands are all very
  16. * similar to commands in the SCSI-II and ATAPI specifications.
  17. *
  18. * It is important to note that in a number of cases this class
  19. * exhibits class-specific exemptions from the USB specification.
  20. * Notably the usage of NAK, STALL and ACK differs from the norm, in
  21. * that they are used to communicate wait, failed and OK on commands.
  22. *
  23. * Also, for certain devices, the interrupt endpoint is used to convey
  24. * status of a command.
  25. *
  26. * Please see http://www.one-eyed-alien.net/~mdharm/linux-usb for more
  27. * information about this driver.
  28. *
  29. * This program is free software; you can redistribute it and/or modify it
  30. * under the terms of the GNU General Public License as published by the
  31. * Free Software Foundation; either version 2, or (at your option) any
  32. * later version.
  33. *
  34. * This program is distributed in the hope that it will be useful, but
  35. * WITHOUT ANY WARRANTY; without even the implied warranty of
  36. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  37. * General Public License for more details.
  38. *
  39. * You should have received a copy of the GNU General Public License along
  40. * with this program; if not, write to the Free Software Foundation, Inc.,
  41. * 675 Mass Ave, Cambridge, MA 02139, USA.
  42. */
  43. #ifndef _USB_H_
  44. #define _USB_H_
  45. #include <linux/usb.h>
  46. #include <linux/blkdev.h>
  47. #include <linux/smp_lock.h>
  48. #include <linux/completion.h>
  49. #include <scsi/scsi_host.h>
  50. struct us_data;
  51. struct scsi_cmnd;
  52. /*
  53. * Unusual device list definitions
  54. */
  55. struct us_unusual_dev {
  56. const char* vendorName;
  57. const char* productName;
  58. __u8 useProtocol;
  59. __u8 useTransport;
  60. int (*initFunction)(struct us_data *);
  61. unsigned int flags;
  62. };
  63. /*
  64. * Static flag definitions. We use this roundabout technique so that the
  65. * proc_info() routine can automatically display a message for each flag.
  66. */
  67. #define US_DO_ALL_FLAGS \
  68. US_FLAG(SINGLE_LUN, 0x00000001) \
  69. /* allow access to only LUN 0 */ \
  70. US_FLAG(NEED_OVERRIDE, 0x00000002) \
  71. /* unusual_devs entry is necessary */ \
  72. US_FLAG(SCM_MULT_TARG, 0x00000004) \
  73. /* supports multiple targets */ \
  74. US_FLAG(FIX_INQUIRY, 0x00000008) \
  75. /* INQUIRY response needs faking */ \
  76. US_FLAG(FIX_CAPACITY, 0x00000010) \
  77. /* READ CAPACITY response too big */ \
  78. US_FLAG(IGNORE_RESIDUE, 0x00000020) \
  79. /* reported residue is wrong */ \
  80. US_FLAG(BULK32, 0x00000040) \
  81. /* Uses 32-byte CBW length */ \
  82. US_FLAG(NOT_LOCKABLE, 0x00000080) \
  83. /* PREVENT/ALLOW not supported */ \
  84. US_FLAG(GO_SLOW, 0x00000100) \
  85. /* Need delay after Command phase */ \
  86. US_FLAG(NO_WP_DETECT, 0x00000200) \
  87. /* Don't check for write-protect */ \
  88. #define US_FLAG(name, value) US_FL_##name = value ,
  89. enum { US_DO_ALL_FLAGS };
  90. #undef US_FLAG
  91. /* Dynamic flag definitions: used in set_bit() etc. */
  92. #define US_FLIDX_URB_ACTIVE 18 /* 0x00040000 current_urb is in use */
  93. #define US_FLIDX_SG_ACTIVE 19 /* 0x00080000 current_sg is in use */
  94. #define US_FLIDX_ABORTING 20 /* 0x00100000 abort is in progress */
  95. #define US_FLIDX_DISCONNECTING 21 /* 0x00200000 disconnect in progress */
  96. #define ABORTING_OR_DISCONNECTING ((1UL << US_FLIDX_ABORTING) | \
  97. (1UL << US_FLIDX_DISCONNECTING))
  98. #define US_FLIDX_RESETTING 22 /* 0x00400000 device reset in progress */
  99. #define US_FLIDX_TIMED_OUT 23 /* 0x00800000 SCSI midlayer timed out */
  100. #define USB_STOR_STRING_LEN 32
  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. #define US_IOBUF_SIZE 64 /* Size of the DMA-mapped I/O buffer */
  108. typedef int (*trans_cmnd)(struct scsi_cmnd *, struct us_data*);
  109. typedef int (*trans_reset)(struct us_data*);
  110. typedef void (*proto_cmnd)(struct scsi_cmnd*, struct us_data*);
  111. typedef void (*extra_data_destructor)(void *); /* extra data destructor */
  112. /* we allocate one of these for every device that we remember */
  113. struct us_data {
  114. /* The device we're working with
  115. * It's important to note:
  116. * (o) you must hold dev_semaphore to change pusb_dev
  117. */
  118. struct semaphore dev_semaphore; /* protect pusb_dev */
  119. struct usb_device *pusb_dev; /* this usb_device */
  120. struct usb_interface *pusb_intf; /* this interface */
  121. struct us_unusual_dev *unusual_dev; /* device-filter entry */
  122. unsigned long flags; /* from filter initially */
  123. unsigned int send_bulk_pipe; /* cached pipe values */
  124. unsigned int recv_bulk_pipe;
  125. unsigned int send_ctrl_pipe;
  126. unsigned int recv_ctrl_pipe;
  127. unsigned int recv_intr_pipe;
  128. /* information about the device */
  129. char *transport_name;
  130. char *protocol_name;
  131. __le32 bcs_signature;
  132. u8 subclass;
  133. u8 protocol;
  134. u8 max_lun;
  135. u8 ifnum; /* interface number */
  136. u8 ep_bInterval; /* interrupt interval */
  137. /* function pointers for this device */
  138. trans_cmnd transport; /* transport function */
  139. trans_reset transport_reset; /* transport device reset */
  140. proto_cmnd proto_handler; /* protocol handler */
  141. /* SCSI interfaces */
  142. struct scsi_cmnd *srb; /* current srb */
  143. unsigned int tag; /* current dCBWTag */
  144. /* thread information */
  145. int pid; /* control thread */
  146. /* control and bulk communications data */
  147. struct urb *current_urb; /* USB requests */
  148. struct usb_ctrlrequest *cr; /* control requests */
  149. struct usb_sg_request current_sg; /* scatter-gather req. */
  150. unsigned char *iobuf; /* I/O buffer */
  151. dma_addr_t cr_dma; /* buffer DMA addresses */
  152. dma_addr_t iobuf_dma;
  153. /* mutual exclusion and synchronization structures */
  154. struct semaphore sema; /* to sleep thread on */
  155. struct completion notify; /* thread begin/end */
  156. wait_queue_head_t delay_wait; /* wait during scan, reset */
  157. /* subdriver information */
  158. void *extra; /* Any extra data */
  159. extra_data_destructor extra_destructor;/* extra data destructor */
  160. };
  161. /* Convert between us_data and the corresponding Scsi_Host */
  162. static struct Scsi_Host inline *us_to_host(struct us_data *us) {
  163. return container_of((void *) us, struct Scsi_Host, hostdata);
  164. }
  165. static struct us_data inline *host_to_us(struct Scsi_Host *host) {
  166. return (struct us_data *) host->hostdata;
  167. }
  168. /* Function to fill an inquiry response. See usb.c for details */
  169. extern void fill_inquiry_response(struct us_data *us,
  170. unsigned char *data, unsigned int data_len);
  171. /* The scsi_lock() and scsi_unlock() macros protect the sm_state and the
  172. * single queue element srb for write access */
  173. #define scsi_unlock(host) spin_unlock_irq(host->host_lock)
  174. #define scsi_lock(host) spin_lock_irq(host->host_lock)
  175. /* Vendor ID list for devices that require special handling */
  176. #define USB_VENDOR_ID_GENESYS 0x05e3 /* Genesys Logic */
  177. #endif