mac80211.c 121 KB

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