mac80211.c 92 KB

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