rt2x00usb.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
  3. <http://rt2x00.serialmonkey.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the
  14. Free Software Foundation, Inc.,
  15. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. /*
  18. Module: rt2x00usb
  19. Abstract: Data structures for the rt2x00usb module.
  20. */
  21. #ifndef RT2X00USB_H
  22. #define RT2X00USB_H
  23. /*
  24. * This variable should be used with the
  25. * usb_driver structure initialization.
  26. */
  27. #define USB_DEVICE_DATA(__ops) .driver_info = (kernel_ulong_t)(__ops)
  28. /*
  29. * Register defines.
  30. * Some registers require multiple attempts before success,
  31. * in those cases REGISTER_BUSY_COUNT attempts should be
  32. * taken with a REGISTER_BUSY_DELAY interval.
  33. * For USB vendor requests we need to pass a timeout
  34. * time in ms, for this we use the REGISTER_TIMEOUT,
  35. * however when loading firmware a higher value is
  36. * required. In that case we use the REGISTER_TIMEOUT_FIRMWARE.
  37. */
  38. #define REGISTER_BUSY_COUNT 5
  39. #define REGISTER_BUSY_DELAY 100
  40. #define REGISTER_TIMEOUT 500
  41. #define REGISTER_TIMEOUT_FIRMWARE 1000
  42. /**
  43. * REGISTER_TIMEOUT16 - Determine the timeout for 16bit register access
  44. * @__datalen: Data length
  45. */
  46. #define REGISTER_TIMEOUT16(__datalen) \
  47. ( REGISTER_TIMEOUT * ((__datalen) / sizeof(u16)) )
  48. /**
  49. * REGISTER_TIMEOUT32 - Determine the timeout for 32bit register access
  50. * @__datalen: Data length
  51. */
  52. #define REGISTER_TIMEOUT32(__datalen) \
  53. ( REGISTER_TIMEOUT * ((__datalen) / sizeof(u32)) )
  54. /*
  55. * Cache size
  56. */
  57. #define CSR_CACHE_SIZE 8
  58. #define CSR_CACHE_SIZE_FIRMWARE 64
  59. /*
  60. * USB request types.
  61. */
  62. #define USB_VENDOR_REQUEST ( USB_TYPE_VENDOR | USB_RECIP_DEVICE )
  63. #define USB_VENDOR_REQUEST_IN ( USB_DIR_IN | USB_VENDOR_REQUEST )
  64. #define USB_VENDOR_REQUEST_OUT ( USB_DIR_OUT | USB_VENDOR_REQUEST )
  65. /**
  66. * enum rt2x00usb_vendor_request: USB vendor commands.
  67. */
  68. enum rt2x00usb_vendor_request {
  69. USB_DEVICE_MODE = 1,
  70. USB_SINGLE_WRITE = 2,
  71. USB_SINGLE_READ = 3,
  72. USB_MULTI_WRITE = 6,
  73. USB_MULTI_READ = 7,
  74. USB_EEPROM_WRITE = 8,
  75. USB_EEPROM_READ = 9,
  76. USB_LED_CONTROL = 10, /* RT73USB */
  77. USB_RX_CONTROL = 12,
  78. };
  79. /**
  80. * enum rt2x00usb_mode_offset: Device modes offset.
  81. */
  82. enum rt2x00usb_mode_offset {
  83. USB_MODE_RESET = 1,
  84. USB_MODE_UNPLUG = 2,
  85. USB_MODE_FUNCTION = 3,
  86. USB_MODE_TEST = 4,
  87. USB_MODE_SLEEP = 7, /* RT73USB */
  88. USB_MODE_FIRMWARE = 8, /* RT73USB */
  89. USB_MODE_WAKEUP = 9, /* RT73USB */
  90. };
  91. /**
  92. * rt2x00usb_vendor_request - Send register command to device
  93. * @rt2x00dev: Pointer to &struct rt2x00_dev
  94. * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
  95. * @requesttype: Request type &USB_VENDOR_REQUEST_*
  96. * @offset: Register offset to perform action on
  97. * @value: Value to write to device
  98. * @buffer: Buffer where information will be read/written to by device
  99. * @buffer_length: Size of &buffer
  100. * @timeout: Operation timeout
  101. *
  102. * This is the main function to communicate with the device,
  103. * the &buffer argument _must_ either be NULL or point to
  104. * a buffer allocated by kmalloc. Failure to do so can lead
  105. * to unexpected behavior depending on the architecture.
  106. */
  107. int rt2x00usb_vendor_request(struct rt2x00_dev *rt2x00dev,
  108. const u8 request, const u8 requesttype,
  109. const u16 offset, const u16 value,
  110. void *buffer, const u16 buffer_length,
  111. const int timeout);
  112. /**
  113. * rt2x00usb_vendor_request_buff - Send register command to device (buffered)
  114. * @rt2x00dev: Pointer to &struct rt2x00_dev
  115. * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
  116. * @requesttype: Request type &USB_VENDOR_REQUEST_*
  117. * @offset: Register offset to perform action on
  118. * @buffer: Buffer where information will be read/written to by device
  119. * @buffer_length: Size of &buffer
  120. * @timeout: Operation timeout
  121. *
  122. * This function will use a previously with kmalloc allocated cache
  123. * to communicate with the device. The contents of the buffer pointer
  124. * will be copied to this cache when writing, or read from the cache
  125. * when reading.
  126. * Buffers send to &rt2x00usb_vendor_request _must_ be allocated with
  127. * kmalloc. Hence the reason for using a previously allocated cache
  128. * which has been allocated properly.
  129. */
  130. int rt2x00usb_vendor_request_buff(struct rt2x00_dev *rt2x00dev,
  131. const u8 request, const u8 requesttype,
  132. const u16 offset, void *buffer,
  133. const u16 buffer_length, const int timeout);
  134. /**
  135. * rt2x00usb_vendor_request_buff - Send register command to device (buffered)
  136. * @rt2x00dev: Pointer to &struct rt2x00_dev
  137. * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
  138. * @requesttype: Request type &USB_VENDOR_REQUEST_*
  139. * @offset: Register offset to perform action on
  140. * @buffer: Buffer where information will be read/written to by device
  141. * @buffer_length: Size of &buffer
  142. * @timeout: Operation timeout
  143. *
  144. * A version of &rt2x00usb_vendor_request_buff which must be called
  145. * if the usb_cache_mutex is already held.
  146. */
  147. int rt2x00usb_vendor_req_buff_lock(struct rt2x00_dev *rt2x00dev,
  148. const u8 request, const u8 requesttype,
  149. const u16 offset, void *buffer,
  150. const u16 buffer_length, const int timeout);
  151. /**
  152. * rt2x00usb_vendor_request_sw - Send single register command to device
  153. * @rt2x00dev: Pointer to &struct rt2x00_dev
  154. * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
  155. * @offset: Register offset to perform action on
  156. * @value: Value to write to device
  157. * @timeout: Operation timeout
  158. *
  159. * Simple wrapper around rt2x00usb_vendor_request to write a single
  160. * command to the device. Since we don't use the buffer argument we
  161. * don't have to worry about kmalloc here.
  162. */
  163. static inline int rt2x00usb_vendor_request_sw(struct rt2x00_dev *rt2x00dev,
  164. const u8 request,
  165. const u16 offset,
  166. const u16 value,
  167. const int timeout)
  168. {
  169. return rt2x00usb_vendor_request(rt2x00dev, request,
  170. USB_VENDOR_REQUEST_OUT, offset,
  171. value, NULL, 0, timeout);
  172. }
  173. /**
  174. * rt2x00usb_eeprom_read - Read eeprom from device
  175. * @rt2x00dev: Pointer to &struct rt2x00_dev
  176. * @eeprom: Pointer to eeprom array to store the information in
  177. * @length: Number of bytes to read from the eeprom
  178. *
  179. * Simple wrapper around rt2x00usb_vendor_request to read the eeprom
  180. * from the device. Note that the eeprom argument _must_ be allocated using
  181. * kmalloc for correct handling inside the kernel USB layer.
  182. */
  183. static inline int rt2x00usb_eeprom_read(struct rt2x00_dev *rt2x00dev,
  184. __le16 *eeprom, const u16 length)
  185. {
  186. return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_READ,
  187. USB_VENDOR_REQUEST_IN, 0, 0,
  188. eeprom, length,
  189. REGISTER_TIMEOUT16(length));
  190. }
  191. /*
  192. * Radio handlers
  193. */
  194. void rt2x00usb_disable_radio(struct rt2x00_dev *rt2x00dev);
  195. /*
  196. * TX data handlers.
  197. */
  198. int rt2x00usb_write_tx_data(struct rt2x00_dev *rt2x00dev,
  199. struct data_queue *queue, struct sk_buff *skb);
  200. /**
  201. * struct queue_entry_priv_usb: Per entry USB specific information
  202. *
  203. * @urb: Urb structure used for device communication.
  204. */
  205. struct queue_entry_priv_usb {
  206. struct urb *urb;
  207. };
  208. /**
  209. * struct queue_entry_priv_usb_bcn: Per TX entry USB specific information
  210. *
  211. * The first section should match &struct queue_entry_priv_usb exactly.
  212. * rt2500usb can use this structure to send a guardian byte when working
  213. * with beacons.
  214. *
  215. * @urb: Urb structure used for device communication.
  216. * @guardian_data: Set to 0, used for sending the guardian data.
  217. * @guardian_urb: Urb structure used to send the guardian data.
  218. */
  219. struct queue_entry_priv_usb_bcn {
  220. struct urb *urb;
  221. unsigned int guardian_data;
  222. struct urb *guardian_urb;
  223. };
  224. /*
  225. * Device initialization handlers.
  226. */
  227. void rt2x00usb_init_rxentry(struct rt2x00_dev *rt2x00dev,
  228. struct queue_entry *entry);
  229. void rt2x00usb_init_txentry(struct rt2x00_dev *rt2x00dev,
  230. struct queue_entry *entry);
  231. int rt2x00usb_initialize(struct rt2x00_dev *rt2x00dev);
  232. void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev);
  233. /*
  234. * USB driver handlers.
  235. */
  236. int rt2x00usb_probe(struct usb_interface *usb_intf,
  237. const struct usb_device_id *id);
  238. void rt2x00usb_disconnect(struct usb_interface *usb_intf);
  239. #ifdef CONFIG_PM
  240. int rt2x00usb_suspend(struct usb_interface *usb_intf, pm_message_t state);
  241. int rt2x00usb_resume(struct usb_interface *usb_intf);
  242. #else
  243. #define rt2x00usb_suspend NULL
  244. #define rt2x00usb_resume NULL
  245. #endif /* CONFIG_PM */
  246. #endif /* RT2X00USB_H */