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>
34 #include <linux/init.h>
36 #include <linux/errno.h>
37 #include <linux/ioport.h>
38 #include <linux/pci.h>
39 #include <linux/kernel.h>
40 #include <linux/netdevice.h>
41 #include <linux/etherdevice.h>
42 #include <linux/skbuff.h>
43 #include <linux/delay.h>
44 #include <linux/timer.h>
45 #include <linux/slab.h>
46 #include <linux/interrupt.h>
47 #include <linux/version.h>
48 #include <linux/string.h>
49 #include <linux/wait.h>
50 #include <linux/if_arp.h>
51 #include <linux/sched.h>
54 //#include <linux/config.h>
55 #include <asm/uaccess.h>
56 #include <linux/proc_fs.h>
57 #include <linux/inetdevice.h>
58 #include <linux/reboot.h>
60 #define DEVICE_ETHTOOL_IOCTL_SUPPORT
61 #include <linux/ethtool.h>
63 #undef DEVICE_ETHTOOL_IOCTL_SUPPORT
65 /* Include Wireless Extension definition and check version - Jean II */
66 #include <linux/wireless.h>
67 #include <net/iw_handler.h> // New driver API
69 //2008-0409-07, <Add> by Einsn Liu
70 #ifndef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
71 #define WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
73 //2008-4-14<add> by chester for led issue
74 //#define FOR_LED_ON_NOTEBOOK
83 #include "device_cfg.h"
103 /*--------------------- Export Definitions -------------------------*/
105 #define MAC_MAX_CONTEXT_REG (256+128)
107 #define MAX_MULTICAST_ADDRESS_NUM 32
108 #define MULTICAST_ADDRESS_LIST_SIZE (MAX_MULTICAST_ADDRESS_NUM * U_ETHER_ADDR_LEN)
111 //#define OP_MODE_INFRASTRUCTURE 0
112 //#define OP_MODE_ADHOC 1
113 //#define OP_MODE_AP 2
115 #define DUPLICATE_RX_CACHE_LENGTH 5
117 #define NUM_KEY_ENTRY 11
119 #define TX_WEP_NONE 0
122 #define TX_WEP_SWOTP 3
123 #define TX_WEP_OTPSW 4
124 #define TX_WEP_SW232 5
126 #define KEYSEL_WEP40 0
127 #define KEYSEL_WEP104 1
128 #define KEYSEL_TKIP 2
129 #define KEYSEL_CCMP 3
133 #define AUTO_FB_NONE 0
143 #define ANT_DIVERSITY 2
144 #define ANT_RXD_TXA 3
145 #define ANT_RXD_TXB 4
146 #define ANT_UNKNOWN 0xFF
148 #define MAXCHECKHANGCNT 4
150 #define BB_VGA_LEVEL 4
151 #define BB_VGA_CHANGE_THRESHOLD 16
156 #define RUN_AT(x) (jiffies+(x))
160 #define RESERV_AC0DMA 4
166 #define AVAIL_TD(p,q) ((p)->sOpts.nTxDescs[(q)]-((p)->iTDUsed[(q)]))
174 #define PRIVATE_Message 0
176 /*--------------------- Export Types ------------------------------*/
179 #define DBG_PRT(l, p, args...) {if (l<=msglevel) printk( p ,##args);}
180 #define PRINT_K(p, args...) {if (PRIVATE_Message) printk( p ,##args);}
183 typedef enum _VIA_BB_TYPE
188 } VIA_BB_TYPE
, *PVIA_BB_TYPE
;
190 //0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate)
191 typedef enum _VIA_PKT_TYPE
197 } VIA_PKT_TYPE
, *PVIA_PKT_TYPE
;
200 typedef enum __device_msg_level
{
201 MSG_LEVEL_ERR
=0, //Errors that will cause abnormal operation.
202 MSG_LEVEL_NOTICE
=1, //Some errors need users to be notified.
203 MSG_LEVEL_INFO
=2, //Normal message.
204 MSG_LEVEL_VERBOSE
=3, //Will report all trival errors.
205 MSG_LEVEL_DEBUG
=4 //Only for debug purpose.
206 } DEVICE_MSG_LEVEL
, *PDEVICE_MSG_LEVEL
;
208 typedef enum __device_init_type
{
209 DEVICE_INIT_COLD
=0, // cold init
210 DEVICE_INIT_RESET
, // reset init or Dx to D0 power remain init
211 DEVICE_INIT_DXPL
// Dx to D0 power lost init
212 } DEVICE_INIT_TYPE
, *PDEVICE_INIT_TYPE
;
217 #define MAX_BSSIDINFO_4_PMKID 16
218 #define MAX_PMKIDLIST 5
219 //Flags for PMKID Candidate list structure
220 #define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
223 typedef UCHAR NDIS_802_11_PMKID_VALUE
[16];
226 typedef enum _NDIS_802_11_WEP_STATUS
228 Ndis802_11WEPEnabled
,
229 Ndis802_11Encryption1Enabled
= Ndis802_11WEPEnabled
,
230 Ndis802_11WEPDisabled
,
231 Ndis802_11EncryptionDisabled
= Ndis802_11WEPDisabled
,
232 Ndis802_11WEPKeyAbsent
,
233 Ndis802_11Encryption1KeyAbsent
= Ndis802_11WEPKeyAbsent
,
234 Ndis802_11WEPNotSupported
,
235 Ndis802_11EncryptionNotSupported
= Ndis802_11WEPNotSupported
,
236 Ndis802_11Encryption2Enabled
,
237 Ndis802_11Encryption2KeyAbsent
,
238 Ndis802_11Encryption3Enabled
,
239 Ndis802_11Encryption3KeyAbsent
240 } NDIS_802_11_WEP_STATUS
, *PNDIS_802_11_WEP_STATUS
,
241 NDIS_802_11_ENCRYPTION_STATUS
, *PNDIS_802_11_ENCRYPTION_STATUS
;
244 typedef enum _NDIS_802_11_STATUS_TYPE
246 Ndis802_11StatusType_Authentication
,
247 Ndis802_11StatusType_MediaStreamMode
,
248 Ndis802_11StatusType_PMKID_CandidateList
,
249 Ndis802_11StatusTypeMax
// not a real type, defined as an upper bound
250 } NDIS_802_11_STATUS_TYPE
, *PNDIS_802_11_STATUS_TYPE
;
252 //Added new types for PMKID Candidate lists.
253 typedef struct _PMKID_CANDIDATE
{
254 NDIS_802_11_MAC_ADDRESS BSSID
;
256 } PMKID_CANDIDATE
, *PPMKID_CANDIDATE
;
259 typedef struct _BSSID_INFO
261 NDIS_802_11_MAC_ADDRESS BSSID
;
262 NDIS_802_11_PMKID_VALUE PMKID
;
263 } BSSID_INFO
, *PBSSID_INFO
;
265 typedef struct tagSPMKID
{
267 ULONG BSSIDInfoCount
;
268 BSSID_INFO BSSIDInfo
[MAX_BSSIDINFO_4_PMKID
];
271 typedef struct tagSPMKIDCandidateEvent
{
272 NDIS_802_11_STATUS_TYPE StatusType
;
273 ULONG Version
; // Version of the structure
274 ULONG NumCandidates
; // No. of pmkid candidates
275 PMKID_CANDIDATE CandidateList
[MAX_PMKIDLIST
];
276 } SPMKIDCandidateEvent
, *PSPMKIDCandidateEvent
;
281 #define MAX_QUIET_COUNT 8
283 typedef struct tagSQuietControl
{
288 } SQuietControl
, *PSQuietControl
;
291 typedef struct __chip_info_tbl
{
297 } CHIP_INFO
, *PCHIP_INFO
;
303 } DEVICE_OWNER_TYPE
, *PDEVICE_OWNER_TYPE
;
306 // The receive duplicate detection cache entry
307 typedef struct tagSCacheEntry
{
309 BYTE abyAddr2
[U_ETHER_ADDR_LEN
];
310 } SCacheEntry
, *PSCacheEntry
;
312 typedef struct tagSCache
{
313 /* The receive cache is updated circularly. The next entry to be written is
314 * indexed by the "InPtr".
316 UINT uInPtr
; // Place to use next
317 SCacheEntry asCacheEntry
[DUPLICATE_RX_CACHE_LENGTH
];
320 #define CB_MAX_RX_FRAG 64
321 // DeFragment Control Block, used for collecting fragments prior to reassembly
322 typedef struct tagSDeFragControlBlock
326 BYTE abyAddr2
[U_ETHER_ADDR_LEN
];
332 } SDeFragControlBlock
, *PSDeFragControlBlock
;
337 #define DEVICE_FLAGS_IP_ALIGN 0x00000001UL
338 #define DEVICE_FLAGS_PREAMBLE_TYPE 0x00000002UL
339 #define DEVICE_FLAGS_OP_MODE 0x00000004UL
340 #define DEVICE_FLAGS_PS_MODE 0x00000008UL
341 #define DEVICE_FLAGS_80211h_MODE 0x00000010UL
342 #define DEVICE_FLAGS_DiversityANT 0x00000020UL
344 //flags for driver status
345 #define DEVICE_FLAGS_OPENED 0x00010000UL
346 #define DEVICE_FLAGS_WOL_ENABLED 0x00080000UL
347 //flags for capbilities
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
367 typedef struct _RxManagementQueue
371 PSRxMgmtPacket Q
[NUM
];
372 } RxManagementQueue
,*PSRxManagementQueue
;
379 typedef struct __device_opt
{
380 int nRxDescs0
; //Number of RX descriptors0
381 int nRxDescs1
; //Number of RX descriptors1
382 int nTxDescs
[2]; //Number of TX descriptors 0, 1
383 int int_works
; //interrupt limits
384 int rts_thresh
; //rts threshold
392 } OPTIONS
, *POPTIONS
;
395 typedef struct __device_info
{
396 struct __device_info
* next
;
397 struct __device_info
* prev
;
399 struct pci_dev
* pcid
;
406 struct net_device
* dev
;
407 struct net_device
* next_module
;
408 struct net_device_stats stats
;
410 //dma addr, rx/tx pool
412 dma_addr_t rd0_pool_dma
;
413 dma_addr_t rd1_pool_dma
;
415 dma_addr_t td0_pool_dma
;
416 dma_addr_t td1_pool_dma
;
418 dma_addr_t tx_bufs_dma0
;
419 dma_addr_t tx_bufs_dma1
;
420 dma_addr_t tx_beacon_dma
;
424 PBYTE tx_beacon_bufs
;
439 volatile int iTDUsed
[TYPE_MAXTD
];
441 volatile PSTxDesc apCurrTD
[TYPE_MAXTD
];
442 volatile PSTxDesc apTailTD
[TYPE_MAXTD
];
444 volatile PSTxDesc apTD0Rings
;
445 volatile PSTxDesc apTD1Rings
;
447 volatile PSRxDesc aRD0Ring
;
448 volatile PSRxDesc aRD1Ring
;
449 volatile PSRxDesc pCurrRD
[TYPE_MAXRD
];
452 SDeFragControlBlock sRxDFCB
[CB_MAX_RX_FRAG
];
455 UINT uCurrentDFCBIdx
;
467 struct tasklet_struct RxMngWorkItem
;
468 RxManagementQueue rxManeQueue
;
472 struct completion notify
;
473 struct semaphore mlme_semaphore
;
486 BYTE byOriginalZonetype
;
487 BYTE abyMacContext
[MAC_MAX_CONTEXT_REG
];
488 BOOL bLinkPass
; // link status: OK or fail
489 BYTE abyCurrentNetAddr
[U_ETHER_ADDR_LEN
];
491 // Adapter statistics
492 SStatCounter scStatistic
;
494 SDot11Counters s802_11Counter
;
499 SMgmtObject sMgmtObj
;
501 // 802.11 MAC specific
505 DWORD dwTxAntennaSel
;
506 DWORD dwRxAntennaSel
;
508 BYTE byRxAntennaMode
;
509 BYTE byTxAntennaMode
;
513 UINT uSIFS
; //Current SIFS
514 UINT uDIFS
; //Current DIFS
515 UINT uEIFS
; //Current EIFS
516 UINT uSlot
; //Current SlotTime
517 UINT uCwMin
; //Current CwMin
518 UINT uCwMax
; //CwMax is fixed on 1023.
525 CARD_PHY_TYPE eCurrentPHYType
;
528 VIA_BB_TYPE byBBType
; //0: 11A, 1:11B, 2:11G
529 VIA_PKT_TYPE byPacketType
; //0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate)
532 BYTE byTopOFDMBasicRate
;
533 BYTE byTopCCKBasicRate
;
537 UINT uConnectionRate
;
540 BYTE byShortPreamble
;
544 WORD wFragmentationThreshold
;
545 BYTE byShortRetryLimit
;
546 BYTE byLongRetryLimit
;
547 CARD_OP_MODE eOPMode
;
550 WORD wMaxTransmitMSDULifetime
;
551 BYTE abyBSSID
[U_ETHER_ADDR_LEN
];
552 BYTE abyDesireBSSID
[U_ETHER_ADDR_LEN
];
553 WORD wCTSDuration
; // update while speed change
554 WORD wACKDuration
; // update while speed change
555 WORD wRTSTransmitLen
; // update while speed change
556 BYTE byRTSServiceField
; // update while speed change
557 BYTE byRTSSignalField
; // update while speed change
559 DWORD dwMaxReceiveLifetime
; // dot11MaxReceiveLifetime
562 BOOL bEncryptionEnable
;
567 BOOL bBarkerPreambleMd
;
570 WORD wUseProtectCntDown
;
572 BOOL bRadioControlOff
;
575 WORD wListenInterval
;
577 WMAC_POWER_MODE ePSMode
;
580 // GPIO Radio Control
584 BOOL bPrvActive4RadioOFF
;
590 BOOL bBeaconBufReady
;
592 BOOL bIsBeaconBufReadySet
;
593 UINT cbBeaconBufReadySetCnt
;
598 CMD_STATE eCommandState
;
606 UINT uAutoReConnectTime
;
610 CMD_ITEM eCmdQueue
[CMD_Q_SIZE
];
624 NDIS_802_11_WEP_STATUS eEncryptionStatus
;
626 //2007-0925-01<Add>by MikeLiu
627 //mike add :save old Encryption
628 NDIS_802_11_WEP_STATUS eOldEncryptionStatus
;
633 QWORD qwPacketNumber
; //For CCMP and TKIP as TSC(6 bytes)
634 UINT uCurrentWEPMode
;
637 BYTE abyPRNG
[WLAN_WEPMAX_KEYLEN
+3];
640 BYTE abyKey
[WLAN_WEP232_KEYLEN
];
652 // for OID_802_11_ASSOCIATION_INFORMATION
665 // For Update BaseBand VGA Gain Offset
667 UINT uBBVGADiffCount
;
670 BYTE abyBBVGA
[BB_VGA_LEVEL
];
671 LONG ldBmThreshold
[BB_VGA_LEVEL
];
678 DWORD dwDiagRefCount
;
683 // For Auto Power Tunning
685 BYTE byAutoPwrTunning
;
687 SHORT sPSetPointOFDMG
;
688 SHORT sPSetPointOFDMA
;
689 LONG lPFormulaOffset
;
694 // For RF Power table
699 BYTE abyCCKPwrTbl
[CB_MAX_CHANNEL_24G
+1];
700 BYTE abyOFDMPwrTbl
[CB_MAX_CHANNEL
+1];
701 I8 abyCCKDefaultPwr
[CB_MAX_CHANNEL_24G
+1];
702 I8 abyOFDMDefaultPwr
[CB_MAX_CHANNEL
+1];
703 I8 abyRegPwr
[CB_MAX_CHANNEL
+1];
704 I8 abyLocalPwr
[CB_MAX_CHANNEL
+1];
707 // BaseBand Loopback Use
714 struct timer_list sTimerCommand
;
716 struct timer_list sTimerTxData
;
717 ULONG nTxDataTimeCout
;
719 BOOL IsTxDataTrigger
;
722 #ifdef WPA_SM_Transtatus
723 BOOL fWPA_Authened
; //is WPA/WPA-PSK or WPA2/WPA2-PSK authen??
725 BYTE byReAssocCount
; //mike add:re-association retry times!
726 BYTE byLinkWaitCount
;
729 BYTE abyNodeName
[17];
731 BOOL bDiversityRegCtlON
;
732 BOOL bDiversityEnable
;
733 ULONG ulDiversityNValue
;
734 ULONG ulDiversityMValue
;
743 ULONG ulRatio_State0
;
744 ULONG ulRatio_State1
;
746 //SQ3 functions for antenna diversity
747 struct timer_list TimerSQ3Tmax1
;
748 struct timer_list TimerSQ3Tmax2
;
749 struct timer_list TimerSQ3Tmax3
;
752 ULONG uNumSQ3
[MAX_RATE
];
753 WORD wAntDiversityMaxRate
;
756 SEthernetHeader sTxEthHeader
;
757 SEthernetHeader sRxEthHeader
;
758 BYTE abyBroadcastAddr
[U_ETHER_ADDR_LEN
];
759 BYTE abySNAP_RFC1042
[U_ETHER_ADDR_LEN
];
760 BYTE abySNAP_Bridgetunnel
[U_ETHER_ADDR_LEN
];
761 BYTE abyEEPROM
[EEP_MAX_CONTEXT_SIZE
]; //DWORD alignment
762 // Pre-Authentication & PMK cache
764 SPMKIDCandidateEvent gsPMKIDCandidate
;
769 BYTE abyCountryCode
[3];
771 UINT uNumOfMeasureEIDs
;
772 PWLAN_IE_MEASURE_REQ pCurrMeasureEID
;
773 BOOL bMeasureInProgress
;
784 BYTE byChannelSwitchCount
;
786 BOOL bEnableFirstQuiet
;
787 BYTE byQuietStartCount
;
789 DWORD dwCurrentQuietEndTime
;
790 SQuietControl sQuiet
[MAX_QUIET_COUNT
];
793 BOOL bCountryInfo24G
;
795 WORD wBeaconInterval
;
797 //WPA supplicant deamon
798 struct net_device
*wpadev
;
801 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
809 BOOL bWPASuppWextEnabled
;
814 // user space daemon: hostapd, is used for HOSTAP
818 struct net_device
*apdev
;
819 int (*tx_80211
)(struct sk_buff
*skb
, struct net_device
*dev
);
824 struct iw_statistics wstats
; // wireless stats
827 } DEVICE_INFO
, *PSDevice
;
833 inline static VOID
EnQueue (PSDevice pDevice
,PSRxMgmtPacket pRxMgmtPacket
)
835 //printk("Enter EnQueue:tail is %d\n",pDevice->rxManeQueue.tail);
836 if ((pDevice
->rxManeQueue
.tail
+1) % NUM
== pDevice
->rxManeQueue
.head
)
838 //printk("Queue is Full,tail is %d\n",pDevice->rxManeQueue.tail);
843 pDevice
->rxManeQueue
.tail
= (pDevice
->rxManeQueue
.tail
+1)% NUM
;
844 pDevice
->rxManeQueue
.Q
[pDevice
->rxManeQueue
.tail
] = pRxMgmtPacket
;
845 pDevice
->rxManeQueue
.packet_num
++;
846 //printk("packet num is %d\n",pDevice->rxManeQueue.packet_num);
853 inline static PSRxMgmtPacket
DeQueue (PSDevice pDevice
)
855 PSRxMgmtPacket pRxMgmtPacket
;
856 if (pDevice
->rxManeQueue
.tail
== pDevice
->rxManeQueue
.head
)
858 printk("Queue is Empty\n");
864 //x=pDevice->rxManeQueue.head = (pDevice->rxManeQueue.head+1)%NUM;
865 pDevice
->rxManeQueue
.head
= (pDevice
->rxManeQueue
.head
+1)%NUM
;
866 x
= pDevice
->rxManeQueue
.head
;
867 //printk("Enter DeQueue:head is %d\n",x);
868 pRxMgmtPacket
= pDevice
->rxManeQueue
.Q
[x
];
869 pDevice
->rxManeQueue
.packet_num
--;
870 return pRxMgmtPacket
;
874 VOID
InitRxManagementQueue(PSDevice pDevice
);
885 inline static BOOL
device_get_ip(PSDevice pInfo
) {
886 struct in_device
* in_dev
=(struct in_device
*) pInfo
->dev
->ip_ptr
;
887 struct in_ifaddr
* ifa
;
890 ifa
=(struct in_ifaddr
*) in_dev
->ifa_list
;
892 memcpy(pInfo
->abyIPAddr
,&ifa
->ifa_address
,4);
901 static inline PDEVICE_RD_INFO
alloc_rd_info(void) {
903 if ((ptr
= (PDEVICE_RD_INFO
)kmalloc((int)sizeof(DEVICE_RD_INFO
), (int)GFP_ATOMIC
)) == NULL
)
906 memset(ptr
,0,sizeof(DEVICE_RD_INFO
));
911 static inline PDEVICE_TD_INFO
alloc_td_info(void) {
913 if ((ptr
= (PDEVICE_TD_INFO
)kmalloc((int)sizeof(DEVICE_TD_INFO
), (int)GFP_ATOMIC
))==NULL
)
916 memset(ptr
,0,sizeof(DEVICE_TD_INFO
));
921 /*--------------------- Export Functions --------------------------*/
923 BOOL
device_dma0_xmit(PSDevice pDevice
, struct sk_buff
*skb
, UINT uNodeIndex
);
924 BOOL
device_alloc_frag_buf(PSDevice pDevice
, PSDeFragControlBlock pDeF
);
925 int Config_FileOperation(PSDevice pDevice
,BOOL fwrite
,unsigned char *Parameter
);