mac80211.c 50 KB

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