diff options
author | Daniel Drake <dsd@gentoo.org> | 2006-06-02 12:11:32 -0400 |
---|---|---|
committer | Jeff Garzik <jeff@garzik.org> | 2006-07-05 13:42:58 -0400 |
commit | e85d0918b54fbd9b38003752f7d665416b06edd8 (patch) | |
tree | 6f53e6bb10562eec331defc6811fb6d434eb21e5 /drivers/net/wireless/zd1211rw/zd_usb.h | |
parent | 4a232e725b5cc1bc7fc5b177424a9ff8313b23ad (diff) |
[PATCH] ZyDAS ZD1211 USB-WLAN driver
There are 60+ USB wifi adapters available on the market based on the ZyDAS
ZD1211 chip.
Unlike the predecessor (ZD1201), ZD1211 does not have a hardware MAC, so most
data operations are coordinated by the device driver. The ZD1211 chip sits
alongside an RF transceiver which is also controlled by the driver. Our driver
currently supports 2 RF types, we know of one other available in a few marketed
products which we will be supporting soon.
Our driver also supports the newer revision of ZD1211, called ZD1211B. The
initialization and RF operations are slightly different for the new revision,
but the main difference is 802.11e support. Our driver does not support the
QoS features yet, but we think we know how to use them.
This driver is based on ZyDAS's own GPL driver available from www.zydas.com.tw.
ZyDAS engineers have been responsive and supportive of our efforts, so thumbs
up to them. Additionally, the firmware is redistributable and they have
provided device specs.
This driver has been written primarily by Ulrich Kunitz and myself. Graham
Gower, Greg KH, Remco and Bryan Rittmeyer have also contributed. The
developers of ieee80211 and softmac have made our lives so much easier- thanks!
We maintain a small info-page: http://zd1211.ath.cx/wiki/DriverRewrite
If there is enough time for review, we would like to aim for inclusion in
2.6.18. The driver works nicely as a STA, and can connect to both open and
encrypted networks (we are using software-based encryption for now). We will
work towards supporting more advanced features in the future (ad-hoc, master
mode, 802.11a, ...).
Signed-off-by: Daniel Drake <dsd@gentoo.org>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/zd1211rw/zd_usb.h')
-rw-r--r-- | drivers/net/wireless/zd1211rw/zd_usb.h | 240 |
1 files changed, 240 insertions, 0 deletions
diff --git a/drivers/net/wireless/zd1211rw/zd_usb.h b/drivers/net/wireless/zd1211rw/zd_usb.h new file mode 100644 index 000000000000..d6420283bd5a --- /dev/null +++ b/drivers/net/wireless/zd1211rw/zd_usb.h | |||
@@ -0,0 +1,240 @@ | |||
1 | /* zd_usb.h: Header for USB interface implemented by ZD1211 chip | ||
2 | * | ||
3 | * This program is free software; you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation; either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
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 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program; if not, write to the Free Software | ||
15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
16 | */ | ||
17 | |||
18 | #ifndef _ZD_USB_H | ||
19 | #define _ZD_USB_H | ||
20 | |||
21 | #include <linux/completion.h> | ||
22 | #include <linux/netdevice.h> | ||
23 | #include <linux/spinlock.h> | ||
24 | #include <linux/skbuff.h> | ||
25 | #include <linux/usb.h> | ||
26 | |||
27 | #include "zd_def.h" | ||
28 | #include "zd_types.h" | ||
29 | |||
30 | enum devicetype { | ||
31 | DEVICE_ZD1211 = 0, | ||
32 | DEVICE_ZD1211B = 1, | ||
33 | }; | ||
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 | |||
43 | enum { | ||
44 | USB_MAX_TRANSFER_SIZE = 4096, /* bytes */ | ||
45 | /* FIXME: The original driver uses this value. We have to check, | ||
46 | * whether the MAX_TRANSFER_SIZE is sufficient and this needs only be | ||
47 | * used if one combined frame is split over two USB transactions. | ||
48 | */ | ||
49 | USB_MAX_RX_SIZE = 4800, /* bytes */ | ||
50 | USB_MAX_IOWRITE16_COUNT = 15, | ||
51 | USB_MAX_IOWRITE32_COUNT = USB_MAX_IOWRITE16_COUNT/2, | ||
52 | USB_MAX_IOREAD16_COUNT = 15, | ||
53 | USB_MAX_IOREAD32_COUNT = USB_MAX_IOREAD16_COUNT/2, | ||
54 | USB_MIN_RFWRITE_BIT_COUNT = 16, | ||
55 | USB_MAX_RFWRITE_BIT_COUNT = 28, | ||
56 | USB_MAX_EP_INT_BUFFER = 64, | ||
57 | USB_ZD1211B_BCD_DEVICE = 0x4810, | ||
58 | }; | ||
59 | |||
60 | enum control_requests { | ||
61 | USB_REQ_WRITE_REGS = 0x21, | ||
62 | USB_REQ_READ_REGS = 0x22, | ||
63 | USB_REQ_WRITE_RF = 0x23, | ||
64 | USB_REQ_PROG_FLASH = 0x24, | ||
65 | USB_REQ_EEPROM_START = 0x0128, /* ? request is a byte */ | ||
66 | USB_REQ_EEPROM_MID = 0x28, | ||
67 | USB_REQ_EEPROM_END = 0x0228, /* ? request is a byte */ | ||
68 | USB_REQ_FIRMWARE_DOWNLOAD = 0x30, | ||
69 | USB_REQ_FIRMWARE_CONFIRM = 0x31, | ||
70 | USB_REQ_FIRMWARE_READ_DATA = 0x32, | ||
71 | }; | ||
72 | |||
73 | struct usb_req_read_regs { | ||
74 | __le16 id; | ||
75 | __le16 addr[0]; | ||
76 | } __attribute__((packed)); | ||
77 | |||
78 | struct reg_data { | ||
79 | __le16 addr; | ||
80 | __le16 value; | ||
81 | } __attribute__((packed)); | ||
82 | |||
83 | struct usb_req_write_regs { | ||
84 | __le16 id; | ||
85 | struct reg_data reg_writes[0]; | ||
86 | } __attribute__((packed)); | ||
87 | |||
88 | enum { | ||
89 | RF_IF_LE = 0x02, | ||
90 | RF_CLK = 0x04, | ||
91 | RF_DATA = 0x08, | ||
92 | }; | ||
93 | |||
94 | struct usb_req_rfwrite { | ||
95 | __le16 id; | ||
96 | __le16 value; | ||
97 | /* 1: 3683a */ | ||
98 | /* 2: other (default) */ | ||
99 | __le16 bits; | ||
100 | /* RF2595: 24 */ | ||
101 | __le16 bit_values[0]; | ||
102 | /* (CR203 & ~(RF_IF_LE | RF_CLK | RF_DATA)) | (bit ? RF_DATA : 0) */ | ||
103 | } __attribute__((packed)); | ||
104 | |||
105 | /* USB interrupt */ | ||
106 | |||
107 | enum usb_int_id { | ||
108 | USB_INT_TYPE = 0x01, | ||
109 | USB_INT_ID_REGS = 0x90, | ||
110 | USB_INT_ID_RETRY_FAILED = 0xa0, | ||
111 | }; | ||
112 | |||
113 | enum usb_int_flags { | ||
114 | USB_INT_READ_REGS_EN = 0x01, | ||
115 | }; | ||
116 | |||
117 | struct usb_int_header { | ||
118 | u8 type; /* must always be 1 */ | ||
119 | u8 id; | ||
120 | } __attribute__((packed)); | ||
121 | |||
122 | struct usb_int_regs { | ||
123 | struct usb_int_header hdr; | ||
124 | struct reg_data regs[0]; | ||
125 | } __attribute__((packed)); | ||
126 | |||
127 | struct usb_int_retry_fail { | ||
128 | struct usb_int_header hdr; | ||
129 | u8 new_rate; | ||
130 | u8 _dummy; | ||
131 | u8 addr[ETH_ALEN]; | ||
132 | u8 ibss_wakeup_dest; | ||
133 | } __attribute__((packed)); | ||
134 | |||
135 | struct read_regs_int { | ||
136 | struct completion completion; | ||
137 | /* Stores the USB int structure and contains the USB address of the | ||
138 | * first requested register before request. | ||
139 | */ | ||
140 | u8 buffer[USB_MAX_EP_INT_BUFFER]; | ||
141 | int length; | ||
142 | __le16 cr_int_addr; | ||
143 | }; | ||
144 | |||
145 | struct zd_ioreq16 { | ||
146 | zd_addr_t addr; | ||
147 | u16 value; | ||
148 | }; | ||
149 | |||
150 | struct zd_ioreq32 { | ||
151 | zd_addr_t addr; | ||
152 | u32 value; | ||
153 | }; | ||
154 | |||
155 | struct zd_usb_interrupt { | ||
156 | struct read_regs_int read_regs; | ||
157 | spinlock_t lock; | ||
158 | struct urb *urb; | ||
159 | int interval; | ||
160 | u8 read_regs_enabled:1; | ||
161 | }; | ||
162 | |||
163 | static inline struct usb_int_regs *get_read_regs(struct zd_usb_interrupt *intr) | ||
164 | { | ||
165 | return (struct usb_int_regs *)intr->read_regs.buffer; | ||
166 | } | ||
167 | |||
168 | #define URBS_COUNT 5 | ||
169 | |||
170 | struct zd_usb_rx { | ||
171 | spinlock_t lock; | ||
172 | u8 fragment[2*USB_MAX_RX_SIZE]; | ||
173 | unsigned int fragment_length; | ||
174 | unsigned int usb_packet_size; | ||
175 | struct urb **urbs; | ||
176 | int urbs_count; | ||
177 | }; | ||
178 | |||
179 | struct zd_usb_tx { | ||
180 | spinlock_t lock; | ||
181 | }; | ||
182 | |||
183 | /* Contains the usb parts. The structure doesn't require a lock, because intf | ||
184 | * and fw_base_offset, will not be changed after initialization. | ||
185 | */ | ||
186 | struct zd_usb { | ||
187 | struct zd_usb_interrupt intr; | ||
188 | struct zd_usb_rx rx; | ||
189 | struct zd_usb_tx tx; | ||
190 | struct usb_interface *intf; | ||
191 | u16 fw_base_offset; | ||
192 | }; | ||
193 | |||
194 | #define zd_usb_dev(usb) (&usb->intf->dev) | ||
195 | |||
196 | static inline struct usb_device *zd_usb_to_usbdev(struct zd_usb *usb) | ||
197 | { | ||
198 | return interface_to_usbdev(usb->intf); | ||
199 | } | ||
200 | |||
201 | static inline struct net_device *zd_intf_to_netdev(struct usb_interface *intf) | ||
202 | { | ||
203 | return usb_get_intfdata(intf); | ||
204 | } | ||
205 | |||
206 | static inline struct net_device *zd_usb_to_netdev(struct zd_usb *usb) | ||
207 | { | ||
208 | return zd_intf_to_netdev(usb->intf); | ||
209 | } | ||
210 | |||
211 | void zd_usb_init(struct zd_usb *usb, struct net_device *netdev, | ||
212 | struct usb_interface *intf); | ||
213 | int zd_usb_init_hw(struct zd_usb *usb); | ||
214 | void zd_usb_clear(struct zd_usb *usb); | ||
215 | |||
216 | int zd_usb_scnprint_id(struct zd_usb *usb, char *buffer, size_t size); | ||
217 | |||
218 | int zd_usb_enable_int(struct zd_usb *usb); | ||
219 | void zd_usb_disable_int(struct zd_usb *usb); | ||
220 | |||
221 | int zd_usb_enable_rx(struct zd_usb *usb); | ||
222 | void zd_usb_disable_rx(struct zd_usb *usb); | ||
223 | |||
224 | int zd_usb_tx(struct zd_usb *usb, const u8 *frame, unsigned int length); | ||
225 | |||
226 | int zd_usb_ioread16v(struct zd_usb *usb, u16 *values, | ||
227 | const zd_addr_t *addresses, unsigned int count); | ||
228 | |||
229 | static inline int zd_usb_ioread16(struct zd_usb *usb, u16 *value, | ||
230 | const zd_addr_t addr) | ||
231 | { | ||
232 | return zd_usb_ioread16v(usb, value, (const zd_addr_t *)&addr, 1); | ||
233 | } | ||
234 | |||
235 | int zd_usb_iowrite16v(struct zd_usb *usb, const struct zd_ioreq16 *ioreqs, | ||
236 | unsigned int count); | ||
237 | |||
238 | int zd_usb_rfwrite(struct zd_usb *usb, u32 value, u8 bits); | ||
239 | |||
240 | #endif /* _ZD_USB_H */ | ||