wifi.h 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2010 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 <wlanfae@realtek.com>
  23. * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  24. * Hsinchu 300, Taiwan.
  25. *
  26. * Larry Finger <Larry.Finger@lwfinger.net>
  27. *
  28. *****************************************************************************/
  29. #ifndef __RTL_WIFI_H__
  30. #define __RTL_WIFI_H__
  31. #include <linux/sched.h>
  32. #include <linux/firmware.h>
  33. #include <linux/version.h>
  34. #include <linux/etherdevice.h>
  35. #include <linux/vmalloc.h>
  36. #include <linux/usb.h>
  37. #include <net/mac80211.h>
  38. #include "debug.h"
  39. #define RF_CHANGE_BY_INIT 0
  40. #define RF_CHANGE_BY_IPS BIT(28)
  41. #define RF_CHANGE_BY_PS BIT(29)
  42. #define RF_CHANGE_BY_HW BIT(30)
  43. #define RF_CHANGE_BY_SW BIT(31)
  44. #define IQK_ADDA_REG_NUM 16
  45. #define IQK_MAC_REG_NUM 4
  46. #define MAX_KEY_LEN 61
  47. #define KEY_BUF_SIZE 5
  48. /* QoS related. */
  49. /*aci: 0x00 Best Effort*/
  50. /*aci: 0x01 Background*/
  51. /*aci: 0x10 Video*/
  52. /*aci: 0x11 Voice*/
  53. /*Max: define total number.*/
  54. #define AC0_BE 0
  55. #define AC1_BK 1
  56. #define AC2_VI 2
  57. #define AC3_VO 3
  58. #define AC_MAX 4
  59. #define QOS_QUEUE_NUM 4
  60. #define RTL_MAC80211_NUM_QUEUE 5
  61. #define QBSS_LOAD_SIZE 5
  62. #define MAX_WMMELE_LENGTH 64
  63. #define TOTAL_CAM_ENTRY 32
  64. /*slot time for 11g. */
  65. #define RTL_SLOT_TIME_9 9
  66. #define RTL_SLOT_TIME_20 20
  67. /*related with tcp/ip. */
  68. /*if_ehther.h*/
  69. #define ETH_P_PAE 0x888E /*Port Access Entity (IEEE 802.1X) */
  70. #define ETH_P_IP 0x0800 /*Internet Protocol packet */
  71. #define ETH_P_ARP 0x0806 /*Address Resolution packet */
  72. #define SNAP_SIZE 6
  73. #define PROTOC_TYPE_SIZE 2
  74. /*related with 802.11 frame*/
  75. #define MAC80211_3ADDR_LEN 24
  76. #define MAC80211_4ADDR_LEN 30
  77. #define CHANNEL_MAX_NUMBER (14 + 24 + 21) /* 14 is the max channel no */
  78. #define CHANNEL_GROUP_MAX (3 + 9) /* ch1~3, 4~9, 10~14 = three groups */
  79. #define MAX_PG_GROUP 13
  80. #define CHANNEL_GROUP_MAX_2G 3
  81. #define CHANNEL_GROUP_IDX_5GL 3
  82. #define CHANNEL_GROUP_IDX_5GM 6
  83. #define CHANNEL_GROUP_IDX_5GH 9
  84. #define CHANNEL_GROUP_MAX_5G 9
  85. #define CHANNEL_MAX_NUMBER_2G 14
  86. #define AVG_THERMAL_NUM 8
  87. #define MAX_TID_COUNT 9
  88. /* for early mode */
  89. #define FCS_LEN 4
  90. #define EM_HDR_LEN 8
  91. enum intf_type {
  92. INTF_PCI = 0,
  93. INTF_USB = 1,
  94. };
  95. enum radio_path {
  96. RF90_PATH_A = 0,
  97. RF90_PATH_B = 1,
  98. RF90_PATH_C = 2,
  99. RF90_PATH_D = 3,
  100. };
  101. enum rt_eeprom_type {
  102. EEPROM_93C46,
  103. EEPROM_93C56,
  104. EEPROM_BOOT_EFUSE,
  105. };
  106. enum rtl_status {
  107. RTL_STATUS_INTERFACE_START = 0,
  108. };
  109. enum hardware_type {
  110. HARDWARE_TYPE_RTL8192E,
  111. HARDWARE_TYPE_RTL8192U,
  112. HARDWARE_TYPE_RTL8192SE,
  113. HARDWARE_TYPE_RTL8192SU,
  114. HARDWARE_TYPE_RTL8192CE,
  115. HARDWARE_TYPE_RTL8192CU,
  116. HARDWARE_TYPE_RTL8192DE,
  117. HARDWARE_TYPE_RTL8192DU,
  118. HARDWARE_TYPE_RTL8723E,
  119. HARDWARE_TYPE_RTL8723U,
  120. /* keep it last */
  121. HARDWARE_TYPE_NUM
  122. };
  123. #define IS_HARDWARE_TYPE_8192SU(rtlhal) \
  124. (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SU)
  125. #define IS_HARDWARE_TYPE_8192SE(rtlhal) \
  126. (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SE)
  127. #define IS_HARDWARE_TYPE_8192CE(rtlhal) \
  128. (rtlhal->hw_type == HARDWARE_TYPE_RTL8192CE)
  129. #define IS_HARDWARE_TYPE_8192CU(rtlhal) \
  130. (rtlhal->hw_type == HARDWARE_TYPE_RTL8192CU)
  131. #define IS_HARDWARE_TYPE_8192DE(rtlhal) \
  132. (rtlhal->hw_type == HARDWARE_TYPE_RTL8192DE)
  133. #define IS_HARDWARE_TYPE_8192DU(rtlhal) \
  134. (rtlhal->hw_type == HARDWARE_TYPE_RTL8192DU)
  135. #define IS_HARDWARE_TYPE_8723E(rtlhal) \
  136. (rtlhal->hw_type == HARDWARE_TYPE_RTL8723E)
  137. #define IS_HARDWARE_TYPE_8723U(rtlhal) \
  138. (rtlhal->hw_type == HARDWARE_TYPE_RTL8723U)
  139. #define IS_HARDWARE_TYPE_8192S(rtlhal) \
  140. (IS_HARDWARE_TYPE_8192SE(rtlhal) || IS_HARDWARE_TYPE_8192SU(rtlhal))
  141. #define IS_HARDWARE_TYPE_8192C(rtlhal) \
  142. (IS_HARDWARE_TYPE_8192CE(rtlhal) || IS_HARDWARE_TYPE_8192CU(rtlhal))
  143. #define IS_HARDWARE_TYPE_8192D(rtlhal) \
  144. (IS_HARDWARE_TYPE_8192DE(rtlhal) || IS_HARDWARE_TYPE_8192DU(rtlhal))
  145. #define IS_HARDWARE_TYPE_8723(rtlhal) \
  146. (IS_HARDWARE_TYPE_8723E(rtlhal) || IS_HARDWARE_TYPE_8723U(rtlhal))
  147. #define IS_HARDWARE_TYPE_8723U(rtlhal) \
  148. (rtlhal->hw_type == HARDWARE_TYPE_RTL8723U)
  149. enum scan_operation_backup_opt {
  150. SCAN_OPT_BACKUP = 0,
  151. SCAN_OPT_RESTORE,
  152. SCAN_OPT_MAX
  153. };
  154. /*RF state.*/
  155. enum rf_pwrstate {
  156. ERFON,
  157. ERFSLEEP,
  158. ERFOFF
  159. };
  160. struct bb_reg_def {
  161. u32 rfintfs;
  162. u32 rfintfi;
  163. u32 rfintfo;
  164. u32 rfintfe;
  165. u32 rf3wire_offset;
  166. u32 rflssi_select;
  167. u32 rftxgain_stage;
  168. u32 rfhssi_para1;
  169. u32 rfhssi_para2;
  170. u32 rfswitch_control;
  171. u32 rfagc_control1;
  172. u32 rfagc_control2;
  173. u32 rfrxiq_imbalance;
  174. u32 rfrx_afe;
  175. u32 rftxiq_imbalance;
  176. u32 rftx_afe;
  177. u32 rflssi_readback;
  178. u32 rflssi_readbackpi;
  179. };
  180. enum io_type {
  181. IO_CMD_PAUSE_DM_BY_SCAN = 0,
  182. IO_CMD_RESUME_DM_BY_SCAN = 1,
  183. };
  184. enum hw_variables {
  185. HW_VAR_ETHER_ADDR,
  186. HW_VAR_MULTICAST_REG,
  187. HW_VAR_BASIC_RATE,
  188. HW_VAR_BSSID,
  189. HW_VAR_MEDIA_STATUS,
  190. HW_VAR_SECURITY_CONF,
  191. HW_VAR_BEACON_INTERVAL,
  192. HW_VAR_ATIM_WINDOW,
  193. HW_VAR_LISTEN_INTERVAL,
  194. HW_VAR_CS_COUNTER,
  195. HW_VAR_DEFAULTKEY0,
  196. HW_VAR_DEFAULTKEY1,
  197. HW_VAR_DEFAULTKEY2,
  198. HW_VAR_DEFAULTKEY3,
  199. HW_VAR_SIFS,
  200. HW_VAR_DIFS,
  201. HW_VAR_EIFS,
  202. HW_VAR_SLOT_TIME,
  203. HW_VAR_ACK_PREAMBLE,
  204. HW_VAR_CW_CONFIG,
  205. HW_VAR_CW_VALUES,
  206. HW_VAR_RATE_FALLBACK_CONTROL,
  207. HW_VAR_CONTENTION_WINDOW,
  208. HW_VAR_RETRY_COUNT,
  209. HW_VAR_TR_SWITCH,
  210. HW_VAR_COMMAND,
  211. HW_VAR_WPA_CONFIG,
  212. HW_VAR_AMPDU_MIN_SPACE,
  213. HW_VAR_SHORTGI_DENSITY,
  214. HW_VAR_AMPDU_FACTOR,
  215. HW_VAR_MCS_RATE_AVAILABLE,
  216. HW_VAR_AC_PARAM,
  217. HW_VAR_ACM_CTRL,
  218. HW_VAR_DIS_Req_Qsize,
  219. HW_VAR_CCX_CHNL_LOAD,
  220. HW_VAR_CCX_NOISE_HISTOGRAM,
  221. HW_VAR_CCX_CLM_NHM,
  222. HW_VAR_TxOPLimit,
  223. HW_VAR_TURBO_MODE,
  224. HW_VAR_RF_STATE,
  225. HW_VAR_RF_OFF_BY_HW,
  226. HW_VAR_BUS_SPEED,
  227. HW_VAR_SET_DEV_POWER,
  228. HW_VAR_RCR,
  229. HW_VAR_RATR_0,
  230. HW_VAR_RRSR,
  231. HW_VAR_CPU_RST,
  232. HW_VAR_CECHK_BSSID,
  233. HW_VAR_LBK_MODE,
  234. HW_VAR_AES_11N_FIX,
  235. HW_VAR_USB_RX_AGGR,
  236. HW_VAR_USER_CONTROL_TURBO_MODE,
  237. HW_VAR_RETRY_LIMIT,
  238. HW_VAR_INIT_TX_RATE,
  239. HW_VAR_TX_RATE_REG,
  240. HW_VAR_EFUSE_USAGE,
  241. HW_VAR_EFUSE_BYTES,
  242. HW_VAR_AUTOLOAD_STATUS,
  243. HW_VAR_RF_2R_DISABLE,
  244. HW_VAR_SET_RPWM,
  245. HW_VAR_H2C_FW_PWRMODE,
  246. HW_VAR_H2C_FW_JOINBSSRPT,
  247. HW_VAR_FW_PSMODE_STATUS,
  248. HW_VAR_1X1_RECV_COMBINE,
  249. HW_VAR_STOP_SEND_BEACON,
  250. HW_VAR_TSF_TIMER,
  251. HW_VAR_IO_CMD,
  252. HW_VAR_RF_RECOVERY,
  253. HW_VAR_H2C_FW_UPDATE_GTK,
  254. HW_VAR_WF_MASK,
  255. HW_VAR_WF_CRC,
  256. HW_VAR_WF_IS_MAC_ADDR,
  257. HW_VAR_H2C_FW_OFFLOAD,
  258. HW_VAR_RESET_WFCRC,
  259. HW_VAR_HANDLE_FW_C2H,
  260. HW_VAR_DL_FW_RSVD_PAGE,
  261. HW_VAR_AID,
  262. HW_VAR_HW_SEQ_ENABLE,
  263. HW_VAR_CORRECT_TSF,
  264. HW_VAR_BCN_VALID,
  265. HW_VAR_FWLPS_RF_ON,
  266. HW_VAR_DUAL_TSF_RST,
  267. HW_VAR_SWITCH_EPHY_WoWLAN,
  268. HW_VAR_INT_MIGRATION,
  269. HW_VAR_INT_AC,
  270. HW_VAR_RF_TIMING,
  271. HW_VAR_MRC,
  272. HW_VAR_MGT_FILTER,
  273. HW_VAR_CTRL_FILTER,
  274. HW_VAR_DATA_FILTER,
  275. };
  276. enum _RT_MEDIA_STATUS {
  277. RT_MEDIA_DISCONNECT = 0,
  278. RT_MEDIA_CONNECT = 1
  279. };
  280. enum rt_oem_id {
  281. RT_CID_DEFAULT = 0,
  282. RT_CID_8187_ALPHA0 = 1,
  283. RT_CID_8187_SERCOMM_PS = 2,
  284. RT_CID_8187_HW_LED = 3,
  285. RT_CID_8187_NETGEAR = 4,
  286. RT_CID_WHQL = 5,
  287. RT_CID_819x_CAMEO = 6,
  288. RT_CID_819x_RUNTOP = 7,
  289. RT_CID_819x_Senao = 8,
  290. RT_CID_TOSHIBA = 9,
  291. RT_CID_819x_Netcore = 10,
  292. RT_CID_Nettronix = 11,
  293. RT_CID_DLINK = 12,
  294. RT_CID_PRONET = 13,
  295. RT_CID_COREGA = 14,
  296. RT_CID_819x_ALPHA = 15,
  297. RT_CID_819x_Sitecom = 16,
  298. RT_CID_CCX = 17,
  299. RT_CID_819x_Lenovo = 18,
  300. RT_CID_819x_QMI = 19,
  301. RT_CID_819x_Edimax_Belkin = 20,
  302. RT_CID_819x_Sercomm_Belkin = 21,
  303. RT_CID_819x_CAMEO1 = 22,
  304. RT_CID_819x_MSI = 23,
  305. RT_CID_819x_Acer = 24,
  306. RT_CID_819x_HP = 27,
  307. RT_CID_819x_CLEVO = 28,
  308. RT_CID_819x_Arcadyan_Belkin = 29,
  309. RT_CID_819x_SAMSUNG = 30,
  310. RT_CID_819x_WNC_COREGA = 31,
  311. RT_CID_819x_Foxcoon = 32,
  312. RT_CID_819x_DELL = 33,
  313. };
  314. enum hw_descs {
  315. HW_DESC_OWN,
  316. HW_DESC_RXOWN,
  317. HW_DESC_TX_NEXTDESC_ADDR,
  318. HW_DESC_TXBUFF_ADDR,
  319. HW_DESC_RXBUFF_ADDR,
  320. HW_DESC_RXPKT_LEN,
  321. HW_DESC_RXERO,
  322. };
  323. enum prime_sc {
  324. PRIME_CHNL_OFFSET_DONT_CARE = 0,
  325. PRIME_CHNL_OFFSET_LOWER = 1,
  326. PRIME_CHNL_OFFSET_UPPER = 2,
  327. };
  328. enum rf_type {
  329. RF_1T1R = 0,
  330. RF_1T2R = 1,
  331. RF_2T2R = 2,
  332. RF_2T2R_GREEN = 3,
  333. };
  334. enum ht_channel_width {
  335. HT_CHANNEL_WIDTH_20 = 0,
  336. HT_CHANNEL_WIDTH_20_40 = 1,
  337. };
  338. /* Ref: 802.11i sepc D10.0 7.3.2.25.1
  339. Cipher Suites Encryption Algorithms */
  340. enum rt_enc_alg {
  341. NO_ENCRYPTION = 0,
  342. WEP40_ENCRYPTION = 1,
  343. TKIP_ENCRYPTION = 2,
  344. RSERVED_ENCRYPTION = 3,
  345. AESCCMP_ENCRYPTION = 4,
  346. WEP104_ENCRYPTION = 5,
  347. };
  348. enum rtl_hal_state {
  349. _HAL_STATE_STOP = 0,
  350. _HAL_STATE_START = 1,
  351. };
  352. enum rtl_var_map {
  353. /*reg map */
  354. SYS_ISO_CTRL = 0,
  355. SYS_FUNC_EN,
  356. SYS_CLK,
  357. MAC_RCR_AM,
  358. MAC_RCR_AB,
  359. MAC_RCR_ACRC32,
  360. MAC_RCR_ACF,
  361. MAC_RCR_AAP,
  362. /*efuse map */
  363. EFUSE_TEST,
  364. EFUSE_CTRL,
  365. EFUSE_CLK,
  366. EFUSE_CLK_CTRL,
  367. EFUSE_PWC_EV12V,
  368. EFUSE_FEN_ELDR,
  369. EFUSE_LOADER_CLK_EN,
  370. EFUSE_ANA8M,
  371. EFUSE_HWSET_MAX_SIZE,
  372. EFUSE_MAX_SECTION_MAP,
  373. EFUSE_REAL_CONTENT_SIZE,
  374. /*CAM map */
  375. RWCAM,
  376. WCAMI,
  377. RCAMO,
  378. CAMDBG,
  379. SECR,
  380. SEC_CAM_NONE,
  381. SEC_CAM_WEP40,
  382. SEC_CAM_TKIP,
  383. SEC_CAM_AES,
  384. SEC_CAM_WEP104,
  385. /*IMR map */
  386. RTL_IMR_BCNDMAINT6, /*Beacon DMA Interrupt 6 */
  387. RTL_IMR_BCNDMAINT5, /*Beacon DMA Interrupt 5 */
  388. RTL_IMR_BCNDMAINT4, /*Beacon DMA Interrupt 4 */
  389. RTL_IMR_BCNDMAINT3, /*Beacon DMA Interrupt 3 */
  390. RTL_IMR_BCNDMAINT2, /*Beacon DMA Interrupt 2 */
  391. RTL_IMR_BCNDMAINT1, /*Beacon DMA Interrupt 1 */
  392. RTL_IMR_BCNDOK8, /*Beacon Queue DMA OK Interrup 8 */
  393. RTL_IMR_BCNDOK7, /*Beacon Queue DMA OK Interrup 7 */
  394. RTL_IMR_BCNDOK6, /*Beacon Queue DMA OK Interrup 6 */
  395. RTL_IMR_BCNDOK5, /*Beacon Queue DMA OK Interrup 5 */
  396. RTL_IMR_BCNDOK4, /*Beacon Queue DMA OK Interrup 4 */
  397. RTL_IMR_BCNDOK3, /*Beacon Queue DMA OK Interrup 3 */
  398. RTL_IMR_BCNDOK2, /*Beacon Queue DMA OK Interrup 2 */
  399. RTL_IMR_BCNDOK1, /*Beacon Queue DMA OK Interrup 1 */
  400. RTL_IMR_TIMEOUT2, /*Timeout interrupt 2 */
  401. RTL_IMR_TIMEOUT1, /*Timeout interrupt 1 */
  402. RTL_IMR_TXFOVW, /*Transmit FIFO Overflow */
  403. RTL_IMR_PSTIMEOUT, /*Power save time out interrupt */
  404. RTL_IMR_BcnInt, /*Beacon DMA Interrupt 0 */
  405. RTL_IMR_RXFOVW, /*Receive FIFO Overflow */
  406. RTL_IMR_RDU, /*Receive Descriptor Unavailable */
  407. RTL_IMR_ATIMEND, /*For 92C,ATIM Window End Interrupt */
  408. RTL_IMR_BDOK, /*Beacon Queue DMA OK Interrup */
  409. RTL_IMR_HIGHDOK, /*High Queue DMA OK Interrupt */
  410. RTL_IMR_COMDOK, /*Command Queue DMA OK Interrupt*/
  411. RTL_IMR_TBDOK, /*Transmit Beacon OK interrup */
  412. RTL_IMR_MGNTDOK, /*Management Queue DMA OK Interrupt */
  413. RTL_IMR_TBDER, /*For 92C,Transmit Beacon Error Interrupt */
  414. RTL_IMR_BKDOK, /*AC_BK DMA OK Interrupt */
  415. RTL_IMR_BEDOK, /*AC_BE DMA OK Interrupt */
  416. RTL_IMR_VIDOK, /*AC_VI DMA OK Interrupt */
  417. RTL_IMR_VODOK, /*AC_VO DMA Interrupt */
  418. RTL_IMR_ROK, /*Receive DMA OK Interrupt */
  419. RTL_IBSS_INT_MASKS, /*(RTL_IMR_BcnInt | RTL_IMR_TBDOK |
  420. * RTL_IMR_TBDER) */
  421. /*CCK Rates, TxHT = 0 */
  422. RTL_RC_CCK_RATE1M,
  423. RTL_RC_CCK_RATE2M,
  424. RTL_RC_CCK_RATE5_5M,
  425. RTL_RC_CCK_RATE11M,
  426. /*OFDM Rates, TxHT = 0 */
  427. RTL_RC_OFDM_RATE6M,
  428. RTL_RC_OFDM_RATE9M,
  429. RTL_RC_OFDM_RATE12M,
  430. RTL_RC_OFDM_RATE18M,
  431. RTL_RC_OFDM_RATE24M,
  432. RTL_RC_OFDM_RATE36M,
  433. RTL_RC_OFDM_RATE48M,
  434. RTL_RC_OFDM_RATE54M,
  435. RTL_RC_HT_RATEMCS7,
  436. RTL_RC_HT_RATEMCS15,
  437. /*keep it last */
  438. RTL_VAR_MAP_MAX,
  439. };
  440. /*Firmware PS mode for control LPS.*/
  441. enum _fw_ps_mode {
  442. FW_PS_ACTIVE_MODE = 0,
  443. FW_PS_MIN_MODE = 1,
  444. FW_PS_MAX_MODE = 2,
  445. FW_PS_DTIM_MODE = 3,
  446. FW_PS_VOIP_MODE = 4,
  447. FW_PS_UAPSD_WMM_MODE = 5,
  448. FW_PS_UAPSD_MODE = 6,
  449. FW_PS_IBSS_MODE = 7,
  450. FW_PS_WWLAN_MODE = 8,
  451. FW_PS_PM_Radio_Off = 9,
  452. FW_PS_PM_Card_Disable = 10,
  453. };
  454. enum rt_psmode {
  455. EACTIVE, /*Active/Continuous access. */
  456. EMAXPS, /*Max power save mode. */
  457. EFASTPS, /*Fast power save mode. */
  458. EAUTOPS, /*Auto power save mode. */
  459. };
  460. /*LED related.*/
  461. enum led_ctl_mode {
  462. LED_CTL_POWER_ON = 1,
  463. LED_CTL_LINK = 2,
  464. LED_CTL_NO_LINK = 3,
  465. LED_CTL_TX = 4,
  466. LED_CTL_RX = 5,
  467. LED_CTL_SITE_SURVEY = 6,
  468. LED_CTL_POWER_OFF = 7,
  469. LED_CTL_START_TO_LINK = 8,
  470. LED_CTL_START_WPS = 9,
  471. LED_CTL_STOP_WPS = 10,
  472. };
  473. enum rtl_led_pin {
  474. LED_PIN_GPIO0,
  475. LED_PIN_LED0,
  476. LED_PIN_LED1,
  477. LED_PIN_LED2
  478. };
  479. /*QoS related.*/
  480. /*acm implementation method.*/
  481. enum acm_method {
  482. eAcmWay0_SwAndHw = 0,
  483. eAcmWay1_HW = 1,
  484. eAcmWay2_SW = 2,
  485. };
  486. enum macphy_mode {
  487. SINGLEMAC_SINGLEPHY = 0,
  488. DUALMAC_DUALPHY,
  489. DUALMAC_SINGLEPHY,
  490. };
  491. enum band_type {
  492. BAND_ON_2_4G = 0,
  493. BAND_ON_5G,
  494. BAND_ON_BOTH,
  495. BANDMAX
  496. };
  497. /*aci/aifsn Field.
  498. Ref: WMM spec 2.2.2: WME Parameter Element, p.12.*/
  499. union aci_aifsn {
  500. u8 char_data;
  501. struct {
  502. u8 aifsn:4;
  503. u8 acm:1;
  504. u8 aci:2;
  505. u8 reserved:1;
  506. } f; /* Field */
  507. };
  508. /*mlme related.*/
  509. enum wireless_mode {
  510. WIRELESS_MODE_UNKNOWN = 0x00,
  511. WIRELESS_MODE_A = 0x01,
  512. WIRELESS_MODE_B = 0x02,
  513. WIRELESS_MODE_G = 0x04,
  514. WIRELESS_MODE_AUTO = 0x08,
  515. WIRELESS_MODE_N_24G = 0x10,
  516. WIRELESS_MODE_N_5G = 0x20
  517. };
  518. #define IS_WIRELESS_MODE_A(wirelessmode) \
  519. (wirelessmode == WIRELESS_MODE_A)
  520. #define IS_WIRELESS_MODE_B(wirelessmode) \
  521. (wirelessmode == WIRELESS_MODE_B)
  522. #define IS_WIRELESS_MODE_G(wirelessmode) \
  523. (wirelessmode == WIRELESS_MODE_G)
  524. #define IS_WIRELESS_MODE_N_24G(wirelessmode) \
  525. (wirelessmode == WIRELESS_MODE_N_24G)
  526. #define IS_WIRELESS_MODE_N_5G(wirelessmode) \
  527. (wirelessmode == WIRELESS_MODE_N_5G)
  528. enum ratr_table_mode {
  529. RATR_INX_WIRELESS_NGB = 0,
  530. RATR_INX_WIRELESS_NG = 1,
  531. RATR_INX_WIRELESS_NB = 2,
  532. RATR_INX_WIRELESS_N = 3,
  533. RATR_INX_WIRELESS_GB = 4,
  534. RATR_INX_WIRELESS_G = 5,
  535. RATR_INX_WIRELESS_B = 6,
  536. RATR_INX_WIRELESS_MC = 7,
  537. RATR_INX_WIRELESS_A = 8,
  538. };
  539. enum rtl_link_state {
  540. MAC80211_NOLINK = 0,
  541. MAC80211_LINKING = 1,
  542. MAC80211_LINKED = 2,
  543. MAC80211_LINKED_SCANNING = 3,
  544. };
  545. enum act_category {
  546. ACT_CAT_QOS = 1,
  547. ACT_CAT_DLS = 2,
  548. ACT_CAT_BA = 3,
  549. ACT_CAT_HT = 7,
  550. ACT_CAT_WMM = 17,
  551. };
  552. enum ba_action {
  553. ACT_ADDBAREQ = 0,
  554. ACT_ADDBARSP = 1,
  555. ACT_DELBA = 2,
  556. };
  557. struct octet_string {
  558. u8 *octet;
  559. u16 length;
  560. };
  561. struct rtl_hdr_3addr {
  562. __le16 frame_ctl;
  563. __le16 duration_id;
  564. u8 addr1[ETH_ALEN];
  565. u8 addr2[ETH_ALEN];
  566. u8 addr3[ETH_ALEN];
  567. __le16 seq_ctl;
  568. u8 payload[0];
  569. } __packed;
  570. struct rtl_info_element {
  571. u8 id;
  572. u8 len;
  573. u8 data[0];
  574. } __packed;
  575. struct rtl_probe_rsp {
  576. struct rtl_hdr_3addr header;
  577. u32 time_stamp[2];
  578. __le16 beacon_interval;
  579. __le16 capability;
  580. /*SSID, supported rates, FH params, DS params,
  581. CF params, IBSS params, TIM (if beacon), RSN */
  582. struct rtl_info_element info_element[0];
  583. } __packed;
  584. /*LED related.*/
  585. /*ledpin Identify how to implement this SW led.*/
  586. struct rtl_led {
  587. void *hw;
  588. enum rtl_led_pin ledpin;
  589. bool ledon;
  590. };
  591. struct rtl_led_ctl {
  592. bool led_opendrain;
  593. struct rtl_led sw_led0;
  594. struct rtl_led sw_led1;
  595. };
  596. struct rtl_qos_parameters {
  597. __le16 cw_min;
  598. __le16 cw_max;
  599. u8 aifs;
  600. u8 flag;
  601. __le16 tx_op;
  602. } __packed;
  603. struct rt_smooth_data {
  604. u32 elements[100]; /*array to store values */
  605. u32 index; /*index to current array to store */
  606. u32 total_num; /*num of valid elements */
  607. u32 total_val; /*sum of valid elements */
  608. };
  609. struct false_alarm_statistics {
  610. u32 cnt_parity_fail;
  611. u32 cnt_rate_illegal;
  612. u32 cnt_crc8_fail;
  613. u32 cnt_mcs_fail;
  614. u32 cnt_fast_fsync_fail;
  615. u32 cnt_sb_search_fail;
  616. u32 cnt_ofdm_fail;
  617. u32 cnt_cck_fail;
  618. u32 cnt_all;
  619. };
  620. struct init_gain {
  621. u8 xaagccore1;
  622. u8 xbagccore1;
  623. u8 xcagccore1;
  624. u8 xdagccore1;
  625. u8 cca;
  626. };
  627. struct wireless_stats {
  628. unsigned long txbytesunicast;
  629. unsigned long txbytesmulticast;
  630. unsigned long txbytesbroadcast;
  631. unsigned long rxbytesunicast;
  632. long rx_snr_db[4];
  633. /*Correct smoothed ss in Dbm, only used
  634. in driver to report real power now. */
  635. long recv_signal_power;
  636. long signal_quality;
  637. long last_sigstrength_inpercent;
  638. u32 rssi_calculate_cnt;
  639. /*Transformed, in dbm. Beautified signal
  640. strength for UI, not correct. */
  641. long signal_strength;
  642. u8 rx_rssi_percentage[4];
  643. u8 rx_evm_percentage[2];
  644. struct rt_smooth_data ui_rssi;
  645. struct rt_smooth_data ui_link_quality;
  646. };
  647. struct rate_adaptive {
  648. u8 rate_adaptive_disabled;
  649. u8 ratr_state;
  650. u16 reserve;
  651. u32 high_rssi_thresh_for_ra;
  652. u32 high2low_rssi_thresh_for_ra;
  653. u8 low2high_rssi_thresh_for_ra40m;
  654. u32 low_rssi_thresh_for_ra40M;
  655. u8 low2high_rssi_thresh_for_ra20m;
  656. u32 low_rssi_thresh_for_ra20M;
  657. u32 upper_rssi_threshold_ratr;
  658. u32 middleupper_rssi_threshold_ratr;
  659. u32 middle_rssi_threshold_ratr;
  660. u32 middlelow_rssi_threshold_ratr;
  661. u32 low_rssi_threshold_ratr;
  662. u32 ultralow_rssi_threshold_ratr;
  663. u32 low_rssi_threshold_ratr_40m;
  664. u32 low_rssi_threshold_ratr_20m;
  665. u8 ping_rssi_enable;
  666. u32 ping_rssi_ratr;
  667. u32 ping_rssi_thresh_for_ra;
  668. u32 last_ratr;
  669. u8 pre_ratr_state;
  670. };
  671. struct regd_pair_mapping {
  672. u16 reg_dmnenum;
  673. u16 reg_5ghz_ctl;
  674. u16 reg_2ghz_ctl;
  675. };
  676. struct rtl_regulatory {
  677. char alpha2[2];
  678. u16 country_code;
  679. u16 max_power_level;
  680. u32 tp_scale;
  681. u16 current_rd;
  682. u16 current_rd_ext;
  683. int16_t power_limit;
  684. struct regd_pair_mapping *regpair;
  685. };
  686. struct rtl_rfkill {
  687. bool rfkill_state; /*0 is off, 1 is on */
  688. };
  689. #define IQK_MATRIX_REG_NUM 8
  690. #define IQK_MATRIX_SETTINGS_NUM (1 + 24 + 21)
  691. struct iqk_matrix_regs {
  692. bool iqk_done;
  693. long value[1][IQK_MATRIX_REG_NUM];
  694. };
  695. struct phy_parameters {
  696. u16 length;
  697. u32 *pdata;
  698. };
  699. enum hw_param_tab_index {
  700. PHY_REG_2T,
  701. PHY_REG_1T,
  702. PHY_REG_PG,
  703. RADIOA_2T,
  704. RADIOB_2T,
  705. RADIOA_1T,
  706. RADIOB_1T,
  707. MAC_REG,
  708. AGCTAB_2T,
  709. AGCTAB_1T,
  710. MAX_TAB
  711. };
  712. struct rtl_phy {
  713. struct bb_reg_def phyreg_def[4]; /*Radio A/B/C/D */
  714. struct init_gain initgain_backup;
  715. enum io_type current_io_type;
  716. u8 rf_mode;
  717. u8 rf_type;
  718. u8 current_chan_bw;
  719. u8 set_bwmode_inprogress;
  720. u8 sw_chnl_inprogress;
  721. u8 sw_chnl_stage;
  722. u8 sw_chnl_step;
  723. u8 current_channel;
  724. u8 h2c_box_num;
  725. u8 set_io_inprogress;
  726. u8 lck_inprogress;
  727. /* record for power tracking */
  728. s32 reg_e94;
  729. s32 reg_e9c;
  730. s32 reg_ea4;
  731. s32 reg_eac;
  732. s32 reg_eb4;
  733. s32 reg_ebc;
  734. s32 reg_ec4;
  735. s32 reg_ecc;
  736. u8 rfpienable;
  737. u8 reserve_0;
  738. u16 reserve_1;
  739. u32 reg_c04, reg_c08, reg_874;
  740. u32 adda_backup[16];
  741. u32 iqk_mac_backup[IQK_MAC_REG_NUM];
  742. u32 iqk_bb_backup[10];
  743. /* Dual mac */
  744. bool need_iqk;
  745. struct iqk_matrix_regs iqk_matrix_regsetting[IQK_MATRIX_SETTINGS_NUM];
  746. bool rfpi_enable;
  747. u8 pwrgroup_cnt;
  748. u8 cck_high_power;
  749. /* MAX_PG_GROUP groups of pwr diff by rates */
  750. u32 mcs_txpwrlevel_origoffset[MAX_PG_GROUP][16];
  751. u8 default_initialgain[4];
  752. /* the current Tx power level */
  753. u8 cur_cck_txpwridx;
  754. u8 cur_ofdm24g_txpwridx;
  755. u32 rfreg_chnlval[2];
  756. bool apk_done;
  757. u32 reg_rf3c[2]; /* pathA / pathB */
  758. /* bfsync */
  759. u8 framesync;
  760. u32 framesync_c34;
  761. u8 num_total_rfpath;
  762. struct phy_parameters hwparam_tables[MAX_TAB];
  763. u16 rf_pathmap;
  764. };
  765. #define MAX_TID_COUNT 9
  766. #define RTL_AGG_STOP 0
  767. #define RTL_AGG_PROGRESS 1
  768. #define RTL_AGG_START 2
  769. #define RTL_AGG_OPERATIONAL 3
  770. #define RTL_AGG_OFF 0
  771. #define RTL_AGG_ON 1
  772. #define RTL_AGG_EMPTYING_HW_QUEUE_ADDBA 2
  773. #define RTL_AGG_EMPTYING_HW_QUEUE_DELBA 3
  774. struct rtl_ht_agg {
  775. u16 txq_id;
  776. u16 wait_for_ba;
  777. u16 start_idx;
  778. u64 bitmap;
  779. u32 rate_n_flags;
  780. u8 agg_state;
  781. };
  782. struct rtl_tid_data {
  783. u16 seq_number;
  784. struct rtl_ht_agg agg;
  785. };
  786. struct rtl_sta_info {
  787. u8 ratr_index;
  788. u8 wireless_mode;
  789. u8 mimo_ps;
  790. struct rtl_tid_data tids[MAX_TID_COUNT];
  791. } __packed;
  792. struct rtl_priv;
  793. struct rtl_io {
  794. struct device *dev;
  795. struct mutex bb_mutex;
  796. /*PCI MEM map */
  797. unsigned long pci_mem_end; /*shared mem end */
  798. unsigned long pci_mem_start; /*shared mem start */
  799. /*PCI IO map */
  800. unsigned long pci_base_addr; /*device I/O address */
  801. void (*write8_async) (struct rtl_priv *rtlpriv, u32 addr, u8 val);
  802. void (*write16_async) (struct rtl_priv *rtlpriv, u32 addr, u16 val);
  803. void (*write32_async) (struct rtl_priv *rtlpriv, u32 addr, u32 val);
  804. int (*writeN_async) (struct rtl_priv *rtlpriv, u32 addr, u16 len,
  805. u8 *pdata);
  806. u8(*read8_sync) (struct rtl_priv *rtlpriv, u32 addr);
  807. u16(*read16_sync) (struct rtl_priv *rtlpriv, u32 addr);
  808. u32(*read32_sync) (struct rtl_priv *rtlpriv, u32 addr);
  809. int (*readN_sync) (struct rtl_priv *rtlpriv, u32 addr, u16 len,
  810. u8 *pdata);
  811. };
  812. struct rtl_mac {
  813. u8 mac_addr[ETH_ALEN];
  814. u8 mac80211_registered;
  815. u8 beacon_enabled;
  816. u32 tx_ss_num;
  817. u32 rx_ss_num;
  818. struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
  819. struct ieee80211_hw *hw;
  820. struct ieee80211_vif *vif;
  821. enum nl80211_iftype opmode;
  822. /*Probe Beacon management */
  823. struct rtl_tid_data tids[MAX_TID_COUNT];
  824. enum rtl_link_state link_state;
  825. int n_channels;
  826. int n_bitrates;
  827. bool offchan_delay;
  828. /*filters */
  829. u32 rx_conf;
  830. u16 rx_mgt_filter;
  831. u16 rx_ctrl_filter;
  832. u16 rx_data_filter;
  833. bool act_scanning;
  834. u8 cnt_after_linked;
  835. /* early mode */
  836. /* skb wait queue */
  837. struct sk_buff_head skb_waitq[MAX_TID_COUNT];
  838. u8 earlymode_threshold;
  839. /*RDG*/
  840. bool rdg_en;
  841. /*AP*/
  842. u8 bssid[6];
  843. u32 vendor;
  844. u8 mcs[16]; /* 16 bytes mcs for HT rates. */
  845. u32 basic_rates; /* b/g rates */
  846. u8 ht_enable;
  847. u8 sgi_40;
  848. u8 sgi_20;
  849. u8 bw_40;
  850. u8 mode; /* wireless mode */
  851. u8 slot_time;
  852. u8 short_preamble;
  853. u8 use_cts_protect;
  854. u8 cur_40_prime_sc;
  855. u8 cur_40_prime_sc_bk;
  856. u64 tsf;
  857. u8 retry_short;
  858. u8 retry_long;
  859. u16 assoc_id;
  860. /*IBSS*/
  861. int beacon_interval;
  862. /*AMPDU*/
  863. u8 min_space_cfg; /*For Min spacing configurations */
  864. u8 max_mss_density;
  865. u8 current_ampdu_factor;
  866. u8 current_ampdu_density;
  867. /*QOS & EDCA */
  868. struct ieee80211_tx_queue_params edca_param[RTL_MAC80211_NUM_QUEUE];
  869. struct rtl_qos_parameters ac[AC_MAX];
  870. };
  871. struct rtl_hal {
  872. struct ieee80211_hw *hw;
  873. enum intf_type interface;
  874. u16 hw_type; /*92c or 92d or 92s and so on */
  875. u8 ic_class;
  876. u8 oem_id;
  877. u32 version; /*version of chip */
  878. u8 state; /*stop 0, start 1 */
  879. /*firmware */
  880. u32 fwsize;
  881. u8 *pfirmware;
  882. u16 fw_version;
  883. u16 fw_subversion;
  884. bool h2c_setinprogress;
  885. u8 last_hmeboxnum;
  886. bool fw_ready;
  887. /*Reserve page start offset except beacon in TxQ. */
  888. u8 fw_rsvdpage_startoffset;
  889. u8 h2c_txcmd_seq;
  890. /* FW Cmd IO related */
  891. u16 fwcmd_iomap;
  892. u32 fwcmd_ioparam;
  893. bool set_fwcmd_inprogress;
  894. u8 current_fwcmd_io;
  895. /**/
  896. bool driver_going2unload;
  897. /*AMPDU init min space*/
  898. u8 minspace_cfg; /*For Min spacing configurations */
  899. /* Dual mac */
  900. enum macphy_mode macphymode;
  901. enum band_type current_bandtype; /* 0:2.4G, 1:5G */
  902. enum band_type current_bandtypebackup;
  903. enum band_type bandset;
  904. /* dual MAC 0--Mac0 1--Mac1 */
  905. u32 interfaceindex;
  906. /* just for DualMac S3S4 */
  907. u8 macphyctl_reg;
  908. bool earlymode_enable;
  909. /* Dual mac*/
  910. bool during_mac0init_radiob;
  911. bool during_mac1init_radioa;
  912. bool reloadtxpowerindex;
  913. /* True if IMR or IQK have done
  914. for 2.4G in scan progress */
  915. bool load_imrandiqk_setting_for2g;
  916. bool disable_amsdu_8k;
  917. };
  918. struct rtl_security {
  919. /*default 0 */
  920. bool use_sw_sec;
  921. bool being_setkey;
  922. bool use_defaultkey;
  923. /*Encryption Algorithm for Unicast Packet */
  924. enum rt_enc_alg pairwise_enc_algorithm;
  925. /*Encryption Algorithm for Brocast/Multicast */
  926. enum rt_enc_alg group_enc_algorithm;
  927. /*Cam Entry Bitmap */
  928. u32 hwsec_cam_bitmap;
  929. u8 hwsec_cam_sta_addr[TOTAL_CAM_ENTRY][ETH_ALEN];
  930. /*local Key buffer, indx 0 is for
  931. pairwise key 1-4 is for agoup key. */
  932. u8 key_buf[KEY_BUF_SIZE][MAX_KEY_LEN];
  933. u8 key_len[KEY_BUF_SIZE];
  934. /*The pointer of Pairwise Key,
  935. it always points to KeyBuf[4] */
  936. u8 *pairwise_key;
  937. };
  938. struct rtl_dm {
  939. /*PHY status for Dynamic Management */
  940. long entry_min_undecoratedsmoothed_pwdb;
  941. long undecorated_smoothed_pwdb; /*out dm */
  942. long entry_max_undecoratedsmoothed_pwdb;
  943. bool dm_initialgain_enable;
  944. bool dynamic_txpower_enable;
  945. bool current_turbo_edca;
  946. bool is_any_nonbepkts; /*out dm */
  947. bool is_cur_rdlstate;
  948. bool txpower_trackinginit;
  949. bool disable_framebursting;
  950. bool cck_inch14;
  951. bool txpower_tracking;
  952. bool useramask;
  953. bool rfpath_rxenable[4];
  954. bool inform_fw_driverctrldm;
  955. bool current_mrc_switch;
  956. u8 txpowercount;
  957. u8 thermalvalue_rxgain;
  958. u8 thermalvalue_iqk;
  959. u8 thermalvalue_lck;
  960. u8 thermalvalue;
  961. u8 last_dtp_lvl;
  962. u8 thermalvalue_avg[AVG_THERMAL_NUM];
  963. u8 thermalvalue_avg_index;
  964. bool done_txpower;
  965. u8 dynamic_txhighpower_lvl; /*Tx high power level */
  966. u8 dm_flag; /*Indicate each dynamic mechanism's status. */
  967. u8 dm_type;
  968. u8 txpower_track_control;
  969. bool interrupt_migration;
  970. bool disable_tx_int;
  971. char ofdm_index[2];
  972. char cck_index;
  973. };
  974. #define EFUSE_MAX_LOGICAL_SIZE 256
  975. struct rtl_efuse {
  976. bool autoLoad_ok;
  977. bool bootfromefuse;
  978. u16 max_physical_size;
  979. u8 efuse_map[2][EFUSE_MAX_LOGICAL_SIZE];
  980. u16 efuse_usedbytes;
  981. u8 efuse_usedpercentage;
  982. #ifdef EFUSE_REPG_WORKAROUND
  983. bool efuse_re_pg_sec1flag;
  984. u8 efuse_re_pg_data[8];
  985. #endif
  986. u8 autoload_failflag;
  987. u8 autoload_status;
  988. short epromtype;
  989. u16 eeprom_vid;
  990. u16 eeprom_did;
  991. u16 eeprom_svid;
  992. u16 eeprom_smid;
  993. u8 eeprom_oemid;
  994. u16 eeprom_channelplan;
  995. u8 eeprom_version;
  996. u8 board_type;
  997. u8 external_pa;
  998. u8 dev_addr[6];
  999. bool txpwr_fromeprom;
  1000. u8 eeprom_crystalcap;
  1001. u8 eeprom_tssi[2];
  1002. u8 eeprom_tssi_5g[3][2]; /* for 5GL/5GM/5GH band. */
  1003. u8 eeprom_pwrlimit_ht20[CHANNEL_GROUP_MAX];
  1004. u8 eeprom_pwrlimit_ht40[CHANNEL_GROUP_MAX];
  1005. u8 eeprom_chnlarea_txpwr_cck[2][CHANNEL_GROUP_MAX_2G];
  1006. u8 eeprom_chnlarea_txpwr_ht40_1s[2][CHANNEL_GROUP_MAX];
  1007. u8 eeprom_chnlarea_txpwr_ht40_2sdiif[2][CHANNEL_GROUP_MAX];
  1008. u8 txpwrlevel_cck[2][CHANNEL_MAX_NUMBER_2G];
  1009. u8 txpwrlevel_ht40_1s[2][CHANNEL_MAX_NUMBER]; /*For HT 40MHZ pwr */
  1010. u8 txpwrlevel_ht40_2s[2][CHANNEL_MAX_NUMBER]; /*For HT 40MHZ pwr */
  1011. u8 internal_pa_5g[2]; /* pathA / pathB */
  1012. u8 eeprom_c9;
  1013. u8 eeprom_cc;
  1014. /*For power group */
  1015. u8 eeprom_pwrgroup[2][3];
  1016. u8 pwrgroup_ht20[2][CHANNEL_MAX_NUMBER];
  1017. u8 pwrgroup_ht40[2][CHANNEL_MAX_NUMBER];
  1018. char txpwr_ht20diff[2][CHANNEL_MAX_NUMBER]; /*HT 20<->40 Pwr diff */
  1019. /*For HT<->legacy pwr diff*/
  1020. u8 txpwr_legacyhtdiff[2][CHANNEL_MAX_NUMBER];
  1021. u8 txpwr_safetyflag; /* Band edge enable flag */
  1022. u16 eeprom_txpowerdiff;
  1023. u8 legacy_httxpowerdiff; /* Legacy to HT rate power diff */
  1024. u8 antenna_txpwdiff[3];
  1025. u8 eeprom_regulatory;
  1026. u8 eeprom_thermalmeter;
  1027. u8 thermalmeter[2]; /*ThermalMeter, index 0 for RFIC0, 1 for RFIC1 */
  1028. u16 tssi_13dbm;
  1029. u8 crystalcap; /* CrystalCap. */
  1030. u8 delta_iqk;
  1031. u8 delta_lck;
  1032. u8 legacy_ht_txpowerdiff; /*Legacy to HT rate power diff */
  1033. bool apk_thermalmeterignore;
  1034. bool b1x1_recvcombine;
  1035. bool b1ss_support;
  1036. /*channel plan */
  1037. u8 channel_plan;
  1038. };
  1039. struct rtl_ps_ctl {
  1040. bool pwrdomain_protect;
  1041. bool in_powersavemode;
  1042. bool rfchange_inprogress;
  1043. bool swrf_processing;
  1044. bool hwradiooff;
  1045. /*
  1046. * just for PCIE ASPM
  1047. * If it supports ASPM, Offset[560h] = 0x40,
  1048. * otherwise Offset[560h] = 0x00.
  1049. * */
  1050. bool support_aspm;
  1051. bool support_backdoor;
  1052. /*for LPS */
  1053. enum rt_psmode dot11_psmode; /*Power save mode configured. */
  1054. bool swctrl_lps;
  1055. bool leisure_ps;
  1056. bool fwctrl_lps;
  1057. u8 fwctrl_psmode;
  1058. /*For Fw control LPS mode */
  1059. u8 reg_fwctrl_lps;
  1060. /*Record Fw PS mode status. */
  1061. bool fw_current_inpsmode;
  1062. u8 reg_max_lps_awakeintvl;
  1063. bool report_linked;
  1064. /*for IPS */
  1065. bool inactiveps;
  1066. u32 rfoff_reason;
  1067. /*RF OFF Level */
  1068. u32 cur_ps_level;
  1069. u32 reg_rfps_level;
  1070. /*just for PCIE ASPM */
  1071. u8 const_amdpci_aspm;
  1072. bool pwrdown_mode;
  1073. enum rf_pwrstate inactive_pwrstate;
  1074. enum rf_pwrstate rfpwr_state; /*cur power state */
  1075. /* for SW LPS*/
  1076. bool sw_ps_enabled;
  1077. bool state;
  1078. bool state_inap;
  1079. bool multi_buffered;
  1080. u16 nullfunc_seq;
  1081. unsigned int dtim_counter;
  1082. unsigned int sleep_ms;
  1083. unsigned long last_sleep_jiffies;
  1084. unsigned long last_awake_jiffies;
  1085. unsigned long last_delaylps_stamp_jiffies;
  1086. unsigned long last_dtim;
  1087. unsigned long last_beacon;
  1088. unsigned long last_action;
  1089. unsigned long last_slept;
  1090. };
  1091. struct rtl_stats {
  1092. u32 mac_time[2];
  1093. s8 rssi;
  1094. u8 signal;
  1095. u8 noise;
  1096. u16 rate; /*in 100 kbps */
  1097. u8 received_channel;
  1098. u8 control;
  1099. u8 mask;
  1100. u8 freq;
  1101. u16 len;
  1102. u64 tsf;
  1103. u32 beacon_time;
  1104. u8 nic_type;
  1105. u16 length;
  1106. u8 signalquality; /*in 0-100 index. */
  1107. /*
  1108. * Real power in dBm for this packet,
  1109. * no beautification and aggregation.
  1110. * */
  1111. s32 recvsignalpower;
  1112. s8 rxpower; /*in dBm Translate from PWdB */
  1113. u8 signalstrength; /*in 0-100 index. */
  1114. u16 hwerror:1;
  1115. u16 crc:1;
  1116. u16 icv:1;
  1117. u16 shortpreamble:1;
  1118. u16 antenna:1;
  1119. u16 decrypted:1;
  1120. u16 wakeup:1;
  1121. u32 timestamp_low;
  1122. u32 timestamp_high;
  1123. u8 rx_drvinfo_size;
  1124. u8 rx_bufshift;
  1125. bool isampdu;
  1126. bool isfirst_ampdu;
  1127. bool rx_is40Mhzpacket;
  1128. u32 rx_pwdb_all;
  1129. u8 rx_mimo_signalstrength[4]; /*in 0~100 index */
  1130. s8 rx_mimo_signalquality[2];
  1131. bool packet_matchbssid;
  1132. bool is_cck;
  1133. bool packet_toself;
  1134. bool packet_beacon; /*for rssi */
  1135. char cck_adc_pwdb[4]; /*for rx path selection */
  1136. };
  1137. struct rt_link_detect {
  1138. u32 num_tx_in4period[4];
  1139. u32 num_rx_in4period[4];
  1140. u32 num_tx_inperiod;
  1141. u32 num_rx_inperiod;
  1142. bool busytraffic;
  1143. bool higher_busytraffic;
  1144. bool higher_busyrxtraffic;
  1145. u32 tidtx_in4period[MAX_TID_COUNT][4];
  1146. u32 tidtx_inperiod[MAX_TID_COUNT];
  1147. bool higher_busytxtraffic[MAX_TID_COUNT];
  1148. };
  1149. struct rtl_tcb_desc {
  1150. u8 packet_bw:1;
  1151. u8 multicast:1;
  1152. u8 broadcast:1;
  1153. u8 rts_stbc:1;
  1154. u8 rts_enable:1;
  1155. u8 cts_enable:1;
  1156. u8 rts_use_shortpreamble:1;
  1157. u8 rts_use_shortgi:1;
  1158. u8 rts_sc:1;
  1159. u8 rts_bw:1;
  1160. u8 rts_rate;
  1161. u8 use_shortgi:1;
  1162. u8 use_shortpreamble:1;
  1163. u8 use_driver_rate:1;
  1164. u8 disable_ratefallback:1;
  1165. u8 ratr_index;
  1166. u8 mac_id;
  1167. u8 hw_rate;
  1168. u8 last_inipkt:1;
  1169. u8 cmd_or_init:1;
  1170. u8 queue_index;
  1171. /* early mode */
  1172. u8 empkt_num;
  1173. /* The max value by HW */
  1174. u32 empkt_len[5];
  1175. };
  1176. struct rtl_hal_ops {
  1177. int (*init_sw_vars) (struct ieee80211_hw *hw);
  1178. void (*deinit_sw_vars) (struct ieee80211_hw *hw);
  1179. void (*read_chip_version)(struct ieee80211_hw *hw);
  1180. void (*read_eeprom_info) (struct ieee80211_hw *hw);
  1181. void (*interrupt_recognized) (struct ieee80211_hw *hw,
  1182. u32 *p_inta, u32 *p_intb);
  1183. int (*hw_init) (struct ieee80211_hw *hw);
  1184. void (*hw_disable) (struct ieee80211_hw *hw);
  1185. void (*hw_suspend) (struct ieee80211_hw *hw);
  1186. void (*hw_resume) (struct ieee80211_hw *hw);
  1187. void (*enable_interrupt) (struct ieee80211_hw *hw);
  1188. void (*disable_interrupt) (struct ieee80211_hw *hw);
  1189. int (*set_network_type) (struct ieee80211_hw *hw,
  1190. enum nl80211_iftype type);
  1191. void (*set_chk_bssid)(struct ieee80211_hw *hw,
  1192. bool check_bssid);
  1193. void (*set_bw_mode) (struct ieee80211_hw *hw,
  1194. enum nl80211_channel_type ch_type);
  1195. u8(*switch_channel) (struct ieee80211_hw *hw);
  1196. void (*set_qos) (struct ieee80211_hw *hw, int aci);
  1197. void (*set_bcn_reg) (struct ieee80211_hw *hw);
  1198. void (*set_bcn_intv) (struct ieee80211_hw *hw);
  1199. void (*update_interrupt_mask) (struct ieee80211_hw *hw,
  1200. u32 add_msr, u32 rm_msr);
  1201. void (*get_hw_reg) (struct ieee80211_hw *hw, u8 variable, u8 *val);
  1202. void (*set_hw_reg) (struct ieee80211_hw *hw, u8 variable, u8 *val);
  1203. void (*update_rate_tbl) (struct ieee80211_hw *hw,
  1204. struct ieee80211_sta *sta, u8 rssi_level);
  1205. void (*update_rate_mask) (struct ieee80211_hw *hw, u8 rssi_level);
  1206. void (*fill_tx_desc) (struct ieee80211_hw *hw,
  1207. struct ieee80211_hdr *hdr, u8 *pdesc_tx,
  1208. struct ieee80211_tx_info *info,
  1209. struct sk_buff *skb, u8 hw_queue,
  1210. struct rtl_tcb_desc *ptcb_desc);
  1211. void (*fill_fake_txdesc) (struct ieee80211_hw *hw, u8 *pDesc,
  1212. u32 buffer_len, bool bIsPsPoll);
  1213. void (*fill_tx_cmddesc) (struct ieee80211_hw *hw, u8 *pdesc,
  1214. bool firstseg, bool lastseg,
  1215. struct sk_buff *skb);
  1216. bool (*cmd_send_packet)(struct ieee80211_hw *hw, struct sk_buff *skb);
  1217. bool (*query_rx_desc) (struct ieee80211_hw *hw,
  1218. struct rtl_stats *stats,
  1219. struct ieee80211_rx_status *rx_status,
  1220. u8 *pdesc, struct sk_buff *skb);
  1221. void (*set_channel_access) (struct ieee80211_hw *hw);
  1222. bool (*radio_onoff_checking) (struct ieee80211_hw *hw, u8 *valid);
  1223. void (*dm_watchdog) (struct ieee80211_hw *hw);
  1224. void (*scan_operation_backup) (struct ieee80211_hw *hw, u8 operation);
  1225. bool (*set_rf_power_state) (struct ieee80211_hw *hw,
  1226. enum rf_pwrstate rfpwr_state);
  1227. void (*led_control) (struct ieee80211_hw *hw,
  1228. enum led_ctl_mode ledaction);
  1229. void (*set_desc) (u8 *pdesc, bool istx, u8 desc_name, u8 *val);
  1230. u32 (*get_desc) (u8 *pdesc, bool istx, u8 desc_name);
  1231. void (*tx_polling) (struct ieee80211_hw *hw, u8 hw_queue);
  1232. void (*enable_hw_sec) (struct ieee80211_hw *hw);
  1233. void (*set_key) (struct ieee80211_hw *hw, u32 key_index,
  1234. u8 *macaddr, bool is_group, u8 enc_algo,
  1235. bool is_wepkey, bool clear_all);
  1236. void (*init_sw_leds) (struct ieee80211_hw *hw);
  1237. void (*deinit_sw_leds) (struct ieee80211_hw *hw);
  1238. u32 (*get_bbreg) (struct ieee80211_hw *hw, u32 regaddr, u32 bitmask);
  1239. void (*set_bbreg) (struct ieee80211_hw *hw, u32 regaddr, u32 bitmask,
  1240. u32 data);
  1241. u32 (*get_rfreg) (struct ieee80211_hw *hw, enum radio_path rfpath,
  1242. u32 regaddr, u32 bitmask);
  1243. void (*set_rfreg) (struct ieee80211_hw *hw, enum radio_path rfpath,
  1244. u32 regaddr, u32 bitmask, u32 data);
  1245. void (*linked_set_reg) (struct ieee80211_hw *hw);
  1246. bool (*phy_rf6052_config) (struct ieee80211_hw *hw);
  1247. void (*phy_rf6052_set_cck_txpower) (struct ieee80211_hw *hw,
  1248. u8 *powerlevel);
  1249. void (*phy_rf6052_set_ofdm_txpower) (struct ieee80211_hw *hw,
  1250. u8 *ppowerlevel, u8 channel);
  1251. bool (*config_bb_with_headerfile) (struct ieee80211_hw *hw,
  1252. u8 configtype);
  1253. bool (*config_bb_with_pgheaderfile) (struct ieee80211_hw *hw,
  1254. u8 configtype);
  1255. void (*phy_lc_calibrate) (struct ieee80211_hw *hw, bool is2t);
  1256. void (*phy_set_bw_mode_callback) (struct ieee80211_hw *hw);
  1257. void (*dm_dynamic_txpower) (struct ieee80211_hw *hw);
  1258. };
  1259. struct rtl_intf_ops {
  1260. /*com */
  1261. void (*read_efuse_byte)(struct ieee80211_hw *hw, u16 _offset, u8 *pbuf);
  1262. int (*adapter_start) (struct ieee80211_hw *hw);
  1263. void (*adapter_stop) (struct ieee80211_hw *hw);
  1264. int (*adapter_tx) (struct ieee80211_hw *hw, struct sk_buff *skb,
  1265. struct rtl_tcb_desc *ptcb_desc);
  1266. void (*flush)(struct ieee80211_hw *hw, bool drop);
  1267. int (*reset_trx_ring) (struct ieee80211_hw *hw);
  1268. bool (*waitq_insert) (struct ieee80211_hw *hw, struct sk_buff *skb);
  1269. /*pci */
  1270. void (*disable_aspm) (struct ieee80211_hw *hw);
  1271. void (*enable_aspm) (struct ieee80211_hw *hw);
  1272. /*usb */
  1273. };
  1274. struct rtl_mod_params {
  1275. /* default: 0 = using hardware encryption */
  1276. int sw_crypto;
  1277. /* default: 1 = using no linked power save */
  1278. bool inactiveps;
  1279. /* default: 1 = using linked sw power save */
  1280. bool swctrl_lps;
  1281. /* default: 1 = using linked fw power save */
  1282. bool fwctrl_lps;
  1283. };
  1284. struct rtl_hal_usbint_cfg {
  1285. /* data - rx */
  1286. u32 in_ep_num;
  1287. u32 rx_urb_num;
  1288. u32 rx_max_size;
  1289. /* op - rx */
  1290. void (*usb_rx_hdl)(struct ieee80211_hw *, struct sk_buff *);
  1291. void (*usb_rx_segregate_hdl)(struct ieee80211_hw *, struct sk_buff *,
  1292. struct sk_buff_head *);
  1293. /* tx */
  1294. void (*usb_tx_cleanup)(struct ieee80211_hw *, struct sk_buff *);
  1295. int (*usb_tx_post_hdl)(struct ieee80211_hw *, struct urb *,
  1296. struct sk_buff *);
  1297. struct sk_buff *(*usb_tx_aggregate_hdl)(struct ieee80211_hw *,
  1298. struct sk_buff_head *);
  1299. /* endpoint mapping */
  1300. int (*usb_endpoint_mapping)(struct ieee80211_hw *hw);
  1301. u16 (*usb_mq_to_hwq)(__le16 fc, u16 mac80211_queue_index);
  1302. };
  1303. struct rtl_hal_cfg {
  1304. u8 bar_id;
  1305. bool write_readback;
  1306. char *name;
  1307. char *fw_name;
  1308. struct rtl_hal_ops *ops;
  1309. struct rtl_mod_params *mod_params;
  1310. struct rtl_hal_usbint_cfg *usb_interface_cfg;
  1311. /*this map used for some registers or vars
  1312. defined int HAL but used in MAIN */
  1313. u32 maps[RTL_VAR_MAP_MAX];
  1314. };
  1315. struct rtl_locks {
  1316. /* mutex */
  1317. struct mutex conf_mutex;
  1318. /*spin lock */
  1319. spinlock_t ips_lock;
  1320. spinlock_t irq_th_lock;
  1321. spinlock_t h2c_lock;
  1322. spinlock_t rf_ps_lock;
  1323. spinlock_t rf_lock;
  1324. spinlock_t lps_lock;
  1325. spinlock_t waitq_lock;
  1326. /*Dual mac*/
  1327. spinlock_t cck_and_rw_pagea_lock;
  1328. };
  1329. struct rtl_works {
  1330. struct ieee80211_hw *hw;
  1331. /*timer */
  1332. struct timer_list watchdog_timer;
  1333. /*task */
  1334. struct tasklet_struct irq_tasklet;
  1335. struct tasklet_struct irq_prepare_bcn_tasklet;
  1336. /*work queue */
  1337. struct workqueue_struct *rtl_wq;
  1338. struct delayed_work watchdog_wq;
  1339. struct delayed_work ips_nic_off_wq;
  1340. /* For SW LPS */
  1341. struct delayed_work ps_work;
  1342. struct delayed_work ps_rfon_wq;
  1343. struct tasklet_struct ips_leave_tasklet;
  1344. };
  1345. struct rtl_debug {
  1346. u32 dbgp_type[DBGP_TYPE_MAX];
  1347. u32 global_debuglevel;
  1348. u64 global_debugcomponents;
  1349. /* add for proc debug */
  1350. struct proc_dir_entry *proc_dir;
  1351. char proc_name[20];
  1352. };
  1353. struct rtl_priv {
  1354. struct rtl_locks locks;
  1355. struct rtl_works works;
  1356. struct rtl_mac mac80211;
  1357. struct rtl_hal rtlhal;
  1358. struct rtl_regulatory regd;
  1359. struct rtl_rfkill rfkill;
  1360. struct rtl_io io;
  1361. struct rtl_phy phy;
  1362. struct rtl_dm dm;
  1363. struct rtl_security sec;
  1364. struct rtl_efuse efuse;
  1365. struct rtl_ps_ctl psc;
  1366. struct rate_adaptive ra;
  1367. struct wireless_stats stats;
  1368. struct rt_link_detect link_info;
  1369. struct false_alarm_statistics falsealm_cnt;
  1370. struct rtl_rate_priv *rate_priv;
  1371. struct rtl_debug dbg;
  1372. /*
  1373. *hal_cfg : for diff cards
  1374. *intf_ops : for diff interrface usb/pcie
  1375. */
  1376. struct rtl_hal_cfg *cfg;
  1377. struct rtl_intf_ops *intf_ops;
  1378. /*this var will be set by set_bit,
  1379. and was used to indicate status of
  1380. interface or hardware */
  1381. unsigned long status;
  1382. /*This must be the last item so
  1383. that it points to the data allocated
  1384. beyond this structure like:
  1385. rtl_pci_priv or rtl_usb_priv */
  1386. u8 priv[0];
  1387. };
  1388. #define rtl_priv(hw) (((struct rtl_priv *)(hw)->priv))
  1389. #define rtl_mac(rtlpriv) (&((rtlpriv)->mac80211))
  1390. #define rtl_hal(rtlpriv) (&((rtlpriv)->rtlhal))
  1391. #define rtl_efuse(rtlpriv) (&((rtlpriv)->efuse))
  1392. #define rtl_psc(rtlpriv) (&((rtlpriv)->psc))
  1393. /***************************************
  1394. Bluetooth Co-existence Related
  1395. ****************************************/
  1396. enum bt_ant_num {
  1397. ANT_X2 = 0,
  1398. ANT_X1 = 1,
  1399. };
  1400. enum bt_co_type {
  1401. BT_2WIRE = 0,
  1402. BT_ISSC_3WIRE = 1,
  1403. BT_ACCEL = 2,
  1404. BT_CSR_BC4 = 3,
  1405. BT_CSR_BC8 = 4,
  1406. BT_RTL8756 = 5,
  1407. };
  1408. enum bt_cur_state {
  1409. BT_OFF = 0,
  1410. BT_ON = 1,
  1411. };
  1412. enum bt_service_type {
  1413. BT_SCO = 0,
  1414. BT_A2DP = 1,
  1415. BT_HID = 2,
  1416. BT_HID_IDLE = 3,
  1417. BT_SCAN = 4,
  1418. BT_IDLE = 5,
  1419. BT_OTHER_ACTION = 6,
  1420. BT_BUSY = 7,
  1421. BT_OTHERBUSY = 8,
  1422. BT_PAN = 9,
  1423. };
  1424. enum bt_radio_shared {
  1425. BT_RADIO_SHARED = 0,
  1426. BT_RADIO_INDIVIDUAL = 1,
  1427. };
  1428. struct bt_coexist_info {
  1429. /* EEPROM BT info. */
  1430. u8 eeprom_bt_coexist;
  1431. u8 eeprom_bt_type;
  1432. u8 eeprom_bt_ant_num;
  1433. u8 eeprom_bt_ant_isolation;
  1434. u8 eeprom_bt_radio_shared;
  1435. u8 bt_coexistence;
  1436. u8 bt_ant_num;
  1437. u8 bt_coexist_type;
  1438. u8 bt_state;
  1439. u8 bt_cur_state; /* 0:on, 1:off */
  1440. u8 bt_ant_isolation; /* 0:good, 1:bad */
  1441. u8 bt_pape_ctrl; /* 0:SW, 1:SW/HW dynamic */
  1442. u8 bt_service;
  1443. u8 bt_radio_shared_type;
  1444. u8 bt_rfreg_origin_1e;
  1445. u8 bt_rfreg_origin_1f;
  1446. u8 bt_rssi_state;
  1447. u32 ratio_tx;
  1448. u32 ratio_pri;
  1449. u32 bt_edca_ul;
  1450. u32 bt_edca_dl;
  1451. bool init_set;
  1452. bool bt_busy_traffic;
  1453. bool bt_traffic_mode_set;
  1454. bool bt_non_traffic_mode_set;
  1455. bool fw_coexist_all_off;
  1456. bool sw_coexist_all_off;
  1457. u32 current_state;
  1458. u32 previous_state;
  1459. u8 bt_pre_rssi_state;
  1460. u8 reg_bt_iso;
  1461. u8 reg_bt_sco;
  1462. };
  1463. /****************************************
  1464. mem access macro define start
  1465. Call endian free function when
  1466. 1. Read/write packet content.
  1467. 2. Before write integer to IO.
  1468. 3. After read integer from IO.
  1469. ****************************************/
  1470. /* Convert little data endian to host ordering */
  1471. #define EF1BYTE(_val) \
  1472. ((u8)(_val))
  1473. #define EF2BYTE(_val) \
  1474. (le16_to_cpu(_val))
  1475. #define EF4BYTE(_val) \
  1476. (le32_to_cpu(_val))
  1477. /* Read data from memory */
  1478. #define READEF1BYTE(_ptr) \
  1479. EF1BYTE(*((u8 *)(_ptr)))
  1480. /* Read le16 data from memory and convert to host ordering */
  1481. #define READEF2BYTE(_ptr) \
  1482. EF2BYTE(*((u16 *)(_ptr)))
  1483. #define READEF4BYTE(_ptr) \
  1484. EF4BYTE(*((u32 *)(_ptr)))
  1485. /* Write data to memory */
  1486. #define WRITEEF1BYTE(_ptr, _val) \
  1487. (*((u8 *)(_ptr))) = EF1BYTE(_val)
  1488. /* Write le16 data to memory in host ordering */
  1489. #define WRITEEF2BYTE(_ptr, _val) \
  1490. (*((u16 *)(_ptr))) = EF2BYTE(_val)
  1491. #define WRITEEF4BYTE(_ptr, _val) \
  1492. (*((u16 *)(_ptr))) = EF2BYTE(_val)
  1493. /* Create a bit mask
  1494. * Examples:
  1495. * BIT_LEN_MASK_32(0) => 0x00000000
  1496. * BIT_LEN_MASK_32(1) => 0x00000001
  1497. * BIT_LEN_MASK_32(2) => 0x00000003
  1498. * BIT_LEN_MASK_32(32) => 0xFFFFFFFF
  1499. */
  1500. #define BIT_LEN_MASK_32(__bitlen) \
  1501. (0xFFFFFFFF >> (32 - (__bitlen)))
  1502. #define BIT_LEN_MASK_16(__bitlen) \
  1503. (0xFFFF >> (16 - (__bitlen)))
  1504. #define BIT_LEN_MASK_8(__bitlen) \
  1505. (0xFF >> (8 - (__bitlen)))
  1506. /* Create an offset bit mask
  1507. * Examples:
  1508. * BIT_OFFSET_LEN_MASK_32(0, 2) => 0x00000003
  1509. * BIT_OFFSET_LEN_MASK_32(16, 2) => 0x00030000
  1510. */
  1511. #define BIT_OFFSET_LEN_MASK_32(__bitoffset, __bitlen) \
  1512. (BIT_LEN_MASK_32(__bitlen) << (__bitoffset))
  1513. #define BIT_OFFSET_LEN_MASK_16(__bitoffset, __bitlen) \
  1514. (BIT_LEN_MASK_16(__bitlen) << (__bitoffset))
  1515. #define BIT_OFFSET_LEN_MASK_8(__bitoffset, __bitlen) \
  1516. (BIT_LEN_MASK_8(__bitlen) << (__bitoffset))
  1517. /*Description:
  1518. * Return 4-byte value in host byte ordering from
  1519. * 4-byte pointer in little-endian system.
  1520. */
  1521. #define LE_P4BYTE_TO_HOST_4BYTE(__pstart) \
  1522. (EF4BYTE(*((u32 *)(__pstart))))
  1523. #define LE_P2BYTE_TO_HOST_2BYTE(__pstart) \
  1524. (EF2BYTE(*((u16 *)(__pstart))))
  1525. #define LE_P1BYTE_TO_HOST_1BYTE(__pstart) \
  1526. (EF1BYTE(*((u8 *)(__pstart))))
  1527. /*Description:
  1528. Translate subfield (continuous bits in little-endian) of 4-byte
  1529. value to host byte ordering.*/
  1530. #define LE_BITS_TO_4BYTE(__pstart, __bitoffset, __bitlen) \
  1531. ( \
  1532. (LE_P4BYTE_TO_HOST_4BYTE(__pstart) >> (__bitoffset)) & \
  1533. BIT_LEN_MASK_32(__bitlen) \
  1534. )
  1535. #define LE_BITS_TO_2BYTE(__pstart, __bitoffset, __bitlen) \
  1536. ( \
  1537. (LE_P2BYTE_TO_HOST_2BYTE(__pstart) >> (__bitoffset)) & \
  1538. BIT_LEN_MASK_16(__bitlen) \
  1539. )
  1540. #define LE_BITS_TO_1BYTE(__pstart, __bitoffset, __bitlen) \
  1541. ( \
  1542. (LE_P1BYTE_TO_HOST_1BYTE(__pstart) >> (__bitoffset)) & \
  1543. BIT_LEN_MASK_8(__bitlen) \
  1544. )
  1545. /* Description:
  1546. * Mask subfield (continuous bits in little-endian) of 4-byte value
  1547. * and return the result in 4-byte value in host byte ordering.
  1548. */
  1549. #define LE_BITS_CLEARED_TO_4BYTE(__pstart, __bitoffset, __bitlen) \
  1550. ( \
  1551. LE_P4BYTE_TO_HOST_4BYTE(__pstart) & \
  1552. (~BIT_OFFSET_LEN_MASK_32(__bitoffset, __bitlen)) \
  1553. )
  1554. #define LE_BITS_CLEARED_TO_2BYTE(__pstart, __bitoffset, __bitlen) \
  1555. ( \
  1556. LE_P2BYTE_TO_HOST_2BYTE(__pstart) & \
  1557. (~BIT_OFFSET_LEN_MASK_16(__bitoffset, __bitlen)) \
  1558. )
  1559. #define LE_BITS_CLEARED_TO_1BYTE(__pstart, __bitoffset, __bitlen) \
  1560. ( \
  1561. LE_P1BYTE_TO_HOST_1BYTE(__pstart) & \
  1562. (~BIT_OFFSET_LEN_MASK_8(__bitoffset, __bitlen)) \
  1563. )
  1564. /* Description:
  1565. * Set subfield of little-endian 4-byte value to specified value.
  1566. */
  1567. #define SET_BITS_TO_LE_4BYTE(__pstart, __bitoffset, __bitlen, __val) \
  1568. *((u32 *)(__pstart)) = EF4BYTE \
  1569. ( \
  1570. LE_BITS_CLEARED_TO_4BYTE(__pstart, __bitoffset, __bitlen) | \
  1571. ((((u32)__val) & BIT_LEN_MASK_32(__bitlen)) << (__bitoffset)) \
  1572. );
  1573. #define SET_BITS_TO_LE_2BYTE(__pstart, __bitoffset, __bitlen, __val) \
  1574. *((u16 *)(__pstart)) = EF2BYTE \
  1575. ( \
  1576. LE_BITS_CLEARED_TO_2BYTE(__pstart, __bitoffset, __bitlen) | \
  1577. ((((u16)__val) & BIT_LEN_MASK_16(__bitlen)) << (__bitoffset)) \
  1578. );
  1579. #define SET_BITS_TO_LE_1BYTE(__pstart, __bitoffset, __bitlen, __val) \
  1580. *((u8 *)(__pstart)) = EF1BYTE \
  1581. ( \
  1582. LE_BITS_CLEARED_TO_1BYTE(__pstart, __bitoffset, __bitlen) | \
  1583. ((((u8)__val) & BIT_LEN_MASK_8(__bitlen)) << (__bitoffset)) \
  1584. );
  1585. #define N_BYTE_ALIGMENT(__value, __aligment) ((__aligment == 1) ? \
  1586. (__value) : (((__value + __aligment - 1) / __aligment) * __aligment))
  1587. /****************************************
  1588. mem access macro define end
  1589. ****************************************/
  1590. #define byte(x, n) ((x >> (8 * n)) & 0xff)
  1591. #define packet_get_type(_packet) (EF1BYTE((_packet).octet[0]) & 0xFC)
  1592. #define RTL_WATCH_DOG_TIME 2000
  1593. #define MSECS(t) msecs_to_jiffies(t)
  1594. #define WLAN_FC_GET_VERS(fc) (le16_to_cpu(fc) & IEEE80211_FCTL_VERS)
  1595. #define WLAN_FC_GET_TYPE(fc) (le16_to_cpu(fc) & IEEE80211_FCTL_FTYPE)
  1596. #define WLAN_FC_GET_STYPE(fc) (le16_to_cpu(fc) & IEEE80211_FCTL_STYPE)
  1597. #define WLAN_FC_MORE_DATA(fc) (le16_to_cpu(fc) & IEEE80211_FCTL_MOREDATA)
  1598. #define SEQ_TO_SN(seq) (((seq) & IEEE80211_SCTL_SEQ) >> 4)
  1599. #define SN_TO_SEQ(ssn) (((ssn) << 4) & IEEE80211_SCTL_SEQ)
  1600. #define MAX_SN ((IEEE80211_SCTL_SEQ) >> 4)
  1601. #define RT_RF_OFF_LEVL_ASPM BIT(0) /*PCI ASPM */
  1602. #define RT_RF_OFF_LEVL_CLK_REQ BIT(1) /*PCI clock request */
  1603. #define RT_RF_OFF_LEVL_PCI_D3 BIT(2) /*PCI D3 mode */
  1604. /*NIC halt, re-initialize hw parameters*/
  1605. #define RT_RF_OFF_LEVL_HALT_NIC BIT(3)
  1606. #define RT_RF_OFF_LEVL_FREE_FW BIT(4) /*FW free, re-download the FW */
  1607. #define RT_RF_OFF_LEVL_FW_32K BIT(5) /*FW in 32k */
  1608. /*Always enable ASPM and Clock Req in initialization.*/
  1609. #define RT_RF_PS_LEVEL_ALWAYS_ASPM BIT(6)
  1610. /* no matter RFOFF or SLEEP we set PS_ASPM_LEVL*/
  1611. #define RT_PS_LEVEL_ASPM BIT(7)
  1612. /*When LPS is on, disable 2R if no packet is received or transmittd.*/
  1613. #define RT_RF_LPS_DISALBE_2R BIT(30)
  1614. #define RT_RF_LPS_LEVEL_ASPM BIT(31) /*LPS with ASPM */
  1615. #define RT_IN_PS_LEVEL(ppsc, _ps_flg) \
  1616. ((ppsc->cur_ps_level & _ps_flg) ? true : false)
  1617. #define RT_CLEAR_PS_LEVEL(ppsc, _ps_flg) \
  1618. (ppsc->cur_ps_level &= (~(_ps_flg)))
  1619. #define RT_SET_PS_LEVEL(ppsc, _ps_flg) \
  1620. (ppsc->cur_ps_level |= _ps_flg)
  1621. #define container_of_dwork_rtl(x, y, z) \
  1622. container_of(container_of(x, struct delayed_work, work), y, z)
  1623. #define FILL_OCTET_STRING(_os, _octet, _len) \
  1624. (_os).octet = (u8 *)(_octet); \
  1625. (_os).length = (_len);
  1626. #define CP_MACADDR(des, src) \
  1627. ((des)[0] = (src)[0], (des)[1] = (src)[1],\
  1628. (des)[2] = (src)[2], (des)[3] = (src)[3],\
  1629. (des)[4] = (src)[4], (des)[5] = (src)[5])
  1630. static inline u8 rtl_read_byte(struct rtl_priv *rtlpriv, u32 addr)
  1631. {
  1632. return rtlpriv->io.read8_sync(rtlpriv, addr);
  1633. }
  1634. static inline u16 rtl_read_word(struct rtl_priv *rtlpriv, u32 addr)
  1635. {
  1636. return rtlpriv->io.read16_sync(rtlpriv, addr);
  1637. }
  1638. static inline u32 rtl_read_dword(struct rtl_priv *rtlpriv, u32 addr)
  1639. {
  1640. return rtlpriv->io.read32_sync(rtlpriv, addr);
  1641. }
  1642. static inline void rtl_write_byte(struct rtl_priv *rtlpriv, u32 addr, u8 val8)
  1643. {
  1644. rtlpriv->io.write8_async(rtlpriv, addr, val8);
  1645. if (rtlpriv->cfg->write_readback)
  1646. rtlpriv->io.read8_sync(rtlpriv, addr);
  1647. }
  1648. static inline void rtl_write_word(struct rtl_priv *rtlpriv, u32 addr, u16 val16)
  1649. {
  1650. rtlpriv->io.write16_async(rtlpriv, addr, val16);
  1651. if (rtlpriv->cfg->write_readback)
  1652. rtlpriv->io.read16_sync(rtlpriv, addr);
  1653. }
  1654. static inline void rtl_write_dword(struct rtl_priv *rtlpriv,
  1655. u32 addr, u32 val32)
  1656. {
  1657. rtlpriv->io.write32_async(rtlpriv, addr, val32);
  1658. if (rtlpriv->cfg->write_readback)
  1659. rtlpriv->io.read32_sync(rtlpriv, addr);
  1660. }
  1661. static inline u32 rtl_get_bbreg(struct ieee80211_hw *hw,
  1662. u32 regaddr, u32 bitmask)
  1663. {
  1664. return ((struct rtl_priv *)(hw)->priv)->cfg->ops->get_bbreg(hw,
  1665. regaddr,
  1666. bitmask);
  1667. }
  1668. static inline void rtl_set_bbreg(struct ieee80211_hw *hw, u32 regaddr,
  1669. u32 bitmask, u32 data)
  1670. {
  1671. ((struct rtl_priv *)(hw)->priv)->cfg->ops->set_bbreg(hw,
  1672. regaddr, bitmask,
  1673. data);
  1674. }
  1675. static inline u32 rtl_get_rfreg(struct ieee80211_hw *hw,
  1676. enum radio_path rfpath, u32 regaddr,
  1677. u32 bitmask)
  1678. {
  1679. return ((struct rtl_priv *)(hw)->priv)->cfg->ops->get_rfreg(hw,
  1680. rfpath,
  1681. regaddr,
  1682. bitmask);
  1683. }
  1684. static inline void rtl_set_rfreg(struct ieee80211_hw *hw,
  1685. enum radio_path rfpath, u32 regaddr,
  1686. u32 bitmask, u32 data)
  1687. {
  1688. ((struct rtl_priv *)(hw)->priv)->cfg->ops->set_rfreg(hw,
  1689. rfpath, regaddr,
  1690. bitmask, data);
  1691. }
  1692. static inline bool is_hal_stop(struct rtl_hal *rtlhal)
  1693. {
  1694. return (_HAL_STATE_STOP == rtlhal->state);
  1695. }
  1696. static inline void set_hal_start(struct rtl_hal *rtlhal)
  1697. {
  1698. rtlhal->state = _HAL_STATE_START;
  1699. }
  1700. static inline void set_hal_stop(struct rtl_hal *rtlhal)
  1701. {
  1702. rtlhal->state = _HAL_STATE_STOP;
  1703. }
  1704. static inline u8 get_rf_type(struct rtl_phy *rtlphy)
  1705. {
  1706. return rtlphy->rf_type;
  1707. }
  1708. static inline struct ieee80211_hdr *rtl_get_hdr(struct sk_buff *skb)
  1709. {
  1710. return (struct ieee80211_hdr *)(skb->data);
  1711. }
  1712. static inline __le16 rtl_get_fc(struct sk_buff *skb)
  1713. {
  1714. return rtl_get_hdr(skb)->frame_control;
  1715. }
  1716. static inline u16 rtl_get_tid_h(struct ieee80211_hdr *hdr)
  1717. {
  1718. return (ieee80211_get_qos_ctl(hdr))[0] & IEEE80211_QOS_CTL_TID_MASK;
  1719. }
  1720. static inline u16 rtl_get_tid(struct sk_buff *skb)
  1721. {
  1722. return rtl_get_tid_h(rtl_get_hdr(skb));
  1723. }
  1724. static inline struct ieee80211_sta *get_sta(struct ieee80211_hw *hw,
  1725. struct ieee80211_vif *vif,
  1726. const u8 *bssid)
  1727. {
  1728. return ieee80211_find_sta(vif, bssid);
  1729. }
  1730. #endif