mac80211.c 111 KB

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