wifi.h 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474
  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 AVG_THERMAL_NUM_88E 4
  87. #define MAX_TID_COUNT 9
  88. /* for early mode */
  89. #define FCS_LEN 4
  90. #define EM_HDR_LEN 8
  91. #define MAX_TX_COUNT 4
  92. #define MAX_RF_PATH 4
  93. #define MAX_CHNL_GROUP_24G 6
  94. #define MAX_CHNL_GROUP_5G 14
  95. struct txpower_info_2g {
  96. u8 index_cck_base[MAX_RF_PATH][MAX_CHNL_GROUP_24G];
  97. u8 index_bw40_base[MAX_RF_PATH][MAX_CHNL_GROUP_24G];
  98. /*If only one tx, only BW20 and OFDM are used.*/
  99. u8 cck_diff[MAX_RF_PATH][MAX_TX_COUNT];
  100. u8 ofdm_diff[MAX_RF_PATH][MAX_TX_COUNT];
  101. u8 bw20_diff[MAX_RF_PATH][MAX_TX_COUNT];
  102. u8 bw40_diff[MAX_RF_PATH][MAX_TX_COUNT];
  103. };
  104. struct txpower_info_5g {
  105. u8 index_bw40_base[MAX_RF_PATH][MAX_CHNL_GROUP_5G];
  106. /*If only one tx, only BW20, OFDM, BW80 and BW160 are used.*/
  107. u8 ofdm_diff[MAX_RF_PATH][MAX_TX_COUNT];
  108. u8 bw20_diff[MAX_RF_PATH][MAX_TX_COUNT];
  109. u8 bw40_diff[MAX_RF_PATH][MAX_TX_COUNT];
  110. };
  111. enum intf_type {
  112. INTF_PCI = 0,
  113. INTF_USB = 1,
  114. };
  115. enum radio_path {
  116. RF90_PATH_A = 0,
  117. RF90_PATH_B = 1,
  118. RF90_PATH_C = 2,
  119. RF90_PATH_D = 3,
  120. };
  121. enum rt_eeprom_type {
  122. EEPROM_93C46,
  123. EEPROM_93C56,
  124. EEPROM_BOOT_EFUSE,
  125. };
  126. enum ttl_status {
  127. RTL_STATUS_INTERFACE_START = 0,
  128. };
  129. enum hardware_type {
  130. HARDWARE_TYPE_RTL8192E,
  131. HARDWARE_TYPE_RTL8192U,
  132. HARDWARE_TYPE_RTL8192SE,
  133. HARDWARE_TYPE_RTL8192SU,
  134. HARDWARE_TYPE_RTL8192CE,
  135. HARDWARE_TYPE_RTL8192CU,
  136. HARDWARE_TYPE_RTL8192DE,
  137. HARDWARE_TYPE_RTL8192DU,
  138. HARDWARE_TYPE_RTL8723AE,
  139. HARDWARE_TYPE_RTL8723U,
  140. HARDWARE_TYPE_RTL8188EE,
  141. /* keep it last */
  142. HARDWARE_TYPE_NUM
  143. };
  144. #define IS_HARDWARE_TYPE_8192SU(rtlhal) \
  145. (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SU)
  146. #define IS_HARDWARE_TYPE_8192SE(rtlhal) \
  147. (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SE)
  148. #define IS_HARDWARE_TYPE_8192CE(rtlhal) \
  149. (rtlhal->hw_type == HARDWARE_TYPE_RTL8192CE)
  150. #define IS_HARDWARE_TYPE_8192CU(rtlhal) \
  151. (rtlhal->hw_type == HARDWARE_TYPE_RTL8192CU)
  152. #define IS_HARDWARE_TYPE_8192DE(rtlhal) \
  153. (rtlhal->hw_type == HARDWARE_TYPE_RTL8192DE)
  154. #define IS_HARDWARE_TYPE_8192DU(rtlhal) \
  155. (rtlhal->hw_type == HARDWARE_TYPE_RTL8192DU)
  156. #define IS_HARDWARE_TYPE_8723E(rtlhal) \
  157. (rtlhal->hw_type == HARDWARE_TYPE_RTL8723E)
  158. #define IS_HARDWARE_TYPE_8723U(rtlhal) \
  159. (rtlhal->hw_type == HARDWARE_TYPE_RTL8723U)
  160. #define IS_HARDWARE_TYPE_8192S(rtlhal) \
  161. (IS_HARDWARE_TYPE_8192SE(rtlhal) || IS_HARDWARE_TYPE_8192SU(rtlhal))
  162. #define IS_HARDWARE_TYPE_8192C(rtlhal) \
  163. (IS_HARDWARE_TYPE_8192CE(rtlhal) || IS_HARDWARE_TYPE_8192CU(rtlhal))
  164. #define IS_HARDWARE_TYPE_8192D(rtlhal) \
  165. (IS_HARDWARE_TYPE_8192DE(rtlhal) || IS_HARDWARE_TYPE_8192DU(rtlhal))
  166. #define IS_HARDWARE_TYPE_8723(rtlhal) \
  167. (IS_HARDWARE_TYPE_8723E(rtlhal) || IS_HARDWARE_TYPE_8723U(rtlhal))
  168. #define RX_HAL_IS_CCK_RATE(_pdesc)\
  169. (_pdesc->rxmcs == DESC92_RATE1M || \
  170. _pdesc->rxmcs == DESC92_RATE2M || \
  171. _pdesc->rxmcs == DESC92_RATE5_5M || \
  172. _pdesc->rxmcs == DESC92_RATE11M)
  173. enum scan_operation_backup_opt {
  174. SCAN_OPT_BACKUP = 0,
  175. SCAN_OPT_RESTORE,
  176. SCAN_OPT_MAX
  177. };
  178. /*RF state.*/
  179. enum rf_pwrstate {
  180. ERFON,
  181. ERFSLEEP,
  182. ERFOFF
  183. };
  184. struct bb_reg_def {
  185. u32 rfintfs;
  186. u32 rfintfi;
  187. u32 rfintfo;
  188. u32 rfintfe;
  189. u32 rf3wire_offset;
  190. u32 rflssi_select;
  191. u32 rftxgain_stage;
  192. u32 rfhssi_para1;
  193. u32 rfhssi_para2;
  194. u32 rfsw_ctrl;
  195. u32 rfagc_control1;
  196. u32 rfagc_control2;
  197. u32 rfrxiq_imbal;
  198. u32 rfrx_afe;
  199. u32 rftxiq_imbal;
  200. u32 rftx_afe;
  201. u32 rf_rb; /* rflssi_readback */
  202. u32 rf_rbpi; /* rflssi_readbackpi */
  203. };
  204. enum io_type {
  205. IO_CMD_PAUSE_DM_BY_SCAN = 0,
  206. IO_CMD_RESUME_DM_BY_SCAN = 1,
  207. };
  208. enum hw_variables {
  209. HW_VAR_ETHER_ADDR,
  210. HW_VAR_MULTICAST_REG,
  211. HW_VAR_BASIC_RATE,
  212. HW_VAR_BSSID,
  213. HW_VAR_MEDIA_STATUS,
  214. HW_VAR_SECURITY_CONF,
  215. HW_VAR_BEACON_INTERVAL,
  216. HW_VAR_ATIM_WINDOW,
  217. HW_VAR_LISTEN_INTERVAL,
  218. HW_VAR_CS_COUNTER,
  219. HW_VAR_DEFAULTKEY0,
  220. HW_VAR_DEFAULTKEY1,
  221. HW_VAR_DEFAULTKEY2,
  222. HW_VAR_DEFAULTKEY3,
  223. HW_VAR_SIFS,
  224. HW_VAR_DIFS,
  225. HW_VAR_EIFS,
  226. HW_VAR_SLOT_TIME,
  227. HW_VAR_ACK_PREAMBLE,
  228. HW_VAR_CW_CONFIG,
  229. HW_VAR_CW_VALUES,
  230. HW_VAR_RATE_FALLBACK_CONTROL,
  231. HW_VAR_CONTENTION_WINDOW,
  232. HW_VAR_RETRY_COUNT,
  233. HW_VAR_TR_SWITCH,
  234. HW_VAR_COMMAND,
  235. HW_VAR_WPA_CONFIG,
  236. HW_VAR_AMPDU_MIN_SPACE,
  237. HW_VAR_SHORTGI_DENSITY,
  238. HW_VAR_AMPDU_FACTOR,
  239. HW_VAR_MCS_RATE_AVAILABLE,
  240. HW_VAR_AC_PARAM,
  241. HW_VAR_ACM_CTRL,
  242. HW_VAR_DIS_Req_Qsize,
  243. HW_VAR_CCX_CHNL_LOAD,
  244. HW_VAR_CCX_NOISE_HISTOGRAM,
  245. HW_VAR_CCX_CLM_NHM,
  246. HW_VAR_TxOPLimit,
  247. HW_VAR_TURBO_MODE,
  248. HW_VAR_RF_STATE,
  249. HW_VAR_RF_OFF_BY_HW,
  250. HW_VAR_BUS_SPEED,
  251. HW_VAR_SET_DEV_POWER,
  252. HW_VAR_RCR,
  253. HW_VAR_RATR_0,
  254. HW_VAR_RRSR,
  255. HW_VAR_CPU_RST,
  256. HW_VAR_CHECK_BSSID,
  257. HW_VAR_LBK_MODE,
  258. HW_VAR_AES_11N_FIX,
  259. HW_VAR_USB_RX_AGGR,
  260. HW_VAR_USER_CONTROL_TURBO_MODE,
  261. HW_VAR_RETRY_LIMIT,
  262. HW_VAR_INIT_TX_RATE,
  263. HW_VAR_TX_RATE_REG,
  264. HW_VAR_EFUSE_USAGE,
  265. HW_VAR_EFUSE_BYTES,
  266. HW_VAR_AUTOLOAD_STATUS,
  267. HW_VAR_RF_2R_DISABLE,
  268. HW_VAR_SET_RPWM,
  269. HW_VAR_H2C_FW_PWRMODE,
  270. HW_VAR_H2C_FW_JOINBSSRPT,
  271. HW_VAR_H2C_FW_P2P_PS_OFFLOAD,
  272. HW_VAR_FW_PSMODE_STATUS,
  273. HW_VAR_RESUME_CLK_ON,
  274. HW_VAR_FW_LPS_ACTION,
  275. HW_VAR_1X1_RECV_COMBINE,
  276. HW_VAR_STOP_SEND_BEACON,
  277. HW_VAR_TSF_TIMER,
  278. HW_VAR_IO_CMD,
  279. HW_VAR_RF_RECOVERY,
  280. HW_VAR_H2C_FW_UPDATE_GTK,
  281. HW_VAR_WF_MASK,
  282. HW_VAR_WF_CRC,
  283. HW_VAR_WF_IS_MAC_ADDR,
  284. HW_VAR_H2C_FW_OFFLOAD,
  285. HW_VAR_RESET_WFCRC,
  286. HW_VAR_HANDLE_FW_C2H,
  287. HW_VAR_DL_FW_RSVD_PAGE,
  288. HW_VAR_AID,
  289. HW_VAR_HW_SEQ_ENABLE,
  290. HW_VAR_CORRECT_TSF,
  291. HW_VAR_BCN_VALID,
  292. HW_VAR_FWLPS_RF_ON,
  293. HW_VAR_DUAL_TSF_RST,
  294. HW_VAR_SWITCH_EPHY_WoWLAN,
  295. HW_VAR_INT_MIGRATION,
  296. HW_VAR_INT_AC,
  297. HW_VAR_RF_TIMING,
  298. HAL_DEF_WOWLAN,
  299. HW_VAR_MRC,
  300. HW_VAR_MGT_FILTER,
  301. HW_VAR_CTRL_FILTER,
  302. HW_VAR_DATA_FILTER,
  303. };
  304. enum _RT_MEDIA_STATUS {
  305. RT_MEDIA_DISCONNECT = 0,
  306. RT_MEDIA_CONNECT = 1
  307. };
  308. enum rt_oem_id {
  309. RT_CID_DEFAULT = 0,
  310. RT_CID_8187_ALPHA0 = 1,
  311. RT_CID_8187_SERCOMM_PS = 2,
  312. RT_CID_8187_HW_LED = 3,
  313. RT_CID_8187_NETGEAR = 4,
  314. RT_CID_WHQL = 5,
  315. RT_CID_819x_CAMEO = 6,
  316. RT_CID_819x_RUNTOP = 7,
  317. RT_CID_819x_Senao = 8,
  318. RT_CID_TOSHIBA = 9,
  319. RT_CID_819x_Netcore = 10,
  320. RT_CID_Nettronix = 11,
  321. RT_CID_DLINK = 12,
  322. RT_CID_PRONET = 13,
  323. RT_CID_COREGA = 14,
  324. RT_CID_819x_ALPHA = 15,
  325. RT_CID_819x_Sitecom = 16,
  326. RT_CID_CCX = 17,
  327. RT_CID_819x_Lenovo = 18,
  328. RT_CID_819x_QMI = 19,
  329. RT_CID_819x_Edimax_Belkin = 20,
  330. RT_CID_819x_Sercomm_Belkin = 21,
  331. RT_CID_819x_CAMEO1 = 22,
  332. RT_CID_819x_MSI = 23,
  333. RT_CID_819x_Acer = 24,
  334. RT_CID_819x_HP = 27,
  335. RT_CID_819x_CLEVO = 28,
  336. RT_CID_819x_Arcadyan_Belkin = 29,
  337. RT_CID_819x_SAMSUNG = 30,
  338. RT_CID_819x_WNC_COREGA = 31,
  339. RT_CID_819x_Foxcoon = 32,
  340. RT_CID_819x_DELL = 33,
  341. RT_CID_819x_PRONETS = 34,
  342. RT_CID_819x_Edimax_ASUS = 35,
  343. RT_CID_NETGEAR = 36,
  344. RT_CID_PLANEX = 37,
  345. RT_CID_CC_C = 38,
  346. };
  347. enum hw_descs {
  348. HW_DESC_OWN,
  349. HW_DESC_RXOWN,
  350. HW_DESC_TX_NEXTDESC_ADDR,
  351. HW_DESC_TXBUFF_ADDR,
  352. HW_DESC_RXBUFF_ADDR,
  353. HW_DESC_RXPKT_LEN,
  354. HW_DESC_RXERO,
  355. };
  356. enum prime_sc {
  357. PRIME_CHNL_OFFSET_DONT_CARE = 0,
  358. PRIME_CHNL_OFFSET_LOWER = 1,
  359. PRIME_CHNL_OFFSET_UPPER = 2,
  360. };
  361. enum rf_type {
  362. RF_1T1R = 0,
  363. RF_1T2R = 1,
  364. RF_2T2R = 2,
  365. RF_2T2R_GREEN = 3,
  366. };
  367. enum ht_channel_width {
  368. HT_CHANNEL_WIDTH_20 = 0,
  369. HT_CHANNEL_WIDTH_20_40 = 1,
  370. };
  371. /* Ref: 802.11i sepc D10.0 7.3.2.25.1
  372. Cipher Suites Encryption Algorithms */
  373. enum rt_enc_alg {
  374. NO_ENCRYPTION = 0,
  375. WEP40_ENCRYPTION = 1,
  376. TKIP_ENCRYPTION = 2,
  377. RSERVED_ENCRYPTION = 3,
  378. AESCCMP_ENCRYPTION = 4,
  379. WEP104_ENCRYPTION = 5,
  380. AESCMAC_ENCRYPTION = 6, /*IEEE802.11w */
  381. };
  382. enum rtl_hal_state {
  383. _HAL_STATE_STOP = 0,
  384. _HAL_STATE_START = 1,
  385. };
  386. enum rtl_desc92_rate {
  387. DESC92_RATE1M = 0x00,
  388. DESC92_RATE2M = 0x01,
  389. DESC92_RATE5_5M = 0x02,
  390. DESC92_RATE11M = 0x03,
  391. DESC92_RATE6M = 0x04,
  392. DESC92_RATE9M = 0x05,
  393. DESC92_RATE12M = 0x06,
  394. DESC92_RATE18M = 0x07,
  395. DESC92_RATE24M = 0x08,
  396. DESC92_RATE36M = 0x09,
  397. DESC92_RATE48M = 0x0a,
  398. DESC92_RATE54M = 0x0b,
  399. DESC92_RATEMCS0 = 0x0c,
  400. DESC92_RATEMCS1 = 0x0d,
  401. DESC92_RATEMCS2 = 0x0e,
  402. DESC92_RATEMCS3 = 0x0f,
  403. DESC92_RATEMCS4 = 0x10,
  404. DESC92_RATEMCS5 = 0x11,
  405. DESC92_RATEMCS6 = 0x12,
  406. DESC92_RATEMCS7 = 0x13,
  407. DESC92_RATEMCS8 = 0x14,
  408. DESC92_RATEMCS9 = 0x15,
  409. DESC92_RATEMCS10 = 0x16,
  410. DESC92_RATEMCS11 = 0x17,
  411. DESC92_RATEMCS12 = 0x18,
  412. DESC92_RATEMCS13 = 0x19,
  413. DESC92_RATEMCS14 = 0x1a,
  414. DESC92_RATEMCS15 = 0x1b,
  415. DESC92_RATEMCS15_SG = 0x1c,
  416. DESC92_RATEMCS32 = 0x20,
  417. };
  418. enum rtl_var_map {
  419. /*reg map */
  420. SYS_ISO_CTRL = 0,
  421. SYS_FUNC_EN,
  422. SYS_CLK,
  423. MAC_RCR_AM,
  424. MAC_RCR_AB,
  425. MAC_RCR_ACRC32,
  426. MAC_RCR_ACF,
  427. MAC_RCR_AAP,
  428. /*efuse map */
  429. EFUSE_TEST,
  430. EFUSE_CTRL,
  431. EFUSE_CLK,
  432. EFUSE_CLK_CTRL,
  433. EFUSE_PWC_EV12V,
  434. EFUSE_FEN_ELDR,
  435. EFUSE_LOADER_CLK_EN,
  436. EFUSE_ANA8M,
  437. EFUSE_HWSET_MAX_SIZE,
  438. EFUSE_MAX_SECTION_MAP,
  439. EFUSE_REAL_CONTENT_SIZE,
  440. EFUSE_OOB_PROTECT_BYTES_LEN,
  441. EFUSE_ACCESS,
  442. /*CAM map */
  443. RWCAM,
  444. WCAMI,
  445. RCAMO,
  446. CAMDBG,
  447. SECR,
  448. SEC_CAM_NONE,
  449. SEC_CAM_WEP40,
  450. SEC_CAM_TKIP,
  451. SEC_CAM_AES,
  452. SEC_CAM_WEP104,
  453. /*IMR map */
  454. RTL_IMR_BCNDMAINT6, /*Beacon DMA Interrupt 6 */
  455. RTL_IMR_BCNDMAINT5, /*Beacon DMA Interrupt 5 */
  456. RTL_IMR_BCNDMAINT4, /*Beacon DMA Interrupt 4 */
  457. RTL_IMR_BCNDMAINT3, /*Beacon DMA Interrupt 3 */
  458. RTL_IMR_BCNDMAINT2, /*Beacon DMA Interrupt 2 */
  459. RTL_IMR_BCNDMAINT1, /*Beacon DMA Interrupt 1 */
  460. RTL_IMR_BCNDOK8, /*Beacon Queue DMA OK Interrup 8 */
  461. RTL_IMR_BCNDOK7, /*Beacon Queue DMA OK Interrup 7 */
  462. RTL_IMR_BCNDOK6, /*Beacon Queue DMA OK Interrup 6 */
  463. RTL_IMR_BCNDOK5, /*Beacon Queue DMA OK Interrup 5 */
  464. RTL_IMR_BCNDOK4, /*Beacon Queue DMA OK Interrup 4 */
  465. RTL_IMR_BCNDOK3, /*Beacon Queue DMA OK Interrup 3 */
  466. RTL_IMR_BCNDOK2, /*Beacon Queue DMA OK Interrup 2 */
  467. RTL_IMR_BCNDOK1, /*Beacon Queue DMA OK Interrup 1 */
  468. RTL_IMR_TIMEOUT2, /*Timeout interrupt 2 */
  469. RTL_IMR_TIMEOUT1, /*Timeout interrupt 1 */
  470. RTL_IMR_TXFOVW, /*Transmit FIFO Overflow */
  471. RTL_IMR_PSTIMEOUT, /*Power save time out interrupt */
  472. RTL_IMR_BCNINT, /*Beacon DMA Interrupt 0 */
  473. RTL_IMR_RXFOVW, /*Receive FIFO Overflow */
  474. RTL_IMR_RDU, /*Receive Descriptor Unavailable */
  475. RTL_IMR_ATIMEND, /*For 92C,ATIM Window End Interrupt */
  476. RTL_IMR_BDOK, /*Beacon Queue DMA OK Interrup */
  477. RTL_IMR_HIGHDOK, /*High Queue DMA OK Interrupt */
  478. RTL_IMR_COMDOK, /*Command Queue DMA OK Interrupt*/
  479. RTL_IMR_TBDOK, /*Transmit Beacon OK interrup */
  480. RTL_IMR_MGNTDOK, /*Management Queue DMA OK Interrupt */
  481. RTL_IMR_TBDER, /*For 92C,Transmit Beacon Error Interrupt */
  482. RTL_IMR_BKDOK, /*AC_BK DMA OK Interrupt */
  483. RTL_IMR_BEDOK, /*AC_BE DMA OK Interrupt */
  484. RTL_IMR_VIDOK, /*AC_VI DMA OK Interrupt */
  485. RTL_IMR_VODOK, /*AC_VO DMA Interrupt */
  486. RTL_IMR_ROK, /*Receive DMA OK Interrupt */
  487. RTL_IBSS_INT_MASKS, /*(RTL_IMR_BCNINT | RTL_IMR_TBDOK |
  488. * RTL_IMR_TBDER) */
  489. RTL_IMR_C2HCMD, /*fw interrupt*/
  490. /*CCK Rates, TxHT = 0 */
  491. RTL_RC_CCK_RATE1M,
  492. RTL_RC_CCK_RATE2M,
  493. RTL_RC_CCK_RATE5_5M,
  494. RTL_RC_CCK_RATE11M,
  495. /*OFDM Rates, TxHT = 0 */
  496. RTL_RC_OFDM_RATE6M,
  497. RTL_RC_OFDM_RATE9M,
  498. RTL_RC_OFDM_RATE12M,
  499. RTL_RC_OFDM_RATE18M,
  500. RTL_RC_OFDM_RATE24M,
  501. RTL_RC_OFDM_RATE36M,
  502. RTL_RC_OFDM_RATE48M,
  503. RTL_RC_OFDM_RATE54M,
  504. RTL_RC_HT_RATEMCS7,
  505. RTL_RC_HT_RATEMCS15,
  506. /*keep it last */
  507. RTL_VAR_MAP_MAX,
  508. };
  509. /*Firmware PS mode for control LPS.*/
  510. enum _fw_ps_mode {
  511. FW_PS_ACTIVE_MODE = 0,
  512. FW_PS_MIN_MODE = 1,
  513. FW_PS_MAX_MODE = 2,
  514. FW_PS_DTIM_MODE = 3,
  515. FW_PS_VOIP_MODE = 4,
  516. FW_PS_UAPSD_WMM_MODE = 5,
  517. FW_PS_UAPSD_MODE = 6,
  518. FW_PS_IBSS_MODE = 7,
  519. FW_PS_WWLAN_MODE = 8,
  520. FW_PS_PM_Radio_Off = 9,
  521. FW_PS_PM_Card_Disable = 10,
  522. };
  523. enum rt_psmode {
  524. EACTIVE, /*Active/Continuous access. */
  525. EMAXPS, /*Max power save mode. */
  526. EFASTPS, /*Fast power save mode. */
  527. EAUTOPS, /*Auto power save mode. */
  528. };
  529. /*LED related.*/
  530. enum led_ctl_mode {
  531. LED_CTL_POWER_ON = 1,
  532. LED_CTL_LINK = 2,
  533. LED_CTL_NO_LINK = 3,
  534. LED_CTL_TX = 4,
  535. LED_CTL_RX = 5,
  536. LED_CTL_SITE_SURVEY = 6,
  537. LED_CTL_POWER_OFF = 7,
  538. LED_CTL_START_TO_LINK = 8,
  539. LED_CTL_START_WPS = 9,
  540. LED_CTL_STOP_WPS = 10,
  541. };
  542. enum rtl_led_pin {
  543. LED_PIN_GPIO0,
  544. LED_PIN_LED0,
  545. LED_PIN_LED1,
  546. LED_PIN_LED2
  547. };
  548. /*QoS related.*/
  549. /*acm implementation method.*/
  550. enum acm_method {
  551. eAcmWay0_SwAndHw = 0,
  552. eAcmWay1_HW = 1,
  553. eAcmWay2_SW = 2,
  554. };
  555. enum macphy_mode {
  556. SINGLEMAC_SINGLEPHY = 0,
  557. DUALMAC_DUALPHY,
  558. DUALMAC_SINGLEPHY,
  559. };
  560. enum band_type {
  561. BAND_ON_2_4G = 0,
  562. BAND_ON_5G,
  563. BAND_ON_BOTH,
  564. BANDMAX
  565. };
  566. /*aci/aifsn Field.
  567. Ref: WMM spec 2.2.2: WME Parameter Element, p.12.*/
  568. union aci_aifsn {
  569. u8 char_data;
  570. struct {
  571. u8 aifsn:4;
  572. u8 acm:1;
  573. u8 aci:2;
  574. u8 reserved:1;
  575. } f; /* Field */
  576. };
  577. /*mlme related.*/
  578. enum wireless_mode {
  579. WIRELESS_MODE_UNKNOWN = 0x00,
  580. WIRELESS_MODE_A = 0x01,
  581. WIRELESS_MODE_B = 0x02,
  582. WIRELESS_MODE_G = 0x04,
  583. WIRELESS_MODE_AUTO = 0x08,
  584. WIRELESS_MODE_N_24G = 0x10,
  585. WIRELESS_MODE_N_5G = 0x20
  586. };
  587. #define IS_WIRELESS_MODE_A(wirelessmode) \
  588. (wirelessmode == WIRELESS_MODE_A)
  589. #define IS_WIRELESS_MODE_B(wirelessmode) \
  590. (wirelessmode == WIRELESS_MODE_B)
  591. #define IS_WIRELESS_MODE_G(wirelessmode) \
  592. (wirelessmode == WIRELESS_MODE_G)
  593. #define IS_WIRELESS_MODE_N_24G(wirelessmode) \
  594. (wirelessmode == WIRELESS_MODE_N_24G)
  595. #define IS_WIRELESS_MODE_N_5G(wirelessmode) \
  596. (wirelessmode == WIRELESS_MODE_N_5G)
  597. enum ratr_table_mode {
  598. RATR_INX_WIRELESS_NGB = 0,
  599. RATR_INX_WIRELESS_NG = 1,
  600. RATR_INX_WIRELESS_NB = 2,
  601. RATR_INX_WIRELESS_N = 3,
  602. RATR_INX_WIRELESS_GB = 4,
  603. RATR_INX_WIRELESS_G = 5,
  604. RATR_INX_WIRELESS_B = 6,
  605. RATR_INX_WIRELESS_MC = 7,
  606. RATR_INX_WIRELESS_A = 8,
  607. };
  608. enum rtl_link_state {
  609. MAC80211_NOLINK = 0,
  610. MAC80211_LINKING = 1,
  611. MAC80211_LINKED = 2,
  612. MAC80211_LINKED_SCANNING = 3,
  613. };
  614. enum act_category {
  615. ACT_CAT_QOS = 1,
  616. ACT_CAT_DLS = 2,
  617. ACT_CAT_BA = 3,
  618. ACT_CAT_HT = 7,
  619. ACT_CAT_WMM = 17,
  620. };
  621. enum ba_action {
  622. ACT_ADDBAREQ = 0,
  623. ACT_ADDBARSP = 1,
  624. ACT_DELBA = 2,
  625. };
  626. enum rt_polarity_ctl {
  627. RT_POLARITY_LOW_ACT = 0,
  628. RT_POLARITY_HIGH_ACT = 1,
  629. };
  630. struct octet_string {
  631. u8 *octet;
  632. u16 length;
  633. };
  634. struct rtl_hdr_3addr {
  635. __le16 frame_ctl;
  636. __le16 duration_id;
  637. u8 addr1[ETH_ALEN];
  638. u8 addr2[ETH_ALEN];
  639. u8 addr3[ETH_ALEN];
  640. __le16 seq_ctl;
  641. u8 payload[0];
  642. } __packed;
  643. struct rtl_info_element {
  644. u8 id;
  645. u8 len;
  646. u8 data[0];
  647. } __packed;
  648. struct rtl_probe_rsp {
  649. struct rtl_hdr_3addr header;
  650. u32 time_stamp[2];
  651. __le16 beacon_interval;
  652. __le16 capability;
  653. /*SSID, supported rates, FH params, DS params,
  654. CF params, IBSS params, TIM (if beacon), RSN */
  655. struct rtl_info_element info_element[0];
  656. } __packed;
  657. /*LED related.*/
  658. /*ledpin Identify how to implement this SW led.*/
  659. struct rtl_led {
  660. void *hw;
  661. enum rtl_led_pin ledpin;
  662. bool ledon;
  663. };
  664. struct rtl_led_ctl {
  665. bool led_opendrain;
  666. struct rtl_led sw_led0;
  667. struct rtl_led sw_led1;
  668. };
  669. struct rtl_qos_parameters {
  670. __le16 cw_min;
  671. __le16 cw_max;
  672. u8 aifs;
  673. u8 flag;
  674. __le16 tx_op;
  675. } __packed;
  676. struct rt_smooth_data {
  677. u32 elements[100]; /*array to store values */
  678. u32 index; /*index to current array to store */
  679. u32 total_num; /*num of valid elements */
  680. u32 total_val; /*sum of valid elements */
  681. };
  682. struct false_alarm_statistics {
  683. u32 cnt_parity_fail;
  684. u32 cnt_rate_illegal;
  685. u32 cnt_crc8_fail;
  686. u32 cnt_mcs_fail;
  687. u32 cnt_fast_fsync_fail;
  688. u32 cnt_sb_search_fail;
  689. u32 cnt_ofdm_fail;
  690. u32 cnt_cck_fail;
  691. u32 cnt_all;
  692. u32 cnt_ofdm_cca;
  693. u32 cnt_cck_cca;
  694. u32 cnt_cca_all;
  695. u32 cnt_bw_usc;
  696. u32 cnt_bw_lsc;
  697. };
  698. struct init_gain {
  699. u8 xaagccore1;
  700. u8 xbagccore1;
  701. u8 xcagccore1;
  702. u8 xdagccore1;
  703. u8 cca;
  704. };
  705. struct wireless_stats {
  706. unsigned long txbytesunicast;
  707. unsigned long txbytesmulticast;
  708. unsigned long txbytesbroadcast;
  709. unsigned long rxbytesunicast;
  710. long rx_snr_db[4];
  711. /*Correct smoothed ss in Dbm, only used
  712. in driver to report real power now. */
  713. long recv_signal_power;
  714. long signal_quality;
  715. long last_sigstrength_inpercent;
  716. u32 rssi_calculate_cnt;
  717. /*Transformed, in dbm. Beautified signal
  718. strength for UI, not correct. */
  719. long signal_strength;
  720. u8 rx_rssi_percentage[4];
  721. u8 rx_evm_percentage[2];
  722. struct rt_smooth_data ui_rssi;
  723. struct rt_smooth_data ui_link_quality;
  724. };
  725. struct rate_adaptive {
  726. u8 rate_adaptive_disabled;
  727. u8 ratr_state;
  728. u16 reserve;
  729. u32 high_rssi_thresh_for_ra;
  730. u32 high2low_rssi_thresh_for_ra;
  731. u8 low2high_rssi_thresh_for_ra40m;
  732. u32 low_rssi_thresh_for_ra40M;
  733. u8 low2high_rssi_thresh_for_ra20m;
  734. u32 low_rssi_thresh_for_ra20M;
  735. u32 upper_rssi_threshold_ratr;
  736. u32 middleupper_rssi_threshold_ratr;
  737. u32 middle_rssi_threshold_ratr;
  738. u32 middlelow_rssi_threshold_ratr;
  739. u32 low_rssi_threshold_ratr;
  740. u32 ultralow_rssi_threshold_ratr;
  741. u32 low_rssi_threshold_ratr_40m;
  742. u32 low_rssi_threshold_ratr_20m;
  743. u8 ping_rssi_enable;
  744. u32 ping_rssi_ratr;
  745. u32 ping_rssi_thresh_for_ra;
  746. u32 last_ratr;
  747. u8 pre_ratr_state;
  748. };
  749. struct regd_pair_mapping {
  750. u16 reg_dmnenum;
  751. u16 reg_5ghz_ctl;
  752. u16 reg_2ghz_ctl;
  753. };
  754. struct rtl_regulatory {
  755. char alpha2[2];
  756. u16 country_code;
  757. u16 max_power_level;
  758. u32 tp_scale;
  759. u16 current_rd;
  760. u16 current_rd_ext;
  761. int16_t power_limit;
  762. struct regd_pair_mapping *regpair;
  763. };
  764. struct rtl_rfkill {
  765. bool rfkill_state; /*0 is off, 1 is on */
  766. };
  767. /*for P2P PS**/
  768. #define P2P_MAX_NOA_NUM 2
  769. enum p2p_role {
  770. P2P_ROLE_DISABLE = 0,
  771. P2P_ROLE_DEVICE = 1,
  772. P2P_ROLE_CLIENT = 2,
  773. P2P_ROLE_GO = 3
  774. };
  775. enum p2p_ps_state {
  776. P2P_PS_DISABLE = 0,
  777. P2P_PS_ENABLE = 1,
  778. P2P_PS_SCAN = 2,
  779. P2P_PS_SCAN_DONE = 3,
  780. P2P_PS_ALLSTASLEEP = 4, /* for P2P GO */
  781. };
  782. enum p2p_ps_mode {
  783. P2P_PS_NONE = 0,
  784. P2P_PS_CTWINDOW = 1,
  785. P2P_PS_NOA = 2,
  786. P2P_PS_MIX = 3, /* CTWindow and NoA */
  787. };
  788. struct rtl_p2p_ps_info {
  789. enum p2p_ps_mode p2p_ps_mode; /* indicate p2p ps mode */
  790. enum p2p_ps_state p2p_ps_state; /* indicate p2p ps state */
  791. u8 noa_index; /* Identifies instance of Notice of Absence timing. */
  792. /* Client traffic window. A period of time in TU after TBTT. */
  793. u8 ctwindow;
  794. u8 opp_ps; /* opportunistic power save. */
  795. u8 noa_num; /* number of NoA descriptor in P2P IE. */
  796. /* Count for owner, Type of client. */
  797. u8 noa_count_type[P2P_MAX_NOA_NUM];
  798. /* Max duration for owner, preferred or min acceptable duration
  799. * for client.
  800. */
  801. u32 noa_duration[P2P_MAX_NOA_NUM];
  802. /* Length of interval for owner, preferred or max acceptable intervali
  803. * of client.
  804. */
  805. u32 noa_interval[P2P_MAX_NOA_NUM];
  806. /* schedule in terms of the lower 4 bytes of the TSF timer. */
  807. u32 noa_start_time[P2P_MAX_NOA_NUM];
  808. };
  809. struct p2p_ps_offload_t {
  810. u8 offload_en:1;
  811. u8 role:1; /* 1: Owner, 0: Client */
  812. u8 ctwindow_en:1;
  813. u8 noa0_en:1;
  814. u8 noa1_en:1;
  815. u8 allstasleep:1;
  816. u8 discovery:1;
  817. u8 reserved:1;
  818. };
  819. #define IQK_MATRIX_REG_NUM 8
  820. #define IQK_MATRIX_SETTINGS_NUM (1 + 24 + 21)
  821. struct iqk_matrix_regs {
  822. bool iqk_done;
  823. long value[1][IQK_MATRIX_REG_NUM];
  824. };
  825. struct phy_parameters {
  826. u16 length;
  827. u32 *pdata;
  828. };
  829. enum hw_param_tab_index {
  830. PHY_REG_2T,
  831. PHY_REG_1T,
  832. PHY_REG_PG,
  833. RADIOA_2T,
  834. RADIOB_2T,
  835. RADIOA_1T,
  836. RADIOB_1T,
  837. MAC_REG,
  838. AGCTAB_2T,
  839. AGCTAB_1T,
  840. MAX_TAB
  841. };
  842. struct rtl_phy {
  843. struct bb_reg_def phyreg_def[4]; /*Radio A/B/C/D */
  844. struct init_gain initgain_backup;
  845. enum io_type current_io_type;
  846. u8 rf_mode;
  847. u8 rf_type;
  848. u8 current_chan_bw;
  849. u8 set_bwmode_inprogress;
  850. u8 sw_chnl_inprogress;
  851. u8 sw_chnl_stage;
  852. u8 sw_chnl_step;
  853. u8 current_channel;
  854. u8 h2c_box_num;
  855. u8 set_io_inprogress;
  856. u8 lck_inprogress;
  857. /* record for power tracking */
  858. s32 reg_e94;
  859. s32 reg_e9c;
  860. s32 reg_ea4;
  861. s32 reg_eac;
  862. s32 reg_eb4;
  863. s32 reg_ebc;
  864. s32 reg_ec4;
  865. s32 reg_ecc;
  866. u8 rfpienable;
  867. u8 reserve_0;
  868. u16 reserve_1;
  869. u32 reg_c04, reg_c08, reg_874;
  870. u32 adda_backup[16];
  871. u32 iqk_mac_backup[IQK_MAC_REG_NUM];
  872. u32 iqk_bb_backup[10];
  873. bool iqk_initialized;
  874. /* Dual mac */
  875. bool need_iqk;
  876. struct iqk_matrix_regs iqk_matrix[IQK_MATRIX_SETTINGS_NUM];
  877. bool rfpi_enable;
  878. u8 pwrgroup_cnt;
  879. u8 cck_high_power;
  880. /* MAX_PG_GROUP groups of pwr diff by rates */
  881. u32 mcs_offset[MAX_PG_GROUP][16];
  882. u8 default_initialgain[4];
  883. /* the current Tx power level */
  884. u8 cur_cck_txpwridx;
  885. u8 cur_ofdm24g_txpwridx;
  886. u8 cur_bw20_txpwridx;
  887. u8 cur_bw40_txpwridx;
  888. u32 rfreg_chnlval[2];
  889. bool apk_done;
  890. u32 reg_rf3c[2]; /* pathA / pathB */
  891. /* bfsync */
  892. u8 framesync;
  893. u32 framesync_c34;
  894. u8 num_total_rfpath;
  895. struct phy_parameters hwparam_tables[MAX_TAB];
  896. u16 rf_pathmap;
  897. enum rt_polarity_ctl polarity_ctl;
  898. };
  899. #define MAX_TID_COUNT 9
  900. #define RTL_AGG_STOP 0
  901. #define RTL_AGG_PROGRESS 1
  902. #define RTL_AGG_START 2
  903. #define RTL_AGG_OPERATIONAL 3
  904. #define RTL_AGG_OFF 0
  905. #define RTL_AGG_ON 1
  906. #define RTL_RX_AGG_START 1
  907. #define RTL_RX_AGG_STOP 0
  908. #define RTL_AGG_EMPTYING_HW_QUEUE_ADDBA 2
  909. #define RTL_AGG_EMPTYING_HW_QUEUE_DELBA 3
  910. struct rtl_ht_agg {
  911. u16 txq_id;
  912. u16 wait_for_ba;
  913. u16 start_idx;
  914. u64 bitmap;
  915. u32 rate_n_flags;
  916. u8 agg_state;
  917. u8 rx_agg_state;
  918. };
  919. struct rssi_sta {
  920. long undec_sm_pwdb;
  921. long undec_sm_cck;
  922. };
  923. struct rtl_tid_data {
  924. u16 seq_number;
  925. struct rtl_ht_agg agg;
  926. };
  927. struct rtl_sta_info {
  928. struct list_head list;
  929. u8 ratr_index;
  930. u8 wireless_mode;
  931. u8 mimo_ps;
  932. u8 mac_addr[ETH_ALEN];
  933. struct rtl_tid_data tids[MAX_TID_COUNT];
  934. /* just used for ap adhoc or mesh*/
  935. struct rssi_sta rssi_stat;
  936. } __packed;
  937. struct rtl_priv;
  938. struct rtl_io {
  939. struct device *dev;
  940. struct mutex bb_mutex;
  941. /*PCI MEM map */
  942. unsigned long pci_mem_end; /*shared mem end */
  943. unsigned long pci_mem_start; /*shared mem start */
  944. /*PCI IO map */
  945. unsigned long pci_base_addr; /*device I/O address */
  946. void (*write8_async) (struct rtl_priv *rtlpriv, u32 addr, u8 val);
  947. void (*write16_async) (struct rtl_priv *rtlpriv, u32 addr, u16 val);
  948. void (*write32_async) (struct rtl_priv *rtlpriv, u32 addr, u32 val);
  949. void (*writeN_sync) (struct rtl_priv *rtlpriv, u32 addr, void *buf,
  950. u16 len);
  951. u8(*read8_sync) (struct rtl_priv *rtlpriv, u32 addr);
  952. u16(*read16_sync) (struct rtl_priv *rtlpriv, u32 addr);
  953. u32(*read32_sync) (struct rtl_priv *rtlpriv, u32 addr);
  954. };
  955. struct rtl_mac {
  956. u8 mac_addr[ETH_ALEN];
  957. u8 mac80211_registered;
  958. u8 beacon_enabled;
  959. u32 tx_ss_num;
  960. u32 rx_ss_num;
  961. struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
  962. struct ieee80211_hw *hw;
  963. struct ieee80211_vif *vif;
  964. enum nl80211_iftype opmode;
  965. /*Probe Beacon management */
  966. struct rtl_tid_data tids[MAX_TID_COUNT];
  967. enum rtl_link_state link_state;
  968. int n_channels;
  969. int n_bitrates;
  970. bool offchan_delay;
  971. u8 p2p; /*using p2p role*/
  972. bool p2p_in_use;
  973. /*filters */
  974. u32 rx_conf;
  975. u16 rx_mgt_filter;
  976. u16 rx_ctrl_filter;
  977. u16 rx_data_filter;
  978. bool act_scanning;
  979. u8 cnt_after_linked;
  980. bool skip_scan;
  981. /* early mode */
  982. /* skb wait queue */
  983. struct sk_buff_head skb_waitq[MAX_TID_COUNT];
  984. /*RDG*/
  985. bool rdg_en;
  986. /*AP*/
  987. u8 bssid[6];
  988. u32 vendor;
  989. u8 mcs[16]; /* 16 bytes mcs for HT rates. */
  990. u32 basic_rates; /* b/g rates */
  991. u8 ht_enable;
  992. u8 sgi_40;
  993. u8 sgi_20;
  994. u8 bw_40;
  995. u8 mode; /* wireless mode */
  996. u8 slot_time;
  997. u8 short_preamble;
  998. u8 use_cts_protect;
  999. u8 cur_40_prime_sc;
  1000. u8 cur_40_prime_sc_bk;
  1001. u64 tsf;
  1002. u8 retry_short;
  1003. u8 retry_long;
  1004. u16 assoc_id;
  1005. bool hiddenssid;
  1006. /*IBSS*/
  1007. int beacon_interval;
  1008. /*AMPDU*/
  1009. u8 min_space_cfg; /*For Min spacing configurations */
  1010. u8 max_mss_density;
  1011. u8 current_ampdu_factor;
  1012. u8 current_ampdu_density;
  1013. /*QOS & EDCA */
  1014. struct ieee80211_tx_queue_params edca_param[RTL_MAC80211_NUM_QUEUE];
  1015. struct rtl_qos_parameters ac[AC_MAX];
  1016. /* counters */
  1017. u64 last_txok_cnt;
  1018. u64 last_rxok_cnt;
  1019. u32 last_bt_edca_ul;
  1020. u32 last_bt_edca_dl;
  1021. };
  1022. struct btdm_8723 {
  1023. bool all_off;
  1024. bool agc_table_en;
  1025. bool adc_back_off_on;
  1026. bool b2_ant_hid_en;
  1027. bool low_penalty_rate_adaptive;
  1028. bool rf_rx_lpf_shrink;
  1029. bool reject_aggre_pkt;
  1030. bool tra_tdma_on;
  1031. u8 tra_tdma_nav;
  1032. u8 tra_tdma_ant;
  1033. bool tdma_on;
  1034. u8 tdma_ant;
  1035. u8 tdma_nav;
  1036. u8 tdma_dac_swing;
  1037. u8 fw_dac_swing_lvl;
  1038. bool ps_tdma_on;
  1039. u8 ps_tdma_byte[5];
  1040. bool pta_on;
  1041. u32 val_0x6c0;
  1042. u32 val_0x6c8;
  1043. u32 val_0x6cc;
  1044. bool sw_dac_swing_on;
  1045. u32 sw_dac_swing_lvl;
  1046. u32 wlan_act_hi;
  1047. u32 wlan_act_lo;
  1048. u32 bt_retry_index;
  1049. bool dec_bt_pwr;
  1050. bool ignore_wlan_act;
  1051. };
  1052. struct bt_coexist_8723 {
  1053. u32 high_priority_tx;
  1054. u32 high_priority_rx;
  1055. u32 low_priority_tx;
  1056. u32 low_priority_rx;
  1057. u8 c2h_bt_info;
  1058. bool c2h_bt_info_req_sent;
  1059. bool c2h_bt_inquiry_page;
  1060. u32 bt_inq_page_start_time;
  1061. u8 bt_retry_cnt;
  1062. u8 c2h_bt_info_original;
  1063. u8 bt_inquiry_page_cnt;
  1064. struct btdm_8723 btdm;
  1065. };
  1066. struct rtl_hal {
  1067. struct ieee80211_hw *hw;
  1068. bool driver_is_goingto_unload;
  1069. bool up_first_time;
  1070. bool first_init;
  1071. bool being_init_adapter;
  1072. bool bbrf_ready;
  1073. bool mac_func_enable;
  1074. struct bt_coexist_8723 hal_coex_8723;
  1075. enum intf_type interface;
  1076. u16 hw_type; /*92c or 92d or 92s and so on */
  1077. u8 ic_class;
  1078. u8 oem_id;
  1079. u32 version; /*version of chip */
  1080. u8 state; /*stop 0, start 1 */
  1081. u8 board_type;
  1082. /*firmware */
  1083. u32 fwsize;
  1084. u8 *pfirmware;
  1085. u16 fw_version;
  1086. u16 fw_subversion;
  1087. bool h2c_setinprogress;
  1088. u8 last_hmeboxnum;
  1089. bool fw_ready;
  1090. /*Reserve page start offset except beacon in TxQ. */
  1091. u8 fw_rsvdpage_startoffset;
  1092. u8 h2c_txcmd_seq;
  1093. /* FW Cmd IO related */
  1094. u16 fwcmd_iomap;
  1095. u32 fwcmd_ioparam;
  1096. bool set_fwcmd_inprogress;
  1097. u8 current_fwcmd_io;
  1098. struct p2p_ps_offload_t p2p_ps_offload;
  1099. bool fw_clk_change_in_progress;
  1100. bool allow_sw_to_change_hwclc;
  1101. u8 fw_ps_state;
  1102. /**/
  1103. bool driver_going2unload;
  1104. /*AMPDU init min space*/
  1105. u8 minspace_cfg; /*For Min spacing configurations */
  1106. /* Dual mac */
  1107. enum macphy_mode macphymode;
  1108. enum band_type current_bandtype; /* 0:2.4G, 1:5G */
  1109. enum band_type current_bandtypebackup;
  1110. enum band_type bandset;
  1111. /* dual MAC 0--Mac0 1--Mac1 */
  1112. u32 interfaceindex;
  1113. /* just for DualMac S3S4 */
  1114. u8 macphyctl_reg;
  1115. bool earlymode_enable;
  1116. u8 max_earlymode_num;
  1117. /* Dual mac*/
  1118. bool during_mac0init_radiob;
  1119. bool during_mac1init_radioa;
  1120. bool reloadtxpowerindex;
  1121. /* True if IMR or IQK have done
  1122. for 2.4G in scan progress */
  1123. bool load_imrandiqk_setting_for2g;
  1124. bool disable_amsdu_8k;
  1125. bool master_of_dmsp;
  1126. bool slave_of_dmsp;
  1127. };
  1128. struct rtl_security {
  1129. /*default 0 */
  1130. bool use_sw_sec;
  1131. bool being_setkey;
  1132. bool use_defaultkey;
  1133. /*Encryption Algorithm for Unicast Packet */
  1134. enum rt_enc_alg pairwise_enc_algorithm;
  1135. /*Encryption Algorithm for Brocast/Multicast */
  1136. enum rt_enc_alg group_enc_algorithm;
  1137. /*Cam Entry Bitmap */
  1138. u32 hwsec_cam_bitmap;
  1139. u8 hwsec_cam_sta_addr[TOTAL_CAM_ENTRY][ETH_ALEN];
  1140. /*local Key buffer, indx 0 is for
  1141. pairwise key 1-4 is for agoup key. */
  1142. u8 key_buf[KEY_BUF_SIZE][MAX_KEY_LEN];
  1143. u8 key_len[KEY_BUF_SIZE];
  1144. /*The pointer of Pairwise Key,
  1145. it always points to KeyBuf[4] */
  1146. u8 *pairwise_key;
  1147. };
  1148. #define ASSOCIATE_ENTRY_NUM 33
  1149. struct fast_ant_training {
  1150. u8 bssid[6];
  1151. u8 antsel_rx_keep_0;
  1152. u8 antsel_rx_keep_1;
  1153. u8 antsel_rx_keep_2;
  1154. u32 ant_sum[7];
  1155. u32 ant_cnt[7];
  1156. u32 ant_ave[7];
  1157. u8 fat_state;
  1158. u32 train_idx;
  1159. u8 antsel_a[ASSOCIATE_ENTRY_NUM];
  1160. u8 antsel_b[ASSOCIATE_ENTRY_NUM];
  1161. u8 antsel_c[ASSOCIATE_ENTRY_NUM];
  1162. u32 main_ant_sum[ASSOCIATE_ENTRY_NUM];
  1163. u32 aux_ant_sum[ASSOCIATE_ENTRY_NUM];
  1164. u32 main_ant_cnt[ASSOCIATE_ENTRY_NUM];
  1165. u32 aux_ant_cnt[ASSOCIATE_ENTRY_NUM];
  1166. u8 rx_idle_ant;
  1167. bool becomelinked;
  1168. };
  1169. struct rtl_dm {
  1170. /*PHY status for Dynamic Management */
  1171. long entry_min_undec_sm_pwdb;
  1172. long undec_sm_cck;
  1173. long undec_sm_pwdb; /*out dm */
  1174. long entry_max_undec_sm_pwdb;
  1175. s32 ofdm_pkt_cnt;
  1176. bool dm_initialgain_enable;
  1177. bool dynamic_txpower_enable;
  1178. bool current_turbo_edca;
  1179. bool is_any_nonbepkts; /*out dm */
  1180. bool is_cur_rdlstate;
  1181. bool txpower_trackinginit;
  1182. bool disable_framebursting;
  1183. bool cck_inch14;
  1184. bool txpower_tracking;
  1185. bool useramask;
  1186. bool rfpath_rxenable[4];
  1187. bool inform_fw_driverctrldm;
  1188. bool current_mrc_switch;
  1189. u8 txpowercount;
  1190. u8 powerindex_backup[6];
  1191. u8 thermalvalue_rxgain;
  1192. u8 thermalvalue_iqk;
  1193. u8 thermalvalue_lck;
  1194. u8 thermalvalue;
  1195. u8 last_dtp_lvl;
  1196. u8 thermalvalue_avg[AVG_THERMAL_NUM];
  1197. u8 thermalvalue_avg_index;
  1198. bool done_txpower;
  1199. u8 dynamic_txhighpower_lvl; /*Tx high power level */
  1200. u8 dm_flag; /*Indicate each dynamic mechanism's status. */
  1201. u8 dm_flag_tmp;
  1202. u8 dm_type;
  1203. u8 dm_rssi_sel;
  1204. u8 txpower_track_control;
  1205. bool interrupt_migration;
  1206. bool disable_tx_int;
  1207. char ofdm_index[2];
  1208. char cck_index;
  1209. char delta_power_index;
  1210. char delta_power_index_last;
  1211. char power_index_offset;
  1212. /*88e tx power tracking*/
  1213. u8 swing_idx_ofdm[2];
  1214. u8 swing_idx_ofdm_cur;
  1215. u8 swing_idx_ofdm_base;
  1216. bool swing_flag_ofdm;
  1217. u8 swing_idx_cck;
  1218. u8 swing_idx_cck_cur;
  1219. u8 swing_idx_cck_base;
  1220. bool swing_flag_cck;
  1221. /* DMSP */
  1222. bool supp_phymode_switch;
  1223. struct fast_ant_training fat_table;
  1224. };
  1225. #define EFUSE_MAX_LOGICAL_SIZE 256
  1226. struct rtl_efuse {
  1227. bool autoLoad_ok;
  1228. bool bootfromefuse;
  1229. u16 max_physical_size;
  1230. u8 efuse_map[2][EFUSE_MAX_LOGICAL_SIZE];
  1231. u16 efuse_usedbytes;
  1232. u8 efuse_usedpercentage;
  1233. #ifdef EFUSE_REPG_WORKAROUND
  1234. bool efuse_re_pg_sec1flag;
  1235. u8 efuse_re_pg_data[8];
  1236. #endif
  1237. u8 autoload_failflag;
  1238. u8 autoload_status;
  1239. short epromtype;
  1240. u16 eeprom_vid;
  1241. u16 eeprom_did;
  1242. u16 eeprom_svid;
  1243. u16 eeprom_smid;
  1244. u8 eeprom_oemid;
  1245. u16 eeprom_channelplan;
  1246. u8 eeprom_version;
  1247. u8 board_type;
  1248. u8 external_pa;
  1249. u8 dev_addr[6];
  1250. u8 wowlan_enable;
  1251. u8 antenna_div_cfg;
  1252. u8 antenna_div_type;
  1253. bool txpwr_fromeprom;
  1254. u8 eeprom_crystalcap;
  1255. u8 eeprom_tssi[2];
  1256. u8 eeprom_tssi_5g[3][2]; /* for 5GL/5GM/5GH band. */
  1257. u8 eeprom_pwrlimit_ht20[CHANNEL_GROUP_MAX];
  1258. u8 eeprom_pwrlimit_ht40[CHANNEL_GROUP_MAX];
  1259. u8 eeprom_chnlarea_txpwr_cck[2][CHANNEL_GROUP_MAX_2G];
  1260. u8 eeprom_chnlarea_txpwr_ht40_1s[2][CHANNEL_GROUP_MAX];
  1261. u8 eprom_chnl_txpwr_ht40_2sdf[2][CHANNEL_GROUP_MAX];
  1262. u8 txpwrlevel_cck[2][CHANNEL_MAX_NUMBER_2G];
  1263. u8 txpwrlevel_ht40_1s[2][CHANNEL_MAX_NUMBER]; /*For HT 40MHZ pwr */
  1264. u8 txpwrlevel_ht40_2s[2][CHANNEL_MAX_NUMBER]; /*For HT 40MHZ pwr */
  1265. u8 internal_pa_5g[2]; /* pathA / pathB */
  1266. u8 eeprom_c9;
  1267. u8 eeprom_cc;
  1268. /*For power group */
  1269. u8 eeprom_pwrgroup[2][3];
  1270. u8 pwrgroup_ht20[2][CHANNEL_MAX_NUMBER];
  1271. u8 pwrgroup_ht40[2][CHANNEL_MAX_NUMBER];
  1272. char txpwr_ht20diff[2][CHANNEL_MAX_NUMBER]; /*HT 20<->40 Pwr diff */
  1273. /*For HT<->legacy pwr diff*/
  1274. u8 txpwr_legacyhtdiff[2][CHANNEL_MAX_NUMBER];
  1275. u8 txpwr_safetyflag; /* Band edge enable flag */
  1276. u16 eeprom_txpowerdiff;
  1277. u8 legacy_httxpowerdiff; /* Legacy to HT rate power diff */
  1278. u8 antenna_txpwdiff[3];
  1279. u8 eeprom_regulatory;
  1280. u8 eeprom_thermalmeter;
  1281. u8 thermalmeter[2]; /*ThermalMeter, index 0 for RFIC0, 1 for RFIC1 */
  1282. u16 tssi_13dbm;
  1283. u8 crystalcap; /* CrystalCap. */
  1284. u8 delta_iqk;
  1285. u8 delta_lck;
  1286. u8 legacy_ht_txpowerdiff; /*Legacy to HT rate power diff */
  1287. bool apk_thermalmeterignore;
  1288. bool b1x1_recvcombine;
  1289. bool b1ss_support;
  1290. /*channel plan */
  1291. u8 channel_plan;
  1292. };
  1293. struct rtl_ps_ctl {
  1294. bool pwrdomain_protect;
  1295. bool in_powersavemode;
  1296. bool rfchange_inprogress;
  1297. bool swrf_processing;
  1298. bool hwradiooff;
  1299. /*
  1300. * just for PCIE ASPM
  1301. * If it supports ASPM, Offset[560h] = 0x40,
  1302. * otherwise Offset[560h] = 0x00.
  1303. * */
  1304. bool support_aspm;
  1305. bool support_backdoor;
  1306. /*for LPS */
  1307. enum rt_psmode dot11_psmode; /*Power save mode configured. */
  1308. bool swctrl_lps;
  1309. bool leisure_ps;
  1310. bool fwctrl_lps;
  1311. u8 fwctrl_psmode;
  1312. /*For Fw control LPS mode */
  1313. u8 reg_fwctrl_lps;
  1314. /*Record Fw PS mode status. */
  1315. bool fw_current_inpsmode;
  1316. u8 reg_max_lps_awakeintvl;
  1317. bool report_linked;
  1318. bool low_power_enable;/*for 32k*/
  1319. /*for IPS */
  1320. bool inactiveps;
  1321. u32 rfoff_reason;
  1322. /*RF OFF Level */
  1323. u32 cur_ps_level;
  1324. u32 reg_rfps_level;
  1325. /*just for PCIE ASPM */
  1326. u8 const_amdpci_aspm;
  1327. bool pwrdown_mode;
  1328. enum rf_pwrstate inactive_pwrstate;
  1329. enum rf_pwrstate rfpwr_state; /*cur power state */
  1330. /* for SW LPS*/
  1331. bool sw_ps_enabled;
  1332. bool state;
  1333. bool state_inap;
  1334. bool multi_buffered;
  1335. u16 nullfunc_seq;
  1336. unsigned int dtim_counter;
  1337. unsigned int sleep_ms;
  1338. unsigned long last_sleep_jiffies;
  1339. unsigned long last_awake_jiffies;
  1340. unsigned long last_delaylps_stamp_jiffies;
  1341. unsigned long last_dtim;
  1342. unsigned long last_beacon;
  1343. unsigned long last_action;
  1344. unsigned long last_slept;
  1345. /*For P2P PS */
  1346. struct rtl_p2p_ps_info p2p_ps_info;
  1347. u8 pwr_mode;
  1348. u8 smart_ps;
  1349. };
  1350. struct rtl_stats {
  1351. u8 psaddr[ETH_ALEN];
  1352. u32 mac_time[2];
  1353. s8 rssi;
  1354. u8 signal;
  1355. u8 noise;
  1356. u8 rate; /* hw desc rate */
  1357. u8 received_channel;
  1358. u8 control;
  1359. u8 mask;
  1360. u8 freq;
  1361. u16 len;
  1362. u64 tsf;
  1363. u32 beacon_time;
  1364. u8 nic_type;
  1365. u16 length;
  1366. u8 signalquality; /*in 0-100 index. */
  1367. /*
  1368. * Real power in dBm for this packet,
  1369. * no beautification and aggregation.
  1370. * */
  1371. s32 recvsignalpower;
  1372. s8 rxpower; /*in dBm Translate from PWdB */
  1373. u8 signalstrength; /*in 0-100 index. */
  1374. u16 hwerror:1;
  1375. u16 crc:1;
  1376. u16 icv:1;
  1377. u16 shortpreamble:1;
  1378. u16 antenna:1;
  1379. u16 decrypted:1;
  1380. u16 wakeup:1;
  1381. u32 timestamp_low;
  1382. u32 timestamp_high;
  1383. u8 rx_drvinfo_size;
  1384. u8 rx_bufshift;
  1385. bool isampdu;
  1386. bool isfirst_ampdu;
  1387. bool rx_is40Mhzpacket;
  1388. u32 rx_pwdb_all;
  1389. u8 rx_mimo_signalstrength[4]; /*in 0~100 index */
  1390. s8 rx_mimo_sig_qual[2];
  1391. bool packet_matchbssid;
  1392. bool is_cck;
  1393. bool is_ht;
  1394. bool packet_toself;
  1395. bool packet_beacon; /*for rssi */
  1396. char cck_adc_pwdb[4]; /*for rx path selection */
  1397. u8 packet_report_type;
  1398. u32 macid;
  1399. u8 wake_match;
  1400. u32 bt_rx_rssi_percentage;
  1401. u32 macid_valid_entry[2];
  1402. };
  1403. struct rt_link_detect {
  1404. /* count for roaming */
  1405. u32 bcn_rx_inperiod;
  1406. u32 roam_times;
  1407. u32 num_tx_in4period[4];
  1408. u32 num_rx_in4period[4];
  1409. u32 num_tx_inperiod;
  1410. u32 num_rx_inperiod;
  1411. bool busytraffic;
  1412. bool tx_busy_traffic;
  1413. bool rx_busy_traffic;
  1414. bool higher_busytraffic;
  1415. bool higher_busyrxtraffic;
  1416. u32 tidtx_in4period[MAX_TID_COUNT][4];
  1417. u32 tidtx_inperiod[MAX_TID_COUNT];
  1418. bool higher_busytxtraffic[MAX_TID_COUNT];
  1419. };
  1420. struct rtl_tcb_desc {
  1421. u8 packet_bw:1;
  1422. u8 multicast:1;
  1423. u8 broadcast:1;
  1424. u8 rts_stbc:1;
  1425. u8 rts_enable:1;
  1426. u8 cts_enable:1;
  1427. u8 rts_use_shortpreamble:1;
  1428. u8 rts_use_shortgi:1;
  1429. u8 rts_sc:1;
  1430. u8 rts_bw:1;
  1431. u8 rts_rate;
  1432. u8 use_shortgi:1;
  1433. u8 use_shortpreamble:1;
  1434. u8 use_driver_rate:1;
  1435. u8 disable_ratefallback:1;
  1436. u8 ratr_index;
  1437. u8 mac_id;
  1438. u8 hw_rate;
  1439. u8 last_inipkt:1;
  1440. u8 cmd_or_init:1;
  1441. u8 queue_index;
  1442. /* early mode */
  1443. u8 empkt_num;
  1444. /* The max value by HW */
  1445. u32 empkt_len[10];
  1446. bool btx_enable_sw_calc_duration;
  1447. };
  1448. struct rtl_hal_ops {
  1449. int (*init_sw_vars) (struct ieee80211_hw *hw);
  1450. void (*deinit_sw_vars) (struct ieee80211_hw *hw);
  1451. void (*read_chip_version)(struct ieee80211_hw *hw);
  1452. void (*read_eeprom_info) (struct ieee80211_hw *hw);
  1453. void (*interrupt_recognized) (struct ieee80211_hw *hw,
  1454. u32 *p_inta, u32 *p_intb);
  1455. int (*hw_init) (struct ieee80211_hw *hw);
  1456. void (*hw_disable) (struct ieee80211_hw *hw);
  1457. void (*hw_suspend) (struct ieee80211_hw *hw);
  1458. void (*hw_resume) (struct ieee80211_hw *hw);
  1459. void (*enable_interrupt) (struct ieee80211_hw *hw);
  1460. void (*disable_interrupt) (struct ieee80211_hw *hw);
  1461. int (*set_network_type) (struct ieee80211_hw *hw,
  1462. enum nl80211_iftype type);
  1463. void (*set_chk_bssid)(struct ieee80211_hw *hw,
  1464. bool check_bssid);
  1465. void (*set_bw_mode) (struct ieee80211_hw *hw,
  1466. enum nl80211_channel_type ch_type);
  1467. u8(*switch_channel) (struct ieee80211_hw *hw);
  1468. void (*set_qos) (struct ieee80211_hw *hw, int aci);
  1469. void (*set_bcn_reg) (struct ieee80211_hw *hw);
  1470. void (*set_bcn_intv) (struct ieee80211_hw *hw);
  1471. void (*update_interrupt_mask) (struct ieee80211_hw *hw,
  1472. u32 add_msr, u32 rm_msr);
  1473. void (*get_hw_reg) (struct ieee80211_hw *hw, u8 variable, u8 *val);
  1474. void (*set_hw_reg) (struct ieee80211_hw *hw, u8 variable, u8 *val);
  1475. void (*update_rate_tbl) (struct ieee80211_hw *hw,
  1476. struct ieee80211_sta *sta, u8 rssi_level);
  1477. void (*update_rate_mask) (struct ieee80211_hw *hw, u8 rssi_level);
  1478. void (*fill_tx_desc) (struct ieee80211_hw *hw,
  1479. struct ieee80211_hdr *hdr, u8 *pdesc_tx,
  1480. struct ieee80211_tx_info *info,
  1481. struct ieee80211_sta *sta,
  1482. struct sk_buff *skb, u8 hw_queue,
  1483. struct rtl_tcb_desc *ptcb_desc);
  1484. void (*fill_fake_txdesc) (struct ieee80211_hw *hw, u8 *pDesc,
  1485. u32 buffer_len, bool bIsPsPoll);
  1486. void (*fill_tx_cmddesc) (struct ieee80211_hw *hw, u8 *pdesc,
  1487. bool firstseg, bool lastseg,
  1488. struct sk_buff *skb);
  1489. bool (*cmd_send_packet)(struct ieee80211_hw *hw, struct sk_buff *skb);
  1490. bool (*query_rx_desc) (struct ieee80211_hw *hw,
  1491. struct rtl_stats *stats,
  1492. struct ieee80211_rx_status *rx_status,
  1493. u8 *pdesc, struct sk_buff *skb);
  1494. void (*set_channel_access) (struct ieee80211_hw *hw);
  1495. bool (*radio_onoff_checking) (struct ieee80211_hw *hw, u8 *valid);
  1496. void (*dm_watchdog) (struct ieee80211_hw *hw);
  1497. void (*scan_operation_backup) (struct ieee80211_hw *hw, u8 operation);
  1498. bool (*set_rf_power_state) (struct ieee80211_hw *hw,
  1499. enum rf_pwrstate rfpwr_state);
  1500. void (*led_control) (struct ieee80211_hw *hw,
  1501. enum led_ctl_mode ledaction);
  1502. void (*set_desc) (u8 *pdesc, bool istx, u8 desc_name, u8 *val);
  1503. u32 (*get_desc) (u8 *pdesc, bool istx, u8 desc_name);
  1504. void (*tx_polling) (struct ieee80211_hw *hw, u8 hw_queue);
  1505. void (*enable_hw_sec) (struct ieee80211_hw *hw);
  1506. void (*set_key) (struct ieee80211_hw *hw, u32 key_index,
  1507. u8 *macaddr, bool is_group, u8 enc_algo,
  1508. bool is_wepkey, bool clear_all);
  1509. void (*init_sw_leds) (struct ieee80211_hw *hw);
  1510. void (*deinit_sw_leds) (struct ieee80211_hw *hw);
  1511. u32 (*get_bbreg) (struct ieee80211_hw *hw, u32 regaddr, u32 bitmask);
  1512. void (*set_bbreg) (struct ieee80211_hw *hw, u32 regaddr, u32 bitmask,
  1513. u32 data);
  1514. u32 (*get_rfreg) (struct ieee80211_hw *hw, enum radio_path rfpath,
  1515. u32 regaddr, u32 bitmask);
  1516. void (*set_rfreg) (struct ieee80211_hw *hw, enum radio_path rfpath,
  1517. u32 regaddr, u32 bitmask, u32 data);
  1518. void (*allow_all_destaddr)(struct ieee80211_hw *hw,
  1519. bool allow_all_da, bool write_into_reg);
  1520. void (*linked_set_reg) (struct ieee80211_hw *hw);
  1521. void (*chk_switch_dmdp) (struct ieee80211_hw *hw);
  1522. void (*dualmac_easy_concurrent) (struct ieee80211_hw *hw);
  1523. void (*dualmac_switch_to_dmdp) (struct ieee80211_hw *hw);
  1524. bool (*phy_rf6052_config) (struct ieee80211_hw *hw);
  1525. void (*phy_rf6052_set_cck_txpower) (struct ieee80211_hw *hw,
  1526. u8 *powerlevel);
  1527. void (*phy_rf6052_set_ofdm_txpower) (struct ieee80211_hw *hw,
  1528. u8 *ppowerlevel, u8 channel);
  1529. bool (*config_bb_with_headerfile) (struct ieee80211_hw *hw,
  1530. u8 configtype);
  1531. bool (*config_bb_with_pgheaderfile) (struct ieee80211_hw *hw,
  1532. u8 configtype);
  1533. void (*phy_lc_calibrate) (struct ieee80211_hw *hw, bool is2t);
  1534. void (*phy_set_bw_mode_callback) (struct ieee80211_hw *hw);
  1535. void (*dm_dynamic_txpower) (struct ieee80211_hw *hw);
  1536. void (*c2h_command_handle) (struct ieee80211_hw *hw);
  1537. void (*bt_wifi_media_status_notify) (struct ieee80211_hw *hw,
  1538. bool mstate);
  1539. void (*bt_coex_off_before_lps) (struct ieee80211_hw *hw);
  1540. void (*fill_h2c_cmd) (struct ieee80211_hw *hw, u8 element_id,
  1541. u32 cmd_len, u8 *p_cmdbuffer);
  1542. };
  1543. struct rtl_intf_ops {
  1544. /*com */
  1545. void (*read_efuse_byte)(struct ieee80211_hw *hw, u16 _offset, u8 *pbuf);
  1546. int (*adapter_start) (struct ieee80211_hw *hw);
  1547. void (*adapter_stop) (struct ieee80211_hw *hw);
  1548. bool (*check_buddy_priv)(struct ieee80211_hw *hw,
  1549. struct rtl_priv **buddy_priv);
  1550. int (*adapter_tx) (struct ieee80211_hw *hw,
  1551. struct ieee80211_sta *sta,
  1552. struct sk_buff *skb,
  1553. struct rtl_tcb_desc *ptcb_desc);
  1554. void (*flush)(struct ieee80211_hw *hw, bool drop);
  1555. int (*reset_trx_ring) (struct ieee80211_hw *hw);
  1556. bool (*waitq_insert) (struct ieee80211_hw *hw,
  1557. struct ieee80211_sta *sta,
  1558. struct sk_buff *skb);
  1559. /*pci */
  1560. void (*disable_aspm) (struct ieee80211_hw *hw);
  1561. void (*enable_aspm) (struct ieee80211_hw *hw);
  1562. /*usb */
  1563. };
  1564. struct rtl_mod_params {
  1565. /* default: 0 = using hardware encryption */
  1566. bool sw_crypto;
  1567. /* default: 0 = DBG_EMERG (0)*/
  1568. int debug;
  1569. /* default: 1 = using no linked power save */
  1570. bool inactiveps;
  1571. /* default: 1 = using linked sw power save */
  1572. bool swctrl_lps;
  1573. /* default: 1 = using linked fw power save */
  1574. bool fwctrl_lps;
  1575. };
  1576. struct rtl_hal_usbint_cfg {
  1577. /* data - rx */
  1578. u32 in_ep_num;
  1579. u32 rx_urb_num;
  1580. u32 rx_max_size;
  1581. /* op - rx */
  1582. void (*usb_rx_hdl)(struct ieee80211_hw *, struct sk_buff *);
  1583. void (*usb_rx_segregate_hdl)(struct ieee80211_hw *, struct sk_buff *,
  1584. struct sk_buff_head *);
  1585. /* tx */
  1586. void (*usb_tx_cleanup)(struct ieee80211_hw *, struct sk_buff *);
  1587. int (*usb_tx_post_hdl)(struct ieee80211_hw *, struct urb *,
  1588. struct sk_buff *);
  1589. struct sk_buff *(*usb_tx_aggregate_hdl)(struct ieee80211_hw *,
  1590. struct sk_buff_head *);
  1591. /* endpoint mapping */
  1592. int (*usb_endpoint_mapping)(struct ieee80211_hw *hw);
  1593. u16 (*usb_mq_to_hwq)(__le16 fc, u16 mac80211_queue_index);
  1594. };
  1595. struct rtl_hal_cfg {
  1596. u8 bar_id;
  1597. bool write_readback;
  1598. char *name;
  1599. char *fw_name;
  1600. char *alt_fw_name;
  1601. struct rtl_hal_ops *ops;
  1602. struct rtl_mod_params *mod_params;
  1603. struct rtl_hal_usbint_cfg *usb_interface_cfg;
  1604. /*this map used for some registers or vars
  1605. defined int HAL but used in MAIN */
  1606. u32 maps[RTL_VAR_MAP_MAX];
  1607. };
  1608. struct rtl_locks {
  1609. /* mutex */
  1610. struct mutex conf_mutex;
  1611. struct mutex ps_mutex;
  1612. /*spin lock */
  1613. spinlock_t ips_lock;
  1614. spinlock_t irq_th_lock;
  1615. spinlock_t irq_pci_lock;
  1616. spinlock_t tx_lock;
  1617. spinlock_t h2c_lock;
  1618. spinlock_t rf_ps_lock;
  1619. spinlock_t rf_lock;
  1620. spinlock_t lps_lock;
  1621. spinlock_t waitq_lock;
  1622. spinlock_t entry_list_lock;
  1623. spinlock_t usb_lock;
  1624. /*FW clock change */
  1625. spinlock_t fw_ps_lock;
  1626. /*Dual mac*/
  1627. spinlock_t cck_and_rw_pagea_lock;
  1628. /*Easy concurrent*/
  1629. spinlock_t check_sendpkt_lock;
  1630. };
  1631. struct rtl_works {
  1632. struct ieee80211_hw *hw;
  1633. /*timer */
  1634. struct timer_list watchdog_timer;
  1635. struct timer_list dualmac_easyconcurrent_retrytimer;
  1636. struct timer_list fw_clockoff_timer;
  1637. struct timer_list fast_antenna_training_timer;
  1638. /*task */
  1639. struct tasklet_struct irq_tasklet;
  1640. struct tasklet_struct irq_prepare_bcn_tasklet;
  1641. /*work queue */
  1642. struct workqueue_struct *rtl_wq;
  1643. struct delayed_work watchdog_wq;
  1644. struct delayed_work ips_nic_off_wq;
  1645. /* For SW LPS */
  1646. struct delayed_work ps_work;
  1647. struct delayed_work ps_rfon_wq;
  1648. struct delayed_work fwevt_wq;
  1649. struct work_struct lps_change_work;
  1650. struct work_struct fill_h2c_cmd;
  1651. };
  1652. struct rtl_debug {
  1653. u32 dbgp_type[DBGP_TYPE_MAX];
  1654. int global_debuglevel;
  1655. u64 global_debugcomponents;
  1656. /* add for proc debug */
  1657. struct proc_dir_entry *proc_dir;
  1658. char proc_name[20];
  1659. };
  1660. #define MIMO_PS_STATIC 0
  1661. #define MIMO_PS_DYNAMIC 1
  1662. #define MIMO_PS_NOLIMIT 3
  1663. struct rtl_dualmac_easy_concurrent_ctl {
  1664. enum band_type currentbandtype_backfordmdp;
  1665. bool close_bbandrf_for_dmsp;
  1666. bool change_to_dmdp;
  1667. bool change_to_dmsp;
  1668. bool switch_in_process;
  1669. };
  1670. struct rtl_dmsp_ctl {
  1671. bool activescan_for_slaveofdmsp;
  1672. bool scan_for_anothermac_fordmsp;
  1673. bool scan_for_itself_fordmsp;
  1674. bool writedig_for_anothermacofdmsp;
  1675. u32 curdigvalue_for_anothermacofdmsp;
  1676. bool changecckpdstate_for_anothermacofdmsp;
  1677. u8 curcckpdstate_for_anothermacofdmsp;
  1678. bool changetxhighpowerlvl_for_anothermacofdmsp;
  1679. u8 curtxhighlvl_for_anothermacofdmsp;
  1680. long rssivalmin_for_anothermacofdmsp;
  1681. };
  1682. struct ps_t {
  1683. u8 pre_ccastate;
  1684. u8 cur_ccasate;
  1685. u8 pre_rfstate;
  1686. u8 cur_rfstate;
  1687. long rssi_val_min;
  1688. };
  1689. struct dig_t {
  1690. u32 rssi_lowthresh;
  1691. u32 rssi_highthresh;
  1692. u32 fa_lowthresh;
  1693. u32 fa_highthresh;
  1694. long last_min_undec_pwdb_for_dm;
  1695. long rssi_highpower_lowthresh;
  1696. long rssi_highpower_highthresh;
  1697. u32 recover_cnt;
  1698. u32 pre_igvalue;
  1699. u32 cur_igvalue;
  1700. long rssi_val;
  1701. u8 dig_enable_flag;
  1702. u8 dig_ext_port_stage;
  1703. u8 dig_algorithm;
  1704. u8 dig_twoport_algorithm;
  1705. u8 dig_dbgmode;
  1706. u8 dig_slgorithm_switch;
  1707. u8 cursta_cstate;
  1708. u8 presta_cstate;
  1709. u8 curmultista_cstate;
  1710. char back_val;
  1711. char back_range_max;
  1712. char back_range_min;
  1713. u8 rx_gain_max;
  1714. u8 rx_gain_min;
  1715. u8 min_undec_pwdb_for_dm;
  1716. u8 rssi_val_min;
  1717. u8 pre_cck_cca_thres;
  1718. u8 cur_cck_cca_thres;
  1719. u8 pre_cck_pd_state;
  1720. u8 cur_cck_pd_state;
  1721. u8 pre_cck_fa_state;
  1722. u8 cur_cck_fa_state;
  1723. u8 pre_ccastate;
  1724. u8 cur_ccasate;
  1725. u8 large_fa_hit;
  1726. u8 dig_dynamic_min;
  1727. u8 forbidden_igi;
  1728. u8 dig_state;
  1729. u8 dig_highpwrstate;
  1730. u8 cur_sta_cstate;
  1731. u8 pre_sta_cstate;
  1732. u8 cur_ap_cstate;
  1733. u8 pre_ap_cstate;
  1734. u8 cur_pd_thstate;
  1735. u8 pre_pd_thstate;
  1736. u8 cur_cs_ratiostate;
  1737. u8 pre_cs_ratiostate;
  1738. u8 backoff_enable_flag;
  1739. char backoffval_range_max;
  1740. char backoffval_range_min;
  1741. u8 dig_min_0;
  1742. u8 dig_min_1;
  1743. bool media_connect_0;
  1744. bool media_connect_1;
  1745. u32 antdiv_rssi_max;
  1746. u32 rssi_max;
  1747. };
  1748. struct rtl_global_var {
  1749. /* from this list we can get
  1750. * other adapter's rtl_priv */
  1751. struct list_head glb_priv_list;
  1752. spinlock_t glb_list_lock;
  1753. };
  1754. struct rtl_priv {
  1755. struct ieee80211_hw *hw;
  1756. struct completion firmware_loading_complete;
  1757. struct list_head list;
  1758. struct rtl_priv *buddy_priv;
  1759. struct rtl_global_var *glb_var;
  1760. struct rtl_dualmac_easy_concurrent_ctl easy_concurrent_ctl;
  1761. struct rtl_dmsp_ctl dmsp_ctl;
  1762. struct rtl_locks locks;
  1763. struct rtl_works works;
  1764. struct rtl_mac mac80211;
  1765. struct rtl_hal rtlhal;
  1766. struct rtl_regulatory regd;
  1767. struct rtl_rfkill rfkill;
  1768. struct rtl_io io;
  1769. struct rtl_phy phy;
  1770. struct rtl_dm dm;
  1771. struct rtl_security sec;
  1772. struct rtl_efuse efuse;
  1773. struct rtl_ps_ctl psc;
  1774. struct rate_adaptive ra;
  1775. struct wireless_stats stats;
  1776. struct rt_link_detect link_info;
  1777. struct false_alarm_statistics falsealm_cnt;
  1778. struct rtl_rate_priv *rate_priv;
  1779. /* sta entry list for ap adhoc or mesh */
  1780. struct list_head entry_list;
  1781. struct rtl_debug dbg;
  1782. int max_fw_size;
  1783. /*
  1784. *hal_cfg : for diff cards
  1785. *intf_ops : for diff interrface usb/pcie
  1786. */
  1787. struct rtl_hal_cfg *cfg;
  1788. struct rtl_intf_ops *intf_ops;
  1789. /*this var will be set by set_bit,
  1790. and was used to indicate status of
  1791. interface or hardware */
  1792. unsigned long status;
  1793. /* tables for dm */
  1794. struct dig_t dm_digtable;
  1795. struct ps_t dm_pstable;
  1796. u32 reg_874;
  1797. u32 reg_c70;
  1798. u32 reg_85c;
  1799. u32 reg_a74;
  1800. bool reg_init; /* true if regs saved */
  1801. bool bt_operation_on;
  1802. __le32 *usb_data;
  1803. int usb_data_index;
  1804. bool initialized;
  1805. bool enter_ps; /* true when entering PS */
  1806. u8 rate_mask[5];
  1807. /*This must be the last item so
  1808. that it points to the data allocated
  1809. beyond this structure like:
  1810. rtl_pci_priv or rtl_usb_priv */
  1811. u8 priv[0] __aligned(sizeof(void *));
  1812. };
  1813. #define rtl_priv(hw) (((struct rtl_priv *)(hw)->priv))
  1814. #define rtl_mac(rtlpriv) (&((rtlpriv)->mac80211))
  1815. #define rtl_hal(rtlpriv) (&((rtlpriv)->rtlhal))
  1816. #define rtl_efuse(rtlpriv) (&((rtlpriv)->efuse))
  1817. #define rtl_psc(rtlpriv) (&((rtlpriv)->psc))
  1818. /***************************************
  1819. Bluetooth Co-existence Related
  1820. ****************************************/
  1821. enum bt_ant_num {
  1822. ANT_X2 = 0,
  1823. ANT_X1 = 1,
  1824. };
  1825. enum bt_co_type {
  1826. BT_2WIRE = 0,
  1827. BT_ISSC_3WIRE = 1,
  1828. BT_ACCEL = 2,
  1829. BT_CSR_BC4 = 3,
  1830. BT_CSR_BC8 = 4,
  1831. BT_RTL8756 = 5,
  1832. BT_RTL8723A = 6,
  1833. };
  1834. enum bt_cur_state {
  1835. BT_OFF = 0,
  1836. BT_ON = 1,
  1837. };
  1838. enum bt_service_type {
  1839. BT_SCO = 0,
  1840. BT_A2DP = 1,
  1841. BT_HID = 2,
  1842. BT_HID_IDLE = 3,
  1843. BT_SCAN = 4,
  1844. BT_IDLE = 5,
  1845. BT_OTHER_ACTION = 6,
  1846. BT_BUSY = 7,
  1847. BT_OTHERBUSY = 8,
  1848. BT_PAN = 9,
  1849. };
  1850. enum bt_radio_shared {
  1851. BT_RADIO_SHARED = 0,
  1852. BT_RADIO_INDIVIDUAL = 1,
  1853. };
  1854. struct bt_coexist_info {
  1855. /* EEPROM BT info. */
  1856. u8 eeprom_bt_coexist;
  1857. u8 eeprom_bt_type;
  1858. u8 eeprom_bt_ant_num;
  1859. u8 eeprom_bt_ant_isol;
  1860. u8 eeprom_bt_radio_shared;
  1861. u8 bt_coexistence;
  1862. u8 bt_ant_num;
  1863. u8 bt_coexist_type;
  1864. u8 bt_state;
  1865. u8 bt_cur_state; /* 0:on, 1:off */
  1866. u8 bt_ant_isolation; /* 0:good, 1:bad */
  1867. u8 bt_pape_ctrl; /* 0:SW, 1:SW/HW dynamic */
  1868. u8 bt_service;
  1869. u8 bt_radio_shared_type;
  1870. u8 bt_rfreg_origin_1e;
  1871. u8 bt_rfreg_origin_1f;
  1872. u8 bt_rssi_state;
  1873. u32 ratio_tx;
  1874. u32 ratio_pri;
  1875. u32 bt_edca_ul;
  1876. u32 bt_edca_dl;
  1877. bool init_set;
  1878. bool bt_busy_traffic;
  1879. bool bt_traffic_mode_set;
  1880. bool bt_non_traffic_mode_set;
  1881. bool fw_coexist_all_off;
  1882. bool sw_coexist_all_off;
  1883. bool hw_coexist_all_off;
  1884. u32 cstate;
  1885. u32 previous_state;
  1886. u32 cstate_h;
  1887. u32 previous_state_h;
  1888. u8 bt_pre_rssi_state;
  1889. u8 bt_pre_rssi_state1;
  1890. u8 reg_bt_iso;
  1891. u8 reg_bt_sco;
  1892. bool balance_on;
  1893. u8 bt_active_zero_cnt;
  1894. bool cur_bt_disabled;
  1895. bool pre_bt_disabled;
  1896. u8 bt_profile_case;
  1897. u8 bt_profile_action;
  1898. bool bt_busy;
  1899. bool hold_for_bt_operation;
  1900. u8 lps_counter;
  1901. };
  1902. /****************************************
  1903. mem access macro define start
  1904. Call endian free function when
  1905. 1. Read/write packet content.
  1906. 2. Before write integer to IO.
  1907. 3. After read integer from IO.
  1908. ****************************************/
  1909. /* Convert little data endian to host ordering */
  1910. #define EF1BYTE(_val) \
  1911. ((u8)(_val))
  1912. #define EF2BYTE(_val) \
  1913. (le16_to_cpu(_val))
  1914. #define EF4BYTE(_val) \
  1915. (le32_to_cpu(_val))
  1916. /* Read data from memory */
  1917. #define READEF1BYTE(_ptr) \
  1918. EF1BYTE(*((u8 *)(_ptr)))
  1919. /* Read le16 data from memory and convert to host ordering */
  1920. #define READEF2BYTE(_ptr) \
  1921. EF2BYTE(*(_ptr))
  1922. #define READEF4BYTE(_ptr) \
  1923. EF4BYTE(*(_ptr))
  1924. /* Write data to memory */
  1925. #define WRITEEF1BYTE(_ptr, _val) \
  1926. (*((u8 *)(_ptr))) = EF1BYTE(_val)
  1927. /* Write le16 data to memory in host ordering */
  1928. #define WRITEEF2BYTE(_ptr, _val) \
  1929. (*((u16 *)(_ptr))) = EF2BYTE(_val)
  1930. #define WRITEEF4BYTE(_ptr, _val) \
  1931. (*((u32 *)(_ptr))) = EF2BYTE(_val)
  1932. /* Create a bit mask
  1933. * Examples:
  1934. * BIT_LEN_MASK_32(0) => 0x00000000
  1935. * BIT_LEN_MASK_32(1) => 0x00000001
  1936. * BIT_LEN_MASK_32(2) => 0x00000003
  1937. * BIT_LEN_MASK_32(32) => 0xFFFFFFFF
  1938. */
  1939. #define BIT_LEN_MASK_32(__bitlen) \
  1940. (0xFFFFFFFF >> (32 - (__bitlen)))
  1941. #define BIT_LEN_MASK_16(__bitlen) \
  1942. (0xFFFF >> (16 - (__bitlen)))
  1943. #define BIT_LEN_MASK_8(__bitlen) \
  1944. (0xFF >> (8 - (__bitlen)))
  1945. /* Create an offset bit mask
  1946. * Examples:
  1947. * BIT_OFFSET_LEN_MASK_32(0, 2) => 0x00000003
  1948. * BIT_OFFSET_LEN_MASK_32(16, 2) => 0x00030000
  1949. */
  1950. #define BIT_OFFSET_LEN_MASK_32(__bitoffset, __bitlen) \
  1951. (BIT_LEN_MASK_32(__bitlen) << (__bitoffset))
  1952. #define BIT_OFFSET_LEN_MASK_16(__bitoffset, __bitlen) \
  1953. (BIT_LEN_MASK_16(__bitlen) << (__bitoffset))
  1954. #define BIT_OFFSET_LEN_MASK_8(__bitoffset, __bitlen) \
  1955. (BIT_LEN_MASK_8(__bitlen) << (__bitoffset))
  1956. /*Description:
  1957. * Return 4-byte value in host byte ordering from
  1958. * 4-byte pointer in little-endian system.
  1959. */
  1960. #define LE_P4BYTE_TO_HOST_4BYTE(__pstart) \
  1961. (EF4BYTE(*((__le32 *)(__pstart))))
  1962. #define LE_P2BYTE_TO_HOST_2BYTE(__pstart) \
  1963. (EF2BYTE(*((__le16 *)(__pstart))))
  1964. #define LE_P1BYTE_TO_HOST_1BYTE(__pstart) \
  1965. (EF1BYTE(*((u8 *)(__pstart))))
  1966. /*Description:
  1967. Translate subfield (continuous bits in little-endian) of 4-byte
  1968. value to host byte ordering.*/
  1969. #define LE_BITS_TO_4BYTE(__pstart, __bitoffset, __bitlen) \
  1970. ( \
  1971. (LE_P4BYTE_TO_HOST_4BYTE(__pstart) >> (__bitoffset)) & \
  1972. BIT_LEN_MASK_32(__bitlen) \
  1973. )
  1974. #define LE_BITS_TO_2BYTE(__pstart, __bitoffset, __bitlen) \
  1975. ( \
  1976. (LE_P2BYTE_TO_HOST_2BYTE(__pstart) >> (__bitoffset)) & \
  1977. BIT_LEN_MASK_16(__bitlen) \
  1978. )
  1979. #define LE_BITS_TO_1BYTE(__pstart, __bitoffset, __bitlen) \
  1980. ( \
  1981. (LE_P1BYTE_TO_HOST_1BYTE(__pstart) >> (__bitoffset)) & \
  1982. BIT_LEN_MASK_8(__bitlen) \
  1983. )
  1984. /* Description:
  1985. * Mask subfield (continuous bits in little-endian) of 4-byte value
  1986. * and return the result in 4-byte value in host byte ordering.
  1987. */
  1988. #define LE_BITS_CLEARED_TO_4BYTE(__pstart, __bitoffset, __bitlen) \
  1989. ( \
  1990. LE_P4BYTE_TO_HOST_4BYTE(__pstart) & \
  1991. (~BIT_OFFSET_LEN_MASK_32(__bitoffset, __bitlen)) \
  1992. )
  1993. #define LE_BITS_CLEARED_TO_2BYTE(__pstart, __bitoffset, __bitlen) \
  1994. ( \
  1995. LE_P2BYTE_TO_HOST_2BYTE(__pstart) & \
  1996. (~BIT_OFFSET_LEN_MASK_16(__bitoffset, __bitlen)) \
  1997. )
  1998. #define LE_BITS_CLEARED_TO_1BYTE(__pstart, __bitoffset, __bitlen) \
  1999. ( \
  2000. LE_P1BYTE_TO_HOST_1BYTE(__pstart) & \
  2001. (~BIT_OFFSET_LEN_MASK_8(__bitoffset, __bitlen)) \
  2002. )
  2003. /* Description:
  2004. * Set subfield of little-endian 4-byte value to specified value.
  2005. */
  2006. #define SET_BITS_TO_LE_4BYTE(__pstart, __bitoffset, __bitlen, __val) \
  2007. *((u32 *)(__pstart)) = \
  2008. ( \
  2009. LE_BITS_CLEARED_TO_4BYTE(__pstart, __bitoffset, __bitlen) | \
  2010. ((((u32)__val) & BIT_LEN_MASK_32(__bitlen)) << (__bitoffset)) \
  2011. );
  2012. #define SET_BITS_TO_LE_2BYTE(__pstart, __bitoffset, __bitlen, __val) \
  2013. *((u16 *)(__pstart)) = \
  2014. ( \
  2015. LE_BITS_CLEARED_TO_2BYTE(__pstart, __bitoffset, __bitlen) | \
  2016. ((((u16)__val) & BIT_LEN_MASK_16(__bitlen)) << (__bitoffset)) \
  2017. );
  2018. #define SET_BITS_TO_LE_1BYTE(__pstart, __bitoffset, __bitlen, __val) \
  2019. *((u8 *)(__pstart)) = EF1BYTE \
  2020. ( \
  2021. LE_BITS_CLEARED_TO_1BYTE(__pstart, __bitoffset, __bitlen) | \
  2022. ((((u8)__val) & BIT_LEN_MASK_8(__bitlen)) << (__bitoffset)) \
  2023. );
  2024. #define N_BYTE_ALIGMENT(__value, __aligment) ((__aligment == 1) ? \
  2025. (__value) : (((__value + __aligment - 1) / __aligment) * __aligment))
  2026. /****************************************
  2027. mem access macro define end
  2028. ****************************************/
  2029. #define byte(x, n) ((x >> (8 * n)) & 0xff)
  2030. #define packet_get_type(_packet) (EF1BYTE((_packet).octet[0]) & 0xFC)
  2031. #define RTL_WATCH_DOG_TIME 2000
  2032. #define MSECS(t) msecs_to_jiffies(t)
  2033. #define WLAN_FC_GET_VERS(fc) (le16_to_cpu(fc) & IEEE80211_FCTL_VERS)
  2034. #define WLAN_FC_GET_TYPE(fc) (le16_to_cpu(fc) & IEEE80211_FCTL_FTYPE)
  2035. #define WLAN_FC_GET_STYPE(fc) (le16_to_cpu(fc) & IEEE80211_FCTL_STYPE)
  2036. #define WLAN_FC_MORE_DATA(fc) (le16_to_cpu(fc) & IEEE80211_FCTL_MOREDATA)
  2037. #define rtl_dm(rtlpriv) (&((rtlpriv)->dm))
  2038. #define RT_RF_OFF_LEVL_ASPM BIT(0) /*PCI ASPM */
  2039. #define RT_RF_OFF_LEVL_CLK_REQ BIT(1) /*PCI clock request */
  2040. #define RT_RF_OFF_LEVL_PCI_D3 BIT(2) /*PCI D3 mode */
  2041. /*NIC halt, re-initialize hw parameters*/
  2042. #define RT_RF_OFF_LEVL_HALT_NIC BIT(3)
  2043. #define RT_RF_OFF_LEVL_FREE_FW BIT(4) /*FW free, re-download the FW */
  2044. #define RT_RF_OFF_LEVL_FW_32K BIT(5) /*FW in 32k */
  2045. /*Always enable ASPM and Clock Req in initialization.*/
  2046. #define RT_RF_PS_LEVEL_ALWAYS_ASPM BIT(6)
  2047. /* no matter RFOFF or SLEEP we set PS_ASPM_LEVL*/
  2048. #define RT_PS_LEVEL_ASPM BIT(7)
  2049. /*When LPS is on, disable 2R if no packet is received or transmittd.*/
  2050. #define RT_RF_LPS_DISALBE_2R BIT(30)
  2051. #define RT_RF_LPS_LEVEL_ASPM BIT(31) /*LPS with ASPM */
  2052. #define RT_IN_PS_LEVEL(ppsc, _ps_flg) \
  2053. ((ppsc->cur_ps_level & _ps_flg) ? true : false)
  2054. #define RT_CLEAR_PS_LEVEL(ppsc, _ps_flg) \
  2055. (ppsc->cur_ps_level &= (~(_ps_flg)))
  2056. #define RT_SET_PS_LEVEL(ppsc, _ps_flg) \
  2057. (ppsc->cur_ps_level |= _ps_flg)
  2058. #define container_of_dwork_rtl(x, y, z) \
  2059. container_of(container_of(x, struct delayed_work, work), y, z)
  2060. #define FILL_OCTET_STRING(_os, _octet, _len) \
  2061. (_os).octet = (u8 *)(_octet); \
  2062. (_os).length = (_len);
  2063. #define CP_MACADDR(des, src) \
  2064. ((des)[0] = (src)[0], (des)[1] = (src)[1],\
  2065. (des)[2] = (src)[2], (des)[3] = (src)[3],\
  2066. (des)[4] = (src)[4], (des)[5] = (src)[5])
  2067. static inline u8 rtl_read_byte(struct rtl_priv *rtlpriv, u32 addr)
  2068. {
  2069. return rtlpriv->io.read8_sync(rtlpriv, addr);
  2070. }
  2071. static inline u16 rtl_read_word(struct rtl_priv *rtlpriv, u32 addr)
  2072. {
  2073. return rtlpriv->io.read16_sync(rtlpriv, addr);
  2074. }
  2075. static inline u32 rtl_read_dword(struct rtl_priv *rtlpriv, u32 addr)
  2076. {
  2077. return rtlpriv->io.read32_sync(rtlpriv, addr);
  2078. }
  2079. static inline void rtl_write_byte(struct rtl_priv *rtlpriv, u32 addr, u8 val8)
  2080. {
  2081. rtlpriv->io.write8_async(rtlpriv, addr, val8);
  2082. if (rtlpriv->cfg->write_readback)
  2083. rtlpriv->io.read8_sync(rtlpriv, addr);
  2084. }
  2085. static inline void rtl_write_word(struct rtl_priv *rtlpriv, u32 addr, u16 val16)
  2086. {
  2087. rtlpriv->io.write16_async(rtlpriv, addr, val16);
  2088. if (rtlpriv->cfg->write_readback)
  2089. rtlpriv->io.read16_sync(rtlpriv, addr);
  2090. }
  2091. static inline void rtl_write_dword(struct rtl_priv *rtlpriv,
  2092. u32 addr, u32 val32)
  2093. {
  2094. rtlpriv->io.write32_async(rtlpriv, addr, val32);
  2095. if (rtlpriv->cfg->write_readback)
  2096. rtlpriv->io.read32_sync(rtlpriv, addr);
  2097. }
  2098. static inline u32 rtl_get_bbreg(struct ieee80211_hw *hw,
  2099. u32 regaddr, u32 bitmask)
  2100. {
  2101. struct rtl_priv *rtlpriv = hw->priv;
  2102. return rtlpriv->cfg->ops->get_bbreg(hw, regaddr, bitmask);
  2103. }
  2104. static inline void rtl_set_bbreg(struct ieee80211_hw *hw, u32 regaddr,
  2105. u32 bitmask, u32 data)
  2106. {
  2107. struct rtl_priv *rtlpriv = hw->priv;
  2108. rtlpriv->cfg->ops->set_bbreg(hw, regaddr, bitmask, data);
  2109. }
  2110. static inline u32 rtl_get_rfreg(struct ieee80211_hw *hw,
  2111. enum radio_path rfpath, u32 regaddr,
  2112. u32 bitmask)
  2113. {
  2114. struct rtl_priv *rtlpriv = hw->priv;
  2115. return rtlpriv->cfg->ops->get_rfreg(hw, rfpath, regaddr, bitmask);
  2116. }
  2117. static inline void rtl_set_rfreg(struct ieee80211_hw *hw,
  2118. enum radio_path rfpath, u32 regaddr,
  2119. u32 bitmask, u32 data)
  2120. {
  2121. struct rtl_priv *rtlpriv = hw->priv;
  2122. rtlpriv->cfg->ops->set_rfreg(hw, rfpath, regaddr, bitmask, data);
  2123. }
  2124. static inline bool is_hal_stop(struct rtl_hal *rtlhal)
  2125. {
  2126. return (_HAL_STATE_STOP == rtlhal->state);
  2127. }
  2128. static inline void set_hal_start(struct rtl_hal *rtlhal)
  2129. {
  2130. rtlhal->state = _HAL_STATE_START;
  2131. }
  2132. static inline void set_hal_stop(struct rtl_hal *rtlhal)
  2133. {
  2134. rtlhal->state = _HAL_STATE_STOP;
  2135. }
  2136. static inline u8 get_rf_type(struct rtl_phy *rtlphy)
  2137. {
  2138. return rtlphy->rf_type;
  2139. }
  2140. static inline struct ieee80211_hdr *rtl_get_hdr(struct sk_buff *skb)
  2141. {
  2142. return (struct ieee80211_hdr *)(skb->data);
  2143. }
  2144. static inline __le16 rtl_get_fc(struct sk_buff *skb)
  2145. {
  2146. return rtl_get_hdr(skb)->frame_control;
  2147. }
  2148. static inline u16 rtl_get_tid_h(struct ieee80211_hdr *hdr)
  2149. {
  2150. return (ieee80211_get_qos_ctl(hdr))[0] & IEEE80211_QOS_CTL_TID_MASK;
  2151. }
  2152. static inline u16 rtl_get_tid(struct sk_buff *skb)
  2153. {
  2154. return rtl_get_tid_h(rtl_get_hdr(skb));
  2155. }
  2156. static inline struct ieee80211_sta *get_sta(struct ieee80211_hw *hw,
  2157. struct ieee80211_vif *vif,
  2158. const u8 *bssid)
  2159. {
  2160. return ieee80211_find_sta(vif, bssid);
  2161. }
  2162. static inline struct ieee80211_sta *rtl_find_sta(struct ieee80211_hw *hw,
  2163. u8 *mac_addr)
  2164. {
  2165. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  2166. return ieee80211_find_sta(mac->vif, mac_addr);
  2167. }
  2168. #endif