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/kernel.h>
34 #include <linux/slab.h>
35 #include <linux/init.h>
36 #include <linux/delay.h>
37 #include <linux/device.h>
38 #include <linux/firmware.h>
39 #include <linux/etherdevice.h>
40 #include <linux/suspend.h>
41 #include <linux/if_arp.h>
42 #include <linux/wireless.h>
43 #include <net/iw_handler.h>
44 #include <net/cfg80211.h>
45 #include <linux/timer.h>
46 #include <linux/usb.h>
49 #define DEVICE_ETHTOOL_IOCTL_SUPPORT
50 #include <linux/ethtool.h>
52 #undef DEVICE_ETHTOOL_IOCTL_SUPPORT
55 /* please copy below macro to driver_event.c for API */
56 #define RT_INSMOD_EVENT_FLAG 0x0101
57 #define RT_UPDEV_EVENT_FLAG 0x0102
58 #define RT_DISCONNECTED_EVENT_FLAG 0x0103
59 #define RT_WPACONNECTED_EVENT_FLAG 0x0104
60 #define RT_DOWNDEV_EVENT_FLAG 0x0105
61 #define RT_RMMOD_EVENT_FLAG 0x0106
67 #include "device_cfg.h"
79 #define VNT_USB_VENDOR_ID 0x160a
80 #define VNT_USB_PRODUCT_ID 0x3184
82 #define MAC_MAX_CONTEXT_REG (256+128)
84 #define MAX_MULTICAST_ADDRESS_NUM 32
85 #define MULTICAST_ADDRESS_LIST_SIZE (MAX_MULTICAST_ADDRESS_NUM * ETH_ALEN)
87 #define DUPLICATE_RX_CACHE_LENGTH 5
89 #define NUM_KEY_ENTRY 11
94 #define TX_WEP_SWOTP 3
95 #define TX_WEP_OTPSW 4
96 #define TX_WEP_SW232 5
98 #define KEYSEL_WEP40 0
99 #define KEYSEL_WEP104 1
100 #define KEYSEL_TKIP 2
101 #define KEYSEL_CCMP 3
103 #define AUTO_FB_NONE 0
113 #define ANT_DIVERSITY 2
114 #define ANT_RXD_TXA 3
115 #define ANT_RXD_TXB 4
116 #define ANT_UNKNOWN 0xFF
122 #define MAXCHECKHANGCNT 4
125 #define TX_PKT_UNI 0x00
126 #define TX_PKT_MULTI 0x01
127 #define TX_PKT_BROAD 0x02
129 #define BB_VGA_LEVEL 4
130 #define BB_VGA_CHANGE_THRESHOLD 3
133 #define RUN_AT(x) (jiffies+(x))
137 #define RESERV_AC0DMA 4
139 #define PRIVATE_Message 0
141 #define DBG_PRT(l, p, args...) { if (l <= msglevel) printk(p, ##args); }
142 #define PRINT_K(p, args...) { if (PRIVATE_Message) printk(p, ##args); }
144 typedef enum __device_msg_level
{
145 MSG_LEVEL_ERR
= 0, /* Errors causing abnormal operation */
146 MSG_LEVEL_NOTICE
= 1, /* Errors needing user notification */
147 MSG_LEVEL_INFO
= 2, /* Normal message. */
148 MSG_LEVEL_VERBOSE
= 3, /* Will report all trival errors. */
149 MSG_LEVEL_DEBUG
= 4 /* Only for debug purpose. */
150 } DEVICE_MSG_LEVEL
, *PDEVICE_MSG_LEVEL
;
152 typedef enum __device_init_type
{
153 DEVICE_INIT_COLD
= 0, /* cold init */
154 DEVICE_INIT_RESET
, /* reset init or Dx to D0 power remain */
155 DEVICE_INIT_DXPL
/* Dx to D0 power lost init */
156 } DEVICE_INIT_TYPE
, *PDEVICE_INIT_TYPE
;
161 * Enum of context types for SendPacket
163 typedef enum _CONTEXT_TYPE
{
164 CONTEXT_DATA_PACKET
= 1,
168 /* RCB (Receive Control Block) */
174 struct vnt_rx_mgmt sMngPacket
;
179 /* used to track bulk out irps */
180 struct vnt_usb_send_context
{
182 struct sk_buff
*pPacket
;
184 unsigned int uBufLen
;
186 struct ethhdr sEthHeader
;
189 unsigned char Data
[MAX_TOTAL_SIZE_WITH_ALL_HEADERS
];
192 /* structure got from configuration file as user-desired default settings */
193 typedef struct _DEFAULT_CONFIG
{
195 signed int eConfigMode
;
196 signed int eAuthenMode
; /* open/wep/wpa */
197 signed int bShareKeyAlgorithm
; /* open-open/{open,wep}-sharekey */
198 signed int keyidx
; /* wepkey index */
199 signed int eEncryptionStatus
;
200 } DEFAULT_CONFIG
, *PDEFAULT_CONFIG
;
203 * Structure to keep track of USB interrupt packets
206 unsigned int uDataLen
;
208 /* struct urb *pUrb; */
210 } INT_BUFFER
, *PINT_BUFFER
;
212 /* 0:11A 1:11B 2:11G */
213 typedef enum _VIA_BB_TYPE
218 } VIA_BB_TYPE
, *PVIA_BB_TYPE
;
220 /* 0:11a, 1:11b, 2:11gb (only CCK in BasicRate), 3:11ga(OFDM in BasicRate) */
221 typedef enum _VIA_PKT_TYPE
227 } VIA_PKT_TYPE
, *PVIA_PKT_TYPE
;
231 typedef enum __DEVICE_NDIS_STATUS
{
236 } DEVICE_NDIS_STATUS
, *PDEVICE_NDIS_STATUS
;
238 #define MAX_BSSIDINFO_4_PMKID 16
239 #define MAX_PMKIDLIST 5
240 /* flags for PMKID Candidate list structure */
241 #define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
243 /* PMKID Structures */
244 typedef unsigned char NDIS_802_11_PMKID_VALUE
[16];
246 typedef enum _NDIS_802_11_WEP_STATUS
248 Ndis802_11WEPEnabled
,
249 Ndis802_11Encryption1Enabled
= Ndis802_11WEPEnabled
,
250 Ndis802_11WEPDisabled
,
251 Ndis802_11EncryptionDisabled
= Ndis802_11WEPDisabled
,
252 Ndis802_11WEPKeyAbsent
,
253 Ndis802_11Encryption1KeyAbsent
= Ndis802_11WEPKeyAbsent
,
254 Ndis802_11WEPNotSupported
,
255 Ndis802_11EncryptionNotSupported
= Ndis802_11WEPNotSupported
,
256 Ndis802_11Encryption2Enabled
,
257 Ndis802_11Encryption2KeyAbsent
,
258 Ndis802_11Encryption3Enabled
,
259 Ndis802_11Encryption3KeyAbsent
260 } NDIS_802_11_WEP_STATUS
, *PNDIS_802_11_WEP_STATUS
,
261 NDIS_802_11_ENCRYPTION_STATUS
, *PNDIS_802_11_ENCRYPTION_STATUS
;
263 typedef enum _NDIS_802_11_STATUS_TYPE
265 Ndis802_11StatusType_Authentication
,
266 Ndis802_11StatusType_MediaStreamMode
,
267 Ndis802_11StatusType_PMKID_CandidateList
,
268 Ndis802_11StatusTypeMax
, /* not a real type, defined as upper bound */
269 } NDIS_802_11_STATUS_TYPE
, *PNDIS_802_11_STATUS_TYPE
;
271 /* added new types for PMKID Candidate lists */
272 typedef struct _PMKID_CANDIDATE
{
273 NDIS_802_11_MAC_ADDRESS BSSID
;
275 } PMKID_CANDIDATE
, *PPMKID_CANDIDATE
;
277 typedef struct _BSSID_INFO
279 NDIS_802_11_MAC_ADDRESS BSSID
;
280 NDIS_802_11_PMKID_VALUE PMKID
;
281 } BSSID_INFO
, *PBSSID_INFO
;
283 typedef struct tagSPMKID
{
284 unsigned long Length
;
285 unsigned long BSSIDInfoCount
;
286 BSSID_INFO BSSIDInfo
[MAX_BSSIDINFO_4_PMKID
];
289 typedef struct tagSPMKIDCandidateEvent
{
290 NDIS_802_11_STATUS_TYPE StatusType
;
291 unsigned long Version
; /* Version of the structure */
292 unsigned long NumCandidates
; /* No. of pmkid candidates */
293 PMKID_CANDIDATE CandidateList
[MAX_PMKIDLIST
];
294 } SPMKIDCandidateEvent
, *PSPMKIDCandidateEvent
;
296 /*++ 802.11h related */
297 #define MAX_QUIET_COUNT 8
299 typedef struct tagSQuietControl
{
304 } SQuietControl
, *PSQuietControl
;
306 /* The receive duplicate detection cache entry */
307 typedef struct tagSCacheEntry
{
309 u8 abyAddr2
[ETH_ALEN
];
311 } SCacheEntry
, *PSCacheEntry
;
313 typedef struct tagSCache
{
314 /* The receive cache is updated circularly. The next entry to be written is
315 * indexed by the "InPtr".
317 unsigned int uInPtr
; /* Place to use next */
318 SCacheEntry asCacheEntry
[DUPLICATE_RX_CACHE_LENGTH
];
321 #define CB_MAX_RX_FRAG 64
323 * DeFragment Control Block, used for collecting fragments prior to reassembly
325 typedef struct tagSDeFragControlBlock
329 u8 abyAddr2
[ETH_ALEN
];
330 unsigned int uLifetime
;
333 unsigned int cbFrameLength
;
335 } SDeFragControlBlock
, *PSDeFragControlBlock
;
337 /* flags for options */
338 #define DEVICE_FLAGS_UNPLUG 0x00000001UL
339 #define DEVICE_FLAGS_PREAMBLE_TYPE 0x00000002UL
340 #define DEVICE_FLAGS_OP_MODE 0x00000004UL
341 #define DEVICE_FLAGS_PS_MODE 0x00000008UL
342 #define DEVICE_FLAGS_80211h_MODE 0x00000010UL
344 /* flags for driver status */
345 #define DEVICE_FLAGS_OPENED 0x00010000UL
346 #define DEVICE_FLAGS_WOL_ENABLED 0x00080000UL
347 /* flags for capabilities */
348 #define DEVICE_FLAGS_TX_ALIGN 0x01000000UL
349 #define DEVICE_FLAGS_HAVE_CAM 0x02000000UL
350 #define DEVICE_FLAGS_FLOW_CTRL 0x04000000UL
352 /* flags for MII status */
353 #define DEVICE_LINK_FAIL 0x00000001UL
354 #define DEVICE_SPEED_10 0x00000002UL
355 #define DEVICE_SPEED_100 0x00000004UL
356 #define DEVICE_SPEED_1000 0x00000008UL
357 #define DEVICE_DUPLEX_FULL 0x00000010UL
358 #define DEVICE_AUTONEG_ENABLE 0x00000020UL
359 #define DEVICE_FORCED_BY_EEPROM 0x00000040UL
360 /* for device_set_media_duplex */
361 #define DEVICE_LINK_CHANGE 0x00000001UL
363 typedef struct __device_opt
{
364 int nRxDescs0
; /* number of RX descriptors 0 */
365 int nTxDescs0
; /* number of TX descriptors 0, 1, 2, 3 */
366 int rts_thresh
; /* RTS threshold */
375 } OPTIONS
, *POPTIONS
;
379 struct usb_device
*usb
;
380 struct net_device
*dev
;
381 struct net_device_stats stats
;
385 struct tasklet_struct CmdWorkItem
;
386 struct tasklet_struct EventWorkItem
;
387 struct tasklet_struct ReadWorkItem
;
388 struct tasklet_struct RxMngWorkItem
;
405 SDeFragControlBlock sRxDFCB
[CB_MAX_RX_FRAG
];
411 struct urb
*pControlURB
;
412 struct urb
*pInterruptURB
;
413 struct usb_ctrlrequest sUsbCtlRequest
;
416 /* Variables to track resources for the BULK In Pipe */
417 struct vnt_rcb
*pRCBMem
;
418 struct vnt_rcb
*apRCB
[CB_MAX_RX_DESC
];
420 struct vnt_rcb
*FirstRecvFreeList
;
421 struct vnt_rcb
*LastRecvFreeList
;
423 struct vnt_rcb
*FirstRecvMngList
;
424 struct vnt_rcb
*LastRecvMngList
;
426 int bIsRxWorkItemQueued
;
427 int bIsRxMngWorkItemQueued
;
428 unsigned long ulRcvRefCount
; /* packets that have not returned back */
430 /* Variables to track resources for the BULK Out Pipe */
431 struct vnt_usb_send_context
*apTD
[CB_MAX_TX_DESC
];
434 /* Variables to track resources for the Interrupt In Pipe */
436 int fKillEventPollingThread
;
439 /* default config from file by user setting */
440 DEFAULT_CONFIG config_file
;
442 /* Statistic for USB */
443 unsigned long ulBulkInPosted
;
444 unsigned long ulBulkInError
;
445 unsigned long ulBulkInContCRCError
;
446 unsigned long ulBulkInBytesRead
;
448 unsigned long ulBulkOutPosted
;
449 unsigned long ulBulkOutError
;
450 unsigned long ulBulkOutContCRCError
;
451 unsigned long ulBulkOutBytesWrite
;
453 unsigned long ulIntInPosted
;
454 unsigned long ulIntInError
;
455 unsigned long ulIntInContCRCError
;
456 unsigned long ulIntInBytesRead
;
458 /* Version control */
459 u16 wFirmwareVersion
;
467 u8 byOriginalZonetype
;
469 int bLinkPass
; /* link status: OK or fail */
470 u8 abyCurrentNetAddr
[ETH_ALEN
];
471 u8 abyPermanentNetAddr
[ETH_ALEN
];
475 /* Adapter statistics */
476 SStatCounter scStatistic
;
478 SDot11Counters s802_11Counter
;
480 /* Maintain statistical debug info. */
481 unsigned long packetsReceived
;
482 unsigned long packetsReceivedDropped
;
483 unsigned long packetsReceivedOverflow
;
484 unsigned long packetsSent
;
485 unsigned long packetsSentDropped
;
486 unsigned long SendContextsInUse
;
487 unsigned long RcvBuffersInUse
;
489 /* 802.11 management */
490 struct vnt_manager vnt_mgmt
;
496 /* 802.11 MAC specific */
500 /* Antenna Diversity */
510 /* SQ3 functions for antenna diversity */
511 struct timer_list TimerSQ3Tmax1
;
512 struct timer_list TimerSQ3Tmax2
;
513 struct timer_list TimerSQ3Tmax3
;
515 int bDiversityRegCtlON
;
516 int bDiversityEnable
;
517 unsigned long ulDiversityNValue
;
518 unsigned long ulDiversityMValue
;
522 unsigned long ulSQ3TH
;
524 unsigned long uDiversityCnt
;
526 unsigned long ulRatio_State0
;
527 unsigned long ulRatio_State1
;
528 unsigned long ulSQ3_State0
;
529 unsigned long ulSQ3_State1
;
531 unsigned long aulSQ3Val
[MAX_RATE
];
532 unsigned long aulPktNum
[MAX_RATE
];
535 u32 uSIFS
; /* Current SIFS */
536 u32 uDIFS
; /* Current DIFS */
537 u32 uEIFS
; /* Current EIFS */
538 u32 uSlot
; /* Current SlotTime */
539 u32 uCwMin
; /* Current CwMin */
540 u32 uCwMax
; /* CwMax is fixed on 1023 */
550 VIA_BB_TYPE byBBType
; /* 0: 11A, 1:11B, 2:11G */
551 VIA_PKT_TYPE byPacketType
; /* 0:11a 1:11b 2:11gb 3:11ga */
554 u8 byTopOFDMBasicRate
;
555 u8 byTopCCKBasicRate
;
557 u32 dwAotoRateTxOkCnt
;
558 u32 dwAotoRateTxFailCnt
;
559 u32 dwErrorRateThreshold
[13];
560 u32 dwTPTable
[MAX_RATE
];
561 u8 abyEEPROM
[EEP_MAX_CONTEXT_SIZE
]; /*u32 alignment */
572 /* For RF Power table */
578 u8 abyOFDMPwrTbl
[14];
579 u8 abyOFDMAPwrTbl
[42];
583 u16 wFragmentationThreshold
;
584 u8 byShortRetryLimit
;
586 CARD_OP_MODE eOPMode
;
588 u16 wMaxTransmitMSDULifetime
;
589 u8 abyBSSID
[ETH_ALEN
];
590 u8 abyDesireBSSID
[ETH_ALEN
];
592 u32 dwMaxReceiveLifetime
; /* dot11MaxReceiveLifetime */
595 int bEncryptionEnable
;
600 int bBarkerPreambleMd
;
603 u16 wUseProtectCntDown
;
605 int bRadioControlOff
;
612 WMAC_POWER_MODE ePSMode
;
613 unsigned long ulPSModeWaitTx
;
616 /* Beacon releated */
624 CMD_STATE eCommandState
;
633 u32 uAutoReConnectTime
;
638 CMD_ITEM eCmdQueue
[CMD_Q_SIZE
];
653 unsigned long ulTxPower
;
656 NDIS_802_11_WEP_STATUS eEncryptionStatus
;
658 NDIS_802_11_WEP_STATUS eOldEncryptionStatus
;
663 u8 abyPRNG
[WLAN_WEPMAX_KEYLEN
+3];
669 u8 abyKey
[WLAN_WEP232_KEYLEN
];
683 /* For Update BaseBand VGA Gain Offset */
688 u8 abyBBVGA
[BB_VGA_LEVEL
];
689 signed long ldBmThreshold
[BB_VGA_LEVEL
];
700 /* For Auto Power Tunning */
703 /* BaseBand Loopback Use */
710 struct timer_list sTimerCommand
;
712 struct timer_list sTimerTxData
;
713 unsigned long nTxDataTimeCout
;
717 int fWPA_Authened
; /*is WPA/WPA-PSK or WPA2/WPA2-PSK authen?? */
721 struct ethhdr sTxEthHeader
;
722 struct ethhdr sRxEthHeader
;
723 u8 abyBroadcastAddr
[ETH_ALEN
];
724 u8 abySNAP_RFC1042
[ETH_ALEN
];
725 u8 abySNAP_Bridgetunnel
[ETH_ALEN
];
727 /* Pre-Authentication & PMK cache */
729 SPMKIDCandidateEvent gsPMKIDCandidate
;
736 u8 byChannelSwitchCount
;
738 /* WPA supplicant daemon */
744 int bWPASuppWextEnabled
;
746 /* user space daemon: hostapd, is used for HOSTAP */
750 struct net_device
*apdev
;
751 int (*tx_80211
)(struct sk_buff
*skb
, struct net_device
*dev
);
755 struct iw_statistics wstats
; /* wireless stats */
761 #define EnqueueRCB(_Head, _Tail, _RCB) \
767 _Tail->Next = _RCB; \
773 #define DequeueRCB(Head, Tail) \
775 struct vnt_rcb *RCB = Head; \
782 #define ADD_ONE_WITH_WRAP_AROUND(uVar, uModulo) { \
783 if ((uVar) >= ((uModulo) - 1)) \
789 #define fMP_RESET_IN_PROGRESS 0x00000001
790 #define fMP_DISCONNECTED 0x00000002
791 #define fMP_HALT_IN_PROGRESS 0x00000004
792 #define fMP_SURPRISE_REMOVED 0x00000008
793 #define fMP_RECV_LOOKASIDE 0x00000010
794 #define fMP_INIT_IN_PROGRESS 0x00000020
795 #define fMP_SEND_SIDE_RESOURCE_ALLOCATED 0x00000040
796 #define fMP_RECV_SIDE_RESOURCE_ALLOCATED 0x00000080
797 #define fMP_POST_READS 0x00000100
798 #define fMP_POST_WRITES 0x00000200
799 #define fMP_CONTROL_READS 0x00000400
800 #define fMP_CONTROL_WRITES 0x00000800
802 #define MP_SET_FLAG(_M, _F) ((_M)->Flags |= (_F))
803 #define MP_CLEAR_FLAG(_M, _F) ((_M)->Flags &= ~(_F))
804 #define MP_TEST_FLAGS(_M, _F) (((_M)->Flags & (_F)) == (_F))
806 #define MP_IS_READY(_M) (((_M)->Flags & \
807 (fMP_DISCONNECTED | fMP_RESET_IN_PROGRESS | fMP_HALT_IN_PROGRESS | fMP_INIT_IN_PROGRESS | fMP_SURPRISE_REMOVED)) == 0)
809 int device_alloc_frag_buf(struct vnt_private
*, PSDeFragControlBlock pDeF
);