mac80211.c 84 KB

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