mac80211.c 115 KB

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