mac80211.c 104 KB

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