wifi.h 47 KB

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