wifi.h 47 KB

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