sta.c 100 KB

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