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