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