mac80211.c 38 KB

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