mac80211.c 117 KB

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