mac80211.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314
  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_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. 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_atomic(
  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. } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
  572. /* remove AP station now that the MAC is unassoc */
  573. ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
  574. if (ret)
  575. IWL_ERR(mvm, "failed to remove AP station\n");
  576. mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
  577. /* remove quota for this interface */
  578. ret = iwl_mvm_update_quotas(mvm, NULL);
  579. if (ret)
  580. IWL_ERR(mvm, "failed to update quotas\n");
  581. }
  582. } else if (changes & BSS_CHANGED_DTIM_PERIOD) {
  583. /*
  584. * We received a beacon _after_ association so
  585. * remove the session protection.
  586. */
  587. iwl_mvm_remove_time_event(mvm, mvmvif,
  588. &mvmvif->time_event_data);
  589. } else if (changes & BSS_CHANGED_PS) {
  590. /*
  591. * TODO: remove this temporary code.
  592. * Currently MVM FW supports power management only on single
  593. * MAC. Avoid power mode update if more than one interface
  594. * is active.
  595. */
  596. IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n",
  597. mvm->vif_count);
  598. if (mvm->vif_count == 1) {
  599. ret = iwl_mvm_power_update_mode(mvm, vif);
  600. if (ret)
  601. IWL_ERR(mvm, "failed to update power mode\n");
  602. }
  603. }
  604. }
  605. static int iwl_mvm_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  606. {
  607. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  608. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  609. int ret;
  610. mutex_lock(&mvm->mutex);
  611. /* Send the beacon template */
  612. ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
  613. if (ret)
  614. goto out_unlock;
  615. /* Add the mac context */
  616. ret = iwl_mvm_mac_ctxt_add(mvm, vif);
  617. if (ret)
  618. goto out_unlock;
  619. /* Perform the binding */
  620. ret = iwl_mvm_binding_add_vif(mvm, vif);
  621. if (ret)
  622. goto out_remove;
  623. mvmvif->ap_active = true;
  624. /* Send the bcast station. At this stage the TBTT and DTIM time events
  625. * are added and applied to the scheduler */
  626. ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
  627. if (ret)
  628. goto out_unbind;
  629. ret = iwl_mvm_update_quotas(mvm, vif);
  630. if (ret)
  631. goto out_rm_bcast;
  632. /* Need to update the P2P Device MAC */
  633. if (vif->p2p && mvm->p2p_device_vif)
  634. iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
  635. mutex_unlock(&mvm->mutex);
  636. return 0;
  637. out_rm_bcast:
  638. iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
  639. out_unbind:
  640. iwl_mvm_binding_remove_vif(mvm, vif);
  641. out_remove:
  642. iwl_mvm_mac_ctxt_remove(mvm, vif);
  643. out_unlock:
  644. mutex_unlock(&mvm->mutex);
  645. return ret;
  646. }
  647. static void iwl_mvm_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  648. {
  649. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  650. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  651. mutex_lock(&mvm->mutex);
  652. mvmvif->ap_active = false;
  653. /* Need to update the P2P Device MAC */
  654. if (vif->p2p && mvm->p2p_device_vif)
  655. iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
  656. iwl_mvm_update_quotas(mvm, NULL);
  657. iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
  658. iwl_mvm_binding_remove_vif(mvm, vif);
  659. iwl_mvm_mac_ctxt_remove(mvm, vif);
  660. mutex_unlock(&mvm->mutex);
  661. }
  662. static void iwl_mvm_bss_info_changed_ap(struct iwl_mvm *mvm,
  663. struct ieee80211_vif *vif,
  664. struct ieee80211_bss_conf *bss_conf,
  665. u32 changes)
  666. {
  667. /* Need to send a new beacon template to the FW */
  668. if (changes & BSS_CHANGED_BEACON) {
  669. if (iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
  670. IWL_WARN(mvm, "Failed updating beacon data\n");
  671. }
  672. }
  673. static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
  674. struct ieee80211_vif *vif,
  675. struct ieee80211_bss_conf *bss_conf,
  676. u32 changes)
  677. {
  678. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  679. mutex_lock(&mvm->mutex);
  680. switch (vif->type) {
  681. case NL80211_IFTYPE_STATION:
  682. iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
  683. break;
  684. case NL80211_IFTYPE_AP:
  685. iwl_mvm_bss_info_changed_ap(mvm, vif, bss_conf, changes);
  686. break;
  687. default:
  688. /* shouldn't happen */
  689. WARN_ON_ONCE(1);
  690. }
  691. mutex_unlock(&mvm->mutex);
  692. }
  693. static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
  694. struct ieee80211_vif *vif,
  695. struct cfg80211_scan_request *req)
  696. {
  697. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  698. int ret;
  699. if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS)
  700. return -EINVAL;
  701. mutex_lock(&mvm->mutex);
  702. if (mvm->scan_status == IWL_MVM_SCAN_NONE)
  703. ret = iwl_mvm_scan_request(mvm, vif, req);
  704. else
  705. ret = -EBUSY;
  706. mutex_unlock(&mvm->mutex);
  707. return ret;
  708. }
  709. static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
  710. struct ieee80211_vif *vif)
  711. {
  712. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  713. mutex_lock(&mvm->mutex);
  714. iwl_mvm_cancel_scan(mvm);
  715. mutex_unlock(&mvm->mutex);
  716. }
  717. static void
  718. iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
  719. struct ieee80211_sta *sta, u16 tid,
  720. int num_frames,
  721. enum ieee80211_frame_release_type reason,
  722. bool more_data)
  723. {
  724. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  725. /* TODO: how do we tell the fw to send frames for a specific TID */
  726. /*
  727. * The fw will send EOSP notification when the last frame will be
  728. * transmitted.
  729. */
  730. iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames);
  731. }
  732. static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
  733. struct ieee80211_vif *vif,
  734. enum sta_notify_cmd cmd,
  735. struct ieee80211_sta *sta)
  736. {
  737. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  738. struct iwl_mvm_sta *mvmsta = (void *)sta->drv_priv;
  739. switch (cmd) {
  740. case STA_NOTIFY_SLEEP:
  741. if (atomic_read(&mvmsta->pending_frames) > 0)
  742. ieee80211_sta_block_awake(hw, sta, true);
  743. /*
  744. * The fw updates the STA to be asleep. Tx packets on the Tx
  745. * queues to this station will not be transmitted. The fw will
  746. * send a Tx response with TX_STATUS_FAIL_DEST_PS.
  747. */
  748. break;
  749. case STA_NOTIFY_AWAKE:
  750. if (WARN_ON(mvmsta->sta_id == IWL_INVALID_STATION))
  751. break;
  752. iwl_mvm_sta_modify_ps_wake(mvm, sta);
  753. break;
  754. default:
  755. break;
  756. }
  757. }
  758. static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
  759. struct ieee80211_vif *vif,
  760. struct ieee80211_sta *sta,
  761. enum ieee80211_sta_state old_state,
  762. enum ieee80211_sta_state new_state)
  763. {
  764. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  765. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  766. int ret;
  767. IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
  768. sta->addr, old_state, new_state);
  769. /* this would be a mac80211 bug ... but don't crash */
  770. if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
  771. return -EINVAL;
  772. /* if a STA is being removed, reuse its ID */
  773. flush_work(&mvm->sta_drained_wk);
  774. mutex_lock(&mvm->mutex);
  775. if (old_state == IEEE80211_STA_NOTEXIST &&
  776. new_state == IEEE80211_STA_NONE) {
  777. ret = iwl_mvm_add_sta(mvm, vif, sta);
  778. } else if (old_state == IEEE80211_STA_NONE &&
  779. new_state == IEEE80211_STA_AUTH) {
  780. ret = 0;
  781. } else if (old_state == IEEE80211_STA_AUTH &&
  782. new_state == IEEE80211_STA_ASSOC) {
  783. ret = iwl_mvm_update_sta(mvm, vif, sta);
  784. if (ret == 0)
  785. iwl_mvm_rs_rate_init(mvm, sta,
  786. mvmvif->phy_ctxt->channel->band);
  787. } else if (old_state == IEEE80211_STA_ASSOC &&
  788. new_state == IEEE80211_STA_AUTHORIZED) {
  789. ret = 0;
  790. } else if (old_state == IEEE80211_STA_AUTHORIZED &&
  791. new_state == IEEE80211_STA_ASSOC) {
  792. ret = 0;
  793. } else if (old_state == IEEE80211_STA_ASSOC &&
  794. new_state == IEEE80211_STA_AUTH) {
  795. ret = 0;
  796. } else if (old_state == IEEE80211_STA_AUTH &&
  797. new_state == IEEE80211_STA_NONE) {
  798. ret = 0;
  799. } else if (old_state == IEEE80211_STA_NONE &&
  800. new_state == IEEE80211_STA_NOTEXIST) {
  801. ret = iwl_mvm_rm_sta(mvm, vif, sta);
  802. } else {
  803. ret = -EIO;
  804. }
  805. mutex_unlock(&mvm->mutex);
  806. return ret;
  807. }
  808. static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  809. {
  810. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  811. mvm->rts_threshold = value;
  812. return 0;
  813. }
  814. static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
  815. struct ieee80211_vif *vif, u16 ac,
  816. const struct ieee80211_tx_queue_params *params)
  817. {
  818. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  819. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  820. mvmvif->queue_params[ac] = *params;
  821. /*
  822. * No need to update right away, we'll get BSS_CHANGED_QOS
  823. * The exception is P2P_DEVICE interface which needs immediate update.
  824. */
  825. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  826. int ret;
  827. mutex_lock(&mvm->mutex);
  828. ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
  829. mutex_unlock(&mvm->mutex);
  830. return ret;
  831. }
  832. return 0;
  833. }
  834. static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
  835. struct ieee80211_vif *vif)
  836. {
  837. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  838. u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
  839. 200 + vif->bss_conf.beacon_int);
  840. u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
  841. 100 + vif->bss_conf.beacon_int);
  842. if (WARN_ON_ONCE(vif->bss_conf.assoc))
  843. return;
  844. mutex_lock(&mvm->mutex);
  845. /* Try really hard to protect the session and hear a beacon */
  846. iwl_mvm_protect_session(mvm, vif, duration, min_duration);
  847. mutex_unlock(&mvm->mutex);
  848. }
  849. static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
  850. enum set_key_cmd cmd,
  851. struct ieee80211_vif *vif,
  852. struct ieee80211_sta *sta,
  853. struct ieee80211_key_conf *key)
  854. {
  855. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  856. int ret;
  857. if (iwlwifi_mod_params.sw_crypto) {
  858. IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
  859. return -EOPNOTSUPP;
  860. }
  861. switch (key->cipher) {
  862. case WLAN_CIPHER_SUITE_TKIP:
  863. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  864. /* fall-through */
  865. case WLAN_CIPHER_SUITE_CCMP:
  866. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  867. break;
  868. case WLAN_CIPHER_SUITE_AES_CMAC:
  869. WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
  870. break;
  871. case WLAN_CIPHER_SUITE_WEP40:
  872. case WLAN_CIPHER_SUITE_WEP104:
  873. /*
  874. * Support for TX only, at least for now, so accept
  875. * the key and do nothing else. Then mac80211 will
  876. * pass it for TX but we don't have to use it for RX.
  877. */
  878. return 0;
  879. default:
  880. return -EOPNOTSUPP;
  881. }
  882. mutex_lock(&mvm->mutex);
  883. switch (cmd) {
  884. case SET_KEY:
  885. IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
  886. ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
  887. if (ret) {
  888. IWL_WARN(mvm, "set key failed\n");
  889. /*
  890. * can't add key for RX, but we don't need it
  891. * in the device for TX so still return 0
  892. */
  893. ret = 0;
  894. }
  895. break;
  896. case DISABLE_KEY:
  897. IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
  898. ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
  899. break;
  900. default:
  901. ret = -EINVAL;
  902. }
  903. mutex_unlock(&mvm->mutex);
  904. return ret;
  905. }
  906. static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
  907. struct ieee80211_vif *vif,
  908. struct ieee80211_key_conf *keyconf,
  909. struct ieee80211_sta *sta,
  910. u32 iv32, u16 *phase1key)
  911. {
  912. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  913. iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
  914. }
  915. static int iwl_mvm_roc(struct ieee80211_hw *hw,
  916. struct ieee80211_vif *vif,
  917. struct ieee80211_channel *channel,
  918. int duration)
  919. {
  920. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  921. struct cfg80211_chan_def chandef;
  922. int ret;
  923. if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
  924. IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
  925. return -EINVAL;
  926. }
  927. IWL_DEBUG_MAC80211(mvm, "enter (%d, %d)\n", channel->hw_value,
  928. duration);
  929. mutex_lock(&mvm->mutex);
  930. cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
  931. ret = iwl_mvm_phy_ctxt_changed(mvm, &mvm->phy_ctxt_roc,
  932. &chandef, 1, 1);
  933. /* Schedule the time events */
  934. ret = iwl_mvm_start_p2p_roc(mvm, vif, duration);
  935. mutex_unlock(&mvm->mutex);
  936. IWL_DEBUG_MAC80211(mvm, "leave\n");
  937. return ret;
  938. }
  939. static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
  940. {
  941. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  942. IWL_DEBUG_MAC80211(mvm, "enter\n");
  943. mutex_lock(&mvm->mutex);
  944. iwl_mvm_stop_p2p_roc(mvm);
  945. mutex_unlock(&mvm->mutex);
  946. IWL_DEBUG_MAC80211(mvm, "leave\n");
  947. return 0;
  948. }
  949. static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
  950. struct ieee80211_chanctx_conf *ctx)
  951. {
  952. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  953. struct iwl_mvm_phy_ctxt *phy_ctxt = (void *)ctx->drv_priv;
  954. int ret;
  955. mutex_lock(&mvm->mutex);
  956. IWL_DEBUG_MAC80211(mvm, "Add PHY context\n");
  957. ret = iwl_mvm_phy_ctxt_add(mvm, phy_ctxt, &ctx->def,
  958. ctx->rx_chains_static,
  959. ctx->rx_chains_dynamic);
  960. mutex_unlock(&mvm->mutex);
  961. return ret;
  962. }
  963. static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
  964. struct ieee80211_chanctx_conf *ctx)
  965. {
  966. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  967. struct iwl_mvm_phy_ctxt *phy_ctxt = (void *)ctx->drv_priv;
  968. mutex_lock(&mvm->mutex);
  969. iwl_mvm_phy_ctxt_remove(mvm, phy_ctxt);
  970. mutex_unlock(&mvm->mutex);
  971. }
  972. static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
  973. struct ieee80211_chanctx_conf *ctx,
  974. u32 changed)
  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_changed(mvm, phy_ctxt, &ctx->def,
  980. ctx->rx_chains_static,
  981. ctx->rx_chains_dynamic);
  982. mutex_unlock(&mvm->mutex);
  983. }
  984. static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
  985. struct ieee80211_vif *vif,
  986. struct ieee80211_chanctx_conf *ctx)
  987. {
  988. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  989. struct iwl_mvm_phy_ctxt *phyctx = (void *)ctx->drv_priv;
  990. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  991. int ret;
  992. mutex_lock(&mvm->mutex);
  993. mvmvif->phy_ctxt = phyctx;
  994. switch (vif->type) {
  995. case NL80211_IFTYPE_AP:
  996. /*
  997. * The AP binding flow is handled as part of the start_ap flow
  998. * (in bss_info_changed).
  999. */
  1000. ret = 0;
  1001. goto out_unlock;
  1002. case NL80211_IFTYPE_STATION:
  1003. case NL80211_IFTYPE_ADHOC:
  1004. case NL80211_IFTYPE_MONITOR:
  1005. break;
  1006. default:
  1007. ret = -EINVAL;
  1008. goto out_unlock;
  1009. }
  1010. ret = iwl_mvm_binding_add_vif(mvm, vif);
  1011. if (ret)
  1012. goto out_unlock;
  1013. /*
  1014. * Setting the quota at this stage is only required for monitor
  1015. * interfaces. For the other types, the bss_info changed flow
  1016. * will handle quota settings.
  1017. */
  1018. if (vif->type == NL80211_IFTYPE_MONITOR) {
  1019. ret = iwl_mvm_update_quotas(mvm, vif);
  1020. if (ret)
  1021. goto out_remove_binding;
  1022. }
  1023. goto out_unlock;
  1024. out_remove_binding:
  1025. iwl_mvm_binding_remove_vif(mvm, vif);
  1026. out_unlock:
  1027. mutex_unlock(&mvm->mutex);
  1028. if (ret)
  1029. mvmvif->phy_ctxt = NULL;
  1030. return ret;
  1031. }
  1032. static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
  1033. struct ieee80211_vif *vif,
  1034. struct ieee80211_chanctx_conf *ctx)
  1035. {
  1036. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1037. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1038. mutex_lock(&mvm->mutex);
  1039. iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
  1040. if (vif->type == NL80211_IFTYPE_AP)
  1041. goto out_unlock;
  1042. iwl_mvm_binding_remove_vif(mvm, vif);
  1043. switch (vif->type) {
  1044. case NL80211_IFTYPE_MONITOR:
  1045. iwl_mvm_update_quotas(mvm, vif);
  1046. break;
  1047. default:
  1048. break;
  1049. }
  1050. out_unlock:
  1051. mvmvif->phy_ctxt = NULL;
  1052. mutex_unlock(&mvm->mutex);
  1053. }
  1054. static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
  1055. struct ieee80211_sta *sta,
  1056. bool set)
  1057. {
  1058. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1059. struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
  1060. if (!mvm_sta || !mvm_sta->vif) {
  1061. IWL_ERR(mvm, "Station is not associated to a vif\n");
  1062. return -EINVAL;
  1063. }
  1064. return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
  1065. }
  1066. struct ieee80211_ops iwl_mvm_hw_ops = {
  1067. .tx = iwl_mvm_mac_tx,
  1068. .ampdu_action = iwl_mvm_mac_ampdu_action,
  1069. .start = iwl_mvm_mac_start,
  1070. .restart_complete = iwl_mvm_mac_restart_complete,
  1071. .stop = iwl_mvm_mac_stop,
  1072. .add_interface = iwl_mvm_mac_add_interface,
  1073. .remove_interface = iwl_mvm_mac_remove_interface,
  1074. .config = iwl_mvm_mac_config,
  1075. .configure_filter = iwl_mvm_configure_filter,
  1076. .bss_info_changed = iwl_mvm_bss_info_changed,
  1077. .hw_scan = iwl_mvm_mac_hw_scan,
  1078. .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
  1079. .sta_state = iwl_mvm_mac_sta_state,
  1080. .sta_notify = iwl_mvm_mac_sta_notify,
  1081. .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
  1082. .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
  1083. .conf_tx = iwl_mvm_mac_conf_tx,
  1084. .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
  1085. .set_key = iwl_mvm_mac_set_key,
  1086. .update_tkip_key = iwl_mvm_mac_update_tkip_key,
  1087. .remain_on_channel = iwl_mvm_roc,
  1088. .cancel_remain_on_channel = iwl_mvm_cancel_roc,
  1089. .add_chanctx = iwl_mvm_add_chanctx,
  1090. .remove_chanctx = iwl_mvm_remove_chanctx,
  1091. .change_chanctx = iwl_mvm_change_chanctx,
  1092. .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
  1093. .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
  1094. .start_ap = iwl_mvm_start_ap,
  1095. .stop_ap = iwl_mvm_stop_ap,
  1096. .set_tim = iwl_mvm_set_tim,
  1097. #ifdef CONFIG_PM_SLEEP
  1098. /* look at d3.c */
  1099. .suspend = iwl_mvm_suspend,
  1100. .resume = iwl_mvm_resume,
  1101. .set_wakeup = iwl_mvm_set_wakeup,
  1102. .set_rekey_data = iwl_mvm_set_rekey_data,
  1103. #if IS_ENABLED(CONFIG_IPV6)
  1104. .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
  1105. #endif
  1106. .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
  1107. #endif
  1108. };