mac80211.c 121 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428
  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 - 2014 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 - 2014 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 <linux/kernel.h>
  68. #include <linux/slab.h>
  69. #include <linux/skbuff.h>
  70. #include <linux/netdevice.h>
  71. #include <linux/etherdevice.h>
  72. #include <linux/ip.h>
  73. #include <linux/if_arp.h>
  74. #include <linux/time.h>
  75. #include <net/mac80211.h>
  76. #include <net/ieee80211_radiotap.h>
  77. #include <net/tcp.h>
  78. #include "iwl-op-mode.h"
  79. #include "iwl-io.h"
  80. #include "mvm.h"
  81. #include "sta.h"
  82. #include "time-event.h"
  83. #include "iwl-eeprom-parse.h"
  84. #include "iwl-phy-db.h"
  85. #include "testmode.h"
  86. #include "fw/error-dump.h"
  87. #include "iwl-prph.h"
  88. #include "iwl-nvm-parse.h"
  89. static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
  90. {
  91. .max = 1,
  92. .types = BIT(NL80211_IFTYPE_STATION),
  93. },
  94. {
  95. .max = 1,
  96. .types = BIT(NL80211_IFTYPE_AP) |
  97. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  98. BIT(NL80211_IFTYPE_P2P_GO),
  99. },
  100. {
  101. .max = 1,
  102. .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
  103. },
  104. };
  105. static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
  106. {
  107. .num_different_channels = 2,
  108. .max_interfaces = 3,
  109. .limits = iwl_mvm_limits,
  110. .n_limits = ARRAY_SIZE(iwl_mvm_limits),
  111. },
  112. };
  113. #ifdef CONFIG_PM_SLEEP
  114. static const struct nl80211_wowlan_tcp_data_token_feature
  115. iwl_mvm_wowlan_tcp_token_feature = {
  116. .min_len = 0,
  117. .max_len = 255,
  118. .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
  119. };
  120. static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
  121. .tok = &iwl_mvm_wowlan_tcp_token_feature,
  122. .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
  123. sizeof(struct ethhdr) -
  124. sizeof(struct iphdr) -
  125. sizeof(struct tcphdr),
  126. .data_interval_max = 65535, /* __le16 in API */
  127. .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
  128. sizeof(struct ethhdr) -
  129. sizeof(struct iphdr) -
  130. sizeof(struct tcphdr),
  131. .seq = true,
  132. };
  133. #endif
  134. #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
  135. /*
  136. * Use the reserved field to indicate magic values.
  137. * these values will only be used internally by the driver,
  138. * and won't make it to the fw (reserved will be 0).
  139. * BC_FILTER_MAGIC_IP - configure the val of this attribute to
  140. * be the vif's ip address. in case there is not a single
  141. * ip address (0, or more than 1), this attribute will
  142. * be skipped.
  143. * BC_FILTER_MAGIC_MAC - set the val of this attribute to
  144. * the LSB bytes of the vif's mac address
  145. */
  146. enum {
  147. BC_FILTER_MAGIC_NONE = 0,
  148. BC_FILTER_MAGIC_IP,
  149. BC_FILTER_MAGIC_MAC,
  150. };
  151. static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
  152. {
  153. /* arp */
  154. .discard = 0,
  155. .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
  156. .attrs = {
  157. {
  158. /* frame type - arp, hw type - ethernet */
  159. .offset_type =
  160. BCAST_FILTER_OFFSET_PAYLOAD_START,
  161. .offset = sizeof(rfc1042_header),
  162. .val = cpu_to_be32(0x08060001),
  163. .mask = cpu_to_be32(0xffffffff),
  164. },
  165. {
  166. /* arp dest ip */
  167. .offset_type =
  168. BCAST_FILTER_OFFSET_PAYLOAD_START,
  169. .offset = sizeof(rfc1042_header) + 2 +
  170. sizeof(struct arphdr) +
  171. ETH_ALEN + sizeof(__be32) +
  172. ETH_ALEN,
  173. .mask = cpu_to_be32(0xffffffff),
  174. /* mark it as special field */
  175. .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
  176. },
  177. },
  178. },
  179. {
  180. /* dhcp offer bcast */
  181. .discard = 0,
  182. .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
  183. .attrs = {
  184. {
  185. /* udp dest port - 68 (bootp client)*/
  186. .offset_type = BCAST_FILTER_OFFSET_IP_END,
  187. .offset = offsetof(struct udphdr, dest),
  188. .val = cpu_to_be32(0x00440000),
  189. .mask = cpu_to_be32(0xffff0000),
  190. },
  191. {
  192. /* dhcp - lsb bytes of client hw address */
  193. .offset_type = BCAST_FILTER_OFFSET_IP_END,
  194. .offset = 38,
  195. .mask = cpu_to_be32(0xffffffff),
  196. /* mark it as special field */
  197. .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
  198. },
  199. },
  200. },
  201. /* last filter must be empty */
  202. {},
  203. };
  204. #endif
  205. void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
  206. {
  207. if (!iwl_mvm_is_d0i3_supported(mvm))
  208. return;
  209. IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
  210. spin_lock_bh(&mvm->refs_lock);
  211. mvm->refs[ref_type]++;
  212. spin_unlock_bh(&mvm->refs_lock);
  213. iwl_trans_ref(mvm->trans);
  214. }
  215. void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
  216. {
  217. if (!iwl_mvm_is_d0i3_supported(mvm))
  218. return;
  219. IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
  220. spin_lock_bh(&mvm->refs_lock);
  221. if (WARN_ON(!mvm->refs[ref_type])) {
  222. spin_unlock_bh(&mvm->refs_lock);
  223. return;
  224. }
  225. mvm->refs[ref_type]--;
  226. spin_unlock_bh(&mvm->refs_lock);
  227. iwl_trans_unref(mvm->trans);
  228. }
  229. static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm,
  230. enum iwl_mvm_ref_type except_ref)
  231. {
  232. int i, j;
  233. if (!iwl_mvm_is_d0i3_supported(mvm))
  234. return;
  235. spin_lock_bh(&mvm->refs_lock);
  236. for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
  237. if (except_ref == i || !mvm->refs[i])
  238. continue;
  239. IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n",
  240. i, mvm->refs[i]);
  241. for (j = 0; j < mvm->refs[i]; j++)
  242. iwl_trans_unref(mvm->trans);
  243. mvm->refs[i] = 0;
  244. }
  245. spin_unlock_bh(&mvm->refs_lock);
  246. }
  247. bool iwl_mvm_ref_taken(struct iwl_mvm *mvm)
  248. {
  249. int i;
  250. bool taken = false;
  251. if (!iwl_mvm_is_d0i3_supported(mvm))
  252. return true;
  253. spin_lock_bh(&mvm->refs_lock);
  254. for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
  255. if (mvm->refs[i]) {
  256. taken = true;
  257. break;
  258. }
  259. }
  260. spin_unlock_bh(&mvm->refs_lock);
  261. return taken;
  262. }
  263. int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
  264. {
  265. iwl_mvm_ref(mvm, ref_type);
  266. if (!wait_event_timeout(mvm->d0i3_exit_waitq,
  267. !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status),
  268. HZ)) {
  269. WARN_ON_ONCE(1);
  270. iwl_mvm_unref(mvm, ref_type);
  271. return -EIO;
  272. }
  273. return 0;
  274. }
  275. static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
  276. {
  277. int i;
  278. memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
  279. for (i = 0; i < NUM_PHY_CTX; i++) {
  280. mvm->phy_ctxts[i].id = i;
  281. mvm->phy_ctxts[i].ref = 0;
  282. }
  283. }
  284. struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
  285. const char *alpha2,
  286. enum iwl_mcc_source src_id,
  287. bool *changed)
  288. {
  289. struct ieee80211_regdomain *regd = NULL;
  290. struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
  291. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  292. struct iwl_mcc_update_resp *resp;
  293. IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2);
  294. lockdep_assert_held(&mvm->mutex);
  295. resp = iwl_mvm_update_mcc(mvm, alpha2, src_id);
  296. if (IS_ERR_OR_NULL(resp)) {
  297. IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n",
  298. PTR_ERR_OR_ZERO(resp));
  299. goto out;
  300. }
  301. if (changed)
  302. *changed = (resp->status == MCC_RESP_NEW_CHAN_PROFILE);
  303. regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg,
  304. __le32_to_cpu(resp->n_channels),
  305. resp->channels,
  306. __le16_to_cpu(resp->mcc));
  307. /* Store the return source id */
  308. src_id = resp->source_id;
  309. kfree(resp);
  310. if (IS_ERR_OR_NULL(regd)) {
  311. IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
  312. PTR_ERR_OR_ZERO(regd));
  313. goto out;
  314. }
  315. IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
  316. regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id);
  317. mvm->lar_regdom_set = true;
  318. mvm->mcc_src = src_id;
  319. out:
  320. return regd;
  321. }
  322. void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm)
  323. {
  324. bool changed;
  325. struct ieee80211_regdomain *regd;
  326. if (!iwl_mvm_is_lar_supported(mvm))
  327. return;
  328. regd = iwl_mvm_get_current_regdomain(mvm, &changed);
  329. if (!IS_ERR_OR_NULL(regd)) {
  330. /* only update the regulatory core if changed */
  331. if (changed)
  332. regulatory_set_wiphy_regd(mvm->hw->wiphy, regd);
  333. kfree(regd);
  334. }
  335. }
  336. struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
  337. bool *changed)
  338. {
  339. return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ",
  340. iwl_mvm_is_wifi_mcc_supported(mvm) ?
  341. MCC_SOURCE_GET_CURRENT :
  342. MCC_SOURCE_OLD_FW, changed);
  343. }
  344. int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm)
  345. {
  346. enum iwl_mcc_source used_src;
  347. struct ieee80211_regdomain *regd;
  348. int ret;
  349. bool changed;
  350. const struct ieee80211_regdomain *r =
  351. rtnl_dereference(mvm->hw->wiphy->regd);
  352. if (!r)
  353. return -ENOENT;
  354. /* save the last source in case we overwrite it below */
  355. used_src = mvm->mcc_src;
  356. if (iwl_mvm_is_wifi_mcc_supported(mvm)) {
  357. /* Notify the firmware we support wifi location updates */
  358. regd = iwl_mvm_get_current_regdomain(mvm, NULL);
  359. if (!IS_ERR_OR_NULL(regd))
  360. kfree(regd);
  361. }
  362. /* Now set our last stored MCC and source */
  363. regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src,
  364. &changed);
  365. if (IS_ERR_OR_NULL(regd))
  366. return -EIO;
  367. /* update cfg80211 if the regdomain was changed */
  368. if (changed)
  369. ret = regulatory_set_wiphy_regd_sync_rtnl(mvm->hw->wiphy, regd);
  370. else
  371. ret = 0;
  372. kfree(regd);
  373. return ret;
  374. }
  375. int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
  376. {
  377. struct ieee80211_hw *hw = mvm->hw;
  378. int num_mac, ret, i;
  379. static const u32 mvm_ciphers[] = {
  380. WLAN_CIPHER_SUITE_WEP40,
  381. WLAN_CIPHER_SUITE_WEP104,
  382. WLAN_CIPHER_SUITE_TKIP,
  383. WLAN_CIPHER_SUITE_CCMP,
  384. };
  385. /* Tell mac80211 our characteristics */
  386. ieee80211_hw_set(hw, SIGNAL_DBM);
  387. ieee80211_hw_set(hw, SPECTRUM_MGMT);
  388. ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
  389. ieee80211_hw_set(hw, QUEUE_CONTROL);
  390. ieee80211_hw_set(hw, WANT_MONITOR_VIF);
  391. ieee80211_hw_set(hw, SUPPORTS_PS);
  392. ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
  393. ieee80211_hw_set(hw, AMPDU_AGGREGATION);
  394. ieee80211_hw_set(hw, TIMING_BEACON_ONLY);
  395. ieee80211_hw_set(hw, CONNECTION_MONITOR);
  396. ieee80211_hw_set(hw, CHANCTX_STA_CSA);
  397. ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
  398. ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
  399. ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
  400. ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
  401. if (iwl_mvm_has_new_rx_api(mvm))
  402. ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
  403. if (fw_has_capa(&mvm->fw->ucode_capa,
  404. IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) {
  405. ieee80211_hw_set(hw, AP_LINK_PS);
  406. } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) {
  407. /*
  408. * we absolutely need this for the new TX API since that comes
  409. * with many more queues than the current code can deal with
  410. * for station powersave
  411. */
  412. return -EINVAL;
  413. }
  414. if (mvm->trans->num_rx_queues > 1)
  415. ieee80211_hw_set(hw, USES_RSS);
  416. if (mvm->trans->max_skb_frags)
  417. hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
  418. hw->queues = IEEE80211_MAX_QUEUES;
  419. hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
  420. hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
  421. IEEE80211_RADIOTAP_MCS_HAVE_STBC;
  422. hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
  423. IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
  424. hw->radiotap_timestamp.units_pos =
  425. IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
  426. IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
  427. /* this is the case for CCK frames, it's better (only 8) for OFDM */
  428. hw->radiotap_timestamp.accuracy = 22;
  429. hw->rate_control_algorithm = "iwl-mvm-rs";
  430. hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
  431. hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
  432. BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6);
  433. memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers));
  434. hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers);
  435. hw->wiphy->cipher_suites = mvm->ciphers;
  436. if (iwl_mvm_has_new_rx_api(mvm)) {
  437. mvm->ciphers[hw->wiphy->n_cipher_suites] =
  438. WLAN_CIPHER_SUITE_GCMP;
  439. hw->wiphy->n_cipher_suites++;
  440. mvm->ciphers[hw->wiphy->n_cipher_suites] =
  441. WLAN_CIPHER_SUITE_GCMP_256;
  442. hw->wiphy->n_cipher_suites++;
  443. }
  444. /* Enable 11w if software crypto is not enabled (as the
  445. * firmware will interpret some mgmt packets, so enabling it
  446. * with software crypto isn't safe).
  447. */
  448. if (!iwlwifi_mod_params.swcrypto) {
  449. ieee80211_hw_set(hw, MFP_CAPABLE);
  450. mvm->ciphers[hw->wiphy->n_cipher_suites] =
  451. WLAN_CIPHER_SUITE_AES_CMAC;
  452. hw->wiphy->n_cipher_suites++;
  453. if (iwl_mvm_has_new_rx_api(mvm)) {
  454. mvm->ciphers[hw->wiphy->n_cipher_suites] =
  455. WLAN_CIPHER_SUITE_BIP_GMAC_128;
  456. hw->wiphy->n_cipher_suites++;
  457. mvm->ciphers[hw->wiphy->n_cipher_suites] =
  458. WLAN_CIPHER_SUITE_BIP_GMAC_256;
  459. hw->wiphy->n_cipher_suites++;
  460. }
  461. }
  462. /* currently FW API supports only one optional cipher scheme */
  463. if (mvm->fw->cs[0].cipher) {
  464. const struct iwl_fw_cipher_scheme *fwcs = &mvm->fw->cs[0];
  465. struct ieee80211_cipher_scheme *cs = &mvm->cs[0];
  466. mvm->hw->n_cipher_schemes = 1;
  467. cs->cipher = le32_to_cpu(fwcs->cipher);
  468. cs->iftype = BIT(NL80211_IFTYPE_STATION);
  469. cs->hdr_len = fwcs->hdr_len;
  470. cs->pn_len = fwcs->pn_len;
  471. cs->pn_off = fwcs->pn_off;
  472. cs->key_idx_off = fwcs->key_idx_off;
  473. cs->key_idx_mask = fwcs->key_idx_mask;
  474. cs->key_idx_shift = fwcs->key_idx_shift;
  475. cs->mic_len = fwcs->mic_len;
  476. mvm->hw->cipher_schemes = mvm->cs;
  477. mvm->ciphers[hw->wiphy->n_cipher_suites] = cs->cipher;
  478. hw->wiphy->n_cipher_suites++;
  479. }
  480. ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
  481. hw->wiphy->features |=
  482. NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
  483. NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
  484. NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
  485. hw->sta_data_size = sizeof(struct iwl_mvm_sta);
  486. hw->vif_data_size = sizeof(struct iwl_mvm_vif);
  487. hw->chanctx_data_size = sizeof(u16);
  488. hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  489. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  490. BIT(NL80211_IFTYPE_AP) |
  491. BIT(NL80211_IFTYPE_P2P_GO) |
  492. BIT(NL80211_IFTYPE_P2P_DEVICE) |
  493. BIT(NL80211_IFTYPE_ADHOC);
  494. hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
  495. hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
  496. if (iwl_mvm_is_lar_supported(mvm))
  497. hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
  498. else
  499. hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
  500. REGULATORY_DISABLE_BEACON_HINTS;
  501. hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
  502. hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
  503. hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
  504. hw->wiphy->n_iface_combinations =
  505. ARRAY_SIZE(iwl_mvm_iface_combinations);
  506. hw->wiphy->max_remain_on_channel_duration = 10000;
  507. hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
  508. /* we can compensate an offset of up to 3 channels = 15 MHz */
  509. hw->wiphy->max_adj_channel_rssi_comp = 3 * 5;
  510. /* Extract MAC address */
  511. memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
  512. hw->wiphy->addresses = mvm->addresses;
  513. hw->wiphy->n_addresses = 1;
  514. /* Extract additional MAC addresses if available */
  515. num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
  516. min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
  517. for (i = 1; i < num_mac; i++) {
  518. memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
  519. ETH_ALEN);
  520. mvm->addresses[i].addr[5]++;
  521. hw->wiphy->n_addresses++;
  522. }
  523. iwl_mvm_reset_phy_ctxts(mvm);
  524. hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
  525. hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
  526. BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
  527. BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
  528. IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
  529. if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
  530. mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
  531. else
  532. mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
  533. if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
  534. hw->wiphy->bands[NL80211_BAND_2GHZ] =
  535. &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
  536. if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
  537. hw->wiphy->bands[NL80211_BAND_5GHZ] =
  538. &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
  539. if (fw_has_capa(&mvm->fw->ucode_capa,
  540. IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
  541. fw_has_api(&mvm->fw->ucode_capa,
  542. IWL_UCODE_TLV_API_LQ_SS_PARAMS))
  543. hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
  544. IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
  545. }
  546. hw->wiphy->hw_version = mvm->trans->hw_id;
  547. if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
  548. hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
  549. else
  550. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  551. hw->wiphy->max_sched_scan_reqs = 1;
  552. hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
  553. hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
  554. /* we create the 802.11 header and zero length SSID IE. */
  555. hw->wiphy->max_sched_scan_ie_len =
  556. SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
  557. hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
  558. hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
  559. /*
  560. * the firmware uses u8 for num of iterations, but 0xff is saved for
  561. * infinite loop, so the maximum number of iterations is actually 254.
  562. */
  563. hw->wiphy->max_sched_scan_plan_iterations = 254;
  564. hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
  565. NL80211_FEATURE_LOW_PRIORITY_SCAN |
  566. NL80211_FEATURE_P2P_GO_OPPPS |
  567. NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
  568. NL80211_FEATURE_DYNAMIC_SMPS |
  569. NL80211_FEATURE_STATIC_SMPS |
  570. NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
  571. if (fw_has_capa(&mvm->fw->ucode_capa,
  572. IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
  573. hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
  574. if (fw_has_capa(&mvm->fw->ucode_capa,
  575. IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
  576. hw->wiphy->features |= NL80211_FEATURE_QUIET;
  577. if (fw_has_capa(&mvm->fw->ucode_capa,
  578. IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
  579. hw->wiphy->features |=
  580. NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
  581. if (fw_has_capa(&mvm->fw->ucode_capa,
  582. IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
  583. hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
  584. if (fw_has_api(&mvm->fw->ucode_capa,
  585. IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
  586. wiphy_ext_feature_set(hw->wiphy,
  587. NL80211_EXT_FEATURE_SCAN_START_TIME);
  588. wiphy_ext_feature_set(hw->wiphy,
  589. NL80211_EXT_FEATURE_BSS_PARENT_TSF);
  590. wiphy_ext_feature_set(hw->wiphy,
  591. NL80211_EXT_FEATURE_SET_SCAN_DWELL);
  592. }
  593. mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
  594. #ifdef CONFIG_PM_SLEEP
  595. if (iwl_mvm_is_d0i3_supported(mvm) &&
  596. device_can_wakeup(mvm->trans->dev)) {
  597. mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
  598. hw->wiphy->wowlan = &mvm->wowlan;
  599. }
  600. if (mvm->fw->img[IWL_UCODE_WOWLAN].num_sec &&
  601. mvm->trans->ops->d3_suspend &&
  602. mvm->trans->ops->d3_resume &&
  603. device_can_wakeup(mvm->trans->dev)) {
  604. mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
  605. WIPHY_WOWLAN_DISCONNECT |
  606. WIPHY_WOWLAN_EAP_IDENTITY_REQ |
  607. WIPHY_WOWLAN_RFKILL_RELEASE |
  608. WIPHY_WOWLAN_NET_DETECT;
  609. if (!iwlwifi_mod_params.swcrypto)
  610. mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
  611. WIPHY_WOWLAN_GTK_REKEY_FAILURE |
  612. WIPHY_WOWLAN_4WAY_HANDSHAKE;
  613. mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
  614. mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
  615. mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
  616. mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
  617. mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
  618. hw->wiphy->wowlan = &mvm->wowlan;
  619. }
  620. #endif
  621. #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
  622. /* assign default bcast filtering configuration */
  623. mvm->bcast_filters = iwl_mvm_default_bcast_filters;
  624. #endif
  625. ret = iwl_mvm_leds_init(mvm);
  626. if (ret)
  627. return ret;
  628. if (fw_has_capa(&mvm->fw->ucode_capa,
  629. IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
  630. IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
  631. hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
  632. ieee80211_hw_set(hw, TDLS_WIDER_BW);
  633. }
  634. if (fw_has_capa(&mvm->fw->ucode_capa,
  635. IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
  636. IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
  637. hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
  638. }
  639. hw->netdev_features |= mvm->cfg->features;
  640. if (!iwl_mvm_is_csum_supported(mvm)) {
  641. hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS |
  642. NETIF_F_RXCSUM);
  643. /* We may support SW TX CSUM */
  644. if (IWL_MVM_SW_TX_CSUM_OFFLOAD)
  645. hw->netdev_features |= IWL_TX_CSUM_NETIF_FLAGS;
  646. }
  647. ret = ieee80211_register_hw(mvm->hw);
  648. if (ret)
  649. iwl_mvm_leds_exit(mvm);
  650. mvm->init_status |= IWL_MVM_INIT_STATUS_REG_HW_INIT_COMPLETE;
  651. if (mvm->cfg->vht_mu_mimo_supported)
  652. wiphy_ext_feature_set(hw->wiphy,
  653. NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
  654. return ret;
  655. }
  656. static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
  657. struct ieee80211_sta *sta,
  658. struct sk_buff *skb)
  659. {
  660. struct iwl_mvm_sta *mvmsta;
  661. bool defer = false;
  662. /*
  663. * double check the IN_D0I3 flag both before and after
  664. * taking the spinlock, in order to prevent taking
  665. * the spinlock when not needed.
  666. */
  667. if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
  668. return false;
  669. spin_lock(&mvm->d0i3_tx_lock);
  670. /*
  671. * testing the flag again ensures the skb dequeue
  672. * loop (on d0i3 exit) hasn't run yet.
  673. */
  674. if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
  675. goto out;
  676. mvmsta = iwl_mvm_sta_from_mac80211(sta);
  677. if (mvmsta->sta_id == IWL_MVM_INVALID_STA ||
  678. mvmsta->sta_id != mvm->d0i3_ap_sta_id)
  679. goto out;
  680. __skb_queue_tail(&mvm->d0i3_tx, skb);
  681. ieee80211_stop_queues(mvm->hw);
  682. /* trigger wakeup */
  683. iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
  684. iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
  685. defer = true;
  686. out:
  687. spin_unlock(&mvm->d0i3_tx_lock);
  688. return defer;
  689. }
  690. static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
  691. struct ieee80211_tx_control *control,
  692. struct sk_buff *skb)
  693. {
  694. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  695. struct ieee80211_sta *sta = control->sta;
  696. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  697. struct ieee80211_hdr *hdr = (void *)skb->data;
  698. if (iwl_mvm_is_radio_killed(mvm)) {
  699. IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
  700. goto drop;
  701. }
  702. if (info->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
  703. !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
  704. !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
  705. goto drop;
  706. /* treat non-bufferable MMPDUs on AP interfaces as broadcast */
  707. if ((info->control.vif->type == NL80211_IFTYPE_AP ||
  708. info->control.vif->type == NL80211_IFTYPE_ADHOC) &&
  709. ieee80211_is_mgmt(hdr->frame_control) &&
  710. !ieee80211_is_bufferable_mmpdu(hdr->frame_control))
  711. sta = NULL;
  712. if (sta) {
  713. if (iwl_mvm_defer_tx(mvm, sta, skb))
  714. return;
  715. if (iwl_mvm_tx_skb(mvm, skb, sta))
  716. goto drop;
  717. return;
  718. }
  719. if (iwl_mvm_tx_skb_non_sta(mvm, skb))
  720. goto drop;
  721. return;
  722. drop:
  723. ieee80211_free_txskb(hw, skb);
  724. }
  725. static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
  726. {
  727. if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
  728. return false;
  729. return true;
  730. }
  731. static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
  732. {
  733. if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
  734. return false;
  735. if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
  736. return true;
  737. /* enabled by default */
  738. return true;
  739. }
  740. #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
  741. do { \
  742. if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
  743. break; \
  744. iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
  745. } while (0)
  746. static void
  747. iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  748. struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
  749. enum ieee80211_ampdu_mlme_action action)
  750. {
  751. struct iwl_fw_dbg_trigger_tlv *trig;
  752. struct iwl_fw_dbg_trigger_ba *ba_trig;
  753. if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
  754. return;
  755. trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
  756. ba_trig = (void *)trig->data;
  757. if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
  758. ieee80211_vif_to_wdev(vif), trig))
  759. return;
  760. switch (action) {
  761. case IEEE80211_AMPDU_TX_OPERATIONAL: {
  762. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  763. struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
  764. CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
  765. "TX AGG START: MAC %pM tid %d ssn %d\n",
  766. sta->addr, tid, tid_data->ssn);
  767. break;
  768. }
  769. case IEEE80211_AMPDU_TX_STOP_CONT:
  770. CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
  771. "TX AGG STOP: MAC %pM tid %d\n",
  772. sta->addr, tid);
  773. break;
  774. case IEEE80211_AMPDU_RX_START:
  775. CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
  776. "RX AGG START: MAC %pM tid %d ssn %d\n",
  777. sta->addr, tid, rx_ba_ssn);
  778. break;
  779. case IEEE80211_AMPDU_RX_STOP:
  780. CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
  781. "RX AGG STOP: MAC %pM tid %d\n",
  782. sta->addr, tid);
  783. break;
  784. default:
  785. break;
  786. }
  787. }
  788. static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
  789. struct ieee80211_vif *vif,
  790. struct ieee80211_ampdu_params *params)
  791. {
  792. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  793. int ret;
  794. bool tx_agg_ref = false;
  795. struct ieee80211_sta *sta = params->sta;
  796. enum ieee80211_ampdu_mlme_action action = params->action;
  797. u16 tid = params->tid;
  798. u16 *ssn = &params->ssn;
  799. u8 buf_size = params->buf_size;
  800. bool amsdu = params->amsdu;
  801. u16 timeout = params->timeout;
  802. IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
  803. sta->addr, tid, action);
  804. if (!(mvm->nvm_data->sku_cap_11n_enable))
  805. return -EACCES;
  806. /* return from D0i3 before starting a new Tx aggregation */
  807. switch (action) {
  808. case IEEE80211_AMPDU_TX_START:
  809. case IEEE80211_AMPDU_TX_STOP_CONT:
  810. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  811. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  812. case IEEE80211_AMPDU_TX_OPERATIONAL:
  813. /*
  814. * for tx start, wait synchronously until D0i3 exit to
  815. * get the correct sequence number for the tid.
  816. * additionally, some other ampdu actions use direct
  817. * target access, which is not handled automatically
  818. * by the trans layer (unlike commands), so wait for
  819. * d0i3 exit in these cases as well.
  820. */
  821. ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
  822. if (ret)
  823. return ret;
  824. tx_agg_ref = true;
  825. break;
  826. default:
  827. break;
  828. }
  829. mutex_lock(&mvm->mutex);
  830. switch (action) {
  831. case IEEE80211_AMPDU_RX_START:
  832. if (!iwl_enable_rx_ampdu(mvm->cfg)) {
  833. ret = -EINVAL;
  834. break;
  835. }
  836. ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
  837. timeout);
  838. break;
  839. case IEEE80211_AMPDU_RX_STOP:
  840. ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
  841. timeout);
  842. break;
  843. case IEEE80211_AMPDU_TX_START:
  844. if (!iwl_enable_tx_ampdu(mvm->cfg)) {
  845. ret = -EINVAL;
  846. break;
  847. }
  848. ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
  849. break;
  850. case IEEE80211_AMPDU_TX_STOP_CONT:
  851. ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
  852. break;
  853. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  854. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  855. ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
  856. break;
  857. case IEEE80211_AMPDU_TX_OPERATIONAL:
  858. ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid,
  859. buf_size, amsdu);
  860. break;
  861. default:
  862. WARN_ON_ONCE(1);
  863. ret = -EINVAL;
  864. break;
  865. }
  866. if (!ret) {
  867. u16 rx_ba_ssn = 0;
  868. if (action == IEEE80211_AMPDU_RX_START)
  869. rx_ba_ssn = *ssn;
  870. iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
  871. rx_ba_ssn, action);
  872. }
  873. mutex_unlock(&mvm->mutex);
  874. /*
  875. * If the tid is marked as started, we won't use it for offloaded
  876. * traffic on the next D0i3 entry. It's safe to unref.
  877. */
  878. if (tx_agg_ref)
  879. iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
  880. return ret;
  881. }
  882. static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
  883. struct ieee80211_vif *vif)
  884. {
  885. struct iwl_mvm *mvm = data;
  886. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  887. mvmvif->uploaded = false;
  888. mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
  889. spin_lock_bh(&mvm->time_event_lock);
  890. iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
  891. spin_unlock_bh(&mvm->time_event_lock);
  892. mvmvif->phy_ctxt = NULL;
  893. memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
  894. }
  895. static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
  896. {
  897. /* clear the D3 reconfig, we only need it to avoid dumping a
  898. * firmware coredump on reconfiguration, we shouldn't do that
  899. * on D3->D0 transition
  900. */
  901. if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status)) {
  902. mvm->fwrt.dump.desc = &iwl_dump_desc_assert;
  903. iwl_fw_error_dump(&mvm->fwrt);
  904. }
  905. /* cleanup all stale references (scan, roc), but keep the
  906. * ucode_down ref until reconfig is complete
  907. */
  908. iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
  909. iwl_mvm_stop_device(mvm);
  910. mvm->scan_status = 0;
  911. mvm->ps_disabled = false;
  912. mvm->calibrating = false;
  913. /* just in case one was running */
  914. iwl_mvm_cleanup_roc_te(mvm);
  915. ieee80211_remain_on_channel_expired(mvm->hw);
  916. /*
  917. * cleanup all interfaces, even inactive ones, as some might have
  918. * gone down during the HW restart
  919. */
  920. ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
  921. mvm->p2p_device_vif = NULL;
  922. mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA;
  923. iwl_mvm_reset_phy_ctxts(mvm);
  924. memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
  925. memset(mvm->sta_deferred_frames, 0, sizeof(mvm->sta_deferred_frames));
  926. memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
  927. memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
  928. ieee80211_wake_queues(mvm->hw);
  929. /* clear any stale d0i3 state */
  930. clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
  931. mvm->vif_count = 0;
  932. mvm->rx_ba_sessions = 0;
  933. mvm->fwrt.dump.conf = FW_DBG_INVALID;
  934. /* keep statistics ticking */
  935. iwl_mvm_accu_radio_stats(mvm);
  936. }
  937. int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
  938. {
  939. int ret;
  940. lockdep_assert_held(&mvm->mutex);
  941. if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) {
  942. /*
  943. * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
  944. * so later code will - from now on - see that we're doing it.
  945. */
  946. set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
  947. clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
  948. /* Clean up some internal and mac80211 state on restart */
  949. iwl_mvm_restart_cleanup(mvm);
  950. } else {
  951. /* Hold the reference to prevent runtime suspend while
  952. * the start procedure runs. It's a bit confusing
  953. * that the UCODE_DOWN reference is taken, but it just
  954. * means "UCODE is not UP yet". ( TODO: rename this
  955. * reference).
  956. */
  957. iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
  958. }
  959. ret = iwl_mvm_up(mvm);
  960. if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
  961. /* Something went wrong - we need to finish some cleanup
  962. * that normally iwl_mvm_mac_restart_complete() below
  963. * would do.
  964. */
  965. clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
  966. iwl_mvm_d0i3_enable_tx(mvm, NULL);
  967. }
  968. return ret;
  969. }
  970. static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
  971. {
  972. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  973. int ret;
  974. /* Some hw restart cleanups must not hold the mutex */
  975. if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
  976. /*
  977. * Make sure we are out of d0i3. This is needed
  978. * to make sure the reference accounting is correct
  979. * (and there is no stale d0i3_exit_work).
  980. */
  981. wait_event_timeout(mvm->d0i3_exit_waitq,
  982. !test_bit(IWL_MVM_STATUS_IN_D0I3,
  983. &mvm->status),
  984. HZ);
  985. }
  986. mutex_lock(&mvm->mutex);
  987. ret = __iwl_mvm_mac_start(mvm);
  988. mutex_unlock(&mvm->mutex);
  989. return ret;
  990. }
  991. static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
  992. {
  993. int ret;
  994. mutex_lock(&mvm->mutex);
  995. clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
  996. iwl_mvm_d0i3_enable_tx(mvm, NULL);
  997. ret = iwl_mvm_update_quotas(mvm, true, NULL);
  998. if (ret)
  999. IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
  1000. ret);
  1001. /* allow transport/FW low power modes */
  1002. iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
  1003. /*
  1004. * If we have TDLS peers, remove them. We don't know the last seqno/PN
  1005. * of packets the FW sent out, so we must reconnect.
  1006. */
  1007. iwl_mvm_teardown_tdls_peers(mvm);
  1008. mutex_unlock(&mvm->mutex);
  1009. }
  1010. static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
  1011. {
  1012. if (iwl_mvm_is_d0i3_supported(mvm) &&
  1013. iwl_mvm_enter_d0i3_on_suspend(mvm))
  1014. WARN_ONCE(!wait_event_timeout(mvm->d0i3_exit_waitq,
  1015. !test_bit(IWL_MVM_STATUS_IN_D0I3,
  1016. &mvm->status),
  1017. HZ),
  1018. "D0i3 exit on resume timed out\n");
  1019. }
  1020. static void
  1021. iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
  1022. enum ieee80211_reconfig_type reconfig_type)
  1023. {
  1024. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1025. switch (reconfig_type) {
  1026. case IEEE80211_RECONFIG_TYPE_RESTART:
  1027. iwl_mvm_restart_complete(mvm);
  1028. break;
  1029. case IEEE80211_RECONFIG_TYPE_SUSPEND:
  1030. iwl_mvm_resume_complete(mvm);
  1031. break;
  1032. }
  1033. }
  1034. void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
  1035. {
  1036. lockdep_assert_held(&mvm->mutex);
  1037. /* firmware counters are obviously reset now, but we shouldn't
  1038. * partially track so also clear the fw_reset_accu counters.
  1039. */
  1040. memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
  1041. /* async_handlers_wk is now blocked */
  1042. /*
  1043. * The work item could be running or queued if the
  1044. * ROC time event stops just as we get here.
  1045. */
  1046. flush_work(&mvm->roc_done_wk);
  1047. iwl_mvm_stop_device(mvm);
  1048. iwl_mvm_async_handlers_purge(mvm);
  1049. /* async_handlers_list is empty and will stay empty: HW is stopped */
  1050. /* the fw is stopped, the aux sta is dead: clean up driver state */
  1051. iwl_mvm_del_aux_sta(mvm);
  1052. /*
  1053. * Clear IN_HW_RESTART flag when stopping the hw (as restart_complete()
  1054. * won't be called in this case).
  1055. * But make sure to cleanup interfaces that have gone down before/during
  1056. * HW restart was requested.
  1057. */
  1058. if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
  1059. ieee80211_iterate_interfaces(mvm->hw, 0,
  1060. iwl_mvm_cleanup_iterator, mvm);
  1061. /* We shouldn't have any UIDs still set. Loop over all the UIDs to
  1062. * make sure there's nothing left there and warn if any is found.
  1063. */
  1064. if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
  1065. int i;
  1066. for (i = 0; i < mvm->max_scans; i++) {
  1067. if (WARN_ONCE(mvm->scan_uid_status[i],
  1068. "UMAC scan UID %d status was not cleaned\n",
  1069. i))
  1070. mvm->scan_uid_status[i] = 0;
  1071. }
  1072. }
  1073. }
  1074. static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
  1075. {
  1076. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1077. flush_work(&mvm->d0i3_exit_work);
  1078. flush_work(&mvm->async_handlers_wk);
  1079. flush_work(&mvm->add_stream_wk);
  1080. /*
  1081. * Lock and clear the firmware running bit here already, so that
  1082. * new commands coming in elsewhere, e.g. from debugfs, will not
  1083. * be able to proceed. This is important here because one of those
  1084. * debugfs files causes the firmware dump to be triggered, and if we
  1085. * don't stop debugfs accesses before canceling that it could be
  1086. * retriggered after we flush it but before we've cleared the bit.
  1087. */
  1088. clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
  1089. iwl_fw_cancel_dump(&mvm->fwrt);
  1090. cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
  1091. cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
  1092. iwl_fw_free_dump_desc(&mvm->fwrt);
  1093. mutex_lock(&mvm->mutex);
  1094. __iwl_mvm_mac_stop(mvm);
  1095. mutex_unlock(&mvm->mutex);
  1096. /*
  1097. * The worker might have been waiting for the mutex, let it run and
  1098. * discover that its list is now empty.
  1099. */
  1100. cancel_work_sync(&mvm->async_handlers_wk);
  1101. }
  1102. static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
  1103. {
  1104. u16 i;
  1105. lockdep_assert_held(&mvm->mutex);
  1106. for (i = 0; i < NUM_PHY_CTX; i++)
  1107. if (!mvm->phy_ctxts[i].ref)
  1108. return &mvm->phy_ctxts[i];
  1109. IWL_ERR(mvm, "No available PHY context\n");
  1110. return NULL;
  1111. }
  1112. static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  1113. s16 tx_power)
  1114. {
  1115. struct iwl_dev_tx_power_cmd cmd = {
  1116. .v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
  1117. .v3.mac_context_id =
  1118. cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
  1119. .v3.pwr_restriction = cpu_to_le16(8 * tx_power),
  1120. };
  1121. int len = sizeof(cmd);
  1122. if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
  1123. cmd.v3.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
  1124. if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
  1125. len = sizeof(cmd.v3);
  1126. return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
  1127. }
  1128. static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
  1129. struct ieee80211_vif *vif)
  1130. {
  1131. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1132. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1133. int ret;
  1134. mvmvif->mvm = mvm;
  1135. /*
  1136. * make sure D0i3 exit is completed, otherwise a target access
  1137. * during tx queue configuration could be done when still in
  1138. * D0i3 state.
  1139. */
  1140. ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
  1141. if (ret)
  1142. return ret;
  1143. /*
  1144. * Not much to do here. The stack will not allow interface
  1145. * types or combinations that we didn't advertise, so we
  1146. * don't really have to check the types.
  1147. */
  1148. mutex_lock(&mvm->mutex);
  1149. /* make sure that beacon statistics don't go backwards with FW reset */
  1150. if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
  1151. mvmvif->beacon_stats.accu_num_beacons +=
  1152. mvmvif->beacon_stats.num_beacons;
  1153. /* Allocate resources for the MAC context, and add it to the fw */
  1154. ret = iwl_mvm_mac_ctxt_init(mvm, vif);
  1155. if (ret)
  1156. goto out_unlock;
  1157. /* Counting number of interfaces is needed for legacy PM */
  1158. if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
  1159. mvm->vif_count++;
  1160. /*
  1161. * The AP binding flow can be done only after the beacon
  1162. * template is configured (which happens only in the mac80211
  1163. * start_ap() flow), and adding the broadcast station can happen
  1164. * only after the binding.
  1165. * In addition, since modifying the MAC before adding a bcast
  1166. * station is not allowed by the FW, delay the adding of MAC context to
  1167. * the point where we can also add the bcast station.
  1168. * In short: there's not much we can do at this point, other than
  1169. * allocating resources :)
  1170. */
  1171. if (vif->type == NL80211_IFTYPE_AP ||
  1172. vif->type == NL80211_IFTYPE_ADHOC) {
  1173. ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
  1174. if (ret) {
  1175. IWL_ERR(mvm, "Failed to allocate bcast sta\n");
  1176. goto out_release;
  1177. }
  1178. /*
  1179. * Only queue for this station is the mcast queue,
  1180. * which shouldn't be in TFD mask anyway
  1181. */
  1182. ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta,
  1183. 0, vif->type,
  1184. IWL_STA_MULTICAST);
  1185. if (ret)
  1186. goto out_release;
  1187. iwl_mvm_vif_dbgfs_register(mvm, vif);
  1188. goto out_unlock;
  1189. }
  1190. mvmvif->features |= hw->netdev_features;
  1191. ret = iwl_mvm_mac_ctxt_add(mvm, vif);
  1192. if (ret)
  1193. goto out_release;
  1194. ret = iwl_mvm_power_update_mac(mvm);
  1195. if (ret)
  1196. goto out_remove_mac;
  1197. /* beacon filtering */
  1198. ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
  1199. if (ret)
  1200. goto out_remove_mac;
  1201. if (!mvm->bf_allowed_vif &&
  1202. vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
  1203. mvm->bf_allowed_vif = mvmvif;
  1204. vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
  1205. IEEE80211_VIF_SUPPORTS_CQM_RSSI;
  1206. }
  1207. /*
  1208. * P2P_DEVICE interface does not have a channel context assigned to it,
  1209. * so a dedicated PHY context is allocated to it and the corresponding
  1210. * MAC context is bound to it at this stage.
  1211. */
  1212. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  1213. mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
  1214. if (!mvmvif->phy_ctxt) {
  1215. ret = -ENOSPC;
  1216. goto out_free_bf;
  1217. }
  1218. iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
  1219. ret = iwl_mvm_binding_add_vif(mvm, vif);
  1220. if (ret)
  1221. goto out_unref_phy;
  1222. ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif);
  1223. if (ret)
  1224. goto out_unbind;
  1225. /* Save a pointer to p2p device vif, so it can later be used to
  1226. * update the p2p device MAC when a GO is started/stopped */
  1227. mvm->p2p_device_vif = vif;
  1228. }
  1229. iwl_mvm_vif_dbgfs_register(mvm, vif);
  1230. goto out_unlock;
  1231. out_unbind:
  1232. iwl_mvm_binding_remove_vif(mvm, vif);
  1233. out_unref_phy:
  1234. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  1235. out_free_bf:
  1236. if (mvm->bf_allowed_vif == mvmvif) {
  1237. mvm->bf_allowed_vif = NULL;
  1238. vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
  1239. IEEE80211_VIF_SUPPORTS_CQM_RSSI);
  1240. }
  1241. out_remove_mac:
  1242. mvmvif->phy_ctxt = NULL;
  1243. iwl_mvm_mac_ctxt_remove(mvm, vif);
  1244. out_release:
  1245. if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
  1246. mvm->vif_count--;
  1247. out_unlock:
  1248. mutex_unlock(&mvm->mutex);
  1249. iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
  1250. return ret;
  1251. }
  1252. static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
  1253. struct ieee80211_vif *vif)
  1254. {
  1255. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  1256. /*
  1257. * Flush the ROC worker which will flush the OFFCHANNEL queue.
  1258. * We assume here that all the packets sent to the OFFCHANNEL
  1259. * queue are sent in ROC session.
  1260. */
  1261. flush_work(&mvm->roc_done_wk);
  1262. }
  1263. }
  1264. static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
  1265. struct ieee80211_vif *vif)
  1266. {
  1267. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1268. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1269. iwl_mvm_prepare_mac_removal(mvm, vif);
  1270. mutex_lock(&mvm->mutex);
  1271. if (mvm->bf_allowed_vif == mvmvif) {
  1272. mvm->bf_allowed_vif = NULL;
  1273. vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
  1274. IEEE80211_VIF_SUPPORTS_CQM_RSSI);
  1275. }
  1276. iwl_mvm_vif_dbgfs_clean(mvm, vif);
  1277. /*
  1278. * For AP/GO interface, the tear down of the resources allocated to the
  1279. * interface is be handled as part of the stop_ap flow.
  1280. */
  1281. if (vif->type == NL80211_IFTYPE_AP ||
  1282. vif->type == NL80211_IFTYPE_ADHOC) {
  1283. #ifdef CONFIG_NL80211_TESTMODE
  1284. if (vif == mvm->noa_vif) {
  1285. mvm->noa_vif = NULL;
  1286. mvm->noa_duration = 0;
  1287. }
  1288. #endif
  1289. iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta);
  1290. iwl_mvm_dealloc_bcast_sta(mvm, vif);
  1291. goto out_release;
  1292. }
  1293. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  1294. mvm->p2p_device_vif = NULL;
  1295. iwl_mvm_rm_p2p_bcast_sta(mvm, vif);
  1296. iwl_mvm_binding_remove_vif(mvm, vif);
  1297. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  1298. mvmvif->phy_ctxt = NULL;
  1299. }
  1300. if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
  1301. mvm->vif_count--;
  1302. iwl_mvm_power_update_mac(mvm);
  1303. iwl_mvm_mac_ctxt_remove(mvm, vif);
  1304. out_release:
  1305. mutex_unlock(&mvm->mutex);
  1306. }
  1307. static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
  1308. {
  1309. return 0;
  1310. }
  1311. struct iwl_mvm_mc_iter_data {
  1312. struct iwl_mvm *mvm;
  1313. int port_id;
  1314. };
  1315. static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
  1316. struct ieee80211_vif *vif)
  1317. {
  1318. struct iwl_mvm_mc_iter_data *data = _data;
  1319. struct iwl_mvm *mvm = data->mvm;
  1320. struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
  1321. struct iwl_host_cmd hcmd = {
  1322. .id = MCAST_FILTER_CMD,
  1323. .flags = CMD_ASYNC,
  1324. .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
  1325. };
  1326. int ret, len;
  1327. /* if we don't have free ports, mcast frames will be dropped */
  1328. if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
  1329. return;
  1330. if (vif->type != NL80211_IFTYPE_STATION ||
  1331. !vif->bss_conf.assoc)
  1332. return;
  1333. cmd->port_id = data->port_id++;
  1334. memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
  1335. len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
  1336. hcmd.len[0] = len;
  1337. hcmd.data[0] = cmd;
  1338. ret = iwl_mvm_send_cmd(mvm, &hcmd);
  1339. if (ret)
  1340. IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
  1341. }
  1342. static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
  1343. {
  1344. struct iwl_mvm_mc_iter_data iter_data = {
  1345. .mvm = mvm,
  1346. };
  1347. lockdep_assert_held(&mvm->mutex);
  1348. if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
  1349. return;
  1350. ieee80211_iterate_active_interfaces_atomic(
  1351. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  1352. iwl_mvm_mc_iface_iterator, &iter_data);
  1353. }
  1354. static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
  1355. struct netdev_hw_addr_list *mc_list)
  1356. {
  1357. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1358. struct iwl_mcast_filter_cmd *cmd;
  1359. struct netdev_hw_addr *addr;
  1360. int addr_count;
  1361. bool pass_all;
  1362. int len;
  1363. addr_count = netdev_hw_addr_list_count(mc_list);
  1364. pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
  1365. IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
  1366. if (pass_all)
  1367. addr_count = 0;
  1368. len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
  1369. cmd = kzalloc(len, GFP_ATOMIC);
  1370. if (!cmd)
  1371. return 0;
  1372. if (pass_all) {
  1373. cmd->pass_all = 1;
  1374. return (u64)(unsigned long)cmd;
  1375. }
  1376. netdev_hw_addr_list_for_each(addr, mc_list) {
  1377. IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
  1378. cmd->count, addr->addr);
  1379. memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
  1380. addr->addr, ETH_ALEN);
  1381. cmd->count++;
  1382. }
  1383. return (u64)(unsigned long)cmd;
  1384. }
  1385. static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
  1386. unsigned int changed_flags,
  1387. unsigned int *total_flags,
  1388. u64 multicast)
  1389. {
  1390. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1391. struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
  1392. mutex_lock(&mvm->mutex);
  1393. /* replace previous configuration */
  1394. kfree(mvm->mcast_filter_cmd);
  1395. mvm->mcast_filter_cmd = cmd;
  1396. if (!cmd)
  1397. goto out;
  1398. if (changed_flags & FIF_ALLMULTI)
  1399. cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
  1400. if (cmd->pass_all)
  1401. cmd->count = 0;
  1402. iwl_mvm_recalc_multicast(mvm);
  1403. out:
  1404. mutex_unlock(&mvm->mutex);
  1405. *total_flags = 0;
  1406. }
  1407. static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
  1408. struct ieee80211_vif *vif,
  1409. unsigned int filter_flags,
  1410. unsigned int changed_flags)
  1411. {
  1412. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1413. /* We support only filter for probe requests */
  1414. if (!(changed_flags & FIF_PROBE_REQ))
  1415. return;
  1416. /* Supported only for p2p client interfaces */
  1417. if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
  1418. !vif->p2p)
  1419. return;
  1420. mutex_lock(&mvm->mutex);
  1421. iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
  1422. mutex_unlock(&mvm->mutex);
  1423. }
  1424. #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
  1425. struct iwl_bcast_iter_data {
  1426. struct iwl_mvm *mvm;
  1427. struct iwl_bcast_filter_cmd *cmd;
  1428. u8 current_filter;
  1429. };
  1430. static void
  1431. iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
  1432. const struct iwl_fw_bcast_filter *in_filter,
  1433. struct iwl_fw_bcast_filter *out_filter)
  1434. {
  1435. struct iwl_fw_bcast_filter_attr *attr;
  1436. int i;
  1437. memcpy(out_filter, in_filter, sizeof(*out_filter));
  1438. for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
  1439. attr = &out_filter->attrs[i];
  1440. if (!attr->mask)
  1441. break;
  1442. switch (attr->reserved1) {
  1443. case cpu_to_le16(BC_FILTER_MAGIC_IP):
  1444. if (vif->bss_conf.arp_addr_cnt != 1) {
  1445. attr->mask = 0;
  1446. continue;
  1447. }
  1448. attr->val = vif->bss_conf.arp_addr_list[0];
  1449. break;
  1450. case cpu_to_le16(BC_FILTER_MAGIC_MAC):
  1451. attr->val = *(__be32 *)&vif->addr[2];
  1452. break;
  1453. default:
  1454. break;
  1455. }
  1456. attr->reserved1 = 0;
  1457. out_filter->num_attrs++;
  1458. }
  1459. }
  1460. static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
  1461. struct ieee80211_vif *vif)
  1462. {
  1463. struct iwl_bcast_iter_data *data = _data;
  1464. struct iwl_mvm *mvm = data->mvm;
  1465. struct iwl_bcast_filter_cmd *cmd = data->cmd;
  1466. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1467. struct iwl_fw_bcast_mac *bcast_mac;
  1468. int i;
  1469. if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
  1470. return;
  1471. bcast_mac = &cmd->macs[mvmvif->id];
  1472. /*
  1473. * enable filtering only for associated stations, but not for P2P
  1474. * Clients
  1475. */
  1476. if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
  1477. !vif->bss_conf.assoc)
  1478. return;
  1479. bcast_mac->default_discard = 1;
  1480. /* copy all configured filters */
  1481. for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
  1482. /*
  1483. * Make sure we don't exceed our filters limit.
  1484. * if there is still a valid filter to be configured,
  1485. * be on the safe side and just allow bcast for this mac.
  1486. */
  1487. if (WARN_ON_ONCE(data->current_filter >=
  1488. ARRAY_SIZE(cmd->filters))) {
  1489. bcast_mac->default_discard = 0;
  1490. bcast_mac->attached_filters = 0;
  1491. break;
  1492. }
  1493. iwl_mvm_set_bcast_filter(vif,
  1494. &mvm->bcast_filters[i],
  1495. &cmd->filters[data->current_filter]);
  1496. /* skip current filter if it contains no attributes */
  1497. if (!cmd->filters[data->current_filter].num_attrs)
  1498. continue;
  1499. /* attach the filter to current mac */
  1500. bcast_mac->attached_filters |=
  1501. cpu_to_le16(BIT(data->current_filter));
  1502. data->current_filter++;
  1503. }
  1504. }
  1505. bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
  1506. struct iwl_bcast_filter_cmd *cmd)
  1507. {
  1508. struct iwl_bcast_iter_data iter_data = {
  1509. .mvm = mvm,
  1510. .cmd = cmd,
  1511. };
  1512. if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
  1513. return false;
  1514. memset(cmd, 0, sizeof(*cmd));
  1515. cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
  1516. cmd->max_macs = ARRAY_SIZE(cmd->macs);
  1517. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1518. /* use debugfs filters/macs if override is configured */
  1519. if (mvm->dbgfs_bcast_filtering.override) {
  1520. memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
  1521. sizeof(cmd->filters));
  1522. memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
  1523. sizeof(cmd->macs));
  1524. return true;
  1525. }
  1526. #endif
  1527. /* if no filters are configured, do nothing */
  1528. if (!mvm->bcast_filters)
  1529. return false;
  1530. /* configure and attach these filters for each associated sta vif */
  1531. ieee80211_iterate_active_interfaces(
  1532. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  1533. iwl_mvm_bcast_filter_iterator, &iter_data);
  1534. return true;
  1535. }
  1536. static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
  1537. {
  1538. struct iwl_bcast_filter_cmd cmd;
  1539. if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
  1540. return 0;
  1541. if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
  1542. return 0;
  1543. return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
  1544. sizeof(cmd), &cmd);
  1545. }
  1546. #else
  1547. static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
  1548. {
  1549. return 0;
  1550. }
  1551. #endif
  1552. static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
  1553. struct ieee80211_vif *vif)
  1554. {
  1555. struct iwl_mu_group_mgmt_cmd cmd = {};
  1556. memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
  1557. WLAN_MEMBERSHIP_LEN);
  1558. memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
  1559. WLAN_USER_POSITION_LEN);
  1560. return iwl_mvm_send_cmd_pdu(mvm,
  1561. WIDE_ID(DATA_PATH_GROUP,
  1562. UPDATE_MU_GROUPS_CMD),
  1563. 0, sizeof(cmd), &cmd);
  1564. }
  1565. static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
  1566. struct ieee80211_vif *vif)
  1567. {
  1568. if (vif->mu_mimo_owner) {
  1569. struct iwl_mu_group_mgmt_notif *notif = _data;
  1570. /*
  1571. * MU-MIMO Group Id action frame is little endian. We treat
  1572. * the data received from firmware as if it came from the
  1573. * action frame, so no conversion is needed.
  1574. */
  1575. ieee80211_update_mu_groups(vif,
  1576. (u8 *)&notif->membership_status,
  1577. (u8 *)&notif->user_position);
  1578. }
  1579. }
  1580. void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
  1581. struct iwl_rx_cmd_buffer *rxb)
  1582. {
  1583. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1584. struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
  1585. ieee80211_iterate_active_interfaces_atomic(
  1586. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  1587. iwl_mvm_mu_mimo_iface_iterator, notif);
  1588. }
  1589. static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
  1590. struct ieee80211_vif *vif,
  1591. struct ieee80211_bss_conf *bss_conf,
  1592. u32 changes)
  1593. {
  1594. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1595. int ret;
  1596. /*
  1597. * Re-calculate the tsf id, as the master-slave relations depend on the
  1598. * beacon interval, which was not known when the station interface was
  1599. * added.
  1600. */
  1601. if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
  1602. iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
  1603. if (changes & BSS_CHANGED_ASSOC && !bss_conf->assoc &&
  1604. mvmvif->lqm_active)
  1605. iwl_mvm_send_lqm_cmd(vif, LQM_CMD_OPERATION_STOP_MEASUREMENT,
  1606. 0, 0);
  1607. /*
  1608. * If we're not associated yet, take the (new) BSSID before associating
  1609. * so the firmware knows. If we're already associated, then use the old
  1610. * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
  1611. * branch for disassociation below.
  1612. */
  1613. if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
  1614. memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
  1615. ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
  1616. if (ret)
  1617. IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
  1618. /* after sending it once, adopt mac80211 data */
  1619. memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
  1620. mvmvif->associated = bss_conf->assoc;
  1621. if (changes & BSS_CHANGED_ASSOC) {
  1622. if (bss_conf->assoc) {
  1623. /* clear statistics to get clean beacon counter */
  1624. iwl_mvm_request_statistics(mvm, true);
  1625. memset(&mvmvif->beacon_stats, 0,
  1626. sizeof(mvmvif->beacon_stats));
  1627. /* add quota for this interface */
  1628. ret = iwl_mvm_update_quotas(mvm, true, NULL);
  1629. if (ret) {
  1630. IWL_ERR(mvm, "failed to update quotas\n");
  1631. return;
  1632. }
  1633. if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
  1634. &mvm->status)) {
  1635. /*
  1636. * If we're restarting then the firmware will
  1637. * obviously have lost synchronisation with
  1638. * the AP. It will attempt to synchronise by
  1639. * itself, but we can make it more reliable by
  1640. * scheduling a session protection time event.
  1641. *
  1642. * The firmware needs to receive a beacon to
  1643. * catch up with synchronisation, use 110% of
  1644. * the beacon interval.
  1645. *
  1646. * Set a large maximum delay to allow for more
  1647. * than a single interface.
  1648. */
  1649. u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
  1650. iwl_mvm_protect_session(mvm, vif, dur, dur,
  1651. 5 * dur, false);
  1652. }
  1653. iwl_mvm_sf_update(mvm, vif, false);
  1654. iwl_mvm_power_vif_assoc(mvm, vif);
  1655. if (vif->p2p) {
  1656. iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
  1657. iwl_mvm_update_smps(mvm, vif,
  1658. IWL_MVM_SMPS_REQ_PROT,
  1659. IEEE80211_SMPS_DYNAMIC);
  1660. }
  1661. } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
  1662. /*
  1663. * If update fails - SF might be running in associated
  1664. * mode while disassociated - which is forbidden.
  1665. */
  1666. WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
  1667. "Failed to update SF upon disassociation\n");
  1668. /*
  1669. * If we get an assert during the connection (after the
  1670. * station has been added, but before the vif is set
  1671. * to associated), mac80211 will re-add the station and
  1672. * then configure the vif. Since the vif is not
  1673. * associated, we would remove the station here and
  1674. * this would fail the recovery.
  1675. */
  1676. if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
  1677. &mvm->status)) {
  1678. /*
  1679. * Remove AP station now that
  1680. * the MAC is unassoc
  1681. */
  1682. ret = iwl_mvm_rm_sta_id(mvm, vif,
  1683. mvmvif->ap_sta_id);
  1684. if (ret)
  1685. IWL_ERR(mvm,
  1686. "failed to remove AP station\n");
  1687. if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
  1688. mvm->d0i3_ap_sta_id =
  1689. IWL_MVM_INVALID_STA;
  1690. mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
  1691. }
  1692. /* remove quota for this interface */
  1693. ret = iwl_mvm_update_quotas(mvm, false, NULL);
  1694. if (ret)
  1695. IWL_ERR(mvm, "failed to update quotas\n");
  1696. if (vif->p2p)
  1697. iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
  1698. /* this will take the cleared BSSID from bss_conf */
  1699. ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
  1700. if (ret)
  1701. IWL_ERR(mvm,
  1702. "failed to update MAC %pM (clear after unassoc)\n",
  1703. vif->addr);
  1704. }
  1705. /*
  1706. * The firmware tracks the MU-MIMO group on its own.
  1707. * However, on HW restart we should restore this data.
  1708. */
  1709. if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
  1710. (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) {
  1711. ret = iwl_mvm_update_mu_groups(mvm, vif);
  1712. if (ret)
  1713. IWL_ERR(mvm,
  1714. "failed to update VHT MU_MIMO groups\n");
  1715. }
  1716. iwl_mvm_recalc_multicast(mvm);
  1717. iwl_mvm_configure_bcast_filter(mvm);
  1718. /* reset rssi values */
  1719. mvmvif->bf_data.ave_beacon_signal = 0;
  1720. iwl_mvm_bt_coex_vif_change(mvm);
  1721. iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
  1722. IEEE80211_SMPS_AUTOMATIC);
  1723. if (fw_has_capa(&mvm->fw->ucode_capa,
  1724. IWL_UCODE_TLV_CAPA_UMAC_SCAN))
  1725. iwl_mvm_config_scan(mvm);
  1726. }
  1727. if (changes & BSS_CHANGED_BEACON_INFO) {
  1728. /*
  1729. * We received a beacon from the associated AP so
  1730. * remove the session protection.
  1731. */
  1732. iwl_mvm_stop_session_protection(mvm, vif);
  1733. iwl_mvm_sf_update(mvm, vif, false);
  1734. WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
  1735. }
  1736. if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
  1737. /*
  1738. * Send power command on every beacon change,
  1739. * because we may have not enabled beacon abort yet.
  1740. */
  1741. BSS_CHANGED_BEACON_INFO)) {
  1742. ret = iwl_mvm_power_update_mac(mvm);
  1743. if (ret)
  1744. IWL_ERR(mvm, "failed to update power mode\n");
  1745. }
  1746. if (changes & BSS_CHANGED_TXPOWER) {
  1747. IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
  1748. bss_conf->txpower);
  1749. iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
  1750. }
  1751. if (changes & BSS_CHANGED_CQM) {
  1752. IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
  1753. /* reset cqm events tracking */
  1754. mvmvif->bf_data.last_cqm_event = 0;
  1755. if (mvmvif->bf_data.bf_enabled) {
  1756. ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
  1757. if (ret)
  1758. IWL_ERR(mvm,
  1759. "failed to update CQM thresholds\n");
  1760. }
  1761. }
  1762. if (changes & BSS_CHANGED_ARP_FILTER) {
  1763. IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
  1764. iwl_mvm_configure_bcast_filter(mvm);
  1765. }
  1766. }
  1767. static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
  1768. struct ieee80211_vif *vif)
  1769. {
  1770. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1771. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1772. int ret;
  1773. /*
  1774. * iwl_mvm_mac_ctxt_add() might read directly from the device
  1775. * (the system time), so make sure it is available.
  1776. */
  1777. ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
  1778. if (ret)
  1779. return ret;
  1780. mutex_lock(&mvm->mutex);
  1781. /* Send the beacon template */
  1782. ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
  1783. if (ret)
  1784. goto out_unlock;
  1785. /*
  1786. * Re-calculate the tsf id, as the master-slave relations depend on the
  1787. * beacon interval, which was not known when the AP interface was added.
  1788. */
  1789. if (vif->type == NL80211_IFTYPE_AP)
  1790. iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
  1791. mvmvif->ap_assoc_sta_count = 0;
  1792. /* Add the mac context */
  1793. ret = iwl_mvm_mac_ctxt_add(mvm, vif);
  1794. if (ret)
  1795. goto out_unlock;
  1796. /* Perform the binding */
  1797. ret = iwl_mvm_binding_add_vif(mvm, vif);
  1798. if (ret)
  1799. goto out_remove;
  1800. ret = iwl_mvm_add_mcast_sta(mvm, vif);
  1801. if (ret)
  1802. goto out_unbind;
  1803. /* Send the bcast station. At this stage the TBTT and DTIM time events
  1804. * are added and applied to the scheduler */
  1805. ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
  1806. if (ret)
  1807. goto out_rm_mcast;
  1808. /* must be set before quota calculations */
  1809. mvmvif->ap_ibss_active = true;
  1810. /* power updated needs to be done before quotas */
  1811. iwl_mvm_power_update_mac(mvm);
  1812. ret = iwl_mvm_update_quotas(mvm, false, NULL);
  1813. if (ret)
  1814. goto out_quota_failed;
  1815. /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
  1816. if (vif->p2p && mvm->p2p_device_vif)
  1817. iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
  1818. iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
  1819. iwl_mvm_bt_coex_vif_change(mvm);
  1820. /* we don't support TDLS during DCM */
  1821. if (iwl_mvm_phy_ctx_count(mvm) > 1)
  1822. iwl_mvm_teardown_tdls_peers(mvm);
  1823. goto out_unlock;
  1824. out_quota_failed:
  1825. iwl_mvm_power_update_mac(mvm);
  1826. mvmvif->ap_ibss_active = false;
  1827. iwl_mvm_send_rm_bcast_sta(mvm, vif);
  1828. out_rm_mcast:
  1829. iwl_mvm_rm_mcast_sta(mvm, vif);
  1830. out_unbind:
  1831. iwl_mvm_binding_remove_vif(mvm, vif);
  1832. out_remove:
  1833. iwl_mvm_mac_ctxt_remove(mvm, vif);
  1834. out_unlock:
  1835. mutex_unlock(&mvm->mutex);
  1836. iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
  1837. return ret;
  1838. }
  1839. static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
  1840. struct ieee80211_vif *vif)
  1841. {
  1842. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1843. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1844. iwl_mvm_prepare_mac_removal(mvm, vif);
  1845. mutex_lock(&mvm->mutex);
  1846. /* Handle AP stop while in CSA */
  1847. if (rcu_access_pointer(mvm->csa_vif) == vif) {
  1848. iwl_mvm_remove_time_event(mvm, mvmvif,
  1849. &mvmvif->time_event_data);
  1850. RCU_INIT_POINTER(mvm->csa_vif, NULL);
  1851. mvmvif->csa_countdown = false;
  1852. }
  1853. if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
  1854. RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
  1855. mvm->csa_tx_block_bcn_timeout = 0;
  1856. }
  1857. mvmvif->ap_ibss_active = false;
  1858. mvm->ap_last_beacon_gp2 = 0;
  1859. iwl_mvm_bt_coex_vif_change(mvm);
  1860. iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
  1861. /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
  1862. if (vif->p2p && mvm->p2p_device_vif)
  1863. iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
  1864. iwl_mvm_update_quotas(mvm, false, NULL);
  1865. /*
  1866. * This is not very nice, but the simplest:
  1867. * For older FWs removing the mcast sta before the bcast station may
  1868. * cause assert 0x2b00.
  1869. * This is fixed in later FW (which will stop beaconing when removing
  1870. * bcast station).
  1871. * So make the order of removal depend on the TLV
  1872. */
  1873. if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
  1874. iwl_mvm_rm_mcast_sta(mvm, vif);
  1875. iwl_mvm_send_rm_bcast_sta(mvm, vif);
  1876. if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
  1877. iwl_mvm_rm_mcast_sta(mvm, vif);
  1878. iwl_mvm_binding_remove_vif(mvm, vif);
  1879. iwl_mvm_power_update_mac(mvm);
  1880. iwl_mvm_mac_ctxt_remove(mvm, vif);
  1881. mutex_unlock(&mvm->mutex);
  1882. }
  1883. static void
  1884. iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
  1885. struct ieee80211_vif *vif,
  1886. struct ieee80211_bss_conf *bss_conf,
  1887. u32 changes)
  1888. {
  1889. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1890. /* Changes will be applied when the AP/IBSS is started */
  1891. if (!mvmvif->ap_ibss_active)
  1892. return;
  1893. if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
  1894. BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
  1895. iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
  1896. IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
  1897. /* Need to send a new beacon template to the FW */
  1898. if (changes & BSS_CHANGED_BEACON &&
  1899. iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
  1900. IWL_WARN(mvm, "Failed updating beacon data\n");
  1901. if (changes & BSS_CHANGED_TXPOWER) {
  1902. IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
  1903. bss_conf->txpower);
  1904. iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
  1905. }
  1906. }
  1907. static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
  1908. struct ieee80211_vif *vif,
  1909. struct ieee80211_bss_conf *bss_conf,
  1910. u32 changes)
  1911. {
  1912. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1913. /*
  1914. * iwl_mvm_bss_info_changed_station() might call
  1915. * iwl_mvm_protect_session(), which reads directly from
  1916. * the device (the system time), so make sure it is available.
  1917. */
  1918. if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
  1919. return;
  1920. mutex_lock(&mvm->mutex);
  1921. if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
  1922. iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
  1923. switch (vif->type) {
  1924. case NL80211_IFTYPE_STATION:
  1925. iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
  1926. break;
  1927. case NL80211_IFTYPE_AP:
  1928. case NL80211_IFTYPE_ADHOC:
  1929. iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
  1930. break;
  1931. case NL80211_IFTYPE_MONITOR:
  1932. if (changes & BSS_CHANGED_MU_GROUPS)
  1933. iwl_mvm_update_mu_groups(mvm, vif);
  1934. break;
  1935. default:
  1936. /* shouldn't happen */
  1937. WARN_ON_ONCE(1);
  1938. }
  1939. mutex_unlock(&mvm->mutex);
  1940. iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
  1941. }
  1942. static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
  1943. struct ieee80211_vif *vif,
  1944. struct ieee80211_scan_request *hw_req)
  1945. {
  1946. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1947. int ret;
  1948. if (hw_req->req.n_channels == 0 ||
  1949. hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
  1950. return -EINVAL;
  1951. mutex_lock(&mvm->mutex);
  1952. ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
  1953. mutex_unlock(&mvm->mutex);
  1954. return ret;
  1955. }
  1956. static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
  1957. struct ieee80211_vif *vif)
  1958. {
  1959. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1960. mutex_lock(&mvm->mutex);
  1961. /* Due to a race condition, it's possible that mac80211 asks
  1962. * us to stop a hw_scan when it's already stopped. This can
  1963. * happen, for instance, if we stopped the scan ourselves,
  1964. * called ieee80211_scan_completed() and the userspace called
  1965. * cancel scan scan before ieee80211_scan_work() could run.
  1966. * To handle that, simply return if the scan is not running.
  1967. */
  1968. if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
  1969. iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
  1970. mutex_unlock(&mvm->mutex);
  1971. }
  1972. static void
  1973. iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
  1974. struct ieee80211_sta *sta, u16 tids,
  1975. int num_frames,
  1976. enum ieee80211_frame_release_type reason,
  1977. bool more_data)
  1978. {
  1979. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1980. /* Called when we need to transmit (a) frame(s) from mac80211 */
  1981. iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
  1982. tids, more_data, false);
  1983. }
  1984. static void
  1985. iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
  1986. struct ieee80211_sta *sta, u16 tids,
  1987. int num_frames,
  1988. enum ieee80211_frame_release_type reason,
  1989. bool more_data)
  1990. {
  1991. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1992. /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
  1993. iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
  1994. tids, more_data, true);
  1995. }
  1996. static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
  1997. enum sta_notify_cmd cmd,
  1998. struct ieee80211_sta *sta)
  1999. {
  2000. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2001. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  2002. unsigned long txqs = 0, tids = 0;
  2003. int tid;
  2004. /*
  2005. * If we have TVQM then we get too high queue numbers - luckily
  2006. * we really shouldn't get here with that because such hardware
  2007. * should have firmware supporting buffer station offload.
  2008. */
  2009. if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
  2010. return;
  2011. spin_lock_bh(&mvmsta->lock);
  2012. for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
  2013. struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
  2014. if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
  2015. continue;
  2016. __set_bit(tid_data->txq_id, &txqs);
  2017. if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
  2018. continue;
  2019. __set_bit(tid, &tids);
  2020. }
  2021. switch (cmd) {
  2022. case STA_NOTIFY_SLEEP:
  2023. for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
  2024. ieee80211_sta_set_buffered(sta, tid, true);
  2025. if (txqs)
  2026. iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
  2027. /*
  2028. * The fw updates the STA to be asleep. Tx packets on the Tx
  2029. * queues to this station will not be transmitted. The fw will
  2030. * send a Tx response with TX_STATUS_FAIL_DEST_PS.
  2031. */
  2032. break;
  2033. case STA_NOTIFY_AWAKE:
  2034. if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA))
  2035. break;
  2036. if (txqs)
  2037. iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
  2038. iwl_mvm_sta_modify_ps_wake(mvm, sta);
  2039. break;
  2040. default:
  2041. break;
  2042. }
  2043. spin_unlock_bh(&mvmsta->lock);
  2044. }
  2045. static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
  2046. struct ieee80211_vif *vif,
  2047. enum sta_notify_cmd cmd,
  2048. struct ieee80211_sta *sta)
  2049. {
  2050. __iwl_mvm_mac_sta_notify(hw, cmd, sta);
  2051. }
  2052. void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
  2053. {
  2054. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  2055. struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
  2056. struct ieee80211_sta *sta;
  2057. struct iwl_mvm_sta *mvmsta;
  2058. bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
  2059. if (WARN_ON(notif->sta_id >= ARRAY_SIZE(mvm->fw_id_to_mac_id)))
  2060. return;
  2061. rcu_read_lock();
  2062. sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
  2063. if (WARN_ON(IS_ERR_OR_NULL(sta))) {
  2064. rcu_read_unlock();
  2065. return;
  2066. }
  2067. mvmsta = iwl_mvm_sta_from_mac80211(sta);
  2068. if (!mvmsta->vif ||
  2069. mvmsta->vif->type != NL80211_IFTYPE_AP) {
  2070. rcu_read_unlock();
  2071. return;
  2072. }
  2073. if (mvmsta->sleeping != sleeping) {
  2074. mvmsta->sleeping = sleeping;
  2075. __iwl_mvm_mac_sta_notify(mvm->hw,
  2076. sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
  2077. sta);
  2078. ieee80211_sta_ps_transition(sta, sleeping);
  2079. }
  2080. if (sleeping) {
  2081. switch (notif->type) {
  2082. case IWL_MVM_PM_EVENT_AWAKE:
  2083. case IWL_MVM_PM_EVENT_ASLEEP:
  2084. break;
  2085. case IWL_MVM_PM_EVENT_UAPSD:
  2086. ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
  2087. break;
  2088. case IWL_MVM_PM_EVENT_PS_POLL:
  2089. ieee80211_sta_pspoll(sta);
  2090. break;
  2091. default:
  2092. break;
  2093. }
  2094. }
  2095. rcu_read_unlock();
  2096. }
  2097. static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
  2098. struct ieee80211_vif *vif,
  2099. struct ieee80211_sta *sta)
  2100. {
  2101. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2102. struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
  2103. /*
  2104. * This is called before mac80211 does RCU synchronisation,
  2105. * so here we already invalidate our internal RCU-protected
  2106. * station pointer. The rest of the code will thus no longer
  2107. * be able to find the station this way, and we don't rely
  2108. * on further RCU synchronisation after the sta_state()
  2109. * callback deleted the station.
  2110. */
  2111. mutex_lock(&mvm->mutex);
  2112. if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
  2113. rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
  2114. ERR_PTR(-ENOENT));
  2115. mutex_unlock(&mvm->mutex);
  2116. }
  2117. static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  2118. const u8 *bssid)
  2119. {
  2120. if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
  2121. return;
  2122. if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
  2123. vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
  2124. return;
  2125. }
  2126. if (!vif->p2p &&
  2127. (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
  2128. vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
  2129. return;
  2130. }
  2131. vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
  2132. }
  2133. static void
  2134. iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
  2135. struct ieee80211_vif *vif, u8 *peer_addr,
  2136. enum nl80211_tdls_operation action)
  2137. {
  2138. struct iwl_fw_dbg_trigger_tlv *trig;
  2139. struct iwl_fw_dbg_trigger_tdls *tdls_trig;
  2140. if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_TDLS))
  2141. return;
  2142. trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_TDLS);
  2143. tdls_trig = (void *)trig->data;
  2144. if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
  2145. ieee80211_vif_to_wdev(vif), trig))
  2146. return;
  2147. if (!(tdls_trig->action_bitmap & BIT(action)))
  2148. return;
  2149. if (tdls_trig->peer_mode &&
  2150. memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
  2151. return;
  2152. iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
  2153. "TDLS event occurred, peer %pM, action %d",
  2154. peer_addr, action);
  2155. }
  2156. static void iwl_mvm_purge_deferred_tx_frames(struct iwl_mvm *mvm,
  2157. struct iwl_mvm_sta *mvm_sta)
  2158. {
  2159. struct iwl_mvm_tid_data *tid_data;
  2160. struct sk_buff *skb;
  2161. int i;
  2162. spin_lock_bh(&mvm_sta->lock);
  2163. for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
  2164. tid_data = &mvm_sta->tid_data[i];
  2165. while ((skb = __skb_dequeue(&tid_data->deferred_tx_frames))) {
  2166. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  2167. /*
  2168. * The first deferred frame should've stopped the MAC
  2169. * queues, so we should never get a second deferred
  2170. * frame for the RA/TID.
  2171. */
  2172. iwl_mvm_start_mac_queues(mvm, BIT(info->hw_queue));
  2173. ieee80211_free_txskb(mvm->hw, skb);
  2174. }
  2175. }
  2176. spin_unlock_bh(&mvm_sta->lock);
  2177. }
  2178. static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
  2179. struct ieee80211_vif *vif,
  2180. struct ieee80211_sta *sta,
  2181. enum ieee80211_sta_state old_state,
  2182. enum ieee80211_sta_state new_state)
  2183. {
  2184. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2185. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  2186. struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
  2187. int ret;
  2188. IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
  2189. sta->addr, old_state, new_state);
  2190. /* this would be a mac80211 bug ... but don't crash */
  2191. if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
  2192. return -EINVAL;
  2193. /*
  2194. * If we are in a STA removal flow and in DQA mode:
  2195. *
  2196. * This is after the sync_rcu part, so the queues have already been
  2197. * flushed. No more TXs on their way in mac80211's path, and no more in
  2198. * the queues.
  2199. * Also, we won't be getting any new TX frames for this station.
  2200. * What we might have are deferred TX frames that need to be taken care
  2201. * of.
  2202. *
  2203. * Drop any still-queued deferred-frame before removing the STA, and
  2204. * make sure the worker is no longer handling frames for this STA.
  2205. */
  2206. if (old_state == IEEE80211_STA_NONE &&
  2207. new_state == IEEE80211_STA_NOTEXIST) {
  2208. iwl_mvm_purge_deferred_tx_frames(mvm, mvm_sta);
  2209. flush_work(&mvm->add_stream_wk);
  2210. /*
  2211. * No need to make sure deferred TX indication is off since the
  2212. * worker will already remove it if it was on
  2213. */
  2214. }
  2215. mutex_lock(&mvm->mutex);
  2216. /* track whether or not the station is associated */
  2217. mvm_sta->associated = new_state >= IEEE80211_STA_ASSOC;
  2218. if (old_state == IEEE80211_STA_NOTEXIST &&
  2219. new_state == IEEE80211_STA_NONE) {
  2220. /*
  2221. * Firmware bug - it'll crash if the beacon interval is less
  2222. * than 16. We can't avoid connecting at all, so refuse the
  2223. * station state change, this will cause mac80211 to abandon
  2224. * attempts to connect to this AP, and eventually wpa_s will
  2225. * blacklist the AP...
  2226. */
  2227. if (vif->type == NL80211_IFTYPE_STATION &&
  2228. vif->bss_conf.beacon_int < 16) {
  2229. IWL_ERR(mvm,
  2230. "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
  2231. sta->addr, vif->bss_conf.beacon_int);
  2232. ret = -EINVAL;
  2233. goto out_unlock;
  2234. }
  2235. if (sta->tdls &&
  2236. (vif->p2p ||
  2237. iwl_mvm_tdls_sta_count(mvm, NULL) ==
  2238. IWL_MVM_TDLS_STA_COUNT ||
  2239. iwl_mvm_phy_ctx_count(mvm) > 1)) {
  2240. IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
  2241. ret = -EBUSY;
  2242. goto out_unlock;
  2243. }
  2244. ret = iwl_mvm_add_sta(mvm, vif, sta);
  2245. if (sta->tdls && ret == 0) {
  2246. iwl_mvm_recalc_tdls_state(mvm, vif, true);
  2247. iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
  2248. NL80211_TDLS_SETUP);
  2249. }
  2250. } else if (old_state == IEEE80211_STA_NONE &&
  2251. new_state == IEEE80211_STA_AUTH) {
  2252. /*
  2253. * EBS may be disabled due to previous failures reported by FW.
  2254. * Reset EBS status here assuming environment has been changed.
  2255. */
  2256. mvm->last_ebs_successful = true;
  2257. iwl_mvm_check_uapsd(mvm, vif, sta->addr);
  2258. ret = 0;
  2259. } else if (old_state == IEEE80211_STA_AUTH &&
  2260. new_state == IEEE80211_STA_ASSOC) {
  2261. if (vif->type == NL80211_IFTYPE_AP) {
  2262. mvmvif->ap_assoc_sta_count++;
  2263. iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
  2264. }
  2265. iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
  2266. true);
  2267. ret = iwl_mvm_update_sta(mvm, vif, sta);
  2268. } else if (old_state == IEEE80211_STA_ASSOC &&
  2269. new_state == IEEE80211_STA_AUTHORIZED) {
  2270. /* we don't support TDLS during DCM */
  2271. if (iwl_mvm_phy_ctx_count(mvm) > 1)
  2272. iwl_mvm_teardown_tdls_peers(mvm);
  2273. if (sta->tdls)
  2274. iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
  2275. NL80211_TDLS_ENABLE_LINK);
  2276. /* enable beacon filtering */
  2277. WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
  2278. ret = 0;
  2279. } else if (old_state == IEEE80211_STA_AUTHORIZED &&
  2280. new_state == IEEE80211_STA_ASSOC) {
  2281. /* disable beacon filtering */
  2282. WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
  2283. ret = 0;
  2284. } else if (old_state == IEEE80211_STA_ASSOC &&
  2285. new_state == IEEE80211_STA_AUTH) {
  2286. if (vif->type == NL80211_IFTYPE_AP) {
  2287. mvmvif->ap_assoc_sta_count--;
  2288. iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
  2289. }
  2290. ret = 0;
  2291. } else if (old_state == IEEE80211_STA_AUTH &&
  2292. new_state == IEEE80211_STA_NONE) {
  2293. ret = 0;
  2294. } else if (old_state == IEEE80211_STA_NONE &&
  2295. new_state == IEEE80211_STA_NOTEXIST) {
  2296. ret = iwl_mvm_rm_sta(mvm, vif, sta);
  2297. if (sta->tdls) {
  2298. iwl_mvm_recalc_tdls_state(mvm, vif, false);
  2299. iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
  2300. NL80211_TDLS_DISABLE_LINK);
  2301. }
  2302. } else {
  2303. ret = -EIO;
  2304. }
  2305. out_unlock:
  2306. mutex_unlock(&mvm->mutex);
  2307. if (sta->tdls && ret == 0) {
  2308. if (old_state == IEEE80211_STA_NOTEXIST &&
  2309. new_state == IEEE80211_STA_NONE)
  2310. ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
  2311. else if (old_state == IEEE80211_STA_NONE &&
  2312. new_state == IEEE80211_STA_NOTEXIST)
  2313. ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
  2314. }
  2315. return ret;
  2316. }
  2317. static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  2318. {
  2319. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2320. mvm->rts_threshold = value;
  2321. return 0;
  2322. }
  2323. static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
  2324. struct ieee80211_vif *vif,
  2325. struct ieee80211_sta *sta, u32 changed)
  2326. {
  2327. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2328. if (vif->type == NL80211_IFTYPE_STATION &&
  2329. changed & IEEE80211_RC_NSS_CHANGED)
  2330. iwl_mvm_sf_update(mvm, vif, false);
  2331. }
  2332. static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
  2333. struct ieee80211_vif *vif, u16 ac,
  2334. const struct ieee80211_tx_queue_params *params)
  2335. {
  2336. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2337. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  2338. mvmvif->queue_params[ac] = *params;
  2339. /*
  2340. * No need to update right away, we'll get BSS_CHANGED_QOS
  2341. * The exception is P2P_DEVICE interface which needs immediate update.
  2342. */
  2343. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  2344. int ret;
  2345. mutex_lock(&mvm->mutex);
  2346. ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
  2347. mutex_unlock(&mvm->mutex);
  2348. return ret;
  2349. }
  2350. return 0;
  2351. }
  2352. static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
  2353. struct ieee80211_vif *vif)
  2354. {
  2355. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2356. u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
  2357. u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
  2358. if (WARN_ON_ONCE(vif->bss_conf.assoc))
  2359. return;
  2360. /*
  2361. * iwl_mvm_protect_session() reads directly from the device
  2362. * (the system time), so make sure it is available.
  2363. */
  2364. if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
  2365. return;
  2366. mutex_lock(&mvm->mutex);
  2367. /* Try really hard to protect the session and hear a beacon */
  2368. iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
  2369. mutex_unlock(&mvm->mutex);
  2370. iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
  2371. }
  2372. static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
  2373. struct ieee80211_vif *vif,
  2374. struct cfg80211_sched_scan_request *req,
  2375. struct ieee80211_scan_ies *ies)
  2376. {
  2377. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2378. int ret;
  2379. mutex_lock(&mvm->mutex);
  2380. if (!vif->bss_conf.idle) {
  2381. ret = -EBUSY;
  2382. goto out;
  2383. }
  2384. ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
  2385. out:
  2386. mutex_unlock(&mvm->mutex);
  2387. return ret;
  2388. }
  2389. static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
  2390. struct ieee80211_vif *vif)
  2391. {
  2392. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2393. int ret;
  2394. mutex_lock(&mvm->mutex);
  2395. /* Due to a race condition, it's possible that mac80211 asks
  2396. * us to stop a sched_scan when it's already stopped. This
  2397. * can happen, for instance, if we stopped the scan ourselves,
  2398. * called ieee80211_sched_scan_stopped() and the userspace called
  2399. * stop sched scan scan before ieee80211_sched_scan_stopped_work()
  2400. * could run. To handle this, simply return if the scan is
  2401. * not running.
  2402. */
  2403. if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
  2404. mutex_unlock(&mvm->mutex);
  2405. return 0;
  2406. }
  2407. ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
  2408. mutex_unlock(&mvm->mutex);
  2409. iwl_mvm_wait_for_async_handlers(mvm);
  2410. return ret;
  2411. }
  2412. static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
  2413. enum set_key_cmd cmd,
  2414. struct ieee80211_vif *vif,
  2415. struct ieee80211_sta *sta,
  2416. struct ieee80211_key_conf *key)
  2417. {
  2418. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2419. struct iwl_mvm_sta *mvmsta;
  2420. struct iwl_mvm_key_pn *ptk_pn;
  2421. int keyidx = key->keyidx;
  2422. int ret;
  2423. u8 key_offset;
  2424. if (iwlwifi_mod_params.swcrypto) {
  2425. IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
  2426. return -EOPNOTSUPP;
  2427. }
  2428. switch (key->cipher) {
  2429. case WLAN_CIPHER_SUITE_TKIP:
  2430. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  2431. key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
  2432. break;
  2433. case WLAN_CIPHER_SUITE_CCMP:
  2434. case WLAN_CIPHER_SUITE_GCMP:
  2435. case WLAN_CIPHER_SUITE_GCMP_256:
  2436. if (!iwl_mvm_has_new_tx_api(mvm))
  2437. key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
  2438. break;
  2439. case WLAN_CIPHER_SUITE_AES_CMAC:
  2440. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  2441. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  2442. WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
  2443. break;
  2444. case WLAN_CIPHER_SUITE_WEP40:
  2445. case WLAN_CIPHER_SUITE_WEP104:
  2446. /* For non-client mode, only use WEP keys for TX as we probably
  2447. * don't have a station yet anyway and would then have to keep
  2448. * track of the keys, linking them to each of the clients/peers
  2449. * as they appear. For now, don't do that, for performance WEP
  2450. * offload doesn't really matter much, but we need it for some
  2451. * other offload features in client mode.
  2452. */
  2453. if (vif->type != NL80211_IFTYPE_STATION)
  2454. return 0;
  2455. break;
  2456. default:
  2457. /* currently FW supports only one optional cipher scheme */
  2458. if (hw->n_cipher_schemes &&
  2459. hw->cipher_schemes->cipher == key->cipher)
  2460. key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
  2461. else
  2462. return -EOPNOTSUPP;
  2463. }
  2464. mutex_lock(&mvm->mutex);
  2465. switch (cmd) {
  2466. case SET_KEY:
  2467. if ((vif->type == NL80211_IFTYPE_ADHOC ||
  2468. vif->type == NL80211_IFTYPE_AP) && !sta) {
  2469. /*
  2470. * GTK on AP interface is a TX-only key, return 0;
  2471. * on IBSS they're per-station and because we're lazy
  2472. * we don't support them for RX, so do the same.
  2473. * CMAC/GMAC in AP/IBSS modes must be done in software.
  2474. */
  2475. if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
  2476. key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
  2477. key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
  2478. ret = -EOPNOTSUPP;
  2479. else
  2480. ret = 0;
  2481. if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
  2482. key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
  2483. !iwl_mvm_has_new_tx_api(mvm)) {
  2484. key->hw_key_idx = STA_KEY_IDX_INVALID;
  2485. break;
  2486. }
  2487. }
  2488. /* During FW restart, in order to restore the state as it was,
  2489. * don't try to reprogram keys we previously failed for.
  2490. */
  2491. if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
  2492. key->hw_key_idx == STA_KEY_IDX_INVALID) {
  2493. IWL_DEBUG_MAC80211(mvm,
  2494. "skip invalid idx key programming during restart\n");
  2495. ret = 0;
  2496. break;
  2497. }
  2498. if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
  2499. sta && iwl_mvm_has_new_rx_api(mvm) &&
  2500. key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
  2501. (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
  2502. key->cipher == WLAN_CIPHER_SUITE_GCMP ||
  2503. key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
  2504. struct ieee80211_key_seq seq;
  2505. int tid, q;
  2506. mvmsta = iwl_mvm_sta_from_mac80211(sta);
  2507. WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
  2508. ptk_pn = kzalloc(sizeof(*ptk_pn) +
  2509. mvm->trans->num_rx_queues *
  2510. sizeof(ptk_pn->q[0]),
  2511. GFP_KERNEL);
  2512. if (!ptk_pn) {
  2513. ret = -ENOMEM;
  2514. break;
  2515. }
  2516. for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
  2517. ieee80211_get_key_rx_seq(key, tid, &seq);
  2518. for (q = 0; q < mvm->trans->num_rx_queues; q++)
  2519. memcpy(ptk_pn->q[q].pn[tid],
  2520. seq.ccmp.pn,
  2521. IEEE80211_CCMP_PN_LEN);
  2522. }
  2523. rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
  2524. }
  2525. /* in HW restart reuse the index, otherwise request a new one */
  2526. if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
  2527. key_offset = key->hw_key_idx;
  2528. else
  2529. key_offset = STA_KEY_IDX_INVALID;
  2530. IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
  2531. ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
  2532. if (ret) {
  2533. IWL_WARN(mvm, "set key failed\n");
  2534. /*
  2535. * can't add key for RX, but we don't need it
  2536. * in the device for TX so still return 0
  2537. */
  2538. key->hw_key_idx = STA_KEY_IDX_INVALID;
  2539. ret = 0;
  2540. }
  2541. break;
  2542. case DISABLE_KEY:
  2543. if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
  2544. ret = 0;
  2545. break;
  2546. }
  2547. if (sta && iwl_mvm_has_new_rx_api(mvm) &&
  2548. key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
  2549. (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
  2550. key->cipher == WLAN_CIPHER_SUITE_GCMP ||
  2551. key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
  2552. mvmsta = iwl_mvm_sta_from_mac80211(sta);
  2553. ptk_pn = rcu_dereference_protected(
  2554. mvmsta->ptk_pn[keyidx],
  2555. lockdep_is_held(&mvm->mutex));
  2556. RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
  2557. if (ptk_pn)
  2558. kfree_rcu(ptk_pn, rcu_head);
  2559. }
  2560. IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
  2561. ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
  2562. break;
  2563. default:
  2564. ret = -EINVAL;
  2565. }
  2566. mutex_unlock(&mvm->mutex);
  2567. return ret;
  2568. }
  2569. static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
  2570. struct ieee80211_vif *vif,
  2571. struct ieee80211_key_conf *keyconf,
  2572. struct ieee80211_sta *sta,
  2573. u32 iv32, u16 *phase1key)
  2574. {
  2575. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2576. if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
  2577. return;
  2578. iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
  2579. }
  2580. static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
  2581. struct iwl_rx_packet *pkt, void *data)
  2582. {
  2583. struct iwl_mvm *mvm =
  2584. container_of(notif_wait, struct iwl_mvm, notif_wait);
  2585. struct iwl_hs20_roc_res *resp;
  2586. int resp_len = iwl_rx_packet_payload_len(pkt);
  2587. struct iwl_mvm_time_event_data *te_data = data;
  2588. if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
  2589. return true;
  2590. if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
  2591. IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
  2592. return true;
  2593. }
  2594. resp = (void *)pkt->data;
  2595. IWL_DEBUG_TE(mvm,
  2596. "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
  2597. resp->status, resp->event_unique_id);
  2598. te_data->uid = le32_to_cpu(resp->event_unique_id);
  2599. IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
  2600. te_data->uid);
  2601. spin_lock_bh(&mvm->time_event_lock);
  2602. list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
  2603. spin_unlock_bh(&mvm->time_event_lock);
  2604. return true;
  2605. }
  2606. #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
  2607. #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
  2608. #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
  2609. #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
  2610. #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
  2611. static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
  2612. struct ieee80211_channel *channel,
  2613. struct ieee80211_vif *vif,
  2614. int duration)
  2615. {
  2616. int res, time_reg = DEVICE_SYSTEM_TIME_REG;
  2617. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  2618. struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
  2619. static const u16 time_event_response[] = { HOT_SPOT_CMD };
  2620. struct iwl_notification_wait wait_time_event;
  2621. u32 dtim_interval = vif->bss_conf.dtim_period *
  2622. vif->bss_conf.beacon_int;
  2623. u32 req_dur, delay;
  2624. struct iwl_hs20_roc_req aux_roc_req = {
  2625. .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
  2626. .id_and_color =
  2627. cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
  2628. .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
  2629. /* Set the channel info data */
  2630. .channel_info.band = (channel->band == NL80211_BAND_2GHZ) ?
  2631. PHY_BAND_24 : PHY_BAND_5,
  2632. .channel_info.channel = channel->hw_value,
  2633. .channel_info.width = PHY_VHT_CHANNEL_MODE20,
  2634. /* Set the time and duration */
  2635. .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
  2636. };
  2637. delay = AUX_ROC_MIN_DELAY;
  2638. req_dur = MSEC_TO_TU(duration);
  2639. /*
  2640. * If we are associated we want the delay time to be at least one
  2641. * dtim interval so that the FW can wait until after the DTIM and
  2642. * then start the time event, this will potentially allow us to
  2643. * remain off-channel for the max duration.
  2644. * Since we want to use almost a whole dtim interval we would also
  2645. * like the delay to be for 2-3 dtim intervals, in case there are
  2646. * other time events with higher priority.
  2647. */
  2648. if (vif->bss_conf.assoc) {
  2649. delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
  2650. /* We cannot remain off-channel longer than the DTIM interval */
  2651. if (dtim_interval <= req_dur) {
  2652. req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
  2653. if (req_dur <= AUX_ROC_MIN_DURATION)
  2654. req_dur = dtim_interval -
  2655. AUX_ROC_MIN_SAFETY_BUFFER;
  2656. }
  2657. }
  2658. aux_roc_req.duration = cpu_to_le32(req_dur);
  2659. aux_roc_req.apply_time_max_delay = cpu_to_le32(delay);
  2660. IWL_DEBUG_TE(mvm,
  2661. "ROC: Requesting to remain on channel %u for %ums (requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
  2662. channel->hw_value, req_dur, duration, delay,
  2663. dtim_interval);
  2664. /* Set the node address */
  2665. memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
  2666. lockdep_assert_held(&mvm->mutex);
  2667. spin_lock_bh(&mvm->time_event_lock);
  2668. if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
  2669. spin_unlock_bh(&mvm->time_event_lock);
  2670. return -EIO;
  2671. }
  2672. te_data->vif = vif;
  2673. te_data->duration = duration;
  2674. te_data->id = HOT_SPOT_CMD;
  2675. spin_unlock_bh(&mvm->time_event_lock);
  2676. /*
  2677. * Use a notification wait, which really just processes the
  2678. * command response and doesn't wait for anything, in order
  2679. * to be able to process the response and get the UID inside
  2680. * the RX path. Using CMD_WANT_SKB doesn't work because it
  2681. * stores the buffer and then wakes up this thread, by which
  2682. * time another notification (that the time event started)
  2683. * might already be processed unsuccessfully.
  2684. */
  2685. iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
  2686. time_event_response,
  2687. ARRAY_SIZE(time_event_response),
  2688. iwl_mvm_rx_aux_roc, te_data);
  2689. res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
  2690. &aux_roc_req);
  2691. if (res) {
  2692. IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
  2693. iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
  2694. goto out_clear_te;
  2695. }
  2696. /* No need to wait for anything, so just pass 1 (0 isn't valid) */
  2697. res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
  2698. /* should never fail */
  2699. WARN_ON_ONCE(res);
  2700. if (res) {
  2701. out_clear_te:
  2702. spin_lock_bh(&mvm->time_event_lock);
  2703. iwl_mvm_te_clear_data(mvm, te_data);
  2704. spin_unlock_bh(&mvm->time_event_lock);
  2705. }
  2706. return res;
  2707. }
  2708. static int iwl_mvm_roc(struct ieee80211_hw *hw,
  2709. struct ieee80211_vif *vif,
  2710. struct ieee80211_channel *channel,
  2711. int duration,
  2712. enum ieee80211_roc_type type)
  2713. {
  2714. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2715. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  2716. struct cfg80211_chan_def chandef;
  2717. struct iwl_mvm_phy_ctxt *phy_ctxt;
  2718. int ret, i;
  2719. IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
  2720. duration, type);
  2721. flush_work(&mvm->roc_done_wk);
  2722. mutex_lock(&mvm->mutex);
  2723. switch (vif->type) {
  2724. case NL80211_IFTYPE_STATION:
  2725. if (fw_has_capa(&mvm->fw->ucode_capa,
  2726. IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
  2727. /* Use aux roc framework (HS20) */
  2728. ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
  2729. vif, duration);
  2730. goto out_unlock;
  2731. }
  2732. IWL_ERR(mvm, "hotspot not supported\n");
  2733. ret = -EINVAL;
  2734. goto out_unlock;
  2735. case NL80211_IFTYPE_P2P_DEVICE:
  2736. /* handle below */
  2737. break;
  2738. default:
  2739. IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
  2740. ret = -EINVAL;
  2741. goto out_unlock;
  2742. }
  2743. for (i = 0; i < NUM_PHY_CTX; i++) {
  2744. phy_ctxt = &mvm->phy_ctxts[i];
  2745. if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
  2746. continue;
  2747. if (phy_ctxt->ref && channel == phy_ctxt->channel) {
  2748. /*
  2749. * Unbind the P2P_DEVICE from the current PHY context,
  2750. * and if the PHY context is not used remove it.
  2751. */
  2752. ret = iwl_mvm_binding_remove_vif(mvm, vif);
  2753. if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
  2754. goto out_unlock;
  2755. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  2756. /* Bind the P2P_DEVICE to the current PHY Context */
  2757. mvmvif->phy_ctxt = phy_ctxt;
  2758. ret = iwl_mvm_binding_add_vif(mvm, vif);
  2759. if (WARN(ret, "Failed binding P2P_DEVICE\n"))
  2760. goto out_unlock;
  2761. iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
  2762. goto schedule_time_event;
  2763. }
  2764. }
  2765. /* Need to update the PHY context only if the ROC channel changed */
  2766. if (channel == mvmvif->phy_ctxt->channel)
  2767. goto schedule_time_event;
  2768. cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
  2769. /*
  2770. * Change the PHY context configuration as it is currently referenced
  2771. * only by the P2P Device MAC
  2772. */
  2773. if (mvmvif->phy_ctxt->ref == 1) {
  2774. ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
  2775. &chandef, 1, 1);
  2776. if (ret)
  2777. goto out_unlock;
  2778. } else {
  2779. /*
  2780. * The PHY context is shared with other MACs. Need to remove the
  2781. * P2P Device from the binding, allocate an new PHY context and
  2782. * create a new binding
  2783. */
  2784. phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
  2785. if (!phy_ctxt) {
  2786. ret = -ENOSPC;
  2787. goto out_unlock;
  2788. }
  2789. ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
  2790. 1, 1);
  2791. if (ret) {
  2792. IWL_ERR(mvm, "Failed to change PHY context\n");
  2793. goto out_unlock;
  2794. }
  2795. /* Unbind the P2P_DEVICE from the current PHY context */
  2796. ret = iwl_mvm_binding_remove_vif(mvm, vif);
  2797. if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
  2798. goto out_unlock;
  2799. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  2800. /* Bind the P2P_DEVICE to the new allocated PHY context */
  2801. mvmvif->phy_ctxt = phy_ctxt;
  2802. ret = iwl_mvm_binding_add_vif(mvm, vif);
  2803. if (WARN(ret, "Failed binding P2P_DEVICE\n"))
  2804. goto out_unlock;
  2805. iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
  2806. }
  2807. schedule_time_event:
  2808. /* Schedule the time events */
  2809. ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
  2810. out_unlock:
  2811. mutex_unlock(&mvm->mutex);
  2812. IWL_DEBUG_MAC80211(mvm, "leave\n");
  2813. return ret;
  2814. }
  2815. static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
  2816. {
  2817. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2818. IWL_DEBUG_MAC80211(mvm, "enter\n");
  2819. mutex_lock(&mvm->mutex);
  2820. iwl_mvm_stop_roc(mvm);
  2821. mutex_unlock(&mvm->mutex);
  2822. IWL_DEBUG_MAC80211(mvm, "leave\n");
  2823. return 0;
  2824. }
  2825. static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
  2826. struct ieee80211_chanctx_conf *ctx)
  2827. {
  2828. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  2829. struct iwl_mvm_phy_ctxt *phy_ctxt;
  2830. int ret;
  2831. lockdep_assert_held(&mvm->mutex);
  2832. IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
  2833. phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
  2834. if (!phy_ctxt) {
  2835. ret = -ENOSPC;
  2836. goto out;
  2837. }
  2838. ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
  2839. ctx->rx_chains_static,
  2840. ctx->rx_chains_dynamic);
  2841. if (ret) {
  2842. IWL_ERR(mvm, "Failed to add PHY context\n");
  2843. goto out;
  2844. }
  2845. iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
  2846. *phy_ctxt_id = phy_ctxt->id;
  2847. out:
  2848. return ret;
  2849. }
  2850. static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
  2851. struct ieee80211_chanctx_conf *ctx)
  2852. {
  2853. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2854. int ret;
  2855. mutex_lock(&mvm->mutex);
  2856. ret = __iwl_mvm_add_chanctx(mvm, ctx);
  2857. mutex_unlock(&mvm->mutex);
  2858. return ret;
  2859. }
  2860. static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
  2861. struct ieee80211_chanctx_conf *ctx)
  2862. {
  2863. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  2864. struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
  2865. lockdep_assert_held(&mvm->mutex);
  2866. iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
  2867. }
  2868. static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
  2869. struct ieee80211_chanctx_conf *ctx)
  2870. {
  2871. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2872. mutex_lock(&mvm->mutex);
  2873. __iwl_mvm_remove_chanctx(mvm, ctx);
  2874. mutex_unlock(&mvm->mutex);
  2875. }
  2876. static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
  2877. struct ieee80211_chanctx_conf *ctx,
  2878. u32 changed)
  2879. {
  2880. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2881. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  2882. struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
  2883. if (WARN_ONCE((phy_ctxt->ref > 1) &&
  2884. (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
  2885. IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
  2886. IEEE80211_CHANCTX_CHANGE_RADAR |
  2887. IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
  2888. "Cannot change PHY. Ref=%d, changed=0x%X\n",
  2889. phy_ctxt->ref, changed))
  2890. return;
  2891. mutex_lock(&mvm->mutex);
  2892. iwl_mvm_bt_coex_vif_change(mvm);
  2893. iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
  2894. ctx->rx_chains_static,
  2895. ctx->rx_chains_dynamic);
  2896. mutex_unlock(&mvm->mutex);
  2897. }
  2898. static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
  2899. struct ieee80211_vif *vif,
  2900. struct ieee80211_chanctx_conf *ctx,
  2901. bool switching_chanctx)
  2902. {
  2903. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  2904. struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
  2905. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  2906. int ret;
  2907. lockdep_assert_held(&mvm->mutex);
  2908. mvmvif->phy_ctxt = phy_ctxt;
  2909. switch (vif->type) {
  2910. case NL80211_IFTYPE_AP:
  2911. /* only needed if we're switching chanctx (i.e. during CSA) */
  2912. if (switching_chanctx) {
  2913. mvmvif->ap_ibss_active = true;
  2914. break;
  2915. }
  2916. case NL80211_IFTYPE_ADHOC:
  2917. /*
  2918. * The AP binding flow is handled as part of the start_ap flow
  2919. * (in bss_info_changed), similarly for IBSS.
  2920. */
  2921. ret = 0;
  2922. goto out;
  2923. case NL80211_IFTYPE_STATION:
  2924. break;
  2925. case NL80211_IFTYPE_MONITOR:
  2926. /* always disable PS when a monitor interface is active */
  2927. mvmvif->ps_disabled = true;
  2928. break;
  2929. default:
  2930. ret = -EINVAL;
  2931. goto out;
  2932. }
  2933. ret = iwl_mvm_binding_add_vif(mvm, vif);
  2934. if (ret)
  2935. goto out;
  2936. /*
  2937. * Power state must be updated before quotas,
  2938. * otherwise fw will complain.
  2939. */
  2940. iwl_mvm_power_update_mac(mvm);
  2941. /* Setting the quota at this stage is only required for monitor
  2942. * interfaces. For the other types, the bss_info changed flow
  2943. * will handle quota settings.
  2944. */
  2945. if (vif->type == NL80211_IFTYPE_MONITOR) {
  2946. mvmvif->monitor_active = true;
  2947. ret = iwl_mvm_update_quotas(mvm, false, NULL);
  2948. if (ret)
  2949. goto out_remove_binding;
  2950. ret = iwl_mvm_add_snif_sta(mvm, vif);
  2951. if (ret)
  2952. goto out_remove_binding;
  2953. }
  2954. /* Handle binding during CSA */
  2955. if (vif->type == NL80211_IFTYPE_AP) {
  2956. iwl_mvm_update_quotas(mvm, false, NULL);
  2957. iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
  2958. }
  2959. if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
  2960. u32 duration = 2 * vif->bss_conf.beacon_int;
  2961. /* iwl_mvm_protect_session() reads directly from the
  2962. * device (the system time), so make sure it is
  2963. * available.
  2964. */
  2965. ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
  2966. if (ret)
  2967. goto out_remove_binding;
  2968. /* Protect the session to make sure we hear the first
  2969. * beacon on the new channel.
  2970. */
  2971. iwl_mvm_protect_session(mvm, vif, duration, duration,
  2972. vif->bss_conf.beacon_int / 2,
  2973. true);
  2974. iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
  2975. iwl_mvm_update_quotas(mvm, false, NULL);
  2976. }
  2977. goto out;
  2978. out_remove_binding:
  2979. iwl_mvm_binding_remove_vif(mvm, vif);
  2980. iwl_mvm_power_update_mac(mvm);
  2981. out:
  2982. if (ret)
  2983. mvmvif->phy_ctxt = NULL;
  2984. return ret;
  2985. }
  2986. static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
  2987. struct ieee80211_vif *vif,
  2988. struct ieee80211_chanctx_conf *ctx)
  2989. {
  2990. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  2991. int ret;
  2992. mutex_lock(&mvm->mutex);
  2993. ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
  2994. mutex_unlock(&mvm->mutex);
  2995. return ret;
  2996. }
  2997. static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
  2998. struct ieee80211_vif *vif,
  2999. struct ieee80211_chanctx_conf *ctx,
  3000. bool switching_chanctx)
  3001. {
  3002. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  3003. struct ieee80211_vif *disabled_vif = NULL;
  3004. lockdep_assert_held(&mvm->mutex);
  3005. iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
  3006. switch (vif->type) {
  3007. case NL80211_IFTYPE_ADHOC:
  3008. goto out;
  3009. case NL80211_IFTYPE_MONITOR:
  3010. mvmvif->monitor_active = false;
  3011. mvmvif->ps_disabled = false;
  3012. iwl_mvm_rm_snif_sta(mvm, vif);
  3013. break;
  3014. case NL80211_IFTYPE_AP:
  3015. /* This part is triggered only during CSA */
  3016. if (!switching_chanctx || !mvmvif->ap_ibss_active)
  3017. goto out;
  3018. mvmvif->csa_countdown = false;
  3019. /* Set CS bit on all the stations */
  3020. iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
  3021. /* Save blocked iface, the timeout is set on the next beacon */
  3022. rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
  3023. mvmvif->ap_ibss_active = false;
  3024. break;
  3025. case NL80211_IFTYPE_STATION:
  3026. if (!switching_chanctx)
  3027. break;
  3028. disabled_vif = vif;
  3029. iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
  3030. break;
  3031. default:
  3032. break;
  3033. }
  3034. iwl_mvm_update_quotas(mvm, false, disabled_vif);
  3035. iwl_mvm_binding_remove_vif(mvm, vif);
  3036. out:
  3037. mvmvif->phy_ctxt = NULL;
  3038. iwl_mvm_power_update_mac(mvm);
  3039. }
  3040. static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
  3041. struct ieee80211_vif *vif,
  3042. struct ieee80211_chanctx_conf *ctx)
  3043. {
  3044. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  3045. mutex_lock(&mvm->mutex);
  3046. __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
  3047. mutex_unlock(&mvm->mutex);
  3048. }
  3049. static int
  3050. iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
  3051. struct ieee80211_vif_chanctx_switch *vifs)
  3052. {
  3053. int ret;
  3054. mutex_lock(&mvm->mutex);
  3055. __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
  3056. __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
  3057. ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
  3058. if (ret) {
  3059. IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
  3060. goto out_reassign;
  3061. }
  3062. ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
  3063. true);
  3064. if (ret) {
  3065. IWL_ERR(mvm,
  3066. "failed to assign new_ctx during channel switch\n");
  3067. goto out_remove;
  3068. }
  3069. /* we don't support TDLS during DCM - can be caused by channel switch */
  3070. if (iwl_mvm_phy_ctx_count(mvm) > 1)
  3071. iwl_mvm_teardown_tdls_peers(mvm);
  3072. goto out;
  3073. out_remove:
  3074. __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
  3075. out_reassign:
  3076. if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
  3077. IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
  3078. goto out_restart;
  3079. }
  3080. if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
  3081. true)) {
  3082. IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
  3083. goto out_restart;
  3084. }
  3085. goto out;
  3086. out_restart:
  3087. /* things keep failing, better restart the hw */
  3088. iwl_mvm_nic_restart(mvm, false);
  3089. out:
  3090. mutex_unlock(&mvm->mutex);
  3091. return ret;
  3092. }
  3093. static int
  3094. iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
  3095. struct ieee80211_vif_chanctx_switch *vifs)
  3096. {
  3097. int ret;
  3098. mutex_lock(&mvm->mutex);
  3099. __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
  3100. ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
  3101. true);
  3102. if (ret) {
  3103. IWL_ERR(mvm,
  3104. "failed to assign new_ctx during channel switch\n");
  3105. goto out_reassign;
  3106. }
  3107. goto out;
  3108. out_reassign:
  3109. if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
  3110. true)) {
  3111. IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
  3112. goto out_restart;
  3113. }
  3114. goto out;
  3115. out_restart:
  3116. /* things keep failing, better restart the hw */
  3117. iwl_mvm_nic_restart(mvm, false);
  3118. out:
  3119. mutex_unlock(&mvm->mutex);
  3120. return ret;
  3121. }
  3122. static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
  3123. struct ieee80211_vif_chanctx_switch *vifs,
  3124. int n_vifs,
  3125. enum ieee80211_chanctx_switch_mode mode)
  3126. {
  3127. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  3128. int ret;
  3129. /* we only support a single-vif right now */
  3130. if (n_vifs > 1)
  3131. return -EOPNOTSUPP;
  3132. switch (mode) {
  3133. case CHANCTX_SWMODE_SWAP_CONTEXTS:
  3134. ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
  3135. break;
  3136. case CHANCTX_SWMODE_REASSIGN_VIF:
  3137. ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
  3138. break;
  3139. default:
  3140. ret = -EOPNOTSUPP;
  3141. break;
  3142. }
  3143. return ret;
  3144. }
  3145. static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
  3146. {
  3147. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  3148. return mvm->ibss_manager;
  3149. }
  3150. static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
  3151. struct ieee80211_sta *sta,
  3152. bool set)
  3153. {
  3154. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  3155. struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
  3156. if (!mvm_sta || !mvm_sta->vif) {
  3157. IWL_ERR(mvm, "Station is not associated to a vif\n");
  3158. return -EINVAL;
  3159. }
  3160. return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
  3161. }
  3162. #ifdef CONFIG_NL80211_TESTMODE
  3163. static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
  3164. [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
  3165. [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
  3166. [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
  3167. };
  3168. static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
  3169. struct ieee80211_vif *vif,
  3170. void *data, int len)
  3171. {
  3172. struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
  3173. int err;
  3174. u32 noa_duration;
  3175. err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy,
  3176. NULL);
  3177. if (err)
  3178. return err;
  3179. if (!tb[IWL_MVM_TM_ATTR_CMD])
  3180. return -EINVAL;
  3181. switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
  3182. case IWL_MVM_TM_CMD_SET_NOA:
  3183. if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
  3184. !vif->bss_conf.enable_beacon ||
  3185. !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
  3186. return -EINVAL;
  3187. noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
  3188. if (noa_duration >= vif->bss_conf.beacon_int)
  3189. return -EINVAL;
  3190. mvm->noa_duration = noa_duration;
  3191. mvm->noa_vif = vif;
  3192. return iwl_mvm_update_quotas(mvm, false, NULL);
  3193. case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
  3194. /* must be associated client vif - ignore authorized */
  3195. if (!vif || vif->type != NL80211_IFTYPE_STATION ||
  3196. !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
  3197. !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
  3198. return -EINVAL;
  3199. if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
  3200. return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
  3201. return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
  3202. }
  3203. return -EOPNOTSUPP;
  3204. }
  3205. static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
  3206. struct ieee80211_vif *vif,
  3207. void *data, int len)
  3208. {
  3209. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  3210. int err;
  3211. mutex_lock(&mvm->mutex);
  3212. err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
  3213. mutex_unlock(&mvm->mutex);
  3214. return err;
  3215. }
  3216. #endif
  3217. static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
  3218. struct ieee80211_vif *vif,
  3219. struct ieee80211_channel_switch *chsw)
  3220. {
  3221. /* By implementing this operation, we prevent mac80211 from
  3222. * starting its own channel switch timer, so that we can call
  3223. * ieee80211_chswitch_done() ourselves at the right time
  3224. * (which is when the absence time event starts).
  3225. */
  3226. IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
  3227. "dummy channel switch op\n");
  3228. }
  3229. static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
  3230. struct ieee80211_vif *vif,
  3231. struct ieee80211_channel_switch *chsw)
  3232. {
  3233. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  3234. struct ieee80211_vif *csa_vif;
  3235. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  3236. u32 apply_time;
  3237. int ret;
  3238. mutex_lock(&mvm->mutex);
  3239. mvmvif->csa_failed = false;
  3240. IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
  3241. chsw->chandef.center_freq1);
  3242. iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
  3243. ieee80211_vif_to_wdev(vif),
  3244. FW_DBG_TRIGGER_CHANNEL_SWITCH);
  3245. switch (vif->type) {
  3246. case NL80211_IFTYPE_AP:
  3247. csa_vif =
  3248. rcu_dereference_protected(mvm->csa_vif,
  3249. lockdep_is_held(&mvm->mutex));
  3250. if (WARN_ONCE(csa_vif && csa_vif->csa_active,
  3251. "Another CSA is already in progress")) {
  3252. ret = -EBUSY;
  3253. goto out_unlock;
  3254. }
  3255. /* we still didn't unblock tx. prevent new CS meanwhile */
  3256. if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
  3257. lockdep_is_held(&mvm->mutex))) {
  3258. ret = -EBUSY;
  3259. goto out_unlock;
  3260. }
  3261. rcu_assign_pointer(mvm->csa_vif, vif);
  3262. if (WARN_ONCE(mvmvif->csa_countdown,
  3263. "Previous CSA countdown didn't complete")) {
  3264. ret = -EBUSY;
  3265. goto out_unlock;
  3266. }
  3267. mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
  3268. break;
  3269. case NL80211_IFTYPE_STATION:
  3270. if (mvmvif->lqm_active)
  3271. iwl_mvm_send_lqm_cmd(vif,
  3272. LQM_CMD_OPERATION_STOP_MEASUREMENT,
  3273. 0, 0);
  3274. /* Schedule the time event to a bit before beacon 1,
  3275. * to make sure we're in the new channel when the
  3276. * GO/AP arrives. In case count <= 1 immediately schedule the
  3277. * TE (this might result with some packet loss or connection
  3278. * loss).
  3279. */
  3280. if (chsw->count <= 1)
  3281. apply_time = 0;
  3282. else
  3283. apply_time = chsw->device_timestamp +
  3284. ((vif->bss_conf.beacon_int * (chsw->count - 1) -
  3285. IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
  3286. if (chsw->block_tx)
  3287. iwl_mvm_csa_client_absent(mvm, vif);
  3288. iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
  3289. apply_time);
  3290. if (mvmvif->bf_data.bf_enabled) {
  3291. ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
  3292. if (ret)
  3293. goto out_unlock;
  3294. }
  3295. break;
  3296. default:
  3297. break;
  3298. }
  3299. mvmvif->ps_disabled = true;
  3300. ret = iwl_mvm_power_update_ps(mvm);
  3301. if (ret)
  3302. goto out_unlock;
  3303. /* we won't be on this channel any longer */
  3304. iwl_mvm_teardown_tdls_peers(mvm);
  3305. out_unlock:
  3306. mutex_unlock(&mvm->mutex);
  3307. return ret;
  3308. }
  3309. static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
  3310. struct ieee80211_vif *vif)
  3311. {
  3312. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  3313. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  3314. int ret;
  3315. mutex_lock(&mvm->mutex);
  3316. if (mvmvif->csa_failed) {
  3317. mvmvif->csa_failed = false;
  3318. ret = -EIO;
  3319. goto out_unlock;
  3320. }
  3321. if (vif->type == NL80211_IFTYPE_STATION) {
  3322. struct iwl_mvm_sta *mvmsta;
  3323. mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
  3324. mvmvif->ap_sta_id);
  3325. if (WARN_ON(!mvmsta)) {
  3326. ret = -EIO;
  3327. goto out_unlock;
  3328. }
  3329. iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
  3330. iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
  3331. ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
  3332. if (ret)
  3333. goto out_unlock;
  3334. iwl_mvm_stop_session_protection(mvm, vif);
  3335. }
  3336. mvmvif->ps_disabled = false;
  3337. ret = iwl_mvm_power_update_ps(mvm);
  3338. out_unlock:
  3339. mutex_unlock(&mvm->mutex);
  3340. return ret;
  3341. }
  3342. static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
  3343. {
  3344. if (drop) {
  3345. if (iwl_mvm_has_new_tx_api(mvm))
  3346. /* TODO new tx api */
  3347. WARN_ONCE(1,
  3348. "Need to implement flush TX queue\n");
  3349. else
  3350. iwl_mvm_flush_tx_path(mvm,
  3351. iwl_mvm_flushable_queues(mvm) & queues,
  3352. 0);
  3353. } else {
  3354. if (iwl_mvm_has_new_tx_api(mvm)) {
  3355. struct ieee80211_sta *sta;
  3356. int i;
  3357. mutex_lock(&mvm->mutex);
  3358. for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
  3359. sta = rcu_dereference_protected(
  3360. mvm->fw_id_to_mac_id[i],
  3361. lockdep_is_held(&mvm->mutex));
  3362. if (IS_ERR_OR_NULL(sta))
  3363. continue;
  3364. iwl_mvm_wait_sta_queues_empty(mvm,
  3365. iwl_mvm_sta_from_mac80211(sta));
  3366. }
  3367. mutex_unlock(&mvm->mutex);
  3368. } else {
  3369. iwl_trans_wait_tx_queues_empty(mvm->trans,
  3370. queues);
  3371. }
  3372. }
  3373. }
  3374. static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
  3375. struct ieee80211_vif *vif, u32 queues, bool drop)
  3376. {
  3377. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  3378. struct iwl_mvm_vif *mvmvif;
  3379. struct iwl_mvm_sta *mvmsta;
  3380. struct ieee80211_sta *sta;
  3381. int i;
  3382. u32 msk = 0;
  3383. if (!vif) {
  3384. iwl_mvm_flush_no_vif(mvm, queues, drop);
  3385. return;
  3386. }
  3387. if (vif->type != NL80211_IFTYPE_STATION)
  3388. return;
  3389. /* Make sure we're done with the deferred traffic before flushing */
  3390. flush_work(&mvm->add_stream_wk);
  3391. mutex_lock(&mvm->mutex);
  3392. mvmvif = iwl_mvm_vif_from_mac80211(vif);
  3393. /* flush the AP-station and all TDLS peers */
  3394. for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
  3395. sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
  3396. lockdep_is_held(&mvm->mutex));
  3397. if (IS_ERR_OR_NULL(sta))
  3398. continue;
  3399. mvmsta = iwl_mvm_sta_from_mac80211(sta);
  3400. if (mvmsta->vif != vif)
  3401. continue;
  3402. /* make sure only TDLS peers or the AP are flushed */
  3403. WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
  3404. if (drop) {
  3405. if (iwl_mvm_flush_sta(mvm, mvmsta, false, 0))
  3406. IWL_ERR(mvm, "flush request fail\n");
  3407. } else {
  3408. msk |= mvmsta->tfd_queue_msk;
  3409. if (iwl_mvm_has_new_tx_api(mvm))
  3410. iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
  3411. }
  3412. }
  3413. mutex_unlock(&mvm->mutex);
  3414. /* this can take a while, and we may need/want other operations
  3415. * to succeed while doing this, so do it without the mutex held
  3416. */
  3417. if (!drop && !iwl_mvm_has_new_tx_api(mvm))
  3418. iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
  3419. }
  3420. static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
  3421. struct survey_info *survey)
  3422. {
  3423. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  3424. int ret;
  3425. memset(survey, 0, sizeof(*survey));
  3426. /* only support global statistics right now */
  3427. if (idx != 0)
  3428. return -ENOENT;
  3429. if (!fw_has_capa(&mvm->fw->ucode_capa,
  3430. IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
  3431. return -ENOENT;
  3432. mutex_lock(&mvm->mutex);
  3433. if (iwl_mvm_firmware_running(mvm)) {
  3434. ret = iwl_mvm_request_statistics(mvm, false);
  3435. if (ret)
  3436. goto out;
  3437. }
  3438. survey->filled = SURVEY_INFO_TIME |
  3439. SURVEY_INFO_TIME_RX |
  3440. SURVEY_INFO_TIME_TX |
  3441. SURVEY_INFO_TIME_SCAN;
  3442. survey->time = mvm->accu_radio_stats.on_time_rf +
  3443. mvm->radio_stats.on_time_rf;
  3444. do_div(survey->time, USEC_PER_MSEC);
  3445. survey->time_rx = mvm->accu_radio_stats.rx_time +
  3446. mvm->radio_stats.rx_time;
  3447. do_div(survey->time_rx, USEC_PER_MSEC);
  3448. survey->time_tx = mvm->accu_radio_stats.tx_time +
  3449. mvm->radio_stats.tx_time;
  3450. do_div(survey->time_tx, USEC_PER_MSEC);
  3451. survey->time_scan = mvm->accu_radio_stats.on_time_scan +
  3452. mvm->radio_stats.on_time_scan;
  3453. do_div(survey->time_scan, USEC_PER_MSEC);
  3454. ret = 0;
  3455. out:
  3456. mutex_unlock(&mvm->mutex);
  3457. return ret;
  3458. }
  3459. static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
  3460. struct ieee80211_vif *vif,
  3461. struct ieee80211_sta *sta,
  3462. struct station_info *sinfo)
  3463. {
  3464. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  3465. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  3466. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  3467. if (mvmsta->avg_energy) {
  3468. sinfo->signal_avg = mvmsta->avg_energy;
  3469. sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL_AVG);
  3470. }
  3471. if (!fw_has_capa(&mvm->fw->ucode_capa,
  3472. IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
  3473. return;
  3474. /* if beacon filtering isn't on mac80211 does it anyway */
  3475. if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
  3476. return;
  3477. if (!vif->bss_conf.assoc)
  3478. return;
  3479. mutex_lock(&mvm->mutex);
  3480. if (mvmvif->ap_sta_id != mvmsta->sta_id)
  3481. goto unlock;
  3482. if (iwl_mvm_request_statistics(mvm, false))
  3483. goto unlock;
  3484. sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
  3485. mvmvif->beacon_stats.accu_num_beacons;
  3486. sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_RX);
  3487. if (mvmvif->beacon_stats.avg_signal) {
  3488. /* firmware only reports a value after RXing a few beacons */
  3489. sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
  3490. sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
  3491. }
  3492. unlock:
  3493. mutex_unlock(&mvm->mutex);
  3494. }
  3495. static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
  3496. struct ieee80211_vif *vif,
  3497. const struct ieee80211_event *event)
  3498. {
  3499. #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
  3500. do { \
  3501. if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
  3502. break; \
  3503. iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
  3504. } while (0)
  3505. struct iwl_fw_dbg_trigger_tlv *trig;
  3506. struct iwl_fw_dbg_trigger_mlme *trig_mlme;
  3507. if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_MLME))
  3508. return;
  3509. trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_MLME);
  3510. trig_mlme = (void *)trig->data;
  3511. if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
  3512. ieee80211_vif_to_wdev(vif), trig))
  3513. return;
  3514. if (event->u.mlme.data == ASSOC_EVENT) {
  3515. if (event->u.mlme.status == MLME_DENIED)
  3516. CHECK_MLME_TRIGGER(stop_assoc_denied,
  3517. "DENIED ASSOC: reason %d",
  3518. event->u.mlme.reason);
  3519. else if (event->u.mlme.status == MLME_TIMEOUT)
  3520. CHECK_MLME_TRIGGER(stop_assoc_timeout,
  3521. "ASSOC TIMEOUT");
  3522. } else if (event->u.mlme.data == AUTH_EVENT) {
  3523. if (event->u.mlme.status == MLME_DENIED)
  3524. CHECK_MLME_TRIGGER(stop_auth_denied,
  3525. "DENIED AUTH: reason %d",
  3526. event->u.mlme.reason);
  3527. else if (event->u.mlme.status == MLME_TIMEOUT)
  3528. CHECK_MLME_TRIGGER(stop_auth_timeout,
  3529. "AUTH TIMEOUT");
  3530. } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
  3531. CHECK_MLME_TRIGGER(stop_rx_deauth,
  3532. "DEAUTH RX %d", event->u.mlme.reason);
  3533. } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
  3534. CHECK_MLME_TRIGGER(stop_tx_deauth,
  3535. "DEAUTH TX %d", event->u.mlme.reason);
  3536. }
  3537. #undef CHECK_MLME_TRIGGER
  3538. }
  3539. static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
  3540. struct ieee80211_vif *vif,
  3541. const struct ieee80211_event *event)
  3542. {
  3543. struct iwl_fw_dbg_trigger_tlv *trig;
  3544. struct iwl_fw_dbg_trigger_ba *ba_trig;
  3545. if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
  3546. return;
  3547. trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
  3548. ba_trig = (void *)trig->data;
  3549. if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
  3550. ieee80211_vif_to_wdev(vif), trig))
  3551. return;
  3552. if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
  3553. return;
  3554. iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
  3555. "BAR received from %pM, tid %d, ssn %d",
  3556. event->u.ba.sta->addr, event->u.ba.tid,
  3557. event->u.ba.ssn);
  3558. }
  3559. static void
  3560. iwl_mvm_event_frame_timeout_callback(struct iwl_mvm *mvm,
  3561. struct ieee80211_vif *vif,
  3562. const struct ieee80211_event *event)
  3563. {
  3564. struct iwl_fw_dbg_trigger_tlv *trig;
  3565. struct iwl_fw_dbg_trigger_ba *ba_trig;
  3566. if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
  3567. return;
  3568. trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
  3569. ba_trig = (void *)trig->data;
  3570. if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
  3571. ieee80211_vif_to_wdev(vif), trig))
  3572. return;
  3573. if (!(le16_to_cpu(ba_trig->frame_timeout) & BIT(event->u.ba.tid)))
  3574. return;
  3575. iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
  3576. "Frame from %pM timed out, tid %d",
  3577. event->u.ba.sta->addr, event->u.ba.tid);
  3578. }
  3579. static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
  3580. struct ieee80211_vif *vif,
  3581. const struct ieee80211_event *event)
  3582. {
  3583. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  3584. switch (event->type) {
  3585. case MLME_EVENT:
  3586. iwl_mvm_event_mlme_callback(mvm, vif, event);
  3587. break;
  3588. case BAR_RX_EVENT:
  3589. iwl_mvm_event_bar_rx_callback(mvm, vif, event);
  3590. break;
  3591. case BA_FRAME_TIMEOUT:
  3592. iwl_mvm_event_frame_timeout_callback(mvm, vif, event);
  3593. break;
  3594. default:
  3595. break;
  3596. }
  3597. }
  3598. void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
  3599. struct iwl_mvm_internal_rxq_notif *notif,
  3600. u32 size)
  3601. {
  3602. u32 qmask = BIT(mvm->trans->num_rx_queues) - 1;
  3603. int ret;
  3604. lockdep_assert_held(&mvm->mutex);
  3605. /* TODO - remove a000 disablement when we have RXQ config API */
  3606. if (!iwl_mvm_has_new_rx_api(mvm) ||
  3607. mvm->trans->cfg->device_family == IWL_DEVICE_FAMILY_A000)
  3608. return;
  3609. notif->cookie = mvm->queue_sync_cookie;
  3610. if (notif->sync)
  3611. atomic_set(&mvm->queue_sync_counter,
  3612. mvm->trans->num_rx_queues);
  3613. ret = iwl_mvm_notify_rx_queue(mvm, qmask, (u8 *)notif, size);
  3614. if (ret) {
  3615. IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
  3616. goto out;
  3617. }
  3618. if (notif->sync) {
  3619. ret = wait_event_timeout(mvm->rx_sync_waitq,
  3620. atomic_read(&mvm->queue_sync_counter) == 0 ||
  3621. iwl_mvm_is_radio_killed(mvm),
  3622. HZ);
  3623. WARN_ON_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm));
  3624. }
  3625. out:
  3626. atomic_set(&mvm->queue_sync_counter, 0);
  3627. mvm->queue_sync_cookie++;
  3628. }
  3629. static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
  3630. {
  3631. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  3632. struct iwl_mvm_internal_rxq_notif data = {
  3633. .type = IWL_MVM_RXQ_EMPTY,
  3634. .sync = 1,
  3635. };
  3636. mutex_lock(&mvm->mutex);
  3637. iwl_mvm_sync_rx_queues_internal(mvm, &data, sizeof(data));
  3638. mutex_unlock(&mvm->mutex);
  3639. }
  3640. const struct ieee80211_ops iwl_mvm_hw_ops = {
  3641. .tx = iwl_mvm_mac_tx,
  3642. .ampdu_action = iwl_mvm_mac_ampdu_action,
  3643. .start = iwl_mvm_mac_start,
  3644. .reconfig_complete = iwl_mvm_mac_reconfig_complete,
  3645. .stop = iwl_mvm_mac_stop,
  3646. .add_interface = iwl_mvm_mac_add_interface,
  3647. .remove_interface = iwl_mvm_mac_remove_interface,
  3648. .config = iwl_mvm_mac_config,
  3649. .prepare_multicast = iwl_mvm_prepare_multicast,
  3650. .configure_filter = iwl_mvm_configure_filter,
  3651. .config_iface_filter = iwl_mvm_config_iface_filter,
  3652. .bss_info_changed = iwl_mvm_bss_info_changed,
  3653. .hw_scan = iwl_mvm_mac_hw_scan,
  3654. .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
  3655. .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
  3656. .sta_state = iwl_mvm_mac_sta_state,
  3657. .sta_notify = iwl_mvm_mac_sta_notify,
  3658. .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
  3659. .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
  3660. .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
  3661. .sta_rc_update = iwl_mvm_sta_rc_update,
  3662. .conf_tx = iwl_mvm_mac_conf_tx,
  3663. .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
  3664. .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
  3665. .flush = iwl_mvm_mac_flush,
  3666. .sched_scan_start = iwl_mvm_mac_sched_scan_start,
  3667. .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
  3668. .set_key = iwl_mvm_mac_set_key,
  3669. .update_tkip_key = iwl_mvm_mac_update_tkip_key,
  3670. .remain_on_channel = iwl_mvm_roc,
  3671. .cancel_remain_on_channel = iwl_mvm_cancel_roc,
  3672. .add_chanctx = iwl_mvm_add_chanctx,
  3673. .remove_chanctx = iwl_mvm_remove_chanctx,
  3674. .change_chanctx = iwl_mvm_change_chanctx,
  3675. .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
  3676. .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
  3677. .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
  3678. .start_ap = iwl_mvm_start_ap_ibss,
  3679. .stop_ap = iwl_mvm_stop_ap_ibss,
  3680. .join_ibss = iwl_mvm_start_ap_ibss,
  3681. .leave_ibss = iwl_mvm_stop_ap_ibss,
  3682. .tx_last_beacon = iwl_mvm_tx_last_beacon,
  3683. .set_tim = iwl_mvm_set_tim,
  3684. .channel_switch = iwl_mvm_channel_switch,
  3685. .pre_channel_switch = iwl_mvm_pre_channel_switch,
  3686. .post_channel_switch = iwl_mvm_post_channel_switch,
  3687. .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
  3688. .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
  3689. .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
  3690. .event_callback = iwl_mvm_mac_event_callback,
  3691. .sync_rx_queues = iwl_mvm_sync_rx_queues,
  3692. CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
  3693. #ifdef CONFIG_PM_SLEEP
  3694. /* look at d3.c */
  3695. .suspend = iwl_mvm_suspend,
  3696. .resume = iwl_mvm_resume,
  3697. .set_wakeup = iwl_mvm_set_wakeup,
  3698. .set_rekey_data = iwl_mvm_set_rekey_data,
  3699. #if IS_ENABLED(CONFIG_IPV6)
  3700. .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
  3701. #endif
  3702. .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
  3703. #endif
  3704. .get_survey = iwl_mvm_mac_get_survey,
  3705. .sta_statistics = iwl_mvm_mac_sta_statistics,
  3706. };