mac80211.c 36 KB

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