mac80211.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303
  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 - 2014 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 - 2014 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 <linux/if_arp.h>
  70. #include <net/mac80211.h>
  71. #include <net/ieee80211_radiotap.h>
  72. #include <net/tcp.h>
  73. #include "iwl-op-mode.h"
  74. #include "iwl-io.h"
  75. #include "mvm.h"
  76. #include "sta.h"
  77. #include "time-event.h"
  78. #include "iwl-eeprom-parse.h"
  79. #include "fw-api-scan.h"
  80. #include "iwl-phy-db.h"
  81. #include "testmode.h"
  82. static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
  83. {
  84. .max = 1,
  85. .types = BIT(NL80211_IFTYPE_STATION),
  86. },
  87. {
  88. .max = 1,
  89. .types = BIT(NL80211_IFTYPE_AP) |
  90. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  91. BIT(NL80211_IFTYPE_P2P_GO),
  92. },
  93. {
  94. .max = 1,
  95. .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
  96. },
  97. };
  98. static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
  99. {
  100. .num_different_channels = 1,
  101. .max_interfaces = 3,
  102. .limits = iwl_mvm_limits,
  103. .n_limits = ARRAY_SIZE(iwl_mvm_limits),
  104. },
  105. };
  106. #ifdef CONFIG_PM_SLEEP
  107. static const struct nl80211_wowlan_tcp_data_token_feature
  108. iwl_mvm_wowlan_tcp_token_feature = {
  109. .min_len = 0,
  110. .max_len = 255,
  111. .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
  112. };
  113. static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
  114. .tok = &iwl_mvm_wowlan_tcp_token_feature,
  115. .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
  116. sizeof(struct ethhdr) -
  117. sizeof(struct iphdr) -
  118. sizeof(struct tcphdr),
  119. .data_interval_max = 65535, /* __le16 in API */
  120. .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
  121. sizeof(struct ethhdr) -
  122. sizeof(struct iphdr) -
  123. sizeof(struct tcphdr),
  124. .seq = true,
  125. };
  126. #endif
  127. #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
  128. /*
  129. * Use the reserved field to indicate magic values.
  130. * these values will only be used internally by the driver,
  131. * and won't make it to the fw (reserved will be 0).
  132. * BC_FILTER_MAGIC_IP - configure the val of this attribute to
  133. * be the vif's ip address. in case there is not a single
  134. * ip address (0, or more than 1), this attribute will
  135. * be skipped.
  136. * BC_FILTER_MAGIC_MAC - set the val of this attribute to
  137. * the LSB bytes of the vif's mac address
  138. */
  139. enum {
  140. BC_FILTER_MAGIC_NONE = 0,
  141. BC_FILTER_MAGIC_IP,
  142. BC_FILTER_MAGIC_MAC,
  143. };
  144. static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
  145. {
  146. /* arp */
  147. .discard = 0,
  148. .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
  149. .attrs = {
  150. {
  151. /* frame type - arp, hw type - ethernet */
  152. .offset_type =
  153. BCAST_FILTER_OFFSET_PAYLOAD_START,
  154. .offset = sizeof(rfc1042_header),
  155. .val = cpu_to_be32(0x08060001),
  156. .mask = cpu_to_be32(0xffffffff),
  157. },
  158. {
  159. /* arp dest ip */
  160. .offset_type =
  161. BCAST_FILTER_OFFSET_PAYLOAD_START,
  162. .offset = sizeof(rfc1042_header) + 2 +
  163. sizeof(struct arphdr) +
  164. ETH_ALEN + sizeof(__be32) +
  165. ETH_ALEN,
  166. .mask = cpu_to_be32(0xffffffff),
  167. /* mark it as special field */
  168. .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
  169. },
  170. },
  171. },
  172. {
  173. /* dhcp offer bcast */
  174. .discard = 0,
  175. .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
  176. .attrs = {
  177. {
  178. /* udp dest port - 68 (bootp client)*/
  179. .offset_type = BCAST_FILTER_OFFSET_IP_END,
  180. .offset = offsetof(struct udphdr, dest),
  181. .val = cpu_to_be32(0x00440000),
  182. .mask = cpu_to_be32(0xffff0000),
  183. },
  184. {
  185. /* dhcp - lsb bytes of client hw address */
  186. .offset_type = BCAST_FILTER_OFFSET_IP_END,
  187. .offset = 38,
  188. .mask = cpu_to_be32(0xffffffff),
  189. /* mark it as special field */
  190. .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
  191. },
  192. },
  193. },
  194. /* last filter must be empty */
  195. {},
  196. };
  197. #endif
  198. void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
  199. {
  200. if (!iwl_mvm_is_d0i3_supported(mvm))
  201. return;
  202. IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
  203. WARN_ON(test_and_set_bit(ref_type, mvm->ref_bitmap));
  204. iwl_trans_ref(mvm->trans);
  205. }
  206. void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
  207. {
  208. if (!iwl_mvm_is_d0i3_supported(mvm))
  209. return;
  210. IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
  211. WARN_ON(!test_and_clear_bit(ref_type, mvm->ref_bitmap));
  212. iwl_trans_unref(mvm->trans);
  213. }
  214. static void
  215. iwl_mvm_unref_all_except(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref)
  216. {
  217. int i;
  218. if (!iwl_mvm_is_d0i3_supported(mvm))
  219. return;
  220. for_each_set_bit(i, mvm->ref_bitmap, IWL_MVM_REF_COUNT) {
  221. if (ref == i)
  222. continue;
  223. IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d\n", i);
  224. clear_bit(i, mvm->ref_bitmap);
  225. iwl_trans_unref(mvm->trans);
  226. }
  227. }
  228. static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
  229. {
  230. int i;
  231. memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
  232. for (i = 0; i < NUM_PHY_CTX; i++) {
  233. mvm->phy_ctxts[i].id = i;
  234. mvm->phy_ctxts[i].ref = 0;
  235. }
  236. }
  237. static int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm)
  238. {
  239. /* we create the 802.11 header and SSID element */
  240. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID)
  241. return mvm->fw->ucode_capa.max_probe_length - 24 - 2;
  242. return mvm->fw->ucode_capa.max_probe_length - 24 - 34;
  243. }
  244. int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
  245. {
  246. struct ieee80211_hw *hw = mvm->hw;
  247. int num_mac, ret, i;
  248. /* Tell mac80211 our characteristics */
  249. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  250. IEEE80211_HW_SPECTRUM_MGMT |
  251. IEEE80211_HW_REPORTS_TX_ACK_STATUS |
  252. IEEE80211_HW_QUEUE_CONTROL |
  253. IEEE80211_HW_WANT_MONITOR_VIF |
  254. IEEE80211_HW_SUPPORTS_PS |
  255. IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
  256. IEEE80211_HW_AMPDU_AGGREGATION |
  257. IEEE80211_HW_TIMING_BEACON_ONLY |
  258. IEEE80211_HW_CONNECTION_MONITOR |
  259. IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
  260. IEEE80211_HW_SUPPORTS_STATIC_SMPS;
  261. hw->queues = mvm->first_agg_queue;
  262. hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
  263. hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
  264. IEEE80211_RADIOTAP_MCS_HAVE_STBC;
  265. hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC;
  266. hw->rate_control_algorithm = "iwl-mvm-rs";
  267. /*
  268. * Enable 11w if advertised by firmware and software crypto
  269. * is not enabled (as the firmware will interpret some mgmt
  270. * packets, so enabling it with software crypto isn't safe)
  271. */
  272. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
  273. !iwlwifi_mod_params.sw_crypto)
  274. hw->flags |= IEEE80211_HW_MFP_CAPABLE;
  275. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT) {
  276. hw->flags |= IEEE80211_HW_SUPPORTS_UAPSD;
  277. hw->uapsd_queues = IWL_UAPSD_AC_INFO;
  278. hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
  279. }
  280. hw->sta_data_size = sizeof(struct iwl_mvm_sta);
  281. hw->vif_data_size = sizeof(struct iwl_mvm_vif);
  282. hw->chanctx_data_size = sizeof(u16);
  283. hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  284. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  285. BIT(NL80211_IFTYPE_AP) |
  286. BIT(NL80211_IFTYPE_P2P_GO) |
  287. BIT(NL80211_IFTYPE_P2P_DEVICE);
  288. /* IBSS has bugs in older versions */
  289. if (IWL_UCODE_API(mvm->fw->ucode_ver) >= 8)
  290. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
  291. hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
  292. hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
  293. REGULATORY_DISABLE_BEACON_HINTS;
  294. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD)
  295. hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
  296. hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
  297. hw->wiphy->n_iface_combinations =
  298. ARRAY_SIZE(iwl_mvm_iface_combinations);
  299. hw->wiphy->max_remain_on_channel_duration = 10000;
  300. hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
  301. /* Extract MAC address */
  302. memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
  303. hw->wiphy->addresses = mvm->addresses;
  304. hw->wiphy->n_addresses = 1;
  305. /* Extract additional MAC addresses if available */
  306. num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
  307. min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
  308. for (i = 1; i < num_mac; i++) {
  309. memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
  310. ETH_ALEN);
  311. mvm->addresses[i].addr[5]++;
  312. hw->wiphy->n_addresses++;
  313. }
  314. iwl_mvm_reset_phy_ctxts(mvm);
  315. hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
  316. hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
  317. if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
  318. hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  319. &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
  320. if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
  321. hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  322. &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
  323. hw->wiphy->hw_version = mvm->trans->hw_id;
  324. if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
  325. hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
  326. else
  327. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  328. if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SCHED_SCAN) {
  329. hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
  330. hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
  331. hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
  332. /* we create the 802.11 header and zero length SSID IE. */
  333. hw->wiphy->max_sched_scan_ie_len =
  334. SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
  335. }
  336. hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
  337. NL80211_FEATURE_P2P_GO_OPPPS |
  338. NL80211_FEATURE_LOW_PRIORITY_SCAN;
  339. mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
  340. /* currently FW API supports only one optional cipher scheme */
  341. if (mvm->fw->cs[0].cipher) {
  342. mvm->hw->n_cipher_schemes = 1;
  343. mvm->hw->cipher_schemes = &mvm->fw->cs[0];
  344. }
  345. #ifdef CONFIG_PM_SLEEP
  346. if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
  347. mvm->trans->ops->d3_suspend &&
  348. mvm->trans->ops->d3_resume &&
  349. device_can_wakeup(mvm->trans->dev)) {
  350. mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
  351. WIPHY_WOWLAN_DISCONNECT |
  352. WIPHY_WOWLAN_EAP_IDENTITY_REQ |
  353. WIPHY_WOWLAN_RFKILL_RELEASE;
  354. if (!iwlwifi_mod_params.sw_crypto)
  355. mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
  356. WIPHY_WOWLAN_GTK_REKEY_FAILURE |
  357. WIPHY_WOWLAN_4WAY_HANDSHAKE;
  358. mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
  359. mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
  360. mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
  361. mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
  362. hw->wiphy->wowlan = &mvm->wowlan;
  363. }
  364. #endif
  365. #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
  366. /* assign default bcast filtering configuration */
  367. mvm->bcast_filters = iwl_mvm_default_bcast_filters;
  368. #endif
  369. ret = iwl_mvm_leds_init(mvm);
  370. if (ret)
  371. return ret;
  372. ret = ieee80211_register_hw(mvm->hw);
  373. if (ret)
  374. iwl_mvm_leds_exit(mvm);
  375. return ret;
  376. }
  377. static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
  378. struct ieee80211_tx_control *control,
  379. struct sk_buff *skb)
  380. {
  381. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  382. struct ieee80211_sta *sta = control->sta;
  383. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  384. struct ieee80211_hdr *hdr = (void *)skb->data;
  385. if (iwl_mvm_is_radio_killed(mvm)) {
  386. IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
  387. goto drop;
  388. }
  389. if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
  390. !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status))
  391. goto drop;
  392. /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
  393. if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER &&
  394. ieee80211_is_mgmt(hdr->frame_control) &&
  395. !ieee80211_is_deauth(hdr->frame_control) &&
  396. !ieee80211_is_disassoc(hdr->frame_control) &&
  397. !ieee80211_is_action(hdr->frame_control)))
  398. sta = NULL;
  399. if (sta) {
  400. if (iwl_mvm_tx_skb(mvm, skb, sta))
  401. goto drop;
  402. return;
  403. }
  404. if (iwl_mvm_tx_skb_non_sta(mvm, skb))
  405. goto drop;
  406. return;
  407. drop:
  408. ieee80211_free_txskb(hw, skb);
  409. }
  410. static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
  411. struct ieee80211_vif *vif,
  412. enum ieee80211_ampdu_mlme_action action,
  413. struct ieee80211_sta *sta, u16 tid,
  414. u16 *ssn, u8 buf_size)
  415. {
  416. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  417. int ret;
  418. IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
  419. sta->addr, tid, action);
  420. if (!(mvm->nvm_data->sku_cap_11n_enable))
  421. return -EACCES;
  422. mutex_lock(&mvm->mutex);
  423. switch (action) {
  424. case IEEE80211_AMPDU_RX_START:
  425. if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) {
  426. ret = -EINVAL;
  427. break;
  428. }
  429. ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
  430. break;
  431. case IEEE80211_AMPDU_RX_STOP:
  432. ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
  433. break;
  434. case IEEE80211_AMPDU_TX_START:
  435. if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) {
  436. ret = -EINVAL;
  437. break;
  438. }
  439. ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
  440. break;
  441. case IEEE80211_AMPDU_TX_STOP_CONT:
  442. ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
  443. break;
  444. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  445. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  446. ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
  447. break;
  448. case IEEE80211_AMPDU_TX_OPERATIONAL:
  449. ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
  450. break;
  451. default:
  452. WARN_ON_ONCE(1);
  453. ret = -EINVAL;
  454. break;
  455. }
  456. mutex_unlock(&mvm->mutex);
  457. return ret;
  458. }
  459. static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
  460. struct ieee80211_vif *vif)
  461. {
  462. struct iwl_mvm *mvm = data;
  463. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  464. mvmvif->uploaded = false;
  465. mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
  466. /* does this make sense at all? */
  467. mvmvif->color++;
  468. spin_lock_bh(&mvm->time_event_lock);
  469. iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
  470. spin_unlock_bh(&mvm->time_event_lock);
  471. mvmvif->phy_ctxt = NULL;
  472. }
  473. static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
  474. {
  475. iwl_trans_stop_device(mvm->trans);
  476. mvm->scan_status = IWL_MVM_SCAN_NONE;
  477. /* just in case one was running */
  478. ieee80211_remain_on_channel_expired(mvm->hw);
  479. ieee80211_iterate_active_interfaces_atomic(
  480. mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
  481. iwl_mvm_cleanup_iterator, mvm);
  482. mvm->p2p_device_vif = NULL;
  483. mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
  484. iwl_mvm_reset_phy_ctxts(mvm);
  485. memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
  486. memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
  487. ieee80211_wake_queues(mvm->hw);
  488. /* cleanup all stale references (scan, roc), but keep the
  489. * ucode_down ref until reconfig is complete */
  490. iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
  491. mvm->vif_count = 0;
  492. mvm->rx_ba_sessions = 0;
  493. }
  494. static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
  495. {
  496. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  497. int ret;
  498. mutex_lock(&mvm->mutex);
  499. /* Clean up some internal and mac80211 state on restart */
  500. if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
  501. iwl_mvm_restart_cleanup(mvm);
  502. ret = iwl_mvm_up(mvm);
  503. mutex_unlock(&mvm->mutex);
  504. return ret;
  505. }
  506. static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
  507. {
  508. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  509. int ret;
  510. mutex_lock(&mvm->mutex);
  511. clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
  512. ret = iwl_mvm_update_quotas(mvm, NULL);
  513. if (ret)
  514. IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
  515. ret);
  516. /* allow transport/FW low power modes */
  517. iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
  518. mutex_unlock(&mvm->mutex);
  519. }
  520. static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
  521. {
  522. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  523. flush_work(&mvm->d0i3_exit_work);
  524. flush_work(&mvm->async_handlers_wk);
  525. mutex_lock(&mvm->mutex);
  526. /* disallow low power states when the FW is down */
  527. iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
  528. /* async_handlers_wk is now blocked */
  529. /*
  530. * The work item could be running or queued if the
  531. * ROC time event stops just as we get here.
  532. */
  533. cancel_work_sync(&mvm->roc_done_wk);
  534. iwl_trans_stop_device(mvm->trans);
  535. iwl_mvm_async_handlers_purge(mvm);
  536. /* async_handlers_list is empty and will stay empty: HW is stopped */
  537. /* the fw is stopped, the aux sta is dead: clean up driver state */
  538. iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
  539. mutex_unlock(&mvm->mutex);
  540. /*
  541. * The worker might have been waiting for the mutex, let it run and
  542. * discover that its list is now empty.
  543. */
  544. cancel_work_sync(&mvm->async_handlers_wk);
  545. }
  546. static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
  547. {
  548. u16 i;
  549. lockdep_assert_held(&mvm->mutex);
  550. for (i = 0; i < NUM_PHY_CTX; i++)
  551. if (!mvm->phy_ctxts[i].ref)
  552. return &mvm->phy_ctxts[i];
  553. IWL_ERR(mvm, "No available PHY context\n");
  554. return NULL;
  555. }
  556. static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  557. s8 tx_power)
  558. {
  559. /* FW is in charge of regulatory enforcement */
  560. struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
  561. .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
  562. .pwr_restriction = cpu_to_le16(tx_power),
  563. };
  564. return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, CMD_SYNC,
  565. sizeof(reduce_txpwr_cmd),
  566. &reduce_txpwr_cmd);
  567. }
  568. static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
  569. struct ieee80211_vif *vif)
  570. {
  571. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  572. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  573. int ret;
  574. /*
  575. * Not much to do here. The stack will not allow interface
  576. * types or combinations that we didn't advertise, so we
  577. * don't really have to check the types.
  578. */
  579. mutex_lock(&mvm->mutex);
  580. /* Allocate resources for the MAC context, and add it to the fw */
  581. ret = iwl_mvm_mac_ctxt_init(mvm, vif);
  582. if (ret)
  583. goto out_unlock;
  584. /* Counting number of interfaces is needed for legacy PM */
  585. if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
  586. mvm->vif_count++;
  587. /*
  588. * The AP binding flow can be done only after the beacon
  589. * template is configured (which happens only in the mac80211
  590. * start_ap() flow), and adding the broadcast station can happen
  591. * only after the binding.
  592. * In addition, since modifying the MAC before adding a bcast
  593. * station is not allowed by the FW, delay the adding of MAC context to
  594. * the point where we can also add the bcast station.
  595. * In short: there's not much we can do at this point, other than
  596. * allocating resources :)
  597. */
  598. if (vif->type == NL80211_IFTYPE_AP ||
  599. vif->type == NL80211_IFTYPE_ADHOC) {
  600. u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif);
  601. ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta,
  602. qmask,
  603. ieee80211_vif_type_p2p(vif));
  604. if (ret) {
  605. IWL_ERR(mvm, "Failed to allocate bcast sta\n");
  606. goto out_release;
  607. }
  608. iwl_mvm_vif_dbgfs_register(mvm, vif);
  609. goto out_unlock;
  610. }
  611. ret = iwl_mvm_mac_ctxt_add(mvm, vif);
  612. if (ret)
  613. goto out_release;
  614. ret = iwl_mvm_power_update_mac(mvm, vif);
  615. if (ret)
  616. goto out_release;
  617. /* beacon filtering */
  618. ret = iwl_mvm_disable_beacon_filter(mvm, vif, CMD_SYNC);
  619. if (ret)
  620. goto out_remove_mac;
  621. if (!mvm->bf_allowed_vif &&
  622. vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
  623. mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED){
  624. mvm->bf_allowed_vif = mvmvif;
  625. vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
  626. IEEE80211_VIF_SUPPORTS_CQM_RSSI;
  627. }
  628. /*
  629. * P2P_DEVICE interface does not have a channel context assigned to it,
  630. * so a dedicated PHY context is allocated to it and the corresponding
  631. * MAC context is bound to it at this stage.
  632. */
  633. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  634. mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
  635. if (!mvmvif->phy_ctxt) {
  636. ret = -ENOSPC;
  637. goto out_free_bf;
  638. }
  639. iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
  640. ret = iwl_mvm_binding_add_vif(mvm, vif);
  641. if (ret)
  642. goto out_unref_phy;
  643. ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
  644. if (ret)
  645. goto out_unbind;
  646. /* Save a pointer to p2p device vif, so it can later be used to
  647. * update the p2p device MAC when a GO is started/stopped */
  648. mvm->p2p_device_vif = vif;
  649. }
  650. iwl_mvm_vif_dbgfs_register(mvm, vif);
  651. goto out_unlock;
  652. out_unbind:
  653. iwl_mvm_binding_remove_vif(mvm, vif);
  654. out_unref_phy:
  655. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  656. out_free_bf:
  657. if (mvm->bf_allowed_vif == mvmvif) {
  658. mvm->bf_allowed_vif = NULL;
  659. vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
  660. IEEE80211_VIF_SUPPORTS_CQM_RSSI);
  661. }
  662. out_remove_mac:
  663. mvmvif->phy_ctxt = NULL;
  664. iwl_mvm_mac_ctxt_remove(mvm, vif);
  665. out_release:
  666. if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
  667. mvm->vif_count--;
  668. iwl_mvm_mac_ctxt_release(mvm, vif);
  669. out_unlock:
  670. mutex_unlock(&mvm->mutex);
  671. return ret;
  672. }
  673. static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
  674. struct ieee80211_vif *vif)
  675. {
  676. u32 tfd_msk = 0, ac;
  677. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  678. if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
  679. tfd_msk |= BIT(vif->hw_queue[ac]);
  680. if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
  681. tfd_msk |= BIT(vif->cab_queue);
  682. if (tfd_msk) {
  683. mutex_lock(&mvm->mutex);
  684. iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
  685. mutex_unlock(&mvm->mutex);
  686. }
  687. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  688. /*
  689. * Flush the ROC worker which will flush the OFFCHANNEL queue.
  690. * We assume here that all the packets sent to the OFFCHANNEL
  691. * queue are sent in ROC session.
  692. */
  693. flush_work(&mvm->roc_done_wk);
  694. } else {
  695. /*
  696. * By now, all the AC queues are empty. The AGG queues are
  697. * empty too. We already got all the Tx responses for all the
  698. * packets in the queues. The drain work can have been
  699. * triggered. Flush it.
  700. */
  701. flush_work(&mvm->sta_drained_wk);
  702. }
  703. }
  704. static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
  705. struct ieee80211_vif *vif)
  706. {
  707. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  708. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  709. iwl_mvm_prepare_mac_removal(mvm, vif);
  710. mutex_lock(&mvm->mutex);
  711. if (mvm->bf_allowed_vif == mvmvif) {
  712. mvm->bf_allowed_vif = NULL;
  713. vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
  714. IEEE80211_VIF_SUPPORTS_CQM_RSSI);
  715. }
  716. iwl_mvm_vif_dbgfs_clean(mvm, vif);
  717. /*
  718. * For AP/GO interface, the tear down of the resources allocated to the
  719. * interface is be handled as part of the stop_ap flow.
  720. */
  721. if (vif->type == NL80211_IFTYPE_AP ||
  722. vif->type == NL80211_IFTYPE_ADHOC) {
  723. #ifdef CONFIG_NL80211_TESTMODE
  724. if (vif == mvm->noa_vif) {
  725. mvm->noa_vif = NULL;
  726. mvm->noa_duration = 0;
  727. }
  728. #endif
  729. iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
  730. goto out_release;
  731. }
  732. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  733. mvm->p2p_device_vif = NULL;
  734. iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
  735. iwl_mvm_binding_remove_vif(mvm, vif);
  736. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  737. mvmvif->phy_ctxt = NULL;
  738. }
  739. if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
  740. mvm->vif_count--;
  741. iwl_mvm_power_update_mac(mvm, vif);
  742. iwl_mvm_mac_ctxt_remove(mvm, vif);
  743. out_release:
  744. iwl_mvm_mac_ctxt_release(mvm, vif);
  745. mutex_unlock(&mvm->mutex);
  746. }
  747. static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
  748. {
  749. return 0;
  750. }
  751. struct iwl_mvm_mc_iter_data {
  752. struct iwl_mvm *mvm;
  753. int port_id;
  754. };
  755. static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
  756. struct ieee80211_vif *vif)
  757. {
  758. struct iwl_mvm_mc_iter_data *data = _data;
  759. struct iwl_mvm *mvm = data->mvm;
  760. struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
  761. int ret, len;
  762. /* if we don't have free ports, mcast frames will be dropped */
  763. if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
  764. return;
  765. if (vif->type != NL80211_IFTYPE_STATION ||
  766. !vif->bss_conf.assoc)
  767. return;
  768. cmd->port_id = data->port_id++;
  769. memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
  770. len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
  771. ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_SYNC, len, cmd);
  772. if (ret)
  773. IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
  774. }
  775. static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
  776. {
  777. struct iwl_mvm_mc_iter_data iter_data = {
  778. .mvm = mvm,
  779. };
  780. lockdep_assert_held(&mvm->mutex);
  781. if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
  782. return;
  783. ieee80211_iterate_active_interfaces(
  784. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  785. iwl_mvm_mc_iface_iterator, &iter_data);
  786. }
  787. static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
  788. struct netdev_hw_addr_list *mc_list)
  789. {
  790. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  791. struct iwl_mcast_filter_cmd *cmd;
  792. struct netdev_hw_addr *addr;
  793. int addr_count = netdev_hw_addr_list_count(mc_list);
  794. bool pass_all = false;
  795. int len;
  796. if (addr_count > MAX_MCAST_FILTERING_ADDRESSES) {
  797. pass_all = true;
  798. addr_count = 0;
  799. }
  800. len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
  801. cmd = kzalloc(len, GFP_ATOMIC);
  802. if (!cmd)
  803. return 0;
  804. if (pass_all) {
  805. cmd->pass_all = 1;
  806. return (u64)(unsigned long)cmd;
  807. }
  808. netdev_hw_addr_list_for_each(addr, mc_list) {
  809. IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
  810. cmd->count, addr->addr);
  811. memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
  812. addr->addr, ETH_ALEN);
  813. cmd->count++;
  814. }
  815. return (u64)(unsigned long)cmd;
  816. }
  817. static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
  818. unsigned int changed_flags,
  819. unsigned int *total_flags,
  820. u64 multicast)
  821. {
  822. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  823. struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
  824. mutex_lock(&mvm->mutex);
  825. /* replace previous configuration */
  826. kfree(mvm->mcast_filter_cmd);
  827. mvm->mcast_filter_cmd = cmd;
  828. if (!cmd)
  829. goto out;
  830. iwl_mvm_recalc_multicast(mvm);
  831. out:
  832. mutex_unlock(&mvm->mutex);
  833. *total_flags = 0;
  834. }
  835. #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
  836. struct iwl_bcast_iter_data {
  837. struct iwl_mvm *mvm;
  838. struct iwl_bcast_filter_cmd *cmd;
  839. u8 current_filter;
  840. };
  841. static void
  842. iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
  843. const struct iwl_fw_bcast_filter *in_filter,
  844. struct iwl_fw_bcast_filter *out_filter)
  845. {
  846. struct iwl_fw_bcast_filter_attr *attr;
  847. int i;
  848. memcpy(out_filter, in_filter, sizeof(*out_filter));
  849. for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
  850. attr = &out_filter->attrs[i];
  851. if (!attr->mask)
  852. break;
  853. switch (attr->reserved1) {
  854. case cpu_to_le16(BC_FILTER_MAGIC_IP):
  855. if (vif->bss_conf.arp_addr_cnt != 1) {
  856. attr->mask = 0;
  857. continue;
  858. }
  859. attr->val = vif->bss_conf.arp_addr_list[0];
  860. break;
  861. case cpu_to_le16(BC_FILTER_MAGIC_MAC):
  862. attr->val = *(__be32 *)&vif->addr[2];
  863. break;
  864. default:
  865. break;
  866. }
  867. attr->reserved1 = 0;
  868. out_filter->num_attrs++;
  869. }
  870. }
  871. static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
  872. struct ieee80211_vif *vif)
  873. {
  874. struct iwl_bcast_iter_data *data = _data;
  875. struct iwl_mvm *mvm = data->mvm;
  876. struct iwl_bcast_filter_cmd *cmd = data->cmd;
  877. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  878. struct iwl_fw_bcast_mac *bcast_mac;
  879. int i;
  880. if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
  881. return;
  882. bcast_mac = &cmd->macs[mvmvif->id];
  883. /* enable filtering only for associated stations */
  884. if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc)
  885. return;
  886. bcast_mac->default_discard = 1;
  887. /* copy all configured filters */
  888. for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
  889. /*
  890. * Make sure we don't exceed our filters limit.
  891. * if there is still a valid filter to be configured,
  892. * be on the safe side and just allow bcast for this mac.
  893. */
  894. if (WARN_ON_ONCE(data->current_filter >=
  895. ARRAY_SIZE(cmd->filters))) {
  896. bcast_mac->default_discard = 0;
  897. bcast_mac->attached_filters = 0;
  898. break;
  899. }
  900. iwl_mvm_set_bcast_filter(vif,
  901. &mvm->bcast_filters[i],
  902. &cmd->filters[data->current_filter]);
  903. /* skip current filter if it contains no attributes */
  904. if (!cmd->filters[data->current_filter].num_attrs)
  905. continue;
  906. /* attach the filter to current mac */
  907. bcast_mac->attached_filters |=
  908. cpu_to_le16(BIT(data->current_filter));
  909. data->current_filter++;
  910. }
  911. }
  912. bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
  913. struct iwl_bcast_filter_cmd *cmd)
  914. {
  915. struct iwl_bcast_iter_data iter_data = {
  916. .mvm = mvm,
  917. .cmd = cmd,
  918. };
  919. memset(cmd, 0, sizeof(*cmd));
  920. cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
  921. cmd->max_macs = ARRAY_SIZE(cmd->macs);
  922. #ifdef CONFIG_IWLWIFI_DEBUGFS
  923. /* use debugfs filters/macs if override is configured */
  924. if (mvm->dbgfs_bcast_filtering.override) {
  925. memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
  926. sizeof(cmd->filters));
  927. memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
  928. sizeof(cmd->macs));
  929. return true;
  930. }
  931. #endif
  932. /* if no filters are configured, do nothing */
  933. if (!mvm->bcast_filters)
  934. return false;
  935. /* configure and attach these filters for each associated sta vif */
  936. ieee80211_iterate_active_interfaces(
  937. mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
  938. iwl_mvm_bcast_filter_iterator, &iter_data);
  939. return true;
  940. }
  941. static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
  942. struct ieee80211_vif *vif)
  943. {
  944. struct iwl_bcast_filter_cmd cmd;
  945. if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
  946. return 0;
  947. if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
  948. return 0;
  949. return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, CMD_SYNC,
  950. sizeof(cmd), &cmd);
  951. }
  952. #else
  953. static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
  954. struct ieee80211_vif *vif)
  955. {
  956. return 0;
  957. }
  958. #endif
  959. static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
  960. struct ieee80211_vif *vif,
  961. struct ieee80211_bss_conf *bss_conf,
  962. u32 changes)
  963. {
  964. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  965. int ret;
  966. /*
  967. * Re-calculate the tsf id, as the master-slave relations depend on the
  968. * beacon interval, which was not known when the station interface was
  969. * added.
  970. */
  971. if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
  972. iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
  973. ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
  974. if (ret)
  975. IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
  976. if (changes & BSS_CHANGED_ASSOC) {
  977. if (bss_conf->assoc) {
  978. /* add quota for this interface */
  979. ret = iwl_mvm_update_quotas(mvm, vif);
  980. if (ret) {
  981. IWL_ERR(mvm, "failed to update quotas\n");
  982. return;
  983. }
  984. if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
  985. &mvm->status)) {
  986. /*
  987. * If we're restarting then the firmware will
  988. * obviously have lost synchronisation with
  989. * the AP. It will attempt to synchronise by
  990. * itself, but we can make it more reliable by
  991. * scheduling a session protection time event.
  992. *
  993. * The firmware needs to receive a beacon to
  994. * catch up with synchronisation, use 110% of
  995. * the beacon interval.
  996. *
  997. * Set a large maximum delay to allow for more
  998. * than a single interface.
  999. */
  1000. u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
  1001. iwl_mvm_protect_session(mvm, vif, dur, dur,
  1002. 5 * dur);
  1003. }
  1004. iwl_mvm_sf_update(mvm, vif, false);
  1005. iwl_mvm_power_vif_assoc(mvm, vif);
  1006. if (vif->p2p)
  1007. iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
  1008. } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
  1009. /*
  1010. * If update fails - SF might be running in associated
  1011. * mode while disassociated - which is forbidden.
  1012. */
  1013. WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
  1014. "Failed to update SF upon disassociation\n");
  1015. /* remove AP station now that the MAC is unassoc */
  1016. ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
  1017. if (ret)
  1018. IWL_ERR(mvm, "failed to remove AP station\n");
  1019. if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
  1020. mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
  1021. mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
  1022. /* remove quota for this interface */
  1023. ret = iwl_mvm_update_quotas(mvm, NULL);
  1024. if (ret)
  1025. IWL_ERR(mvm, "failed to update quotas\n");
  1026. if (vif->p2p)
  1027. iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
  1028. }
  1029. iwl_mvm_recalc_multicast(mvm);
  1030. iwl_mvm_configure_bcast_filter(mvm, vif);
  1031. /* reset rssi values */
  1032. mvmvif->bf_data.ave_beacon_signal = 0;
  1033. iwl_mvm_bt_coex_vif_change(mvm);
  1034. iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
  1035. IEEE80211_SMPS_AUTOMATIC);
  1036. } else if (changes & BSS_CHANGED_BEACON_INFO) {
  1037. /*
  1038. * We received a beacon _after_ association so
  1039. * remove the session protection.
  1040. */
  1041. iwl_mvm_remove_time_event(mvm, mvmvif,
  1042. &mvmvif->time_event_data);
  1043. WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, CMD_SYNC));
  1044. } else if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS |
  1045. BSS_CHANGED_QOS)) {
  1046. ret = iwl_mvm_power_update_mac(mvm, vif);
  1047. if (ret)
  1048. IWL_ERR(mvm, "failed to update power mode\n");
  1049. }
  1050. if (changes & BSS_CHANGED_TXPOWER) {
  1051. IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
  1052. bss_conf->txpower);
  1053. iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
  1054. }
  1055. if (changes & BSS_CHANGED_CQM) {
  1056. IWL_DEBUG_MAC80211(mvm, "cqm info_changed");
  1057. /* reset cqm events tracking */
  1058. mvmvif->bf_data.last_cqm_event = 0;
  1059. ret = iwl_mvm_update_beacon_filter(mvm, vif, false, CMD_SYNC);
  1060. if (ret)
  1061. IWL_ERR(mvm, "failed to update CQM thresholds\n");
  1062. }
  1063. if (changes & BSS_CHANGED_ARP_FILTER) {
  1064. IWL_DEBUG_MAC80211(mvm, "arp filter changed");
  1065. iwl_mvm_configure_bcast_filter(mvm, vif);
  1066. }
  1067. }
  1068. static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
  1069. struct ieee80211_vif *vif)
  1070. {
  1071. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1072. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1073. int ret;
  1074. mutex_lock(&mvm->mutex);
  1075. /* Send the beacon template */
  1076. ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
  1077. if (ret)
  1078. goto out_unlock;
  1079. /*
  1080. * Re-calculate the tsf id, as the master-slave relations depend on the
  1081. * beacon interval, which was not known when the AP interface was added.
  1082. */
  1083. if (vif->type == NL80211_IFTYPE_AP)
  1084. iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
  1085. /* Add the mac context */
  1086. ret = iwl_mvm_mac_ctxt_add(mvm, vif);
  1087. if (ret)
  1088. goto out_unlock;
  1089. /* Perform the binding */
  1090. ret = iwl_mvm_binding_add_vif(mvm, vif);
  1091. if (ret)
  1092. goto out_remove;
  1093. /* Send the bcast station. At this stage the TBTT and DTIM time events
  1094. * are added and applied to the scheduler */
  1095. ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
  1096. if (ret)
  1097. goto out_unbind;
  1098. /* must be set before quota calculations */
  1099. mvmvif->ap_ibss_active = true;
  1100. /* power updated needs to be done before quotas */
  1101. iwl_mvm_power_update_mac(mvm, vif);
  1102. ret = iwl_mvm_update_quotas(mvm, vif);
  1103. if (ret)
  1104. goto out_quota_failed;
  1105. /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
  1106. if (vif->p2p && mvm->p2p_device_vif)
  1107. iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
  1108. iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
  1109. iwl_mvm_bt_coex_vif_change(mvm);
  1110. mutex_unlock(&mvm->mutex);
  1111. return 0;
  1112. out_quota_failed:
  1113. iwl_mvm_power_update_mac(mvm, vif);
  1114. mvmvif->ap_ibss_active = false;
  1115. iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
  1116. out_unbind:
  1117. iwl_mvm_binding_remove_vif(mvm, vif);
  1118. out_remove:
  1119. iwl_mvm_mac_ctxt_remove(mvm, vif);
  1120. out_unlock:
  1121. mutex_unlock(&mvm->mutex);
  1122. return ret;
  1123. }
  1124. static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
  1125. struct ieee80211_vif *vif)
  1126. {
  1127. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1128. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1129. iwl_mvm_prepare_mac_removal(mvm, vif);
  1130. mutex_lock(&mvm->mutex);
  1131. mvmvif->ap_ibss_active = false;
  1132. iwl_mvm_bt_coex_vif_change(mvm);
  1133. iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
  1134. /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
  1135. if (vif->p2p && mvm->p2p_device_vif)
  1136. iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
  1137. iwl_mvm_update_quotas(mvm, NULL);
  1138. iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
  1139. iwl_mvm_binding_remove_vif(mvm, vif);
  1140. iwl_mvm_power_update_mac(mvm, vif);
  1141. iwl_mvm_mac_ctxt_remove(mvm, vif);
  1142. mutex_unlock(&mvm->mutex);
  1143. }
  1144. static void
  1145. iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
  1146. struct ieee80211_vif *vif,
  1147. struct ieee80211_bss_conf *bss_conf,
  1148. u32 changes)
  1149. {
  1150. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1151. /* Changes will be applied when the AP/IBSS is started */
  1152. if (!mvmvif->ap_ibss_active)
  1153. return;
  1154. if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
  1155. BSS_CHANGED_BANDWIDTH) &&
  1156. iwl_mvm_mac_ctxt_changed(mvm, vif))
  1157. IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
  1158. /* Need to send a new beacon template to the FW */
  1159. if (changes & BSS_CHANGED_BEACON &&
  1160. iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
  1161. IWL_WARN(mvm, "Failed updating beacon data\n");
  1162. }
  1163. static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
  1164. struct ieee80211_vif *vif,
  1165. struct ieee80211_bss_conf *bss_conf,
  1166. u32 changes)
  1167. {
  1168. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1169. mutex_lock(&mvm->mutex);
  1170. switch (vif->type) {
  1171. case NL80211_IFTYPE_STATION:
  1172. iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
  1173. break;
  1174. case NL80211_IFTYPE_AP:
  1175. case NL80211_IFTYPE_ADHOC:
  1176. iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
  1177. break;
  1178. default:
  1179. /* shouldn't happen */
  1180. WARN_ON_ONCE(1);
  1181. }
  1182. mutex_unlock(&mvm->mutex);
  1183. }
  1184. static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
  1185. struct ieee80211_vif *vif,
  1186. struct cfg80211_scan_request *req)
  1187. {
  1188. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1189. int ret;
  1190. if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS)
  1191. return -EINVAL;
  1192. mutex_lock(&mvm->mutex);
  1193. switch (mvm->scan_status) {
  1194. case IWL_MVM_SCAN_SCHED:
  1195. ret = iwl_mvm_sched_scan_stop(mvm);
  1196. if (ret) {
  1197. ret = -EBUSY;
  1198. goto out;
  1199. }
  1200. break;
  1201. case IWL_MVM_SCAN_NONE:
  1202. break;
  1203. default:
  1204. ret = -EBUSY;
  1205. goto out;
  1206. }
  1207. iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
  1208. ret = iwl_mvm_scan_request(mvm, vif, req);
  1209. if (ret)
  1210. iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
  1211. out:
  1212. mutex_unlock(&mvm->mutex);
  1213. /* make sure to flush the Rx handler before the next scan arrives */
  1214. iwl_mvm_wait_for_async_handlers(mvm);
  1215. return ret;
  1216. }
  1217. static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
  1218. struct ieee80211_vif *vif)
  1219. {
  1220. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1221. mutex_lock(&mvm->mutex);
  1222. iwl_mvm_cancel_scan(mvm);
  1223. mutex_unlock(&mvm->mutex);
  1224. }
  1225. static void
  1226. iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
  1227. struct ieee80211_sta *sta, u16 tids,
  1228. int num_frames,
  1229. enum ieee80211_frame_release_type reason,
  1230. bool more_data)
  1231. {
  1232. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1233. /* Called when we need to transmit (a) frame(s) from mac80211 */
  1234. iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
  1235. tids, more_data, false);
  1236. }
  1237. static void
  1238. iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
  1239. struct ieee80211_sta *sta, u16 tids,
  1240. int num_frames,
  1241. enum ieee80211_frame_release_type reason,
  1242. bool more_data)
  1243. {
  1244. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1245. /* Called when we need to transmit (a) frame(s) from agg queue */
  1246. iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
  1247. tids, more_data, true);
  1248. }
  1249. static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
  1250. struct ieee80211_vif *vif,
  1251. enum sta_notify_cmd cmd,
  1252. struct ieee80211_sta *sta)
  1253. {
  1254. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1255. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  1256. int tid;
  1257. switch (cmd) {
  1258. case STA_NOTIFY_SLEEP:
  1259. if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
  1260. ieee80211_sta_block_awake(hw, sta, true);
  1261. spin_lock_bh(&mvmsta->lock);
  1262. for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
  1263. struct iwl_mvm_tid_data *tid_data;
  1264. tid_data = &mvmsta->tid_data[tid];
  1265. if (tid_data->state != IWL_AGG_ON &&
  1266. tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA)
  1267. continue;
  1268. if (iwl_mvm_tid_queued(tid_data) == 0)
  1269. continue;
  1270. ieee80211_sta_set_buffered(sta, tid, true);
  1271. }
  1272. spin_unlock_bh(&mvmsta->lock);
  1273. /*
  1274. * The fw updates the STA to be asleep. Tx packets on the Tx
  1275. * queues to this station will not be transmitted. The fw will
  1276. * send a Tx response with TX_STATUS_FAIL_DEST_PS.
  1277. */
  1278. break;
  1279. case STA_NOTIFY_AWAKE:
  1280. if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
  1281. break;
  1282. iwl_mvm_sta_modify_ps_wake(mvm, sta);
  1283. break;
  1284. default:
  1285. break;
  1286. }
  1287. }
  1288. static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
  1289. struct ieee80211_vif *vif,
  1290. struct ieee80211_sta *sta)
  1291. {
  1292. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1293. struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
  1294. /*
  1295. * This is called before mac80211 does RCU synchronisation,
  1296. * so here we already invalidate our internal RCU-protected
  1297. * station pointer. The rest of the code will thus no longer
  1298. * be able to find the station this way, and we don't rely
  1299. * on further RCU synchronisation after the sta_state()
  1300. * callback deleted the station.
  1301. */
  1302. mutex_lock(&mvm->mutex);
  1303. if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
  1304. rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
  1305. ERR_PTR(-ENOENT));
  1306. mutex_unlock(&mvm->mutex);
  1307. }
  1308. static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
  1309. struct ieee80211_vif *vif,
  1310. struct ieee80211_sta *sta,
  1311. enum ieee80211_sta_state old_state,
  1312. enum ieee80211_sta_state new_state)
  1313. {
  1314. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1315. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1316. int ret;
  1317. IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
  1318. sta->addr, old_state, new_state);
  1319. /* this would be a mac80211 bug ... but don't crash */
  1320. if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
  1321. return -EINVAL;
  1322. /* if a STA is being removed, reuse its ID */
  1323. flush_work(&mvm->sta_drained_wk);
  1324. mutex_lock(&mvm->mutex);
  1325. if (old_state == IEEE80211_STA_NOTEXIST &&
  1326. new_state == IEEE80211_STA_NONE) {
  1327. /*
  1328. * Firmware bug - it'll crash if the beacon interval is less
  1329. * than 16. We can't avoid connecting at all, so refuse the
  1330. * station state change, this will cause mac80211 to abandon
  1331. * attempts to connect to this AP, and eventually wpa_s will
  1332. * blacklist the AP...
  1333. */
  1334. if (vif->type == NL80211_IFTYPE_STATION &&
  1335. vif->bss_conf.beacon_int < 16) {
  1336. IWL_ERR(mvm,
  1337. "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
  1338. sta->addr, vif->bss_conf.beacon_int);
  1339. ret = -EINVAL;
  1340. goto out_unlock;
  1341. }
  1342. ret = iwl_mvm_add_sta(mvm, vif, sta);
  1343. } else if (old_state == IEEE80211_STA_NONE &&
  1344. new_state == IEEE80211_STA_AUTH) {
  1345. ret = 0;
  1346. } else if (old_state == IEEE80211_STA_AUTH &&
  1347. new_state == IEEE80211_STA_ASSOC) {
  1348. ret = iwl_mvm_update_sta(mvm, vif, sta);
  1349. if (ret == 0)
  1350. iwl_mvm_rs_rate_init(mvm, sta,
  1351. mvmvif->phy_ctxt->channel->band,
  1352. true);
  1353. } else if (old_state == IEEE80211_STA_ASSOC &&
  1354. new_state == IEEE80211_STA_AUTHORIZED) {
  1355. /* enable beacon filtering */
  1356. if (vif->bss_conf.dtim_period)
  1357. WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif,
  1358. CMD_SYNC));
  1359. ret = 0;
  1360. } else if (old_state == IEEE80211_STA_AUTHORIZED &&
  1361. new_state == IEEE80211_STA_ASSOC) {
  1362. /* disable beacon filtering */
  1363. WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, CMD_SYNC));
  1364. ret = 0;
  1365. } else if (old_state == IEEE80211_STA_ASSOC &&
  1366. new_state == IEEE80211_STA_AUTH) {
  1367. ret = 0;
  1368. } else if (old_state == IEEE80211_STA_AUTH &&
  1369. new_state == IEEE80211_STA_NONE) {
  1370. ret = 0;
  1371. } else if (old_state == IEEE80211_STA_NONE &&
  1372. new_state == IEEE80211_STA_NOTEXIST) {
  1373. ret = iwl_mvm_rm_sta(mvm, vif, sta);
  1374. } else {
  1375. ret = -EIO;
  1376. }
  1377. out_unlock:
  1378. mutex_unlock(&mvm->mutex);
  1379. return ret;
  1380. }
  1381. static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  1382. {
  1383. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1384. mvm->rts_threshold = value;
  1385. return 0;
  1386. }
  1387. static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
  1388. struct ieee80211_vif *vif,
  1389. struct ieee80211_sta *sta, u32 changed)
  1390. {
  1391. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1392. if (vif->type == NL80211_IFTYPE_STATION &&
  1393. changed & IEEE80211_RC_NSS_CHANGED)
  1394. iwl_mvm_sf_update(mvm, vif, false);
  1395. }
  1396. static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
  1397. struct ieee80211_vif *vif, u16 ac,
  1398. const struct ieee80211_tx_queue_params *params)
  1399. {
  1400. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1401. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1402. mvmvif->queue_params[ac] = *params;
  1403. /*
  1404. * No need to update right away, we'll get BSS_CHANGED_QOS
  1405. * The exception is P2P_DEVICE interface which needs immediate update.
  1406. */
  1407. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  1408. int ret;
  1409. mutex_lock(&mvm->mutex);
  1410. ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
  1411. mutex_unlock(&mvm->mutex);
  1412. return ret;
  1413. }
  1414. return 0;
  1415. }
  1416. static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
  1417. struct ieee80211_vif *vif)
  1418. {
  1419. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1420. u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
  1421. 200 + vif->bss_conf.beacon_int);
  1422. u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
  1423. 100 + vif->bss_conf.beacon_int);
  1424. if (WARN_ON_ONCE(vif->bss_conf.assoc))
  1425. return;
  1426. mutex_lock(&mvm->mutex);
  1427. /* Try really hard to protect the session and hear a beacon */
  1428. iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500);
  1429. mutex_unlock(&mvm->mutex);
  1430. }
  1431. static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
  1432. struct ieee80211_vif *vif,
  1433. struct cfg80211_sched_scan_request *req,
  1434. struct ieee80211_sched_scan_ies *ies)
  1435. {
  1436. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1437. int ret;
  1438. mutex_lock(&mvm->mutex);
  1439. switch (mvm->scan_status) {
  1440. case IWL_MVM_SCAN_OS:
  1441. IWL_DEBUG_SCAN(mvm, "Stopping previous scan for sched_scan\n");
  1442. ret = iwl_mvm_cancel_scan(mvm);
  1443. if (ret) {
  1444. ret = -EBUSY;
  1445. goto out;
  1446. }
  1447. /*
  1448. * iwl_mvm_rx_scan_complete() will be called soon but will
  1449. * not reset the scan status as it won't be IWL_MVM_SCAN_OS
  1450. * any more since we queue the next scan immediately (below).
  1451. * We make sure it is called before the next scan starts by
  1452. * flushing the async-handlers work.
  1453. */
  1454. break;
  1455. case IWL_MVM_SCAN_NONE:
  1456. break;
  1457. default:
  1458. ret = -EBUSY;
  1459. goto out;
  1460. }
  1461. mvm->scan_status = IWL_MVM_SCAN_SCHED;
  1462. ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies);
  1463. if (ret)
  1464. goto err;
  1465. ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
  1466. if (ret)
  1467. goto err;
  1468. ret = iwl_mvm_sched_scan_start(mvm, req);
  1469. if (!ret)
  1470. goto out;
  1471. err:
  1472. mvm->scan_status = IWL_MVM_SCAN_NONE;
  1473. out:
  1474. mutex_unlock(&mvm->mutex);
  1475. /* make sure to flush the Rx handler before the next scan arrives */
  1476. iwl_mvm_wait_for_async_handlers(mvm);
  1477. return ret;
  1478. }
  1479. static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
  1480. struct ieee80211_vif *vif)
  1481. {
  1482. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1483. int ret;
  1484. mutex_lock(&mvm->mutex);
  1485. ret = iwl_mvm_sched_scan_stop(mvm);
  1486. mutex_unlock(&mvm->mutex);
  1487. iwl_mvm_wait_for_async_handlers(mvm);
  1488. return ret;
  1489. }
  1490. static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
  1491. enum set_key_cmd cmd,
  1492. struct ieee80211_vif *vif,
  1493. struct ieee80211_sta *sta,
  1494. struct ieee80211_key_conf *key)
  1495. {
  1496. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1497. int ret;
  1498. if (iwlwifi_mod_params.sw_crypto) {
  1499. IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
  1500. return -EOPNOTSUPP;
  1501. }
  1502. switch (key->cipher) {
  1503. case WLAN_CIPHER_SUITE_TKIP:
  1504. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  1505. /* fall-through */
  1506. case WLAN_CIPHER_SUITE_CCMP:
  1507. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  1508. break;
  1509. case WLAN_CIPHER_SUITE_AES_CMAC:
  1510. WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
  1511. break;
  1512. case WLAN_CIPHER_SUITE_WEP40:
  1513. case WLAN_CIPHER_SUITE_WEP104:
  1514. /*
  1515. * Support for TX only, at least for now, so accept
  1516. * the key and do nothing else. Then mac80211 will
  1517. * pass it for TX but we don't have to use it for RX.
  1518. */
  1519. return 0;
  1520. default:
  1521. /* currently FW supports only one optional cipher scheme */
  1522. if (hw->n_cipher_schemes &&
  1523. hw->cipher_schemes->cipher == key->cipher)
  1524. key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
  1525. else
  1526. return -EOPNOTSUPP;
  1527. }
  1528. mutex_lock(&mvm->mutex);
  1529. switch (cmd) {
  1530. case SET_KEY:
  1531. if ((vif->type == NL80211_IFTYPE_ADHOC ||
  1532. vif->type == NL80211_IFTYPE_AP) && !sta) {
  1533. /*
  1534. * GTK on AP interface is a TX-only key, return 0;
  1535. * on IBSS they're per-station and because we're lazy
  1536. * we don't support them for RX, so do the same.
  1537. */
  1538. ret = 0;
  1539. key->hw_key_idx = STA_KEY_IDX_INVALID;
  1540. break;
  1541. }
  1542. IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
  1543. ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
  1544. if (ret) {
  1545. IWL_WARN(mvm, "set key failed\n");
  1546. /*
  1547. * can't add key for RX, but we don't need it
  1548. * in the device for TX so still return 0
  1549. */
  1550. key->hw_key_idx = STA_KEY_IDX_INVALID;
  1551. ret = 0;
  1552. }
  1553. break;
  1554. case DISABLE_KEY:
  1555. if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
  1556. ret = 0;
  1557. break;
  1558. }
  1559. IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
  1560. ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
  1561. break;
  1562. default:
  1563. ret = -EINVAL;
  1564. }
  1565. mutex_unlock(&mvm->mutex);
  1566. return ret;
  1567. }
  1568. static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
  1569. struct ieee80211_vif *vif,
  1570. struct ieee80211_key_conf *keyconf,
  1571. struct ieee80211_sta *sta,
  1572. u32 iv32, u16 *phase1key)
  1573. {
  1574. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1575. if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
  1576. return;
  1577. iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
  1578. }
  1579. static int iwl_mvm_roc(struct ieee80211_hw *hw,
  1580. struct ieee80211_vif *vif,
  1581. struct ieee80211_channel *channel,
  1582. int duration,
  1583. enum ieee80211_roc_type type)
  1584. {
  1585. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1586. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1587. struct cfg80211_chan_def chandef;
  1588. struct iwl_mvm_phy_ctxt *phy_ctxt;
  1589. int ret, i;
  1590. IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
  1591. duration, type);
  1592. if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
  1593. IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
  1594. return -EINVAL;
  1595. }
  1596. mutex_lock(&mvm->mutex);
  1597. for (i = 0; i < NUM_PHY_CTX; i++) {
  1598. phy_ctxt = &mvm->phy_ctxts[i];
  1599. if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
  1600. continue;
  1601. if (phy_ctxt->ref && channel == phy_ctxt->channel) {
  1602. /*
  1603. * Unbind the P2P_DEVICE from the current PHY context,
  1604. * and if the PHY context is not used remove it.
  1605. */
  1606. ret = iwl_mvm_binding_remove_vif(mvm, vif);
  1607. if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
  1608. goto out_unlock;
  1609. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  1610. /* Bind the P2P_DEVICE to the current PHY Context */
  1611. mvmvif->phy_ctxt = phy_ctxt;
  1612. ret = iwl_mvm_binding_add_vif(mvm, vif);
  1613. if (WARN(ret, "Failed binding P2P_DEVICE\n"))
  1614. goto out_unlock;
  1615. iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
  1616. goto schedule_time_event;
  1617. }
  1618. }
  1619. /* Need to update the PHY context only if the ROC channel changed */
  1620. if (channel == mvmvif->phy_ctxt->channel)
  1621. goto schedule_time_event;
  1622. cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
  1623. /*
  1624. * Change the PHY context configuration as it is currently referenced
  1625. * only by the P2P Device MAC
  1626. */
  1627. if (mvmvif->phy_ctxt->ref == 1) {
  1628. ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
  1629. &chandef, 1, 1);
  1630. if (ret)
  1631. goto out_unlock;
  1632. } else {
  1633. /*
  1634. * The PHY context is shared with other MACs. Need to remove the
  1635. * P2P Device from the binding, allocate an new PHY context and
  1636. * create a new binding
  1637. */
  1638. phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
  1639. if (!phy_ctxt) {
  1640. ret = -ENOSPC;
  1641. goto out_unlock;
  1642. }
  1643. ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
  1644. 1, 1);
  1645. if (ret) {
  1646. IWL_ERR(mvm, "Failed to change PHY context\n");
  1647. goto out_unlock;
  1648. }
  1649. /* Unbind the P2P_DEVICE from the current PHY context */
  1650. ret = iwl_mvm_binding_remove_vif(mvm, vif);
  1651. if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
  1652. goto out_unlock;
  1653. iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
  1654. /* Bind the P2P_DEVICE to the new allocated PHY context */
  1655. mvmvif->phy_ctxt = phy_ctxt;
  1656. ret = iwl_mvm_binding_add_vif(mvm, vif);
  1657. if (WARN(ret, "Failed binding P2P_DEVICE\n"))
  1658. goto out_unlock;
  1659. iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
  1660. }
  1661. schedule_time_event:
  1662. /* Schedule the time events */
  1663. ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
  1664. out_unlock:
  1665. mutex_unlock(&mvm->mutex);
  1666. IWL_DEBUG_MAC80211(mvm, "leave\n");
  1667. return ret;
  1668. }
  1669. static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
  1670. {
  1671. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1672. IWL_DEBUG_MAC80211(mvm, "enter\n");
  1673. mutex_lock(&mvm->mutex);
  1674. iwl_mvm_stop_p2p_roc(mvm);
  1675. mutex_unlock(&mvm->mutex);
  1676. IWL_DEBUG_MAC80211(mvm, "leave\n");
  1677. return 0;
  1678. }
  1679. static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
  1680. struct ieee80211_chanctx_conf *ctx)
  1681. {
  1682. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1683. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  1684. struct iwl_mvm_phy_ctxt *phy_ctxt;
  1685. int ret;
  1686. IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
  1687. mutex_lock(&mvm->mutex);
  1688. phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
  1689. if (!phy_ctxt) {
  1690. ret = -ENOSPC;
  1691. goto out;
  1692. }
  1693. ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
  1694. ctx->rx_chains_static,
  1695. ctx->rx_chains_dynamic);
  1696. if (ret) {
  1697. IWL_ERR(mvm, "Failed to add PHY context\n");
  1698. goto out;
  1699. }
  1700. iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
  1701. *phy_ctxt_id = phy_ctxt->id;
  1702. out:
  1703. mutex_unlock(&mvm->mutex);
  1704. return ret;
  1705. }
  1706. static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
  1707. struct ieee80211_chanctx_conf *ctx)
  1708. {
  1709. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1710. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  1711. struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
  1712. mutex_lock(&mvm->mutex);
  1713. iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
  1714. mutex_unlock(&mvm->mutex);
  1715. }
  1716. static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
  1717. struct ieee80211_chanctx_conf *ctx,
  1718. u32 changed)
  1719. {
  1720. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1721. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  1722. struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
  1723. if (WARN_ONCE((phy_ctxt->ref > 1) &&
  1724. (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
  1725. IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
  1726. IEEE80211_CHANCTX_CHANGE_RADAR |
  1727. IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
  1728. "Cannot change PHY. Ref=%d, changed=0x%X\n",
  1729. phy_ctxt->ref, changed))
  1730. return;
  1731. mutex_lock(&mvm->mutex);
  1732. iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
  1733. ctx->rx_chains_static,
  1734. ctx->rx_chains_dynamic);
  1735. iwl_mvm_bt_coex_vif_change(mvm);
  1736. mutex_unlock(&mvm->mutex);
  1737. }
  1738. static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
  1739. struct ieee80211_vif *vif,
  1740. struct ieee80211_chanctx_conf *ctx)
  1741. {
  1742. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1743. u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
  1744. struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
  1745. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1746. int ret;
  1747. mutex_lock(&mvm->mutex);
  1748. mvmvif->phy_ctxt = phy_ctxt;
  1749. switch (vif->type) {
  1750. case NL80211_IFTYPE_AP:
  1751. case NL80211_IFTYPE_ADHOC:
  1752. /*
  1753. * The AP binding flow is handled as part of the start_ap flow
  1754. * (in bss_info_changed), similarly for IBSS.
  1755. */
  1756. ret = 0;
  1757. goto out_unlock;
  1758. case NL80211_IFTYPE_STATION:
  1759. case NL80211_IFTYPE_MONITOR:
  1760. break;
  1761. default:
  1762. ret = -EINVAL;
  1763. goto out_unlock;
  1764. }
  1765. ret = iwl_mvm_binding_add_vif(mvm, vif);
  1766. if (ret)
  1767. goto out_unlock;
  1768. /*
  1769. * Power state must be updated before quotas,
  1770. * otherwise fw will complain.
  1771. */
  1772. iwl_mvm_power_update_mac(mvm, vif);
  1773. /* Setting the quota at this stage is only required for monitor
  1774. * interfaces. For the other types, the bss_info changed flow
  1775. * will handle quota settings.
  1776. */
  1777. if (vif->type == NL80211_IFTYPE_MONITOR) {
  1778. mvmvif->monitor_active = true;
  1779. ret = iwl_mvm_update_quotas(mvm, vif);
  1780. if (ret)
  1781. goto out_remove_binding;
  1782. }
  1783. goto out_unlock;
  1784. out_remove_binding:
  1785. iwl_mvm_binding_remove_vif(mvm, vif);
  1786. iwl_mvm_power_update_mac(mvm, vif);
  1787. out_unlock:
  1788. mutex_unlock(&mvm->mutex);
  1789. if (ret)
  1790. mvmvif->phy_ctxt = NULL;
  1791. return ret;
  1792. }
  1793. static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
  1794. struct ieee80211_vif *vif,
  1795. struct ieee80211_chanctx_conf *ctx)
  1796. {
  1797. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1798. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1799. mutex_lock(&mvm->mutex);
  1800. iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
  1801. switch (vif->type) {
  1802. case NL80211_IFTYPE_AP:
  1803. case NL80211_IFTYPE_ADHOC:
  1804. goto out_unlock;
  1805. case NL80211_IFTYPE_MONITOR:
  1806. mvmvif->monitor_active = false;
  1807. iwl_mvm_update_quotas(mvm, NULL);
  1808. break;
  1809. default:
  1810. break;
  1811. }
  1812. iwl_mvm_binding_remove_vif(mvm, vif);
  1813. iwl_mvm_power_update_mac(mvm, vif);
  1814. out_unlock:
  1815. mvmvif->phy_ctxt = NULL;
  1816. mutex_unlock(&mvm->mutex);
  1817. }
  1818. static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
  1819. struct ieee80211_sta *sta,
  1820. bool set)
  1821. {
  1822. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1823. struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
  1824. if (!mvm_sta || !mvm_sta->vif) {
  1825. IWL_ERR(mvm, "Station is not associated to a vif\n");
  1826. return -EINVAL;
  1827. }
  1828. return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
  1829. }
  1830. #ifdef CONFIG_NL80211_TESTMODE
  1831. static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
  1832. [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
  1833. [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
  1834. [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
  1835. };
  1836. static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
  1837. struct ieee80211_vif *vif,
  1838. void *data, int len)
  1839. {
  1840. struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
  1841. int err;
  1842. u32 noa_duration;
  1843. err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
  1844. if (err)
  1845. return err;
  1846. if (!tb[IWL_MVM_TM_ATTR_CMD])
  1847. return -EINVAL;
  1848. switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
  1849. case IWL_MVM_TM_CMD_SET_NOA:
  1850. if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
  1851. !vif->bss_conf.enable_beacon ||
  1852. !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
  1853. return -EINVAL;
  1854. noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
  1855. if (noa_duration >= vif->bss_conf.beacon_int)
  1856. return -EINVAL;
  1857. mvm->noa_duration = noa_duration;
  1858. mvm->noa_vif = vif;
  1859. return iwl_mvm_update_quotas(mvm, NULL);
  1860. case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
  1861. /* must be associated client vif - ignore authorized */
  1862. if (!vif || vif->type != NL80211_IFTYPE_STATION ||
  1863. !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
  1864. !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
  1865. return -EINVAL;
  1866. if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
  1867. return iwl_mvm_enable_beacon_filter(mvm, vif,
  1868. CMD_SYNC);
  1869. return iwl_mvm_disable_beacon_filter(mvm, vif, CMD_SYNC);
  1870. }
  1871. return -EOPNOTSUPP;
  1872. }
  1873. static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
  1874. struct ieee80211_vif *vif,
  1875. void *data, int len)
  1876. {
  1877. struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
  1878. int err;
  1879. mutex_lock(&mvm->mutex);
  1880. err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
  1881. mutex_unlock(&mvm->mutex);
  1882. return err;
  1883. }
  1884. #endif
  1885. const struct ieee80211_ops iwl_mvm_hw_ops = {
  1886. .tx = iwl_mvm_mac_tx,
  1887. .ampdu_action = iwl_mvm_mac_ampdu_action,
  1888. .start = iwl_mvm_mac_start,
  1889. .restart_complete = iwl_mvm_mac_restart_complete,
  1890. .stop = iwl_mvm_mac_stop,
  1891. .add_interface = iwl_mvm_mac_add_interface,
  1892. .remove_interface = iwl_mvm_mac_remove_interface,
  1893. .config = iwl_mvm_mac_config,
  1894. .prepare_multicast = iwl_mvm_prepare_multicast,
  1895. .configure_filter = iwl_mvm_configure_filter,
  1896. .bss_info_changed = iwl_mvm_bss_info_changed,
  1897. .hw_scan = iwl_mvm_mac_hw_scan,
  1898. .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
  1899. .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
  1900. .sta_state = iwl_mvm_mac_sta_state,
  1901. .sta_notify = iwl_mvm_mac_sta_notify,
  1902. .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
  1903. .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
  1904. .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
  1905. .sta_rc_update = iwl_mvm_sta_rc_update,
  1906. .conf_tx = iwl_mvm_mac_conf_tx,
  1907. .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
  1908. .sched_scan_start = iwl_mvm_mac_sched_scan_start,
  1909. .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
  1910. .set_key = iwl_mvm_mac_set_key,
  1911. .update_tkip_key = iwl_mvm_mac_update_tkip_key,
  1912. .remain_on_channel = iwl_mvm_roc,
  1913. .cancel_remain_on_channel = iwl_mvm_cancel_roc,
  1914. .add_chanctx = iwl_mvm_add_chanctx,
  1915. .remove_chanctx = iwl_mvm_remove_chanctx,
  1916. .change_chanctx = iwl_mvm_change_chanctx,
  1917. .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
  1918. .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
  1919. .start_ap = iwl_mvm_start_ap_ibss,
  1920. .stop_ap = iwl_mvm_stop_ap_ibss,
  1921. .join_ibss = iwl_mvm_start_ap_ibss,
  1922. .leave_ibss = iwl_mvm_stop_ap_ibss,
  1923. .set_tim = iwl_mvm_set_tim,
  1924. CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
  1925. #ifdef CONFIG_PM_SLEEP
  1926. /* look at d3.c */
  1927. .suspend = iwl_mvm_suspend,
  1928. .resume = iwl_mvm_resume,
  1929. .set_wakeup = iwl_mvm_set_wakeup,
  1930. .set_rekey_data = iwl_mvm_set_rekey_data,
  1931. #if IS_ENABLED(CONFIG_IPV6)
  1932. .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
  1933. #endif
  1934. .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
  1935. #endif
  1936. };