mac80211.c 119 KB

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