mac80211.c 39 KB

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