rt2x00usb.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. Copyright (C) 2004 - 2007 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. * USB vendor commands.
  55. */
  56. #define USB_DEVICE_MODE 0x01
  57. #define USB_SINGLE_WRITE 0x02
  58. #define USB_SINGLE_READ 0x03
  59. #define USB_MULTI_WRITE 0x06
  60. #define USB_MULTI_READ 0x07
  61. #define USB_EEPROM_WRITE 0x08
  62. #define USB_EEPROM_READ 0x09
  63. #define USB_LED_CONTROL 0x0a /* RT73USB */
  64. #define USB_RX_CONTROL 0x0c
  65. /*
  66. * Device modes offset
  67. */
  68. #define USB_MODE_RESET 0x01
  69. #define USB_MODE_UNPLUG 0x02
  70. #define USB_MODE_FUNCTION 0x03
  71. #define USB_MODE_TEST 0x04
  72. #define USB_MODE_SLEEP 0x07 /* RT73USB */
  73. #define USB_MODE_FIRMWARE 0x08 /* RT73USB */
  74. #define USB_MODE_WAKEUP 0x09 /* RT73USB */
  75. /*
  76. * Used to read/write from/to the device.
  77. * This is the main function to communicate with the device,
  78. * the buffer argument _must_ either be NULL or point to
  79. * a buffer allocated by kmalloc. Failure to do so can lead
  80. * to unexpected behavior depending on the architecture.
  81. */
  82. int rt2x00usb_vendor_request(const struct rt2x00_dev *rt2x00dev,
  83. const u8 request, const u8 requesttype,
  84. const u16 offset, const u16 value,
  85. void *buffer, const u16 buffer_length,
  86. const int timeout);
  87. /*
  88. * Used to read/write from/to the device.
  89. * This function will use a previously with kmalloc allocated cache
  90. * to communicate with the device. The contents of the buffer pointer
  91. * will be copied to this cache when writing, or read from the cache
  92. * when reading.
  93. * Buffers send to rt2x00usb_vendor_request _must_ be allocated with
  94. * kmalloc. Hence the reason for using a previously allocated cache
  95. * which has been allocated properly.
  96. */
  97. int rt2x00usb_vendor_request_buff(const struct rt2x00_dev *rt2x00dev,
  98. const u8 request, const u8 requesttype,
  99. const u16 offset, void *buffer,
  100. const u16 buffer_length, const int timeout);
  101. /*
  102. * Simple wrapper around rt2x00usb_vendor_request to write a single
  103. * command to the device. Since we don't use the buffer argument we
  104. * don't have to worry about kmalloc here.
  105. */
  106. static inline int rt2x00usb_vendor_request_sw(const struct rt2x00_dev
  107. *rt2x00dev,
  108. const u8 request,
  109. const u16 offset,
  110. const u16 value,
  111. const int timeout)
  112. {
  113. return rt2x00usb_vendor_request(rt2x00dev, request,
  114. USB_VENDOR_REQUEST_OUT, offset,
  115. value, NULL, 0, timeout);
  116. }
  117. /*
  118. * Simple wrapper around rt2x00usb_vendor_request to read the eeprom
  119. * from the device. Note that the eeprom argument _must_ be allocated using
  120. * kmalloc for correct handling inside the kernel USB layer.
  121. */
  122. static inline int rt2x00usb_eeprom_read(const struct rt2x00_dev *rt2x00dev,
  123. __le16 *eeprom, const u16 lenght)
  124. {
  125. int timeout = REGISTER_TIMEOUT * (lenght / sizeof(u16));
  126. return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_READ,
  127. USB_VENDOR_REQUEST_IN, 0x0000,
  128. 0x0000, eeprom, lenght, timeout);
  129. }
  130. /*
  131. * Radio handlers
  132. */
  133. void rt2x00usb_enable_radio(struct rt2x00_dev *rt2x00dev);
  134. void rt2x00usb_disable_radio(struct rt2x00_dev *rt2x00dev);
  135. /*
  136. * TX data handlers.
  137. */
  138. int rt2x00usb_write_tx_data(struct rt2x00_dev *rt2x00dev,
  139. struct data_ring *ring, struct sk_buff *skb,
  140. struct ieee80211_tx_control *control);
  141. /*
  142. * Device initialization handlers.
  143. */
  144. int rt2x00usb_initialize(struct rt2x00_dev *rt2x00dev);
  145. void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev);
  146. /*
  147. * USB driver handlers.
  148. */
  149. int rt2x00usb_probe(struct usb_interface *usb_intf,
  150. const struct usb_device_id *id);
  151. void rt2x00usb_disconnect(struct usb_interface *usb_intf);
  152. #ifdef CONFIG_PM
  153. int rt2x00usb_suspend(struct usb_interface *usb_intf, pm_message_t state);
  154. int rt2x00usb_resume(struct usb_interface *usb_intf);
  155. #else
  156. #define rt2x00usb_suspend NULL
  157. #define rt2x00usb_resume NULL
  158. #endif /* CONFIG_PM */
  159. #endif /* RT2X00USB_H */