mac-ctxt.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503
  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. * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
  10. * Copyright(c) 2015 - 2016 Intel Deutschland GmbH
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of version 2 of the GNU General Public License as
  14. * published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  24. * USA
  25. *
  26. * The full GNU General Public License is included in this distribution
  27. * in the file called COPYING.
  28. *
  29. * Contact Information:
  30. * Intel Linux Wireless <linuxwifi@intel.com>
  31. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  32. *
  33. * BSD LICENSE
  34. *
  35. * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
  36. * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
  37. * Copyright(c) 2015 - 2016 Intel Deutschland GmbH
  38. * All rights reserved.
  39. *
  40. * Redistribution and use in source and binary forms, with or without
  41. * modification, are permitted provided that the following conditions
  42. * are met:
  43. *
  44. * * Redistributions of source code must retain the above copyright
  45. * notice, this list of conditions and the following disclaimer.
  46. * * Redistributions in binary form must reproduce the above copyright
  47. * notice, this list of conditions and the following disclaimer in
  48. * the documentation and/or other materials provided with the
  49. * distribution.
  50. * * Neither the name Intel Corporation nor the names of its
  51. * contributors may be used to endorse or promote products derived
  52. * from this software without specific prior written permission.
  53. *
  54. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  55. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  56. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  57. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  58. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  59. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  60. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  61. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  62. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  63. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  64. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  65. *
  66. *****************************************************************************/
  67. #include <linux/etherdevice.h>
  68. #include <net/mac80211.h>
  69. #include "iwl-io.h"
  70. #include "iwl-prph.h"
  71. #include "fw-api.h"
  72. #include "mvm.h"
  73. #include "time-event.h"
  74. #include "fw-dbg.h"
  75. const u8 iwl_mvm_ac_to_tx_fifo[] = {
  76. IWL_MVM_TX_FIFO_VO,
  77. IWL_MVM_TX_FIFO_VI,
  78. IWL_MVM_TX_FIFO_BE,
  79. IWL_MVM_TX_FIFO_BK,
  80. };
  81. struct iwl_mvm_mac_iface_iterator_data {
  82. struct iwl_mvm *mvm;
  83. struct ieee80211_vif *vif;
  84. unsigned long available_mac_ids[BITS_TO_LONGS(NUM_MAC_INDEX_DRIVER)];
  85. unsigned long available_tsf_ids[BITS_TO_LONGS(NUM_TSF_IDS)];
  86. enum iwl_tsf_id preferred_tsf;
  87. bool found_vif;
  88. };
  89. struct iwl_mvm_hw_queues_iface_iterator_data {
  90. struct ieee80211_vif *exclude_vif;
  91. unsigned long used_hw_queues;
  92. };
  93. static void iwl_mvm_mac_tsf_id_iter(void *_data, u8 *mac,
  94. struct ieee80211_vif *vif)
  95. {
  96. struct iwl_mvm_mac_iface_iterator_data *data = _data;
  97. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  98. u16 min_bi;
  99. /* Skip the interface for which we are trying to assign a tsf_id */
  100. if (vif == data->vif)
  101. return;
  102. /*
  103. * The TSF is a hardware/firmware resource, there are 4 and
  104. * the driver should assign and free them as needed. However,
  105. * there are cases where 2 MACs should share the same TSF ID
  106. * for the purpose of clock sync, an optimization to avoid
  107. * clock drift causing overlapping TBTTs/DTIMs for a GO and
  108. * client in the system.
  109. *
  110. * The firmware will decide according to the MAC type which
  111. * will be the master and slave. Clients that need to sync
  112. * with a remote station will be the master, and an AP or GO
  113. * will be the slave.
  114. *
  115. * Depending on the new interface type it can be slaved to
  116. * or become the master of an existing interface.
  117. */
  118. switch (data->vif->type) {
  119. case NL80211_IFTYPE_STATION:
  120. /*
  121. * The new interface is a client, so if the one we're iterating
  122. * is an AP, and the beacon interval of the AP is a multiple or
  123. * divisor of the beacon interval of the client, the same TSF
  124. * should be used to avoid drift between the new client and
  125. * existing AP. The existing AP will get drift updates from the
  126. * new client context in this case.
  127. */
  128. if (vif->type != NL80211_IFTYPE_AP ||
  129. data->preferred_tsf != NUM_TSF_IDS ||
  130. !test_bit(mvmvif->tsf_id, data->available_tsf_ids))
  131. break;
  132. min_bi = min(data->vif->bss_conf.beacon_int,
  133. vif->bss_conf.beacon_int);
  134. if (!min_bi)
  135. break;
  136. if ((data->vif->bss_conf.beacon_int -
  137. vif->bss_conf.beacon_int) % min_bi == 0) {
  138. data->preferred_tsf = mvmvif->tsf_id;
  139. return;
  140. }
  141. break;
  142. case NL80211_IFTYPE_AP:
  143. /*
  144. * The new interface is AP/GO, so if its beacon interval is a
  145. * multiple or a divisor of the beacon interval of an existing
  146. * interface, it should get drift updates from an existing
  147. * client or use the same TSF as an existing GO. There's no
  148. * drift between TSFs internally but if they used different
  149. * TSFs then a new client MAC could update one of them and
  150. * cause drift that way.
  151. */
  152. if ((vif->type != NL80211_IFTYPE_AP &&
  153. vif->type != NL80211_IFTYPE_STATION) ||
  154. data->preferred_tsf != NUM_TSF_IDS ||
  155. !test_bit(mvmvif->tsf_id, data->available_tsf_ids))
  156. break;
  157. min_bi = min(data->vif->bss_conf.beacon_int,
  158. vif->bss_conf.beacon_int);
  159. if (!min_bi)
  160. break;
  161. if ((data->vif->bss_conf.beacon_int -
  162. vif->bss_conf.beacon_int) % min_bi == 0) {
  163. data->preferred_tsf = mvmvif->tsf_id;
  164. return;
  165. }
  166. break;
  167. default:
  168. /*
  169. * For all other interface types there's no need to
  170. * take drift into account. Either they're exclusive
  171. * like IBSS and monitor, or we don't care much about
  172. * their TSF (like P2P Device), but we won't be able
  173. * to share the TSF resource.
  174. */
  175. break;
  176. }
  177. /*
  178. * Unless we exited above, we can't share the TSF resource
  179. * that the virtual interface we're iterating over is using
  180. * with the new one, so clear the available bit and if this
  181. * was the preferred one, reset that as well.
  182. */
  183. __clear_bit(mvmvif->tsf_id, data->available_tsf_ids);
  184. if (data->preferred_tsf == mvmvif->tsf_id)
  185. data->preferred_tsf = NUM_TSF_IDS;
  186. }
  187. /*
  188. * Get the mask of the queues used by the vif
  189. */
  190. u32 iwl_mvm_mac_get_queues_mask(struct ieee80211_vif *vif)
  191. {
  192. u32 qmask = 0, ac;
  193. if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
  194. return BIT(IWL_MVM_OFFCHANNEL_QUEUE);
  195. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  196. if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
  197. qmask |= BIT(vif->hw_queue[ac]);
  198. }
  199. if (vif->type == NL80211_IFTYPE_AP)
  200. qmask |= BIT(vif->cab_queue);
  201. return qmask;
  202. }
  203. static void iwl_mvm_iface_hw_queues_iter(void *_data, u8 *mac,
  204. struct ieee80211_vif *vif)
  205. {
  206. struct iwl_mvm_hw_queues_iface_iterator_data *data = _data;
  207. /* exclude the given vif */
  208. if (vif == data->exclude_vif)
  209. return;
  210. data->used_hw_queues |= iwl_mvm_mac_get_queues_mask(vif);
  211. }
  212. static void iwl_mvm_mac_sta_hw_queues_iter(void *_data,
  213. struct ieee80211_sta *sta)
  214. {
  215. struct iwl_mvm_hw_queues_iface_iterator_data *data = _data;
  216. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  217. /* Mark the queues used by the sta */
  218. data->used_hw_queues |= mvmsta->tfd_queue_msk;
  219. }
  220. unsigned long iwl_mvm_get_used_hw_queues(struct iwl_mvm *mvm,
  221. struct ieee80211_vif *exclude_vif)
  222. {
  223. u8 sta_id;
  224. struct iwl_mvm_hw_queues_iface_iterator_data data = {
  225. .exclude_vif = exclude_vif,
  226. .used_hw_queues =
  227. BIT(IWL_MVM_OFFCHANNEL_QUEUE) |
  228. BIT(mvm->aux_queue) |
  229. BIT(IWL_MVM_CMD_QUEUE),
  230. };
  231. lockdep_assert_held(&mvm->mutex);
  232. /* mark all VIF used hw queues */
  233. ieee80211_iterate_active_interfaces_atomic(
  234. mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
  235. iwl_mvm_iface_hw_queues_iter, &data);
  236. /* don't assign the same hw queues as TDLS stations */
  237. ieee80211_iterate_stations_atomic(mvm->hw,
  238. iwl_mvm_mac_sta_hw_queues_iter,
  239. &data);
  240. /*
  241. * Some TDLS stations may be removed but are in the process of being
  242. * drained. Don't touch their queues.
  243. */
  244. for_each_set_bit(sta_id, mvm->sta_drained, IWL_MVM_STATION_COUNT)
  245. data.used_hw_queues |= mvm->tfd_drained[sta_id];
  246. return data.used_hw_queues;
  247. }
  248. static void iwl_mvm_mac_iface_iterator(void *_data, u8 *mac,
  249. struct ieee80211_vif *vif)
  250. {
  251. struct iwl_mvm_mac_iface_iterator_data *data = _data;
  252. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  253. /* Iterator may already find the interface being added -- skip it */
  254. if (vif == data->vif) {
  255. data->found_vif = true;
  256. return;
  257. }
  258. /* Mark MAC IDs as used by clearing the available bit, and
  259. * (below) mark TSFs as used if their existing use is not
  260. * compatible with the new interface type.
  261. * No locking or atomic bit operations are needed since the
  262. * data is on the stack of the caller function.
  263. */
  264. __clear_bit(mvmvif->id, data->available_mac_ids);
  265. /* find a suitable tsf_id */
  266. iwl_mvm_mac_tsf_id_iter(_data, mac, vif);
  267. }
  268. void iwl_mvm_mac_ctxt_recalc_tsf_id(struct iwl_mvm *mvm,
  269. struct ieee80211_vif *vif)
  270. {
  271. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  272. struct iwl_mvm_mac_iface_iterator_data data = {
  273. .mvm = mvm,
  274. .vif = vif,
  275. .available_tsf_ids = { (1 << NUM_TSF_IDS) - 1 },
  276. /* no preference yet */
  277. .preferred_tsf = NUM_TSF_IDS,
  278. };
  279. ieee80211_iterate_active_interfaces_atomic(
  280. mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
  281. iwl_mvm_mac_tsf_id_iter, &data);
  282. if (data.preferred_tsf != NUM_TSF_IDS)
  283. mvmvif->tsf_id = data.preferred_tsf;
  284. else if (!test_bit(mvmvif->tsf_id, data.available_tsf_ids))
  285. mvmvif->tsf_id = find_first_bit(data.available_tsf_ids,
  286. NUM_TSF_IDS);
  287. }
  288. static int iwl_mvm_mac_ctxt_allocate_resources(struct iwl_mvm *mvm,
  289. struct ieee80211_vif *vif)
  290. {
  291. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  292. struct iwl_mvm_mac_iface_iterator_data data = {
  293. .mvm = mvm,
  294. .vif = vif,
  295. .available_mac_ids = { (1 << NUM_MAC_INDEX_DRIVER) - 1 },
  296. .available_tsf_ids = { (1 << NUM_TSF_IDS) - 1 },
  297. /* no preference yet */
  298. .preferred_tsf = NUM_TSF_IDS,
  299. .found_vif = false,
  300. };
  301. u32 ac;
  302. int ret, i;
  303. unsigned long used_hw_queues;
  304. /*
  305. * Allocate a MAC ID and a TSF for this MAC, along with the queues
  306. * and other resources.
  307. */
  308. /*
  309. * Before the iterator, we start with all MAC IDs and TSFs available.
  310. *
  311. * During iteration, all MAC IDs are cleared that are in use by other
  312. * virtual interfaces, and all TSF IDs are cleared that can't be used
  313. * by this new virtual interface because they're used by an interface
  314. * that can't share it with the new one.
  315. * At the same time, we check if there's a preferred TSF in the case
  316. * that we should share it with another interface.
  317. */
  318. /* Currently, MAC ID 0 should be used only for the managed/IBSS vif */
  319. switch (vif->type) {
  320. case NL80211_IFTYPE_ADHOC:
  321. break;
  322. case NL80211_IFTYPE_STATION:
  323. if (!vif->p2p)
  324. break;
  325. /* fall through */
  326. default:
  327. __clear_bit(0, data.available_mac_ids);
  328. }
  329. ieee80211_iterate_active_interfaces_atomic(
  330. mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
  331. iwl_mvm_mac_iface_iterator, &data);
  332. used_hw_queues = iwl_mvm_get_used_hw_queues(mvm, vif);
  333. /*
  334. * In the case we're getting here during resume, it's similar to
  335. * firmware restart, and with RESUME_ALL the iterator will find
  336. * the vif being added already.
  337. * We don't want to reassign any IDs in either case since doing
  338. * so would probably assign different IDs (as interfaces aren't
  339. * necessarily added in the same order), but the old IDs were
  340. * preserved anyway, so skip ID assignment for both resume and
  341. * recovery.
  342. */
  343. if (data.found_vif)
  344. return 0;
  345. /* Therefore, in recovery, we can't get here */
  346. if (WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)))
  347. return -EBUSY;
  348. mvmvif->id = find_first_bit(data.available_mac_ids,
  349. NUM_MAC_INDEX_DRIVER);
  350. if (mvmvif->id == NUM_MAC_INDEX_DRIVER) {
  351. IWL_ERR(mvm, "Failed to init MAC context - no free ID!\n");
  352. ret = -EIO;
  353. goto exit_fail;
  354. }
  355. if (data.preferred_tsf != NUM_TSF_IDS)
  356. mvmvif->tsf_id = data.preferred_tsf;
  357. else
  358. mvmvif->tsf_id = find_first_bit(data.available_tsf_ids,
  359. NUM_TSF_IDS);
  360. if (mvmvif->tsf_id == NUM_TSF_IDS) {
  361. IWL_ERR(mvm, "Failed to init MAC context - no free TSF!\n");
  362. ret = -EIO;
  363. goto exit_fail;
  364. }
  365. mvmvif->color = 0;
  366. INIT_LIST_HEAD(&mvmvif->time_event_data.list);
  367. mvmvif->time_event_data.id = TE_MAX;
  368. /* No need to allocate data queues to P2P Device MAC.*/
  369. if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
  370. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  371. vif->hw_queue[ac] = IEEE80211_INVAL_HW_QUEUE;
  372. return 0;
  373. }
  374. /* Find available queues, and allocate them to the ACs */
  375. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  376. u8 queue = find_first_zero_bit(&used_hw_queues,
  377. mvm->first_agg_queue);
  378. if (queue >= mvm->first_agg_queue) {
  379. IWL_ERR(mvm, "Failed to allocate queue\n");
  380. ret = -EIO;
  381. goto exit_fail;
  382. }
  383. __set_bit(queue, &used_hw_queues);
  384. vif->hw_queue[ac] = queue;
  385. }
  386. /* Allocate the CAB queue for softAP and GO interfaces */
  387. if (vif->type == NL80211_IFTYPE_AP) {
  388. u8 queue = find_first_zero_bit(&used_hw_queues,
  389. mvm->first_agg_queue);
  390. if (queue >= mvm->first_agg_queue) {
  391. IWL_ERR(mvm, "Failed to allocate cab queue\n");
  392. ret = -EIO;
  393. goto exit_fail;
  394. }
  395. vif->cab_queue = queue;
  396. } else {
  397. vif->cab_queue = IEEE80211_INVAL_HW_QUEUE;
  398. }
  399. mvmvif->bcast_sta.sta_id = IWL_MVM_STATION_COUNT;
  400. mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
  401. for (i = 0; i < NUM_IWL_MVM_SMPS_REQ; i++)
  402. mvmvif->smps_requests[i] = IEEE80211_SMPS_AUTOMATIC;
  403. return 0;
  404. exit_fail:
  405. memset(mvmvif, 0, sizeof(struct iwl_mvm_vif));
  406. memset(vif->hw_queue, IEEE80211_INVAL_HW_QUEUE, sizeof(vif->hw_queue));
  407. vif->cab_queue = IEEE80211_INVAL_HW_QUEUE;
  408. return ret;
  409. }
  410. int iwl_mvm_mac_ctxt_init(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  411. {
  412. unsigned int wdg_timeout =
  413. iwl_mvm_get_wd_timeout(mvm, vif, false, false);
  414. u32 ac;
  415. int ret;
  416. lockdep_assert_held(&mvm->mutex);
  417. ret = iwl_mvm_mac_ctxt_allocate_resources(mvm, vif);
  418. if (ret)
  419. return ret;
  420. switch (vif->type) {
  421. case NL80211_IFTYPE_P2P_DEVICE:
  422. iwl_mvm_enable_ac_txq(mvm, IWL_MVM_OFFCHANNEL_QUEUE,
  423. IWL_MVM_OFFCHANNEL_QUEUE,
  424. IWL_MVM_TX_FIFO_VO, 0, wdg_timeout);
  425. break;
  426. case NL80211_IFTYPE_AP:
  427. iwl_mvm_enable_ac_txq(mvm, vif->cab_queue, vif->cab_queue,
  428. IWL_MVM_TX_FIFO_MCAST, 0, wdg_timeout);
  429. /* fall through */
  430. default:
  431. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  432. iwl_mvm_enable_ac_txq(mvm, vif->hw_queue[ac],
  433. vif->hw_queue[ac],
  434. iwl_mvm_ac_to_tx_fifo[ac], 0,
  435. wdg_timeout);
  436. break;
  437. }
  438. return 0;
  439. }
  440. void iwl_mvm_mac_ctxt_release(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  441. {
  442. int ac;
  443. lockdep_assert_held(&mvm->mutex);
  444. switch (vif->type) {
  445. case NL80211_IFTYPE_P2P_DEVICE:
  446. iwl_mvm_disable_txq(mvm, IWL_MVM_OFFCHANNEL_QUEUE,
  447. IWL_MVM_OFFCHANNEL_QUEUE, IWL_MAX_TID_COUNT,
  448. 0);
  449. break;
  450. case NL80211_IFTYPE_AP:
  451. iwl_mvm_disable_txq(mvm, vif->cab_queue, vif->cab_queue,
  452. IWL_MAX_TID_COUNT, 0);
  453. /* fall through */
  454. default:
  455. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  456. iwl_mvm_disable_txq(mvm, vif->hw_queue[ac],
  457. vif->hw_queue[ac],
  458. IWL_MAX_TID_COUNT, 0);
  459. }
  460. }
  461. static void iwl_mvm_ack_rates(struct iwl_mvm *mvm,
  462. struct ieee80211_vif *vif,
  463. enum ieee80211_band band,
  464. u8 *cck_rates, u8 *ofdm_rates)
  465. {
  466. struct ieee80211_supported_band *sband;
  467. unsigned long basic = vif->bss_conf.basic_rates;
  468. int lowest_present_ofdm = 100;
  469. int lowest_present_cck = 100;
  470. u8 cck = 0;
  471. u8 ofdm = 0;
  472. int i;
  473. sband = mvm->hw->wiphy->bands[band];
  474. for_each_set_bit(i, &basic, BITS_PER_LONG) {
  475. int hw = sband->bitrates[i].hw_value;
  476. if (hw >= IWL_FIRST_OFDM_RATE) {
  477. ofdm |= BIT(hw - IWL_FIRST_OFDM_RATE);
  478. if (lowest_present_ofdm > hw)
  479. lowest_present_ofdm = hw;
  480. } else {
  481. BUILD_BUG_ON(IWL_FIRST_CCK_RATE != 0);
  482. cck |= BIT(hw);
  483. if (lowest_present_cck > hw)
  484. lowest_present_cck = hw;
  485. }
  486. }
  487. /*
  488. * Now we've got the basic rates as bitmaps in the ofdm and cck
  489. * variables. This isn't sufficient though, as there might not
  490. * be all the right rates in the bitmap. E.g. if the only basic
  491. * rates are 5.5 Mbps and 11 Mbps, we still need to add 1 Mbps
  492. * and 6 Mbps because the 802.11-2007 standard says in 9.6:
  493. *
  494. * [...] a STA responding to a received frame shall transmit
  495. * its Control Response frame [...] at the highest rate in the
  496. * BSSBasicRateSet parameter that is less than or equal to the
  497. * rate of the immediately previous frame in the frame exchange
  498. * sequence ([...]) and that is of the same modulation class
  499. * ([...]) as the received frame. If no rate contained in the
  500. * BSSBasicRateSet parameter meets these conditions, then the
  501. * control frame sent in response to a received frame shall be
  502. * transmitted at the highest mandatory rate of the PHY that is
  503. * less than or equal to the rate of the received frame, and
  504. * that is of the same modulation class as the received frame.
  505. *
  506. * As a consequence, we need to add all mandatory rates that are
  507. * lower than all of the basic rates to these bitmaps.
  508. */
  509. if (IWL_RATE_24M_INDEX < lowest_present_ofdm)
  510. ofdm |= IWL_RATE_BIT_MSK(24) >> IWL_FIRST_OFDM_RATE;
  511. if (IWL_RATE_12M_INDEX < lowest_present_ofdm)
  512. ofdm |= IWL_RATE_BIT_MSK(12) >> IWL_FIRST_OFDM_RATE;
  513. /* 6M already there or needed so always add */
  514. ofdm |= IWL_RATE_BIT_MSK(6) >> IWL_FIRST_OFDM_RATE;
  515. /*
  516. * CCK is a bit more complex with DSSS vs. HR/DSSS vs. ERP.
  517. * Note, however:
  518. * - if no CCK rates are basic, it must be ERP since there must
  519. * be some basic rates at all, so they're OFDM => ERP PHY
  520. * (or we're in 5 GHz, and the cck bitmap will never be used)
  521. * - if 11M is a basic rate, it must be ERP as well, so add 5.5M
  522. * - if 5.5M is basic, 1M and 2M are mandatory
  523. * - if 2M is basic, 1M is mandatory
  524. * - if 1M is basic, that's the only valid ACK rate.
  525. * As a consequence, it's not as complicated as it sounds, just add
  526. * any lower rates to the ACK rate bitmap.
  527. */
  528. if (IWL_RATE_11M_INDEX < lowest_present_cck)
  529. cck |= IWL_RATE_BIT_MSK(11) >> IWL_FIRST_CCK_RATE;
  530. if (IWL_RATE_5M_INDEX < lowest_present_cck)
  531. cck |= IWL_RATE_BIT_MSK(5) >> IWL_FIRST_CCK_RATE;
  532. if (IWL_RATE_2M_INDEX < lowest_present_cck)
  533. cck |= IWL_RATE_BIT_MSK(2) >> IWL_FIRST_CCK_RATE;
  534. /* 1M already there or needed so always add */
  535. cck |= IWL_RATE_BIT_MSK(1) >> IWL_FIRST_CCK_RATE;
  536. *cck_rates = cck;
  537. *ofdm_rates = ofdm;
  538. }
  539. static void iwl_mvm_mac_ctxt_set_ht_flags(struct iwl_mvm *mvm,
  540. struct ieee80211_vif *vif,
  541. struct iwl_mac_ctx_cmd *cmd)
  542. {
  543. /* for both sta and ap, ht_operation_mode hold the protection_mode */
  544. u8 protection_mode = vif->bss_conf.ht_operation_mode &
  545. IEEE80211_HT_OP_MODE_PROTECTION;
  546. /* The fw does not distinguish between ht and fat */
  547. u32 ht_flag = MAC_PROT_FLG_HT_PROT | MAC_PROT_FLG_FAT_PROT;
  548. IWL_DEBUG_RATE(mvm, "protection mode set to %d\n", protection_mode);
  549. /*
  550. * See section 9.23.3.1 of IEEE 80211-2012.
  551. * Nongreenfield HT STAs Present is not supported.
  552. */
  553. switch (protection_mode) {
  554. case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
  555. break;
  556. case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
  557. case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
  558. cmd->protection_flags |= cpu_to_le32(ht_flag);
  559. break;
  560. case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
  561. /* Protect when channel wider than 20MHz */
  562. if (vif->bss_conf.chandef.width > NL80211_CHAN_WIDTH_20)
  563. cmd->protection_flags |= cpu_to_le32(ht_flag);
  564. break;
  565. default:
  566. IWL_ERR(mvm, "Illegal protection mode %d\n",
  567. protection_mode);
  568. break;
  569. }
  570. }
  571. static void iwl_mvm_mac_ctxt_cmd_common(struct iwl_mvm *mvm,
  572. struct ieee80211_vif *vif,
  573. struct iwl_mac_ctx_cmd *cmd,
  574. const u8 *bssid_override,
  575. u32 action)
  576. {
  577. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  578. struct ieee80211_chanctx_conf *chanctx;
  579. bool ht_enabled = !!(vif->bss_conf.ht_operation_mode &
  580. IEEE80211_HT_OP_MODE_PROTECTION);
  581. u8 cck_ack_rates, ofdm_ack_rates;
  582. const u8 *bssid = bssid_override ?: vif->bss_conf.bssid;
  583. int i;
  584. cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
  585. mvmvif->color));
  586. cmd->action = cpu_to_le32(action);
  587. switch (vif->type) {
  588. case NL80211_IFTYPE_STATION:
  589. if (vif->p2p)
  590. cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_P2P_STA);
  591. else
  592. cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_BSS_STA);
  593. break;
  594. case NL80211_IFTYPE_AP:
  595. cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_GO);
  596. break;
  597. case NL80211_IFTYPE_MONITOR:
  598. cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_LISTENER);
  599. break;
  600. case NL80211_IFTYPE_P2P_DEVICE:
  601. cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_P2P_DEVICE);
  602. break;
  603. case NL80211_IFTYPE_ADHOC:
  604. cmd->mac_type = cpu_to_le32(FW_MAC_TYPE_IBSS);
  605. break;
  606. default:
  607. WARN_ON_ONCE(1);
  608. }
  609. cmd->tsf_id = cpu_to_le32(mvmvif->tsf_id);
  610. memcpy(cmd->node_addr, vif->addr, ETH_ALEN);
  611. if (bssid)
  612. memcpy(cmd->bssid_addr, bssid, ETH_ALEN);
  613. else
  614. eth_broadcast_addr(cmd->bssid_addr);
  615. rcu_read_lock();
  616. chanctx = rcu_dereference(vif->chanctx_conf);
  617. iwl_mvm_ack_rates(mvm, vif, chanctx ? chanctx->def.chan->band
  618. : IEEE80211_BAND_2GHZ,
  619. &cck_ack_rates, &ofdm_ack_rates);
  620. rcu_read_unlock();
  621. cmd->cck_rates = cpu_to_le32((u32)cck_ack_rates);
  622. cmd->ofdm_rates = cpu_to_le32((u32)ofdm_ack_rates);
  623. cmd->cck_short_preamble =
  624. cpu_to_le32(vif->bss_conf.use_short_preamble ?
  625. MAC_FLG_SHORT_PREAMBLE : 0);
  626. cmd->short_slot =
  627. cpu_to_le32(vif->bss_conf.use_short_slot ?
  628. MAC_FLG_SHORT_SLOT : 0);
  629. cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP);
  630. for (i = 0; i < IEEE80211_NUM_ACS; i++) {
  631. u8 txf = iwl_mvm_ac_to_tx_fifo[i];
  632. cmd->ac[txf].cw_min =
  633. cpu_to_le16(mvmvif->queue_params[i].cw_min);
  634. cmd->ac[txf].cw_max =
  635. cpu_to_le16(mvmvif->queue_params[i].cw_max);
  636. cmd->ac[txf].edca_txop =
  637. cpu_to_le16(mvmvif->queue_params[i].txop * 32);
  638. cmd->ac[txf].aifsn = mvmvif->queue_params[i].aifs;
  639. cmd->ac[txf].fifos_mask = BIT(txf);
  640. }
  641. if (vif->type == NL80211_IFTYPE_AP) {
  642. /* in AP mode, the MCAST FIFO takes the EDCA params from VO */
  643. cmd->ac[IWL_MVM_TX_FIFO_VO].fifos_mask |=
  644. BIT(IWL_MVM_TX_FIFO_MCAST);
  645. /*
  646. * in AP mode, pass probe requests and beacons from other APs
  647. * (needed for ht protection); when there're no any associated
  648. * station don't ask FW to pass beacons to prevent unnecessary
  649. * wake-ups.
  650. */
  651. cmd->filter_flags |= cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST);
  652. if (mvmvif->ap_assoc_sta_count || !mvm->drop_bcn_ap_mode) {
  653. cmd->filter_flags |= cpu_to_le32(MAC_FILTER_IN_BEACON);
  654. IWL_DEBUG_HC(mvm, "Asking FW to pass beacons\n");
  655. } else {
  656. IWL_DEBUG_HC(mvm, "No need to receive beacons\n");
  657. }
  658. }
  659. if (vif->bss_conf.qos)
  660. cmd->qos_flags |= cpu_to_le32(MAC_QOS_FLG_UPDATE_EDCA);
  661. if (vif->bss_conf.use_cts_prot)
  662. cmd->protection_flags |= cpu_to_le32(MAC_PROT_FLG_TGG_PROTECT);
  663. IWL_DEBUG_RATE(mvm, "use_cts_prot %d, ht_operation_mode %d\n",
  664. vif->bss_conf.use_cts_prot,
  665. vif->bss_conf.ht_operation_mode);
  666. if (vif->bss_conf.chandef.width != NL80211_CHAN_WIDTH_20_NOHT)
  667. cmd->qos_flags |= cpu_to_le32(MAC_QOS_FLG_TGN);
  668. if (ht_enabled)
  669. iwl_mvm_mac_ctxt_set_ht_flags(mvm, vif, cmd);
  670. }
  671. static int iwl_mvm_mac_ctxt_send_cmd(struct iwl_mvm *mvm,
  672. struct iwl_mac_ctx_cmd *cmd)
  673. {
  674. int ret = iwl_mvm_send_cmd_pdu(mvm, MAC_CONTEXT_CMD, 0,
  675. sizeof(*cmd), cmd);
  676. if (ret)
  677. IWL_ERR(mvm, "Failed to send MAC context (action:%d): %d\n",
  678. le32_to_cpu(cmd->action), ret);
  679. return ret;
  680. }
  681. static int iwl_mvm_mac_ctxt_cmd_sta(struct iwl_mvm *mvm,
  682. struct ieee80211_vif *vif,
  683. u32 action, bool force_assoc_off,
  684. const u8 *bssid_override)
  685. {
  686. struct iwl_mac_ctx_cmd cmd = {};
  687. struct iwl_mac_data_sta *ctxt_sta;
  688. WARN_ON(vif->type != NL80211_IFTYPE_STATION);
  689. /* Fill the common data for all mac context types */
  690. iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, bssid_override, action);
  691. if (vif->p2p) {
  692. struct ieee80211_p2p_noa_attr *noa =
  693. &vif->bss_conf.p2p_noa_attr;
  694. cmd.p2p_sta.ctwin = cpu_to_le32(noa->oppps_ctwindow &
  695. IEEE80211_P2P_OPPPS_CTWINDOW_MASK);
  696. ctxt_sta = &cmd.p2p_sta.sta;
  697. } else {
  698. ctxt_sta = &cmd.sta;
  699. }
  700. /* We need the dtim_period to set the MAC as associated */
  701. if (vif->bss_conf.assoc && vif->bss_conf.dtim_period &&
  702. !force_assoc_off) {
  703. u32 dtim_offs;
  704. /*
  705. * The DTIM count counts down, so when it is N that means N
  706. * more beacon intervals happen until the DTIM TBTT. Therefore
  707. * add this to the current time. If that ends up being in the
  708. * future, the firmware will handle it.
  709. *
  710. * Also note that the system_timestamp (which we get here as
  711. * "sync_device_ts") and TSF timestamp aren't at exactly the
  712. * same offset in the frame -- the TSF is at the first symbol
  713. * of the TSF, the system timestamp is at signal acquisition
  714. * time. This means there's an offset between them of at most
  715. * a few hundred microseconds (24 * 8 bits + PLCP time gives
  716. * 384us in the longest case), this is currently not relevant
  717. * as the firmware wakes up around 2ms before the TBTT.
  718. */
  719. dtim_offs = vif->bss_conf.sync_dtim_count *
  720. vif->bss_conf.beacon_int;
  721. /* convert TU to usecs */
  722. dtim_offs *= 1024;
  723. ctxt_sta->dtim_tsf =
  724. cpu_to_le64(vif->bss_conf.sync_tsf + dtim_offs);
  725. ctxt_sta->dtim_time =
  726. cpu_to_le32(vif->bss_conf.sync_device_ts + dtim_offs);
  727. IWL_DEBUG_INFO(mvm, "DTIM TBTT is 0x%llx/0x%x, offset %d\n",
  728. le64_to_cpu(ctxt_sta->dtim_tsf),
  729. le32_to_cpu(ctxt_sta->dtim_time),
  730. dtim_offs);
  731. ctxt_sta->is_assoc = cpu_to_le32(1);
  732. } else {
  733. ctxt_sta->is_assoc = cpu_to_le32(0);
  734. /* Allow beacons to pass through as long as we are not
  735. * associated, or we do not have dtim period information.
  736. */
  737. cmd.filter_flags |= cpu_to_le32(MAC_FILTER_IN_BEACON);
  738. }
  739. ctxt_sta->bi = cpu_to_le32(vif->bss_conf.beacon_int);
  740. ctxt_sta->bi_reciprocal =
  741. cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int));
  742. ctxt_sta->dtim_interval = cpu_to_le32(vif->bss_conf.beacon_int *
  743. vif->bss_conf.dtim_period);
  744. ctxt_sta->dtim_reciprocal =
  745. cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int *
  746. vif->bss_conf.dtim_period));
  747. ctxt_sta->listen_interval = cpu_to_le32(mvm->hw->conf.listen_interval);
  748. ctxt_sta->assoc_id = cpu_to_le32(vif->bss_conf.aid);
  749. if (vif->probe_req_reg && vif->bss_conf.assoc && vif->p2p)
  750. cmd.filter_flags |= cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST);
  751. return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
  752. }
  753. static int iwl_mvm_mac_ctxt_cmd_listener(struct iwl_mvm *mvm,
  754. struct ieee80211_vif *vif,
  755. u32 action)
  756. {
  757. struct iwl_mac_ctx_cmd cmd = {};
  758. u32 tfd_queue_msk = 0;
  759. int ret, i;
  760. WARN_ON(vif->type != NL80211_IFTYPE_MONITOR);
  761. iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
  762. for (i = 0; i < IEEE80211_NUM_ACS; i++)
  763. if (vif->hw_queue[i] != IEEE80211_INVAL_HW_QUEUE)
  764. tfd_queue_msk |= BIT(vif->hw_queue[i]);
  765. cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_PROMISC |
  766. MAC_FILTER_IN_CONTROL_AND_MGMT |
  767. MAC_FILTER_IN_BEACON |
  768. MAC_FILTER_IN_PROBE_REQUEST |
  769. MAC_FILTER_IN_CRC32);
  770. ieee80211_hw_set(mvm->hw, RX_INCLUDES_FCS);
  771. /* Allocate sniffer station */
  772. ret = iwl_mvm_allocate_int_sta(mvm, &mvm->snif_sta, tfd_queue_msk,
  773. vif->type);
  774. if (ret)
  775. return ret;
  776. return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
  777. }
  778. static int iwl_mvm_mac_ctxt_cmd_ibss(struct iwl_mvm *mvm,
  779. struct ieee80211_vif *vif,
  780. u32 action)
  781. {
  782. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  783. struct iwl_mac_ctx_cmd cmd = {};
  784. WARN_ON(vif->type != NL80211_IFTYPE_ADHOC);
  785. iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
  786. cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_BEACON |
  787. MAC_FILTER_IN_PROBE_REQUEST);
  788. /* cmd.ibss.beacon_time/cmd.ibss.beacon_tsf are curently ignored */
  789. cmd.ibss.bi = cpu_to_le32(vif->bss_conf.beacon_int);
  790. cmd.ibss.bi_reciprocal =
  791. cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int));
  792. /* TODO: Assumes that the beacon id == mac context id */
  793. cmd.ibss.beacon_template = cpu_to_le32(mvmvif->id);
  794. return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
  795. }
  796. struct iwl_mvm_go_iterator_data {
  797. bool go_active;
  798. };
  799. static void iwl_mvm_go_iterator(void *_data, u8 *mac, struct ieee80211_vif *vif)
  800. {
  801. struct iwl_mvm_go_iterator_data *data = _data;
  802. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  803. if (vif->type == NL80211_IFTYPE_AP && vif->p2p &&
  804. mvmvif->ap_ibss_active)
  805. data->go_active = true;
  806. }
  807. static int iwl_mvm_mac_ctxt_cmd_p2p_device(struct iwl_mvm *mvm,
  808. struct ieee80211_vif *vif,
  809. u32 action)
  810. {
  811. struct iwl_mac_ctx_cmd cmd = {};
  812. struct iwl_mvm_go_iterator_data data = {};
  813. WARN_ON(vif->type != NL80211_IFTYPE_P2P_DEVICE);
  814. iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
  815. cmd.protection_flags |= cpu_to_le32(MAC_PROT_FLG_TGG_PROTECT);
  816. /* Override the filter flags to accept only probe requests */
  817. cmd.filter_flags = cpu_to_le32(MAC_FILTER_IN_PROBE_REQUEST);
  818. /*
  819. * This flag should be set to true when the P2P Device is
  820. * discoverable and there is at least another active P2P GO. Settings
  821. * this flag will allow the P2P Device to be discoverable on other
  822. * channels in addition to its listen channel.
  823. * Note that this flag should not be set in other cases as it opens the
  824. * Rx filters on all MAC and increases the number of interrupts.
  825. */
  826. ieee80211_iterate_active_interfaces_atomic(
  827. mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
  828. iwl_mvm_go_iterator, &data);
  829. cmd.p2p_dev.is_disc_extended = cpu_to_le32(data.go_active ? 1 : 0);
  830. return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
  831. }
  832. static void iwl_mvm_mac_ctxt_set_tim(struct iwl_mvm *mvm,
  833. struct iwl_mac_beacon_cmd *beacon_cmd,
  834. u8 *beacon, u32 frame_size)
  835. {
  836. u32 tim_idx;
  837. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
  838. /* The index is relative to frame start but we start looking at the
  839. * variable-length part of the beacon. */
  840. tim_idx = mgmt->u.beacon.variable - beacon;
  841. /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
  842. while ((tim_idx < (frame_size - 2)) &&
  843. (beacon[tim_idx] != WLAN_EID_TIM))
  844. tim_idx += beacon[tim_idx+1] + 2;
  845. /* If TIM field was found, set variables */
  846. if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
  847. beacon_cmd->tim_idx = cpu_to_le32(tim_idx);
  848. beacon_cmd->tim_size = cpu_to_le32((u32)beacon[tim_idx+1]);
  849. } else {
  850. IWL_WARN(mvm, "Unable to find TIM Element in beacon\n");
  851. }
  852. }
  853. static int iwl_mvm_mac_ctxt_send_beacon(struct iwl_mvm *mvm,
  854. struct ieee80211_vif *vif,
  855. struct sk_buff *beacon)
  856. {
  857. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  858. struct iwl_host_cmd cmd = {
  859. .id = BEACON_TEMPLATE_CMD,
  860. .flags = CMD_ASYNC,
  861. };
  862. struct iwl_mac_beacon_cmd beacon_cmd = {};
  863. struct ieee80211_tx_info *info;
  864. u32 beacon_skb_len;
  865. u32 rate, tx_flags;
  866. if (WARN_ON(!beacon))
  867. return -EINVAL;
  868. beacon_skb_len = beacon->len;
  869. /* TODO: for now the beacon template id is set to be the mac context id.
  870. * Might be better to handle it as another resource ... */
  871. beacon_cmd.template_id = cpu_to_le32((u32)mvmvif->id);
  872. info = IEEE80211_SKB_CB(beacon);
  873. /* Set up TX command fields */
  874. beacon_cmd.tx.len = cpu_to_le16((u16)beacon_skb_len);
  875. beacon_cmd.tx.sta_id = mvmvif->bcast_sta.sta_id;
  876. beacon_cmd.tx.life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE);
  877. tx_flags = TX_CMD_FLG_SEQ_CTL | TX_CMD_FLG_TSF;
  878. tx_flags |=
  879. iwl_mvm_bt_coex_tx_prio(mvm, (void *)beacon->data, info, 0) <<
  880. TX_CMD_FLG_BT_PRIO_POS;
  881. beacon_cmd.tx.tx_flags = cpu_to_le32(tx_flags);
  882. if (!fw_has_capa(&mvm->fw->ucode_capa,
  883. IWL_UCODE_TLV_CAPA_BEACON_ANT_SELECTION)) {
  884. mvm->mgmt_last_antenna_idx =
  885. iwl_mvm_next_antenna(mvm, iwl_mvm_get_valid_tx_ant(mvm),
  886. mvm->mgmt_last_antenna_idx);
  887. }
  888. beacon_cmd.tx.rate_n_flags =
  889. cpu_to_le32(BIT(mvm->mgmt_last_antenna_idx) <<
  890. RATE_MCS_ANT_POS);
  891. if (info->band == IEEE80211_BAND_5GHZ || vif->p2p) {
  892. rate = IWL_FIRST_OFDM_RATE;
  893. } else {
  894. rate = IWL_FIRST_CCK_RATE;
  895. beacon_cmd.tx.rate_n_flags |= cpu_to_le32(RATE_MCS_CCK_MSK);
  896. }
  897. beacon_cmd.tx.rate_n_flags |=
  898. cpu_to_le32(iwl_mvm_mac80211_idx_to_hwrate(rate));
  899. /* Set up TX beacon command fields */
  900. if (vif->type == NL80211_IFTYPE_AP)
  901. iwl_mvm_mac_ctxt_set_tim(mvm, &beacon_cmd,
  902. beacon->data,
  903. beacon_skb_len);
  904. /* Submit command */
  905. cmd.len[0] = sizeof(beacon_cmd);
  906. cmd.data[0] = &beacon_cmd;
  907. cmd.dataflags[0] = 0;
  908. cmd.len[1] = beacon_skb_len;
  909. cmd.data[1] = beacon->data;
  910. cmd.dataflags[1] = IWL_HCMD_DFL_DUP;
  911. return iwl_mvm_send_cmd(mvm, &cmd);
  912. }
  913. /* The beacon template for the AP/GO/IBSS has changed and needs update */
  914. int iwl_mvm_mac_ctxt_beacon_changed(struct iwl_mvm *mvm,
  915. struct ieee80211_vif *vif)
  916. {
  917. struct sk_buff *beacon;
  918. int ret;
  919. WARN_ON(vif->type != NL80211_IFTYPE_AP &&
  920. vif->type != NL80211_IFTYPE_ADHOC);
  921. beacon = ieee80211_beacon_get_template(mvm->hw, vif, NULL);
  922. if (!beacon)
  923. return -ENOMEM;
  924. ret = iwl_mvm_mac_ctxt_send_beacon(mvm, vif, beacon);
  925. dev_kfree_skb(beacon);
  926. return ret;
  927. }
  928. struct iwl_mvm_mac_ap_iterator_data {
  929. struct iwl_mvm *mvm;
  930. struct ieee80211_vif *vif;
  931. u32 beacon_device_ts;
  932. u16 beacon_int;
  933. };
  934. /* Find the beacon_device_ts and beacon_int for a managed interface */
  935. static void iwl_mvm_mac_ap_iterator(void *_data, u8 *mac,
  936. struct ieee80211_vif *vif)
  937. {
  938. struct iwl_mvm_mac_ap_iterator_data *data = _data;
  939. if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc)
  940. return;
  941. /* Station client has higher priority over P2P client*/
  942. if (vif->p2p && data->beacon_device_ts)
  943. return;
  944. data->beacon_device_ts = vif->bss_conf.sync_device_ts;
  945. data->beacon_int = vif->bss_conf.beacon_int;
  946. }
  947. /*
  948. * Fill the specific data for mac context of type AP of P2P GO
  949. */
  950. static void iwl_mvm_mac_ctxt_cmd_fill_ap(struct iwl_mvm *mvm,
  951. struct ieee80211_vif *vif,
  952. struct iwl_mac_data_ap *ctxt_ap,
  953. bool add)
  954. {
  955. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  956. struct iwl_mvm_mac_ap_iterator_data data = {
  957. .mvm = mvm,
  958. .vif = vif,
  959. .beacon_device_ts = 0
  960. };
  961. ctxt_ap->bi = cpu_to_le32(vif->bss_conf.beacon_int);
  962. ctxt_ap->bi_reciprocal =
  963. cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int));
  964. ctxt_ap->dtim_interval = cpu_to_le32(vif->bss_conf.beacon_int *
  965. vif->bss_conf.dtim_period);
  966. ctxt_ap->dtim_reciprocal =
  967. cpu_to_le32(iwl_mvm_reciprocal(vif->bss_conf.beacon_int *
  968. vif->bss_conf.dtim_period));
  969. ctxt_ap->mcast_qid = cpu_to_le32(vif->cab_queue);
  970. /*
  971. * Only set the beacon time when the MAC is being added, when we
  972. * just modify the MAC then we should keep the time -- the firmware
  973. * can otherwise have a "jumping" TBTT.
  974. */
  975. if (add) {
  976. /*
  977. * If there is a station/P2P client interface which is
  978. * associated, set the AP's TBTT far enough from the station's
  979. * TBTT. Otherwise, set it to the current system time
  980. */
  981. ieee80211_iterate_active_interfaces_atomic(
  982. mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
  983. iwl_mvm_mac_ap_iterator, &data);
  984. if (data.beacon_device_ts) {
  985. u32 rand = (prandom_u32() % (64 - 36)) + 36;
  986. mvmvif->ap_beacon_time = data.beacon_device_ts +
  987. ieee80211_tu_to_usec(data.beacon_int * rand /
  988. 100);
  989. } else {
  990. mvmvif->ap_beacon_time =
  991. iwl_read_prph(mvm->trans,
  992. DEVICE_SYSTEM_TIME_REG);
  993. }
  994. }
  995. ctxt_ap->beacon_time = cpu_to_le32(mvmvif->ap_beacon_time);
  996. ctxt_ap->beacon_tsf = 0; /* unused */
  997. /* TODO: Assume that the beacon id == mac context id */
  998. ctxt_ap->beacon_template = cpu_to_le32(mvmvif->id);
  999. }
  1000. static int iwl_mvm_mac_ctxt_cmd_ap(struct iwl_mvm *mvm,
  1001. struct ieee80211_vif *vif,
  1002. u32 action)
  1003. {
  1004. struct iwl_mac_ctx_cmd cmd = {};
  1005. WARN_ON(vif->type != NL80211_IFTYPE_AP || vif->p2p);
  1006. /* Fill the common data for all mac context types */
  1007. iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
  1008. /* Fill the data specific for ap mode */
  1009. iwl_mvm_mac_ctxt_cmd_fill_ap(mvm, vif, &cmd.ap,
  1010. action == FW_CTXT_ACTION_ADD);
  1011. return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
  1012. }
  1013. static int iwl_mvm_mac_ctxt_cmd_go(struct iwl_mvm *mvm,
  1014. struct ieee80211_vif *vif,
  1015. u32 action)
  1016. {
  1017. struct iwl_mac_ctx_cmd cmd = {};
  1018. struct ieee80211_p2p_noa_attr *noa = &vif->bss_conf.p2p_noa_attr;
  1019. WARN_ON(vif->type != NL80211_IFTYPE_AP || !vif->p2p);
  1020. /* Fill the common data for all mac context types */
  1021. iwl_mvm_mac_ctxt_cmd_common(mvm, vif, &cmd, NULL, action);
  1022. /* Fill the data specific for GO mode */
  1023. iwl_mvm_mac_ctxt_cmd_fill_ap(mvm, vif, &cmd.go.ap,
  1024. action == FW_CTXT_ACTION_ADD);
  1025. cmd.go.ctwin = cpu_to_le32(noa->oppps_ctwindow &
  1026. IEEE80211_P2P_OPPPS_CTWINDOW_MASK);
  1027. cmd.go.opp_ps_enabled =
  1028. cpu_to_le32(!!(noa->oppps_ctwindow &
  1029. IEEE80211_P2P_OPPPS_ENABLE_BIT));
  1030. return iwl_mvm_mac_ctxt_send_cmd(mvm, &cmd);
  1031. }
  1032. static int iwl_mvm_mac_ctx_send(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  1033. u32 action, bool force_assoc_off,
  1034. const u8 *bssid_override)
  1035. {
  1036. switch (vif->type) {
  1037. case NL80211_IFTYPE_STATION:
  1038. return iwl_mvm_mac_ctxt_cmd_sta(mvm, vif, action,
  1039. force_assoc_off,
  1040. bssid_override);
  1041. break;
  1042. case NL80211_IFTYPE_AP:
  1043. if (!vif->p2p)
  1044. return iwl_mvm_mac_ctxt_cmd_ap(mvm, vif, action);
  1045. else
  1046. return iwl_mvm_mac_ctxt_cmd_go(mvm, vif, action);
  1047. break;
  1048. case NL80211_IFTYPE_MONITOR:
  1049. return iwl_mvm_mac_ctxt_cmd_listener(mvm, vif, action);
  1050. case NL80211_IFTYPE_P2P_DEVICE:
  1051. return iwl_mvm_mac_ctxt_cmd_p2p_device(mvm, vif, action);
  1052. case NL80211_IFTYPE_ADHOC:
  1053. return iwl_mvm_mac_ctxt_cmd_ibss(mvm, vif, action);
  1054. default:
  1055. break;
  1056. }
  1057. return -EOPNOTSUPP;
  1058. }
  1059. int iwl_mvm_mac_ctxt_add(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  1060. {
  1061. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1062. int ret;
  1063. if (WARN_ONCE(mvmvif->uploaded, "Adding active MAC %pM/%d\n",
  1064. vif->addr, ieee80211_vif_type_p2p(vif)))
  1065. return -EIO;
  1066. ret = iwl_mvm_mac_ctx_send(mvm, vif, FW_CTXT_ACTION_ADD,
  1067. true, NULL);
  1068. if (ret)
  1069. return ret;
  1070. /* will only do anything at resume from D3 time */
  1071. iwl_mvm_set_last_nonqos_seq(mvm, vif);
  1072. mvmvif->uploaded = true;
  1073. return 0;
  1074. }
  1075. int iwl_mvm_mac_ctxt_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
  1076. bool force_assoc_off, const u8 *bssid_override)
  1077. {
  1078. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1079. if (WARN_ONCE(!mvmvif->uploaded, "Changing inactive MAC %pM/%d\n",
  1080. vif->addr, ieee80211_vif_type_p2p(vif)))
  1081. return -EIO;
  1082. return iwl_mvm_mac_ctx_send(mvm, vif, FW_CTXT_ACTION_MODIFY,
  1083. force_assoc_off, bssid_override);
  1084. }
  1085. int iwl_mvm_mac_ctxt_remove(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
  1086. {
  1087. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1088. struct iwl_mac_ctx_cmd cmd;
  1089. int ret;
  1090. if (WARN_ONCE(!mvmvif->uploaded, "Removing inactive MAC %pM/%d\n",
  1091. vif->addr, ieee80211_vif_type_p2p(vif)))
  1092. return -EIO;
  1093. memset(&cmd, 0, sizeof(cmd));
  1094. cmd.id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
  1095. mvmvif->color));
  1096. cmd.action = cpu_to_le32(FW_CTXT_ACTION_REMOVE);
  1097. ret = iwl_mvm_send_cmd_pdu(mvm, MAC_CONTEXT_CMD, 0,
  1098. sizeof(cmd), &cmd);
  1099. if (ret) {
  1100. IWL_ERR(mvm, "Failed to remove MAC context: %d\n", ret);
  1101. return ret;
  1102. }
  1103. mvmvif->uploaded = false;
  1104. if (vif->type == NL80211_IFTYPE_MONITOR) {
  1105. __clear_bit(IEEE80211_HW_RX_INCLUDES_FCS, mvm->hw->flags);
  1106. iwl_mvm_dealloc_snif_sta(mvm);
  1107. }
  1108. return 0;
  1109. }
  1110. static void iwl_mvm_csa_count_down(struct iwl_mvm *mvm,
  1111. struct ieee80211_vif *csa_vif, u32 gp2,
  1112. bool tx_success)
  1113. {
  1114. struct iwl_mvm_vif *mvmvif =
  1115. iwl_mvm_vif_from_mac80211(csa_vif);
  1116. /* Don't start to countdown from a failed beacon */
  1117. if (!tx_success && !mvmvif->csa_countdown)
  1118. return;
  1119. mvmvif->csa_countdown = true;
  1120. if (!ieee80211_csa_is_complete(csa_vif)) {
  1121. int c = ieee80211_csa_update_counter(csa_vif);
  1122. iwl_mvm_mac_ctxt_beacon_changed(mvm, csa_vif);
  1123. if (csa_vif->p2p &&
  1124. !iwl_mvm_te_scheduled(&mvmvif->time_event_data) && gp2 &&
  1125. tx_success) {
  1126. u32 rel_time = (c + 1) *
  1127. csa_vif->bss_conf.beacon_int -
  1128. IWL_MVM_CHANNEL_SWITCH_TIME_GO;
  1129. u32 apply_time = gp2 + rel_time * 1024;
  1130. iwl_mvm_schedule_csa_period(mvm, csa_vif,
  1131. IWL_MVM_CHANNEL_SWITCH_TIME_GO -
  1132. IWL_MVM_CHANNEL_SWITCH_MARGIN,
  1133. apply_time);
  1134. }
  1135. } else if (!iwl_mvm_te_scheduled(&mvmvif->time_event_data)) {
  1136. /* we don't have CSA NoA scheduled yet, switch now */
  1137. ieee80211_csa_finish(csa_vif);
  1138. RCU_INIT_POINTER(mvm->csa_vif, NULL);
  1139. }
  1140. }
  1141. void iwl_mvm_rx_beacon_notif(struct iwl_mvm *mvm,
  1142. struct iwl_rx_cmd_buffer *rxb)
  1143. {
  1144. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1145. struct iwl_extended_beacon_notif *beacon = (void *)pkt->data;
  1146. struct iwl_mvm_tx_resp *beacon_notify_hdr;
  1147. struct ieee80211_vif *csa_vif;
  1148. struct ieee80211_vif *tx_blocked_vif;
  1149. u16 status;
  1150. lockdep_assert_held(&mvm->mutex);
  1151. beacon_notify_hdr = &beacon->beacon_notify_hdr;
  1152. mvm->ap_last_beacon_gp2 = le32_to_cpu(beacon->gp2);
  1153. status = le16_to_cpu(beacon_notify_hdr->status.status) & TX_STATUS_MSK;
  1154. IWL_DEBUG_RX(mvm,
  1155. "beacon status %#x retries:%d tsf:0x%16llX gp2:0x%X rate:%d\n",
  1156. status, beacon_notify_hdr->failure_frame,
  1157. le64_to_cpu(beacon->tsf),
  1158. mvm->ap_last_beacon_gp2,
  1159. le32_to_cpu(beacon_notify_hdr->initial_rate));
  1160. csa_vif = rcu_dereference_protected(mvm->csa_vif,
  1161. lockdep_is_held(&mvm->mutex));
  1162. if (unlikely(csa_vif && csa_vif->csa_active))
  1163. iwl_mvm_csa_count_down(mvm, csa_vif, mvm->ap_last_beacon_gp2,
  1164. (status == TX_STATUS_SUCCESS));
  1165. tx_blocked_vif = rcu_dereference_protected(mvm->csa_tx_blocked_vif,
  1166. lockdep_is_held(&mvm->mutex));
  1167. if (unlikely(tx_blocked_vif)) {
  1168. struct iwl_mvm_vif *mvmvif =
  1169. iwl_mvm_vif_from_mac80211(tx_blocked_vif);
  1170. /*
  1171. * The channel switch is started and we have blocked the
  1172. * stations. If this is the first beacon (the timeout wasn't
  1173. * set), set the unblock timeout, otherwise countdown
  1174. */
  1175. if (!mvm->csa_tx_block_bcn_timeout)
  1176. mvm->csa_tx_block_bcn_timeout =
  1177. IWL_MVM_CS_UNBLOCK_TX_TIMEOUT;
  1178. else
  1179. mvm->csa_tx_block_bcn_timeout--;
  1180. /* Check if the timeout is expired, and unblock tx */
  1181. if (mvm->csa_tx_block_bcn_timeout == 0) {
  1182. iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, false);
  1183. RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
  1184. }
  1185. }
  1186. }
  1187. static void iwl_mvm_beacon_loss_iterator(void *_data, u8 *mac,
  1188. struct ieee80211_vif *vif)
  1189. {
  1190. struct iwl_missed_beacons_notif *missed_beacons = _data;
  1191. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
  1192. struct iwl_mvm *mvm = mvmvif->mvm;
  1193. struct iwl_fw_dbg_trigger_missed_bcon *bcon_trig;
  1194. struct iwl_fw_dbg_trigger_tlv *trigger;
  1195. u32 stop_trig_missed_bcon, stop_trig_missed_bcon_since_rx;
  1196. u32 rx_missed_bcon, rx_missed_bcon_since_rx;
  1197. if (mvmvif->id != (u16)le32_to_cpu(missed_beacons->mac_id))
  1198. return;
  1199. rx_missed_bcon = le32_to_cpu(missed_beacons->consec_missed_beacons);
  1200. rx_missed_bcon_since_rx =
  1201. le32_to_cpu(missed_beacons->consec_missed_beacons_since_last_rx);
  1202. /*
  1203. * TODO: the threshold should be adjusted based on latency conditions,
  1204. * and/or in case of a CS flow on one of the other AP vifs.
  1205. */
  1206. if (le32_to_cpu(missed_beacons->consec_missed_beacons_since_last_rx) >
  1207. IWL_MVM_MISSED_BEACONS_THRESHOLD)
  1208. ieee80211_beacon_loss(vif);
  1209. if (!iwl_fw_dbg_trigger_enabled(mvm->fw,
  1210. FW_DBG_TRIGGER_MISSED_BEACONS))
  1211. return;
  1212. trigger = iwl_fw_dbg_get_trigger(mvm->fw,
  1213. FW_DBG_TRIGGER_MISSED_BEACONS);
  1214. bcon_trig = (void *)trigger->data;
  1215. stop_trig_missed_bcon = le32_to_cpu(bcon_trig->stop_consec_missed_bcon);
  1216. stop_trig_missed_bcon_since_rx =
  1217. le32_to_cpu(bcon_trig->stop_consec_missed_bcon_since_rx);
  1218. /* TODO: implement start trigger */
  1219. if (!iwl_fw_dbg_trigger_check_stop(mvm, vif, trigger))
  1220. return;
  1221. if (rx_missed_bcon_since_rx >= stop_trig_missed_bcon_since_rx ||
  1222. rx_missed_bcon >= stop_trig_missed_bcon)
  1223. iwl_mvm_fw_dbg_collect_trig(mvm, trigger, NULL);
  1224. }
  1225. void iwl_mvm_rx_missed_beacons_notif(struct iwl_mvm *mvm,
  1226. struct iwl_rx_cmd_buffer *rxb)
  1227. {
  1228. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1229. struct iwl_missed_beacons_notif *mb = (void *)pkt->data;
  1230. IWL_DEBUG_INFO(mvm,
  1231. "missed bcn mac_id=%u, consecutive=%u (%u, %u, %u)\n",
  1232. le32_to_cpu(mb->mac_id),
  1233. le32_to_cpu(mb->consec_missed_beacons),
  1234. le32_to_cpu(mb->consec_missed_beacons_since_last_rx),
  1235. le32_to_cpu(mb->num_recvd_beacons),
  1236. le32_to_cpu(mb->num_expected_beacons));
  1237. ieee80211_iterate_active_interfaces_atomic(mvm->hw,
  1238. IEEE80211_IFACE_ITER_NORMAL,
  1239. iwl_mvm_beacon_loss_iterator,
  1240. mb);
  1241. }
  1242. void iwl_mvm_rx_stored_beacon_notif(struct iwl_mvm *mvm,
  1243. struct iwl_rx_cmd_buffer *rxb)
  1244. {
  1245. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1246. struct iwl_stored_beacon_notif *sb = (void *)pkt->data;
  1247. struct ieee80211_rx_status rx_status;
  1248. struct sk_buff *skb;
  1249. u32 size = le32_to_cpu(sb->byte_count);
  1250. if (size == 0)
  1251. return;
  1252. skb = alloc_skb(size, GFP_ATOMIC);
  1253. if (!skb) {
  1254. IWL_ERR(mvm, "alloc_skb failed\n");
  1255. return;
  1256. }
  1257. /* update rx_status according to the notification's metadata */
  1258. memset(&rx_status, 0, sizeof(rx_status));
  1259. rx_status.mactime = le64_to_cpu(sb->tsf);
  1260. /* TSF as indicated by the firmware is at INA time */
  1261. rx_status.flag |= RX_FLAG_MACTIME_PLCP_START;
  1262. rx_status.device_timestamp = le32_to_cpu(sb->system_time);
  1263. rx_status.band =
  1264. (sb->phy_flags & cpu_to_le16(RX_RES_PHY_FLAGS_BAND_24)) ?
  1265. IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
  1266. rx_status.freq =
  1267. ieee80211_channel_to_frequency(le16_to_cpu(sb->channel),
  1268. rx_status.band);
  1269. /* copy the data */
  1270. memcpy(skb_put(skb, size), sb->data, size);
  1271. memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
  1272. /* pass it as regular rx to mac80211 */
  1273. ieee80211_rx_napi(mvm->hw, skb, NULL);
  1274. }