1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
8 * Purpose: MAC Data structure
19 #include <linux/bits.h>
20 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/slab.h>
23 #include <linux/delay.h>
24 #include <linux/device.h>
25 #include <linux/firmware.h>
26 #include <linux/suspend.h>
27 #include <linux/if_arp.h>
28 #include <linux/wireless.h>
29 #include <linux/timer.h>
30 #include <linux/usb.h>
31 #include <linux/crc32.h>
32 #include <net/mac80211.h>
35 #define DEVICE_ETHTOOL_IOCTL_SUPPORT
36 #include <linux/ethtool.h>
38 #undef DEVICE_ETHTOOL_IOCTL_SUPPORT
56 #define VNT_B_RATES (BIT(RATE_1M) | BIT(RATE_2M) |\
57 BIT(RATE_5M) | BIT(RATE_11M))
68 #define VNT_USB_VENDOR_ID 0x160a
69 #define VNT_USB_PRODUCT_ID 0x3184
71 #define DEVICE_NAME "vt6656"
72 #define DEVICE_FULL_DRV_NAM "VIA Networking Wireless LAN USB Driver"
74 #define DEVICE_VERSION "mac80211"
76 #define FIRMWARE_VERSION 0x133 /* version 1.51 */
77 #define FIRMWARE_NAME "vntwusb.fw"
78 #define FIRMWARE_CHUNK_SIZE 0x400
80 #define CONFIG_PATH "/etc/vntconfiguration.dat"
83 #define OPTION_DEFAULT { [0 ... MAX_UINTS - 1] = -1}
85 #define DUPLICATE_RX_CACHE_LENGTH 5
87 #define AUTO_FB_NONE 0
97 #define ANT_DIVERSITY 2
100 #define ANT_UNKNOWN 0xFF
106 #define BB_VGA_LEVEL 4
107 #define BB_VGA_CHANGE_THRESHOLD 3
109 #define EEP_MAX_CONTEXT_SIZE 256
111 /* Contents in the EEPROM */
112 #define EEP_OFS_PAR 0x0
113 #define EEP_OFS_ANTENNA 0x17
114 #define EEP_OFS_RADIOCTL 0x18
115 #define EEP_OFS_RFTYPE 0x1b
116 #define EEP_OFS_MINCHANNEL 0x1c
117 #define EEP_OFS_MAXCHANNEL 0x1d
118 #define EEP_OFS_SIGNATURE 0x1e
119 #define EEP_OFS_ZONETYPE 0x1f
120 #define EEP_OFS_RFTABLE 0x20
121 #define EEP_OFS_PWR_CCK 0x20
122 #define EEP_OFS_SETPT_CCK 0x21
123 #define EEP_OFS_PWR_OFDMG 0x23
125 #define EEP_OFS_CALIB_TX_IQ 0x24
126 #define EEP_OFS_CALIB_TX_DC 0x25
127 #define EEP_OFS_CALIB_RX_IQ 0x26
129 #define EEP_OFS_MAJOR_VER 0x2e
130 #define EEP_OFS_MINOR_VER 0x2f
132 #define EEP_OFS_CCK_PWR_TBL 0x30
133 #define EEP_OFS_OFDM_PWR_TBL 0x40
134 #define EEP_OFS_OFDMA_PWR_TBL 0x50
136 /* Bits in EEP_OFS_ANTENNA */
137 #define EEP_ANTENNA_MAIN BIT(0)
138 #define EEP_ANTENNA_AUX BIT(1)
139 #define EEP_ANTINV BIT(2)
141 /* Bits in EEP_OFS_RADIOCTL */
142 #define EEP_RADIOCTL_ENABLE BIT(7)
144 /* control commands */
145 #define MESSAGE_TYPE_READ 0x1
146 #define MESSAGE_TYPE_WRITE 0x0
147 #define MESSAGE_TYPE_LOCK_OR 0x2
148 #define MESSAGE_TYPE_LOCK_AND 0x3
149 #define MESSAGE_TYPE_WRITE_MASK 0x4
150 #define MESSAGE_TYPE_CARDINIT 0x5
151 #define MESSAGE_TYPE_INIT_RSP 0x6
152 #define MESSAGE_TYPE_MACSHUTDOWN 0x7
153 #define MESSAGE_TYPE_SETKEY 0x8
154 #define MESSAGE_TYPE_CLRKEYENTRY 0x9
155 #define MESSAGE_TYPE_WRITE_MISCFF 0xa
156 #define MESSAGE_TYPE_SET_ANTMD 0xb
157 #define MESSAGE_TYPE_SELECT_CHANNEL 0xc
158 #define MESSAGE_TYPE_SET_TSFTBTT 0xd
159 #define MESSAGE_TYPE_SET_SSTIFS 0xe
160 #define MESSAGE_TYPE_CHANGE_BBTYPE 0xf
161 #define MESSAGE_TYPE_DISABLE_PS 0x10
162 #define MESSAGE_TYPE_WRITE_IFRF 0x11
164 /* command read/write(index) */
165 #define MESSAGE_REQUEST_MEM 0x1
166 #define MESSAGE_REQUEST_BBREG 0x2
167 #define MESSAGE_REQUEST_MACREG 0x3
168 #define MESSAGE_REQUEST_EEPROM 0x4
169 #define MESSAGE_REQUEST_TSF 0x5
170 #define MESSAGE_REQUEST_TBTT 0x6
171 #define MESSAGE_REQUEST_BBAGC 0x7
172 #define MESSAGE_REQUEST_VERSION 0x8
173 #define MESSAGE_REQUEST_RF_INIT 0x9
174 #define MESSAGE_REQUEST_RF_INIT2 0xa
175 #define MESSAGE_REQUEST_RF_CH0 0xb
176 #define MESSAGE_REQUEST_RF_CH1 0xc
177 #define MESSAGE_REQUEST_RF_CH2 0xd
180 #define USB_REG4 0x604
182 #define DEVICE_INIT_COLD 0x0 /* cold init */
183 #define DEVICE_INIT_RESET 0x1 /* reset init or Dx to D0 power remain */
184 #define DEVICE_INIT_DXPL 0x2 /* Dx to D0 power lost init */
187 struct vnt_cmd_card_init {
189 u8 exist_sw_net_addr;
191 u8 short_retry_limit;
195 struct vnt_rsp_card_init {
206 * Enum of context types for SendPacket
209 CONTEXT_DATA_PACKET = 0,
210 CONTEXT_BEACON_PACKET
213 struct vnt_rx_header {
229 /* RCB (Receive Control Block) */
236 /* used to track bulk out irps */
237 struct vnt_usb_send_context {
251 * Structure to keep track of USB interrupt packets
253 struct vnt_interrupt_buffer {
257 /* flags for options */
258 #define DEVICE_FLAGS_UNPLUG 0
259 #define DEVICE_FLAGS_DISCONNECTED 1
263 struct ieee80211_hw *hw;
264 struct ieee80211_vif *vif;
267 struct usb_device *usb;
268 struct usb_interface *intf;
276 struct mutex usb_lock;
281 struct urb *interrupt_urb;
284 /* Variables to track resources for the BULK In Pipe */
285 struct vnt_rcb *rcb[CB_MAX_RX_DESC];
288 /* Variables to track resources for the BULK Out Pipe */
289 struct vnt_usb_send_context *tx_context[CB_MAX_TX_DESC];
290 struct usb_anchor tx_submitted;
293 /* Variables to track resources for the Interrupt In Pipe */
294 struct vnt_interrupt_buffer int_buf;
296 /* Version control */
297 u16 firmware_version;
302 struct vnt_cmd_card_init init_command;
303 struct vnt_rsp_card_init init_response;
304 u8 current_net_addr[ETH_ALEN] __aligned(2);
305 u8 permanent_net_addr[ETH_ALEN] __aligned(2);
307 u8 exist_sw_net_addr;
311 /* 802.11 MAC specific */
314 /* Antenna Diversity */
322 u32 sifs; /* Current SIFS */
323 u32 difs; /* Current DIFS */
324 u32 eifs; /* Current EIFS */
325 u32 slot; /* Current SlotTime */
328 u8 bb_type; /* 0: 11A, 1:11B, 2:11G */
329 u8 packet_type; /* 0:11a 1:11b 2:11gb 3:11ga */
331 u8 top_ofdm_basic_rate;
332 u8 top_cck_basic_rate;
334 u8 eeprom[EEP_MAX_CONTEXT_SIZE]; /*u32 alignment */
338 /* For RF Power table */
345 u8 ofdm_a_pwr_tbl[42];
350 enum nl80211_iftype op_mode;
360 enum vnt_cmd_state command_state;
362 enum vnt_cmd command;
366 enum vnt_cmd cmd_queue[CMD_Q_SIZE];
372 unsigned long key_entry_inuse;
376 /* For Update BaseBand VGA Gain Offset */
377 u8 bb_vga[BB_VGA_LEVEL];
383 struct delayed_work run_command_work;
385 struct ieee80211_low_level_stats low_stats;
388 #define ADD_ONE_WITH_WRAP_AROUND(uVar, uModulo) { \
389 if ((uVar) >= ((uModulo) - 1)) \
395 int vnt_init(struct vnt_private *priv);