usb.h 7.1 KB

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