• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3  * All rights reserved.
4  *
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.
9  *
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.
14  *
15  *
16  * File: device.h
17  *
18  * Purpose: MAC Data structure
19  *
20  * Author: Tevin Chen
21  *
22  * Date: Mar 17, 1997
23  *
24  */
25 
26 #ifndef __DEVICE_H__
27 #define __DEVICE_H__
28 
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>
42 
43 #ifdef SIOCETHTOOL
44 #define DEVICE_ETHTOOL_IOCTL_SUPPORT
45 #include <linux/ethtool.h>
46 #else
47 #undef DEVICE_ETHTOOL_IOCTL_SUPPORT
48 #endif
49 
50 #define RATE_1M		0
51 #define RATE_2M		1
52 #define RATE_5M		2
53 #define RATE_11M	3
54 #define RATE_6M		4
55 #define RATE_9M		5
56 #define RATE_12M	6
57 #define RATE_18M	7
58 #define RATE_24M	8
59 #define RATE_36M	9
60 #define RATE_48M	10
61 #define RATE_54M	11
62 #define RATE_AUTO	12
63 
64 #define MAX_RATE			12
65 #define VNT_B_RATES	(BIT(RATE_1M) | BIT(RATE_2M) |\
66 			BIT(RATE_5M) | BIT(RATE_11M))
67 
68 /*
69  * device specific
70  */
71 
72 #include "wcmd.h"
73 #include "desc.h"
74 #include "key.h"
75 #include "card.h"
76 
77 #define VNT_USB_VENDOR_ID                     0x160a
78 #define VNT_USB_PRODUCT_ID                    0x3184
79 
80 #define DEVICE_NAME			"vt6656"
81 #define DEVICE_FULL_DRV_NAM		"VIA Networking Wireless LAN USB Driver"
82 
83 #define DEVICE_VERSION			"mac80211"
84 
85 #define CONFIG_PATH			"/etc/vntconfiguration.dat"
86 
87 #define MAX_UINTS			8
88 #define OPTION_DEFAULT			{ [0 ... MAX_UINTS - 1] = -1}
89 
90 #define DUPLICATE_RX_CACHE_LENGTH       5
91 
92 #define AUTO_FB_NONE            0
93 #define AUTO_FB_0               1
94 #define AUTO_FB_1               2
95 
96 #define FB_RATE0                0
97 #define FB_RATE1                1
98 
99 /* Antenna Mode */
100 #define ANT_A                   0
101 #define ANT_B                   1
102 #define ANT_DIVERSITY           2
103 #define ANT_RXD_TXA             3
104 #define ANT_RXD_TXB             4
105 #define ANT_UNKNOWN             0xFF
106 #define ANT_TXA                 0
107 #define ANT_TXB                 1
108 #define ANT_RXA                 2
109 #define ANT_RXB                 3
110 
111 #define BB_VGA_LEVEL            4
112 #define BB_VGA_CHANGE_THRESHOLD 3
113 
114 #define EEP_MAX_CONTEXT_SIZE    256
115 
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
129 
130 #define EEP_OFS_CALIB_TX_IQ	0x24
131 #define EEP_OFS_CALIB_TX_DC	0x25
132 #define EEP_OFS_CALIB_RX_IQ	0x26
133 
134 #define EEP_OFS_MAJOR_VER	0x2e
135 #define EEP_OFS_MINOR_VER	0x2f
136 
137 #define EEP_OFS_CCK_PWR_TBL	0x30
138 #define EEP_OFS_OFDM_PWR_TBL	0x40
139 #define EEP_OFS_OFDMA_PWR_TBL	0x50
140 
141 /* Bits in EEP_OFS_ANTENNA */
142 #define EEP_ANTENNA_MAIN	0x1
143 #define EEP_ANTENNA_AUX		0x2
144 #define EEP_ANTINV		0x4
145 
146 /* Bits in EEP_OFS_RADIOCTL */
147 #define EEP_RADIOCTL_ENABLE	0x80
148 
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
168 
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
183 
184 /* USB registers */
185 #define USB_REG4			0x604
186 
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 */
190 
191 /* Device init */
192 struct vnt_cmd_card_init {
193 	u8 init_class;
194 	u8 exist_sw_net_addr;
195 	u8 sw_net_addr[6];
196 	u8 short_retry_limit;
197 	u8 long_retry_limit;
198 };
199 
200 struct vnt_rsp_card_init {
201 	u8 status;
202 	u8 net_addr[6];
203 	u8 rf_type;
204 	u8 min_channel;
205 	u8 max_channel;
206 };
207 
208 /* USB */
209 
210 /*
211  * Enum of context types for SendPacket
212  */
213 enum {
214 	CONTEXT_DATA_PACKET = 1,
215 	CONTEXT_MGMT_PACKET,
216 	CONTEXT_BEACON_PACKET
217 };
218 
219 /* RCB (Receive Control Block) */
220 struct vnt_rcb {
221 	void *priv;
222 	struct urb *urb;
223 	struct sk_buff *skb;
224 	int in_use;
225 };
226 
227 /* used to track bulk out irps */
228 struct vnt_usb_send_context {
229 	void *priv;
230 	struct sk_buff *skb;
231 	struct urb *urb;
232 	struct ieee80211_hdr *hdr;
233 	unsigned int buf_len;
234 	u32 frame_len;
235 	u16 tx_hdr_size;
236 	u16 tx_rate;
237 	u8 type;
238 	u8 pkt_no;
239 	u8 pkt_type;
240 	u8 need_ack;
241 	u8 fb_option;
242 	bool in_use;
243 	unsigned char data[MAX_TOTAL_SIZE_WITH_ALL_HEADERS];
244 };
245 
246 /*
247  * Structure to keep track of USB interrupt packets
248  */
249 struct vnt_interrupt_buffer {
250 	u8 *data_buf;
251 	bool in_use;
252 };
253 
254 /*++ NDIS related */
255 
256 enum {
257 	STATUS_SUCCESS = 0,
258 	STATUS_FAILURE,
259 	STATUS_RESOURCES,
260 	STATUS_PENDING,
261 };
262 
263 /* flags for options */
264 #define DEVICE_FLAGS_UNPLUG		0
265 #define DEVICE_FLAGS_DISCONNECTED	1
266 
267 struct vnt_private {
268 	/* mac80211 */
269 	struct ieee80211_hw *hw;
270 	struct ieee80211_vif *vif;
271 	u8 mac_hw;
272 	/* netdev */
273 	struct usb_device *usb;
274 	struct usb_interface *intf;
275 
276 	u64 tsf_time;
277 	u8 rx_rate;
278 
279 	u32 rx_buf_sz;
280 	int mc_list_count;
281 
282 	spinlock_t lock;
283 	struct mutex usb_lock;
284 
285 	unsigned long flags;
286 
287 	/* USB */
288 	struct urb *interrupt_urb;
289 	u32 int_interval;
290 
291 	/* Variables to track resources for the BULK In Pipe */
292 	struct vnt_rcb *rcb[CB_MAX_RX_DESC];
293 	u32 num_rcb;
294 
295 	/* Variables to track resources for the BULK Out Pipe */
296 	struct vnt_usb_send_context *tx_context[CB_MAX_TX_DESC];
297 	u32 num_tx_context;
298 
299 	/* Variables to track resources for the Interrupt In Pipe */
300 	struct vnt_interrupt_buffer int_buf;
301 
302 	/* Version control */
303 	u16 firmware_version;
304 	u8 local_id;
305 	u8 rf_type;
306 	u8 bb_rx_conf;
307 
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);
312 
313 	u8 exist_sw_net_addr;
314 
315 	u64 current_tsf;
316 
317 	/* 802.11 MAC specific */
318 	u32 current_rssi;
319 
320 	/* Antenna Diversity */
321 	int tx_rx_ant_inv;
322 	u32 rx_antenna_sel;
323 	u8 rx_antenna_mode;
324 	u8 tx_antenna_mode;
325 	u8 radio_ctl;
326 
327 	/* IFS & Cw */
328 	u32 sifs;  /* Current SIFS */
329 	u32 difs;  /* Current DIFS */
330 	u32 eifs;  /* Current EIFS */
331 	u32 slot;  /* Current SlotTime */
332 
333 	/* Rate */
334 	u8 bb_type; /* 0: 11A, 1:11B, 2:11G */
335 	u8 packet_type; /* 0:11a 1:11b 2:11gb 3:11ga */
336 	u32 basic_rates;
337 	u8 top_ofdm_basic_rate;
338 	u8 top_cck_basic_rate;
339 
340 	u8 eeprom[EEP_MAX_CONTEXT_SIZE];  /*u32 alignment */
341 
342 	u8 preamble_type;
343 
344 	/* For RF Power table */
345 	u8 cck_pwr;
346 	u8 ofdm_pwr_g;
347 	u8 ofdm_pwr_a;
348 	u8 power;
349 	u8 cck_pwr_tbl[14];
350 	u8 ofdm_pwr_tbl[14];
351 	u8 ofdm_a_pwr_tbl[42];
352 
353 	u16 current_rate;
354 	u16 tx_rate_fb0;
355 	u16 tx_rate_fb1;
356 
357 	u8 short_retry_limit;
358 	u8 long_retry_limit;
359 
360 	enum nl80211_iftype op_mode;
361 
362 	int short_slot_time;
363 
364 	/* Power save */
365 	u16 current_aid;
366 
367 	/* Beacon related */
368 	u16 seq_counter;
369 
370 	enum vnt_cmd_state command_state;
371 
372 	enum vnt_cmd command;
373 
374 	/* 802.11 counter */
375 
376 	enum vnt_cmd cmd_queue[CMD_Q_SIZE];
377 	u32 cmd_dequeue_idx;
378 	u32 cmd_enqueue_idx;
379 	u32 free_cmd_queue;
380 	int cmd_running;
381 
382 	unsigned long key_entry_inuse;
383 
384 	u8 auto_fb_ctrl;
385 
386 	/* For Update BaseBand VGA Gain Offset */
387 	u8 bb_vga[BB_VGA_LEVEL];
388 
389 	u8 bb_pre_ed_rssi;
390 	u8 bb_pre_ed_index;
391 
392 	u16 wake_up_count;
393 
394 	/* command timer */
395 	struct delayed_work run_command_work;
396 
397 	struct ieee80211_low_level_stats low_stats;
398 };
399 
400 #define ADD_ONE_WITH_WRAP_AROUND(uVar, uModulo) {	\
401 	if ((uVar) >= ((uModulo) - 1))			\
402 		(uVar) = 0;				\
403 	else						\
404 		(uVar)++;				\
405 }
406 
407 int vnt_init(struct vnt_private *priv);
408 
409 #endif
410