base.c 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551
  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. * The full GNU General Public License is included in this distribution in the
  15. * file called LICENSE.
  16. *
  17. * Contact Information:
  18. * wlanfae <wlanfae@realtek.com>
  19. * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  20. * Hsinchu 300, Taiwan.
  21. *
  22. * Larry Finger <Larry.Finger@lwfinger.net>
  23. *
  24. *****************************************************************************/
  25. #include "wifi.h"
  26. #include "rc.h"
  27. #include "base.h"
  28. #include "efuse.h"
  29. #include "cam.h"
  30. #include "ps.h"
  31. #include "regd.h"
  32. #include "pci.h"
  33. #include <linux/ip.h>
  34. #include <linux/module.h>
  35. #include <linux/udp.h>
  36. /*
  37. *NOTICE!!!: This file will be very big, we should
  38. *keep it clear under following roles:
  39. *
  40. *This file include following parts, so, if you add new
  41. *functions into this file, please check which part it
  42. *should includes. or check if you should add new part
  43. *for this file:
  44. *
  45. *1) mac80211 init functions
  46. *2) tx information functions
  47. *3) functions called by core.c
  48. *4) wq & timer callback functions
  49. *5) frame process functions
  50. *6) IOT functions
  51. *7) sysfs functions
  52. *8) vif functions
  53. *9) ...
  54. */
  55. /*********************************************************
  56. *
  57. * mac80211 init functions
  58. *
  59. *********************************************************/
  60. static struct ieee80211_channel rtl_channeltable_2g[] = {
  61. {.center_freq = 2412, .hw_value = 1,},
  62. {.center_freq = 2417, .hw_value = 2,},
  63. {.center_freq = 2422, .hw_value = 3,},
  64. {.center_freq = 2427, .hw_value = 4,},
  65. {.center_freq = 2432, .hw_value = 5,},
  66. {.center_freq = 2437, .hw_value = 6,},
  67. {.center_freq = 2442, .hw_value = 7,},
  68. {.center_freq = 2447, .hw_value = 8,},
  69. {.center_freq = 2452, .hw_value = 9,},
  70. {.center_freq = 2457, .hw_value = 10,},
  71. {.center_freq = 2462, .hw_value = 11,},
  72. {.center_freq = 2467, .hw_value = 12,},
  73. {.center_freq = 2472, .hw_value = 13,},
  74. {.center_freq = 2484, .hw_value = 14,},
  75. };
  76. static struct ieee80211_channel rtl_channeltable_5g[] = {
  77. {.center_freq = 5180, .hw_value = 36,},
  78. {.center_freq = 5200, .hw_value = 40,},
  79. {.center_freq = 5220, .hw_value = 44,},
  80. {.center_freq = 5240, .hw_value = 48,},
  81. {.center_freq = 5260, .hw_value = 52,},
  82. {.center_freq = 5280, .hw_value = 56,},
  83. {.center_freq = 5300, .hw_value = 60,},
  84. {.center_freq = 5320, .hw_value = 64,},
  85. {.center_freq = 5500, .hw_value = 100,},
  86. {.center_freq = 5520, .hw_value = 104,},
  87. {.center_freq = 5540, .hw_value = 108,},
  88. {.center_freq = 5560, .hw_value = 112,},
  89. {.center_freq = 5580, .hw_value = 116,},
  90. {.center_freq = 5600, .hw_value = 120,},
  91. {.center_freq = 5620, .hw_value = 124,},
  92. {.center_freq = 5640, .hw_value = 128,},
  93. {.center_freq = 5660, .hw_value = 132,},
  94. {.center_freq = 5680, .hw_value = 136,},
  95. {.center_freq = 5700, .hw_value = 140,},
  96. {.center_freq = 5745, .hw_value = 149,},
  97. {.center_freq = 5765, .hw_value = 153,},
  98. {.center_freq = 5785, .hw_value = 157,},
  99. {.center_freq = 5805, .hw_value = 161,},
  100. {.center_freq = 5825, .hw_value = 165,},
  101. };
  102. static struct ieee80211_rate rtl_ratetable_2g[] = {
  103. {.bitrate = 10, .hw_value = 0x00,},
  104. {.bitrate = 20, .hw_value = 0x01,},
  105. {.bitrate = 55, .hw_value = 0x02,},
  106. {.bitrate = 110, .hw_value = 0x03,},
  107. {.bitrate = 60, .hw_value = 0x04,},
  108. {.bitrate = 90, .hw_value = 0x05,},
  109. {.bitrate = 120, .hw_value = 0x06,},
  110. {.bitrate = 180, .hw_value = 0x07,},
  111. {.bitrate = 240, .hw_value = 0x08,},
  112. {.bitrate = 360, .hw_value = 0x09,},
  113. {.bitrate = 480, .hw_value = 0x0a,},
  114. {.bitrate = 540, .hw_value = 0x0b,},
  115. };
  116. static struct ieee80211_rate rtl_ratetable_5g[] = {
  117. {.bitrate = 60, .hw_value = 0x04,},
  118. {.bitrate = 90, .hw_value = 0x05,},
  119. {.bitrate = 120, .hw_value = 0x06,},
  120. {.bitrate = 180, .hw_value = 0x07,},
  121. {.bitrate = 240, .hw_value = 0x08,},
  122. {.bitrate = 360, .hw_value = 0x09,},
  123. {.bitrate = 480, .hw_value = 0x0a,},
  124. {.bitrate = 540, .hw_value = 0x0b,},
  125. };
  126. static const struct ieee80211_supported_band rtl_band_2ghz = {
  127. .band = NL80211_BAND_2GHZ,
  128. .channels = rtl_channeltable_2g,
  129. .n_channels = ARRAY_SIZE(rtl_channeltable_2g),
  130. .bitrates = rtl_ratetable_2g,
  131. .n_bitrates = ARRAY_SIZE(rtl_ratetable_2g),
  132. .ht_cap = {0},
  133. };
  134. static struct ieee80211_supported_band rtl_band_5ghz = {
  135. .band = NL80211_BAND_5GHZ,
  136. .channels = rtl_channeltable_5g,
  137. .n_channels = ARRAY_SIZE(rtl_channeltable_5g),
  138. .bitrates = rtl_ratetable_5g,
  139. .n_bitrates = ARRAY_SIZE(rtl_ratetable_5g),
  140. .ht_cap = {0},
  141. };
  142. static const u8 tid_to_ac[] = {
  143. 2, /* IEEE80211_AC_BE */
  144. 3, /* IEEE80211_AC_BK */
  145. 3, /* IEEE80211_AC_BK */
  146. 2, /* IEEE80211_AC_BE */
  147. 1, /* IEEE80211_AC_VI */
  148. 1, /* IEEE80211_AC_VI */
  149. 0, /* IEEE80211_AC_VO */
  150. 0, /* IEEE80211_AC_VO */
  151. };
  152. u8 rtl_tid_to_ac(u8 tid)
  153. {
  154. return tid_to_ac[tid];
  155. }
  156. EXPORT_SYMBOL_GPL(rtl_tid_to_ac);
  157. static void _rtl_init_hw_ht_capab(struct ieee80211_hw *hw,
  158. struct ieee80211_sta_ht_cap *ht_cap)
  159. {
  160. struct rtl_priv *rtlpriv = rtl_priv(hw);
  161. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  162. ht_cap->ht_supported = true;
  163. ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  164. IEEE80211_HT_CAP_SGI_40 |
  165. IEEE80211_HT_CAP_SGI_20 |
  166. IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU;
  167. if (rtlpriv->rtlhal.disable_amsdu_8k)
  168. ht_cap->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
  169. /*
  170. *Maximum length of AMPDU that the STA can receive.
  171. *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
  172. */
  173. ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  174. /*Minimum MPDU start spacing , */
  175. ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
  176. ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  177. /*hw->wiphy->bands[NL80211_BAND_2GHZ]
  178. *base on ant_num
  179. *rx_mask: RX mask
  180. *if rx_ant = 1 rx_mask[0]= 0xff;==>MCS0-MCS7
  181. *if rx_ant = 2 rx_mask[1]= 0xff;==>MCS8-MCS15
  182. *if rx_ant >= 3 rx_mask[2]= 0xff;
  183. *if BW_40 rx_mask[4]= 0x01;
  184. *highest supported RX rate
  185. */
  186. if (rtlpriv->dm.supp_phymode_switch) {
  187. pr_info("Support phy mode switch\n");
  188. ht_cap->mcs.rx_mask[0] = 0xFF;
  189. ht_cap->mcs.rx_mask[1] = 0xFF;
  190. ht_cap->mcs.rx_mask[4] = 0x01;
  191. ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
  192. } else {
  193. if (get_rf_type(rtlphy) == RF_1T2R ||
  194. get_rf_type(rtlphy) == RF_2T2R) {
  195. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  196. "1T2R or 2T2R\n");
  197. ht_cap->mcs.rx_mask[0] = 0xFF;
  198. ht_cap->mcs.rx_mask[1] = 0xFF;
  199. ht_cap->mcs.rx_mask[4] = 0x01;
  200. ht_cap->mcs.rx_highest =
  201. cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
  202. } else if (get_rf_type(rtlphy) == RF_1T1R) {
  203. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "1T1R\n");
  204. ht_cap->mcs.rx_mask[0] = 0xFF;
  205. ht_cap->mcs.rx_mask[1] = 0x00;
  206. ht_cap->mcs.rx_mask[4] = 0x01;
  207. ht_cap->mcs.rx_highest =
  208. cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7);
  209. }
  210. }
  211. }
  212. static void _rtl_init_hw_vht_capab(struct ieee80211_hw *hw,
  213. struct ieee80211_sta_vht_cap *vht_cap)
  214. {
  215. struct rtl_priv *rtlpriv = rtl_priv(hw);
  216. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  217. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE) {
  218. u16 mcs_map;
  219. vht_cap->vht_supported = true;
  220. vht_cap->cap =
  221. IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
  222. IEEE80211_VHT_CAP_SHORT_GI_80 |
  223. IEEE80211_VHT_CAP_TXSTBC |
  224. IEEE80211_VHT_CAP_RXSTBC_1 |
  225. IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
  226. IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  227. IEEE80211_VHT_CAP_HTC_VHT |
  228. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
  229. IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
  230. IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
  231. 0;
  232. mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
  233. IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 |
  234. IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
  235. IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
  236. IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
  237. IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
  238. IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
  239. IEEE80211_VHT_MCS_NOT_SUPPORTED << 14;
  240. vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
  241. vht_cap->vht_mcs.rx_highest =
  242. cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9);
  243. vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
  244. vht_cap->vht_mcs.tx_highest =
  245. cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9);
  246. } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) {
  247. u16 mcs_map;
  248. vht_cap->vht_supported = true;
  249. vht_cap->cap =
  250. IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
  251. IEEE80211_VHT_CAP_SHORT_GI_80 |
  252. IEEE80211_VHT_CAP_TXSTBC |
  253. IEEE80211_VHT_CAP_RXSTBC_1 |
  254. IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
  255. IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  256. IEEE80211_VHT_CAP_HTC_VHT |
  257. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
  258. IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
  259. IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
  260. 0;
  261. mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
  262. IEEE80211_VHT_MCS_NOT_SUPPORTED << 2 |
  263. IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
  264. IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
  265. IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
  266. IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
  267. IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
  268. IEEE80211_VHT_MCS_NOT_SUPPORTED << 14;
  269. vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
  270. vht_cap->vht_mcs.rx_highest =
  271. cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9);
  272. vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
  273. vht_cap->vht_mcs.tx_highest =
  274. cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9);
  275. }
  276. }
  277. static void _rtl_init_mac80211(struct ieee80211_hw *hw)
  278. {
  279. struct rtl_priv *rtlpriv = rtl_priv(hw);
  280. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  281. struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
  282. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  283. struct ieee80211_supported_band *sband;
  284. if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY &&
  285. rtlhal->bandset == BAND_ON_BOTH) {
  286. /* 1: 2.4 G bands */
  287. /* <1> use mac->bands as mem for hw->wiphy->bands */
  288. sband = &(rtlmac->bands[NL80211_BAND_2GHZ]);
  289. /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ]
  290. * to default value(1T1R) */
  291. memcpy(&(rtlmac->bands[NL80211_BAND_2GHZ]), &rtl_band_2ghz,
  292. sizeof(struct ieee80211_supported_band));
  293. /* <3> init ht cap base on ant_num */
  294. _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
  295. /* <4> set mac->sband to wiphy->sband */
  296. hw->wiphy->bands[NL80211_BAND_2GHZ] = sband;
  297. /* 2: 5 G bands */
  298. /* <1> use mac->bands as mem for hw->wiphy->bands */
  299. sband = &(rtlmac->bands[NL80211_BAND_5GHZ]);
  300. /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ]
  301. * to default value(1T1R) */
  302. memcpy(&(rtlmac->bands[NL80211_BAND_5GHZ]), &rtl_band_5ghz,
  303. sizeof(struct ieee80211_supported_band));
  304. /* <3> init ht cap base on ant_num */
  305. _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
  306. _rtl_init_hw_vht_capab(hw, &sband->vht_cap);
  307. /* <4> set mac->sband to wiphy->sband */
  308. hw->wiphy->bands[NL80211_BAND_5GHZ] = sband;
  309. } else {
  310. if (rtlhal->current_bandtype == BAND_ON_2_4G) {
  311. /* <1> use mac->bands as mem for hw->wiphy->bands */
  312. sband = &(rtlmac->bands[NL80211_BAND_2GHZ]);
  313. /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ]
  314. * to default value(1T1R) */
  315. memcpy(&(rtlmac->bands[NL80211_BAND_2GHZ]),
  316. &rtl_band_2ghz,
  317. sizeof(struct ieee80211_supported_band));
  318. /* <3> init ht cap base on ant_num */
  319. _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
  320. /* <4> set mac->sband to wiphy->sband */
  321. hw->wiphy->bands[NL80211_BAND_2GHZ] = sband;
  322. } else if (rtlhal->current_bandtype == BAND_ON_5G) {
  323. /* <1> use mac->bands as mem for hw->wiphy->bands */
  324. sband = &(rtlmac->bands[NL80211_BAND_5GHZ]);
  325. /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ]
  326. * to default value(1T1R) */
  327. memcpy(&(rtlmac->bands[NL80211_BAND_5GHZ]),
  328. &rtl_band_5ghz,
  329. sizeof(struct ieee80211_supported_band));
  330. /* <3> init ht cap base on ant_num */
  331. _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
  332. _rtl_init_hw_vht_capab(hw, &sband->vht_cap);
  333. /* <4> set mac->sband to wiphy->sband */
  334. hw->wiphy->bands[NL80211_BAND_5GHZ] = sband;
  335. } else {
  336. pr_err("Err BAND %d\n",
  337. rtlhal->current_bandtype);
  338. }
  339. }
  340. /* <5> set hw caps */
  341. ieee80211_hw_set(hw, SIGNAL_DBM);
  342. ieee80211_hw_set(hw, RX_INCLUDES_FCS);
  343. ieee80211_hw_set(hw, AMPDU_AGGREGATION);
  344. ieee80211_hw_set(hw, CONNECTION_MONITOR);
  345. ieee80211_hw_set(hw, MFP_CAPABLE);
  346. ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
  347. /* swlps or hwlps has been set in diff chip in init_sw_vars */
  348. if (rtlpriv->psc.swctrl_lps) {
  349. ieee80211_hw_set(hw, SUPPORTS_PS);
  350. ieee80211_hw_set(hw, PS_NULLFUNC_STACK);
  351. }
  352. if (rtlpriv->psc.fwctrl_lps) {
  353. ieee80211_hw_set(hw, SUPPORTS_PS);
  354. ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
  355. }
  356. hw->wiphy->interface_modes =
  357. BIT(NL80211_IFTYPE_AP) |
  358. BIT(NL80211_IFTYPE_STATION) |
  359. BIT(NL80211_IFTYPE_ADHOC) |
  360. BIT(NL80211_IFTYPE_MESH_POINT) |
  361. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  362. BIT(NL80211_IFTYPE_P2P_GO);
  363. hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
  364. hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  365. hw->wiphy->rts_threshold = 2347;
  366. hw->queues = AC_MAX;
  367. hw->extra_tx_headroom = RTL_TX_HEADER_SIZE;
  368. /* TODO: Correct this value for our hw */
  369. hw->max_listen_interval = MAX_LISTEN_INTERVAL;
  370. hw->max_rate_tries = MAX_RATE_TRIES;
  371. /* hw->max_rates = 1; */
  372. hw->sta_data_size = sizeof(struct rtl_sta_info);
  373. /* wowlan is not supported by kernel if CONFIG_PM is not defined */
  374. #ifdef CONFIG_PM
  375. if (rtlpriv->psc.wo_wlan_mode) {
  376. if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_MAGIC_PACKET)
  377. rtlpriv->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT;
  378. if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_PATTERN_MATCH) {
  379. rtlpriv->wowlan.n_patterns =
  380. MAX_SUPPORT_WOL_PATTERN_NUM;
  381. rtlpriv->wowlan.pattern_min_len = MIN_WOL_PATTERN_SIZE;
  382. rtlpriv->wowlan.pattern_max_len = MAX_WOL_PATTERN_SIZE;
  383. }
  384. hw->wiphy->wowlan = &rtlpriv->wowlan;
  385. }
  386. #endif
  387. /* <6> mac address */
  388. if (is_valid_ether_addr(rtlefuse->dev_addr)) {
  389. SET_IEEE80211_PERM_ADDR(hw, rtlefuse->dev_addr);
  390. } else {
  391. u8 rtlmac1[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 };
  392. get_random_bytes((rtlmac1 + (ETH_ALEN - 1)), 1);
  393. SET_IEEE80211_PERM_ADDR(hw, rtlmac1);
  394. }
  395. }
  396. static void _rtl_init_deferred_work(struct ieee80211_hw *hw)
  397. {
  398. struct rtl_priv *rtlpriv = rtl_priv(hw);
  399. /* <1> timer */
  400. timer_setup(&rtlpriv->works.watchdog_timer,
  401. rtl_watch_dog_timer_callback, 0);
  402. timer_setup(&rtlpriv->works.dualmac_easyconcurrent_retrytimer,
  403. rtl_easy_concurrent_retrytimer_callback, 0);
  404. /* <2> work queue */
  405. rtlpriv->works.hw = hw;
  406. rtlpriv->works.rtl_wq = alloc_workqueue("%s", 0, 0, rtlpriv->cfg->name);
  407. INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq,
  408. (void *)rtl_watchdog_wq_callback);
  409. INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq,
  410. (void *)rtl_ips_nic_off_wq_callback);
  411. INIT_DELAYED_WORK(&rtlpriv->works.ps_work,
  412. (void *)rtl_swlps_wq_callback);
  413. INIT_DELAYED_WORK(&rtlpriv->works.ps_rfon_wq,
  414. (void *)rtl_swlps_rfon_wq_callback);
  415. INIT_DELAYED_WORK(&rtlpriv->works.fwevt_wq,
  416. (void *)rtl_fwevt_wq_callback);
  417. INIT_DELAYED_WORK(&rtlpriv->works.c2hcmd_wq,
  418. (void *)rtl_c2hcmd_wq_callback);
  419. }
  420. void rtl_deinit_deferred_work(struct ieee80211_hw *hw)
  421. {
  422. struct rtl_priv *rtlpriv = rtl_priv(hw);
  423. del_timer_sync(&rtlpriv->works.watchdog_timer);
  424. cancel_delayed_work(&rtlpriv->works.watchdog_wq);
  425. cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq);
  426. cancel_delayed_work(&rtlpriv->works.ps_work);
  427. cancel_delayed_work(&rtlpriv->works.ps_rfon_wq);
  428. cancel_delayed_work(&rtlpriv->works.fwevt_wq);
  429. cancel_delayed_work(&rtlpriv->works.c2hcmd_wq);
  430. }
  431. EXPORT_SYMBOL_GPL(rtl_deinit_deferred_work);
  432. void rtl_init_rfkill(struct ieee80211_hw *hw)
  433. {
  434. struct rtl_priv *rtlpriv = rtl_priv(hw);
  435. bool radio_state;
  436. bool blocked;
  437. u8 valid = 0;
  438. /*set init state to on */
  439. rtlpriv->rfkill.rfkill_state = true;
  440. wiphy_rfkill_set_hw_state(hw->wiphy, 0);
  441. radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
  442. if (valid) {
  443. pr_info("rtlwifi: wireless switch is %s\n",
  444. rtlpriv->rfkill.rfkill_state ? "on" : "off");
  445. rtlpriv->rfkill.rfkill_state = radio_state;
  446. blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
  447. wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
  448. }
  449. wiphy_rfkill_start_polling(hw->wiphy);
  450. }
  451. EXPORT_SYMBOL(rtl_init_rfkill);
  452. void rtl_deinit_rfkill(struct ieee80211_hw *hw)
  453. {
  454. wiphy_rfkill_stop_polling(hw->wiphy);
  455. }
  456. EXPORT_SYMBOL_GPL(rtl_deinit_rfkill);
  457. int rtl_init_core(struct ieee80211_hw *hw)
  458. {
  459. struct rtl_priv *rtlpriv = rtl_priv(hw);
  460. struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
  461. /* <1> init mac80211 */
  462. _rtl_init_mac80211(hw);
  463. rtlmac->hw = hw;
  464. /* <2> rate control register */
  465. hw->rate_control_algorithm = "rtl_rc";
  466. /*
  467. * <3> init CRDA must come after init
  468. * mac80211 hw in _rtl_init_mac80211.
  469. */
  470. if (rtl_regd_init(hw, rtl_reg_notifier)) {
  471. pr_err("REGD init failed\n");
  472. return 1;
  473. }
  474. /* <4> locks */
  475. mutex_init(&rtlpriv->locks.conf_mutex);
  476. mutex_init(&rtlpriv->locks.ips_mutex);
  477. mutex_init(&rtlpriv->locks.lps_mutex);
  478. spin_lock_init(&rtlpriv->locks.irq_th_lock);
  479. spin_lock_init(&rtlpriv->locks.h2c_lock);
  480. spin_lock_init(&rtlpriv->locks.rf_ps_lock);
  481. spin_lock_init(&rtlpriv->locks.rf_lock);
  482. spin_lock_init(&rtlpriv->locks.waitq_lock);
  483. spin_lock_init(&rtlpriv->locks.entry_list_lock);
  484. spin_lock_init(&rtlpriv->locks.c2hcmd_lock);
  485. spin_lock_init(&rtlpriv->locks.scan_list_lock);
  486. spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock);
  487. spin_lock_init(&rtlpriv->locks.fw_ps_lock);
  488. spin_lock_init(&rtlpriv->locks.iqk_lock);
  489. /* <5> init list */
  490. INIT_LIST_HEAD(&rtlpriv->entry_list);
  491. INIT_LIST_HEAD(&rtlpriv->c2hcmd_list);
  492. INIT_LIST_HEAD(&rtlpriv->scan_list.list);
  493. rtlmac->link_state = MAC80211_NOLINK;
  494. /* <6> init deferred work */
  495. _rtl_init_deferred_work(hw);
  496. return 0;
  497. }
  498. EXPORT_SYMBOL_GPL(rtl_init_core);
  499. static void rtl_free_entries_from_scan_list(struct ieee80211_hw *hw);
  500. void rtl_deinit_core(struct ieee80211_hw *hw)
  501. {
  502. rtl_c2hcmd_launcher(hw, 0);
  503. rtl_free_entries_from_scan_list(hw);
  504. }
  505. EXPORT_SYMBOL_GPL(rtl_deinit_core);
  506. void rtl_init_rx_config(struct ieee80211_hw *hw)
  507. {
  508. struct rtl_priv *rtlpriv = rtl_priv(hw);
  509. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  510. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf));
  511. }
  512. EXPORT_SYMBOL_GPL(rtl_init_rx_config);
  513. /*********************************************************
  514. *
  515. * tx information functions
  516. *
  517. *********************************************************/
  518. static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw,
  519. struct rtl_tcb_desc *tcb_desc,
  520. struct ieee80211_tx_info *info)
  521. {
  522. struct rtl_priv *rtlpriv = rtl_priv(hw);
  523. u8 rate_flag = info->control.rates[0].flags;
  524. tcb_desc->use_shortpreamble = false;
  525. /* 1M can only use Long Preamble. 11B spec */
  526. if (tcb_desc->hw_rate == rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M])
  527. return;
  528. else if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
  529. tcb_desc->use_shortpreamble = true;
  530. return;
  531. }
  532. static void _rtl_query_shortgi(struct ieee80211_hw *hw,
  533. struct ieee80211_sta *sta,
  534. struct rtl_tcb_desc *tcb_desc,
  535. struct ieee80211_tx_info *info)
  536. {
  537. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  538. u8 rate_flag = info->control.rates[0].flags;
  539. u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0;
  540. u8 sgi_80 = 0, bw_80 = 0;
  541. tcb_desc->use_shortgi = false;
  542. if (sta == NULL)
  543. return;
  544. sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40;
  545. sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20;
  546. sgi_80 = sta->vht_cap.cap & IEEE80211_VHT_CAP_SHORT_GI_80;
  547. if ((!sta->ht_cap.ht_supported) && (!sta->vht_cap.vht_supported))
  548. return;
  549. if (!sgi_40 && !sgi_20)
  550. return;
  551. if (mac->opmode == NL80211_IFTYPE_STATION) {
  552. bw_40 = mac->bw_40;
  553. bw_80 = mac->bw_80;
  554. } else if (mac->opmode == NL80211_IFTYPE_AP ||
  555. mac->opmode == NL80211_IFTYPE_ADHOC ||
  556. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  557. bw_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  558. bw_80 = sta->vht_cap.vht_supported;
  559. }
  560. if (bw_80) {
  561. if (sgi_80)
  562. tcb_desc->use_shortgi = true;
  563. else
  564. tcb_desc->use_shortgi = false;
  565. } else {
  566. if (bw_40 && sgi_40)
  567. tcb_desc->use_shortgi = true;
  568. else if (!bw_40 && sgi_20)
  569. tcb_desc->use_shortgi = true;
  570. }
  571. if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI))
  572. tcb_desc->use_shortgi = false;
  573. }
  574. static void _rtl_query_protection_mode(struct ieee80211_hw *hw,
  575. struct rtl_tcb_desc *tcb_desc,
  576. struct ieee80211_tx_info *info)
  577. {
  578. struct rtl_priv *rtlpriv = rtl_priv(hw);
  579. u8 rate_flag = info->control.rates[0].flags;
  580. /* Common Settings */
  581. tcb_desc->rts_stbc = false;
  582. tcb_desc->cts_enable = false;
  583. tcb_desc->rts_sc = 0;
  584. tcb_desc->rts_bw = false;
  585. tcb_desc->rts_use_shortpreamble = false;
  586. tcb_desc->rts_use_shortgi = false;
  587. if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) {
  588. /* Use CTS-to-SELF in protection mode. */
  589. tcb_desc->rts_enable = true;
  590. tcb_desc->cts_enable = true;
  591. tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
  592. } else if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) {
  593. /* Use RTS-CTS in protection mode. */
  594. tcb_desc->rts_enable = true;
  595. tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
  596. }
  597. }
  598. static void _rtl_txrate_selectmode(struct ieee80211_hw *hw,
  599. struct ieee80211_sta *sta,
  600. struct rtl_tcb_desc *tcb_desc)
  601. {
  602. struct rtl_priv *rtlpriv = rtl_priv(hw);
  603. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  604. struct rtl_sta_info *sta_entry = NULL;
  605. u8 ratr_index = 7;
  606. if (sta) {
  607. sta_entry = (struct rtl_sta_info *) sta->drv_priv;
  608. ratr_index = sta_entry->ratr_index;
  609. }
  610. if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) {
  611. if (mac->opmode == NL80211_IFTYPE_STATION) {
  612. tcb_desc->ratr_index = 0;
  613. } else if (mac->opmode == NL80211_IFTYPE_ADHOC ||
  614. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  615. if (tcb_desc->multicast || tcb_desc->broadcast) {
  616. tcb_desc->hw_rate =
  617. rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M];
  618. tcb_desc->use_driver_rate = 1;
  619. tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
  620. } else {
  621. tcb_desc->ratr_index = ratr_index;
  622. }
  623. } else if (mac->opmode == NL80211_IFTYPE_AP) {
  624. tcb_desc->ratr_index = ratr_index;
  625. }
  626. }
  627. if (rtlpriv->dm.useramask) {
  628. tcb_desc->ratr_index = ratr_index;
  629. /* TODO we will differentiate adhoc and station future */
  630. if (mac->opmode == NL80211_IFTYPE_STATION ||
  631. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  632. tcb_desc->mac_id = 0;
  633. if (mac->mode == WIRELESS_MODE_AC_5G)
  634. tcb_desc->ratr_index =
  635. RATR_INX_WIRELESS_AC_5N;
  636. else if (mac->mode == WIRELESS_MODE_AC_24G)
  637. tcb_desc->ratr_index =
  638. RATR_INX_WIRELESS_AC_24N;
  639. else if (mac->mode == WIRELESS_MODE_N_24G)
  640. tcb_desc->ratr_index = RATR_INX_WIRELESS_NGB;
  641. else if (mac->mode == WIRELESS_MODE_N_5G)
  642. tcb_desc->ratr_index = RATR_INX_WIRELESS_NG;
  643. else if (mac->mode & WIRELESS_MODE_G)
  644. tcb_desc->ratr_index = RATR_INX_WIRELESS_GB;
  645. else if (mac->mode & WIRELESS_MODE_B)
  646. tcb_desc->ratr_index = RATR_INX_WIRELESS_B;
  647. else if (mac->mode & WIRELESS_MODE_A)
  648. tcb_desc->ratr_index = RATR_INX_WIRELESS_G;
  649. } else if (mac->opmode == NL80211_IFTYPE_AP ||
  650. mac->opmode == NL80211_IFTYPE_ADHOC) {
  651. if (NULL != sta) {
  652. if (sta->aid > 0)
  653. tcb_desc->mac_id = sta->aid + 1;
  654. else
  655. tcb_desc->mac_id = 1;
  656. } else {
  657. tcb_desc->mac_id = 0;
  658. }
  659. }
  660. }
  661. }
  662. static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw,
  663. struct ieee80211_sta *sta,
  664. struct rtl_tcb_desc *tcb_desc)
  665. {
  666. struct rtl_priv *rtlpriv = rtl_priv(hw);
  667. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  668. tcb_desc->packet_bw = false;
  669. if (!sta)
  670. return;
  671. if (mac->opmode == NL80211_IFTYPE_AP ||
  672. mac->opmode == NL80211_IFTYPE_ADHOC ||
  673. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  674. if (!(sta->ht_cap.ht_supported) ||
  675. !(sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
  676. return;
  677. } else if (mac->opmode == NL80211_IFTYPE_STATION) {
  678. if (!mac->bw_40 || !(sta->ht_cap.ht_supported))
  679. return;
  680. }
  681. if (tcb_desc->multicast || tcb_desc->broadcast)
  682. return;
  683. /*use legency rate, shall use 20MHz */
  684. if (tcb_desc->hw_rate <= rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M])
  685. return;
  686. tcb_desc->packet_bw = HT_CHANNEL_WIDTH_20_40;
  687. if (rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8812AE ||
  688. rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8821AE) {
  689. if (mac->opmode == NL80211_IFTYPE_AP ||
  690. mac->opmode == NL80211_IFTYPE_ADHOC ||
  691. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  692. if (!(sta->vht_cap.vht_supported))
  693. return;
  694. } else if (mac->opmode == NL80211_IFTYPE_STATION) {
  695. if (!mac->bw_80 ||
  696. !(sta->vht_cap.vht_supported))
  697. return;
  698. }
  699. if (tcb_desc->hw_rate <=
  700. rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15])
  701. return;
  702. tcb_desc->packet_bw = HT_CHANNEL_WIDTH_80;
  703. }
  704. }
  705. static u8 _rtl_get_vht_highest_n_rate(struct ieee80211_hw *hw,
  706. struct ieee80211_sta *sta)
  707. {
  708. struct rtl_priv *rtlpriv = rtl_priv(hw);
  709. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  710. u8 hw_rate;
  711. u16 tx_mcs_map = le16_to_cpu(sta->vht_cap.vht_mcs.tx_mcs_map);
  712. if ((get_rf_type(rtlphy) == RF_2T2R) &&
  713. (tx_mcs_map & 0x000c) != 0x000c) {
  714. if ((tx_mcs_map & 0x000c) >> 2 ==
  715. IEEE80211_VHT_MCS_SUPPORT_0_7)
  716. hw_rate =
  717. rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS7];
  718. else if ((tx_mcs_map & 0x000c) >> 2 ==
  719. IEEE80211_VHT_MCS_SUPPORT_0_8)
  720. hw_rate =
  721. rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS8];
  722. else
  723. hw_rate =
  724. rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9];
  725. } else {
  726. if ((tx_mcs_map & 0x0003) ==
  727. IEEE80211_VHT_MCS_SUPPORT_0_7)
  728. hw_rate =
  729. rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS7];
  730. else if ((tx_mcs_map & 0x0003) ==
  731. IEEE80211_VHT_MCS_SUPPORT_0_8)
  732. hw_rate =
  733. rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS8];
  734. else
  735. hw_rate =
  736. rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9];
  737. }
  738. return hw_rate;
  739. }
  740. static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw,
  741. struct ieee80211_sta *sta)
  742. {
  743. struct rtl_priv *rtlpriv = rtl_priv(hw);
  744. struct rtl_phy *rtlphy = &rtlpriv->phy;
  745. u8 hw_rate;
  746. if (get_rf_type(rtlphy) == RF_2T2R &&
  747. sta->ht_cap.mcs.rx_mask[1] != 0)
  748. hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15];
  749. else
  750. hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS7];
  751. return hw_rate;
  752. }
  753. /* mac80211's rate_idx is like this:
  754. *
  755. * 2.4G band:rx_status->band == NL80211_BAND_2GHZ
  756. *
  757. * B/G rate:
  758. * (rx_status->flag & RX_FLAG_HT) = 0,
  759. * DESC_RATE1M-->DESC_RATE54M ==> idx is 0-->11,
  760. *
  761. * N rate:
  762. * (rx_status->flag & RX_FLAG_HT) = 1,
  763. * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
  764. *
  765. * 5G band:rx_status->band == NL80211_BAND_5GHZ
  766. * A rate:
  767. * (rx_status->flag & RX_FLAG_HT) = 0,
  768. * DESC_RATE6M-->DESC_RATE54M ==> idx is 0-->7,
  769. *
  770. * N rate:
  771. * (rx_status->flag & RX_FLAG_HT) = 1,
  772. * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
  773. *
  774. * VHT rates:
  775. * DESC_RATEVHT1SS_MCS0-->DESC_RATEVHT1SS_MCS9 ==> idx is 0-->9
  776. * DESC_RATEVHT2SS_MCS0-->DESC_RATEVHT2SS_MCS9 ==> idx is 0-->9
  777. */
  778. int rtlwifi_rate_mapping(struct ieee80211_hw *hw, bool isht, bool isvht,
  779. u8 desc_rate)
  780. {
  781. int rate_idx;
  782. if (isvht) {
  783. switch (desc_rate) {
  784. case DESC_RATEVHT1SS_MCS0:
  785. rate_idx = 0;
  786. break;
  787. case DESC_RATEVHT1SS_MCS1:
  788. rate_idx = 1;
  789. break;
  790. case DESC_RATEVHT1SS_MCS2:
  791. rate_idx = 2;
  792. break;
  793. case DESC_RATEVHT1SS_MCS3:
  794. rate_idx = 3;
  795. break;
  796. case DESC_RATEVHT1SS_MCS4:
  797. rate_idx = 4;
  798. break;
  799. case DESC_RATEVHT1SS_MCS5:
  800. rate_idx = 5;
  801. break;
  802. case DESC_RATEVHT1SS_MCS6:
  803. rate_idx = 6;
  804. break;
  805. case DESC_RATEVHT1SS_MCS7:
  806. rate_idx = 7;
  807. break;
  808. case DESC_RATEVHT1SS_MCS8:
  809. rate_idx = 8;
  810. break;
  811. case DESC_RATEVHT1SS_MCS9:
  812. rate_idx = 9;
  813. break;
  814. case DESC_RATEVHT2SS_MCS0:
  815. rate_idx = 0;
  816. break;
  817. case DESC_RATEVHT2SS_MCS1:
  818. rate_idx = 1;
  819. break;
  820. case DESC_RATEVHT2SS_MCS2:
  821. rate_idx = 2;
  822. break;
  823. case DESC_RATEVHT2SS_MCS3:
  824. rate_idx = 3;
  825. break;
  826. case DESC_RATEVHT2SS_MCS4:
  827. rate_idx = 4;
  828. break;
  829. case DESC_RATEVHT2SS_MCS5:
  830. rate_idx = 5;
  831. break;
  832. case DESC_RATEVHT2SS_MCS6:
  833. rate_idx = 6;
  834. break;
  835. case DESC_RATEVHT2SS_MCS7:
  836. rate_idx = 7;
  837. break;
  838. case DESC_RATEVHT2SS_MCS8:
  839. rate_idx = 8;
  840. break;
  841. case DESC_RATEVHT2SS_MCS9:
  842. rate_idx = 9;
  843. break;
  844. default:
  845. rate_idx = 0;
  846. break;
  847. }
  848. return rate_idx;
  849. }
  850. if (false == isht) {
  851. if (NL80211_BAND_2GHZ == hw->conf.chandef.chan->band) {
  852. switch (desc_rate) {
  853. case DESC_RATE1M:
  854. rate_idx = 0;
  855. break;
  856. case DESC_RATE2M:
  857. rate_idx = 1;
  858. break;
  859. case DESC_RATE5_5M:
  860. rate_idx = 2;
  861. break;
  862. case DESC_RATE11M:
  863. rate_idx = 3;
  864. break;
  865. case DESC_RATE6M:
  866. rate_idx = 4;
  867. break;
  868. case DESC_RATE9M:
  869. rate_idx = 5;
  870. break;
  871. case DESC_RATE12M:
  872. rate_idx = 6;
  873. break;
  874. case DESC_RATE18M:
  875. rate_idx = 7;
  876. break;
  877. case DESC_RATE24M:
  878. rate_idx = 8;
  879. break;
  880. case DESC_RATE36M:
  881. rate_idx = 9;
  882. break;
  883. case DESC_RATE48M:
  884. rate_idx = 10;
  885. break;
  886. case DESC_RATE54M:
  887. rate_idx = 11;
  888. break;
  889. default:
  890. rate_idx = 0;
  891. break;
  892. }
  893. } else {
  894. switch (desc_rate) {
  895. case DESC_RATE6M:
  896. rate_idx = 0;
  897. break;
  898. case DESC_RATE9M:
  899. rate_idx = 1;
  900. break;
  901. case DESC_RATE12M:
  902. rate_idx = 2;
  903. break;
  904. case DESC_RATE18M:
  905. rate_idx = 3;
  906. break;
  907. case DESC_RATE24M:
  908. rate_idx = 4;
  909. break;
  910. case DESC_RATE36M:
  911. rate_idx = 5;
  912. break;
  913. case DESC_RATE48M:
  914. rate_idx = 6;
  915. break;
  916. case DESC_RATE54M:
  917. rate_idx = 7;
  918. break;
  919. default:
  920. rate_idx = 0;
  921. break;
  922. }
  923. }
  924. } else {
  925. switch (desc_rate) {
  926. case DESC_RATEMCS0:
  927. rate_idx = 0;
  928. break;
  929. case DESC_RATEMCS1:
  930. rate_idx = 1;
  931. break;
  932. case DESC_RATEMCS2:
  933. rate_idx = 2;
  934. break;
  935. case DESC_RATEMCS3:
  936. rate_idx = 3;
  937. break;
  938. case DESC_RATEMCS4:
  939. rate_idx = 4;
  940. break;
  941. case DESC_RATEMCS5:
  942. rate_idx = 5;
  943. break;
  944. case DESC_RATEMCS6:
  945. rate_idx = 6;
  946. break;
  947. case DESC_RATEMCS7:
  948. rate_idx = 7;
  949. break;
  950. case DESC_RATEMCS8:
  951. rate_idx = 8;
  952. break;
  953. case DESC_RATEMCS9:
  954. rate_idx = 9;
  955. break;
  956. case DESC_RATEMCS10:
  957. rate_idx = 10;
  958. break;
  959. case DESC_RATEMCS11:
  960. rate_idx = 11;
  961. break;
  962. case DESC_RATEMCS12:
  963. rate_idx = 12;
  964. break;
  965. case DESC_RATEMCS13:
  966. rate_idx = 13;
  967. break;
  968. case DESC_RATEMCS14:
  969. rate_idx = 14;
  970. break;
  971. case DESC_RATEMCS15:
  972. rate_idx = 15;
  973. break;
  974. default:
  975. rate_idx = 0;
  976. break;
  977. }
  978. }
  979. return rate_idx;
  980. }
  981. EXPORT_SYMBOL(rtlwifi_rate_mapping);
  982. static u8 _rtl_get_tx_hw_rate(struct ieee80211_hw *hw,
  983. struct ieee80211_tx_info *info)
  984. {
  985. struct rtl_priv *rtlpriv = rtl_priv(hw);
  986. struct ieee80211_tx_rate *r = &info->status.rates[0];
  987. struct ieee80211_rate *txrate;
  988. u8 hw_value = 0x0;
  989. if (r->flags & IEEE80211_TX_RC_MCS) {
  990. /* HT MCS0-15 */
  991. hw_value = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15] - 15 +
  992. r->idx;
  993. } else if (r->flags & IEEE80211_TX_RC_VHT_MCS) {
  994. /* VHT MCS0-9, NSS */
  995. if (ieee80211_rate_get_vht_nss(r) == 2)
  996. hw_value = rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9];
  997. else
  998. hw_value = rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9];
  999. hw_value = hw_value - 9 + ieee80211_rate_get_vht_mcs(r);
  1000. } else {
  1001. /* legacy */
  1002. txrate = ieee80211_get_tx_rate(hw, info);
  1003. if (txrate)
  1004. hw_value = txrate->hw_value;
  1005. }
  1006. /* check 5G band */
  1007. if (rtlpriv->rtlhal.current_bandtype == BAND_ON_5G &&
  1008. hw_value < rtlpriv->cfg->maps[RTL_RC_OFDM_RATE6M])
  1009. hw_value = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE6M];
  1010. return hw_value;
  1011. }
  1012. void rtl_get_tcb_desc(struct ieee80211_hw *hw,
  1013. struct ieee80211_tx_info *info,
  1014. struct ieee80211_sta *sta,
  1015. struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc)
  1016. {
  1017. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1018. struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
  1019. struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
  1020. __le16 fc = rtl_get_fc(skb);
  1021. tcb_desc->hw_rate = _rtl_get_tx_hw_rate(hw, info);
  1022. if (rtl_is_tx_report_skb(hw, skb))
  1023. tcb_desc->use_spe_rpt = 1;
  1024. if (ieee80211_is_data(fc)) {
  1025. /*
  1026. *we set data rate INX 0
  1027. *in rtl_rc.c if skb is special data or
  1028. *mgt which need low data rate.
  1029. */
  1030. /*
  1031. *So tcb_desc->hw_rate is just used for
  1032. *special data and mgt frames
  1033. */
  1034. if (info->control.rates[0].idx == 0 ||
  1035. ieee80211_is_nullfunc(fc)) {
  1036. tcb_desc->use_driver_rate = true;
  1037. tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
  1038. tcb_desc->disable_ratefallback = 1;
  1039. } else {
  1040. /*
  1041. *because hw will nerver use hw_rate
  1042. *when tcb_desc->use_driver_rate = false
  1043. *so we never set highest N rate here,
  1044. *and N rate will all be controlled by FW
  1045. *when tcb_desc->use_driver_rate = false
  1046. */
  1047. if (sta && sta->vht_cap.vht_supported) {
  1048. tcb_desc->hw_rate =
  1049. _rtl_get_vht_highest_n_rate(hw, sta);
  1050. } else {
  1051. if (sta && sta->ht_cap.ht_supported) {
  1052. tcb_desc->hw_rate =
  1053. _rtl_get_highest_n_rate(hw, sta);
  1054. } else {
  1055. if (rtlmac->mode == WIRELESS_MODE_B) {
  1056. tcb_desc->hw_rate =
  1057. rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M];
  1058. } else {
  1059. tcb_desc->hw_rate =
  1060. rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M];
  1061. }
  1062. }
  1063. }
  1064. }
  1065. if (is_multicast_ether_addr(hdr->addr1))
  1066. tcb_desc->multicast = 1;
  1067. else if (is_broadcast_ether_addr(hdr->addr1))
  1068. tcb_desc->broadcast = 1;
  1069. _rtl_txrate_selectmode(hw, sta, tcb_desc);
  1070. _rtl_query_bandwidth_mode(hw, sta, tcb_desc);
  1071. _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info);
  1072. _rtl_query_shortgi(hw, sta, tcb_desc, info);
  1073. _rtl_query_protection_mode(hw, tcb_desc, info);
  1074. } else {
  1075. tcb_desc->use_driver_rate = true;
  1076. tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
  1077. tcb_desc->disable_ratefallback = 1;
  1078. tcb_desc->mac_id = 0;
  1079. tcb_desc->packet_bw = false;
  1080. }
  1081. }
  1082. EXPORT_SYMBOL(rtl_get_tcb_desc);
  1083. bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb)
  1084. {
  1085. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1086. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1087. __le16 fc = rtl_get_fc(skb);
  1088. if (rtlpriv->dm.supp_phymode_switch &&
  1089. mac->link_state < MAC80211_LINKED &&
  1090. (ieee80211_is_auth(fc) || ieee80211_is_probe_req(fc))) {
  1091. if (rtlpriv->cfg->ops->chk_switch_dmdp)
  1092. rtlpriv->cfg->ops->chk_switch_dmdp(hw);
  1093. }
  1094. if (ieee80211_is_auth(fc)) {
  1095. RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "MAC80211_LINKING\n");
  1096. mac->link_state = MAC80211_LINKING;
  1097. /* Dul mac */
  1098. rtlpriv->phy.need_iqk = true;
  1099. }
  1100. return true;
  1101. }
  1102. EXPORT_SYMBOL_GPL(rtl_tx_mgmt_proc);
  1103. struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw, u8 *sa,
  1104. u8 *bssid, u16 tid);
  1105. static void process_agg_start(struct ieee80211_hw *hw,
  1106. struct ieee80211_hdr *hdr, u16 tid)
  1107. {
  1108. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1109. struct ieee80211_rx_status rx_status = { 0 };
  1110. struct sk_buff *skb_delba = NULL;
  1111. skb_delba = rtl_make_del_ba(hw, hdr->addr2, hdr->addr3, tid);
  1112. if (skb_delba) {
  1113. rx_status.freq = hw->conf.chandef.chan->center_freq;
  1114. rx_status.band = hw->conf.chandef.chan->band;
  1115. rx_status.flag |= RX_FLAG_DECRYPTED;
  1116. rx_status.flag |= RX_FLAG_MACTIME_START;
  1117. rx_status.rate_idx = 0;
  1118. rx_status.signal = 50 + 10;
  1119. memcpy(IEEE80211_SKB_RXCB(skb_delba),
  1120. &rx_status, sizeof(rx_status));
  1121. RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG,
  1122. "fake del\n",
  1123. skb_delba->data,
  1124. skb_delba->len);
  1125. ieee80211_rx_irqsafe(hw, skb_delba);
  1126. }
  1127. }
  1128. bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
  1129. {
  1130. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1131. struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
  1132. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1133. __le16 fc = rtl_get_fc(skb);
  1134. u8 *act = (u8 *)(((u8 *)skb->data + MAC80211_3ADDR_LEN));
  1135. u8 category;
  1136. if (!ieee80211_is_action(fc))
  1137. return true;
  1138. category = *act;
  1139. act++;
  1140. switch (category) {
  1141. case ACT_CAT_BA:
  1142. switch (*act) {
  1143. case ACT_ADDBAREQ:
  1144. if (mac->act_scanning)
  1145. return false;
  1146. RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
  1147. "%s ACT_ADDBAREQ From :%pM\n",
  1148. is_tx ? "Tx" : "Rx", hdr->addr2);
  1149. RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "req\n",
  1150. skb->data, skb->len);
  1151. if (!is_tx) {
  1152. struct ieee80211_sta *sta = NULL;
  1153. struct rtl_sta_info *sta_entry = NULL;
  1154. struct rtl_tid_data *tid_data;
  1155. struct ieee80211_mgmt *mgmt = (void *)skb->data;
  1156. u16 capab = 0, tid = 0;
  1157. rcu_read_lock();
  1158. sta = rtl_find_sta(hw, hdr->addr3);
  1159. if (sta == NULL) {
  1160. RT_TRACE(rtlpriv, COMP_SEND | COMP_RECV,
  1161. DBG_DMESG, "sta is NULL\n");
  1162. rcu_read_unlock();
  1163. return true;
  1164. }
  1165. sta_entry =
  1166. (struct rtl_sta_info *)sta->drv_priv;
  1167. if (!sta_entry) {
  1168. rcu_read_unlock();
  1169. return true;
  1170. }
  1171. capab =
  1172. le16_to_cpu(mgmt->u.action.u.addba_req.capab);
  1173. tid = (capab &
  1174. IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
  1175. if (tid >= MAX_TID_COUNT) {
  1176. rcu_read_unlock();
  1177. return true;
  1178. }
  1179. tid_data = &sta_entry->tids[tid];
  1180. if (tid_data->agg.rx_agg_state ==
  1181. RTL_RX_AGG_START)
  1182. process_agg_start(hw, hdr, tid);
  1183. rcu_read_unlock();
  1184. }
  1185. break;
  1186. case ACT_ADDBARSP:
  1187. RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
  1188. "%s ACT_ADDBARSP From :%pM\n",
  1189. is_tx ? "Tx" : "Rx", hdr->addr2);
  1190. break;
  1191. case ACT_DELBA:
  1192. RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
  1193. "ACT_ADDBADEL From :%pM\n", hdr->addr2);
  1194. break;
  1195. }
  1196. break;
  1197. default:
  1198. break;
  1199. }
  1200. return true;
  1201. }
  1202. EXPORT_SYMBOL_GPL(rtl_action_proc);
  1203. static void setup_special_tx(struct rtl_priv *rtlpriv, struct rtl_ps_ctl *ppsc,
  1204. int type)
  1205. {
  1206. struct ieee80211_hw *hw = rtlpriv->hw;
  1207. rtlpriv->ra.is_special_data = true;
  1208. if (rtlpriv->cfg->ops->get_btc_status())
  1209. rtlpriv->btcoexist.btc_ops->btc_special_packet_notify(
  1210. rtlpriv, type);
  1211. rtl_lps_leave(hw);
  1212. ppsc->last_delaylps_stamp_jiffies = jiffies;
  1213. }
  1214. static const u8 *rtl_skb_ether_type_ptr(struct ieee80211_hw *hw,
  1215. struct sk_buff *skb, bool is_enc)
  1216. {
  1217. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1218. u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb);
  1219. u8 encrypt_header_len = 0;
  1220. u8 offset;
  1221. switch (rtlpriv->sec.pairwise_enc_algorithm) {
  1222. case WEP40_ENCRYPTION:
  1223. case WEP104_ENCRYPTION:
  1224. encrypt_header_len = 4;/*WEP_IV_LEN*/
  1225. break;
  1226. case TKIP_ENCRYPTION:
  1227. encrypt_header_len = 8;/*TKIP_IV_LEN*/
  1228. break;
  1229. case AESCCMP_ENCRYPTION:
  1230. encrypt_header_len = 8;/*CCMP_HDR_LEN;*/
  1231. break;
  1232. default:
  1233. break;
  1234. }
  1235. offset = mac_hdr_len + SNAP_SIZE;
  1236. if (is_enc)
  1237. offset += encrypt_header_len;
  1238. return skb->data + offset;
  1239. }
  1240. /*should call before software enc*/
  1241. u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx,
  1242. bool is_enc)
  1243. {
  1244. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1245. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1246. __le16 fc = rtl_get_fc(skb);
  1247. u16 ether_type;
  1248. const u8 *ether_type_ptr;
  1249. const struct iphdr *ip;
  1250. if (!ieee80211_is_data(fc))
  1251. goto end;
  1252. ether_type_ptr = rtl_skb_ether_type_ptr(hw, skb, is_enc);
  1253. ether_type = be16_to_cpup((__be16 *)ether_type_ptr);
  1254. if (ETH_P_IP == ether_type) {
  1255. ip = (struct iphdr *)((u8 *)ether_type_ptr +
  1256. PROTOC_TYPE_SIZE);
  1257. if (IPPROTO_UDP == ip->protocol) {
  1258. struct udphdr *udp = (struct udphdr *)((u8 *)ip +
  1259. (ip->ihl << 2));
  1260. if (((((u8 *)udp)[1] == 68) &&
  1261. (((u8 *)udp)[3] == 67)) ||
  1262. ((((u8 *)udp)[1] == 67) &&
  1263. (((u8 *)udp)[3] == 68))) {
  1264. /* 68 : UDP BOOTP client
  1265. * 67 : UDP BOOTP server
  1266. */
  1267. RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV),
  1268. DBG_DMESG, "dhcp %s !!\n",
  1269. (is_tx) ? "Tx" : "Rx");
  1270. if (is_tx)
  1271. setup_special_tx(rtlpriv, ppsc,
  1272. PACKET_DHCP);
  1273. return true;
  1274. }
  1275. }
  1276. } else if (ETH_P_ARP == ether_type) {
  1277. if (is_tx)
  1278. setup_special_tx(rtlpriv, ppsc, PACKET_ARP);
  1279. return true;
  1280. } else if (ETH_P_PAE == ether_type) {
  1281. /* EAPOL is seens as in-4way */
  1282. rtlpriv->btcoexist.btc_info.in_4way = true;
  1283. rtlpriv->btcoexist.btc_info.in_4way_ts = jiffies;
  1284. rtlpriv->btcoexist.btc_info.in_4way_ts = jiffies;
  1285. RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
  1286. "802.1X %s EAPOL pkt!!\n", (is_tx) ? "Tx" : "Rx");
  1287. if (is_tx) {
  1288. rtlpriv->ra.is_special_data = true;
  1289. rtl_lps_leave(hw);
  1290. ppsc->last_delaylps_stamp_jiffies = jiffies;
  1291. setup_special_tx(rtlpriv, ppsc, PACKET_EAPOL);
  1292. }
  1293. return true;
  1294. } else if (ETH_P_IPV6 == ether_type) {
  1295. /* TODO: Handle any IPv6 cases that need special handling.
  1296. * For now, always return false
  1297. */
  1298. goto end;
  1299. }
  1300. end:
  1301. rtlpriv->ra.is_special_data = false;
  1302. return false;
  1303. }
  1304. EXPORT_SYMBOL_GPL(rtl_is_special_data);
  1305. bool rtl_is_tx_report_skb(struct ieee80211_hw *hw, struct sk_buff *skb)
  1306. {
  1307. u16 ether_type;
  1308. const u8 *ether_type_ptr;
  1309. ether_type_ptr = rtl_skb_ether_type_ptr(hw, skb, true);
  1310. ether_type = be16_to_cpup((__be16 *)ether_type_ptr);
  1311. /* EAPOL */
  1312. if (ether_type == ETH_P_PAE)
  1313. return true;
  1314. return false;
  1315. }
  1316. static u16 rtl_get_tx_report_sn(struct ieee80211_hw *hw)
  1317. {
  1318. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1319. struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
  1320. u16 sn;
  1321. sn = atomic_inc_return(&tx_report->sn) & 0x0FFF;
  1322. tx_report->last_sent_sn = sn;
  1323. tx_report->last_sent_time = jiffies;
  1324. RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_DMESG,
  1325. "Send TX-Report sn=0x%X\n", sn);
  1326. return sn;
  1327. }
  1328. void rtl_get_tx_report(struct rtl_tcb_desc *ptcb_desc, u8 *pdesc,
  1329. struct ieee80211_hw *hw)
  1330. {
  1331. if (ptcb_desc->use_spe_rpt) {
  1332. u16 sn = rtl_get_tx_report_sn(hw);
  1333. SET_TX_DESC_SPE_RPT(pdesc, 1);
  1334. SET_TX_DESC_SW_DEFINE(pdesc, sn);
  1335. }
  1336. }
  1337. EXPORT_SYMBOL_GPL(rtl_get_tx_report);
  1338. void rtl_tx_report_handler(struct ieee80211_hw *hw, u8 *tmp_buf, u8 c2h_cmd_len)
  1339. {
  1340. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1341. struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
  1342. u16 sn;
  1343. sn = ((tmp_buf[7] & 0x0F) << 8) | tmp_buf[6];
  1344. tx_report->last_recv_sn = sn;
  1345. RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_DMESG,
  1346. "Recv TX-Report st=0x%02X sn=0x%X retry=0x%X\n",
  1347. tmp_buf[0], sn, tmp_buf[2]);
  1348. }
  1349. EXPORT_SYMBOL_GPL(rtl_tx_report_handler);
  1350. bool rtl_check_tx_report_acked(struct ieee80211_hw *hw)
  1351. {
  1352. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1353. struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
  1354. if (tx_report->last_sent_sn == tx_report->last_recv_sn)
  1355. return true;
  1356. if (time_before(tx_report->last_sent_time + 3 * HZ, jiffies)) {
  1357. RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_WARNING,
  1358. "Check TX-Report timeout!!\n");
  1359. return true; /* 3 sec. (timeout) seen as acked */
  1360. }
  1361. return false;
  1362. }
  1363. void rtl_wait_tx_report_acked(struct ieee80211_hw *hw, u32 wait_ms)
  1364. {
  1365. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1366. int i;
  1367. for (i = 0; i < wait_ms; i++) {
  1368. if (rtl_check_tx_report_acked(hw))
  1369. break;
  1370. usleep_range(1000, 2000);
  1371. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1372. "Wait 1ms (%d/%d) to disable key.\n", i, wait_ms);
  1373. }
  1374. }
  1375. u32 rtl_get_hal_edca_param(struct ieee80211_hw *hw,
  1376. struct ieee80211_vif *vif,
  1377. enum wireless_mode wirelessmode,
  1378. struct ieee80211_tx_queue_params *param)
  1379. {
  1380. u32 reg = 0;
  1381. u8 sifstime = 10;
  1382. u8 slottime = 20;
  1383. /* AIFS = AIFSN * slot time + SIFS */
  1384. switch (wirelessmode) {
  1385. case WIRELESS_MODE_A:
  1386. case WIRELESS_MODE_N_24G:
  1387. case WIRELESS_MODE_N_5G:
  1388. case WIRELESS_MODE_AC_5G:
  1389. case WIRELESS_MODE_AC_24G:
  1390. sifstime = 16;
  1391. slottime = 9;
  1392. break;
  1393. case WIRELESS_MODE_G:
  1394. slottime = (vif->bss_conf.use_short_slot ? 9 : 20);
  1395. break;
  1396. default:
  1397. break;
  1398. }
  1399. reg |= (param->txop & 0x7FF) << 16;
  1400. reg |= (fls(param->cw_max) & 0xF) << 12;
  1401. reg |= (fls(param->cw_min) & 0xF) << 8;
  1402. reg |= (param->aifs & 0x0F) * slottime + sifstime;
  1403. return reg;
  1404. }
  1405. EXPORT_SYMBOL_GPL(rtl_get_hal_edca_param);
  1406. /*********************************************************
  1407. *
  1408. * functions called by core.c
  1409. *
  1410. *********************************************************/
  1411. int rtl_tx_agg_start(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1412. struct ieee80211_sta *sta, u16 tid, u16 *ssn)
  1413. {
  1414. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1415. struct rtl_tid_data *tid_data;
  1416. struct rtl_sta_info *sta_entry = NULL;
  1417. if (sta == NULL)
  1418. return -EINVAL;
  1419. if (unlikely(tid >= MAX_TID_COUNT))
  1420. return -EINVAL;
  1421. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1422. if (!sta_entry)
  1423. return -ENXIO;
  1424. tid_data = &sta_entry->tids[tid];
  1425. RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
  1426. "on ra = %pM tid = %d seq:%d\n", sta->addr, tid,
  1427. *ssn);
  1428. tid_data->agg.agg_state = RTL_AGG_START;
  1429. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1430. return 0;
  1431. }
  1432. int rtl_tx_agg_stop(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1433. struct ieee80211_sta *sta, u16 tid)
  1434. {
  1435. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1436. struct rtl_sta_info *sta_entry = NULL;
  1437. if (sta == NULL)
  1438. return -EINVAL;
  1439. RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
  1440. "on ra = %pM tid = %d\n", sta->addr, tid);
  1441. if (unlikely(tid >= MAX_TID_COUNT))
  1442. return -EINVAL;
  1443. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1444. sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP;
  1445. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1446. return 0;
  1447. }
  1448. int rtl_rx_agg_start(struct ieee80211_hw *hw,
  1449. struct ieee80211_sta *sta, u16 tid)
  1450. {
  1451. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1452. struct rtl_tid_data *tid_data;
  1453. struct rtl_sta_info *sta_entry = NULL;
  1454. u8 reject_agg;
  1455. if (sta == NULL)
  1456. return -EINVAL;
  1457. if (unlikely(tid >= MAX_TID_COUNT))
  1458. return -EINVAL;
  1459. if (rtlpriv->cfg->ops->get_btc_status()) {
  1460. rtlpriv->btcoexist.btc_ops->btc_get_ampdu_cfg(rtlpriv,
  1461. &reject_agg,
  1462. NULL, NULL);
  1463. if (reject_agg)
  1464. return -EINVAL;
  1465. }
  1466. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1467. if (!sta_entry)
  1468. return -ENXIO;
  1469. tid_data = &sta_entry->tids[tid];
  1470. RT_TRACE(rtlpriv, COMP_RECV, DBG_DMESG,
  1471. "on ra = %pM tid = %d\n", sta->addr, tid);
  1472. tid_data->agg.rx_agg_state = RTL_RX_AGG_START;
  1473. return 0;
  1474. }
  1475. int rtl_rx_agg_stop(struct ieee80211_hw *hw,
  1476. struct ieee80211_sta *sta, u16 tid)
  1477. {
  1478. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1479. struct rtl_sta_info *sta_entry = NULL;
  1480. if (sta == NULL)
  1481. return -EINVAL;
  1482. RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
  1483. "on ra = %pM tid = %d\n", sta->addr, tid);
  1484. if (unlikely(tid >= MAX_TID_COUNT))
  1485. return -EINVAL;
  1486. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1487. sta_entry->tids[tid].agg.rx_agg_state = RTL_RX_AGG_STOP;
  1488. return 0;
  1489. }
  1490. int rtl_tx_agg_oper(struct ieee80211_hw *hw,
  1491. struct ieee80211_sta *sta, u16 tid)
  1492. {
  1493. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1494. struct rtl_sta_info *sta_entry = NULL;
  1495. if (sta == NULL)
  1496. return -EINVAL;
  1497. RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
  1498. "on ra = %pM tid = %d\n", sta->addr, tid);
  1499. if (unlikely(tid >= MAX_TID_COUNT))
  1500. return -EINVAL;
  1501. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1502. sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL;
  1503. return 0;
  1504. }
  1505. void rtl_rx_ampdu_apply(struct rtl_priv *rtlpriv)
  1506. {
  1507. struct rtl_btc_ops *btc_ops = rtlpriv->btcoexist.btc_ops;
  1508. u8 reject_agg = 0, ctrl_agg_size = 0, agg_size = 0;
  1509. if (rtlpriv->cfg->ops->get_btc_status())
  1510. btc_ops->btc_get_ampdu_cfg(rtlpriv, &reject_agg,
  1511. &ctrl_agg_size, &agg_size);
  1512. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
  1513. "Set RX AMPDU: coex - reject=%d, ctrl_agg_size=%d, size=%d",
  1514. reject_agg, ctrl_agg_size, agg_size);
  1515. rtlpriv->hw->max_rx_aggregation_subframes =
  1516. (ctrl_agg_size ? agg_size : IEEE80211_MAX_AMPDU_BUF);
  1517. }
  1518. EXPORT_SYMBOL(rtl_rx_ampdu_apply);
  1519. /*********************************************************
  1520. *
  1521. * wq & timer callback functions
  1522. *
  1523. *********************************************************/
  1524. /* this function is used for roaming */
  1525. void rtl_beacon_statistic(struct ieee80211_hw *hw, struct sk_buff *skb)
  1526. {
  1527. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1528. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1529. if (rtlpriv->mac80211.opmode != NL80211_IFTYPE_STATION)
  1530. return;
  1531. if (rtlpriv->mac80211.link_state < MAC80211_LINKED)
  1532. return;
  1533. /* check if this really is a beacon */
  1534. if (!ieee80211_is_beacon(hdr->frame_control) &&
  1535. !ieee80211_is_probe_resp(hdr->frame_control))
  1536. return;
  1537. /* min. beacon length + FCS_LEN */
  1538. if (skb->len <= 40 + FCS_LEN)
  1539. return;
  1540. /* and only beacons from the associated BSSID, please */
  1541. if (!ether_addr_equal(hdr->addr3, rtlpriv->mac80211.bssid))
  1542. return;
  1543. rtlpriv->link_info.bcn_rx_inperiod++;
  1544. }
  1545. EXPORT_SYMBOL_GPL(rtl_beacon_statistic);
  1546. static void rtl_free_entries_from_scan_list(struct ieee80211_hw *hw)
  1547. {
  1548. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1549. struct rtl_bssid_entry *entry, *next;
  1550. list_for_each_entry_safe(entry, next, &rtlpriv->scan_list.list, list) {
  1551. list_del(&entry->list);
  1552. kfree(entry);
  1553. rtlpriv->scan_list.num--;
  1554. }
  1555. }
  1556. void rtl_scan_list_expire(struct ieee80211_hw *hw)
  1557. {
  1558. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1559. struct rtl_bssid_entry *entry, *next;
  1560. unsigned long flags;
  1561. spin_lock_irqsave(&rtlpriv->locks.scan_list_lock, flags);
  1562. list_for_each_entry_safe(entry, next, &rtlpriv->scan_list.list, list) {
  1563. /* 180 seconds */
  1564. if (jiffies_to_msecs(jiffies - entry->age) < 180000)
  1565. continue;
  1566. list_del(&entry->list);
  1567. rtlpriv->scan_list.num--;
  1568. RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD,
  1569. "BSSID=%pM is expire in scan list (total=%d)\n",
  1570. entry->bssid, rtlpriv->scan_list.num);
  1571. kfree(entry);
  1572. }
  1573. spin_unlock_irqrestore(&rtlpriv->locks.scan_list_lock, flags);
  1574. rtlpriv->btcoexist.btc_info.ap_num = rtlpriv->scan_list.num;
  1575. }
  1576. void rtl_collect_scan_list(struct ieee80211_hw *hw, struct sk_buff *skb)
  1577. {
  1578. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1579. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1580. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1581. unsigned long flags;
  1582. struct rtl_bssid_entry *entry;
  1583. bool entry_found = false;
  1584. /* check if it is scanning */
  1585. if (!mac->act_scanning)
  1586. return;
  1587. /* check if this really is a beacon */
  1588. if (!ieee80211_is_beacon(hdr->frame_control) &&
  1589. !ieee80211_is_probe_resp(hdr->frame_control))
  1590. return;
  1591. spin_lock_irqsave(&rtlpriv->locks.scan_list_lock, flags);
  1592. list_for_each_entry(entry, &rtlpriv->scan_list.list, list) {
  1593. if (memcmp(entry->bssid, hdr->addr3, ETH_ALEN) == 0) {
  1594. list_del_init(&entry->list);
  1595. entry_found = true;
  1596. RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD,
  1597. "Update BSSID=%pM to scan list (total=%d)\n",
  1598. hdr->addr3, rtlpriv->scan_list.num);
  1599. break;
  1600. }
  1601. }
  1602. if (!entry_found) {
  1603. entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
  1604. if (!entry)
  1605. goto label_err;
  1606. memcpy(entry->bssid, hdr->addr3, ETH_ALEN);
  1607. rtlpriv->scan_list.num++;
  1608. RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD,
  1609. "Add BSSID=%pM to scan list (total=%d)\n",
  1610. hdr->addr3, rtlpriv->scan_list.num);
  1611. }
  1612. entry->age = jiffies;
  1613. list_add_tail(&entry->list, &rtlpriv->scan_list.list);
  1614. label_err:
  1615. spin_unlock_irqrestore(&rtlpriv->locks.scan_list_lock, flags);
  1616. }
  1617. EXPORT_SYMBOL(rtl_collect_scan_list);
  1618. void rtl_watchdog_wq_callback(void *data)
  1619. {
  1620. struct rtl_works *rtlworks = container_of_dwork_rtl(data,
  1621. struct rtl_works,
  1622. watchdog_wq);
  1623. struct ieee80211_hw *hw = rtlworks->hw;
  1624. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1625. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1626. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1627. bool busytraffic = false;
  1628. bool tx_busy_traffic = false;
  1629. bool rx_busy_traffic = false;
  1630. bool higher_busytraffic = false;
  1631. bool higher_busyrxtraffic = false;
  1632. u8 idx, tid;
  1633. u32 rx_cnt_inp4eriod = 0;
  1634. u32 tx_cnt_inp4eriod = 0;
  1635. u32 aver_rx_cnt_inperiod = 0;
  1636. u32 aver_tx_cnt_inperiod = 0;
  1637. u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0};
  1638. u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0};
  1639. if (is_hal_stop(rtlhal))
  1640. return;
  1641. /* <1> Determine if action frame is allowed */
  1642. if (mac->link_state > MAC80211_NOLINK) {
  1643. if (mac->cnt_after_linked < 20)
  1644. mac->cnt_after_linked++;
  1645. } else {
  1646. mac->cnt_after_linked = 0;
  1647. }
  1648. /* <2> to check if traffic busy, if
  1649. * busytraffic we don't change channel
  1650. */
  1651. if (mac->link_state >= MAC80211_LINKED) {
  1652. /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */
  1653. for (idx = 0; idx <= 2; idx++) {
  1654. rtlpriv->link_info.num_rx_in4period[idx] =
  1655. rtlpriv->link_info.num_rx_in4period[idx + 1];
  1656. rtlpriv->link_info.num_tx_in4period[idx] =
  1657. rtlpriv->link_info.num_tx_in4period[idx + 1];
  1658. }
  1659. rtlpriv->link_info.num_rx_in4period[3] =
  1660. rtlpriv->link_info.num_rx_inperiod;
  1661. rtlpriv->link_info.num_tx_in4period[3] =
  1662. rtlpriv->link_info.num_tx_inperiod;
  1663. for (idx = 0; idx <= 3; idx++) {
  1664. rx_cnt_inp4eriod +=
  1665. rtlpriv->link_info.num_rx_in4period[idx];
  1666. tx_cnt_inp4eriod +=
  1667. rtlpriv->link_info.num_tx_in4period[idx];
  1668. }
  1669. aver_rx_cnt_inperiod = rx_cnt_inp4eriod / 4;
  1670. aver_tx_cnt_inperiod = tx_cnt_inp4eriod / 4;
  1671. /* (2) check traffic busy */
  1672. if (aver_rx_cnt_inperiod > 100 || aver_tx_cnt_inperiod > 100) {
  1673. busytraffic = true;
  1674. if (aver_rx_cnt_inperiod > aver_tx_cnt_inperiod)
  1675. rx_busy_traffic = true;
  1676. else
  1677. tx_busy_traffic = false;
  1678. }
  1679. /* Higher Tx/Rx data. */
  1680. if (aver_rx_cnt_inperiod > 4000 ||
  1681. aver_tx_cnt_inperiod > 4000) {
  1682. higher_busytraffic = true;
  1683. /* Extremely high Rx data. */
  1684. if (aver_rx_cnt_inperiod > 5000)
  1685. higher_busyrxtraffic = true;
  1686. }
  1687. /* check every tid's tx traffic */
  1688. for (tid = 0; tid <= 7; tid++) {
  1689. for (idx = 0; idx <= 2; idx++)
  1690. rtlpriv->link_info.tidtx_in4period[tid][idx] =
  1691. rtlpriv->link_info.tidtx_in4period[tid]
  1692. [idx + 1];
  1693. rtlpriv->link_info.tidtx_in4period[tid][3] =
  1694. rtlpriv->link_info.tidtx_inperiod[tid];
  1695. for (idx = 0; idx <= 3; idx++)
  1696. tidtx_inp4eriod[tid] +=
  1697. rtlpriv->link_info.tidtx_in4period[tid][idx];
  1698. aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4;
  1699. if (aver_tidtx_inperiod[tid] > 5000)
  1700. rtlpriv->link_info.higher_busytxtraffic[tid] =
  1701. true;
  1702. else
  1703. rtlpriv->link_info.higher_busytxtraffic[tid] =
  1704. false;
  1705. }
  1706. /* PS is controlled by coex. */
  1707. if (rtlpriv->cfg->ops->get_btc_status() &&
  1708. rtlpriv->btcoexist.btc_ops->btc_is_bt_ctrl_lps(rtlpriv))
  1709. goto label_lps_done;
  1710. if (rtlpriv->link_info.num_rx_inperiod +
  1711. rtlpriv->link_info.num_tx_inperiod > 8 ||
  1712. rtlpriv->link_info.num_rx_inperiod > 2)
  1713. rtl_lps_leave(hw);
  1714. else
  1715. rtl_lps_enter(hw);
  1716. label_lps_done:
  1717. ;
  1718. }
  1719. rtlpriv->link_info.num_rx_inperiod = 0;
  1720. rtlpriv->link_info.num_tx_inperiod = 0;
  1721. for (tid = 0; tid <= 7; tid++)
  1722. rtlpriv->link_info.tidtx_inperiod[tid] = 0;
  1723. rtlpriv->link_info.busytraffic = busytraffic;
  1724. rtlpriv->link_info.higher_busytraffic = higher_busytraffic;
  1725. rtlpriv->link_info.rx_busy_traffic = rx_busy_traffic;
  1726. rtlpriv->link_info.tx_busy_traffic = tx_busy_traffic;
  1727. rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic;
  1728. rtlpriv->stats.txbytesunicast_inperiod =
  1729. rtlpriv->stats.txbytesunicast -
  1730. rtlpriv->stats.txbytesunicast_last;
  1731. rtlpriv->stats.rxbytesunicast_inperiod =
  1732. rtlpriv->stats.rxbytesunicast -
  1733. rtlpriv->stats.rxbytesunicast_last;
  1734. rtlpriv->stats.txbytesunicast_last = rtlpriv->stats.txbytesunicast;
  1735. rtlpriv->stats.rxbytesunicast_last = rtlpriv->stats.rxbytesunicast;
  1736. rtlpriv->stats.txbytesunicast_inperiod_tp =
  1737. (u32)(rtlpriv->stats.txbytesunicast_inperiod * 8 / 2 /
  1738. 1024 / 1024);
  1739. rtlpriv->stats.rxbytesunicast_inperiod_tp =
  1740. (u32)(rtlpriv->stats.rxbytesunicast_inperiod * 8 / 2 /
  1741. 1024 / 1024);
  1742. /* <3> DM */
  1743. if (!rtlpriv->cfg->mod_params->disable_watchdog)
  1744. rtlpriv->cfg->ops->dm_watchdog(hw);
  1745. /* <4> roaming */
  1746. if (mac->link_state == MAC80211_LINKED &&
  1747. mac->opmode == NL80211_IFTYPE_STATION) {
  1748. if ((rtlpriv->link_info.bcn_rx_inperiod +
  1749. rtlpriv->link_info.num_rx_inperiod) == 0) {
  1750. rtlpriv->link_info.roam_times++;
  1751. RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG,
  1752. "AP off for %d s\n",
  1753. (rtlpriv->link_info.roam_times * 2));
  1754. /* if we can't recv beacon for 10s,
  1755. * we should reconnect this AP
  1756. */
  1757. if (rtlpriv->link_info.roam_times >= 5) {
  1758. pr_err("AP off, try to reconnect now\n");
  1759. rtlpriv->link_info.roam_times = 0;
  1760. ieee80211_connection_loss(
  1761. rtlpriv->mac80211.vif);
  1762. }
  1763. } else {
  1764. rtlpriv->link_info.roam_times = 0;
  1765. }
  1766. }
  1767. if (rtlpriv->cfg->ops->get_btc_status())
  1768. rtlpriv->btcoexist.btc_ops->btc_periodical(rtlpriv);
  1769. if (rtlpriv->btcoexist.btc_info.in_4way) {
  1770. if (time_after(jiffies, rtlpriv->btcoexist.btc_info.in_4way_ts +
  1771. msecs_to_jiffies(IN_4WAY_TIMEOUT_TIME)))
  1772. rtlpriv->btcoexist.btc_info.in_4way = false;
  1773. }
  1774. rtlpriv->link_info.bcn_rx_inperiod = 0;
  1775. /* <6> scan list */
  1776. rtl_scan_list_expire(hw);
  1777. }
  1778. void rtl_watch_dog_timer_callback(struct timer_list *t)
  1779. {
  1780. struct rtl_priv *rtlpriv = from_timer(rtlpriv, t, works.watchdog_timer);
  1781. queue_delayed_work(rtlpriv->works.rtl_wq,
  1782. &rtlpriv->works.watchdog_wq, 0);
  1783. mod_timer(&rtlpriv->works.watchdog_timer,
  1784. jiffies + MSECS(RTL_WATCH_DOG_TIME));
  1785. }
  1786. void rtl_fwevt_wq_callback(void *data)
  1787. {
  1788. struct rtl_works *rtlworks =
  1789. container_of_dwork_rtl(data, struct rtl_works, fwevt_wq);
  1790. struct ieee80211_hw *hw = rtlworks->hw;
  1791. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1792. rtlpriv->cfg->ops->c2h_command_handle(hw);
  1793. }
  1794. void rtl_c2hcmd_enqueue(struct ieee80211_hw *hw, u8 tag, u8 len, u8 *val)
  1795. {
  1796. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1797. unsigned long flags;
  1798. struct rtl_c2hcmd *c2hcmd;
  1799. c2hcmd = kmalloc(sizeof(*c2hcmd),
  1800. in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
  1801. if (!c2hcmd)
  1802. goto label_err;
  1803. c2hcmd->val = kmalloc(len,
  1804. in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
  1805. if (!c2hcmd->val)
  1806. goto label_err2;
  1807. /* fill data */
  1808. c2hcmd->tag = tag;
  1809. c2hcmd->len = len;
  1810. memcpy(c2hcmd->val, val, len);
  1811. /* enqueue */
  1812. spin_lock_irqsave(&rtlpriv->locks.c2hcmd_lock, flags);
  1813. list_add_tail(&c2hcmd->list, &rtlpriv->c2hcmd_list);
  1814. spin_unlock_irqrestore(&rtlpriv->locks.c2hcmd_lock, flags);
  1815. /* wake up wq */
  1816. queue_delayed_work(rtlpriv->works.rtl_wq, &rtlpriv->works.c2hcmd_wq, 0);
  1817. return;
  1818. label_err2:
  1819. kfree(c2hcmd);
  1820. label_err:
  1821. RT_TRACE(rtlpriv, COMP_CMD, DBG_WARNING,
  1822. "C2H cmd enqueue fail.\n");
  1823. }
  1824. EXPORT_SYMBOL(rtl_c2hcmd_enqueue);
  1825. void rtl_c2hcmd_launcher(struct ieee80211_hw *hw, int exec)
  1826. {
  1827. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1828. unsigned long flags;
  1829. struct rtl_c2hcmd *c2hcmd;
  1830. int i;
  1831. for (i = 0; i < 200; i++) {
  1832. /* dequeue a task */
  1833. spin_lock_irqsave(&rtlpriv->locks.c2hcmd_lock, flags);
  1834. c2hcmd = list_first_entry_or_null(&rtlpriv->c2hcmd_list,
  1835. struct rtl_c2hcmd, list);
  1836. if (c2hcmd)
  1837. list_del(&c2hcmd->list);
  1838. spin_unlock_irqrestore(&rtlpriv->locks.c2hcmd_lock, flags);
  1839. /* do it */
  1840. if (!c2hcmd)
  1841. break;
  1842. if (rtlpriv->cfg->ops->c2h_content_parsing && exec)
  1843. rtlpriv->cfg->ops->c2h_content_parsing(hw,
  1844. c2hcmd->tag, c2hcmd->len, c2hcmd->val);
  1845. /* free */
  1846. kfree(c2hcmd->val);
  1847. kfree(c2hcmd);
  1848. }
  1849. }
  1850. void rtl_c2hcmd_wq_callback(void *data)
  1851. {
  1852. struct rtl_works *rtlworks = container_of_dwork_rtl(data,
  1853. struct rtl_works,
  1854. c2hcmd_wq);
  1855. struct ieee80211_hw *hw = rtlworks->hw;
  1856. rtl_c2hcmd_launcher(hw, 1);
  1857. }
  1858. void rtl_easy_concurrent_retrytimer_callback(struct timer_list *t)
  1859. {
  1860. struct rtl_priv *rtlpriv =
  1861. from_timer(rtlpriv, t, works.dualmac_easyconcurrent_retrytimer);
  1862. struct ieee80211_hw *hw = rtlpriv->hw;
  1863. struct rtl_priv *buddy_priv = rtlpriv->buddy_priv;
  1864. if (buddy_priv == NULL)
  1865. return;
  1866. rtlpriv->cfg->ops->dualmac_easy_concurrent(hw);
  1867. }
  1868. /*********************************************************
  1869. *
  1870. * frame process functions
  1871. *
  1872. *********************************************************/
  1873. u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie)
  1874. {
  1875. struct ieee80211_mgmt *mgmt = (void *)data;
  1876. u8 *pos, *end;
  1877. pos = (u8 *)mgmt->u.beacon.variable;
  1878. end = data + len;
  1879. while (pos < end) {
  1880. if (pos + 2 + pos[1] > end)
  1881. return NULL;
  1882. if (pos[0] == ie)
  1883. return pos;
  1884. pos += 2 + pos[1];
  1885. }
  1886. return NULL;
  1887. }
  1888. /* when we use 2 rx ants we send IEEE80211_SMPS_OFF */
  1889. /* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */
  1890. static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw,
  1891. enum ieee80211_smps_mode smps,
  1892. u8 *da, u8 *bssid)
  1893. {
  1894. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1895. struct sk_buff *skb;
  1896. struct ieee80211_mgmt *action_frame;
  1897. /* 27 = header + category + action + smps mode */
  1898. skb = dev_alloc_skb(27 + hw->extra_tx_headroom);
  1899. if (!skb)
  1900. return NULL;
  1901. skb_reserve(skb, hw->extra_tx_headroom);
  1902. action_frame = skb_put_zero(skb, 27);
  1903. memcpy(action_frame->da, da, ETH_ALEN);
  1904. memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN);
  1905. memcpy(action_frame->bssid, bssid, ETH_ALEN);
  1906. action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1907. IEEE80211_STYPE_ACTION);
  1908. action_frame->u.action.category = WLAN_CATEGORY_HT;
  1909. action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS;
  1910. switch (smps) {
  1911. case IEEE80211_SMPS_AUTOMATIC:/* 0 */
  1912. case IEEE80211_SMPS_NUM_MODES:/* 4 */
  1913. WARN_ON(1);
  1914. /* fall through */
  1915. case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/
  1916. action_frame->u.action.u.ht_smps.smps_control =
  1917. WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */
  1918. break;
  1919. case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/
  1920. action_frame->u.action.u.ht_smps.smps_control =
  1921. WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */
  1922. break;
  1923. case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/
  1924. action_frame->u.action.u.ht_smps.smps_control =
  1925. WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */
  1926. break;
  1927. }
  1928. return skb;
  1929. }
  1930. int rtl_send_smps_action(struct ieee80211_hw *hw,
  1931. struct ieee80211_sta *sta,
  1932. enum ieee80211_smps_mode smps)
  1933. {
  1934. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1935. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1936. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1937. struct sk_buff *skb = NULL;
  1938. struct rtl_tcb_desc tcb_desc;
  1939. u8 bssid[ETH_ALEN] = {0};
  1940. memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
  1941. if (rtlpriv->mac80211.act_scanning)
  1942. goto err_free;
  1943. if (!sta)
  1944. goto err_free;
  1945. if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
  1946. goto err_free;
  1947. if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
  1948. goto err_free;
  1949. if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_AP)
  1950. memcpy(bssid, rtlpriv->efuse.dev_addr, ETH_ALEN);
  1951. else
  1952. memcpy(bssid, rtlpriv->mac80211.bssid, ETH_ALEN);
  1953. skb = rtl_make_smps_action(hw, smps, sta->addr, bssid);
  1954. /* this is a type = mgmt * stype = action frame */
  1955. if (skb) {
  1956. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1957. struct rtl_sta_info *sta_entry =
  1958. (struct rtl_sta_info *) sta->drv_priv;
  1959. sta_entry->mimo_ps = smps;
  1960. /* rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0, true); */
  1961. info->control.rates[0].idx = 0;
  1962. info->band = hw->conf.chandef.chan->band;
  1963. rtlpriv->intf_ops->adapter_tx(hw, sta, skb, &tcb_desc);
  1964. }
  1965. return 1;
  1966. err_free:
  1967. return 0;
  1968. }
  1969. EXPORT_SYMBOL(rtl_send_smps_action);
  1970. void rtl_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation)
  1971. {
  1972. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1973. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1974. enum io_type iotype;
  1975. if (!is_hal_stop(rtlhal)) {
  1976. switch (operation) {
  1977. case SCAN_OPT_BACKUP:
  1978. iotype = IO_CMD_PAUSE_DM_BY_SCAN;
  1979. rtlpriv->cfg->ops->set_hw_reg(hw,
  1980. HW_VAR_IO_CMD,
  1981. (u8 *)&iotype);
  1982. break;
  1983. case SCAN_OPT_RESTORE:
  1984. iotype = IO_CMD_RESUME_DM_BY_SCAN;
  1985. rtlpriv->cfg->ops->set_hw_reg(hw,
  1986. HW_VAR_IO_CMD,
  1987. (u8 *)&iotype);
  1988. break;
  1989. default:
  1990. pr_err("Unknown Scan Backup operation.\n");
  1991. break;
  1992. }
  1993. }
  1994. }
  1995. EXPORT_SYMBOL(rtl_phy_scan_operation_backup);
  1996. /* because mac80211 have issues when can receive del ba
  1997. * so here we just make a fake del_ba if we receive a ba_req
  1998. * but rx_agg was opened to let mac80211 release some ba
  1999. * related resources, so please this del_ba for tx
  2000. */
  2001. struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw,
  2002. u8 *sa, u8 *bssid, u16 tid)
  2003. {
  2004. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  2005. struct sk_buff *skb;
  2006. struct ieee80211_mgmt *action_frame;
  2007. u16 params;
  2008. /* 27 = header + category + action + smps mode */
  2009. skb = dev_alloc_skb(34 + hw->extra_tx_headroom);
  2010. if (!skb)
  2011. return NULL;
  2012. skb_reserve(skb, hw->extra_tx_headroom);
  2013. action_frame = skb_put_zero(skb, 34);
  2014. memcpy(action_frame->sa, sa, ETH_ALEN);
  2015. memcpy(action_frame->da, rtlefuse->dev_addr, ETH_ALEN);
  2016. memcpy(action_frame->bssid, bssid, ETH_ALEN);
  2017. action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  2018. IEEE80211_STYPE_ACTION);
  2019. action_frame->u.action.category = WLAN_CATEGORY_BACK;
  2020. action_frame->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
  2021. params = (u16)(1 << 11); /* bit 11 initiator */
  2022. params |= (u16)(tid << 12); /* bit 15:12 TID number */
  2023. action_frame->u.action.u.delba.params = cpu_to_le16(params);
  2024. action_frame->u.action.u.delba.reason_code =
  2025. cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT);
  2026. return skb;
  2027. }
  2028. /*********************************************************
  2029. *
  2030. * IOT functions
  2031. *
  2032. *********************************************************/
  2033. static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw,
  2034. struct octet_string vendor_ie)
  2035. {
  2036. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2037. bool matched = false;
  2038. static u8 athcap_1[] = { 0x00, 0x03, 0x7F };
  2039. static u8 athcap_2[] = { 0x00, 0x13, 0x74 };
  2040. static u8 broadcap_1[] = { 0x00, 0x10, 0x18 };
  2041. static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 };
  2042. static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 };
  2043. static u8 racap[] = { 0x00, 0x0c, 0x43 };
  2044. static u8 ciscocap[] = { 0x00, 0x40, 0x96 };
  2045. static u8 marvcap[] = { 0x00, 0x50, 0x43 };
  2046. if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 ||
  2047. memcmp(vendor_ie.octet, athcap_2, 3) == 0) {
  2048. rtlpriv->mac80211.vendor = PEER_ATH;
  2049. matched = true;
  2050. } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 ||
  2051. memcmp(vendor_ie.octet, broadcap_2, 3) == 0 ||
  2052. memcmp(vendor_ie.octet, broadcap_3, 3) == 0) {
  2053. rtlpriv->mac80211.vendor = PEER_BROAD;
  2054. matched = true;
  2055. } else if (memcmp(vendor_ie.octet, racap, 3) == 0) {
  2056. rtlpriv->mac80211.vendor = PEER_RAL;
  2057. matched = true;
  2058. } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) {
  2059. rtlpriv->mac80211.vendor = PEER_CISCO;
  2060. matched = true;
  2061. } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) {
  2062. rtlpriv->mac80211.vendor = PEER_MARV;
  2063. matched = true;
  2064. }
  2065. return matched;
  2066. }
  2067. static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data,
  2068. unsigned int len)
  2069. {
  2070. struct ieee80211_mgmt *mgmt = (void *)data;
  2071. struct octet_string vendor_ie;
  2072. u8 *pos, *end;
  2073. pos = (u8 *)mgmt->u.beacon.variable;
  2074. end = data + len;
  2075. while (pos < end) {
  2076. if (pos[0] == 221) {
  2077. vendor_ie.length = pos[1];
  2078. vendor_ie.octet = &pos[2];
  2079. if (rtl_chk_vendor_ouisub(hw, vendor_ie))
  2080. return true;
  2081. }
  2082. if (pos + 2 + pos[1] > end)
  2083. return false;
  2084. pos += 2 + pos[1];
  2085. }
  2086. return false;
  2087. }
  2088. void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len)
  2089. {
  2090. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2091. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  2092. struct ieee80211_hdr *hdr = (void *)data;
  2093. u32 vendor = PEER_UNKNOWN;
  2094. static u8 ap3_1[3] = { 0x00, 0x14, 0xbf };
  2095. static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 };
  2096. static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e };
  2097. static u8 ap4_1[3] = { 0x00, 0x90, 0xcc };
  2098. static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e };
  2099. static u8 ap4_3[3] = { 0x00, 0x18, 0x02 };
  2100. static u8 ap4_4[3] = { 0x00, 0x17, 0x3f };
  2101. static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf };
  2102. static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 };
  2103. static u8 ap5_2[3] = { 0x00, 0x21, 0x91 };
  2104. static u8 ap5_3[3] = { 0x00, 0x24, 0x01 };
  2105. static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 };
  2106. static u8 ap5_5[3] = { 0x00, 0x17, 0x9A };
  2107. static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 };
  2108. static u8 ap6_1[3] = { 0x00, 0x17, 0x94 };
  2109. static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 };
  2110. if (mac->opmode != NL80211_IFTYPE_STATION)
  2111. return;
  2112. if (mac->link_state == MAC80211_NOLINK) {
  2113. mac->vendor = PEER_UNKNOWN;
  2114. return;
  2115. }
  2116. if (mac->cnt_after_linked > 2)
  2117. return;
  2118. /* check if this really is a beacon */
  2119. if (!ieee80211_is_beacon(hdr->frame_control))
  2120. return;
  2121. /* min. beacon length + FCS_LEN */
  2122. if (len <= 40 + FCS_LEN)
  2123. return;
  2124. /* and only beacons from the associated BSSID, please */
  2125. if (!ether_addr_equal_64bits(hdr->addr3, rtlpriv->mac80211.bssid))
  2126. return;
  2127. if (rtl_find_221_ie(hw, data, len))
  2128. vendor = mac->vendor;
  2129. if ((memcmp(mac->bssid, ap5_1, 3) == 0) ||
  2130. (memcmp(mac->bssid, ap5_2, 3) == 0) ||
  2131. (memcmp(mac->bssid, ap5_3, 3) == 0) ||
  2132. (memcmp(mac->bssid, ap5_4, 3) == 0) ||
  2133. (memcmp(mac->bssid, ap5_5, 3) == 0) ||
  2134. (memcmp(mac->bssid, ap5_6, 3) == 0) ||
  2135. vendor == PEER_ATH) {
  2136. vendor = PEER_ATH;
  2137. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ath find\n");
  2138. } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) ||
  2139. (memcmp(mac->bssid, ap4_5, 3) == 0) ||
  2140. (memcmp(mac->bssid, ap4_1, 3) == 0) ||
  2141. (memcmp(mac->bssid, ap4_2, 3) == 0) ||
  2142. (memcmp(mac->bssid, ap4_3, 3) == 0) ||
  2143. vendor == PEER_RAL) {
  2144. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ral find\n");
  2145. vendor = PEER_RAL;
  2146. } else if (memcmp(mac->bssid, ap6_1, 3) == 0 ||
  2147. vendor == PEER_CISCO) {
  2148. vendor = PEER_CISCO;
  2149. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>cisco find\n");
  2150. } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) ||
  2151. (memcmp(mac->bssid, ap3_2, 3) == 0) ||
  2152. (memcmp(mac->bssid, ap3_3, 3) == 0) ||
  2153. vendor == PEER_BROAD) {
  2154. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>broad find\n");
  2155. vendor = PEER_BROAD;
  2156. } else if (memcmp(mac->bssid, ap7_1, 3) == 0 ||
  2157. vendor == PEER_MARV) {
  2158. vendor = PEER_MARV;
  2159. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>marv find\n");
  2160. }
  2161. mac->vendor = vendor;
  2162. }
  2163. EXPORT_SYMBOL_GPL(rtl_recognize_peer);
  2164. MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
  2165. MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
  2166. MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
  2167. MODULE_LICENSE("GPL");
  2168. MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
  2169. struct rtl_global_var rtl_global_var = {};
  2170. EXPORT_SYMBOL_GPL(rtl_global_var);
  2171. static int __init rtl_core_module_init(void)
  2172. {
  2173. if (rtl_rate_control_register())
  2174. pr_err("rtl: Unable to register rtl_rc, use default RC !!\n");
  2175. /* add debugfs */
  2176. rtl_debugfs_add_topdir();
  2177. /* init some global vars */
  2178. INIT_LIST_HEAD(&rtl_global_var.glb_priv_list);
  2179. spin_lock_init(&rtl_global_var.glb_list_lock);
  2180. return 0;
  2181. }
  2182. static void __exit rtl_core_module_exit(void)
  2183. {
  2184. /*RC*/
  2185. rtl_rate_control_unregister();
  2186. /* remove debugfs */
  2187. rtl_debugfs_remove_topdir();
  2188. }
  2189. module_init(rtl_core_module_init);
  2190. module_exit(rtl_core_module_exit);