mac80211.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789
  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 - 2013 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 - 2013 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 <net/mac80211.h>
  70. #include <net/tcp.h>
  71. #include "iwl-op-mode.h"
  72. #include "iwl-io.h"
  73. #include "mvm.h"
  74. #include "sta.h"
  75. #include "time-event.h"
  76. #include "iwl-eeprom-parse.h"
  77. #include "fw-api-scan.h"
  78. #include "iwl-phy-db.h"
  79. #include "testmode.h"
  80. static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
  81. {
  82. .max = 1,
  83. .types = BIT(NL80211_IFTYPE_STATION),
  84. },
  85. {
  86. .max = 1,
  87. .types = BIT(NL80211_IFTYPE_AP) |
  88. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  89. BIT(NL80211_IFTYPE_P2P_GO),
  90. },
  91. {
  92. .max = 1,
  93. .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
  94. },
  95. };
  96. static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
  97. {
  98. .num_different_channels = 1,
  99. .max_interfaces = 3,
  100. .limits = iwl_mvm_limits,
  101. .n_limits = ARRAY_SIZE(iwl_mvm_limits),
  102. },
  103. };
  104. #ifdef CONFIG_PM_SLEEP
  105. static const struct nl80211_wowlan_tcp_data_token_feature
  106. iwl_mvm_wowlan_tcp_token_feature = {
  107. .min_len = 0,
  108. .max_len = 255,
  109. .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
  110. };
  111. static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
  112. .tok = &iwl_mvm_wowlan_tcp_token_feature,
  113. .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
  114. sizeof(struct ethhdr) -
  115. sizeof(struct iphdr) -
  116. sizeof(struct tcphdr),
  117. .data_interval_max = 65535, /* __le16 in API */
  118. .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
  119. sizeof(struct ethhdr) -
  120. sizeof(struct iphdr) -
  121. sizeof(struct tcphdr),
  122. .seq = true,
  123. };
  124. #endif
  125. static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
  126. {
  127. int i;
  128. memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
  129. for (i = 0; i < NUM_PHY_CTX; i++) {
  130. mvm->phy_ctxts[i].id = i;
  131. mvm->phy_ctxts[i].ref = 0;
  132. }
  133. }
  134. static int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm)
  135. {
  136. /* we create the 802.11 header and SSID element */
  137. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID)
  138. return mvm->fw->ucode_capa.max_probe_length - 24 - 2;
  139. return mvm->fw->ucode_capa.max_probe_length - 24 - 34;
  140. }
  141. int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
  142. {
  143. struct ieee80211_hw *hw = mvm->hw;
  144. int num_mac, ret, i;
  145. /* Tell mac80211 our characteristics */
  146. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  147. IEEE80211_HW_SPECTRUM_MGMT |
  148. IEEE80211_HW_REPORTS_TX_ACK_STATUS |
  149. IEEE80211_HW_QUEUE_CONTROL |
  150. IEEE80211_HW_WANT_MONITOR_VIF |
  151. IEEE80211_HW_SUPPORTS_PS |
  152. IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
  153. IEEE80211_HW_AMPDU_AGGREGATION |
  154. IEEE80211_HW_TIMING_BEACON_ONLY |
  155. IEEE80211_HW_CONNECTION_MONITOR |
  156. IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
  157. IEEE80211_HW_SUPPORTS_STATIC_SMPS;
  158. hw->queues = mvm->first_agg_queue;
  159. hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
  160. hw->rate_control_algorithm = "iwl-mvm-rs";
  161. /*
  162. * Enable 11w if advertised by firmware and software crypto
  163. * is not enabled (as the firmware will interpret some mgmt
  164. * packets, so enabling it with software crypto isn't safe)
  165. */
  166. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
  167. !iwlwifi_mod_params.sw_crypto)
  168. hw->flags |= IEEE80211_HW_MFP_CAPABLE;
  169. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT) {
  170. hw->flags |= IEEE80211_HW_SUPPORTS_UAPSD;
  171. hw->uapsd_queues = IWL_UAPSD_AC_INFO;
  172. hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
  173. }
  174. hw->sta_data_size = sizeof(struct iwl_mvm_sta);
  175. hw->vif_data_size = sizeof(struct iwl_mvm_vif);
  176. hw->chanctx_data_size = sizeof(u16);
  177. hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  178. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  179. BIT(NL80211_IFTYPE_AP) |
  180. BIT(NL80211_IFTYPE_P2P_GO) |
  181. BIT(NL80211_IFTYPE_P2P_DEVICE);
  182. /* IBSS has bugs in older versions */
  183. if (IWL_UCODE_API(mvm->fw->ucode_ver) >= 8)
  184. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
  185. hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
  186. WIPHY_FLAG_DISABLE_BEACON_HINTS |
  187. WIPHY_FLAG_IBSS_RSN;
  188. hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
  189. hw->wiphy->n_iface_combinations =
  190. ARRAY_SIZE(iwl_mvm_iface_combinations);
  191. hw->wiphy->max_remain_on_channel_duration = 10000;
  192. hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
  193. /* Extract MAC address */
  194. memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
  195. hw->wiphy->addresses = mvm->addresses;
  196. hw->wiphy->n_addresses = 1;
  197. /* Extract additional MAC addresses if available */
  198. num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
  199. min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
  200. for (i = 1; i < num_mac; i++) {
  201. memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
  202. ETH_ALEN);
  203. mvm->addresses[i].addr[5]++;
  204. hw->wiphy->n_addresses++;
  205. }
  206. iwl_mvm_reset_phy_ctxts(mvm);
  207. hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
  208. hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
  209. if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
  210. hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  211. &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
  212. if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
  213. hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  214. &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
  215. hw->wiphy->hw_version = mvm->trans->hw_id;
  216. if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
  217. hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
  218. else
  219. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  220. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SCHED_SCAN) {
  221. hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
  222. hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
  223. hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
  224. /* we create the 802.11 header and zero length SSID IE. */
  225. hw->wiphy->max_sched_scan_ie_len =
  226. SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
  227. }
  228. hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
  229. NL80211_FEATURE_P2P_GO_OPPPS;
  230. mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
  231. #ifdef CONFIG_PM_SLEEP
  232. if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
  233. mvm->trans->ops->d3_suspend &&
  234. mvm->trans->ops->d3_resume &&
  235. device_can_wakeup(mvm->trans->dev)) {
  236. mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
  237. WIPHY_WOWLAN_DISCONNECT |
  238. WIPHY_WOWLAN_EAP_IDENTITY_REQ |
  239. WIPHY_WOWLAN_RFKILL_RELEASE;
  240. if (!iwlwifi_mod_params.sw_crypto)
  241. mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
  242. WIPHY_WOWLAN_GTK_REKEY_FAILURE |
  243. WIPHY_WOWLAN_4WAY_HANDSHAKE;
  244. mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
  245. mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
  246. mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
  247. mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
  248. hw->wiphy->wowlan = &mvm->wowlan;
  249. }
  250. #endif
  251. ret = iwl_mvm_leds_init(mvm);
  252. if (ret)
  253. return ret;
  254. ret = ieee80211_register_hw(mvm->hw);
  255. if (ret)
  256. iwl_mvm_leds_exit(mvm);
  257. return ret;
  258. }
  259. static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
  260. struct ieee80211_tx_control *control,
  261. struct sk_buff *skb)
  262. {
  263. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  264. if (iwl_mvm_is_radio_killed(mvm)) {
  265. IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
  266. goto drop;
  267. }
  268. if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
  269. !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status))
  270. goto drop;
  271. if (control->sta) {
  272. if (iwl_mvm_tx_skb(mvm, skb, control->sta))
  273. goto drop;
  274. return;
  275. }
  276. if (iwl_mvm_tx_skb_non_sta(mvm, skb))
  277. goto drop;
  278. return;
  279. drop:
  280. ieee80211_free_txskb(hw, skb);
  281. }
  282. static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
  283. struct ieee80211_vif *vif,
  284. enum ieee80211_ampdu_mlme_action action,
  285. struct ieee80211_sta *sta, u16 tid,
  286. u16 *ssn, u8 buf_size)
  287. {
  288. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  289. int ret;
  290. IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
  291. sta->addr, tid, action);
  292. if (!(mvm->nvm_data->sku_cap_11n_enable))
  293. return -EACCES;
  294. mutex_lock(&mvm->mutex);
  295. switch (action) {
  296. case IEEE80211_AMPDU_RX_START:
  297. if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) {
  298. ret = -EINVAL;
  299. break;
  300. }
  301. ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
  302. break;
  303. case IEEE80211_AMPDU_RX_STOP:
  304. ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
  305. break;
  306. case IEEE80211_AMPDU_TX_START:
  307. if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) {
  308. ret = -EINVAL;
  309. break;
  310. }
  311. ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
  312. break;
  313. case IEEE80211_AMPDU_TX_STOP_CONT:
  314. ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
  315. break;
  316. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  317. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  318. ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
  319. break;
  320. case IEEE80211_AMPDU_TX_OPERATIONAL:
  321. ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
  322. break;
  323. default:
  324. WARN_ON_ONCE(1);
  325. ret = -EINVAL;
  326. break;
  327. }
  328. mutex_unlock(&mvm->mutex);
  329. return ret;
  330. }
  331. static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
  332. struct ieee80211_vif *vif)
  333. {
  334. struct iwl_mvm *mvm = data;
  335. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  336. mvmvif->uploaded = false;
  337. mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
  338. /* does this make sense at all? */
  339. mvmvif->color++;
  340. spin_lock_bh(&mvm->time_event_lock);
  341. iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
  342. spin_unlock_bh(&mvm->time_event_lock);
  343. mvmvif->phy_ctxt = NULL;
  344. }
  345. static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
  346. {
  347. iwl_trans_stop_device(mvm->trans);
  348. iwl_trans_stop_hw(mvm->trans, false);
  349. mvm->scan_status = IWL_MVM_SCAN_NONE;
  350. /* just in case one was running */
  351. ieee80211_remain_on_channel_expired(mvm->hw);
  352. ieee80211_iterate_active_interfaces_atomic(
  353. mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
  354. iwl_mvm_cleanup_iterator, mvm);
  355. mvm->p2p_device_vif = NULL;
  356. iwl_mvm_reset_phy_ctxts(mvm);
  357. memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
  358. memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
  359. ieee80211_wake_queues(mvm->hw);
  360. mvm->vif_count = 0;
  361. mvm->rx_ba_sessions = 0;
  362. }
  363. static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
  364. {
  365. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  366. int ret;
  367. mutex_lock(&mvm->mutex);
  368. /* Clean up some internal and mac80211 state on restart */
  369. if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
  370. iwl_mvm_restart_cleanup(mvm);
  371. ret = iwl_mvm_up(mvm);
  372. mutex_unlock(&mvm->mutex);
  373. return ret;
  374. }
  375. static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
  376. {
  377. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  378. int ret;
  379. mutex_lock(&mvm->mutex);
  380. clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
  381. ret = iwl_mvm_update_quotas(mvm, NULL);
  382. if (ret)
  383. IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
  384. ret);
  385. mutex_unlock(&mvm->mutex);
  386. }
  387. static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
  388. {
  389. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  390. flush_work(&mvm->async_handlers_wk);
  391. mutex_lock(&mvm->mutex);
  392. /* async_handlers_wk is now blocked */
  393. /*
  394. * The work item could be running or queued if the
  395. * ROC time event stops just as we get here.
  396. */
  397. cancel_work_sync(&mvm->roc_done_wk);
  398. iwl_trans_stop_device(mvm->trans);
  399. iwl_trans_stop_hw(mvm->trans, false);
  400. iwl_mvm_async_handlers_purge(mvm);
  401. /* async_handlers_list is empty and will stay empty: HW is stopped */
  402. /* the fw is stopped, the aux sta is dead: clean up driver state */
  403. iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
  404. mutex_unlock(&mvm->mutex);
  405. /*
  406. * The worker might have been waiting for the mutex, let it run and
  407. * discover that its list is now empty.
  408. */
  409. cancel_work_sync(&mvm->async_handlers_wk);
  410. }
  411. static void iwl_mvm_pm_disable_iterator(void *data, u8 *mac,
  412. struct ieee80211_vif *vif)
  413. {
  414. struct iwl_mvm *mvm = data;
  415. int ret;
  416. ret = iwl_mvm_power_disable(mvm, vif);
  417. if (ret)
  418. IWL_ERR(mvm, "failed to disable power management\n");
  419. }
  420. static void iwl_mvm_power_update_iterator(void *data, u8 *mac,
  421. struct ieee80211_vif *vif)
  422. {
  423. struct iwl_mvm *mvm = data;
  424. iwl_mvm_power_update_mode(mvm, vif);
  425. }
  426. static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
  427. {
  428. u16 i;
  429. lockdep_assert_held(&mvm->mutex);
  430. for (i = 0; i < NUM_PHY_CTX; i++)
  431. if (!mvm->phy_ctxts[i].ref)
  432. return &mvm->phy_ctxts[i];
  433. IWL_ERR(mvm, "No available PHY context\n");
  434. return NULL;
  435. }
  436. static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
  437. struct ieee80211_vif *vif)
  438. {
  439. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  440. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  441. int ret;
  442. /*
  443. * Not much to do here. The stack will not allow interface
  444. * types or combinations that we didn't advertise, so we
  445. * don't really have to check the types.
  446. */
  447. mutex_lock(&mvm->mutex);
  448. /* Allocate resources for the MAC context, and add it to the fw */
  449. ret = iwl_mvm_mac_ctxt_init(mvm, vif);
  450. if (ret)
  451. goto out_unlock;
  452. /*
  453. * TODO: remove this temporary code.
  454. * Currently MVM FW supports power management only on single MAC.
  455. * If new interface added, disable PM on existing interface.
  456. * P2P device is a special case, since it is handled by FW similary to
  457. * scan. If P2P deviced is added, PM remains enabled on existing
  458. * interface.
  459. * Note: the method below does not count the new interface being added
  460. * at this moment.
  461. */
  462. if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
  463. mvm->vif_count++;
  464. if (mvm->vif_count > 1) {
  465. IWL_DEBUG_MAC80211(mvm,
  466. "Disable power on existing interfaces\n");
  467. ieee80211_iterate_active_interfaces_atomic(
  468. mvm->hw,
  469. IEEE80211_IFACE_ITER_NORMAL,
  470. iwl_mvm_pm_disable_iterator, mvm);
  471. }
  472. /*
  473. * The AP binding flow can be done only after the beacon
  474. * template is configured (which happens only in the mac80211
  475. * start_ap() flow), and adding the broadcast station can happen
  476. * only after the binding.
  477. * In addition, since modifying the MAC before adding a bcast
  478. * station is not allowed by the FW, delay the adding of MAC context to
  479. * the point where we can also add the bcast station.
  480. * In short: there's not much we can do at this point, other than
  481. * allocating resources :)
  482. */
  483. if (vif->type == NL80211_IFTYPE_AP ||
  484. vif->type == NL80211_IFTYPE_ADHOC) {
  485. u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif);
  486. ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta,
  487. qmask);
  488. if (ret) {
  489. IWL_ERR(mvm, "Failed to allocate bcast sta\n");
  490. goto out_release;
  491. }
  492. iwl_mvm_vif_dbgfs_register(mvm, vif);
  493. goto out_unlock;
  494. }
  495. ret = iwl_mvm_mac_ctxt_add(mvm, vif);
  496. if (ret)
  497. goto out_release;
  498. /*
  499. * Update power state on the new interface. Admittedly, based on
  500. * mac80211 logics this power update will disable power management
  501. */
  502. iwl_mvm_power_update_mode(mvm, vif);
  503. /* beacon filtering */
  504. ret = iwl_mvm_disable_beacon_filter(mvm, vif);
  505. if (ret)
  506. goto out_remove_mac;
  507. if (!mvm->bf_allowed_vif &&
  508. vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
  509. mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED){
  510. mvm->bf_allowed_vif = mvmvif;
  511. vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
  512. IEEE80211_VIF_SUPPORTS_CQM_RSSI;
  513. }
  514. /*
  515. * P2P_DEVICE interface does not have a channel context assigned to it,
  516. * so a dedicated PHY context is allocated to it and the corresponding
  517. * MAC context is bound to it at this stage.
  518. */
  519. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  520. mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
  521. if (!mvmvif->phy_ctxt) {
  522. ret = -ENOSPC;
  523. goto out_free_bf;
  524. }
  525. iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
  526. ret = iwl_mvm_binding_add_vif(mvm, vif);
  527. if (ret)
  528. goto out_unref_phy;
  529. ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
  530. if (ret)
  531. goto out_unbind;
  532. /* Save a pointer to p2p device vif, so it can later be used to
  533. * update the p2p device MAC when a GO is started/stopped */
  534. mvm->p2p_device_vif = vif;
  535. }
  536. iwl_mvm_vif_dbgfs_register(mvm, vif);
  537. goto out_unlock;
  538. out_unbind:
  539. iwl_mvm_binding_remove_vif(mvm, vif);
  540. out_unref_phy:
  541. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  542. out_free_bf:
  543. if (mvm->bf_allowed_vif == mvmvif) {
  544. mvm->bf_allowed_vif = NULL;
  545. vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
  546. IEEE80211_VIF_SUPPORTS_CQM_RSSI);
  547. }
  548. out_remove_mac:
  549. mvmvif->phy_ctxt = NULL;
  550. iwl_mvm_mac_ctxt_remove(mvm, vif);
  551. out_release:
  552. if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
  553. mvm->vif_count--;
  554. ieee80211_iterate_active_interfaces(
  555. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  556. iwl_mvm_power_update_iterator, mvm);
  557. iwl_mvm_mac_ctxt_release(mvm, vif);
  558. out_unlock:
  559. mutex_unlock(&mvm->mutex);
  560. return ret;
  561. }
  562. static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
  563. struct ieee80211_vif *vif)
  564. {
  565. u32 tfd_msk = 0, ac;
  566. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  567. if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
  568. tfd_msk |= BIT(vif->hw_queue[ac]);
  569. if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
  570. tfd_msk |= BIT(vif->cab_queue);
  571. if (tfd_msk) {
  572. mutex_lock(&mvm->mutex);
  573. iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
  574. mutex_unlock(&mvm->mutex);
  575. }
  576. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  577. /*
  578. * Flush the ROC worker which will flush the OFFCHANNEL queue.
  579. * We assume here that all the packets sent to the OFFCHANNEL
  580. * queue are sent in ROC session.
  581. */
  582. flush_work(&mvm->roc_done_wk);
  583. } else {
  584. /*
  585. * By now, all the AC queues are empty. The AGG queues are
  586. * empty too. We already got all the Tx responses for all the
  587. * packets in the queues. The drain work can have been
  588. * triggered. Flush it.
  589. */
  590. flush_work(&mvm->sta_drained_wk);
  591. }
  592. }
  593. static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
  594. struct ieee80211_vif *vif)
  595. {
  596. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  597. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  598. iwl_mvm_prepare_mac_removal(mvm, vif);
  599. mutex_lock(&mvm->mutex);
  600. if (mvm->bf_allowed_vif == mvmvif) {
  601. mvm->bf_allowed_vif = NULL;
  602. vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
  603. IEEE80211_VIF_SUPPORTS_CQM_RSSI);
  604. }
  605. iwl_mvm_vif_dbgfs_clean(mvm, vif);
  606. /*
  607. * For AP/GO interface, the tear down of the resources allocated to the
  608. * interface is be handled as part of the stop_ap flow.
  609. */
  610. if (vif->type == NL80211_IFTYPE_AP ||
  611. vif->type == NL80211_IFTYPE_ADHOC) {
  612. #ifdef CONFIG_NL80211_TESTMODE
  613. if (vif == mvm->noa_vif) {
  614. mvm->noa_vif = NULL;
  615. mvm->noa_duration = 0;
  616. }
  617. #endif
  618. iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
  619. goto out_release;
  620. }
  621. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  622. mvm->p2p_device_vif = NULL;
  623. iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
  624. iwl_mvm_binding_remove_vif(mvm, vif);
  625. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  626. mvmvif->phy_ctxt = NULL;
  627. }
  628. /*
  629. * TODO: remove this temporary code.
  630. * Currently MVM FW supports power management only on single MAC.
  631. * Check if only one additional interface remains after removing
  632. * current one. Update power mode on the remaining interface.
  633. */
  634. if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
  635. mvm->vif_count--;
  636. IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n",
  637. mvm->vif_count);
  638. if (mvm->vif_count == 1) {
  639. ieee80211_iterate_active_interfaces(
  640. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  641. iwl_mvm_power_update_iterator, mvm);
  642. }
  643. iwl_mvm_mac_ctxt_remove(mvm, vif);
  644. out_release:
  645. iwl_mvm_mac_ctxt_release(mvm, vif);
  646. mutex_unlock(&mvm->mutex);
  647. }
  648. static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  649. s8 tx_power)
  650. {
  651. /* FW is in charge of regulatory enforcement */
  652. struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
  653. .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
  654. .pwr_restriction = cpu_to_le16(tx_power),
  655. };
  656. return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, CMD_SYNC,
  657. sizeof(reduce_txpwr_cmd),
  658. &reduce_txpwr_cmd);
  659. }
  660. static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
  661. {
  662. return 0;
  663. }
  664. static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
  665. unsigned int changed_flags,
  666. unsigned int *total_flags,
  667. u64 multicast)
  668. {
  669. *total_flags = 0;
  670. }
  671. static int iwl_mvm_configure_mcast_filter(struct iwl_mvm *mvm,
  672. struct ieee80211_vif *vif)
  673. {
  674. struct iwl_mcast_filter_cmd mcast_filter_cmd = {
  675. .pass_all = 1,
  676. };
  677. memcpy(mcast_filter_cmd.bssid, vif->bss_conf.bssid, ETH_ALEN);
  678. return iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_SYNC,
  679. sizeof(mcast_filter_cmd),
  680. &mcast_filter_cmd);
  681. }
  682. static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
  683. struct ieee80211_vif *vif,
  684. struct ieee80211_bss_conf *bss_conf,
  685. u32 changes)
  686. {
  687. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  688. int ret;
  689. ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
  690. if (ret)
  691. IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
  692. if (changes & BSS_CHANGED_ASSOC) {
  693. if (bss_conf->assoc) {
  694. /* add quota for this interface */
  695. ret = iwl_mvm_update_quotas(mvm, vif);
  696. if (ret) {
  697. IWL_ERR(mvm, "failed to update quotas\n");
  698. return;
  699. }
  700. iwl_mvm_configure_mcast_filter(mvm, vif);
  701. if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
  702. &mvm->status)) {
  703. /*
  704. * If we're restarting then the firmware will
  705. * obviously have lost synchronisation with
  706. * the AP. It will attempt to synchronise by
  707. * itself, but we can make it more reliable by
  708. * scheduling a session protection time event.
  709. *
  710. * The firmware needs to receive a beacon to
  711. * catch up with synchronisation, use 110% of
  712. * the beacon interval.
  713. *
  714. * Set a large maximum delay to allow for more
  715. * than a single interface.
  716. */
  717. u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
  718. iwl_mvm_protect_session(mvm, vif, dur, dur,
  719. 5 * dur);
  720. }
  721. } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
  722. /* remove AP station now that the MAC is unassoc */
  723. ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
  724. if (ret)
  725. IWL_ERR(mvm, "failed to remove AP station\n");
  726. mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
  727. /* remove quota for this interface */
  728. ret = iwl_mvm_update_quotas(mvm, NULL);
  729. if (ret)
  730. IWL_ERR(mvm, "failed to update quotas\n");
  731. }
  732. /* reset rssi values */
  733. mvmvif->bf_data.ave_beacon_signal = 0;
  734. if (!(mvm->fw->ucode_capa.flags &
  735. IWL_UCODE_TLV_FLAGS_PM_CMD_SUPPORT)) {
  736. /* Workaround for FW bug, otherwise FW disables device
  737. * power save upon disassociation
  738. */
  739. ret = iwl_mvm_power_update_mode(mvm, vif);
  740. if (ret)
  741. IWL_ERR(mvm, "failed to update power mode\n");
  742. }
  743. iwl_mvm_bt_coex_vif_change(mvm);
  744. } else if (changes & BSS_CHANGED_BEACON_INFO) {
  745. /*
  746. * We received a beacon _after_ association so
  747. * remove the session protection.
  748. */
  749. iwl_mvm_remove_time_event(mvm, mvmvif,
  750. &mvmvif->time_event_data);
  751. } else if (changes & (BSS_CHANGED_PS | BSS_CHANGED_QOS)) {
  752. ret = iwl_mvm_power_update_mode(mvm, vif);
  753. if (ret)
  754. IWL_ERR(mvm, "failed to update power mode\n");
  755. }
  756. if (changes & BSS_CHANGED_TXPOWER) {
  757. IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
  758. bss_conf->txpower);
  759. iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
  760. }
  761. if (changes & BSS_CHANGED_CQM) {
  762. IWL_DEBUG_MAC80211(mvm, "cqm info_changed");
  763. /* reset cqm events tracking */
  764. mvmvif->bf_data.last_cqm_event = 0;
  765. ret = iwl_mvm_update_beacon_filter(mvm, vif);
  766. if (ret)
  767. IWL_ERR(mvm, "failed to update CQM thresholds\n");
  768. }
  769. }
  770. static int iwl_mvm_start_ap_ibss(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. mutex_lock(&mvm->mutex);
  777. /* Send the beacon template */
  778. ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
  779. if (ret)
  780. goto out_unlock;
  781. /* Add the mac context */
  782. ret = iwl_mvm_mac_ctxt_add(mvm, vif);
  783. if (ret)
  784. goto out_unlock;
  785. /* Perform the binding */
  786. ret = iwl_mvm_binding_add_vif(mvm, vif);
  787. if (ret)
  788. goto out_remove;
  789. mvmvif->ap_ibss_active = true;
  790. /* Send the bcast station. At this stage the TBTT and DTIM time events
  791. * are added and applied to the scheduler */
  792. ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
  793. if (ret)
  794. goto out_unbind;
  795. ret = iwl_mvm_update_quotas(mvm, vif);
  796. if (ret)
  797. goto out_rm_bcast;
  798. /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
  799. if (vif->p2p && mvm->p2p_device_vif)
  800. iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
  801. iwl_mvm_bt_coex_vif_change(mvm);
  802. mutex_unlock(&mvm->mutex);
  803. return 0;
  804. out_rm_bcast:
  805. iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
  806. out_unbind:
  807. iwl_mvm_binding_remove_vif(mvm, vif);
  808. out_remove:
  809. iwl_mvm_mac_ctxt_remove(mvm, vif);
  810. out_unlock:
  811. mutex_unlock(&mvm->mutex);
  812. return ret;
  813. }
  814. static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
  815. struct ieee80211_vif *vif)
  816. {
  817. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  818. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  819. iwl_mvm_prepare_mac_removal(mvm, vif);
  820. mutex_lock(&mvm->mutex);
  821. mvmvif->ap_ibss_active = false;
  822. iwl_mvm_bt_coex_vif_change(mvm);
  823. /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
  824. if (vif->p2p && mvm->p2p_device_vif)
  825. iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
  826. iwl_mvm_update_quotas(mvm, NULL);
  827. iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
  828. iwl_mvm_binding_remove_vif(mvm, vif);
  829. iwl_mvm_mac_ctxt_remove(mvm, vif);
  830. mutex_unlock(&mvm->mutex);
  831. }
  832. static void
  833. iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
  834. struct ieee80211_vif *vif,
  835. struct ieee80211_bss_conf *bss_conf,
  836. u32 changes)
  837. {
  838. /* Need to send a new beacon template to the FW */
  839. if (changes & BSS_CHANGED_BEACON) {
  840. if (iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
  841. IWL_WARN(mvm, "Failed updating beacon data\n");
  842. }
  843. }
  844. static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
  845. struct ieee80211_vif *vif,
  846. struct ieee80211_bss_conf *bss_conf,
  847. u32 changes)
  848. {
  849. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  850. mutex_lock(&mvm->mutex);
  851. switch (vif->type) {
  852. case NL80211_IFTYPE_STATION:
  853. iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
  854. break;
  855. case NL80211_IFTYPE_AP:
  856. case NL80211_IFTYPE_ADHOC:
  857. iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
  858. break;
  859. default:
  860. /* shouldn't happen */
  861. WARN_ON_ONCE(1);
  862. }
  863. mutex_unlock(&mvm->mutex);
  864. }
  865. static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
  866. struct ieee80211_vif *vif,
  867. struct cfg80211_scan_request *req)
  868. {
  869. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  870. int ret;
  871. if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS)
  872. return -EINVAL;
  873. mutex_lock(&mvm->mutex);
  874. if (mvm->scan_status == IWL_MVM_SCAN_NONE)
  875. ret = iwl_mvm_scan_request(mvm, vif, req);
  876. else
  877. ret = -EBUSY;
  878. mutex_unlock(&mvm->mutex);
  879. return ret;
  880. }
  881. static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
  882. struct ieee80211_vif *vif)
  883. {
  884. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  885. mutex_lock(&mvm->mutex);
  886. iwl_mvm_cancel_scan(mvm);
  887. mutex_unlock(&mvm->mutex);
  888. }
  889. static void
  890. iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
  891. struct ieee80211_sta *sta, u16 tid,
  892. int num_frames,
  893. enum ieee80211_frame_release_type reason,
  894. bool more_data)
  895. {
  896. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  897. /* TODO: how do we tell the fw to send frames for a specific TID */
  898. /*
  899. * The fw will send EOSP notification when the last frame will be
  900. * transmitted.
  901. */
  902. iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames);
  903. }
  904. static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
  905. struct ieee80211_vif *vif,
  906. enum sta_notify_cmd cmd,
  907. struct ieee80211_sta *sta)
  908. {
  909. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  910. struct iwl_mvm_sta *mvmsta = (void *)sta->drv_priv;
  911. switch (cmd) {
  912. case STA_NOTIFY_SLEEP:
  913. if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
  914. ieee80211_sta_block_awake(hw, sta, true);
  915. /*
  916. * The fw updates the STA to be asleep. Tx packets on the Tx
  917. * queues to this station will not be transmitted. The fw will
  918. * send a Tx response with TX_STATUS_FAIL_DEST_PS.
  919. */
  920. break;
  921. case STA_NOTIFY_AWAKE:
  922. if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
  923. break;
  924. iwl_mvm_sta_modify_ps_wake(mvm, sta);
  925. break;
  926. default:
  927. break;
  928. }
  929. }
  930. static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
  931. struct ieee80211_vif *vif,
  932. struct ieee80211_sta *sta,
  933. enum ieee80211_sta_state old_state,
  934. enum ieee80211_sta_state new_state)
  935. {
  936. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  937. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  938. int ret;
  939. IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
  940. sta->addr, old_state, new_state);
  941. /* this would be a mac80211 bug ... but don't crash */
  942. if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
  943. return -EINVAL;
  944. /* if a STA is being removed, reuse its ID */
  945. flush_work(&mvm->sta_drained_wk);
  946. mutex_lock(&mvm->mutex);
  947. if (old_state == IEEE80211_STA_NOTEXIST &&
  948. new_state == IEEE80211_STA_NONE) {
  949. /*
  950. * Firmware bug - it'll crash if the beacon interval is less
  951. * than 16. We can't avoid connecting at all, so refuse the
  952. * station state change, this will cause mac80211 to abandon
  953. * attempts to connect to this AP, and eventually wpa_s will
  954. * blacklist the AP...
  955. */
  956. if (vif->type == NL80211_IFTYPE_STATION &&
  957. vif->bss_conf.beacon_int < 16) {
  958. IWL_ERR(mvm,
  959. "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
  960. sta->addr, vif->bss_conf.beacon_int);
  961. ret = -EINVAL;
  962. goto out_unlock;
  963. }
  964. ret = iwl_mvm_add_sta(mvm, vif, sta);
  965. } else if (old_state == IEEE80211_STA_NONE &&
  966. new_state == IEEE80211_STA_AUTH) {
  967. ret = 0;
  968. } else if (old_state == IEEE80211_STA_AUTH &&
  969. new_state == IEEE80211_STA_ASSOC) {
  970. ret = iwl_mvm_update_sta(mvm, vif, sta);
  971. if (ret == 0)
  972. iwl_mvm_rs_rate_init(mvm, sta,
  973. mvmvif->phy_ctxt->channel->band);
  974. } else if (old_state == IEEE80211_STA_ASSOC &&
  975. new_state == IEEE80211_STA_AUTHORIZED) {
  976. /* enable beacon filtering */
  977. WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif));
  978. ret = 0;
  979. } else if (old_state == IEEE80211_STA_AUTHORIZED &&
  980. new_state == IEEE80211_STA_ASSOC) {
  981. /* disable beacon filtering */
  982. WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif));
  983. ret = 0;
  984. } else if (old_state == IEEE80211_STA_ASSOC &&
  985. new_state == IEEE80211_STA_AUTH) {
  986. ret = 0;
  987. } else if (old_state == IEEE80211_STA_AUTH &&
  988. new_state == IEEE80211_STA_NONE) {
  989. ret = 0;
  990. } else if (old_state == IEEE80211_STA_NONE &&
  991. new_state == IEEE80211_STA_NOTEXIST) {
  992. ret = iwl_mvm_rm_sta(mvm, vif, sta);
  993. } else {
  994. ret = -EIO;
  995. }
  996. out_unlock:
  997. mutex_unlock(&mvm->mutex);
  998. return ret;
  999. }
  1000. static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  1001. {
  1002. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1003. mvm->rts_threshold = value;
  1004. return 0;
  1005. }
  1006. static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
  1007. struct ieee80211_vif *vif, u16 ac,
  1008. const struct ieee80211_tx_queue_params *params)
  1009. {
  1010. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1011. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1012. mvmvif->queue_params[ac] = *params;
  1013. /*
  1014. * No need to update right away, we'll get BSS_CHANGED_QOS
  1015. * The exception is P2P_DEVICE interface which needs immediate update.
  1016. */
  1017. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  1018. int ret;
  1019. mutex_lock(&mvm->mutex);
  1020. ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
  1021. mutex_unlock(&mvm->mutex);
  1022. return ret;
  1023. }
  1024. return 0;
  1025. }
  1026. static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
  1027. struct ieee80211_vif *vif)
  1028. {
  1029. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1030. u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
  1031. 200 + vif->bss_conf.beacon_int);
  1032. u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
  1033. 100 + vif->bss_conf.beacon_int);
  1034. if (WARN_ON_ONCE(vif->bss_conf.assoc))
  1035. return;
  1036. mutex_lock(&mvm->mutex);
  1037. /* Try really hard to protect the session and hear a beacon */
  1038. iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500);
  1039. mutex_unlock(&mvm->mutex);
  1040. }
  1041. static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
  1042. struct ieee80211_vif *vif,
  1043. struct cfg80211_sched_scan_request *req,
  1044. struct ieee80211_sched_scan_ies *ies)
  1045. {
  1046. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1047. int ret;
  1048. mutex_lock(&mvm->mutex);
  1049. if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
  1050. IWL_DEBUG_SCAN(mvm,
  1051. "SCHED SCAN request during internal scan - abort\n");
  1052. ret = -EBUSY;
  1053. goto out;
  1054. }
  1055. mvm->scan_status = IWL_MVM_SCAN_SCHED;
  1056. ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies);
  1057. if (ret)
  1058. goto err;
  1059. ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
  1060. if (ret)
  1061. goto err;
  1062. ret = iwl_mvm_sched_scan_start(mvm, req);
  1063. if (!ret)
  1064. goto out;
  1065. err:
  1066. mvm->scan_status = IWL_MVM_SCAN_NONE;
  1067. out:
  1068. mutex_unlock(&mvm->mutex);
  1069. return ret;
  1070. }
  1071. static void iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
  1072. struct ieee80211_vif *vif)
  1073. {
  1074. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1075. mutex_lock(&mvm->mutex);
  1076. iwl_mvm_sched_scan_stop(mvm);
  1077. mutex_unlock(&mvm->mutex);
  1078. }
  1079. static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
  1080. enum set_key_cmd cmd,
  1081. struct ieee80211_vif *vif,
  1082. struct ieee80211_sta *sta,
  1083. struct ieee80211_key_conf *key)
  1084. {
  1085. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1086. int ret;
  1087. if (iwlwifi_mod_params.sw_crypto) {
  1088. IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
  1089. return -EOPNOTSUPP;
  1090. }
  1091. switch (key->cipher) {
  1092. case WLAN_CIPHER_SUITE_TKIP:
  1093. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  1094. /* fall-through */
  1095. case WLAN_CIPHER_SUITE_CCMP:
  1096. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  1097. break;
  1098. case WLAN_CIPHER_SUITE_AES_CMAC:
  1099. WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
  1100. break;
  1101. case WLAN_CIPHER_SUITE_WEP40:
  1102. case WLAN_CIPHER_SUITE_WEP104:
  1103. /*
  1104. * Support for TX only, at least for now, so accept
  1105. * the key and do nothing else. Then mac80211 will
  1106. * pass it for TX but we don't have to use it for RX.
  1107. */
  1108. return 0;
  1109. default:
  1110. return -EOPNOTSUPP;
  1111. }
  1112. mutex_lock(&mvm->mutex);
  1113. switch (cmd) {
  1114. case SET_KEY:
  1115. if ((vif->type == NL80211_IFTYPE_ADHOC ||
  1116. vif->type == NL80211_IFTYPE_AP) && !sta) {
  1117. /*
  1118. * GTK on AP interface is a TX-only key, return 0;
  1119. * on IBSS they're per-station and because we're lazy
  1120. * we don't support them for RX, so do the same.
  1121. */
  1122. ret = 0;
  1123. key->hw_key_idx = STA_KEY_IDX_INVALID;
  1124. break;
  1125. }
  1126. IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
  1127. ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
  1128. if (ret) {
  1129. IWL_WARN(mvm, "set key failed\n");
  1130. /*
  1131. * can't add key for RX, but we don't need it
  1132. * in the device for TX so still return 0
  1133. */
  1134. key->hw_key_idx = STA_KEY_IDX_INVALID;
  1135. ret = 0;
  1136. }
  1137. break;
  1138. case DISABLE_KEY:
  1139. if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
  1140. ret = 0;
  1141. break;
  1142. }
  1143. IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
  1144. ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
  1145. break;
  1146. default:
  1147. ret = -EINVAL;
  1148. }
  1149. mutex_unlock(&mvm->mutex);
  1150. return ret;
  1151. }
  1152. static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
  1153. struct ieee80211_vif *vif,
  1154. struct ieee80211_key_conf *keyconf,
  1155. struct ieee80211_sta *sta,
  1156. u32 iv32, u16 *phase1key)
  1157. {
  1158. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1159. if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
  1160. return;
  1161. iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
  1162. }
  1163. static int iwl_mvm_roc(struct ieee80211_hw *hw,
  1164. struct ieee80211_vif *vif,
  1165. struct ieee80211_channel *channel,
  1166. int duration,
  1167. enum ieee80211_roc_type type)
  1168. {
  1169. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1170. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1171. struct cfg80211_chan_def chandef;
  1172. struct iwl_mvm_phy_ctxt *phy_ctxt;
  1173. int ret, i;
  1174. IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
  1175. duration, type);
  1176. if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
  1177. IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
  1178. return -EINVAL;
  1179. }
  1180. mutex_lock(&mvm->mutex);
  1181. for (i = 0; i < NUM_PHY_CTX; i++) {
  1182. phy_ctxt = &mvm->phy_ctxts[i];
  1183. if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
  1184. continue;
  1185. if (phy_ctxt->ref && channel == phy_ctxt->channel) {
  1186. /*
  1187. * Unbind the P2P_DEVICE from the current PHY context,
  1188. * and if the PHY context is not used remove it.
  1189. */
  1190. ret = iwl_mvm_binding_remove_vif(mvm, vif);
  1191. if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
  1192. goto out_unlock;
  1193. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  1194. /* Bind the P2P_DEVICE to the current PHY Context */
  1195. mvmvif->phy_ctxt = phy_ctxt;
  1196. ret = iwl_mvm_binding_add_vif(mvm, vif);
  1197. if (WARN(ret, "Failed binding P2P_DEVICE\n"))
  1198. goto out_unlock;
  1199. iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
  1200. goto schedule_time_event;
  1201. }
  1202. }
  1203. /* Need to update the PHY context only if the ROC channel changed */
  1204. if (channel == mvmvif->phy_ctxt->channel)
  1205. goto schedule_time_event;
  1206. cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
  1207. /*
  1208. * Change the PHY context configuration as it is currently referenced
  1209. * only by the P2P Device MAC
  1210. */
  1211. if (mvmvif->phy_ctxt->ref == 1) {
  1212. ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
  1213. &chandef, 1, 1);
  1214. if (ret)
  1215. goto out_unlock;
  1216. } else {
  1217. /*
  1218. * The PHY context is shared with other MACs. Need to remove the
  1219. * P2P Device from the binding, allocate an new PHY context and
  1220. * create a new binding
  1221. */
  1222. phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
  1223. if (!phy_ctxt) {
  1224. ret = -ENOSPC;
  1225. goto out_unlock;
  1226. }
  1227. ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
  1228. 1, 1);
  1229. if (ret) {
  1230. IWL_ERR(mvm, "Failed to change PHY context\n");
  1231. goto out_unlock;
  1232. }
  1233. /* Unbind the P2P_DEVICE from the current PHY context */
  1234. ret = iwl_mvm_binding_remove_vif(mvm, vif);
  1235. if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
  1236. goto out_unlock;
  1237. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  1238. /* Bind the P2P_DEVICE to the new allocated PHY context */
  1239. mvmvif->phy_ctxt = phy_ctxt;
  1240. ret = iwl_mvm_binding_add_vif(mvm, vif);
  1241. if (WARN(ret, "Failed binding P2P_DEVICE\n"))
  1242. goto out_unlock;
  1243. iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
  1244. }
  1245. schedule_time_event:
  1246. /* Schedule the time events */
  1247. ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
  1248. out_unlock:
  1249. mutex_unlock(&mvm->mutex);
  1250. IWL_DEBUG_MAC80211(mvm, "leave\n");
  1251. return ret;
  1252. }
  1253. static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
  1254. {
  1255. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1256. IWL_DEBUG_MAC80211(mvm, "enter\n");
  1257. mutex_lock(&mvm->mutex);
  1258. iwl_mvm_stop_p2p_roc(mvm);
  1259. mutex_unlock(&mvm->mutex);
  1260. IWL_DEBUG_MAC80211(mvm, "leave\n");
  1261. return 0;
  1262. }
  1263. static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
  1264. struct ieee80211_chanctx_conf *ctx)
  1265. {
  1266. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1267. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  1268. struct iwl_mvm_phy_ctxt *phy_ctxt;
  1269. int ret;
  1270. IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
  1271. mutex_lock(&mvm->mutex);
  1272. phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
  1273. if (!phy_ctxt) {
  1274. ret = -ENOSPC;
  1275. goto out;
  1276. }
  1277. ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
  1278. ctx->rx_chains_static,
  1279. ctx->rx_chains_dynamic);
  1280. if (ret) {
  1281. IWL_ERR(mvm, "Failed to add PHY context\n");
  1282. goto out;
  1283. }
  1284. iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
  1285. *phy_ctxt_id = phy_ctxt->id;
  1286. out:
  1287. mutex_unlock(&mvm->mutex);
  1288. return ret;
  1289. }
  1290. static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
  1291. struct ieee80211_chanctx_conf *ctx)
  1292. {
  1293. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1294. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  1295. struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
  1296. mutex_lock(&mvm->mutex);
  1297. iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
  1298. mutex_unlock(&mvm->mutex);
  1299. }
  1300. static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
  1301. struct ieee80211_chanctx_conf *ctx,
  1302. u32 changed)
  1303. {
  1304. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1305. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  1306. struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
  1307. if (WARN_ONCE((phy_ctxt->ref > 1) &&
  1308. (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
  1309. IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
  1310. IEEE80211_CHANCTX_CHANGE_RADAR)),
  1311. "Cannot change PHY. Ref=%d, changed=0x%X\n",
  1312. phy_ctxt->ref, changed))
  1313. return;
  1314. mutex_lock(&mvm->mutex);
  1315. iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
  1316. ctx->rx_chains_static,
  1317. ctx->rx_chains_dynamic);
  1318. iwl_mvm_bt_coex_vif_change(mvm);
  1319. mutex_unlock(&mvm->mutex);
  1320. }
  1321. static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
  1322. struct ieee80211_vif *vif,
  1323. struct ieee80211_chanctx_conf *ctx)
  1324. {
  1325. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1326. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  1327. struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
  1328. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1329. int ret;
  1330. mutex_lock(&mvm->mutex);
  1331. mvmvif->phy_ctxt = phy_ctxt;
  1332. switch (vif->type) {
  1333. case NL80211_IFTYPE_AP:
  1334. case NL80211_IFTYPE_ADHOC:
  1335. /*
  1336. * The AP binding flow is handled as part of the start_ap flow
  1337. * (in bss_info_changed), similarly for IBSS.
  1338. */
  1339. ret = 0;
  1340. goto out_unlock;
  1341. case NL80211_IFTYPE_STATION:
  1342. case NL80211_IFTYPE_MONITOR:
  1343. break;
  1344. default:
  1345. ret = -EINVAL;
  1346. goto out_unlock;
  1347. }
  1348. ret = iwl_mvm_binding_add_vif(mvm, vif);
  1349. if (ret)
  1350. goto out_unlock;
  1351. /*
  1352. * Setting the quota at this stage is only required for monitor
  1353. * interfaces. For the other types, the bss_info changed flow
  1354. * will handle quota settings.
  1355. */
  1356. if (vif->type == NL80211_IFTYPE_MONITOR) {
  1357. mvmvif->monitor_active = true;
  1358. ret = iwl_mvm_update_quotas(mvm, vif);
  1359. if (ret)
  1360. goto out_remove_binding;
  1361. }
  1362. goto out_unlock;
  1363. out_remove_binding:
  1364. iwl_mvm_binding_remove_vif(mvm, vif);
  1365. out_unlock:
  1366. mutex_unlock(&mvm->mutex);
  1367. if (ret)
  1368. mvmvif->phy_ctxt = NULL;
  1369. return ret;
  1370. }
  1371. static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
  1372. struct ieee80211_vif *vif,
  1373. struct ieee80211_chanctx_conf *ctx)
  1374. {
  1375. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1376. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1377. mutex_lock(&mvm->mutex);
  1378. iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
  1379. switch (vif->type) {
  1380. case NL80211_IFTYPE_AP:
  1381. case NL80211_IFTYPE_ADHOC:
  1382. goto out_unlock;
  1383. case NL80211_IFTYPE_MONITOR:
  1384. mvmvif->monitor_active = false;
  1385. iwl_mvm_update_quotas(mvm, NULL);
  1386. break;
  1387. default:
  1388. break;
  1389. }
  1390. iwl_mvm_binding_remove_vif(mvm, vif);
  1391. out_unlock:
  1392. mvmvif->phy_ctxt = NULL;
  1393. mutex_unlock(&mvm->mutex);
  1394. }
  1395. static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
  1396. struct ieee80211_sta *sta,
  1397. bool set)
  1398. {
  1399. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1400. struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
  1401. if (!mvm_sta || !mvm_sta->vif) {
  1402. IWL_ERR(mvm, "Station is not associated to a vif\n");
  1403. return -EINVAL;
  1404. }
  1405. return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
  1406. }
  1407. #ifdef CONFIG_NL80211_TESTMODE
  1408. static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
  1409. [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
  1410. [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
  1411. [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
  1412. };
  1413. static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
  1414. struct ieee80211_vif *vif,
  1415. void *data, int len)
  1416. {
  1417. struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
  1418. int err;
  1419. u32 noa_duration;
  1420. err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
  1421. if (err)
  1422. return err;
  1423. if (!tb[IWL_MVM_TM_ATTR_CMD])
  1424. return -EINVAL;
  1425. switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
  1426. case IWL_MVM_TM_CMD_SET_NOA:
  1427. if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
  1428. !vif->bss_conf.enable_beacon ||
  1429. !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
  1430. return -EINVAL;
  1431. noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
  1432. if (noa_duration >= vif->bss_conf.beacon_int)
  1433. return -EINVAL;
  1434. mvm->noa_duration = noa_duration;
  1435. mvm->noa_vif = vif;
  1436. return iwl_mvm_update_quotas(mvm, NULL);
  1437. case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
  1438. /* must be associated client vif - ignore authorized */
  1439. if (!vif || vif->type != NL80211_IFTYPE_STATION ||
  1440. !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
  1441. !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
  1442. return -EINVAL;
  1443. if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
  1444. return iwl_mvm_enable_beacon_filter(mvm, vif);
  1445. return iwl_mvm_disable_beacon_filter(mvm, vif);
  1446. }
  1447. return -EOPNOTSUPP;
  1448. }
  1449. static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
  1450. struct ieee80211_vif *vif,
  1451. void *data, int len)
  1452. {
  1453. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1454. int err;
  1455. mutex_lock(&mvm->mutex);
  1456. err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
  1457. mutex_unlock(&mvm->mutex);
  1458. return err;
  1459. }
  1460. #endif
  1461. struct ieee80211_ops iwl_mvm_hw_ops = {
  1462. .tx = iwl_mvm_mac_tx,
  1463. .ampdu_action = iwl_mvm_mac_ampdu_action,
  1464. .start = iwl_mvm_mac_start,
  1465. .restart_complete = iwl_mvm_mac_restart_complete,
  1466. .stop = iwl_mvm_mac_stop,
  1467. .add_interface = iwl_mvm_mac_add_interface,
  1468. .remove_interface = iwl_mvm_mac_remove_interface,
  1469. .config = iwl_mvm_mac_config,
  1470. .configure_filter = iwl_mvm_configure_filter,
  1471. .bss_info_changed = iwl_mvm_bss_info_changed,
  1472. .hw_scan = iwl_mvm_mac_hw_scan,
  1473. .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
  1474. .sta_state = iwl_mvm_mac_sta_state,
  1475. .sta_notify = iwl_mvm_mac_sta_notify,
  1476. .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
  1477. .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
  1478. .conf_tx = iwl_mvm_mac_conf_tx,
  1479. .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
  1480. .sched_scan_start = iwl_mvm_mac_sched_scan_start,
  1481. .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
  1482. .set_key = iwl_mvm_mac_set_key,
  1483. .update_tkip_key = iwl_mvm_mac_update_tkip_key,
  1484. .remain_on_channel = iwl_mvm_roc,
  1485. .cancel_remain_on_channel = iwl_mvm_cancel_roc,
  1486. .add_chanctx = iwl_mvm_add_chanctx,
  1487. .remove_chanctx = iwl_mvm_remove_chanctx,
  1488. .change_chanctx = iwl_mvm_change_chanctx,
  1489. .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
  1490. .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
  1491. .start_ap = iwl_mvm_start_ap_ibss,
  1492. .stop_ap = iwl_mvm_stop_ap_ibss,
  1493. .join_ibss = iwl_mvm_start_ap_ibss,
  1494. .leave_ibss = iwl_mvm_stop_ap_ibss,
  1495. .set_tim = iwl_mvm_set_tim,
  1496. CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
  1497. #ifdef CONFIG_PM_SLEEP
  1498. /* look at d3.c */
  1499. .suspend = iwl_mvm_suspend,
  1500. .resume = iwl_mvm_resume,
  1501. .set_wakeup = iwl_mvm_set_wakeup,
  1502. .set_rekey_data = iwl_mvm_set_rekey_data,
  1503. #if IS_ENABLED(CONFIG_IPV6)
  1504. .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
  1505. #endif
  1506. .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
  1507. #endif
  1508. };