1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#ifndef R8180H
19#define R8180H
20
21#include <linux/interrupt.h>
22
23#define RTL8180_MODULE_NAME "r8180"
24#define DMESG(x,a...) printk(KERN_INFO RTL8180_MODULE_NAME ": " x "\n", ## a)
25#define DMESGW(x,a...) printk(KERN_WARNING RTL8180_MODULE_NAME ": WW:" x "\n", ## a)
26#define DMESGE(x,a...) printk(KERN_WARNING RTL8180_MODULE_NAME ": EE:" x "\n", ## a)
27
28#include <linux/module.h>
29#include <linux/kernel.h>
30
31#include <linux/init.h>
32#include <linux/ioport.h>
33#include <linux/sched.h>
34#include <linux/types.h>
35#include <linux/slab.h>
36#include <linux/netdevice.h>
37#include <linux/pci.h>
38#include <linux/etherdevice.h>
39#include <linux/delay.h>
40#include <linux/rtnetlink.h>
41#include <linux/wireless.h>
42#include <linux/timer.h>
43#include <linux/proc_fs.h>
44#include <linux/if_arp.h>
45#include "ieee80211/ieee80211.h"
46#include <asm/io.h>
47
48
49#define EPROM_93c46 0
50#define EPROM_93c56 1
51
52#define RTL_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30
53
54#define DEFAULT_FRAG_THRESHOLD 2342U
55#define MIN_FRAG_THRESHOLD 256U
56#define DEFAULT_RTS_THRESHOLD 2342U
57#define MIN_RTS_THRESHOLD 0U
58#define MAX_RTS_THRESHOLD 2342U
59#define DEFAULT_BEACONINTERVAL 0x64U
60
61#define DEFAULT_RETRY_RTS 7
62#define DEFAULT_RETRY_DATA 7
63
64#define BEACON_QUEUE 6
65
66#define aSifsTime 10
67
68#define sCrcLng 4
69#define sAckCtsLng 112
70
71#define RATE_ADAPTIVE_TIMER_PERIOD 300
72
73typedef enum _WIRELESS_MODE {
74 WIRELESS_MODE_UNKNOWN = 0x00,
75 WIRELESS_MODE_A = 0x01,
76 WIRELESS_MODE_B = 0x02,
77 WIRELESS_MODE_G = 0x04,
78 WIRELESS_MODE_AUTO = 0x08,
79} WIRELESS_MODE;
80
81typedef struct ChnlAccessSetting {
82 u16 SIFS_Timer;
83 u16 DIFS_Timer;
84 u16 SlotTimeTimer;
85 u16 EIFS_Timer;
86 u16 CWminIndex;
87 u16 CWmaxIndex;
88}*PCHANNEL_ACCESS_SETTING,CHANNEL_ACCESS_SETTING;
89
90typedef enum{
91 NIC_8185 = 1,
92 NIC_8185B
93 } nic_t;
94
95typedef u32 AC_CODING;
96#define AC0_BE 0
97#define AC1_BK 1
98#define AC2_VI 2
99#define AC3_VO 3
100#define AC_MAX 4
101
102
103
104
105
106typedef union _ECW{
107 u8 charData;
108 struct
109 {
110 u8 ECWmin:4;
111 u8 ECWmax:4;
112 }f;
113}ECW, *PECW;
114
115
116
117
118
119typedef union _ACI_AIFSN{
120 u8 charData;
121
122 struct
123 {
124 u8 AIFSN:4;
125 u8 ACM:1;
126 u8 ACI:2;
127 u8 Reserved:1;
128 }f;
129}ACI_AIFSN, *PACI_AIFSN;
130
131
132
133
134
135typedef union _AC_PARAM{
136 u32 longData;
137 u8 charData[4];
138
139 struct
140 {
141 ACI_AIFSN AciAifsn;
142 ECW Ecw;
143 u16 TXOPLimit;
144 }f;
145}AC_PARAM, *PAC_PARAM;
146
147
148
149
150
151
152
153
154
155
156
157
158
159typedef union _ThreeWire{
160 struct _ThreeWireStruc{
161 u16 data:1;
162 u16 clk:1;
163 u16 enableB:1;
164 u16 read_write:1;
165 u16 resv1:12;
166
167
168
169 }struc;
170 u16 longData;
171}ThreeWireReg;
172
173
174typedef struct buffer
175{
176 struct buffer *next;
177 u32 *buf;
178 dma_addr_t dma;
179} buffer;
180
181
182typedef struct Stats
183{
184 unsigned long txrdu;
185 unsigned long rxrdu;
186 unsigned long rxnolast;
187 unsigned long rxnodata;
188
189
190 unsigned long rxnopointer;
191 unsigned long txnperr;
192 unsigned long txresumed;
193 unsigned long rxerr;
194 unsigned long rxoverflow;
195 unsigned long rxint;
196 unsigned long txbkpokint;
197 unsigned long txbepoking;
198 unsigned long txbkperr;
199 unsigned long txbeperr;
200 unsigned long txnpokint;
201 unsigned long txhpokint;
202 unsigned long txhperr;
203 unsigned long ints;
204 unsigned long shints;
205 unsigned long txoverflow;
206 unsigned long rxdmafail;
207 unsigned long txbeacon;
208 unsigned long txbeaconerr;
209 unsigned long txlpokint;
210 unsigned long txlperr;
211 unsigned long txretry;
212 unsigned long rxcrcerrmin;
213 unsigned long rxcrcerrmid;
214 unsigned long rxcrcerrmax;
215 unsigned long rxicverr;
216} Stats;
217
218#define MAX_LD_SLOT_NUM 10
219#define KEEP_ALIVE_INTERVAL 20
220#define CHECK_FOR_HANG_PERIOD 2
221#define DEFAULT_KEEP_ALIVE_LEVEL 1
222#define DEFAULT_SLOT_NUM 2
223#define POWER_PROFILE_AC 0
224#define POWER_PROFILE_BATTERY 1
225
226typedef struct _link_detect_t
227{
228 u32 RxFrameNum[MAX_LD_SLOT_NUM];
229 u16 SlotNum;
230 u16 SlotIndex;
231
232 u32 NumTxOkInPeriod;
233 u32 NumRxOkInPeriod;
234
235 u8 IdleCount;
236 u32 LastNumTxUnicast;
237 u32 LastNumRxUnicast;
238
239 bool bBusyTraffic;
240}link_detect_t, *plink_detect_t;
241
242
243
244
245
246
247
248
249typedef enum _LED_STRATEGY_8185{
250 SW_LED_MODE0,
251 SW_LED_MODE1,
252 HW_LED,
253}LED_STRATEGY_8185, *PLED_STRATEGY_8185;
254
255
256typedef enum _LED_CTL_MODE{
257 LED_CTL_POWER_ON = 1,
258 LED_CTL_LINK = 2,
259 LED_CTL_NO_LINK = 3,
260 LED_CTL_TX = 4,
261 LED_CTL_RX = 5,
262 LED_CTL_SITE_SURVEY = 6,
263 LED_CTL_POWER_OFF = 7
264}LED_CTL_MODE;
265
266typedef enum _RT_RF_POWER_STATE
267{
268 eRfOn,
269 eRfSleep,
270 eRfOff
271}RT_RF_POWER_STATE;
272
273enum _ReasonCode{
274 unspec_reason = 0x1,
275 auth_not_valid = 0x2,
276 deauth_lv_ss = 0x3,
277 inactivity = 0x4,
278 ap_overload = 0x5,
279 class2_err = 0x6,
280 class3_err = 0x7,
281 disas_lv_ss = 0x8,
282 asoc_not_auth = 0x9,
283
284
285 mic_failure = 0xe,
286
287
288
289 invalid_IE = 0x0d,
290 four_way_tmout = 0x0f,
291 two_way_tmout = 0x10,
292 IE_dismatch = 0x11,
293 invalid_Gcipher = 0x12,
294 invalid_Pcipher = 0x13,
295 invalid_AKMP = 0x14,
296 unsup_RSNIEver = 0x15,
297 invalid_RSNIE = 0x16,
298 auth_802_1x_fail= 0x17,
299 ciper_reject = 0x18,
300
301
302 QoS_unspec = 0x20,
303 QAP_bandwidth = 0x21,
304 poor_condition = 0x22,
305 no_facility = 0x23,
306
307 req_declined = 0x25,
308 invalid_param = 0x26,
309 req_not_honored= 0x27,
310 TS_not_created = 0x2F,
311 DL_not_allowed = 0x30,
312 dest_not_exist = 0x31,
313 dest_not_QSTA = 0x32,
314};
315typedef enum _RT_PS_MODE
316{
317 eActive,
318 eMaxPs,
319 eFastPs
320}RT_PS_MODE;
321
322typedef struct r8180_priv
323{
324 struct pci_dev *pdev;
325
326 short epromtype;
327 int irq;
328 struct ieee80211_device *ieee80211;
329
330 short phy_ver;
331 short enable_gpio0;
332 short hw_plcp_len;
333 short plcp_preamble_mode;
334
335 spinlock_t irq_lock;
336 spinlock_t irq_th_lock;
337 spinlock_t tx_lock;
338 spinlock_t ps_lock;
339 spinlock_t rf_ps_lock;
340
341 u16 irq_mask;
342 short irq_enabled;
343 struct net_device *dev;
344 short chan;
345 short sens;
346 short max_sens;
347 u8 chtxpwr[15];
348 u8 chtxpwr_ofdm[15];
349
350 u8 channel_plan;
351 short up;
352 short crcmon;
353 short prism_hdr;
354
355 struct timer_list scan_timer;
356
357
358 spinlock_t scan_lock;
359 u8 active_probe;
360
361 struct semaphore wx_sem;
362 struct semaphore rf_state;
363 short hw_wep;
364
365 short digphy;
366 short antb;
367 short diversity;
368 u8 cs_treshold;
369 short rcr_csense;
370 u32 key0[4];
371 short (*rf_set_sens)(struct net_device *dev,short sens);
372 void (*rf_set_chan)(struct net_device *dev,short ch);
373 void (*rf_close)(struct net_device *dev);
374 void (*rf_init)(struct net_device *dev);
375 void (*rf_sleep)(struct net_device *dev);
376 void (*rf_wakeup)(struct net_device *dev);
377
378 short promisc;
379
380 struct Stats stats;
381 struct _link_detect_t link_detect;
382 struct iw_statistics wstats;
383 struct proc_dir_entry *dir_dev;
384
385
386 u32 *rxring;
387 u32 *rxringtail;
388 dma_addr_t rxringdma;
389 struct buffer *rxbuffer;
390 struct buffer *rxbufferhead;
391 int rxringcount;
392 u16 rxbuffersize;
393
394 struct sk_buff *rx_skb;
395
396 short rx_skb_complete;
397
398 u32 rx_prevlen;
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421 u32 *txmapring;
422 u32 *txbkpring;
423 u32 *txbepring;
424 u32 *txvipring;
425 u32 *txvopring;
426 u32 *txhpring;
427 dma_addr_t txmapringdma;
428 dma_addr_t txbkpringdma;
429 dma_addr_t txbepringdma;
430 dma_addr_t txvipringdma;
431 dma_addr_t txvopringdma;
432 dma_addr_t txhpringdma;
433 u32 *txmapringtail;
434 u32 *txbkpringtail;
435 u32 *txbepringtail;
436 u32 *txvipringtail;
437 u32 *txvopringtail;
438 u32 *txhpringtail;
439 u32 *txmapringhead;
440 u32 *txbkpringhead;
441 u32 *txbepringhead;
442 u32 *txvipringhead;
443 u32 *txvopringhead;
444 u32 *txhpringhead;
445 struct buffer *txmapbufs;
446 struct buffer *txbkpbufs;
447 struct buffer *txbepbufs;
448 struct buffer *txvipbufs;
449 struct buffer *txvopbufs;
450 struct buffer *txhpbufs;
451 struct buffer *txmapbufstail;
452 struct buffer *txbkpbufstail;
453 struct buffer *txbepbufstail;
454 struct buffer *txvipbufstail;
455 struct buffer *txvopbufstail;
456 struct buffer *txhpbufstail;
457
458 int txringcount;
459 int txbuffsize;
460
461
462 struct tasklet_struct irq_rx_tasklet;
463 u8 dma_poll_mask;
464
465
466
467 u32 *txbeaconringtail;
468 dma_addr_t txbeaconringdma;
469 u32 *txbeaconring;
470 int txbeaconcount;
471 struct buffer *txbeaconbufs;
472 struct buffer *txbeaconbufstail;
473
474
475
476
477
478 u8 retry_data;
479 u8 retry_rts;
480 u16 rts;
481
482
483 LED_STRATEGY_8185 LedStrategy;
484
485
486
487 struct timer_list watch_dog_timer;
488 bool bInactivePs;
489 bool bSwRfProcessing;
490 RT_RF_POWER_STATE eInactivePowerState;
491 RT_RF_POWER_STATE eRFPowerState;
492 u32 RfOffReason;
493 bool RFChangeInProgress;
494 bool bInHctTest;
495 bool SetRFPowerStateInProgress;
496 u8 RFProgType;
497 bool bLeisurePs;
498 RT_PS_MODE dot11PowerSaveMode;
499
500
501 u8 TxPollingTimes;
502
503 bool bApBufOurFrame;
504 u8 WaitBufDataBcnCount;
505 u8 WaitBufDataTimeOut;
506
507
508
509 u8 EEPROMSwAntennaDiversity;
510 bool EEPROMDefaultAntenna1;
511 u8 RegSwAntennaDiversityMechanism;
512 bool bSwAntennaDiverity;
513 u8 RegDefaultAntenna;
514 bool bDefaultAntenna1;
515 u8 SignalStrength;
516 long Stats_SignalStrength;
517 long LastSignalStrengthInPercent;
518 u8 SignalQuality;
519 long Stats_SignalQuality;
520 long RecvSignalPower;
521 long Stats_RecvSignalPower;
522 u8 LastRxPktAntenna;
523 u32 AdRxOkCnt;
524 long AdRxSignalStrength;
525 u8 CurrAntennaIndex;
526 u8 AdTickCount;
527 u8 AdCheckPeriod;
528 u8 AdMinCheckPeriod;
529 u8 AdMaxCheckPeriod;
530 long AdRxSsThreshold;
531 long AdMaxRxSsThreshold;
532 bool bAdSwitchedChecking;
533 long AdRxSsBeforeSwitched;
534 struct timer_list SwAntennaDiversityTimer;
535
536
537
538
539
540
541 bool bXtalCalibration;
542 u8 XtalCal_Xin;
543 u8 XtalCal_Xout;
544
545
546
547
548 bool bTxPowerTrack;
549 u8 ThermalMeter;
550
551
552
553 bool bDigMechanism;
554 bool bRegHighPowerMechanism;
555 u32 FalseAlarmRegValue;
556 u8 RegDigOfdmFaUpTh;
557 u8 DIG_NumberFallbackVote;
558 u8 DIG_NumberUpgradeVote;
559
560 u32 AdMainAntennaRxOkCnt;
561 u32 AdAuxAntennaRxOkCnt;
562 bool bHWAdSwitched;
563
564 u8 RegHiPwrUpperTh;
565 u8 RegHiPwrLowerTh;
566
567 u8 RegRSSIHiPwrUpperTh;
568 u8 RegRSSIHiPwrLowerTh;
569
570 u8 CurCCKRSSI;
571 bool bCurCCKPkt;
572
573
574
575 bool bToUpdateTxPwr;
576 long UndecoratedSmoothedSS;
577 long UndercorateSmoothedRxPower;
578 u8 RSSI;
579 char RxPower;
580 u8 InitialGain;
581
582 u32 DozePeriodInPast2Sec;
583
584 u8 InitialGainBackUp;
585 u8 RegBModeGainStage;
586
587 struct timer_list rateadapter_timer;
588 u32 RateAdaptivePeriod;
589 bool bEnhanceTxPwr;
590 bool bUpdateARFR;
591 int ForcedDataRate;
592 u32 NumTxUnicast;
593 u8 keepAliveLevel;
594 unsigned long NumTxOkTotal;
595 u16 LastRetryCnt;
596 u16 LastRetryRate;
597 unsigned long LastTxokCnt;
598 unsigned long LastRxokCnt;
599 u16 CurrRetryCnt;
600 unsigned long LastTxOKBytes;
601 unsigned long NumTxOkBytesTotal;
602 u8 LastFailTxRate;
603 long LastFailTxRateSS;
604 u8 FailTxRateCount;
605 u32 LastTxThroughput;
606
607 unsigned short bTryuping;
608 u8 CurrTxRate;
609 u16 CurrRetryRate;
610 u16 TryupingCount;
611 u8 TryDownCountLowData;
612 u8 TryupingCountNoData;
613
614 u8 CurrentOperaRate;
615
616
617
618
619 struct work_struct reset_wq;
620 struct work_struct watch_dog_wq;
621 struct work_struct tx_irq_wq;
622 short ack_tx_to_ieee;
623
624 u8 PowerProfile;
625 u32 CSMethod;
626 u8 cck_txpwr_base;
627 u8 ofdm_txpwr_base;
628 u8 dma_poll_stop_mask;
629
630
631 u8 MWIEnable;
632 u16 ShortRetryLimit;
633 u16 LongRetryLimit;
634 u16 EarlyRxThreshold;
635 u32 TransmitConfig;
636 u32 ReceiveConfig;
637 u32 IntrMask;
638
639 struct ChnlAccessSetting ChannelAccessSetting;
640}r8180_priv;
641
642#define MANAGE_PRIORITY 0
643#define BK_PRIORITY 1
644#define BE_PRIORITY 2
645#define VI_PRIORITY 3
646#define VO_PRIORITY 4
647#define HI_PRIORITY 5
648#define BEACON_PRIORITY 6
649
650#define LOW_PRIORITY VI_PRIORITY
651#define NORM_PRIORITY VO_PRIORITY
652
653#define AC2Q(_ac) (((_ac) == WME_AC_VO) ? VO_PRIORITY : \
654 ((_ac) == WME_AC_VI) ? VI_PRIORITY : \
655 ((_ac) == WME_AC_BK) ? BK_PRIORITY : \
656 BE_PRIORITY)
657
658short rtl8180_tx(struct net_device *dev,u8* skbuf, int len,int priority,
659 short morefrag,short fragdesc,int rate);
660
661u8 read_nic_byte(struct net_device *dev, int x);
662u32 read_nic_dword(struct net_device *dev, int x);
663u16 read_nic_word(struct net_device *dev, int x) ;
664void write_nic_byte(struct net_device *dev, int x,u8 y);
665void write_nic_word(struct net_device *dev, int x,u16 y);
666void write_nic_dword(struct net_device *dev, int x,u32 y);
667void force_pci_posting(struct net_device *dev);
668
669void rtl8180_rtx_disable(struct net_device *);
670void rtl8180_rx_enable(struct net_device *);
671void rtl8180_tx_enable(struct net_device *);
672void rtl8180_start_scanning(struct net_device *dev);
673void rtl8180_start_scanning_s(struct net_device *dev);
674void rtl8180_stop_scanning(struct net_device *dev);
675void rtl8180_disassociate(struct net_device *dev);
676
677void rtl8180_set_anaparam(struct net_device *dev,u32 a);
678void rtl8185_set_anaparam2(struct net_device *dev,u32 a);
679void rtl8180_set_hw_wep(struct net_device *dev);
680void rtl8180_no_hw_wep(struct net_device *dev);
681void rtl8180_update_msr(struct net_device *dev);
682
683void rtl8180_beacon_tx_disable(struct net_device *dev);
684void rtl8180_beacon_rx_disable(struct net_device *dev);
685void rtl8180_conttx_enable(struct net_device *dev);
686void rtl8180_conttx_disable(struct net_device *dev);
687int rtl8180_down(struct net_device *dev);
688int rtl8180_up(struct net_device *dev);
689void rtl8180_commit(struct net_device *dev);
690void rtl8180_set_chan(struct net_device *dev,short ch);
691void rtl8180_set_master_essid(struct net_device *dev,char *essid);
692void rtl8180_update_beacon_security(struct net_device *dev);
693void write_phy(struct net_device *dev, u8 adr, u8 data);
694void write_phy_cck(struct net_device *dev, u8 adr, u32 data);
695void write_phy_ofdm(struct net_device *dev, u8 adr, u32 data);
696void rtl8185_tx_antenna(struct net_device *dev, u8 ant);
697void rtl8185_rf_pins_enable(struct net_device *dev);
698void IBSS_randomize_cell(struct net_device *dev);
699void IPSEnter(struct net_device *dev);
700void IPSLeave(struct net_device *dev);
701int get_curr_tx_free_desc(struct net_device *dev, int priority);
702void UpdateInitialGain(struct net_device *dev);
703bool SetAntennaConfig87SE(struct net_device *dev, u8 DefaultAnt, bool bAntDiversity);
704
705
706void rtl8185b_adapter_start(struct net_device *dev);
707void rtl8185b_rx_enable(struct net_device *dev);
708void rtl8185b_tx_enable(struct net_device *dev);
709void rtl8180_reset(struct net_device *dev);
710void rtl8185b_irq_enable(struct net_device *dev);
711void fix_rx_fifo(struct net_device *dev);
712void fix_tx_fifo(struct net_device *dev);
713void rtl8225z2_SetTXPowerLevel(struct net_device *dev, short ch);
714void rtl8180_rate_adapter(struct work_struct * work);
715
716bool MgntActSet_RF_State(struct net_device *dev, RT_RF_POWER_STATE StateToSet, u32 ChangeSource);
717
718#endif
719