base.c 75 KB

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