mac80211.c 49 KB

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