mac80211.c 48 KB

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