sta.c 102 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639
  1. /******************************************************************************
  2. *
  3. * This file is provided under a dual BSD/GPLv2 license. When using or
  4. * redistributing this file, you may do so under either license.
  5. *
  6. * GPL LICENSE SUMMARY
  7. *
  8. * Copyright(c) 2012 - 2015 Intel Corporation. All rights reserved.
  9. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  10. * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of version 2 of the GNU General Public License as
  14. * published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  24. * USA
  25. *
  26. * The full GNU General Public License is included in this distribution
  27. * in the file called COPYING.
  28. *
  29. * Contact Information:
  30. * Intel Linux Wireless <linuxwifi@intel.com>
  31. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  32. *
  33. * BSD LICENSE
  34. *
  35. * Copyright(c) 2012 - 2015 Intel Corporation. All rights reserved.
  36. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  37. * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
  38. * All rights reserved.
  39. *
  40. * Redistribution and use in source and binary forms, with or without
  41. * modification, are permitted provided that the following conditions
  42. * are met:
  43. *
  44. * * Redistributions of source code must retain the above copyright
  45. * notice, this list of conditions and the following disclaimer.
  46. * * Redistributions in binary form must reproduce the above copyright
  47. * notice, this list of conditions and the following disclaimer in
  48. * the documentation and/or other materials provided with the
  49. * distribution.
  50. * * Neither the name Intel Corporation nor the names of its
  51. * contributors may be used to endorse or promote products derived
  52. * from this software without specific prior written permission.
  53. *
  54. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  55. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  56. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  57. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  58. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  59. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  60. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  61. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  62. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  63. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  64. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  65. *
  66. *****************************************************************************/
  67. #include <net/mac80211.h>
  68. #include "mvm.h"
  69. #include "sta.h"
  70. #include "rs.h"
  71. /*
  72. * New version of ADD_STA_sta command added new fields at the end of the
  73. * structure, so sending the size of the relevant API's structure is enough to
  74. * support both API versions.
  75. */
  76. static inline int iwl_mvm_add_sta_cmd_size(struct iwl_mvm *mvm)
  77. {
  78. if (iwl_mvm_has_new_rx_api(mvm) ||
  79. fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
  80. return sizeof(struct iwl_mvm_add_sta_cmd);
  81. else
  82. return sizeof(struct iwl_mvm_add_sta_cmd_v7);
  83. }
  84. static int iwl_mvm_find_free_sta_id(struct iwl_mvm *mvm,
  85. enum nl80211_iftype iftype)
  86. {
  87. int sta_id;
  88. u32 reserved_ids = 0;
  89. BUILD_BUG_ON(IWL_MVM_STATION_COUNT > 32);
  90. WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status));
  91. lockdep_assert_held(&mvm->mutex);
  92. /* d0i3/d3 assumes the AP's sta_id (of sta vif) is 0. reserve it. */
  93. if (iftype != NL80211_IFTYPE_STATION)
  94. reserved_ids = BIT(0);
  95. /* Don't take rcu_read_lock() since we are protected by mvm->mutex */
  96. for (sta_id = 0; sta_id < ARRAY_SIZE(mvm->fw_id_to_mac_id); sta_id++) {
  97. if (BIT(sta_id) & reserved_ids)
  98. continue;
  99. if (!rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
  100. lockdep_is_held(&mvm->mutex)))
  101. return sta_id;
  102. }
  103. return IWL_MVM_INVALID_STA;
  104. }
  105. /* send station add/update command to firmware */
  106. int iwl_mvm_sta_send_to_fw(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
  107. bool update, unsigned int flags)
  108. {
  109. struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
  110. struct iwl_mvm_add_sta_cmd add_sta_cmd = {
  111. .sta_id = mvm_sta->sta_id,
  112. .mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color),
  113. .add_modify = update ? 1 : 0,
  114. .station_flags_msk = cpu_to_le32(STA_FLG_FAT_EN_MSK |
  115. STA_FLG_MIMO_EN_MSK),
  116. .tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg),
  117. };
  118. int ret;
  119. u32 status;
  120. u32 agg_size = 0, mpdu_dens = 0;
  121. if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
  122. add_sta_cmd.station_type = mvm_sta->sta_type;
  123. if (!update || (flags & STA_MODIFY_QUEUES)) {
  124. memcpy(&add_sta_cmd.addr, sta->addr, ETH_ALEN);
  125. if (!iwl_mvm_has_new_tx_api(mvm)) {
  126. add_sta_cmd.tfd_queue_msk =
  127. cpu_to_le32(mvm_sta->tfd_queue_msk);
  128. if (flags & STA_MODIFY_QUEUES)
  129. add_sta_cmd.modify_mask |= STA_MODIFY_QUEUES;
  130. } else {
  131. WARN_ON(flags & STA_MODIFY_QUEUES);
  132. }
  133. }
  134. switch (sta->bandwidth) {
  135. case IEEE80211_STA_RX_BW_160:
  136. add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_160MHZ);
  137. /* fall through */
  138. case IEEE80211_STA_RX_BW_80:
  139. add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_80MHZ);
  140. /* fall through */
  141. case IEEE80211_STA_RX_BW_40:
  142. add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_40MHZ);
  143. /* fall through */
  144. case IEEE80211_STA_RX_BW_20:
  145. if (sta->ht_cap.ht_supported)
  146. add_sta_cmd.station_flags |=
  147. cpu_to_le32(STA_FLG_FAT_EN_20MHZ);
  148. break;
  149. }
  150. switch (sta->rx_nss) {
  151. case 1:
  152. add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO);
  153. break;
  154. case 2:
  155. add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO2);
  156. break;
  157. case 3 ... 8:
  158. add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO3);
  159. break;
  160. }
  161. switch (sta->smps_mode) {
  162. case IEEE80211_SMPS_AUTOMATIC:
  163. case IEEE80211_SMPS_NUM_MODES:
  164. WARN_ON(1);
  165. break;
  166. case IEEE80211_SMPS_STATIC:
  167. /* override NSS */
  168. add_sta_cmd.station_flags &= ~cpu_to_le32(STA_FLG_MIMO_EN_MSK);
  169. add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO);
  170. break;
  171. case IEEE80211_SMPS_DYNAMIC:
  172. add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_RTS_MIMO_PROT);
  173. break;
  174. case IEEE80211_SMPS_OFF:
  175. /* nothing */
  176. break;
  177. }
  178. if (sta->ht_cap.ht_supported) {
  179. add_sta_cmd.station_flags_msk |=
  180. cpu_to_le32(STA_FLG_MAX_AGG_SIZE_MSK |
  181. STA_FLG_AGG_MPDU_DENS_MSK);
  182. mpdu_dens = sta->ht_cap.ampdu_density;
  183. }
  184. if (sta->vht_cap.vht_supported) {
  185. agg_size = sta->vht_cap.cap &
  186. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
  187. agg_size >>=
  188. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
  189. } else if (sta->ht_cap.ht_supported) {
  190. agg_size = sta->ht_cap.ampdu_factor;
  191. }
  192. add_sta_cmd.station_flags |=
  193. cpu_to_le32(agg_size << STA_FLG_MAX_AGG_SIZE_SHIFT);
  194. add_sta_cmd.station_flags |=
  195. cpu_to_le32(mpdu_dens << STA_FLG_AGG_MPDU_DENS_SHIFT);
  196. if (mvm_sta->associated)
  197. add_sta_cmd.assoc_id = cpu_to_le16(sta->aid);
  198. if (sta->wme) {
  199. add_sta_cmd.modify_mask |= STA_MODIFY_UAPSD_ACS;
  200. if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
  201. add_sta_cmd.uapsd_acs |= BIT(AC_BK);
  202. if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
  203. add_sta_cmd.uapsd_acs |= BIT(AC_BE);
  204. if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
  205. add_sta_cmd.uapsd_acs |= BIT(AC_VI);
  206. if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
  207. add_sta_cmd.uapsd_acs |= BIT(AC_VO);
  208. add_sta_cmd.uapsd_acs |= add_sta_cmd.uapsd_acs << 4;
  209. add_sta_cmd.sp_length = sta->max_sp ? sta->max_sp * 2 : 128;
  210. }
  211. status = ADD_STA_SUCCESS;
  212. ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
  213. iwl_mvm_add_sta_cmd_size(mvm),
  214. &add_sta_cmd, &status);
  215. if (ret)
  216. return ret;
  217. switch (status & IWL_ADD_STA_STATUS_MASK) {
  218. case ADD_STA_SUCCESS:
  219. IWL_DEBUG_ASSOC(mvm, "ADD_STA PASSED\n");
  220. break;
  221. default:
  222. ret = -EIO;
  223. IWL_ERR(mvm, "ADD_STA failed\n");
  224. break;
  225. }
  226. return ret;
  227. }
  228. static void iwl_mvm_rx_agg_session_expired(unsigned long data)
  229. {
  230. struct iwl_mvm_baid_data __rcu **rcu_ptr = (void *)data;
  231. struct iwl_mvm_baid_data *ba_data;
  232. struct ieee80211_sta *sta;
  233. struct iwl_mvm_sta *mvm_sta;
  234. unsigned long timeout;
  235. rcu_read_lock();
  236. ba_data = rcu_dereference(*rcu_ptr);
  237. if (WARN_ON(!ba_data))
  238. goto unlock;
  239. if (!ba_data->timeout)
  240. goto unlock;
  241. timeout = ba_data->last_rx + TU_TO_JIFFIES(ba_data->timeout * 2);
  242. if (time_is_after_jiffies(timeout)) {
  243. mod_timer(&ba_data->session_timer, timeout);
  244. goto unlock;
  245. }
  246. /* Timer expired */
  247. sta = rcu_dereference(ba_data->mvm->fw_id_to_mac_id[ba_data->sta_id]);
  248. mvm_sta = iwl_mvm_sta_from_mac80211(sta);
  249. ieee80211_stop_rx_ba_session_offl(mvm_sta->vif,
  250. sta->addr, ba_data->tid);
  251. unlock:
  252. rcu_read_unlock();
  253. }
  254. static int iwl_mvm_tdls_sta_init(struct iwl_mvm *mvm,
  255. struct ieee80211_sta *sta)
  256. {
  257. unsigned long used_hw_queues;
  258. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  259. unsigned int wdg_timeout =
  260. iwl_mvm_get_wd_timeout(mvm, NULL, true, false);
  261. u32 ac;
  262. lockdep_assert_held(&mvm->mutex);
  263. used_hw_queues = iwl_mvm_get_used_hw_queues(mvm, NULL);
  264. /* Find available queues, and allocate them to the ACs */
  265. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  266. u8 queue = find_first_zero_bit(&used_hw_queues,
  267. mvm->first_agg_queue);
  268. if (queue >= mvm->first_agg_queue) {
  269. IWL_ERR(mvm, "Failed to allocate STA queue\n");
  270. return -EBUSY;
  271. }
  272. __set_bit(queue, &used_hw_queues);
  273. mvmsta->hw_queue[ac] = queue;
  274. }
  275. /* Found a place for all queues - enable them */
  276. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  277. iwl_mvm_enable_ac_txq(mvm, mvmsta->hw_queue[ac],
  278. mvmsta->hw_queue[ac],
  279. iwl_mvm_ac_to_tx_fifo[ac], 0,
  280. wdg_timeout);
  281. mvmsta->tfd_queue_msk |= BIT(mvmsta->hw_queue[ac]);
  282. }
  283. return 0;
  284. }
  285. static void iwl_mvm_tdls_sta_deinit(struct iwl_mvm *mvm,
  286. struct ieee80211_sta *sta)
  287. {
  288. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  289. unsigned long sta_msk;
  290. int i;
  291. lockdep_assert_held(&mvm->mutex);
  292. /* disable the TDLS STA-specific queues */
  293. sta_msk = mvmsta->tfd_queue_msk;
  294. for_each_set_bit(i, &sta_msk, sizeof(sta_msk) * BITS_PER_BYTE)
  295. iwl_mvm_disable_txq(mvm, i, i, IWL_MAX_TID_COUNT, 0);
  296. }
  297. /* Disable aggregations for a bitmap of TIDs for a given station */
  298. static int iwl_mvm_invalidate_sta_queue(struct iwl_mvm *mvm, int queue,
  299. unsigned long disable_agg_tids,
  300. bool remove_queue)
  301. {
  302. struct iwl_mvm_add_sta_cmd cmd = {};
  303. struct ieee80211_sta *sta;
  304. struct iwl_mvm_sta *mvmsta;
  305. u32 status;
  306. u8 sta_id;
  307. int ret;
  308. if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
  309. return -EINVAL;
  310. spin_lock_bh(&mvm->queue_info_lock);
  311. sta_id = mvm->queue_info[queue].ra_sta_id;
  312. spin_unlock_bh(&mvm->queue_info_lock);
  313. rcu_read_lock();
  314. sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
  315. if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) {
  316. rcu_read_unlock();
  317. return -EINVAL;
  318. }
  319. mvmsta = iwl_mvm_sta_from_mac80211(sta);
  320. mvmsta->tid_disable_agg |= disable_agg_tids;
  321. cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color);
  322. cmd.sta_id = mvmsta->sta_id;
  323. cmd.add_modify = STA_MODE_MODIFY;
  324. cmd.modify_mask = STA_MODIFY_QUEUES;
  325. if (disable_agg_tids)
  326. cmd.modify_mask |= STA_MODIFY_TID_DISABLE_TX;
  327. if (remove_queue)
  328. cmd.modify_mask |= STA_MODIFY_QUEUE_REMOVAL;
  329. cmd.tfd_queue_msk = cpu_to_le32(mvmsta->tfd_queue_msk);
  330. cmd.tid_disable_tx = cpu_to_le16(mvmsta->tid_disable_agg);
  331. rcu_read_unlock();
  332. /* Notify FW of queue removal from the STA queues */
  333. status = ADD_STA_SUCCESS;
  334. ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
  335. iwl_mvm_add_sta_cmd_size(mvm),
  336. &cmd, &status);
  337. return ret;
  338. }
  339. static int iwl_mvm_get_queue_agg_tids(struct iwl_mvm *mvm, int queue)
  340. {
  341. struct ieee80211_sta *sta;
  342. struct iwl_mvm_sta *mvmsta;
  343. unsigned long tid_bitmap;
  344. unsigned long agg_tids = 0;
  345. s8 sta_id;
  346. int tid;
  347. lockdep_assert_held(&mvm->mutex);
  348. if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
  349. return -EINVAL;
  350. spin_lock_bh(&mvm->queue_info_lock);
  351. sta_id = mvm->queue_info[queue].ra_sta_id;
  352. tid_bitmap = mvm->queue_info[queue].tid_bitmap;
  353. spin_unlock_bh(&mvm->queue_info_lock);
  354. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
  355. lockdep_is_held(&mvm->mutex));
  356. if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta)))
  357. return -EINVAL;
  358. mvmsta = iwl_mvm_sta_from_mac80211(sta);
  359. spin_lock_bh(&mvmsta->lock);
  360. for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) {
  361. if (mvmsta->tid_data[tid].state == IWL_AGG_ON)
  362. agg_tids |= BIT(tid);
  363. }
  364. spin_unlock_bh(&mvmsta->lock);
  365. return agg_tids;
  366. }
  367. /*
  368. * Remove a queue from a station's resources.
  369. * Note that this only marks as free. It DOESN'T delete a BA agreement, and
  370. * doesn't disable the queue
  371. */
  372. static int iwl_mvm_remove_sta_queue_marking(struct iwl_mvm *mvm, int queue)
  373. {
  374. struct ieee80211_sta *sta;
  375. struct iwl_mvm_sta *mvmsta;
  376. unsigned long tid_bitmap;
  377. unsigned long disable_agg_tids = 0;
  378. u8 sta_id;
  379. int tid;
  380. lockdep_assert_held(&mvm->mutex);
  381. if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
  382. return -EINVAL;
  383. spin_lock_bh(&mvm->queue_info_lock);
  384. sta_id = mvm->queue_info[queue].ra_sta_id;
  385. tid_bitmap = mvm->queue_info[queue].tid_bitmap;
  386. spin_unlock_bh(&mvm->queue_info_lock);
  387. rcu_read_lock();
  388. sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
  389. if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) {
  390. rcu_read_unlock();
  391. return 0;
  392. }
  393. mvmsta = iwl_mvm_sta_from_mac80211(sta);
  394. spin_lock_bh(&mvmsta->lock);
  395. /* Unmap MAC queues and TIDs from this queue */
  396. for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) {
  397. if (mvmsta->tid_data[tid].state == IWL_AGG_ON)
  398. disable_agg_tids |= BIT(tid);
  399. mvmsta->tid_data[tid].txq_id = IWL_MVM_INVALID_QUEUE;
  400. }
  401. mvmsta->tfd_queue_msk &= ~BIT(queue); /* Don't use this queue anymore */
  402. spin_unlock_bh(&mvmsta->lock);
  403. rcu_read_unlock();
  404. return disable_agg_tids;
  405. }
  406. static int iwl_mvm_free_inactive_queue(struct iwl_mvm *mvm, int queue,
  407. bool same_sta)
  408. {
  409. struct iwl_mvm_sta *mvmsta;
  410. u8 txq_curr_ac, sta_id, tid;
  411. unsigned long disable_agg_tids = 0;
  412. int ret;
  413. lockdep_assert_held(&mvm->mutex);
  414. if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
  415. return -EINVAL;
  416. spin_lock_bh(&mvm->queue_info_lock);
  417. txq_curr_ac = mvm->queue_info[queue].mac80211_ac;
  418. sta_id = mvm->queue_info[queue].ra_sta_id;
  419. tid = mvm->queue_info[queue].txq_tid;
  420. spin_unlock_bh(&mvm->queue_info_lock);
  421. mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
  422. if (WARN_ON(!mvmsta))
  423. return -EINVAL;
  424. disable_agg_tids = iwl_mvm_remove_sta_queue_marking(mvm, queue);
  425. /* Disable the queue */
  426. if (disable_agg_tids)
  427. iwl_mvm_invalidate_sta_queue(mvm, queue,
  428. disable_agg_tids, false);
  429. ret = iwl_mvm_disable_txq(mvm, queue,
  430. mvmsta->vif->hw_queue[txq_curr_ac],
  431. tid, 0);
  432. if (ret) {
  433. /* Re-mark the inactive queue as inactive */
  434. spin_lock_bh(&mvm->queue_info_lock);
  435. mvm->queue_info[queue].status = IWL_MVM_QUEUE_INACTIVE;
  436. spin_unlock_bh(&mvm->queue_info_lock);
  437. IWL_ERR(mvm,
  438. "Failed to free inactive queue %d (ret=%d)\n",
  439. queue, ret);
  440. return ret;
  441. }
  442. /* If TXQ is allocated to another STA, update removal in FW */
  443. if (!same_sta)
  444. iwl_mvm_invalidate_sta_queue(mvm, queue, 0, true);
  445. return 0;
  446. }
  447. static int iwl_mvm_get_shared_queue(struct iwl_mvm *mvm,
  448. unsigned long tfd_queue_mask, u8 ac)
  449. {
  450. int queue = 0;
  451. u8 ac_to_queue[IEEE80211_NUM_ACS];
  452. int i;
  453. lockdep_assert_held(&mvm->queue_info_lock);
  454. if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
  455. return -EINVAL;
  456. memset(&ac_to_queue, IEEE80211_INVAL_HW_QUEUE, sizeof(ac_to_queue));
  457. /* See what ACs the existing queues for this STA have */
  458. for_each_set_bit(i, &tfd_queue_mask, IWL_MVM_DQA_MAX_DATA_QUEUE) {
  459. /* Only DATA queues can be shared */
  460. if (i < IWL_MVM_DQA_MIN_DATA_QUEUE &&
  461. i != IWL_MVM_DQA_BSS_CLIENT_QUEUE)
  462. continue;
  463. /* Don't try and take queues being reconfigured */
  464. if (mvm->queue_info[queue].status ==
  465. IWL_MVM_QUEUE_RECONFIGURING)
  466. continue;
  467. ac_to_queue[mvm->queue_info[i].mac80211_ac] = i;
  468. }
  469. /*
  470. * The queue to share is chosen only from DATA queues as follows (in
  471. * descending priority):
  472. * 1. An AC_BE queue
  473. * 2. Same AC queue
  474. * 3. Highest AC queue that is lower than new AC
  475. * 4. Any existing AC (there always is at least 1 DATA queue)
  476. */
  477. /* Priority 1: An AC_BE queue */
  478. if (ac_to_queue[IEEE80211_AC_BE] != IEEE80211_INVAL_HW_QUEUE)
  479. queue = ac_to_queue[IEEE80211_AC_BE];
  480. /* Priority 2: Same AC queue */
  481. else if (ac_to_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
  482. queue = ac_to_queue[ac];
  483. /* Priority 3a: If new AC is VO and VI exists - use VI */
  484. else if (ac == IEEE80211_AC_VO &&
  485. ac_to_queue[IEEE80211_AC_VI] != IEEE80211_INVAL_HW_QUEUE)
  486. queue = ac_to_queue[IEEE80211_AC_VI];
  487. /* Priority 3b: No BE so only AC less than the new one is BK */
  488. else if (ac_to_queue[IEEE80211_AC_BK] != IEEE80211_INVAL_HW_QUEUE)
  489. queue = ac_to_queue[IEEE80211_AC_BK];
  490. /* Priority 4a: No BE nor BK - use VI if exists */
  491. else if (ac_to_queue[IEEE80211_AC_VI] != IEEE80211_INVAL_HW_QUEUE)
  492. queue = ac_to_queue[IEEE80211_AC_VI];
  493. /* Priority 4b: No BE, BK nor VI - use VO if exists */
  494. else if (ac_to_queue[IEEE80211_AC_VO] != IEEE80211_INVAL_HW_QUEUE)
  495. queue = ac_to_queue[IEEE80211_AC_VO];
  496. /* Make sure queue found (or not) is legal */
  497. if (!iwl_mvm_is_dqa_data_queue(mvm, queue) &&
  498. !iwl_mvm_is_dqa_mgmt_queue(mvm, queue) &&
  499. (queue != IWL_MVM_DQA_BSS_CLIENT_QUEUE)) {
  500. IWL_ERR(mvm, "No DATA queues available to share\n");
  501. return -ENOSPC;
  502. }
  503. /* Make sure the queue isn't in the middle of being reconfigured */
  504. if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_RECONFIGURING) {
  505. IWL_ERR(mvm,
  506. "TXQ %d is in the middle of re-config - try again\n",
  507. queue);
  508. return -EBUSY;
  509. }
  510. return queue;
  511. }
  512. /*
  513. * If a given queue has a higher AC than the TID stream that is being compared
  514. * to, the queue needs to be redirected to the lower AC. This function does that
  515. * in such a case, otherwise - if no redirection required - it does nothing,
  516. * unless the %force param is true.
  517. */
  518. int iwl_mvm_scd_queue_redirect(struct iwl_mvm *mvm, int queue, int tid,
  519. int ac, int ssn, unsigned int wdg_timeout,
  520. bool force)
  521. {
  522. struct iwl_scd_txq_cfg_cmd cmd = {
  523. .scd_queue = queue,
  524. .action = SCD_CFG_DISABLE_QUEUE,
  525. };
  526. bool shared_queue;
  527. unsigned long mq;
  528. int ret;
  529. if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
  530. return -EINVAL;
  531. /*
  532. * If the AC is lower than current one - FIFO needs to be redirected to
  533. * the lowest one of the streams in the queue. Check if this is needed
  534. * here.
  535. * Notice that the enum ieee80211_ac_numbers is "flipped", so BK is with
  536. * value 3 and VO with value 0, so to check if ac X is lower than ac Y
  537. * we need to check if the numerical value of X is LARGER than of Y.
  538. */
  539. spin_lock_bh(&mvm->queue_info_lock);
  540. if (ac <= mvm->queue_info[queue].mac80211_ac && !force) {
  541. spin_unlock_bh(&mvm->queue_info_lock);
  542. IWL_DEBUG_TX_QUEUES(mvm,
  543. "No redirection needed on TXQ #%d\n",
  544. queue);
  545. return 0;
  546. }
  547. cmd.sta_id = mvm->queue_info[queue].ra_sta_id;
  548. cmd.tx_fifo = iwl_mvm_ac_to_tx_fifo[mvm->queue_info[queue].mac80211_ac];
  549. cmd.tid = mvm->queue_info[queue].txq_tid;
  550. mq = mvm->hw_queue_to_mac80211[queue];
  551. shared_queue = (mvm->queue_info[queue].hw_queue_refcount > 1);
  552. spin_unlock_bh(&mvm->queue_info_lock);
  553. IWL_DEBUG_TX_QUEUES(mvm, "Redirecting TXQ #%d to FIFO #%d\n",
  554. queue, iwl_mvm_ac_to_tx_fifo[ac]);
  555. /* Stop MAC queues and wait for this queue to empty */
  556. iwl_mvm_stop_mac_queues(mvm, mq);
  557. ret = iwl_trans_wait_tx_queues_empty(mvm->trans, BIT(queue));
  558. if (ret) {
  559. IWL_ERR(mvm, "Error draining queue %d before reconfig\n",
  560. queue);
  561. ret = -EIO;
  562. goto out;
  563. }
  564. /* Before redirecting the queue we need to de-activate it */
  565. iwl_trans_txq_disable(mvm->trans, queue, false);
  566. ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), &cmd);
  567. if (ret)
  568. IWL_ERR(mvm, "Failed SCD disable TXQ %d (ret=%d)\n", queue,
  569. ret);
  570. /* Make sure the SCD wrptr is correctly set before reconfiguring */
  571. iwl_trans_txq_enable_cfg(mvm->trans, queue, ssn, NULL, wdg_timeout);
  572. /* Update the TID "owner" of the queue */
  573. spin_lock_bh(&mvm->queue_info_lock);
  574. mvm->queue_info[queue].txq_tid = tid;
  575. spin_unlock_bh(&mvm->queue_info_lock);
  576. /* TODO: Work-around SCD bug when moving back by multiples of 0x40 */
  577. /* Redirect to lower AC */
  578. iwl_mvm_reconfig_scd(mvm, queue, iwl_mvm_ac_to_tx_fifo[ac],
  579. cmd.sta_id, tid, LINK_QUAL_AGG_FRAME_LIMIT_DEF,
  580. ssn);
  581. /* Update AC marking of the queue */
  582. spin_lock_bh(&mvm->queue_info_lock);
  583. mvm->queue_info[queue].mac80211_ac = ac;
  584. spin_unlock_bh(&mvm->queue_info_lock);
  585. /*
  586. * Mark queue as shared in transport if shared
  587. * Note this has to be done after queue enablement because enablement
  588. * can also set this value, and there is no indication there to shared
  589. * queues
  590. */
  591. if (shared_queue)
  592. iwl_trans_txq_set_shared_mode(mvm->trans, queue, true);
  593. out:
  594. /* Continue using the MAC queues */
  595. iwl_mvm_start_mac_queues(mvm, mq);
  596. return ret;
  597. }
  598. static int iwl_mvm_sta_alloc_queue_tvqm(struct iwl_mvm *mvm,
  599. struct ieee80211_sta *sta, u8 ac,
  600. int tid)
  601. {
  602. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  603. unsigned int wdg_timeout =
  604. iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false);
  605. u8 mac_queue = mvmsta->vif->hw_queue[ac];
  606. int queue = -1;
  607. lockdep_assert_held(&mvm->mutex);
  608. IWL_DEBUG_TX_QUEUES(mvm,
  609. "Allocating queue for sta %d on tid %d\n",
  610. mvmsta->sta_id, tid);
  611. queue = iwl_mvm_tvqm_enable_txq(mvm, mac_queue, mvmsta->sta_id, tid,
  612. wdg_timeout);
  613. if (queue < 0)
  614. return queue;
  615. IWL_DEBUG_TX_QUEUES(mvm, "Allocated queue is %d\n", queue);
  616. spin_lock_bh(&mvmsta->lock);
  617. mvmsta->tid_data[tid].txq_id = queue;
  618. mvmsta->tid_data[tid].is_tid_active = true;
  619. mvmsta->tfd_queue_msk |= BIT(queue);
  620. spin_unlock_bh(&mvmsta->lock);
  621. return 0;
  622. }
  623. static int iwl_mvm_sta_alloc_queue(struct iwl_mvm *mvm,
  624. struct ieee80211_sta *sta, u8 ac, int tid,
  625. struct ieee80211_hdr *hdr)
  626. {
  627. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  628. struct iwl_trans_txq_scd_cfg cfg = {
  629. .fifo = iwl_mvm_ac_to_tx_fifo[ac],
  630. .sta_id = mvmsta->sta_id,
  631. .tid = tid,
  632. .frame_limit = IWL_FRAME_LIMIT,
  633. };
  634. unsigned int wdg_timeout =
  635. iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false);
  636. u8 mac_queue = mvmsta->vif->hw_queue[ac];
  637. int queue = -1;
  638. bool using_inactive_queue = false, same_sta = false;
  639. unsigned long disable_agg_tids = 0;
  640. enum iwl_mvm_agg_state queue_state;
  641. bool shared_queue = false;
  642. int ssn;
  643. unsigned long tfd_queue_mask;
  644. int ret;
  645. lockdep_assert_held(&mvm->mutex);
  646. if (iwl_mvm_has_new_tx_api(mvm))
  647. return iwl_mvm_sta_alloc_queue_tvqm(mvm, sta, ac, tid);
  648. spin_lock_bh(&mvmsta->lock);
  649. tfd_queue_mask = mvmsta->tfd_queue_msk;
  650. spin_unlock_bh(&mvmsta->lock);
  651. spin_lock_bh(&mvm->queue_info_lock);
  652. /*
  653. * Non-QoS, QoS NDP and MGMT frames should go to a MGMT queue, if one
  654. * exists
  655. */
  656. if (!ieee80211_is_data_qos(hdr->frame_control) ||
  657. ieee80211_is_qos_nullfunc(hdr->frame_control)) {
  658. queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
  659. IWL_MVM_DQA_MIN_MGMT_QUEUE,
  660. IWL_MVM_DQA_MAX_MGMT_QUEUE);
  661. if (queue >= IWL_MVM_DQA_MIN_MGMT_QUEUE)
  662. IWL_DEBUG_TX_QUEUES(mvm, "Found free MGMT queue #%d\n",
  663. queue);
  664. /* If no such queue is found, we'll use a DATA queue instead */
  665. }
  666. if ((queue < 0 && mvmsta->reserved_queue != IEEE80211_INVAL_HW_QUEUE) &&
  667. (mvm->queue_info[mvmsta->reserved_queue].status ==
  668. IWL_MVM_QUEUE_RESERVED ||
  669. mvm->queue_info[mvmsta->reserved_queue].status ==
  670. IWL_MVM_QUEUE_INACTIVE)) {
  671. queue = mvmsta->reserved_queue;
  672. mvm->queue_info[queue].reserved = true;
  673. IWL_DEBUG_TX_QUEUES(mvm, "Using reserved queue #%d\n", queue);
  674. }
  675. if (queue < 0)
  676. queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
  677. IWL_MVM_DQA_MIN_DATA_QUEUE,
  678. IWL_MVM_DQA_MAX_DATA_QUEUE);
  679. /*
  680. * Check if this queue is already allocated but inactive.
  681. * In such a case, we'll need to first free this queue before enabling
  682. * it again, so we'll mark it as reserved to make sure no new traffic
  683. * arrives on it
  684. */
  685. if (queue > 0 &&
  686. mvm->queue_info[queue].status == IWL_MVM_QUEUE_INACTIVE) {
  687. mvm->queue_info[queue].status = IWL_MVM_QUEUE_RESERVED;
  688. using_inactive_queue = true;
  689. same_sta = mvm->queue_info[queue].ra_sta_id == mvmsta->sta_id;
  690. IWL_DEBUG_TX_QUEUES(mvm,
  691. "Re-assigning TXQ %d: sta_id=%d, tid=%d\n",
  692. queue, mvmsta->sta_id, tid);
  693. }
  694. /* No free queue - we'll have to share */
  695. if (queue <= 0) {
  696. queue = iwl_mvm_get_shared_queue(mvm, tfd_queue_mask, ac);
  697. if (queue > 0) {
  698. shared_queue = true;
  699. mvm->queue_info[queue].status = IWL_MVM_QUEUE_SHARED;
  700. }
  701. }
  702. /*
  703. * Mark TXQ as ready, even though it hasn't been fully configured yet,
  704. * to make sure no one else takes it.
  705. * This will allow avoiding re-acquiring the lock at the end of the
  706. * configuration. On error we'll mark it back as free.
  707. */
  708. if ((queue > 0) && !shared_queue)
  709. mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY;
  710. spin_unlock_bh(&mvm->queue_info_lock);
  711. /* This shouldn't happen - out of queues */
  712. if (WARN_ON(queue <= 0)) {
  713. IWL_ERR(mvm, "No available queues for tid %d on sta_id %d\n",
  714. tid, cfg.sta_id);
  715. return queue;
  716. }
  717. /*
  718. * Actual en/disablement of aggregations is through the ADD_STA HCMD,
  719. * but for configuring the SCD to send A-MPDUs we need to mark the queue
  720. * as aggregatable.
  721. * Mark all DATA queues as allowing to be aggregated at some point
  722. */
  723. cfg.aggregate = (queue >= IWL_MVM_DQA_MIN_DATA_QUEUE ||
  724. queue == IWL_MVM_DQA_BSS_CLIENT_QUEUE);
  725. /*
  726. * If this queue was previously inactive (idle) - we need to free it
  727. * first
  728. */
  729. if (using_inactive_queue) {
  730. ret = iwl_mvm_free_inactive_queue(mvm, queue, same_sta);
  731. if (ret)
  732. return ret;
  733. }
  734. IWL_DEBUG_TX_QUEUES(mvm,
  735. "Allocating %squeue #%d to sta %d on tid %d\n",
  736. shared_queue ? "shared " : "", queue,
  737. mvmsta->sta_id, tid);
  738. if (shared_queue) {
  739. /* Disable any open aggs on this queue */
  740. disable_agg_tids = iwl_mvm_get_queue_agg_tids(mvm, queue);
  741. if (disable_agg_tids) {
  742. IWL_DEBUG_TX_QUEUES(mvm, "Disabling aggs on queue %d\n",
  743. queue);
  744. iwl_mvm_invalidate_sta_queue(mvm, queue,
  745. disable_agg_tids, false);
  746. }
  747. }
  748. ssn = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl));
  749. iwl_mvm_enable_txq(mvm, queue, mac_queue, ssn, &cfg,
  750. wdg_timeout);
  751. /*
  752. * Mark queue as shared in transport if shared
  753. * Note this has to be done after queue enablement because enablement
  754. * can also set this value, and there is no indication there to shared
  755. * queues
  756. */
  757. if (shared_queue)
  758. iwl_trans_txq_set_shared_mode(mvm->trans, queue, true);
  759. spin_lock_bh(&mvmsta->lock);
  760. mvmsta->tid_data[tid].txq_id = queue;
  761. mvmsta->tid_data[tid].is_tid_active = true;
  762. mvmsta->tfd_queue_msk |= BIT(queue);
  763. queue_state = mvmsta->tid_data[tid].state;
  764. if (mvmsta->reserved_queue == queue)
  765. mvmsta->reserved_queue = IEEE80211_INVAL_HW_QUEUE;
  766. spin_unlock_bh(&mvmsta->lock);
  767. if (!shared_queue) {
  768. ret = iwl_mvm_sta_send_to_fw(mvm, sta, true, STA_MODIFY_QUEUES);
  769. if (ret)
  770. goto out_err;
  771. /* If we need to re-enable aggregations... */
  772. if (queue_state == IWL_AGG_ON) {
  773. ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true);
  774. if (ret)
  775. goto out_err;
  776. }
  777. } else {
  778. /* Redirect queue, if needed */
  779. ret = iwl_mvm_scd_queue_redirect(mvm, queue, tid, ac, ssn,
  780. wdg_timeout, false);
  781. if (ret)
  782. goto out_err;
  783. }
  784. return 0;
  785. out_err:
  786. iwl_mvm_disable_txq(mvm, queue, mac_queue, tid, 0);
  787. return ret;
  788. }
  789. static void iwl_mvm_change_queue_owner(struct iwl_mvm *mvm, int queue)
  790. {
  791. struct iwl_scd_txq_cfg_cmd cmd = {
  792. .scd_queue = queue,
  793. .action = SCD_CFG_UPDATE_QUEUE_TID,
  794. };
  795. int tid;
  796. unsigned long tid_bitmap;
  797. int ret;
  798. lockdep_assert_held(&mvm->mutex);
  799. if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
  800. return;
  801. spin_lock_bh(&mvm->queue_info_lock);
  802. tid_bitmap = mvm->queue_info[queue].tid_bitmap;
  803. spin_unlock_bh(&mvm->queue_info_lock);
  804. if (WARN(!tid_bitmap, "TXQ %d has no tids assigned to it\n", queue))
  805. return;
  806. /* Find any TID for queue */
  807. tid = find_first_bit(&tid_bitmap, IWL_MAX_TID_COUNT + 1);
  808. cmd.tid = tid;
  809. cmd.tx_fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]];
  810. ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), &cmd);
  811. if (ret) {
  812. IWL_ERR(mvm, "Failed to update owner of TXQ %d (ret=%d)\n",
  813. queue, ret);
  814. return;
  815. }
  816. spin_lock_bh(&mvm->queue_info_lock);
  817. mvm->queue_info[queue].txq_tid = tid;
  818. spin_unlock_bh(&mvm->queue_info_lock);
  819. IWL_DEBUG_TX_QUEUES(mvm, "Changed TXQ %d ownership to tid %d\n",
  820. queue, tid);
  821. }
  822. static void iwl_mvm_unshare_queue(struct iwl_mvm *mvm, int queue)
  823. {
  824. struct ieee80211_sta *sta;
  825. struct iwl_mvm_sta *mvmsta;
  826. s8 sta_id;
  827. int tid = -1;
  828. unsigned long tid_bitmap;
  829. unsigned int wdg_timeout;
  830. int ssn;
  831. int ret = true;
  832. /* queue sharing is disabled on new TX path */
  833. if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
  834. return;
  835. lockdep_assert_held(&mvm->mutex);
  836. spin_lock_bh(&mvm->queue_info_lock);
  837. sta_id = mvm->queue_info[queue].ra_sta_id;
  838. tid_bitmap = mvm->queue_info[queue].tid_bitmap;
  839. spin_unlock_bh(&mvm->queue_info_lock);
  840. /* Find TID for queue, and make sure it is the only one on the queue */
  841. tid = find_first_bit(&tid_bitmap, IWL_MAX_TID_COUNT + 1);
  842. if (tid_bitmap != BIT(tid)) {
  843. IWL_ERR(mvm, "Failed to unshare q %d, active tids=0x%lx\n",
  844. queue, tid_bitmap);
  845. return;
  846. }
  847. IWL_DEBUG_TX_QUEUES(mvm, "Unsharing TXQ %d, keeping tid %d\n", queue,
  848. tid);
  849. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
  850. lockdep_is_held(&mvm->mutex));
  851. if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta)))
  852. return;
  853. mvmsta = iwl_mvm_sta_from_mac80211(sta);
  854. wdg_timeout = iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false);
  855. ssn = IEEE80211_SEQ_TO_SN(mvmsta->tid_data[tid].seq_number);
  856. ret = iwl_mvm_scd_queue_redirect(mvm, queue, tid,
  857. tid_to_mac80211_ac[tid], ssn,
  858. wdg_timeout, true);
  859. if (ret) {
  860. IWL_ERR(mvm, "Failed to redirect TXQ %d\n", queue);
  861. return;
  862. }
  863. /* If aggs should be turned back on - do it */
  864. if (mvmsta->tid_data[tid].state == IWL_AGG_ON) {
  865. struct iwl_mvm_add_sta_cmd cmd = {0};
  866. mvmsta->tid_disable_agg &= ~BIT(tid);
  867. cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color);
  868. cmd.sta_id = mvmsta->sta_id;
  869. cmd.add_modify = STA_MODE_MODIFY;
  870. cmd.modify_mask = STA_MODIFY_TID_DISABLE_TX;
  871. cmd.tfd_queue_msk = cpu_to_le32(mvmsta->tfd_queue_msk);
  872. cmd.tid_disable_tx = cpu_to_le16(mvmsta->tid_disable_agg);
  873. ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC,
  874. iwl_mvm_add_sta_cmd_size(mvm), &cmd);
  875. if (!ret) {
  876. IWL_DEBUG_TX_QUEUES(mvm,
  877. "TXQ #%d is now aggregated again\n",
  878. queue);
  879. /* Mark queue intenally as aggregating again */
  880. iwl_trans_txq_set_shared_mode(mvm->trans, queue, false);
  881. }
  882. }
  883. spin_lock_bh(&mvm->queue_info_lock);
  884. mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY;
  885. spin_unlock_bh(&mvm->queue_info_lock);
  886. }
  887. static inline u8 iwl_mvm_tid_to_ac_queue(int tid)
  888. {
  889. if (tid == IWL_MAX_TID_COUNT)
  890. return IEEE80211_AC_VO; /* MGMT */
  891. return tid_to_mac80211_ac[tid];
  892. }
  893. static void iwl_mvm_tx_deferred_stream(struct iwl_mvm *mvm,
  894. struct ieee80211_sta *sta, int tid)
  895. {
  896. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  897. struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
  898. struct sk_buff *skb;
  899. struct ieee80211_hdr *hdr;
  900. struct sk_buff_head deferred_tx;
  901. u8 mac_queue;
  902. bool no_queue = false; /* Marks if there is a problem with the queue */
  903. u8 ac;
  904. lockdep_assert_held(&mvm->mutex);
  905. skb = skb_peek(&tid_data->deferred_tx_frames);
  906. if (!skb)
  907. return;
  908. hdr = (void *)skb->data;
  909. ac = iwl_mvm_tid_to_ac_queue(tid);
  910. mac_queue = IEEE80211_SKB_CB(skb)->hw_queue;
  911. if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE &&
  912. iwl_mvm_sta_alloc_queue(mvm, sta, ac, tid, hdr)) {
  913. IWL_ERR(mvm,
  914. "Can't alloc TXQ for sta %d tid %d - dropping frame\n",
  915. mvmsta->sta_id, tid);
  916. /*
  917. * Mark queue as problematic so later the deferred traffic is
  918. * freed, as we can do nothing with it
  919. */
  920. no_queue = true;
  921. }
  922. __skb_queue_head_init(&deferred_tx);
  923. /* Disable bottom-halves when entering TX path */
  924. local_bh_disable();
  925. spin_lock(&mvmsta->lock);
  926. skb_queue_splice_init(&tid_data->deferred_tx_frames, &deferred_tx);
  927. mvmsta->deferred_traffic_tid_map &= ~BIT(tid);
  928. spin_unlock(&mvmsta->lock);
  929. while ((skb = __skb_dequeue(&deferred_tx)))
  930. if (no_queue || iwl_mvm_tx_skb(mvm, skb, sta))
  931. ieee80211_free_txskb(mvm->hw, skb);
  932. local_bh_enable();
  933. /* Wake queue */
  934. iwl_mvm_start_mac_queues(mvm, BIT(mac_queue));
  935. }
  936. void iwl_mvm_add_new_dqa_stream_wk(struct work_struct *wk)
  937. {
  938. struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm,
  939. add_stream_wk);
  940. struct ieee80211_sta *sta;
  941. struct iwl_mvm_sta *mvmsta;
  942. unsigned long deferred_tid_traffic;
  943. int queue, sta_id, tid;
  944. /* Check inactivity of queues */
  945. iwl_mvm_inactivity_check(mvm);
  946. mutex_lock(&mvm->mutex);
  947. /* No queue reconfiguration in TVQM mode */
  948. if (iwl_mvm_has_new_tx_api(mvm))
  949. goto alloc_queues;
  950. /* Reconfigure queues requiring reconfiguation */
  951. for (queue = 0; queue < ARRAY_SIZE(mvm->queue_info); queue++) {
  952. bool reconfig;
  953. bool change_owner;
  954. spin_lock_bh(&mvm->queue_info_lock);
  955. reconfig = (mvm->queue_info[queue].status ==
  956. IWL_MVM_QUEUE_RECONFIGURING);
  957. /*
  958. * We need to take into account a situation in which a TXQ was
  959. * allocated to TID x, and then turned shared by adding TIDs y
  960. * and z. If TID x becomes inactive and is removed from the TXQ,
  961. * ownership must be given to one of the remaining TIDs.
  962. * This is mainly because if TID x continues - a new queue can't
  963. * be allocated for it as long as it is an owner of another TXQ.
  964. */
  965. change_owner = !(mvm->queue_info[queue].tid_bitmap &
  966. BIT(mvm->queue_info[queue].txq_tid)) &&
  967. (mvm->queue_info[queue].status ==
  968. IWL_MVM_QUEUE_SHARED);
  969. spin_unlock_bh(&mvm->queue_info_lock);
  970. if (reconfig)
  971. iwl_mvm_unshare_queue(mvm, queue);
  972. else if (change_owner)
  973. iwl_mvm_change_queue_owner(mvm, queue);
  974. }
  975. alloc_queues:
  976. /* Go over all stations with deferred traffic */
  977. for_each_set_bit(sta_id, mvm->sta_deferred_frames,
  978. IWL_MVM_STATION_COUNT) {
  979. clear_bit(sta_id, mvm->sta_deferred_frames);
  980. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
  981. lockdep_is_held(&mvm->mutex));
  982. if (IS_ERR_OR_NULL(sta))
  983. continue;
  984. mvmsta = iwl_mvm_sta_from_mac80211(sta);
  985. deferred_tid_traffic = mvmsta->deferred_traffic_tid_map;
  986. for_each_set_bit(tid, &deferred_tid_traffic,
  987. IWL_MAX_TID_COUNT + 1)
  988. iwl_mvm_tx_deferred_stream(mvm, sta, tid);
  989. }
  990. mutex_unlock(&mvm->mutex);
  991. }
  992. static int iwl_mvm_reserve_sta_stream(struct iwl_mvm *mvm,
  993. struct ieee80211_sta *sta,
  994. enum nl80211_iftype vif_type)
  995. {
  996. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  997. int queue;
  998. bool using_inactive_queue = false, same_sta = false;
  999. /* queue reserving is disabled on new TX path */
  1000. if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
  1001. return 0;
  1002. /*
  1003. * Check for inactive queues, so we don't reach a situation where we
  1004. * can't add a STA due to a shortage in queues that doesn't really exist
  1005. */
  1006. iwl_mvm_inactivity_check(mvm);
  1007. spin_lock_bh(&mvm->queue_info_lock);
  1008. /* Make sure we have free resources for this STA */
  1009. if (vif_type == NL80211_IFTYPE_STATION && !sta->tdls &&
  1010. !mvm->queue_info[IWL_MVM_DQA_BSS_CLIENT_QUEUE].hw_queue_refcount &&
  1011. (mvm->queue_info[IWL_MVM_DQA_BSS_CLIENT_QUEUE].status ==
  1012. IWL_MVM_QUEUE_FREE))
  1013. queue = IWL_MVM_DQA_BSS_CLIENT_QUEUE;
  1014. else
  1015. queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
  1016. IWL_MVM_DQA_MIN_DATA_QUEUE,
  1017. IWL_MVM_DQA_MAX_DATA_QUEUE);
  1018. if (queue < 0) {
  1019. spin_unlock_bh(&mvm->queue_info_lock);
  1020. IWL_ERR(mvm, "No available queues for new station\n");
  1021. return -ENOSPC;
  1022. } else if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_INACTIVE) {
  1023. /*
  1024. * If this queue is already allocated but inactive we'll need to
  1025. * first free this queue before enabling it again, we'll mark
  1026. * it as reserved to make sure no new traffic arrives on it
  1027. */
  1028. using_inactive_queue = true;
  1029. same_sta = mvm->queue_info[queue].ra_sta_id == mvmsta->sta_id;
  1030. }
  1031. mvm->queue_info[queue].status = IWL_MVM_QUEUE_RESERVED;
  1032. spin_unlock_bh(&mvm->queue_info_lock);
  1033. mvmsta->reserved_queue = queue;
  1034. if (using_inactive_queue)
  1035. iwl_mvm_free_inactive_queue(mvm, queue, same_sta);
  1036. IWL_DEBUG_TX_QUEUES(mvm, "Reserving data queue #%d for sta_id %d\n",
  1037. queue, mvmsta->sta_id);
  1038. return 0;
  1039. }
  1040. /*
  1041. * In DQA mode, after a HW restart the queues should be allocated as before, in
  1042. * order to avoid race conditions when there are shared queues. This function
  1043. * does the re-mapping and queue allocation.
  1044. *
  1045. * Note that re-enabling aggregations isn't done in this function.
  1046. */
  1047. static void iwl_mvm_realloc_queues_after_restart(struct iwl_mvm *mvm,
  1048. struct iwl_mvm_sta *mvm_sta)
  1049. {
  1050. unsigned int wdg_timeout =
  1051. iwl_mvm_get_wd_timeout(mvm, mvm_sta->vif, false, false);
  1052. int i;
  1053. struct iwl_trans_txq_scd_cfg cfg = {
  1054. .sta_id = mvm_sta->sta_id,
  1055. .frame_limit = IWL_FRAME_LIMIT,
  1056. };
  1057. /* Make sure reserved queue is still marked as such (if allocated) */
  1058. if (mvm_sta->reserved_queue != IEEE80211_INVAL_HW_QUEUE)
  1059. mvm->queue_info[mvm_sta->reserved_queue].status =
  1060. IWL_MVM_QUEUE_RESERVED;
  1061. for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
  1062. struct iwl_mvm_tid_data *tid_data = &mvm_sta->tid_data[i];
  1063. int txq_id = tid_data->txq_id;
  1064. int ac;
  1065. u8 mac_queue;
  1066. if (txq_id == IWL_MVM_INVALID_QUEUE)
  1067. continue;
  1068. skb_queue_head_init(&tid_data->deferred_tx_frames);
  1069. ac = tid_to_mac80211_ac[i];
  1070. mac_queue = mvm_sta->vif->hw_queue[ac];
  1071. if (iwl_mvm_has_new_tx_api(mvm)) {
  1072. IWL_DEBUG_TX_QUEUES(mvm,
  1073. "Re-mapping sta %d tid %d\n",
  1074. mvm_sta->sta_id, i);
  1075. txq_id = iwl_mvm_tvqm_enable_txq(mvm, mac_queue,
  1076. mvm_sta->sta_id,
  1077. i, wdg_timeout);
  1078. tid_data->txq_id = txq_id;
  1079. } else {
  1080. u16 seq = IEEE80211_SEQ_TO_SN(tid_data->seq_number);
  1081. cfg.tid = i;
  1082. cfg.fifo = iwl_mvm_ac_to_tx_fifo[ac];
  1083. cfg.aggregate = (txq_id >= IWL_MVM_DQA_MIN_DATA_QUEUE ||
  1084. txq_id ==
  1085. IWL_MVM_DQA_BSS_CLIENT_QUEUE);
  1086. IWL_DEBUG_TX_QUEUES(mvm,
  1087. "Re-mapping sta %d tid %d to queue %d\n",
  1088. mvm_sta->sta_id, i, txq_id);
  1089. iwl_mvm_enable_txq(mvm, txq_id, mac_queue, seq, &cfg,
  1090. wdg_timeout);
  1091. mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_READY;
  1092. }
  1093. }
  1094. atomic_set(&mvm->pending_frames[mvm_sta->sta_id], 0);
  1095. }
  1096. int iwl_mvm_add_sta(struct iwl_mvm *mvm,
  1097. struct ieee80211_vif *vif,
  1098. struct ieee80211_sta *sta)
  1099. {
  1100. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1101. struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
  1102. struct iwl_mvm_rxq_dup_data *dup_data;
  1103. int i, ret, sta_id;
  1104. lockdep_assert_held(&mvm->mutex);
  1105. if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
  1106. sta_id = iwl_mvm_find_free_sta_id(mvm,
  1107. ieee80211_vif_type_p2p(vif));
  1108. else
  1109. sta_id = mvm_sta->sta_id;
  1110. if (sta_id == IWL_MVM_INVALID_STA)
  1111. return -ENOSPC;
  1112. spin_lock_init(&mvm_sta->lock);
  1113. /* In DQA mode, if this is a HW restart, re-alloc existing queues */
  1114. if (iwl_mvm_is_dqa_supported(mvm) &&
  1115. test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
  1116. iwl_mvm_realloc_queues_after_restart(mvm, mvm_sta);
  1117. goto update_fw;
  1118. }
  1119. mvm_sta->sta_id = sta_id;
  1120. mvm_sta->mac_id_n_color = FW_CMD_ID_AND_COLOR(mvmvif->id,
  1121. mvmvif->color);
  1122. mvm_sta->vif = vif;
  1123. mvm_sta->max_agg_bufsize = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
  1124. mvm_sta->tx_protection = 0;
  1125. mvm_sta->tt_tx_protection = false;
  1126. mvm_sta->sta_type = sta->tdls ? IWL_STA_TDLS_LINK : IWL_STA_LINK;
  1127. /* HW restart, don't assume the memory has been zeroed */
  1128. atomic_set(&mvm->pending_frames[sta_id], 0);
  1129. mvm_sta->tid_disable_agg = 0xffff; /* No aggs at first */
  1130. mvm_sta->tfd_queue_msk = 0;
  1131. /*
  1132. * Allocate new queues for a TDLS station, unless we're in DQA mode,
  1133. * and then they'll be allocated dynamically
  1134. */
  1135. if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls) {
  1136. ret = iwl_mvm_tdls_sta_init(mvm, sta);
  1137. if (ret)
  1138. return ret;
  1139. } else if (!iwl_mvm_is_dqa_supported(mvm)) {
  1140. for (i = 0; i < IEEE80211_NUM_ACS; i++)
  1141. if (vif->hw_queue[i] != IEEE80211_INVAL_HW_QUEUE)
  1142. mvm_sta->tfd_queue_msk |= BIT(vif->hw_queue[i]);
  1143. }
  1144. /* for HW restart - reset everything but the sequence number */
  1145. for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
  1146. u16 seq = mvm_sta->tid_data[i].seq_number;
  1147. memset(&mvm_sta->tid_data[i], 0, sizeof(mvm_sta->tid_data[i]));
  1148. mvm_sta->tid_data[i].seq_number = seq;
  1149. if (!iwl_mvm_is_dqa_supported(mvm))
  1150. continue;
  1151. /*
  1152. * Mark all queues for this STA as unallocated and defer TX
  1153. * frames until the queue is allocated
  1154. */
  1155. mvm_sta->tid_data[i].txq_id = IWL_MVM_INVALID_QUEUE;
  1156. skb_queue_head_init(&mvm_sta->tid_data[i].deferred_tx_frames);
  1157. }
  1158. mvm_sta->deferred_traffic_tid_map = 0;
  1159. mvm_sta->agg_tids = 0;
  1160. if (iwl_mvm_has_new_rx_api(mvm) &&
  1161. !test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
  1162. dup_data = kcalloc(mvm->trans->num_rx_queues,
  1163. sizeof(*dup_data),
  1164. GFP_KERNEL);
  1165. if (!dup_data)
  1166. return -ENOMEM;
  1167. mvm_sta->dup_data = dup_data;
  1168. }
  1169. if (iwl_mvm_is_dqa_supported(mvm) && !iwl_mvm_has_new_tx_api(mvm)) {
  1170. ret = iwl_mvm_reserve_sta_stream(mvm, sta,
  1171. ieee80211_vif_type_p2p(vif));
  1172. if (ret)
  1173. goto err;
  1174. }
  1175. update_fw:
  1176. ret = iwl_mvm_sta_send_to_fw(mvm, sta, false, 0);
  1177. if (ret)
  1178. goto err;
  1179. if (vif->type == NL80211_IFTYPE_STATION) {
  1180. if (!sta->tdls) {
  1181. WARN_ON(mvmvif->ap_sta_id != IWL_MVM_INVALID_STA);
  1182. mvmvif->ap_sta_id = sta_id;
  1183. } else {
  1184. WARN_ON(mvmvif->ap_sta_id == IWL_MVM_INVALID_STA);
  1185. }
  1186. }
  1187. rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id], sta);
  1188. return 0;
  1189. err:
  1190. if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls)
  1191. iwl_mvm_tdls_sta_deinit(mvm, sta);
  1192. return ret;
  1193. }
  1194. int iwl_mvm_drain_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta,
  1195. bool drain)
  1196. {
  1197. struct iwl_mvm_add_sta_cmd cmd = {};
  1198. int ret;
  1199. u32 status;
  1200. lockdep_assert_held(&mvm->mutex);
  1201. cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color);
  1202. cmd.sta_id = mvmsta->sta_id;
  1203. cmd.add_modify = STA_MODE_MODIFY;
  1204. cmd.station_flags = drain ? cpu_to_le32(STA_FLG_DRAIN_FLOW) : 0;
  1205. cmd.station_flags_msk = cpu_to_le32(STA_FLG_DRAIN_FLOW);
  1206. status = ADD_STA_SUCCESS;
  1207. ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
  1208. iwl_mvm_add_sta_cmd_size(mvm),
  1209. &cmd, &status);
  1210. if (ret)
  1211. return ret;
  1212. switch (status & IWL_ADD_STA_STATUS_MASK) {
  1213. case ADD_STA_SUCCESS:
  1214. IWL_DEBUG_INFO(mvm, "Frames for staid %d will drained in fw\n",
  1215. mvmsta->sta_id);
  1216. break;
  1217. default:
  1218. ret = -EIO;
  1219. IWL_ERR(mvm, "Couldn't drain frames for staid %d\n",
  1220. mvmsta->sta_id);
  1221. break;
  1222. }
  1223. return ret;
  1224. }
  1225. /*
  1226. * Remove a station from the FW table. Before sending the command to remove
  1227. * the station validate that the station is indeed known to the driver (sanity
  1228. * only).
  1229. */
  1230. static int iwl_mvm_rm_sta_common(struct iwl_mvm *mvm, u8 sta_id)
  1231. {
  1232. struct ieee80211_sta *sta;
  1233. struct iwl_mvm_rm_sta_cmd rm_sta_cmd = {
  1234. .sta_id = sta_id,
  1235. };
  1236. int ret;
  1237. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
  1238. lockdep_is_held(&mvm->mutex));
  1239. /* Note: internal stations are marked as error values */
  1240. if (!sta) {
  1241. IWL_ERR(mvm, "Invalid station id\n");
  1242. return -EINVAL;
  1243. }
  1244. ret = iwl_mvm_send_cmd_pdu(mvm, REMOVE_STA, 0,
  1245. sizeof(rm_sta_cmd), &rm_sta_cmd);
  1246. if (ret) {
  1247. IWL_ERR(mvm, "Failed to remove station. Id=%d\n", sta_id);
  1248. return ret;
  1249. }
  1250. return 0;
  1251. }
  1252. void iwl_mvm_sta_drained_wk(struct work_struct *wk)
  1253. {
  1254. struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, sta_drained_wk);
  1255. u8 sta_id;
  1256. /*
  1257. * The mutex is needed because of the SYNC cmd, but not only: if the
  1258. * work would run concurrently with iwl_mvm_rm_sta, it would run before
  1259. * iwl_mvm_rm_sta sets the station as busy, and exit. Then
  1260. * iwl_mvm_rm_sta would set the station as busy, and nobody will clean
  1261. * that later.
  1262. */
  1263. mutex_lock(&mvm->mutex);
  1264. for_each_set_bit(sta_id, mvm->sta_drained, IWL_MVM_STATION_COUNT) {
  1265. int ret;
  1266. struct ieee80211_sta *sta =
  1267. rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
  1268. lockdep_is_held(&mvm->mutex));
  1269. /*
  1270. * This station is in use or RCU-removed; the latter happens in
  1271. * managed mode, where mac80211 removes the station before we
  1272. * can remove it from firmware (we can only do that after the
  1273. * MAC is marked unassociated), and possibly while the deauth
  1274. * frame to disconnect from the AP is still queued. Then, the
  1275. * station pointer is -ENOENT when the last skb is reclaimed.
  1276. */
  1277. if (!IS_ERR(sta) || PTR_ERR(sta) == -ENOENT)
  1278. continue;
  1279. if (PTR_ERR(sta) == -EINVAL) {
  1280. IWL_ERR(mvm, "Drained sta %d, but it is internal?\n",
  1281. sta_id);
  1282. continue;
  1283. }
  1284. if (!sta) {
  1285. IWL_ERR(mvm, "Drained sta %d, but it was NULL?\n",
  1286. sta_id);
  1287. continue;
  1288. }
  1289. WARN_ON(PTR_ERR(sta) != -EBUSY);
  1290. /* This station was removed and we waited until it got drained,
  1291. * we can now proceed and remove it.
  1292. */
  1293. ret = iwl_mvm_rm_sta_common(mvm, sta_id);
  1294. if (ret) {
  1295. IWL_ERR(mvm,
  1296. "Couldn't remove sta %d after it was drained\n",
  1297. sta_id);
  1298. continue;
  1299. }
  1300. RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL);
  1301. clear_bit(sta_id, mvm->sta_drained);
  1302. if (mvm->tfd_drained[sta_id]) {
  1303. unsigned long i, msk = mvm->tfd_drained[sta_id];
  1304. for_each_set_bit(i, &msk, sizeof(msk) * BITS_PER_BYTE)
  1305. iwl_mvm_disable_txq(mvm, i, i,
  1306. IWL_MAX_TID_COUNT, 0);
  1307. mvm->tfd_drained[sta_id] = 0;
  1308. IWL_DEBUG_TDLS(mvm, "Drained sta %d, with queues %ld\n",
  1309. sta_id, msk);
  1310. }
  1311. }
  1312. mutex_unlock(&mvm->mutex);
  1313. }
  1314. static void iwl_mvm_disable_sta_queues(struct iwl_mvm *mvm,
  1315. struct ieee80211_vif *vif,
  1316. struct iwl_mvm_sta *mvm_sta)
  1317. {
  1318. int ac;
  1319. int i;
  1320. lockdep_assert_held(&mvm->mutex);
  1321. for (i = 0; i < ARRAY_SIZE(mvm_sta->tid_data); i++) {
  1322. if (mvm_sta->tid_data[i].txq_id == IWL_MVM_INVALID_QUEUE)
  1323. continue;
  1324. ac = iwl_mvm_tid_to_ac_queue(i);
  1325. iwl_mvm_disable_txq(mvm, mvm_sta->tid_data[i].txq_id,
  1326. vif->hw_queue[ac], i, 0);
  1327. mvm_sta->tid_data[i].txq_id = IWL_MVM_INVALID_QUEUE;
  1328. }
  1329. }
  1330. int iwl_mvm_rm_sta(struct iwl_mvm *mvm,
  1331. struct ieee80211_vif *vif,
  1332. struct ieee80211_sta *sta)
  1333. {
  1334. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1335. struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
  1336. u8 sta_id = mvm_sta->sta_id;
  1337. int ret;
  1338. lockdep_assert_held(&mvm->mutex);
  1339. if (iwl_mvm_has_new_rx_api(mvm))
  1340. kfree(mvm_sta->dup_data);
  1341. if ((vif->type == NL80211_IFTYPE_STATION &&
  1342. mvmvif->ap_sta_id == sta_id) ||
  1343. iwl_mvm_is_dqa_supported(mvm)){
  1344. ret = iwl_mvm_drain_sta(mvm, mvm_sta, true);
  1345. if (ret)
  1346. return ret;
  1347. /* flush its queues here since we are freeing mvm_sta */
  1348. ret = iwl_mvm_flush_tx_path(mvm, mvm_sta->tfd_queue_msk, 0);
  1349. if (ret)
  1350. return ret;
  1351. ret = iwl_trans_wait_tx_queues_empty(mvm->trans,
  1352. mvm_sta->tfd_queue_msk);
  1353. if (ret)
  1354. return ret;
  1355. ret = iwl_mvm_drain_sta(mvm, mvm_sta, false);
  1356. /* If DQA is supported - the queues can be disabled now */
  1357. if (iwl_mvm_is_dqa_supported(mvm)) {
  1358. iwl_mvm_disable_sta_queues(mvm, vif, mvm_sta);
  1359. /*
  1360. * If pending_frames is set at this point - it must be
  1361. * driver internal logic error, since queues are empty
  1362. * and removed successuly.
  1363. * warn on it but set it to 0 anyway to avoid station
  1364. * not being removed later in the function
  1365. */
  1366. WARN_ON(atomic_xchg(&mvm->pending_frames[sta_id], 0));
  1367. }
  1368. /* If there is a TXQ still marked as reserved - free it */
  1369. if (iwl_mvm_is_dqa_supported(mvm) &&
  1370. mvm_sta->reserved_queue != IEEE80211_INVAL_HW_QUEUE) {
  1371. u8 reserved_txq = mvm_sta->reserved_queue;
  1372. enum iwl_mvm_queue_status *status;
  1373. /*
  1374. * If no traffic has gone through the reserved TXQ - it
  1375. * is still marked as IWL_MVM_QUEUE_RESERVED, and
  1376. * should be manually marked as free again
  1377. */
  1378. spin_lock_bh(&mvm->queue_info_lock);
  1379. status = &mvm->queue_info[reserved_txq].status;
  1380. if (WARN((*status != IWL_MVM_QUEUE_RESERVED) &&
  1381. (*status != IWL_MVM_QUEUE_FREE),
  1382. "sta_id %d reserved txq %d status %d",
  1383. sta_id, reserved_txq, *status)) {
  1384. spin_unlock_bh(&mvm->queue_info_lock);
  1385. return -EINVAL;
  1386. }
  1387. *status = IWL_MVM_QUEUE_FREE;
  1388. spin_unlock_bh(&mvm->queue_info_lock);
  1389. }
  1390. if (vif->type == NL80211_IFTYPE_STATION &&
  1391. mvmvif->ap_sta_id == sta_id) {
  1392. /* if associated - we can't remove the AP STA now */
  1393. if (vif->bss_conf.assoc)
  1394. return ret;
  1395. /* unassoc - go ahead - remove the AP STA now */
  1396. mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
  1397. /* clear d0i3_ap_sta_id if no longer relevant */
  1398. if (mvm->d0i3_ap_sta_id == sta_id)
  1399. mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA;
  1400. }
  1401. }
  1402. /*
  1403. * This shouldn't happen - the TDLS channel switch should be canceled
  1404. * before the STA is removed.
  1405. */
  1406. if (WARN_ON_ONCE(mvm->tdls_cs.peer.sta_id == sta_id)) {
  1407. mvm->tdls_cs.peer.sta_id = IWL_MVM_INVALID_STA;
  1408. cancel_delayed_work(&mvm->tdls_cs.dwork);
  1409. }
  1410. /*
  1411. * Make sure that the tx response code sees the station as -EBUSY and
  1412. * calls the drain worker.
  1413. */
  1414. spin_lock_bh(&mvm_sta->lock);
  1415. /*
  1416. * There are frames pending on the AC queues for this station.
  1417. * We need to wait until all the frames are drained...
  1418. */
  1419. if (atomic_read(&mvm->pending_frames[sta_id])) {
  1420. rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id],
  1421. ERR_PTR(-EBUSY));
  1422. spin_unlock_bh(&mvm_sta->lock);
  1423. /* disable TDLS sta queues on drain complete */
  1424. if (sta->tdls) {
  1425. mvm->tfd_drained[sta_id] = mvm_sta->tfd_queue_msk;
  1426. IWL_DEBUG_TDLS(mvm, "Draining TDLS sta %d\n", sta_id);
  1427. }
  1428. ret = iwl_mvm_drain_sta(mvm, mvm_sta, true);
  1429. } else {
  1430. spin_unlock_bh(&mvm_sta->lock);
  1431. if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls)
  1432. iwl_mvm_tdls_sta_deinit(mvm, sta);
  1433. ret = iwl_mvm_rm_sta_common(mvm, mvm_sta->sta_id);
  1434. RCU_INIT_POINTER(mvm->fw_id_to_mac_id[mvm_sta->sta_id], NULL);
  1435. }
  1436. return ret;
  1437. }
  1438. int iwl_mvm_rm_sta_id(struct iwl_mvm *mvm,
  1439. struct ieee80211_vif *vif,
  1440. u8 sta_id)
  1441. {
  1442. int ret = iwl_mvm_rm_sta_common(mvm, sta_id);
  1443. lockdep_assert_held(&mvm->mutex);
  1444. RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL);
  1445. return ret;
  1446. }
  1447. int iwl_mvm_allocate_int_sta(struct iwl_mvm *mvm,
  1448. struct iwl_mvm_int_sta *sta,
  1449. u32 qmask, enum nl80211_iftype iftype,
  1450. enum iwl_sta_type type)
  1451. {
  1452. if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
  1453. sta->sta_id = iwl_mvm_find_free_sta_id(mvm, iftype);
  1454. if (WARN_ON_ONCE(sta->sta_id == IWL_MVM_INVALID_STA))
  1455. return -ENOSPC;
  1456. }
  1457. sta->tfd_queue_msk = qmask;
  1458. sta->type = type;
  1459. /* put a non-NULL value so iterating over the stations won't stop */
  1460. rcu_assign_pointer(mvm->fw_id_to_mac_id[sta->sta_id], ERR_PTR(-EINVAL));
  1461. return 0;
  1462. }
  1463. void iwl_mvm_dealloc_int_sta(struct iwl_mvm *mvm, struct iwl_mvm_int_sta *sta)
  1464. {
  1465. RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta->sta_id], NULL);
  1466. memset(sta, 0, sizeof(struct iwl_mvm_int_sta));
  1467. sta->sta_id = IWL_MVM_INVALID_STA;
  1468. }
  1469. static int iwl_mvm_add_int_sta_common(struct iwl_mvm *mvm,
  1470. struct iwl_mvm_int_sta *sta,
  1471. const u8 *addr,
  1472. u16 mac_id, u16 color)
  1473. {
  1474. struct iwl_mvm_add_sta_cmd cmd;
  1475. int ret;
  1476. u32 status;
  1477. lockdep_assert_held(&mvm->mutex);
  1478. memset(&cmd, 0, sizeof(cmd));
  1479. cmd.sta_id = sta->sta_id;
  1480. cmd.mac_id_n_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id,
  1481. color));
  1482. if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
  1483. cmd.station_type = sta->type;
  1484. if (!iwl_mvm_has_new_tx_api(mvm))
  1485. cmd.tfd_queue_msk = cpu_to_le32(sta->tfd_queue_msk);
  1486. cmd.tid_disable_tx = cpu_to_le16(0xffff);
  1487. if (addr)
  1488. memcpy(cmd.addr, addr, ETH_ALEN);
  1489. ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
  1490. iwl_mvm_add_sta_cmd_size(mvm),
  1491. &cmd, &status);
  1492. if (ret)
  1493. return ret;
  1494. switch (status & IWL_ADD_STA_STATUS_MASK) {
  1495. case ADD_STA_SUCCESS:
  1496. IWL_DEBUG_INFO(mvm, "Internal station added.\n");
  1497. return 0;
  1498. default:
  1499. ret = -EIO;
  1500. IWL_ERR(mvm, "Add internal station failed, status=0x%x\n",
  1501. status);
  1502. break;
  1503. }
  1504. return ret;
  1505. }
  1506. static void iwl_mvm_enable_aux_queue(struct iwl_mvm *mvm)
  1507. {
  1508. unsigned int wdg_timeout = iwlmvm_mod_params.tfd_q_hang_detect ?
  1509. mvm->cfg->base_params->wd_timeout :
  1510. IWL_WATCHDOG_DISABLED;
  1511. if (iwl_mvm_has_new_tx_api(mvm)) {
  1512. int queue = iwl_mvm_tvqm_enable_txq(mvm, mvm->aux_queue,
  1513. mvm->aux_sta.sta_id,
  1514. IWL_MAX_TID_COUNT,
  1515. wdg_timeout);
  1516. mvm->aux_queue = queue;
  1517. } else if (iwl_mvm_is_dqa_supported(mvm)) {
  1518. struct iwl_trans_txq_scd_cfg cfg = {
  1519. .fifo = IWL_MVM_TX_FIFO_MCAST,
  1520. .sta_id = mvm->aux_sta.sta_id,
  1521. .tid = IWL_MAX_TID_COUNT,
  1522. .aggregate = false,
  1523. .frame_limit = IWL_FRAME_LIMIT,
  1524. };
  1525. iwl_mvm_enable_txq(mvm, mvm->aux_queue, mvm->aux_queue, 0, &cfg,
  1526. wdg_timeout);
  1527. } else {
  1528. iwl_mvm_enable_ac_txq(mvm, mvm->aux_queue, mvm->aux_queue,
  1529. IWL_MVM_TX_FIFO_MCAST, 0, wdg_timeout);
  1530. }
  1531. }
  1532. int iwl_mvm_add_aux_sta(struct iwl_mvm *mvm)
  1533. {
  1534. int ret;
  1535. lockdep_assert_held(&mvm->mutex);
  1536. /* Allocate aux station and assign to it the aux queue */
  1537. ret = iwl_mvm_allocate_int_sta(mvm, &mvm->aux_sta, BIT(mvm->aux_queue),
  1538. NL80211_IFTYPE_UNSPECIFIED,
  1539. IWL_STA_AUX_ACTIVITY);
  1540. if (ret)
  1541. return ret;
  1542. /* Map Aux queue to fifo - needs to happen before adding Aux station */
  1543. if (!iwl_mvm_has_new_tx_api(mvm))
  1544. iwl_mvm_enable_aux_queue(mvm);
  1545. ret = iwl_mvm_add_int_sta_common(mvm, &mvm->aux_sta, NULL,
  1546. MAC_INDEX_AUX, 0);
  1547. if (ret) {
  1548. iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
  1549. return ret;
  1550. }
  1551. /*
  1552. * For a000 firmware and on we cannot add queue to a station unknown
  1553. * to firmware so enable queue here - after the station was added
  1554. */
  1555. if (iwl_mvm_has_new_tx_api(mvm))
  1556. iwl_mvm_enable_aux_queue(mvm);
  1557. return 0;
  1558. }
  1559. int iwl_mvm_add_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  1560. {
  1561. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1562. lockdep_assert_held(&mvm->mutex);
  1563. return iwl_mvm_add_int_sta_common(mvm, &mvm->snif_sta, vif->addr,
  1564. mvmvif->id, 0);
  1565. }
  1566. int iwl_mvm_rm_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  1567. {
  1568. int ret;
  1569. lockdep_assert_held(&mvm->mutex);
  1570. ret = iwl_mvm_rm_sta_common(mvm, mvm->snif_sta.sta_id);
  1571. if (ret)
  1572. IWL_WARN(mvm, "Failed sending remove station\n");
  1573. return ret;
  1574. }
  1575. void iwl_mvm_dealloc_snif_sta(struct iwl_mvm *mvm)
  1576. {
  1577. iwl_mvm_dealloc_int_sta(mvm, &mvm->snif_sta);
  1578. }
  1579. void iwl_mvm_del_aux_sta(struct iwl_mvm *mvm)
  1580. {
  1581. lockdep_assert_held(&mvm->mutex);
  1582. iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
  1583. }
  1584. /*
  1585. * Send the add station command for the vif's broadcast station.
  1586. * Assumes that the station was already allocated.
  1587. *
  1588. * @mvm: the mvm component
  1589. * @vif: the interface to which the broadcast station is added
  1590. * @bsta: the broadcast station to add.
  1591. */
  1592. int iwl_mvm_send_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  1593. {
  1594. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1595. struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta;
  1596. static const u8 _baddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  1597. const u8 *baddr = _baddr;
  1598. int queue;
  1599. int ret;
  1600. unsigned int wdg_timeout =
  1601. iwl_mvm_get_wd_timeout(mvm, vif, false, false);
  1602. struct iwl_trans_txq_scd_cfg cfg = {
  1603. .fifo = IWL_MVM_TX_FIFO_VO,
  1604. .sta_id = mvmvif->bcast_sta.sta_id,
  1605. .tid = IWL_MAX_TID_COUNT,
  1606. .aggregate = false,
  1607. .frame_limit = IWL_FRAME_LIMIT,
  1608. };
  1609. lockdep_assert_held(&mvm->mutex);
  1610. if (iwl_mvm_is_dqa_supported(mvm) && !iwl_mvm_has_new_tx_api(mvm)) {
  1611. if (vif->type == NL80211_IFTYPE_AP ||
  1612. vif->type == NL80211_IFTYPE_ADHOC)
  1613. queue = mvm->probe_queue;
  1614. else if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
  1615. queue = mvm->p2p_dev_queue;
  1616. else if (WARN(1, "Missing required TXQ for adding bcast STA\n"))
  1617. return -EINVAL;
  1618. bsta->tfd_queue_msk |= BIT(queue);
  1619. iwl_mvm_enable_txq(mvm, queue, vif->hw_queue[0], 0,
  1620. &cfg, wdg_timeout);
  1621. }
  1622. if (vif->type == NL80211_IFTYPE_ADHOC)
  1623. baddr = vif->bss_conf.bssid;
  1624. if (WARN_ON_ONCE(bsta->sta_id == IWL_MVM_INVALID_STA))
  1625. return -ENOSPC;
  1626. ret = iwl_mvm_add_int_sta_common(mvm, bsta, baddr,
  1627. mvmvif->id, mvmvif->color);
  1628. if (ret)
  1629. return ret;
  1630. /*
  1631. * For a000 firmware and on we cannot add queue to a station unknown
  1632. * to firmware so enable queue here - after the station was added
  1633. */
  1634. if (iwl_mvm_has_new_tx_api(mvm)) {
  1635. queue = iwl_mvm_tvqm_enable_txq(mvm, vif->hw_queue[0],
  1636. bsta->sta_id,
  1637. IWL_MAX_TID_COUNT,
  1638. wdg_timeout);
  1639. if (vif->type == NL80211_IFTYPE_AP)
  1640. mvm->probe_queue = queue;
  1641. else if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
  1642. mvm->p2p_dev_queue = queue;
  1643. bsta->tfd_queue_msk |= BIT(queue);
  1644. }
  1645. return 0;
  1646. }
  1647. static void iwl_mvm_free_bcast_sta_queues(struct iwl_mvm *mvm,
  1648. struct ieee80211_vif *vif)
  1649. {
  1650. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1651. lockdep_assert_held(&mvm->mutex);
  1652. if (vif->type == NL80211_IFTYPE_AP ||
  1653. vif->type == NL80211_IFTYPE_ADHOC)
  1654. iwl_mvm_disable_txq(mvm, vif->cab_queue, vif->cab_queue,
  1655. IWL_MAX_TID_COUNT, 0);
  1656. if (mvmvif->bcast_sta.tfd_queue_msk & BIT(mvm->probe_queue)) {
  1657. iwl_mvm_disable_txq(mvm, mvm->probe_queue,
  1658. vif->hw_queue[0], IWL_MAX_TID_COUNT,
  1659. 0);
  1660. mvmvif->bcast_sta.tfd_queue_msk &= ~BIT(mvm->probe_queue);
  1661. }
  1662. if (mvmvif->bcast_sta.tfd_queue_msk & BIT(mvm->p2p_dev_queue)) {
  1663. iwl_mvm_disable_txq(mvm, mvm->p2p_dev_queue,
  1664. vif->hw_queue[0], IWL_MAX_TID_COUNT,
  1665. 0);
  1666. mvmvif->bcast_sta.tfd_queue_msk &= ~BIT(mvm->p2p_dev_queue);
  1667. }
  1668. }
  1669. /* Send the FW a request to remove the station from it's internal data
  1670. * structures, but DO NOT remove the entry from the local data structures. */
  1671. int iwl_mvm_send_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  1672. {
  1673. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1674. int ret;
  1675. lockdep_assert_held(&mvm->mutex);
  1676. if (iwl_mvm_is_dqa_supported(mvm))
  1677. iwl_mvm_free_bcast_sta_queues(mvm, vif);
  1678. ret = iwl_mvm_rm_sta_common(mvm, mvmvif->bcast_sta.sta_id);
  1679. if (ret)
  1680. IWL_WARN(mvm, "Failed sending remove station\n");
  1681. return ret;
  1682. }
  1683. int iwl_mvm_alloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  1684. {
  1685. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1686. u32 qmask = 0;
  1687. lockdep_assert_held(&mvm->mutex);
  1688. if (!iwl_mvm_is_dqa_supported(mvm)) {
  1689. qmask = iwl_mvm_mac_get_queues_mask(vif);
  1690. /*
  1691. * The firmware defines the TFD queue mask to only be relevant
  1692. * for *unicast* queues, so the multicast (CAB) queue shouldn't
  1693. * be included. This only happens in NL80211_IFTYPE_AP vif type,
  1694. * so the next line will only have an effect there.
  1695. */
  1696. qmask &= ~BIT(vif->cab_queue);
  1697. }
  1698. return iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, qmask,
  1699. ieee80211_vif_type_p2p(vif),
  1700. IWL_STA_GENERAL_PURPOSE);
  1701. }
  1702. /* Allocate a new station entry for the broadcast station to the given vif,
  1703. * and send it to the FW.
  1704. * Note that each P2P mac should have its own broadcast station.
  1705. *
  1706. * @mvm: the mvm component
  1707. * @vif: the interface to which the broadcast station is added
  1708. * @bsta: the broadcast station to add. */
  1709. int iwl_mvm_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  1710. {
  1711. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1712. struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta;
  1713. int ret;
  1714. lockdep_assert_held(&mvm->mutex);
  1715. ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
  1716. if (ret)
  1717. return ret;
  1718. ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
  1719. if (ret)
  1720. iwl_mvm_dealloc_int_sta(mvm, bsta);
  1721. return ret;
  1722. }
  1723. void iwl_mvm_dealloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  1724. {
  1725. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1726. iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
  1727. }
  1728. /*
  1729. * Send the FW a request to remove the station from it's internal data
  1730. * structures, and in addition remove it from the local data structure.
  1731. */
  1732. int iwl_mvm_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  1733. {
  1734. int ret;
  1735. lockdep_assert_held(&mvm->mutex);
  1736. ret = iwl_mvm_send_rm_bcast_sta(mvm, vif);
  1737. iwl_mvm_dealloc_bcast_sta(mvm, vif);
  1738. return ret;
  1739. }
  1740. /*
  1741. * Allocate a new station entry for the multicast station to the given vif,
  1742. * and send it to the FW.
  1743. * Note that each AP/GO mac should have its own multicast station.
  1744. *
  1745. * @mvm: the mvm component
  1746. * @vif: the interface to which the multicast station is added
  1747. */
  1748. int iwl_mvm_add_mcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  1749. {
  1750. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1751. struct iwl_mvm_int_sta *msta = &mvmvif->mcast_sta;
  1752. static const u8 _maddr[] = {0x03, 0x00, 0x00, 0x00, 0x00, 0x00};
  1753. const u8 *maddr = _maddr;
  1754. struct iwl_trans_txq_scd_cfg cfg = {
  1755. .fifo = IWL_MVM_TX_FIFO_MCAST,
  1756. .sta_id = msta->sta_id,
  1757. .tid = IWL_MAX_TID_COUNT,
  1758. .aggregate = false,
  1759. .frame_limit = IWL_FRAME_LIMIT,
  1760. };
  1761. unsigned int timeout = iwl_mvm_get_wd_timeout(mvm, vif, false, false);
  1762. int ret;
  1763. lockdep_assert_held(&mvm->mutex);
  1764. if (!iwl_mvm_is_dqa_supported(mvm))
  1765. return 0;
  1766. if (WARN_ON(vif->type != NL80211_IFTYPE_AP))
  1767. return -ENOTSUPP;
  1768. /*
  1769. * While in previous FWs we had to exclude cab queue from TFD queue
  1770. * mask, now it is needed as any other queue.
  1771. */
  1772. if (!iwl_mvm_has_new_tx_api(mvm) &&
  1773. fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
  1774. iwl_mvm_enable_txq(mvm, vif->cab_queue, vif->cab_queue, 0,
  1775. &cfg, timeout);
  1776. msta->tfd_queue_msk |= BIT(vif->cab_queue);
  1777. }
  1778. ret = iwl_mvm_add_int_sta_common(mvm, msta, maddr,
  1779. mvmvif->id, mvmvif->color);
  1780. if (ret) {
  1781. iwl_mvm_dealloc_int_sta(mvm, msta);
  1782. return ret;
  1783. }
  1784. /*
  1785. * Enable cab queue after the ADD_STA command is sent.
  1786. * This is needed for a000 firmware which won't accept SCD_QUEUE_CFG
  1787. * command with unknown station id, and for FW that doesn't support
  1788. * station API since the cab queue is not included in the
  1789. * tfd_queue_mask.
  1790. */
  1791. if (iwl_mvm_has_new_tx_api(mvm)) {
  1792. int queue = iwl_mvm_tvqm_enable_txq(mvm, vif->cab_queue,
  1793. msta->sta_id,
  1794. IWL_MAX_TID_COUNT,
  1795. timeout);
  1796. mvmvif->cab_queue = queue;
  1797. } else if (!fw_has_api(&mvm->fw->ucode_capa,
  1798. IWL_UCODE_TLV_API_STA_TYPE)) {
  1799. iwl_mvm_enable_txq(mvm, vif->cab_queue, vif->cab_queue, 0,
  1800. &cfg, timeout);
  1801. }
  1802. return 0;
  1803. }
  1804. /*
  1805. * Send the FW a request to remove the station from it's internal data
  1806. * structures, and in addition remove it from the local data structure.
  1807. */
  1808. int iwl_mvm_rm_mcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  1809. {
  1810. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1811. int ret;
  1812. lockdep_assert_held(&mvm->mutex);
  1813. if (!iwl_mvm_is_dqa_supported(mvm))
  1814. return 0;
  1815. iwl_mvm_disable_txq(mvm, mvmvif->cab_queue, vif->cab_queue,
  1816. IWL_MAX_TID_COUNT, 0);
  1817. ret = iwl_mvm_rm_sta_common(mvm, mvmvif->mcast_sta.sta_id);
  1818. if (ret)
  1819. IWL_WARN(mvm, "Failed sending remove station\n");
  1820. return ret;
  1821. }
  1822. #define IWL_MAX_RX_BA_SESSIONS 16
  1823. static void iwl_mvm_sync_rxq_del_ba(struct iwl_mvm *mvm, u8 baid)
  1824. {
  1825. struct iwl_mvm_delba_notif notif = {
  1826. .metadata.type = IWL_MVM_RXQ_NOTIF_DEL_BA,
  1827. .metadata.sync = 1,
  1828. .delba.baid = baid,
  1829. };
  1830. iwl_mvm_sync_rx_queues_internal(mvm, (void *)&notif, sizeof(notif));
  1831. };
  1832. static void iwl_mvm_free_reorder(struct iwl_mvm *mvm,
  1833. struct iwl_mvm_baid_data *data)
  1834. {
  1835. int i;
  1836. iwl_mvm_sync_rxq_del_ba(mvm, data->baid);
  1837. for (i = 0; i < mvm->trans->num_rx_queues; i++) {
  1838. int j;
  1839. struct iwl_mvm_reorder_buffer *reorder_buf =
  1840. &data->reorder_buf[i];
  1841. spin_lock_bh(&reorder_buf->lock);
  1842. if (likely(!reorder_buf->num_stored)) {
  1843. spin_unlock_bh(&reorder_buf->lock);
  1844. continue;
  1845. }
  1846. /*
  1847. * This shouldn't happen in regular DELBA since the internal
  1848. * delBA notification should trigger a release of all frames in
  1849. * the reorder buffer.
  1850. */
  1851. WARN_ON(1);
  1852. for (j = 0; j < reorder_buf->buf_size; j++)
  1853. __skb_queue_purge(&reorder_buf->entries[j]);
  1854. /*
  1855. * Prevent timer re-arm. This prevents a very far fetched case
  1856. * where we timed out on the notification. There may be prior
  1857. * RX frames pending in the RX queue before the notification
  1858. * that might get processed between now and the actual deletion
  1859. * and we would re-arm the timer although we are deleting the
  1860. * reorder buffer.
  1861. */
  1862. reorder_buf->removed = true;
  1863. spin_unlock_bh(&reorder_buf->lock);
  1864. del_timer_sync(&reorder_buf->reorder_timer);
  1865. }
  1866. }
  1867. static void iwl_mvm_init_reorder_buffer(struct iwl_mvm *mvm,
  1868. u32 sta_id,
  1869. struct iwl_mvm_baid_data *data,
  1870. u16 ssn, u8 buf_size)
  1871. {
  1872. int i;
  1873. for (i = 0; i < mvm->trans->num_rx_queues; i++) {
  1874. struct iwl_mvm_reorder_buffer *reorder_buf =
  1875. &data->reorder_buf[i];
  1876. int j;
  1877. reorder_buf->num_stored = 0;
  1878. reorder_buf->head_sn = ssn;
  1879. reorder_buf->buf_size = buf_size;
  1880. /* rx reorder timer */
  1881. reorder_buf->reorder_timer.function =
  1882. iwl_mvm_reorder_timer_expired;
  1883. reorder_buf->reorder_timer.data = (unsigned long)reorder_buf;
  1884. init_timer(&reorder_buf->reorder_timer);
  1885. spin_lock_init(&reorder_buf->lock);
  1886. reorder_buf->mvm = mvm;
  1887. reorder_buf->queue = i;
  1888. reorder_buf->sta_id = sta_id;
  1889. reorder_buf->valid = false;
  1890. for (j = 0; j < reorder_buf->buf_size; j++)
  1891. __skb_queue_head_init(&reorder_buf->entries[j]);
  1892. }
  1893. }
  1894. int iwl_mvm_sta_rx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
  1895. int tid, u16 ssn, bool start, u8 buf_size, u16 timeout)
  1896. {
  1897. struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
  1898. struct iwl_mvm_add_sta_cmd cmd = {};
  1899. struct iwl_mvm_baid_data *baid_data = NULL;
  1900. int ret;
  1901. u32 status;
  1902. lockdep_assert_held(&mvm->mutex);
  1903. if (start && mvm->rx_ba_sessions >= IWL_MAX_RX_BA_SESSIONS) {
  1904. IWL_WARN(mvm, "Not enough RX BA SESSIONS\n");
  1905. return -ENOSPC;
  1906. }
  1907. if (iwl_mvm_has_new_rx_api(mvm) && start) {
  1908. /*
  1909. * Allocate here so if allocation fails we can bail out early
  1910. * before starting the BA session in the firmware
  1911. */
  1912. baid_data = kzalloc(sizeof(*baid_data) +
  1913. mvm->trans->num_rx_queues *
  1914. sizeof(baid_data->reorder_buf[0]),
  1915. GFP_KERNEL);
  1916. if (!baid_data)
  1917. return -ENOMEM;
  1918. }
  1919. cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color);
  1920. cmd.sta_id = mvm_sta->sta_id;
  1921. cmd.add_modify = STA_MODE_MODIFY;
  1922. if (start) {
  1923. cmd.add_immediate_ba_tid = (u8) tid;
  1924. cmd.add_immediate_ba_ssn = cpu_to_le16(ssn);
  1925. cmd.rx_ba_window = cpu_to_le16((u16)buf_size);
  1926. } else {
  1927. cmd.remove_immediate_ba_tid = (u8) tid;
  1928. }
  1929. cmd.modify_mask = start ? STA_MODIFY_ADD_BA_TID :
  1930. STA_MODIFY_REMOVE_BA_TID;
  1931. status = ADD_STA_SUCCESS;
  1932. ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
  1933. iwl_mvm_add_sta_cmd_size(mvm),
  1934. &cmd, &status);
  1935. if (ret)
  1936. goto out_free;
  1937. switch (status & IWL_ADD_STA_STATUS_MASK) {
  1938. case ADD_STA_SUCCESS:
  1939. IWL_DEBUG_HT(mvm, "RX BA Session %sed in fw\n",
  1940. start ? "start" : "stopp");
  1941. break;
  1942. case ADD_STA_IMMEDIATE_BA_FAILURE:
  1943. IWL_WARN(mvm, "RX BA Session refused by fw\n");
  1944. ret = -ENOSPC;
  1945. break;
  1946. default:
  1947. ret = -EIO;
  1948. IWL_ERR(mvm, "RX BA Session failed %sing, status 0x%x\n",
  1949. start ? "start" : "stopp", status);
  1950. break;
  1951. }
  1952. if (ret)
  1953. goto out_free;
  1954. if (start) {
  1955. u8 baid;
  1956. mvm->rx_ba_sessions++;
  1957. if (!iwl_mvm_has_new_rx_api(mvm))
  1958. return 0;
  1959. if (WARN_ON(!(status & IWL_ADD_STA_BAID_VALID_MASK))) {
  1960. ret = -EINVAL;
  1961. goto out_free;
  1962. }
  1963. baid = (u8)((status & IWL_ADD_STA_BAID_MASK) >>
  1964. IWL_ADD_STA_BAID_SHIFT);
  1965. baid_data->baid = baid;
  1966. baid_data->timeout = timeout;
  1967. baid_data->last_rx = jiffies;
  1968. setup_timer(&baid_data->session_timer,
  1969. iwl_mvm_rx_agg_session_expired,
  1970. (unsigned long)&mvm->baid_map[baid]);
  1971. baid_data->mvm = mvm;
  1972. baid_data->tid = tid;
  1973. baid_data->sta_id = mvm_sta->sta_id;
  1974. mvm_sta->tid_to_baid[tid] = baid;
  1975. if (timeout)
  1976. mod_timer(&baid_data->session_timer,
  1977. TU_TO_EXP_TIME(timeout * 2));
  1978. iwl_mvm_init_reorder_buffer(mvm, mvm_sta->sta_id,
  1979. baid_data, ssn, buf_size);
  1980. /*
  1981. * protect the BA data with RCU to cover a case where our
  1982. * internal RX sync mechanism will timeout (not that it's
  1983. * supposed to happen) and we will free the session data while
  1984. * RX is being processed in parallel
  1985. */
  1986. IWL_DEBUG_HT(mvm, "Sta %d(%d) is assigned to BAID %d\n",
  1987. mvm_sta->sta_id, tid, baid);
  1988. WARN_ON(rcu_access_pointer(mvm->baid_map[baid]));
  1989. rcu_assign_pointer(mvm->baid_map[baid], baid_data);
  1990. } else {
  1991. u8 baid = mvm_sta->tid_to_baid[tid];
  1992. if (mvm->rx_ba_sessions > 0)
  1993. /* check that restart flow didn't zero the counter */
  1994. mvm->rx_ba_sessions--;
  1995. if (!iwl_mvm_has_new_rx_api(mvm))
  1996. return 0;
  1997. if (WARN_ON(baid == IWL_RX_REORDER_DATA_INVALID_BAID))
  1998. return -EINVAL;
  1999. baid_data = rcu_access_pointer(mvm->baid_map[baid]);
  2000. if (WARN_ON(!baid_data))
  2001. return -EINVAL;
  2002. /* synchronize all rx queues so we can safely delete */
  2003. iwl_mvm_free_reorder(mvm, baid_data);
  2004. del_timer_sync(&baid_data->session_timer);
  2005. RCU_INIT_POINTER(mvm->baid_map[baid], NULL);
  2006. kfree_rcu(baid_data, rcu_head);
  2007. IWL_DEBUG_HT(mvm, "BAID %d is free\n", baid);
  2008. }
  2009. return 0;
  2010. out_free:
  2011. kfree(baid_data);
  2012. return ret;
  2013. }
  2014. int iwl_mvm_sta_tx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
  2015. int tid, u8 queue, bool start)
  2016. {
  2017. struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
  2018. struct iwl_mvm_add_sta_cmd cmd = {};
  2019. int ret;
  2020. u32 status;
  2021. lockdep_assert_held(&mvm->mutex);
  2022. if (start) {
  2023. mvm_sta->tfd_queue_msk |= BIT(queue);
  2024. mvm_sta->tid_disable_agg &= ~BIT(tid);
  2025. } else {
  2026. /* In DQA-mode the queue isn't removed on agg termination */
  2027. if (!iwl_mvm_is_dqa_supported(mvm))
  2028. mvm_sta->tfd_queue_msk &= ~BIT(queue);
  2029. mvm_sta->tid_disable_agg |= BIT(tid);
  2030. }
  2031. cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color);
  2032. cmd.sta_id = mvm_sta->sta_id;
  2033. cmd.add_modify = STA_MODE_MODIFY;
  2034. if (!iwl_mvm_has_new_tx_api(mvm))
  2035. cmd.modify_mask = STA_MODIFY_QUEUES;
  2036. cmd.modify_mask |= STA_MODIFY_TID_DISABLE_TX;
  2037. cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk);
  2038. cmd.tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg);
  2039. status = ADD_STA_SUCCESS;
  2040. ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
  2041. iwl_mvm_add_sta_cmd_size(mvm),
  2042. &cmd, &status);
  2043. if (ret)
  2044. return ret;
  2045. switch (status & IWL_ADD_STA_STATUS_MASK) {
  2046. case ADD_STA_SUCCESS:
  2047. break;
  2048. default:
  2049. ret = -EIO;
  2050. IWL_ERR(mvm, "TX BA Session failed %sing, status 0x%x\n",
  2051. start ? "start" : "stopp", status);
  2052. break;
  2053. }
  2054. return ret;
  2055. }
  2056. const u8 tid_to_mac80211_ac[] = {
  2057. IEEE80211_AC_BE,
  2058. IEEE80211_AC_BK,
  2059. IEEE80211_AC_BK,
  2060. IEEE80211_AC_BE,
  2061. IEEE80211_AC_VI,
  2062. IEEE80211_AC_VI,
  2063. IEEE80211_AC_VO,
  2064. IEEE80211_AC_VO,
  2065. IEEE80211_AC_VO, /* We treat MGMT as TID 8, which is set as AC_VO */
  2066. };
  2067. static const u8 tid_to_ucode_ac[] = {
  2068. AC_BE,
  2069. AC_BK,
  2070. AC_BK,
  2071. AC_BE,
  2072. AC_VI,
  2073. AC_VI,
  2074. AC_VO,
  2075. AC_VO,
  2076. };
  2077. int iwl_mvm_sta_tx_agg_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  2078. struct ieee80211_sta *sta, u16 tid, u16 *ssn)
  2079. {
  2080. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  2081. struct iwl_mvm_tid_data *tid_data;
  2082. int txq_id;
  2083. int ret;
  2084. if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT))
  2085. return -EINVAL;
  2086. if (mvmsta->tid_data[tid].state != IWL_AGG_OFF) {
  2087. IWL_ERR(mvm, "Start AGG when state is not IWL_AGG_OFF %d!\n",
  2088. mvmsta->tid_data[tid].state);
  2089. return -ENXIO;
  2090. }
  2091. lockdep_assert_held(&mvm->mutex);
  2092. spin_lock_bh(&mvmsta->lock);
  2093. /* possible race condition - we entered D0i3 while starting agg */
  2094. if (test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)) {
  2095. spin_unlock_bh(&mvmsta->lock);
  2096. IWL_ERR(mvm, "Entered D0i3 while starting Tx agg\n");
  2097. return -EIO;
  2098. }
  2099. spin_lock(&mvm->queue_info_lock);
  2100. /*
  2101. * Note the possible cases:
  2102. * 1. In DQA mode with an enabled TXQ - TXQ needs to become agg'ed
  2103. * 2. Non-DQA mode: the TXQ hasn't yet been enabled, so find a free
  2104. * one and mark it as reserved
  2105. * 3. In DQA mode, but no traffic yet on this TID: same treatment as in
  2106. * non-DQA mode, since the TXQ hasn't yet been allocated
  2107. * Don't support case 3 for new TX path as it is not expected to happen
  2108. * and aggregation will be offloaded soon anyway
  2109. */
  2110. txq_id = mvmsta->tid_data[tid].txq_id;
  2111. if (iwl_mvm_has_new_tx_api(mvm)) {
  2112. if (txq_id == IWL_MVM_INVALID_QUEUE) {
  2113. ret = -ENXIO;
  2114. goto release_locks;
  2115. }
  2116. } else if (iwl_mvm_is_dqa_supported(mvm) &&
  2117. unlikely(mvm->queue_info[txq_id].status ==
  2118. IWL_MVM_QUEUE_SHARED)) {
  2119. ret = -ENXIO;
  2120. IWL_DEBUG_TX_QUEUES(mvm,
  2121. "Can't start tid %d agg on shared queue!\n",
  2122. tid);
  2123. goto release_locks;
  2124. } else if (!iwl_mvm_is_dqa_supported(mvm) ||
  2125. mvm->queue_info[txq_id].status != IWL_MVM_QUEUE_READY) {
  2126. txq_id = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
  2127. mvm->first_agg_queue,
  2128. mvm->last_agg_queue);
  2129. if (txq_id < 0) {
  2130. ret = txq_id;
  2131. IWL_ERR(mvm, "Failed to allocate agg queue\n");
  2132. goto release_locks;
  2133. }
  2134. /*
  2135. * TXQ shouldn't be in inactive mode for non-DQA, so getting
  2136. * an inactive queue from iwl_mvm_find_free_queue() is
  2137. * certainly a bug
  2138. */
  2139. WARN_ON(mvm->queue_info[txq_id].status ==
  2140. IWL_MVM_QUEUE_INACTIVE);
  2141. /* TXQ hasn't yet been enabled, so mark it only as reserved */
  2142. mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_RESERVED;
  2143. }
  2144. spin_unlock(&mvm->queue_info_lock);
  2145. IWL_DEBUG_TX_QUEUES(mvm,
  2146. "AGG for tid %d will be on queue #%d\n",
  2147. tid, txq_id);
  2148. tid_data = &mvmsta->tid_data[tid];
  2149. tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number);
  2150. tid_data->txq_id = txq_id;
  2151. *ssn = tid_data->ssn;
  2152. IWL_DEBUG_TX_QUEUES(mvm,
  2153. "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n",
  2154. mvmsta->sta_id, tid, txq_id, tid_data->ssn,
  2155. tid_data->next_reclaimed);
  2156. if (tid_data->ssn == tid_data->next_reclaimed) {
  2157. tid_data->state = IWL_AGG_STARTING;
  2158. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  2159. } else {
  2160. tid_data->state = IWL_EMPTYING_HW_QUEUE_ADDBA;
  2161. }
  2162. ret = 0;
  2163. goto out;
  2164. release_locks:
  2165. spin_unlock(&mvm->queue_info_lock);
  2166. out:
  2167. spin_unlock_bh(&mvmsta->lock);
  2168. return ret;
  2169. }
  2170. int iwl_mvm_sta_tx_agg_oper(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  2171. struct ieee80211_sta *sta, u16 tid, u8 buf_size,
  2172. bool amsdu)
  2173. {
  2174. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  2175. struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
  2176. unsigned int wdg_timeout =
  2177. iwl_mvm_get_wd_timeout(mvm, vif, sta->tdls, false);
  2178. int queue, ret;
  2179. bool alloc_queue = true;
  2180. enum iwl_mvm_queue_status queue_status;
  2181. u16 ssn;
  2182. struct iwl_trans_txq_scd_cfg cfg = {
  2183. .sta_id = mvmsta->sta_id,
  2184. .tid = tid,
  2185. .frame_limit = buf_size,
  2186. .aggregate = true,
  2187. };
  2188. BUILD_BUG_ON((sizeof(mvmsta->agg_tids) * BITS_PER_BYTE)
  2189. != IWL_MAX_TID_COUNT);
  2190. buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF);
  2191. spin_lock_bh(&mvmsta->lock);
  2192. ssn = tid_data->ssn;
  2193. queue = tid_data->txq_id;
  2194. tid_data->state = IWL_AGG_ON;
  2195. mvmsta->agg_tids |= BIT(tid);
  2196. tid_data->ssn = 0xffff;
  2197. tid_data->amsdu_in_ampdu_allowed = amsdu;
  2198. spin_unlock_bh(&mvmsta->lock);
  2199. if (iwl_mvm_has_new_tx_api(mvm)) {
  2200. /*
  2201. * If no queue iwl_mvm_sta_tx_agg_start() would have failed so
  2202. * no need to check queue's status
  2203. */
  2204. if (buf_size < mvmsta->max_agg_bufsize)
  2205. return -ENOTSUPP;
  2206. ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true);
  2207. if (ret)
  2208. return -EIO;
  2209. goto out;
  2210. }
  2211. cfg.fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]];
  2212. spin_lock_bh(&mvm->queue_info_lock);
  2213. queue_status = mvm->queue_info[queue].status;
  2214. spin_unlock_bh(&mvm->queue_info_lock);
  2215. /* In DQA mode, the existing queue might need to be reconfigured */
  2216. if (iwl_mvm_is_dqa_supported(mvm)) {
  2217. /* Maybe there is no need to even alloc a queue... */
  2218. if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_READY)
  2219. alloc_queue = false;
  2220. /*
  2221. * Only reconfig the SCD for the queue if the window size has
  2222. * changed from current (become smaller)
  2223. */
  2224. if (!alloc_queue && buf_size < mvmsta->max_agg_bufsize) {
  2225. /*
  2226. * If reconfiguring an existing queue, it first must be
  2227. * drained
  2228. */
  2229. ret = iwl_trans_wait_tx_queues_empty(mvm->trans,
  2230. BIT(queue));
  2231. if (ret) {
  2232. IWL_ERR(mvm,
  2233. "Error draining queue before reconfig\n");
  2234. return ret;
  2235. }
  2236. ret = iwl_mvm_reconfig_scd(mvm, queue, cfg.fifo,
  2237. mvmsta->sta_id, tid,
  2238. buf_size, ssn);
  2239. if (ret) {
  2240. IWL_ERR(mvm,
  2241. "Error reconfiguring TXQ #%d\n", queue);
  2242. return ret;
  2243. }
  2244. }
  2245. }
  2246. if (alloc_queue)
  2247. iwl_mvm_enable_txq(mvm, queue,
  2248. vif->hw_queue[tid_to_mac80211_ac[tid]], ssn,
  2249. &cfg, wdg_timeout);
  2250. /* Send ADD_STA command to enable aggs only if the queue isn't shared */
  2251. if (queue_status != IWL_MVM_QUEUE_SHARED) {
  2252. ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true);
  2253. if (ret)
  2254. return -EIO;
  2255. }
  2256. /* No need to mark as reserved */
  2257. spin_lock_bh(&mvm->queue_info_lock);
  2258. mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY;
  2259. spin_unlock_bh(&mvm->queue_info_lock);
  2260. out:
  2261. /*
  2262. * Even though in theory the peer could have different
  2263. * aggregation reorder buffer sizes for different sessions,
  2264. * our ucode doesn't allow for that and has a global limit
  2265. * for each station. Therefore, use the minimum of all the
  2266. * aggregation sessions and our default value.
  2267. */
  2268. mvmsta->max_agg_bufsize =
  2269. min(mvmsta->max_agg_bufsize, buf_size);
  2270. mvmsta->lq_sta.lq.agg_frame_cnt_limit = mvmsta->max_agg_bufsize;
  2271. IWL_DEBUG_HT(mvm, "Tx aggregation enabled on ra = %pM tid = %d\n",
  2272. sta->addr, tid);
  2273. return iwl_mvm_send_lq_cmd(mvm, &mvmsta->lq_sta.lq, false);
  2274. }
  2275. static void iwl_mvm_unreserve_agg_queue(struct iwl_mvm *mvm,
  2276. struct iwl_mvm_sta *mvmsta,
  2277. u16 txq_id)
  2278. {
  2279. if (iwl_mvm_has_new_tx_api(mvm))
  2280. return;
  2281. spin_lock_bh(&mvm->queue_info_lock);
  2282. /*
  2283. * The TXQ is marked as reserved only if no traffic came through yet
  2284. * This means no traffic has been sent on this TID (agg'd or not), so
  2285. * we no longer have use for the queue. Since it hasn't even been
  2286. * allocated through iwl_mvm_enable_txq, so we can just mark it back as
  2287. * free.
  2288. */
  2289. if (mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_RESERVED)
  2290. mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_FREE;
  2291. spin_unlock_bh(&mvm->queue_info_lock);
  2292. }
  2293. int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  2294. struct ieee80211_sta *sta, u16 tid)
  2295. {
  2296. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  2297. struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
  2298. u16 txq_id;
  2299. int err;
  2300. /*
  2301. * If mac80211 is cleaning its state, then say that we finished since
  2302. * our state has been cleared anyway.
  2303. */
  2304. if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
  2305. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  2306. return 0;
  2307. }
  2308. spin_lock_bh(&mvmsta->lock);
  2309. txq_id = tid_data->txq_id;
  2310. IWL_DEBUG_TX_QUEUES(mvm, "Stop AGG: sta %d tid %d q %d state %d\n",
  2311. mvmsta->sta_id, tid, txq_id, tid_data->state);
  2312. mvmsta->agg_tids &= ~BIT(tid);
  2313. iwl_mvm_unreserve_agg_queue(mvm, mvmsta, txq_id);
  2314. switch (tid_data->state) {
  2315. case IWL_AGG_ON:
  2316. tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number);
  2317. IWL_DEBUG_TX_QUEUES(mvm,
  2318. "ssn = %d, next_recl = %d\n",
  2319. tid_data->ssn, tid_data->next_reclaimed);
  2320. /* There are still packets for this RA / TID in the HW */
  2321. if (tid_data->ssn != tid_data->next_reclaimed) {
  2322. tid_data->state = IWL_EMPTYING_HW_QUEUE_DELBA;
  2323. err = 0;
  2324. break;
  2325. }
  2326. tid_data->ssn = 0xffff;
  2327. tid_data->state = IWL_AGG_OFF;
  2328. spin_unlock_bh(&mvmsta->lock);
  2329. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  2330. iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false);
  2331. if (!iwl_mvm_is_dqa_supported(mvm)) {
  2332. int mac_queue = vif->hw_queue[tid_to_mac80211_ac[tid]];
  2333. iwl_mvm_disable_txq(mvm, txq_id, mac_queue, tid, 0);
  2334. }
  2335. return 0;
  2336. case IWL_AGG_STARTING:
  2337. case IWL_EMPTYING_HW_QUEUE_ADDBA:
  2338. /*
  2339. * The agg session has been stopped before it was set up. This
  2340. * can happen when the AddBA timer times out for example.
  2341. */
  2342. /* No barriers since we are under mutex */
  2343. lockdep_assert_held(&mvm->mutex);
  2344. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  2345. tid_data->state = IWL_AGG_OFF;
  2346. err = 0;
  2347. break;
  2348. default:
  2349. IWL_ERR(mvm,
  2350. "Stopping AGG while state not ON or starting for %d on %d (%d)\n",
  2351. mvmsta->sta_id, tid, tid_data->state);
  2352. IWL_ERR(mvm,
  2353. "\ttid_data->txq_id = %d\n", tid_data->txq_id);
  2354. err = -EINVAL;
  2355. }
  2356. spin_unlock_bh(&mvmsta->lock);
  2357. return err;
  2358. }
  2359. int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  2360. struct ieee80211_sta *sta, u16 tid)
  2361. {
  2362. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  2363. struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
  2364. u16 txq_id;
  2365. enum iwl_mvm_agg_state old_state;
  2366. /*
  2367. * First set the agg state to OFF to avoid calling
  2368. * ieee80211_stop_tx_ba_cb in iwl_mvm_check_ratid_empty.
  2369. */
  2370. spin_lock_bh(&mvmsta->lock);
  2371. txq_id = tid_data->txq_id;
  2372. IWL_DEBUG_TX_QUEUES(mvm, "Flush AGG: sta %d tid %d q %d state %d\n",
  2373. mvmsta->sta_id, tid, txq_id, tid_data->state);
  2374. old_state = tid_data->state;
  2375. tid_data->state = IWL_AGG_OFF;
  2376. mvmsta->agg_tids &= ~BIT(tid);
  2377. spin_unlock_bh(&mvmsta->lock);
  2378. iwl_mvm_unreserve_agg_queue(mvm, mvmsta, txq_id);
  2379. if (old_state >= IWL_AGG_ON) {
  2380. iwl_mvm_drain_sta(mvm, mvmsta, true);
  2381. if (iwl_mvm_flush_tx_path(mvm, BIT(txq_id), 0))
  2382. IWL_ERR(mvm, "Couldn't flush the AGG queue\n");
  2383. iwl_trans_wait_tx_queues_empty(mvm->trans,
  2384. mvmsta->tfd_queue_msk);
  2385. iwl_mvm_drain_sta(mvm, mvmsta, false);
  2386. iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false);
  2387. if (!iwl_mvm_is_dqa_supported(mvm)) {
  2388. int mac_queue = vif->hw_queue[tid_to_mac80211_ac[tid]];
  2389. iwl_mvm_disable_txq(mvm, tid_data->txq_id, mac_queue,
  2390. tid, 0);
  2391. }
  2392. }
  2393. return 0;
  2394. }
  2395. static int iwl_mvm_set_fw_key_idx(struct iwl_mvm *mvm)
  2396. {
  2397. int i, max = -1, max_offs = -1;
  2398. lockdep_assert_held(&mvm->mutex);
  2399. /* Pick the unused key offset with the highest 'deleted'
  2400. * counter. Every time a key is deleted, all the counters
  2401. * are incremented and the one that was just deleted is
  2402. * reset to zero. Thus, the highest counter is the one
  2403. * that was deleted longest ago. Pick that one.
  2404. */
  2405. for (i = 0; i < STA_KEY_MAX_NUM; i++) {
  2406. if (test_bit(i, mvm->fw_key_table))
  2407. continue;
  2408. if (mvm->fw_key_deleted[i] > max) {
  2409. max = mvm->fw_key_deleted[i];
  2410. max_offs = i;
  2411. }
  2412. }
  2413. if (max_offs < 0)
  2414. return STA_KEY_IDX_INVALID;
  2415. return max_offs;
  2416. }
  2417. static struct iwl_mvm_sta *iwl_mvm_get_key_sta(struct iwl_mvm *mvm,
  2418. struct ieee80211_vif *vif,
  2419. struct ieee80211_sta *sta)
  2420. {
  2421. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  2422. if (sta)
  2423. return iwl_mvm_sta_from_mac80211(sta);
  2424. /*
  2425. * The device expects GTKs for station interfaces to be
  2426. * installed as GTKs for the AP station. If we have no
  2427. * station ID, then use AP's station ID.
  2428. */
  2429. if (vif->type == NL80211_IFTYPE_STATION &&
  2430. mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
  2431. u8 sta_id = mvmvif->ap_sta_id;
  2432. sta = rcu_dereference_check(mvm->fw_id_to_mac_id[sta_id],
  2433. lockdep_is_held(&mvm->mutex));
  2434. /*
  2435. * It is possible that the 'sta' parameter is NULL,
  2436. * for example when a GTK is removed - the sta_id will then
  2437. * be the AP ID, and no station was passed by mac80211.
  2438. */
  2439. if (IS_ERR_OR_NULL(sta))
  2440. return NULL;
  2441. return iwl_mvm_sta_from_mac80211(sta);
  2442. }
  2443. return NULL;
  2444. }
  2445. static int iwl_mvm_send_sta_key(struct iwl_mvm *mvm,
  2446. struct iwl_mvm_sta *mvm_sta,
  2447. struct ieee80211_key_conf *key, bool mcast,
  2448. u32 tkip_iv32, u16 *tkip_p1k, u32 cmd_flags,
  2449. u8 key_offset)
  2450. {
  2451. union {
  2452. struct iwl_mvm_add_sta_key_cmd_v1 cmd_v1;
  2453. struct iwl_mvm_add_sta_key_cmd cmd;
  2454. } u = {};
  2455. __le16 key_flags;
  2456. int ret;
  2457. u32 status;
  2458. u16 keyidx;
  2459. u64 pn = 0;
  2460. int i, size;
  2461. bool new_api = fw_has_api(&mvm->fw->ucode_capa,
  2462. IWL_UCODE_TLV_API_TKIP_MIC_KEYS);
  2463. keyidx = (key->keyidx << STA_KEY_FLG_KEYID_POS) &
  2464. STA_KEY_FLG_KEYID_MSK;
  2465. key_flags = cpu_to_le16(keyidx);
  2466. key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP);
  2467. switch (key->cipher) {
  2468. case WLAN_CIPHER_SUITE_TKIP:
  2469. key_flags |= cpu_to_le16(STA_KEY_FLG_TKIP);
  2470. if (new_api) {
  2471. memcpy((void *)&u.cmd.tx_mic_key,
  2472. &key->key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY],
  2473. IWL_MIC_KEY_SIZE);
  2474. memcpy((void *)&u.cmd.rx_mic_key,
  2475. &key->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY],
  2476. IWL_MIC_KEY_SIZE);
  2477. pn = atomic64_read(&key->tx_pn);
  2478. } else {
  2479. u.cmd_v1.tkip_rx_tsc_byte2 = tkip_iv32;
  2480. for (i = 0; i < 5; i++)
  2481. u.cmd_v1.tkip_rx_ttak[i] =
  2482. cpu_to_le16(tkip_p1k[i]);
  2483. }
  2484. memcpy(u.cmd.common.key, key->key, key->keylen);
  2485. break;
  2486. case WLAN_CIPHER_SUITE_CCMP:
  2487. key_flags |= cpu_to_le16(STA_KEY_FLG_CCM);
  2488. memcpy(u.cmd.common.key, key->key, key->keylen);
  2489. if (new_api)
  2490. pn = atomic64_read(&key->tx_pn);
  2491. break;
  2492. case WLAN_CIPHER_SUITE_WEP104:
  2493. key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_13BYTES);
  2494. /* fall through */
  2495. case WLAN_CIPHER_SUITE_WEP40:
  2496. key_flags |= cpu_to_le16(STA_KEY_FLG_WEP);
  2497. memcpy(u.cmd.common.key + 3, key->key, key->keylen);
  2498. break;
  2499. case WLAN_CIPHER_SUITE_GCMP_256:
  2500. key_flags |= cpu_to_le16(STA_KEY_FLG_KEY_32BYTES);
  2501. /* fall through */
  2502. case WLAN_CIPHER_SUITE_GCMP:
  2503. key_flags |= cpu_to_le16(STA_KEY_FLG_GCMP);
  2504. memcpy(u.cmd.common.key, key->key, key->keylen);
  2505. if (new_api)
  2506. pn = atomic64_read(&key->tx_pn);
  2507. break;
  2508. default:
  2509. key_flags |= cpu_to_le16(STA_KEY_FLG_EXT);
  2510. memcpy(u.cmd.common.key, key->key, key->keylen);
  2511. }
  2512. if (mcast)
  2513. key_flags |= cpu_to_le16(STA_KEY_MULTICAST);
  2514. u.cmd.common.key_offset = key_offset;
  2515. u.cmd.common.key_flags = key_flags;
  2516. u.cmd.common.sta_id = mvm_sta->sta_id;
  2517. if (new_api) {
  2518. u.cmd.transmit_seq_cnt = cpu_to_le64(pn);
  2519. size = sizeof(u.cmd);
  2520. } else {
  2521. size = sizeof(u.cmd_v1);
  2522. }
  2523. status = ADD_STA_SUCCESS;
  2524. if (cmd_flags & CMD_ASYNC)
  2525. ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA_KEY, CMD_ASYNC, size,
  2526. &u.cmd);
  2527. else
  2528. ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, size,
  2529. &u.cmd, &status);
  2530. switch (status) {
  2531. case ADD_STA_SUCCESS:
  2532. IWL_DEBUG_WEP(mvm, "MODIFY_STA: set dynamic key passed\n");
  2533. break;
  2534. default:
  2535. ret = -EIO;
  2536. IWL_ERR(mvm, "MODIFY_STA: set dynamic key failed\n");
  2537. break;
  2538. }
  2539. return ret;
  2540. }
  2541. static int iwl_mvm_send_sta_igtk(struct iwl_mvm *mvm,
  2542. struct ieee80211_key_conf *keyconf,
  2543. u8 sta_id, bool remove_key)
  2544. {
  2545. struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd = {};
  2546. /* verify the key details match the required command's expectations */
  2547. if (WARN_ON((keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE) ||
  2548. (keyconf->keyidx != 4 && keyconf->keyidx != 5) ||
  2549. (keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC &&
  2550. keyconf->cipher != WLAN_CIPHER_SUITE_BIP_GMAC_128 &&
  2551. keyconf->cipher != WLAN_CIPHER_SUITE_BIP_GMAC_256)))
  2552. return -EINVAL;
  2553. if (WARN_ON(!iwl_mvm_has_new_rx_api(mvm) &&
  2554. keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC))
  2555. return -EINVAL;
  2556. igtk_cmd.key_id = cpu_to_le32(keyconf->keyidx);
  2557. igtk_cmd.sta_id = cpu_to_le32(sta_id);
  2558. if (remove_key) {
  2559. igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_NOT_VALID);
  2560. } else {
  2561. struct ieee80211_key_seq seq;
  2562. const u8 *pn;
  2563. switch (keyconf->cipher) {
  2564. case WLAN_CIPHER_SUITE_AES_CMAC:
  2565. igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_FLG_CCM);
  2566. break;
  2567. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  2568. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  2569. igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_FLG_GCMP);
  2570. break;
  2571. default:
  2572. return -EINVAL;
  2573. }
  2574. memcpy(igtk_cmd.igtk, keyconf->key, keyconf->keylen);
  2575. if (keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
  2576. igtk_cmd.ctrl_flags |=
  2577. cpu_to_le32(STA_KEY_FLG_KEY_32BYTES);
  2578. ieee80211_get_key_rx_seq(keyconf, 0, &seq);
  2579. pn = seq.aes_cmac.pn;
  2580. igtk_cmd.receive_seq_cnt = cpu_to_le64(((u64) pn[5] << 0) |
  2581. ((u64) pn[4] << 8) |
  2582. ((u64) pn[3] << 16) |
  2583. ((u64) pn[2] << 24) |
  2584. ((u64) pn[1] << 32) |
  2585. ((u64) pn[0] << 40));
  2586. }
  2587. IWL_DEBUG_INFO(mvm, "%s igtk for sta %u\n",
  2588. remove_key ? "removing" : "installing",
  2589. igtk_cmd.sta_id);
  2590. if (!iwl_mvm_has_new_rx_api(mvm)) {
  2591. struct iwl_mvm_mgmt_mcast_key_cmd_v1 igtk_cmd_v1 = {
  2592. .ctrl_flags = igtk_cmd.ctrl_flags,
  2593. .key_id = igtk_cmd.key_id,
  2594. .sta_id = igtk_cmd.sta_id,
  2595. .receive_seq_cnt = igtk_cmd.receive_seq_cnt
  2596. };
  2597. memcpy(igtk_cmd_v1.igtk, igtk_cmd.igtk,
  2598. ARRAY_SIZE(igtk_cmd_v1.igtk));
  2599. return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0,
  2600. sizeof(igtk_cmd_v1), &igtk_cmd_v1);
  2601. }
  2602. return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0,
  2603. sizeof(igtk_cmd), &igtk_cmd);
  2604. }
  2605. static inline u8 *iwl_mvm_get_mac_addr(struct iwl_mvm *mvm,
  2606. struct ieee80211_vif *vif,
  2607. struct ieee80211_sta *sta)
  2608. {
  2609. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  2610. if (sta)
  2611. return sta->addr;
  2612. if (vif->type == NL80211_IFTYPE_STATION &&
  2613. mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
  2614. u8 sta_id = mvmvif->ap_sta_id;
  2615. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
  2616. lockdep_is_held(&mvm->mutex));
  2617. return sta->addr;
  2618. }
  2619. return NULL;
  2620. }
  2621. static int __iwl_mvm_set_sta_key(struct iwl_mvm *mvm,
  2622. struct ieee80211_vif *vif,
  2623. struct ieee80211_sta *sta,
  2624. struct ieee80211_key_conf *keyconf,
  2625. u8 key_offset,
  2626. bool mcast)
  2627. {
  2628. struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
  2629. int ret;
  2630. const u8 *addr;
  2631. struct ieee80211_key_seq seq;
  2632. u16 p1k[5];
  2633. switch (keyconf->cipher) {
  2634. case WLAN_CIPHER_SUITE_TKIP:
  2635. addr = iwl_mvm_get_mac_addr(mvm, vif, sta);
  2636. /* get phase 1 key from mac80211 */
  2637. ieee80211_get_key_rx_seq(keyconf, 0, &seq);
  2638. ieee80211_get_tkip_rx_p1k(keyconf, addr, seq.tkip.iv32, p1k);
  2639. ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
  2640. seq.tkip.iv32, p1k, 0, key_offset);
  2641. break;
  2642. case WLAN_CIPHER_SUITE_CCMP:
  2643. case WLAN_CIPHER_SUITE_WEP40:
  2644. case WLAN_CIPHER_SUITE_WEP104:
  2645. case WLAN_CIPHER_SUITE_GCMP:
  2646. case WLAN_CIPHER_SUITE_GCMP_256:
  2647. ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
  2648. 0, NULL, 0, key_offset);
  2649. break;
  2650. default:
  2651. ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
  2652. 0, NULL, 0, key_offset);
  2653. }
  2654. return ret;
  2655. }
  2656. static int __iwl_mvm_remove_sta_key(struct iwl_mvm *mvm, u8 sta_id,
  2657. struct ieee80211_key_conf *keyconf,
  2658. bool mcast)
  2659. {
  2660. union {
  2661. struct iwl_mvm_add_sta_key_cmd_v1 cmd_v1;
  2662. struct iwl_mvm_add_sta_key_cmd cmd;
  2663. } u = {};
  2664. bool new_api = fw_has_api(&mvm->fw->ucode_capa,
  2665. IWL_UCODE_TLV_API_TKIP_MIC_KEYS);
  2666. __le16 key_flags;
  2667. int ret, size;
  2668. u32 status;
  2669. key_flags = cpu_to_le16((keyconf->keyidx << STA_KEY_FLG_KEYID_POS) &
  2670. STA_KEY_FLG_KEYID_MSK);
  2671. key_flags |= cpu_to_le16(STA_KEY_FLG_NO_ENC | STA_KEY_FLG_WEP_KEY_MAP);
  2672. key_flags |= cpu_to_le16(STA_KEY_NOT_VALID);
  2673. if (mcast)
  2674. key_flags |= cpu_to_le16(STA_KEY_MULTICAST);
  2675. /*
  2676. * The fields assigned here are in the same location at the start
  2677. * of the command, so we can do this union trick.
  2678. */
  2679. u.cmd.common.key_flags = key_flags;
  2680. u.cmd.common.key_offset = keyconf->hw_key_idx;
  2681. u.cmd.common.sta_id = sta_id;
  2682. size = new_api ? sizeof(u.cmd) : sizeof(u.cmd_v1);
  2683. status = ADD_STA_SUCCESS;
  2684. ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, size, &u.cmd,
  2685. &status);
  2686. switch (status) {
  2687. case ADD_STA_SUCCESS:
  2688. IWL_DEBUG_WEP(mvm, "MODIFY_STA: remove sta key passed\n");
  2689. break;
  2690. default:
  2691. ret = -EIO;
  2692. IWL_ERR(mvm, "MODIFY_STA: remove sta key failed\n");
  2693. break;
  2694. }
  2695. return ret;
  2696. }
  2697. int iwl_mvm_set_sta_key(struct iwl_mvm *mvm,
  2698. struct ieee80211_vif *vif,
  2699. struct ieee80211_sta *sta,
  2700. struct ieee80211_key_conf *keyconf,
  2701. u8 key_offset)
  2702. {
  2703. bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
  2704. struct iwl_mvm_sta *mvm_sta;
  2705. u8 sta_id;
  2706. int ret;
  2707. static const u8 __maybe_unused zero_addr[ETH_ALEN] = {0};
  2708. lockdep_assert_held(&mvm->mutex);
  2709. /* Get the station id from the mvm local station table */
  2710. mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
  2711. if (!mvm_sta) {
  2712. IWL_ERR(mvm, "Failed to find station\n");
  2713. return -EINVAL;
  2714. }
  2715. sta_id = mvm_sta->sta_id;
  2716. if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
  2717. keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
  2718. keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) {
  2719. ret = iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, false);
  2720. goto end;
  2721. }
  2722. /*
  2723. * It is possible that the 'sta' parameter is NULL, and thus
  2724. * there is a need to retrieve the sta from the local station table.
  2725. */
  2726. if (!sta) {
  2727. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
  2728. lockdep_is_held(&mvm->mutex));
  2729. if (IS_ERR_OR_NULL(sta)) {
  2730. IWL_ERR(mvm, "Invalid station id\n");
  2731. return -EINVAL;
  2732. }
  2733. }
  2734. if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta)->vif != vif))
  2735. return -EINVAL;
  2736. /* If the key_offset is not pre-assigned, we need to find a
  2737. * new offset to use. In normal cases, the offset is not
  2738. * pre-assigned, but during HW_RESTART we want to reuse the
  2739. * same indices, so we pass them when this function is called.
  2740. *
  2741. * In D3 entry, we need to hardcoded the indices (because the
  2742. * firmware hardcodes the PTK offset to 0). In this case, we
  2743. * need to make sure we don't overwrite the hw_key_idx in the
  2744. * keyconf structure, because otherwise we cannot configure
  2745. * the original ones back when resuming.
  2746. */
  2747. if (key_offset == STA_KEY_IDX_INVALID) {
  2748. key_offset = iwl_mvm_set_fw_key_idx(mvm);
  2749. if (key_offset == STA_KEY_IDX_INVALID)
  2750. return -ENOSPC;
  2751. keyconf->hw_key_idx = key_offset;
  2752. }
  2753. ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf, key_offset, mcast);
  2754. if (ret)
  2755. goto end;
  2756. /*
  2757. * For WEP, the same key is used for multicast and unicast. Upload it
  2758. * again, using the same key offset, and now pointing the other one
  2759. * to the same key slot (offset).
  2760. * If this fails, remove the original as well.
  2761. */
  2762. if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  2763. keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) {
  2764. ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf,
  2765. key_offset, !mcast);
  2766. if (ret) {
  2767. __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast);
  2768. goto end;
  2769. }
  2770. }
  2771. __set_bit(key_offset, mvm->fw_key_table);
  2772. end:
  2773. IWL_DEBUG_WEP(mvm, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n",
  2774. keyconf->cipher, keyconf->keylen, keyconf->keyidx,
  2775. sta ? sta->addr : zero_addr, ret);
  2776. return ret;
  2777. }
  2778. int iwl_mvm_remove_sta_key(struct iwl_mvm *mvm,
  2779. struct ieee80211_vif *vif,
  2780. struct ieee80211_sta *sta,
  2781. struct ieee80211_key_conf *keyconf)
  2782. {
  2783. bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
  2784. struct iwl_mvm_sta *mvm_sta;
  2785. u8 sta_id = IWL_MVM_INVALID_STA;
  2786. int ret, i;
  2787. lockdep_assert_held(&mvm->mutex);
  2788. /* Get the station from the mvm local station table */
  2789. mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
  2790. if (!mvm_sta) {
  2791. IWL_ERR(mvm, "Failed to find station\n");
  2792. return -EINVAL;
  2793. }
  2794. sta_id = mvm_sta->sta_id;
  2795. IWL_DEBUG_WEP(mvm, "mvm remove dynamic key: idx=%d sta=%d\n",
  2796. keyconf->keyidx, sta_id);
  2797. if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
  2798. keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
  2799. keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
  2800. return iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, true);
  2801. if (!__test_and_clear_bit(keyconf->hw_key_idx, mvm->fw_key_table)) {
  2802. IWL_ERR(mvm, "offset %d not used in fw key table.\n",
  2803. keyconf->hw_key_idx);
  2804. return -ENOENT;
  2805. }
  2806. /* track which key was deleted last */
  2807. for (i = 0; i < STA_KEY_MAX_NUM; i++) {
  2808. if (mvm->fw_key_deleted[i] < U8_MAX)
  2809. mvm->fw_key_deleted[i]++;
  2810. }
  2811. mvm->fw_key_deleted[keyconf->hw_key_idx] = 0;
  2812. if (!mvm_sta) {
  2813. IWL_DEBUG_WEP(mvm, "station non-existent, early return.\n");
  2814. return 0;
  2815. }
  2816. ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast);
  2817. if (ret)
  2818. return ret;
  2819. /* delete WEP key twice to get rid of (now useless) offset */
  2820. if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  2821. keyconf->cipher == WLAN_CIPHER_SUITE_WEP104)
  2822. ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, !mcast);
  2823. return ret;
  2824. }
  2825. void iwl_mvm_update_tkip_key(struct iwl_mvm *mvm,
  2826. struct ieee80211_vif *vif,
  2827. struct ieee80211_key_conf *keyconf,
  2828. struct ieee80211_sta *sta, u32 iv32,
  2829. u16 *phase1key)
  2830. {
  2831. struct iwl_mvm_sta *mvm_sta;
  2832. bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
  2833. rcu_read_lock();
  2834. mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
  2835. if (WARN_ON_ONCE(!mvm_sta))
  2836. goto unlock;
  2837. iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
  2838. iv32, phase1key, CMD_ASYNC, keyconf->hw_key_idx);
  2839. unlock:
  2840. rcu_read_unlock();
  2841. }
  2842. void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm *mvm,
  2843. struct ieee80211_sta *sta)
  2844. {
  2845. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  2846. struct iwl_mvm_add_sta_cmd cmd = {
  2847. .add_modify = STA_MODE_MODIFY,
  2848. .sta_id = mvmsta->sta_id,
  2849. .station_flags_msk = cpu_to_le32(STA_FLG_PS),
  2850. .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
  2851. };
  2852. int ret;
  2853. ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC,
  2854. iwl_mvm_add_sta_cmd_size(mvm), &cmd);
  2855. if (ret)
  2856. IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
  2857. }
  2858. void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm *mvm,
  2859. struct ieee80211_sta *sta,
  2860. enum ieee80211_frame_release_type reason,
  2861. u16 cnt, u16 tids, bool more_data,
  2862. bool single_sta_queue)
  2863. {
  2864. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  2865. struct iwl_mvm_add_sta_cmd cmd = {
  2866. .add_modify = STA_MODE_MODIFY,
  2867. .sta_id = mvmsta->sta_id,
  2868. .modify_mask = STA_MODIFY_SLEEPING_STA_TX_COUNT,
  2869. .sleep_tx_count = cpu_to_le16(cnt),
  2870. .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
  2871. };
  2872. int tid, ret;
  2873. unsigned long _tids = tids;
  2874. /* convert TIDs to ACs - we don't support TSPEC so that's OK
  2875. * Note that this field is reserved and unused by firmware not
  2876. * supporting GO uAPSD, so it's safe to always do this.
  2877. */
  2878. for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT)
  2879. cmd.awake_acs |= BIT(tid_to_ucode_ac[tid]);
  2880. /* If we're releasing frames from aggregation or dqa queues then check
  2881. * if all the queues that we're releasing frames from, combined, have:
  2882. * - more frames than the service period, in which case more_data
  2883. * needs to be set
  2884. * - fewer than 'cnt' frames, in which case we need to adjust the
  2885. * firmware command (but do that unconditionally)
  2886. */
  2887. if (single_sta_queue) {
  2888. int remaining = cnt;
  2889. int sleep_tx_count;
  2890. spin_lock_bh(&mvmsta->lock);
  2891. for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) {
  2892. struct iwl_mvm_tid_data *tid_data;
  2893. u16 n_queued;
  2894. tid_data = &mvmsta->tid_data[tid];
  2895. if (WARN(!iwl_mvm_is_dqa_supported(mvm) &&
  2896. tid_data->state != IWL_AGG_ON &&
  2897. tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA,
  2898. "TID %d state is %d\n",
  2899. tid, tid_data->state)) {
  2900. spin_unlock_bh(&mvmsta->lock);
  2901. ieee80211_sta_eosp(sta);
  2902. return;
  2903. }
  2904. n_queued = iwl_mvm_tid_queued(tid_data);
  2905. if (n_queued > remaining) {
  2906. more_data = true;
  2907. remaining = 0;
  2908. break;
  2909. }
  2910. remaining -= n_queued;
  2911. }
  2912. sleep_tx_count = cnt - remaining;
  2913. if (reason == IEEE80211_FRAME_RELEASE_UAPSD)
  2914. mvmsta->sleep_tx_count = sleep_tx_count;
  2915. spin_unlock_bh(&mvmsta->lock);
  2916. cmd.sleep_tx_count = cpu_to_le16(sleep_tx_count);
  2917. if (WARN_ON(cnt - remaining == 0)) {
  2918. ieee80211_sta_eosp(sta);
  2919. return;
  2920. }
  2921. }
  2922. /* Note: this is ignored by firmware not supporting GO uAPSD */
  2923. if (more_data)
  2924. cmd.sleep_state_flags |= STA_SLEEP_STATE_MOREDATA;
  2925. if (reason == IEEE80211_FRAME_RELEASE_PSPOLL) {
  2926. mvmsta->next_status_eosp = true;
  2927. cmd.sleep_state_flags |= STA_SLEEP_STATE_PS_POLL;
  2928. } else {
  2929. cmd.sleep_state_flags |= STA_SLEEP_STATE_UAPSD;
  2930. }
  2931. /* block the Tx queues until the FW updated the sleep Tx count */
  2932. iwl_trans_block_txq_ptrs(mvm->trans, true);
  2933. ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA,
  2934. CMD_ASYNC | CMD_WANT_ASYNC_CALLBACK,
  2935. iwl_mvm_add_sta_cmd_size(mvm), &cmd);
  2936. if (ret)
  2937. IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
  2938. }
  2939. void iwl_mvm_rx_eosp_notif(struct iwl_mvm *mvm,
  2940. struct iwl_rx_cmd_buffer *rxb)
  2941. {
  2942. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  2943. struct iwl_mvm_eosp_notification *notif = (void *)pkt->data;
  2944. struct ieee80211_sta *sta;
  2945. u32 sta_id = le32_to_cpu(notif->sta_id);
  2946. if (WARN_ON_ONCE(sta_id >= IWL_MVM_STATION_COUNT))
  2947. return;
  2948. rcu_read_lock();
  2949. sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
  2950. if (!IS_ERR_OR_NULL(sta))
  2951. ieee80211_sta_eosp(sta);
  2952. rcu_read_unlock();
  2953. }
  2954. void iwl_mvm_sta_modify_disable_tx(struct iwl_mvm *mvm,
  2955. struct iwl_mvm_sta *mvmsta, bool disable)
  2956. {
  2957. struct iwl_mvm_add_sta_cmd cmd = {
  2958. .add_modify = STA_MODE_MODIFY,
  2959. .sta_id = mvmsta->sta_id,
  2960. .station_flags = disable ? cpu_to_le32(STA_FLG_DISABLE_TX) : 0,
  2961. .station_flags_msk = cpu_to_le32(STA_FLG_DISABLE_TX),
  2962. .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
  2963. };
  2964. int ret;
  2965. ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC,
  2966. iwl_mvm_add_sta_cmd_size(mvm), &cmd);
  2967. if (ret)
  2968. IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
  2969. }
  2970. void iwl_mvm_sta_modify_disable_tx_ap(struct iwl_mvm *mvm,
  2971. struct ieee80211_sta *sta,
  2972. bool disable)
  2973. {
  2974. struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
  2975. spin_lock_bh(&mvm_sta->lock);
  2976. if (mvm_sta->disable_tx == disable) {
  2977. spin_unlock_bh(&mvm_sta->lock);
  2978. return;
  2979. }
  2980. mvm_sta->disable_tx = disable;
  2981. /*
  2982. * Tell mac80211 to start/stop queuing tx for this station,
  2983. * but don't stop queuing if there are still pending frames
  2984. * for this station.
  2985. */
  2986. if (disable || !atomic_read(&mvm->pending_frames[mvm_sta->sta_id]))
  2987. ieee80211_sta_block_awake(mvm->hw, sta, disable);
  2988. iwl_mvm_sta_modify_disable_tx(mvm, mvm_sta, disable);
  2989. spin_unlock_bh(&mvm_sta->lock);
  2990. }
  2991. static void iwl_mvm_int_sta_modify_disable_tx(struct iwl_mvm *mvm,
  2992. struct iwl_mvm_vif *mvmvif,
  2993. struct iwl_mvm_int_sta *sta,
  2994. bool disable)
  2995. {
  2996. u32 id = FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color);
  2997. struct iwl_mvm_add_sta_cmd cmd = {
  2998. .add_modify = STA_MODE_MODIFY,
  2999. .sta_id = sta->sta_id,
  3000. .station_flags = disable ? cpu_to_le32(STA_FLG_DISABLE_TX) : 0,
  3001. .station_flags_msk = cpu_to_le32(STA_FLG_DISABLE_TX),
  3002. .mac_id_n_color = cpu_to_le32(id),
  3003. };
  3004. int ret;
  3005. ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, 0,
  3006. iwl_mvm_add_sta_cmd_size(mvm), &cmd);
  3007. if (ret)
  3008. IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
  3009. }
  3010. void iwl_mvm_modify_all_sta_disable_tx(struct iwl_mvm *mvm,
  3011. struct iwl_mvm_vif *mvmvif,
  3012. bool disable)
  3013. {
  3014. struct ieee80211_sta *sta;
  3015. struct iwl_mvm_sta *mvm_sta;
  3016. int i;
  3017. lockdep_assert_held(&mvm->mutex);
  3018. /* Block/unblock all the stations of the given mvmvif */
  3019. for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
  3020. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
  3021. lockdep_is_held(&mvm->mutex));
  3022. if (IS_ERR_OR_NULL(sta))
  3023. continue;
  3024. mvm_sta = iwl_mvm_sta_from_mac80211(sta);
  3025. if (mvm_sta->mac_id_n_color !=
  3026. FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color))
  3027. continue;
  3028. iwl_mvm_sta_modify_disable_tx_ap(mvm, sta, disable);
  3029. }
  3030. if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
  3031. return;
  3032. /* Need to block/unblock also multicast station */
  3033. if (mvmvif->mcast_sta.sta_id != IWL_MVM_INVALID_STA)
  3034. iwl_mvm_int_sta_modify_disable_tx(mvm, mvmvif,
  3035. &mvmvif->mcast_sta, disable);
  3036. /*
  3037. * Only unblock the broadcast station (FW blocks it for immediate
  3038. * quiet, not the driver)
  3039. */
  3040. if (!disable && mvmvif->bcast_sta.sta_id != IWL_MVM_INVALID_STA)
  3041. iwl_mvm_int_sta_modify_disable_tx(mvm, mvmvif,
  3042. &mvmvif->bcast_sta, disable);
  3043. }
  3044. void iwl_mvm_csa_client_absent(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  3045. {
  3046. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  3047. struct iwl_mvm_sta *mvmsta;
  3048. rcu_read_lock();
  3049. mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, mvmvif->ap_sta_id);
  3050. if (!WARN_ON(!mvmsta))
  3051. iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, true);
  3052. rcu_read_unlock();
  3053. }