mac80211.c 72 KB

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