mac80211.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802
  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. } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
  723. /* remove AP station now that the MAC is unassoc */
  724. ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
  725. if (ret)
  726. IWL_ERR(mvm, "failed to remove AP station\n");
  727. mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
  728. /* remove quota for this interface */
  729. ret = iwl_mvm_update_quotas(mvm, NULL);
  730. if (ret)
  731. IWL_ERR(mvm, "failed to update quotas\n");
  732. }
  733. /* reset rssi values */
  734. mvmvif->bf_data.ave_beacon_signal = 0;
  735. if (!(mvm->fw->ucode_capa.flags &
  736. IWL_UCODE_TLV_FLAGS_PM_CMD_SUPPORT)) {
  737. /* Workaround for FW bug, otherwise FW disables device
  738. * power save upon disassociation
  739. */
  740. ret = iwl_mvm_power_update_mode(mvm, vif);
  741. if (ret)
  742. IWL_ERR(mvm, "failed to update power mode\n");
  743. }
  744. iwl_mvm_bt_coex_vif_change(mvm);
  745. } else if (changes & BSS_CHANGED_BEACON_INFO) {
  746. /*
  747. * We received a beacon _after_ association so
  748. * remove the session protection.
  749. */
  750. iwl_mvm_remove_time_event(mvm, mvmvif,
  751. &mvmvif->time_event_data);
  752. } else if (changes & (BSS_CHANGED_PS | BSS_CHANGED_QOS)) {
  753. ret = iwl_mvm_power_update_mode(mvm, vif);
  754. if (ret)
  755. IWL_ERR(mvm, "failed to update power mode\n");
  756. }
  757. if (changes & BSS_CHANGED_TXPOWER) {
  758. IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
  759. bss_conf->txpower);
  760. iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
  761. }
  762. if (changes & BSS_CHANGED_CQM) {
  763. IWL_DEBUG_MAC80211(mvm, "cqm info_changed");
  764. /* reset cqm events tracking */
  765. mvmvif->bf_data.last_cqm_event = 0;
  766. ret = iwl_mvm_update_beacon_filter(mvm, vif);
  767. if (ret)
  768. IWL_ERR(mvm, "failed to update CQM thresholds\n");
  769. }
  770. }
  771. static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
  772. struct ieee80211_vif *vif)
  773. {
  774. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  775. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  776. int ret;
  777. mutex_lock(&mvm->mutex);
  778. /* Send the beacon template */
  779. ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
  780. if (ret)
  781. goto out_unlock;
  782. /* Add the mac context */
  783. ret = iwl_mvm_mac_ctxt_add(mvm, vif);
  784. if (ret)
  785. goto out_unlock;
  786. /* Perform the binding */
  787. ret = iwl_mvm_binding_add_vif(mvm, vif);
  788. if (ret)
  789. goto out_remove;
  790. mvmvif->ap_ibss_active = true;
  791. /* Send the bcast station. At this stage the TBTT and DTIM time events
  792. * are added and applied to the scheduler */
  793. ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
  794. if (ret)
  795. goto out_unbind;
  796. ret = iwl_mvm_update_quotas(mvm, vif);
  797. if (ret)
  798. goto out_rm_bcast;
  799. /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
  800. if (vif->p2p && mvm->p2p_device_vif)
  801. iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
  802. iwl_mvm_bt_coex_vif_change(mvm);
  803. mutex_unlock(&mvm->mutex);
  804. return 0;
  805. out_rm_bcast:
  806. iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
  807. out_unbind:
  808. iwl_mvm_binding_remove_vif(mvm, vif);
  809. out_remove:
  810. iwl_mvm_mac_ctxt_remove(mvm, vif);
  811. out_unlock:
  812. mutex_unlock(&mvm->mutex);
  813. return ret;
  814. }
  815. static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
  816. struct ieee80211_vif *vif)
  817. {
  818. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  819. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  820. iwl_mvm_prepare_mac_removal(mvm, vif);
  821. mutex_lock(&mvm->mutex);
  822. mvmvif->ap_ibss_active = false;
  823. iwl_mvm_bt_coex_vif_change(mvm);
  824. /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
  825. if (vif->p2p && mvm->p2p_device_vif)
  826. iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
  827. iwl_mvm_update_quotas(mvm, NULL);
  828. iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
  829. iwl_mvm_binding_remove_vif(mvm, vif);
  830. iwl_mvm_mac_ctxt_remove(mvm, vif);
  831. mutex_unlock(&mvm->mutex);
  832. }
  833. static void
  834. iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
  835. struct ieee80211_vif *vif,
  836. struct ieee80211_bss_conf *bss_conf,
  837. u32 changes)
  838. {
  839. enum ieee80211_bss_change ht_change = BSS_CHANGED_ERP_CTS_PROT |
  840. BSS_CHANGED_HT |
  841. BSS_CHANGED_BANDWIDTH;
  842. int ret;
  843. if (changes & ht_change) {
  844. ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
  845. if (ret)
  846. IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
  847. }
  848. /* Need to send a new beacon template to the FW */
  849. if (changes & BSS_CHANGED_BEACON) {
  850. if (iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
  851. IWL_WARN(mvm, "Failed updating beacon data\n");
  852. }
  853. }
  854. static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
  855. struct ieee80211_vif *vif,
  856. struct ieee80211_bss_conf *bss_conf,
  857. u32 changes)
  858. {
  859. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  860. mutex_lock(&mvm->mutex);
  861. switch (vif->type) {
  862. case NL80211_IFTYPE_STATION:
  863. iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
  864. break;
  865. case NL80211_IFTYPE_AP:
  866. case NL80211_IFTYPE_ADHOC:
  867. iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
  868. break;
  869. default:
  870. /* shouldn't happen */
  871. WARN_ON_ONCE(1);
  872. }
  873. mutex_unlock(&mvm->mutex);
  874. }
  875. static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
  876. struct ieee80211_vif *vif,
  877. struct cfg80211_scan_request *req)
  878. {
  879. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  880. int ret;
  881. if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS)
  882. return -EINVAL;
  883. mutex_lock(&mvm->mutex);
  884. if (mvm->scan_status == IWL_MVM_SCAN_NONE)
  885. ret = iwl_mvm_scan_request(mvm, vif, req);
  886. else
  887. ret = -EBUSY;
  888. mutex_unlock(&mvm->mutex);
  889. return ret;
  890. }
  891. static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
  892. struct ieee80211_vif *vif)
  893. {
  894. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  895. mutex_lock(&mvm->mutex);
  896. iwl_mvm_cancel_scan(mvm);
  897. mutex_unlock(&mvm->mutex);
  898. }
  899. static void
  900. iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
  901. struct ieee80211_sta *sta, u16 tid,
  902. int num_frames,
  903. enum ieee80211_frame_release_type reason,
  904. bool more_data)
  905. {
  906. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  907. /* TODO: how do we tell the fw to send frames for a specific TID */
  908. /*
  909. * The fw will send EOSP notification when the last frame will be
  910. * transmitted.
  911. */
  912. iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames);
  913. }
  914. static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
  915. struct ieee80211_vif *vif,
  916. enum sta_notify_cmd cmd,
  917. struct ieee80211_sta *sta)
  918. {
  919. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  920. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  921. switch (cmd) {
  922. case STA_NOTIFY_SLEEP:
  923. if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
  924. ieee80211_sta_block_awake(hw, sta, true);
  925. /*
  926. * The fw updates the STA to be asleep. Tx packets on the Tx
  927. * queues to this station will not be transmitted. The fw will
  928. * send a Tx response with TX_STATUS_FAIL_DEST_PS.
  929. */
  930. break;
  931. case STA_NOTIFY_AWAKE:
  932. if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
  933. break;
  934. iwl_mvm_sta_modify_ps_wake(mvm, sta);
  935. break;
  936. default:
  937. break;
  938. }
  939. }
  940. static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
  941. struct ieee80211_vif *vif,
  942. struct ieee80211_sta *sta,
  943. enum ieee80211_sta_state old_state,
  944. enum ieee80211_sta_state new_state)
  945. {
  946. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  947. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  948. int ret;
  949. IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
  950. sta->addr, old_state, new_state);
  951. /* this would be a mac80211 bug ... but don't crash */
  952. if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
  953. return -EINVAL;
  954. /* if a STA is being removed, reuse its ID */
  955. flush_work(&mvm->sta_drained_wk);
  956. mutex_lock(&mvm->mutex);
  957. if (old_state == IEEE80211_STA_NOTEXIST &&
  958. new_state == IEEE80211_STA_NONE) {
  959. /*
  960. * Firmware bug - it'll crash if the beacon interval is less
  961. * than 16. We can't avoid connecting at all, so refuse the
  962. * station state change, this will cause mac80211 to abandon
  963. * attempts to connect to this AP, and eventually wpa_s will
  964. * blacklist the AP...
  965. */
  966. if (vif->type == NL80211_IFTYPE_STATION &&
  967. vif->bss_conf.beacon_int < 16) {
  968. IWL_ERR(mvm,
  969. "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
  970. sta->addr, vif->bss_conf.beacon_int);
  971. ret = -EINVAL;
  972. goto out_unlock;
  973. }
  974. ret = iwl_mvm_add_sta(mvm, vif, sta);
  975. } else if (old_state == IEEE80211_STA_NONE &&
  976. new_state == IEEE80211_STA_AUTH) {
  977. ret = 0;
  978. } else if (old_state == IEEE80211_STA_AUTH &&
  979. new_state == IEEE80211_STA_ASSOC) {
  980. ret = iwl_mvm_update_sta(mvm, vif, sta);
  981. if (ret == 0)
  982. iwl_mvm_rs_rate_init(mvm, sta,
  983. mvmvif->phy_ctxt->channel->band,
  984. true);
  985. } else if (old_state == IEEE80211_STA_ASSOC &&
  986. new_state == IEEE80211_STA_AUTHORIZED) {
  987. /* enable beacon filtering */
  988. WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif));
  989. ret = 0;
  990. } else if (old_state == IEEE80211_STA_AUTHORIZED &&
  991. new_state == IEEE80211_STA_ASSOC) {
  992. /* disable beacon filtering */
  993. WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif));
  994. ret = 0;
  995. } else if (old_state == IEEE80211_STA_ASSOC &&
  996. new_state == IEEE80211_STA_AUTH) {
  997. ret = 0;
  998. } else if (old_state == IEEE80211_STA_AUTH &&
  999. new_state == IEEE80211_STA_NONE) {
  1000. ret = 0;
  1001. } else if (old_state == IEEE80211_STA_NONE &&
  1002. new_state == IEEE80211_STA_NOTEXIST) {
  1003. ret = iwl_mvm_rm_sta(mvm, vif, sta);
  1004. } else {
  1005. ret = -EIO;
  1006. }
  1007. out_unlock:
  1008. mutex_unlock(&mvm->mutex);
  1009. return ret;
  1010. }
  1011. static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  1012. {
  1013. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1014. mvm->rts_threshold = value;
  1015. return 0;
  1016. }
  1017. static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
  1018. struct ieee80211_vif *vif, u16 ac,
  1019. const struct ieee80211_tx_queue_params *params)
  1020. {
  1021. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1022. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1023. mvmvif->queue_params[ac] = *params;
  1024. /*
  1025. * No need to update right away, we'll get BSS_CHANGED_QOS
  1026. * The exception is P2P_DEVICE interface which needs immediate update.
  1027. */
  1028. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  1029. int ret;
  1030. mutex_lock(&mvm->mutex);
  1031. ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
  1032. mutex_unlock(&mvm->mutex);
  1033. return ret;
  1034. }
  1035. return 0;
  1036. }
  1037. static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
  1038. struct ieee80211_vif *vif)
  1039. {
  1040. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1041. u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
  1042. 200 + vif->bss_conf.beacon_int);
  1043. u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
  1044. 100 + vif->bss_conf.beacon_int);
  1045. if (WARN_ON_ONCE(vif->bss_conf.assoc))
  1046. return;
  1047. mutex_lock(&mvm->mutex);
  1048. /* Try really hard to protect the session and hear a beacon */
  1049. iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500);
  1050. mutex_unlock(&mvm->mutex);
  1051. }
  1052. static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
  1053. struct ieee80211_vif *vif,
  1054. struct cfg80211_sched_scan_request *req,
  1055. struct ieee80211_sched_scan_ies *ies)
  1056. {
  1057. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1058. int ret;
  1059. mutex_lock(&mvm->mutex);
  1060. if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
  1061. IWL_DEBUG_SCAN(mvm,
  1062. "SCHED SCAN request during internal scan - abort\n");
  1063. ret = -EBUSY;
  1064. goto out;
  1065. }
  1066. mvm->scan_status = IWL_MVM_SCAN_SCHED;
  1067. ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies);
  1068. if (ret)
  1069. goto err;
  1070. ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
  1071. if (ret)
  1072. goto err;
  1073. ret = iwl_mvm_sched_scan_start(mvm, req);
  1074. if (!ret)
  1075. goto out;
  1076. err:
  1077. mvm->scan_status = IWL_MVM_SCAN_NONE;
  1078. out:
  1079. mutex_unlock(&mvm->mutex);
  1080. return ret;
  1081. }
  1082. static void iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
  1083. struct ieee80211_vif *vif)
  1084. {
  1085. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1086. mutex_lock(&mvm->mutex);
  1087. iwl_mvm_sched_scan_stop(mvm);
  1088. mutex_unlock(&mvm->mutex);
  1089. }
  1090. static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
  1091. enum set_key_cmd cmd,
  1092. struct ieee80211_vif *vif,
  1093. struct ieee80211_sta *sta,
  1094. struct ieee80211_key_conf *key)
  1095. {
  1096. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1097. int ret;
  1098. if (iwlwifi_mod_params.sw_crypto) {
  1099. IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
  1100. return -EOPNOTSUPP;
  1101. }
  1102. switch (key->cipher) {
  1103. case WLAN_CIPHER_SUITE_TKIP:
  1104. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  1105. /* fall-through */
  1106. case WLAN_CIPHER_SUITE_CCMP:
  1107. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  1108. break;
  1109. case WLAN_CIPHER_SUITE_AES_CMAC:
  1110. WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
  1111. break;
  1112. case WLAN_CIPHER_SUITE_WEP40:
  1113. case WLAN_CIPHER_SUITE_WEP104:
  1114. /*
  1115. * Support for TX only, at least for now, so accept
  1116. * the key and do nothing else. Then mac80211 will
  1117. * pass it for TX but we don't have to use it for RX.
  1118. */
  1119. return 0;
  1120. default:
  1121. return -EOPNOTSUPP;
  1122. }
  1123. mutex_lock(&mvm->mutex);
  1124. switch (cmd) {
  1125. case SET_KEY:
  1126. if ((vif->type == NL80211_IFTYPE_ADHOC ||
  1127. vif->type == NL80211_IFTYPE_AP) && !sta) {
  1128. /*
  1129. * GTK on AP interface is a TX-only key, return 0;
  1130. * on IBSS they're per-station and because we're lazy
  1131. * we don't support them for RX, so do the same.
  1132. */
  1133. ret = 0;
  1134. key->hw_key_idx = STA_KEY_IDX_INVALID;
  1135. break;
  1136. }
  1137. IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
  1138. ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
  1139. if (ret) {
  1140. IWL_WARN(mvm, "set key failed\n");
  1141. /*
  1142. * can't add key for RX, but we don't need it
  1143. * in the device for TX so still return 0
  1144. */
  1145. key->hw_key_idx = STA_KEY_IDX_INVALID;
  1146. ret = 0;
  1147. }
  1148. break;
  1149. case DISABLE_KEY:
  1150. if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
  1151. ret = 0;
  1152. break;
  1153. }
  1154. IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
  1155. ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
  1156. break;
  1157. default:
  1158. ret = -EINVAL;
  1159. }
  1160. mutex_unlock(&mvm->mutex);
  1161. return ret;
  1162. }
  1163. static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
  1164. struct ieee80211_vif *vif,
  1165. struct ieee80211_key_conf *keyconf,
  1166. struct ieee80211_sta *sta,
  1167. u32 iv32, u16 *phase1key)
  1168. {
  1169. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1170. if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
  1171. return;
  1172. iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
  1173. }
  1174. static int iwl_mvm_roc(struct ieee80211_hw *hw,
  1175. struct ieee80211_vif *vif,
  1176. struct ieee80211_channel *channel,
  1177. int duration,
  1178. enum ieee80211_roc_type type)
  1179. {
  1180. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1181. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1182. struct cfg80211_chan_def chandef;
  1183. struct iwl_mvm_phy_ctxt *phy_ctxt;
  1184. int ret, i;
  1185. IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
  1186. duration, type);
  1187. if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
  1188. IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
  1189. return -EINVAL;
  1190. }
  1191. mutex_lock(&mvm->mutex);
  1192. for (i = 0; i < NUM_PHY_CTX; i++) {
  1193. phy_ctxt = &mvm->phy_ctxts[i];
  1194. if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
  1195. continue;
  1196. if (phy_ctxt->ref && channel == phy_ctxt->channel) {
  1197. /*
  1198. * Unbind the P2P_DEVICE from the current PHY context,
  1199. * and if the PHY context is not used remove it.
  1200. */
  1201. ret = iwl_mvm_binding_remove_vif(mvm, vif);
  1202. if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
  1203. goto out_unlock;
  1204. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  1205. /* Bind the P2P_DEVICE to the current PHY Context */
  1206. mvmvif->phy_ctxt = phy_ctxt;
  1207. ret = iwl_mvm_binding_add_vif(mvm, vif);
  1208. if (WARN(ret, "Failed binding P2P_DEVICE\n"))
  1209. goto out_unlock;
  1210. iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
  1211. goto schedule_time_event;
  1212. }
  1213. }
  1214. /* Need to update the PHY context only if the ROC channel changed */
  1215. if (channel == mvmvif->phy_ctxt->channel)
  1216. goto schedule_time_event;
  1217. cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
  1218. /*
  1219. * Change the PHY context configuration as it is currently referenced
  1220. * only by the P2P Device MAC
  1221. */
  1222. if (mvmvif->phy_ctxt->ref == 1) {
  1223. ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
  1224. &chandef, 1, 1);
  1225. if (ret)
  1226. goto out_unlock;
  1227. } else {
  1228. /*
  1229. * The PHY context is shared with other MACs. Need to remove the
  1230. * P2P Device from the binding, allocate an new PHY context and
  1231. * create a new binding
  1232. */
  1233. phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
  1234. if (!phy_ctxt) {
  1235. ret = -ENOSPC;
  1236. goto out_unlock;
  1237. }
  1238. ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
  1239. 1, 1);
  1240. if (ret) {
  1241. IWL_ERR(mvm, "Failed to change PHY context\n");
  1242. goto out_unlock;
  1243. }
  1244. /* Unbind the P2P_DEVICE from the current PHY context */
  1245. ret = iwl_mvm_binding_remove_vif(mvm, vif);
  1246. if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
  1247. goto out_unlock;
  1248. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  1249. /* Bind the P2P_DEVICE to the new allocated PHY context */
  1250. mvmvif->phy_ctxt = phy_ctxt;
  1251. ret = iwl_mvm_binding_add_vif(mvm, vif);
  1252. if (WARN(ret, "Failed binding P2P_DEVICE\n"))
  1253. goto out_unlock;
  1254. iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
  1255. }
  1256. schedule_time_event:
  1257. /* Schedule the time events */
  1258. ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
  1259. out_unlock:
  1260. mutex_unlock(&mvm->mutex);
  1261. IWL_DEBUG_MAC80211(mvm, "leave\n");
  1262. return ret;
  1263. }
  1264. static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
  1265. {
  1266. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1267. IWL_DEBUG_MAC80211(mvm, "enter\n");
  1268. mutex_lock(&mvm->mutex);
  1269. iwl_mvm_stop_p2p_roc(mvm);
  1270. mutex_unlock(&mvm->mutex);
  1271. IWL_DEBUG_MAC80211(mvm, "leave\n");
  1272. return 0;
  1273. }
  1274. static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
  1275. struct ieee80211_chanctx_conf *ctx)
  1276. {
  1277. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1278. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  1279. struct iwl_mvm_phy_ctxt *phy_ctxt;
  1280. int ret;
  1281. IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
  1282. mutex_lock(&mvm->mutex);
  1283. phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
  1284. if (!phy_ctxt) {
  1285. ret = -ENOSPC;
  1286. goto out;
  1287. }
  1288. ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
  1289. ctx->rx_chains_static,
  1290. ctx->rx_chains_dynamic);
  1291. if (ret) {
  1292. IWL_ERR(mvm, "Failed to add PHY context\n");
  1293. goto out;
  1294. }
  1295. iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
  1296. *phy_ctxt_id = phy_ctxt->id;
  1297. out:
  1298. mutex_unlock(&mvm->mutex);
  1299. return ret;
  1300. }
  1301. static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
  1302. struct ieee80211_chanctx_conf *ctx)
  1303. {
  1304. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1305. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  1306. struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
  1307. mutex_lock(&mvm->mutex);
  1308. iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
  1309. mutex_unlock(&mvm->mutex);
  1310. }
  1311. static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
  1312. struct ieee80211_chanctx_conf *ctx,
  1313. u32 changed)
  1314. {
  1315. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1316. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  1317. struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
  1318. if (WARN_ONCE((phy_ctxt->ref > 1) &&
  1319. (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
  1320. IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
  1321. IEEE80211_CHANCTX_CHANGE_RADAR)),
  1322. "Cannot change PHY. Ref=%d, changed=0x%X\n",
  1323. phy_ctxt->ref, changed))
  1324. return;
  1325. mutex_lock(&mvm->mutex);
  1326. iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
  1327. ctx->rx_chains_static,
  1328. ctx->rx_chains_dynamic);
  1329. iwl_mvm_bt_coex_vif_change(mvm);
  1330. mutex_unlock(&mvm->mutex);
  1331. }
  1332. static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
  1333. struct ieee80211_vif *vif,
  1334. struct ieee80211_chanctx_conf *ctx)
  1335. {
  1336. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1337. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  1338. struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
  1339. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1340. int ret;
  1341. mutex_lock(&mvm->mutex);
  1342. mvmvif->phy_ctxt = phy_ctxt;
  1343. switch (vif->type) {
  1344. case NL80211_IFTYPE_AP:
  1345. case NL80211_IFTYPE_ADHOC:
  1346. /*
  1347. * The AP binding flow is handled as part of the start_ap flow
  1348. * (in bss_info_changed), similarly for IBSS.
  1349. */
  1350. ret = 0;
  1351. goto out_unlock;
  1352. case NL80211_IFTYPE_STATION:
  1353. case NL80211_IFTYPE_MONITOR:
  1354. break;
  1355. default:
  1356. ret = -EINVAL;
  1357. goto out_unlock;
  1358. }
  1359. ret = iwl_mvm_binding_add_vif(mvm, vif);
  1360. if (ret)
  1361. goto out_unlock;
  1362. /*
  1363. * Setting the quota at this stage is only required for monitor
  1364. * interfaces. For the other types, the bss_info changed flow
  1365. * will handle quota settings.
  1366. */
  1367. if (vif->type == NL80211_IFTYPE_MONITOR) {
  1368. mvmvif->monitor_active = true;
  1369. ret = iwl_mvm_update_quotas(mvm, vif);
  1370. if (ret)
  1371. goto out_remove_binding;
  1372. }
  1373. goto out_unlock;
  1374. out_remove_binding:
  1375. iwl_mvm_binding_remove_vif(mvm, vif);
  1376. out_unlock:
  1377. mutex_unlock(&mvm->mutex);
  1378. if (ret)
  1379. mvmvif->phy_ctxt = NULL;
  1380. return ret;
  1381. }
  1382. static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
  1383. struct ieee80211_vif *vif,
  1384. struct ieee80211_chanctx_conf *ctx)
  1385. {
  1386. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1387. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1388. mutex_lock(&mvm->mutex);
  1389. iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
  1390. switch (vif->type) {
  1391. case NL80211_IFTYPE_AP:
  1392. case NL80211_IFTYPE_ADHOC:
  1393. goto out_unlock;
  1394. case NL80211_IFTYPE_MONITOR:
  1395. mvmvif->monitor_active = false;
  1396. iwl_mvm_update_quotas(mvm, NULL);
  1397. break;
  1398. default:
  1399. break;
  1400. }
  1401. iwl_mvm_binding_remove_vif(mvm, vif);
  1402. out_unlock:
  1403. mvmvif->phy_ctxt = NULL;
  1404. mutex_unlock(&mvm->mutex);
  1405. }
  1406. static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
  1407. struct ieee80211_sta *sta,
  1408. bool set)
  1409. {
  1410. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1411. struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
  1412. if (!mvm_sta || !mvm_sta->vif) {
  1413. IWL_ERR(mvm, "Station is not associated to a vif\n");
  1414. return -EINVAL;
  1415. }
  1416. return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
  1417. }
  1418. #ifdef CONFIG_NL80211_TESTMODE
  1419. static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
  1420. [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
  1421. [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
  1422. [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
  1423. };
  1424. static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
  1425. struct ieee80211_vif *vif,
  1426. void *data, int len)
  1427. {
  1428. struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
  1429. int err;
  1430. u32 noa_duration;
  1431. err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
  1432. if (err)
  1433. return err;
  1434. if (!tb[IWL_MVM_TM_ATTR_CMD])
  1435. return -EINVAL;
  1436. switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
  1437. case IWL_MVM_TM_CMD_SET_NOA:
  1438. if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
  1439. !vif->bss_conf.enable_beacon ||
  1440. !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
  1441. return -EINVAL;
  1442. noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
  1443. if (noa_duration >= vif->bss_conf.beacon_int)
  1444. return -EINVAL;
  1445. mvm->noa_duration = noa_duration;
  1446. mvm->noa_vif = vif;
  1447. return iwl_mvm_update_quotas(mvm, NULL);
  1448. case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
  1449. /* must be associated client vif - ignore authorized */
  1450. if (!vif || vif->type != NL80211_IFTYPE_STATION ||
  1451. !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
  1452. !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
  1453. return -EINVAL;
  1454. if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
  1455. return iwl_mvm_enable_beacon_filter(mvm, vif);
  1456. return iwl_mvm_disable_beacon_filter(mvm, vif);
  1457. }
  1458. return -EOPNOTSUPP;
  1459. }
  1460. static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
  1461. struct ieee80211_vif *vif,
  1462. void *data, int len)
  1463. {
  1464. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1465. int err;
  1466. mutex_lock(&mvm->mutex);
  1467. err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
  1468. mutex_unlock(&mvm->mutex);
  1469. return err;
  1470. }
  1471. #endif
  1472. struct ieee80211_ops iwl_mvm_hw_ops = {
  1473. .tx = iwl_mvm_mac_tx,
  1474. .ampdu_action = iwl_mvm_mac_ampdu_action,
  1475. .start = iwl_mvm_mac_start,
  1476. .restart_complete = iwl_mvm_mac_restart_complete,
  1477. .stop = iwl_mvm_mac_stop,
  1478. .add_interface = iwl_mvm_mac_add_interface,
  1479. .remove_interface = iwl_mvm_mac_remove_interface,
  1480. .config = iwl_mvm_mac_config,
  1481. .configure_filter = iwl_mvm_configure_filter,
  1482. .bss_info_changed = iwl_mvm_bss_info_changed,
  1483. .hw_scan = iwl_mvm_mac_hw_scan,
  1484. .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
  1485. .sta_state = iwl_mvm_mac_sta_state,
  1486. .sta_notify = iwl_mvm_mac_sta_notify,
  1487. .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
  1488. .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
  1489. .conf_tx = iwl_mvm_mac_conf_tx,
  1490. .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
  1491. .sched_scan_start = iwl_mvm_mac_sched_scan_start,
  1492. .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
  1493. .set_key = iwl_mvm_mac_set_key,
  1494. .update_tkip_key = iwl_mvm_mac_update_tkip_key,
  1495. .remain_on_channel = iwl_mvm_roc,
  1496. .cancel_remain_on_channel = iwl_mvm_cancel_roc,
  1497. .add_chanctx = iwl_mvm_add_chanctx,
  1498. .remove_chanctx = iwl_mvm_remove_chanctx,
  1499. .change_chanctx = iwl_mvm_change_chanctx,
  1500. .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
  1501. .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
  1502. .start_ap = iwl_mvm_start_ap_ibss,
  1503. .stop_ap = iwl_mvm_stop_ap_ibss,
  1504. .join_ibss = iwl_mvm_start_ap_ibss,
  1505. .leave_ibss = iwl_mvm_stop_ap_ibss,
  1506. .set_tim = iwl_mvm_set_tim,
  1507. CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
  1508. #ifdef CONFIG_PM_SLEEP
  1509. /* look at d3.c */
  1510. .suspend = iwl_mvm_suspend,
  1511. .resume = iwl_mvm_resume,
  1512. .set_wakeup = iwl_mvm_set_wakeup,
  1513. .set_rekey_data = iwl_mvm_set_rekey_data,
  1514. #if IS_ENABLED(CONFIG_IPV6)
  1515. .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
  1516. #endif
  1517. .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
  1518. #endif
  1519. };