rxmq.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126
  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 - 2015 Intel Mobile Communications GmbH
  10. * Copyright(c) 2015 - 2017 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. * The full GNU General Public License is included in this distribution
  22. * in the file called COPYING.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. * BSD LICENSE
  29. *
  30. * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
  31. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  32. * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
  33. * All rights reserved.
  34. *
  35. * Redistribution and use in source and binary forms, with or without
  36. * modification, are permitted provided that the following conditions
  37. * are met:
  38. *
  39. * * Redistributions of source code must retain the above copyright
  40. * notice, this list of conditions and the following disclaimer.
  41. * * Redistributions in binary form must reproduce the above copyright
  42. * notice, this list of conditions and the following disclaimer in
  43. * the documentation and/or other materials provided with the
  44. * distribution.
  45. * * Neither the name Intel Corporation nor the names of its
  46. * contributors may be used to endorse or promote products derived
  47. * from this software without specific prior written permission.
  48. *
  49. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  50. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  51. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  52. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  53. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  54. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  55. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  56. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  57. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  58. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  59. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  60. *****************************************************************************/
  61. #include <linux/etherdevice.h>
  62. #include <linux/skbuff.h>
  63. #include "iwl-trans.h"
  64. #include "mvm.h"
  65. #include "fw-api.h"
  66. static inline int iwl_mvm_check_pn(struct iwl_mvm *mvm, struct sk_buff *skb,
  67. int queue, struct ieee80211_sta *sta)
  68. {
  69. struct iwl_mvm_sta *mvmsta;
  70. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  71. struct ieee80211_rx_status *stats = IEEE80211_SKB_RXCB(skb);
  72. struct iwl_mvm_key_pn *ptk_pn;
  73. int res;
  74. u8 tid, keyidx;
  75. u8 pn[IEEE80211_CCMP_PN_LEN];
  76. u8 *extiv;
  77. /* do PN checking */
  78. /* multicast and non-data only arrives on default queue */
  79. if (!ieee80211_is_data(hdr->frame_control) ||
  80. is_multicast_ether_addr(hdr->addr1))
  81. return 0;
  82. /* do not check PN for open AP */
  83. if (!(stats->flag & RX_FLAG_DECRYPTED))
  84. return 0;
  85. /*
  86. * avoid checking for default queue - we don't want to replicate
  87. * all the logic that's necessary for checking the PN on fragmented
  88. * frames, leave that to mac80211
  89. */
  90. if (queue == 0)
  91. return 0;
  92. /* if we are here - this for sure is either CCMP or GCMP */
  93. if (IS_ERR_OR_NULL(sta)) {
  94. IWL_ERR(mvm,
  95. "expected hw-decrypted unicast frame for station\n");
  96. return -1;
  97. }
  98. mvmsta = iwl_mvm_sta_from_mac80211(sta);
  99. extiv = (u8 *)hdr + ieee80211_hdrlen(hdr->frame_control);
  100. keyidx = extiv[3] >> 6;
  101. ptk_pn = rcu_dereference(mvmsta->ptk_pn[keyidx]);
  102. if (!ptk_pn)
  103. return -1;
  104. if (ieee80211_is_data_qos(hdr->frame_control))
  105. tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
  106. else
  107. tid = 0;
  108. /* we don't use HCCA/802.11 QoS TSPECs, so drop such frames */
  109. if (tid >= IWL_MAX_TID_COUNT)
  110. return -1;
  111. /* load pn */
  112. pn[0] = extiv[7];
  113. pn[1] = extiv[6];
  114. pn[2] = extiv[5];
  115. pn[3] = extiv[4];
  116. pn[4] = extiv[1];
  117. pn[5] = extiv[0];
  118. res = memcmp(pn, ptk_pn->q[queue].pn[tid], IEEE80211_CCMP_PN_LEN);
  119. if (res < 0)
  120. return -1;
  121. if (!res && !(stats->flag & RX_FLAG_ALLOW_SAME_PN))
  122. return -1;
  123. memcpy(ptk_pn->q[queue].pn[tid], pn, IEEE80211_CCMP_PN_LEN);
  124. stats->flag |= RX_FLAG_PN_VALIDATED;
  125. return 0;
  126. }
  127. /* iwl_mvm_create_skb Adds the rxb to a new skb */
  128. static void iwl_mvm_create_skb(struct sk_buff *skb, struct ieee80211_hdr *hdr,
  129. u16 len, u8 crypt_len,
  130. struct iwl_rx_cmd_buffer *rxb)
  131. {
  132. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  133. struct iwl_rx_mpdu_desc *desc = (void *)pkt->data;
  134. unsigned int headlen, fraglen, pad_len = 0;
  135. unsigned int hdrlen = ieee80211_hdrlen(hdr->frame_control);
  136. if (desc->mac_flags2 & IWL_RX_MPDU_MFLG2_PAD) {
  137. pad_len = 2;
  138. /*
  139. * If the device inserted padding it means that (it thought)
  140. * the 802.11 header wasn't a multiple of 4 bytes long. In
  141. * this case, reserve two bytes at the start of the SKB to
  142. * align the payload properly in case we end up copying it.
  143. */
  144. skb_reserve(skb, pad_len);
  145. }
  146. len -= pad_len;
  147. /* If frame is small enough to fit in skb->head, pull it completely.
  148. * If not, only pull ieee80211_hdr (including crypto if present, and
  149. * an additional 8 bytes for SNAP/ethertype, see below) so that
  150. * splice() or TCP coalesce are more efficient.
  151. *
  152. * Since, in addition, ieee80211_data_to_8023() always pull in at
  153. * least 8 bytes (possibly more for mesh) we can do the same here
  154. * to save the cost of doing it later. That still doesn't pull in
  155. * the actual IP header since the typical case has a SNAP header.
  156. * If the latter changes (there are efforts in the standards group
  157. * to do so) we should revisit this and ieee80211_data_to_8023().
  158. */
  159. headlen = (len <= skb_tailroom(skb)) ? len :
  160. hdrlen + crypt_len + 8;
  161. /* The firmware may align the packet to DWORD.
  162. * The padding is inserted after the IV.
  163. * After copying the header + IV skip the padding if
  164. * present before copying packet data.
  165. */
  166. hdrlen += crypt_len;
  167. skb_put_data(skb, hdr, hdrlen);
  168. skb_put_data(skb, (u8 *)hdr + hdrlen + pad_len, headlen - hdrlen);
  169. fraglen = len - headlen;
  170. if (fraglen) {
  171. int offset = (void *)hdr + headlen + pad_len -
  172. rxb_addr(rxb) + rxb_offset(rxb);
  173. skb_add_rx_frag(skb, 0, rxb_steal_page(rxb), offset,
  174. fraglen, rxb->truesize);
  175. }
  176. }
  177. /* iwl_mvm_pass_packet_to_mac80211 - passes the packet for mac80211 */
  178. static void iwl_mvm_pass_packet_to_mac80211(struct iwl_mvm *mvm,
  179. struct napi_struct *napi,
  180. struct sk_buff *skb, int queue,
  181. struct ieee80211_sta *sta)
  182. {
  183. if (iwl_mvm_check_pn(mvm, skb, queue, sta))
  184. kfree_skb(skb);
  185. else
  186. ieee80211_rx_napi(mvm->hw, sta, skb, napi);
  187. }
  188. static void iwl_mvm_get_signal_strength(struct iwl_mvm *mvm,
  189. struct iwl_rx_mpdu_desc *desc,
  190. struct ieee80211_rx_status *rx_status)
  191. {
  192. int energy_a, energy_b, max_energy;
  193. u32 rate_flags = le32_to_cpu(desc->rate_n_flags);
  194. energy_a = desc->energy_a;
  195. energy_a = energy_a ? -energy_a : S8_MIN;
  196. energy_b = desc->energy_b;
  197. energy_b = energy_b ? -energy_b : S8_MIN;
  198. max_energy = max(energy_a, energy_b);
  199. IWL_DEBUG_STATS(mvm, "energy In A %d B %d, and max %d\n",
  200. energy_a, energy_b, max_energy);
  201. rx_status->signal = max_energy;
  202. rx_status->chains =
  203. (rate_flags & RATE_MCS_ANT_AB_MSK) >> RATE_MCS_ANT_POS;
  204. rx_status->chain_signal[0] = energy_a;
  205. rx_status->chain_signal[1] = energy_b;
  206. rx_status->chain_signal[2] = S8_MIN;
  207. }
  208. static int iwl_mvm_rx_crypto(struct iwl_mvm *mvm, struct ieee80211_hdr *hdr,
  209. struct ieee80211_rx_status *stats,
  210. struct iwl_rx_mpdu_desc *desc, u32 pkt_flags,
  211. int queue, u8 *crypt_len)
  212. {
  213. u16 status = le16_to_cpu(desc->status);
  214. if (!ieee80211_has_protected(hdr->frame_control) ||
  215. (status & IWL_RX_MPDU_STATUS_SEC_MASK) ==
  216. IWL_RX_MPDU_STATUS_SEC_NONE)
  217. return 0;
  218. /* TODO: handle packets encrypted with unknown alg */
  219. switch (status & IWL_RX_MPDU_STATUS_SEC_MASK) {
  220. case IWL_RX_MPDU_STATUS_SEC_CCM:
  221. case IWL_RX_MPDU_STATUS_SEC_GCM:
  222. BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN != IEEE80211_GCMP_PN_LEN);
  223. /* alg is CCM: check MIC only */
  224. if (!(status & IWL_RX_MPDU_STATUS_MIC_OK))
  225. return -1;
  226. stats->flag |= RX_FLAG_DECRYPTED;
  227. if (pkt_flags & FH_RSCSR_RADA_EN)
  228. stats->flag |= RX_FLAG_MIC_STRIPPED;
  229. *crypt_len = IEEE80211_CCMP_HDR_LEN;
  230. return 0;
  231. case IWL_RX_MPDU_STATUS_SEC_TKIP:
  232. /* Don't drop the frame and decrypt it in SW */
  233. if (!fw_has_api(&mvm->fw->ucode_capa,
  234. IWL_UCODE_TLV_API_DEPRECATE_TTAK) &&
  235. !(status & IWL_RX_MPDU_RES_STATUS_TTAK_OK))
  236. return 0;
  237. *crypt_len = IEEE80211_TKIP_IV_LEN;
  238. /* fall through if TTAK OK */
  239. case IWL_RX_MPDU_STATUS_SEC_WEP:
  240. if (!(status & IWL_RX_MPDU_STATUS_ICV_OK))
  241. return -1;
  242. stats->flag |= RX_FLAG_DECRYPTED;
  243. if ((status & IWL_RX_MPDU_STATUS_SEC_MASK) ==
  244. IWL_RX_MPDU_STATUS_SEC_WEP)
  245. *crypt_len = IEEE80211_WEP_IV_LEN;
  246. if (pkt_flags & FH_RSCSR_RADA_EN)
  247. stats->flag |= RX_FLAG_ICV_STRIPPED;
  248. return 0;
  249. case IWL_RX_MPDU_STATUS_SEC_EXT_ENC:
  250. if (!(status & IWL_RX_MPDU_STATUS_MIC_OK))
  251. return -1;
  252. stats->flag |= RX_FLAG_DECRYPTED;
  253. return 0;
  254. default:
  255. /* Expected in monitor (not having the keys) */
  256. if (!mvm->monitor_on)
  257. IWL_ERR(mvm, "Unhandled alg: 0x%x\n", status);
  258. }
  259. return 0;
  260. }
  261. static void iwl_mvm_rx_csum(struct ieee80211_sta *sta,
  262. struct sk_buff *skb,
  263. struct iwl_rx_mpdu_desc *desc)
  264. {
  265. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  266. struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif);
  267. u16 flags = le16_to_cpu(desc->l3l4_flags);
  268. u8 l3_prot = (u8)((flags & IWL_RX_L3L4_L3_PROTO_MASK) >>
  269. IWL_RX_L3_PROTO_POS);
  270. if (mvmvif->features & NETIF_F_RXCSUM &&
  271. flags & IWL_RX_L3L4_TCP_UDP_CSUM_OK &&
  272. (flags & IWL_RX_L3L4_IP_HDR_CSUM_OK ||
  273. l3_prot == IWL_RX_L3_TYPE_IPV6 ||
  274. l3_prot == IWL_RX_L3_TYPE_IPV6_FRAG))
  275. skb->ip_summed = CHECKSUM_UNNECESSARY;
  276. }
  277. /*
  278. * returns true if a packet is a duplicate and should be dropped.
  279. * Updates AMSDU PN tracking info
  280. */
  281. static bool iwl_mvm_is_dup(struct ieee80211_sta *sta, int queue,
  282. struct ieee80211_rx_status *rx_status,
  283. struct ieee80211_hdr *hdr,
  284. struct iwl_rx_mpdu_desc *desc)
  285. {
  286. struct iwl_mvm_sta *mvm_sta;
  287. struct iwl_mvm_rxq_dup_data *dup_data;
  288. u8 tid, sub_frame_idx;
  289. if (WARN_ON(IS_ERR_OR_NULL(sta)))
  290. return false;
  291. mvm_sta = iwl_mvm_sta_from_mac80211(sta);
  292. dup_data = &mvm_sta->dup_data[queue];
  293. /*
  294. * Drop duplicate 802.11 retransmissions
  295. * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
  296. */
  297. if (ieee80211_is_ctl(hdr->frame_control) ||
  298. ieee80211_is_qos_nullfunc(hdr->frame_control) ||
  299. is_multicast_ether_addr(hdr->addr1)) {
  300. rx_status->flag |= RX_FLAG_DUP_VALIDATED;
  301. return false;
  302. }
  303. if (ieee80211_is_data_qos(hdr->frame_control))
  304. /* frame has qos control */
  305. tid = *ieee80211_get_qos_ctl(hdr) &
  306. IEEE80211_QOS_CTL_TID_MASK;
  307. else
  308. tid = IWL_MAX_TID_COUNT;
  309. /* If this wasn't a part of an A-MSDU the sub-frame index will be 0 */
  310. sub_frame_idx = desc->amsdu_info & IWL_RX_MPDU_AMSDU_SUBFRAME_IDX_MASK;
  311. if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
  312. dup_data->last_seq[tid] == hdr->seq_ctrl &&
  313. dup_data->last_sub_frame[tid] >= sub_frame_idx))
  314. return true;
  315. /* Allow same PN as the first subframe for following sub frames */
  316. if (dup_data->last_seq[tid] == hdr->seq_ctrl &&
  317. sub_frame_idx > dup_data->last_sub_frame[tid] &&
  318. desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU)
  319. rx_status->flag |= RX_FLAG_ALLOW_SAME_PN;
  320. dup_data->last_seq[tid] = hdr->seq_ctrl;
  321. dup_data->last_sub_frame[tid] = sub_frame_idx;
  322. rx_status->flag |= RX_FLAG_DUP_VALIDATED;
  323. return false;
  324. }
  325. int iwl_mvm_notify_rx_queue(struct iwl_mvm *mvm, u32 rxq_mask,
  326. const u8 *data, u32 count)
  327. {
  328. struct iwl_rxq_sync_cmd *cmd;
  329. u32 data_size = sizeof(*cmd) + count;
  330. int ret;
  331. /* should be DWORD aligned */
  332. if (WARN_ON(count & 3 || count > IWL_MULTI_QUEUE_SYNC_MSG_MAX_SIZE))
  333. return -EINVAL;
  334. cmd = kzalloc(data_size, GFP_KERNEL);
  335. if (!cmd)
  336. return -ENOMEM;
  337. cmd->rxq_mask = cpu_to_le32(rxq_mask);
  338. cmd->count = cpu_to_le32(count);
  339. cmd->flags = 0;
  340. memcpy(cmd->payload, data, count);
  341. ret = iwl_mvm_send_cmd_pdu(mvm,
  342. WIDE_ID(DATA_PATH_GROUP,
  343. TRIGGER_RX_QUEUES_NOTIF_CMD),
  344. 0, data_size, cmd);
  345. kfree(cmd);
  346. return ret;
  347. }
  348. /*
  349. * Returns true if sn2 - buffer_size < sn1 < sn2.
  350. * To be used only in order to compare reorder buffer head with NSSN.
  351. * We fully trust NSSN unless it is behind us due to reorder timeout.
  352. * Reorder timeout can only bring us up to buffer_size SNs ahead of NSSN.
  353. */
  354. static bool iwl_mvm_is_sn_less(u16 sn1, u16 sn2, u16 buffer_size)
  355. {
  356. return ieee80211_sn_less(sn1, sn2) &&
  357. !ieee80211_sn_less(sn1, sn2 - buffer_size);
  358. }
  359. #define RX_REORDER_BUF_TIMEOUT_MQ (HZ / 10)
  360. static void iwl_mvm_release_frames(struct iwl_mvm *mvm,
  361. struct ieee80211_sta *sta,
  362. struct napi_struct *napi,
  363. struct iwl_mvm_baid_data *baid_data,
  364. struct iwl_mvm_reorder_buffer *reorder_buf,
  365. u16 nssn)
  366. {
  367. struct iwl_mvm_reorder_buf_entry *entries =
  368. &baid_data->entries[reorder_buf->queue *
  369. baid_data->entries_per_queue];
  370. u16 ssn = reorder_buf->head_sn;
  371. lockdep_assert_held(&reorder_buf->lock);
  372. /* ignore nssn smaller than head sn - this can happen due to timeout */
  373. if (iwl_mvm_is_sn_less(nssn, ssn, reorder_buf->buf_size))
  374. goto set_timer;
  375. while (iwl_mvm_is_sn_less(ssn, nssn, reorder_buf->buf_size)) {
  376. int index = ssn % reorder_buf->buf_size;
  377. struct sk_buff_head *skb_list = &entries[index].e.frames;
  378. struct sk_buff *skb;
  379. ssn = ieee80211_sn_inc(ssn);
  380. /*
  381. * Empty the list. Will have more than one frame for A-MSDU.
  382. * Empty list is valid as well since nssn indicates frames were
  383. * received.
  384. */
  385. while ((skb = __skb_dequeue(skb_list))) {
  386. iwl_mvm_pass_packet_to_mac80211(mvm, napi, skb,
  387. reorder_buf->queue,
  388. sta);
  389. reorder_buf->num_stored--;
  390. }
  391. }
  392. reorder_buf->head_sn = nssn;
  393. set_timer:
  394. if (reorder_buf->num_stored && !reorder_buf->removed) {
  395. u16 index = reorder_buf->head_sn % reorder_buf->buf_size;
  396. while (skb_queue_empty(&entries[index].e.frames))
  397. index = (index + 1) % reorder_buf->buf_size;
  398. /* modify timer to match next frame's expiration time */
  399. mod_timer(&reorder_buf->reorder_timer,
  400. entries[index].e.reorder_time + 1 +
  401. RX_REORDER_BUF_TIMEOUT_MQ);
  402. } else {
  403. del_timer(&reorder_buf->reorder_timer);
  404. }
  405. }
  406. void iwl_mvm_reorder_timer_expired(struct timer_list *t)
  407. {
  408. struct iwl_mvm_reorder_buffer *buf = from_timer(buf, t, reorder_timer);
  409. struct iwl_mvm_baid_data *baid_data =
  410. iwl_mvm_baid_data_from_reorder_buf(buf);
  411. struct iwl_mvm_reorder_buf_entry *entries =
  412. &baid_data->entries[buf->queue * baid_data->entries_per_queue];
  413. int i;
  414. u16 sn = 0, index = 0;
  415. bool expired = false;
  416. bool cont = false;
  417. spin_lock(&buf->lock);
  418. if (!buf->num_stored || buf->removed) {
  419. spin_unlock(&buf->lock);
  420. return;
  421. }
  422. for (i = 0; i < buf->buf_size ; i++) {
  423. index = (buf->head_sn + i) % buf->buf_size;
  424. if (skb_queue_empty(&entries[index].e.frames)) {
  425. /*
  426. * If there is a hole and the next frame didn't expire
  427. * we want to break and not advance SN
  428. */
  429. cont = false;
  430. continue;
  431. }
  432. if (!cont &&
  433. !time_after(jiffies, entries[index].e.reorder_time +
  434. RX_REORDER_BUF_TIMEOUT_MQ))
  435. break;
  436. expired = true;
  437. /* continue until next hole after this expired frames */
  438. cont = true;
  439. sn = ieee80211_sn_add(buf->head_sn, i + 1);
  440. }
  441. if (expired) {
  442. struct ieee80211_sta *sta;
  443. struct iwl_mvm_sta *mvmsta;
  444. u8 sta_id = baid_data->sta_id;
  445. rcu_read_lock();
  446. sta = rcu_dereference(buf->mvm->fw_id_to_mac_id[sta_id]);
  447. mvmsta = iwl_mvm_sta_from_mac80211(sta);
  448. /* SN is set to the last expired frame + 1 */
  449. IWL_DEBUG_HT(buf->mvm,
  450. "Releasing expired frames for sta %u, sn %d\n",
  451. sta_id, sn);
  452. iwl_mvm_event_frame_timeout_callback(buf->mvm, mvmsta->vif,
  453. sta, baid_data->tid);
  454. iwl_mvm_release_frames(buf->mvm, sta, NULL, baid_data, buf, sn);
  455. rcu_read_unlock();
  456. } else {
  457. /*
  458. * If no frame expired and there are stored frames, index is now
  459. * pointing to the first unexpired frame - modify timer
  460. * accordingly to this frame.
  461. */
  462. mod_timer(&buf->reorder_timer,
  463. entries[index].e.reorder_time +
  464. 1 + RX_REORDER_BUF_TIMEOUT_MQ);
  465. }
  466. spin_unlock(&buf->lock);
  467. }
  468. static void iwl_mvm_del_ba(struct iwl_mvm *mvm, int queue,
  469. struct iwl_mvm_delba_data *data)
  470. {
  471. struct iwl_mvm_baid_data *ba_data;
  472. struct ieee80211_sta *sta;
  473. struct iwl_mvm_reorder_buffer *reorder_buf;
  474. u8 baid = data->baid;
  475. if (WARN_ONCE(baid >= IWL_MAX_BAID, "invalid BAID: %x\n", baid))
  476. return;
  477. rcu_read_lock();
  478. ba_data = rcu_dereference(mvm->baid_map[baid]);
  479. if (WARN_ON_ONCE(!ba_data))
  480. goto out;
  481. sta = rcu_dereference(mvm->fw_id_to_mac_id[ba_data->sta_id]);
  482. if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta)))
  483. goto out;
  484. reorder_buf = &ba_data->reorder_buf[queue];
  485. /* release all frames that are in the reorder buffer to the stack */
  486. spin_lock_bh(&reorder_buf->lock);
  487. iwl_mvm_release_frames(mvm, sta, NULL, ba_data, reorder_buf,
  488. ieee80211_sn_add(reorder_buf->head_sn,
  489. reorder_buf->buf_size));
  490. spin_unlock_bh(&reorder_buf->lock);
  491. del_timer_sync(&reorder_buf->reorder_timer);
  492. out:
  493. rcu_read_unlock();
  494. }
  495. void iwl_mvm_rx_queue_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
  496. int queue)
  497. {
  498. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  499. struct iwl_rxq_sync_notification *notif;
  500. struct iwl_mvm_internal_rxq_notif *internal_notif;
  501. notif = (void *)pkt->data;
  502. internal_notif = (void *)notif->payload;
  503. if (internal_notif->sync) {
  504. if (mvm->queue_sync_cookie != internal_notif->cookie) {
  505. WARN_ONCE(1,
  506. "Received expired RX queue sync message\n");
  507. return;
  508. }
  509. if (!atomic_dec_return(&mvm->queue_sync_counter))
  510. wake_up(&mvm->rx_sync_waitq);
  511. }
  512. switch (internal_notif->type) {
  513. case IWL_MVM_RXQ_EMPTY:
  514. break;
  515. case IWL_MVM_RXQ_NOTIF_DEL_BA:
  516. iwl_mvm_del_ba(mvm, queue, (void *)internal_notif->data);
  517. break;
  518. default:
  519. WARN_ONCE(1, "Invalid identifier %d", internal_notif->type);
  520. }
  521. }
  522. /*
  523. * Returns true if the MPDU was buffered\dropped, false if it should be passed
  524. * to upper layer.
  525. */
  526. static bool iwl_mvm_reorder(struct iwl_mvm *mvm,
  527. struct napi_struct *napi,
  528. int queue,
  529. struct ieee80211_sta *sta,
  530. struct sk_buff *skb,
  531. struct iwl_rx_mpdu_desc *desc)
  532. {
  533. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  534. struct iwl_mvm_sta *mvm_sta;
  535. struct iwl_mvm_baid_data *baid_data;
  536. struct iwl_mvm_reorder_buffer *buffer;
  537. struct sk_buff *tail;
  538. u32 reorder = le32_to_cpu(desc->reorder_data);
  539. bool amsdu = desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU;
  540. bool last_subframe =
  541. desc->amsdu_info & IWL_RX_MPDU_AMSDU_LAST_SUBFRAME;
  542. u8 tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
  543. u8 sub_frame_idx = desc->amsdu_info &
  544. IWL_RX_MPDU_AMSDU_SUBFRAME_IDX_MASK;
  545. struct iwl_mvm_reorder_buf_entry *entries;
  546. int index;
  547. u16 nssn, sn;
  548. u8 baid;
  549. baid = (reorder & IWL_RX_MPDU_REORDER_BAID_MASK) >>
  550. IWL_RX_MPDU_REORDER_BAID_SHIFT;
  551. /*
  552. * This also covers the case of receiving a Block Ack Request
  553. * outside a BA session; we'll pass it to mac80211 and that
  554. * then sends a delBA action frame.
  555. */
  556. if (baid == IWL_RX_REORDER_DATA_INVALID_BAID)
  557. return false;
  558. /* no sta yet */
  559. if (WARN_ONCE(IS_ERR_OR_NULL(sta),
  560. "Got valid BAID without a valid station assigned\n"))
  561. return false;
  562. mvm_sta = iwl_mvm_sta_from_mac80211(sta);
  563. /* not a data packet or a bar */
  564. if (!ieee80211_is_back_req(hdr->frame_control) &&
  565. (!ieee80211_is_data_qos(hdr->frame_control) ||
  566. is_multicast_ether_addr(hdr->addr1)))
  567. return false;
  568. if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
  569. return false;
  570. baid_data = rcu_dereference(mvm->baid_map[baid]);
  571. if (!baid_data) {
  572. IWL_DEBUG_RX(mvm,
  573. "Got valid BAID but no baid allocated, bypass the re-ordering buffer. Baid %d reorder 0x%x\n",
  574. baid, reorder);
  575. return false;
  576. }
  577. if (WARN(tid != baid_data->tid || mvm_sta->sta_id != baid_data->sta_id,
  578. "baid 0x%x is mapped to sta:%d tid:%d, but was received for sta:%d tid:%d\n",
  579. baid, baid_data->sta_id, baid_data->tid, mvm_sta->sta_id,
  580. tid))
  581. return false;
  582. nssn = reorder & IWL_RX_MPDU_REORDER_NSSN_MASK;
  583. sn = (reorder & IWL_RX_MPDU_REORDER_SN_MASK) >>
  584. IWL_RX_MPDU_REORDER_SN_SHIFT;
  585. buffer = &baid_data->reorder_buf[queue];
  586. entries = &baid_data->entries[queue * baid_data->entries_per_queue];
  587. spin_lock_bh(&buffer->lock);
  588. if (!buffer->valid) {
  589. if (reorder & IWL_RX_MPDU_REORDER_BA_OLD_SN) {
  590. spin_unlock_bh(&buffer->lock);
  591. return false;
  592. }
  593. buffer->valid = true;
  594. }
  595. if (ieee80211_is_back_req(hdr->frame_control)) {
  596. iwl_mvm_release_frames(mvm, sta, napi, baid_data, buffer, nssn);
  597. goto drop;
  598. }
  599. /*
  600. * If there was a significant jump in the nssn - adjust.
  601. * If the SN is smaller than the NSSN it might need to first go into
  602. * the reorder buffer, in which case we just release up to it and the
  603. * rest of the function will take care of storing it and releasing up to
  604. * the nssn
  605. */
  606. if (!iwl_mvm_is_sn_less(nssn, buffer->head_sn + buffer->buf_size,
  607. buffer->buf_size) ||
  608. !ieee80211_sn_less(sn, buffer->head_sn + buffer->buf_size)) {
  609. u16 min_sn = ieee80211_sn_less(sn, nssn) ? sn : nssn;
  610. iwl_mvm_release_frames(mvm, sta, napi, baid_data, buffer,
  611. min_sn);
  612. }
  613. /* drop any oudated packets */
  614. if (ieee80211_sn_less(sn, buffer->head_sn))
  615. goto drop;
  616. /* release immediately if allowed by nssn and no stored frames */
  617. if (!buffer->num_stored && ieee80211_sn_less(sn, nssn)) {
  618. if (iwl_mvm_is_sn_less(buffer->head_sn, nssn,
  619. buffer->buf_size) &&
  620. (!amsdu || last_subframe))
  621. buffer->head_sn = nssn;
  622. /* No need to update AMSDU last SN - we are moving the head */
  623. spin_unlock_bh(&buffer->lock);
  624. return false;
  625. }
  626. /*
  627. * release immediately if there are no stored frames, and the sn is
  628. * equal to the head.
  629. * This can happen due to reorder timer, where NSSN is behind head_sn.
  630. * When we released everything, and we got the next frame in the
  631. * sequence, according to the NSSN we can't release immediately,
  632. * while technically there is no hole and we can move forward.
  633. */
  634. if (!buffer->num_stored && sn == buffer->head_sn) {
  635. if (!amsdu || last_subframe)
  636. buffer->head_sn = ieee80211_sn_inc(buffer->head_sn);
  637. /* No need to update AMSDU last SN - we are moving the head */
  638. spin_unlock_bh(&buffer->lock);
  639. return false;
  640. }
  641. index = sn % buffer->buf_size;
  642. /*
  643. * Check if we already stored this frame
  644. * As AMSDU is either received or not as whole, logic is simple:
  645. * If we have frames in that position in the buffer and the last frame
  646. * originated from AMSDU had a different SN then it is a retransmission.
  647. * If it is the same SN then if the subframe index is incrementing it
  648. * is the same AMSDU - otherwise it is a retransmission.
  649. */
  650. tail = skb_peek_tail(&entries[index].e.frames);
  651. if (tail && !amsdu)
  652. goto drop;
  653. else if (tail && (sn != buffer->last_amsdu ||
  654. buffer->last_sub_index >= sub_frame_idx))
  655. goto drop;
  656. /* put in reorder buffer */
  657. __skb_queue_tail(&entries[index].e.frames, skb);
  658. buffer->num_stored++;
  659. entries[index].e.reorder_time = jiffies;
  660. if (amsdu) {
  661. buffer->last_amsdu = sn;
  662. buffer->last_sub_index = sub_frame_idx;
  663. }
  664. /*
  665. * We cannot trust NSSN for AMSDU sub-frames that are not the last.
  666. * The reason is that NSSN advances on the first sub-frame, and may
  667. * cause the reorder buffer to advance before all the sub-frames arrive.
  668. * Example: reorder buffer contains SN 0 & 2, and we receive AMSDU with
  669. * SN 1. NSSN for first sub frame will be 3 with the result of driver
  670. * releasing SN 0,1, 2. When sub-frame 1 arrives - reorder buffer is
  671. * already ahead and it will be dropped.
  672. * If the last sub-frame is not on this queue - we will get frame
  673. * release notification with up to date NSSN.
  674. */
  675. if (!amsdu || last_subframe)
  676. iwl_mvm_release_frames(mvm, sta, napi, baid_data, buffer, nssn);
  677. spin_unlock_bh(&buffer->lock);
  678. return true;
  679. drop:
  680. kfree_skb(skb);
  681. spin_unlock_bh(&buffer->lock);
  682. return true;
  683. }
  684. static void iwl_mvm_agg_rx_received(struct iwl_mvm *mvm,
  685. u32 reorder_data, u8 baid)
  686. {
  687. unsigned long now = jiffies;
  688. unsigned long timeout;
  689. struct iwl_mvm_baid_data *data;
  690. rcu_read_lock();
  691. data = rcu_dereference(mvm->baid_map[baid]);
  692. if (!data) {
  693. IWL_DEBUG_RX(mvm,
  694. "Got valid BAID but no baid allocated, bypass the re-ordering buffer. Baid %d reorder 0x%x\n",
  695. baid, reorder_data);
  696. goto out;
  697. }
  698. if (!data->timeout)
  699. goto out;
  700. timeout = data->timeout;
  701. /*
  702. * Do not update last rx all the time to avoid cache bouncing
  703. * between the rx queues.
  704. * Update it every timeout. Worst case is the session will
  705. * expire after ~ 2 * timeout, which doesn't matter that much.
  706. */
  707. if (time_before(data->last_rx + TU_TO_JIFFIES(timeout), now))
  708. /* Update is atomic */
  709. data->last_rx = now;
  710. out:
  711. rcu_read_unlock();
  712. }
  713. static void iwl_mvm_flip_address(u8 *addr)
  714. {
  715. int i;
  716. u8 mac_addr[ETH_ALEN];
  717. for (i = 0; i < ETH_ALEN; i++)
  718. mac_addr[i] = addr[ETH_ALEN - i - 1];
  719. ether_addr_copy(addr, mac_addr);
  720. }
  721. void iwl_mvm_rx_mpdu_mq(struct iwl_mvm *mvm, struct napi_struct *napi,
  722. struct iwl_rx_cmd_buffer *rxb, int queue)
  723. {
  724. struct ieee80211_rx_status *rx_status;
  725. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  726. struct iwl_rx_mpdu_desc *desc = (void *)pkt->data;
  727. struct ieee80211_hdr *hdr = (void *)(pkt->data + sizeof(*desc));
  728. u32 len = le16_to_cpu(desc->mpdu_len);
  729. u32 rate_n_flags = le32_to_cpu(desc->rate_n_flags);
  730. u16 phy_info = le16_to_cpu(desc->phy_info);
  731. struct ieee80211_sta *sta = NULL;
  732. struct sk_buff *skb;
  733. u8 crypt_len = 0;
  734. if (unlikely(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)))
  735. return;
  736. /* Dont use dev_alloc_skb(), we'll have enough headroom once
  737. * ieee80211_hdr pulled.
  738. */
  739. skb = alloc_skb(128, GFP_ATOMIC);
  740. if (!skb) {
  741. IWL_ERR(mvm, "alloc_skb failed\n");
  742. return;
  743. }
  744. rx_status = IEEE80211_SKB_RXCB(skb);
  745. if (iwl_mvm_rx_crypto(mvm, hdr, rx_status, desc,
  746. le32_to_cpu(pkt->len_n_flags), queue,
  747. &crypt_len)) {
  748. kfree_skb(skb);
  749. return;
  750. }
  751. /*
  752. * Keep packets with CRC errors (and with overrun) for monitor mode
  753. * (otherwise the firmware discards them) but mark them as bad.
  754. */
  755. if (!(desc->status & cpu_to_le16(IWL_RX_MPDU_STATUS_CRC_OK)) ||
  756. !(desc->status & cpu_to_le16(IWL_RX_MPDU_STATUS_OVERRUN_OK))) {
  757. IWL_DEBUG_RX(mvm, "Bad CRC or FIFO: 0x%08X.\n",
  758. le16_to_cpu(desc->status));
  759. rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
  760. }
  761. /* set the preamble flag if appropriate */
  762. if (phy_info & IWL_RX_MPDU_PHY_SHORT_PREAMBLE)
  763. rx_status->enc_flags |= RX_ENC_FLAG_SHORTPRE;
  764. if (likely(!(phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD))) {
  765. rx_status->mactime = le64_to_cpu(desc->tsf_on_air_rise);
  766. /* TSF as indicated by the firmware is at INA time */
  767. rx_status->flag |= RX_FLAG_MACTIME_PLCP_START;
  768. }
  769. rx_status->device_timestamp = le32_to_cpu(desc->gp2_on_air_rise);
  770. rx_status->band = desc->channel > 14 ? NL80211_BAND_5GHZ :
  771. NL80211_BAND_2GHZ;
  772. rx_status->freq = ieee80211_channel_to_frequency(desc->channel,
  773. rx_status->band);
  774. iwl_mvm_get_signal_strength(mvm, desc, rx_status);
  775. /* update aggregation data for monitor sake on default queue */
  776. if (!queue && (phy_info & IWL_RX_MPDU_PHY_AMPDU)) {
  777. bool toggle_bit = phy_info & IWL_RX_MPDU_PHY_AMPDU_TOGGLE;
  778. rx_status->flag |= RX_FLAG_AMPDU_DETAILS;
  779. rx_status->ampdu_reference = mvm->ampdu_ref;
  780. /* toggle is switched whenever new aggregation starts */
  781. if (toggle_bit != mvm->ampdu_toggle) {
  782. mvm->ampdu_ref++;
  783. mvm->ampdu_toggle = toggle_bit;
  784. }
  785. }
  786. rcu_read_lock();
  787. if (desc->status & cpu_to_le16(IWL_RX_MPDU_STATUS_SRC_STA_FOUND)) {
  788. u8 id = desc->sta_id_flags & IWL_RX_MPDU_SIF_STA_ID_MASK;
  789. if (!WARN_ON_ONCE(id >= ARRAY_SIZE(mvm->fw_id_to_mac_id))) {
  790. sta = rcu_dereference(mvm->fw_id_to_mac_id[id]);
  791. if (IS_ERR(sta))
  792. sta = NULL;
  793. }
  794. } else if (!is_multicast_ether_addr(hdr->addr2)) {
  795. /*
  796. * This is fine since we prevent two stations with the same
  797. * address from being added.
  798. */
  799. sta = ieee80211_find_sta_by_ifaddr(mvm->hw, hdr->addr2, NULL);
  800. }
  801. if (sta) {
  802. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  803. struct ieee80211_vif *tx_blocked_vif =
  804. rcu_dereference(mvm->csa_tx_blocked_vif);
  805. u8 baid = (u8)((le32_to_cpu(desc->reorder_data) &
  806. IWL_RX_MPDU_REORDER_BAID_MASK) >>
  807. IWL_RX_MPDU_REORDER_BAID_SHIFT);
  808. /*
  809. * We have tx blocked stations (with CS bit). If we heard
  810. * frames from a blocked station on a new channel we can
  811. * TX to it again.
  812. */
  813. if (unlikely(tx_blocked_vif) &&
  814. tx_blocked_vif == mvmsta->vif) {
  815. struct iwl_mvm_vif *mvmvif =
  816. iwl_mvm_vif_from_mac80211(tx_blocked_vif);
  817. if (mvmvif->csa_target_freq == rx_status->freq)
  818. iwl_mvm_sta_modify_disable_tx_ap(mvm, sta,
  819. false);
  820. }
  821. rs_update_last_rssi(mvm, mvmsta, rx_status);
  822. if (iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_RSSI) &&
  823. ieee80211_is_beacon(hdr->frame_control)) {
  824. struct iwl_fw_dbg_trigger_tlv *trig;
  825. struct iwl_fw_dbg_trigger_low_rssi *rssi_trig;
  826. bool trig_check;
  827. s32 rssi;
  828. trig = iwl_fw_dbg_get_trigger(mvm->fw,
  829. FW_DBG_TRIGGER_RSSI);
  830. rssi_trig = (void *)trig->data;
  831. rssi = le32_to_cpu(rssi_trig->rssi);
  832. trig_check =
  833. iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
  834. ieee80211_vif_to_wdev(mvmsta->vif),
  835. trig);
  836. if (trig_check && rx_status->signal < rssi)
  837. iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
  838. NULL);
  839. }
  840. if (ieee80211_is_data(hdr->frame_control))
  841. iwl_mvm_rx_csum(sta, skb, desc);
  842. if (iwl_mvm_is_dup(sta, queue, rx_status, hdr, desc)) {
  843. kfree_skb(skb);
  844. goto out;
  845. }
  846. /*
  847. * Our hardware de-aggregates AMSDUs but copies the mac header
  848. * as it to the de-aggregated MPDUs. We need to turn off the
  849. * AMSDU bit in the QoS control ourselves.
  850. * In addition, HW reverses addr3 and addr4 - reverse it back.
  851. */
  852. if ((desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU) &&
  853. !WARN_ON(!ieee80211_is_data_qos(hdr->frame_control))) {
  854. u8 *qc = ieee80211_get_qos_ctl(hdr);
  855. *qc &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT;
  856. if (mvm->trans->cfg->device_family ==
  857. IWL_DEVICE_FAMILY_9000) {
  858. iwl_mvm_flip_address(hdr->addr3);
  859. if (ieee80211_has_a4(hdr->frame_control))
  860. iwl_mvm_flip_address(hdr->addr4);
  861. }
  862. }
  863. if (baid != IWL_RX_REORDER_DATA_INVALID_BAID) {
  864. u32 reorder_data = le32_to_cpu(desc->reorder_data);
  865. iwl_mvm_agg_rx_received(mvm, reorder_data, baid);
  866. }
  867. }
  868. /* Set up the HT phy flags */
  869. switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) {
  870. case RATE_MCS_CHAN_WIDTH_20:
  871. break;
  872. case RATE_MCS_CHAN_WIDTH_40:
  873. rx_status->bw = RATE_INFO_BW_40;
  874. break;
  875. case RATE_MCS_CHAN_WIDTH_80:
  876. rx_status->bw = RATE_INFO_BW_80;
  877. break;
  878. case RATE_MCS_CHAN_WIDTH_160:
  879. rx_status->bw = RATE_INFO_BW_160;
  880. break;
  881. }
  882. if (!(rate_n_flags & RATE_MCS_CCK_MSK) &&
  883. rate_n_flags & RATE_MCS_SGI_MSK)
  884. rx_status->enc_flags |= RX_ENC_FLAG_SHORT_GI;
  885. if (rate_n_flags & RATE_HT_MCS_GF_MSK)
  886. rx_status->enc_flags |= RX_ENC_FLAG_HT_GF;
  887. if (rate_n_flags & RATE_MCS_LDPC_MSK)
  888. rx_status->enc_flags |= RX_ENC_FLAG_LDPC;
  889. if (rate_n_flags & RATE_MCS_HT_MSK) {
  890. u8 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >>
  891. RATE_MCS_STBC_POS;
  892. rx_status->encoding = RX_ENC_HT;
  893. rx_status->rate_idx = rate_n_flags & RATE_HT_MCS_INDEX_MSK;
  894. rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT;
  895. } else if (rate_n_flags & RATE_MCS_VHT_MSK) {
  896. u8 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >>
  897. RATE_MCS_STBC_POS;
  898. rx_status->nss =
  899. ((rate_n_flags & RATE_VHT_MCS_NSS_MSK) >>
  900. RATE_VHT_MCS_NSS_POS) + 1;
  901. rx_status->rate_idx = rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK;
  902. rx_status->encoding = RX_ENC_VHT;
  903. rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT;
  904. if (rate_n_flags & RATE_MCS_BF_MSK)
  905. rx_status->enc_flags |= RX_ENC_FLAG_BF;
  906. } else {
  907. int rate = iwl_mvm_legacy_rate_to_mac80211_idx(rate_n_flags,
  908. rx_status->band);
  909. if (WARN(rate < 0 || rate > 0xFF,
  910. "Invalid rate flags 0x%x, band %d,\n",
  911. rate_n_flags, rx_status->band)) {
  912. kfree_skb(skb);
  913. goto out;
  914. }
  915. rx_status->rate_idx = rate;
  916. }
  917. /* management stuff on default queue */
  918. if (!queue) {
  919. if (unlikely((ieee80211_is_beacon(hdr->frame_control) ||
  920. ieee80211_is_probe_resp(hdr->frame_control)) &&
  921. mvm->sched_scan_pass_all ==
  922. SCHED_SCAN_PASS_ALL_ENABLED))
  923. mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_FOUND;
  924. if (unlikely(ieee80211_is_beacon(hdr->frame_control) ||
  925. ieee80211_is_probe_resp(hdr->frame_control)))
  926. rx_status->boottime_ns = ktime_get_boot_ns();
  927. }
  928. iwl_mvm_create_skb(skb, hdr, len, crypt_len, rxb);
  929. if (!iwl_mvm_reorder(mvm, napi, queue, sta, skb, desc))
  930. iwl_mvm_pass_packet_to_mac80211(mvm, napi, skb, queue, sta);
  931. out:
  932. rcu_read_unlock();
  933. }
  934. void iwl_mvm_rx_frame_release(struct iwl_mvm *mvm, struct napi_struct *napi,
  935. struct iwl_rx_cmd_buffer *rxb, int queue)
  936. {
  937. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  938. struct iwl_frame_release *release = (void *)pkt->data;
  939. struct ieee80211_sta *sta;
  940. struct iwl_mvm_reorder_buffer *reorder_buf;
  941. struct iwl_mvm_baid_data *ba_data;
  942. int baid = release->baid;
  943. IWL_DEBUG_HT(mvm, "Frame release notification for BAID %u, NSSN %d\n",
  944. release->baid, le16_to_cpu(release->nssn));
  945. if (WARN_ON_ONCE(baid == IWL_RX_REORDER_DATA_INVALID_BAID))
  946. return;
  947. rcu_read_lock();
  948. ba_data = rcu_dereference(mvm->baid_map[baid]);
  949. if (WARN_ON_ONCE(!ba_data))
  950. goto out;
  951. sta = rcu_dereference(mvm->fw_id_to_mac_id[ba_data->sta_id]);
  952. if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta)))
  953. goto out;
  954. reorder_buf = &ba_data->reorder_buf[queue];
  955. spin_lock_bh(&reorder_buf->lock);
  956. iwl_mvm_release_frames(mvm, sta, napi, ba_data, reorder_buf,
  957. le16_to_cpu(release->nssn));
  958. spin_unlock_bh(&reorder_buf->lock);
  959. out:
  960. rcu_read_unlock();
  961. }