mac80211.c 37 KB

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