rxmq.c 35 KB

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