rt2x00usb.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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 64
  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_large_buff - Send register command to device (buffered)
  158. * @rt2x00dev: Pointer to &struct rt2x00_dev
  159. * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
  160. * @requesttype: Request type &USB_VENDOR_REQUEST_*
  161. * @offset: Register start offset to perform action on
  162. * @buffer: Buffer where information will be read/written to by device
  163. * @buffer_length: Size of &buffer
  164. * @timeout: Operation timeout
  165. *
  166. * This function is used to transfer register data in blocks larger
  167. * then CSR_CACHE_SIZE. Use for firmware upload, keys and beacons.
  168. */
  169. int rt2x00usb_vendor_request_large_buff(struct rt2x00_dev *rt2x00dev,
  170. const u8 request, const u8 requesttype,
  171. const u16 offset, void *buffer,
  172. const u16 buffer_length,
  173. const int timeout);
  174. /**
  175. * rt2x00usb_vendor_request_sw - Send single register command to device
  176. * @rt2x00dev: Pointer to &struct rt2x00_dev
  177. * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
  178. * @offset: Register offset to perform action on
  179. * @value: Value to write to device
  180. * @timeout: Operation timeout
  181. *
  182. * Simple wrapper around rt2x00usb_vendor_request to write a single
  183. * command to the device. Since we don't use the buffer argument we
  184. * don't have to worry about kmalloc here.
  185. */
  186. static inline int rt2x00usb_vendor_request_sw(struct rt2x00_dev *rt2x00dev,
  187. const u8 request,
  188. const u16 offset,
  189. const u16 value,
  190. const int timeout)
  191. {
  192. return rt2x00usb_vendor_request(rt2x00dev, request,
  193. USB_VENDOR_REQUEST_OUT, offset,
  194. value, NULL, 0, timeout);
  195. }
  196. /**
  197. * rt2x00usb_eeprom_read - Read eeprom from device
  198. * @rt2x00dev: Pointer to &struct rt2x00_dev
  199. * @eeprom: Pointer to eeprom array to store the information in
  200. * @length: Number of bytes to read from the eeprom
  201. *
  202. * Simple wrapper around rt2x00usb_vendor_request to read the eeprom
  203. * from the device. Note that the eeprom argument _must_ be allocated using
  204. * kmalloc for correct handling inside the kernel USB layer.
  205. */
  206. static inline int rt2x00usb_eeprom_read(struct rt2x00_dev *rt2x00dev,
  207. __le16 *eeprom, const u16 length)
  208. {
  209. return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_READ,
  210. USB_VENDOR_REQUEST_IN, 0, 0,
  211. eeprom, length,
  212. REGISTER_TIMEOUT16(length));
  213. }
  214. /*
  215. * Radio handlers
  216. */
  217. void rt2x00usb_disable_radio(struct rt2x00_dev *rt2x00dev);
  218. /**
  219. * rt2x00usb_write_tx_data - Initialize URB for TX operation
  220. * @entry: The entry where the frame is located
  221. *
  222. * This function will initialize the URB and skb descriptor
  223. * to prepare the entry for the actual TX operation.
  224. */
  225. int rt2x00usb_write_tx_data(struct queue_entry *entry);
  226. /**
  227. * struct queue_entry_priv_usb: Per entry USB specific information
  228. *
  229. * @urb: Urb structure used for device communication.
  230. */
  231. struct queue_entry_priv_usb {
  232. struct urb *urb;
  233. };
  234. /**
  235. * struct queue_entry_priv_usb_bcn: Per TX entry USB specific information
  236. *
  237. * The first section should match &struct queue_entry_priv_usb exactly.
  238. * rt2500usb can use this structure to send a guardian byte when working
  239. * with beacons.
  240. *
  241. * @urb: Urb structure used for device communication.
  242. * @guardian_data: Set to 0, used for sending the guardian data.
  243. * @guardian_urb: Urb structure used to send the guardian data.
  244. */
  245. struct queue_entry_priv_usb_bcn {
  246. struct urb *urb;
  247. unsigned int guardian_data;
  248. struct urb *guardian_urb;
  249. };
  250. /**
  251. * rt2x00usb_kick_tx_queue - Kick data queue
  252. * @rt2x00dev: Pointer to &struct rt2x00_dev
  253. * @qid: Data queue to kick
  254. *
  255. * This will walk through all entries of the queue and push all pending
  256. * frames to the hardware as a single burst.
  257. */
  258. void rt2x00usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
  259. const enum data_queue_qid qid);
  260. /*
  261. * Device initialization handlers.
  262. */
  263. void rt2x00usb_init_rxentry(struct rt2x00_dev *rt2x00dev,
  264. struct queue_entry *entry);
  265. void rt2x00usb_init_txentry(struct rt2x00_dev *rt2x00dev,
  266. struct queue_entry *entry);
  267. int rt2x00usb_initialize(struct rt2x00_dev *rt2x00dev);
  268. void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev);
  269. /*
  270. * USB driver handlers.
  271. */
  272. int rt2x00usb_probe(struct usb_interface *usb_intf,
  273. const struct usb_device_id *id);
  274. void rt2x00usb_disconnect(struct usb_interface *usb_intf);
  275. #ifdef CONFIG_PM
  276. int rt2x00usb_suspend(struct usb_interface *usb_intf, pm_message_t state);
  277. int rt2x00usb_resume(struct usb_interface *usb_intf);
  278. #else
  279. #define rt2x00usb_suspend NULL
  280. #define rt2x00usb_resume NULL
  281. #endif /* CONFIG_PM */
  282. #endif /* RT2X00USB_H */