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
88 #if !defined(_KCOMPAT_H)
92 #if !defined(__DEVICE_CONFIG_H)
93 #include "device_cfg.h"
96 #if !defined(__TTYPE_H__)
99 #if !defined(__80211HDR_H__)
100 #include "80211hdr.h"
102 #if !defined(__TETHER_H__)
105 #if !defined(__WMGR_H__)
108 #if !defined(__WCMD_H__)
111 #if !defined(__MIB_H__)
114 #if !defined(__SROM_H__)
117 #if !defined(__RC4_H__)
120 #if !defined(__TPCI_H__)
123 #if !defined(__DESC_H__)
126 #if !defined(__KEY_H__)
129 #if !defined(__MAC_H__)
140 /*--------------------- Export Definitions -------------------------*/
142 #define MAC_MAX_CONTEXT_REG (256+128)
144 #define MAX_MULTICAST_ADDRESS_NUM 32
145 #define MULTICAST_ADDRESS_LIST_SIZE (MAX_MULTICAST_ADDRESS_NUM * U_ETHER_ADDR_LEN)
148 //#define OP_MODE_INFRASTRUCTURE 0
149 //#define OP_MODE_ADHOC 1
150 //#define OP_MODE_AP 2
152 #define DUPLICATE_RX_CACHE_LENGTH 5
154 #define NUM_KEY_ENTRY 11
156 #define TX_WEP_NONE 0
159 #define TX_WEP_SWOTP 3
160 #define TX_WEP_OTPSW 4
161 #define TX_WEP_SW232 5
163 #define KEYSEL_WEP40 0
164 #define KEYSEL_WEP104 1
165 #define KEYSEL_TKIP 2
166 #define KEYSEL_CCMP 3
170 #define AUTO_FB_NONE 0
180 #define ANT_DIVERSITY 2
181 #define ANT_RXD_TXA 3
182 #define ANT_RXD_TXB 4
183 #define ANT_UNKNOWN 0xFF
185 #define MAXCHECKHANGCNT 4
187 #define BB_VGA_LEVEL 4
188 #define BB_VGA_CHANGE_THRESHOLD 16
193 #define RUN_AT(x) (jiffies+(x))
197 #define RESERV_AC0DMA 4
203 #define AVAIL_TD(p,q) ((p)->sOpts.nTxDescs[(q)]-((p)->iTDUsed[(q)]))
211 #define PRIVATE_Message 0
213 /*--------------------- Export Types ------------------------------*/
216 #define DBG_PRT(l, p, args...) {if (l<=msglevel) printk( p ,##args);}
217 #define PRINT_K(p, args...) {if (PRIVATE_Message) printk( p ,##args);}
220 typedef enum _VIA_BB_TYPE
225 } VIA_BB_TYPE
, *PVIA_BB_TYPE
;
227 //0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate)
228 typedef enum _VIA_PKT_TYPE
234 } VIA_PKT_TYPE
, *PVIA_PKT_TYPE
;
237 typedef enum __device_msg_level
{
238 MSG_LEVEL_ERR
=0, //Errors that will cause abnormal operation.
239 MSG_LEVEL_NOTICE
=1, //Some errors need users to be notified.
240 MSG_LEVEL_INFO
=2, //Normal message.
241 MSG_LEVEL_VERBOSE
=3, //Will report all trival errors.
242 MSG_LEVEL_DEBUG
=4 //Only for debug purpose.
243 } DEVICE_MSG_LEVEL
, *PDEVICE_MSG_LEVEL
;
245 typedef enum __device_init_type
{
246 DEVICE_INIT_COLD
=0, // cold init
247 DEVICE_INIT_RESET
, // reset init or Dx to D0 power remain init
248 DEVICE_INIT_DXPL
// Dx to D0 power lost init
249 } DEVICE_INIT_TYPE
, *PDEVICE_INIT_TYPE
;
254 #define MAX_BSSIDINFO_4_PMKID 16
255 #define MAX_PMKIDLIST 5
256 //Flags for PMKID Candidate list structure
257 #define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
260 typedef UCHAR NDIS_802_11_PMKID_VALUE
[16];
263 typedef enum _NDIS_802_11_WEP_STATUS
265 Ndis802_11WEPEnabled
,
266 Ndis802_11Encryption1Enabled
= Ndis802_11WEPEnabled
,
267 Ndis802_11WEPDisabled
,
268 Ndis802_11EncryptionDisabled
= Ndis802_11WEPDisabled
,
269 Ndis802_11WEPKeyAbsent
,
270 Ndis802_11Encryption1KeyAbsent
= Ndis802_11WEPKeyAbsent
,
271 Ndis802_11WEPNotSupported
,
272 Ndis802_11EncryptionNotSupported
= Ndis802_11WEPNotSupported
,
273 Ndis802_11Encryption2Enabled
,
274 Ndis802_11Encryption2KeyAbsent
,
275 Ndis802_11Encryption3Enabled
,
276 Ndis802_11Encryption3KeyAbsent
277 } NDIS_802_11_WEP_STATUS
, *PNDIS_802_11_WEP_STATUS
,
278 NDIS_802_11_ENCRYPTION_STATUS
, *PNDIS_802_11_ENCRYPTION_STATUS
;
281 typedef enum _NDIS_802_11_STATUS_TYPE
283 Ndis802_11StatusType_Authentication
,
284 Ndis802_11StatusType_MediaStreamMode
,
285 Ndis802_11StatusType_PMKID_CandidateList
,
286 Ndis802_11StatusTypeMax
// not a real type, defined as an upper bound
287 } NDIS_802_11_STATUS_TYPE
, *PNDIS_802_11_STATUS_TYPE
;
289 //Added new types for PMKID Candidate lists.
290 typedef struct _PMKID_CANDIDATE
{
291 NDIS_802_11_MAC_ADDRESS BSSID
;
293 } PMKID_CANDIDATE
, *PPMKID_CANDIDATE
;
296 typedef struct _BSSID_INFO
298 NDIS_802_11_MAC_ADDRESS BSSID
;
299 NDIS_802_11_PMKID_VALUE PMKID
;
300 } BSSID_INFO
, *PBSSID_INFO
;
302 typedef struct tagSPMKID
{
304 ULONG BSSIDInfoCount
;
305 BSSID_INFO BSSIDInfo
[MAX_BSSIDINFO_4_PMKID
];
308 typedef struct tagSPMKIDCandidateEvent
{
309 NDIS_802_11_STATUS_TYPE StatusType
;
310 ULONG Version
; // Version of the structure
311 ULONG NumCandidates
; // No. of pmkid candidates
312 PMKID_CANDIDATE CandidateList
[MAX_PMKIDLIST
];
313 } SPMKIDCandidateEvent
, *PSPMKIDCandidateEvent
;
318 #define MAX_QUIET_COUNT 8
320 typedef struct tagSQuietControl
{
325 } SQuietControl
, *PSQuietControl
;
328 typedef struct __chip_info_tbl
{
334 } CHIP_INFO
, *PCHIP_INFO
;
340 } DEVICE_OWNER_TYPE
, *PDEVICE_OWNER_TYPE
;
343 // The receive duplicate detection cache entry
344 typedef struct tagSCacheEntry
{
346 BYTE abyAddr2
[U_ETHER_ADDR_LEN
];
347 } SCacheEntry
, *PSCacheEntry
;
349 typedef struct tagSCache
{
350 /* The receive cache is updated circularly. The next entry to be written is
351 * indexed by the "InPtr".
353 UINT uInPtr
; // Place to use next
354 SCacheEntry asCacheEntry
[DUPLICATE_RX_CACHE_LENGTH
];
357 #define CB_MAX_RX_FRAG 64
358 // DeFragment Control Block, used for collecting fragments prior to reassembly
359 typedef struct tagSDeFragControlBlock
363 BYTE abyAddr2
[U_ETHER_ADDR_LEN
];
369 } SDeFragControlBlock
, *PSDeFragControlBlock
;
374 #define DEVICE_FLAGS_IP_ALIGN 0x00000001UL
375 #define DEVICE_FLAGS_PREAMBLE_TYPE 0x00000002UL
376 #define DEVICE_FLAGS_OP_MODE 0x00000004UL
377 #define DEVICE_FLAGS_PS_MODE 0x00000008UL
378 #define DEVICE_FLAGS_80211h_MODE 0x00000010UL
379 #define DEVICE_FLAGS_DiversityANT 0x00000020UL
381 //flags for driver status
382 #define DEVICE_FLAGS_OPENED 0x00010000UL
383 #define DEVICE_FLAGS_WOL_ENABLED 0x00080000UL
384 //flags for capbilities
385 #define DEVICE_FLAGS_TX_ALIGN 0x01000000UL
386 #define DEVICE_FLAGS_HAVE_CAM 0x02000000UL
387 #define DEVICE_FLAGS_FLOW_CTRL 0x04000000UL
389 //flags for MII status
390 #define DEVICE_LINK_FAIL 0x00000001UL
391 #define DEVICE_SPEED_10 0x00000002UL
392 #define DEVICE_SPEED_100 0x00000004UL
393 #define DEVICE_SPEED_1000 0x00000008UL
394 #define DEVICE_DUPLEX_FULL 0x00000010UL
395 #define DEVICE_AUTONEG_ENABLE 0x00000020UL
396 #define DEVICE_FORCED_BY_EEPROM 0x00000040UL
397 //for device_set_media_duplex
398 #define DEVICE_LINK_CHANGE 0x00000001UL
404 typedef struct _RxManagementQueue
408 PSRxMgmtPacket Q
[NUM
];
409 } RxManagementQueue
,*PSRxManagementQueue
;
416 typedef struct __device_opt
{
417 int nRxDescs0
; //Number of RX descriptors0
418 int nRxDescs1
; //Number of RX descriptors1
419 int nTxDescs
[2]; //Number of TX descriptors 0, 1
420 int int_works
; //interrupt limits
421 int rts_thresh
; //rts threshold
429 } OPTIONS
, *POPTIONS
;
432 typedef struct __device_info
{
433 struct __device_info
* next
;
434 struct __device_info
* prev
;
436 struct pci_dev
* pcid
;
443 struct net_device
* dev
;
444 struct net_device
* next_module
;
445 struct net_device_stats stats
;
447 //dma addr, rx/tx pool
449 dma_addr_t rd0_pool_dma
;
450 dma_addr_t rd1_pool_dma
;
452 dma_addr_t td0_pool_dma
;
453 dma_addr_t td1_pool_dma
;
455 dma_addr_t tx_bufs_dma0
;
456 dma_addr_t tx_bufs_dma1
;
457 dma_addr_t tx_beacon_dma
;
461 PBYTE tx_beacon_bufs
;
476 volatile int iTDUsed
[TYPE_MAXTD
];
478 volatile PSTxDesc apCurrTD
[TYPE_MAXTD
];
479 volatile PSTxDesc apTailTD
[TYPE_MAXTD
];
481 volatile PSTxDesc apTD0Rings
;
482 volatile PSTxDesc apTD1Rings
;
484 volatile PSRxDesc aRD0Ring
;
485 volatile PSRxDesc aRD1Ring
;
486 volatile PSRxDesc pCurrRD
[TYPE_MAXRD
];
489 SDeFragControlBlock sRxDFCB
[CB_MAX_RX_FRAG
];
492 UINT uCurrentDFCBIdx
;
504 struct tasklet_struct RxMngWorkItem
;
505 RxManagementQueue rxManeQueue
;
509 struct completion notify
;
510 struct semaphore mlme_semaphore
;
523 BYTE byOriginalZonetype
;
524 BYTE abyMacContext
[MAC_MAX_CONTEXT_REG
];
525 BOOL bLinkPass
; // link status: OK or fail
526 BYTE abyCurrentNetAddr
[U_ETHER_ADDR_LEN
];
528 // Adapter statistics
529 SStatCounter scStatistic
;
531 SDot11Counters s802_11Counter
;
536 SMgmtObject sMgmtObj
;
538 // 802.11 MAC specific
542 DWORD dwTxAntennaSel
;
543 DWORD dwRxAntennaSel
;
545 BYTE byRxAntennaMode
;
546 BYTE byTxAntennaMode
;
550 UINT uSIFS
; //Current SIFS
551 UINT uDIFS
; //Current DIFS
552 UINT uEIFS
; //Current EIFS
553 UINT uSlot
; //Current SlotTime
554 UINT uCwMin
; //Current CwMin
555 UINT uCwMax
; //CwMax is fixed on 1023.
562 CARD_PHY_TYPE eCurrentPHYType
;
565 VIA_BB_TYPE byBBType
; //0: 11A, 1:11B, 2:11G
566 VIA_PKT_TYPE byPacketType
; //0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate)
569 BYTE byTopOFDMBasicRate
;
570 BYTE byTopCCKBasicRate
;
574 UINT uConnectionRate
;
577 BYTE byShortPreamble
;
581 WORD wFragmentationThreshold
;
582 BYTE byShortRetryLimit
;
583 BYTE byLongRetryLimit
;
584 CARD_OP_MODE eOPMode
;
587 WORD wMaxTransmitMSDULifetime
;
588 BYTE abyBSSID
[U_ETHER_ADDR_LEN
];
589 BYTE abyDesireBSSID
[U_ETHER_ADDR_LEN
];
590 WORD wCTSDuration
; // update while speed change
591 WORD wACKDuration
; // update while speed change
592 WORD wRTSTransmitLen
; // update while speed change
593 BYTE byRTSServiceField
; // update while speed change
594 BYTE byRTSSignalField
; // update while speed change
596 DWORD dwMaxReceiveLifetime
; // dot11MaxReceiveLifetime
599 BOOL bEncryptionEnable
;
604 BOOL bBarkerPreambleMd
;
607 WORD wUseProtectCntDown
;
609 BOOL bRadioControlOff
;
612 WORD wListenInterval
;
614 WMAC_POWER_MODE ePSMode
;
617 // GPIO Radio Control
621 BOOL bPrvActive4RadioOFF
;
627 BOOL bBeaconBufReady
;
629 BOOL bIsBeaconBufReadySet
;
630 UINT cbBeaconBufReadySetCnt
;
635 CMD_STATE eCommandState
;
643 UINT uAutoReConnectTime
;
647 CMD_ITEM eCmdQueue
[CMD_Q_SIZE
];
661 NDIS_802_11_WEP_STATUS eEncryptionStatus
;
663 //2007-0925-01<Add>by MikeLiu
664 //mike add :save old Encryption
665 NDIS_802_11_WEP_STATUS eOldEncryptionStatus
;
670 QWORD qwPacketNumber
; //For CCMP and TKIP as TSC(6 bytes)
671 UINT uCurrentWEPMode
;
674 BYTE abyPRNG
[WLAN_WEPMAX_KEYLEN
+3];
677 BYTE abyKey
[WLAN_WEP232_KEYLEN
];
689 // for OID_802_11_ASSOCIATION_INFORMATION
702 // For Update BaseBand VGA Gain Offset
704 UINT uBBVGADiffCount
;
707 BYTE abyBBVGA
[BB_VGA_LEVEL
];
708 LONG ldBmThreshold
[BB_VGA_LEVEL
];
715 DWORD dwDiagRefCount
;
720 // For Auto Power Tunning
722 BYTE byAutoPwrTunning
;
724 SHORT sPSetPointOFDMG
;
725 SHORT sPSetPointOFDMA
;
726 LONG lPFormulaOffset
;
731 // For RF Power table
736 BYTE abyCCKPwrTbl
[CB_MAX_CHANNEL_24G
+1];
737 BYTE abyOFDMPwrTbl
[CB_MAX_CHANNEL
+1];
738 I8 abyCCKDefaultPwr
[CB_MAX_CHANNEL_24G
+1];
739 I8 abyOFDMDefaultPwr
[CB_MAX_CHANNEL
+1];
740 I8 abyRegPwr
[CB_MAX_CHANNEL
+1];
741 I8 abyLocalPwr
[CB_MAX_CHANNEL
+1];
744 // BaseBand Loopback Use
751 struct timer_list sTimerCommand
;
753 struct timer_list sTimerTxData
;
754 ULONG nTxDataTimeCout
;
756 BOOL IsTxDataTrigger
;
759 #ifdef WPA_SM_Transtatus
760 BOOL fWPA_Authened
; //is WPA/WPA-PSK or WPA2/WPA2-PSK authen??
762 BYTE byReAssocCount
; //mike add:re-association retry times!
763 BYTE byLinkWaitCount
;
766 BYTE abyNodeName
[17];
768 BOOL bDiversityRegCtlON
;
769 BOOL bDiversityEnable
;
770 ULONG ulDiversityNValue
;
771 ULONG ulDiversityMValue
;
780 ULONG ulRatio_State0
;
781 ULONG ulRatio_State1
;
783 //SQ3 functions for antenna diversity
784 struct timer_list TimerSQ3Tmax1
;
785 struct timer_list TimerSQ3Tmax2
;
786 struct timer_list TimerSQ3Tmax3
;
789 ULONG uNumSQ3
[MAX_RATE
];
790 WORD wAntDiversityMaxRate
;
793 SEthernetHeader sTxEthHeader
;
794 SEthernetHeader sRxEthHeader
;
795 BYTE abyBroadcastAddr
[U_ETHER_ADDR_LEN
];
796 BYTE abySNAP_RFC1042
[U_ETHER_ADDR_LEN
];
797 BYTE abySNAP_Bridgetunnel
[U_ETHER_ADDR_LEN
];
798 BYTE abyEEPROM
[EEP_MAX_CONTEXT_SIZE
]; //DWORD alignment
799 // Pre-Authentication & PMK cache
801 SPMKIDCandidateEvent gsPMKIDCandidate
;
806 BYTE abyCountryCode
[3];
808 UINT uNumOfMeasureEIDs
;
809 PWLAN_IE_MEASURE_REQ pCurrMeasureEID
;
810 BOOL bMeasureInProgress
;
821 BYTE byChannelSwitchCount
;
823 BOOL bEnableFirstQuiet
;
824 BYTE byQuietStartCount
;
826 DWORD dwCurrentQuietEndTime
;
827 SQuietControl sQuiet
[MAX_QUIET_COUNT
];
830 BOOL bCountryInfo24G
;
832 WORD wBeaconInterval
;
834 //WPA supplicant deamon
835 struct net_device
*wpadev
;
838 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
846 BOOL bWPASuppWextEnabled
;
851 // user space daemon: hostapd, is used for HOSTAP
855 struct net_device
*apdev
;
856 int (*tx_80211
)(struct sk_buff
*skb
, struct net_device
*dev
);
861 struct iw_statistics wstats
; // wireless stats
864 } DEVICE_INFO
, *PSDevice
;
870 inline static VOID
EnQueue (PSDevice pDevice
,PSRxMgmtPacket pRxMgmtPacket
)
872 //printk("Enter EnQueue:tail is %d\n",pDevice->rxManeQueue.tail);
873 if ((pDevice
->rxManeQueue
.tail
+1) % NUM
== pDevice
->rxManeQueue
.head
)
875 //printk("Queue is Full,tail is %d\n",pDevice->rxManeQueue.tail);
880 pDevice
->rxManeQueue
.tail
= (pDevice
->rxManeQueue
.tail
+1)% NUM
;
881 pDevice
->rxManeQueue
.Q
[pDevice
->rxManeQueue
.tail
] = pRxMgmtPacket
;
882 pDevice
->rxManeQueue
.packet_num
++;
883 //printk("packet num is %d\n",pDevice->rxManeQueue.packet_num);
890 inline static PSRxMgmtPacket
DeQueue (PSDevice pDevice
)
892 PSRxMgmtPacket pRxMgmtPacket
;
893 if (pDevice
->rxManeQueue
.tail
== pDevice
->rxManeQueue
.head
)
895 printk("Queue is Empty\n");
901 //x=pDevice->rxManeQueue.head = (pDevice->rxManeQueue.head+1)%NUM;
902 pDevice
->rxManeQueue
.head
= (pDevice
->rxManeQueue
.head
+1)%NUM
;
903 x
= pDevice
->rxManeQueue
.head
;
904 //printk("Enter DeQueue:head is %d\n",x);
905 pRxMgmtPacket
= pDevice
->rxManeQueue
.Q
[x
];
906 pDevice
->rxManeQueue
.packet_num
--;
907 return pRxMgmtPacket
;
911 VOID
InitRxManagementQueue(PSDevice pDevice
);
922 inline static BOOL
device_get_ip(PSDevice pInfo
) {
923 struct in_device
* in_dev
=(struct in_device
*) pInfo
->dev
->ip_ptr
;
924 struct in_ifaddr
* ifa
;
927 ifa
=(struct in_ifaddr
*) in_dev
->ifa_list
;
929 memcpy(pInfo
->abyIPAddr
,&ifa
->ifa_address
,4);
938 static inline PDEVICE_RD_INFO
alloc_rd_info(void) {
940 if ((ptr
= (PDEVICE_RD_INFO
)kmalloc((int)sizeof(DEVICE_RD_INFO
), (int)GFP_ATOMIC
)) == NULL
)
943 memset(ptr
,0,sizeof(DEVICE_RD_INFO
));
948 static inline PDEVICE_TD_INFO
alloc_td_info(void) {
950 if ((ptr
= (PDEVICE_TD_INFO
)kmalloc((int)sizeof(DEVICE_TD_INFO
), (int)GFP_ATOMIC
))==NULL
)
953 memset(ptr
,0,sizeof(DEVICE_TD_INFO
));
958 /*--------------------- Export Functions --------------------------*/
960 BOOL
device_dma0_xmit(PSDevice pDevice
, struct sk_buff
*skb
, UINT uNodeIndex
);
961 BOOL
device_alloc_frag_buf(PSDevice pDevice
, PSDeFragControlBlock pDeF
);
962 int Config_FileOperation(PSDevice pDevice
,BOOL fwrite
,unsigned char *Parameter
);