wifi.h 58 KB

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