mac80211.c 42 KB

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