mac80211.c 119 KB

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