]>
Commit | Line | Data |
---|---|---|
92b96797 FB |
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 | * You should have received a copy of the GNU General Public License along | |
16 | * with this program; if not, write to the Free Software Foundation, Inc., | |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 | * | |
19 | * File: device.h | |
20 | * | |
21 | * Purpose: MAC Data structure | |
22 | * | |
23 | * Author: Tevin Chen | |
24 | * | |
25 | * Date: Mar 17, 1997 | |
26 | * | |
27 | */ | |
28 | ||
29 | #ifndef __DEVICE_H__ | |
30 | #define __DEVICE_H__ | |
31 | ||
92b96797 | 32 | #include <linux/module.h> |
92b96797 | 33 | #include <linux/kernel.h> |
92b96797 | 34 | #include <linux/slab.h> |
11d404cb MP |
35 | #include <linux/delay.h> |
36 | #include <linux/device.h> | |
37 | #include <linux/firmware.h> | |
11d404cb | 38 | #include <linux/suspend.h> |
92b96797 | 39 | #include <linux/if_arp.h> |
11d404cb | 40 | #include <linux/wireless.h> |
11d404cb | 41 | #include <linux/timer.h> |
92b96797 | 42 | #include <linux/usb.h> |
f0fde117 | 43 | #include <linux/crc32.h> |
63b9907f | 44 | #include <net/mac80211.h> |
11d404cb | 45 | |
92b96797 FB |
46 | #ifdef SIOCETHTOOL |
47 | #define DEVICE_ETHTOOL_IOCTL_SUPPORT | |
48 | #include <linux/ethtool.h> | |
49 | #else | |
50 | #undef DEVICE_ETHTOOL_IOCTL_SUPPORT | |
51 | #endif | |
92b96797 | 52 | |
f07e9fb2 MP |
53 | #define RATE_1M 0 |
54 | #define RATE_2M 1 | |
55 | #define RATE_5M 2 | |
56 | #define RATE_11M 3 | |
57 | #define RATE_6M 4 | |
58 | #define RATE_9M 5 | |
59 | #define RATE_12M 6 | |
60 | #define RATE_18M 7 | |
61 | #define RATE_24M 8 | |
62 | #define RATE_36M 9 | |
63 | #define RATE_48M 10 | |
64 | #define RATE_54M 11 | |
65 | #define RATE_AUTO 12 | |
66 | ||
4aeaf153 MP |
67 | #define MAX_RATE 12 |
68 | ||
d3e23951 AM |
69 | /* |
70 | * device specific | |
71 | */ | |
92b96797 | 72 | |
92b96797 | 73 | #include "wcmd.h" |
92b96797 | 74 | #include "desc.h" |
92b96797 | 75 | #include "key.h" |
92b96797 | 76 | #include "card.h" |
92b96797 | 77 | |
5008c456 | 78 | #define VNT_USB_VENDOR_ID 0x160a |
92b96797 FB |
79 | #define VNT_USB_PRODUCT_ID 0x3184 |
80 | ||
4aeaf153 MP |
81 | #define DEVICE_NAME "vt6656" |
82 | #define DEVICE_FULL_DRV_NAM "VIA Networking Wireless LAN USB Driver" | |
83 | ||
84 | #define DEVICE_VERSION "1.19_12" | |
85 | ||
86 | #define CONFIG_PATH "/etc/vntconfiguration.dat" | |
87 | ||
88 | #define MAX_UINTS 8 | |
89 | #define OPTION_DEFAULT { [0 ... MAX_UINTS-1] = -1} | |
90 | ||
92b96797 FB |
91 | #define DUPLICATE_RX_CACHE_LENGTH 5 |
92 | ||
92b96797 FB |
93 | #define AUTO_FB_NONE 0 |
94 | #define AUTO_FB_0 1 | |
95 | #define AUTO_FB_1 2 | |
96 | ||
97 | #define FB_RATE0 0 | |
98 | #define FB_RATE1 1 | |
99 | ||
d3e23951 | 100 | /* Antenna Mode */ |
92b96797 FB |
101 | #define ANT_A 0 |
102 | #define ANT_B 1 | |
103 | #define ANT_DIVERSITY 2 | |
104 | #define ANT_RXD_TXA 3 | |
105 | #define ANT_RXD_TXB 4 | |
106 | #define ANT_UNKNOWN 0xFF | |
107 | #define ANT_TXA 0 | |
108 | #define ANT_TXB 1 | |
109 | #define ANT_RXA 2 | |
110 | #define ANT_RXB 3 | |
111 | ||
92b96797 FB |
112 | #define BB_VGA_LEVEL 4 |
113 | #define BB_VGA_CHANGE_THRESHOLD 3 | |
114 | ||
15baf4ff MP |
115 | #define EEP_MAX_CONTEXT_SIZE 256 |
116 | ||
117 | /* Contents in the EEPROM */ | |
118 | #define EEP_OFS_PAR 0x0 | |
119 | #define EEP_OFS_ANTENNA 0x17 | |
120 | #define EEP_OFS_RADIOCTL 0x18 | |
121 | #define EEP_OFS_RFTYPE 0x1b | |
122 | #define EEP_OFS_MINCHANNEL 0x1c | |
123 | #define EEP_OFS_MAXCHANNEL 0x1d | |
124 | #define EEP_OFS_SIGNATURE 0x1e | |
125 | #define EEP_OFS_ZONETYPE 0x1f | |
126 | #define EEP_OFS_RFTABLE 0x20 | |
127 | #define EEP_OFS_PWR_CCK 0x20 | |
128 | #define EEP_OFS_SETPT_CCK 0x21 | |
129 | #define EEP_OFS_PWR_OFDMG 0x23 | |
130 | ||
131 | #define EEP_OFS_CALIB_TX_IQ 0x24 | |
132 | #define EEP_OFS_CALIB_TX_DC 0x25 | |
133 | #define EEP_OFS_CALIB_RX_IQ 0x26 | |
134 | ||
135 | #define EEP_OFS_MAJOR_VER 0x2e | |
136 | #define EEP_OFS_MINOR_VER 0x2f | |
137 | ||
138 | #define EEP_OFS_CCK_PWR_TBL 0x30 | |
139 | #define EEP_OFS_OFDM_PWR_TBL 0x40 | |
140 | #define EEP_OFS_OFDMA_PWR_TBL 0x50 | |
141 | ||
142 | /* Bits in EEP_OFS_ANTENNA */ | |
143 | #define EEP_ANTENNA_MAIN 0x1 | |
144 | #define EEP_ANTENNA_AUX 0x2 | |
145 | #define EEP_ANTINV 0x4 | |
146 | ||
147 | /* Bits in EEP_OFS_RADIOCTL */ | |
148 | #define EEP_RADIOCTL_ENABLE 0x80 | |
149 | ||
60f8ce8d MP |
150 | /* control commands */ |
151 | #define MESSAGE_TYPE_READ 0x1 | |
152 | #define MESSAGE_TYPE_WRITE 0x0 | |
153 | #define MESSAGE_TYPE_LOCK_OR 0x2 | |
154 | #define MESSAGE_TYPE_LOCK_AND 0x3 | |
155 | #define MESSAGE_TYPE_WRITE_MASK 0x4 | |
156 | #define MESSAGE_TYPE_CARDINIT 0x5 | |
157 | #define MESSAGE_TYPE_INIT_RSP 0x6 | |
158 | #define MESSAGE_TYPE_MACSHUTDOWN 0x7 | |
159 | #define MESSAGE_TYPE_SETKEY 0x8 | |
160 | #define MESSAGE_TYPE_CLRKEYENTRY 0x9 | |
161 | #define MESSAGE_TYPE_WRITE_MISCFF 0xa | |
162 | #define MESSAGE_TYPE_SET_ANTMD 0xb | |
163 | #define MESSAGE_TYPE_SELECT_CHANNLE 0xc | |
164 | #define MESSAGE_TYPE_SET_TSFTBTT 0xd | |
165 | #define MESSAGE_TYPE_SET_SSTIFS 0xe | |
166 | #define MESSAGE_TYPE_CHANGE_BBTYPE 0xf | |
167 | #define MESSAGE_TYPE_DISABLE_PS 0x10 | |
168 | #define MESSAGE_TYPE_WRITE_IFRF 0x11 | |
169 | ||
170 | /* command read/write(index) */ | |
171 | #define MESSAGE_REQUEST_MEM 0x1 | |
172 | #define MESSAGE_REQUEST_BBREG 0x2 | |
173 | #define MESSAGE_REQUEST_MACREG 0x3 | |
174 | #define MESSAGE_REQUEST_EEPROM 0x4 | |
175 | #define MESSAGE_REQUEST_TSF 0x5 | |
176 | #define MESSAGE_REQUEST_TBTT 0x6 | |
177 | #define MESSAGE_REQUEST_BBAGC 0x7 | |
178 | #define MESSAGE_REQUEST_VERSION 0x8 | |
179 | #define MESSAGE_REQUEST_RF_INIT 0x9 | |
180 | #define MESSAGE_REQUEST_RF_INIT2 0xa | |
181 | #define MESSAGE_REQUEST_RF_CH0 0xb | |
182 | #define MESSAGE_REQUEST_RF_CH1 0xc | |
183 | #define MESSAGE_REQUEST_RF_CH2 0xd | |
184 | ||
185 | /* USB registers */ | |
186 | #define USB_REG4 0x604 | |
187 | ||
d9d1ccb5 | 188 | #define DBG_PRT(l, p, args...) { if (l <= msglevel) printk(p, ##args); } |
92b96797 FB |
189 | |
190 | typedef enum __device_msg_level { | |
d9d1ccb5 AM |
191 | MSG_LEVEL_ERR = 0, /* Errors causing abnormal operation */ |
192 | MSG_LEVEL_NOTICE = 1, /* Errors needing user notification */ | |
193 | MSG_LEVEL_INFO = 2, /* Normal message. */ | |
194 | MSG_LEVEL_VERBOSE = 3, /* Will report all trival errors. */ | |
195 | MSG_LEVEL_DEBUG = 4 /* Only for debug purpose. */ | |
92b96797 FB |
196 | } DEVICE_MSG_LEVEL, *PDEVICE_MSG_LEVEL; |
197 | ||
302433da MP |
198 | #define DEVICE_INIT_COLD 0x0 /* cold init */ |
199 | #define DEVICE_INIT_RESET 0x1 /* reset init or Dx to D0 power remain */ | |
200 | #define DEVICE_INIT_DXPL 0x2 /* Dx to D0 power lost init */ | |
92b96797 | 201 | |
60f8ce8d MP |
202 | /* Device init */ |
203 | struct vnt_cmd_card_init { | |
204 | u8 init_class; | |
205 | u8 exist_sw_net_addr; | |
206 | u8 sw_net_addr[6]; | |
207 | u8 short_retry_limit; | |
208 | u8 long_retry_limit; | |
209 | }; | |
210 | ||
211 | struct vnt_rsp_card_init { | |
212 | u8 status; | |
213 | u8 net_addr[6]; | |
214 | u8 rf_type; | |
215 | u8 min_channel; | |
216 | u8 max_channel; | |
217 | }; | |
218 | ||
d3e23951 | 219 | /* USB */ |
92b96797 | 220 | |
d3e23951 AM |
221 | /* |
222 | * Enum of context types for SendPacket | |
223 | */ | |
1450ba62 MP |
224 | enum { |
225 | CONTEXT_DATA_PACKET = 1, | |
d38b13aa MP |
226 | CONTEXT_MGMT_PACKET, |
227 | CONTEXT_BEACON_PACKET | |
1450ba62 | 228 | }; |
92b96797 | 229 | |
d3e23951 | 230 | /* RCB (Receive Control Block) */ |
115cac2e | 231 | struct vnt_rcb { |
dd0a774f MP |
232 | void *Next; |
233 | signed long Ref; | |
234 | void *pDevice; | |
235 | struct urb *pUrb; | |
dd0a774f MP |
236 | struct sk_buff *skb; |
237 | int bBoolInUse; | |
115cac2e | 238 | }; |
92b96797 | 239 | |
d3e23951 | 240 | /* used to track bulk out irps */ |
dcdf1d03 | 241 | struct vnt_usb_send_context { |
30a05b39 MP |
242 | void *priv; |
243 | struct sk_buff *skb; | |
244 | struct urb *urb; | |
1622c8fc | 245 | struct ieee80211_hdr *hdr; |
30a05b39 | 246 | unsigned int buf_len; |
1622c8fc | 247 | u16 tx_hdr_size; |
1450ba62 | 248 | u8 type; |
71d764ae MP |
249 | u8 pkt_no; |
250 | u8 fb_option; | |
30a05b39 MP |
251 | bool in_use; |
252 | unsigned char data[MAX_TOTAL_SIZE_WITH_ALL_HEADERS]; | |
dcdf1d03 | 253 | }; |
92b96797 | 254 | |
51934e7f MP |
255 | /* tx packet info for rxtx */ |
256 | struct vnt_tx_pkt_info { | |
257 | u16 fifo_ctl; | |
258 | u8 dest_addr[ETH_ALEN]; | |
259 | }; | |
260 | ||
d3e23951 AM |
261 | /* |
262 | * Structure to keep track of USB interrupt packets | |
263 | */ | |
f764e00d MP |
264 | struct vnt_interrupt_buffer { |
265 | u8 *data_buf; | |
266 | bool in_use; | |
267 | }; | |
92b96797 | 268 | |
d3e23951 | 269 | /*++ NDIS related */ |
92b96797 | 270 | |
92b96797 | 271 | typedef enum __DEVICE_NDIS_STATUS { |
d9d1ccb5 | 272 | STATUS_SUCCESS = 0, |
92b96797 FB |
273 | STATUS_FAILURE, |
274 | STATUS_RESOURCES, | |
275 | STATUS_PENDING, | |
276 | } DEVICE_NDIS_STATUS, *PDEVICE_NDIS_STATUS; | |
277 | ||
92b96797 | 278 | |
d3e23951 | 279 | /* flags for options */ |
92b96797 | 280 | #define DEVICE_FLAGS_UNPLUG 0x00000001UL |
92b96797 | 281 | |
d3e23951 | 282 | /* flags for driver status */ |
92b96797 | 283 | #define DEVICE_FLAGS_OPENED 0x00010000UL |
92b96797 | 284 | |
14c5ef57 | 285 | struct vnt_private { |
63b9907f MP |
286 | /* mac80211 */ |
287 | struct ieee80211_hw *hw; | |
db8f37fa | 288 | struct ieee80211_vif *vif; |
30816f83 | 289 | u8 mac_hw; |
61462ab3 MP |
290 | /* netdev */ |
291 | struct usb_device *usb; | |
61462ab3 | 292 | struct net_device_stats stats; |
92b96797 | 293 | |
63b9907f MP |
294 | u64 tsf_time; |
295 | u8 rx_rate; | |
296 | ||
61462ab3 | 297 | u32 rx_buf_sz; |
db8f37fa | 298 | int mc_list_count; |
92b96797 | 299 | |
61462ab3 | 300 | spinlock_t lock; |
c91b1869 | 301 | struct mutex usb_lock; |
92b96797 | 302 | |
61462ab3 MP |
303 | u32 flags; |
304 | unsigned long Flags; | |
92b96797 | 305 | |
61462ab3 | 306 | /* USB */ |
61462ab3 | 307 | struct urb *pInterruptURB; |
61462ab3 | 308 | u32 int_interval; |
92b96797 | 309 | |
61462ab3 | 310 | /* Variables to track resources for the BULK In Pipe */ |
115cac2e | 311 | struct vnt_rcb *apRCB[CB_MAX_RX_DESC]; |
61462ab3 | 312 | u32 cbRD; |
92b96797 | 313 | |
61462ab3 | 314 | /* Variables to track resources for the BULK Out Pipe */ |
dcdf1d03 | 315 | struct vnt_usb_send_context *apTD[CB_MAX_TX_DESC]; |
61462ab3 | 316 | u32 cbTD; |
51934e7f | 317 | struct vnt_tx_pkt_info pkt_info[16]; |
92b96797 | 318 | |
61462ab3 | 319 | /* Variables to track resources for the Interrupt In Pipe */ |
f764e00d | 320 | struct vnt_interrupt_buffer int_buf; |
92b96797 | 321 | |
61462ab3 MP |
322 | /* Version control */ |
323 | u16 wFirmwareVersion; | |
324 | u8 byLocalID; | |
325 | u8 byRFType; | |
326 | u8 byBBRxConf; | |
92b96797 | 327 | |
61462ab3 | 328 | u8 byZoneType; |
92b96797 | 329 | |
748bf69c MP |
330 | struct vnt_cmd_card_init init_command; |
331 | struct vnt_rsp_card_init init_response; | |
61462ab3 MP |
332 | u8 abyCurrentNetAddr[ETH_ALEN]; |
333 | u8 abyPermanentNetAddr[ETH_ALEN]; | |
92b96797 | 334 | |
61462ab3 | 335 | int bExistSWNetAddr; |
92b96797 | 336 | |
7c65fa2a | 337 | u64 qwCurrTSF; |
61462ab3 MP |
338 | |
339 | /* 802.11 MAC specific */ | |
340 | u32 uCurrRSSI; | |
61462ab3 MP |
341 | |
342 | /* Antenna Diversity */ | |
343 | int bTxRxAntInv; | |
344 | u32 dwRxAntennaSel; | |
345 | u32 dwTxAntennaSel; | |
346 | u8 byAntennaCount; | |
347 | u8 byRxAntennaMode; | |
348 | u8 byTxAntennaMode; | |
349 | u8 byRadioCtl; | |
350 | u8 bHWRadioOff; | |
351 | ||
cc856e61 | 352 | /* IFS & Cw */ |
61462ab3 MP |
353 | u32 uSIFS; /* Current SIFS */ |
354 | u32 uDIFS; /* Current DIFS */ | |
355 | u32 uEIFS; /* Current EIFS */ | |
356 | u32 uSlot; /* Current SlotTime */ | |
357 | u32 uCwMin; /* Current CwMin */ | |
358 | u32 uCwMax; /* CwMax is fixed on 1023 */ | |
359 | ||
61462ab3 | 360 | /* Rate */ |
a9052bc9 | 361 | u8 byBBType; /* 0: 11A, 1:11B, 2:11G */ |
bf1c820f | 362 | u8 byPacketType; /* 0:11a 1:11b 2:11gb 3:11ga */ |
ee61fde2 | 363 | u32 wBasicRate; |
61462ab3 MP |
364 | u8 byTopOFDMBasicRate; |
365 | u8 byTopCCKBasicRate; | |
366 | ||
61462ab3 MP |
367 | u8 abyEEPROM[EEP_MAX_CONTEXT_SIZE]; /*u32 alignment */ |
368 | ||
61462ab3 | 369 | u8 byPreambleType; |
61462ab3 MP |
370 | |
371 | /* For RF Power table */ | |
372 | u8 byCCKPwr; | |
373 | u8 byOFDMPwrG; | |
374 | u8 byOFDMPwrA; | |
375 | u8 byCurPwr; | |
376 | u8 abyCCKPwrTbl[14]; | |
377 | u8 abyOFDMPwrTbl[14]; | |
378 | u8 abyOFDMAPwrTbl[42]; | |
379 | ||
380 | u16 wCurrentRate; | |
f84cdf65 MP |
381 | u16 tx_rate_fb0; |
382 | u16 tx_rate_fb1; | |
383 | ||
61462ab3 MP |
384 | u8 byShortRetryLimit; |
385 | u8 byLongRetryLimit; | |
a0ad2776 MP |
386 | |
387 | enum nl80211_iftype op_mode; | |
388 | ||
61462ab3 | 389 | int bShortSlotTime; |
61462ab3 MP |
390 | int bBarkerPreambleMd; |
391 | ||
61462ab3 MP |
392 | int bRadioControlOff; |
393 | int bRadioOff; | |
394 | ||
395 | /* Power save */ | |
db8f37fa | 396 | u16 current_aid; |
61462ab3 MP |
397 | |
398 | /* Beacon releated */ | |
399 | u16 wSeqCounter; | |
61462ab3 | 400 | |
ad74e91d | 401 | enum vnt_cmd_state command_state; |
61462ab3 | 402 | |
80f0d092 | 403 | enum vnt_cmd command; |
61462ab3 | 404 | |
61462ab3 | 405 | int bStopDataPkt; |
61462ab3 MP |
406 | |
407 | /* 802.11 counter */ | |
408 | ||
409 | CMD_ITEM eCmdQueue[CMD_Q_SIZE]; | |
410 | u32 uCmdDequeueIdx; | |
411 | u32 uCmdEnqueueIdx; | |
412 | u32 cbFreeCmdQueue; | |
413 | int bCmdRunning; | |
414 | int bCmdClear; | |
415 | int bNeedRadioOFF; | |
416 | ||
d1eb5003 | 417 | unsigned long key_entry_inuse; |
61462ab3 | 418 | |
61462ab3 MP |
419 | u8 byAutoFBCtrl; |
420 | ||
61462ab3 | 421 | /* For Update BaseBand VGA Gain Offset */ |
61462ab3 MP |
422 | u32 uBBVGADiffCount; |
423 | u8 byBBVGANew; | |
424 | u8 byBBVGACurrent; | |
425 | u8 abyBBVGA[BB_VGA_LEVEL]; | |
426 | signed long ldBmThreshold[BB_VGA_LEVEL]; | |
427 | ||
428 | u8 byBBPreEDRSSI; | |
429 | u8 byBBPreEDIndex; | |
430 | ||
61462ab3 | 431 | int bRadioCmd; |
61462ab3 | 432 | |
61462ab3 | 433 | /* command timer */ |
94488a7e | 434 | struct delayed_work run_command_work; |
92b96797 | 435 | |
60cc2747 | 436 | u8 tx_data_time_out; |
92b96797 | 437 | |
61462ab3 MP |
438 | int bChannelSwitch; |
439 | u8 byNewChannel; | |
440 | u8 byChannelSwitchCount; | |
92b96797 | 441 | |
61462ab3 | 442 | struct iw_statistics wstats; /* wireless stats */ |
1786384e | 443 | struct ieee80211_low_level_stats low_stats; |
14c5ef57 | 444 | }; |
92b96797 | 445 | |
92b96797 FB |
446 | #define ADD_ONE_WITH_WRAP_AROUND(uVar, uModulo) { \ |
447 | if ((uVar) >= ((uModulo) - 1)) \ | |
448 | (uVar) = 0; \ | |
449 | else \ | |
450 | (uVar)++; \ | |
451 | } | |
452 | ||
92b96797 | 453 | #define fMP_DISCONNECTED 0x00000002 |
92b96797 FB |
454 | #define fMP_POST_READS 0x00000100 |
455 | #define fMP_POST_WRITES 0x00000200 | |
92b96797 | 456 | |
92b96797 FB |
457 | #define MP_SET_FLAG(_M, _F) ((_M)->Flags |= (_F)) |
458 | #define MP_CLEAR_FLAG(_M, _F) ((_M)->Flags &= ~(_F)) | |
92b96797 FB |
459 | #define MP_TEST_FLAGS(_M, _F) (((_M)->Flags & (_F)) == (_F)) |
460 | ||
d4f376dd | 461 | #define MP_IS_READY(_M) (((_M)->Flags & fMP_DISCONNECTED) == 0) |
92b96797 | 462 | |
30816f83 | 463 | int vnt_init(struct vnt_private *priv); |
92b96797 FB |
464 | |
465 | #endif |