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