mac80211.c 62 KB

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