mac80211.c 36 KB

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