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>
47 #include <linux/crc32.h>
50 #define DEVICE_ETHTOOL_IOCTL_SUPPORT
51 #include <linux/ethtool.h>
53 #undef DEVICE_ETHTOOL_IOCTL_SUPPORT
56 /* please copy below macro to driver_event.c for API */
57 #define RT_INSMOD_EVENT_FLAG 0x0101
58 #define RT_UPDEV_EVENT_FLAG 0x0102
59 #define RT_DISCONNECTED_EVENT_FLAG 0x0103
60 #define RT_WPACONNECTED_EVENT_FLAG 0x0104
61 #define RT_DOWNDEV_EVENT_FLAG 0x0105
62 #define RT_RMMOD_EVENT_FLAG 0x0106
68 #include "device_cfg.h"
81 #define VNT_USB_VENDOR_ID 0x160a
82 #define VNT_USB_PRODUCT_ID 0x3184
84 #define MAC_MAX_CONTEXT_REG (256+128)
86 #define MAX_MULTICAST_ADDRESS_NUM 32
87 #define MULTICAST_ADDRESS_LIST_SIZE (MAX_MULTICAST_ADDRESS_NUM * ETH_ALEN)
89 #define DUPLICATE_RX_CACHE_LENGTH 5
91 #define NUM_KEY_ENTRY 11
96 #define TX_WEP_SWOTP 3
97 #define TX_WEP_OTPSW 4
98 #define TX_WEP_SW232 5
100 #define KEYSEL_WEP40 0
101 #define KEYSEL_WEP104 1
102 #define KEYSEL_TKIP 2
103 #define KEYSEL_CCMP 3
105 #define AUTO_FB_NONE 0
115 #define ANT_DIVERSITY 2
116 #define ANT_RXD_TXA 3
117 #define ANT_RXD_TXB 4
118 #define ANT_UNKNOWN 0xFF
124 #define MAXCHECKHANGCNT 4
127 #define TX_PKT_UNI 0x00
128 #define TX_PKT_MULTI 0x01
129 #define TX_PKT_BROAD 0x02
131 #define BB_VGA_LEVEL 4
132 #define BB_VGA_CHANGE_THRESHOLD 3
135 #define RUN_AT(x) (jiffies+(x))
139 #define RESERV_AC0DMA 4
141 #define PRIVATE_Message 0
143 #define DBG_PRT(l, p, args...) { if (l <= msglevel) printk(p, ##args); }
144 #define PRINT_K(p, args...) { if (PRIVATE_Message) printk(p, ##args); }
146 typedef enum __device_msg_level
{
147 MSG_LEVEL_ERR
= 0, /* Errors causing abnormal operation */
148 MSG_LEVEL_NOTICE
= 1, /* Errors needing user notification */
149 MSG_LEVEL_INFO
= 2, /* Normal message. */
150 MSG_LEVEL_VERBOSE
= 3, /* Will report all trival errors. */
151 MSG_LEVEL_DEBUG
= 4 /* Only for debug purpose. */
152 } DEVICE_MSG_LEVEL
, *PDEVICE_MSG_LEVEL
;
154 #define DEVICE_INIT_COLD 0x0 /* cold init */
155 #define DEVICE_INIT_RESET 0x1 /* reset init or Dx to D0 power remain */
156 #define DEVICE_INIT_DXPL 0x2 /* Dx to D0 power lost init */
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 /* tx packet info for rxtx */
193 struct vnt_tx_pkt_info
{
195 u8 dest_addr
[ETH_ALEN
];
198 /* structure got from configuration file as user-desired default settings */
199 typedef struct _DEFAULT_CONFIG
{
201 signed int eConfigMode
;
202 signed int eAuthenMode
; /* open/wep/wpa */
203 signed int bShareKeyAlgorithm
; /* open-open/{open,wep}-sharekey */
204 signed int keyidx
; /* wepkey index */
205 signed int eEncryptionStatus
;
206 } DEFAULT_CONFIG
, *PDEFAULT_CONFIG
;
209 * Structure to keep track of USB interrupt packets
212 unsigned int uDataLen
;
214 /* struct urb *pUrb; */
216 } INT_BUFFER
, *PINT_BUFFER
;
218 /* 0:11A 1:11B 2:11G */
219 typedef enum _VIA_BB_TYPE
224 } VIA_BB_TYPE
, *PVIA_BB_TYPE
;
226 /* 0:11a, 1:11b, 2:11gb (only CCK in BasicRate), 3:11ga(OFDM in BasicRate) */
227 typedef enum _VIA_PKT_TYPE
233 } VIA_PKT_TYPE
, *PVIA_PKT_TYPE
;
237 typedef enum __DEVICE_NDIS_STATUS
{
242 } DEVICE_NDIS_STATUS
, *PDEVICE_NDIS_STATUS
;
244 #define MAX_BSSIDINFO_4_PMKID 16
245 #define MAX_PMKIDLIST 5
246 /* flags for PMKID Candidate list structure */
247 #define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
249 /* PMKID Structures */
250 typedef unsigned char NDIS_802_11_PMKID_VALUE
[16];
252 typedef enum _NDIS_802_11_WEP_STATUS
254 Ndis802_11WEPEnabled
,
255 Ndis802_11Encryption1Enabled
= Ndis802_11WEPEnabled
,
256 Ndis802_11WEPDisabled
,
257 Ndis802_11EncryptionDisabled
= Ndis802_11WEPDisabled
,
258 Ndis802_11WEPKeyAbsent
,
259 Ndis802_11Encryption1KeyAbsent
= Ndis802_11WEPKeyAbsent
,
260 Ndis802_11WEPNotSupported
,
261 Ndis802_11EncryptionNotSupported
= Ndis802_11WEPNotSupported
,
262 Ndis802_11Encryption2Enabled
,
263 Ndis802_11Encryption2KeyAbsent
,
264 Ndis802_11Encryption3Enabled
,
265 Ndis802_11Encryption3KeyAbsent
266 } NDIS_802_11_WEP_STATUS
, *PNDIS_802_11_WEP_STATUS
,
267 NDIS_802_11_ENCRYPTION_STATUS
, *PNDIS_802_11_ENCRYPTION_STATUS
;
269 typedef enum _NDIS_802_11_STATUS_TYPE
271 Ndis802_11StatusType_Authentication
,
272 Ndis802_11StatusType_MediaStreamMode
,
273 Ndis802_11StatusType_PMKID_CandidateList
,
274 Ndis802_11StatusTypeMax
, /* not a real type, defined as upper bound */
275 } NDIS_802_11_STATUS_TYPE
, *PNDIS_802_11_STATUS_TYPE
;
277 /* added new types for PMKID Candidate lists */
278 typedef struct _PMKID_CANDIDATE
{
279 NDIS_802_11_MAC_ADDRESS BSSID
;
281 } PMKID_CANDIDATE
, *PPMKID_CANDIDATE
;
283 typedef struct _BSSID_INFO
285 NDIS_802_11_MAC_ADDRESS BSSID
;
286 NDIS_802_11_PMKID_VALUE PMKID
;
287 } BSSID_INFO
, *PBSSID_INFO
;
289 typedef struct tagSPMKID
{
290 unsigned long Length
;
291 unsigned long BSSIDInfoCount
;
292 BSSID_INFO BSSIDInfo
[MAX_BSSIDINFO_4_PMKID
];
295 typedef struct tagSPMKIDCandidateEvent
{
296 NDIS_802_11_STATUS_TYPE StatusType
;
297 unsigned long Version
; /* Version of the structure */
298 unsigned long NumCandidates
; /* No. of pmkid candidates */
299 PMKID_CANDIDATE CandidateList
[MAX_PMKIDLIST
];
300 } SPMKIDCandidateEvent
, *PSPMKIDCandidateEvent
;
302 /*++ 802.11h related */
303 #define MAX_QUIET_COUNT 8
305 typedef struct tagSQuietControl
{
310 } SQuietControl
, *PSQuietControl
;
312 /* The receive duplicate detection cache entry */
313 typedef struct tagSCacheEntry
{
315 u8 abyAddr2
[ETH_ALEN
];
317 } SCacheEntry
, *PSCacheEntry
;
319 typedef struct tagSCache
{
320 /* The receive cache is updated circularly. The next entry to be written is
321 * indexed by the "InPtr".
323 unsigned int uInPtr
; /* Place to use next */
324 SCacheEntry asCacheEntry
[DUPLICATE_RX_CACHE_LENGTH
];
327 #define CB_MAX_RX_FRAG 64
329 * DeFragment Control Block, used for collecting fragments prior to reassembly
331 typedef struct tagSDeFragControlBlock
335 u8 abyAddr2
[ETH_ALEN
];
336 unsigned int uLifetime
;
339 unsigned int cbFrameLength
;
341 } SDeFragControlBlock
, *PSDeFragControlBlock
;
343 /* flags for options */
344 #define DEVICE_FLAGS_UNPLUG 0x00000001UL
345 #define DEVICE_FLAGS_PREAMBLE_TYPE 0x00000002UL
346 #define DEVICE_FLAGS_OP_MODE 0x00000004UL
347 #define DEVICE_FLAGS_PS_MODE 0x00000008UL
348 #define DEVICE_FLAGS_80211h_MODE 0x00000010UL
350 /* flags for driver status */
351 #define DEVICE_FLAGS_OPENED 0x00010000UL
352 #define DEVICE_FLAGS_WOL_ENABLED 0x00080000UL
353 /* flags for capabilities */
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
369 typedef struct __device_opt
{
370 int nRxDescs0
; /* number of RX descriptors 0 */
371 int nTxDescs0
; /* number of TX descriptors 0, 1, 2, 3 */
372 int rts_thresh
; /* RTS threshold */
381 } OPTIONS
, *POPTIONS
;
385 struct usb_device
*usb
;
386 struct net_device
*dev
;
387 struct net_device_stats stats
;
391 struct tasklet_struct CmdWorkItem
;
392 struct tasklet_struct EventWorkItem
;
393 struct work_struct read_work_item
;
394 struct work_struct rx_mng_work_item
;
411 SDeFragControlBlock sRxDFCB
[CB_MAX_RX_FRAG
];
417 struct urb
*pControlURB
;
418 struct urb
*pInterruptURB
;
419 struct usb_ctrlrequest sUsbCtlRequest
;
422 /* Variables to track resources for the BULK In Pipe */
423 struct vnt_rcb
*pRCBMem
;
424 struct vnt_rcb
*apRCB
[CB_MAX_RX_DESC
];
426 struct vnt_rcb
*FirstRecvFreeList
;
427 struct vnt_rcb
*LastRecvFreeList
;
429 struct vnt_rcb
*FirstRecvMngList
;
430 struct vnt_rcb
*LastRecvMngList
;
432 int bIsRxWorkItemQueued
;
433 int bIsRxMngWorkItemQueued
;
434 unsigned long ulRcvRefCount
; /* packets that have not returned back */
436 /* Variables to track resources for the BULK Out Pipe */
437 struct vnt_usb_send_context
*apTD
[CB_MAX_TX_DESC
];
439 struct vnt_tx_pkt_info pkt_info
[16];
441 /* Variables to track resources for the Interrupt In Pipe */
443 int fKillEventPollingThread
;
446 /* default config from file by user setting */
447 DEFAULT_CONFIG config_file
;
449 /* Statistic for USB */
450 unsigned long ulBulkInPosted
;
451 unsigned long ulBulkInError
;
452 unsigned long ulBulkInContCRCError
;
453 unsigned long ulBulkInBytesRead
;
455 unsigned long ulBulkOutPosted
;
456 unsigned long ulBulkOutError
;
457 unsigned long ulBulkOutContCRCError
;
458 unsigned long ulBulkOutBytesWrite
;
460 unsigned long ulIntInPosted
;
461 unsigned long ulIntInError
;
462 unsigned long ulIntInContCRCError
;
463 unsigned long ulIntInBytesRead
;
465 /* Version control */
466 u16 wFirmwareVersion
;
474 u8 byOriginalZonetype
;
476 int bLinkPass
; /* link status: OK or fail */
477 struct vnt_cmd_card_init init_command
;
478 struct vnt_rsp_card_init init_response
;
479 u8 abyCurrentNetAddr
[ETH_ALEN
];
480 u8 abyPermanentNetAddr
[ETH_ALEN
];
484 /* Adapter statistics */
485 SStatCounter scStatistic
;
487 SDot11Counters s802_11Counter
;
489 /* Maintain statistical debug info. */
490 unsigned long packetsReceived
;
491 unsigned long packetsReceivedDropped
;
492 unsigned long packetsReceivedOverflow
;
493 unsigned long packetsSent
;
494 unsigned long packetsSentDropped
;
495 unsigned long SendContextsInUse
;
496 unsigned long RcvBuffersInUse
;
498 /* 802.11 management */
499 struct vnt_manager vnt_mgmt
;
505 /* 802.11 MAC specific */
509 /* Antenna Diversity */
519 /* SQ3 functions for antenna diversity */
520 struct timer_list TimerSQ3Tmax1
;
521 struct timer_list TimerSQ3Tmax2
;
522 struct timer_list TimerSQ3Tmax3
;
524 int bDiversityRegCtlON
;
525 int bDiversityEnable
;
526 unsigned long ulDiversityNValue
;
527 unsigned long ulDiversityMValue
;
531 unsigned long ulSQ3TH
;
533 unsigned long uDiversityCnt
;
535 unsigned long ulRatio_State0
;
536 unsigned long ulRatio_State1
;
537 unsigned long ulSQ3_State0
;
538 unsigned long ulSQ3_State1
;
540 unsigned long aulSQ3Val
[MAX_RATE
];
541 unsigned long aulPktNum
[MAX_RATE
];
544 u32 uSIFS
; /* Current SIFS */
545 u32 uDIFS
; /* Current DIFS */
546 u32 uEIFS
; /* Current EIFS */
547 u32 uSlot
; /* Current SlotTime */
548 u32 uCwMin
; /* Current CwMin */
549 u32 uCwMax
; /* CwMax is fixed on 1023 */
559 VIA_BB_TYPE byBBType
; /* 0: 11A, 1:11B, 2:11G */
560 VIA_PKT_TYPE byPacketType
; /* 0:11a 1:11b 2:11gb 3:11ga */
563 u8 byTopOFDMBasicRate
;
564 u8 byTopCCKBasicRate
;
566 u32 dwAotoRateTxOkCnt
;
567 u32 dwAotoRateTxFailCnt
;
568 u32 dwErrorRateThreshold
[13];
569 u32 dwTPTable
[MAX_RATE
];
570 u8 abyEEPROM
[EEP_MAX_CONTEXT_SIZE
]; /*u32 alignment */
581 /* For RF Power table */
587 u8 abyOFDMPwrTbl
[14];
588 u8 abyOFDMAPwrTbl
[42];
595 u16 wFragmentationThreshold
;
596 u8 byShortRetryLimit
;
598 CARD_OP_MODE eOPMode
;
600 u16 wMaxTransmitMSDULifetime
;
601 u8 abyBSSID
[ETH_ALEN
];
602 u8 abyDesireBSSID
[ETH_ALEN
];
604 u32 dwMaxReceiveLifetime
; /* dot11MaxReceiveLifetime */
607 int bEncryptionEnable
;
611 int bBarkerPreambleMd
;
614 u16 wUseProtectCntDown
;
616 int bRadioControlOff
;
623 WMAC_POWER_MODE ePSMode
;
624 unsigned long ulPSModeWaitTx
;
627 /* Beacon releated */
635 CMD_STATE eCommandState
;
644 u32 uAutoReConnectTime
;
649 CMD_ITEM eCmdQueue
[CMD_Q_SIZE
];
664 unsigned long ulTxPower
;
667 NDIS_802_11_WEP_STATUS eEncryptionStatus
;
669 NDIS_802_11_WEP_STATUS eOldEncryptionStatus
;
674 u8 abyPRNG
[WLAN_WEPMAX_KEYLEN
+3];
678 u8 abyKey
[WLAN_WEP232_KEYLEN
];
692 /* For Update BaseBand VGA Gain Offset */
697 u8 abyBBVGA
[BB_VGA_LEVEL
];
698 signed long ldBmThreshold
[BB_VGA_LEVEL
];
708 /* For Auto Power Tunning */
711 /* BaseBand Loopback Use */
718 struct delayed_work run_command_work
;
719 /* One second callback */
720 struct delayed_work second_callback_work
;
724 int fWPA_Authened
; /*is WPA/WPA-PSK or WPA2/WPA2-PSK authen?? */
728 struct ethhdr sTxEthHeader
;
729 struct ethhdr sRxEthHeader
;
730 u8 abyBroadcastAddr
[ETH_ALEN
];
731 u8 abySNAP_RFC1042
[ETH_ALEN
];
732 u8 abySNAP_Bridgetunnel
[ETH_ALEN
];
734 /* Pre-Authentication & PMK cache */
736 SPMKIDCandidateEvent gsPMKIDCandidate
;
743 u8 byChannelSwitchCount
;
745 /* WPA supplicant daemon */
751 int bWPASuppWextEnabled
;
753 /* user space daemon: hostapd, is used for HOSTAP */
757 struct net_device
*apdev
;
758 int (*tx_80211
)(struct sk_buff
*skb
, struct net_device
*dev
);
762 struct iw_statistics wstats
; /* wireless stats */
768 #define EnqueueRCB(_Head, _Tail, _RCB) \
774 _Tail->Next = _RCB; \
780 #define DequeueRCB(Head, Tail) \
782 struct vnt_rcb *RCB = Head; \
789 #define ADD_ONE_WITH_WRAP_AROUND(uVar, uModulo) { \
790 if ((uVar) >= ((uModulo) - 1)) \
796 #define fMP_RESET_IN_PROGRESS 0x00000001
797 #define fMP_DISCONNECTED 0x00000002
798 #define fMP_HALT_IN_PROGRESS 0x00000004
799 #define fMP_SURPRISE_REMOVED 0x00000008
800 #define fMP_RECV_LOOKASIDE 0x00000010
801 #define fMP_INIT_IN_PROGRESS 0x00000020
802 #define fMP_SEND_SIDE_RESOURCE_ALLOCATED 0x00000040
803 #define fMP_RECV_SIDE_RESOURCE_ALLOCATED 0x00000080
804 #define fMP_POST_READS 0x00000100
805 #define fMP_POST_WRITES 0x00000200
806 #define fMP_CONTROL_READS 0x00000400
807 #define fMP_CONTROL_WRITES 0x00000800
809 #define MP_SET_FLAG(_M, _F) ((_M)->Flags |= (_F))
810 #define MP_CLEAR_FLAG(_M, _F) ((_M)->Flags &= ~(_F))
811 #define MP_TEST_FLAGS(_M, _F) (((_M)->Flags & (_F)) == (_F))
813 #define MP_IS_READY(_M) (((_M)->Flags & \
814 (fMP_DISCONNECTED | fMP_RESET_IN_PROGRESS | fMP_HALT_IN_PROGRESS | fMP_INIT_IN_PROGRESS | fMP_SURPRISE_REMOVED)) == 0)
816 int device_alloc_frag_buf(struct vnt_private
*, PSDeFragControlBlock pDeF
);