sta.c 101 KB

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