usb.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. * Driver for USB Mass Storage compliant devices
  3. * Main Header File
  4. *
  5. * Current development and maintenance by:
  6. * (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
  7. *
  8. * Initial work by:
  9. * (c) 1999 Michael Gee (michael@linuxspecific.com)
  10. *
  11. * This driver is based on the 'USB Mass Storage Class' document. This
  12. * describes in detail the protocol used to communicate with such
  13. * devices. Clearly, the designers had SCSI and ATAPI commands in
  14. * mind when they created this document. The commands are all very
  15. * similar to commands in the SCSI-II and ATAPI specifications.
  16. *
  17. * It is important to note that in a number of cases this class
  18. * exhibits class-specific exemptions from the USB specification.
  19. * Notably the usage of NAK, STALL and ACK differs from the norm, in
  20. * that they are used to communicate wait, failed and OK on commands.
  21. *
  22. * Also, for certain devices, the interrupt endpoint is used to convey
  23. * status of a command.
  24. *
  25. * Please see http://www.one-eyed-alien.net/~mdharm/linux-usb for more
  26. * information about this driver.
  27. *
  28. * This program is free software; you can redistribute it and/or modify it
  29. * under the terms of the GNU General Public License as published by the
  30. * Free Software Foundation; either version 2, or (at your option) any
  31. * later version.
  32. *
  33. * This program is distributed in the hope that it will be useful, but
  34. * WITHOUT ANY WARRANTY; without even the implied warranty of
  35. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  36. * General Public License for more details.
  37. *
  38. * You should have received a copy of the GNU General Public License along
  39. * with this program; if not, write to the Free Software Foundation, Inc.,
  40. * 675 Mass Ave, Cambridge, MA 02139, USA.
  41. */
  42. #ifndef _USB_H_
  43. #define _USB_H_
  44. #include <linux/usb.h>
  45. #include <linux/usb_usual.h>
  46. #include <linux/blkdev.h>
  47. #include <linux/completion.h>
  48. #include <linux/mutex.h>
  49. #include <linux/workqueue.h>
  50. #include <scsi/scsi_host.h>
  51. struct us_data;
  52. struct scsi_cmnd;
  53. /*
  54. * Unusual device list definitions
  55. */
  56. struct us_unusual_dev {
  57. const char* vendorName;
  58. const char* productName;
  59. __u8 useProtocol;
  60. __u8 useTransport;
  61. int (*initFunction)(struct us_data *);
  62. };
  63. /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
  64. #define US_FLIDX_URB_ACTIVE 0 /* current_urb is in use */
  65. #define US_FLIDX_SG_ACTIVE 1 /* current_sg is in use */
  66. #define US_FLIDX_ABORTING 2 /* abort is in progress */
  67. #define US_FLIDX_DISCONNECTING 3 /* disconnect in progress */
  68. #define US_FLIDX_RESETTING 4 /* device reset in progress */
  69. #define US_FLIDX_TIMED_OUT 5 /* SCSI midlayer timed out */
  70. #define US_FLIDX_SCAN_PENDING 6 /* scanning not yet done */
  71. #define US_FLIDX_REDO_READ10 7 /* redo READ(10) command */
  72. #define US_FLIDX_READ10_WORKED 8 /* previous READ(10) succeeded */
  73. #define USB_STOR_STRING_LEN 32
  74. /*
  75. * We provide a DMA-mapped I/O buffer for use with small USB transfers.
  76. * It turns out that CB[I] needs a 12-byte buffer and Bulk-only needs a
  77. * 31-byte buffer. But Freecom needs a 64-byte buffer, so that's the
  78. * size we'll allocate.
  79. */
  80. #define US_IOBUF_SIZE 64 /* Size of the DMA-mapped I/O buffer */
  81. #define US_SENSE_SIZE 18 /* Size of the autosense data buffer */
  82. typedef int (*trans_cmnd)(struct scsi_cmnd *, struct us_data*);
  83. typedef int (*trans_reset)(struct us_data*);
  84. typedef void (*proto_cmnd)(struct scsi_cmnd*, struct us_data*);
  85. typedef void (*extra_data_destructor)(void *); /* extra data destructor */
  86. typedef void (*pm_hook)(struct us_data *, int); /* power management hook */
  87. #define US_SUSPEND 0
  88. #define US_RESUME 1
  89. /* we allocate one of these for every device that we remember */
  90. struct us_data {
  91. /*
  92. * The device we're working with
  93. * It's important to note:
  94. * (o) you must hold dev_mutex to change pusb_dev
  95. */
  96. struct mutex dev_mutex; /* protect pusb_dev */
  97. struct usb_device *pusb_dev; /* this usb_device */
  98. struct usb_interface *pusb_intf; /* this interface */
  99. struct us_unusual_dev *unusual_dev; /* device-filter entry */
  100. unsigned long fflags; /* fixed flags from filter */
  101. unsigned long dflags; /* dynamic atomic bitflags */
  102. unsigned int send_bulk_pipe; /* cached pipe values */
  103. unsigned int recv_bulk_pipe;
  104. unsigned int send_ctrl_pipe;
  105. unsigned int recv_ctrl_pipe;
  106. unsigned int recv_intr_pipe;
  107. /* information about the device */
  108. char *transport_name;
  109. char *protocol_name;
  110. __le32 bcs_signature;
  111. u8 subclass;
  112. u8 protocol;
  113. u8 max_lun;
  114. u8 ifnum; /* interface number */
  115. u8 ep_bInterval; /* interrupt interval */
  116. /* function pointers for this device */
  117. trans_cmnd transport; /* transport function */
  118. trans_reset transport_reset; /* transport device reset */
  119. proto_cmnd proto_handler; /* protocol handler */
  120. /* SCSI interfaces */
  121. struct scsi_cmnd *srb; /* current srb */
  122. unsigned int tag; /* current dCBWTag */
  123. char scsi_name[32]; /* scsi_host name */
  124. /* control and bulk communications data */
  125. struct urb *current_urb; /* USB requests */
  126. struct usb_ctrlrequest *cr; /* control requests */
  127. struct usb_sg_request current_sg; /* scatter-gather req. */
  128. unsigned char *iobuf; /* I/O buffer */
  129. dma_addr_t iobuf_dma; /* buffer DMA addresses */
  130. struct task_struct *ctl_thread; /* the control thread */
  131. /* mutual exclusion and synchronization structures */
  132. struct completion cmnd_ready; /* to sleep thread on */
  133. struct completion notify; /* thread begin/end */
  134. wait_queue_head_t delay_wait; /* wait during reset */
  135. struct delayed_work scan_dwork; /* for async scanning */
  136. /* subdriver information */
  137. void *extra; /* Any extra data */
  138. extra_data_destructor extra_destructor;/* extra data destructor */
  139. #ifdef CONFIG_PM
  140. pm_hook suspend_resume_hook;
  141. #endif
  142. /* hacks for READ CAPACITY bug handling */
  143. int use_last_sector_hacks;
  144. int last_sector_retries;
  145. };
  146. /* Convert between us_data and the corresponding Scsi_Host */
  147. static inline struct Scsi_Host *us_to_host(struct us_data *us) {
  148. return container_of((void *) us, struct Scsi_Host, hostdata);
  149. }
  150. static inline struct us_data *host_to_us(struct Scsi_Host *host) {
  151. return (struct us_data *) host->hostdata;
  152. }
  153. /* Function to fill an inquiry response. See usb.c for details */
  154. extern void fill_inquiry_response(struct us_data *us,
  155. unsigned char *data, unsigned int data_len);
  156. /*
  157. * The scsi_lock() and scsi_unlock() macros protect the sm_state and the
  158. * single queue element srb for write access
  159. */
  160. #define scsi_unlock(host) spin_unlock_irq(host->host_lock)
  161. #define scsi_lock(host) spin_lock_irq(host->host_lock)
  162. /* General routines provided by the usb-storage standard core */
  163. #ifdef CONFIG_PM
  164. extern int usb_stor_suspend(struct usb_interface *iface, pm_message_t message);
  165. extern int usb_stor_resume(struct usb_interface *iface);
  166. extern int usb_stor_reset_resume(struct usb_interface *iface);
  167. #else
  168. #define usb_stor_suspend NULL
  169. #define usb_stor_resume NULL
  170. #define usb_stor_reset_resume NULL
  171. #endif
  172. extern int usb_stor_pre_reset(struct usb_interface *iface);
  173. extern int usb_stor_post_reset(struct usb_interface *iface);
  174. extern int usb_stor_probe1(struct us_data **pus,
  175. struct usb_interface *intf,
  176. const struct usb_device_id *id,
  177. struct us_unusual_dev *unusual_dev,
  178. struct scsi_host_template *sht);
  179. extern int usb_stor_probe2(struct us_data *us);
  180. extern void usb_stor_disconnect(struct usb_interface *intf);
  181. extern void usb_stor_adjust_quirks(struct usb_device *dev,
  182. unsigned long *fflags);
  183. #define module_usb_stor_driver(__driver, __sht, __name) \
  184. static int __init __driver##_init(void) \
  185. { \
  186. usb_stor_host_template_init(&(__sht), __name, THIS_MODULE); \
  187. return usb_register(&(__driver)); \
  188. } \
  189. module_init(__driver##_init); \
  190. static void __exit __driver##_exit(void) \
  191. { \
  192. usb_deregister(&(__driver)); \
  193. } \
  194. module_exit(__driver##_exit)
  195. #endif