mac80211.c 118 KB

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