mac80211.c 36 KB

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