mac80211.c 46 KB

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