mac80211.c 114 KB

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