rt2x00usb.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. #define to_usb_device_intf(d) \
  24. ({ \
  25. struct usb_interface *intf = to_usb_interface(d); \
  26. interface_to_usbdev(intf); \
  27. })
  28. /*
  29. * This variable should be used with the
  30. * usb_driver structure initialization.
  31. */
  32. #define USB_DEVICE_DATA(__ops) .driver_info = (kernel_ulong_t)(__ops)
  33. /*
  34. * Register defines.
  35. * Some registers require multiple attempts before success,
  36. * in those cases REGISTER_BUSY_COUNT attempts should be
  37. * taken with a REGISTER_BUSY_DELAY interval.
  38. * For USB vendor requests we need to pass a timeout
  39. * time in ms, for this we use the REGISTER_TIMEOUT,
  40. * however when loading firmware a higher value is
  41. * required. In that case we use the REGISTER_TIMEOUT_FIRMWARE.
  42. */
  43. #define REGISTER_BUSY_COUNT 5
  44. #define REGISTER_BUSY_DELAY 100
  45. #define REGISTER_TIMEOUT 500
  46. #define REGISTER_TIMEOUT_FIRMWARE 1000
  47. /**
  48. * REGISTER_TIMEOUT16 - Determine the timeout for 16bit register access
  49. * @__datalen: Data length
  50. */
  51. #define REGISTER_TIMEOUT16(__datalen) \
  52. ( REGISTER_TIMEOUT * ((__datalen) / sizeof(u16)) )
  53. /**
  54. * REGISTER_TIMEOUT32 - Determine the timeout for 32bit register access
  55. * @__datalen: Data length
  56. */
  57. #define REGISTER_TIMEOUT32(__datalen) \
  58. ( REGISTER_TIMEOUT * ((__datalen) / sizeof(u32)) )
  59. /*
  60. * Cache size
  61. */
  62. #define CSR_CACHE_SIZE 8
  63. #define CSR_CACHE_SIZE_FIRMWARE 64
  64. /*
  65. * USB request types.
  66. */
  67. #define USB_VENDOR_REQUEST ( USB_TYPE_VENDOR | USB_RECIP_DEVICE )
  68. #define USB_VENDOR_REQUEST_IN ( USB_DIR_IN | USB_VENDOR_REQUEST )
  69. #define USB_VENDOR_REQUEST_OUT ( USB_DIR_OUT | USB_VENDOR_REQUEST )
  70. /**
  71. * enum rt2x00usb_vendor_request: USB vendor commands.
  72. */
  73. enum rt2x00usb_vendor_request {
  74. USB_DEVICE_MODE = 1,
  75. USB_SINGLE_WRITE = 2,
  76. USB_SINGLE_READ = 3,
  77. USB_MULTI_WRITE = 6,
  78. USB_MULTI_READ = 7,
  79. USB_EEPROM_WRITE = 8,
  80. USB_EEPROM_READ = 9,
  81. USB_LED_CONTROL = 10, /* RT73USB */
  82. USB_RX_CONTROL = 12,
  83. };
  84. /**
  85. * enum rt2x00usb_mode_offset: Device modes offset.
  86. */
  87. enum rt2x00usb_mode_offset {
  88. USB_MODE_RESET = 1,
  89. USB_MODE_UNPLUG = 2,
  90. USB_MODE_FUNCTION = 3,
  91. USB_MODE_TEST = 4,
  92. USB_MODE_SLEEP = 7, /* RT73USB */
  93. USB_MODE_FIRMWARE = 8, /* RT73USB */
  94. USB_MODE_WAKEUP = 9, /* RT73USB */
  95. };
  96. /**
  97. * rt2x00usb_vendor_request - Send register command to device
  98. * @rt2x00dev: Pointer to &struct rt2x00_dev
  99. * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
  100. * @requesttype: Request type &USB_VENDOR_REQUEST_*
  101. * @offset: Register offset to perform action on
  102. * @value: Value to write to device
  103. * @buffer: Buffer where information will be read/written to by device
  104. * @buffer_length: Size of &buffer
  105. * @timeout: Operation timeout
  106. *
  107. * This is the main function to communicate with the device,
  108. * the &buffer argument _must_ either be NULL or point to
  109. * a buffer allocated by kmalloc. Failure to do so can lead
  110. * to unexpected behavior depending on the architecture.
  111. */
  112. int rt2x00usb_vendor_request(struct rt2x00_dev *rt2x00dev,
  113. const u8 request, const u8 requesttype,
  114. const u16 offset, const u16 value,
  115. void *buffer, const u16 buffer_length,
  116. const int timeout);
  117. /**
  118. * rt2x00usb_vendor_request_buff - Send register command to device (buffered)
  119. * @rt2x00dev: Pointer to &struct rt2x00_dev
  120. * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
  121. * @requesttype: Request type &USB_VENDOR_REQUEST_*
  122. * @offset: Register offset to perform action on
  123. * @buffer: Buffer where information will be read/written to by device
  124. * @buffer_length: Size of &buffer
  125. * @timeout: Operation timeout
  126. *
  127. * This function will use a previously with kmalloc allocated cache
  128. * to communicate with the device. The contents of the buffer pointer
  129. * will be copied to this cache when writing, or read from the cache
  130. * when reading.
  131. * Buffers send to &rt2x00usb_vendor_request _must_ be allocated with
  132. * kmalloc. Hence the reason for using a previously allocated cache
  133. * which has been allocated properly.
  134. */
  135. int rt2x00usb_vendor_request_buff(struct rt2x00_dev *rt2x00dev,
  136. const u8 request, const u8 requesttype,
  137. const u16 offset, void *buffer,
  138. const u16 buffer_length, const int timeout);
  139. /**
  140. * rt2x00usb_vendor_request_buff - Send register command to device (buffered)
  141. * @rt2x00dev: Pointer to &struct rt2x00_dev
  142. * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
  143. * @requesttype: Request type &USB_VENDOR_REQUEST_*
  144. * @offset: Register offset to perform action on
  145. * @buffer: Buffer where information will be read/written to by device
  146. * @buffer_length: Size of &buffer
  147. * @timeout: Operation timeout
  148. *
  149. * A version of &rt2x00usb_vendor_request_buff which must be called
  150. * if the usb_cache_mutex is already held.
  151. */
  152. int rt2x00usb_vendor_req_buff_lock(struct rt2x00_dev *rt2x00dev,
  153. const u8 request, const u8 requesttype,
  154. const u16 offset, void *buffer,
  155. const u16 buffer_length, const int timeout);
  156. /**
  157. * rt2x00usb_vendor_request_sw - Send single register command to device
  158. * @rt2x00dev: Pointer to &struct rt2x00_dev
  159. * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
  160. * @offset: Register offset to perform action on
  161. * @value: Value to write to device
  162. * @timeout: Operation timeout
  163. *
  164. * Simple wrapper around rt2x00usb_vendor_request to write a single
  165. * command to the device. Since we don't use the buffer argument we
  166. * don't have to worry about kmalloc here.
  167. */
  168. static inline int rt2x00usb_vendor_request_sw(struct rt2x00_dev *rt2x00dev,
  169. const u8 request,
  170. const u16 offset,
  171. const u16 value,
  172. const int timeout)
  173. {
  174. return rt2x00usb_vendor_request(rt2x00dev, request,
  175. USB_VENDOR_REQUEST_OUT, offset,
  176. value, NULL, 0, timeout);
  177. }
  178. /**
  179. * rt2x00usb_eeprom_read - Read eeprom from device
  180. * @rt2x00dev: Pointer to &struct rt2x00_dev
  181. * @eeprom: Pointer to eeprom array to store the information in
  182. * @length: Number of bytes to read from the eeprom
  183. *
  184. * Simple wrapper around rt2x00usb_vendor_request to read the eeprom
  185. * from the device. Note that the eeprom argument _must_ be allocated using
  186. * kmalloc for correct handling inside the kernel USB layer.
  187. */
  188. static inline int rt2x00usb_eeprom_read(struct rt2x00_dev *rt2x00dev,
  189. __le16 *eeprom, const u16 length)
  190. {
  191. return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_READ,
  192. USB_VENDOR_REQUEST_IN, 0, 0,
  193. eeprom, length,
  194. REGISTER_TIMEOUT16(length));
  195. }
  196. /*
  197. * Radio handlers
  198. */
  199. void rt2x00usb_disable_radio(struct rt2x00_dev *rt2x00dev);
  200. /**
  201. * rt2x00usb_write_tx_data - Initialize URB for TX operation
  202. * @entry: The entry where the frame is located
  203. *
  204. * This function will initialize the URB and skb descriptor
  205. * to prepare the entry for the actual TX operation.
  206. */
  207. int rt2x00usb_write_tx_data(struct queue_entry *entry);
  208. /**
  209. * struct queue_entry_priv_usb: Per entry USB specific information
  210. *
  211. * @urb: Urb structure used for device communication.
  212. */
  213. struct queue_entry_priv_usb {
  214. struct urb *urb;
  215. };
  216. /**
  217. * struct queue_entry_priv_usb_bcn: Per TX entry USB specific information
  218. *
  219. * The first section should match &struct queue_entry_priv_usb exactly.
  220. * rt2500usb can use this structure to send a guardian byte when working
  221. * with beacons.
  222. *
  223. * @urb: Urb structure used for device communication.
  224. * @guardian_data: Set to 0, used for sending the guardian data.
  225. * @guardian_urb: Urb structure used to send the guardian data.
  226. */
  227. struct queue_entry_priv_usb_bcn {
  228. struct urb *urb;
  229. unsigned int guardian_data;
  230. struct urb *guardian_urb;
  231. };
  232. /**
  233. * rt2x00usb_kick_tx_queue - Kick data queue
  234. * @rt2x00dev: Pointer to &struct rt2x00_dev
  235. * @qid: Data queue to kick
  236. *
  237. * This will walk through all entries of the queue and push all pending
  238. * frames to the hardware as a single burst.
  239. */
  240. void rt2x00usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
  241. const enum data_queue_qid qid);
  242. /*
  243. * Device initialization handlers.
  244. */
  245. void rt2x00usb_init_rxentry(struct rt2x00_dev *rt2x00dev,
  246. struct queue_entry *entry);
  247. void rt2x00usb_init_txentry(struct rt2x00_dev *rt2x00dev,
  248. struct queue_entry *entry);
  249. int rt2x00usb_initialize(struct rt2x00_dev *rt2x00dev);
  250. void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev);
  251. /*
  252. * USB driver handlers.
  253. */
  254. int rt2x00usb_probe(struct usb_interface *usb_intf,
  255. const struct usb_device_id *id);
  256. void rt2x00usb_disconnect(struct usb_interface *usb_intf);
  257. #ifdef CONFIG_PM
  258. int rt2x00usb_suspend(struct usb_interface *usb_intf, pm_message_t state);
  259. int rt2x00usb_resume(struct usb_interface *usb_intf);
  260. #else
  261. #define rt2x00usb_suspend NULL
  262. #define rt2x00usb_resume NULL
  263. #endif /* CONFIG_PM */
  264. #endif /* RT2X00USB_H */