mac80211.c 116 KB

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