wifi.h 44 KB

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