zd_usb.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /* ZD1211 USB-WLAN driver for Linux
  2. *
  3. * Copyright (C) 2005-2007 Ulrich Kunitz <kune@deine-taler.de>
  4. * Copyright (C) 2006-2007 Daniel Drake <dsd@gentoo.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #ifndef _ZD_USB_H
  21. #define _ZD_USB_H
  22. #include <linux/completion.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/spinlock.h>
  25. #include <linux/skbuff.h>
  26. #include <linux/usb.h>
  27. #include "zd_def.h"
  28. #define ZD_USB_TX_HIGH 5
  29. #define ZD_USB_TX_LOW 2
  30. enum devicetype {
  31. DEVICE_ZD1211 = 0,
  32. DEVICE_ZD1211B = 1,
  33. DEVICE_INSTALLER = 2,
  34. };
  35. enum endpoints {
  36. EP_CTRL = 0,
  37. EP_DATA_OUT = 1,
  38. EP_DATA_IN = 2,
  39. EP_INT_IN = 3,
  40. EP_REGS_OUT = 4,
  41. };
  42. enum {
  43. USB_MAX_TRANSFER_SIZE = 4096, /* bytes */
  44. /* FIXME: The original driver uses this value. We have to check,
  45. * whether the MAX_TRANSFER_SIZE is sufficient and this needs only be
  46. * used if one combined frame is split over two USB transactions.
  47. */
  48. USB_MAX_RX_SIZE = 4800, /* bytes */
  49. USB_MAX_IOWRITE16_COUNT = 15,
  50. USB_MAX_IOWRITE32_COUNT = USB_MAX_IOWRITE16_COUNT/2,
  51. USB_MAX_IOREAD16_COUNT = 15,
  52. USB_MAX_IOREAD32_COUNT = USB_MAX_IOREAD16_COUNT/2,
  53. USB_MIN_RFWRITE_BIT_COUNT = 16,
  54. USB_MAX_RFWRITE_BIT_COUNT = 28,
  55. USB_MAX_EP_INT_BUFFER = 64,
  56. USB_ZD1211B_BCD_DEVICE = 0x4810,
  57. };
  58. enum control_requests {
  59. USB_REQ_WRITE_REGS = 0x21,
  60. USB_REQ_READ_REGS = 0x22,
  61. USB_REQ_WRITE_RF = 0x23,
  62. USB_REQ_PROG_FLASH = 0x24,
  63. USB_REQ_EEPROM_START = 0x0128, /* ? request is a byte */
  64. USB_REQ_EEPROM_MID = 0x28,
  65. USB_REQ_EEPROM_END = 0x0228, /* ? request is a byte */
  66. USB_REQ_FIRMWARE_DOWNLOAD = 0x30,
  67. USB_REQ_FIRMWARE_CONFIRM = 0x31,
  68. USB_REQ_FIRMWARE_READ_DATA = 0x32,
  69. };
  70. struct usb_req_read_regs {
  71. __le16 id;
  72. __le16 addr[0];
  73. } __attribute__((packed));
  74. struct reg_data {
  75. __le16 addr;
  76. __le16 value;
  77. } __attribute__((packed));
  78. struct usb_req_write_regs {
  79. __le16 id;
  80. struct reg_data reg_writes[0];
  81. } __attribute__((packed));
  82. enum {
  83. RF_IF_LE = 0x02,
  84. RF_CLK = 0x04,
  85. RF_DATA = 0x08,
  86. };
  87. struct usb_req_rfwrite {
  88. __le16 id;
  89. __le16 value;
  90. /* 1: 3683a */
  91. /* 2: other (default) */
  92. __le16 bits;
  93. /* RF2595: 24 */
  94. __le16 bit_values[0];
  95. /* (CR203 & ~(RF_IF_LE | RF_CLK | RF_DATA)) | (bit ? RF_DATA : 0) */
  96. } __attribute__((packed));
  97. /* USB interrupt */
  98. enum usb_int_id {
  99. USB_INT_TYPE = 0x01,
  100. USB_INT_ID_REGS = 0x90,
  101. USB_INT_ID_RETRY_FAILED = 0xa0,
  102. };
  103. enum usb_int_flags {
  104. USB_INT_READ_REGS_EN = 0x01,
  105. };
  106. struct usb_int_header {
  107. u8 type; /* must always be 1 */
  108. u8 id;
  109. } __attribute__((packed));
  110. struct usb_int_regs {
  111. struct usb_int_header hdr;
  112. struct reg_data regs[0];
  113. } __attribute__((packed));
  114. struct usb_int_retry_fail {
  115. struct usb_int_header hdr;
  116. u8 new_rate;
  117. u8 _dummy;
  118. u8 addr[ETH_ALEN];
  119. u8 ibss_wakeup_dest;
  120. } __attribute__((packed));
  121. struct read_regs_int {
  122. struct completion completion;
  123. /* Stores the USB int structure and contains the USB address of the
  124. * first requested register before request.
  125. */
  126. u8 buffer[USB_MAX_EP_INT_BUFFER];
  127. int length;
  128. __le16 cr_int_addr;
  129. };
  130. struct zd_ioreq16 {
  131. zd_addr_t addr;
  132. u16 value;
  133. };
  134. struct zd_ioreq32 {
  135. zd_addr_t addr;
  136. u32 value;
  137. };
  138. struct zd_usb_interrupt {
  139. struct read_regs_int read_regs;
  140. spinlock_t lock;
  141. struct urb *urb;
  142. int interval;
  143. u8 read_regs_enabled:1;
  144. };
  145. static inline struct usb_int_regs *get_read_regs(struct zd_usb_interrupt *intr)
  146. {
  147. return (struct usb_int_regs *)intr->read_regs.buffer;
  148. }
  149. #define RX_URBS_COUNT 5
  150. struct zd_usb_rx {
  151. spinlock_t lock;
  152. u8 fragment[2*USB_MAX_RX_SIZE];
  153. unsigned int fragment_length;
  154. unsigned int usb_packet_size;
  155. struct urb **urbs;
  156. int urbs_count;
  157. };
  158. /**
  159. * struct zd_usb_tx - structure used for transmitting frames
  160. * @lock: lock for transmission
  161. * @free_urb_list: list of free URBs, contains all the URBs, which can be used
  162. * @submitted_urbs: atomic integer that counts the URBs having sent to the
  163. * device, which haven't been completed
  164. * @enabled: enabled flag, indicates whether tx is enabled
  165. * @stopped: indicates whether higher level tx queues are stopped
  166. */
  167. struct zd_usb_tx {
  168. spinlock_t lock;
  169. struct list_head free_urb_list;
  170. int submitted_urbs;
  171. int enabled;
  172. int stopped;
  173. };
  174. /* Contains the usb parts. The structure doesn't require a lock because intf
  175. * will not be changed after initialization.
  176. */
  177. struct zd_usb {
  178. struct zd_usb_interrupt intr;
  179. struct zd_usb_rx rx;
  180. struct zd_usb_tx tx;
  181. struct usb_interface *intf;
  182. u8 is_zd1211b:1, initialized:1;
  183. };
  184. #define zd_usb_dev(usb) (&usb->intf->dev)
  185. static inline struct usb_device *zd_usb_to_usbdev(struct zd_usb *usb)
  186. {
  187. return interface_to_usbdev(usb->intf);
  188. }
  189. static inline struct ieee80211_hw *zd_intf_to_hw(struct usb_interface *intf)
  190. {
  191. return usb_get_intfdata(intf);
  192. }
  193. static inline struct ieee80211_hw *zd_usb_to_hw(struct zd_usb *usb)
  194. {
  195. return zd_intf_to_hw(usb->intf);
  196. }
  197. void zd_usb_init(struct zd_usb *usb, struct ieee80211_hw *hw,
  198. struct usb_interface *intf);
  199. int zd_usb_init_hw(struct zd_usb *usb);
  200. void zd_usb_clear(struct zd_usb *usb);
  201. int zd_usb_scnprint_id(struct zd_usb *usb, char *buffer, size_t size);
  202. int zd_usb_enable_int(struct zd_usb *usb);
  203. void zd_usb_disable_int(struct zd_usb *usb);
  204. int zd_usb_enable_rx(struct zd_usb *usb);
  205. void zd_usb_disable_rx(struct zd_usb *usb);
  206. void zd_usb_enable_tx(struct zd_usb *usb);
  207. void zd_usb_disable_tx(struct zd_usb *usb);
  208. int zd_usb_tx(struct zd_usb *usb, struct sk_buff *skb);
  209. int zd_usb_ioread16v(struct zd_usb *usb, u16 *values,
  210. const zd_addr_t *addresses, unsigned int count);
  211. static inline int zd_usb_ioread16(struct zd_usb *usb, u16 *value,
  212. const zd_addr_t addr)
  213. {
  214. return zd_usb_ioread16v(usb, value, (const zd_addr_t *)&addr, 1);
  215. }
  216. int zd_usb_iowrite16v(struct zd_usb *usb, const struct zd_ioreq16 *ioreqs,
  217. unsigned int count);
  218. int zd_usb_rfwrite(struct zd_usb *usb, u32 value, u8 bits);
  219. int zd_usb_read_fw(struct zd_usb *usb, zd_addr_t addr, u8 *data, u16 len);
  220. extern struct workqueue_struct *zd_workqueue;
  221. #endif /* _ZD_USB_H */