2 * This is part of rtl8187 OpenSource driver.
3 * Copyright (C) Andrea Merello 2004-2005 <andrea.merello@gmail.com>
4 * Released under the terms of GPL (General Public Licence)
6 * Parts of this driver are based on the GPL part of the
7 * official realtek driver
9 * Parts of this driver are based on the rtl8192 driver skeleton
10 * from Patric Schenke & Andres Salomon
12 * Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver
14 * We want to thank the Authors of those projects and the Ndiswrapper
21 #include <linux/module.h>
22 #include <linux/kernel.h>
23 #include <linux/init.h>
24 #include <linux/ioport.h>
25 #include <linux/sched.h>
26 #include <linux/types.h>
27 #include <linux/slab.h>
28 #include <linux/netdevice.h>
29 #include <linux/usb.h>
30 #include <linux/etherdevice.h>
31 #include <linux/delay.h>
32 #include <linux/rtnetlink.h>
33 #include <linux/wireless.h>
34 #include <linux/timer.h>
35 #include <linux/proc_fs.h>
36 #include <linux/if_arp.h>
37 #include <linux/random.h>
39 #include "ieee80211/ieee80211.h"
42 #define RTL819xU_MODULE_NAME "rtl819xU"
46 #define MAX_KEY_LEN 61
47 #define KEY_BUF_SIZE 5
49 #define BIT0 0x00000001
50 #define BIT1 0x00000002
51 #define BIT2 0x00000004
52 #define BIT3 0x00000008
53 #define BIT4 0x00000010
54 #define BIT5 0x00000020
55 #define BIT6 0x00000040
56 #define BIT7 0x00000080
57 #define BIT8 0x00000100
58 #define BIT9 0x00000200
59 #define BIT10 0x00000400
60 #define BIT11 0x00000800
61 #define BIT12 0x00001000
62 #define BIT13 0x00002000
63 #define BIT14 0x00004000
64 #define BIT15 0x00008000
65 #define BIT16 0x00010000
66 #define BIT17 0x00020000
67 #define BIT18 0x00040000
68 #define BIT19 0x00080000
69 #define BIT20 0x00100000
70 #define BIT21 0x00200000
71 #define BIT22 0x00400000
72 #define BIT23 0x00800000
73 #define BIT24 0x01000000
74 #define BIT25 0x02000000
75 #define BIT26 0x04000000
76 #define BIT27 0x08000000
77 #define BIT28 0x10000000
78 #define BIT29 0x20000000
79 #define BIT30 0x40000000
80 #define BIT31 0x80000000
82 #define Rx_Smooth_Factor 20
83 #define DMESG(x, a...)
84 #define DMESGW(x, a...)
85 #define DMESGE(x, a...)
86 extern u32 rt_global_debug_component;
87 #define RT_TRACE(component, x, args...) \
89 if (rt_global_debug_component & component) \
90 pr_debug("RTL8192U: " x "\n", ##args); \
93 #define COMP_TRACE BIT0 /* Function call tracing. */
95 #define COMP_INIT BIT2 /* Driver initialization/halt/reset. */
98 #define COMP_RECV BIT3 /* Receive data path. */
99 #define COMP_SEND BIT4 /* Send data path. */
101 /* 802.11 Power Save mode or System/Device Power state. */
102 #define COMP_POWER BIT6
103 /* 802.11 link related: join/start BSS, leave BSS. */
104 #define COMP_EPROM BIT7
105 #define COMP_SWBW BIT8 /* Bandwidth switch. */
106 #define COMP_POWER_TRACKING BIT9 /* 8190 TX Power Tracking */
107 #define COMP_TURBO BIT10 /* Turbo Mode */
108 #define COMP_QOS BIT11
109 #define COMP_RATE BIT12 /* Rate Adaptive mechanism */
110 #define COMP_RM BIT13 /* Radio Measurement */
111 #define COMP_DIG BIT14
112 #define COMP_PHY BIT15
113 #define COMP_CH BIT16 /* Channel setting debug */
114 #define COMP_TXAGC BIT17 /* Tx power */
115 #define COMP_HIPWR BIT18 /* High Power Mechanism */
116 #define COMP_HALDM BIT19 /* HW Dynamic Mechanism */
117 #define COMP_SEC BIT20 /* Event handling */
118 #define COMP_LED BIT21
119 #define COMP_RF BIT22
120 #define COMP_RXDESC BIT23 /* Rx desc information for SD3 debug */
122 /* 11n or 8190 specific code */
124 #define COMP_FIRMWARE BIT24 /* Firmware downloading */
125 #define COMP_HT BIT25 /* 802.11n HT related information */
126 #define COMP_AMSDU BIT26 /* A-MSDU Debugging */
127 #define COMP_SCAN BIT27
128 #define COMP_DOWN BIT29 /* rm driver module */
129 #define COMP_RESET BIT30 /* Silent reset */
130 #define COMP_ERR BIT31 /* Error out, always on */
132 #define RTL819x_DEBUG
134 #define RTL8192U_ASSERT(expr) \
137 pr_debug("Assertion failed! %s, %s, %s, line = %d\n", \
138 #expr, __FILE__, __func__, __LINE__); \
142 * Debug out data buf.
143 * If you want to print DATA buffer related BA,
144 * please set ieee80211_debug_level to DATA|BA
146 #define RT_DEBUG_DATA(level, data, datalen) \
148 if ((rt_global_debug_component & (level)) == (level)) { \
150 u8 *pdata = (u8 *) data; \
151 pr_debug("RTL8192U: %s()\n", __func__); \
152 for (i = 0; i < (int)(datalen); i++) { \
153 printk("%2x ", pdata[i]); \
161 #define RTL8192U_ASSERT(expr) do {} while (0)
162 #define RT_DEBUG_DATA(level, data, datalen) do {} while (0)
163 #endif /* RTL8169_DEBUG */
166 /* Queue Select Value in TxDesc */
171 #define QSLT_BEACON 0x10
172 #define QSLT_HIGH 0x11
173 #define QSLT_MGNT 0x12
174 #define QSLT_CMD 0x13
176 #define DESC90_RATE1M 0x00
177 #define DESC90_RATE2M 0x01
178 #define DESC90_RATE5_5M 0x02
179 #define DESC90_RATE11M 0x03
180 #define DESC90_RATE6M 0x04
181 #define DESC90_RATE9M 0x05
182 #define DESC90_RATE12M 0x06
183 #define DESC90_RATE18M 0x07
184 #define DESC90_RATE24M 0x08
185 #define DESC90_RATE36M 0x09
186 #define DESC90_RATE48M 0x0a
187 #define DESC90_RATE54M 0x0b
188 #define DESC90_RATEMCS0 0x00
189 #define DESC90_RATEMCS1 0x01
190 #define DESC90_RATEMCS2 0x02
191 #define DESC90_RATEMCS3 0x03
192 #define DESC90_RATEMCS4 0x04
193 #define DESC90_RATEMCS5 0x05
194 #define DESC90_RATEMCS6 0x06
195 #define DESC90_RATEMCS7 0x07
196 #define DESC90_RATEMCS8 0x08
197 #define DESC90_RATEMCS9 0x09
198 #define DESC90_RATEMCS10 0x0a
199 #define DESC90_RATEMCS11 0x0b
200 #define DESC90_RATEMCS12 0x0c
201 #define DESC90_RATEMCS13 0x0d
202 #define DESC90_RATEMCS14 0x0e
203 #define DESC90_RATEMCS15 0x0f
204 #define DESC90_RATEMCS32 0x20
206 #define RTL819X_DEFAULT_RF_TYPE RF_1T2R
208 #define IEEE80211_WATCH_DOG_TIME 2000
209 #define PHY_Beacon_RSSI_SLID_WIN_MAX 10
210 /* For Tx Power Tracking */
211 #define OFDM_Table_Length 19
212 #define CCK_Table_length 12
215 typedef struct _tx_desc_819x_usb {
243 u8 ResvForPaddingLen:7;
251 } tx_desc_819x_usb, *ptx_desc_819x_usb;
253 #ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
254 typedef struct _tx_desc_819x_usb_aggr_subframe {
275 } tx_desc_819x_usb_aggr_subframe, *ptx_desc_819x_usb_aggr_subframe;
280 typedef struct _tx_desc_cmd_819x_usb {
305 } tx_desc_cmd_819x_usb, *ptx_desc_cmd_819x_usb;
308 typedef struct _tx_fwinfo_819x_usb {
315 u8 Short:1; /* Error out, always on */
316 u8 TxBandwidth:1; /* Used for HT MCS rate only */
317 u8 TxSubCarrier:2; /* Used for legacy OFDM rate only */
319 u8 AllowAggregation:1;
320 /* Interpret RtsRate field as high throughput data rate */
322 u8 RtsShort:1; /* Short PLCP for CCK or short GI for 11n MCS */
323 u8 RtsBandwidth:1; /* Used for HT MCS rate only */
324 u8 RtsSubcarrier:2;/* Used for legacy OFDM rate only */
326 /* Enable firmware to recalculate and assign packet duration */
332 /* 1 indicate Tx info gathered by firmware and returned by Rx Cmd */
333 u32 TxPerPktInfoFeedback:1;
339 } tx_fwinfo_819x_usb, *ptx_fwinfo_819x_usb;
341 typedef struct rtl8192_rx_info {
343 struct net_device *dev;
347 typedef struct rx_desc_819x_usb {
360 } rx_desc_819x_usb, *prx_desc_819x_usb;
362 #ifdef USB_RX_AGGREGATION_SUPPORT
363 typedef struct _rx_desc_819x_usb_aggr_subframe {
377 } rx_desc_819x_usb_aggr_subframe, *prx_desc_819x_usb_aggr_subframe;
380 typedef struct rx_drvinfo_819x_usb {
401 } rx_drvinfo_819x_usb, *prx_drvinfo_819x_usb;
403 /* Support till 64 bit bus width OS */
404 #define MAX_DEV_ADDR_SIZE 8
406 #define MAX_FIRMWARE_INFORMATION_SIZE 32
407 #define MAX_802_11_HEADER_LENGTH (40 + MAX_FIRMWARE_INFORMATION_SIZE)
408 #define ENCRYPTION_MAX_OVERHEAD 128
409 #define USB_HWDESC_HEADER_LEN sizeof(tx_desc_819x_usb)
410 #define TX_PACKET_SHIFT_BYTES (USB_HWDESC_HEADER_LEN + sizeof(tx_fwinfo_819x_usb))
411 #define MAX_FRAGMENT_COUNT 8
412 #ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
413 #define MAX_TRANSMIT_BUFFER_SIZE 32000
415 #define MAX_TRANSMIT_BUFFER_SIZE 8000
417 #ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
418 #define TX_PACKET_DRVAGGR_SUBFRAME_SHIFT_BYTES (sizeof(tx_desc_819x_usb_aggr_subframe) + sizeof(tx_fwinfo_819x_usb))
420 /* Octets for crc32 (FCS, ICV) */
423 typedef enum rf_optype {
424 RF_OP_By_SW_3wire = 0,
428 /* 8190 Loopback Mode definition */
429 typedef enum _rtl819xUsb_loopback {
430 RTL819xU_NO_LOOPBACK = 0,
431 RTL819xU_MAC_LOOPBACK = 1,
432 RTL819xU_DMA_LOOPBACK = 2,
433 RTL819xU_CCK_LOOPBACK = 3,
434 } rtl819xUsb_loopback_e;
436 /* due to rtl8192 firmware */
437 typedef enum _desc_packet_type_e {
438 DESC_PACKET_TYPE_INIT = 0,
439 DESC_PACKET_TYPE_NORMAL = 1,
440 } desc_packet_type_e;
442 typedef enum _firmware_status {
443 FW_STATUS_0_INIT = 0,
444 FW_STATUS_1_MOVE_BOOT_CODE = 1,
445 FW_STATUS_2_MOVE_MAIN_CODE = 2,
446 FW_STATUS_3_TURNON_CPU = 3,
447 FW_STATUS_4_MOVE_DATA_CODE = 4,
448 FW_STATUS_5_READY = 5,
451 typedef struct _rt_firmare_seg_container {
454 } fw_seg_container, *pfw_seg_container;
455 typedef struct _rt_firmware {
456 firmware_status_e firmware_status;
457 u16 cmdpacket_frag_thresold;
458 #define RTL8190_MAX_FIRMWARE_CODE_SIZE 64000
459 u8 firmware_buf[RTL8190_MAX_FIRMWARE_CODE_SIZE];
460 u16 firmware_buf_size;
461 } rt_firmware, *prt_firmware;
463 /* Add this to 9100 bytes to receive A-MSDU from RT-AP */
464 #define MAX_RECEIVE_BUFFER_SIZE 9100
466 typedef struct _rt_firmware_info_819xUsb {
468 } rt_firmware_info_819xUsb, *prt_firmware_info_819xUsb;
470 /* Firmware Queue Layout */
471 #define NUM_OF_FIRMWARE_QUEUE 10
472 #define NUM_OF_PAGES_IN_FW 0x100
475 #define NUM_OF_PAGE_IN_FW_QUEUE_BE 0x000
476 #define NUM_OF_PAGE_IN_FW_QUEUE_BK 0x000
477 #define NUM_OF_PAGE_IN_FW_QUEUE_VI 0x0ff
478 #define NUM_OF_PAGE_IN_FW_QUEUE_VO 0x000
479 #define NUM_OF_PAGE_IN_FW_QUEUE_HCCA 0
480 #define NUM_OF_PAGE_IN_FW_QUEUE_CMD 0x0
481 #define NUM_OF_PAGE_IN_FW_QUEUE_MGNT 0x00
482 #define NUM_OF_PAGE_IN_FW_QUEUE_HIGH 0
483 #define NUM_OF_PAGE_IN_FW_QUEUE_BCN 0x0
484 #define NUM_OF_PAGE_IN_FW_QUEUE_PUB 0x00
487 #define NUM_OF_PAGE_IN_FW_QUEUE_BE 0x020
488 #define NUM_OF_PAGE_IN_FW_QUEUE_BK 0x020
489 #define NUM_OF_PAGE_IN_FW_QUEUE_VI 0x040
490 #define NUM_OF_PAGE_IN_FW_QUEUE_VO 0x040
491 #define NUM_OF_PAGE_IN_FW_QUEUE_HCCA 0
492 #define NUM_OF_PAGE_IN_FW_QUEUE_CMD 0x4
493 #define NUM_OF_PAGE_IN_FW_QUEUE_MGNT 0x20
494 #define NUM_OF_PAGE_IN_FW_QUEUE_HIGH 0
495 #define NUM_OF_PAGE_IN_FW_QUEUE_BCN 0x4
496 #define NUM_OF_PAGE_IN_FW_QUEUE_PUB 0x18
500 #define APPLIED_RESERVED_QUEUE_IN_FW 0x80000000
501 #define RSVD_FW_QUEUE_PAGE_BK_SHIFT 0x00
502 #define RSVD_FW_QUEUE_PAGE_BE_SHIFT 0x08
503 #define RSVD_FW_QUEUE_PAGE_VI_SHIFT 0x10
504 #define RSVD_FW_QUEUE_PAGE_VO_SHIFT 0x18
505 #define RSVD_FW_QUEUE_PAGE_MGNT_SHIFT 0x10
506 #define RSVD_FW_QUEUE_PAGE_CMD_SHIFT 0x08
507 #define RSVD_FW_QUEUE_PAGE_BCN_SHIFT 0x00
508 #define RSVD_FW_QUEUE_PAGE_PUB_SHIFT 0x08
511 * =================================================================
512 * =================================================================
515 #define EPROM_93c46 0
516 #define EPROM_93c56 1
518 #define DEFAULT_FRAG_THRESHOLD 2342U
519 #define MIN_FRAG_THRESHOLD 256U
520 #define DEFAULT_BEACONINTERVAL 0x64U
521 #define DEFAULT_BEACON_ESSID "Rtl819xU"
523 #define DEFAULT_SSID ""
524 #define DEFAULT_RETRY_RTS 7
525 #define DEFAULT_RETRY_DATA 7
526 #define PRISM_HDR_SIZE 64
528 #define PHY_RSSI_SLID_WIN_MAX 100
531 typedef enum _WIRELESS_MODE {
532 WIRELESS_MODE_UNKNOWN = 0x00,
533 WIRELESS_MODE_A = 0x01,
534 WIRELESS_MODE_B = 0x02,
535 WIRELESS_MODE_G = 0x04,
536 WIRELESS_MODE_AUTO = 0x08,
537 WIRELESS_MODE_N_24G = 0x10,
538 WIRELESS_MODE_N_5G = 0x20
542 #define RTL_IOCTL_WPA_SUPPLICANT (SIOCIWFIRSTPRIV + 30)
544 typedef struct buffer {
550 typedef struct rtl_reg_debug {
556 unsigned char length;
558 unsigned char buf[0xff];
566 typedef struct _rt_9x_tx_rate_history {
570 } rt_tx_rahis_t, *prt_tx_rahis_t;
571 typedef struct _RT_SMOOTH_DATA_4RF {
572 char elements[4][100]; /* array to store values */
573 u32 index; /* index to current array to store */
574 u32 TotalNum; /* num of valid elements */
575 u32 TotalVal[4]; /* sum of valid elements */
576 } RT_SMOOTH_DATA_4RF, *PRT_SMOOTH_DATA_4RF;
578 /* This maybe changed for D-cut larger aggregation size */
579 #define MAX_8192U_RX_SIZE 8192
580 /* Stats seems messed up, clean it ASAP */
581 typedef struct Stats {
584 unsigned long rxframgment;
585 unsigned long rxurberr;
586 unsigned long rxstaterr;
587 /* 0: Total, 1: OK, 2: CRC, 3: ICV */
588 unsigned long received_rate_histogram[4][32];
589 /* 0: Long preamble/GI, 1: Short preamble/GI */
590 unsigned long received_preamble_GI[2][32];
591 /* level: (<4K), (4K~8K), (8K~16K), (16K~32K), (32K~64K) */
592 unsigned long rx_AMPDUsize_histogram[5];
593 /* level: (<5), (5~10), (10~20), (20~40), (>40) */
594 unsigned long rx_AMPDUnum_histogram[5];
595 unsigned long numpacket_matchbssid;
596 unsigned long numpacket_toself;
597 unsigned long num_process_phyinfo;
598 unsigned long numqry_phystatus;
599 unsigned long numqry_phystatusCCK;
600 unsigned long numqry_phystatusHT;
601 /* 0: 20M, 1: funn40M, 2: upper20M, 3: lower20M, 4: duplicate */
602 unsigned long received_bwtype[5];
603 unsigned long txnperr;
604 unsigned long txnpdrop;
605 unsigned long txresumed;
606 unsigned long txnpokint;
607 unsigned long txoverflow;
608 unsigned long txlpokint;
609 unsigned long txlpdrop;
610 unsigned long txlperr;
611 unsigned long txbeokint;
612 unsigned long txbedrop;
613 unsigned long txbeerr;
614 unsigned long txbkokint;
615 unsigned long txbkdrop;
616 unsigned long txbkerr;
617 unsigned long txviokint;
618 unsigned long txvidrop;
619 unsigned long txvierr;
620 unsigned long txvookint;
621 unsigned long txvodrop;
622 unsigned long txvoerr;
623 unsigned long txbeaconokint;
624 unsigned long txbeacondrop;
625 unsigned long txbeaconerr;
626 unsigned long txmanageokint;
627 unsigned long txmanagedrop;
628 unsigned long txmanageerr;
629 unsigned long txdatapkt;
630 unsigned long txfeedback;
631 unsigned long txfeedbackok;
633 unsigned long txoktotal;
634 unsigned long txokbytestotal;
635 unsigned long txokinperiod;
636 unsigned long txmulticast;
637 unsigned long txbytesmulticast;
638 unsigned long txbroadcast;
639 unsigned long txbytesbroadcast;
640 unsigned long txunicast;
641 unsigned long txbytesunicast;
643 unsigned long rxoktotal;
644 unsigned long rxbytesunicast;
645 unsigned long txfeedbackfail;
646 unsigned long txerrtotal;
647 unsigned long txerrbytestotal;
648 unsigned long txerrmulticast;
649 unsigned long txerrbroadcast;
650 unsigned long txerrunicast;
651 unsigned long txretrycount;
652 unsigned long txfeedbackretry;
654 unsigned long slide_signal_strength[100];
655 unsigned long slide_evm[100];
656 /* For recording sliding window's RSSI value */
657 unsigned long slide_rssi_total;
658 /* For recording sliding window's EVM value */
659 unsigned long slide_evm_total;
660 /* Transformed in dbm. Beautified signal strength for UI, not correct */
661 long signal_strength;
663 long last_signal_strength_inpercent;
664 /* Correct smoothed ss in dbm, only used in driver
665 * to report real power now */
666 long recv_signal_power;
667 u8 rx_rssi_percentage[4];
668 u8 rx_evm_percentage[2];
670 rt_tx_rahis_t txrate;
671 /* For beacon RSSI */
672 u32 Slide_Beacon_pwdb[100];
673 u32 Slide_Beacon_Total;
674 RT_SMOOTH_DATA_4RF cck_adc_pwdb;
676 u32 CurrentShowTxate;
680 /* Bandwidth Offset */
681 #define HAL_PRIME_CHNL_OFFSET_DONT_CARE 0
682 #define HAL_PRIME_CHNL_OFFSET_LOWER 1
683 #define HAL_PRIME_CHNL_OFFSET_UPPER 2
686 typedef struct ChnlAccessSetting {
693 } *PCHANNEL_ACCESS_SETTING, CHANNEL_ACCESS_SETTING;
695 typedef struct _BB_REGISTER_DEFINITION {
696 /* set software control: 0x870~0x877 [8 bytes] */
698 /* readback data: 0x8e0~0x8e7 [8 bytes] */
700 /* output data: 0x860~0x86f [16 bytes] */
702 /* output enable: 0x860~0x86f [16 bytes] */
704 /* LSSI data: 0x840~0x84f [16 bytes] */
706 /* BB Band Select: 0x878~0x87f [8 bytes] */
708 /* Tx gain stage: 0x80c~0x80f [4 bytes] */
710 /* wire parameter control1: 0x820~0x823, 0x828~0x82b,
711 * 0x830~0x833, 0x838~0x83b [16 bytes] */
713 /* wire parameter control2: 0x824~0x827, 0x82c~0x82f,
714 * 0x834~0x837, 0x83c~0x83f [16 bytes] */
716 /* Tx Rx antenna control: 0x858~0x85f [16 bytes] */
718 /* AGC parameter control1: 0xc50~0xc53, 0xc58~0xc5b,
719 * 0xc60~0xc63, 0xc68~0xc6b [16 bytes] */
721 /* AGC parameter control2: 0xc54~0xc57, 0xc5c~0xc5f,
722 * 0xc64~0xc67, 0xc6c~0xc6f [16 bytes] */
724 /* OFDM Rx IQ imbalance matrix: 0xc14~0xc17, 0xc1c~0xc1f,
725 * 0xc24~0xc27, 0xc2c~0xc2f [16 bytes] */
727 /* Rx IQ DC offset and Rx digital filter, Rx DC notch filter:
728 * 0xc10~0xc13, 0xc18~0xc1b,
729 * 0xc20~0xc23, 0xc28~0xc2b [16 bytes] */
731 /* OFDM Tx IQ imbalance matrix: 0xc80~0xc83, 0xc88~0xc8b,
732 * 0xc90~0xc93, 0xc98~0xc9b [16 bytes] */
734 /* Tx IQ DC Offset and Tx DFIR type:
735 * 0xc84~0xc87, 0xc8c~0xc8f,
736 * 0xc94~0xc97, 0xc9c~0xc9f [16 bytes] */
738 /* LSSI RF readback data: 0x8a0~0x8af [16 bytes] */
740 } BB_REGISTER_DEFINITION_T, *PBB_REGISTER_DEFINITION_T;
742 typedef enum _RT_RF_TYPE_819xU {
748 } RT_RF_TYPE_819xU, *PRT_RF_TYPE_819xU;
750 typedef struct _rate_adaptive {
751 u8 rate_adaptive_disabled;
755 u32 high_rssi_thresh_for_ra;
756 u32 high2low_rssi_thresh_for_ra;
757 u8 low2high_rssi_thresh_for_ra40M;
758 u32 low_rssi_thresh_for_ra40M;
759 u8 low2high_rssi_thresh_for_ra20M;
760 u32 low_rssi_thresh_for_ra20M;
761 u32 upper_rssi_threshold_ratr;
762 u32 middle_rssi_threshold_ratr;
763 u32 low_rssi_threshold_ratr;
764 u32 low_rssi_threshold_ratr_40M;
765 u32 low_rssi_threshold_ratr_20M;
768 u32 ping_rssi_thresh_for_ra;
771 } rate_adaptive, *prate_adaptive;
773 #define TxBBGainTableLength 37
774 #define CCKTxBBGainTableLength 23
776 typedef struct _txbbgain_struct {
777 long txbb_iq_amplifygain;
779 } txbbgain_struct, *ptxbbgain_struct;
781 typedef struct _ccktxbbgain_struct {
782 /* The value is from a22 to a29, one byte one time is much safer */
783 u8 ccktxbb_valuearray[8];
784 } ccktxbbgain_struct, *pccktxbbgain_struct;
787 typedef struct _init_gain {
794 } init_gain, *pinit_gain;
796 typedef struct _phy_ofdm_rx_status_report_819xusb {
810 } phy_sts_ofdm_819xusb_t;
812 typedef struct _phy_cck_rx_status_report_819xusb {
813 /* For CCK rate descriptor. This is an unsigned 8:1 variable.
814 * LSB bit presend 0.5. And MSB 7 bts presend a signed value.
815 * Range from -64~+63.5. */
819 } phy_sts_cck_819xusb_t;
822 typedef struct _phy_ofdm_rx_status_rxsc_sgien_exintfflag {
827 } phy_ofdm_rx_status_rxsc_sgien_exintfflag;
829 typedef enum _RT_CUSTOMER_ID {
831 RT_CID_8187_ALPHA0 = 1,
832 RT_CID_8187_SERCOMM_PS = 2,
833 RT_CID_8187_HW_LED = 3,
834 RT_CID_8187_NETGEAR = 4,
836 RT_CID_819x_CAMEO = 6,
837 RT_CID_819x_RUNTOP = 7,
838 RT_CID_819x_Senao = 8,
840 RT_CID_819x_Netcore = 10,
841 RT_CID_Nettronix = 11,
844 } RT_CUSTOMER_ID, *PRT_CUSTOMER_ID;
847 * ==========================================================================
849 * ==========================================================================
852 typedef enum _LED_STRATEGY_8190 {
853 SW_LED_MODE0, /* SW control 1 LED via GPIO0. It is default option. */
854 SW_LED_MODE1, /* SW control for PCI Express */
855 SW_LED_MODE2, /* SW control for Cameo. */
856 SW_LED_MODE3, /* SW control for RunTop. */
857 SW_LED_MODE4, /* SW control for Netcore. */
858 /* HW control 2 LEDs, LED0 and LED1 (4 different control modes) */
860 } LED_STRATEGY_8190, *PLED_STRATEGY_8190;
862 typedef enum _RESET_TYPE {
863 RESET_TYPE_NORESET = 0x00,
864 RESET_TYPE_NORMAL = 0x01,
865 RESET_TYPE_SILENT = 0x02
868 /* The simple tx command OP code. */
869 typedef enum _tag_TxCmd_Config_Index {
870 TXCMD_TXRA_HISTORY_CTRL = 0xFF900000,
871 TXCMD_RESET_TX_PKT_BUFF = 0xFF900001,
872 TXCMD_RESET_RX_PKT_BUFF = 0xFF900002,
873 TXCMD_SET_TX_DURATION = 0xFF900003,
874 TXCMD_SET_RX_RSSI = 0xFF900004,
875 TXCMD_SET_TX_PWR_TRACKING = 0xFF900005,
879 typedef struct r8192_priv {
880 struct usb_device *udev;
881 /* For maintain info from eeprom */
885 u8 eeprom_CustomerID;
886 u8 eeprom_ChannelPlan;
887 RT_CUSTOMER_ID CustomerID;
888 LED_STRATEGY_8190 LedStrategy;
889 u8 txqueue_to_outpipemap[9];
891 struct ieee80211_device *ieee80211;
893 /* O: rtl8192, 1: rtl8185 V B/C, 2: rtl8185 V D */
895 /* If TCR reports card V B/C, this discriminates */
896 u8 card_8192_version;
899 PCI, MINIPCI, CARDBUS, USB
902 short plcp_preamble_mode;
915 /* If 1, allow bad crc frame, reception in monitor mode */
918 struct semaphore wx_sem;
919 struct semaphore rf_sem; /* Used to lock rf write operation */
921 u8 rf_type; /* 0: 1T2R, 1: 2T4R */
922 RT_RF_TYPE_819xU rf_chip;
924 short (*rf_set_sens)(struct net_device *dev, short sens);
925 u8 (*rf_set_chan)(struct net_device *dev, u8 ch);
926 void (*rf_close)(struct net_device *dev);
927 void (*rf_init)(struct net_device *dev);
931 struct iw_statistics wstats;
935 struct urb **rx_cmd_urb;
939 #ifdef THOMAS_TASKLET
940 atomic_t irt_counter; /* count for irq_rx_tasklet */
942 #ifdef JACKSON_NEW_RX
943 struct sk_buff **pp_rxskb;
947 struct sk_buff_head rx_queue;
948 struct sk_buff_head skb_queue;
949 struct work_struct qos_activate;
951 atomic_t tx_pending[0x10]; /* UART_PRIORITY + 1 */
954 struct tasklet_struct irq_rx_tasklet;
955 struct urb *rxurb_task;
957 /* Tx Related variables */
961 u8 RegCWinMin; /* For turbo mode CW adaptive */
963 u32 LastRxDescTSFHigh;
964 u32 LastRxDescTSFLow;
967 /* Rx Related variables */
968 u16 EarlyRxThreshold;
978 struct ChnlAccessSetting ChannelAccessSetting;
979 struct work_struct reset_wq;
981 /**********************************************************/
987 bool bCurrentRxAggrEnable;
988 u8 Rf_Mode; /* For Firmware RF -R/W switch */
989 prt_firmware pFirmware;
990 rtl819xUsb_loopback_e LoopbackMode;
991 u16 EEPROMTxPowerDiff;
992 u8 EEPROMThermalMeter;
996 u8 EEPROMTxPowerLevelCCK; /* CCK channel 1~14 */
997 u8 EEPROMTxPowerLevelCCK_V1[3];
998 u8 EEPROMTxPowerLevelOFDM24G[3]; /* OFDM 2.4G channel 1~14 */
999 u8 EEPROMTxPowerLevelOFDM5G[24]; /* OFDM 5G */
1002 BB_REGISTER_DEFINITION_T PHYRegDef[4]; /* Radio A/B/C/D */
1003 /* Read/write are allow for following hardware information variables */
1004 u32 MCSTxPowerLevelOriginalOffset[6];
1005 u32 CCKTxPowerLevelOriginalOffset;
1006 u8 TxPowerLevelCCK[14]; /* CCK channel 1~14 */
1007 u8 TxPowerLevelOFDM24G[14]; /* OFDM 2.4G channel 1~14 */
1008 u8 TxPowerLevelOFDM5G[14]; /* OFDM 5G */
1011 u8 AntennaTxPwDiff[2]; /* Antenna gain offset, 0: B, 1: C, 2: D */
1013 u8 ThermalMeter[2]; /* index 0: RFIC0, index 1: RFIC1 */
1016 /* Use to calculate PWBD */
1018 long undecorated_smoothed_pwdb;
1020 /* For set channel */
1021 u8 SwChnlInProgress;
1024 u8 SetBWModeInProgress;
1025 HT_CHANNEL_WIDTH CurrentChannelBW;
1027 /* 8190 40MHz mode */
1028 /* Control channel sub-carrier */
1029 u8 nCur40MhzPrimeSC;
1030 /* Test for shorten RF configuration time.
1031 * We save RF reg0 in this variable to reduce RF reading. */
1034 bool brfpath_rxenable[4];
1035 /* RF set related */
1036 bool SetRFPowerStateInProgress;
1037 struct timer_list watch_dog_timer;
1039 /* For dynamic mechanism */
1040 /* Tx Power Control for Near/Far Range */
1041 bool bdynamic_txpower;
1042 bool bDynamicTxHighPower;
1043 bool bDynamicTxLowPower;
1044 bool bLastDTPFlag_High;
1045 bool bLastDTPFlag_Low;
1047 bool bstore_last_dtpflag;
1048 /* Define to discriminate on High power State or
1049 * on sitesurvey to change Tx gain index */
1050 bool bstart_txctrl_bydtp;
1051 rate_adaptive rate_adaptive;
1052 /* TX power tracking
1053 * OPEN/CLOSE TX POWER TRACKING */
1054 txbbgain_struct txbbgain_table[TxBBGainTableLength];
1055 u8 txpower_count; /* For 6 sec do tracking again */
1056 bool btxpower_trackingInit;
1059 /* CCK TX Power Tracking */
1060 ccktxbbgain_struct cck_txbbgain_table[CCKTxBBGainTableLength];
1061 ccktxbbgain_struct cck_txbbgain_ch14_table[CCKTxBBGainTableLength];
1062 u8 rfa_txpowertrackingindex;
1063 u8 rfa_txpowertrackingindex_real;
1064 u8 rfa_txpowertracking_default;
1065 u8 rfc_txpowertrackingindex;
1066 u8 rfc_txpowertrackingindex_real;
1068 s8 cck_present_attentuation;
1069 u8 cck_present_attentuation_20Mdefault;
1070 u8 cck_present_attentuation_40Mdefault;
1071 char cck_present_attentuation_difference;
1072 bool btxpower_tracking;
1074 bool btxpowerdata_readfromEEPORM;
1076 init_gain initgain_backup;
1077 u8 DefaultInitialGain[4];
1078 /* For EDCA Turbo mode */
1079 bool bis_any_nonbepkts;
1080 bool bcurrent_turbo_EDCA;
1081 bool bis_cur_rdlstate;
1082 struct timer_list fsync_timer;
1083 bool bfsync_processing; /* 500ms Fsync timer is active or not */
1085 u32 rateCountDiffRecord;
1086 u32 ContinueDiffCount;
1091 u8 framesyncMonitor;
1093 u8 nrxAMPDU_aggr_num;
1100 u32 txpower_checkcnt;
1101 u32 txpower_tracking_callback_cnt;
1102 u8 thermal_read_val[40];
1103 u8 thermal_readback_index;
1104 u32 ccktxpower_adjustcnt_not_ch14;
1105 u32 ccktxpower_adjustcnt_ch14;
1106 u8 tx_fwinfo_force_subcarriermode;
1107 u8 tx_fwinfo_force_subcarrierval;
1108 /* For silent reset */
1109 RESET_TYPE ResetProgress;
1110 bool bForcedSilentReset;
1111 bool bDisableNormalResetCheck;
1114 int IrpPendingCount;
1115 bool bResetInProgress;
1117 u8 InitialGainOperateType;
1121 /* Define work item */
1123 struct delayed_work update_beacon_wq;
1124 struct delayed_work watch_dog_wq;
1125 struct delayed_work txpower_tracking_wq;
1126 struct delayed_work rfpath_check_wq;
1127 struct delayed_work gpio_change_rf_wq;
1128 struct delayed_work initialgain_operate_wq;
1129 struct workqueue_struct *priv_wq;
1134 BULK_PRIORITY = 0x01,
1157 bool init_firmware(struct net_device *dev);
1158 short rtl819xU_tx_cmd(struct net_device *dev, struct sk_buff *skb);
1159 short rtl8192_tx(struct net_device *dev, struct sk_buff *skb);
1161 u32 read_cam(struct net_device *dev, u8 addr);
1162 void write_cam(struct net_device *dev, u8 addr, u32 data);
1164 int read_nic_byte(struct net_device *dev, int x, u8 *data);
1165 int read_nic_byte_E(struct net_device *dev, int x, u8 *data);
1166 int read_nic_dword(struct net_device *dev, int x, u32 *data);
1167 int read_nic_word(struct net_device *dev, int x, u16 *data);
1168 void write_nic_byte(struct net_device *dev, int x, u8 y);
1169 void write_nic_byte_E(struct net_device *dev, int x, u8 y);
1170 void write_nic_word(struct net_device *dev, int x, u16 y);
1171 void write_nic_dword(struct net_device *dev, int x, u32 y);
1172 void force_pci_posting(struct net_device *dev);
1174 void rtl8192_rtx_disable(struct net_device *);
1175 void rtl8192_rx_enable(struct net_device *);
1176 void rtl8192_tx_enable(struct net_device *);
1178 void rtl8192_disassociate(struct net_device *dev);
1179 void rtl8185_set_rf_pins_enable(struct net_device *dev, u32 a);
1181 void rtl8192_set_anaparam(struct net_device *dev, u32 a);
1182 void rtl8185_set_anaparam2(struct net_device *dev, u32 a);
1183 void rtl8192_update_msr(struct net_device *dev);
1184 int rtl8192_down(struct net_device *dev);
1185 int rtl8192_up(struct net_device *dev);
1186 void rtl8192_commit(struct net_device *dev);
1187 void rtl8192_set_chan(struct net_device *dev, short ch);
1188 void write_phy(struct net_device *dev, u8 adr, u8 data);
1189 void write_phy_cck(struct net_device *dev, u8 adr, u32 data);
1190 void write_phy_ofdm(struct net_device *dev, u8 adr, u32 data);
1191 void rtl8185_tx_antenna(struct net_device *dev, u8 ant);
1192 void rtl8192_set_rxconf(struct net_device *dev);
1193 extern void rtl819xusb_beacon_tx(struct net_device *dev, u16 tx_rate);
1195 void EnableHWSecurityConfig8192(struct net_device *dev);
1196 void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType, u8 *MacAddr, u8 DefaultKey, u32 *KeyContent);