wifi.h 48 KB

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