mac80211.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542
  1. /******************************************************************************
  2. *
  3. * This file is provided under a dual BSD/GPLv2 license. When using or
  4. * redistributing this file, you may do so under either license.
  5. *
  6. * GPL LICENSE SUMMARY
  7. *
  8. * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of version 2 of the GNU General Public License as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  22. * USA
  23. *
  24. * The full GNU General Public License is included in this distribution
  25. * in the file called COPYING.
  26. *
  27. * Contact Information:
  28. * Intel Linux Wireless <ilw@linux.intel.com>
  29. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  30. *
  31. * BSD LICENSE
  32. *
  33. * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
  34. * All rights reserved.
  35. *
  36. * Redistribution and use in source and binary forms, with or without
  37. * modification, are permitted provided that the following conditions
  38. * are met:
  39. *
  40. * * Redistributions of source code must retain the above copyright
  41. * notice, this list of conditions and the following disclaimer.
  42. * * Redistributions in binary form must reproduce the above copyright
  43. * notice, this list of conditions and the following disclaimer in
  44. * the documentation and/or other materials provided with the
  45. * distribution.
  46. * * Neither the name Intel Corporation nor the names of its
  47. * contributors may be used to endorse or promote products derived
  48. * from this software without specific prior written permission.
  49. *
  50. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  51. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  52. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  53. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  54. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  55. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  56. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  57. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  58. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  59. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  60. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  61. *
  62. *****************************************************************************/
  63. #include <linux/kernel.h>
  64. #include <linux/slab.h>
  65. #include <linux/skbuff.h>
  66. #include <linux/netdevice.h>
  67. #include <linux/etherdevice.h>
  68. #include <linux/ip.h>
  69. #include <net/mac80211.h>
  70. #include <net/tcp.h>
  71. #include "iwl-op-mode.h"
  72. #include "iwl-io.h"
  73. #include "mvm.h"
  74. #include "sta.h"
  75. #include "time-event.h"
  76. #include "iwl-eeprom-parse.h"
  77. #include "fw-api-scan.h"
  78. #include "iwl-phy-db.h"
  79. static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
  80. {
  81. .max = 1,
  82. .types = BIT(NL80211_IFTYPE_STATION) |
  83. BIT(NL80211_IFTYPE_AP),
  84. },
  85. };
  86. static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
  87. {
  88. .num_different_channels = 1,
  89. .max_interfaces = 3,
  90. .limits = iwl_mvm_limits,
  91. .n_limits = ARRAY_SIZE(iwl_mvm_limits),
  92. },
  93. };
  94. #ifdef CONFIG_PM_SLEEP
  95. static const struct nl80211_wowlan_tcp_data_token_feature
  96. iwl_mvm_wowlan_tcp_token_feature = {
  97. .min_len = 0,
  98. .max_len = 255,
  99. .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
  100. };
  101. static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
  102. .tok = &iwl_mvm_wowlan_tcp_token_feature,
  103. .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
  104. sizeof(struct ethhdr) -
  105. sizeof(struct iphdr) -
  106. sizeof(struct tcphdr),
  107. .data_interval_max = 65535, /* __le16 in API */
  108. .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
  109. sizeof(struct ethhdr) -
  110. sizeof(struct iphdr) -
  111. sizeof(struct tcphdr),
  112. .seq = true,
  113. };
  114. #endif
  115. static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
  116. {
  117. int i;
  118. memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
  119. for (i = 0; i < NUM_PHY_CTX; i++) {
  120. mvm->phy_ctxts[i].id = i;
  121. mvm->phy_ctxts[i].ref = 0;
  122. }
  123. }
  124. int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
  125. {
  126. struct ieee80211_hw *hw = mvm->hw;
  127. int num_mac, ret, i;
  128. /* Tell mac80211 our characteristics */
  129. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  130. IEEE80211_HW_SPECTRUM_MGMT |
  131. IEEE80211_HW_REPORTS_TX_ACK_STATUS |
  132. IEEE80211_HW_QUEUE_CONTROL |
  133. IEEE80211_HW_WANT_MONITOR_VIF |
  134. IEEE80211_HW_SUPPORTS_PS |
  135. IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
  136. IEEE80211_HW_AMPDU_AGGREGATION |
  137. IEEE80211_HW_TIMING_BEACON_ONLY |
  138. IEEE80211_HW_CONNECTION_MONITOR;
  139. hw->queues = IWL_MVM_FIRST_AGG_QUEUE;
  140. hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
  141. hw->rate_control_algorithm = "iwl-mvm-rs";
  142. /*
  143. * Enable 11w if advertised by firmware and software crypto
  144. * is not enabled (as the firmware will interpret some mgmt
  145. * packets, so enabling it with software crypto isn't safe)
  146. */
  147. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
  148. !iwlwifi_mod_params.sw_crypto)
  149. hw->flags |= IEEE80211_HW_MFP_CAPABLE;
  150. hw->sta_data_size = sizeof(struct iwl_mvm_sta);
  151. hw->vif_data_size = sizeof(struct iwl_mvm_vif);
  152. hw->chanctx_data_size = sizeof(u16);
  153. hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  154. BIT(NL80211_IFTYPE_AP);
  155. hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
  156. WIPHY_FLAG_DISABLE_BEACON_HINTS |
  157. WIPHY_FLAG_IBSS_RSN;
  158. hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
  159. hw->wiphy->n_iface_combinations =
  160. ARRAY_SIZE(iwl_mvm_iface_combinations);
  161. hw->wiphy->max_remain_on_channel_duration = 10000;
  162. hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
  163. /* Extract MAC address */
  164. memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
  165. hw->wiphy->addresses = mvm->addresses;
  166. hw->wiphy->n_addresses = 1;
  167. /* Extract additional MAC addresses if available */
  168. num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
  169. min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
  170. for (i = 1; i < num_mac; i++) {
  171. memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
  172. ETH_ALEN);
  173. mvm->addresses[i].addr[5]++;
  174. hw->wiphy->n_addresses++;
  175. }
  176. iwl_mvm_reset_phy_ctxts(mvm);
  177. /* we create the 802.11 header and a max-length SSID element */
  178. hw->wiphy->max_scan_ie_len =
  179. mvm->fw->ucode_capa.max_probe_length - 24 - 34;
  180. hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
  181. if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
  182. hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  183. &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
  184. if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
  185. hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  186. &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
  187. hw->wiphy->hw_version = mvm->trans->hw_id;
  188. if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
  189. hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
  190. else
  191. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  192. hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
  193. NL80211_FEATURE_P2P_GO_OPPPS;
  194. mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
  195. #ifdef CONFIG_PM_SLEEP
  196. if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
  197. mvm->trans->ops->d3_suspend &&
  198. mvm->trans->ops->d3_resume &&
  199. device_can_wakeup(mvm->trans->dev)) {
  200. hw->wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
  201. WIPHY_WOWLAN_DISCONNECT |
  202. WIPHY_WOWLAN_EAP_IDENTITY_REQ |
  203. WIPHY_WOWLAN_RFKILL_RELEASE;
  204. if (!iwlwifi_mod_params.sw_crypto)
  205. hw->wiphy->wowlan.flags |=
  206. WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
  207. WIPHY_WOWLAN_GTK_REKEY_FAILURE |
  208. WIPHY_WOWLAN_4WAY_HANDSHAKE;
  209. hw->wiphy->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
  210. hw->wiphy->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
  211. hw->wiphy->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
  212. hw->wiphy->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
  213. }
  214. #endif
  215. ret = iwl_mvm_leds_init(mvm);
  216. if (ret)
  217. return ret;
  218. return ieee80211_register_hw(mvm->hw);
  219. }
  220. static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
  221. struct ieee80211_tx_control *control,
  222. struct sk_buff *skb)
  223. {
  224. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  225. if (iwl_mvm_is_radio_killed(mvm)) {
  226. IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
  227. goto drop;
  228. }
  229. if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
  230. !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status))
  231. goto drop;
  232. if (control->sta) {
  233. if (iwl_mvm_tx_skb(mvm, skb, control->sta))
  234. goto drop;
  235. return;
  236. }
  237. if (iwl_mvm_tx_skb_non_sta(mvm, skb))
  238. goto drop;
  239. return;
  240. drop:
  241. ieee80211_free_txskb(hw, skb);
  242. }
  243. static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
  244. struct ieee80211_vif *vif,
  245. enum ieee80211_ampdu_mlme_action action,
  246. struct ieee80211_sta *sta, u16 tid,
  247. u16 *ssn, u8 buf_size)
  248. {
  249. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  250. int ret;
  251. IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
  252. sta->addr, tid, action);
  253. if (!(mvm->nvm_data->sku_cap_11n_enable))
  254. return -EACCES;
  255. mutex_lock(&mvm->mutex);
  256. switch (action) {
  257. case IEEE80211_AMPDU_RX_START:
  258. if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) {
  259. ret = -EINVAL;
  260. break;
  261. }
  262. ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
  263. break;
  264. case IEEE80211_AMPDU_RX_STOP:
  265. ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
  266. break;
  267. case IEEE80211_AMPDU_TX_START:
  268. if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) {
  269. ret = -EINVAL;
  270. break;
  271. }
  272. ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
  273. break;
  274. case IEEE80211_AMPDU_TX_STOP_CONT:
  275. ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
  276. break;
  277. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  278. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  279. ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
  280. break;
  281. case IEEE80211_AMPDU_TX_OPERATIONAL:
  282. ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
  283. break;
  284. default:
  285. WARN_ON_ONCE(1);
  286. ret = -EINVAL;
  287. break;
  288. }
  289. mutex_unlock(&mvm->mutex);
  290. return ret;
  291. }
  292. static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
  293. struct ieee80211_vif *vif)
  294. {
  295. struct iwl_mvm *mvm = data;
  296. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  297. mvmvif->uploaded = false;
  298. mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
  299. /* does this make sense at all? */
  300. mvmvif->color++;
  301. spin_lock_bh(&mvm->time_event_lock);
  302. iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
  303. spin_unlock_bh(&mvm->time_event_lock);
  304. mvmvif->phy_ctxt = NULL;
  305. }
  306. static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
  307. {
  308. iwl_trans_stop_device(mvm->trans);
  309. iwl_trans_stop_hw(mvm->trans, false);
  310. mvm->scan_status = IWL_MVM_SCAN_NONE;
  311. /* just in case one was running */
  312. ieee80211_remain_on_channel_expired(mvm->hw);
  313. ieee80211_iterate_active_interfaces_atomic(
  314. mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
  315. iwl_mvm_cleanup_iterator, mvm);
  316. mvm->p2p_device_vif = NULL;
  317. iwl_mvm_reset_phy_ctxts(mvm);
  318. memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
  319. memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
  320. ieee80211_wake_queues(mvm->hw);
  321. mvm->vif_count = 0;
  322. }
  323. static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
  324. {
  325. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  326. int ret;
  327. mutex_lock(&mvm->mutex);
  328. /* Clean up some internal and mac80211 state on restart */
  329. if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
  330. iwl_mvm_restart_cleanup(mvm);
  331. ret = iwl_mvm_up(mvm);
  332. mutex_unlock(&mvm->mutex);
  333. return ret;
  334. }
  335. static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
  336. {
  337. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  338. int ret;
  339. mutex_lock(&mvm->mutex);
  340. clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
  341. ret = iwl_mvm_update_quotas(mvm, NULL);
  342. if (ret)
  343. IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
  344. ret);
  345. mutex_unlock(&mvm->mutex);
  346. }
  347. static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
  348. {
  349. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  350. flush_work(&mvm->async_handlers_wk);
  351. mutex_lock(&mvm->mutex);
  352. /* async_handlers_wk is now blocked */
  353. /*
  354. * The work item could be running or queued if the
  355. * ROC time event stops just as we get here.
  356. */
  357. cancel_work_sync(&mvm->roc_done_wk);
  358. iwl_trans_stop_device(mvm->trans);
  359. iwl_trans_stop_hw(mvm->trans, false);
  360. iwl_mvm_async_handlers_purge(mvm);
  361. /* async_handlers_list is empty and will stay empty: HW is stopped */
  362. /* the fw is stopped, the aux sta is dead: clean up driver state */
  363. iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
  364. mutex_unlock(&mvm->mutex);
  365. /*
  366. * The worker might have been waiting for the mutex, let it run and
  367. * discover that its list is now empty.
  368. */
  369. cancel_work_sync(&mvm->async_handlers_wk);
  370. }
  371. static void iwl_mvm_pm_disable_iterator(void *data, u8 *mac,
  372. struct ieee80211_vif *vif)
  373. {
  374. struct iwl_mvm *mvm = data;
  375. int ret;
  376. ret = iwl_mvm_power_disable(mvm, vif);
  377. if (ret)
  378. IWL_ERR(mvm, "failed to disable power management\n");
  379. }
  380. static void iwl_mvm_power_update_iterator(void *data, u8 *mac,
  381. struct ieee80211_vif *vif)
  382. {
  383. struct iwl_mvm *mvm = data;
  384. iwl_mvm_power_update_mode(mvm, vif);
  385. }
  386. static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
  387. {
  388. u16 i;
  389. lockdep_assert_held(&mvm->mutex);
  390. for (i = 0; i < NUM_PHY_CTX; i++)
  391. if (!mvm->phy_ctxts[i].ref)
  392. return &mvm->phy_ctxts[i];
  393. IWL_ERR(mvm, "No available PHY context\n");
  394. return NULL;
  395. }
  396. static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
  397. struct ieee80211_vif *vif)
  398. {
  399. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  400. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  401. int ret;
  402. /*
  403. * Not much to do here. The stack will not allow interface
  404. * types or combinations that we didn't advertise, so we
  405. * don't really have to check the types.
  406. */
  407. mutex_lock(&mvm->mutex);
  408. /* Allocate resources for the MAC context, and add it the the fw */
  409. ret = iwl_mvm_mac_ctxt_init(mvm, vif);
  410. if (ret)
  411. goto out_unlock;
  412. /*
  413. * The AP binding flow can be done only after the beacon
  414. * template is configured (which happens only in the mac80211
  415. * start_ap() flow), and adding the broadcast station can happen
  416. * only after the binding.
  417. * In addition, since modifying the MAC before adding a bcast
  418. * station is not allowed by the FW, delay the adding of MAC context to
  419. * the point where we can also add the bcast station.
  420. * In short: there's not much we can do at this point, other than
  421. * allocating resources :)
  422. */
  423. if (vif->type == NL80211_IFTYPE_AP) {
  424. u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif);
  425. ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta,
  426. qmask);
  427. if (ret) {
  428. IWL_ERR(mvm, "Failed to allocate bcast sta\n");
  429. goto out_release;
  430. }
  431. goto out_unlock;
  432. }
  433. /*
  434. * TODO: remove this temporary code.
  435. * Currently MVM FW supports power management only on single MAC.
  436. * If new interface added, disable PM on existing interface.
  437. * P2P device is a special case, since it is handled by FW similary to
  438. * scan. If P2P deviced is added, PM remains enabled on existing
  439. * interface.
  440. * Note: the method below does not count the new interface being added
  441. * at this moment.
  442. */
  443. if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
  444. mvm->vif_count++;
  445. if (mvm->vif_count > 1) {
  446. IWL_DEBUG_MAC80211(mvm,
  447. "Disable power on existing interfaces\n");
  448. ieee80211_iterate_active_interfaces_atomic(
  449. mvm->hw,
  450. IEEE80211_IFACE_ITER_NORMAL,
  451. iwl_mvm_pm_disable_iterator, mvm);
  452. }
  453. ret = iwl_mvm_mac_ctxt_add(mvm, vif);
  454. if (ret)
  455. goto out_release;
  456. /*
  457. * Update power state on the new interface. Admittedly, based on
  458. * mac80211 logics this power update will disable power management
  459. */
  460. iwl_mvm_power_update_mode(mvm, vif);
  461. /* beacon filtering */
  462. if (!mvm->bf_allowed_vif &&
  463. vif->type == NL80211_IFTYPE_STATION && !vif->p2p){
  464. mvm->bf_allowed_vif = mvmvif;
  465. vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
  466. }
  467. ret = iwl_mvm_disable_beacon_filter(mvm, vif);
  468. if (ret)
  469. goto out_release;
  470. /*
  471. * P2P_DEVICE interface does not have a channel context assigned to it,
  472. * so a dedicated PHY context is allocated to it and the corresponding
  473. * MAC context is bound to it at this stage.
  474. */
  475. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  476. mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
  477. if (!mvmvif->phy_ctxt) {
  478. ret = -ENOSPC;
  479. goto out_remove_mac;
  480. }
  481. iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
  482. ret = iwl_mvm_binding_add_vif(mvm, vif);
  483. if (ret)
  484. goto out_unref_phy;
  485. ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
  486. if (ret)
  487. goto out_unbind;
  488. /* Save a pointer to p2p device vif, so it can later be used to
  489. * update the p2p device MAC when a GO is started/stopped */
  490. mvm->p2p_device_vif = vif;
  491. }
  492. iwl_mvm_vif_dbgfs_register(mvm, vif);
  493. goto out_unlock;
  494. out_unbind:
  495. iwl_mvm_binding_remove_vif(mvm, vif);
  496. out_unref_phy:
  497. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  498. out_remove_mac:
  499. mvmvif->phy_ctxt = NULL;
  500. iwl_mvm_mac_ctxt_remove(mvm, vif);
  501. out_release:
  502. /*
  503. * TODO: remove this temporary code.
  504. * Currently MVM FW supports power management only on single MAC.
  505. * Check if only one additional interface remains after releasing
  506. * current one. Update power mode on the remaining interface.
  507. */
  508. if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
  509. mvm->vif_count--;
  510. IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n",
  511. mvm->vif_count);
  512. if (mvm->vif_count == 1) {
  513. ieee80211_iterate_active_interfaces(
  514. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  515. iwl_mvm_power_update_iterator, mvm);
  516. }
  517. iwl_mvm_mac_ctxt_release(mvm, vif);
  518. out_unlock:
  519. mutex_unlock(&mvm->mutex);
  520. return ret;
  521. }
  522. static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
  523. struct ieee80211_vif *vif)
  524. {
  525. u32 tfd_msk = 0, ac;
  526. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  527. if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
  528. tfd_msk |= BIT(vif->hw_queue[ac]);
  529. if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
  530. tfd_msk |= BIT(vif->cab_queue);
  531. if (tfd_msk) {
  532. mutex_lock(&mvm->mutex);
  533. iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
  534. mutex_unlock(&mvm->mutex);
  535. }
  536. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  537. /*
  538. * Flush the ROC worker which will flush the OFFCHANNEL queue.
  539. * We assume here that all the packets sent to the OFFCHANNEL
  540. * queue are sent in ROC session.
  541. */
  542. flush_work(&mvm->roc_done_wk);
  543. } else {
  544. /*
  545. * By now, all the AC queues are empty. The AGG queues are
  546. * empty too. We already got all the Tx responses for all the
  547. * packets in the queues. The drain work can have been
  548. * triggered. Flush it. This work item takes the mutex, so kill
  549. * it before we take it.
  550. */
  551. flush_work(&mvm->sta_drained_wk);
  552. }
  553. }
  554. static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
  555. struct ieee80211_vif *vif)
  556. {
  557. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  558. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  559. iwl_mvm_prepare_mac_removal(mvm, vif);
  560. mutex_lock(&mvm->mutex);
  561. if (mvm->bf_allowed_vif == mvmvif) {
  562. mvm->bf_allowed_vif = NULL;
  563. vif->driver_flags &= ~IEEE80211_VIF_BEACON_FILTER;
  564. }
  565. iwl_mvm_vif_dbgfs_clean(mvm, vif);
  566. /*
  567. * For AP/GO interface, the tear down of the resources allocated to the
  568. * interface is be handled as part of the stop_ap flow.
  569. */
  570. if (vif->type == NL80211_IFTYPE_AP) {
  571. iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
  572. goto out_release;
  573. }
  574. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  575. mvm->p2p_device_vif = NULL;
  576. iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
  577. iwl_mvm_binding_remove_vif(mvm, vif);
  578. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  579. mvmvif->phy_ctxt = NULL;
  580. }
  581. /*
  582. * TODO: remove this temporary code.
  583. * Currently MVM FW supports power management only on single MAC.
  584. * Check if only one additional interface remains after removing
  585. * current one. Update power mode on the remaining interface.
  586. */
  587. if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
  588. mvm->vif_count--;
  589. IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n",
  590. mvm->vif_count);
  591. if (mvm->vif_count == 1) {
  592. ieee80211_iterate_active_interfaces(
  593. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  594. iwl_mvm_power_update_iterator, mvm);
  595. }
  596. iwl_mvm_mac_ctxt_remove(mvm, vif);
  597. out_release:
  598. iwl_mvm_mac_ctxt_release(mvm, vif);
  599. mutex_unlock(&mvm->mutex);
  600. }
  601. static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
  602. {
  603. return 0;
  604. }
  605. static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
  606. unsigned int changed_flags,
  607. unsigned int *total_flags,
  608. u64 multicast)
  609. {
  610. *total_flags = 0;
  611. }
  612. static int iwl_mvm_configure_mcast_filter(struct iwl_mvm *mvm,
  613. struct ieee80211_vif *vif)
  614. {
  615. struct iwl_mcast_filter_cmd mcast_filter_cmd = {
  616. .pass_all = 1,
  617. };
  618. memcpy(mcast_filter_cmd.bssid, vif->bss_conf.bssid, ETH_ALEN);
  619. return iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_SYNC,
  620. sizeof(mcast_filter_cmd),
  621. &mcast_filter_cmd);
  622. }
  623. static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
  624. struct ieee80211_vif *vif,
  625. struct ieee80211_bss_conf *bss_conf,
  626. u32 changes)
  627. {
  628. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  629. int ret;
  630. ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
  631. if (ret)
  632. IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
  633. if (changes & BSS_CHANGED_ASSOC) {
  634. if (bss_conf->assoc) {
  635. /* add quota for this interface */
  636. ret = iwl_mvm_update_quotas(mvm, vif);
  637. if (ret) {
  638. IWL_ERR(mvm, "failed to update quotas\n");
  639. return;
  640. }
  641. iwl_mvm_bt_coex_vif_assoc(mvm, vif);
  642. iwl_mvm_configure_mcast_filter(mvm, vif);
  643. } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
  644. /* remove AP station now that the MAC is unassoc */
  645. ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
  646. if (ret)
  647. IWL_ERR(mvm, "failed to remove AP station\n");
  648. mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
  649. /* remove quota for this interface */
  650. ret = iwl_mvm_update_quotas(mvm, NULL);
  651. if (ret)
  652. IWL_ERR(mvm, "failed to update quotas\n");
  653. }
  654. } else if (changes & BSS_CHANGED_DTIM_PERIOD) {
  655. /*
  656. * We received a beacon _after_ association so
  657. * remove the session protection.
  658. */
  659. iwl_mvm_remove_time_event(mvm, mvmvif,
  660. &mvmvif->time_event_data);
  661. } else if (changes & BSS_CHANGED_PS) {
  662. /*
  663. * TODO: remove this temporary code.
  664. * Currently MVM FW supports power management only on single
  665. * MAC. Avoid power mode update if more than one interface
  666. * is active.
  667. */
  668. IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n",
  669. mvm->vif_count);
  670. if (mvm->vif_count == 1) {
  671. ret = iwl_mvm_power_update_mode(mvm, vif);
  672. if (ret)
  673. IWL_ERR(mvm, "failed to update power mode\n");
  674. }
  675. }
  676. }
  677. static int iwl_mvm_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  678. {
  679. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  680. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  681. int ret;
  682. mutex_lock(&mvm->mutex);
  683. /* Send the beacon template */
  684. ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
  685. if (ret)
  686. goto out_unlock;
  687. /* Add the mac context */
  688. ret = iwl_mvm_mac_ctxt_add(mvm, vif);
  689. if (ret)
  690. goto out_unlock;
  691. /* Perform the binding */
  692. ret = iwl_mvm_binding_add_vif(mvm, vif);
  693. if (ret)
  694. goto out_remove;
  695. mvmvif->ap_active = true;
  696. /* Send the bcast station. At this stage the TBTT and DTIM time events
  697. * are added and applied to the scheduler */
  698. ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
  699. if (ret)
  700. goto out_unbind;
  701. ret = iwl_mvm_update_quotas(mvm, vif);
  702. if (ret)
  703. goto out_rm_bcast;
  704. /* Need to update the P2P Device MAC */
  705. if (vif->p2p && mvm->p2p_device_vif)
  706. iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
  707. mutex_unlock(&mvm->mutex);
  708. return 0;
  709. out_rm_bcast:
  710. iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
  711. out_unbind:
  712. iwl_mvm_binding_remove_vif(mvm, vif);
  713. out_remove:
  714. iwl_mvm_mac_ctxt_remove(mvm, vif);
  715. out_unlock:
  716. mutex_unlock(&mvm->mutex);
  717. return ret;
  718. }
  719. static void iwl_mvm_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  720. {
  721. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  722. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  723. iwl_mvm_prepare_mac_removal(mvm, vif);
  724. mutex_lock(&mvm->mutex);
  725. mvmvif->ap_active = false;
  726. /* Need to update the P2P Device MAC */
  727. if (vif->p2p && mvm->p2p_device_vif)
  728. iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
  729. iwl_mvm_update_quotas(mvm, NULL);
  730. iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
  731. iwl_mvm_binding_remove_vif(mvm, vif);
  732. iwl_mvm_mac_ctxt_remove(mvm, vif);
  733. mutex_unlock(&mvm->mutex);
  734. }
  735. static void iwl_mvm_bss_info_changed_ap(struct iwl_mvm *mvm,
  736. struct ieee80211_vif *vif,
  737. struct ieee80211_bss_conf *bss_conf,
  738. u32 changes)
  739. {
  740. /* Need to send a new beacon template to the FW */
  741. if (changes & BSS_CHANGED_BEACON) {
  742. if (iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
  743. IWL_WARN(mvm, "Failed updating beacon data\n");
  744. }
  745. }
  746. static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
  747. struct ieee80211_vif *vif,
  748. struct ieee80211_bss_conf *bss_conf,
  749. u32 changes)
  750. {
  751. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  752. mutex_lock(&mvm->mutex);
  753. switch (vif->type) {
  754. case NL80211_IFTYPE_STATION:
  755. iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
  756. break;
  757. case NL80211_IFTYPE_AP:
  758. iwl_mvm_bss_info_changed_ap(mvm, vif, bss_conf, changes);
  759. break;
  760. default:
  761. /* shouldn't happen */
  762. WARN_ON_ONCE(1);
  763. }
  764. mutex_unlock(&mvm->mutex);
  765. }
  766. static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
  767. struct ieee80211_vif *vif,
  768. struct cfg80211_scan_request *req)
  769. {
  770. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  771. int ret;
  772. if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS)
  773. return -EINVAL;
  774. mutex_lock(&mvm->mutex);
  775. if (mvm->scan_status == IWL_MVM_SCAN_NONE)
  776. ret = iwl_mvm_scan_request(mvm, vif, req);
  777. else
  778. ret = -EBUSY;
  779. mutex_unlock(&mvm->mutex);
  780. return ret;
  781. }
  782. static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
  783. struct ieee80211_vif *vif)
  784. {
  785. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  786. mutex_lock(&mvm->mutex);
  787. iwl_mvm_cancel_scan(mvm);
  788. mutex_unlock(&mvm->mutex);
  789. }
  790. static void
  791. iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
  792. struct ieee80211_sta *sta, u16 tid,
  793. int num_frames,
  794. enum ieee80211_frame_release_type reason,
  795. bool more_data)
  796. {
  797. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  798. /* TODO: how do we tell the fw to send frames for a specific TID */
  799. /*
  800. * The fw will send EOSP notification when the last frame will be
  801. * transmitted.
  802. */
  803. iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames);
  804. }
  805. static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
  806. struct ieee80211_vif *vif,
  807. enum sta_notify_cmd cmd,
  808. struct ieee80211_sta *sta)
  809. {
  810. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  811. struct iwl_mvm_sta *mvmsta = (void *)sta->drv_priv;
  812. switch (cmd) {
  813. case STA_NOTIFY_SLEEP:
  814. if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
  815. ieee80211_sta_block_awake(hw, sta, true);
  816. /*
  817. * The fw updates the STA to be asleep. Tx packets on the Tx
  818. * queues to this station will not be transmitted. The fw will
  819. * send a Tx response with TX_STATUS_FAIL_DEST_PS.
  820. */
  821. break;
  822. case STA_NOTIFY_AWAKE:
  823. if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
  824. break;
  825. iwl_mvm_sta_modify_ps_wake(mvm, sta);
  826. break;
  827. default:
  828. break;
  829. }
  830. }
  831. static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
  832. struct ieee80211_vif *vif,
  833. struct ieee80211_sta *sta,
  834. enum ieee80211_sta_state old_state,
  835. enum ieee80211_sta_state new_state)
  836. {
  837. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  838. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  839. int ret;
  840. IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
  841. sta->addr, old_state, new_state);
  842. /* this would be a mac80211 bug ... but don't crash */
  843. if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
  844. return -EINVAL;
  845. /* if a STA is being removed, reuse its ID */
  846. flush_work(&mvm->sta_drained_wk);
  847. mutex_lock(&mvm->mutex);
  848. if (old_state == IEEE80211_STA_NOTEXIST &&
  849. new_state == IEEE80211_STA_NONE) {
  850. ret = iwl_mvm_add_sta(mvm, vif, sta);
  851. } else if (old_state == IEEE80211_STA_NONE &&
  852. new_state == IEEE80211_STA_AUTH) {
  853. ret = 0;
  854. } else if (old_state == IEEE80211_STA_AUTH &&
  855. new_state == IEEE80211_STA_ASSOC) {
  856. ret = iwl_mvm_update_sta(mvm, vif, sta);
  857. if (ret == 0)
  858. iwl_mvm_rs_rate_init(mvm, sta,
  859. mvmvif->phy_ctxt->channel->band);
  860. } else if (old_state == IEEE80211_STA_ASSOC &&
  861. new_state == IEEE80211_STA_AUTHORIZED) {
  862. /* enable beacon filtering */
  863. WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif));
  864. ret = 0;
  865. } else if (old_state == IEEE80211_STA_AUTHORIZED &&
  866. new_state == IEEE80211_STA_ASSOC) {
  867. /* disable beacon filtering */
  868. WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif));
  869. ret = 0;
  870. } else if (old_state == IEEE80211_STA_ASSOC &&
  871. new_state == IEEE80211_STA_AUTH) {
  872. ret = 0;
  873. } else if (old_state == IEEE80211_STA_AUTH &&
  874. new_state == IEEE80211_STA_NONE) {
  875. ret = 0;
  876. } else if (old_state == IEEE80211_STA_NONE &&
  877. new_state == IEEE80211_STA_NOTEXIST) {
  878. ret = iwl_mvm_rm_sta(mvm, vif, sta);
  879. } else {
  880. ret = -EIO;
  881. }
  882. mutex_unlock(&mvm->mutex);
  883. return ret;
  884. }
  885. static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  886. {
  887. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  888. mvm->rts_threshold = value;
  889. return 0;
  890. }
  891. static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
  892. struct ieee80211_vif *vif, u16 ac,
  893. const struct ieee80211_tx_queue_params *params)
  894. {
  895. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  896. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  897. mvmvif->queue_params[ac] = *params;
  898. /*
  899. * No need to update right away, we'll get BSS_CHANGED_QOS
  900. * The exception is P2P_DEVICE interface which needs immediate update.
  901. */
  902. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  903. int ret;
  904. mutex_lock(&mvm->mutex);
  905. ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
  906. mutex_unlock(&mvm->mutex);
  907. return ret;
  908. }
  909. return 0;
  910. }
  911. static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
  912. struct ieee80211_vif *vif)
  913. {
  914. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  915. u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
  916. 200 + vif->bss_conf.beacon_int);
  917. u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
  918. 100 + vif->bss_conf.beacon_int);
  919. if (WARN_ON_ONCE(vif->bss_conf.assoc))
  920. return;
  921. mutex_lock(&mvm->mutex);
  922. /* Try really hard to protect the session and hear a beacon */
  923. iwl_mvm_protect_session(mvm, vif, duration, min_duration);
  924. mutex_unlock(&mvm->mutex);
  925. }
  926. static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
  927. enum set_key_cmd cmd,
  928. struct ieee80211_vif *vif,
  929. struct ieee80211_sta *sta,
  930. struct ieee80211_key_conf *key)
  931. {
  932. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  933. int ret;
  934. if (iwlwifi_mod_params.sw_crypto) {
  935. IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
  936. return -EOPNOTSUPP;
  937. }
  938. switch (key->cipher) {
  939. case WLAN_CIPHER_SUITE_TKIP:
  940. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  941. /* fall-through */
  942. case WLAN_CIPHER_SUITE_CCMP:
  943. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  944. break;
  945. case WLAN_CIPHER_SUITE_AES_CMAC:
  946. WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
  947. break;
  948. case WLAN_CIPHER_SUITE_WEP40:
  949. case WLAN_CIPHER_SUITE_WEP104:
  950. /*
  951. * Support for TX only, at least for now, so accept
  952. * the key and do nothing else. Then mac80211 will
  953. * pass it for TX but we don't have to use it for RX.
  954. */
  955. return 0;
  956. default:
  957. return -EOPNOTSUPP;
  958. }
  959. mutex_lock(&mvm->mutex);
  960. switch (cmd) {
  961. case SET_KEY:
  962. if (vif->type == NL80211_IFTYPE_AP && !sta) {
  963. /* GTK on AP interface is a TX-only key, return 0 */
  964. ret = 0;
  965. key->hw_key_idx = STA_KEY_IDX_INVALID;
  966. break;
  967. }
  968. IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
  969. ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
  970. if (ret) {
  971. IWL_WARN(mvm, "set key failed\n");
  972. /*
  973. * can't add key for RX, but we don't need it
  974. * in the device for TX so still return 0
  975. */
  976. key->hw_key_idx = STA_KEY_IDX_INVALID;
  977. ret = 0;
  978. }
  979. break;
  980. case DISABLE_KEY:
  981. if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
  982. ret = 0;
  983. break;
  984. }
  985. IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
  986. ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
  987. break;
  988. default:
  989. ret = -EINVAL;
  990. }
  991. mutex_unlock(&mvm->mutex);
  992. return ret;
  993. }
  994. static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
  995. struct ieee80211_vif *vif,
  996. struct ieee80211_key_conf *keyconf,
  997. struct ieee80211_sta *sta,
  998. u32 iv32, u16 *phase1key)
  999. {
  1000. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1001. iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
  1002. }
  1003. static int iwl_mvm_roc(struct ieee80211_hw *hw,
  1004. struct ieee80211_vif *vif,
  1005. struct ieee80211_channel *channel,
  1006. int duration,
  1007. enum ieee80211_roc_type type)
  1008. {
  1009. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1010. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1011. struct cfg80211_chan_def chandef;
  1012. struct iwl_mvm_phy_ctxt *phy_ctxt;
  1013. int ret, i;
  1014. IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
  1015. duration, type);
  1016. if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
  1017. IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
  1018. return -EINVAL;
  1019. }
  1020. mutex_lock(&mvm->mutex);
  1021. for (i = 0; i < NUM_PHY_CTX; i++) {
  1022. phy_ctxt = &mvm->phy_ctxts[i];
  1023. if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
  1024. continue;
  1025. if (phy_ctxt->ref && channel == phy_ctxt->channel) {
  1026. /*
  1027. * Unbind the P2P_DEVICE from the current PHY context,
  1028. * and if the PHY context is not used remove it.
  1029. */
  1030. ret = iwl_mvm_binding_remove_vif(mvm, vif);
  1031. if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
  1032. goto out_unlock;
  1033. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  1034. /* Bind the P2P_DEVICE to the current PHY Context */
  1035. mvmvif->phy_ctxt = phy_ctxt;
  1036. ret = iwl_mvm_binding_add_vif(mvm, vif);
  1037. if (WARN(ret, "Failed binding P2P_DEVICE\n"))
  1038. goto out_unlock;
  1039. iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
  1040. goto schedule_time_event;
  1041. }
  1042. }
  1043. /* Need to update the PHY context only if the ROC channel changed */
  1044. if (channel == mvmvif->phy_ctxt->channel)
  1045. goto schedule_time_event;
  1046. cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
  1047. /*
  1048. * Change the PHY context configuration as it is currently referenced
  1049. * only by the P2P Device MAC
  1050. */
  1051. if (mvmvif->phy_ctxt->ref == 1) {
  1052. ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
  1053. &chandef, 1, 1);
  1054. if (ret)
  1055. goto out_unlock;
  1056. } else {
  1057. /*
  1058. * The PHY context is shared with other MACs. Need to remove the
  1059. * P2P Device from the binding, allocate an new PHY context and
  1060. * create a new binding
  1061. */
  1062. phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
  1063. if (!phy_ctxt) {
  1064. ret = -ENOSPC;
  1065. goto out_unlock;
  1066. }
  1067. ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
  1068. 1, 1);
  1069. if (ret) {
  1070. IWL_ERR(mvm, "Failed to change PHY context\n");
  1071. goto out_unlock;
  1072. }
  1073. /* Unbind the P2P_DEVICE from the current PHY context */
  1074. ret = iwl_mvm_binding_remove_vif(mvm, vif);
  1075. if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
  1076. goto out_unlock;
  1077. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  1078. /* Bind the P2P_DEVICE to the new allocated PHY context */
  1079. mvmvif->phy_ctxt = phy_ctxt;
  1080. ret = iwl_mvm_binding_add_vif(mvm, vif);
  1081. if (WARN(ret, "Failed binding P2P_DEVICE\n"))
  1082. goto out_unlock;
  1083. iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
  1084. }
  1085. schedule_time_event:
  1086. /* Schedule the time events */
  1087. ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
  1088. out_unlock:
  1089. mutex_unlock(&mvm->mutex);
  1090. IWL_DEBUG_MAC80211(mvm, "leave\n");
  1091. return ret;
  1092. }
  1093. static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
  1094. {
  1095. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1096. IWL_DEBUG_MAC80211(mvm, "enter\n");
  1097. mutex_lock(&mvm->mutex);
  1098. iwl_mvm_stop_p2p_roc(mvm);
  1099. mutex_unlock(&mvm->mutex);
  1100. IWL_DEBUG_MAC80211(mvm, "leave\n");
  1101. return 0;
  1102. }
  1103. static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
  1104. struct ieee80211_chanctx_conf *ctx)
  1105. {
  1106. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1107. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  1108. struct iwl_mvm_phy_ctxt *phy_ctxt;
  1109. int ret;
  1110. IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
  1111. mutex_lock(&mvm->mutex);
  1112. phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
  1113. if (!phy_ctxt) {
  1114. ret = -ENOSPC;
  1115. goto out;
  1116. }
  1117. ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
  1118. ctx->rx_chains_static,
  1119. ctx->rx_chains_dynamic);
  1120. if (ret) {
  1121. IWL_ERR(mvm, "Failed to add PHY context\n");
  1122. goto out;
  1123. }
  1124. iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
  1125. *phy_ctxt_id = phy_ctxt->id;
  1126. out:
  1127. mutex_unlock(&mvm->mutex);
  1128. return ret;
  1129. }
  1130. static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
  1131. struct ieee80211_chanctx_conf *ctx)
  1132. {
  1133. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1134. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  1135. struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
  1136. mutex_lock(&mvm->mutex);
  1137. iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
  1138. mutex_unlock(&mvm->mutex);
  1139. }
  1140. static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
  1141. struct ieee80211_chanctx_conf *ctx,
  1142. u32 changed)
  1143. {
  1144. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1145. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  1146. struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
  1147. if (WARN_ONCE((phy_ctxt->ref > 1) &&
  1148. (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
  1149. IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
  1150. IEEE80211_CHANCTX_CHANGE_RADAR)),
  1151. "Cannot change PHY. Ref=%d, changed=0x%X\n",
  1152. phy_ctxt->ref, changed))
  1153. return;
  1154. mutex_lock(&mvm->mutex);
  1155. iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
  1156. ctx->rx_chains_static,
  1157. ctx->rx_chains_dynamic);
  1158. mutex_unlock(&mvm->mutex);
  1159. }
  1160. static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
  1161. struct ieee80211_vif *vif,
  1162. struct ieee80211_chanctx_conf *ctx)
  1163. {
  1164. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1165. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  1166. struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
  1167. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1168. int ret;
  1169. mutex_lock(&mvm->mutex);
  1170. mvmvif->phy_ctxt = phy_ctxt;
  1171. switch (vif->type) {
  1172. case NL80211_IFTYPE_AP:
  1173. /*
  1174. * The AP binding flow is handled as part of the start_ap flow
  1175. * (in bss_info_changed).
  1176. */
  1177. ret = 0;
  1178. goto out_unlock;
  1179. case NL80211_IFTYPE_STATION:
  1180. case NL80211_IFTYPE_ADHOC:
  1181. case NL80211_IFTYPE_MONITOR:
  1182. break;
  1183. default:
  1184. ret = -EINVAL;
  1185. goto out_unlock;
  1186. }
  1187. ret = iwl_mvm_binding_add_vif(mvm, vif);
  1188. if (ret)
  1189. goto out_unlock;
  1190. /*
  1191. * Setting the quota at this stage is only required for monitor
  1192. * interfaces. For the other types, the bss_info changed flow
  1193. * will handle quota settings.
  1194. */
  1195. if (vif->type == NL80211_IFTYPE_MONITOR) {
  1196. mvmvif->monitor_active = true;
  1197. ret = iwl_mvm_update_quotas(mvm, vif);
  1198. if (ret)
  1199. goto out_remove_binding;
  1200. }
  1201. goto out_unlock;
  1202. out_remove_binding:
  1203. iwl_mvm_binding_remove_vif(mvm, vif);
  1204. out_unlock:
  1205. mutex_unlock(&mvm->mutex);
  1206. if (ret)
  1207. mvmvif->phy_ctxt = NULL;
  1208. return ret;
  1209. }
  1210. static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
  1211. struct ieee80211_vif *vif,
  1212. struct ieee80211_chanctx_conf *ctx)
  1213. {
  1214. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1215. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1216. mutex_lock(&mvm->mutex);
  1217. iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
  1218. if (vif->type == NL80211_IFTYPE_AP)
  1219. goto out_unlock;
  1220. switch (vif->type) {
  1221. case NL80211_IFTYPE_MONITOR:
  1222. mvmvif->monitor_active = false;
  1223. iwl_mvm_update_quotas(mvm, NULL);
  1224. break;
  1225. default:
  1226. break;
  1227. }
  1228. iwl_mvm_binding_remove_vif(mvm, vif);
  1229. out_unlock:
  1230. mvmvif->phy_ctxt = NULL;
  1231. mutex_unlock(&mvm->mutex);
  1232. }
  1233. static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
  1234. struct ieee80211_sta *sta,
  1235. bool set)
  1236. {
  1237. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1238. struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
  1239. if (!mvm_sta || !mvm_sta->vif) {
  1240. IWL_ERR(mvm, "Station is not associated to a vif\n");
  1241. return -EINVAL;
  1242. }
  1243. return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
  1244. }
  1245. static void iwl_mvm_mac_rssi_callback(struct ieee80211_hw *hw,
  1246. struct ieee80211_vif *vif,
  1247. enum ieee80211_rssi_event rssi_event)
  1248. {
  1249. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1250. iwl_mvm_bt_rssi_event(mvm, vif, rssi_event);
  1251. }
  1252. struct ieee80211_ops iwl_mvm_hw_ops = {
  1253. .tx = iwl_mvm_mac_tx,
  1254. .ampdu_action = iwl_mvm_mac_ampdu_action,
  1255. .start = iwl_mvm_mac_start,
  1256. .restart_complete = iwl_mvm_mac_restart_complete,
  1257. .stop = iwl_mvm_mac_stop,
  1258. .add_interface = iwl_mvm_mac_add_interface,
  1259. .remove_interface = iwl_mvm_mac_remove_interface,
  1260. .config = iwl_mvm_mac_config,
  1261. .configure_filter = iwl_mvm_configure_filter,
  1262. .bss_info_changed = iwl_mvm_bss_info_changed,
  1263. .hw_scan = iwl_mvm_mac_hw_scan,
  1264. .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
  1265. .sta_state = iwl_mvm_mac_sta_state,
  1266. .sta_notify = iwl_mvm_mac_sta_notify,
  1267. .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
  1268. .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
  1269. .conf_tx = iwl_mvm_mac_conf_tx,
  1270. .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
  1271. .set_key = iwl_mvm_mac_set_key,
  1272. .update_tkip_key = iwl_mvm_mac_update_tkip_key,
  1273. .remain_on_channel = iwl_mvm_roc,
  1274. .cancel_remain_on_channel = iwl_mvm_cancel_roc,
  1275. .rssi_callback = iwl_mvm_mac_rssi_callback,
  1276. .add_chanctx = iwl_mvm_add_chanctx,
  1277. .remove_chanctx = iwl_mvm_remove_chanctx,
  1278. .change_chanctx = iwl_mvm_change_chanctx,
  1279. .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
  1280. .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
  1281. .start_ap = iwl_mvm_start_ap,
  1282. .stop_ap = iwl_mvm_stop_ap,
  1283. .set_tim = iwl_mvm_set_tim,
  1284. #ifdef CONFIG_PM_SLEEP
  1285. /* look at d3.c */
  1286. .suspend = iwl_mvm_suspend,
  1287. .resume = iwl_mvm_resume,
  1288. .set_wakeup = iwl_mvm_set_wakeup,
  1289. .set_rekey_data = iwl_mvm_set_rekey_data,
  1290. #if IS_ENABLED(CONFIG_IPV6)
  1291. .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
  1292. #endif
  1293. .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
  1294. #endif
  1295. };