base.c 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553
  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. spin_lock_init(&rtlpriv->locks.ips_lock);
  477. spin_lock_init(&rtlpriv->locks.irq_th_lock);
  478. spin_lock_init(&rtlpriv->locks.h2c_lock);
  479. spin_lock_init(&rtlpriv->locks.rf_ps_lock);
  480. spin_lock_init(&rtlpriv->locks.rf_lock);
  481. spin_lock_init(&rtlpriv->locks.waitq_lock);
  482. spin_lock_init(&rtlpriv->locks.entry_list_lock);
  483. spin_lock_init(&rtlpriv->locks.c2hcmd_lock);
  484. spin_lock_init(&rtlpriv->locks.scan_list_lock);
  485. spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock);
  486. spin_lock_init(&rtlpriv->locks.check_sendpkt_lock);
  487. spin_lock_init(&rtlpriv->locks.fw_ps_lock);
  488. spin_lock_init(&rtlpriv->locks.lps_lock);
  489. spin_lock_init(&rtlpriv->locks.iqk_lock);
  490. /* <5> init list */
  491. INIT_LIST_HEAD(&rtlpriv->entry_list);
  492. INIT_LIST_HEAD(&rtlpriv->c2hcmd_list);
  493. INIT_LIST_HEAD(&rtlpriv->scan_list.list);
  494. rtlmac->link_state = MAC80211_NOLINK;
  495. /* <6> init deferred work */
  496. _rtl_init_deferred_work(hw);
  497. return 0;
  498. }
  499. EXPORT_SYMBOL_GPL(rtl_init_core);
  500. static void rtl_free_entries_from_scan_list(struct ieee80211_hw *hw);
  501. void rtl_deinit_core(struct ieee80211_hw *hw)
  502. {
  503. rtl_c2hcmd_launcher(hw, 0);
  504. rtl_free_entries_from_scan_list(hw);
  505. }
  506. EXPORT_SYMBOL_GPL(rtl_deinit_core);
  507. void rtl_init_rx_config(struct ieee80211_hw *hw)
  508. {
  509. struct rtl_priv *rtlpriv = rtl_priv(hw);
  510. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  511. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf));
  512. }
  513. EXPORT_SYMBOL_GPL(rtl_init_rx_config);
  514. /*********************************************************
  515. *
  516. * tx information functions
  517. *
  518. *********************************************************/
  519. static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw,
  520. struct rtl_tcb_desc *tcb_desc,
  521. struct ieee80211_tx_info *info)
  522. {
  523. struct rtl_priv *rtlpriv = rtl_priv(hw);
  524. u8 rate_flag = info->control.rates[0].flags;
  525. tcb_desc->use_shortpreamble = false;
  526. /* 1M can only use Long Preamble. 11B spec */
  527. if (tcb_desc->hw_rate == rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M])
  528. return;
  529. else if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
  530. tcb_desc->use_shortpreamble = true;
  531. return;
  532. }
  533. static void _rtl_query_shortgi(struct ieee80211_hw *hw,
  534. struct ieee80211_sta *sta,
  535. struct rtl_tcb_desc *tcb_desc,
  536. struct ieee80211_tx_info *info)
  537. {
  538. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  539. u8 rate_flag = info->control.rates[0].flags;
  540. u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0;
  541. u8 sgi_80 = 0, bw_80 = 0;
  542. tcb_desc->use_shortgi = false;
  543. if (sta == NULL)
  544. return;
  545. sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40;
  546. sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20;
  547. sgi_80 = sta->vht_cap.cap & IEEE80211_VHT_CAP_SHORT_GI_80;
  548. if ((!sta->ht_cap.ht_supported) && (!sta->vht_cap.vht_supported))
  549. return;
  550. if (!sgi_40 && !sgi_20)
  551. return;
  552. if (mac->opmode == NL80211_IFTYPE_STATION) {
  553. bw_40 = mac->bw_40;
  554. bw_80 = mac->bw_80;
  555. } else if (mac->opmode == NL80211_IFTYPE_AP ||
  556. mac->opmode == NL80211_IFTYPE_ADHOC ||
  557. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  558. bw_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  559. bw_80 = sta->vht_cap.vht_supported;
  560. }
  561. if (bw_80) {
  562. if (sgi_80)
  563. tcb_desc->use_shortgi = true;
  564. else
  565. tcb_desc->use_shortgi = false;
  566. } else {
  567. if (bw_40 && sgi_40)
  568. tcb_desc->use_shortgi = true;
  569. else if (!bw_40 && sgi_20)
  570. tcb_desc->use_shortgi = true;
  571. }
  572. if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI))
  573. tcb_desc->use_shortgi = false;
  574. }
  575. static void _rtl_query_protection_mode(struct ieee80211_hw *hw,
  576. struct rtl_tcb_desc *tcb_desc,
  577. struct ieee80211_tx_info *info)
  578. {
  579. struct rtl_priv *rtlpriv = rtl_priv(hw);
  580. u8 rate_flag = info->control.rates[0].flags;
  581. /* Common Settings */
  582. tcb_desc->rts_stbc = false;
  583. tcb_desc->cts_enable = false;
  584. tcb_desc->rts_sc = 0;
  585. tcb_desc->rts_bw = false;
  586. tcb_desc->rts_use_shortpreamble = false;
  587. tcb_desc->rts_use_shortgi = false;
  588. if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) {
  589. /* Use CTS-to-SELF in protection mode. */
  590. tcb_desc->rts_enable = true;
  591. tcb_desc->cts_enable = true;
  592. tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
  593. } else if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) {
  594. /* Use RTS-CTS in protection mode. */
  595. tcb_desc->rts_enable = true;
  596. tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
  597. }
  598. }
  599. static void _rtl_txrate_selectmode(struct ieee80211_hw *hw,
  600. struct ieee80211_sta *sta,
  601. struct rtl_tcb_desc *tcb_desc)
  602. {
  603. struct rtl_priv *rtlpriv = rtl_priv(hw);
  604. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  605. struct rtl_sta_info *sta_entry = NULL;
  606. u8 ratr_index = 7;
  607. if (sta) {
  608. sta_entry = (struct rtl_sta_info *) sta->drv_priv;
  609. ratr_index = sta_entry->ratr_index;
  610. }
  611. if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) {
  612. if (mac->opmode == NL80211_IFTYPE_STATION) {
  613. tcb_desc->ratr_index = 0;
  614. } else if (mac->opmode == NL80211_IFTYPE_ADHOC ||
  615. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  616. if (tcb_desc->multicast || tcb_desc->broadcast) {
  617. tcb_desc->hw_rate =
  618. rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M];
  619. tcb_desc->use_driver_rate = 1;
  620. tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
  621. } else {
  622. tcb_desc->ratr_index = ratr_index;
  623. }
  624. } else if (mac->opmode == NL80211_IFTYPE_AP) {
  625. tcb_desc->ratr_index = ratr_index;
  626. }
  627. }
  628. if (rtlpriv->dm.useramask) {
  629. tcb_desc->ratr_index = ratr_index;
  630. /* TODO we will differentiate adhoc and station future */
  631. if (mac->opmode == NL80211_IFTYPE_STATION ||
  632. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  633. tcb_desc->mac_id = 0;
  634. if (mac->mode == WIRELESS_MODE_AC_5G)
  635. tcb_desc->ratr_index =
  636. RATR_INX_WIRELESS_AC_5N;
  637. else if (mac->mode == WIRELESS_MODE_AC_24G)
  638. tcb_desc->ratr_index =
  639. RATR_INX_WIRELESS_AC_24N;
  640. else if (mac->mode == WIRELESS_MODE_N_24G)
  641. tcb_desc->ratr_index = RATR_INX_WIRELESS_NGB;
  642. else if (mac->mode == WIRELESS_MODE_N_5G)
  643. tcb_desc->ratr_index = RATR_INX_WIRELESS_NG;
  644. else if (mac->mode & WIRELESS_MODE_G)
  645. tcb_desc->ratr_index = RATR_INX_WIRELESS_GB;
  646. else if (mac->mode & WIRELESS_MODE_B)
  647. tcb_desc->ratr_index = RATR_INX_WIRELESS_B;
  648. else if (mac->mode & WIRELESS_MODE_A)
  649. tcb_desc->ratr_index = RATR_INX_WIRELESS_G;
  650. } else if (mac->opmode == NL80211_IFTYPE_AP ||
  651. mac->opmode == NL80211_IFTYPE_ADHOC) {
  652. if (NULL != sta) {
  653. if (sta->aid > 0)
  654. tcb_desc->mac_id = sta->aid + 1;
  655. else
  656. tcb_desc->mac_id = 1;
  657. } else {
  658. tcb_desc->mac_id = 0;
  659. }
  660. }
  661. }
  662. }
  663. static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw,
  664. struct ieee80211_sta *sta,
  665. struct rtl_tcb_desc *tcb_desc)
  666. {
  667. struct rtl_priv *rtlpriv = rtl_priv(hw);
  668. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  669. tcb_desc->packet_bw = false;
  670. if (!sta)
  671. return;
  672. if (mac->opmode == NL80211_IFTYPE_AP ||
  673. mac->opmode == NL80211_IFTYPE_ADHOC ||
  674. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  675. if (!(sta->ht_cap.ht_supported) ||
  676. !(sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
  677. return;
  678. } else if (mac->opmode == NL80211_IFTYPE_STATION) {
  679. if (!mac->bw_40 || !(sta->ht_cap.ht_supported))
  680. return;
  681. }
  682. if (tcb_desc->multicast || tcb_desc->broadcast)
  683. return;
  684. /*use legency rate, shall use 20MHz */
  685. if (tcb_desc->hw_rate <= rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M])
  686. return;
  687. tcb_desc->packet_bw = HT_CHANNEL_WIDTH_20_40;
  688. if (rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8812AE ||
  689. rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8821AE) {
  690. if (mac->opmode == NL80211_IFTYPE_AP ||
  691. mac->opmode == NL80211_IFTYPE_ADHOC ||
  692. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  693. if (!(sta->vht_cap.vht_supported))
  694. return;
  695. } else if (mac->opmode == NL80211_IFTYPE_STATION) {
  696. if (!mac->bw_80 ||
  697. !(sta->vht_cap.vht_supported))
  698. return;
  699. }
  700. if (tcb_desc->hw_rate <=
  701. rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15])
  702. return;
  703. tcb_desc->packet_bw = HT_CHANNEL_WIDTH_80;
  704. }
  705. }
  706. static u8 _rtl_get_vht_highest_n_rate(struct ieee80211_hw *hw,
  707. struct ieee80211_sta *sta)
  708. {
  709. struct rtl_priv *rtlpriv = rtl_priv(hw);
  710. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  711. u8 hw_rate;
  712. u16 tx_mcs_map = le16_to_cpu(sta->vht_cap.vht_mcs.tx_mcs_map);
  713. if ((get_rf_type(rtlphy) == RF_2T2R) &&
  714. (tx_mcs_map & 0x000c) != 0x000c) {
  715. if ((tx_mcs_map & 0x000c) >> 2 ==
  716. IEEE80211_VHT_MCS_SUPPORT_0_7)
  717. hw_rate =
  718. rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS7];
  719. else if ((tx_mcs_map & 0x000c) >> 2 ==
  720. IEEE80211_VHT_MCS_SUPPORT_0_8)
  721. hw_rate =
  722. rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS8];
  723. else
  724. hw_rate =
  725. rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9];
  726. } else {
  727. if ((tx_mcs_map & 0x0003) ==
  728. IEEE80211_VHT_MCS_SUPPORT_0_7)
  729. hw_rate =
  730. rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS7];
  731. else if ((tx_mcs_map & 0x0003) ==
  732. IEEE80211_VHT_MCS_SUPPORT_0_8)
  733. hw_rate =
  734. rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS8];
  735. else
  736. hw_rate =
  737. rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9];
  738. }
  739. return hw_rate;
  740. }
  741. static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw,
  742. struct ieee80211_sta *sta)
  743. {
  744. struct rtl_priv *rtlpriv = rtl_priv(hw);
  745. struct rtl_phy *rtlphy = &rtlpriv->phy;
  746. u8 hw_rate;
  747. if (get_rf_type(rtlphy) == RF_2T2R &&
  748. sta->ht_cap.mcs.rx_mask[1] != 0)
  749. hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15];
  750. else
  751. hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS7];
  752. return hw_rate;
  753. }
  754. /* mac80211's rate_idx is like this:
  755. *
  756. * 2.4G band:rx_status->band == NL80211_BAND_2GHZ
  757. *
  758. * B/G rate:
  759. * (rx_status->flag & RX_FLAG_HT) = 0,
  760. * DESC_RATE1M-->DESC_RATE54M ==> idx is 0-->11,
  761. *
  762. * N rate:
  763. * (rx_status->flag & RX_FLAG_HT) = 1,
  764. * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
  765. *
  766. * 5G band:rx_status->band == NL80211_BAND_5GHZ
  767. * A rate:
  768. * (rx_status->flag & RX_FLAG_HT) = 0,
  769. * DESC_RATE6M-->DESC_RATE54M ==> idx is 0-->7,
  770. *
  771. * N rate:
  772. * (rx_status->flag & RX_FLAG_HT) = 1,
  773. * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
  774. *
  775. * VHT rates:
  776. * DESC_RATEVHT1SS_MCS0-->DESC_RATEVHT1SS_MCS9 ==> idx is 0-->9
  777. * DESC_RATEVHT2SS_MCS0-->DESC_RATEVHT2SS_MCS9 ==> idx is 0-->9
  778. */
  779. int rtlwifi_rate_mapping(struct ieee80211_hw *hw, bool isht, bool isvht,
  780. u8 desc_rate)
  781. {
  782. int rate_idx;
  783. if (isvht) {
  784. switch (desc_rate) {
  785. case DESC_RATEVHT1SS_MCS0:
  786. rate_idx = 0;
  787. break;
  788. case DESC_RATEVHT1SS_MCS1:
  789. rate_idx = 1;
  790. break;
  791. case DESC_RATEVHT1SS_MCS2:
  792. rate_idx = 2;
  793. break;
  794. case DESC_RATEVHT1SS_MCS3:
  795. rate_idx = 3;
  796. break;
  797. case DESC_RATEVHT1SS_MCS4:
  798. rate_idx = 4;
  799. break;
  800. case DESC_RATEVHT1SS_MCS5:
  801. rate_idx = 5;
  802. break;
  803. case DESC_RATEVHT1SS_MCS6:
  804. rate_idx = 6;
  805. break;
  806. case DESC_RATEVHT1SS_MCS7:
  807. rate_idx = 7;
  808. break;
  809. case DESC_RATEVHT1SS_MCS8:
  810. rate_idx = 8;
  811. break;
  812. case DESC_RATEVHT1SS_MCS9:
  813. rate_idx = 9;
  814. break;
  815. case DESC_RATEVHT2SS_MCS0:
  816. rate_idx = 0;
  817. break;
  818. case DESC_RATEVHT2SS_MCS1:
  819. rate_idx = 1;
  820. break;
  821. case DESC_RATEVHT2SS_MCS2:
  822. rate_idx = 2;
  823. break;
  824. case DESC_RATEVHT2SS_MCS3:
  825. rate_idx = 3;
  826. break;
  827. case DESC_RATEVHT2SS_MCS4:
  828. rate_idx = 4;
  829. break;
  830. case DESC_RATEVHT2SS_MCS5:
  831. rate_idx = 5;
  832. break;
  833. case DESC_RATEVHT2SS_MCS6:
  834. rate_idx = 6;
  835. break;
  836. case DESC_RATEVHT2SS_MCS7:
  837. rate_idx = 7;
  838. break;
  839. case DESC_RATEVHT2SS_MCS8:
  840. rate_idx = 8;
  841. break;
  842. case DESC_RATEVHT2SS_MCS9:
  843. rate_idx = 9;
  844. break;
  845. default:
  846. rate_idx = 0;
  847. break;
  848. }
  849. return rate_idx;
  850. }
  851. if (false == isht) {
  852. if (NL80211_BAND_2GHZ == hw->conf.chandef.chan->band) {
  853. switch (desc_rate) {
  854. case DESC_RATE1M:
  855. rate_idx = 0;
  856. break;
  857. case DESC_RATE2M:
  858. rate_idx = 1;
  859. break;
  860. case DESC_RATE5_5M:
  861. rate_idx = 2;
  862. break;
  863. case DESC_RATE11M:
  864. rate_idx = 3;
  865. break;
  866. case DESC_RATE6M:
  867. rate_idx = 4;
  868. break;
  869. case DESC_RATE9M:
  870. rate_idx = 5;
  871. break;
  872. case DESC_RATE12M:
  873. rate_idx = 6;
  874. break;
  875. case DESC_RATE18M:
  876. rate_idx = 7;
  877. break;
  878. case DESC_RATE24M:
  879. rate_idx = 8;
  880. break;
  881. case DESC_RATE36M:
  882. rate_idx = 9;
  883. break;
  884. case DESC_RATE48M:
  885. rate_idx = 10;
  886. break;
  887. case DESC_RATE54M:
  888. rate_idx = 11;
  889. break;
  890. default:
  891. rate_idx = 0;
  892. break;
  893. }
  894. } else {
  895. switch (desc_rate) {
  896. case DESC_RATE6M:
  897. rate_idx = 0;
  898. break;
  899. case DESC_RATE9M:
  900. rate_idx = 1;
  901. break;
  902. case DESC_RATE12M:
  903. rate_idx = 2;
  904. break;
  905. case DESC_RATE18M:
  906. rate_idx = 3;
  907. break;
  908. case DESC_RATE24M:
  909. rate_idx = 4;
  910. break;
  911. case DESC_RATE36M:
  912. rate_idx = 5;
  913. break;
  914. case DESC_RATE48M:
  915. rate_idx = 6;
  916. break;
  917. case DESC_RATE54M:
  918. rate_idx = 7;
  919. break;
  920. default:
  921. rate_idx = 0;
  922. break;
  923. }
  924. }
  925. } else {
  926. switch (desc_rate) {
  927. case DESC_RATEMCS0:
  928. rate_idx = 0;
  929. break;
  930. case DESC_RATEMCS1:
  931. rate_idx = 1;
  932. break;
  933. case DESC_RATEMCS2:
  934. rate_idx = 2;
  935. break;
  936. case DESC_RATEMCS3:
  937. rate_idx = 3;
  938. break;
  939. case DESC_RATEMCS4:
  940. rate_idx = 4;
  941. break;
  942. case DESC_RATEMCS5:
  943. rate_idx = 5;
  944. break;
  945. case DESC_RATEMCS6:
  946. rate_idx = 6;
  947. break;
  948. case DESC_RATEMCS7:
  949. rate_idx = 7;
  950. break;
  951. case DESC_RATEMCS8:
  952. rate_idx = 8;
  953. break;
  954. case DESC_RATEMCS9:
  955. rate_idx = 9;
  956. break;
  957. case DESC_RATEMCS10:
  958. rate_idx = 10;
  959. break;
  960. case DESC_RATEMCS11:
  961. rate_idx = 11;
  962. break;
  963. case DESC_RATEMCS12:
  964. rate_idx = 12;
  965. break;
  966. case DESC_RATEMCS13:
  967. rate_idx = 13;
  968. break;
  969. case DESC_RATEMCS14:
  970. rate_idx = 14;
  971. break;
  972. case DESC_RATEMCS15:
  973. rate_idx = 15;
  974. break;
  975. default:
  976. rate_idx = 0;
  977. break;
  978. }
  979. }
  980. return rate_idx;
  981. }
  982. EXPORT_SYMBOL(rtlwifi_rate_mapping);
  983. static u8 _rtl_get_tx_hw_rate(struct ieee80211_hw *hw,
  984. struct ieee80211_tx_info *info)
  985. {
  986. struct rtl_priv *rtlpriv = rtl_priv(hw);
  987. struct ieee80211_tx_rate *r = &info->status.rates[0];
  988. struct ieee80211_rate *txrate;
  989. u8 hw_value = 0x0;
  990. if (r->flags & IEEE80211_TX_RC_MCS) {
  991. /* HT MCS0-15 */
  992. hw_value = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15] - 15 +
  993. r->idx;
  994. } else if (r->flags & IEEE80211_TX_RC_VHT_MCS) {
  995. /* VHT MCS0-9, NSS */
  996. if (ieee80211_rate_get_vht_nss(r) == 2)
  997. hw_value = rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9];
  998. else
  999. hw_value = rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9];
  1000. hw_value = hw_value - 9 + ieee80211_rate_get_vht_mcs(r);
  1001. } else {
  1002. /* legacy */
  1003. txrate = ieee80211_get_tx_rate(hw, info);
  1004. if (txrate)
  1005. hw_value = txrate->hw_value;
  1006. }
  1007. /* check 5G band */
  1008. if (rtlpriv->rtlhal.current_bandtype == BAND_ON_5G &&
  1009. hw_value < rtlpriv->cfg->maps[RTL_RC_OFDM_RATE6M])
  1010. hw_value = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE6M];
  1011. return hw_value;
  1012. }
  1013. void rtl_get_tcb_desc(struct ieee80211_hw *hw,
  1014. struct ieee80211_tx_info *info,
  1015. struct ieee80211_sta *sta,
  1016. struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc)
  1017. {
  1018. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1019. struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
  1020. struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
  1021. __le16 fc = rtl_get_fc(skb);
  1022. tcb_desc->hw_rate = _rtl_get_tx_hw_rate(hw, info);
  1023. if (rtl_is_tx_report_skb(hw, skb))
  1024. tcb_desc->use_spe_rpt = 1;
  1025. if (ieee80211_is_data(fc)) {
  1026. /*
  1027. *we set data rate INX 0
  1028. *in rtl_rc.c if skb is special data or
  1029. *mgt which need low data rate.
  1030. */
  1031. /*
  1032. *So tcb_desc->hw_rate is just used for
  1033. *special data and mgt frames
  1034. */
  1035. if (info->control.rates[0].idx == 0 ||
  1036. ieee80211_is_nullfunc(fc)) {
  1037. tcb_desc->use_driver_rate = true;
  1038. tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
  1039. tcb_desc->disable_ratefallback = 1;
  1040. } else {
  1041. /*
  1042. *because hw will nerver use hw_rate
  1043. *when tcb_desc->use_driver_rate = false
  1044. *so we never set highest N rate here,
  1045. *and N rate will all be controlled by FW
  1046. *when tcb_desc->use_driver_rate = false
  1047. */
  1048. if (sta && sta->vht_cap.vht_supported) {
  1049. tcb_desc->hw_rate =
  1050. _rtl_get_vht_highest_n_rate(hw, sta);
  1051. } else {
  1052. if (sta && sta->ht_cap.ht_supported) {
  1053. tcb_desc->hw_rate =
  1054. _rtl_get_highest_n_rate(hw, sta);
  1055. } else {
  1056. if (rtlmac->mode == WIRELESS_MODE_B) {
  1057. tcb_desc->hw_rate =
  1058. rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M];
  1059. } else {
  1060. tcb_desc->hw_rate =
  1061. rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M];
  1062. }
  1063. }
  1064. }
  1065. }
  1066. if (is_multicast_ether_addr(hdr->addr1))
  1067. tcb_desc->multicast = 1;
  1068. else if (is_broadcast_ether_addr(hdr->addr1))
  1069. tcb_desc->broadcast = 1;
  1070. _rtl_txrate_selectmode(hw, sta, tcb_desc);
  1071. _rtl_query_bandwidth_mode(hw, sta, tcb_desc);
  1072. _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info);
  1073. _rtl_query_shortgi(hw, sta, tcb_desc, info);
  1074. _rtl_query_protection_mode(hw, tcb_desc, info);
  1075. } else {
  1076. tcb_desc->use_driver_rate = true;
  1077. tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
  1078. tcb_desc->disable_ratefallback = 1;
  1079. tcb_desc->mac_id = 0;
  1080. tcb_desc->packet_bw = false;
  1081. }
  1082. }
  1083. EXPORT_SYMBOL(rtl_get_tcb_desc);
  1084. bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb)
  1085. {
  1086. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1087. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1088. __le16 fc = rtl_get_fc(skb);
  1089. if (rtlpriv->dm.supp_phymode_switch &&
  1090. mac->link_state < MAC80211_LINKED &&
  1091. (ieee80211_is_auth(fc) || ieee80211_is_probe_req(fc))) {
  1092. if (rtlpriv->cfg->ops->chk_switch_dmdp)
  1093. rtlpriv->cfg->ops->chk_switch_dmdp(hw);
  1094. }
  1095. if (ieee80211_is_auth(fc)) {
  1096. RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "MAC80211_LINKING\n");
  1097. rtl_ips_nic_on(hw);
  1098. mac->link_state = MAC80211_LINKING;
  1099. /* Dul mac */
  1100. rtlpriv->phy.need_iqk = true;
  1101. }
  1102. return true;
  1103. }
  1104. EXPORT_SYMBOL_GPL(rtl_tx_mgmt_proc);
  1105. struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw, u8 *sa,
  1106. u8 *bssid, u16 tid);
  1107. static void process_agg_start(struct ieee80211_hw *hw,
  1108. struct ieee80211_hdr *hdr, u16 tid)
  1109. {
  1110. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1111. struct ieee80211_rx_status rx_status = { 0 };
  1112. struct sk_buff *skb_delba = NULL;
  1113. skb_delba = rtl_make_del_ba(hw, hdr->addr2, hdr->addr3, tid);
  1114. if (skb_delba) {
  1115. rx_status.freq = hw->conf.chandef.chan->center_freq;
  1116. rx_status.band = hw->conf.chandef.chan->band;
  1117. rx_status.flag |= RX_FLAG_DECRYPTED;
  1118. rx_status.flag |= RX_FLAG_MACTIME_START;
  1119. rx_status.rate_idx = 0;
  1120. rx_status.signal = 50 + 10;
  1121. memcpy(IEEE80211_SKB_RXCB(skb_delba),
  1122. &rx_status, sizeof(rx_status));
  1123. RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG,
  1124. "fake del\n",
  1125. skb_delba->data,
  1126. skb_delba->len);
  1127. ieee80211_rx_irqsafe(hw, skb_delba);
  1128. }
  1129. }
  1130. bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
  1131. {
  1132. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1133. struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
  1134. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1135. __le16 fc = rtl_get_fc(skb);
  1136. u8 *act = (u8 *)(((u8 *)skb->data + MAC80211_3ADDR_LEN));
  1137. u8 category;
  1138. if (!ieee80211_is_action(fc))
  1139. return true;
  1140. category = *act;
  1141. act++;
  1142. switch (category) {
  1143. case ACT_CAT_BA:
  1144. switch (*act) {
  1145. case ACT_ADDBAREQ:
  1146. if (mac->act_scanning)
  1147. return false;
  1148. RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
  1149. "%s ACT_ADDBAREQ From :%pM\n",
  1150. is_tx ? "Tx" : "Rx", hdr->addr2);
  1151. RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "req\n",
  1152. skb->data, skb->len);
  1153. if (!is_tx) {
  1154. struct ieee80211_sta *sta = NULL;
  1155. struct rtl_sta_info *sta_entry = NULL;
  1156. struct rtl_tid_data *tid_data;
  1157. struct ieee80211_mgmt *mgmt = (void *)skb->data;
  1158. u16 capab = 0, tid = 0;
  1159. rcu_read_lock();
  1160. sta = rtl_find_sta(hw, hdr->addr3);
  1161. if (sta == NULL) {
  1162. RT_TRACE(rtlpriv, COMP_SEND | COMP_RECV,
  1163. DBG_DMESG, "sta is NULL\n");
  1164. rcu_read_unlock();
  1165. return true;
  1166. }
  1167. sta_entry =
  1168. (struct rtl_sta_info *)sta->drv_priv;
  1169. if (!sta_entry) {
  1170. rcu_read_unlock();
  1171. return true;
  1172. }
  1173. capab =
  1174. le16_to_cpu(mgmt->u.action.u.addba_req.capab);
  1175. tid = (capab &
  1176. IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
  1177. if (tid >= MAX_TID_COUNT) {
  1178. rcu_read_unlock();
  1179. return true;
  1180. }
  1181. tid_data = &sta_entry->tids[tid];
  1182. if (tid_data->agg.rx_agg_state ==
  1183. RTL_RX_AGG_START)
  1184. process_agg_start(hw, hdr, tid);
  1185. rcu_read_unlock();
  1186. }
  1187. break;
  1188. case ACT_ADDBARSP:
  1189. RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
  1190. "%s ACT_ADDBARSP From :%pM\n",
  1191. is_tx ? "Tx" : "Rx", hdr->addr2);
  1192. break;
  1193. case ACT_DELBA:
  1194. RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
  1195. "ACT_ADDBADEL From :%pM\n", hdr->addr2);
  1196. break;
  1197. }
  1198. break;
  1199. default:
  1200. break;
  1201. }
  1202. return true;
  1203. }
  1204. EXPORT_SYMBOL_GPL(rtl_action_proc);
  1205. static void setup_special_tx(struct rtl_priv *rtlpriv, struct rtl_ps_ctl *ppsc,
  1206. int type)
  1207. {
  1208. struct ieee80211_hw *hw = rtlpriv->hw;
  1209. rtlpriv->ra.is_special_data = true;
  1210. if (rtlpriv->cfg->ops->get_btc_status())
  1211. rtlpriv->btcoexist.btc_ops->btc_special_packet_notify(
  1212. rtlpriv, type);
  1213. rtl_lps_leave(hw);
  1214. ppsc->last_delaylps_stamp_jiffies = jiffies;
  1215. }
  1216. static const u8 *rtl_skb_ether_type_ptr(struct ieee80211_hw *hw,
  1217. struct sk_buff *skb, bool is_enc)
  1218. {
  1219. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1220. u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb);
  1221. u8 encrypt_header_len = 0;
  1222. u8 offset;
  1223. switch (rtlpriv->sec.pairwise_enc_algorithm) {
  1224. case WEP40_ENCRYPTION:
  1225. case WEP104_ENCRYPTION:
  1226. encrypt_header_len = 4;/*WEP_IV_LEN*/
  1227. break;
  1228. case TKIP_ENCRYPTION:
  1229. encrypt_header_len = 8;/*TKIP_IV_LEN*/
  1230. break;
  1231. case AESCCMP_ENCRYPTION:
  1232. encrypt_header_len = 8;/*CCMP_HDR_LEN;*/
  1233. break;
  1234. default:
  1235. break;
  1236. }
  1237. offset = mac_hdr_len + SNAP_SIZE;
  1238. if (is_enc)
  1239. offset += encrypt_header_len;
  1240. return skb->data + offset;
  1241. }
  1242. /*should call before software enc*/
  1243. u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx,
  1244. bool is_enc)
  1245. {
  1246. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1247. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1248. __le16 fc = rtl_get_fc(skb);
  1249. u16 ether_type;
  1250. const u8 *ether_type_ptr;
  1251. const struct iphdr *ip;
  1252. if (!ieee80211_is_data(fc))
  1253. goto end;
  1254. ether_type_ptr = rtl_skb_ether_type_ptr(hw, skb, is_enc);
  1255. ether_type = be16_to_cpup((__be16 *)ether_type_ptr);
  1256. if (ETH_P_IP == ether_type) {
  1257. ip = (struct iphdr *)((u8 *)ether_type_ptr +
  1258. PROTOC_TYPE_SIZE);
  1259. if (IPPROTO_UDP == ip->protocol) {
  1260. struct udphdr *udp = (struct udphdr *)((u8 *)ip +
  1261. (ip->ihl << 2));
  1262. if (((((u8 *)udp)[1] == 68) &&
  1263. (((u8 *)udp)[3] == 67)) ||
  1264. ((((u8 *)udp)[1] == 67) &&
  1265. (((u8 *)udp)[3] == 68))) {
  1266. /* 68 : UDP BOOTP client
  1267. * 67 : UDP BOOTP server
  1268. */
  1269. RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV),
  1270. DBG_DMESG, "dhcp %s !!\n",
  1271. (is_tx) ? "Tx" : "Rx");
  1272. if (is_tx)
  1273. setup_special_tx(rtlpriv, ppsc,
  1274. PACKET_DHCP);
  1275. return true;
  1276. }
  1277. }
  1278. } else if (ETH_P_ARP == ether_type) {
  1279. if (is_tx)
  1280. setup_special_tx(rtlpriv, ppsc, PACKET_ARP);
  1281. return true;
  1282. } else if (ETH_P_PAE == ether_type) {
  1283. /* EAPOL is seens as in-4way */
  1284. rtlpriv->btcoexist.btc_info.in_4way = true;
  1285. rtlpriv->btcoexist.btc_info.in_4way_ts = jiffies;
  1286. rtlpriv->btcoexist.btc_info.in_4way_ts = jiffies;
  1287. RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
  1288. "802.1X %s EAPOL pkt!!\n", (is_tx) ? "Tx" : "Rx");
  1289. if (is_tx) {
  1290. rtlpriv->ra.is_special_data = true;
  1291. rtl_lps_leave(hw);
  1292. ppsc->last_delaylps_stamp_jiffies = jiffies;
  1293. setup_special_tx(rtlpriv, ppsc, PACKET_EAPOL);
  1294. }
  1295. return true;
  1296. } else if (ETH_P_IPV6 == ether_type) {
  1297. /* TODO: Handle any IPv6 cases that need special handling.
  1298. * For now, always return false
  1299. */
  1300. goto end;
  1301. }
  1302. end:
  1303. rtlpriv->ra.is_special_data = false;
  1304. return false;
  1305. }
  1306. EXPORT_SYMBOL_GPL(rtl_is_special_data);
  1307. bool rtl_is_tx_report_skb(struct ieee80211_hw *hw, struct sk_buff *skb)
  1308. {
  1309. u16 ether_type;
  1310. const u8 *ether_type_ptr;
  1311. ether_type_ptr = rtl_skb_ether_type_ptr(hw, skb, true);
  1312. ether_type = be16_to_cpup((__be16 *)ether_type_ptr);
  1313. /* EAPOL */
  1314. if (ether_type == ETH_P_PAE)
  1315. return true;
  1316. return false;
  1317. }
  1318. static u16 rtl_get_tx_report_sn(struct ieee80211_hw *hw)
  1319. {
  1320. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1321. struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
  1322. u16 sn;
  1323. sn = atomic_inc_return(&tx_report->sn) & 0x0FFF;
  1324. tx_report->last_sent_sn = sn;
  1325. tx_report->last_sent_time = jiffies;
  1326. RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_DMESG,
  1327. "Send TX-Report sn=0x%X\n", sn);
  1328. return sn;
  1329. }
  1330. void rtl_get_tx_report(struct rtl_tcb_desc *ptcb_desc, u8 *pdesc,
  1331. struct ieee80211_hw *hw)
  1332. {
  1333. if (ptcb_desc->use_spe_rpt) {
  1334. u16 sn = rtl_get_tx_report_sn(hw);
  1335. SET_TX_DESC_SPE_RPT(pdesc, 1);
  1336. SET_TX_DESC_SW_DEFINE(pdesc, sn);
  1337. }
  1338. }
  1339. EXPORT_SYMBOL_GPL(rtl_get_tx_report);
  1340. void rtl_tx_report_handler(struct ieee80211_hw *hw, u8 *tmp_buf, u8 c2h_cmd_len)
  1341. {
  1342. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1343. struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
  1344. u16 sn;
  1345. sn = ((tmp_buf[7] & 0x0F) << 8) | tmp_buf[6];
  1346. tx_report->last_recv_sn = sn;
  1347. RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_DMESG,
  1348. "Recv TX-Report st=0x%02X sn=0x%X retry=0x%X\n",
  1349. tmp_buf[0], sn, tmp_buf[2]);
  1350. }
  1351. EXPORT_SYMBOL_GPL(rtl_tx_report_handler);
  1352. bool rtl_check_tx_report_acked(struct ieee80211_hw *hw)
  1353. {
  1354. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1355. struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
  1356. if (tx_report->last_sent_sn == tx_report->last_recv_sn)
  1357. return true;
  1358. if (time_before(tx_report->last_sent_time + 3 * HZ, jiffies)) {
  1359. RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_WARNING,
  1360. "Check TX-Report timeout!!\n");
  1361. return true; /* 3 sec. (timeout) seen as acked */
  1362. }
  1363. return false;
  1364. }
  1365. void rtl_wait_tx_report_acked(struct ieee80211_hw *hw, u32 wait_ms)
  1366. {
  1367. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1368. int i;
  1369. for (i = 0; i < wait_ms; i++) {
  1370. if (rtl_check_tx_report_acked(hw))
  1371. break;
  1372. usleep_range(1000, 2000);
  1373. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1374. "Wait 1ms (%d/%d) to disable key.\n", i, wait_ms);
  1375. }
  1376. }
  1377. u32 rtl_get_hal_edca_param(struct ieee80211_hw *hw,
  1378. struct ieee80211_vif *vif,
  1379. enum wireless_mode wirelessmode,
  1380. struct ieee80211_tx_queue_params *param)
  1381. {
  1382. u32 reg = 0;
  1383. u8 sifstime = 10;
  1384. u8 slottime = 20;
  1385. /* AIFS = AIFSN * slot time + SIFS */
  1386. switch (wirelessmode) {
  1387. case WIRELESS_MODE_A:
  1388. case WIRELESS_MODE_N_24G:
  1389. case WIRELESS_MODE_N_5G:
  1390. case WIRELESS_MODE_AC_5G:
  1391. case WIRELESS_MODE_AC_24G:
  1392. sifstime = 16;
  1393. slottime = 9;
  1394. break;
  1395. case WIRELESS_MODE_G:
  1396. slottime = (vif->bss_conf.use_short_slot ? 9 : 20);
  1397. break;
  1398. default:
  1399. break;
  1400. }
  1401. reg |= (param->txop & 0x7FF) << 16;
  1402. reg |= (fls(param->cw_max) & 0xF) << 12;
  1403. reg |= (fls(param->cw_min) & 0xF) << 8;
  1404. reg |= (param->aifs & 0x0F) * slottime + sifstime;
  1405. return reg;
  1406. }
  1407. EXPORT_SYMBOL_GPL(rtl_get_hal_edca_param);
  1408. /*********************************************************
  1409. *
  1410. * functions called by core.c
  1411. *
  1412. *********************************************************/
  1413. int rtl_tx_agg_start(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1414. struct ieee80211_sta *sta, u16 tid, u16 *ssn)
  1415. {
  1416. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1417. struct rtl_tid_data *tid_data;
  1418. struct rtl_sta_info *sta_entry = NULL;
  1419. if (sta == NULL)
  1420. return -EINVAL;
  1421. if (unlikely(tid >= MAX_TID_COUNT))
  1422. return -EINVAL;
  1423. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1424. if (!sta_entry)
  1425. return -ENXIO;
  1426. tid_data = &sta_entry->tids[tid];
  1427. RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
  1428. "on ra = %pM tid = %d seq:%d\n", sta->addr, tid,
  1429. *ssn);
  1430. tid_data->agg.agg_state = RTL_AGG_START;
  1431. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1432. return 0;
  1433. }
  1434. int rtl_tx_agg_stop(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1435. struct ieee80211_sta *sta, u16 tid)
  1436. {
  1437. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1438. struct rtl_sta_info *sta_entry = NULL;
  1439. if (sta == NULL)
  1440. return -EINVAL;
  1441. RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
  1442. "on ra = %pM tid = %d\n", sta->addr, tid);
  1443. if (unlikely(tid >= MAX_TID_COUNT))
  1444. return -EINVAL;
  1445. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1446. sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP;
  1447. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1448. return 0;
  1449. }
  1450. int rtl_rx_agg_start(struct ieee80211_hw *hw,
  1451. struct ieee80211_sta *sta, u16 tid)
  1452. {
  1453. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1454. struct rtl_tid_data *tid_data;
  1455. struct rtl_sta_info *sta_entry = NULL;
  1456. u8 reject_agg;
  1457. if (sta == NULL)
  1458. return -EINVAL;
  1459. if (unlikely(tid >= MAX_TID_COUNT))
  1460. return -EINVAL;
  1461. if (rtlpriv->cfg->ops->get_btc_status()) {
  1462. rtlpriv->btcoexist.btc_ops->btc_get_ampdu_cfg(rtlpriv,
  1463. &reject_agg,
  1464. NULL, NULL);
  1465. if (reject_agg)
  1466. return -EINVAL;
  1467. }
  1468. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1469. if (!sta_entry)
  1470. return -ENXIO;
  1471. tid_data = &sta_entry->tids[tid];
  1472. RT_TRACE(rtlpriv, COMP_RECV, DBG_DMESG,
  1473. "on ra = %pM tid = %d\n", sta->addr, tid);
  1474. tid_data->agg.rx_agg_state = RTL_RX_AGG_START;
  1475. return 0;
  1476. }
  1477. int rtl_rx_agg_stop(struct ieee80211_hw *hw,
  1478. struct ieee80211_sta *sta, u16 tid)
  1479. {
  1480. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1481. struct rtl_sta_info *sta_entry = NULL;
  1482. if (sta == NULL)
  1483. return -EINVAL;
  1484. RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
  1485. "on ra = %pM tid = %d\n", sta->addr, tid);
  1486. if (unlikely(tid >= MAX_TID_COUNT))
  1487. return -EINVAL;
  1488. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1489. sta_entry->tids[tid].agg.rx_agg_state = RTL_RX_AGG_STOP;
  1490. return 0;
  1491. }
  1492. int rtl_tx_agg_oper(struct ieee80211_hw *hw,
  1493. struct ieee80211_sta *sta, u16 tid)
  1494. {
  1495. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1496. struct rtl_sta_info *sta_entry = NULL;
  1497. if (sta == NULL)
  1498. return -EINVAL;
  1499. RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
  1500. "on ra = %pM tid = %d\n", sta->addr, tid);
  1501. if (unlikely(tid >= MAX_TID_COUNT))
  1502. return -EINVAL;
  1503. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1504. sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL;
  1505. return 0;
  1506. }
  1507. void rtl_rx_ampdu_apply(struct rtl_priv *rtlpriv)
  1508. {
  1509. struct rtl_btc_ops *btc_ops = rtlpriv->btcoexist.btc_ops;
  1510. u8 reject_agg = 0, ctrl_agg_size = 0, agg_size = 0;
  1511. if (rtlpriv->cfg->ops->get_btc_status())
  1512. btc_ops->btc_get_ampdu_cfg(rtlpriv, &reject_agg,
  1513. &ctrl_agg_size, &agg_size);
  1514. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
  1515. "Set RX AMPDU: coex - reject=%d, ctrl_agg_size=%d, size=%d",
  1516. reject_agg, ctrl_agg_size, agg_size);
  1517. rtlpriv->hw->max_rx_aggregation_subframes =
  1518. (ctrl_agg_size ? agg_size : IEEE80211_MAX_AMPDU_BUF);
  1519. }
  1520. EXPORT_SYMBOL(rtl_rx_ampdu_apply);
  1521. /*********************************************************
  1522. *
  1523. * wq & timer callback functions
  1524. *
  1525. *********************************************************/
  1526. /* this function is used for roaming */
  1527. void rtl_beacon_statistic(struct ieee80211_hw *hw, struct sk_buff *skb)
  1528. {
  1529. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1530. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1531. if (rtlpriv->mac80211.opmode != NL80211_IFTYPE_STATION)
  1532. return;
  1533. if (rtlpriv->mac80211.link_state < MAC80211_LINKED)
  1534. return;
  1535. /* check if this really is a beacon */
  1536. if (!ieee80211_is_beacon(hdr->frame_control) &&
  1537. !ieee80211_is_probe_resp(hdr->frame_control))
  1538. return;
  1539. /* min. beacon length + FCS_LEN */
  1540. if (skb->len <= 40 + FCS_LEN)
  1541. return;
  1542. /* and only beacons from the associated BSSID, please */
  1543. if (!ether_addr_equal(hdr->addr3, rtlpriv->mac80211.bssid))
  1544. return;
  1545. rtlpriv->link_info.bcn_rx_inperiod++;
  1546. }
  1547. EXPORT_SYMBOL_GPL(rtl_beacon_statistic);
  1548. static void rtl_free_entries_from_scan_list(struct ieee80211_hw *hw)
  1549. {
  1550. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1551. struct rtl_bssid_entry *entry, *next;
  1552. list_for_each_entry_safe(entry, next, &rtlpriv->scan_list.list, list) {
  1553. list_del(&entry->list);
  1554. kfree(entry);
  1555. rtlpriv->scan_list.num--;
  1556. }
  1557. }
  1558. void rtl_scan_list_expire(struct ieee80211_hw *hw)
  1559. {
  1560. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1561. struct rtl_bssid_entry *entry, *next;
  1562. unsigned long flags;
  1563. spin_lock_irqsave(&rtlpriv->locks.scan_list_lock, flags);
  1564. list_for_each_entry_safe(entry, next, &rtlpriv->scan_list.list, list) {
  1565. /* 180 seconds */
  1566. if (jiffies_to_msecs(jiffies - entry->age) < 180000)
  1567. continue;
  1568. list_del(&entry->list);
  1569. rtlpriv->scan_list.num--;
  1570. RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD,
  1571. "BSSID=%pM is expire in scan list (total=%d)\n",
  1572. entry->bssid, rtlpriv->scan_list.num);
  1573. kfree(entry);
  1574. }
  1575. spin_unlock_irqrestore(&rtlpriv->locks.scan_list_lock, flags);
  1576. rtlpriv->btcoexist.btc_info.ap_num = rtlpriv->scan_list.num;
  1577. }
  1578. void rtl_collect_scan_list(struct ieee80211_hw *hw, struct sk_buff *skb)
  1579. {
  1580. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1581. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1582. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1583. unsigned long flags;
  1584. struct rtl_bssid_entry *entry;
  1585. bool entry_found = false;
  1586. /* check if it is scanning */
  1587. if (!mac->act_scanning)
  1588. return;
  1589. /* check if this really is a beacon */
  1590. if (!ieee80211_is_beacon(hdr->frame_control) &&
  1591. !ieee80211_is_probe_resp(hdr->frame_control))
  1592. return;
  1593. spin_lock_irqsave(&rtlpriv->locks.scan_list_lock, flags);
  1594. list_for_each_entry(entry, &rtlpriv->scan_list.list, list) {
  1595. if (memcmp(entry->bssid, hdr->addr3, ETH_ALEN) == 0) {
  1596. list_del_init(&entry->list);
  1597. entry_found = true;
  1598. RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD,
  1599. "Update BSSID=%pM to scan list (total=%d)\n",
  1600. hdr->addr3, rtlpriv->scan_list.num);
  1601. break;
  1602. }
  1603. }
  1604. if (!entry_found) {
  1605. entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
  1606. if (!entry)
  1607. goto label_err;
  1608. memcpy(entry->bssid, hdr->addr3, ETH_ALEN);
  1609. rtlpriv->scan_list.num++;
  1610. RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD,
  1611. "Add BSSID=%pM to scan list (total=%d)\n",
  1612. hdr->addr3, rtlpriv->scan_list.num);
  1613. }
  1614. entry->age = jiffies;
  1615. list_add_tail(&entry->list, &rtlpriv->scan_list.list);
  1616. label_err:
  1617. spin_unlock_irqrestore(&rtlpriv->locks.scan_list_lock, flags);
  1618. }
  1619. EXPORT_SYMBOL(rtl_collect_scan_list);
  1620. void rtl_watchdog_wq_callback(void *data)
  1621. {
  1622. struct rtl_works *rtlworks = container_of_dwork_rtl(data,
  1623. struct rtl_works,
  1624. watchdog_wq);
  1625. struct ieee80211_hw *hw = rtlworks->hw;
  1626. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1627. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1628. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1629. bool busytraffic = false;
  1630. bool tx_busy_traffic = false;
  1631. bool rx_busy_traffic = false;
  1632. bool higher_busytraffic = false;
  1633. bool higher_busyrxtraffic = false;
  1634. u8 idx, tid;
  1635. u32 rx_cnt_inp4eriod = 0;
  1636. u32 tx_cnt_inp4eriod = 0;
  1637. u32 aver_rx_cnt_inperiod = 0;
  1638. u32 aver_tx_cnt_inperiod = 0;
  1639. u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0};
  1640. u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0};
  1641. if (is_hal_stop(rtlhal))
  1642. return;
  1643. /* <1> Determine if action frame is allowed */
  1644. if (mac->link_state > MAC80211_NOLINK) {
  1645. if (mac->cnt_after_linked < 20)
  1646. mac->cnt_after_linked++;
  1647. } else {
  1648. mac->cnt_after_linked = 0;
  1649. }
  1650. /* <2> to check if traffic busy, if
  1651. * busytraffic we don't change channel
  1652. */
  1653. if (mac->link_state >= MAC80211_LINKED) {
  1654. /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */
  1655. for (idx = 0; idx <= 2; idx++) {
  1656. rtlpriv->link_info.num_rx_in4period[idx] =
  1657. rtlpriv->link_info.num_rx_in4period[idx + 1];
  1658. rtlpriv->link_info.num_tx_in4period[idx] =
  1659. rtlpriv->link_info.num_tx_in4period[idx + 1];
  1660. }
  1661. rtlpriv->link_info.num_rx_in4period[3] =
  1662. rtlpriv->link_info.num_rx_inperiod;
  1663. rtlpriv->link_info.num_tx_in4period[3] =
  1664. rtlpriv->link_info.num_tx_inperiod;
  1665. for (idx = 0; idx <= 3; idx++) {
  1666. rx_cnt_inp4eriod +=
  1667. rtlpriv->link_info.num_rx_in4period[idx];
  1668. tx_cnt_inp4eriod +=
  1669. rtlpriv->link_info.num_tx_in4period[idx];
  1670. }
  1671. aver_rx_cnt_inperiod = rx_cnt_inp4eriod / 4;
  1672. aver_tx_cnt_inperiod = tx_cnt_inp4eriod / 4;
  1673. /* (2) check traffic busy */
  1674. if (aver_rx_cnt_inperiod > 100 || aver_tx_cnt_inperiod > 100) {
  1675. busytraffic = true;
  1676. if (aver_rx_cnt_inperiod > aver_tx_cnt_inperiod)
  1677. rx_busy_traffic = true;
  1678. else
  1679. tx_busy_traffic = false;
  1680. }
  1681. /* Higher Tx/Rx data. */
  1682. if (aver_rx_cnt_inperiod > 4000 ||
  1683. aver_tx_cnt_inperiod > 4000) {
  1684. higher_busytraffic = true;
  1685. /* Extremely high Rx data. */
  1686. if (aver_rx_cnt_inperiod > 5000)
  1687. higher_busyrxtraffic = true;
  1688. }
  1689. /* check every tid's tx traffic */
  1690. for (tid = 0; tid <= 7; tid++) {
  1691. for (idx = 0; idx <= 2; idx++)
  1692. rtlpriv->link_info.tidtx_in4period[tid][idx] =
  1693. rtlpriv->link_info.tidtx_in4period[tid]
  1694. [idx + 1];
  1695. rtlpriv->link_info.tidtx_in4period[tid][3] =
  1696. rtlpriv->link_info.tidtx_inperiod[tid];
  1697. for (idx = 0; idx <= 3; idx++)
  1698. tidtx_inp4eriod[tid] +=
  1699. rtlpriv->link_info.tidtx_in4period[tid][idx];
  1700. aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4;
  1701. if (aver_tidtx_inperiod[tid] > 5000)
  1702. rtlpriv->link_info.higher_busytxtraffic[tid] =
  1703. true;
  1704. else
  1705. rtlpriv->link_info.higher_busytxtraffic[tid] =
  1706. false;
  1707. }
  1708. /* PS is controlled by coex. */
  1709. if (rtlpriv->cfg->ops->get_btc_status() &&
  1710. rtlpriv->btcoexist.btc_ops->btc_is_bt_ctrl_lps(rtlpriv))
  1711. goto label_lps_done;
  1712. if (rtlpriv->link_info.num_rx_inperiod +
  1713. rtlpriv->link_info.num_tx_inperiod > 8 ||
  1714. rtlpriv->link_info.num_rx_inperiod > 2)
  1715. rtl_lps_leave(hw);
  1716. else
  1717. rtl_lps_enter(hw);
  1718. label_lps_done:
  1719. ;
  1720. }
  1721. rtlpriv->link_info.num_rx_inperiod = 0;
  1722. rtlpriv->link_info.num_tx_inperiod = 0;
  1723. for (tid = 0; tid <= 7; tid++)
  1724. rtlpriv->link_info.tidtx_inperiod[tid] = 0;
  1725. rtlpriv->link_info.busytraffic = busytraffic;
  1726. rtlpriv->link_info.higher_busytraffic = higher_busytraffic;
  1727. rtlpriv->link_info.rx_busy_traffic = rx_busy_traffic;
  1728. rtlpriv->link_info.tx_busy_traffic = tx_busy_traffic;
  1729. rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic;
  1730. rtlpriv->stats.txbytesunicast_inperiod =
  1731. rtlpriv->stats.txbytesunicast -
  1732. rtlpriv->stats.txbytesunicast_last;
  1733. rtlpriv->stats.rxbytesunicast_inperiod =
  1734. rtlpriv->stats.rxbytesunicast -
  1735. rtlpriv->stats.rxbytesunicast_last;
  1736. rtlpriv->stats.txbytesunicast_last = rtlpriv->stats.txbytesunicast;
  1737. rtlpriv->stats.rxbytesunicast_last = rtlpriv->stats.rxbytesunicast;
  1738. rtlpriv->stats.txbytesunicast_inperiod_tp =
  1739. (u32)(rtlpriv->stats.txbytesunicast_inperiod * 8 / 2 /
  1740. 1024 / 1024);
  1741. rtlpriv->stats.rxbytesunicast_inperiod_tp =
  1742. (u32)(rtlpriv->stats.rxbytesunicast_inperiod * 8 / 2 /
  1743. 1024 / 1024);
  1744. /* <3> DM */
  1745. if (!rtlpriv->cfg->mod_params->disable_watchdog)
  1746. rtlpriv->cfg->ops->dm_watchdog(hw);
  1747. /* <4> roaming */
  1748. if (mac->link_state == MAC80211_LINKED &&
  1749. mac->opmode == NL80211_IFTYPE_STATION) {
  1750. if ((rtlpriv->link_info.bcn_rx_inperiod +
  1751. rtlpriv->link_info.num_rx_inperiod) == 0) {
  1752. rtlpriv->link_info.roam_times++;
  1753. RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG,
  1754. "AP off for %d s\n",
  1755. (rtlpriv->link_info.roam_times * 2));
  1756. /* if we can't recv beacon for 10s,
  1757. * we should reconnect this AP
  1758. */
  1759. if (rtlpriv->link_info.roam_times >= 5) {
  1760. pr_err("AP off, try to reconnect now\n");
  1761. rtlpriv->link_info.roam_times = 0;
  1762. ieee80211_connection_loss(
  1763. rtlpriv->mac80211.vif);
  1764. }
  1765. } else {
  1766. rtlpriv->link_info.roam_times = 0;
  1767. }
  1768. }
  1769. if (rtlpriv->cfg->ops->get_btc_status())
  1770. rtlpriv->btcoexist.btc_ops->btc_periodical(rtlpriv);
  1771. if (rtlpriv->btcoexist.btc_info.in_4way) {
  1772. if (time_after(jiffies, rtlpriv->btcoexist.btc_info.in_4way_ts +
  1773. msecs_to_jiffies(IN_4WAY_TIMEOUT_TIME)))
  1774. rtlpriv->btcoexist.btc_info.in_4way = false;
  1775. }
  1776. rtlpriv->link_info.bcn_rx_inperiod = 0;
  1777. /* <6> scan list */
  1778. rtl_scan_list_expire(hw);
  1779. }
  1780. void rtl_watch_dog_timer_callback(struct timer_list *t)
  1781. {
  1782. struct rtl_priv *rtlpriv = from_timer(rtlpriv, t, works.watchdog_timer);
  1783. queue_delayed_work(rtlpriv->works.rtl_wq,
  1784. &rtlpriv->works.watchdog_wq, 0);
  1785. mod_timer(&rtlpriv->works.watchdog_timer,
  1786. jiffies + MSECS(RTL_WATCH_DOG_TIME));
  1787. }
  1788. void rtl_fwevt_wq_callback(void *data)
  1789. {
  1790. struct rtl_works *rtlworks =
  1791. container_of_dwork_rtl(data, struct rtl_works, fwevt_wq);
  1792. struct ieee80211_hw *hw = rtlworks->hw;
  1793. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1794. rtlpriv->cfg->ops->c2h_command_handle(hw);
  1795. }
  1796. void rtl_c2hcmd_enqueue(struct ieee80211_hw *hw, u8 tag, u8 len, u8 *val)
  1797. {
  1798. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1799. unsigned long flags;
  1800. struct rtl_c2hcmd *c2hcmd;
  1801. c2hcmd = kmalloc(sizeof(*c2hcmd),
  1802. in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
  1803. if (!c2hcmd)
  1804. goto label_err;
  1805. c2hcmd->val = kmalloc(len,
  1806. in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
  1807. if (!c2hcmd->val)
  1808. goto label_err2;
  1809. /* fill data */
  1810. c2hcmd->tag = tag;
  1811. c2hcmd->len = len;
  1812. memcpy(c2hcmd->val, val, len);
  1813. /* enqueue */
  1814. spin_lock_irqsave(&rtlpriv->locks.c2hcmd_lock, flags);
  1815. list_add_tail(&c2hcmd->list, &rtlpriv->c2hcmd_list);
  1816. spin_unlock_irqrestore(&rtlpriv->locks.c2hcmd_lock, flags);
  1817. /* wake up wq */
  1818. queue_delayed_work(rtlpriv->works.rtl_wq, &rtlpriv->works.c2hcmd_wq, 0);
  1819. return;
  1820. label_err2:
  1821. kfree(c2hcmd);
  1822. label_err:
  1823. RT_TRACE(rtlpriv, COMP_CMD, DBG_WARNING,
  1824. "C2H cmd enqueue fail.\n");
  1825. }
  1826. EXPORT_SYMBOL(rtl_c2hcmd_enqueue);
  1827. void rtl_c2hcmd_launcher(struct ieee80211_hw *hw, int exec)
  1828. {
  1829. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1830. unsigned long flags;
  1831. struct rtl_c2hcmd *c2hcmd;
  1832. int i;
  1833. for (i = 0; i < 200; i++) {
  1834. /* dequeue a task */
  1835. spin_lock_irqsave(&rtlpriv->locks.c2hcmd_lock, flags);
  1836. c2hcmd = list_first_entry_or_null(&rtlpriv->c2hcmd_list,
  1837. struct rtl_c2hcmd, list);
  1838. if (c2hcmd)
  1839. list_del(&c2hcmd->list);
  1840. spin_unlock_irqrestore(&rtlpriv->locks.c2hcmd_lock, flags);
  1841. /* do it */
  1842. if (!c2hcmd)
  1843. break;
  1844. if (rtlpriv->cfg->ops->c2h_content_parsing && exec)
  1845. rtlpriv->cfg->ops->c2h_content_parsing(hw,
  1846. c2hcmd->tag, c2hcmd->len, c2hcmd->val);
  1847. /* free */
  1848. kfree(c2hcmd->val);
  1849. kfree(c2hcmd);
  1850. }
  1851. }
  1852. void rtl_c2hcmd_wq_callback(void *data)
  1853. {
  1854. struct rtl_works *rtlworks = container_of_dwork_rtl(data,
  1855. struct rtl_works,
  1856. c2hcmd_wq);
  1857. struct ieee80211_hw *hw = rtlworks->hw;
  1858. rtl_c2hcmd_launcher(hw, 1);
  1859. }
  1860. void rtl_easy_concurrent_retrytimer_callback(struct timer_list *t)
  1861. {
  1862. struct rtl_priv *rtlpriv =
  1863. from_timer(rtlpriv, t, works.dualmac_easyconcurrent_retrytimer);
  1864. struct ieee80211_hw *hw = rtlpriv->hw;
  1865. struct rtl_priv *buddy_priv = rtlpriv->buddy_priv;
  1866. if (buddy_priv == NULL)
  1867. return;
  1868. rtlpriv->cfg->ops->dualmac_easy_concurrent(hw);
  1869. }
  1870. /*********************************************************
  1871. *
  1872. * frame process functions
  1873. *
  1874. *********************************************************/
  1875. u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie)
  1876. {
  1877. struct ieee80211_mgmt *mgmt = (void *)data;
  1878. u8 *pos, *end;
  1879. pos = (u8 *)mgmt->u.beacon.variable;
  1880. end = data + len;
  1881. while (pos < end) {
  1882. if (pos + 2 + pos[1] > end)
  1883. return NULL;
  1884. if (pos[0] == ie)
  1885. return pos;
  1886. pos += 2 + pos[1];
  1887. }
  1888. return NULL;
  1889. }
  1890. /* when we use 2 rx ants we send IEEE80211_SMPS_OFF */
  1891. /* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */
  1892. static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw,
  1893. enum ieee80211_smps_mode smps,
  1894. u8 *da, u8 *bssid)
  1895. {
  1896. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1897. struct sk_buff *skb;
  1898. struct ieee80211_mgmt *action_frame;
  1899. /* 27 = header + category + action + smps mode */
  1900. skb = dev_alloc_skb(27 + hw->extra_tx_headroom);
  1901. if (!skb)
  1902. return NULL;
  1903. skb_reserve(skb, hw->extra_tx_headroom);
  1904. action_frame = skb_put_zero(skb, 27);
  1905. memcpy(action_frame->da, da, ETH_ALEN);
  1906. memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN);
  1907. memcpy(action_frame->bssid, bssid, ETH_ALEN);
  1908. action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1909. IEEE80211_STYPE_ACTION);
  1910. action_frame->u.action.category = WLAN_CATEGORY_HT;
  1911. action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS;
  1912. switch (smps) {
  1913. case IEEE80211_SMPS_AUTOMATIC:/* 0 */
  1914. case IEEE80211_SMPS_NUM_MODES:/* 4 */
  1915. WARN_ON(1);
  1916. /* fall through */
  1917. case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/
  1918. action_frame->u.action.u.ht_smps.smps_control =
  1919. WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */
  1920. break;
  1921. case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/
  1922. action_frame->u.action.u.ht_smps.smps_control =
  1923. WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */
  1924. break;
  1925. case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/
  1926. action_frame->u.action.u.ht_smps.smps_control =
  1927. WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */
  1928. break;
  1929. }
  1930. return skb;
  1931. }
  1932. int rtl_send_smps_action(struct ieee80211_hw *hw,
  1933. struct ieee80211_sta *sta,
  1934. enum ieee80211_smps_mode smps)
  1935. {
  1936. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1937. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1938. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1939. struct sk_buff *skb = NULL;
  1940. struct rtl_tcb_desc tcb_desc;
  1941. u8 bssid[ETH_ALEN] = {0};
  1942. memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
  1943. if (rtlpriv->mac80211.act_scanning)
  1944. goto err_free;
  1945. if (!sta)
  1946. goto err_free;
  1947. if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
  1948. goto err_free;
  1949. if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
  1950. goto err_free;
  1951. if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_AP)
  1952. memcpy(bssid, rtlpriv->efuse.dev_addr, ETH_ALEN);
  1953. else
  1954. memcpy(bssid, rtlpriv->mac80211.bssid, ETH_ALEN);
  1955. skb = rtl_make_smps_action(hw, smps, sta->addr, bssid);
  1956. /* this is a type = mgmt * stype = action frame */
  1957. if (skb) {
  1958. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1959. struct rtl_sta_info *sta_entry =
  1960. (struct rtl_sta_info *) sta->drv_priv;
  1961. sta_entry->mimo_ps = smps;
  1962. /* rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0, true); */
  1963. info->control.rates[0].idx = 0;
  1964. info->band = hw->conf.chandef.chan->band;
  1965. rtlpriv->intf_ops->adapter_tx(hw, sta, skb, &tcb_desc);
  1966. }
  1967. return 1;
  1968. err_free:
  1969. return 0;
  1970. }
  1971. EXPORT_SYMBOL(rtl_send_smps_action);
  1972. void rtl_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation)
  1973. {
  1974. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1975. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1976. enum io_type iotype;
  1977. if (!is_hal_stop(rtlhal)) {
  1978. switch (operation) {
  1979. case SCAN_OPT_BACKUP:
  1980. iotype = IO_CMD_PAUSE_DM_BY_SCAN;
  1981. rtlpriv->cfg->ops->set_hw_reg(hw,
  1982. HW_VAR_IO_CMD,
  1983. (u8 *)&iotype);
  1984. break;
  1985. case SCAN_OPT_RESTORE:
  1986. iotype = IO_CMD_RESUME_DM_BY_SCAN;
  1987. rtlpriv->cfg->ops->set_hw_reg(hw,
  1988. HW_VAR_IO_CMD,
  1989. (u8 *)&iotype);
  1990. break;
  1991. default:
  1992. pr_err("Unknown Scan Backup operation.\n");
  1993. break;
  1994. }
  1995. }
  1996. }
  1997. EXPORT_SYMBOL(rtl_phy_scan_operation_backup);
  1998. /* because mac80211 have issues when can receive del ba
  1999. * so here we just make a fake del_ba if we receive a ba_req
  2000. * but rx_agg was opened to let mac80211 release some ba
  2001. * related resources, so please this del_ba for tx
  2002. */
  2003. struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw,
  2004. u8 *sa, u8 *bssid, u16 tid)
  2005. {
  2006. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  2007. struct sk_buff *skb;
  2008. struct ieee80211_mgmt *action_frame;
  2009. u16 params;
  2010. /* 27 = header + category + action + smps mode */
  2011. skb = dev_alloc_skb(34 + hw->extra_tx_headroom);
  2012. if (!skb)
  2013. return NULL;
  2014. skb_reserve(skb, hw->extra_tx_headroom);
  2015. action_frame = skb_put_zero(skb, 34);
  2016. memcpy(action_frame->sa, sa, ETH_ALEN);
  2017. memcpy(action_frame->da, rtlefuse->dev_addr, ETH_ALEN);
  2018. memcpy(action_frame->bssid, bssid, ETH_ALEN);
  2019. action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  2020. IEEE80211_STYPE_ACTION);
  2021. action_frame->u.action.category = WLAN_CATEGORY_BACK;
  2022. action_frame->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
  2023. params = (u16)(1 << 11); /* bit 11 initiator */
  2024. params |= (u16)(tid << 12); /* bit 15:12 TID number */
  2025. action_frame->u.action.u.delba.params = cpu_to_le16(params);
  2026. action_frame->u.action.u.delba.reason_code =
  2027. cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT);
  2028. return skb;
  2029. }
  2030. /*********************************************************
  2031. *
  2032. * IOT functions
  2033. *
  2034. *********************************************************/
  2035. static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw,
  2036. struct octet_string vendor_ie)
  2037. {
  2038. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2039. bool matched = false;
  2040. static u8 athcap_1[] = { 0x00, 0x03, 0x7F };
  2041. static u8 athcap_2[] = { 0x00, 0x13, 0x74 };
  2042. static u8 broadcap_1[] = { 0x00, 0x10, 0x18 };
  2043. static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 };
  2044. static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 };
  2045. static u8 racap[] = { 0x00, 0x0c, 0x43 };
  2046. static u8 ciscocap[] = { 0x00, 0x40, 0x96 };
  2047. static u8 marvcap[] = { 0x00, 0x50, 0x43 };
  2048. if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 ||
  2049. memcmp(vendor_ie.octet, athcap_2, 3) == 0) {
  2050. rtlpriv->mac80211.vendor = PEER_ATH;
  2051. matched = true;
  2052. } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 ||
  2053. memcmp(vendor_ie.octet, broadcap_2, 3) == 0 ||
  2054. memcmp(vendor_ie.octet, broadcap_3, 3) == 0) {
  2055. rtlpriv->mac80211.vendor = PEER_BROAD;
  2056. matched = true;
  2057. } else if (memcmp(vendor_ie.octet, racap, 3) == 0) {
  2058. rtlpriv->mac80211.vendor = PEER_RAL;
  2059. matched = true;
  2060. } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) {
  2061. rtlpriv->mac80211.vendor = PEER_CISCO;
  2062. matched = true;
  2063. } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) {
  2064. rtlpriv->mac80211.vendor = PEER_MARV;
  2065. matched = true;
  2066. }
  2067. return matched;
  2068. }
  2069. static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data,
  2070. unsigned int len)
  2071. {
  2072. struct ieee80211_mgmt *mgmt = (void *)data;
  2073. struct octet_string vendor_ie;
  2074. u8 *pos, *end;
  2075. pos = (u8 *)mgmt->u.beacon.variable;
  2076. end = data + len;
  2077. while (pos < end) {
  2078. if (pos[0] == 221) {
  2079. vendor_ie.length = pos[1];
  2080. vendor_ie.octet = &pos[2];
  2081. if (rtl_chk_vendor_ouisub(hw, vendor_ie))
  2082. return true;
  2083. }
  2084. if (pos + 2 + pos[1] > end)
  2085. return false;
  2086. pos += 2 + pos[1];
  2087. }
  2088. return false;
  2089. }
  2090. void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len)
  2091. {
  2092. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2093. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  2094. struct ieee80211_hdr *hdr = (void *)data;
  2095. u32 vendor = PEER_UNKNOWN;
  2096. static u8 ap3_1[3] = { 0x00, 0x14, 0xbf };
  2097. static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 };
  2098. static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e };
  2099. static u8 ap4_1[3] = { 0x00, 0x90, 0xcc };
  2100. static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e };
  2101. static u8 ap4_3[3] = { 0x00, 0x18, 0x02 };
  2102. static u8 ap4_4[3] = { 0x00, 0x17, 0x3f };
  2103. static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf };
  2104. static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 };
  2105. static u8 ap5_2[3] = { 0x00, 0x21, 0x91 };
  2106. static u8 ap5_3[3] = { 0x00, 0x24, 0x01 };
  2107. static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 };
  2108. static u8 ap5_5[3] = { 0x00, 0x17, 0x9A };
  2109. static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 };
  2110. static u8 ap6_1[3] = { 0x00, 0x17, 0x94 };
  2111. static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 };
  2112. if (mac->opmode != NL80211_IFTYPE_STATION)
  2113. return;
  2114. if (mac->link_state == MAC80211_NOLINK) {
  2115. mac->vendor = PEER_UNKNOWN;
  2116. return;
  2117. }
  2118. if (mac->cnt_after_linked > 2)
  2119. return;
  2120. /* check if this really is a beacon */
  2121. if (!ieee80211_is_beacon(hdr->frame_control))
  2122. return;
  2123. /* min. beacon length + FCS_LEN */
  2124. if (len <= 40 + FCS_LEN)
  2125. return;
  2126. /* and only beacons from the associated BSSID, please */
  2127. if (!ether_addr_equal_64bits(hdr->addr3, rtlpriv->mac80211.bssid))
  2128. return;
  2129. if (rtl_find_221_ie(hw, data, len))
  2130. vendor = mac->vendor;
  2131. if ((memcmp(mac->bssid, ap5_1, 3) == 0) ||
  2132. (memcmp(mac->bssid, ap5_2, 3) == 0) ||
  2133. (memcmp(mac->bssid, ap5_3, 3) == 0) ||
  2134. (memcmp(mac->bssid, ap5_4, 3) == 0) ||
  2135. (memcmp(mac->bssid, ap5_5, 3) == 0) ||
  2136. (memcmp(mac->bssid, ap5_6, 3) == 0) ||
  2137. vendor == PEER_ATH) {
  2138. vendor = PEER_ATH;
  2139. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ath find\n");
  2140. } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) ||
  2141. (memcmp(mac->bssid, ap4_5, 3) == 0) ||
  2142. (memcmp(mac->bssid, ap4_1, 3) == 0) ||
  2143. (memcmp(mac->bssid, ap4_2, 3) == 0) ||
  2144. (memcmp(mac->bssid, ap4_3, 3) == 0) ||
  2145. vendor == PEER_RAL) {
  2146. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ral find\n");
  2147. vendor = PEER_RAL;
  2148. } else if (memcmp(mac->bssid, ap6_1, 3) == 0 ||
  2149. vendor == PEER_CISCO) {
  2150. vendor = PEER_CISCO;
  2151. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>cisco find\n");
  2152. } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) ||
  2153. (memcmp(mac->bssid, ap3_2, 3) == 0) ||
  2154. (memcmp(mac->bssid, ap3_3, 3) == 0) ||
  2155. vendor == PEER_BROAD) {
  2156. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>broad find\n");
  2157. vendor = PEER_BROAD;
  2158. } else if (memcmp(mac->bssid, ap7_1, 3) == 0 ||
  2159. vendor == PEER_MARV) {
  2160. vendor = PEER_MARV;
  2161. RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>marv find\n");
  2162. }
  2163. mac->vendor = vendor;
  2164. }
  2165. EXPORT_SYMBOL_GPL(rtl_recognize_peer);
  2166. MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
  2167. MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
  2168. MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
  2169. MODULE_LICENSE("GPL");
  2170. MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
  2171. struct rtl_global_var rtl_global_var = {};
  2172. EXPORT_SYMBOL_GPL(rtl_global_var);
  2173. static int __init rtl_core_module_init(void)
  2174. {
  2175. if (rtl_rate_control_register())
  2176. pr_err("rtl: Unable to register rtl_rc, use default RC !!\n");
  2177. /* add debugfs */
  2178. rtl_debugfs_add_topdir();
  2179. /* init some global vars */
  2180. INIT_LIST_HEAD(&rtl_global_var.glb_priv_list);
  2181. spin_lock_init(&rtl_global_var.glb_list_lock);
  2182. return 0;
  2183. }
  2184. static void __exit rtl_core_module_exit(void)
  2185. {
  2186. /*RC*/
  2187. rtl_rate_control_unregister();
  2188. /* remove debugfs */
  2189. rtl_debugfs_remove_topdir();
  2190. }
  2191. module_init(rtl_core_module_init);
  2192. module_exit(rtl_core_module_exit);