wifi.h 56 KB

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