tx.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722
  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) 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 - 2015 Intel Mobile Communications GmbH
  37. * All rights reserved.
  38. *
  39. * Redistribution and use in source and binary forms, with or without
  40. * modification, are permitted provided that the following conditions
  41. * are met:
  42. *
  43. * * Redistributions of source code must retain the above copyright
  44. * notice, this list of conditions and the following disclaimer.
  45. * * Redistributions in binary form must reproduce the above copyright
  46. * notice, this list of conditions and the following disclaimer in
  47. * the documentation and/or other materials provided with the
  48. * distribution.
  49. * * Neither the name Intel Corporation nor the names of its
  50. * contributors may be used to endorse or promote products derived
  51. * from this software without specific prior written permission.
  52. *
  53. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  54. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  55. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  56. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  57. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  58. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  59. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  60. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  61. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  62. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  63. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  64. *
  65. *****************************************************************************/
  66. #include <linux/ieee80211.h>
  67. #include <linux/etherdevice.h>
  68. #include <linux/tcp.h>
  69. #include <net/ip.h>
  70. #include <net/ipv6.h>
  71. #include "iwl-trans.h"
  72. #include "iwl-eeprom-parse.h"
  73. #include "mvm.h"
  74. #include "sta.h"
  75. #include "fw-dbg.h"
  76. static void
  77. iwl_mvm_bar_check_trigger(struct iwl_mvm *mvm, const u8 *addr,
  78. u16 tid, u16 ssn)
  79. {
  80. struct iwl_fw_dbg_trigger_tlv *trig;
  81. struct iwl_fw_dbg_trigger_ba *ba_trig;
  82. if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
  83. return;
  84. trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
  85. ba_trig = (void *)trig->data;
  86. if (!iwl_fw_dbg_trigger_check_stop(mvm, NULL, trig))
  87. return;
  88. if (!(le16_to_cpu(ba_trig->tx_bar) & BIT(tid)))
  89. return;
  90. iwl_mvm_fw_dbg_collect_trig(mvm, trig,
  91. "BAR sent to %pM, tid %d, ssn %d",
  92. addr, tid, ssn);
  93. }
  94. #define OPT_HDR(type, skb, off) \
  95. (type *)(skb_network_header(skb) + (off))
  96. static void iwl_mvm_tx_csum(struct iwl_mvm *mvm, struct sk_buff *skb,
  97. struct ieee80211_hdr *hdr,
  98. struct ieee80211_tx_info *info,
  99. struct iwl_tx_cmd *tx_cmd)
  100. {
  101. #if IS_ENABLED(CONFIG_INET)
  102. u16 mh_len = ieee80211_hdrlen(hdr->frame_control);
  103. u16 offload_assist = le16_to_cpu(tx_cmd->offload_assist);
  104. u8 protocol = 0;
  105. /*
  106. * Do not compute checksum if already computed or if transport will
  107. * compute it
  108. */
  109. if (skb->ip_summed != CHECKSUM_PARTIAL || IWL_MVM_SW_TX_CSUM_OFFLOAD)
  110. return;
  111. /* We do not expect to be requested to csum stuff we do not support */
  112. if (WARN_ONCE(!(mvm->hw->netdev_features & IWL_TX_CSUM_NETIF_FLAGS) ||
  113. (skb->protocol != htons(ETH_P_IP) &&
  114. skb->protocol != htons(ETH_P_IPV6)),
  115. "No support for requested checksum\n")) {
  116. skb_checksum_help(skb);
  117. return;
  118. }
  119. if (skb->protocol == htons(ETH_P_IP)) {
  120. protocol = ip_hdr(skb)->protocol;
  121. } else {
  122. #if IS_ENABLED(CONFIG_IPV6)
  123. struct ipv6hdr *ipv6h =
  124. (struct ipv6hdr *)skb_network_header(skb);
  125. unsigned int off = sizeof(*ipv6h);
  126. protocol = ipv6h->nexthdr;
  127. while (protocol != NEXTHDR_NONE && ipv6_ext_hdr(protocol)) {
  128. struct ipv6_opt_hdr *hp;
  129. /* only supported extension headers */
  130. if (protocol != NEXTHDR_ROUTING &&
  131. protocol != NEXTHDR_HOP &&
  132. protocol != NEXTHDR_DEST) {
  133. skb_checksum_help(skb);
  134. return;
  135. }
  136. hp = OPT_HDR(struct ipv6_opt_hdr, skb, off);
  137. protocol = hp->nexthdr;
  138. off += ipv6_optlen(hp);
  139. }
  140. /* if we get here - protocol now should be TCP/UDP */
  141. #endif
  142. }
  143. if (protocol != IPPROTO_TCP && protocol != IPPROTO_UDP) {
  144. WARN_ON_ONCE(1);
  145. skb_checksum_help(skb);
  146. return;
  147. }
  148. /* enable L4 csum */
  149. offload_assist |= BIT(TX_CMD_OFFLD_L4_EN);
  150. /*
  151. * Set offset to IP header (snap).
  152. * We don't support tunneling so no need to take care of inner header.
  153. * Size is in words.
  154. */
  155. offload_assist |= (4 << TX_CMD_OFFLD_IP_HDR);
  156. /* Do IPv4 csum for AMSDU only (no IP csum for Ipv6) */
  157. if (skb->protocol == htons(ETH_P_IP) &&
  158. (offload_assist & BIT(TX_CMD_OFFLD_AMSDU))) {
  159. ip_hdr(skb)->check = 0;
  160. offload_assist |= BIT(TX_CMD_OFFLD_L3_EN);
  161. }
  162. /* reset UDP/TCP header csum */
  163. if (protocol == IPPROTO_TCP)
  164. tcp_hdr(skb)->check = 0;
  165. else
  166. udp_hdr(skb)->check = 0;
  167. /* mac header len should include IV, size is in words */
  168. if (info->control.hw_key)
  169. mh_len += info->control.hw_key->iv_len;
  170. mh_len /= 2;
  171. offload_assist |= mh_len << TX_CMD_OFFLD_MH_SIZE;
  172. tx_cmd->offload_assist = cpu_to_le16(offload_assist);
  173. #endif
  174. }
  175. /*
  176. * Sets most of the Tx cmd's fields
  177. */
  178. void iwl_mvm_set_tx_cmd(struct iwl_mvm *mvm, struct sk_buff *skb,
  179. struct iwl_tx_cmd *tx_cmd,
  180. struct ieee80211_tx_info *info, u8 sta_id)
  181. {
  182. struct ieee80211_tx_info *skb_info = IEEE80211_SKB_CB(skb);
  183. struct ieee80211_hdr *hdr = (void *)skb->data;
  184. __le16 fc = hdr->frame_control;
  185. u32 tx_flags = le32_to_cpu(tx_cmd->tx_flags);
  186. u32 len = skb->len + FCS_LEN;
  187. u8 ac;
  188. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
  189. tx_flags |= TX_CMD_FLG_ACK;
  190. else
  191. tx_flags &= ~TX_CMD_FLG_ACK;
  192. if (ieee80211_is_probe_resp(fc))
  193. tx_flags |= TX_CMD_FLG_TSF;
  194. if (ieee80211_has_morefrags(fc))
  195. tx_flags |= TX_CMD_FLG_MORE_FRAG;
  196. if (ieee80211_is_data_qos(fc)) {
  197. u8 *qc = ieee80211_get_qos_ctl(hdr);
  198. tx_cmd->tid_tspec = qc[0] & 0xf;
  199. tx_flags &= ~TX_CMD_FLG_SEQ_CTL;
  200. if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
  201. tx_cmd->offload_assist |=
  202. cpu_to_le16(BIT(TX_CMD_OFFLD_AMSDU));
  203. } else if (ieee80211_is_back_req(fc)) {
  204. struct ieee80211_bar *bar = (void *)skb->data;
  205. u16 control = le16_to_cpu(bar->control);
  206. u16 ssn = le16_to_cpu(bar->start_seq_num);
  207. tx_flags |= TX_CMD_FLG_ACK | TX_CMD_FLG_BAR;
  208. tx_cmd->tid_tspec = (control &
  209. IEEE80211_BAR_CTRL_TID_INFO_MASK) >>
  210. IEEE80211_BAR_CTRL_TID_INFO_SHIFT;
  211. WARN_ON_ONCE(tx_cmd->tid_tspec >= IWL_MAX_TID_COUNT);
  212. iwl_mvm_bar_check_trigger(mvm, bar->ra, tx_cmd->tid_tspec,
  213. ssn);
  214. } else {
  215. tx_cmd->tid_tspec = IWL_TID_NON_QOS;
  216. if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ)
  217. tx_flags |= TX_CMD_FLG_SEQ_CTL;
  218. else
  219. tx_flags &= ~TX_CMD_FLG_SEQ_CTL;
  220. }
  221. /* Default to 0 (BE) when tid_spec is set to IWL_TID_NON_QOS */
  222. if (tx_cmd->tid_tspec < IWL_MAX_TID_COUNT)
  223. ac = tid_to_mac80211_ac[tx_cmd->tid_tspec];
  224. else
  225. ac = tid_to_mac80211_ac[0];
  226. tx_flags |= iwl_mvm_bt_coex_tx_prio(mvm, hdr, info, ac) <<
  227. TX_CMD_FLG_BT_PRIO_POS;
  228. if (ieee80211_is_mgmt(fc)) {
  229. if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
  230. tx_cmd->pm_frame_timeout = cpu_to_le16(PM_FRAME_ASSOC);
  231. else if (ieee80211_is_action(fc))
  232. tx_cmd->pm_frame_timeout = cpu_to_le16(PM_FRAME_NONE);
  233. else
  234. tx_cmd->pm_frame_timeout = cpu_to_le16(PM_FRAME_MGMT);
  235. /* The spec allows Action frames in A-MPDU, we don't support
  236. * it
  237. */
  238. WARN_ON_ONCE(info->flags & IEEE80211_TX_CTL_AMPDU);
  239. } else if (info->control.flags & IEEE80211_TX_CTRL_PORT_CTRL_PROTO) {
  240. tx_cmd->pm_frame_timeout = cpu_to_le16(PM_FRAME_MGMT);
  241. } else {
  242. tx_cmd->pm_frame_timeout = cpu_to_le16(PM_FRAME_NONE);
  243. }
  244. if (ieee80211_is_data(fc) && len > mvm->rts_threshold &&
  245. !is_multicast_ether_addr(ieee80211_get_DA(hdr)))
  246. tx_flags |= TX_CMD_FLG_PROT_REQUIRE;
  247. if (fw_has_capa(&mvm->fw->ucode_capa,
  248. IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT) &&
  249. ieee80211_action_contains_tpc(skb))
  250. tx_flags |= TX_CMD_FLG_WRITE_TX_POWER;
  251. tx_cmd->tx_flags = cpu_to_le32(tx_flags);
  252. /* Total # bytes to be transmitted */
  253. tx_cmd->len = cpu_to_le16((u16)skb->len +
  254. (uintptr_t)skb_info->driver_data[0]);
  255. tx_cmd->life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE);
  256. tx_cmd->sta_id = sta_id;
  257. /* padding is inserted later in transport */
  258. if (ieee80211_hdrlen(fc) % 4 &&
  259. !(tx_cmd->offload_assist & cpu_to_le16(BIT(TX_CMD_OFFLD_AMSDU))))
  260. tx_cmd->offload_assist |= cpu_to_le16(BIT(TX_CMD_OFFLD_PAD));
  261. iwl_mvm_tx_csum(mvm, skb, hdr, info, tx_cmd);
  262. }
  263. /*
  264. * Sets the fields in the Tx cmd that are rate related
  265. */
  266. void iwl_mvm_set_tx_cmd_rate(struct iwl_mvm *mvm, struct iwl_tx_cmd *tx_cmd,
  267. struct ieee80211_tx_info *info,
  268. struct ieee80211_sta *sta, __le16 fc)
  269. {
  270. u32 rate_flags;
  271. int rate_idx;
  272. u8 rate_plcp;
  273. /* Set retry limit on RTS packets */
  274. tx_cmd->rts_retry_limit = IWL_RTS_DFAULT_RETRY_LIMIT;
  275. /* Set retry limit on DATA packets and Probe Responses*/
  276. if (ieee80211_is_probe_resp(fc)) {
  277. tx_cmd->data_retry_limit = IWL_MGMT_DFAULT_RETRY_LIMIT;
  278. tx_cmd->rts_retry_limit =
  279. min(tx_cmd->data_retry_limit, tx_cmd->rts_retry_limit);
  280. } else if (ieee80211_is_back_req(fc)) {
  281. tx_cmd->data_retry_limit = IWL_BAR_DFAULT_RETRY_LIMIT;
  282. } else {
  283. tx_cmd->data_retry_limit = IWL_DEFAULT_TX_RETRY;
  284. }
  285. /*
  286. * for data packets, rate info comes from the table inside the fw. This
  287. * table is controlled by LINK_QUALITY commands
  288. */
  289. if (ieee80211_is_data(fc) && sta) {
  290. tx_cmd->initial_rate_index = 0;
  291. tx_cmd->tx_flags |= cpu_to_le32(TX_CMD_FLG_STA_RATE);
  292. return;
  293. } else if (ieee80211_is_back_req(fc)) {
  294. tx_cmd->tx_flags |=
  295. cpu_to_le32(TX_CMD_FLG_ACK | TX_CMD_FLG_BAR);
  296. }
  297. /* HT rate doesn't make sense for a non data frame */
  298. WARN_ONCE(info->control.rates[0].flags & IEEE80211_TX_RC_MCS,
  299. "Got an HT rate (flags:0x%x/mcs:%d) for a non data frame (fc:0x%x)\n",
  300. info->control.rates[0].flags,
  301. info->control.rates[0].idx,
  302. le16_to_cpu(fc));
  303. rate_idx = info->control.rates[0].idx;
  304. /* if the rate isn't a well known legacy rate, take the lowest one */
  305. if (rate_idx < 0 || rate_idx > IWL_RATE_COUNT_LEGACY)
  306. rate_idx = rate_lowest_index(
  307. &mvm->nvm_data->bands[info->band], sta);
  308. /* For 5 GHZ band, remap mac80211 rate indices into driver indices */
  309. if (info->band == NL80211_BAND_5GHZ)
  310. rate_idx += IWL_FIRST_OFDM_RATE;
  311. /* For 2.4 GHZ band, check that there is no need to remap */
  312. BUILD_BUG_ON(IWL_FIRST_CCK_RATE != 0);
  313. /* Get PLCP rate for tx_cmd->rate_n_flags */
  314. rate_plcp = iwl_mvm_mac80211_idx_to_hwrate(rate_idx);
  315. mvm->mgmt_last_antenna_idx =
  316. iwl_mvm_next_antenna(mvm, iwl_mvm_get_valid_tx_ant(mvm),
  317. mvm->mgmt_last_antenna_idx);
  318. if (info->band == NL80211_BAND_2GHZ &&
  319. !iwl_mvm_bt_coex_is_shared_ant_avail(mvm))
  320. rate_flags = mvm->cfg->non_shared_ant << RATE_MCS_ANT_POS;
  321. else
  322. rate_flags =
  323. BIT(mvm->mgmt_last_antenna_idx) << RATE_MCS_ANT_POS;
  324. /* Set CCK flag as needed */
  325. if ((rate_idx >= IWL_FIRST_CCK_RATE) && (rate_idx <= IWL_LAST_CCK_RATE))
  326. rate_flags |= RATE_MCS_CCK_MSK;
  327. /* Set the rate in the TX cmd */
  328. tx_cmd->rate_n_flags = cpu_to_le32((u32)rate_plcp | rate_flags);
  329. }
  330. static inline void iwl_mvm_set_tx_cmd_pn(struct ieee80211_tx_info *info,
  331. u8 *crypto_hdr)
  332. {
  333. struct ieee80211_key_conf *keyconf = info->control.hw_key;
  334. u64 pn;
  335. pn = atomic64_inc_return(&keyconf->tx_pn);
  336. crypto_hdr[0] = pn;
  337. crypto_hdr[2] = 0;
  338. crypto_hdr[3] = 0x20 | (keyconf->keyidx << 6);
  339. crypto_hdr[1] = pn >> 8;
  340. crypto_hdr[4] = pn >> 16;
  341. crypto_hdr[5] = pn >> 24;
  342. crypto_hdr[6] = pn >> 32;
  343. crypto_hdr[7] = pn >> 40;
  344. }
  345. /*
  346. * Sets the fields in the Tx cmd that are crypto related
  347. */
  348. static void iwl_mvm_set_tx_cmd_crypto(struct iwl_mvm *mvm,
  349. struct ieee80211_tx_info *info,
  350. struct iwl_tx_cmd *tx_cmd,
  351. struct sk_buff *skb_frag,
  352. int hdrlen)
  353. {
  354. struct ieee80211_key_conf *keyconf = info->control.hw_key;
  355. u8 *crypto_hdr = skb_frag->data + hdrlen;
  356. u64 pn;
  357. switch (keyconf->cipher) {
  358. case WLAN_CIPHER_SUITE_CCMP:
  359. case WLAN_CIPHER_SUITE_CCMP_256:
  360. iwl_mvm_set_tx_cmd_ccmp(info, tx_cmd);
  361. iwl_mvm_set_tx_cmd_pn(info, crypto_hdr);
  362. break;
  363. case WLAN_CIPHER_SUITE_TKIP:
  364. tx_cmd->sec_ctl = TX_CMD_SEC_TKIP;
  365. pn = atomic64_inc_return(&keyconf->tx_pn);
  366. ieee80211_tkip_add_iv(crypto_hdr, keyconf, pn);
  367. ieee80211_get_tkip_p2k(keyconf, skb_frag, tx_cmd->key);
  368. break;
  369. case WLAN_CIPHER_SUITE_WEP104:
  370. tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128;
  371. /* fall through */
  372. case WLAN_CIPHER_SUITE_WEP40:
  373. tx_cmd->sec_ctl |= TX_CMD_SEC_WEP |
  374. ((keyconf->keyidx << TX_CMD_SEC_WEP_KEY_IDX_POS) &
  375. TX_CMD_SEC_WEP_KEY_IDX_MSK);
  376. memcpy(&tx_cmd->key[3], keyconf->key, keyconf->keylen);
  377. break;
  378. case WLAN_CIPHER_SUITE_GCMP:
  379. case WLAN_CIPHER_SUITE_GCMP_256:
  380. /* TODO: Taking the key from the table might introduce a race
  381. * when PTK rekeying is done, having an old packets with a PN
  382. * based on the old key but the message encrypted with a new
  383. * one.
  384. * Need to handle this.
  385. */
  386. tx_cmd->sec_ctl |= TX_CMD_SEC_GCMP | TC_CMD_SEC_KEY_FROM_TABLE;
  387. tx_cmd->key[0] = keyconf->hw_key_idx;
  388. iwl_mvm_set_tx_cmd_pn(info, crypto_hdr);
  389. break;
  390. default:
  391. tx_cmd->sec_ctl |= TX_CMD_SEC_EXT;
  392. }
  393. }
  394. /*
  395. * Allocates and sets the Tx cmd the driver data pointers in the skb
  396. */
  397. static struct iwl_device_cmd *
  398. iwl_mvm_set_tx_params(struct iwl_mvm *mvm, struct sk_buff *skb,
  399. struct ieee80211_tx_info *info, int hdrlen,
  400. struct ieee80211_sta *sta, u8 sta_id)
  401. {
  402. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  403. struct ieee80211_tx_info *skb_info = IEEE80211_SKB_CB(skb);
  404. struct iwl_device_cmd *dev_cmd;
  405. struct iwl_tx_cmd *tx_cmd;
  406. dev_cmd = iwl_trans_alloc_tx_cmd(mvm->trans);
  407. if (unlikely(!dev_cmd))
  408. return NULL;
  409. memset(dev_cmd, 0, sizeof(*dev_cmd));
  410. dev_cmd->hdr.cmd = TX_CMD;
  411. tx_cmd = (struct iwl_tx_cmd *)dev_cmd->payload;
  412. if (info->control.hw_key)
  413. iwl_mvm_set_tx_cmd_crypto(mvm, info, tx_cmd, skb, hdrlen);
  414. iwl_mvm_set_tx_cmd(mvm, skb, tx_cmd, info, sta_id);
  415. iwl_mvm_set_tx_cmd_rate(mvm, tx_cmd, info, sta, hdr->frame_control);
  416. memset(&skb_info->status, 0, sizeof(skb_info->status));
  417. memset(skb_info->driver_data, 0, sizeof(skb_info->driver_data));
  418. skb_info->driver_data[1] = dev_cmd;
  419. return dev_cmd;
  420. }
  421. static int iwl_mvm_get_ctrl_vif_queue(struct iwl_mvm *mvm,
  422. struct ieee80211_tx_info *info, __le16 fc)
  423. {
  424. if (iwl_mvm_is_dqa_supported(mvm)) {
  425. if (info->control.vif->type == NL80211_IFTYPE_AP &&
  426. ieee80211_is_probe_resp(fc))
  427. return IWL_MVM_DQA_AP_PROBE_RESP_QUEUE;
  428. else if (ieee80211_is_mgmt(fc) &&
  429. info->control.vif->type == NL80211_IFTYPE_P2P_DEVICE)
  430. return IWL_MVM_DQA_P2P_DEVICE_QUEUE;
  431. }
  432. return info->hw_queue;
  433. }
  434. int iwl_mvm_tx_skb_non_sta(struct iwl_mvm *mvm, struct sk_buff *skb)
  435. {
  436. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  437. struct ieee80211_tx_info *skb_info = IEEE80211_SKB_CB(skb);
  438. struct ieee80211_tx_info info;
  439. struct iwl_device_cmd *dev_cmd;
  440. struct iwl_tx_cmd *tx_cmd;
  441. u8 sta_id;
  442. int hdrlen = ieee80211_hdrlen(hdr->frame_control);
  443. int queue;
  444. memcpy(&info, skb->cb, sizeof(info));
  445. if (WARN_ON_ONCE(info.flags & IEEE80211_TX_CTL_AMPDU))
  446. return -1;
  447. if (WARN_ON_ONCE(info.flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM &&
  448. (!info.control.vif ||
  449. info.hw_queue != info.control.vif->cab_queue)))
  450. return -1;
  451. /* This holds the amsdu headers length */
  452. skb_info->driver_data[0] = (void *)(uintptr_t)0;
  453. /*
  454. * IWL_MVM_OFFCHANNEL_QUEUE is used for ROC packets that can be used
  455. * in 2 different types of vifs, P2P & STATION. P2P uses the offchannel
  456. * queue. STATION (HS2.0) uses the auxiliary context of the FW,
  457. * and hence needs to be sent on the aux queue
  458. */
  459. if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
  460. info.control.vif->type == NL80211_IFTYPE_STATION)
  461. IEEE80211_SKB_CB(skb)->hw_queue = mvm->aux_queue;
  462. queue = info.hw_queue;
  463. /*
  464. * If the interface on which the frame is sent is the P2P_DEVICE
  465. * or an AP/GO interface use the broadcast station associated
  466. * with it; otherwise if the interface is a managed interface
  467. * use the AP station associated with it for multicast traffic
  468. * (this is not possible for unicast packets as a TLDS discovery
  469. * response are sent without a station entry); otherwise use the
  470. * AUX station.
  471. * In DQA mode, if vif is of type STATION and frames are not multicast,
  472. * they should be sent from the BSS queue. For example, TDLS setup
  473. * frames should be sent on this queue, as they go through the AP.
  474. */
  475. sta_id = mvm->aux_sta.sta_id;
  476. if (info.control.vif) {
  477. struct iwl_mvm_vif *mvmvif =
  478. iwl_mvm_vif_from_mac80211(info.control.vif);
  479. if (info.control.vif->type == NL80211_IFTYPE_P2P_DEVICE ||
  480. info.control.vif->type == NL80211_IFTYPE_AP) {
  481. sta_id = mvmvif->bcast_sta.sta_id;
  482. queue = iwl_mvm_get_ctrl_vif_queue(mvm, &info,
  483. hdr->frame_control);
  484. } else if (info.control.vif->type == NL80211_IFTYPE_STATION &&
  485. is_multicast_ether_addr(hdr->addr1)) {
  486. u8 ap_sta_id = ACCESS_ONCE(mvmvif->ap_sta_id);
  487. if (ap_sta_id != IWL_MVM_STATION_COUNT)
  488. sta_id = ap_sta_id;
  489. } else if (iwl_mvm_is_dqa_supported(mvm) &&
  490. info.control.vif->type == NL80211_IFTYPE_STATION) {
  491. queue = IWL_MVM_DQA_BSS_CLIENT_QUEUE;
  492. }
  493. }
  494. IWL_DEBUG_TX(mvm, "station Id %d, queue=%d\n", sta_id, queue);
  495. dev_cmd = iwl_mvm_set_tx_params(mvm, skb, &info, hdrlen, NULL, sta_id);
  496. if (!dev_cmd)
  497. return -1;
  498. tx_cmd = (struct iwl_tx_cmd *)dev_cmd->payload;
  499. /* Copy MAC header from skb into command buffer */
  500. memcpy(tx_cmd->hdr, hdr, hdrlen);
  501. if (iwl_trans_tx(mvm->trans, skb, dev_cmd, queue)) {
  502. iwl_trans_free_tx_cmd(mvm->trans, dev_cmd);
  503. return -1;
  504. }
  505. /*
  506. * Increase the pending frames counter, so that later when a reply comes
  507. * in and the counter is decreased - we don't start getting negative
  508. * values.
  509. * Note that we don't need to make sure it isn't agg'd, since we're
  510. * TXing non-sta
  511. */
  512. atomic_inc(&mvm->pending_frames[sta_id]);
  513. return 0;
  514. }
  515. #ifdef CONFIG_INET
  516. static int iwl_mvm_tx_tso(struct iwl_mvm *mvm, struct sk_buff *skb,
  517. struct ieee80211_tx_info *info,
  518. struct ieee80211_sta *sta,
  519. struct sk_buff_head *mpdus_skb)
  520. {
  521. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  522. struct ieee80211_hdr *hdr = (void *)skb->data;
  523. unsigned int mss = skb_shinfo(skb)->gso_size;
  524. struct sk_buff *tmp, *next;
  525. char cb[sizeof(skb->cb)];
  526. unsigned int num_subframes, tcp_payload_len, subf_len, max_amsdu_len;
  527. bool ipv4 = (skb->protocol == htons(ETH_P_IP));
  528. u16 ip_base_id = ipv4 ? ntohs(ip_hdr(skb)->id) : 0;
  529. u16 amsdu_add, snap_ip_tcp, pad, i = 0;
  530. unsigned int dbg_max_amsdu_len;
  531. netdev_features_t netdev_features = NETIF_F_CSUM_MASK | NETIF_F_SG;
  532. u8 *qc, tid, txf;
  533. snap_ip_tcp = 8 + skb_transport_header(skb) - skb_network_header(skb) +
  534. tcp_hdrlen(skb);
  535. qc = ieee80211_get_qos_ctl(hdr);
  536. tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
  537. if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT))
  538. return -EINVAL;
  539. dbg_max_amsdu_len = ACCESS_ONCE(mvm->max_amsdu_len);
  540. if (!sta->max_amsdu_len ||
  541. !ieee80211_is_data_qos(hdr->frame_control) ||
  542. (!mvmsta->tlc_amsdu && !dbg_max_amsdu_len)) {
  543. num_subframes = 1;
  544. pad = 0;
  545. goto segment;
  546. }
  547. /*
  548. * Do not build AMSDU for IPv6 with extension headers.
  549. * ask stack to segment and checkum the generated MPDUs for us.
  550. */
  551. if (skb->protocol == htons(ETH_P_IPV6) &&
  552. ((struct ipv6hdr *)skb_network_header(skb))->nexthdr !=
  553. IPPROTO_TCP) {
  554. num_subframes = 1;
  555. pad = 0;
  556. netdev_features &= ~NETIF_F_CSUM_MASK;
  557. goto segment;
  558. }
  559. /*
  560. * No need to lock amsdu_in_ampdu_allowed since it can't be modified
  561. * during an BA session.
  562. */
  563. if (info->flags & IEEE80211_TX_CTL_AMPDU &&
  564. !mvmsta->tid_data[tid].amsdu_in_ampdu_allowed) {
  565. num_subframes = 1;
  566. pad = 0;
  567. goto segment;
  568. }
  569. max_amsdu_len = sta->max_amsdu_len;
  570. /* the Tx FIFO to which this A-MSDU will be routed */
  571. txf = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]];
  572. /*
  573. * Don't send an AMSDU that will be longer than the TXF.
  574. * Add a security margin of 256 for the TX command + headers.
  575. * We also want to have the start of the next packet inside the
  576. * fifo to be able to send bursts.
  577. */
  578. max_amsdu_len = min_t(unsigned int, max_amsdu_len,
  579. mvm->shared_mem_cfg.txfifo_size[txf] - 256);
  580. if (unlikely(dbg_max_amsdu_len))
  581. max_amsdu_len = min_t(unsigned int, max_amsdu_len,
  582. dbg_max_amsdu_len);
  583. /*
  584. * Limit A-MSDU in A-MPDU to 4095 bytes when VHT is not
  585. * supported. This is a spec requirement (IEEE 802.11-2015
  586. * section 8.7.3 NOTE 3).
  587. */
  588. if (info->flags & IEEE80211_TX_CTL_AMPDU &&
  589. !sta->vht_cap.vht_supported)
  590. max_amsdu_len = min_t(unsigned int, max_amsdu_len, 4095);
  591. /* Sub frame header + SNAP + IP header + TCP header + MSS */
  592. subf_len = sizeof(struct ethhdr) + snap_ip_tcp + mss;
  593. pad = (4 - subf_len) & 0x3;
  594. /*
  595. * If we have N subframes in the A-MSDU, then the A-MSDU's size is
  596. * N * subf_len + (N - 1) * pad.
  597. */
  598. num_subframes = (max_amsdu_len + pad) / (subf_len + pad);
  599. if (num_subframes > 1)
  600. *qc |= IEEE80211_QOS_CTL_A_MSDU_PRESENT;
  601. tcp_payload_len = skb_tail_pointer(skb) - skb_transport_header(skb) -
  602. tcp_hdrlen(skb) + skb->data_len;
  603. /*
  604. * Make sure we have enough TBs for the A-MSDU:
  605. * 2 for each subframe
  606. * 1 more for each fragment
  607. * 1 more for the potential data in the header
  608. */
  609. num_subframes =
  610. min_t(unsigned int, num_subframes,
  611. (mvm->trans->max_skb_frags - 1 -
  612. skb_shinfo(skb)->nr_frags) / 2);
  613. /* This skb fits in one single A-MSDU */
  614. if (num_subframes * mss >= tcp_payload_len) {
  615. struct ieee80211_tx_info *skb_info = IEEE80211_SKB_CB(skb);
  616. /*
  617. * Compute the length of all the data added for the A-MSDU.
  618. * This will be used to compute the length to write in the TX
  619. * command. We have: SNAP + IP + TCP for n -1 subframes and
  620. * ETH header for n subframes. Note that the original skb
  621. * already had one set of SNAP / IP / TCP headers.
  622. */
  623. num_subframes = DIV_ROUND_UP(tcp_payload_len, mss);
  624. amsdu_add = num_subframes * sizeof(struct ethhdr) +
  625. (num_subframes - 1) * (snap_ip_tcp + pad);
  626. /* This holds the amsdu headers length */
  627. skb_info->driver_data[0] = (void *)(uintptr_t)amsdu_add;
  628. __skb_queue_tail(mpdus_skb, skb);
  629. return 0;
  630. }
  631. /*
  632. * Trick the segmentation function to make it
  633. * create SKBs that can fit into one A-MSDU.
  634. */
  635. segment:
  636. skb_shinfo(skb)->gso_size = num_subframes * mss;
  637. memcpy(cb, skb->cb, sizeof(cb));
  638. next = skb_gso_segment(skb, netdev_features);
  639. skb_shinfo(skb)->gso_size = mss;
  640. if (WARN_ON_ONCE(IS_ERR(next)))
  641. return -EINVAL;
  642. else if (next)
  643. consume_skb(skb);
  644. while (next) {
  645. tmp = next;
  646. next = tmp->next;
  647. memcpy(tmp->cb, cb, sizeof(tmp->cb));
  648. /*
  649. * Compute the length of all the data added for the A-MSDU.
  650. * This will be used to compute the length to write in the TX
  651. * command. We have: SNAP + IP + TCP for n -1 subframes and
  652. * ETH header for n subframes.
  653. */
  654. tcp_payload_len = skb_tail_pointer(tmp) -
  655. skb_transport_header(tmp) -
  656. tcp_hdrlen(tmp) + tmp->data_len;
  657. if (ipv4)
  658. ip_hdr(tmp)->id = htons(ip_base_id + i * num_subframes);
  659. if (tcp_payload_len > mss) {
  660. struct ieee80211_tx_info *skb_info =
  661. IEEE80211_SKB_CB(tmp);
  662. num_subframes = DIV_ROUND_UP(tcp_payload_len, mss);
  663. amsdu_add = num_subframes * sizeof(struct ethhdr) +
  664. (num_subframes - 1) * (snap_ip_tcp + pad);
  665. skb_info->driver_data[0] =
  666. (void *)(uintptr_t)amsdu_add;
  667. skb_shinfo(tmp)->gso_size = mss;
  668. } else {
  669. qc = ieee80211_get_qos_ctl((void *)tmp->data);
  670. if (ipv4)
  671. ip_send_check(ip_hdr(tmp));
  672. *qc &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT;
  673. skb_shinfo(tmp)->gso_size = 0;
  674. }
  675. tmp->prev = NULL;
  676. tmp->next = NULL;
  677. __skb_queue_tail(mpdus_skb, tmp);
  678. i++;
  679. }
  680. return 0;
  681. }
  682. #else /* CONFIG_INET */
  683. static int iwl_mvm_tx_tso(struct iwl_mvm *mvm, struct sk_buff *skb,
  684. struct ieee80211_tx_info *info,
  685. struct ieee80211_sta *sta,
  686. struct sk_buff_head *mpdus_skb)
  687. {
  688. /* Impossible to get TSO with CONFIG_INET */
  689. WARN_ON(1);
  690. return -1;
  691. }
  692. #endif
  693. static void iwl_mvm_tx_add_stream(struct iwl_mvm *mvm,
  694. struct iwl_mvm_sta *mvm_sta, u8 tid,
  695. struct sk_buff *skb)
  696. {
  697. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  698. u8 mac_queue = info->hw_queue;
  699. struct sk_buff_head *deferred_tx_frames;
  700. lockdep_assert_held(&mvm_sta->lock);
  701. mvm_sta->deferred_traffic_tid_map |= BIT(tid);
  702. set_bit(mvm_sta->sta_id, mvm->sta_deferred_frames);
  703. deferred_tx_frames = &mvm_sta->tid_data[tid].deferred_tx_frames;
  704. skb_queue_tail(deferred_tx_frames, skb);
  705. /*
  706. * The first deferred frame should've stopped the MAC queues, so we
  707. * should never get a second deferred frame for the RA/TID.
  708. */
  709. if (!WARN(skb_queue_len(deferred_tx_frames) != 1,
  710. "RATID %d/%d has %d deferred frames\n", mvm_sta->sta_id, tid,
  711. skb_queue_len(deferred_tx_frames))) {
  712. iwl_mvm_stop_mac_queues(mvm, BIT(mac_queue));
  713. schedule_work(&mvm->add_stream_wk);
  714. }
  715. }
  716. /*
  717. * Sets the fields in the Tx cmd that are crypto related
  718. */
  719. static int iwl_mvm_tx_mpdu(struct iwl_mvm *mvm, struct sk_buff *skb,
  720. struct ieee80211_tx_info *info,
  721. struct ieee80211_sta *sta)
  722. {
  723. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  724. struct iwl_mvm_sta *mvmsta;
  725. struct iwl_device_cmd *dev_cmd;
  726. struct iwl_tx_cmd *tx_cmd;
  727. __le16 fc;
  728. u16 seq_number = 0;
  729. u8 tid = IWL_MAX_TID_COUNT;
  730. u8 txq_id = info->hw_queue;
  731. bool is_ampdu = false;
  732. int hdrlen;
  733. mvmsta = iwl_mvm_sta_from_mac80211(sta);
  734. fc = hdr->frame_control;
  735. hdrlen = ieee80211_hdrlen(fc);
  736. if (WARN_ON_ONCE(!mvmsta))
  737. return -1;
  738. if (WARN_ON_ONCE(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
  739. return -1;
  740. dev_cmd = iwl_mvm_set_tx_params(mvm, skb, info, hdrlen,
  741. sta, mvmsta->sta_id);
  742. if (!dev_cmd)
  743. goto drop;
  744. tx_cmd = (struct iwl_tx_cmd *)dev_cmd->payload;
  745. /* From now on, we cannot access info->control */
  746. /*
  747. * we handle that entirely ourselves -- for uAPSD the firmware
  748. * will always send a notification, and for PS-Poll responses
  749. * we'll notify mac80211 when getting frame status
  750. */
  751. info->flags &= ~IEEE80211_TX_STATUS_EOSP;
  752. spin_lock(&mvmsta->lock);
  753. if (ieee80211_is_data_qos(fc) && !ieee80211_is_qos_nullfunc(fc)) {
  754. u8 *qc = NULL;
  755. qc = ieee80211_get_qos_ctl(hdr);
  756. tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
  757. if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT))
  758. goto drop_unlock_sta;
  759. seq_number = mvmsta->tid_data[tid].seq_number;
  760. seq_number &= IEEE80211_SCTL_SEQ;
  761. hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
  762. hdr->seq_ctrl |= cpu_to_le16(seq_number);
  763. is_ampdu = info->flags & IEEE80211_TX_CTL_AMPDU;
  764. } else if (iwl_mvm_is_dqa_supported(mvm) &&
  765. (ieee80211_is_qos_nullfunc(fc) ||
  766. ieee80211_is_nullfunc(fc))) {
  767. /*
  768. * nullfunc frames should go to the MGMT queue regardless of QOS
  769. */
  770. tid = IWL_MAX_TID_COUNT;
  771. }
  772. if (iwl_mvm_is_dqa_supported(mvm))
  773. txq_id = mvmsta->tid_data[tid].txq_id;
  774. /* Copy MAC header from skb into command buffer */
  775. memcpy(tx_cmd->hdr, hdr, hdrlen);
  776. WARN_ON_ONCE(info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM);
  777. if (sta->tdls && !iwl_mvm_is_dqa_supported(mvm)) {
  778. /* default to TID 0 for non-QoS packets */
  779. u8 tdls_tid = tid == IWL_MAX_TID_COUNT ? 0 : tid;
  780. txq_id = mvmsta->hw_queue[tid_to_mac80211_ac[tdls_tid]];
  781. }
  782. if (is_ampdu) {
  783. if (WARN_ON_ONCE(mvmsta->tid_data[tid].state != IWL_AGG_ON))
  784. goto drop_unlock_sta;
  785. txq_id = mvmsta->tid_data[tid].txq_id;
  786. }
  787. /* Check if TXQ needs to be allocated or re-activated */
  788. if (unlikely(txq_id == IEEE80211_INVAL_HW_QUEUE ||
  789. !mvmsta->tid_data[tid].is_tid_active) &&
  790. iwl_mvm_is_dqa_supported(mvm)) {
  791. /* If TXQ needs to be allocated... */
  792. if (txq_id == IEEE80211_INVAL_HW_QUEUE) {
  793. iwl_mvm_tx_add_stream(mvm, mvmsta, tid, skb);
  794. /*
  795. * The frame is now deferred, and the worker scheduled
  796. * will re-allocate it, so we can free it for now.
  797. */
  798. iwl_trans_free_tx_cmd(mvm->trans, dev_cmd);
  799. spin_unlock(&mvmsta->lock);
  800. return 0;
  801. }
  802. /* If we are here - TXQ exists and needs to be re-activated */
  803. spin_lock(&mvm->queue_info_lock);
  804. mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_READY;
  805. mvmsta->tid_data[tid].is_tid_active = true;
  806. spin_unlock(&mvm->queue_info_lock);
  807. IWL_DEBUG_TX_QUEUES(mvm, "Re-activating queue %d for TX\n",
  808. txq_id);
  809. }
  810. /* Keep track of the time of the last frame for this RA/TID */
  811. mvm->queue_info[txq_id].last_frame_time[tid] = jiffies;
  812. IWL_DEBUG_TX(mvm, "TX to [%d|%d] Q:%d - seq: 0x%x\n", mvmsta->sta_id,
  813. tid, txq_id, IEEE80211_SEQ_TO_SN(seq_number));
  814. if (iwl_trans_tx(mvm->trans, skb, dev_cmd, txq_id))
  815. goto drop_unlock_sta;
  816. if (tid < IWL_MAX_TID_COUNT && !ieee80211_has_morefrags(fc))
  817. mvmsta->tid_data[tid].seq_number = seq_number + 0x10;
  818. spin_unlock(&mvmsta->lock);
  819. /* Increase pending frames count if this isn't AMPDU */
  820. if (!is_ampdu)
  821. atomic_inc(&mvm->pending_frames[mvmsta->sta_id]);
  822. return 0;
  823. drop_unlock_sta:
  824. iwl_trans_free_tx_cmd(mvm->trans, dev_cmd);
  825. spin_unlock(&mvmsta->lock);
  826. drop:
  827. return -1;
  828. }
  829. int iwl_mvm_tx_skb(struct iwl_mvm *mvm, struct sk_buff *skb,
  830. struct ieee80211_sta *sta)
  831. {
  832. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  833. struct ieee80211_tx_info *skb_info = IEEE80211_SKB_CB(skb);
  834. struct ieee80211_tx_info info;
  835. struct sk_buff_head mpdus_skbs;
  836. unsigned int payload_len;
  837. int ret;
  838. if (WARN_ON_ONCE(!mvmsta))
  839. return -1;
  840. if (WARN_ON_ONCE(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
  841. return -1;
  842. memcpy(&info, skb->cb, sizeof(info));
  843. /* This holds the amsdu headers length */
  844. skb_info->driver_data[0] = (void *)(uintptr_t)0;
  845. if (!skb_is_gso(skb))
  846. return iwl_mvm_tx_mpdu(mvm, skb, &info, sta);
  847. payload_len = skb_tail_pointer(skb) - skb_transport_header(skb) -
  848. tcp_hdrlen(skb) + skb->data_len;
  849. if (payload_len <= skb_shinfo(skb)->gso_size)
  850. return iwl_mvm_tx_mpdu(mvm, skb, &info, sta);
  851. __skb_queue_head_init(&mpdus_skbs);
  852. ret = iwl_mvm_tx_tso(mvm, skb, &info, sta, &mpdus_skbs);
  853. if (ret)
  854. return ret;
  855. if (WARN_ON(skb_queue_empty(&mpdus_skbs)))
  856. return ret;
  857. while (!skb_queue_empty(&mpdus_skbs)) {
  858. skb = __skb_dequeue(&mpdus_skbs);
  859. ret = iwl_mvm_tx_mpdu(mvm, skb, &info, sta);
  860. if (ret) {
  861. __skb_queue_purge(&mpdus_skbs);
  862. return ret;
  863. }
  864. }
  865. return 0;
  866. }
  867. static void iwl_mvm_check_ratid_empty(struct iwl_mvm *mvm,
  868. struct ieee80211_sta *sta, u8 tid)
  869. {
  870. struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
  871. struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
  872. struct ieee80211_vif *vif = mvmsta->vif;
  873. lockdep_assert_held(&mvmsta->lock);
  874. if ((tid_data->state == IWL_AGG_ON ||
  875. tid_data->state == IWL_EMPTYING_HW_QUEUE_DELBA) &&
  876. iwl_mvm_tid_queued(tid_data) == 0) {
  877. /*
  878. * Now that this aggregation queue is empty tell mac80211 so it
  879. * knows we no longer have frames buffered for the station on
  880. * this TID (for the TIM bitmap calculation.)
  881. */
  882. ieee80211_sta_set_buffered(sta, tid, false);
  883. }
  884. if (tid_data->ssn != tid_data->next_reclaimed)
  885. return;
  886. switch (tid_data->state) {
  887. case IWL_EMPTYING_HW_QUEUE_ADDBA:
  888. IWL_DEBUG_TX_QUEUES(mvm,
  889. "Can continue addBA flow ssn = next_recl = %d\n",
  890. tid_data->next_reclaimed);
  891. tid_data->state = IWL_AGG_STARTING;
  892. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  893. break;
  894. case IWL_EMPTYING_HW_QUEUE_DELBA:
  895. IWL_DEBUG_TX_QUEUES(mvm,
  896. "Can continue DELBA flow ssn = next_recl = %d\n",
  897. tid_data->next_reclaimed);
  898. iwl_mvm_disable_txq(mvm, tid_data->txq_id,
  899. vif->hw_queue[tid_to_mac80211_ac[tid]], tid,
  900. CMD_ASYNC);
  901. tid_data->state = IWL_AGG_OFF;
  902. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  903. break;
  904. default:
  905. break;
  906. }
  907. }
  908. #ifdef CONFIG_IWLWIFI_DEBUG
  909. const char *iwl_mvm_get_tx_fail_reason(u32 status)
  910. {
  911. #define TX_STATUS_FAIL(x) case TX_STATUS_FAIL_ ## x: return #x
  912. #define TX_STATUS_POSTPONE(x) case TX_STATUS_POSTPONE_ ## x: return #x
  913. switch (status & TX_STATUS_MSK) {
  914. case TX_STATUS_SUCCESS:
  915. return "SUCCESS";
  916. TX_STATUS_POSTPONE(DELAY);
  917. TX_STATUS_POSTPONE(FEW_BYTES);
  918. TX_STATUS_POSTPONE(BT_PRIO);
  919. TX_STATUS_POSTPONE(QUIET_PERIOD);
  920. TX_STATUS_POSTPONE(CALC_TTAK);
  921. TX_STATUS_FAIL(INTERNAL_CROSSED_RETRY);
  922. TX_STATUS_FAIL(SHORT_LIMIT);
  923. TX_STATUS_FAIL(LONG_LIMIT);
  924. TX_STATUS_FAIL(UNDERRUN);
  925. TX_STATUS_FAIL(DRAIN_FLOW);
  926. TX_STATUS_FAIL(RFKILL_FLUSH);
  927. TX_STATUS_FAIL(LIFE_EXPIRE);
  928. TX_STATUS_FAIL(DEST_PS);
  929. TX_STATUS_FAIL(HOST_ABORTED);
  930. TX_STATUS_FAIL(BT_RETRY);
  931. TX_STATUS_FAIL(STA_INVALID);
  932. TX_STATUS_FAIL(FRAG_DROPPED);
  933. TX_STATUS_FAIL(TID_DISABLE);
  934. TX_STATUS_FAIL(FIFO_FLUSHED);
  935. TX_STATUS_FAIL(SMALL_CF_POLL);
  936. TX_STATUS_FAIL(FW_DROP);
  937. TX_STATUS_FAIL(STA_COLOR_MISMATCH);
  938. }
  939. return "UNKNOWN";
  940. #undef TX_STATUS_FAIL
  941. #undef TX_STATUS_POSTPONE
  942. }
  943. #endif /* CONFIG_IWLWIFI_DEBUG */
  944. void iwl_mvm_hwrate_to_tx_rate(u32 rate_n_flags,
  945. enum nl80211_band band,
  946. struct ieee80211_tx_rate *r)
  947. {
  948. if (rate_n_flags & RATE_HT_MCS_GF_MSK)
  949. r->flags |= IEEE80211_TX_RC_GREEN_FIELD;
  950. switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) {
  951. case RATE_MCS_CHAN_WIDTH_20:
  952. break;
  953. case RATE_MCS_CHAN_WIDTH_40:
  954. r->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
  955. break;
  956. case RATE_MCS_CHAN_WIDTH_80:
  957. r->flags |= IEEE80211_TX_RC_80_MHZ_WIDTH;
  958. break;
  959. case RATE_MCS_CHAN_WIDTH_160:
  960. r->flags |= IEEE80211_TX_RC_160_MHZ_WIDTH;
  961. break;
  962. }
  963. if (rate_n_flags & RATE_MCS_SGI_MSK)
  964. r->flags |= IEEE80211_TX_RC_SHORT_GI;
  965. if (rate_n_flags & RATE_MCS_HT_MSK) {
  966. r->flags |= IEEE80211_TX_RC_MCS;
  967. r->idx = rate_n_flags & RATE_HT_MCS_INDEX_MSK;
  968. } else if (rate_n_flags & RATE_MCS_VHT_MSK) {
  969. ieee80211_rate_set_vht(
  970. r, rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK,
  971. ((rate_n_flags & RATE_VHT_MCS_NSS_MSK) >>
  972. RATE_VHT_MCS_NSS_POS) + 1);
  973. r->flags |= IEEE80211_TX_RC_VHT_MCS;
  974. } else {
  975. r->idx = iwl_mvm_legacy_rate_to_mac80211_idx(rate_n_flags,
  976. band);
  977. }
  978. }
  979. /**
  980. * translate ucode response to mac80211 tx status control values
  981. */
  982. static void iwl_mvm_hwrate_to_tx_status(u32 rate_n_flags,
  983. struct ieee80211_tx_info *info)
  984. {
  985. struct ieee80211_tx_rate *r = &info->status.rates[0];
  986. info->status.antenna =
  987. ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS);
  988. iwl_mvm_hwrate_to_tx_rate(rate_n_flags, info->band, r);
  989. }
  990. static void iwl_mvm_tx_status_check_trigger(struct iwl_mvm *mvm,
  991. u32 status)
  992. {
  993. struct iwl_fw_dbg_trigger_tlv *trig;
  994. struct iwl_fw_dbg_trigger_tx_status *status_trig;
  995. int i;
  996. if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_TX_STATUS))
  997. return;
  998. trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_TX_STATUS);
  999. status_trig = (void *)trig->data;
  1000. if (!iwl_fw_dbg_trigger_check_stop(mvm, NULL, trig))
  1001. return;
  1002. for (i = 0; i < ARRAY_SIZE(status_trig->statuses); i++) {
  1003. /* don't collect on status 0 */
  1004. if (!status_trig->statuses[i].status)
  1005. break;
  1006. if (status_trig->statuses[i].status != (status & TX_STATUS_MSK))
  1007. continue;
  1008. iwl_mvm_fw_dbg_collect_trig(mvm, trig,
  1009. "Tx status %d was received",
  1010. status & TX_STATUS_MSK);
  1011. break;
  1012. }
  1013. }
  1014. static void iwl_mvm_rx_tx_cmd_single(struct iwl_mvm *mvm,
  1015. struct iwl_rx_packet *pkt)
  1016. {
  1017. struct ieee80211_sta *sta;
  1018. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  1019. int txq_id = SEQ_TO_QUEUE(sequence);
  1020. struct iwl_mvm_tx_resp *tx_resp = (void *)pkt->data;
  1021. int sta_id = IWL_MVM_TX_RES_GET_RA(tx_resp->ra_tid);
  1022. int tid = IWL_MVM_TX_RES_GET_TID(tx_resp->ra_tid);
  1023. u32 status = le16_to_cpu(tx_resp->status.status);
  1024. u16 ssn = iwl_mvm_get_scd_ssn(tx_resp);
  1025. struct iwl_mvm_sta *mvmsta;
  1026. struct sk_buff_head skbs;
  1027. u8 skb_freed = 0;
  1028. u16 next_reclaimed, seq_ctl;
  1029. bool is_ndp = false;
  1030. bool txq_agg = false; /* Is this TXQ aggregated */
  1031. __skb_queue_head_init(&skbs);
  1032. seq_ctl = le16_to_cpu(tx_resp->seq_ctl);
  1033. /* we can free until ssn % q.n_bd not inclusive */
  1034. iwl_trans_reclaim(mvm->trans, txq_id, ssn, &skbs);
  1035. while (!skb_queue_empty(&skbs)) {
  1036. struct sk_buff *skb = __skb_dequeue(&skbs);
  1037. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1038. skb_freed++;
  1039. iwl_trans_free_tx_cmd(mvm->trans, info->driver_data[1]);
  1040. memset(&info->status, 0, sizeof(info->status));
  1041. info->flags &= ~IEEE80211_TX_CTL_AMPDU;
  1042. /* inform mac80211 about what happened with the frame */
  1043. switch (status & TX_STATUS_MSK) {
  1044. case TX_STATUS_SUCCESS:
  1045. case TX_STATUS_DIRECT_DONE:
  1046. info->flags |= IEEE80211_TX_STAT_ACK;
  1047. break;
  1048. case TX_STATUS_FAIL_DEST_PS:
  1049. info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
  1050. break;
  1051. default:
  1052. break;
  1053. }
  1054. iwl_mvm_tx_status_check_trigger(mvm, status);
  1055. info->status.rates[0].count = tx_resp->failure_frame + 1;
  1056. iwl_mvm_hwrate_to_tx_status(le32_to_cpu(tx_resp->initial_rate),
  1057. info);
  1058. info->status.status_driver_data[1] =
  1059. (void *)(uintptr_t)le32_to_cpu(tx_resp->initial_rate);
  1060. /* Single frame failure in an AMPDU queue => send BAR */
  1061. if (txq_id >= mvm->first_agg_queue &&
  1062. !(info->flags & IEEE80211_TX_STAT_ACK) &&
  1063. !(info->flags & IEEE80211_TX_STAT_TX_FILTERED))
  1064. info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
  1065. /* W/A FW bug: seq_ctl is wrong when the status isn't success */
  1066. if (status != TX_STATUS_SUCCESS) {
  1067. struct ieee80211_hdr *hdr = (void *)skb->data;
  1068. seq_ctl = le16_to_cpu(hdr->seq_ctrl);
  1069. }
  1070. if (unlikely(!seq_ctl)) {
  1071. struct ieee80211_hdr *hdr = (void *)skb->data;
  1072. /*
  1073. * If it is an NDP, we can't update next_reclaim since
  1074. * its sequence control is 0. Note that for that same
  1075. * reason, NDPs are never sent to A-MPDU'able queues
  1076. * so that we can never have more than one freed frame
  1077. * for a single Tx resonse (see WARN_ON below).
  1078. */
  1079. if (ieee80211_is_qos_nullfunc(hdr->frame_control))
  1080. is_ndp = true;
  1081. }
  1082. /*
  1083. * TODO: this is not accurate if we are freeing more than one
  1084. * packet.
  1085. */
  1086. info->status.tx_time =
  1087. le16_to_cpu(tx_resp->wireless_media_time);
  1088. BUILD_BUG_ON(ARRAY_SIZE(info->status.status_driver_data) < 1);
  1089. info->status.status_driver_data[0] =
  1090. (void *)(uintptr_t)tx_resp->reduced_tpc;
  1091. ieee80211_tx_status(mvm->hw, skb);
  1092. }
  1093. if (txq_id >= mvm->first_agg_queue) {
  1094. /* If this is an aggregation queue, we use the ssn since:
  1095. * ssn = wifi seq_num % 256.
  1096. * The seq_ctl is the sequence control of the packet to which
  1097. * this Tx response relates. But if there is a hole in the
  1098. * bitmap of the BA we received, this Tx response may allow to
  1099. * reclaim the hole and all the subsequent packets that were
  1100. * already acked. In that case, seq_ctl != ssn, and the next
  1101. * packet to be reclaimed will be ssn and not seq_ctl. In that
  1102. * case, several packets will be reclaimed even if
  1103. * frame_count = 1.
  1104. *
  1105. * The ssn is the index (% 256) of the latest packet that has
  1106. * treated (acked / dropped) + 1.
  1107. */
  1108. next_reclaimed = ssn;
  1109. } else {
  1110. /* The next packet to be reclaimed is the one after this one */
  1111. next_reclaimed = IEEE80211_SEQ_TO_SN(seq_ctl + 0x10);
  1112. }
  1113. IWL_DEBUG_TX_REPLY(mvm,
  1114. "TXQ %d status %s (0x%08x)\n",
  1115. txq_id, iwl_mvm_get_tx_fail_reason(status), status);
  1116. IWL_DEBUG_TX_REPLY(mvm,
  1117. "\t\t\t\tinitial_rate 0x%x retries %d, idx=%d ssn=%d next_reclaimed=0x%x seq_ctl=0x%x\n",
  1118. le32_to_cpu(tx_resp->initial_rate),
  1119. tx_resp->failure_frame, SEQ_TO_INDEX(sequence),
  1120. ssn, next_reclaimed, seq_ctl);
  1121. rcu_read_lock();
  1122. sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
  1123. /*
  1124. * sta can't be NULL otherwise it'd mean that the sta has been freed in
  1125. * the firmware while we still have packets for it in the Tx queues.
  1126. */
  1127. if (WARN_ON_ONCE(!sta))
  1128. goto out;
  1129. if (!IS_ERR(sta)) {
  1130. mvmsta = iwl_mvm_sta_from_mac80211(sta);
  1131. if (tid != IWL_TID_NON_QOS) {
  1132. struct iwl_mvm_tid_data *tid_data =
  1133. &mvmsta->tid_data[tid];
  1134. bool send_eosp_ndp = false;
  1135. spin_lock_bh(&mvmsta->lock);
  1136. if (iwl_mvm_is_dqa_supported(mvm)) {
  1137. enum iwl_mvm_agg_state state;
  1138. state = mvmsta->tid_data[tid].state;
  1139. txq_agg = (state == IWL_AGG_ON ||
  1140. state == IWL_EMPTYING_HW_QUEUE_DELBA);
  1141. } else {
  1142. txq_agg = txq_id >= mvm->first_agg_queue;
  1143. }
  1144. if (!is_ndp) {
  1145. tid_data->next_reclaimed = next_reclaimed;
  1146. IWL_DEBUG_TX_REPLY(mvm,
  1147. "Next reclaimed packet:%d\n",
  1148. next_reclaimed);
  1149. } else {
  1150. IWL_DEBUG_TX_REPLY(mvm,
  1151. "NDP - don't update next_reclaimed\n");
  1152. }
  1153. iwl_mvm_check_ratid_empty(mvm, sta, tid);
  1154. if (mvmsta->sleep_tx_count) {
  1155. mvmsta->sleep_tx_count--;
  1156. if (mvmsta->sleep_tx_count &&
  1157. !iwl_mvm_tid_queued(tid_data)) {
  1158. /*
  1159. * The number of frames in the queue
  1160. * dropped to 0 even if we sent less
  1161. * frames than we thought we had on the
  1162. * Tx queue.
  1163. * This means we had holes in the BA
  1164. * window that we just filled, ask
  1165. * mac80211 to send EOSP since the
  1166. * firmware won't know how to do that.
  1167. * Send NDP and the firmware will send
  1168. * EOSP notification that will trigger
  1169. * a call to ieee80211_sta_eosp().
  1170. */
  1171. send_eosp_ndp = true;
  1172. }
  1173. }
  1174. spin_unlock_bh(&mvmsta->lock);
  1175. if (send_eosp_ndp) {
  1176. iwl_mvm_sta_modify_sleep_tx_count(mvm, sta,
  1177. IEEE80211_FRAME_RELEASE_UAPSD,
  1178. 1, tid, false, false);
  1179. mvmsta->sleep_tx_count = 0;
  1180. ieee80211_send_eosp_nullfunc(sta, tid);
  1181. }
  1182. }
  1183. if (mvmsta->next_status_eosp) {
  1184. mvmsta->next_status_eosp = false;
  1185. ieee80211_sta_eosp(sta);
  1186. }
  1187. } else {
  1188. mvmsta = NULL;
  1189. }
  1190. /*
  1191. * If the txq is not an AMPDU queue, there is no chance we freed
  1192. * several skbs. Check that out...
  1193. */
  1194. if (txq_agg)
  1195. goto out;
  1196. /* We can't free more than one frame at once on a shared queue */
  1197. WARN_ON(!iwl_mvm_is_dqa_supported(mvm) && (skb_freed > 1));
  1198. /* If we have still frames for this STA nothing to do here */
  1199. if (!atomic_sub_and_test(skb_freed, &mvm->pending_frames[sta_id]))
  1200. goto out;
  1201. if (mvmsta && mvmsta->vif->type == NL80211_IFTYPE_AP) {
  1202. /*
  1203. * If there are no pending frames for this STA and
  1204. * the tx to this station is not disabled, notify
  1205. * mac80211 that this station can now wake up in its
  1206. * STA table.
  1207. * If mvmsta is not NULL, sta is valid.
  1208. */
  1209. spin_lock_bh(&mvmsta->lock);
  1210. if (!mvmsta->disable_tx)
  1211. ieee80211_sta_block_awake(mvm->hw, sta, false);
  1212. spin_unlock_bh(&mvmsta->lock);
  1213. }
  1214. if (PTR_ERR(sta) == -EBUSY || PTR_ERR(sta) == -ENOENT) {
  1215. /*
  1216. * We are draining and this was the last packet - pre_rcu_remove
  1217. * has been called already. We might be after the
  1218. * synchronize_net already.
  1219. * Don't rely on iwl_mvm_rm_sta to see the empty Tx queues.
  1220. */
  1221. set_bit(sta_id, mvm->sta_drained);
  1222. schedule_work(&mvm->sta_drained_wk);
  1223. }
  1224. out:
  1225. rcu_read_unlock();
  1226. }
  1227. #ifdef CONFIG_IWLWIFI_DEBUG
  1228. #define AGG_TX_STATE_(x) case AGG_TX_STATE_ ## x: return #x
  1229. static const char *iwl_get_agg_tx_status(u16 status)
  1230. {
  1231. switch (status & AGG_TX_STATE_STATUS_MSK) {
  1232. AGG_TX_STATE_(TRANSMITTED);
  1233. AGG_TX_STATE_(UNDERRUN);
  1234. AGG_TX_STATE_(BT_PRIO);
  1235. AGG_TX_STATE_(FEW_BYTES);
  1236. AGG_TX_STATE_(ABORT);
  1237. AGG_TX_STATE_(LAST_SENT_TTL);
  1238. AGG_TX_STATE_(LAST_SENT_TRY_CNT);
  1239. AGG_TX_STATE_(LAST_SENT_BT_KILL);
  1240. AGG_TX_STATE_(SCD_QUERY);
  1241. AGG_TX_STATE_(TEST_BAD_CRC32);
  1242. AGG_TX_STATE_(RESPONSE);
  1243. AGG_TX_STATE_(DUMP_TX);
  1244. AGG_TX_STATE_(DELAY_TX);
  1245. }
  1246. return "UNKNOWN";
  1247. }
  1248. static void iwl_mvm_rx_tx_cmd_agg_dbg(struct iwl_mvm *mvm,
  1249. struct iwl_rx_packet *pkt)
  1250. {
  1251. struct iwl_mvm_tx_resp *tx_resp = (void *)pkt->data;
  1252. struct agg_tx_status *frame_status = &tx_resp->status;
  1253. int i;
  1254. for (i = 0; i < tx_resp->frame_count; i++) {
  1255. u16 fstatus = le16_to_cpu(frame_status[i].status);
  1256. IWL_DEBUG_TX_REPLY(mvm,
  1257. "status %s (0x%04x), try-count (%d) seq (0x%x)\n",
  1258. iwl_get_agg_tx_status(fstatus),
  1259. fstatus & AGG_TX_STATE_STATUS_MSK,
  1260. (fstatus & AGG_TX_STATE_TRY_CNT_MSK) >>
  1261. AGG_TX_STATE_TRY_CNT_POS,
  1262. le16_to_cpu(frame_status[i].sequence));
  1263. }
  1264. }
  1265. #else
  1266. static void iwl_mvm_rx_tx_cmd_agg_dbg(struct iwl_mvm *mvm,
  1267. struct iwl_rx_packet *pkt)
  1268. {}
  1269. #endif /* CONFIG_IWLWIFI_DEBUG */
  1270. static void iwl_mvm_rx_tx_cmd_agg(struct iwl_mvm *mvm,
  1271. struct iwl_rx_packet *pkt)
  1272. {
  1273. struct iwl_mvm_tx_resp *tx_resp = (void *)pkt->data;
  1274. int sta_id = IWL_MVM_TX_RES_GET_RA(tx_resp->ra_tid);
  1275. int tid = IWL_MVM_TX_RES_GET_TID(tx_resp->ra_tid);
  1276. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  1277. struct iwl_mvm_sta *mvmsta;
  1278. int queue = SEQ_TO_QUEUE(sequence);
  1279. if (WARN_ON_ONCE(queue < mvm->first_agg_queue &&
  1280. (!iwl_mvm_is_dqa_supported(mvm) ||
  1281. (queue != IWL_MVM_DQA_BSS_CLIENT_QUEUE))))
  1282. return;
  1283. if (WARN_ON_ONCE(tid == IWL_TID_NON_QOS))
  1284. return;
  1285. iwl_mvm_rx_tx_cmd_agg_dbg(mvm, pkt);
  1286. rcu_read_lock();
  1287. mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, sta_id);
  1288. if (!WARN_ON_ONCE(!mvmsta)) {
  1289. mvmsta->tid_data[tid].rate_n_flags =
  1290. le32_to_cpu(tx_resp->initial_rate);
  1291. mvmsta->tid_data[tid].tx_time =
  1292. le16_to_cpu(tx_resp->wireless_media_time);
  1293. }
  1294. rcu_read_unlock();
  1295. }
  1296. void iwl_mvm_rx_tx_cmd(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
  1297. {
  1298. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1299. struct iwl_mvm_tx_resp *tx_resp = (void *)pkt->data;
  1300. if (tx_resp->frame_count == 1)
  1301. iwl_mvm_rx_tx_cmd_single(mvm, pkt);
  1302. else
  1303. iwl_mvm_rx_tx_cmd_agg(mvm, pkt);
  1304. }
  1305. static void iwl_mvm_tx_info_from_ba_notif(struct ieee80211_tx_info *info,
  1306. struct iwl_mvm_ba_notif *ba_notif,
  1307. struct iwl_mvm_tid_data *tid_data)
  1308. {
  1309. info->flags |= IEEE80211_TX_STAT_AMPDU;
  1310. info->status.ampdu_ack_len = ba_notif->txed_2_done;
  1311. info->status.ampdu_len = ba_notif->txed;
  1312. iwl_mvm_hwrate_to_tx_status(tid_data->rate_n_flags,
  1313. info);
  1314. /* TODO: not accounted if the whole A-MPDU failed */
  1315. info->status.tx_time = tid_data->tx_time;
  1316. info->status.status_driver_data[0] =
  1317. (void *)(uintptr_t)ba_notif->reduced_txp;
  1318. info->status.status_driver_data[1] =
  1319. (void *)(uintptr_t)tid_data->rate_n_flags;
  1320. }
  1321. void iwl_mvm_rx_ba_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
  1322. {
  1323. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1324. struct iwl_mvm_ba_notif *ba_notif = (void *)pkt->data;
  1325. struct sk_buff_head reclaimed_skbs;
  1326. struct iwl_mvm_tid_data *tid_data;
  1327. struct ieee80211_sta *sta;
  1328. struct iwl_mvm_sta *mvmsta;
  1329. struct sk_buff *skb;
  1330. int sta_id, tid, freed;
  1331. /* "flow" corresponds to Tx queue */
  1332. u16 scd_flow = le16_to_cpu(ba_notif->scd_flow);
  1333. /* "ssn" is start of block-ack Tx window, corresponds to index
  1334. * (in Tx queue's circular buffer) of first TFD/frame in window */
  1335. u16 ba_resp_scd_ssn = le16_to_cpu(ba_notif->scd_ssn);
  1336. sta_id = ba_notif->sta_id;
  1337. tid = ba_notif->tid;
  1338. if (WARN_ONCE(sta_id >= IWL_MVM_STATION_COUNT ||
  1339. tid >= IWL_MAX_TID_COUNT,
  1340. "sta_id %d tid %d", sta_id, tid))
  1341. return;
  1342. rcu_read_lock();
  1343. sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
  1344. /* Reclaiming frames for a station that has been deleted ? */
  1345. if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) {
  1346. rcu_read_unlock();
  1347. return;
  1348. }
  1349. mvmsta = iwl_mvm_sta_from_mac80211(sta);
  1350. tid_data = &mvmsta->tid_data[tid];
  1351. if (tid_data->txq_id != scd_flow) {
  1352. IWL_ERR(mvm,
  1353. "invalid BA notification: Q %d, tid %d, flow %d\n",
  1354. tid_data->txq_id, tid, scd_flow);
  1355. rcu_read_unlock();
  1356. return;
  1357. }
  1358. spin_lock_bh(&mvmsta->lock);
  1359. __skb_queue_head_init(&reclaimed_skbs);
  1360. /*
  1361. * Release all TFDs before the SSN, i.e. all TFDs in front of
  1362. * block-ack window (we assume that they've been successfully
  1363. * transmitted ... if not, it's too late anyway).
  1364. */
  1365. iwl_trans_reclaim(mvm->trans, scd_flow, ba_resp_scd_ssn,
  1366. &reclaimed_skbs);
  1367. IWL_DEBUG_TX_REPLY(mvm,
  1368. "BA_NOTIFICATION Received from %pM, sta_id = %d\n",
  1369. (u8 *)&ba_notif->sta_addr_lo32,
  1370. ba_notif->sta_id);
  1371. IWL_DEBUG_TX_REPLY(mvm,
  1372. "TID = %d, SeqCtl = %d, bitmap = 0x%llx, scd_flow = %d, scd_ssn = %d sent:%d, acked:%d\n",
  1373. ba_notif->tid, le16_to_cpu(ba_notif->seq_ctl),
  1374. (unsigned long long)le64_to_cpu(ba_notif->bitmap),
  1375. scd_flow, ba_resp_scd_ssn, ba_notif->txed,
  1376. ba_notif->txed_2_done);
  1377. IWL_DEBUG_TX_REPLY(mvm, "reduced txp from ba notif %d\n",
  1378. ba_notif->reduced_txp);
  1379. tid_data->next_reclaimed = ba_resp_scd_ssn;
  1380. iwl_mvm_check_ratid_empty(mvm, sta, tid);
  1381. freed = 0;
  1382. skb_queue_walk(&reclaimed_skbs, skb) {
  1383. struct ieee80211_hdr *hdr = (void *)skb->data;
  1384. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1385. if (ieee80211_is_data_qos(hdr->frame_control))
  1386. freed++;
  1387. else
  1388. WARN_ON_ONCE(1);
  1389. iwl_trans_free_tx_cmd(mvm->trans, info->driver_data[1]);
  1390. memset(&info->status, 0, sizeof(info->status));
  1391. /* Packet was transmitted successfully, failures come as single
  1392. * frames because before failing a frame the firmware transmits
  1393. * it without aggregation at least once.
  1394. */
  1395. info->flags |= IEEE80211_TX_STAT_ACK;
  1396. /* this is the first skb we deliver in this batch */
  1397. /* put the rate scaling data there */
  1398. if (freed == 1)
  1399. iwl_mvm_tx_info_from_ba_notif(info, ba_notif, tid_data);
  1400. }
  1401. spin_unlock_bh(&mvmsta->lock);
  1402. /* We got a BA notif with 0 acked or scd_ssn didn't progress which is
  1403. * possible (i.e. first MPDU in the aggregation wasn't acked)
  1404. * Still it's important to update RS about sent vs. acked.
  1405. */
  1406. if (skb_queue_empty(&reclaimed_skbs)) {
  1407. struct ieee80211_tx_info ba_info = {};
  1408. struct ieee80211_chanctx_conf *chanctx_conf = NULL;
  1409. if (mvmsta->vif)
  1410. chanctx_conf =
  1411. rcu_dereference(mvmsta->vif->chanctx_conf);
  1412. if (WARN_ON_ONCE(!chanctx_conf))
  1413. goto out;
  1414. ba_info.band = chanctx_conf->def.chan->band;
  1415. iwl_mvm_tx_info_from_ba_notif(&ba_info, ba_notif, tid_data);
  1416. IWL_DEBUG_TX_REPLY(mvm, "No reclaim. Update rs directly\n");
  1417. iwl_mvm_rs_tx_status(mvm, sta, tid, &ba_info, false);
  1418. }
  1419. out:
  1420. rcu_read_unlock();
  1421. while (!skb_queue_empty(&reclaimed_skbs)) {
  1422. skb = __skb_dequeue(&reclaimed_skbs);
  1423. ieee80211_tx_status(mvm->hw, skb);
  1424. }
  1425. }
  1426. /*
  1427. * Note that there are transports that buffer frames before they reach
  1428. * the firmware. This means that after flush_tx_path is called, the
  1429. * queue might not be empty. The race-free way to handle this is to:
  1430. * 1) set the station as draining
  1431. * 2) flush the Tx path
  1432. * 3) wait for the transport queues to be empty
  1433. */
  1434. int iwl_mvm_flush_tx_path(struct iwl_mvm *mvm, u32 tfd_msk, u32 flags)
  1435. {
  1436. int ret;
  1437. struct iwl_tx_path_flush_cmd flush_cmd = {
  1438. .queues_ctl = cpu_to_le32(tfd_msk),
  1439. .flush_ctl = cpu_to_le16(DUMP_TX_FIFO_FLUSH),
  1440. };
  1441. ret = iwl_mvm_send_cmd_pdu(mvm, TXPATH_FLUSH, flags,
  1442. sizeof(flush_cmd), &flush_cmd);
  1443. if (ret)
  1444. IWL_ERR(mvm, "Failed to send flush command (%d)\n", ret);
  1445. return ret;
  1446. }