mac80211.c 115 KB

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