Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
wifi.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * Copyright(c) 2009-2012 Realtek Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  * The full GNU General Public License is included in this distribution in the
19  * file called LICENSE.
20  *
21  * Contact Information:
22  * wlanfae <[email protected]>
23  * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24  * Hsinchu 300, Taiwan.
25  *
26  * Larry Finger <[email protected]>
27  *
28  *****************************************************************************/
29 
30 #ifndef __RTL_WIFI_H__
31 #define __RTL_WIFI_H__
32 
33 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
34 
35 #include <linux/sched.h>
36 #include <linux/firmware.h>
37 #include <linux/etherdevice.h>
38 #include <linux/vmalloc.h>
39 #include <linux/usb.h>
40 #include <net/mac80211.h>
41 #include <linux/completion.h>
42 #include "debug.h"
43 
44 #define RF_CHANGE_BY_INIT 0
45 #define RF_CHANGE_BY_IPS BIT(28)
46 #define RF_CHANGE_BY_PS BIT(29)
47 #define RF_CHANGE_BY_HW BIT(30)
48 #define RF_CHANGE_BY_SW BIT(31)
49 
50 #define IQK_ADDA_REG_NUM 16
51 #define IQK_MAC_REG_NUM 4
52 
53 #define MAX_KEY_LEN 61
54 #define KEY_BUF_SIZE 5
55 
56 /* QoS related. */
57 /*aci: 0x00 Best Effort*/
58 /*aci: 0x01 Background*/
59 /*aci: 0x10 Video*/
60 /*aci: 0x11 Voice*/
61 /*Max: define total number.*/
62 #define AC0_BE 0
63 #define AC1_BK 1
64 #define AC2_VI 2
65 #define AC3_VO 3
66 #define AC_MAX 4
67 #define QOS_QUEUE_NUM 4
68 #define RTL_MAC80211_NUM_QUEUE 5
69 #define REALTEK_USB_VENQT_MAX_BUF_SIZE 254
70 #define RTL_USB_MAX_RX_COUNT 100
71 #define QBSS_LOAD_SIZE 5
72 #define MAX_WMMELE_LENGTH 64
73 
74 #define TOTAL_CAM_ENTRY 32
75 
76 /*slot time for 11g. */
77 #define RTL_SLOT_TIME_9 9
78 #define RTL_SLOT_TIME_20 20
79 
80 /*related with tcp/ip. */
81 /*if_ehther.h*/
82 #define ETH_P_PAE 0x888E /*Port Access Entity (IEEE 802.1X) */
83 #define ETH_P_IP 0x0800 /*Internet Protocol packet */
84 #define ETH_P_ARP 0x0806 /*Address Resolution packet */
85 #define SNAP_SIZE 6
86 #define PROTOC_TYPE_SIZE 2
87 
88 /*related with 802.11 frame*/
89 #define MAC80211_3ADDR_LEN 24
90 #define MAC80211_4ADDR_LEN 30
91 
92 #define CHANNEL_MAX_NUMBER (14 + 24 + 21) /* 14 is the max channel no */
93 #define CHANNEL_GROUP_MAX (3 + 9) /* ch1~3, 4~9, 10~14 = three groups */
94 #define MAX_PG_GROUP 13
95 #define CHANNEL_GROUP_MAX_2G 3
96 #define CHANNEL_GROUP_IDX_5GL 3
97 #define CHANNEL_GROUP_IDX_5GM 6
98 #define CHANNEL_GROUP_IDX_5GH 9
99 #define CHANNEL_GROUP_MAX_5G 9
100 #define CHANNEL_MAX_NUMBER_2G 14
101 #define AVG_THERMAL_NUM 8
102 #define MAX_TID_COUNT 9
103 
104 /* for early mode */
105 #define FCS_LEN 4
106 #define EM_HDR_LEN 8
107 enum intf_type {
108  INTF_PCI = 0,
109  INTF_USB = 1,
110 };
111 
117 };
118 
123 };
124 
127 };
128 
140 
141  /* keep it last */
143 };
144 
145 #define IS_HARDWARE_TYPE_8192SU(rtlhal) \
146  (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SU)
147 #define IS_HARDWARE_TYPE_8192SE(rtlhal) \
148  (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SE)
149 #define IS_HARDWARE_TYPE_8192CE(rtlhal) \
150  (rtlhal->hw_type == HARDWARE_TYPE_RTL8192CE)
151 #define IS_HARDWARE_TYPE_8192CU(rtlhal) \
152  (rtlhal->hw_type == HARDWARE_TYPE_RTL8192CU)
153 #define IS_HARDWARE_TYPE_8192DE(rtlhal) \
154  (rtlhal->hw_type == HARDWARE_TYPE_RTL8192DE)
155 #define IS_HARDWARE_TYPE_8192DU(rtlhal) \
156  (rtlhal->hw_type == HARDWARE_TYPE_RTL8192DU)
157 #define IS_HARDWARE_TYPE_8723E(rtlhal) \
158  (rtlhal->hw_type == HARDWARE_TYPE_RTL8723E)
159 #define IS_HARDWARE_TYPE_8723U(rtlhal) \
160  (rtlhal->hw_type == HARDWARE_TYPE_RTL8723U)
161 #define IS_HARDWARE_TYPE_8192S(rtlhal) \
162 (IS_HARDWARE_TYPE_8192SE(rtlhal) || IS_HARDWARE_TYPE_8192SU(rtlhal))
163 #define IS_HARDWARE_TYPE_8192C(rtlhal) \
164 (IS_HARDWARE_TYPE_8192CE(rtlhal) || IS_HARDWARE_TYPE_8192CU(rtlhal))
165 #define IS_HARDWARE_TYPE_8192D(rtlhal) \
166 (IS_HARDWARE_TYPE_8192DE(rtlhal) || IS_HARDWARE_TYPE_8192DU(rtlhal))
167 #define IS_HARDWARE_TYPE_8723(rtlhal) \
168 (IS_HARDWARE_TYPE_8723E(rtlhal) || IS_HARDWARE_TYPE_8723U(rtlhal))
169 #define IS_HARDWARE_TYPE_8723U(rtlhal) \
170  (rtlhal->hw_type == HARDWARE_TYPE_RTL8723U)
171 
172 #define RX_HAL_IS_CCK_RATE(_pdesc)\
173  (_pdesc->rxmcs == DESC92_RATE1M || \
174  _pdesc->rxmcs == DESC92_RATE2M || \
175  _pdesc->rxmcs == DESC92_RATE5_5M || \
176  _pdesc->rxmcs == DESC92_RATE11M)
177 
182 };
183 
184 /*RF state.*/
189 };
190 
191 struct bb_reg_def {
210 };
211 
212 enum io_type {
215 };
216 
261 
286 
294 
307 
309 
313 };
314 
318 };
319 
320 enum rt_oem_id {
353 };
354 
355 enum hw_descs {
363 };
364 
365 enum prime_sc {
369 };
370 
371 enum rf_type {
372  RF_1T1R = 0,
373  RF_1T2R = 1,
374  RF_2T2R = 2,
376 };
377 
381 };
382 
383 /* Ref: 802.11i sepc D10.0 7.3.2.25.1
384 Cipher Suites Encryption Algorithms */
392  AESCMAC_ENCRYPTION = 6, /*IEEE802.11w */
393 };
394 
398 };
399 
405 
414 
433 };
434 
436  /*reg map */
445 
446  /*efuse map */
459 
460  /*CAM map */
471 
472  /*IMR map */
473  RTL_IMR_BCNDMAINT6, /*Beacon DMA Interrupt 6 */
474  RTL_IMR_BCNDMAINT5, /*Beacon DMA Interrupt 5 */
475  RTL_IMR_BCNDMAINT4, /*Beacon DMA Interrupt 4 */
476  RTL_IMR_BCNDMAINT3, /*Beacon DMA Interrupt 3 */
477  RTL_IMR_BCNDMAINT2, /*Beacon DMA Interrupt 2 */
478  RTL_IMR_BCNDMAINT1, /*Beacon DMA Interrupt 1 */
479  RTL_IMR_BCNDOK8, /*Beacon Queue DMA OK Interrup 8 */
480  RTL_IMR_BCNDOK7, /*Beacon Queue DMA OK Interrup 7 */
481  RTL_IMR_BCNDOK6, /*Beacon Queue DMA OK Interrup 6 */
482  RTL_IMR_BCNDOK5, /*Beacon Queue DMA OK Interrup 5 */
483  RTL_IMR_BCNDOK4, /*Beacon Queue DMA OK Interrup 4 */
484  RTL_IMR_BCNDOK3, /*Beacon Queue DMA OK Interrup 3 */
485  RTL_IMR_BCNDOK2, /*Beacon Queue DMA OK Interrup 2 */
486  RTL_IMR_BCNDOK1, /*Beacon Queue DMA OK Interrup 1 */
487  RTL_IMR_TIMEOUT2, /*Timeout interrupt 2 */
488  RTL_IMR_TIMEOUT1, /*Timeout interrupt 1 */
489  RTL_IMR_TXFOVW, /*Transmit FIFO Overflow */
490  RTL_IMR_PSTIMEOUT, /*Power save time out interrupt */
491  RTL_IMR_BcnInt, /*Beacon DMA Interrupt 0 */
492  RTL_IMR_RXFOVW, /*Receive FIFO Overflow */
493  RTL_IMR_RDU, /*Receive Descriptor Unavailable */
494  RTL_IMR_ATIMEND, /*For 92C,ATIM Window End Interrupt */
495  RTL_IMR_BDOK, /*Beacon Queue DMA OK Interrup */
496  RTL_IMR_HIGHDOK, /*High Queue DMA OK Interrupt */
497  RTL_IMR_COMDOK, /*Command Queue DMA OK Interrupt*/
498  RTL_IMR_TBDOK, /*Transmit Beacon OK interrup */
499  RTL_IMR_MGNTDOK, /*Management Queue DMA OK Interrupt */
500  RTL_IMR_TBDER, /*For 92C,Transmit Beacon Error Interrupt */
501  RTL_IMR_BKDOK, /*AC_BK DMA OK Interrupt */
502  RTL_IMR_BEDOK, /*AC_BE DMA OK Interrupt */
503  RTL_IMR_VIDOK, /*AC_VI DMA OK Interrupt */
504  RTL_IMR_VODOK, /*AC_VO DMA Interrupt */
505  RTL_IMR_ROK, /*Receive DMA OK Interrupt */
506  RTL_IBSS_INT_MASKS, /*(RTL_IMR_BcnInt | RTL_IMR_TBDOK |
507  * RTL_IMR_TBDER) */
508 
509  /*CCK Rates, TxHT = 0 */
514 
515  /*OFDM Rates, TxHT = 0 */
524 
527 
528  /*keep it last */
530 };
531 
532 /*Firmware PS mode for control LPS.*/
545 };
546 
547 enum rt_psmode {
548  EACTIVE, /*Active/Continuous access. */
549  EMAXPS, /*Max power save mode. */
550  EFASTPS, /*Fast power save mode. */
551  EAUTOPS, /*Auto power save mode. */
552 };
553 
554 /*LED related.*/
566 };
567 
573 };
574 
575 /*QoS related.*/
576 /*acm implementation method.*/
581 };
582 
587 };
588 
589 enum band_type {
594 };
595 
596 /*aci/aifsn Field.
597 Ref: WMM spec 2.2.2: WME Parameter Element, p.12.*/
598 union aci_aifsn {
600 
601  struct {
603  u8 acm:1;
604  u8 aci:2;
606  } f; /* Field */
607 };
608 
609 /*mlme related.*/
618 };
619 
620 #define IS_WIRELESS_MODE_A(wirelessmode) \
621  (wirelessmode == WIRELESS_MODE_A)
622 #define IS_WIRELESS_MODE_B(wirelessmode) \
623  (wirelessmode == WIRELESS_MODE_B)
624 #define IS_WIRELESS_MODE_G(wirelessmode) \
625  (wirelessmode == WIRELESS_MODE_G)
626 #define IS_WIRELESS_MODE_N_24G(wirelessmode) \
627  (wirelessmode == WIRELESS_MODE_N_24G)
628 #define IS_WIRELESS_MODE_N_5G(wirelessmode) \
629  (wirelessmode == WIRELESS_MODE_N_5G)
630 
641 };
642 
648 };
649 
656 };
657 
658 enum ba_action {
662 };
663 
664 struct octet_string {
667 };
668 
677 } __packed;
678 
682  u8 data[0];
683 } __packed;
684 
690  /*SSID, supported rates, FH params, DS params,
691  CF params, IBSS params, TIM (if beacon), RSN */
693 } __packed;
694 
695 /*LED related.*/
696 /*ledpin Identify how to implement this SW led.*/
697 struct rtl_led {
698  void *hw;
700  bool ledon;
701 };
702 
703 struct rtl_led_ctl {
705  struct rtl_led sw_led0;
706  struct rtl_led sw_led1;
707 };
708 
715 } __packed;
716 
718  u32 elements[100]; /*array to store values */
719  u32 index; /*index to current array to store */
720  u32 total_num; /*num of valid elements */
721  u32 total_val; /*sum of valid elements */
722 };
723 
734 };
735 
736 struct init_gain {
742 
743 };
744 
746  unsigned long txbytesunicast;
747  unsigned long txbytesmulticast;
748  unsigned long txbytesbroadcast;
749  unsigned long rxbytesunicast;
750 
751  long rx_snr_db[4];
752  /*Correct smoothed ss in Dbm, only used
753  in driver to report real power now. */
757 
759 
760  /*Transformed, in dbm. Beautified signal
761  strength for UI, not correct. */
763 
766 
769 };
770 
775 
795 };
796 
801 };
802 
804  char alpha2[2];
812 };
813 
814 struct rtl_rfkill {
815  bool rfkill_state; /*0 is off, 1 is on */
816 };
817 
818 #define IQK_MATRIX_REG_NUM 8
819 #define IQK_MATRIX_SETTINGS_NUM (1 + 24 + 21)
821  bool iqk_done;
823 };
824 
828 };
829 
842 };
843 
844 struct rtl_phy {
845  struct bb_reg_def phyreg_def[4]; /*Radio A/B/C/D */
848 
860 
861  /* record for power tracking */
878 
879  /* Dual mac */
880  bool need_iqk;
882 
884 
887  /* MAX_PG_GROUP groups of pwr diff by rates */
890 
891  /* the current Tx power level */
894 
896  bool apk_done;
897  u32 reg_rf3c[2]; /* pathA / pathB */
898 
899  /* bfsync */
902 
906 };
907 
908 #define MAX_TID_COUNT 9
909 #define RTL_AGG_STOP 0
910 #define RTL_AGG_PROGRESS 1
911 #define RTL_AGG_START 2
912 #define RTL_AGG_OPERATIONAL 3
913 #define RTL_AGG_OFF 0
914 #define RTL_AGG_ON 1
915 #define RTL_RX_AGG_START 1
916 #define RTL_RX_AGG_STOP 0
917 #define RTL_AGG_EMPTYING_HW_QUEUE_ADDBA 2
918 #define RTL_AGG_EMPTYING_HW_QUEUE_DELBA 3
919 
920 struct rtl_ht_agg {
928 };
929 
930 struct rtl_tid_data {
932  struct rtl_ht_agg agg;
933 };
934 
935 struct rssi_sta {
937 };
938 
939 struct rtl_sta_info {
940  struct list_head list;
945 
946  /* just used for ap adhoc or mesh*/
948 } __packed;
949 
950 struct rtl_priv;
951 struct rtl_io {
952  struct device *dev;
953  struct mutex bb_mutex;
954 
955  /*PCI MEM map */
956  unsigned long pci_mem_end; /*shared mem end */
957  unsigned long pci_mem_start; /*shared mem start */
958 
959  /*PCI IO map */
960  unsigned long pci_base_addr; /*device I/O address */
961 
962  void (*write8_async) (struct rtl_priv *rtlpriv, u32 addr, u8 val);
963  void (*write16_async) (struct rtl_priv *rtlpriv, u32 addr, u16 val);
964  void (*write32_async) (struct rtl_priv *rtlpriv, u32 addr, u32 val);
965  void (*writeN_sync) (struct rtl_priv *rtlpriv, u32 addr, void *buf,
966  u16 len);
967 
968  u8(*read8_sync) (struct rtl_priv *rtlpriv, u32 addr);
969  u16(*read16_sync) (struct rtl_priv *rtlpriv, u32 addr);
970  u32(*read32_sync) (struct rtl_priv *rtlpriv, u32 addr);
971 
972 };
973 
974 struct rtl_mac {
978 
981 
983  struct ieee80211_hw *hw;
986 
987  /*Probe Beacon management */
990 
993 
995 
996  /*filters */
1001 
1004 
1005  /* early mode */
1006  /* skb wait queue */
1009 
1010  /*RDG*/
1011  bool rdg_en;
1012 
1013  /*AP*/
1014  u8 bssid[6];
1016  u8 mcs[16]; /* 16 bytes mcs for HT rates. */
1017  u32 basic_rates; /* b/g rates */
1022  u8 mode; /* wireless mode */
1032 
1033  /*IBSS*/
1035 
1036  /*AMPDU*/
1037  u8 min_space_cfg; /*For Min spacing configurations */
1041 
1042  /*QOS & EDCA */
1045 };
1046 
1047 struct rtl_hal {
1048  struct ieee80211_hw *hw;
1049 
1054 
1056  u16 hw_type; /*92c or 92d or 92s and so on */
1059  u32 version; /*version of chip */
1060  u8 state; /*stop 0, start 1 */
1061 
1062  /*firmware */
1069  bool fw_ready;
1070  /*Reserve page start offset except beacon in TxQ. */
1073 
1074  /* FW Cmd IO related */
1079 
1080 
1082 
1083  /*AMPDU init min space*/
1084  u8 minspace_cfg; /*For Min spacing configurations */
1085 
1086  /* Dual mac */
1088  enum band_type current_bandtype; /* 0:2.4G, 1:5G */
1091  /* dual MAC 0--Mac0 1--Mac1 */
1093  /* just for DualMac S3S4 */
1096  /* Dual mac*/
1100  /* True if IMR or IQK have done
1101  for 2.4G in scan progress */
1103 
1107 };
1108 
1110  /*default 0 */
1112 
1115  /*Encryption Algorithm for Unicast Packet */
1117  /*Encryption Algorithm for Brocast/Multicast */
1119  /*Cam Entry Bitmap */
1122  /*local Key buffer, indx 0 is for
1123  pairwise key 1-4 is for agoup key. */
1126 
1127  /*The pointer of Pairwise Key,
1128  it always points to KeyBuf[4] */
1130 };
1131 
1132 struct rtl_dm {
1133  /*PHY status for Dynamic Management */
1135  long undecorated_smoothed_pwdb; /*out dm */
1140  bool is_any_nonbepkts; /*out dm */
1151 
1160  u8 dynamic_txhighpower_lvl; /*Tx high power level */
1161  u8 dm_flag; /*Indicate each dynamic mechanism's status. */
1166  char ofdm_index[2];
1168 
1169  /* DMSP */
1171 };
1172 
1173 #define EFUSE_MAX_LOGICAL_SIZE 256
1174 
1175 struct rtl_efuse {
1179 
1183 #ifdef EFUSE_REPG_WORKAROUND
1184  bool efuse_re_pg_sec1flag;
1185  u8 efuse_re_pg_data[8];
1186 #endif
1187 
1190 
1191  short epromtype;
1201 
1203 
1207  u8 eeprom_tssi_5g[3][2]; /* for 5GL/5GM/5GH band. */
1214  u8 txpwrlevel_ht40_1s[2][CHANNEL_MAX_NUMBER]; /*For HT 40MHZ pwr */
1215  u8 txpwrlevel_ht40_2s[2][CHANNEL_MAX_NUMBER]; /*For HT 40MHZ pwr */
1216 
1217  u8 internal_pa_5g[2]; /* pathA / pathB */
1220 
1221  /*For power group */
1225 
1226  char txpwr_ht20diff[2][CHANNEL_MAX_NUMBER]; /*HT 20<->40 Pwr diff */
1227  /*For HT<->legacy pwr diff*/
1229  u8 txpwr_safetyflag; /* Band edge enable flag */
1231  u8 legacy_httxpowerdiff; /* Legacy to HT rate power diff */
1233 
1236  u8 thermalmeter[2]; /*ThermalMeter, index 0 for RFIC0, 1 for RFIC1 */
1238  u8 crystalcap; /* CrystalCap. */
1241 
1242  u8 legacy_ht_txpowerdiff; /*Legacy to HT rate power diff */
1244 
1247 
1248  /*channel plan */
1250 };
1251 
1252 struct rtl_ps_ctl {
1258 
1259  /*
1260  * just for PCIE ASPM
1261  * If it supports ASPM, Offset[560h] = 0x40,
1262  * otherwise Offset[560h] = 0x00.
1263  * */
1265 
1267 
1268  /*for LPS */
1269  enum rt_psmode dot11_psmode; /*Power save mode configured. */
1274  /*For Fw control LPS mode */
1276  /*Record Fw PS mode status. */
1280 
1281  /*for IPS */
1283 
1285 
1286  /*RF OFF Level */
1289 
1290  /*just for PCIE ASPM */
1293 
1295  enum rf_pwrstate rfpwr_state; /*cur power state */
1296 
1297  /* for SW LPS*/
1299  bool state;
1303  unsigned int dtim_counter;
1304  unsigned int sleep_ms;
1305  unsigned long last_sleep_jiffies;
1306  unsigned long last_awake_jiffies;
1308  unsigned long last_dtim;
1309  unsigned long last_beacon;
1310  unsigned long last_action;
1311  unsigned long last_slept;
1312 };
1313 
1314 struct rtl_stats {
1319  u16 rate; /*in 100 kbps */
1329  u8 signalquality; /*in 0-100 index. */
1330  /*
1331  * Real power in dBm for this packet,
1332  * no beautification and aggregation.
1333  * */
1335  s8 rxpower; /*in dBm Translate from PWdB */
1336  u8 signalstrength; /*in 0-100 index. */
1346 
1349  bool isampdu;
1353  u8 rx_mimo_signalstrength[4]; /*in 0~100 index */
1356  bool is_cck;
1357  bool is_ht;
1359  bool packet_beacon; /*for rssi */
1360  char cck_adc_pwdb[4]; /*for rx path selection */
1361 };
1362 
1364  /* count for roaming */
1367 
1370 
1373 
1379 
1383 };
1384 
1389 
1398 
1403 
1407 
1411 
1412  /* early mode */
1414  /* The max value by HW */
1416 };
1417 
1418 struct rtl_hal_ops {
1424  u32 *p_inta, u32 *p_intb);
1425  int (*hw_init) (struct ieee80211_hw *hw);
1432  enum nl80211_iftype type);
1434  bool check_bssid);
1436  enum nl80211_channel_type ch_type);
1438  void (*set_qos) (struct ieee80211_hw *hw, int aci);
1442  u32 add_msr, u32 rm_msr);
1446  struct ieee80211_sta *sta, u8 rssi_level);
1447  void (*update_rate_mask) (struct ieee80211_hw *hw, u8 rssi_level);
1449  struct ieee80211_hdr *hdr, u8 *pdesc_tx,
1450  struct ieee80211_tx_info *info,
1451  struct ieee80211_sta *sta,
1452  struct sk_buff *skb, u8 hw_queue,
1453  struct rtl_tcb_desc *ptcb_desc);
1454  void (*fill_fake_txdesc) (struct ieee80211_hw *hw, u8 *pDesc,
1455  u32 buffer_len, bool bIsPsPoll);
1457  bool firstseg, bool lastseg,
1458  struct sk_buff *skb);
1461  struct rtl_stats *stats,
1463  u8 *pdesc, struct sk_buff *skb);
1469  enum rf_pwrstate rfpwr_state);
1471  enum led_ctl_mode ledaction);
1472  void (*set_desc) (u8 *pdesc, bool istx, u8 desc_name, u8 *val);
1473  u32 (*get_desc) (u8 *pdesc, bool istx, u8 desc_name);
1477  u8 *macaddr, bool is_group, u8 enc_algo,
1478  bool is_wepkey, bool clear_all);
1481  u32 (*get_bbreg) (struct ieee80211_hw *hw, u32 regaddr, u32 bitmask);
1482  void (*set_bbreg) (struct ieee80211_hw *hw, u32 regaddr, u32 bitmask,
1483  u32 data);
1484  u32 (*get_rfreg) (struct ieee80211_hw *hw, enum radio_path rfpath,
1485  u32 regaddr, u32 bitmask);
1486  void (*set_rfreg) (struct ieee80211_hw *hw, enum radio_path rfpath,
1487  u32 regaddr, u32 bitmask, u32 data);
1489  bool allow_all_da, bool write_into_reg);
1496  u8 *powerlevel);
1498  u8 *ppowerlevel, u8 channel);
1500  u8 configtype);
1502  u8 configtype);
1503  void (*phy_lc_calibrate) (struct ieee80211_hw *hw, bool is2t);
1506 };
1507 
1509  /*com */
1510  void (*read_efuse_byte)(struct ieee80211_hw *hw, u16 _offset, u8 *pbuf);
1514  struct rtl_priv **buddy_priv);
1515 
1517  struct ieee80211_sta *sta,
1518  struct sk_buff *skb,
1519  struct rtl_tcb_desc *ptcb_desc);
1520  void (*flush)(struct ieee80211_hw *hw, bool drop);
1523  struct ieee80211_sta *sta,
1524  struct sk_buff *skb);
1525 
1526  /*pci */
1529 
1530  /*usb */
1531 };
1532 
1534  /* default: 0 = using hardware encryption */
1536 
1537  /* default: 0 = DBG_EMERG (0)*/
1538  int debug;
1539 
1540  /* default: 1 = using no linked power save */
1542 
1543  /* default: 1 = using linked sw power save */
1545 
1546  /* default: 1 = using linked fw power save */
1548 };
1549 
1551  /* data - rx */
1555 
1556  /* op - rx */
1557  void (*usb_rx_hdl)(struct ieee80211_hw *, struct sk_buff *);
1559  struct sk_buff_head *);
1560 
1561  /* tx */
1562  void (*usb_tx_cleanup)(struct ieee80211_hw *, struct sk_buff *);
1563  int (*usb_tx_post_hdl)(struct ieee80211_hw *, struct urb *,
1564  struct sk_buff *);
1565  struct sk_buff *(*usb_tx_aggregate_hdl)(struct ieee80211_hw *,
1566  struct sk_buff_head *);
1567 
1568  /* endpoint mapping */
1570  u16 (*usb_mq_to_hwq)(__le16 fc, u16 mac80211_queue_index);
1571 };
1572 
1573 struct rtl_hal_cfg {
1576  char *name;
1577  char *fw_name;
1578  struct rtl_hal_ops *ops;
1581 
1582  /*this map used for some registers or vars
1583  defined int HAL but used in MAIN */
1585 
1586 };
1587 
1588 struct rtl_locks {
1589  /* mutex */
1591  struct mutex ps_mutex;
1592 
1593  /*spin lock */
1603 
1604  /*Dual mac*/
1606 
1607  /*Easy concurrent*/
1609 };
1610 
1611 struct rtl_works {
1612  struct ieee80211_hw *hw;
1613 
1614  /*timer */
1617 
1618  /*task */
1621 
1622  /*work queue */
1626 
1627  /* For SW LPS */
1630 
1632 };
1633 
1634 struct rtl_debug {
1638 
1639  /* add for proc debug */
1641  char proc_name[20];
1642 };
1643 
1644 #define MIMO_PS_STATIC 0
1645 #define MIMO_PS_DYNAMIC 1
1646 #define MIMO_PS_NOLIMIT 3
1647 
1654 };
1655 
1667 };
1668 
1669 struct ps_t {
1675 };
1676 
1677 struct dig_t {
1688  long rssi_val;
1726 };
1727 
1729  /* from this list we can get
1730  * other adapter's rtl_priv */
1733 };
1734 
1735 struct rtl_priv {
1737  struct list_head list;
1745  struct rtl_hal rtlhal;
1748  struct rtl_io io;
1749  struct rtl_phy phy;
1750  struct rtl_dm dm;
1753 
1754  struct rtl_ps_ctl psc;
1759 
1761 
1762  /* sta entry list for ap adhoc or mesh */
1764 
1765  struct rtl_debug dbg;
1767 
1768  /*
1769  *hal_cfg : for diff cards
1770  *intf_ops : for diff interrface usb/pcie
1771  */
1772  struct rtl_hal_cfg *cfg;
1774 
1775  /*this var will be set by set_bit,
1776  and was used to indicate status of
1777  interface or hardware */
1778  unsigned long status;
1779 
1780  /* tables for dm */
1783 
1784  /* data buffer pointer for USB reads */
1787 
1788  /*This must be the last item so
1789  that it points to the data allocated
1790  beyond this structure like:
1791  rtl_pci_priv or rtl_usb_priv */
1792  u8 priv[0];
1793 };
1794 
1795 #define rtl_priv(hw) (((struct rtl_priv *)(hw)->priv))
1796 #define rtl_mac(rtlpriv) (&((rtlpriv)->mac80211))
1797 #define rtl_hal(rtlpriv) (&((rtlpriv)->rtlhal))
1798 #define rtl_efuse(rtlpriv) (&((rtlpriv)->efuse))
1799 #define rtl_psc(rtlpriv) (&((rtlpriv)->psc))
1800 
1801 
1802 /***************************************
1803  Bluetooth Co-existence Related
1804 ****************************************/
1805 
1807  ANT_X2 = 0,
1808  ANT_X1 = 1,
1809 };
1810 
1818 };
1819 
1821  BT_OFF = 0,
1822  BT_ON = 1,
1823 };
1824 
1826  BT_SCO = 0,
1827  BT_A2DP = 1,
1828  BT_HID = 2,
1830  BT_SCAN = 4,
1831  BT_IDLE = 5,
1833  BT_BUSY = 7,
1835  BT_PAN = 9,
1836 };
1837 
1841 };
1842 
1844 
1845  /* EEPROM BT info. */
1851 
1856  u8 bt_cur_state; /* 0:on, 1:off */
1857  u8 bt_ant_isolation; /* 0:good, 1:bad */
1858  u8 bt_pape_ctrl; /* 0:SW, 1:SW/HW dynamic */
1868 
1869  bool init_set;
1873 
1879 
1882 
1883 };
1884 
1885 
1886 /****************************************
1887  mem access macro define start
1888  Call endian free function when
1889  1. Read/write packet content.
1890  2. Before write integer to IO.
1891  3. After read integer from IO.
1892 ****************************************/
1893 /* Convert little data endian to host ordering */
1894 #define EF1BYTE(_val) \
1895  ((u8)(_val))
1896 #define EF2BYTE(_val) \
1897  (le16_to_cpu(_val))
1898 #define EF4BYTE(_val) \
1899  (le32_to_cpu(_val))
1900 
1901 /* Read data from memory */
1902 #define READEF1BYTE(_ptr) \
1903  EF1BYTE(*((u8 *)(_ptr)))
1904 /* Read le16 data from memory and convert to host ordering */
1905 #define READEF2BYTE(_ptr) \
1906  EF2BYTE(*(_ptr))
1907 #define READEF4BYTE(_ptr) \
1908  EF4BYTE(*(_ptr))
1909 
1910 /* Write data to memory */
1911 #define WRITEEF1BYTE(_ptr, _val) \
1912  (*((u8 *)(_ptr))) = EF1BYTE(_val)
1913 /* Write le16 data to memory in host ordering */
1914 #define WRITEEF2BYTE(_ptr, _val) \
1915  (*((u16 *)(_ptr))) = EF2BYTE(_val)
1916 #define WRITEEF4BYTE(_ptr, _val) \
1917  (*((u32 *)(_ptr))) = EF2BYTE(_val)
1918 
1919 /* Create a bit mask
1920  * Examples:
1921  * BIT_LEN_MASK_32(0) => 0x00000000
1922  * BIT_LEN_MASK_32(1) => 0x00000001
1923  * BIT_LEN_MASK_32(2) => 0x00000003
1924  * BIT_LEN_MASK_32(32) => 0xFFFFFFFF
1925  */
1926 #define BIT_LEN_MASK_32(__bitlen) \
1927  (0xFFFFFFFF >> (32 - (__bitlen)))
1928 #define BIT_LEN_MASK_16(__bitlen) \
1929  (0xFFFF >> (16 - (__bitlen)))
1930 #define BIT_LEN_MASK_8(__bitlen) \
1931  (0xFF >> (8 - (__bitlen)))
1932 
1933 /* Create an offset bit mask
1934  * Examples:
1935  * BIT_OFFSET_LEN_MASK_32(0, 2) => 0x00000003
1936  * BIT_OFFSET_LEN_MASK_32(16, 2) => 0x00030000
1937  */
1938 #define BIT_OFFSET_LEN_MASK_32(__bitoffset, __bitlen) \
1939  (BIT_LEN_MASK_32(__bitlen) << (__bitoffset))
1940 #define BIT_OFFSET_LEN_MASK_16(__bitoffset, __bitlen) \
1941  (BIT_LEN_MASK_16(__bitlen) << (__bitoffset))
1942 #define BIT_OFFSET_LEN_MASK_8(__bitoffset, __bitlen) \
1943  (BIT_LEN_MASK_8(__bitlen) << (__bitoffset))
1944 
1945 /*Description:
1946  * Return 4-byte value in host byte ordering from
1947  * 4-byte pointer in little-endian system.
1948  */
1949 #define LE_P4BYTE_TO_HOST_4BYTE(__pstart) \
1950  (EF4BYTE(*((__le32 *)(__pstart))))
1951 #define LE_P2BYTE_TO_HOST_2BYTE(__pstart) \
1952  (EF2BYTE(*((__le16 *)(__pstart))))
1953 #define LE_P1BYTE_TO_HOST_1BYTE(__pstart) \
1954  (EF1BYTE(*((u8 *)(__pstart))))
1955 
1956 /*Description:
1957 Translate subfield (continuous bits in little-endian) of 4-byte
1958 value to host byte ordering.*/
1959 #define LE_BITS_TO_4BYTE(__pstart, __bitoffset, __bitlen) \
1960  ( \
1961  (LE_P4BYTE_TO_HOST_4BYTE(__pstart) >> (__bitoffset)) & \
1962  BIT_LEN_MASK_32(__bitlen) \
1963  )
1964 #define LE_BITS_TO_2BYTE(__pstart, __bitoffset, __bitlen) \
1965  ( \
1966  (LE_P2BYTE_TO_HOST_2BYTE(__pstart) >> (__bitoffset)) & \
1967  BIT_LEN_MASK_16(__bitlen) \
1968  )
1969 #define LE_BITS_TO_1BYTE(__pstart, __bitoffset, __bitlen) \
1970  ( \
1971  (LE_P1BYTE_TO_HOST_1BYTE(__pstart) >> (__bitoffset)) & \
1972  BIT_LEN_MASK_8(__bitlen) \
1973  )
1974 
1975 /* Description:
1976  * Mask subfield (continuous bits in little-endian) of 4-byte value
1977  * and return the result in 4-byte value in host byte ordering.
1978  */
1979 #define LE_BITS_CLEARED_TO_4BYTE(__pstart, __bitoffset, __bitlen) \
1980  ( \
1981  LE_P4BYTE_TO_HOST_4BYTE(__pstart) & \
1982  (~BIT_OFFSET_LEN_MASK_32(__bitoffset, __bitlen)) \
1983  )
1984 #define LE_BITS_CLEARED_TO_2BYTE(__pstart, __bitoffset, __bitlen) \
1985  ( \
1986  LE_P2BYTE_TO_HOST_2BYTE(__pstart) & \
1987  (~BIT_OFFSET_LEN_MASK_16(__bitoffset, __bitlen)) \
1988  )
1989 #define LE_BITS_CLEARED_TO_1BYTE(__pstart, __bitoffset, __bitlen) \
1990  ( \
1991  LE_P1BYTE_TO_HOST_1BYTE(__pstart) & \
1992  (~BIT_OFFSET_LEN_MASK_8(__bitoffset, __bitlen)) \
1993  )
1994 
1995 /* Description:
1996  * Set subfield of little-endian 4-byte value to specified value.
1997  */
1998 #define SET_BITS_TO_LE_4BYTE(__pstart, __bitoffset, __bitlen, __val) \
1999  *((u32 *)(__pstart)) = \
2000  ( \
2001  LE_BITS_CLEARED_TO_4BYTE(__pstart, __bitoffset, __bitlen) | \
2002  ((((u32)__val) & BIT_LEN_MASK_32(__bitlen)) << (__bitoffset)) \
2003  );
2004 #define SET_BITS_TO_LE_2BYTE(__pstart, __bitoffset, __bitlen, __val) \
2005  *((u16 *)(__pstart)) = \
2006  ( \
2007  LE_BITS_CLEARED_TO_2BYTE(__pstart, __bitoffset, __bitlen) | \
2008  ((((u16)__val) & BIT_LEN_MASK_16(__bitlen)) << (__bitoffset)) \
2009  );
2010 #define SET_BITS_TO_LE_1BYTE(__pstart, __bitoffset, __bitlen, __val) \
2011  *((u8 *)(__pstart)) = EF1BYTE \
2012  ( \
2013  LE_BITS_CLEARED_TO_1BYTE(__pstart, __bitoffset, __bitlen) | \
2014  ((((u8)__val) & BIT_LEN_MASK_8(__bitlen)) << (__bitoffset)) \
2015  );
2016 
2017 #define N_BYTE_ALIGMENT(__value, __aligment) ((__aligment == 1) ? \
2018  (__value) : (((__value + __aligment - 1) / __aligment) * __aligment))
2019 
2020 /****************************************
2021  mem access macro define end
2022 ****************************************/
2023 
2024 #define byte(x, n) ((x >> (8 * n)) & 0xff)
2025 
2026 #define packet_get_type(_packet) (EF1BYTE((_packet).octet[0]) & 0xFC)
2027 #define RTL_WATCH_DOG_TIME 2000
2028 #define MSECS(t) msecs_to_jiffies(t)
2029 #define WLAN_FC_GET_VERS(fc) (le16_to_cpu(fc) & IEEE80211_FCTL_VERS)
2030 #define WLAN_FC_GET_TYPE(fc) (le16_to_cpu(fc) & IEEE80211_FCTL_FTYPE)
2031 #define WLAN_FC_GET_STYPE(fc) (le16_to_cpu(fc) & IEEE80211_FCTL_STYPE)
2032 #define WLAN_FC_MORE_DATA(fc) (le16_to_cpu(fc) & IEEE80211_FCTL_MOREDATA)
2033 #define SEQ_TO_SN(seq) (((seq) & IEEE80211_SCTL_SEQ) >> 4)
2034 #define SN_TO_SEQ(ssn) (((ssn) << 4) & IEEE80211_SCTL_SEQ)
2035 #define MAX_SN ((IEEE80211_SCTL_SEQ) >> 4)
2036 
2037 #define RT_RF_OFF_LEVL_ASPM BIT(0) /*PCI ASPM */
2038 #define RT_RF_OFF_LEVL_CLK_REQ BIT(1) /*PCI clock request */
2039 #define RT_RF_OFF_LEVL_PCI_D3 BIT(2) /*PCI D3 mode */
2040 /*NIC halt, re-initialize hw parameters*/
2041 #define RT_RF_OFF_LEVL_HALT_NIC BIT(3)
2042 #define RT_RF_OFF_LEVL_FREE_FW BIT(4) /*FW free, re-download the FW */
2043 #define RT_RF_OFF_LEVL_FW_32K BIT(5) /*FW in 32k */
2044 /*Always enable ASPM and Clock Req in initialization.*/
2045 #define RT_RF_PS_LEVEL_ALWAYS_ASPM BIT(6)
2046 /* no matter RFOFF or SLEEP we set PS_ASPM_LEVL*/
2047 #define RT_PS_LEVEL_ASPM BIT(7)
2048 /*When LPS is on, disable 2R if no packet is received or transmittd.*/
2049 #define RT_RF_LPS_DISALBE_2R BIT(30)
2050 #define RT_RF_LPS_LEVEL_ASPM BIT(31) /*LPS with ASPM */
2051 #define RT_IN_PS_LEVEL(ppsc, _ps_flg) \
2052  ((ppsc->cur_ps_level & _ps_flg) ? true : false)
2053 #define RT_CLEAR_PS_LEVEL(ppsc, _ps_flg) \
2054  (ppsc->cur_ps_level &= (~(_ps_flg)))
2055 #define RT_SET_PS_LEVEL(ppsc, _ps_flg) \
2056  (ppsc->cur_ps_level |= _ps_flg)
2057 
2058 #define container_of_dwork_rtl(x, y, z) \
2059  container_of(container_of(x, struct delayed_work, work), y, z)
2060 
2061 #define FILL_OCTET_STRING(_os, _octet, _len) \
2062  (_os).octet = (u8 *)(_octet); \
2063  (_os).length = (_len);
2064 
2065 #define CP_MACADDR(des, src) \
2066  ((des)[0] = (src)[0], (des)[1] = (src)[1],\
2067  (des)[2] = (src)[2], (des)[3] = (src)[3],\
2068  (des)[4] = (src)[4], (des)[5] = (src)[5])
2069 
2070 static inline u8 rtl_read_byte(struct rtl_priv *rtlpriv, u32 addr)
2071 {
2072  return rtlpriv->io.read8_sync(rtlpriv, addr);
2073 }
2074 
2075 static inline u16 rtl_read_word(struct rtl_priv *rtlpriv, u32 addr)
2076 {
2077  return rtlpriv->io.read16_sync(rtlpriv, addr);
2078 }
2079 
2080 static inline u32 rtl_read_dword(struct rtl_priv *rtlpriv, u32 addr)
2081 {
2082  return rtlpriv->io.read32_sync(rtlpriv, addr);
2083 }
2084 
2085 static inline void rtl_write_byte(struct rtl_priv *rtlpriv, u32 addr, u8 val8)
2086 {
2087  rtlpriv->io.write8_async(rtlpriv, addr, val8);
2088 
2089  if (rtlpriv->cfg->write_readback)
2090  rtlpriv->io.read8_sync(rtlpriv, addr);
2091 }
2092 
2093 static inline void rtl_write_word(struct rtl_priv *rtlpriv, u32 addr, u16 val16)
2094 {
2095  rtlpriv->io.write16_async(rtlpriv, addr, val16);
2096 
2097  if (rtlpriv->cfg->write_readback)
2098  rtlpriv->io.read16_sync(rtlpriv, addr);
2099 }
2100 
2101 static inline void rtl_write_dword(struct rtl_priv *rtlpriv,
2102  u32 addr, u32 val32)
2103 {
2104  rtlpriv->io.write32_async(rtlpriv, addr, val32);
2105 
2106  if (rtlpriv->cfg->write_readback)
2107  rtlpriv->io.read32_sync(rtlpriv, addr);
2108 }
2109 
2110 static inline u32 rtl_get_bbreg(struct ieee80211_hw *hw,
2111  u32 regaddr, u32 bitmask)
2112 {
2113  struct rtl_priv *rtlpriv = hw->priv;
2114 
2115  return rtlpriv->cfg->ops->get_bbreg(hw, regaddr, bitmask);
2116 }
2117 
2118 static inline void rtl_set_bbreg(struct ieee80211_hw *hw, u32 regaddr,
2119  u32 bitmask, u32 data)
2120 {
2121  struct rtl_priv *rtlpriv = hw->priv;
2122 
2123  rtlpriv->cfg->ops->set_bbreg(hw, regaddr, bitmask, data);
2124 }
2125 
2126 static inline u32 rtl_get_rfreg(struct ieee80211_hw *hw,
2127  enum radio_path rfpath, u32 regaddr,
2128  u32 bitmask)
2129 {
2130  struct rtl_priv *rtlpriv = hw->priv;
2131 
2132  return rtlpriv->cfg->ops->get_rfreg(hw, rfpath, regaddr, bitmask);
2133 }
2134 
2135 static inline void rtl_set_rfreg(struct ieee80211_hw *hw,
2136  enum radio_path rfpath, u32 regaddr,
2137  u32 bitmask, u32 data)
2138 {
2139  struct rtl_priv *rtlpriv = hw->priv;
2140 
2141  rtlpriv->cfg->ops->set_rfreg(hw, rfpath, regaddr, bitmask, data);
2142 }
2143 
2144 static inline bool is_hal_stop(struct rtl_hal *rtlhal)
2145 {
2146  return (_HAL_STATE_STOP == rtlhal->state);
2147 }
2148 
2149 static inline void set_hal_start(struct rtl_hal *rtlhal)
2150 {
2151  rtlhal->state = _HAL_STATE_START;
2152 }
2153 
2154 static inline void set_hal_stop(struct rtl_hal *rtlhal)
2155 {
2156  rtlhal->state = _HAL_STATE_STOP;
2157 }
2158 
2159 static inline u8 get_rf_type(struct rtl_phy *rtlphy)
2160 {
2161  return rtlphy->rf_type;
2162 }
2163 
2164 static inline struct ieee80211_hdr *rtl_get_hdr(struct sk_buff *skb)
2165 {
2166  return (struct ieee80211_hdr *)(skb->data);
2167 }
2168 
2169 static inline __le16 rtl_get_fc(struct sk_buff *skb)
2170 {
2171  return rtl_get_hdr(skb)->frame_control;
2172 }
2173 
2174 static inline u16 rtl_get_tid_h(struct ieee80211_hdr *hdr)
2175 {
2176  return (ieee80211_get_qos_ctl(hdr))[0] & IEEE80211_QOS_CTL_TID_MASK;
2177 }
2178 
2179 static inline u16 rtl_get_tid(struct sk_buff *skb)
2180 {
2181  return rtl_get_tid_h(rtl_get_hdr(skb));
2182 }
2183 
2184 static inline struct ieee80211_sta *get_sta(struct ieee80211_hw *hw,
2185  struct ieee80211_vif *vif,
2186  const u8 *bssid)
2187 {
2188  return ieee80211_find_sta(vif, bssid);
2189 }
2190 
2191 static inline struct ieee80211_sta *rtl_find_sta(struct ieee80211_hw *hw,
2192  u8 *mac_addr)
2193 {
2194  struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
2195  return ieee80211_find_sta(mac->vif, mac_addr);
2196 }
2197 
2198 #endif