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
34 #include <linux/modversions.h>
35 #endif /* MODVERSIONS */
36 #include <linux/module.h>
39 #include <linux/types.h>
40 #include <linux/init.h>
42 #include <linux/errno.h>
43 #include <linux/ioport.h>
44 #include <linux/pci.h>
45 #include <linux/kernel.h>
46 #include <linux/netdevice.h>
47 #include <linux/etherdevice.h>
48 #include <linux/skbuff.h>
49 #include <linux/delay.h>
50 #include <linux/timer.h>
51 #include <linux/slab.h>
52 #include <linux/interrupt.h>
53 #include <linux/version.h>
54 #include <linux/string.h>
55 #include <linux/wait.h>
56 #include <linux/if_arp.h>
57 #include <linux/sched.h>
60 //#include <linux/config.h>
61 #include <asm/uaccess.h>
62 #include <linux/proc_fs.h>
63 #include <linux/inetdevice.h>
64 #include <linux/reboot.h>
66 #define DEVICE_ETHTOOL_IOCTL_SUPPORT
67 #include <linux/ethtool.h>
69 #undef DEVICE_ETHTOOL_IOCTL_SUPPORT
71 /* Include Wireless Extension definition and check version - Jean II */
72 #include <linux/wireless.h>
73 #include <net/iw_handler.h> // New driver API
75 //2008-0409-07, <Add> by Einsn Liu
76 #ifndef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
77 #define WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
79 //2008-4-14<add> by chester for led issue
80 //#define FOR_LED_ON_NOTEBOOK
89 #include "device_cfg.h"
109 /*--------------------- Export Definitions -------------------------*/
111 #define MAC_MAX_CONTEXT_REG (256+128)
113 #define MAX_MULTICAST_ADDRESS_NUM 32
114 #define MULTICAST_ADDRESS_LIST_SIZE (MAX_MULTICAST_ADDRESS_NUM * U_ETHER_ADDR_LEN)
117 //#define OP_MODE_INFRASTRUCTURE 0
118 //#define OP_MODE_ADHOC 1
119 //#define OP_MODE_AP 2
121 #define DUPLICATE_RX_CACHE_LENGTH 5
123 #define NUM_KEY_ENTRY 11
125 #define TX_WEP_NONE 0
128 #define TX_WEP_SWOTP 3
129 #define TX_WEP_OTPSW 4
130 #define TX_WEP_SW232 5
132 #define KEYSEL_WEP40 0
133 #define KEYSEL_WEP104 1
134 #define KEYSEL_TKIP 2
135 #define KEYSEL_CCMP 3
139 #define AUTO_FB_NONE 0
149 #define ANT_DIVERSITY 2
150 #define ANT_RXD_TXA 3
151 #define ANT_RXD_TXB 4
152 #define ANT_UNKNOWN 0xFF
154 #define MAXCHECKHANGCNT 4
156 #define BB_VGA_LEVEL 4
157 #define BB_VGA_CHANGE_THRESHOLD 16
162 #define RUN_AT(x) (jiffies+(x))
166 #define RESERV_AC0DMA 4
172 #define AVAIL_TD(p,q) ((p)->sOpts.nTxDescs[(q)]-((p)->iTDUsed[(q)]))
180 #define PRIVATE_Message 0
182 /*--------------------- Export Types ------------------------------*/
185 #define DBG_PRT(l, p, args...) {if (l<=msglevel) printk( p ,##args);}
186 #define PRINT_K(p, args...) {if (PRIVATE_Message) printk( p ,##args);}
189 typedef enum _VIA_BB_TYPE
194 } VIA_BB_TYPE
, *PVIA_BB_TYPE
;
196 //0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate)
197 typedef enum _VIA_PKT_TYPE
203 } VIA_PKT_TYPE
, *PVIA_PKT_TYPE
;
206 typedef enum __device_msg_level
{
207 MSG_LEVEL_ERR
=0, //Errors that will cause abnormal operation.
208 MSG_LEVEL_NOTICE
=1, //Some errors need users to be notified.
209 MSG_LEVEL_INFO
=2, //Normal message.
210 MSG_LEVEL_VERBOSE
=3, //Will report all trival errors.
211 MSG_LEVEL_DEBUG
=4 //Only for debug purpose.
212 } DEVICE_MSG_LEVEL
, *PDEVICE_MSG_LEVEL
;
214 typedef enum __device_init_type
{
215 DEVICE_INIT_COLD
=0, // cold init
216 DEVICE_INIT_RESET
, // reset init or Dx to D0 power remain init
217 DEVICE_INIT_DXPL
// Dx to D0 power lost init
218 } DEVICE_INIT_TYPE
, *PDEVICE_INIT_TYPE
;
223 #define MAX_BSSIDINFO_4_PMKID 16
224 #define MAX_PMKIDLIST 5
225 //Flags for PMKID Candidate list structure
226 #define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
229 typedef UCHAR NDIS_802_11_PMKID_VALUE
[16];
232 typedef enum _NDIS_802_11_WEP_STATUS
234 Ndis802_11WEPEnabled
,
235 Ndis802_11Encryption1Enabled
= Ndis802_11WEPEnabled
,
236 Ndis802_11WEPDisabled
,
237 Ndis802_11EncryptionDisabled
= Ndis802_11WEPDisabled
,
238 Ndis802_11WEPKeyAbsent
,
239 Ndis802_11Encryption1KeyAbsent
= Ndis802_11WEPKeyAbsent
,
240 Ndis802_11WEPNotSupported
,
241 Ndis802_11EncryptionNotSupported
= Ndis802_11WEPNotSupported
,
242 Ndis802_11Encryption2Enabled
,
243 Ndis802_11Encryption2KeyAbsent
,
244 Ndis802_11Encryption3Enabled
,
245 Ndis802_11Encryption3KeyAbsent
246 } NDIS_802_11_WEP_STATUS
, *PNDIS_802_11_WEP_STATUS
,
247 NDIS_802_11_ENCRYPTION_STATUS
, *PNDIS_802_11_ENCRYPTION_STATUS
;
250 typedef enum _NDIS_802_11_STATUS_TYPE
252 Ndis802_11StatusType_Authentication
,
253 Ndis802_11StatusType_MediaStreamMode
,
254 Ndis802_11StatusType_PMKID_CandidateList
,
255 Ndis802_11StatusTypeMax
// not a real type, defined as an upper bound
256 } NDIS_802_11_STATUS_TYPE
, *PNDIS_802_11_STATUS_TYPE
;
258 //Added new types for PMKID Candidate lists.
259 typedef struct _PMKID_CANDIDATE
{
260 NDIS_802_11_MAC_ADDRESS BSSID
;
262 } PMKID_CANDIDATE
, *PPMKID_CANDIDATE
;
265 typedef struct _BSSID_INFO
267 NDIS_802_11_MAC_ADDRESS BSSID
;
268 NDIS_802_11_PMKID_VALUE PMKID
;
269 } BSSID_INFO
, *PBSSID_INFO
;
271 typedef struct tagSPMKID
{
273 ULONG BSSIDInfoCount
;
274 BSSID_INFO BSSIDInfo
[MAX_BSSIDINFO_4_PMKID
];
277 typedef struct tagSPMKIDCandidateEvent
{
278 NDIS_802_11_STATUS_TYPE StatusType
;
279 ULONG Version
; // Version of the structure
280 ULONG NumCandidates
; // No. of pmkid candidates
281 PMKID_CANDIDATE CandidateList
[MAX_PMKIDLIST
];
282 } SPMKIDCandidateEvent
, *PSPMKIDCandidateEvent
;
287 #define MAX_QUIET_COUNT 8
289 typedef struct tagSQuietControl
{
294 } SQuietControl
, *PSQuietControl
;
297 typedef struct __chip_info_tbl
{
303 } CHIP_INFO
, *PCHIP_INFO
;
309 } DEVICE_OWNER_TYPE
, *PDEVICE_OWNER_TYPE
;
312 // The receive duplicate detection cache entry
313 typedef struct tagSCacheEntry
{
315 BYTE abyAddr2
[U_ETHER_ADDR_LEN
];
316 } SCacheEntry
, *PSCacheEntry
;
318 typedef struct tagSCache
{
319 /* The receive cache is updated circularly. The next entry to be written is
320 * indexed by the "InPtr".
322 UINT uInPtr
; // Place to use next
323 SCacheEntry asCacheEntry
[DUPLICATE_RX_CACHE_LENGTH
];
326 #define CB_MAX_RX_FRAG 64
327 // DeFragment Control Block, used for collecting fragments prior to reassembly
328 typedef struct tagSDeFragControlBlock
332 BYTE abyAddr2
[U_ETHER_ADDR_LEN
];
338 } SDeFragControlBlock
, *PSDeFragControlBlock
;
343 #define DEVICE_FLAGS_IP_ALIGN 0x00000001UL
344 #define DEVICE_FLAGS_PREAMBLE_TYPE 0x00000002UL
345 #define DEVICE_FLAGS_OP_MODE 0x00000004UL
346 #define DEVICE_FLAGS_PS_MODE 0x00000008UL
347 #define DEVICE_FLAGS_80211h_MODE 0x00000010UL
348 #define DEVICE_FLAGS_DiversityANT 0x00000020UL
350 //flags for driver status
351 #define DEVICE_FLAGS_OPENED 0x00010000UL
352 #define DEVICE_FLAGS_WOL_ENABLED 0x00080000UL
353 //flags for capbilities
354 #define DEVICE_FLAGS_TX_ALIGN 0x01000000UL
355 #define DEVICE_FLAGS_HAVE_CAM 0x02000000UL
356 #define DEVICE_FLAGS_FLOW_CTRL 0x04000000UL
358 //flags for MII status
359 #define DEVICE_LINK_FAIL 0x00000001UL
360 #define DEVICE_SPEED_10 0x00000002UL
361 #define DEVICE_SPEED_100 0x00000004UL
362 #define DEVICE_SPEED_1000 0x00000008UL
363 #define DEVICE_DUPLEX_FULL 0x00000010UL
364 #define DEVICE_AUTONEG_ENABLE 0x00000020UL
365 #define DEVICE_FORCED_BY_EEPROM 0x00000040UL
366 //for device_set_media_duplex
367 #define DEVICE_LINK_CHANGE 0x00000001UL
373 typedef struct _RxManagementQueue
377 PSRxMgmtPacket Q
[NUM
];
378 } RxManagementQueue
,*PSRxManagementQueue
;
385 typedef struct __device_opt
{
386 int nRxDescs0
; //Number of RX descriptors0
387 int nRxDescs1
; //Number of RX descriptors1
388 int nTxDescs
[2]; //Number of TX descriptors 0, 1
389 int int_works
; //interrupt limits
390 int rts_thresh
; //rts threshold
398 } OPTIONS
, *POPTIONS
;
401 typedef struct __device_info
{
402 struct __device_info
* next
;
403 struct __device_info
* prev
;
405 struct pci_dev
* pcid
;
412 struct net_device
* dev
;
413 struct net_device
* next_module
;
414 struct net_device_stats stats
;
416 //dma addr, rx/tx pool
418 dma_addr_t rd0_pool_dma
;
419 dma_addr_t rd1_pool_dma
;
421 dma_addr_t td0_pool_dma
;
422 dma_addr_t td1_pool_dma
;
424 dma_addr_t tx_bufs_dma0
;
425 dma_addr_t tx_bufs_dma1
;
426 dma_addr_t tx_beacon_dma
;
430 PBYTE tx_beacon_bufs
;
445 volatile int iTDUsed
[TYPE_MAXTD
];
447 volatile PSTxDesc apCurrTD
[TYPE_MAXTD
];
448 volatile PSTxDesc apTailTD
[TYPE_MAXTD
];
450 volatile PSTxDesc apTD0Rings
;
451 volatile PSTxDesc apTD1Rings
;
453 volatile PSRxDesc aRD0Ring
;
454 volatile PSRxDesc aRD1Ring
;
455 volatile PSRxDesc pCurrRD
[TYPE_MAXRD
];
458 SDeFragControlBlock sRxDFCB
[CB_MAX_RX_FRAG
];
461 UINT uCurrentDFCBIdx
;
473 struct tasklet_struct RxMngWorkItem
;
474 RxManagementQueue rxManeQueue
;
478 struct completion notify
;
479 struct semaphore mlme_semaphore
;
492 BYTE byOriginalZonetype
;
493 BYTE abyMacContext
[MAC_MAX_CONTEXT_REG
];
494 BOOL bLinkPass
; // link status: OK or fail
495 BYTE abyCurrentNetAddr
[U_ETHER_ADDR_LEN
];
497 // Adapter statistics
498 SStatCounter scStatistic
;
500 SDot11Counters s802_11Counter
;
505 SMgmtObject sMgmtObj
;
507 // 802.11 MAC specific
511 DWORD dwTxAntennaSel
;
512 DWORD dwRxAntennaSel
;
514 BYTE byRxAntennaMode
;
515 BYTE byTxAntennaMode
;
519 UINT uSIFS
; //Current SIFS
520 UINT uDIFS
; //Current DIFS
521 UINT uEIFS
; //Current EIFS
522 UINT uSlot
; //Current SlotTime
523 UINT uCwMin
; //Current CwMin
524 UINT uCwMax
; //CwMax is fixed on 1023.
531 CARD_PHY_TYPE eCurrentPHYType
;
534 VIA_BB_TYPE byBBType
; //0: 11A, 1:11B, 2:11G
535 VIA_PKT_TYPE byPacketType
; //0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate)
538 BYTE byTopOFDMBasicRate
;
539 BYTE byTopCCKBasicRate
;
543 UINT uConnectionRate
;
546 BYTE byShortPreamble
;
550 WORD wFragmentationThreshold
;
551 BYTE byShortRetryLimit
;
552 BYTE byLongRetryLimit
;
553 CARD_OP_MODE eOPMode
;
556 WORD wMaxTransmitMSDULifetime
;
557 BYTE abyBSSID
[U_ETHER_ADDR_LEN
];
558 BYTE abyDesireBSSID
[U_ETHER_ADDR_LEN
];
559 WORD wCTSDuration
; // update while speed change
560 WORD wACKDuration
; // update while speed change
561 WORD wRTSTransmitLen
; // update while speed change
562 BYTE byRTSServiceField
; // update while speed change
563 BYTE byRTSSignalField
; // update while speed change
565 DWORD dwMaxReceiveLifetime
; // dot11MaxReceiveLifetime
568 BOOL bEncryptionEnable
;
573 BOOL bBarkerPreambleMd
;
576 WORD wUseProtectCntDown
;
578 BOOL bRadioControlOff
;
581 WORD wListenInterval
;
583 WMAC_POWER_MODE ePSMode
;
586 // GPIO Radio Control
590 BOOL bPrvActive4RadioOFF
;
596 BOOL bBeaconBufReady
;
598 BOOL bIsBeaconBufReadySet
;
599 UINT cbBeaconBufReadySetCnt
;
604 CMD_STATE eCommandState
;
612 UINT uAutoReConnectTime
;
616 CMD_ITEM eCmdQueue
[CMD_Q_SIZE
];
630 NDIS_802_11_WEP_STATUS eEncryptionStatus
;
632 //2007-0925-01<Add>by MikeLiu
633 //mike add :save old Encryption
634 NDIS_802_11_WEP_STATUS eOldEncryptionStatus
;
639 QWORD qwPacketNumber
; //For CCMP and TKIP as TSC(6 bytes)
640 UINT uCurrentWEPMode
;
643 BYTE abyPRNG
[WLAN_WEPMAX_KEYLEN
+3];
646 BYTE abyKey
[WLAN_WEP232_KEYLEN
];
658 // for OID_802_11_ASSOCIATION_INFORMATION
671 // For Update BaseBand VGA Gain Offset
673 UINT uBBVGADiffCount
;
676 BYTE abyBBVGA
[BB_VGA_LEVEL
];
677 LONG ldBmThreshold
[BB_VGA_LEVEL
];
684 DWORD dwDiagRefCount
;
689 // For Auto Power Tunning
691 BYTE byAutoPwrTunning
;
693 SHORT sPSetPointOFDMG
;
694 SHORT sPSetPointOFDMA
;
695 LONG lPFormulaOffset
;
700 // For RF Power table
705 BYTE abyCCKPwrTbl
[CB_MAX_CHANNEL_24G
+1];
706 BYTE abyOFDMPwrTbl
[CB_MAX_CHANNEL
+1];
707 I8 abyCCKDefaultPwr
[CB_MAX_CHANNEL_24G
+1];
708 I8 abyOFDMDefaultPwr
[CB_MAX_CHANNEL
+1];
709 I8 abyRegPwr
[CB_MAX_CHANNEL
+1];
710 I8 abyLocalPwr
[CB_MAX_CHANNEL
+1];
713 // BaseBand Loopback Use
720 struct timer_list sTimerCommand
;
722 struct timer_list sTimerTxData
;
723 ULONG nTxDataTimeCout
;
725 BOOL IsTxDataTrigger
;
728 #ifdef WPA_SM_Transtatus
729 BOOL fWPA_Authened
; //is WPA/WPA-PSK or WPA2/WPA2-PSK authen??
731 BYTE byReAssocCount
; //mike add:re-association retry times!
732 BYTE byLinkWaitCount
;
735 BYTE abyNodeName
[17];
737 BOOL bDiversityRegCtlON
;
738 BOOL bDiversityEnable
;
739 ULONG ulDiversityNValue
;
740 ULONG ulDiversityMValue
;
749 ULONG ulRatio_State0
;
750 ULONG ulRatio_State1
;
752 //SQ3 functions for antenna diversity
753 struct timer_list TimerSQ3Tmax1
;
754 struct timer_list TimerSQ3Tmax2
;
755 struct timer_list TimerSQ3Tmax3
;
758 ULONG uNumSQ3
[MAX_RATE
];
759 WORD wAntDiversityMaxRate
;
762 SEthernetHeader sTxEthHeader
;
763 SEthernetHeader sRxEthHeader
;
764 BYTE abyBroadcastAddr
[U_ETHER_ADDR_LEN
];
765 BYTE abySNAP_RFC1042
[U_ETHER_ADDR_LEN
];
766 BYTE abySNAP_Bridgetunnel
[U_ETHER_ADDR_LEN
];
767 BYTE abyEEPROM
[EEP_MAX_CONTEXT_SIZE
]; //DWORD alignment
768 // Pre-Authentication & PMK cache
770 SPMKIDCandidateEvent gsPMKIDCandidate
;
775 BYTE abyCountryCode
[3];
777 UINT uNumOfMeasureEIDs
;
778 PWLAN_IE_MEASURE_REQ pCurrMeasureEID
;
779 BOOL bMeasureInProgress
;
790 BYTE byChannelSwitchCount
;
792 BOOL bEnableFirstQuiet
;
793 BYTE byQuietStartCount
;
795 DWORD dwCurrentQuietEndTime
;
796 SQuietControl sQuiet
[MAX_QUIET_COUNT
];
799 BOOL bCountryInfo24G
;
801 WORD wBeaconInterval
;
803 //WPA supplicant deamon
804 struct net_device
*wpadev
;
807 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
815 BOOL bWPASuppWextEnabled
;
820 // user space daemon: hostapd, is used for HOSTAP
824 struct net_device
*apdev
;
825 int (*tx_80211
)(struct sk_buff
*skb
, struct net_device
*dev
);
830 struct iw_statistics wstats
; // wireless stats
833 } DEVICE_INFO
, *PSDevice
;
839 inline static VOID
EnQueue (PSDevice pDevice
,PSRxMgmtPacket pRxMgmtPacket
)
841 //printk("Enter EnQueue:tail is %d\n",pDevice->rxManeQueue.tail);
842 if ((pDevice
->rxManeQueue
.tail
+1) % NUM
== pDevice
->rxManeQueue
.head
)
844 //printk("Queue is Full,tail is %d\n",pDevice->rxManeQueue.tail);
849 pDevice
->rxManeQueue
.tail
= (pDevice
->rxManeQueue
.tail
+1)% NUM
;
850 pDevice
->rxManeQueue
.Q
[pDevice
->rxManeQueue
.tail
] = pRxMgmtPacket
;
851 pDevice
->rxManeQueue
.packet_num
++;
852 //printk("packet num is %d\n",pDevice->rxManeQueue.packet_num);
859 inline static PSRxMgmtPacket
DeQueue (PSDevice pDevice
)
861 PSRxMgmtPacket pRxMgmtPacket
;
862 if (pDevice
->rxManeQueue
.tail
== pDevice
->rxManeQueue
.head
)
864 printk("Queue is Empty\n");
870 //x=pDevice->rxManeQueue.head = (pDevice->rxManeQueue.head+1)%NUM;
871 pDevice
->rxManeQueue
.head
= (pDevice
->rxManeQueue
.head
+1)%NUM
;
872 x
= pDevice
->rxManeQueue
.head
;
873 //printk("Enter DeQueue:head is %d\n",x);
874 pRxMgmtPacket
= pDevice
->rxManeQueue
.Q
[x
];
875 pDevice
->rxManeQueue
.packet_num
--;
876 return pRxMgmtPacket
;
880 VOID
InitRxManagementQueue(PSDevice pDevice
);
891 inline static BOOL
device_get_ip(PSDevice pInfo
) {
892 struct in_device
* in_dev
=(struct in_device
*) pInfo
->dev
->ip_ptr
;
893 struct in_ifaddr
* ifa
;
896 ifa
=(struct in_ifaddr
*) in_dev
->ifa_list
;
898 memcpy(pInfo
->abyIPAddr
,&ifa
->ifa_address
,4);
907 static inline PDEVICE_RD_INFO
alloc_rd_info(void) {
909 if ((ptr
= (PDEVICE_RD_INFO
)kmalloc((int)sizeof(DEVICE_RD_INFO
), (int)GFP_ATOMIC
)) == NULL
)
912 memset(ptr
,0,sizeof(DEVICE_RD_INFO
));
917 static inline PDEVICE_TD_INFO
alloc_td_info(void) {
919 if ((ptr
= (PDEVICE_TD_INFO
)kmalloc((int)sizeof(DEVICE_TD_INFO
), (int)GFP_ATOMIC
))==NULL
)
922 memset(ptr
,0,sizeof(DEVICE_TD_INFO
));
927 /*--------------------- Export Functions --------------------------*/
929 BOOL
device_dma0_xmit(PSDevice pDevice
, struct sk_buff
*skb
, UINT uNodeIndex
);
930 BOOL
device_alloc_frag_buf(PSDevice pDevice
, PSDeFragControlBlock pDeF
);
931 int Config_FileOperation(PSDevice pDevice
,BOOL fwrite
,unsigned char *Parameter
);