2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
18 * Purpose: MAC Data structure
29 #include <linux/module.h>
30 #include <linux/kernel.h>
31 #include <linux/slab.h>
32 #include <linux/delay.h>
33 #include <linux/device.h>
34 #include <linux/firmware.h>
35 #include <linux/suspend.h>
36 #include <linux/if_arp.h>
37 #include <linux/wireless.h>
38 #include <linux/timer.h>
39 #include <linux/usb.h>
40 #include <linux/crc32.h>
41 #include <net/mac80211.h>
44 #define DEVICE_ETHTOOL_IOCTL_SUPPORT
45 #include <linux/ethtool.h>
47 #undef DEVICE_ETHTOOL_IOCTL_SUPPORT
65 #define VNT_B_RATES (BIT(RATE_1M) | BIT(RATE_2M) |\
66 BIT(RATE_5M) | BIT(RATE_11M))
77 #define VNT_USB_VENDOR_ID 0x160a
78 #define VNT_USB_PRODUCT_ID 0x3184
80 #define DEVICE_NAME "vt6656"
81 #define DEVICE_FULL_DRV_NAM "VIA Networking Wireless LAN USB Driver"
83 #define DEVICE_VERSION "mac80211"
85 #define CONFIG_PATH "/etc/vntconfiguration.dat"
88 #define OPTION_DEFAULT { [0 ... MAX_UINTS-1] = -1}
90 #define DUPLICATE_RX_CACHE_LENGTH 5
92 #define AUTO_FB_NONE 0
102 #define ANT_DIVERSITY 2
103 #define ANT_RXD_TXA 3
104 #define ANT_RXD_TXB 4
105 #define ANT_UNKNOWN 0xFF
111 #define BB_VGA_LEVEL 4
112 #define BB_VGA_CHANGE_THRESHOLD 3
114 #define EEP_MAX_CONTEXT_SIZE 256
116 /* Contents in the EEPROM */
117 #define EEP_OFS_PAR 0x0
118 #define EEP_OFS_ANTENNA 0x17
119 #define EEP_OFS_RADIOCTL 0x18
120 #define EEP_OFS_RFTYPE 0x1b
121 #define EEP_OFS_MINCHANNEL 0x1c
122 #define EEP_OFS_MAXCHANNEL 0x1d
123 #define EEP_OFS_SIGNATURE 0x1e
124 #define EEP_OFS_ZONETYPE 0x1f
125 #define EEP_OFS_RFTABLE 0x20
126 #define EEP_OFS_PWR_CCK 0x20
127 #define EEP_OFS_SETPT_CCK 0x21
128 #define EEP_OFS_PWR_OFDMG 0x23
130 #define EEP_OFS_CALIB_TX_IQ 0x24
131 #define EEP_OFS_CALIB_TX_DC 0x25
132 #define EEP_OFS_CALIB_RX_IQ 0x26
134 #define EEP_OFS_MAJOR_VER 0x2e
135 #define EEP_OFS_MINOR_VER 0x2f
137 #define EEP_OFS_CCK_PWR_TBL 0x30
138 #define EEP_OFS_OFDM_PWR_TBL 0x40
139 #define EEP_OFS_OFDMA_PWR_TBL 0x50
141 /* Bits in EEP_OFS_ANTENNA */
142 #define EEP_ANTENNA_MAIN 0x1
143 #define EEP_ANTENNA_AUX 0x2
144 #define EEP_ANTINV 0x4
146 /* Bits in EEP_OFS_RADIOCTL */
147 #define EEP_RADIOCTL_ENABLE 0x80
149 /* control commands */
150 #define MESSAGE_TYPE_READ 0x1
151 #define MESSAGE_TYPE_WRITE 0x0
152 #define MESSAGE_TYPE_LOCK_OR 0x2
153 #define MESSAGE_TYPE_LOCK_AND 0x3
154 #define MESSAGE_TYPE_WRITE_MASK 0x4
155 #define MESSAGE_TYPE_CARDINIT 0x5
156 #define MESSAGE_TYPE_INIT_RSP 0x6
157 #define MESSAGE_TYPE_MACSHUTDOWN 0x7
158 #define MESSAGE_TYPE_SETKEY 0x8
159 #define MESSAGE_TYPE_CLRKEYENTRY 0x9
160 #define MESSAGE_TYPE_WRITE_MISCFF 0xa
161 #define MESSAGE_TYPE_SET_ANTMD 0xb
162 #define MESSAGE_TYPE_SELECT_CHANNEL 0xc
163 #define MESSAGE_TYPE_SET_TSFTBTT 0xd
164 #define MESSAGE_TYPE_SET_SSTIFS 0xe
165 #define MESSAGE_TYPE_CHANGE_BBTYPE 0xf
166 #define MESSAGE_TYPE_DISABLE_PS 0x10
167 #define MESSAGE_TYPE_WRITE_IFRF 0x11
169 /* command read/write(index) */
170 #define MESSAGE_REQUEST_MEM 0x1
171 #define MESSAGE_REQUEST_BBREG 0x2
172 #define MESSAGE_REQUEST_MACREG 0x3
173 #define MESSAGE_REQUEST_EEPROM 0x4
174 #define MESSAGE_REQUEST_TSF 0x5
175 #define MESSAGE_REQUEST_TBTT 0x6
176 #define MESSAGE_REQUEST_BBAGC 0x7
177 #define MESSAGE_REQUEST_VERSION 0x8
178 #define MESSAGE_REQUEST_RF_INIT 0x9
179 #define MESSAGE_REQUEST_RF_INIT2 0xa
180 #define MESSAGE_REQUEST_RF_CH0 0xb
181 #define MESSAGE_REQUEST_RF_CH1 0xc
182 #define MESSAGE_REQUEST_RF_CH2 0xd
185 #define USB_REG4 0x604
187 #define DEVICE_INIT_COLD 0x0 /* cold init */
188 #define DEVICE_INIT_RESET 0x1 /* reset init or Dx to D0 power remain */
189 #define DEVICE_INIT_DXPL 0x2 /* Dx to D0 power lost init */
192 struct vnt_cmd_card_init
{
194 u8 exist_sw_net_addr
;
196 u8 short_retry_limit
;
200 struct vnt_rsp_card_init
{
211 * Enum of context types for SendPacket
214 CONTEXT_DATA_PACKET
= 1,
216 CONTEXT_BEACON_PACKET
219 /* RCB (Receive Control Block) */
227 /* used to track bulk out irps */
228 struct vnt_usb_send_context
{
232 struct ieee80211_hdr
*hdr
;
233 unsigned int buf_len
;
243 unsigned char data
[MAX_TOTAL_SIZE_WITH_ALL_HEADERS
];
247 * Structure to keep track of USB interrupt packets
249 struct vnt_interrupt_buffer
{
263 /* flags for options */
264 #define DEVICE_FLAGS_UNPLUG 0
265 #define DEVICE_FLAGS_DISCONNECTED 1
269 struct ieee80211_hw
*hw
;
270 struct ieee80211_vif
*vif
;
273 struct usb_device
*usb
;
274 struct usb_interface
*intf
;
283 struct mutex usb_lock
;
288 struct urb
*interrupt_urb
;
291 /* Variables to track resources for the BULK In Pipe */
292 struct vnt_rcb
*rcb
[CB_MAX_RX_DESC
];
295 /* Variables to track resources for the BULK Out Pipe */
296 struct vnt_usb_send_context
*tx_context
[CB_MAX_TX_DESC
];
299 /* Variables to track resources for the Interrupt In Pipe */
300 struct vnt_interrupt_buffer int_buf
;
302 /* Version control */
303 u16 firmware_version
;
308 struct vnt_cmd_card_init init_command
;
309 struct vnt_rsp_card_init init_response
;
310 u8 current_net_addr
[ETH_ALEN
] __aligned(2);
311 u8 permanent_net_addr
[ETH_ALEN
] __aligned(2);
313 u8 exist_sw_net_addr
;
317 /* 802.11 MAC specific */
320 /* Antenna Diversity */
328 u32 sifs
; /* Current SIFS */
329 u32 difs
; /* Current DIFS */
330 u32 eifs
; /* Current EIFS */
331 u32 slot
; /* Current SlotTime */
334 u8 bb_type
; /* 0: 11A, 1:11B, 2:11G */
335 u8 packet_type
; /* 0:11a 1:11b 2:11gb 3:11ga */
337 u8 top_ofdm_basic_rate
;
338 u8 top_cck_basic_rate
;
340 u8 eeprom
[EEP_MAX_CONTEXT_SIZE
]; /*u32 alignment */
344 /* For RF Power table */
351 u8 ofdm_a_pwr_tbl
[42];
357 u8 short_retry_limit
;
360 enum nl80211_iftype op_mode
;
370 enum vnt_cmd_state command_state
;
372 enum vnt_cmd command
;
376 enum vnt_cmd cmd_queue
[CMD_Q_SIZE
];
382 unsigned long key_entry_inuse
;
386 /* For Update BaseBand VGA Gain Offset */
387 u8 bb_vga
[BB_VGA_LEVEL
];
395 struct delayed_work run_command_work
;
397 struct ieee80211_low_level_stats low_stats
;
400 #define ADD_ONE_WITH_WRAP_AROUND(uVar, uModulo) { \
401 if ((uVar) >= ((uModulo) - 1)) \
407 int vnt_init(struct vnt_private
*priv
);