Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
device.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3  * All rights reserved.
4  *
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.
9  *
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.
14  *
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.
18  *
19  * File: device.h
20  *
21  * Purpose: MAC Data structure
22  *
23  * Author: Tevin Chen
24  *
25  * Date: Mar 17, 1997
26  *
27  */
28 
29 #ifndef __DEVICE_H__
30 #define __DEVICE_H__
31 
32 #include <linux/module.h>
33 #include <linux/types.h>
34 #include <linux/init.h>
35 #include <linux/mm.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/string.h>
48 #include <linux/wait.h>
49 #include <linux/if_arp.h>
50 #include <linux/sched.h>
51 #include <linux/if.h>
52 #include <linux/rtnetlink.h>//James
53 #include <linux/proc_fs.h>
54 #include <linux/inetdevice.h>
55 #include <linux/reboot.h>
56 #include <linux/usb.h>
57 #include <linux/signal.h>
58 #include <linux/firmware.h>
59 #include <asm/io.h>
60 #include <asm/uaccess.h>
61 #ifdef SIOCETHTOOL
62 #define DEVICE_ETHTOOL_IOCTL_SUPPORT
63 #include <linux/ethtool.h>
64 #else
65 #undef DEVICE_ETHTOOL_IOCTL_SUPPORT
66 #endif
67 /* Include Wireless Extension definition and check version - Jean II */
68 #include <linux/wireless.h>
69 #include <net/iw_handler.h> // New driver API
70 
71 #ifndef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
72 #define WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
73 #endif
74 
75 //please copy below macro to driver_event.c for API
76 #define RT_INSMOD_EVENT_FLAG 0x0101
77 #define RT_UPDEV_EVENT_FLAG 0x0102
78 #define RT_DISCONNECTED_EVENT_FLAG 0x0103
79 #define RT_WPACONNECTED_EVENT_FLAG 0x0104
80 #define RT_DOWNDEV_EVENT_FLAG 0x0105
81 #define RT_RMMOD_EVENT_FLAG 0x0106
82 
83 //
84 // device specific
85 //
86 
87 #include "device_cfg.h"
88 #include "ttype.h"
89 #include "80211hdr.h"
90 #include "tether.h"
91 #include "wmgr.h"
92 #include "wcmd.h"
93 #include "mib.h"
94 #include "srom.h"
95 #include "rc4.h"
96 #include "desc.h"
97 #include "key.h"
98 #include "card.h"
99 
100 /*--------------------- Export Definitions -------------------------*/
101 #define VNT_USB_VENDOR_ID 0x160a
102 #define VNT_USB_PRODUCT_ID 0x3184
103 
104 #define MAC_MAX_CONTEXT_REG (256+128)
105 
106 #define MAX_MULTICAST_ADDRESS_NUM 32
107 #define MULTICAST_ADDRESS_LIST_SIZE (MAX_MULTICAST_ADDRESS_NUM * ETH_ALEN)
108 
109 #define DUPLICATE_RX_CACHE_LENGTH 5
110 
111 #define NUM_KEY_ENTRY 11
112 
113 #define TX_WEP_NONE 0
114 #define TX_WEP_OTF 1
115 #define TX_WEP_SW 2
116 #define TX_WEP_SWOTP 3
117 #define TX_WEP_OTPSW 4
118 #define TX_WEP_SW232 5
119 
120 #define KEYSEL_WEP40 0
121 #define KEYSEL_WEP104 1
122 #define KEYSEL_TKIP 2
123 #define KEYSEL_CCMP 3
124 
125 #define AUTO_FB_NONE 0
126 #define AUTO_FB_0 1
127 #define AUTO_FB_1 2
128 
129 #define FB_RATE0 0
130 #define FB_RATE1 1
131 
132 // Antenna Mode
133 #define ANT_A 0
134 #define ANT_B 1
135 #define ANT_DIVERSITY 2
136 #define ANT_RXD_TXA 3
137 #define ANT_RXD_TXB 4
138 #define ANT_UNKNOWN 0xFF
139 #define ANT_TXA 0
140 #define ANT_TXB 1
141 #define ANT_RXA 2
142 #define ANT_RXB 3
143 
144 
145 #define MAXCHECKHANGCNT 4
146 
147 //Packet type
148 #define TX_PKT_UNI 0x00
149 #define TX_PKT_MULTI 0x01
150 #define TX_PKT_BROAD 0x02
151 
152 #define BB_VGA_LEVEL 4
153 #define BB_VGA_CHANGE_THRESHOLD 3
154 
155 #ifndef RUN_AT
156 #define RUN_AT(x) (jiffies+(x))
157 #endif
158 
159 // DMA related
160 #define RESERV_AC0DMA 4
161 
162 #define PRIVATE_Message 0
163 
164 /*--------------------- Export Types ------------------------------*/
165 
166 #define DBG_PRT(l, p, args...) { if (l <= msglevel) printk(p, ##args); }
167 #define PRINT_K(p, args...) { if (PRIVATE_Message) printk(p, ##args); }
168 
169 typedef enum __device_msg_level {
170  MSG_LEVEL_ERR = 0, /* Errors causing abnormal operation */
171  MSG_LEVEL_NOTICE = 1, /* Errors needing user notification */
172  MSG_LEVEL_INFO = 2, /* Normal message. */
173  MSG_LEVEL_VERBOSE = 3, /* Will report all trival errors. */
174  MSG_LEVEL_DEBUG = 4 /* Only for debug purpose. */
176 
177 typedef enum __device_init_type {
178  DEVICE_INIT_COLD = 0, /* cold init */
179  DEVICE_INIT_RESET, /* reset init or Dx to D0 power remain */
180  DEVICE_INIT_DXPL /* Dx to D0 power lost init */
182 
183 //USB
184 
185 //
186 // Enum of context types for SendPacket
187 //
188 typedef enum _CONTEXT_TYPE {
191 } CONTEXT_TYPE;
192 
193 // RCB (Receive Control Block)
194 typedef struct _RCB
195 {
196  void *Next;
197  signed long Ref;
198  void *pDevice;
199  struct urb *pUrb;
201  struct sk_buff* skb;
203 
204 } RCB, *PRCB;
205 
206 // used to track bulk out irps
207 typedef struct _USB_SEND_CONTEXT {
208  void *pDevice;
209  struct sk_buff *pPacket;
210  struct urb *pUrb;
211  unsigned int uBufLen;
213  SEthernetHeader sEthHeader;
214  void *Next;
218 
219 /* structure got from configuration file as user-desired default settings */
220 typedef struct _DEFAULT_CONFIG {
221  signed int ZoneType;
222  signed int eConfigMode;
223  signed int eAuthenMode; /* open/wep/wpa */
224  signed int bShareKeyAlgorithm; /* open-open/{open,wep}-sharekey */
225  signed int keyidx; /* wepkey index */
226  signed int eEncryptionStatus;
228 
229 //
230 // Structure to keep track of usb interrupt packets
231 //
232 typedef struct {
233  unsigned int uDataLen;
235 // struct urb *pUrb;
238 
239 //0:11A 1:11B 2:11G
240 typedef enum _VIA_BB_TYPE
241 {
246 
247 //0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate)
248 typedef enum _VIA_PKT_TYPE
249 {
255 
256 //++ NDIS related
257 
258 typedef enum __DEVICE_NDIS_STATUS {
264 
265 #define MAX_BSSIDINFO_4_PMKID 16
266 #define MAX_PMKIDLIST 5
267 //Flags for PMKID Candidate list structure
268 #define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
269 
270 // PMKID Structures
271 typedef unsigned char NDIS_802_11_PMKID_VALUE[16];
272 
273 
275 {
290 
291 
293 {
297  Ndis802_11StatusTypeMax // not a real type, defined as an upper bound
299 
300 //Added new types for PMKID Candidate lists.
301 typedef struct _PMKID_CANDIDATE {
303  unsigned long Flags;
305 
306 
307 typedef struct _BSSID_INFO
308 {
312 
313 typedef struct tagSPMKID {
314  unsigned long Length;
315  unsigned long BSSIDInfoCount;
317 } SPMKID, *PSPMKID;
318 
319 typedef struct tagSPMKIDCandidateEvent {
321  unsigned long Version; /* Version of the structure */
322  unsigned long NumCandidates; /* No. of pmkid candidates */
325 
326 //--
327 
328 //++ 802.11h related
329 #define MAX_QUIET_COUNT 8
330 
331 typedef struct tagSQuietControl {
337 
338 //--
339 
340 
341 // The receive duplicate detection cache entry
342 typedef struct tagSCacheEntry{
347 
348 typedef struct tagSCache{
349 /* The receive cache is updated circularly. The next entry to be written is
350  * indexed by the "InPtr".
351 */
352  unsigned int uInPtr; /* Place to use next */
354 } SCache, *PSCache;
355 
356 #define CB_MAX_RX_FRAG 64
357 // DeFragment Control Block, used for collecting fragments prior to reassembly
358 typedef struct tagSDeFragControlBlock
359 {
363  unsigned int uLifetime;
364  struct sk_buff* skb;
366  unsigned int cbFrameLength;
369 
370 
371 
372 //flags for options
373 #define DEVICE_FLAGS_UNPLUG 0x00000001UL
374 #define DEVICE_FLAGS_PREAMBLE_TYPE 0x00000002UL
375 #define DEVICE_FLAGS_OP_MODE 0x00000004UL
376 #define DEVICE_FLAGS_PS_MODE 0x00000008UL
377 #define DEVICE_FLAGS_80211h_MODE 0x00000010UL
378 
379 //flags for driver status
380 #define DEVICE_FLAGS_OPENED 0x00010000UL
381 #define DEVICE_FLAGS_WOL_ENABLED 0x00080000UL
382 //flags for capbilities
383 #define DEVICE_FLAGS_TX_ALIGN 0x01000000UL
384 #define DEVICE_FLAGS_HAVE_CAM 0x02000000UL
385 #define DEVICE_FLAGS_FLOW_CTRL 0x04000000UL
386 
387 //flags for MII status
388 #define DEVICE_LINK_FAIL 0x00000001UL
389 #define DEVICE_SPEED_10 0x00000002UL
390 #define DEVICE_SPEED_100 0x00000004UL
391 #define DEVICE_SPEED_1000 0x00000008UL
392 #define DEVICE_DUPLEX_FULL 0x00000010UL
393 #define DEVICE_AUTONEG_ENABLE 0x00000020UL
394 #define DEVICE_FORCED_BY_EEPROM 0x00000040UL
395 //for device_set_media_duplex
396 #define DEVICE_LINK_CHANGE 0x00000001UL
397 
398 
399 typedef struct __device_opt {
400  int nRxDescs0; //Number of RX descriptors0
401  int nTxDescs0; //Number of TX descriptors 0, 1, 2, 3
402  int rts_thresh; //rts threshold
403  int frag_thresh;
404  int OpMode;
405  int data_rate;
406  int channel_num;
407  int short_retry;
408  int long_retry;
409  int bbp_type;
410  u32 flags;
411 } OPTIONS, *POPTIONS;
412 
413 
414 typedef struct __device_info {
415 
416 // netdev
417  struct usb_device* usb;
418  struct net_device* dev;
419  struct net_device_stats stats;
420 
421  const struct firmware *firmware;
422 
423  OPTIONS sOpts;
424 
429 
430  u32 rx_buf_sz;
431  int multicast_limit;
433 
435 
436  u32 rx_bytes;
437 
439 
440  u32 flags;
441  unsigned long Flags;
442 
444 
446  unsigned int cbDFCB;
447  unsigned int cbFreeDFCB;
448  unsigned int uCurrentDFCBIdx;
449 
450  // +++USB
451 
452  struct urb *pControlURB;
455 
456  unsigned int int_interval;
457  //
458  // Variables to track resources for the BULK In Pipe
459  //
460  PRCB pRCBMem;
462  unsigned int cbRD;
465  unsigned int NumRecvFreeList;
468  unsigned int NumRecvMngList;
471  unsigned long ulRcvRefCount; /* packets that have not returned back */
472 
473  //
474  // Variables to track resources for the BULK Out Pipe
475  //
476 
477  PUSB_SEND_CONTEXT apTD[CB_MAX_TX_DESC];
478  unsigned int cbTD;
479 
480  //
481  // Variables to track resources for the Interrupt In Pipe
482  //
486 
487 
488  //default config from file by user setting
490 
491 
492  //
493  // Statistic for USB
494  // protect with spinlock
495  unsigned long ulBulkInPosted;
496  unsigned long ulBulkInError;
497  unsigned long ulBulkInContCRCError;
498  unsigned long ulBulkInBytesRead;
499 
500  unsigned long ulBulkOutPosted;
501  unsigned long ulBulkOutError;
502  unsigned long ulBulkOutContCRCError;
503  unsigned long ulBulkOutBytesWrite;
504 
505  unsigned long ulIntInPosted;
506  unsigned long ulIntInError;
507  unsigned long ulIntInContCRCError;
508  unsigned long ulIntInBytesRead;
509 
510 
511  // Version control
516 
517 
520 
522 
523  BOOL bLinkPass; // link status: OK or fail
526  // SW network address
527  /* u8 abySoftwareNetAddr[ETH_ALEN]; */
529 
530  // Adapter statistics
532  // 802.11 counter
534 
535  //
536  // Maintain statistical debug info.
537  //
538  unsigned long packetsReceived;
539  unsigned long packetsReceivedDropped;
540  unsigned long packetsReceivedOverflow;
541  unsigned long packetsSent;
542  unsigned long packetsSentDropped;
543  unsigned long SendContextsInUse;
544  unsigned long RcvBuffersInUse;
545 
546 
547  // 802.11 management
549 
551  unsigned int cbBulkInMax;
553 
554  // 802.11 MAC specific
555  unsigned int uCurrRSSI;
557 
558 
559  //Antenna Diversity
568 
569  //SQ3 functions for antenna diversity
570  struct timer_list TimerSQ3Tmax1;
571  struct timer_list TimerSQ3Tmax2;
572  struct timer_list TimerSQ3Tmax3;
573 
576  unsigned long ulDiversityNValue;
577  unsigned long ulDiversityMValue;
581  unsigned long ulSQ3TH;
582 
583  unsigned long uDiversityCnt;
585  unsigned long ulRatio_State0;
586  unsigned long ulRatio_State1;
587  unsigned long ulSQ3_State0;
588  unsigned long ulSQ3_State1;
589 
590  unsigned long aulSQ3Val[MAX_RATE];
591  unsigned long aulPktNum[MAX_RATE];
592 
593  /* IFS & Cw */
594  unsigned int uSIFS; /* Current SIFS */
595  unsigned int uDIFS; /* Current DIFS */
596  unsigned int uEIFS; /* Current EIFS */
597  unsigned int uSlot; /* Current SlotTime */
598  unsigned int uCwMin; /* Current CwMin */
599  unsigned int uCwMax; /* CwMax is fixed on 1023 */
600 
601  // PHY parameter
607 
608  // Rate
609  VIA_BB_TYPE byBBType; //0: 11A, 1:11B, 2:11G
610  VIA_PKT_TYPE byPacketType; //0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate)
615 
616 
621  BYTE abyEEPROM[EEP_MAX_CONTEXT_SIZE]; //DWORD alignment
622 
625  unsigned int uConnectionRate;
626 
629  // CARD_PHY_TYPE
631 
632  // For RF Power table
640 
651  WORD wCTSDuration; // update while speed change
652  WORD wACKDuration; // update while speed change
653  WORD wRTSTransmitLen; // update while speed change
654  BYTE byRTSServiceField; // update while speed change
655  BYTE byRTSSignalField; // update while speed change
656 
657  DWORD dwMaxReceiveLifetime; // dot11MaxReceiveLifetime
658 
667 
670 
673 
674  // Power save
679  unsigned long ulPSModeWaitTx;
681 
682  // Beacon releated
688  unsigned int uScanTime;
689 
691 
695 
699  unsigned int uAutoReConnectTime;
700  unsigned int uIsroamingTime;
701 
702  // 802.11 counter
703 
705  unsigned int uCmdDequeueIdx;
706  unsigned int uCmdEnqueueIdx;
707  unsigned int cbFreeCmdQueue;
711 
719  unsigned long ulTxPower;
720 
721  // Encryption
724 
725 //mike add :save old Encryption
727 
730 
731 
732  RC4Ext SBox;
735 
738 
739  unsigned int uKeyLength;
741 
742  // for AP mode
743  unsigned int uAssocCount;
745 
746  // QoS
748 
749 
751 
754 
755 
756  // For Update BaseBand VGA Gain Offset
758  unsigned int uBBVGADiffCount;
763 
766 
767 
770 
771  // For FOE Tuning
773 
774  // For Auto Power Tunning
775 
777 
778  // BaseBand Loopback Use
783 
784  // command timer
785  struct timer_list sTimerCommand;
786 
787  struct timer_list sTimerTxData;
788  unsigned long nTxDataTimeCout;
791 
792  BOOL fWPA_Authened; //is WPA/WPA-PSK or WPA2/WPA2-PSK authen??
793  BYTE byReAssocCount; //mike add:re-association retry times!
795 
796  SEthernetHeader sTxEthHeader;
797  SEthernetHeader sRxEthHeader;
801 
802  // Pre-Authentication & PMK cache
803  SPMKID gsPMKID;
805 
806 
807  // for 802.11h
809 
813 
814  //WPA supplicant daemon
815  struct net_device *wpadev;
817  struct sk_buff *skb;
818  //--
819 
820 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
826 #endif
827 
828 #ifdef HOSTAP
829  // user space daemon: hostapd, is used for HOSTAP
830  BOOL bEnableHostapd;
831  BOOL bEnable8021x;
832  BOOL bEnableHostWEP;
833  struct net_device *apdev;
834  int (*tx_80211)(struct sk_buff *skb, struct net_device *dev);
835 #endif
836  unsigned int uChannel;
837 
838  struct iw_statistics wstats; // wireless stats
840 
842 
843 
844 
845 
846 #define EnqueueRCB(_Head, _Tail, _RCB) \
847 { \
848  if (!_Head) { \
849  _Head = _RCB; \
850  } \
851  else { \
852  _Tail->Next = _RCB; \
853  } \
854  _RCB->Next = NULL; \
855  _Tail = _RCB; \
856 }
857 
858 #define DequeueRCB(Head, Tail) \
859 { \
860  PRCB RCB = Head; \
861  if (!RCB->Next) { \
862  Tail = NULL; \
863  } \
864  Head = RCB->Next; \
865 }
866 
867 
868 #define ADD_ONE_WITH_WRAP_AROUND(uVar, uModulo) { \
869  if ((uVar) >= ((uModulo) - 1)) \
870  (uVar) = 0; \
871  else \
872  (uVar)++; \
873 }
874 
875 
876 #define fMP_RESET_IN_PROGRESS 0x00000001
877 #define fMP_DISCONNECTED 0x00000002
878 #define fMP_HALT_IN_PROGRESS 0x00000004
879 #define fMP_SURPRISE_REMOVED 0x00000008
880 #define fMP_RECV_LOOKASIDE 0x00000010
881 #define fMP_INIT_IN_PROGRESS 0x00000020
882 #define fMP_SEND_SIDE_RESOURCE_ALLOCATED 0x00000040
883 #define fMP_RECV_SIDE_RESOURCE_ALLOCATED 0x00000080
884 #define fMP_POST_READS 0x00000100
885 #define fMP_POST_WRITES 0x00000200
886 #define fMP_CONTROL_READS 0x00000400
887 #define fMP_CONTROL_WRITES 0x00000800
888 
889 #define MP_SET_FLAG(_M, _F) ((_M)->Flags |= (_F))
890 #define MP_CLEAR_FLAG(_M, _F) ((_M)->Flags &= ~(_F))
891 #define MP_TEST_FLAGS(_M, _F) (((_M)->Flags & (_F)) == (_F))
892 
893 #define MP_IS_READY(_M) (((_M)->Flags & \
894  (fMP_DISCONNECTED | fMP_RESET_IN_PROGRESS | fMP_HALT_IN_PROGRESS | fMP_INIT_IN_PROGRESS | fMP_SURPRISE_REMOVED)) == 0)
895 
896 /*--------------------- Export Functions --------------------------*/
897 
898 /* BOOL device_dma0_xmit(PSDevice pDevice, struct sk_buff *skb,
899  * unsigned int uNodeIndex);
900  */
901 BOOL device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF);
902 
903 #endif