mac80211.c 122 KB

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