mac80211.c 50 KB

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