mac80211.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316
  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 LICENSE.GPL.
  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 <net/mac80211.h>
  69. #include "iwl-op-mode.h"
  70. #include "iwl-io.h"
  71. #include "mvm.h"
  72. #include "sta.h"
  73. #include "time-event.h"
  74. #include "iwl-eeprom-parse.h"
  75. #include "fw-api-scan.h"
  76. #include "iwl-phy-db.h"
  77. static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
  78. {
  79. .max = 1,
  80. .types = BIT(NL80211_IFTYPE_STATION) |
  81. BIT(NL80211_IFTYPE_AP),
  82. },
  83. {
  84. .max = 1,
  85. .types = BIT(NL80211_IFTYPE_P2P_CLIENT) |
  86. BIT(NL80211_IFTYPE_P2P_GO),
  87. },
  88. {
  89. .max = 1,
  90. .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
  91. },
  92. };
  93. static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
  94. {
  95. .num_different_channels = 1,
  96. .max_interfaces = 3,
  97. .limits = iwl_mvm_limits,
  98. .n_limits = ARRAY_SIZE(iwl_mvm_limits),
  99. },
  100. };
  101. int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
  102. {
  103. struct ieee80211_hw *hw = mvm->hw;
  104. int num_mac, ret;
  105. /* Tell mac80211 our characteristics */
  106. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  107. IEEE80211_HW_SPECTRUM_MGMT |
  108. IEEE80211_HW_REPORTS_TX_ACK_STATUS |
  109. IEEE80211_HW_QUEUE_CONTROL |
  110. IEEE80211_HW_WANT_MONITOR_VIF |
  111. IEEE80211_HW_NEED_DTIM_BEFORE_ASSOC |
  112. IEEE80211_HW_SUPPORTS_PS |
  113. IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
  114. IEEE80211_HW_AMPDU_AGGREGATION;
  115. hw->queues = IWL_FIRST_AMPDU_QUEUE;
  116. hw->offchannel_tx_hw_queue = IWL_OFFCHANNEL_QUEUE;
  117. hw->rate_control_algorithm = "iwl-mvm-rs";
  118. /*
  119. * Enable 11w if advertised by firmware and software crypto
  120. * is not enabled (as the firmware will interpret some mgmt
  121. * packets, so enabling it with software crypto isn't safe)
  122. */
  123. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
  124. !iwlwifi_mod_params.sw_crypto)
  125. hw->flags |= IEEE80211_HW_MFP_CAPABLE;
  126. hw->sta_data_size = sizeof(struct iwl_mvm_sta);
  127. hw->vif_data_size = sizeof(struct iwl_mvm_vif);
  128. hw->chanctx_data_size = sizeof(struct iwl_mvm_phy_ctxt);
  129. hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  130. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  131. BIT(NL80211_IFTYPE_AP) |
  132. BIT(NL80211_IFTYPE_P2P_GO) |
  133. BIT(NL80211_IFTYPE_P2P_DEVICE);
  134. hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
  135. WIPHY_FLAG_DISABLE_BEACON_HINTS |
  136. WIPHY_FLAG_IBSS_RSN;
  137. hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
  138. hw->wiphy->n_iface_combinations =
  139. ARRAY_SIZE(iwl_mvm_iface_combinations);
  140. hw->wiphy->max_remain_on_channel_duration = 500;
  141. hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
  142. /* Extract MAC address */
  143. memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
  144. hw->wiphy->addresses = mvm->addresses;
  145. hw->wiphy->n_addresses = 1;
  146. num_mac = mvm->nvm_data->n_hw_addrs;
  147. if (num_mac > 1) {
  148. memcpy(mvm->addresses[1].addr, mvm->addresses[0].addr,
  149. ETH_ALEN);
  150. mvm->addresses[1].addr[5]++;
  151. hw->wiphy->n_addresses++;
  152. }
  153. /* we create the 802.11 header and a max-length SSID element */
  154. hw->wiphy->max_scan_ie_len =
  155. mvm->fw->ucode_capa.max_probe_length - 24 - 34;
  156. hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
  157. if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
  158. hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  159. &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
  160. if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
  161. hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  162. &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
  163. hw->wiphy->hw_version = mvm->trans->hw_id;
  164. if (iwlwifi_mod_params.power_save)
  165. hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
  166. else
  167. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  168. hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
  169. NL80211_FEATURE_P2P_GO_OPPPS;
  170. mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
  171. #ifdef CONFIG_PM_SLEEP
  172. if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
  173. mvm->trans->ops->d3_suspend &&
  174. mvm->trans->ops->d3_resume &&
  175. device_can_wakeup(mvm->trans->dev)) {
  176. hw->wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
  177. WIPHY_WOWLAN_DISCONNECT |
  178. WIPHY_WOWLAN_EAP_IDENTITY_REQ |
  179. WIPHY_WOWLAN_RFKILL_RELEASE;
  180. if (!iwlwifi_mod_params.sw_crypto)
  181. hw->wiphy->wowlan.flags |=
  182. WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
  183. WIPHY_WOWLAN_GTK_REKEY_FAILURE |
  184. WIPHY_WOWLAN_4WAY_HANDSHAKE;
  185. hw->wiphy->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
  186. hw->wiphy->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
  187. hw->wiphy->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
  188. }
  189. #endif
  190. ret = iwl_mvm_leds_init(mvm);
  191. if (ret)
  192. return ret;
  193. return ieee80211_register_hw(mvm->hw);
  194. }
  195. static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
  196. struct ieee80211_tx_control *control,
  197. struct sk_buff *skb)
  198. {
  199. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  200. if (test_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status)) {
  201. IWL_DEBUG_DROP(mvm, "Dropping - RF KILL\n");
  202. goto drop;
  203. }
  204. if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_OFFCHANNEL_QUEUE &&
  205. !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status))
  206. goto drop;
  207. if (control->sta) {
  208. if (iwl_mvm_tx_skb(mvm, skb, control->sta))
  209. goto drop;
  210. return;
  211. }
  212. if (iwl_mvm_tx_skb_non_sta(mvm, skb))
  213. goto drop;
  214. return;
  215. drop:
  216. ieee80211_free_txskb(hw, skb);
  217. }
  218. static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
  219. struct ieee80211_vif *vif,
  220. enum ieee80211_ampdu_mlme_action action,
  221. struct ieee80211_sta *sta, u16 tid,
  222. u16 *ssn, u8 buf_size)
  223. {
  224. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  225. int ret;
  226. IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
  227. sta->addr, tid, action);
  228. if (!(mvm->nvm_data->sku_cap_11n_enable))
  229. return -EACCES;
  230. mutex_lock(&mvm->mutex);
  231. switch (action) {
  232. case IEEE80211_AMPDU_RX_START:
  233. if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) {
  234. ret = -EINVAL;
  235. break;
  236. }
  237. ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
  238. break;
  239. case IEEE80211_AMPDU_RX_STOP:
  240. ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
  241. break;
  242. case IEEE80211_AMPDU_TX_START:
  243. ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
  244. break;
  245. case IEEE80211_AMPDU_TX_STOP_CONT:
  246. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  247. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  248. ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
  249. break;
  250. case IEEE80211_AMPDU_TX_OPERATIONAL:
  251. ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
  252. break;
  253. default:
  254. WARN_ON_ONCE(1);
  255. ret = -EINVAL;
  256. break;
  257. }
  258. mutex_unlock(&mvm->mutex);
  259. return ret;
  260. }
  261. static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
  262. struct ieee80211_vif *vif)
  263. {
  264. struct iwl_mvm *mvm = data;
  265. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  266. mvmvif->uploaded = false;
  267. mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
  268. /* does this make sense at all? */
  269. mvmvif->color++;
  270. spin_lock_bh(&mvm->time_event_lock);
  271. iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
  272. spin_unlock_bh(&mvm->time_event_lock);
  273. if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
  274. mvmvif->phy_ctxt = NULL;
  275. }
  276. static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
  277. {
  278. iwl_trans_stop_device(mvm->trans);
  279. iwl_trans_stop_hw(mvm->trans, false);
  280. mvm->scan_status = IWL_MVM_SCAN_NONE;
  281. /* just in case one was running */
  282. ieee80211_remain_on_channel_expired(mvm->hw);
  283. ieee80211_iterate_active_interfaces_atomic(
  284. mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
  285. iwl_mvm_cleanup_iterator, mvm);
  286. memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
  287. memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
  288. ieee80211_wake_queues(mvm->hw);
  289. mvm->vif_count = 0;
  290. }
  291. static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
  292. {
  293. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  294. int ret;
  295. mutex_lock(&mvm->mutex);
  296. /* Clean up some internal and mac80211 state on restart */
  297. if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
  298. iwl_mvm_restart_cleanup(mvm);
  299. ret = iwl_mvm_up(mvm);
  300. mutex_unlock(&mvm->mutex);
  301. return ret;
  302. }
  303. static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
  304. {
  305. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  306. int ret;
  307. mutex_lock(&mvm->mutex);
  308. clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
  309. ret = iwl_mvm_update_quotas(mvm, NULL);
  310. if (ret)
  311. IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
  312. ret);
  313. mutex_unlock(&mvm->mutex);
  314. }
  315. static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
  316. {
  317. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  318. flush_work(&mvm->async_handlers_wk);
  319. mutex_lock(&mvm->mutex);
  320. /* async_handlers_wk is now blocked */
  321. /*
  322. * The work item could be running or queued if the
  323. * ROC time event stops just as we get here.
  324. */
  325. cancel_work_sync(&mvm->roc_done_wk);
  326. iwl_trans_stop_device(mvm->trans);
  327. iwl_trans_stop_hw(mvm->trans, false);
  328. iwl_mvm_async_handlers_purge(mvm);
  329. /* async_handlers_list is empty and will stay empty: HW is stopped */
  330. /* the fw is stopped, the aux sta is dead: clean up driver state */
  331. iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
  332. mutex_unlock(&mvm->mutex);
  333. /*
  334. * The worker might have been waiting for the mutex, let it run and
  335. * discover that its list is now empty.
  336. */
  337. cancel_work_sync(&mvm->async_handlers_wk);
  338. }
  339. static void iwl_mvm_pm_disable_iterator(void *data, u8 *mac,
  340. struct ieee80211_vif *vif)
  341. {
  342. struct iwl_mvm *mvm = data;
  343. int ret;
  344. ret = iwl_mvm_power_disable(mvm, vif);
  345. if (ret)
  346. IWL_ERR(mvm, "failed to disable power management\n");
  347. }
  348. static void iwl_mvm_power_update_iterator(void *data, u8 *mac,
  349. struct ieee80211_vif *vif)
  350. {
  351. struct iwl_mvm *mvm = data;
  352. iwl_mvm_power_update_mode(mvm, vif);
  353. }
  354. static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
  355. struct ieee80211_vif *vif)
  356. {
  357. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  358. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  359. int ret;
  360. /*
  361. * Not much to do here. The stack will not allow interface
  362. * types or combinations that we didn't advertise, so we
  363. * don't really have to check the types.
  364. */
  365. mutex_lock(&mvm->mutex);
  366. /* Allocate resources for the MAC context, and add it the the fw */
  367. ret = iwl_mvm_mac_ctxt_init(mvm, vif);
  368. if (ret)
  369. goto out_unlock;
  370. /*
  371. * The AP binding flow can be done only after the beacon
  372. * template is configured (which happens only in the mac80211
  373. * start_ap() flow), and adding the broadcast station can happen
  374. * only after the binding.
  375. * In addition, since modifying the MAC before adding a bcast
  376. * station is not allowed by the FW, delay the adding of MAC context to
  377. * the point where we can also add the bcast station.
  378. * In short: there's not much we can do at this point, other than
  379. * allocating resources :)
  380. */
  381. if (vif->type == NL80211_IFTYPE_AP) {
  382. u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif);
  383. ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta,
  384. qmask);
  385. if (ret) {
  386. IWL_ERR(mvm, "Failed to allocate bcast sta\n");
  387. goto out_release;
  388. }
  389. goto out_unlock;
  390. }
  391. /*
  392. * TODO: remove this temporary code.
  393. * Currently MVM FW supports power management only on single MAC.
  394. * Iterate and disable PM on all active interfaces.
  395. * Note: the method below does not count the new interface being added
  396. * at this moment.
  397. */
  398. mvm->vif_count++;
  399. if (mvm->vif_count > 1) {
  400. IWL_DEBUG_MAC80211(mvm,
  401. "Disable power on existing interfaces\n");
  402. ieee80211_iterate_active_interfaces_atomic(
  403. mvm->hw,
  404. IEEE80211_IFACE_ITER_NORMAL,
  405. iwl_mvm_pm_disable_iterator, mvm);
  406. }
  407. ret = iwl_mvm_mac_ctxt_add(mvm, vif);
  408. if (ret)
  409. goto out_release;
  410. /*
  411. * Update power state on the new interface. Admittedly, based on
  412. * mac80211 logics this power update will disable power management
  413. */
  414. iwl_mvm_power_update_mode(mvm, vif);
  415. /*
  416. * P2P_DEVICE interface does not have a channel context assigned to it,
  417. * so a dedicated PHY context is allocated to it and the corresponding
  418. * MAC context is bound to it at this stage.
  419. */
  420. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  421. struct ieee80211_channel *chan;
  422. struct cfg80211_chan_def chandef;
  423. mvmvif->phy_ctxt = &mvm->phy_ctxt_roc;
  424. /*
  425. * The channel used here isn't relevant as it's
  426. * going to be overwritten as part of the ROC flow.
  427. * For now use the first channel we have.
  428. */
  429. chan = &mvm->hw->wiphy->bands[IEEE80211_BAND_2GHZ]->channels[0];
  430. cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
  431. ret = iwl_mvm_phy_ctxt_add(mvm, mvmvif->phy_ctxt,
  432. &chandef, 1, 1);
  433. if (ret)
  434. goto out_remove_mac;
  435. ret = iwl_mvm_binding_add_vif(mvm, vif);
  436. if (ret)
  437. goto out_remove_phy;
  438. ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
  439. if (ret)
  440. goto out_unbind;
  441. /* Save a pointer to p2p device vif, so it can later be used to
  442. * update the p2p device MAC when a GO is started/stopped */
  443. mvm->p2p_device_vif = vif;
  444. }
  445. goto out_unlock;
  446. out_unbind:
  447. iwl_mvm_binding_remove_vif(mvm, vif);
  448. out_remove_phy:
  449. iwl_mvm_phy_ctxt_remove(mvm, mvmvif->phy_ctxt);
  450. out_remove_mac:
  451. mvmvif->phy_ctxt = NULL;
  452. iwl_mvm_mac_ctxt_remove(mvm, vif);
  453. out_release:
  454. /*
  455. * TODO: remove this temporary code.
  456. * Currently MVM FW supports power management only on single MAC.
  457. * Check if only one additional interface remains after rereasing
  458. * current one. Update power mode on the remaining interface.
  459. */
  460. mvm->vif_count--;
  461. IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n",
  462. mvm->vif_count);
  463. if (mvm->vif_count == 1) {
  464. ieee80211_iterate_active_interfaces(
  465. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  466. iwl_mvm_power_update_iterator, mvm);
  467. }
  468. iwl_mvm_mac_ctxt_release(mvm, vif);
  469. out_unlock:
  470. mutex_unlock(&mvm->mutex);
  471. return ret;
  472. }
  473. static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
  474. struct ieee80211_vif *vif)
  475. {
  476. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  477. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  478. u32 tfd_msk = 0, ac;
  479. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  480. if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
  481. tfd_msk |= BIT(vif->hw_queue[ac]);
  482. if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
  483. tfd_msk |= BIT(vif->cab_queue);
  484. if (tfd_msk) {
  485. mutex_lock(&mvm->mutex);
  486. iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
  487. mutex_unlock(&mvm->mutex);
  488. }
  489. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  490. /*
  491. * Flush the ROC worker which will flush the OFFCHANNEL queue.
  492. * We assume here that all the packets sent to the OFFCHANNEL
  493. * queue are sent in ROC session.
  494. */
  495. flush_work(&mvm->roc_done_wk);
  496. } else {
  497. /*
  498. * By now, all the AC queues are empty. The AGG queues are
  499. * empty too. We already got all the Tx responses for all the
  500. * packets in the queues. The drain work can have been
  501. * triggered. Flush it. This work item takes the mutex, so kill
  502. * it before we take it.
  503. */
  504. flush_work(&mvm->sta_drained_wk);
  505. }
  506. mutex_lock(&mvm->mutex);
  507. /*
  508. * For AP/GO interface, the tear down of the resources allocated to the
  509. * interface should be handled as part of the bss_info_changed flow.
  510. */
  511. if (vif->type == NL80211_IFTYPE_AP) {
  512. iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
  513. goto out_release;
  514. }
  515. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  516. mvm->p2p_device_vif = NULL;
  517. iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
  518. iwl_mvm_binding_remove_vif(mvm, vif);
  519. iwl_mvm_phy_ctxt_remove(mvm, mvmvif->phy_ctxt);
  520. mvmvif->phy_ctxt = NULL;
  521. }
  522. /*
  523. * TODO: remove this temporary code.
  524. * Currently MVM FW supports power management only on single MAC.
  525. * Check if only one additional interface remains after removing
  526. * current one. Update power mode on the remaining interface.
  527. */
  528. if (mvm->vif_count)
  529. mvm->vif_count--;
  530. IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n",
  531. mvm->vif_count);
  532. if (mvm->vif_count == 1) {
  533. ieee80211_iterate_active_interfaces(
  534. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  535. iwl_mvm_power_update_iterator, mvm);
  536. }
  537. iwl_mvm_mac_ctxt_remove(mvm, vif);
  538. out_release:
  539. iwl_mvm_mac_ctxt_release(mvm, vif);
  540. mutex_unlock(&mvm->mutex);
  541. }
  542. static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
  543. {
  544. return 0;
  545. }
  546. static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
  547. unsigned int changed_flags,
  548. unsigned int *total_flags,
  549. u64 multicast)
  550. {
  551. *total_flags = 0;
  552. }
  553. static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
  554. struct ieee80211_vif *vif,
  555. struct ieee80211_bss_conf *bss_conf,
  556. u32 changes)
  557. {
  558. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  559. int ret;
  560. ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
  561. if (ret)
  562. IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
  563. if (changes & BSS_CHANGED_ASSOC) {
  564. if (bss_conf->assoc) {
  565. /* add quota for this interface */
  566. ret = iwl_mvm_update_quotas(mvm, vif);
  567. if (ret) {
  568. IWL_ERR(mvm, "failed to update quotas\n");
  569. return;
  570. }
  571. } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
  572. /* remove AP station now that the MAC is unassoc */
  573. ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
  574. if (ret)
  575. IWL_ERR(mvm, "failed to remove AP station\n");
  576. mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
  577. /* remove quota for this interface */
  578. ret = iwl_mvm_update_quotas(mvm, NULL);
  579. if (ret)
  580. IWL_ERR(mvm, "failed to update quotas\n");
  581. }
  582. } else if (changes & BSS_CHANGED_DTIM_PERIOD) {
  583. /*
  584. * We received a beacon _after_ association so
  585. * remove the session protection.
  586. */
  587. iwl_mvm_remove_time_event(mvm, mvmvif,
  588. &mvmvif->time_event_data);
  589. } else if (changes & BSS_CHANGED_PS) {
  590. /*
  591. * TODO: remove this temporary code.
  592. * Currently MVM FW supports power management only on single
  593. * MAC. Avoid power mode update if more than one interface
  594. * is active.
  595. */
  596. IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n",
  597. mvm->vif_count);
  598. if (mvm->vif_count == 1) {
  599. ret = iwl_mvm_power_update_mode(mvm, vif);
  600. if (ret)
  601. IWL_ERR(mvm, "failed to update power mode\n");
  602. }
  603. }
  604. }
  605. static int iwl_mvm_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  606. {
  607. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  608. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  609. int ret;
  610. mutex_lock(&mvm->mutex);
  611. /* Send the beacon template */
  612. ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
  613. if (ret)
  614. goto out_unlock;
  615. /* Add the mac context */
  616. ret = iwl_mvm_mac_ctxt_add(mvm, vif);
  617. if (ret)
  618. goto out_unlock;
  619. /* Perform the binding */
  620. ret = iwl_mvm_binding_add_vif(mvm, vif);
  621. if (ret)
  622. goto out_remove;
  623. mvmvif->ap_active = true;
  624. /* Send the bcast station. At this stage the TBTT and DTIM time events
  625. * are added and applied to the scheduler */
  626. ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
  627. if (ret)
  628. goto out_unbind;
  629. ret = iwl_mvm_update_quotas(mvm, vif);
  630. if (ret)
  631. goto out_rm_bcast;
  632. /* Need to update the P2P Device MAC */
  633. if (vif->p2p && mvm->p2p_device_vif)
  634. iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
  635. mutex_unlock(&mvm->mutex);
  636. return 0;
  637. out_rm_bcast:
  638. iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
  639. out_unbind:
  640. iwl_mvm_binding_remove_vif(mvm, vif);
  641. out_remove:
  642. iwl_mvm_mac_ctxt_remove(mvm, vif);
  643. out_unlock:
  644. mutex_unlock(&mvm->mutex);
  645. return ret;
  646. }
  647. static void iwl_mvm_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  648. {
  649. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  650. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  651. mutex_lock(&mvm->mutex);
  652. mvmvif->ap_active = false;
  653. /* Need to update the P2P Device MAC */
  654. if (vif->p2p && mvm->p2p_device_vif)
  655. iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
  656. iwl_mvm_update_quotas(mvm, NULL);
  657. iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
  658. iwl_mvm_binding_remove_vif(mvm, vif);
  659. iwl_mvm_mac_ctxt_remove(mvm, vif);
  660. mutex_unlock(&mvm->mutex);
  661. }
  662. static void iwl_mvm_bss_info_changed_ap(struct iwl_mvm *mvm,
  663. struct ieee80211_vif *vif,
  664. struct ieee80211_bss_conf *bss_conf,
  665. u32 changes)
  666. {
  667. /* Need to send a new beacon template to the FW */
  668. if (changes & BSS_CHANGED_BEACON) {
  669. if (iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
  670. IWL_WARN(mvm, "Failed updating beacon data\n");
  671. }
  672. }
  673. static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
  674. struct ieee80211_vif *vif,
  675. struct ieee80211_bss_conf *bss_conf,
  676. u32 changes)
  677. {
  678. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  679. mutex_lock(&mvm->mutex);
  680. switch (vif->type) {
  681. case NL80211_IFTYPE_STATION:
  682. iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
  683. break;
  684. case NL80211_IFTYPE_AP:
  685. iwl_mvm_bss_info_changed_ap(mvm, vif, bss_conf, changes);
  686. break;
  687. default:
  688. /* shouldn't happen */
  689. WARN_ON_ONCE(1);
  690. }
  691. mutex_unlock(&mvm->mutex);
  692. }
  693. static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
  694. struct ieee80211_vif *vif,
  695. struct cfg80211_scan_request *req)
  696. {
  697. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  698. int ret;
  699. if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS)
  700. return -EINVAL;
  701. mutex_lock(&mvm->mutex);
  702. if (mvm->scan_status == IWL_MVM_SCAN_NONE)
  703. ret = iwl_mvm_scan_request(mvm, vif, req);
  704. else
  705. ret = -EBUSY;
  706. mutex_unlock(&mvm->mutex);
  707. return ret;
  708. }
  709. static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
  710. struct ieee80211_vif *vif)
  711. {
  712. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  713. mutex_lock(&mvm->mutex);
  714. iwl_mvm_cancel_scan(mvm);
  715. mutex_unlock(&mvm->mutex);
  716. }
  717. static void
  718. iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
  719. struct ieee80211_sta *sta, u16 tid,
  720. int num_frames,
  721. enum ieee80211_frame_release_type reason,
  722. bool more_data)
  723. {
  724. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  725. struct iwl_mvm_sta *mvmsta = (void *)sta->drv_priv;
  726. /* TODO: how do we tell the fw to send frames for a specific TID */
  727. /*
  728. * The fw will send EOSP notification when the last frame will be
  729. * transmitted.
  730. */
  731. iwl_mvm_sta_modify_sleep_tx_count(mvm, mvmsta->sta_id, reason,
  732. num_frames);
  733. }
  734. static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
  735. struct ieee80211_vif *vif,
  736. enum sta_notify_cmd cmd,
  737. struct ieee80211_sta *sta)
  738. {
  739. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  740. struct iwl_mvm_sta *mvmsta = (void *)sta->drv_priv;
  741. switch (cmd) {
  742. case STA_NOTIFY_SLEEP:
  743. if (atomic_read(&mvmsta->pending_frames) > 0)
  744. ieee80211_sta_block_awake(hw, sta, true);
  745. /*
  746. * The fw updates the STA to be asleep. Tx packets on the Tx
  747. * queues to this station will not be transmitted. The fw will
  748. * send a Tx response with TX_STATUS_FAIL_DEST_PS.
  749. */
  750. break;
  751. case STA_NOTIFY_AWAKE:
  752. if (WARN_ON(mvmsta->sta_id == IWL_INVALID_STATION))
  753. break;
  754. iwl_mvm_sta_modify_ps_wake(mvm, mvmsta->sta_id);
  755. break;
  756. default:
  757. break;
  758. }
  759. }
  760. static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
  761. struct ieee80211_vif *vif,
  762. struct ieee80211_sta *sta,
  763. enum ieee80211_sta_state old_state,
  764. enum ieee80211_sta_state new_state)
  765. {
  766. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  767. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  768. int ret;
  769. IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
  770. sta->addr, old_state, new_state);
  771. /* this would be a mac80211 bug ... but don't crash */
  772. if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
  773. return -EINVAL;
  774. /* if a STA is being removed, reuse its ID */
  775. flush_work(&mvm->sta_drained_wk);
  776. mutex_lock(&mvm->mutex);
  777. if (old_state == IEEE80211_STA_NOTEXIST &&
  778. new_state == IEEE80211_STA_NONE) {
  779. ret = iwl_mvm_add_sta(mvm, vif, sta);
  780. } else if (old_state == IEEE80211_STA_NONE &&
  781. new_state == IEEE80211_STA_AUTH) {
  782. ret = 0;
  783. } else if (old_state == IEEE80211_STA_AUTH &&
  784. new_state == IEEE80211_STA_ASSOC) {
  785. ret = iwl_mvm_update_sta(mvm, vif, sta);
  786. if (ret == 0)
  787. iwl_mvm_rs_rate_init(mvm, sta,
  788. mvmvif->phy_ctxt->channel->band);
  789. } else if (old_state == IEEE80211_STA_ASSOC &&
  790. new_state == IEEE80211_STA_AUTHORIZED) {
  791. ret = 0;
  792. } else if (old_state == IEEE80211_STA_AUTHORIZED &&
  793. new_state == IEEE80211_STA_ASSOC) {
  794. ret = 0;
  795. } else if (old_state == IEEE80211_STA_ASSOC &&
  796. new_state == IEEE80211_STA_AUTH) {
  797. ret = 0;
  798. } else if (old_state == IEEE80211_STA_AUTH &&
  799. new_state == IEEE80211_STA_NONE) {
  800. ret = 0;
  801. } else if (old_state == IEEE80211_STA_NONE &&
  802. new_state == IEEE80211_STA_NOTEXIST) {
  803. ret = iwl_mvm_rm_sta(mvm, vif, sta);
  804. } else {
  805. ret = -EIO;
  806. }
  807. mutex_unlock(&mvm->mutex);
  808. return ret;
  809. }
  810. static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  811. {
  812. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  813. mvm->rts_threshold = value;
  814. return 0;
  815. }
  816. static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
  817. struct ieee80211_vif *vif, u16 ac,
  818. const struct ieee80211_tx_queue_params *params)
  819. {
  820. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  821. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  822. mvmvif->queue_params[ac] = *params;
  823. /*
  824. * No need to update right away, we'll get BSS_CHANGED_QOS
  825. * The exception is P2P_DEVICE interface which needs immediate update.
  826. */
  827. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  828. int ret;
  829. mutex_lock(&mvm->mutex);
  830. ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
  831. mutex_unlock(&mvm->mutex);
  832. return ret;
  833. }
  834. return 0;
  835. }
  836. static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
  837. struct ieee80211_vif *vif)
  838. {
  839. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  840. u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
  841. 200 + vif->bss_conf.beacon_int);
  842. u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
  843. 100 + vif->bss_conf.beacon_int);
  844. if (WARN_ON_ONCE(vif->bss_conf.assoc))
  845. return;
  846. mutex_lock(&mvm->mutex);
  847. /* Try really hard to protect the session and hear a beacon */
  848. iwl_mvm_protect_session(mvm, vif, duration, min_duration);
  849. mutex_unlock(&mvm->mutex);
  850. }
  851. static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
  852. enum set_key_cmd cmd,
  853. struct ieee80211_vif *vif,
  854. struct ieee80211_sta *sta,
  855. struct ieee80211_key_conf *key)
  856. {
  857. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  858. int ret;
  859. if (iwlwifi_mod_params.sw_crypto) {
  860. IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
  861. return -EOPNOTSUPP;
  862. }
  863. switch (key->cipher) {
  864. case WLAN_CIPHER_SUITE_TKIP:
  865. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  866. /* fall-through */
  867. case WLAN_CIPHER_SUITE_CCMP:
  868. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  869. break;
  870. case WLAN_CIPHER_SUITE_AES_CMAC:
  871. WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
  872. break;
  873. case WLAN_CIPHER_SUITE_WEP40:
  874. case WLAN_CIPHER_SUITE_WEP104:
  875. /*
  876. * Support for TX only, at least for now, so accept
  877. * the key and do nothing else. Then mac80211 will
  878. * pass it for TX but we don't have to use it for RX.
  879. */
  880. return 0;
  881. default:
  882. return -EOPNOTSUPP;
  883. }
  884. mutex_lock(&mvm->mutex);
  885. switch (cmd) {
  886. case SET_KEY:
  887. IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
  888. ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
  889. if (ret) {
  890. IWL_WARN(mvm, "set key failed\n");
  891. /*
  892. * can't add key for RX, but we don't need it
  893. * in the device for TX so still return 0
  894. */
  895. ret = 0;
  896. }
  897. break;
  898. case DISABLE_KEY:
  899. IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
  900. ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
  901. break;
  902. default:
  903. ret = -EINVAL;
  904. }
  905. mutex_unlock(&mvm->mutex);
  906. return ret;
  907. }
  908. static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
  909. struct ieee80211_vif *vif,
  910. struct ieee80211_key_conf *keyconf,
  911. struct ieee80211_sta *sta,
  912. u32 iv32, u16 *phase1key)
  913. {
  914. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  915. iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
  916. }
  917. static int iwl_mvm_roc(struct ieee80211_hw *hw,
  918. struct ieee80211_vif *vif,
  919. struct ieee80211_channel *channel,
  920. int duration)
  921. {
  922. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  923. struct cfg80211_chan_def chandef;
  924. int ret;
  925. if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
  926. IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
  927. return -EINVAL;
  928. }
  929. IWL_DEBUG_MAC80211(mvm, "enter (%d, %d)\n", channel->hw_value,
  930. duration);
  931. mutex_lock(&mvm->mutex);
  932. cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
  933. ret = iwl_mvm_phy_ctxt_changed(mvm, &mvm->phy_ctxt_roc,
  934. &chandef, 1, 1);
  935. /* Schedule the time events */
  936. ret = iwl_mvm_start_p2p_roc(mvm, vif, duration);
  937. mutex_unlock(&mvm->mutex);
  938. IWL_DEBUG_MAC80211(mvm, "leave\n");
  939. return ret;
  940. }
  941. static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
  942. {
  943. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  944. IWL_DEBUG_MAC80211(mvm, "enter\n");
  945. mutex_lock(&mvm->mutex);
  946. iwl_mvm_stop_p2p_roc(mvm);
  947. mutex_unlock(&mvm->mutex);
  948. IWL_DEBUG_MAC80211(mvm, "leave\n");
  949. return 0;
  950. }
  951. static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
  952. struct ieee80211_chanctx_conf *ctx)
  953. {
  954. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  955. struct iwl_mvm_phy_ctxt *phy_ctxt = (void *)ctx->drv_priv;
  956. int ret;
  957. mutex_lock(&mvm->mutex);
  958. IWL_DEBUG_MAC80211(mvm, "Add PHY context\n");
  959. ret = iwl_mvm_phy_ctxt_add(mvm, phy_ctxt, &ctx->def,
  960. ctx->rx_chains_static,
  961. ctx->rx_chains_dynamic);
  962. mutex_unlock(&mvm->mutex);
  963. return ret;
  964. }
  965. static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
  966. struct ieee80211_chanctx_conf *ctx)
  967. {
  968. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  969. struct iwl_mvm_phy_ctxt *phy_ctxt = (void *)ctx->drv_priv;
  970. mutex_lock(&mvm->mutex);
  971. iwl_mvm_phy_ctxt_remove(mvm, phy_ctxt);
  972. mutex_unlock(&mvm->mutex);
  973. }
  974. static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
  975. struct ieee80211_chanctx_conf *ctx,
  976. u32 changed)
  977. {
  978. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  979. struct iwl_mvm_phy_ctxt *phy_ctxt = (void *)ctx->drv_priv;
  980. mutex_lock(&mvm->mutex);
  981. iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
  982. ctx->rx_chains_static,
  983. ctx->rx_chains_dynamic);
  984. mutex_unlock(&mvm->mutex);
  985. }
  986. static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
  987. struct ieee80211_vif *vif,
  988. struct ieee80211_chanctx_conf *ctx)
  989. {
  990. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  991. struct iwl_mvm_phy_ctxt *phyctx = (void *)ctx->drv_priv;
  992. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  993. int ret;
  994. mutex_lock(&mvm->mutex);
  995. mvmvif->phy_ctxt = phyctx;
  996. switch (vif->type) {
  997. case NL80211_IFTYPE_AP:
  998. /*
  999. * The AP binding flow is handled as part of the start_ap flow
  1000. * (in bss_info_changed).
  1001. */
  1002. ret = 0;
  1003. goto out_unlock;
  1004. case NL80211_IFTYPE_STATION:
  1005. case NL80211_IFTYPE_ADHOC:
  1006. case NL80211_IFTYPE_MONITOR:
  1007. break;
  1008. default:
  1009. ret = -EINVAL;
  1010. goto out_unlock;
  1011. }
  1012. ret = iwl_mvm_binding_add_vif(mvm, vif);
  1013. if (ret)
  1014. goto out_unlock;
  1015. /*
  1016. * Setting the quota at this stage is only required for monitor
  1017. * interfaces. For the other types, the bss_info changed flow
  1018. * will handle quota settings.
  1019. */
  1020. if (vif->type == NL80211_IFTYPE_MONITOR) {
  1021. ret = iwl_mvm_update_quotas(mvm, vif);
  1022. if (ret)
  1023. goto out_remove_binding;
  1024. }
  1025. goto out_unlock;
  1026. out_remove_binding:
  1027. iwl_mvm_binding_remove_vif(mvm, vif);
  1028. out_unlock:
  1029. mutex_unlock(&mvm->mutex);
  1030. if (ret)
  1031. mvmvif->phy_ctxt = NULL;
  1032. return ret;
  1033. }
  1034. static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
  1035. struct ieee80211_vif *vif,
  1036. struct ieee80211_chanctx_conf *ctx)
  1037. {
  1038. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1039. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1040. mutex_lock(&mvm->mutex);
  1041. iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
  1042. if (vif->type == NL80211_IFTYPE_AP)
  1043. goto out_unlock;
  1044. iwl_mvm_binding_remove_vif(mvm, vif);
  1045. switch (vif->type) {
  1046. case NL80211_IFTYPE_MONITOR:
  1047. iwl_mvm_update_quotas(mvm, vif);
  1048. break;
  1049. default:
  1050. break;
  1051. }
  1052. out_unlock:
  1053. mvmvif->phy_ctxt = NULL;
  1054. mutex_unlock(&mvm->mutex);
  1055. }
  1056. static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
  1057. struct ieee80211_sta *sta,
  1058. bool set)
  1059. {
  1060. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1061. struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
  1062. if (!mvm_sta || !mvm_sta->vif) {
  1063. IWL_ERR(mvm, "Station is not associated to a vif\n");
  1064. return -EINVAL;
  1065. }
  1066. return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
  1067. }
  1068. struct ieee80211_ops iwl_mvm_hw_ops = {
  1069. .tx = iwl_mvm_mac_tx,
  1070. .ampdu_action = iwl_mvm_mac_ampdu_action,
  1071. .start = iwl_mvm_mac_start,
  1072. .restart_complete = iwl_mvm_mac_restart_complete,
  1073. .stop = iwl_mvm_mac_stop,
  1074. .add_interface = iwl_mvm_mac_add_interface,
  1075. .remove_interface = iwl_mvm_mac_remove_interface,
  1076. .config = iwl_mvm_mac_config,
  1077. .configure_filter = iwl_mvm_configure_filter,
  1078. .bss_info_changed = iwl_mvm_bss_info_changed,
  1079. .hw_scan = iwl_mvm_mac_hw_scan,
  1080. .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
  1081. .sta_state = iwl_mvm_mac_sta_state,
  1082. .sta_notify = iwl_mvm_mac_sta_notify,
  1083. .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
  1084. .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
  1085. .conf_tx = iwl_mvm_mac_conf_tx,
  1086. .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
  1087. .set_key = iwl_mvm_mac_set_key,
  1088. .update_tkip_key = iwl_mvm_mac_update_tkip_key,
  1089. .remain_on_channel = iwl_mvm_roc,
  1090. .cancel_remain_on_channel = iwl_mvm_cancel_roc,
  1091. .add_chanctx = iwl_mvm_add_chanctx,
  1092. .remove_chanctx = iwl_mvm_remove_chanctx,
  1093. .change_chanctx = iwl_mvm_change_chanctx,
  1094. .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
  1095. .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
  1096. .start_ap = iwl_mvm_start_ap,
  1097. .stop_ap = iwl_mvm_stop_ap,
  1098. .set_tim = iwl_mvm_set_tim,
  1099. #ifdef CONFIG_PM_SLEEP
  1100. /* look at d3.c */
  1101. .suspend = iwl_mvm_suspend,
  1102. .resume = iwl_mvm_resume,
  1103. .set_wakeup = iwl_mvm_set_wakeup,
  1104. .set_rekey_data = iwl_mvm_set_rekey_data,
  1105. #if IS_ENABLED(CONFIG_IPV6)
  1106. .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
  1107. #endif
  1108. .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
  1109. #endif
  1110. };