base.c 74 KB

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