rt2x00usb.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. /*
  64. * USB request types.
  65. */
  66. #define USB_VENDOR_REQUEST ( USB_TYPE_VENDOR | USB_RECIP_DEVICE )
  67. #define USB_VENDOR_REQUEST_IN ( USB_DIR_IN | USB_VENDOR_REQUEST )
  68. #define USB_VENDOR_REQUEST_OUT ( USB_DIR_OUT | USB_VENDOR_REQUEST )
  69. /**
  70. * enum rt2x00usb_vendor_request: USB vendor commands.
  71. */
  72. enum rt2x00usb_vendor_request {
  73. USB_DEVICE_MODE = 1,
  74. USB_SINGLE_WRITE = 2,
  75. USB_SINGLE_READ = 3,
  76. USB_MULTI_WRITE = 6,
  77. USB_MULTI_READ = 7,
  78. USB_EEPROM_WRITE = 8,
  79. USB_EEPROM_READ = 9,
  80. USB_LED_CONTROL = 10, /* RT73USB */
  81. USB_RX_CONTROL = 12,
  82. };
  83. /**
  84. * enum rt2x00usb_mode_offset: Device modes offset.
  85. */
  86. enum rt2x00usb_mode_offset {
  87. USB_MODE_RESET = 1,
  88. USB_MODE_UNPLUG = 2,
  89. USB_MODE_FUNCTION = 3,
  90. USB_MODE_TEST = 4,
  91. USB_MODE_SLEEP = 7, /* RT73USB */
  92. USB_MODE_FIRMWARE = 8, /* RT73USB */
  93. USB_MODE_WAKEUP = 9, /* RT73USB */
  94. };
  95. /**
  96. * rt2x00usb_vendor_request - Send register command to device
  97. * @rt2x00dev: Pointer to &struct rt2x00_dev
  98. * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
  99. * @requesttype: Request type &USB_VENDOR_REQUEST_*
  100. * @offset: Register offset to perform action on
  101. * @value: Value to write to device
  102. * @buffer: Buffer where information will be read/written to by device
  103. * @buffer_length: Size of &buffer
  104. * @timeout: Operation timeout
  105. *
  106. * This is the main function to communicate with the device,
  107. * the &buffer argument _must_ either be NULL or point to
  108. * a buffer allocated by kmalloc. Failure to do so can lead
  109. * to unexpected behavior depending on the architecture.
  110. */
  111. int rt2x00usb_vendor_request(struct rt2x00_dev *rt2x00dev,
  112. const u8 request, const u8 requesttype,
  113. const u16 offset, const u16 value,
  114. void *buffer, const u16 buffer_length,
  115. const int timeout);
  116. /**
  117. * rt2x00usb_vendor_request_buff - Send register command to device (buffered)
  118. * @rt2x00dev: Pointer to &struct rt2x00_dev
  119. * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
  120. * @requesttype: Request type &USB_VENDOR_REQUEST_*
  121. * @offset: Register offset to perform action on
  122. * @buffer: Buffer where information will be read/written to by device
  123. * @buffer_length: Size of &buffer
  124. * @timeout: Operation timeout
  125. *
  126. * This function will use a previously with kmalloc allocated cache
  127. * to communicate with the device. The contents of the buffer pointer
  128. * will be copied to this cache when writing, or read from the cache
  129. * when reading.
  130. * Buffers send to &rt2x00usb_vendor_request _must_ be allocated with
  131. * kmalloc. Hence the reason for using a previously allocated cache
  132. * which has been allocated properly.
  133. */
  134. int rt2x00usb_vendor_request_buff(struct rt2x00_dev *rt2x00dev,
  135. const u8 request, const u8 requesttype,
  136. const u16 offset, void *buffer,
  137. const u16 buffer_length, const int timeout);
  138. /**
  139. * rt2x00usb_vendor_request_buff - Send register command to device (buffered)
  140. * @rt2x00dev: Pointer to &struct rt2x00_dev
  141. * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
  142. * @requesttype: Request type &USB_VENDOR_REQUEST_*
  143. * @offset: Register offset to perform action on
  144. * @buffer: Buffer where information will be read/written to by device
  145. * @buffer_length: Size of &buffer
  146. * @timeout: Operation timeout
  147. *
  148. * A version of &rt2x00usb_vendor_request_buff which must be called
  149. * if the usb_cache_mutex is already held.
  150. */
  151. int rt2x00usb_vendor_req_buff_lock(struct rt2x00_dev *rt2x00dev,
  152. const u8 request, const u8 requesttype,
  153. const u16 offset, void *buffer,
  154. const u16 buffer_length, const int timeout);
  155. /**
  156. * rt2x00usb_vendor_request_large_buff - Send register command to device (buffered)
  157. * @rt2x00dev: Pointer to &struct rt2x00_dev
  158. * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
  159. * @requesttype: Request type &USB_VENDOR_REQUEST_*
  160. * @offset: Register start offset to perform action on
  161. * @buffer: Buffer where information will be read/written to by device
  162. * @buffer_length: Size of &buffer
  163. * @timeout: Operation timeout
  164. *
  165. * This function is used to transfer register data in blocks larger
  166. * then CSR_CACHE_SIZE. Use for firmware upload, keys and beacons.
  167. */
  168. int rt2x00usb_vendor_request_large_buff(struct rt2x00_dev *rt2x00dev,
  169. const u8 request, const u8 requesttype,
  170. const u16 offset, const void *buffer,
  171. const u16 buffer_length,
  172. const int timeout);
  173. /**
  174. * rt2x00usb_vendor_request_sw - Send single register command to device
  175. * @rt2x00dev: Pointer to &struct rt2x00_dev
  176. * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
  177. * @offset: Register offset to perform action on
  178. * @value: Value to write to device
  179. * @timeout: Operation timeout
  180. *
  181. * Simple wrapper around rt2x00usb_vendor_request to write a single
  182. * command to the device. Since we don't use the buffer argument we
  183. * don't have to worry about kmalloc here.
  184. */
  185. static inline int rt2x00usb_vendor_request_sw(struct rt2x00_dev *rt2x00dev,
  186. const u8 request,
  187. const u16 offset,
  188. const u16 value,
  189. const int timeout)
  190. {
  191. return rt2x00usb_vendor_request(rt2x00dev, request,
  192. USB_VENDOR_REQUEST_OUT, offset,
  193. value, NULL, 0, timeout);
  194. }
  195. /**
  196. * rt2x00usb_eeprom_read - Read eeprom from device
  197. * @rt2x00dev: Pointer to &struct rt2x00_dev
  198. * @eeprom: Pointer to eeprom array to store the information in
  199. * @length: Number of bytes to read from the eeprom
  200. *
  201. * Simple wrapper around rt2x00usb_vendor_request to read the eeprom
  202. * from the device. Note that the eeprom argument _must_ be allocated using
  203. * kmalloc for correct handling inside the kernel USB layer.
  204. */
  205. static inline int rt2x00usb_eeprom_read(struct rt2x00_dev *rt2x00dev,
  206. __le16 *eeprom, const u16 length)
  207. {
  208. return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_READ,
  209. USB_VENDOR_REQUEST_IN, 0, 0,
  210. eeprom, length,
  211. REGISTER_TIMEOUT16(length));
  212. }
  213. /*
  214. * Radio handlers
  215. */
  216. void rt2x00usb_disable_radio(struct rt2x00_dev *rt2x00dev);
  217. /**
  218. * rt2x00usb_write_tx_data - Initialize URB for TX operation
  219. * @entry: The entry where the frame is located
  220. *
  221. * This function will initialize the URB and skb descriptor
  222. * to prepare the entry for the actual TX operation.
  223. */
  224. int rt2x00usb_write_tx_data(struct queue_entry *entry);
  225. /**
  226. * struct queue_entry_priv_usb: Per entry USB specific information
  227. *
  228. * @urb: Urb structure used for device communication.
  229. */
  230. struct queue_entry_priv_usb {
  231. struct urb *urb;
  232. };
  233. /**
  234. * struct queue_entry_priv_usb_bcn: Per TX entry USB specific information
  235. *
  236. * The first section should match &struct queue_entry_priv_usb exactly.
  237. * rt2500usb can use this structure to send a guardian byte when working
  238. * with beacons.
  239. *
  240. * @urb: Urb structure used for device communication.
  241. * @guardian_data: Set to 0, used for sending the guardian data.
  242. * @guardian_urb: Urb structure used to send the guardian data.
  243. */
  244. struct queue_entry_priv_usb_bcn {
  245. struct urb *urb;
  246. unsigned int guardian_data;
  247. struct urb *guardian_urb;
  248. };
  249. /**
  250. * rt2x00usb_kick_tx_queue - Kick data queue
  251. * @rt2x00dev: Pointer to &struct rt2x00_dev
  252. * @qid: Data queue to kick
  253. *
  254. * This will walk through all entries of the queue and push all pending
  255. * frames to the hardware as a single burst.
  256. */
  257. void rt2x00usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
  258. const enum data_queue_qid qid);
  259. /*
  260. * Device initialization handlers.
  261. */
  262. void rt2x00usb_init_rxentry(struct rt2x00_dev *rt2x00dev,
  263. struct queue_entry *entry);
  264. void rt2x00usb_init_txentry(struct rt2x00_dev *rt2x00dev,
  265. struct queue_entry *entry);
  266. int rt2x00usb_initialize(struct rt2x00_dev *rt2x00dev);
  267. void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev);
  268. /*
  269. * USB driver handlers.
  270. */
  271. int rt2x00usb_probe(struct usb_interface *usb_intf,
  272. const struct usb_device_id *id);
  273. void rt2x00usb_disconnect(struct usb_interface *usb_intf);
  274. #ifdef CONFIG_PM
  275. int rt2x00usb_suspend(struct usb_interface *usb_intf, pm_message_t state);
  276. int rt2x00usb_resume(struct usb_interface *usb_intf);
  277. #else
  278. #define rt2x00usb_suspend NULL
  279. #define rt2x00usb_resume NULL
  280. #endif /* CONFIG_PM */
  281. #endif /* RT2X00USB_H */