mac80211.c 92 KB

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