usb.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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/usb_usual.h>
  47. #include <linux/blkdev.h>
  48. #include <linux/smp_lock.h>
  49. #include <linux/completion.h>
  50. #include <linux/mutex.h>
  51. #include <scsi/scsi_host.h>
  52. struct us_data;
  53. struct scsi_cmnd;
  54. /*
  55. * Unusual device list definitions
  56. */
  57. struct us_unusual_dev {
  58. const char* vendorName;
  59. const char* productName;
  60. __u8 useProtocol;
  61. __u8 useTransport;
  62. int (*initFunction)(struct us_data *);
  63. };
  64. /* Dynamic flag definitions: used in set_bit() etc. */
  65. #define US_FLIDX_URB_ACTIVE 18 /* 0x00040000 current_urb is in use */
  66. #define US_FLIDX_SG_ACTIVE 19 /* 0x00080000 current_sg is in use */
  67. #define US_FLIDX_ABORTING 20 /* 0x00100000 abort is in progress */
  68. #define US_FLIDX_DISCONNECTING 21 /* 0x00200000 disconnect in progress */
  69. #define ABORTING_OR_DISCONNECTING ((1UL << US_FLIDX_ABORTING) | \
  70. (1UL << US_FLIDX_DISCONNECTING))
  71. #define US_FLIDX_RESETTING 22 /* 0x00400000 device reset in progress */
  72. #define US_FLIDX_TIMED_OUT 23 /* 0x00800000 SCSI midlayer timed out */
  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. /* The device we're working with
  92. * It's important to note:
  93. * (o) you must hold dev_mutex to change pusb_dev
  94. */
  95. struct mutex dev_mutex; /* protect pusb_dev */
  96. struct usb_device *pusb_dev; /* this usb_device */
  97. struct usb_interface *pusb_intf; /* this interface */
  98. struct us_unusual_dev *unusual_dev; /* device-filter entry */
  99. unsigned long flags; /* from filter initially */
  100. unsigned int send_bulk_pipe; /* cached pipe values */
  101. unsigned int recv_bulk_pipe;
  102. unsigned int send_ctrl_pipe;
  103. unsigned int recv_ctrl_pipe;
  104. unsigned int recv_intr_pipe;
  105. /* information about the device */
  106. char *transport_name;
  107. char *protocol_name;
  108. __le32 bcs_signature;
  109. u8 subclass;
  110. u8 protocol;
  111. u8 max_lun;
  112. u8 ifnum; /* interface number */
  113. u8 ep_bInterval; /* interrupt interval */
  114. /* function pointers for this device */
  115. trans_cmnd transport; /* transport function */
  116. trans_reset transport_reset; /* transport device reset */
  117. proto_cmnd proto_handler; /* protocol handler */
  118. /* SCSI interfaces */
  119. struct scsi_cmnd *srb; /* current srb */
  120. unsigned int tag; /* current dCBWTag */
  121. /* control and bulk communications data */
  122. struct urb *current_urb; /* USB requests */
  123. struct usb_ctrlrequest *cr; /* control requests */
  124. struct usb_sg_request current_sg; /* scatter-gather req. */
  125. unsigned char *iobuf; /* I/O buffer */
  126. unsigned char *sensebuf; /* sense data buffer */
  127. dma_addr_t cr_dma; /* buffer DMA addresses */
  128. dma_addr_t iobuf_dma;
  129. /* mutual exclusion and synchronization structures */
  130. struct semaphore sema; /* to sleep thread on */
  131. struct completion notify; /* thread begin/end */
  132. wait_queue_head_t delay_wait; /* wait during scan, reset */
  133. /* subdriver information */
  134. void *extra; /* Any extra data */
  135. extra_data_destructor extra_destructor;/* extra data destructor */
  136. #ifdef CONFIG_PM
  137. pm_hook suspend_resume_hook;
  138. #endif
  139. };
  140. /* Convert between us_data and the corresponding Scsi_Host */
  141. static struct Scsi_Host inline *us_to_host(struct us_data *us) {
  142. return container_of((void *) us, struct Scsi_Host, hostdata);
  143. }
  144. static struct us_data inline *host_to_us(struct Scsi_Host *host) {
  145. return (struct us_data *) host->hostdata;
  146. }
  147. /* Function to fill an inquiry response. See usb.c for details */
  148. extern void fill_inquiry_response(struct us_data *us,
  149. unsigned char *data, unsigned int data_len);
  150. /* The scsi_lock() and scsi_unlock() macros protect the sm_state and the
  151. * single queue element srb for write access */
  152. #define scsi_unlock(host) spin_unlock_irq(host->host_lock)
  153. #define scsi_lock(host) spin_lock_irq(host->host_lock)
  154. /* Vendor ID list for devices that require special handling */
  155. #define USB_VENDOR_ID_GENESYS 0x05e3 /* Genesys Logic */
  156. #endif