]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/net/wireless/zd1211rw/zd_usb.h
zd1211rw: port to mac80211
[linux-2.6-omap-h63xx.git] / drivers / net / wireless / zd1211rw / zd_usb.h
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
29 #define ZD_USB_TX_HIGH  5
30 #define ZD_USB_TX_LOW   2
31
32 enum devicetype {
33         DEVICE_ZD1211  = 0,
34         DEVICE_ZD1211B = 1,
35         DEVICE_INSTALLER = 2,
36 };
37
38 enum endpoints {
39         EP_CTRL     = 0,
40         EP_DATA_OUT = 1,
41         EP_DATA_IN  = 2,
42         EP_INT_IN   = 3,
43         EP_REGS_OUT = 4,
44 };
45
46 enum {
47         USB_MAX_TRANSFER_SIZE           = 4096, /* bytes */
48         /* FIXME: The original driver uses this value. We have to check,
49          * whether the MAX_TRANSFER_SIZE is sufficient and this needs only be
50          * used if one combined frame is split over two USB transactions.
51          */
52         USB_MAX_RX_SIZE                 = 4800, /* bytes */
53         USB_MAX_IOWRITE16_COUNT         = 15,
54         USB_MAX_IOWRITE32_COUNT         = USB_MAX_IOWRITE16_COUNT/2,
55         USB_MAX_IOREAD16_COUNT          = 15,
56         USB_MAX_IOREAD32_COUNT          = USB_MAX_IOREAD16_COUNT/2,
57         USB_MIN_RFWRITE_BIT_COUNT       = 16,
58         USB_MAX_RFWRITE_BIT_COUNT       = 28,
59         USB_MAX_EP_INT_BUFFER           = 64,
60         USB_ZD1211B_BCD_DEVICE          = 0x4810,
61 };
62
63 enum control_requests {
64         USB_REQ_WRITE_REGS              = 0x21,
65         USB_REQ_READ_REGS               = 0x22,
66         USB_REQ_WRITE_RF                = 0x23,
67         USB_REQ_PROG_FLASH              = 0x24,
68         USB_REQ_EEPROM_START            = 0x0128, /* ? request is a byte */
69         USB_REQ_EEPROM_MID              = 0x28,
70         USB_REQ_EEPROM_END              = 0x0228, /* ? request is a byte */
71         USB_REQ_FIRMWARE_DOWNLOAD       = 0x30,
72         USB_REQ_FIRMWARE_CONFIRM        = 0x31,
73         USB_REQ_FIRMWARE_READ_DATA      = 0x32,
74 };
75
76 struct usb_req_read_regs {
77         __le16 id;
78         __le16 addr[0];
79 } __attribute__((packed));
80
81 struct reg_data {
82         __le16 addr;
83         __le16 value;
84 } __attribute__((packed));
85
86 struct usb_req_write_regs {
87         __le16 id;
88         struct reg_data reg_writes[0];
89 } __attribute__((packed));
90
91 enum {
92         RF_IF_LE = 0x02,
93         RF_CLK   = 0x04,
94         RF_DATA  = 0x08,
95 };
96
97 struct usb_req_rfwrite {
98         __le16 id;
99         __le16 value;
100         /* 1: 3683a */
101         /* 2: other (default) */
102         __le16 bits;
103         /* RF2595: 24 */
104         __le16 bit_values[0];
105         /* (CR203 & ~(RF_IF_LE | RF_CLK | RF_DATA)) | (bit ? RF_DATA : 0) */
106 } __attribute__((packed));
107
108 /* USB interrupt */
109
110 enum usb_int_id {
111         USB_INT_TYPE                    = 0x01,
112         USB_INT_ID_REGS                 = 0x90,
113         USB_INT_ID_RETRY_FAILED         = 0xa0,
114 };
115
116 enum usb_int_flags {
117         USB_INT_READ_REGS_EN            = 0x01,
118 };
119
120 struct usb_int_header {
121         u8 type;        /* must always be 1 */
122         u8 id;
123 } __attribute__((packed));
124
125 struct usb_int_regs {
126         struct usb_int_header hdr;
127         struct reg_data regs[0];
128 } __attribute__((packed));
129
130 struct usb_int_retry_fail {
131         struct usb_int_header hdr;
132         u8 new_rate;
133         u8 _dummy;
134         u8 addr[ETH_ALEN];
135         u8 ibss_wakeup_dest;
136 } __attribute__((packed));
137
138 struct read_regs_int {
139         struct completion completion;
140         /* Stores the USB int structure and contains the USB address of the
141          * first requested register before request.
142          */
143         u8 buffer[USB_MAX_EP_INT_BUFFER];
144         int length;
145         __le16 cr_int_addr;
146 };
147
148 struct zd_ioreq16 {
149         zd_addr_t addr;
150         u16 value;
151 };
152
153 struct zd_ioreq32 {
154         zd_addr_t addr;
155         u32 value;
156 };
157
158 struct zd_usb_interrupt {
159         struct read_regs_int read_regs;
160         spinlock_t lock;
161         struct urb *urb;
162         int interval;
163         u8 read_regs_enabled:1;
164 };
165
166 static inline struct usb_int_regs *get_read_regs(struct zd_usb_interrupt *intr)
167 {
168         return (struct usb_int_regs *)intr->read_regs.buffer;
169 }
170
171 #define RX_URBS_COUNT 5
172
173 struct zd_usb_rx {
174         spinlock_t lock;
175         u8 fragment[2*USB_MAX_RX_SIZE];
176         unsigned int fragment_length;
177         unsigned int usb_packet_size;
178         struct urb **urbs;
179         int urbs_count;
180 };
181
182 /**
183  * struct zd_usb_tx - structure used for transmitting frames
184  * @lock: lock for transmission
185  * @free_urb_list: list of free URBs, contains all the URBs, which can be used
186  * @submitted_urbs: atomic integer that counts the URBs having sent to the
187  *      device, which haven't been completed
188  * @enabled: enabled flag, indicates whether tx is enabled
189  * @stopped: indicates whether higher level tx queues are stopped
190  */
191 struct zd_usb_tx {
192         spinlock_t lock;
193         struct list_head free_urb_list;
194         int submitted_urbs;
195         int enabled;
196         int stopped;
197 };
198
199 /* Contains the usb parts. The structure doesn't require a lock because intf
200  * will not be changed after initialization.
201  */
202 struct zd_usb {
203         struct zd_usb_interrupt intr;
204         struct zd_usb_rx rx;
205         struct zd_usb_tx tx;
206         struct usb_interface *intf;
207         u8 is_zd1211b:1, initialized:1;
208 };
209
210 #define zd_usb_dev(usb) (&usb->intf->dev)
211
212 static inline struct usb_device *zd_usb_to_usbdev(struct zd_usb *usb)
213 {
214         return interface_to_usbdev(usb->intf);
215 }
216
217 static inline struct ieee80211_hw *zd_intf_to_hw(struct usb_interface *intf)
218 {
219         return usb_get_intfdata(intf);
220 }
221
222 static inline struct ieee80211_hw *zd_usb_to_hw(struct zd_usb *usb)
223 {
224         return zd_intf_to_hw(usb->intf);
225 }
226
227 void zd_usb_init(struct zd_usb *usb, struct ieee80211_hw *hw,
228                  struct usb_interface *intf);
229 int zd_usb_init_hw(struct zd_usb *usb);
230 void zd_usb_clear(struct zd_usb *usb);
231
232 int zd_usb_scnprint_id(struct zd_usb *usb, char *buffer, size_t size);
233
234 int zd_usb_enable_int(struct zd_usb *usb);
235 void zd_usb_disable_int(struct zd_usb *usb);
236
237 int zd_usb_enable_rx(struct zd_usb *usb);
238 void zd_usb_disable_rx(struct zd_usb *usb);
239
240 void zd_usb_enable_tx(struct zd_usb *usb);
241 void zd_usb_disable_tx(struct zd_usb *usb);
242
243 int zd_usb_tx(struct zd_usb *usb, struct sk_buff *skb);
244
245 int zd_usb_ioread16v(struct zd_usb *usb, u16 *values,
246                  const zd_addr_t *addresses, unsigned int count);
247
248 static inline int zd_usb_ioread16(struct zd_usb *usb, u16 *value,
249                               const zd_addr_t addr)
250 {
251         return zd_usb_ioread16v(usb, value, (const zd_addr_t *)&addr, 1);
252 }
253
254 int zd_usb_iowrite16v(struct zd_usb *usb, const struct zd_ioreq16 *ioreqs,
255                       unsigned int count);
256
257 int zd_usb_rfwrite(struct zd_usb *usb, u32 value, u8 bits);
258
259 int zd_usb_read_fw(struct zd_usb *usb, zd_addr_t addr, u8 *data, u16 len);
260
261 extern struct workqueue_struct *zd_workqueue;
262
263 #endif /* _ZD_USB_H */