mac80211.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764
  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. #include "testmode.h"
  80. static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
  81. {
  82. .max = 1,
  83. .types = BIT(NL80211_IFTYPE_STATION),
  84. },
  85. {
  86. .max = 1,
  87. .types = BIT(NL80211_IFTYPE_AP) |
  88. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  89. BIT(NL80211_IFTYPE_P2P_GO),
  90. },
  91. {
  92. .max = 1,
  93. .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
  94. },
  95. };
  96. static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
  97. {
  98. .num_different_channels = 1,
  99. .max_interfaces = 3,
  100. .limits = iwl_mvm_limits,
  101. .n_limits = ARRAY_SIZE(iwl_mvm_limits),
  102. },
  103. };
  104. #ifdef CONFIG_PM_SLEEP
  105. static const struct nl80211_wowlan_tcp_data_token_feature
  106. iwl_mvm_wowlan_tcp_token_feature = {
  107. .min_len = 0,
  108. .max_len = 255,
  109. .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
  110. };
  111. static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
  112. .tok = &iwl_mvm_wowlan_tcp_token_feature,
  113. .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
  114. sizeof(struct ethhdr) -
  115. sizeof(struct iphdr) -
  116. sizeof(struct tcphdr),
  117. .data_interval_max = 65535, /* __le16 in API */
  118. .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
  119. sizeof(struct ethhdr) -
  120. sizeof(struct iphdr) -
  121. sizeof(struct tcphdr),
  122. .seq = true,
  123. };
  124. #endif
  125. static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
  126. {
  127. int i;
  128. memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
  129. for (i = 0; i < NUM_PHY_CTX; i++) {
  130. mvm->phy_ctxts[i].id = i;
  131. mvm->phy_ctxts[i].ref = 0;
  132. }
  133. }
  134. static int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm)
  135. {
  136. /* we create the 802.11 header and SSID element */
  137. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID)
  138. return mvm->fw->ucode_capa.max_probe_length - 24 - 2;
  139. return mvm->fw->ucode_capa.max_probe_length - 24 - 34;
  140. }
  141. int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
  142. {
  143. struct ieee80211_hw *hw = mvm->hw;
  144. int num_mac, ret, i;
  145. /* Tell mac80211 our characteristics */
  146. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  147. IEEE80211_HW_SPECTRUM_MGMT |
  148. IEEE80211_HW_REPORTS_TX_ACK_STATUS |
  149. IEEE80211_HW_QUEUE_CONTROL |
  150. IEEE80211_HW_WANT_MONITOR_VIF |
  151. IEEE80211_HW_SUPPORTS_PS |
  152. IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
  153. IEEE80211_HW_AMPDU_AGGREGATION |
  154. IEEE80211_HW_TIMING_BEACON_ONLY |
  155. IEEE80211_HW_CONNECTION_MONITOR |
  156. IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
  157. IEEE80211_HW_SUPPORTS_STATIC_SMPS |
  158. IEEE80211_HW_SUPPORTS_UAPSD;
  159. hw->queues = mvm->first_agg_queue;
  160. hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
  161. hw->rate_control_algorithm = "iwl-mvm-rs";
  162. /*
  163. * Enable 11w if advertised by firmware and software crypto
  164. * is not enabled (as the firmware will interpret some mgmt
  165. * packets, so enabling it with software crypto isn't safe)
  166. */
  167. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
  168. !iwlwifi_mod_params.sw_crypto)
  169. hw->flags |= IEEE80211_HW_MFP_CAPABLE;
  170. hw->sta_data_size = sizeof(struct iwl_mvm_sta);
  171. hw->vif_data_size = sizeof(struct iwl_mvm_vif);
  172. hw->chanctx_data_size = sizeof(u16);
  173. hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  174. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  175. BIT(NL80211_IFTYPE_AP) |
  176. BIT(NL80211_IFTYPE_P2P_GO) |
  177. BIT(NL80211_IFTYPE_P2P_DEVICE);
  178. hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
  179. WIPHY_FLAG_DISABLE_BEACON_HINTS |
  180. WIPHY_FLAG_IBSS_RSN;
  181. hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
  182. hw->wiphy->n_iface_combinations =
  183. ARRAY_SIZE(iwl_mvm_iface_combinations);
  184. hw->wiphy->max_remain_on_channel_duration = 10000;
  185. hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
  186. hw->uapsd_queues = IWL_UAPSD_AC_INFO;
  187. hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
  188. /* Extract MAC address */
  189. memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
  190. hw->wiphy->addresses = mvm->addresses;
  191. hw->wiphy->n_addresses = 1;
  192. /* Extract additional MAC addresses if available */
  193. num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
  194. min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
  195. for (i = 1; i < num_mac; i++) {
  196. memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
  197. ETH_ALEN);
  198. mvm->addresses[i].addr[5]++;
  199. hw->wiphy->n_addresses++;
  200. }
  201. iwl_mvm_reset_phy_ctxts(mvm);
  202. hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
  203. hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
  204. if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
  205. hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  206. &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
  207. if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
  208. hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  209. &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
  210. hw->wiphy->hw_version = mvm->trans->hw_id;
  211. if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
  212. hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
  213. else
  214. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  215. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SCHED_SCAN) {
  216. hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
  217. hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
  218. hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
  219. /* we create the 802.11 header and zero length SSID IE. */
  220. hw->wiphy->max_sched_scan_ie_len =
  221. SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
  222. }
  223. hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
  224. NL80211_FEATURE_P2P_GO_OPPPS;
  225. mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
  226. #ifdef CONFIG_PM_SLEEP
  227. if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
  228. mvm->trans->ops->d3_suspend &&
  229. mvm->trans->ops->d3_resume &&
  230. device_can_wakeup(mvm->trans->dev)) {
  231. mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
  232. WIPHY_WOWLAN_DISCONNECT |
  233. WIPHY_WOWLAN_EAP_IDENTITY_REQ |
  234. WIPHY_WOWLAN_RFKILL_RELEASE;
  235. if (!iwlwifi_mod_params.sw_crypto)
  236. mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
  237. WIPHY_WOWLAN_GTK_REKEY_FAILURE |
  238. WIPHY_WOWLAN_4WAY_HANDSHAKE;
  239. mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
  240. mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
  241. mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
  242. mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
  243. hw->wiphy->wowlan = &mvm->wowlan;
  244. }
  245. #endif
  246. ret = iwl_mvm_leds_init(mvm);
  247. if (ret)
  248. return ret;
  249. ret = ieee80211_register_hw(mvm->hw);
  250. if (ret)
  251. iwl_mvm_leds_exit(mvm);
  252. return ret;
  253. }
  254. static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
  255. struct ieee80211_tx_control *control,
  256. struct sk_buff *skb)
  257. {
  258. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  259. if (iwl_mvm_is_radio_killed(mvm)) {
  260. IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
  261. goto drop;
  262. }
  263. if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
  264. !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status))
  265. goto drop;
  266. if (control->sta) {
  267. if (iwl_mvm_tx_skb(mvm, skb, control->sta))
  268. goto drop;
  269. return;
  270. }
  271. if (iwl_mvm_tx_skb_non_sta(mvm, skb))
  272. goto drop;
  273. return;
  274. drop:
  275. ieee80211_free_txskb(hw, skb);
  276. }
  277. static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
  278. struct ieee80211_vif *vif,
  279. enum ieee80211_ampdu_mlme_action action,
  280. struct ieee80211_sta *sta, u16 tid,
  281. u16 *ssn, u8 buf_size)
  282. {
  283. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  284. int ret;
  285. IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
  286. sta->addr, tid, action);
  287. if (!(mvm->nvm_data->sku_cap_11n_enable))
  288. return -EACCES;
  289. mutex_lock(&mvm->mutex);
  290. switch (action) {
  291. case IEEE80211_AMPDU_RX_START:
  292. if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) {
  293. ret = -EINVAL;
  294. break;
  295. }
  296. ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
  297. break;
  298. case IEEE80211_AMPDU_RX_STOP:
  299. ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
  300. break;
  301. case IEEE80211_AMPDU_TX_START:
  302. if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) {
  303. ret = -EINVAL;
  304. break;
  305. }
  306. ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
  307. break;
  308. case IEEE80211_AMPDU_TX_STOP_CONT:
  309. ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
  310. break;
  311. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  312. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  313. ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
  314. break;
  315. case IEEE80211_AMPDU_TX_OPERATIONAL:
  316. ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
  317. break;
  318. default:
  319. WARN_ON_ONCE(1);
  320. ret = -EINVAL;
  321. break;
  322. }
  323. mutex_unlock(&mvm->mutex);
  324. return ret;
  325. }
  326. static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
  327. struct ieee80211_vif *vif)
  328. {
  329. struct iwl_mvm *mvm = data;
  330. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  331. mvmvif->uploaded = false;
  332. mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
  333. /* does this make sense at all? */
  334. mvmvif->color++;
  335. spin_lock_bh(&mvm->time_event_lock);
  336. iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
  337. spin_unlock_bh(&mvm->time_event_lock);
  338. mvmvif->phy_ctxt = NULL;
  339. }
  340. static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
  341. {
  342. iwl_trans_stop_device(mvm->trans);
  343. iwl_trans_stop_hw(mvm->trans, false);
  344. mvm->scan_status = IWL_MVM_SCAN_NONE;
  345. /* just in case one was running */
  346. ieee80211_remain_on_channel_expired(mvm->hw);
  347. ieee80211_iterate_active_interfaces_atomic(
  348. mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
  349. iwl_mvm_cleanup_iterator, mvm);
  350. mvm->p2p_device_vif = NULL;
  351. iwl_mvm_reset_phy_ctxts(mvm);
  352. memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
  353. memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
  354. ieee80211_wake_queues(mvm->hw);
  355. mvm->vif_count = 0;
  356. mvm->rx_ba_sessions = 0;
  357. }
  358. static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
  359. {
  360. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  361. int ret;
  362. mutex_lock(&mvm->mutex);
  363. /* Clean up some internal and mac80211 state on restart */
  364. if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
  365. iwl_mvm_restart_cleanup(mvm);
  366. ret = iwl_mvm_up(mvm);
  367. mutex_unlock(&mvm->mutex);
  368. return ret;
  369. }
  370. static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
  371. {
  372. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  373. int ret;
  374. mutex_lock(&mvm->mutex);
  375. clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
  376. ret = iwl_mvm_update_quotas(mvm, NULL);
  377. if (ret)
  378. IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
  379. ret);
  380. mutex_unlock(&mvm->mutex);
  381. }
  382. static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
  383. {
  384. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  385. flush_work(&mvm->async_handlers_wk);
  386. mutex_lock(&mvm->mutex);
  387. /* async_handlers_wk is now blocked */
  388. /*
  389. * The work item could be running or queued if the
  390. * ROC time event stops just as we get here.
  391. */
  392. cancel_work_sync(&mvm->roc_done_wk);
  393. iwl_trans_stop_device(mvm->trans);
  394. iwl_trans_stop_hw(mvm->trans, false);
  395. iwl_mvm_async_handlers_purge(mvm);
  396. /* async_handlers_list is empty and will stay empty: HW is stopped */
  397. /* the fw is stopped, the aux sta is dead: clean up driver state */
  398. iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
  399. mutex_unlock(&mvm->mutex);
  400. /*
  401. * The worker might have been waiting for the mutex, let it run and
  402. * discover that its list is now empty.
  403. */
  404. cancel_work_sync(&mvm->async_handlers_wk);
  405. }
  406. static void iwl_mvm_pm_disable_iterator(void *data, u8 *mac,
  407. struct ieee80211_vif *vif)
  408. {
  409. struct iwl_mvm *mvm = data;
  410. int ret;
  411. ret = iwl_mvm_power_disable(mvm, vif);
  412. if (ret)
  413. IWL_ERR(mvm, "failed to disable power management\n");
  414. }
  415. static void iwl_mvm_power_update_iterator(void *data, u8 *mac,
  416. struct ieee80211_vif *vif)
  417. {
  418. struct iwl_mvm *mvm = data;
  419. iwl_mvm_power_update_mode(mvm, vif);
  420. }
  421. static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
  422. {
  423. u16 i;
  424. lockdep_assert_held(&mvm->mutex);
  425. for (i = 0; i < NUM_PHY_CTX; i++)
  426. if (!mvm->phy_ctxts[i].ref)
  427. return &mvm->phy_ctxts[i];
  428. IWL_ERR(mvm, "No available PHY context\n");
  429. return NULL;
  430. }
  431. static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
  432. struct ieee80211_vif *vif)
  433. {
  434. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  435. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  436. int ret;
  437. /*
  438. * Not much to do here. The stack will not allow interface
  439. * types or combinations that we didn't advertise, so we
  440. * don't really have to check the types.
  441. */
  442. mutex_lock(&mvm->mutex);
  443. /* Allocate resources for the MAC context, and add it to the fw */
  444. ret = iwl_mvm_mac_ctxt_init(mvm, vif);
  445. if (ret)
  446. goto out_unlock;
  447. /*
  448. * TODO: remove this temporary code.
  449. * Currently MVM FW supports power management only on single MAC.
  450. * If new interface added, disable PM on existing interface.
  451. * P2P device is a special case, since it is handled by FW similary to
  452. * scan. If P2P deviced is added, PM remains enabled on existing
  453. * interface.
  454. * Note: the method below does not count the new interface being added
  455. * at this moment.
  456. */
  457. if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
  458. mvm->vif_count++;
  459. if (mvm->vif_count > 1) {
  460. IWL_DEBUG_MAC80211(mvm,
  461. "Disable power on existing interfaces\n");
  462. ieee80211_iterate_active_interfaces_atomic(
  463. mvm->hw,
  464. IEEE80211_IFACE_ITER_NORMAL,
  465. iwl_mvm_pm_disable_iterator, mvm);
  466. }
  467. /*
  468. * The AP binding flow can be done only after the beacon
  469. * template is configured (which happens only in the mac80211
  470. * start_ap() flow), and adding the broadcast station can happen
  471. * only after the binding.
  472. * In addition, since modifying the MAC before adding a bcast
  473. * station is not allowed by the FW, delay the adding of MAC context to
  474. * the point where we can also add the bcast station.
  475. * In short: there's not much we can do at this point, other than
  476. * allocating resources :)
  477. */
  478. if (vif->type == NL80211_IFTYPE_AP) {
  479. u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif);
  480. ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta,
  481. qmask);
  482. if (ret) {
  483. IWL_ERR(mvm, "Failed to allocate bcast sta\n");
  484. goto out_release;
  485. }
  486. iwl_mvm_vif_dbgfs_register(mvm, vif);
  487. goto out_unlock;
  488. }
  489. ret = iwl_mvm_mac_ctxt_add(mvm, vif);
  490. if (ret)
  491. goto out_release;
  492. /*
  493. * Update power state on the new interface. Admittedly, based on
  494. * mac80211 logics this power update will disable power management
  495. */
  496. iwl_mvm_power_update_mode(mvm, vif);
  497. /* beacon filtering */
  498. ret = iwl_mvm_disable_beacon_filter(mvm, vif);
  499. if (ret)
  500. goto out_remove_mac;
  501. if (!mvm->bf_allowed_vif &&
  502. vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
  503. mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED){
  504. mvm->bf_allowed_vif = mvmvif;
  505. vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
  506. IEEE80211_VIF_SUPPORTS_CQM_RSSI;
  507. }
  508. /*
  509. * P2P_DEVICE interface does not have a channel context assigned to it,
  510. * so a dedicated PHY context is allocated to it and the corresponding
  511. * MAC context is bound to it at this stage.
  512. */
  513. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  514. mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
  515. if (!mvmvif->phy_ctxt) {
  516. ret = -ENOSPC;
  517. goto out_free_bf;
  518. }
  519. iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
  520. ret = iwl_mvm_binding_add_vif(mvm, vif);
  521. if (ret)
  522. goto out_unref_phy;
  523. ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
  524. if (ret)
  525. goto out_unbind;
  526. /* Save a pointer to p2p device vif, so it can later be used to
  527. * update the p2p device MAC when a GO is started/stopped */
  528. mvm->p2p_device_vif = vif;
  529. }
  530. iwl_mvm_vif_dbgfs_register(mvm, vif);
  531. goto out_unlock;
  532. out_unbind:
  533. iwl_mvm_binding_remove_vif(mvm, vif);
  534. out_unref_phy:
  535. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  536. out_free_bf:
  537. if (mvm->bf_allowed_vif == mvmvif) {
  538. mvm->bf_allowed_vif = NULL;
  539. vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
  540. IEEE80211_VIF_SUPPORTS_CQM_RSSI);
  541. }
  542. out_remove_mac:
  543. mvmvif->phy_ctxt = NULL;
  544. iwl_mvm_mac_ctxt_remove(mvm, vif);
  545. out_release:
  546. if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
  547. mvm->vif_count--;
  548. ieee80211_iterate_active_interfaces(
  549. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  550. iwl_mvm_power_update_iterator, mvm);
  551. iwl_mvm_mac_ctxt_release(mvm, vif);
  552. out_unlock:
  553. mutex_unlock(&mvm->mutex);
  554. return ret;
  555. }
  556. static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
  557. struct ieee80211_vif *vif)
  558. {
  559. u32 tfd_msk = 0, ac;
  560. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  561. if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
  562. tfd_msk |= BIT(vif->hw_queue[ac]);
  563. if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
  564. tfd_msk |= BIT(vif->cab_queue);
  565. if (tfd_msk) {
  566. mutex_lock(&mvm->mutex);
  567. iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
  568. mutex_unlock(&mvm->mutex);
  569. }
  570. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  571. /*
  572. * Flush the ROC worker which will flush the OFFCHANNEL queue.
  573. * We assume here that all the packets sent to the OFFCHANNEL
  574. * queue are sent in ROC session.
  575. */
  576. flush_work(&mvm->roc_done_wk);
  577. } else {
  578. /*
  579. * By now, all the AC queues are empty. The AGG queues are
  580. * empty too. We already got all the Tx responses for all the
  581. * packets in the queues. The drain work can have been
  582. * triggered. Flush it.
  583. */
  584. flush_work(&mvm->sta_drained_wk);
  585. }
  586. }
  587. static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
  588. struct ieee80211_vif *vif)
  589. {
  590. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  591. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  592. iwl_mvm_prepare_mac_removal(mvm, vif);
  593. mutex_lock(&mvm->mutex);
  594. if (mvm->bf_allowed_vif == mvmvif) {
  595. mvm->bf_allowed_vif = NULL;
  596. vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
  597. IEEE80211_VIF_SUPPORTS_CQM_RSSI);
  598. }
  599. iwl_mvm_vif_dbgfs_clean(mvm, vif);
  600. /*
  601. * For AP/GO interface, the tear down of the resources allocated to the
  602. * interface is be handled as part of the stop_ap flow.
  603. */
  604. if (vif->type == NL80211_IFTYPE_AP) {
  605. #ifdef CONFIG_NL80211_TESTMODE
  606. if (vif == mvm->noa_vif) {
  607. mvm->noa_vif = NULL;
  608. mvm->noa_duration = 0;
  609. }
  610. #endif
  611. iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
  612. goto out_release;
  613. }
  614. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  615. mvm->p2p_device_vif = NULL;
  616. iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
  617. iwl_mvm_binding_remove_vif(mvm, vif);
  618. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  619. mvmvif->phy_ctxt = NULL;
  620. }
  621. /*
  622. * TODO: remove this temporary code.
  623. * Currently MVM FW supports power management only on single MAC.
  624. * Check if only one additional interface remains after removing
  625. * current one. Update power mode on the remaining interface.
  626. */
  627. if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
  628. mvm->vif_count--;
  629. IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n",
  630. mvm->vif_count);
  631. if (mvm->vif_count == 1) {
  632. ieee80211_iterate_active_interfaces(
  633. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  634. iwl_mvm_power_update_iterator, mvm);
  635. }
  636. iwl_mvm_mac_ctxt_remove(mvm, vif);
  637. out_release:
  638. iwl_mvm_mac_ctxt_release(mvm, vif);
  639. mutex_unlock(&mvm->mutex);
  640. }
  641. static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  642. s8 tx_power)
  643. {
  644. /* FW is in charge of regulatory enforcement */
  645. struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
  646. .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
  647. .pwr_restriction = cpu_to_le16(tx_power),
  648. };
  649. return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, CMD_SYNC,
  650. sizeof(reduce_txpwr_cmd),
  651. &reduce_txpwr_cmd);
  652. }
  653. static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
  654. {
  655. return 0;
  656. }
  657. static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
  658. unsigned int changed_flags,
  659. unsigned int *total_flags,
  660. u64 multicast)
  661. {
  662. *total_flags = 0;
  663. }
  664. static int iwl_mvm_configure_mcast_filter(struct iwl_mvm *mvm,
  665. struct ieee80211_vif *vif)
  666. {
  667. struct iwl_mcast_filter_cmd mcast_filter_cmd = {
  668. .pass_all = 1,
  669. };
  670. memcpy(mcast_filter_cmd.bssid, vif->bss_conf.bssid, ETH_ALEN);
  671. return iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_SYNC,
  672. sizeof(mcast_filter_cmd),
  673. &mcast_filter_cmd);
  674. }
  675. static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
  676. struct ieee80211_vif *vif,
  677. struct ieee80211_bss_conf *bss_conf,
  678. u32 changes)
  679. {
  680. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  681. int ret;
  682. ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
  683. if (ret)
  684. IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
  685. if (changes & BSS_CHANGED_ASSOC) {
  686. if (bss_conf->assoc) {
  687. /* add quota for this interface */
  688. ret = iwl_mvm_update_quotas(mvm, vif);
  689. if (ret) {
  690. IWL_ERR(mvm, "failed to update quotas\n");
  691. return;
  692. }
  693. iwl_mvm_configure_mcast_filter(mvm, vif);
  694. if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
  695. &mvm->status)) {
  696. /*
  697. * If we're restarting then the firmware will
  698. * obviously have lost synchronisation with
  699. * the AP. It will attempt to synchronise by
  700. * itself, but we can make it more reliable by
  701. * scheduling a session protection time event.
  702. *
  703. * The firmware needs to receive a beacon to
  704. * catch up with synchronisation, use 110% of
  705. * the beacon interval.
  706. *
  707. * Set a large maximum delay to allow for more
  708. * than a single interface.
  709. */
  710. u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
  711. iwl_mvm_protect_session(mvm, vif, dur, dur,
  712. 5 * dur);
  713. }
  714. } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
  715. /* remove AP station now that the MAC is unassoc */
  716. ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
  717. if (ret)
  718. IWL_ERR(mvm, "failed to remove AP station\n");
  719. mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
  720. /* remove quota for this interface */
  721. ret = iwl_mvm_update_quotas(mvm, NULL);
  722. if (ret)
  723. IWL_ERR(mvm, "failed to update quotas\n");
  724. }
  725. /* reset rssi values */
  726. mvmvif->bf_data.ave_beacon_signal = 0;
  727. if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD)) {
  728. /* Workaround for FW bug, otherwise FW disables device
  729. * power save upon disassociation
  730. */
  731. ret = iwl_mvm_power_update_mode(mvm, vif);
  732. if (ret)
  733. IWL_ERR(mvm, "failed to update power mode\n");
  734. }
  735. iwl_mvm_bt_coex_vif_change(mvm, vif);
  736. } else if (changes & BSS_CHANGED_BEACON_INFO) {
  737. /*
  738. * We received a beacon _after_ association so
  739. * remove the session protection.
  740. */
  741. iwl_mvm_remove_time_event(mvm, mvmvif,
  742. &mvmvif->time_event_data);
  743. } else if (changes & (BSS_CHANGED_PS | BSS_CHANGED_QOS)) {
  744. ret = iwl_mvm_power_update_mode(mvm, vif);
  745. if (ret)
  746. IWL_ERR(mvm, "failed to update power mode\n");
  747. }
  748. if (changes & BSS_CHANGED_TXPOWER) {
  749. IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
  750. bss_conf->txpower);
  751. iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
  752. }
  753. if (changes & BSS_CHANGED_CQM) {
  754. IWL_DEBUG_MAC80211(mvm, "cqm info_changed");
  755. /* reset cqm events tracking */
  756. mvmvif->bf_data.last_cqm_event = 0;
  757. ret = iwl_mvm_update_beacon_filter(mvm, vif);
  758. if (ret)
  759. IWL_ERR(mvm, "failed to update CQM thresholds\n");
  760. }
  761. }
  762. static int iwl_mvm_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  763. {
  764. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  765. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  766. int ret;
  767. mutex_lock(&mvm->mutex);
  768. /* Send the beacon template */
  769. ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
  770. if (ret)
  771. goto out_unlock;
  772. /* Add the mac context */
  773. ret = iwl_mvm_mac_ctxt_add(mvm, vif);
  774. if (ret)
  775. goto out_unlock;
  776. /* Perform the binding */
  777. ret = iwl_mvm_binding_add_vif(mvm, vif);
  778. if (ret)
  779. goto out_remove;
  780. mvmvif->ap_active = true;
  781. /* Send the bcast station. At this stage the TBTT and DTIM time events
  782. * are added and applied to the scheduler */
  783. ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
  784. if (ret)
  785. goto out_unbind;
  786. ret = iwl_mvm_update_quotas(mvm, vif);
  787. if (ret)
  788. goto out_rm_bcast;
  789. /* Need to update the P2P Device MAC */
  790. if (vif->p2p && mvm->p2p_device_vif)
  791. iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
  792. iwl_mvm_bt_coex_vif_change(mvm, vif);
  793. mutex_unlock(&mvm->mutex);
  794. return 0;
  795. out_rm_bcast:
  796. iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
  797. out_unbind:
  798. iwl_mvm_binding_remove_vif(mvm, vif);
  799. out_remove:
  800. iwl_mvm_mac_ctxt_remove(mvm, vif);
  801. out_unlock:
  802. mutex_unlock(&mvm->mutex);
  803. return ret;
  804. }
  805. static void iwl_mvm_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  806. {
  807. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  808. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  809. iwl_mvm_prepare_mac_removal(mvm, vif);
  810. mutex_lock(&mvm->mutex);
  811. mvmvif->ap_active = false;
  812. iwl_mvm_bt_coex_vif_change(mvm, vif);
  813. /* Need to update the P2P Device MAC */
  814. if (vif->p2p && mvm->p2p_device_vif)
  815. iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
  816. iwl_mvm_update_quotas(mvm, NULL);
  817. iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
  818. iwl_mvm_binding_remove_vif(mvm, vif);
  819. iwl_mvm_mac_ctxt_remove(mvm, vif);
  820. mutex_unlock(&mvm->mutex);
  821. }
  822. static void iwl_mvm_bss_info_changed_ap(struct iwl_mvm *mvm,
  823. struct ieee80211_vif *vif,
  824. struct ieee80211_bss_conf *bss_conf,
  825. u32 changes)
  826. {
  827. /* Need to send a new beacon template to the FW */
  828. if (changes & BSS_CHANGED_BEACON) {
  829. if (iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
  830. IWL_WARN(mvm, "Failed updating beacon data\n");
  831. }
  832. }
  833. static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
  834. struct ieee80211_vif *vif,
  835. struct ieee80211_bss_conf *bss_conf,
  836. u32 changes)
  837. {
  838. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  839. mutex_lock(&mvm->mutex);
  840. switch (vif->type) {
  841. case NL80211_IFTYPE_STATION:
  842. iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
  843. break;
  844. case NL80211_IFTYPE_AP:
  845. iwl_mvm_bss_info_changed_ap(mvm, vif, bss_conf, changes);
  846. break;
  847. default:
  848. /* shouldn't happen */
  849. WARN_ON_ONCE(1);
  850. }
  851. mutex_unlock(&mvm->mutex);
  852. }
  853. static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
  854. struct ieee80211_vif *vif,
  855. struct cfg80211_scan_request *req)
  856. {
  857. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  858. int ret;
  859. if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS)
  860. return -EINVAL;
  861. mutex_lock(&mvm->mutex);
  862. if (mvm->scan_status == IWL_MVM_SCAN_NONE)
  863. ret = iwl_mvm_scan_request(mvm, vif, req);
  864. else
  865. ret = -EBUSY;
  866. mutex_unlock(&mvm->mutex);
  867. return ret;
  868. }
  869. static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
  870. struct ieee80211_vif *vif)
  871. {
  872. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  873. mutex_lock(&mvm->mutex);
  874. iwl_mvm_cancel_scan(mvm);
  875. mutex_unlock(&mvm->mutex);
  876. }
  877. static void
  878. iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
  879. struct ieee80211_sta *sta, u16 tid,
  880. int num_frames,
  881. enum ieee80211_frame_release_type reason,
  882. bool more_data)
  883. {
  884. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  885. /* TODO: how do we tell the fw to send frames for a specific TID */
  886. /*
  887. * The fw will send EOSP notification when the last frame will be
  888. * transmitted.
  889. */
  890. iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames);
  891. }
  892. static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
  893. struct ieee80211_vif *vif,
  894. enum sta_notify_cmd cmd,
  895. struct ieee80211_sta *sta)
  896. {
  897. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  898. struct iwl_mvm_sta *mvmsta = (void *)sta->drv_priv;
  899. switch (cmd) {
  900. case STA_NOTIFY_SLEEP:
  901. if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
  902. ieee80211_sta_block_awake(hw, sta, true);
  903. /*
  904. * The fw updates the STA to be asleep. Tx packets on the Tx
  905. * queues to this station will not be transmitted. The fw will
  906. * send a Tx response with TX_STATUS_FAIL_DEST_PS.
  907. */
  908. break;
  909. case STA_NOTIFY_AWAKE:
  910. if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
  911. break;
  912. iwl_mvm_sta_modify_ps_wake(mvm, sta);
  913. break;
  914. default:
  915. break;
  916. }
  917. }
  918. static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
  919. struct ieee80211_vif *vif,
  920. struct ieee80211_sta *sta,
  921. enum ieee80211_sta_state old_state,
  922. enum ieee80211_sta_state new_state)
  923. {
  924. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  925. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  926. int ret;
  927. IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
  928. sta->addr, old_state, new_state);
  929. /* this would be a mac80211 bug ... but don't crash */
  930. if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
  931. return -EINVAL;
  932. /* if a STA is being removed, reuse its ID */
  933. flush_work(&mvm->sta_drained_wk);
  934. mutex_lock(&mvm->mutex);
  935. if (old_state == IEEE80211_STA_NOTEXIST &&
  936. new_state == IEEE80211_STA_NONE) {
  937. /*
  938. * Firmware bug - it'll crash if the beacon interval is less
  939. * than 16. We can't avoid connecting at all, so refuse the
  940. * station state change, this will cause mac80211 to abandon
  941. * attempts to connect to this AP, and eventually wpa_s will
  942. * blacklist the AP...
  943. */
  944. if (vif->type == NL80211_IFTYPE_STATION &&
  945. vif->bss_conf.beacon_int < 16) {
  946. IWL_ERR(mvm,
  947. "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
  948. sta->addr, vif->bss_conf.beacon_int);
  949. ret = -EINVAL;
  950. goto out_unlock;
  951. }
  952. ret = iwl_mvm_add_sta(mvm, vif, sta);
  953. } else if (old_state == IEEE80211_STA_NONE &&
  954. new_state == IEEE80211_STA_AUTH) {
  955. ret = 0;
  956. } else if (old_state == IEEE80211_STA_AUTH &&
  957. new_state == IEEE80211_STA_ASSOC) {
  958. ret = iwl_mvm_update_sta(mvm, vif, sta);
  959. if (ret == 0)
  960. iwl_mvm_rs_rate_init(mvm, sta,
  961. mvmvif->phy_ctxt->channel->band);
  962. } else if (old_state == IEEE80211_STA_ASSOC &&
  963. new_state == IEEE80211_STA_AUTHORIZED) {
  964. /* enable beacon filtering */
  965. WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif));
  966. ret = 0;
  967. } else if (old_state == IEEE80211_STA_AUTHORIZED &&
  968. new_state == IEEE80211_STA_ASSOC) {
  969. /* disable beacon filtering */
  970. WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif));
  971. ret = 0;
  972. } else if (old_state == IEEE80211_STA_ASSOC &&
  973. new_state == IEEE80211_STA_AUTH) {
  974. ret = 0;
  975. } else if (old_state == IEEE80211_STA_AUTH &&
  976. new_state == IEEE80211_STA_NONE) {
  977. ret = 0;
  978. } else if (old_state == IEEE80211_STA_NONE &&
  979. new_state == IEEE80211_STA_NOTEXIST) {
  980. ret = iwl_mvm_rm_sta(mvm, vif, sta);
  981. } else {
  982. ret = -EIO;
  983. }
  984. out_unlock:
  985. mutex_unlock(&mvm->mutex);
  986. return ret;
  987. }
  988. static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  989. {
  990. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  991. mvm->rts_threshold = value;
  992. return 0;
  993. }
  994. static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
  995. struct ieee80211_vif *vif, u16 ac,
  996. const struct ieee80211_tx_queue_params *params)
  997. {
  998. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  999. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1000. mvmvif->queue_params[ac] = *params;
  1001. /*
  1002. * No need to update right away, we'll get BSS_CHANGED_QOS
  1003. * The exception is P2P_DEVICE interface which needs immediate update.
  1004. */
  1005. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  1006. int ret;
  1007. mutex_lock(&mvm->mutex);
  1008. ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
  1009. mutex_unlock(&mvm->mutex);
  1010. return ret;
  1011. }
  1012. return 0;
  1013. }
  1014. static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
  1015. struct ieee80211_vif *vif)
  1016. {
  1017. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1018. u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
  1019. 200 + vif->bss_conf.beacon_int);
  1020. u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
  1021. 100 + vif->bss_conf.beacon_int);
  1022. if (WARN_ON_ONCE(vif->bss_conf.assoc))
  1023. return;
  1024. mutex_lock(&mvm->mutex);
  1025. /* Try really hard to protect the session and hear a beacon */
  1026. iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500);
  1027. mutex_unlock(&mvm->mutex);
  1028. }
  1029. static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
  1030. struct ieee80211_vif *vif,
  1031. struct cfg80211_sched_scan_request *req,
  1032. struct ieee80211_sched_scan_ies *ies)
  1033. {
  1034. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1035. int ret;
  1036. mutex_lock(&mvm->mutex);
  1037. if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
  1038. IWL_DEBUG_SCAN(mvm,
  1039. "SCHED SCAN request during internal scan - abort\n");
  1040. ret = -EBUSY;
  1041. goto out;
  1042. }
  1043. mvm->scan_status = IWL_MVM_SCAN_SCHED;
  1044. ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies);
  1045. if (ret)
  1046. goto err;
  1047. ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
  1048. if (ret)
  1049. goto err;
  1050. ret = iwl_mvm_sched_scan_start(mvm, req);
  1051. if (!ret)
  1052. goto out;
  1053. err:
  1054. mvm->scan_status = IWL_MVM_SCAN_NONE;
  1055. out:
  1056. mutex_unlock(&mvm->mutex);
  1057. return ret;
  1058. }
  1059. static void iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
  1060. struct ieee80211_vif *vif)
  1061. {
  1062. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1063. mutex_lock(&mvm->mutex);
  1064. iwl_mvm_sched_scan_stop(mvm);
  1065. mutex_unlock(&mvm->mutex);
  1066. }
  1067. static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
  1068. enum set_key_cmd cmd,
  1069. struct ieee80211_vif *vif,
  1070. struct ieee80211_sta *sta,
  1071. struct ieee80211_key_conf *key)
  1072. {
  1073. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1074. int ret;
  1075. if (iwlwifi_mod_params.sw_crypto) {
  1076. IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
  1077. return -EOPNOTSUPP;
  1078. }
  1079. switch (key->cipher) {
  1080. case WLAN_CIPHER_SUITE_TKIP:
  1081. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  1082. /* fall-through */
  1083. case WLAN_CIPHER_SUITE_CCMP:
  1084. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  1085. break;
  1086. case WLAN_CIPHER_SUITE_AES_CMAC:
  1087. WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
  1088. break;
  1089. case WLAN_CIPHER_SUITE_WEP40:
  1090. case WLAN_CIPHER_SUITE_WEP104:
  1091. /*
  1092. * Support for TX only, at least for now, so accept
  1093. * the key and do nothing else. Then mac80211 will
  1094. * pass it for TX but we don't have to use it for RX.
  1095. */
  1096. return 0;
  1097. default:
  1098. return -EOPNOTSUPP;
  1099. }
  1100. mutex_lock(&mvm->mutex);
  1101. switch (cmd) {
  1102. case SET_KEY:
  1103. if (vif->type == NL80211_IFTYPE_AP && !sta) {
  1104. /* GTK on AP interface is a TX-only key, return 0 */
  1105. ret = 0;
  1106. key->hw_key_idx = STA_KEY_IDX_INVALID;
  1107. break;
  1108. }
  1109. IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
  1110. ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
  1111. if (ret) {
  1112. IWL_WARN(mvm, "set key failed\n");
  1113. /*
  1114. * can't add key for RX, but we don't need it
  1115. * in the device for TX so still return 0
  1116. */
  1117. key->hw_key_idx = STA_KEY_IDX_INVALID;
  1118. ret = 0;
  1119. }
  1120. break;
  1121. case DISABLE_KEY:
  1122. if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
  1123. ret = 0;
  1124. break;
  1125. }
  1126. IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
  1127. ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
  1128. break;
  1129. default:
  1130. ret = -EINVAL;
  1131. }
  1132. mutex_unlock(&mvm->mutex);
  1133. return ret;
  1134. }
  1135. static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
  1136. struct ieee80211_vif *vif,
  1137. struct ieee80211_key_conf *keyconf,
  1138. struct ieee80211_sta *sta,
  1139. u32 iv32, u16 *phase1key)
  1140. {
  1141. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1142. iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
  1143. }
  1144. static int iwl_mvm_roc(struct ieee80211_hw *hw,
  1145. struct ieee80211_vif *vif,
  1146. struct ieee80211_channel *channel,
  1147. int duration,
  1148. enum ieee80211_roc_type type)
  1149. {
  1150. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1151. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1152. struct cfg80211_chan_def chandef;
  1153. struct iwl_mvm_phy_ctxt *phy_ctxt;
  1154. int ret, i;
  1155. IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
  1156. duration, type);
  1157. if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
  1158. IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
  1159. return -EINVAL;
  1160. }
  1161. mutex_lock(&mvm->mutex);
  1162. for (i = 0; i < NUM_PHY_CTX; i++) {
  1163. phy_ctxt = &mvm->phy_ctxts[i];
  1164. if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
  1165. continue;
  1166. if (phy_ctxt->ref && channel == phy_ctxt->channel) {
  1167. /*
  1168. * Unbind the P2P_DEVICE from the current PHY context,
  1169. * and if the PHY context is not used remove it.
  1170. */
  1171. ret = iwl_mvm_binding_remove_vif(mvm, vif);
  1172. if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
  1173. goto out_unlock;
  1174. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  1175. /* Bind the P2P_DEVICE to the current PHY Context */
  1176. mvmvif->phy_ctxt = phy_ctxt;
  1177. ret = iwl_mvm_binding_add_vif(mvm, vif);
  1178. if (WARN(ret, "Failed binding P2P_DEVICE\n"))
  1179. goto out_unlock;
  1180. iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
  1181. goto schedule_time_event;
  1182. }
  1183. }
  1184. /* Need to update the PHY context only if the ROC channel changed */
  1185. if (channel == mvmvif->phy_ctxt->channel)
  1186. goto schedule_time_event;
  1187. cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
  1188. /*
  1189. * Change the PHY context configuration as it is currently referenced
  1190. * only by the P2P Device MAC
  1191. */
  1192. if (mvmvif->phy_ctxt->ref == 1) {
  1193. ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
  1194. &chandef, 1, 1);
  1195. if (ret)
  1196. goto out_unlock;
  1197. } else {
  1198. /*
  1199. * The PHY context is shared with other MACs. Need to remove the
  1200. * P2P Device from the binding, allocate an new PHY context and
  1201. * create a new binding
  1202. */
  1203. phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
  1204. if (!phy_ctxt) {
  1205. ret = -ENOSPC;
  1206. goto out_unlock;
  1207. }
  1208. ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
  1209. 1, 1);
  1210. if (ret) {
  1211. IWL_ERR(mvm, "Failed to change PHY context\n");
  1212. goto out_unlock;
  1213. }
  1214. /* Unbind the P2P_DEVICE from the current PHY context */
  1215. ret = iwl_mvm_binding_remove_vif(mvm, vif);
  1216. if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
  1217. goto out_unlock;
  1218. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  1219. /* Bind the P2P_DEVICE to the new allocated PHY context */
  1220. mvmvif->phy_ctxt = phy_ctxt;
  1221. ret = iwl_mvm_binding_add_vif(mvm, vif);
  1222. if (WARN(ret, "Failed binding P2P_DEVICE\n"))
  1223. goto out_unlock;
  1224. iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
  1225. }
  1226. schedule_time_event:
  1227. /* Schedule the time events */
  1228. ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
  1229. out_unlock:
  1230. mutex_unlock(&mvm->mutex);
  1231. IWL_DEBUG_MAC80211(mvm, "leave\n");
  1232. return ret;
  1233. }
  1234. static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
  1235. {
  1236. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1237. IWL_DEBUG_MAC80211(mvm, "enter\n");
  1238. mutex_lock(&mvm->mutex);
  1239. iwl_mvm_stop_p2p_roc(mvm);
  1240. mutex_unlock(&mvm->mutex);
  1241. IWL_DEBUG_MAC80211(mvm, "leave\n");
  1242. return 0;
  1243. }
  1244. static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
  1245. struct ieee80211_chanctx_conf *ctx)
  1246. {
  1247. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1248. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  1249. struct iwl_mvm_phy_ctxt *phy_ctxt;
  1250. int ret;
  1251. IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
  1252. mutex_lock(&mvm->mutex);
  1253. phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
  1254. if (!phy_ctxt) {
  1255. ret = -ENOSPC;
  1256. goto out;
  1257. }
  1258. ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
  1259. ctx->rx_chains_static,
  1260. ctx->rx_chains_dynamic);
  1261. if (ret) {
  1262. IWL_ERR(mvm, "Failed to add PHY context\n");
  1263. goto out;
  1264. }
  1265. iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
  1266. *phy_ctxt_id = phy_ctxt->id;
  1267. out:
  1268. mutex_unlock(&mvm->mutex);
  1269. return ret;
  1270. }
  1271. static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
  1272. struct ieee80211_chanctx_conf *ctx)
  1273. {
  1274. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1275. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  1276. struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
  1277. mutex_lock(&mvm->mutex);
  1278. iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
  1279. mutex_unlock(&mvm->mutex);
  1280. }
  1281. static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
  1282. struct ieee80211_chanctx_conf *ctx,
  1283. u32 changed)
  1284. {
  1285. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1286. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  1287. struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
  1288. if (WARN_ONCE((phy_ctxt->ref > 1) &&
  1289. (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
  1290. IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
  1291. IEEE80211_CHANCTX_CHANGE_RADAR)),
  1292. "Cannot change PHY. Ref=%d, changed=0x%X\n",
  1293. phy_ctxt->ref, changed))
  1294. return;
  1295. mutex_lock(&mvm->mutex);
  1296. iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
  1297. ctx->rx_chains_static,
  1298. ctx->rx_chains_dynamic);
  1299. mutex_unlock(&mvm->mutex);
  1300. }
  1301. static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
  1302. struct ieee80211_vif *vif,
  1303. struct ieee80211_chanctx_conf *ctx)
  1304. {
  1305. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1306. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  1307. struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
  1308. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1309. int ret;
  1310. mutex_lock(&mvm->mutex);
  1311. mvmvif->phy_ctxt = phy_ctxt;
  1312. switch (vif->type) {
  1313. case NL80211_IFTYPE_AP:
  1314. /*
  1315. * The AP binding flow is handled as part of the start_ap flow
  1316. * (in bss_info_changed).
  1317. */
  1318. ret = 0;
  1319. goto out_unlock;
  1320. case NL80211_IFTYPE_STATION:
  1321. case NL80211_IFTYPE_ADHOC:
  1322. case NL80211_IFTYPE_MONITOR:
  1323. break;
  1324. default:
  1325. ret = -EINVAL;
  1326. goto out_unlock;
  1327. }
  1328. ret = iwl_mvm_binding_add_vif(mvm, vif);
  1329. if (ret)
  1330. goto out_unlock;
  1331. /*
  1332. * Setting the quota at this stage is only required for monitor
  1333. * interfaces. For the other types, the bss_info changed flow
  1334. * will handle quota settings.
  1335. */
  1336. if (vif->type == NL80211_IFTYPE_MONITOR) {
  1337. mvmvif->monitor_active = true;
  1338. ret = iwl_mvm_update_quotas(mvm, vif);
  1339. if (ret)
  1340. goto out_remove_binding;
  1341. }
  1342. goto out_unlock;
  1343. out_remove_binding:
  1344. iwl_mvm_binding_remove_vif(mvm, vif);
  1345. out_unlock:
  1346. mutex_unlock(&mvm->mutex);
  1347. if (ret)
  1348. mvmvif->phy_ctxt = NULL;
  1349. return ret;
  1350. }
  1351. static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
  1352. struct ieee80211_vif *vif,
  1353. struct ieee80211_chanctx_conf *ctx)
  1354. {
  1355. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1356. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1357. mutex_lock(&mvm->mutex);
  1358. iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
  1359. if (vif->type == NL80211_IFTYPE_AP)
  1360. goto out_unlock;
  1361. switch (vif->type) {
  1362. case NL80211_IFTYPE_MONITOR:
  1363. mvmvif->monitor_active = false;
  1364. iwl_mvm_update_quotas(mvm, NULL);
  1365. break;
  1366. default:
  1367. break;
  1368. }
  1369. iwl_mvm_binding_remove_vif(mvm, vif);
  1370. out_unlock:
  1371. mvmvif->phy_ctxt = NULL;
  1372. mutex_unlock(&mvm->mutex);
  1373. }
  1374. static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
  1375. struct ieee80211_sta *sta,
  1376. bool set)
  1377. {
  1378. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1379. struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
  1380. if (!mvm_sta || !mvm_sta->vif) {
  1381. IWL_ERR(mvm, "Station is not associated to a vif\n");
  1382. return -EINVAL;
  1383. }
  1384. return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
  1385. }
  1386. #ifdef CONFIG_NL80211_TESTMODE
  1387. static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
  1388. [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
  1389. [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
  1390. [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
  1391. };
  1392. static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
  1393. struct ieee80211_vif *vif,
  1394. void *data, int len)
  1395. {
  1396. struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
  1397. int err;
  1398. u32 noa_duration;
  1399. err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
  1400. if (err)
  1401. return err;
  1402. if (!tb[IWL_MVM_TM_ATTR_CMD])
  1403. return -EINVAL;
  1404. switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
  1405. case IWL_MVM_TM_CMD_SET_NOA:
  1406. if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
  1407. !vif->bss_conf.enable_beacon ||
  1408. !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
  1409. return -EINVAL;
  1410. noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
  1411. if (noa_duration >= vif->bss_conf.beacon_int)
  1412. return -EINVAL;
  1413. mvm->noa_duration = noa_duration;
  1414. mvm->noa_vif = vif;
  1415. return iwl_mvm_update_quotas(mvm, NULL);
  1416. case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
  1417. /* must be associated client vif - ignore authorized */
  1418. if (!vif || vif->type != NL80211_IFTYPE_STATION ||
  1419. !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
  1420. !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
  1421. return -EINVAL;
  1422. if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
  1423. return iwl_mvm_enable_beacon_filter(mvm, vif);
  1424. return iwl_mvm_disable_beacon_filter(mvm, vif);
  1425. }
  1426. return -EOPNOTSUPP;
  1427. }
  1428. static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
  1429. struct ieee80211_vif *vif,
  1430. void *data, int len)
  1431. {
  1432. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1433. int err;
  1434. mutex_lock(&mvm->mutex);
  1435. err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
  1436. mutex_unlock(&mvm->mutex);
  1437. return err;
  1438. }
  1439. #endif
  1440. struct ieee80211_ops iwl_mvm_hw_ops = {
  1441. .tx = iwl_mvm_mac_tx,
  1442. .ampdu_action = iwl_mvm_mac_ampdu_action,
  1443. .start = iwl_mvm_mac_start,
  1444. .restart_complete = iwl_mvm_mac_restart_complete,
  1445. .stop = iwl_mvm_mac_stop,
  1446. .add_interface = iwl_mvm_mac_add_interface,
  1447. .remove_interface = iwl_mvm_mac_remove_interface,
  1448. .config = iwl_mvm_mac_config,
  1449. .configure_filter = iwl_mvm_configure_filter,
  1450. .bss_info_changed = iwl_mvm_bss_info_changed,
  1451. .hw_scan = iwl_mvm_mac_hw_scan,
  1452. .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
  1453. .sta_state = iwl_mvm_mac_sta_state,
  1454. .sta_notify = iwl_mvm_mac_sta_notify,
  1455. .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
  1456. .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
  1457. .conf_tx = iwl_mvm_mac_conf_tx,
  1458. .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
  1459. .sched_scan_start = iwl_mvm_mac_sched_scan_start,
  1460. .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
  1461. .set_key = iwl_mvm_mac_set_key,
  1462. .update_tkip_key = iwl_mvm_mac_update_tkip_key,
  1463. .remain_on_channel = iwl_mvm_roc,
  1464. .cancel_remain_on_channel = iwl_mvm_cancel_roc,
  1465. .add_chanctx = iwl_mvm_add_chanctx,
  1466. .remove_chanctx = iwl_mvm_remove_chanctx,
  1467. .change_chanctx = iwl_mvm_change_chanctx,
  1468. .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
  1469. .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
  1470. .start_ap = iwl_mvm_start_ap,
  1471. .stop_ap = iwl_mvm_stop_ap,
  1472. .set_tim = iwl_mvm_set_tim,
  1473. CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
  1474. #ifdef CONFIG_PM_SLEEP
  1475. /* look at d3.c */
  1476. .suspend = iwl_mvm_suspend,
  1477. .resume = iwl_mvm_resume,
  1478. .set_wakeup = iwl_mvm_set_wakeup,
  1479. .set_rekey_data = iwl_mvm_set_rekey_data,
  1480. #if IS_ENABLED(CONFIG_IPV6)
  1481. .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
  1482. #endif
  1483. .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
  1484. #endif
  1485. };