base.c 72 KB

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