wifi.h 47 KB

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