mac80211.c 118 KB

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