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.
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.
21 * Purpose: MAC Data structure
32 #include <linux/module.h>
33 #include <linux/types.h>
35 #include <linux/errno.h>
36 #include <linux/ioport.h>
37 #include <linux/pci.h>
38 #include <linux/kernel.h>
39 #include <linux/netdevice.h>
40 #include <linux/etherdevice.h>
41 #include <linux/skbuff.h>
42 #include <linux/delay.h>
43 #include <linux/timer.h>
44 #include <linux/slab.h>
45 #include <linux/interrupt.h>
46 #include <linux/string.h>
47 #include <linux/wait.h>
48 #include <linux/if_arp.h>
49 #include <linux/sched.h>
52 #include <linux/crc32.h>
53 #include <linux/uaccess.h>
54 #include <linux/proc_fs.h>
55 #include <linux/inetdevice.h>
56 #include <linux/reboot.h>
57 #include <linux/ethtool.h>
58 /* Include Wireless Extension definition and check version - Jean II */
59 #include <net/mac80211.h>
60 #include <linux/wireless.h>
61 #include <net/iw_handler.h> /* New driver API */
63 #ifndef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
64 #define WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
69 #include "device_cfg.h"
76 /*--------------------- Export Definitions -------------------------*/
93 #define MAC_MAX_CONTEXT_REG (256+128)
95 #define MAX_MULTICAST_ADDRESS_NUM 32
96 #define MULTICAST_ADDRESS_LIST_SIZE (MAX_MULTICAST_ADDRESS_NUM * ETH_ALEN)
98 #define DUPLICATE_RX_CACHE_LENGTH 5
100 #define NUM_KEY_ENTRY 11
102 #define TX_WEP_NONE 0
105 #define TX_WEP_SWOTP 3
106 #define TX_WEP_OTPSW 4
107 #define TX_WEP_SW232 5
109 #define KEYSEL_WEP40 0
110 #define KEYSEL_WEP104 1
111 #define KEYSEL_TKIP 2
112 #define KEYSEL_CCMP 3
114 #define AUTO_FB_NONE 0
124 #define ANT_DIVERSITY 2
125 #define ANT_RXD_TXA 3
126 #define ANT_RXD_TXB 4
127 #define ANT_UNKNOWN 0xFF
129 #define MAXCHECKHANGCNT 4
131 #define BB_VGA_LEVEL 4
132 #define BB_VGA_CHANGE_THRESHOLD 16
135 #define RUN_AT(x) (jiffies+(x))
138 #define MAKE_BEACON_RESERVED 10 /* (us) */
141 #define RESERV_AC0DMA 4
145 #define AVAIL_TD(p, q) ((p)->sOpts.nTxDescs[(q)] - ((p)->iTDUsed[(q)]))
149 /* 0:11A 1:11B 2:11G */
150 #define BB_TYPE_11A 0
151 #define BB_TYPE_11B 1
152 #define BB_TYPE_11G 2
154 /* 0:11a, 1:11b, 2:11gb (only CCK in BasicRate), 3:11ga (OFDM in BasicRate) */
155 #define PK_TYPE_11A 0
156 #define PK_TYPE_11B 1
157 #define PK_TYPE_11GB 2
158 #define PK_TYPE_11GA 3
160 typedef struct __chip_info_tbl {
166 } CHIP_INFO, *PCHIP_INFO;
171 } DEVICE_OWNER_TYPE, *PDEVICE_OWNER_TYPE;
173 /* flags for options */
174 #define DEVICE_FLAGS_IP_ALIGN 0x00000001UL
175 #define DEVICE_FLAGS_PREAMBLE_TYPE 0x00000002UL
176 #define DEVICE_FLAGS_OP_MODE 0x00000004UL
177 #define DEVICE_FLAGS_PS_MODE 0x00000008UL
178 #define DEVICE_FLAGS_80211h_MODE 0x00000010UL
179 #define DEVICE_FLAGS_DiversityANT 0x00000020UL
181 /* flags for driver status */
182 #define DEVICE_FLAGS_OPENED 0x00010000UL
183 #define DEVICE_FLAGS_WOL_ENABLED 0x00080000UL
184 /* flags for capabilities */
185 #define DEVICE_FLAGS_TX_ALIGN 0x01000000UL
186 #define DEVICE_FLAGS_HAVE_CAM 0x02000000UL
187 #define DEVICE_FLAGS_FLOW_CTRL 0x04000000UL
189 /* flags for MII status */
190 #define DEVICE_LINK_FAIL 0x00000001UL
191 #define DEVICE_SPEED_10 0x00000002UL
192 #define DEVICE_SPEED_100 0x00000004UL
193 #define DEVICE_SPEED_1000 0x00000008UL
194 #define DEVICE_DUPLEX_FULL 0x00000010UL
195 #define DEVICE_AUTONEG_ENABLE 0x00000020UL
196 #define DEVICE_FORCED_BY_EEPROM 0x00000040UL
197 /* for device_set_media_duplex */
198 #define DEVICE_LINK_CHANGE 0x00000001UL
200 typedef struct __device_opt {
201 int nRxDescs0; /* Number of RX descriptors0 */
202 int nRxDescs1; /* Number of RX descriptors1 */
203 int nTxDescs[2]; /* Number of TX descriptors 0, 1 */
204 int int_works; /* interrupt limits */
209 } OPTIONS, *POPTIONS;
212 struct pci_dev *pcid;
214 struct ieee80211_hw *hw;
215 struct ieee80211_vif *vif;
216 unsigned long key_entry_inuse;
222 /* dma addr, rx/tx pool */
224 dma_addr_t rd0_pool_dma;
225 dma_addr_t rd1_pool_dma;
227 dma_addr_t td0_pool_dma;
228 dma_addr_t td1_pool_dma;
230 dma_addr_t tx_bufs_dma0;
231 dma_addr_t tx_bufs_dma1;
232 dma_addr_t tx_beacon_dma;
234 unsigned char *tx0_bufs;
235 unsigned char *tx1_bufs;
236 unsigned char *tx_beacon_bufs;
240 void __iomem *PortOffset;
245 unsigned char byRevId;
246 unsigned char byRxMode;
247 unsigned short SubSystemID;
248 unsigned short SubVendorID;
253 volatile int iTDUsed[TYPE_MAXTD];
255 struct vnt_tx_desc *apCurrTD[TYPE_MAXTD];
256 struct vnt_tx_desc *apTailTD[TYPE_MAXTD];
258 struct vnt_tx_desc *apTD0Rings;
259 struct vnt_tx_desc *apTD1Rings;
261 volatile PSRxDesc aRD0Ring;
262 volatile PSRxDesc aRD1Ring;
263 volatile PSRxDesc pCurrRD[TYPE_MAXRD];
275 /* Version control */
276 unsigned char byLocalID;
277 unsigned char byRFType;
279 unsigned char byMaxPwrLevel;
280 unsigned char byZoneType;
282 unsigned char byOriginalZonetype;
284 unsigned char abyCurrentNetAddr[ETH_ALEN]; __aligned(2)
285 bool bLinkPass; /* link status: OK or fail */
287 unsigned int uCurrRSSI;
288 unsigned char byCurrSQ;
290 unsigned long dwTxAntennaSel;
291 unsigned long dwRxAntennaSel;
292 unsigned char byAntennaCount;
293 unsigned char byRxAntennaMode;
294 unsigned char byTxAntennaMode;
297 unsigned char *pbyTmpBuff;
298 unsigned int uSIFS; /* Current SIFS */
299 unsigned int uDIFS; /* Current DIFS */
300 unsigned int uEIFS; /* Current EIFS */
301 unsigned int uSlot; /* Current SlotTime */
302 unsigned int uCwMin; /* Current CwMin */
303 unsigned int uCwMax; /* CwMax is fixed on 1023. */
305 unsigned char bySIFS;
306 unsigned char byDIFS;
307 unsigned char byEIFS;
308 unsigned char bySlot;
309 unsigned char byCWMaxMin;
311 u8 byBBType; /* 0:11A, 1:11B, 2:11G */
313 * 0:11a,1:11b,2:11gb (only CCK
314 * in BasicRate), 3:11ga (OFDM in
317 unsigned short wBasicRate;
318 unsigned char byACKRate;
319 unsigned char byTopOFDMBasicRate;
320 unsigned char byTopCCKBasicRate;
322 unsigned char byMinChannel;
323 unsigned char byMaxChannel;
325 unsigned char byPreambleType;
326 unsigned char byShortPreamble;
328 unsigned short wCurrentRate;
329 unsigned char byShortRetryLimit;
330 unsigned char byLongRetryLimit;
331 enum nl80211_iftype op_mode;
333 unsigned short wMaxTransmitMSDULifetime;
335 bool bEncryptionEnable;
340 bool bBarkerPreambleMd;
342 bool bRadioControlOff;
345 unsigned short wListenInterval;
348 /* GPIO Radio Control */
349 unsigned char byRadioCtl;
350 unsigned char byGPIO;
352 bool bPrvActive4RadioOFF;
356 unsigned short wSeqCounter;
357 unsigned short wBCNBufLen;
358 bool bBeaconBufReady;
360 bool bIsBeaconBufReadySet;
361 unsigned int cbBeaconBufReadySetCnt;
367 unsigned char byAutoFBCtrl;
369 /* For Update BaseBand VGA Gain Offset */
371 unsigned int uBBVGADiffCount;
372 unsigned char byBBVGANew;
373 unsigned char byBBVGACurrent;
374 unsigned char abyBBVGA[BB_VGA_LEVEL];
375 long ldBmThreshold[BB_VGA_LEVEL];
377 unsigned char byBBPreEDRSSI;
378 unsigned char byBBPreEDIndex;
380 unsigned long dwDiagRefCount;
383 unsigned char byFOETuning;
385 /* For RF Power table */
386 unsigned char byCCKPwr;
387 unsigned char byOFDMPwrG;
388 unsigned char byCurPwr;
390 unsigned char abyCCKPwrTbl[CB_MAX_CHANNEL_24G+1];
391 unsigned char abyOFDMPwrTbl[CB_MAX_CHANNEL+1];
392 char abyCCKDefaultPwr[CB_MAX_CHANNEL_24G+1];
393 char abyOFDMDefaultPwr[CB_MAX_CHANNEL+1];
394 char abyRegPwr[CB_MAX_CHANNEL+1];
395 char abyLocalPwr[CB_MAX_CHANNEL+1];
397 /* BaseBand Loopback Use */
398 unsigned char byBBCR4d;
399 unsigned char byBBCRc9;
400 unsigned char byBBCR88;
401 unsigned char byBBCR09;
403 unsigned char abyEEPROM[EEP_MAX_CONTEXT_SIZE]; /* unsigned long alignment */
405 unsigned short wBeaconInterval;
408 struct work_struct interrupt_work;
410 struct ieee80211_low_level_stats low_stats;
413 static inline PDEVICE_RD_INFO alloc_rd_info(void)
415 return kzalloc(sizeof(DEVICE_RD_INFO), GFP_ATOMIC);
418 static inline struct vnt_td_info *alloc_td_info(void)
420 return kzalloc(sizeof(struct vnt_td_info), GFP_ATOMIC);