mac80211.c 36 KB

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