base.c 71 KB

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