mac80211.c 118 KB

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