rt2x00usb.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. * Cache size
  44. */
  45. #define CSR_CACHE_SIZE 8
  46. #define CSR_CACHE_SIZE_FIRMWARE 64
  47. /*
  48. * USB request types.
  49. */
  50. #define USB_VENDOR_REQUEST ( USB_TYPE_VENDOR | USB_RECIP_DEVICE )
  51. #define USB_VENDOR_REQUEST_IN ( USB_DIR_IN | USB_VENDOR_REQUEST )
  52. #define USB_VENDOR_REQUEST_OUT ( USB_DIR_OUT | USB_VENDOR_REQUEST )
  53. /**
  54. * enum rt2x00usb_vendor_request: USB vendor commands.
  55. */
  56. enum rt2x00usb_vendor_request {
  57. USB_DEVICE_MODE = 1,
  58. USB_SINGLE_WRITE = 2,
  59. USB_SINGLE_READ = 3,
  60. USB_MULTI_WRITE = 6,
  61. USB_MULTI_READ = 7,
  62. USB_EEPROM_WRITE = 8,
  63. USB_EEPROM_READ = 9,
  64. USB_LED_CONTROL = 10, /* RT73USB */
  65. USB_RX_CONTROL = 12,
  66. };
  67. /**
  68. * enum rt2x00usb_mode_offset: Device modes offset.
  69. */
  70. enum rt2x00usb_mode_offset {
  71. USB_MODE_RESET = 1,
  72. USB_MODE_UNPLUG = 2,
  73. USB_MODE_FUNCTION = 3,
  74. USB_MODE_TEST = 4,
  75. USB_MODE_SLEEP = 7, /* RT73USB */
  76. USB_MODE_FIRMWARE = 8, /* RT73USB */
  77. USB_MODE_WAKEUP = 9, /* RT73USB */
  78. };
  79. /**
  80. * rt2x00usb_vendor_request - Send register command to device
  81. * @rt2x00dev: Pointer to &struct rt2x00_dev
  82. * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
  83. * @requesttype: Request type &USB_VENDOR_REQUEST_*
  84. * @offset: Register offset to perform action on
  85. * @value: Value to write to device
  86. * @buffer: Buffer where information will be read/written to by device
  87. * @buffer_length: Size of &buffer
  88. * @timeout: Operation timeout
  89. *
  90. * This is the main function to communicate with the device,
  91. * the &buffer argument _must_ either be NULL or point to
  92. * a buffer allocated by kmalloc. Failure to do so can lead
  93. * to unexpected behavior depending on the architecture.
  94. */
  95. int rt2x00usb_vendor_request(struct rt2x00_dev *rt2x00dev,
  96. const u8 request, const u8 requesttype,
  97. const u16 offset, const u16 value,
  98. void *buffer, const u16 buffer_length,
  99. const int timeout);
  100. /**
  101. * rt2x00usb_vendor_request_buff - Send register command to device (buffered)
  102. * @rt2x00dev: Pointer to &struct rt2x00_dev
  103. * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
  104. * @requesttype: Request type &USB_VENDOR_REQUEST_*
  105. * @offset: Register offset to perform action on
  106. * @buffer: Buffer where information will be read/written to by device
  107. * @buffer_length: Size of &buffer
  108. * @timeout: Operation timeout
  109. *
  110. * This function will use a previously with kmalloc allocated cache
  111. * to communicate with the device. The contents of the buffer pointer
  112. * will be copied to this cache when writing, or read from the cache
  113. * when reading.
  114. * Buffers send to &rt2x00usb_vendor_request _must_ be allocated with
  115. * kmalloc. Hence the reason for using a previously allocated cache
  116. * which has been allocated properly.
  117. */
  118. int rt2x00usb_vendor_request_buff(struct rt2x00_dev *rt2x00dev,
  119. const u8 request, const u8 requesttype,
  120. const u16 offset, void *buffer,
  121. const u16 buffer_length, const int timeout);
  122. /**
  123. * rt2x00usb_vendor_request_buff - Send register command to device (buffered)
  124. * @rt2x00dev: Pointer to &struct rt2x00_dev
  125. * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
  126. * @requesttype: Request type &USB_VENDOR_REQUEST_*
  127. * @offset: Register offset to perform action on
  128. * @buffer: Buffer where information will be read/written to by device
  129. * @buffer_length: Size of &buffer
  130. * @timeout: Operation timeout
  131. *
  132. * A version of &rt2x00usb_vendor_request_buff which must be called
  133. * if the usb_cache_mutex is already held.
  134. */
  135. int rt2x00usb_vendor_req_buff_lock(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_sw - Send single register command to device
  141. * @rt2x00dev: Pointer to &struct rt2x00_dev
  142. * @request: USB vendor command (See &enum rt2x00usb_vendor_request)
  143. * @offset: Register offset to perform action on
  144. * @value: Value to write to device
  145. * @timeout: Operation timeout
  146. *
  147. * Simple wrapper around rt2x00usb_vendor_request to write a single
  148. * command to the device. Since we don't use the buffer argument we
  149. * don't have to worry about kmalloc here.
  150. */
  151. static inline int rt2x00usb_vendor_request_sw(struct rt2x00_dev *rt2x00dev,
  152. const u8 request,
  153. const u16 offset,
  154. const u16 value,
  155. const int timeout)
  156. {
  157. return rt2x00usb_vendor_request(rt2x00dev, request,
  158. USB_VENDOR_REQUEST_OUT, offset,
  159. value, NULL, 0, timeout);
  160. }
  161. /**
  162. * rt2x00usb_eeprom_read - Read eeprom from device
  163. * @rt2x00dev: Pointer to &struct rt2x00_dev
  164. * @eeprom: Pointer to eeprom array to store the information in
  165. * @length: Number of bytes to read from the eeprom
  166. *
  167. * Simple wrapper around rt2x00usb_vendor_request to read the eeprom
  168. * from the device. Note that the eeprom argument _must_ be allocated using
  169. * kmalloc for correct handling inside the kernel USB layer.
  170. */
  171. static inline int rt2x00usb_eeprom_read(struct rt2x00_dev *rt2x00dev,
  172. __le16 *eeprom, const u16 lenght)
  173. {
  174. int timeout = REGISTER_TIMEOUT * (lenght / sizeof(u16));
  175. return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_READ,
  176. USB_VENDOR_REQUEST_IN, 0, 0,
  177. eeprom, lenght, timeout);
  178. }
  179. /*
  180. * Radio handlers
  181. */
  182. void rt2x00usb_disable_radio(struct rt2x00_dev *rt2x00dev);
  183. /*
  184. * TX data handlers.
  185. */
  186. int rt2x00usb_write_tx_data(struct rt2x00_dev *rt2x00dev,
  187. struct data_queue *queue, struct sk_buff *skb,
  188. struct ieee80211_tx_control *control);
  189. /**
  190. * struct queue_entry_priv_usb_rx: Per RX entry USB specific information
  191. *
  192. * @urb: Urb structure used for device communication.
  193. */
  194. struct queue_entry_priv_usb_rx {
  195. struct urb *urb;
  196. };
  197. /**
  198. * struct queue_entry_priv_usb_tx: Per TX entry USB specific information
  199. *
  200. * @urb: Urb structure used for device communication.
  201. * @control: mac80211 control structure used to transmit data.
  202. */
  203. struct queue_entry_priv_usb_tx {
  204. struct urb *urb;
  205. struct ieee80211_tx_control control;
  206. };
  207. /**
  208. * struct queue_entry_priv_usb_tx: Per TX entry USB specific information
  209. *
  210. * The first section should match &struct queue_entry_priv_usb_tx exactly.
  211. * rt2500usb can use this structure to send a guardian byte when working
  212. * with beacons.
  213. *
  214. * @urb: Urb structure used for device communication.
  215. * @control: mac80211 control structure used to transmit data.
  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. struct ieee80211_tx_control control;
  222. unsigned int guardian_data;
  223. struct urb *guardian_urb;
  224. };
  225. /*
  226. * Device initialization handlers.
  227. */
  228. void rt2x00usb_init_rxentry(struct rt2x00_dev *rt2x00dev,
  229. struct queue_entry *entry);
  230. void rt2x00usb_init_txentry(struct rt2x00_dev *rt2x00dev,
  231. struct queue_entry *entry);
  232. int rt2x00usb_initialize(struct rt2x00_dev *rt2x00dev);
  233. void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev);
  234. /*
  235. * USB driver handlers.
  236. */
  237. int rt2x00usb_probe(struct usb_interface *usb_intf,
  238. const struct usb_device_id *id);
  239. void rt2x00usb_disconnect(struct usb_interface *usb_intf);
  240. #ifdef CONFIG_PM
  241. int rt2x00usb_suspend(struct usb_interface *usb_intf, pm_message_t state);
  242. int rt2x00usb_resume(struct usb_interface *usb_intf);
  243. #else
  244. #define rt2x00usb_suspend NULL
  245. #define rt2x00usb_resume NULL
  246. #endif /* CONFIG_PM */
  247. #endif /* RT2X00USB_H */