sta.c 102 KB

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