mac80211.c 39 KB

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