1 /* ZD1211 USB-WLAN driver for Linux
3 * Copyright (C) 2005-2007 Ulrich Kunitz <kune@deine-taler.de>
4 * Copyright (C) 2006-2007 Daniel Drake <dsd@gentoo.org>
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.
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.
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
24 #include <linux/completion.h>
25 #include <linux/netdevice.h>
26 #include <linux/spinlock.h>
27 #include <linux/skbuff.h>
28 #include <linux/usb.h>
32 #define ZD_USB_TX_HIGH 5
33 #define ZD_USB_TX_LOW 2
50 USB_MAX_TRANSFER_SIZE
= 4096, /* bytes */
51 USB_MAX_RX_SIZE
= 4800, /* bytes */
52 USB_MAX_IOWRITE16_COUNT
= 15,
53 USB_MAX_IOWRITE32_COUNT
= USB_MAX_IOWRITE16_COUNT
/2,
54 USB_MAX_IOREAD16_COUNT
= 15,
55 USB_MAX_IOREAD32_COUNT
= USB_MAX_IOREAD16_COUNT
/2,
56 USB_MIN_RFWRITE_BIT_COUNT
= 16,
57 USB_MAX_RFWRITE_BIT_COUNT
= 28,
58 USB_MAX_EP_INT_BUFFER
= 64,
59 USB_ZD1211B_BCD_DEVICE
= 0x4810,
62 enum control_requests
{
63 USB_REQ_WRITE_REGS
= 0x21,
64 USB_REQ_READ_REGS
= 0x22,
65 USB_REQ_WRITE_RF
= 0x23,
66 USB_REQ_PROG_FLASH
= 0x24,
67 USB_REQ_EEPROM_START
= 0x0128, /* ? request is a byte */
68 USB_REQ_EEPROM_MID
= 0x28,
69 USB_REQ_EEPROM_END
= 0x0228, /* ? request is a byte */
70 USB_REQ_FIRMWARE_DOWNLOAD
= 0x30,
71 USB_REQ_FIRMWARE_CONFIRM
= 0x31,
72 USB_REQ_FIRMWARE_READ_DATA
= 0x32,
75 struct usb_req_read_regs
{
85 struct usb_req_write_regs
{
87 struct reg_data reg_writes
[0];
96 struct usb_req_rfwrite
{
100 /* 2: other (default) */
103 __le16 bit_values
[0];
104 /* (CR203 & ~(RF_IF_LE | RF_CLK | RF_DATA)) | (bit ? RF_DATA : 0) */
111 USB_INT_ID_REGS
= 0x90,
112 USB_INT_ID_RETRY_FAILED
= 0xa0,
116 USB_INT_READ_REGS_EN
= 0x01,
119 struct usb_int_header
{
120 u8 type
; /* must always be 1 */
124 struct usb_int_regs
{
125 struct usb_int_header hdr
;
126 struct reg_data regs
[0];
129 struct usb_int_retry_fail
{
130 struct usb_int_header hdr
;
137 struct read_regs_int
{
138 struct completion completion
;
139 /* Stores the USB int structure and contains the USB address of the
140 * first requested register before request.
142 u8 buffer
[USB_MAX_EP_INT_BUFFER
];
157 struct zd_usb_interrupt
{
158 struct read_regs_int read_regs
;
162 u8 read_regs_enabled
:1;
165 static inline struct usb_int_regs
*get_read_regs(struct zd_usb_interrupt
*intr
)
167 return (struct usb_int_regs
*)intr
->read_regs
.buffer
;
170 #define RX_URBS_COUNT 5
174 u8 fragment
[2*USB_MAX_RX_SIZE
];
175 unsigned int fragment_length
;
176 unsigned int usb_packet_size
;
182 * struct zd_usb_tx - structure used for transmitting frames
183 * @lock: lock for transmission
184 * @free_urb_list: list of free URBs, contains all the URBs, which can be used
185 * @submitted_urbs: atomic integer that counts the URBs having sent to the
186 * device, which haven't been completed
187 * @enabled: enabled flag, indicates whether tx is enabled
188 * @stopped: indicates whether higher level tx queues are stopped
192 struct list_head free_urb_list
;
198 /* Contains the usb parts. The structure doesn't require a lock because intf
199 * will not be changed after initialization.
202 struct zd_usb_interrupt intr
;
205 struct usb_interface
*intf
;
206 u8 is_zd1211b
:1, initialized
:1;
209 #define zd_usb_dev(usb) (&usb->intf->dev)
211 static inline struct usb_device
*zd_usb_to_usbdev(struct zd_usb
*usb
)
213 return interface_to_usbdev(usb
->intf
);
216 static inline struct ieee80211_hw
*zd_intf_to_hw(struct usb_interface
*intf
)
218 return usb_get_intfdata(intf
);
221 static inline struct ieee80211_hw
*zd_usb_to_hw(struct zd_usb
*usb
)
223 return zd_intf_to_hw(usb
->intf
);
226 void zd_usb_init(struct zd_usb
*usb
, struct ieee80211_hw
*hw
,
227 struct usb_interface
*intf
);
228 int zd_usb_init_hw(struct zd_usb
*usb
);
229 void zd_usb_clear(struct zd_usb
*usb
);
231 int zd_usb_scnprint_id(struct zd_usb
*usb
, char *buffer
, size_t size
);
233 int zd_usb_enable_int(struct zd_usb
*usb
);
234 void zd_usb_disable_int(struct zd_usb
*usb
);
236 int zd_usb_enable_rx(struct zd_usb
*usb
);
237 void zd_usb_disable_rx(struct zd_usb
*usb
);
239 void zd_usb_enable_tx(struct zd_usb
*usb
);
240 void zd_usb_disable_tx(struct zd_usb
*usb
);
242 int zd_usb_tx(struct zd_usb
*usb
, struct sk_buff
*skb
);
244 int zd_usb_ioread16v(struct zd_usb
*usb
, u16
*values
,
245 const zd_addr_t
*addresses
, unsigned int count
);
247 static inline int zd_usb_ioread16(struct zd_usb
*usb
, u16
*value
,
248 const zd_addr_t addr
)
250 return zd_usb_ioread16v(usb
, value
, (const zd_addr_t
*)&addr
, 1);
253 int zd_usb_iowrite16v(struct zd_usb
*usb
, const struct zd_ioreq16
*ioreqs
,
256 int zd_usb_rfwrite(struct zd_usb
*usb
, u32 value
, u8 bits
);
258 int zd_usb_read_fw(struct zd_usb
*usb
, zd_addr_t addr
, u8
*data
, u16 len
);
260 extern struct workqueue_struct
*zd_workqueue
;
262 #endif /* _ZD_USB_H */