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