PageRenderTime 59ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/net/wireless/ath/carl9170/tx.c

https://bitbucket.org/sola/android_board_beagleboard_kernel
C | 1335 lines | 862 code | 273 blank | 200 comment | 160 complexity | fcdda21d854978fa6b58a9cabb41a09a MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  1. /*
  2. * Atheros CARL9170 driver
  3. *
  4. * 802.11 xmit & status routines
  5. *
  6. * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
  7. * Copyright 2009, 2010, Christian Lamparter <chunkeey@googlemail.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; see the file COPYING. If not, see
  21. * http://www.gnu.org/licenses/.
  22. *
  23. * This file incorporates work covered by the following copyright and
  24. * permission notice:
  25. * Copyright (c) 2007-2008 Atheros Communications, Inc.
  26. *
  27. * Permission to use, copy, modify, and/or distribute this software for any
  28. * purpose with or without fee is hereby granted, provided that the above
  29. * copyright notice and this permission notice appear in all copies.
  30. *
  31. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  32. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  33. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  34. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  35. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  36. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  37. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  38. */
  39. #include <linux/init.h>
  40. #include <linux/slab.h>
  41. #include <linux/module.h>
  42. #include <linux/etherdevice.h>
  43. #include <net/mac80211.h>
  44. #include "carl9170.h"
  45. #include "hw.h"
  46. #include "cmd.h"
  47. static inline unsigned int __carl9170_get_queue(struct ar9170 *ar,
  48. unsigned int queue)
  49. {
  50. if (unlikely(modparam_noht)) {
  51. return queue;
  52. } else {
  53. /*
  54. * This is just another workaround, until
  55. * someone figures out how to get QoS and
  56. * AMPDU to play nicely together.
  57. */
  58. return 2; /* AC_BE */
  59. }
  60. }
  61. static inline unsigned int carl9170_get_queue(struct ar9170 *ar,
  62. struct sk_buff *skb)
  63. {
  64. return __carl9170_get_queue(ar, skb_get_queue_mapping(skb));
  65. }
  66. static bool is_mem_full(struct ar9170 *ar)
  67. {
  68. return (DIV_ROUND_UP(IEEE80211_MAX_FRAME_LEN, ar->fw.mem_block_size) >
  69. atomic_read(&ar->mem_free_blocks));
  70. }
  71. static void carl9170_tx_accounting(struct ar9170 *ar, struct sk_buff *skb)
  72. {
  73. int queue, i;
  74. bool mem_full;
  75. atomic_inc(&ar->tx_total_queued);
  76. queue = skb_get_queue_mapping(skb);
  77. spin_lock_bh(&ar->tx_stats_lock);
  78. /*
  79. * The driver has to accept the frame, regardless if the queue is
  80. * full to the brim, or not. We have to do the queuing internally,
  81. * since mac80211 assumes that a driver which can operate with
  82. * aggregated frames does not reject frames for this reason.
  83. */
  84. ar->tx_stats[queue].len++;
  85. ar->tx_stats[queue].count++;
  86. mem_full = is_mem_full(ar);
  87. for (i = 0; i < ar->hw->queues; i++) {
  88. if (mem_full || ar->tx_stats[i].len >= ar->tx_stats[i].limit) {
  89. ieee80211_stop_queue(ar->hw, i);
  90. ar->queue_stop_timeout[i] = jiffies;
  91. }
  92. }
  93. spin_unlock_bh(&ar->tx_stats_lock);
  94. }
  95. static void carl9170_tx_accounting_free(struct ar9170 *ar, struct sk_buff *skb)
  96. {
  97. struct ieee80211_tx_info *txinfo;
  98. int queue;
  99. txinfo = IEEE80211_SKB_CB(skb);
  100. queue = skb_get_queue_mapping(skb);
  101. spin_lock_bh(&ar->tx_stats_lock);
  102. ar->tx_stats[queue].len--;
  103. if (!is_mem_full(ar)) {
  104. unsigned int i;
  105. for (i = 0; i < ar->hw->queues; i++) {
  106. if (ar->tx_stats[i].len >= CARL9170_NUM_TX_LIMIT_SOFT)
  107. continue;
  108. if (ieee80211_queue_stopped(ar->hw, i)) {
  109. unsigned long tmp;
  110. tmp = jiffies - ar->queue_stop_timeout[i];
  111. if (tmp > ar->max_queue_stop_timeout[i])
  112. ar->max_queue_stop_timeout[i] = tmp;
  113. }
  114. ieee80211_wake_queue(ar->hw, i);
  115. }
  116. }
  117. spin_unlock_bh(&ar->tx_stats_lock);
  118. if (atomic_dec_and_test(&ar->tx_total_queued))
  119. complete(&ar->tx_flush);
  120. }
  121. static int carl9170_alloc_dev_space(struct ar9170 *ar, struct sk_buff *skb)
  122. {
  123. struct _carl9170_tx_superframe *super = (void *) skb->data;
  124. unsigned int chunks;
  125. int cookie = -1;
  126. atomic_inc(&ar->mem_allocs);
  127. chunks = DIV_ROUND_UP(skb->len, ar->fw.mem_block_size);
  128. if (unlikely(atomic_sub_return(chunks, &ar->mem_free_blocks) < 0)) {
  129. atomic_add(chunks, &ar->mem_free_blocks);
  130. return -ENOSPC;
  131. }
  132. spin_lock_bh(&ar->mem_lock);
  133. cookie = bitmap_find_free_region(ar->mem_bitmap, ar->fw.mem_blocks, 0);
  134. spin_unlock_bh(&ar->mem_lock);
  135. if (unlikely(cookie < 0)) {
  136. atomic_add(chunks, &ar->mem_free_blocks);
  137. return -ENOSPC;
  138. }
  139. super = (void *) skb->data;
  140. /*
  141. * Cookie #0 serves two special purposes:
  142. * 1. The firmware might use it generate BlockACK frames
  143. * in responds of an incoming BlockAckReqs.
  144. *
  145. * 2. Prevent double-free bugs.
  146. */
  147. super->s.cookie = (u8) cookie + 1;
  148. return 0;
  149. }
  150. static void carl9170_release_dev_space(struct ar9170 *ar, struct sk_buff *skb)
  151. {
  152. struct _carl9170_tx_superframe *super = (void *) skb->data;
  153. int cookie;
  154. /* make a local copy of the cookie */
  155. cookie = super->s.cookie;
  156. /* invalidate cookie */
  157. super->s.cookie = 0;
  158. /*
  159. * Do a out-of-bounds check on the cookie:
  160. *
  161. * * cookie "0" is reserved and won't be assigned to any
  162. * out-going frame. Internally however, it is used to
  163. * mark no longer/un-accounted frames and serves as a
  164. * cheap way of preventing frames from being freed
  165. * twice by _accident_. NB: There is a tiny race...
  166. *
  167. * * obviously, cookie number is limited by the amount
  168. * of available memory blocks, so the number can
  169. * never execeed the mem_blocks count.
  170. */
  171. if (unlikely(WARN_ON_ONCE(cookie == 0) ||
  172. WARN_ON_ONCE(cookie > ar->fw.mem_blocks)))
  173. return;
  174. atomic_add(DIV_ROUND_UP(skb->len, ar->fw.mem_block_size),
  175. &ar->mem_free_blocks);
  176. spin_lock_bh(&ar->mem_lock);
  177. bitmap_release_region(ar->mem_bitmap, cookie - 1, 0);
  178. spin_unlock_bh(&ar->mem_lock);
  179. }
  180. /* Called from any context */
  181. static void carl9170_tx_release(struct kref *ref)
  182. {
  183. struct ar9170 *ar;
  184. struct carl9170_tx_info *arinfo;
  185. struct ieee80211_tx_info *txinfo;
  186. struct sk_buff *skb;
  187. arinfo = container_of(ref, struct carl9170_tx_info, ref);
  188. txinfo = container_of((void *) arinfo, struct ieee80211_tx_info,
  189. rate_driver_data);
  190. skb = container_of((void *) txinfo, struct sk_buff, cb);
  191. ar = arinfo->ar;
  192. if (WARN_ON_ONCE(!ar))
  193. return;
  194. BUILD_BUG_ON(
  195. offsetof(struct ieee80211_tx_info, status.ampdu_ack_len) != 23);
  196. memset(&txinfo->status.ampdu_ack_len, 0,
  197. sizeof(struct ieee80211_tx_info) -
  198. offsetof(struct ieee80211_tx_info, status.ampdu_ack_len));
  199. if (atomic_read(&ar->tx_total_queued))
  200. ar->tx_schedule = true;
  201. if (txinfo->flags & IEEE80211_TX_CTL_AMPDU) {
  202. if (!atomic_read(&ar->tx_ampdu_upload))
  203. ar->tx_ampdu_schedule = true;
  204. if (txinfo->flags & IEEE80211_TX_STAT_AMPDU) {
  205. txinfo->status.ampdu_len = txinfo->pad[0];
  206. txinfo->status.ampdu_ack_len = txinfo->pad[1];
  207. txinfo->pad[0] = txinfo->pad[1] = 0;
  208. } else if (txinfo->flags & IEEE80211_TX_STAT_ACK) {
  209. /*
  210. * drop redundant tx_status reports:
  211. *
  212. * 1. ampdu_ack_len of the final tx_status does
  213. * include the feedback of this particular frame.
  214. *
  215. * 2. tx_status_irqsafe only queues up to 128
  216. * tx feedback reports and discards the rest.
  217. *
  218. * 3. minstrel_ht is picky, it only accepts
  219. * reports of frames with the TX_STATUS_AMPDU flag.
  220. */
  221. dev_kfree_skb_any(skb);
  222. return;
  223. } else {
  224. /*
  225. * Frame has failed, but we want to keep it in
  226. * case it was lost due to a power-state
  227. * transition.
  228. */
  229. }
  230. }
  231. skb_pull(skb, sizeof(struct _carl9170_tx_superframe));
  232. ieee80211_tx_status_irqsafe(ar->hw, skb);
  233. }
  234. void carl9170_tx_get_skb(struct sk_buff *skb)
  235. {
  236. struct carl9170_tx_info *arinfo = (void *)
  237. (IEEE80211_SKB_CB(skb))->rate_driver_data;
  238. kref_get(&arinfo->ref);
  239. }
  240. int carl9170_tx_put_skb(struct sk_buff *skb)
  241. {
  242. struct carl9170_tx_info *arinfo = (void *)
  243. (IEEE80211_SKB_CB(skb))->rate_driver_data;
  244. return kref_put(&arinfo->ref, carl9170_tx_release);
  245. }
  246. /* Caller must hold the tid_info->lock & rcu_read_lock */
  247. static void carl9170_tx_shift_bm(struct ar9170 *ar,
  248. struct carl9170_sta_tid *tid_info, u16 seq)
  249. {
  250. u16 off;
  251. off = SEQ_DIFF(seq, tid_info->bsn);
  252. if (WARN_ON_ONCE(off >= CARL9170_BAW_BITS))
  253. return;
  254. /*
  255. * Sanity check. For each MPDU we set the bit in bitmap and
  256. * clear it once we received the tx_status.
  257. * But if the bit is already cleared then we've been bitten
  258. * by a bug.
  259. */
  260. WARN_ON_ONCE(!test_and_clear_bit(off, tid_info->bitmap));
  261. off = SEQ_DIFF(tid_info->snx, tid_info->bsn);
  262. if (WARN_ON_ONCE(off >= CARL9170_BAW_BITS))
  263. return;
  264. if (!bitmap_empty(tid_info->bitmap, off))
  265. off = find_first_bit(tid_info->bitmap, off);
  266. tid_info->bsn += off;
  267. tid_info->bsn &= 0x0fff;
  268. bitmap_shift_right(tid_info->bitmap, tid_info->bitmap,
  269. off, CARL9170_BAW_BITS);
  270. }
  271. static void carl9170_tx_status_process_ampdu(struct ar9170 *ar,
  272. struct sk_buff *skb, struct ieee80211_tx_info *txinfo)
  273. {
  274. struct _carl9170_tx_superframe *super = (void *) skb->data;
  275. struct ieee80211_hdr *hdr = (void *) super->frame_data;
  276. struct ieee80211_tx_info *tx_info;
  277. struct carl9170_tx_info *ar_info;
  278. struct carl9170_sta_info *sta_info;
  279. struct ieee80211_sta *sta;
  280. struct carl9170_sta_tid *tid_info;
  281. struct ieee80211_vif *vif;
  282. unsigned int vif_id;
  283. u8 tid;
  284. if (!(txinfo->flags & IEEE80211_TX_CTL_AMPDU) ||
  285. txinfo->flags & IEEE80211_TX_CTL_INJECTED)
  286. return;
  287. tx_info = IEEE80211_SKB_CB(skb);
  288. ar_info = (void *) tx_info->rate_driver_data;
  289. vif_id = (super->s.misc & CARL9170_TX_SUPER_MISC_VIF_ID) >>
  290. CARL9170_TX_SUPER_MISC_VIF_ID_S;
  291. if (WARN_ON_ONCE(vif_id >= AR9170_MAX_VIRTUAL_MAC))
  292. return;
  293. rcu_read_lock();
  294. vif = rcu_dereference(ar->vif_priv[vif_id].vif);
  295. if (unlikely(!vif))
  296. goto out_rcu;
  297. /*
  298. * Normally we should use wrappers like ieee80211_get_DA to get
  299. * the correct peer ieee80211_sta.
  300. *
  301. * But there is a problem with indirect traffic (broadcasts, or
  302. * data which is designated for other stations) in station mode.
  303. * The frame will be directed to the AP for distribution and not
  304. * to the actual destination.
  305. */
  306. sta = ieee80211_find_sta(vif, hdr->addr1);
  307. if (unlikely(!sta))
  308. goto out_rcu;
  309. tid = get_tid_h(hdr);
  310. sta_info = (void *) sta->drv_priv;
  311. tid_info = rcu_dereference(sta_info->agg[tid]);
  312. if (!tid_info)
  313. goto out_rcu;
  314. spin_lock_bh(&tid_info->lock);
  315. if (likely(tid_info->state >= CARL9170_TID_STATE_IDLE))
  316. carl9170_tx_shift_bm(ar, tid_info, get_seq_h(hdr));
  317. if (sta_info->stats[tid].clear) {
  318. sta_info->stats[tid].clear = false;
  319. sta_info->stats[tid].ampdu_len = 0;
  320. sta_info->stats[tid].ampdu_ack_len = 0;
  321. }
  322. sta_info->stats[tid].ampdu_len++;
  323. if (txinfo->status.rates[0].count == 1)
  324. sta_info->stats[tid].ampdu_ack_len++;
  325. if (super->f.mac_control & cpu_to_le16(AR9170_TX_MAC_IMM_BA)) {
  326. txinfo->pad[0] = sta_info->stats[tid].ampdu_len;
  327. txinfo->pad[1] = sta_info->stats[tid].ampdu_ack_len;
  328. txinfo->flags |= IEEE80211_TX_STAT_AMPDU;
  329. sta_info->stats[tid].clear = true;
  330. }
  331. spin_unlock_bh(&tid_info->lock);
  332. out_rcu:
  333. rcu_read_unlock();
  334. }
  335. void carl9170_tx_status(struct ar9170 *ar, struct sk_buff *skb,
  336. const bool success)
  337. {
  338. struct ieee80211_tx_info *txinfo;
  339. carl9170_tx_accounting_free(ar, skb);
  340. txinfo = IEEE80211_SKB_CB(skb);
  341. if (success)
  342. txinfo->flags |= IEEE80211_TX_STAT_ACK;
  343. else
  344. ar->tx_ack_failures++;
  345. if (txinfo->flags & IEEE80211_TX_CTL_AMPDU)
  346. carl9170_tx_status_process_ampdu(ar, skb, txinfo);
  347. carl9170_tx_put_skb(skb);
  348. }
  349. /* This function may be called form any context */
  350. void carl9170_tx_callback(struct ar9170 *ar, struct sk_buff *skb)
  351. {
  352. struct ieee80211_tx_info *txinfo = IEEE80211_SKB_CB(skb);
  353. atomic_dec(&ar->tx_total_pending);
  354. if (txinfo->flags & IEEE80211_TX_CTL_AMPDU)
  355. atomic_dec(&ar->tx_ampdu_upload);
  356. if (carl9170_tx_put_skb(skb))
  357. tasklet_hi_schedule(&ar->usb_tasklet);
  358. }
  359. static struct sk_buff *carl9170_get_queued_skb(struct ar9170 *ar, u8 cookie,
  360. struct sk_buff_head *queue)
  361. {
  362. struct sk_buff *skb;
  363. spin_lock_bh(&queue->lock);
  364. skb_queue_walk(queue, skb) {
  365. struct _carl9170_tx_superframe *txc = (void *) skb->data;
  366. if (txc->s.cookie != cookie)
  367. continue;
  368. __skb_unlink(skb, queue);
  369. spin_unlock_bh(&queue->lock);
  370. carl9170_release_dev_space(ar, skb);
  371. return skb;
  372. }
  373. spin_unlock_bh(&queue->lock);
  374. return NULL;
  375. }
  376. static void carl9170_tx_fill_rateinfo(struct ar9170 *ar, unsigned int rix,
  377. unsigned int tries, struct ieee80211_tx_info *txinfo)
  378. {
  379. unsigned int i;
  380. for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
  381. if (txinfo->status.rates[i].idx < 0)
  382. break;
  383. if (i == rix) {
  384. txinfo->status.rates[i].count = tries;
  385. i++;
  386. break;
  387. }
  388. }
  389. for (; i < IEEE80211_TX_MAX_RATES; i++) {
  390. txinfo->status.rates[i].idx = -1;
  391. txinfo->status.rates[i].count = 0;
  392. }
  393. }
  394. static void carl9170_check_queue_stop_timeout(struct ar9170 *ar)
  395. {
  396. int i;
  397. struct sk_buff *skb;
  398. struct ieee80211_tx_info *txinfo;
  399. struct carl9170_tx_info *arinfo;
  400. bool restart = false;
  401. for (i = 0; i < ar->hw->queues; i++) {
  402. spin_lock_bh(&ar->tx_status[i].lock);
  403. skb = skb_peek(&ar->tx_status[i]);
  404. if (!skb)
  405. goto next;
  406. txinfo = IEEE80211_SKB_CB(skb);
  407. arinfo = (void *) txinfo->rate_driver_data;
  408. if (time_is_before_jiffies(arinfo->timeout +
  409. msecs_to_jiffies(CARL9170_QUEUE_STUCK_TIMEOUT)) == true)
  410. restart = true;
  411. next:
  412. spin_unlock_bh(&ar->tx_status[i].lock);
  413. }
  414. if (restart) {
  415. /*
  416. * At least one queue has been stuck for long enough.
  417. * Give the device a kick and hope it gets back to
  418. * work.
  419. *
  420. * possible reasons may include:
  421. * - frames got lost/corrupted (bad connection to the device)
  422. * - stalled rx processing/usb controller hiccups
  423. * - firmware errors/bugs
  424. * - every bug you can think of.
  425. * - all bugs you can't...
  426. * - ...
  427. */
  428. carl9170_restart(ar, CARL9170_RR_STUCK_TX);
  429. }
  430. }
  431. void carl9170_tx_janitor(struct work_struct *work)
  432. {
  433. struct ar9170 *ar = container_of(work, struct ar9170,
  434. tx_janitor.work);
  435. if (!IS_STARTED(ar))
  436. return;
  437. ar->tx_janitor_last_run = jiffies;
  438. carl9170_check_queue_stop_timeout(ar);
  439. if (!atomic_read(&ar->tx_total_queued))
  440. return;
  441. ieee80211_queue_delayed_work(ar->hw, &ar->tx_janitor,
  442. msecs_to_jiffies(CARL9170_TX_TIMEOUT));
  443. }
  444. static void __carl9170_tx_process_status(struct ar9170 *ar,
  445. const uint8_t cookie, const uint8_t info)
  446. {
  447. struct sk_buff *skb;
  448. struct ieee80211_tx_info *txinfo;
  449. struct carl9170_tx_info *arinfo;
  450. unsigned int r, t, q;
  451. bool success = true;
  452. q = ar9170_qmap[info & CARL9170_TX_STATUS_QUEUE];
  453. skb = carl9170_get_queued_skb(ar, cookie, &ar->tx_status[q]);
  454. if (!skb) {
  455. /*
  456. * We have lost the race to another thread.
  457. */
  458. return ;
  459. }
  460. txinfo = IEEE80211_SKB_CB(skb);
  461. arinfo = (void *) txinfo->rate_driver_data;
  462. if (!(info & CARL9170_TX_STATUS_SUCCESS))
  463. success = false;
  464. r = (info & CARL9170_TX_STATUS_RIX) >> CARL9170_TX_STATUS_RIX_S;
  465. t = (info & CARL9170_TX_STATUS_TRIES) >> CARL9170_TX_STATUS_TRIES_S;
  466. carl9170_tx_fill_rateinfo(ar, r, t, txinfo);
  467. carl9170_tx_status(ar, skb, success);
  468. }
  469. void carl9170_tx_process_status(struct ar9170 *ar,
  470. const struct carl9170_rsp *cmd)
  471. {
  472. unsigned int i;
  473. for (i = 0; i < cmd->hdr.ext; i++) {
  474. if (WARN_ON(i > ((cmd->hdr.len / 2) + 1))) {
  475. print_hex_dump_bytes("UU:", DUMP_PREFIX_NONE,
  476. (void *) cmd, cmd->hdr.len + 4);
  477. break;
  478. }
  479. __carl9170_tx_process_status(ar, cmd->_tx_status[i].cookie,
  480. cmd->_tx_status[i].info);
  481. }
  482. }
  483. static __le32 carl9170_tx_physet(struct ar9170 *ar,
  484. struct ieee80211_tx_info *info, struct ieee80211_tx_rate *txrate)
  485. {
  486. struct ieee80211_rate *rate = NULL;
  487. u32 power, chains;
  488. __le32 tmp;
  489. tmp = cpu_to_le32(0);
  490. if (txrate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  491. tmp |= cpu_to_le32(AR9170_TX_PHY_BW_40MHZ <<
  492. AR9170_TX_PHY_BW_S);
  493. /* this works because 40 MHz is 2 and dup is 3 */
  494. if (txrate->flags & IEEE80211_TX_RC_DUP_DATA)
  495. tmp |= cpu_to_le32(AR9170_TX_PHY_BW_40MHZ_DUP <<
  496. AR9170_TX_PHY_BW_S);
  497. if (txrate->flags & IEEE80211_TX_RC_SHORT_GI)
  498. tmp |= cpu_to_le32(AR9170_TX_PHY_SHORT_GI);
  499. if (txrate->flags & IEEE80211_TX_RC_MCS) {
  500. u32 r = txrate->idx;
  501. u8 *txpower;
  502. /* heavy clip control */
  503. tmp |= cpu_to_le32((r & 0x7) <<
  504. AR9170_TX_PHY_TX_HEAVY_CLIP_S);
  505. if (txrate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) {
  506. if (info->band == IEEE80211_BAND_5GHZ)
  507. txpower = ar->power_5G_ht40;
  508. else
  509. txpower = ar->power_2G_ht40;
  510. } else {
  511. if (info->band == IEEE80211_BAND_5GHZ)
  512. txpower = ar->power_5G_ht20;
  513. else
  514. txpower = ar->power_2G_ht20;
  515. }
  516. power = txpower[r & 7];
  517. /* +1 dBm for HT40 */
  518. if (txrate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  519. power += 2;
  520. r <<= AR9170_TX_PHY_MCS_S;
  521. BUG_ON(r & ~AR9170_TX_PHY_MCS);
  522. tmp |= cpu_to_le32(r & AR9170_TX_PHY_MCS);
  523. tmp |= cpu_to_le32(AR9170_TX_PHY_MOD_HT);
  524. /*
  525. * green field preamble does not work.
  526. *
  527. * if (txrate->flags & IEEE80211_TX_RC_GREEN_FIELD)
  528. * tmp |= cpu_to_le32(AR9170_TX_PHY_GREENFIELD);
  529. */
  530. } else {
  531. u8 *txpower;
  532. u32 mod;
  533. u32 phyrate;
  534. u8 idx = txrate->idx;
  535. if (info->band != IEEE80211_BAND_2GHZ) {
  536. idx += 4;
  537. txpower = ar->power_5G_leg;
  538. mod = AR9170_TX_PHY_MOD_OFDM;
  539. } else {
  540. if (idx < 4) {
  541. txpower = ar->power_2G_cck;
  542. mod = AR9170_TX_PHY_MOD_CCK;
  543. } else {
  544. mod = AR9170_TX_PHY_MOD_OFDM;
  545. txpower = ar->power_2G_ofdm;
  546. }
  547. }
  548. rate = &__carl9170_ratetable[idx];
  549. phyrate = rate->hw_value & 0xF;
  550. power = txpower[(rate->hw_value & 0x30) >> 4];
  551. phyrate <<= AR9170_TX_PHY_MCS_S;
  552. tmp |= cpu_to_le32(mod);
  553. tmp |= cpu_to_le32(phyrate);
  554. /*
  555. * short preamble seems to be broken too.
  556. *
  557. * if (txrate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
  558. * tmp |= cpu_to_le32(AR9170_TX_PHY_SHORT_PREAMBLE);
  559. */
  560. }
  561. power <<= AR9170_TX_PHY_TX_PWR_S;
  562. power &= AR9170_TX_PHY_TX_PWR;
  563. tmp |= cpu_to_le32(power);
  564. /* set TX chains */
  565. if (ar->eeprom.tx_mask == 1) {
  566. chains = AR9170_TX_PHY_TXCHAIN_1;
  567. } else {
  568. chains = AR9170_TX_PHY_TXCHAIN_2;
  569. /* >= 36M legacy OFDM - use only one chain */
  570. if (rate && rate->bitrate >= 360 &&
  571. !(txrate->flags & IEEE80211_TX_RC_MCS))
  572. chains = AR9170_TX_PHY_TXCHAIN_1;
  573. }
  574. tmp |= cpu_to_le32(chains << AR9170_TX_PHY_TXCHAIN_S);
  575. return tmp;
  576. }
  577. static bool carl9170_tx_rts_check(struct ar9170 *ar,
  578. struct ieee80211_tx_rate *rate,
  579. bool ampdu, bool multi)
  580. {
  581. switch (ar->erp_mode) {
  582. case CARL9170_ERP_AUTO:
  583. if (ampdu)
  584. break;
  585. case CARL9170_ERP_MAC80211:
  586. if (!(rate->flags & IEEE80211_TX_RC_USE_RTS_CTS))
  587. break;
  588. case CARL9170_ERP_RTS:
  589. if (likely(!multi))
  590. return true;
  591. default:
  592. break;
  593. }
  594. return false;
  595. }
  596. static bool carl9170_tx_cts_check(struct ar9170 *ar,
  597. struct ieee80211_tx_rate *rate)
  598. {
  599. switch (ar->erp_mode) {
  600. case CARL9170_ERP_AUTO:
  601. case CARL9170_ERP_MAC80211:
  602. if (!(rate->flags & IEEE80211_TX_RC_USE_CTS_PROTECT))
  603. break;
  604. case CARL9170_ERP_CTS:
  605. return true;
  606. default:
  607. break;
  608. }
  609. return false;
  610. }
  611. static int carl9170_tx_prepare(struct ar9170 *ar, struct sk_buff *skb)
  612. {
  613. struct ieee80211_hdr *hdr;
  614. struct _carl9170_tx_superframe *txc;
  615. struct carl9170_vif_info *cvif;
  616. struct ieee80211_tx_info *info;
  617. struct ieee80211_tx_rate *txrate;
  618. struct ieee80211_sta *sta;
  619. struct carl9170_tx_info *arinfo;
  620. unsigned int hw_queue;
  621. int i;
  622. __le16 mac_tmp;
  623. u16 len;
  624. bool ampdu, no_ack;
  625. BUILD_BUG_ON(sizeof(*arinfo) > sizeof(info->rate_driver_data));
  626. BUILD_BUG_ON(sizeof(struct _carl9170_tx_superdesc) !=
  627. CARL9170_TX_SUPERDESC_LEN);
  628. BUILD_BUG_ON(sizeof(struct _ar9170_tx_hwdesc) !=
  629. AR9170_TX_HWDESC_LEN);
  630. BUILD_BUG_ON(IEEE80211_TX_MAX_RATES < CARL9170_TX_MAX_RATES);
  631. BUILD_BUG_ON(AR9170_MAX_VIRTUAL_MAC >
  632. ((CARL9170_TX_SUPER_MISC_VIF_ID >>
  633. CARL9170_TX_SUPER_MISC_VIF_ID_S) + 1));
  634. hw_queue = ar9170_qmap[carl9170_get_queue(ar, skb)];
  635. hdr = (void *)skb->data;
  636. info = IEEE80211_SKB_CB(skb);
  637. len = skb->len;
  638. /*
  639. * Note: If the frame was sent through a monitor interface,
  640. * the ieee80211_vif pointer can be NULL.
  641. */
  642. if (likely(info->control.vif))
  643. cvif = (void *) info->control.vif->drv_priv;
  644. else
  645. cvif = NULL;
  646. sta = info->control.sta;
  647. txc = (void *)skb_push(skb, sizeof(*txc));
  648. memset(txc, 0, sizeof(*txc));
  649. SET_VAL(CARL9170_TX_SUPER_MISC_QUEUE, txc->s.misc, hw_queue);
  650. if (likely(cvif))
  651. SET_VAL(CARL9170_TX_SUPER_MISC_VIF_ID, txc->s.misc, cvif->id);
  652. if (unlikely(info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM))
  653. txc->s.misc |= CARL9170_TX_SUPER_MISC_CAB;
  654. if (unlikely(ieee80211_is_probe_resp(hdr->frame_control)))
  655. txc->s.misc |= CARL9170_TX_SUPER_MISC_FILL_IN_TSF;
  656. mac_tmp = cpu_to_le16(AR9170_TX_MAC_HW_DURATION |
  657. AR9170_TX_MAC_BACKOFF);
  658. mac_tmp |= cpu_to_le16((hw_queue << AR9170_TX_MAC_QOS_S) &
  659. AR9170_TX_MAC_QOS);
  660. no_ack = !!(info->flags & IEEE80211_TX_CTL_NO_ACK);
  661. if (unlikely(no_ack))
  662. mac_tmp |= cpu_to_le16(AR9170_TX_MAC_NO_ACK);
  663. if (info->control.hw_key) {
  664. len += info->control.hw_key->icv_len;
  665. switch (info->control.hw_key->cipher) {
  666. case WLAN_CIPHER_SUITE_WEP40:
  667. case WLAN_CIPHER_SUITE_WEP104:
  668. case WLAN_CIPHER_SUITE_TKIP:
  669. mac_tmp |= cpu_to_le16(AR9170_TX_MAC_ENCR_RC4);
  670. break;
  671. case WLAN_CIPHER_SUITE_CCMP:
  672. mac_tmp |= cpu_to_le16(AR9170_TX_MAC_ENCR_AES);
  673. break;
  674. default:
  675. WARN_ON(1);
  676. goto err_out;
  677. }
  678. }
  679. ampdu = !!(info->flags & IEEE80211_TX_CTL_AMPDU);
  680. if (ampdu) {
  681. unsigned int density, factor;
  682. if (unlikely(!sta || !cvif))
  683. goto err_out;
  684. factor = min_t(unsigned int, 1u,
  685. info->control.sta->ht_cap.ampdu_factor);
  686. density = info->control.sta->ht_cap.ampdu_density;
  687. if (density) {
  688. /*
  689. * Watch out!
  690. *
  691. * Otus uses slightly different density values than
  692. * those from the 802.11n spec.
  693. */
  694. density = max_t(unsigned int, density + 1, 7u);
  695. }
  696. SET_VAL(CARL9170_TX_SUPER_AMPDU_DENSITY,
  697. txc->s.ampdu_settings, density);
  698. SET_VAL(CARL9170_TX_SUPER_AMPDU_FACTOR,
  699. txc->s.ampdu_settings, factor);
  700. for (i = 0; i < CARL9170_TX_MAX_RATES; i++) {
  701. txrate = &info->control.rates[i];
  702. if (txrate->idx >= 0) {
  703. txc->s.ri[i] =
  704. CARL9170_TX_SUPER_RI_AMPDU;
  705. if (WARN_ON(!(txrate->flags &
  706. IEEE80211_TX_RC_MCS))) {
  707. /*
  708. * Not sure if it's even possible
  709. * to aggregate non-ht rates with
  710. * this HW.
  711. */
  712. goto err_out;
  713. }
  714. continue;
  715. }
  716. txrate->idx = 0;
  717. txrate->count = ar->hw->max_rate_tries;
  718. }
  719. mac_tmp |= cpu_to_le16(AR9170_TX_MAC_AGGR);
  720. }
  721. /*
  722. * NOTE: For the first rate, the ERP & AMPDU flags are directly
  723. * taken from mac_control. For all fallback rate, the firmware
  724. * updates the mac_control flags from the rate info field.
  725. */
  726. for (i = 1; i < CARL9170_TX_MAX_RATES; i++) {
  727. txrate = &info->control.rates[i];
  728. if (txrate->idx < 0)
  729. break;
  730. SET_VAL(CARL9170_TX_SUPER_RI_TRIES, txc->s.ri[i],
  731. txrate->count);
  732. if (carl9170_tx_rts_check(ar, txrate, ampdu, no_ack))
  733. txc->s.ri[i] |= (AR9170_TX_MAC_PROT_RTS <<
  734. CARL9170_TX_SUPER_RI_ERP_PROT_S);
  735. else if (carl9170_tx_cts_check(ar, txrate))
  736. txc->s.ri[i] |= (AR9170_TX_MAC_PROT_CTS <<
  737. CARL9170_TX_SUPER_RI_ERP_PROT_S);
  738. txc->s.rr[i - 1] = carl9170_tx_physet(ar, info, txrate);
  739. }
  740. txrate = &info->control.rates[0];
  741. SET_VAL(CARL9170_TX_SUPER_RI_TRIES, txc->s.ri[0], txrate->count);
  742. if (carl9170_tx_rts_check(ar, txrate, ampdu, no_ack))
  743. mac_tmp |= cpu_to_le16(AR9170_TX_MAC_PROT_RTS);
  744. else if (carl9170_tx_cts_check(ar, txrate))
  745. mac_tmp |= cpu_to_le16(AR9170_TX_MAC_PROT_CTS);
  746. txc->s.len = cpu_to_le16(skb->len);
  747. txc->f.length = cpu_to_le16(len + FCS_LEN);
  748. txc->f.mac_control = mac_tmp;
  749. txc->f.phy_control = carl9170_tx_physet(ar, info, txrate);
  750. arinfo = (void *)info->rate_driver_data;
  751. arinfo->timeout = jiffies;
  752. arinfo->ar = ar;
  753. kref_init(&arinfo->ref);
  754. return 0;
  755. err_out:
  756. skb_pull(skb, sizeof(*txc));
  757. return -EINVAL;
  758. }
  759. static void carl9170_set_immba(struct ar9170 *ar, struct sk_buff *skb)
  760. {
  761. struct _carl9170_tx_superframe *super;
  762. super = (void *) skb->data;
  763. super->f.mac_control |= cpu_to_le16(AR9170_TX_MAC_IMM_BA);
  764. }
  765. static void carl9170_set_ampdu_params(struct ar9170 *ar, struct sk_buff *skb)
  766. {
  767. struct _carl9170_tx_superframe *super;
  768. int tmp;
  769. super = (void *) skb->data;
  770. tmp = (super->s.ampdu_settings & CARL9170_TX_SUPER_AMPDU_DENSITY) <<
  771. CARL9170_TX_SUPER_AMPDU_DENSITY_S;
  772. /*
  773. * If you haven't noticed carl9170_tx_prepare has already filled
  774. * in all ampdu spacing & factor parameters.
  775. * Now it's the time to check whenever the settings have to be
  776. * updated by the firmware, or if everything is still the same.
  777. *
  778. * There's no sane way to handle different density values with
  779. * this hardware, so we may as well just do the compare in the
  780. * driver.
  781. */
  782. if (tmp != ar->current_density) {
  783. ar->current_density = tmp;
  784. super->s.ampdu_settings |=
  785. CARL9170_TX_SUPER_AMPDU_COMMIT_DENSITY;
  786. }
  787. tmp = (super->s.ampdu_settings & CARL9170_TX_SUPER_AMPDU_FACTOR) <<
  788. CARL9170_TX_SUPER_AMPDU_FACTOR_S;
  789. if (tmp != ar->current_factor) {
  790. ar->current_factor = tmp;
  791. super->s.ampdu_settings |=
  792. CARL9170_TX_SUPER_AMPDU_COMMIT_FACTOR;
  793. }
  794. }
  795. static bool carl9170_tx_rate_check(struct ar9170 *ar, struct sk_buff *_dest,
  796. struct sk_buff *_src)
  797. {
  798. struct _carl9170_tx_superframe *dest, *src;
  799. dest = (void *) _dest->data;
  800. src = (void *) _src->data;
  801. /*
  802. * The mac80211 rate control algorithm expects that all MPDUs in
  803. * an AMPDU share the same tx vectors.
  804. * This is not really obvious right now, because the hardware
  805. * does the AMPDU setup according to its own rulebook.
  806. * Our nicely assembled, strictly monotonic increasing mpdu
  807. * chains will be broken up, mashed back together...
  808. */
  809. return (dest->f.phy_control == src->f.phy_control);
  810. }
  811. static void carl9170_tx_ampdu(struct ar9170 *ar)
  812. {
  813. struct sk_buff_head agg;
  814. struct carl9170_sta_tid *tid_info;
  815. struct sk_buff *skb, *first;
  816. unsigned int i = 0, done_ampdus = 0;
  817. u16 seq, queue, tmpssn;
  818. atomic_inc(&ar->tx_ampdu_scheduler);
  819. ar->tx_ampdu_schedule = false;
  820. if (atomic_read(&ar->tx_ampdu_upload))
  821. return;
  822. if (!ar->tx_ampdu_list_len)
  823. return;
  824. __skb_queue_head_init(&agg);
  825. rcu_read_lock();
  826. tid_info = rcu_dereference(ar->tx_ampdu_iter);
  827. if (WARN_ON_ONCE(!tid_info)) {
  828. rcu_read_unlock();
  829. return;
  830. }
  831. retry:
  832. list_for_each_entry_continue_rcu(tid_info, &ar->tx_ampdu_list, list) {
  833. i++;
  834. if (tid_info->state < CARL9170_TID_STATE_PROGRESS)
  835. continue;
  836. queue = TID_TO_WME_AC(tid_info->tid);
  837. spin_lock_bh(&tid_info->lock);
  838. if (tid_info->state != CARL9170_TID_STATE_XMIT)
  839. goto processed;
  840. tid_info->counter++;
  841. first = skb_peek(&tid_info->queue);
  842. tmpssn = carl9170_get_seq(first);
  843. seq = tid_info->snx;
  844. if (unlikely(tmpssn != seq)) {
  845. tid_info->state = CARL9170_TID_STATE_IDLE;
  846. goto processed;
  847. }
  848. while ((skb = skb_peek(&tid_info->queue))) {
  849. /* strict 0, 1, ..., n - 1, n frame sequence order */
  850. if (unlikely(carl9170_get_seq(skb) != seq))
  851. break;
  852. /* don't upload more than AMPDU FACTOR allows. */
  853. if (unlikely(SEQ_DIFF(tid_info->snx, tid_info->bsn) >=
  854. (tid_info->max - 1)))
  855. break;
  856. if (!carl9170_tx_rate_check(ar, skb, first))
  857. break;
  858. atomic_inc(&ar->tx_ampdu_upload);
  859. tid_info->snx = seq = SEQ_NEXT(seq);
  860. __skb_unlink(skb, &tid_info->queue);
  861. __skb_queue_tail(&agg, skb);
  862. if (skb_queue_len(&agg) >= CARL9170_NUM_TX_AGG_MAX)
  863. break;
  864. }
  865. if (skb_queue_empty(&tid_info->queue) ||
  866. carl9170_get_seq(skb_peek(&tid_info->queue)) !=
  867. tid_info->snx) {
  868. /*
  869. * stop TID, if A-MPDU frames are still missing,
  870. * or whenever the queue is empty.
  871. */
  872. tid_info->state = CARL9170_TID_STATE_IDLE;
  873. }
  874. done_ampdus++;
  875. processed:
  876. spin_unlock_bh(&tid_info->lock);
  877. if (skb_queue_empty(&agg))
  878. continue;
  879. /* apply ampdu spacing & factor settings */
  880. carl9170_set_ampdu_params(ar, skb_peek(&agg));
  881. /* set aggregation push bit */
  882. carl9170_set_immba(ar, skb_peek_tail(&agg));
  883. spin_lock_bh(&ar->tx_pending[queue].lock);
  884. skb_queue_splice_tail_init(&agg, &ar->tx_pending[queue]);
  885. spin_unlock_bh(&ar->tx_pending[queue].lock);
  886. ar->tx_schedule = true;
  887. }
  888. if ((done_ampdus++ == 0) && (i++ == 0))
  889. goto retry;
  890. rcu_assign_pointer(ar->tx_ampdu_iter, tid_info);
  891. rcu_read_unlock();
  892. }
  893. static struct sk_buff *carl9170_tx_pick_skb(struct ar9170 *ar,
  894. struct sk_buff_head *queue)
  895. {
  896. struct sk_buff *skb;
  897. struct ieee80211_tx_info *info;
  898. struct carl9170_tx_info *arinfo;
  899. BUILD_BUG_ON(sizeof(*arinfo) > sizeof(info->rate_driver_data));
  900. spin_lock_bh(&queue->lock);
  901. skb = skb_peek(queue);
  902. if (unlikely(!skb))
  903. goto err_unlock;
  904. if (carl9170_alloc_dev_space(ar, skb))
  905. goto err_unlock;
  906. __skb_unlink(skb, queue);
  907. spin_unlock_bh(&queue->lock);
  908. info = IEEE80211_SKB_CB(skb);
  909. arinfo = (void *) info->rate_driver_data;
  910. arinfo->timeout = jiffies;
  911. /*
  912. * increase ref count to "2".
  913. * Ref counting is the easiest way to solve the race between
  914. * the the urb's completion routine: carl9170_tx_callback and
  915. * wlan tx status functions: carl9170_tx_status/janitor.
  916. */
  917. carl9170_tx_get_skb(skb);
  918. return skb;
  919. err_unlock:
  920. spin_unlock_bh(&queue->lock);
  921. return NULL;
  922. }
  923. void carl9170_tx_drop(struct ar9170 *ar, struct sk_buff *skb)
  924. {
  925. struct _carl9170_tx_superframe *super;
  926. uint8_t q = 0;
  927. ar->tx_dropped++;
  928. super = (void *)skb->data;
  929. SET_VAL(CARL9170_TX_SUPER_MISC_QUEUE, q,
  930. ar9170_qmap[carl9170_get_queue(ar, skb)]);
  931. __carl9170_tx_process_status(ar, super->s.cookie, q);
  932. }
  933. static void carl9170_tx(struct ar9170 *ar)
  934. {
  935. struct sk_buff *skb;
  936. unsigned int i, q;
  937. bool schedule_garbagecollector = false;
  938. ar->tx_schedule = false;
  939. if (unlikely(!IS_STARTED(ar)))
  940. return;
  941. carl9170_usb_handle_tx_err(ar);
  942. for (i = 0; i < ar->hw->queues; i++) {
  943. while (!skb_queue_empty(&ar->tx_pending[i])) {
  944. skb = carl9170_tx_pick_skb(ar, &ar->tx_pending[i]);
  945. if (unlikely(!skb))
  946. break;
  947. atomic_inc(&ar->tx_total_pending);
  948. q = __carl9170_get_queue(ar, i);
  949. /*
  950. * NB: tx_status[i] vs. tx_status[q],
  951. * TODO: Move into pick_skb or alloc_dev_space.
  952. */
  953. skb_queue_tail(&ar->tx_status[q], skb);
  954. carl9170_usb_tx(ar, skb);
  955. schedule_garbagecollector = true;
  956. }
  957. }
  958. if (!schedule_garbagecollector)
  959. return;
  960. ieee80211_queue_delayed_work(ar->hw, &ar->tx_janitor,
  961. msecs_to_jiffies(CARL9170_TX_TIMEOUT));
  962. }
  963. static bool carl9170_tx_ampdu_queue(struct ar9170 *ar,
  964. struct ieee80211_sta *sta, struct sk_buff *skb)
  965. {
  966. struct carl9170_sta_info *sta_info;
  967. struct carl9170_sta_tid *agg;
  968. struct sk_buff *iter;
  969. unsigned int max;
  970. u16 tid, seq, qseq, off;
  971. bool run = false;
  972. tid = carl9170_get_tid(skb);
  973. seq = carl9170_get_seq(skb);
  974. sta_info = (void *) sta->drv_priv;
  975. rcu_read_lock();
  976. agg = rcu_dereference(sta_info->agg[tid]);
  977. max = sta_info->ampdu_max_len;
  978. if (!agg)
  979. goto err_unlock_rcu;
  980. spin_lock_bh(&agg->lock);
  981. if (unlikely(agg->state < CARL9170_TID_STATE_IDLE))
  982. goto err_unlock;
  983. /* check if sequence is within the BA window */
  984. if (unlikely(!BAW_WITHIN(agg->bsn, CARL9170_BAW_BITS, seq)))
  985. goto err_unlock;
  986. if (WARN_ON_ONCE(!BAW_WITHIN(agg->snx, CARL9170_BAW_BITS, seq)))
  987. goto err_unlock;
  988. off = SEQ_DIFF(seq, agg->bsn);
  989. if (WARN_ON_ONCE(test_and_set_bit(off, agg->bitmap)))
  990. goto err_unlock;
  991. if (likely(BAW_WITHIN(agg->hsn, CARL9170_BAW_BITS, seq))) {
  992. __skb_queue_tail(&agg->queue, skb);
  993. agg->hsn = seq;
  994. goto queued;
  995. }
  996. skb_queue_reverse_walk(&agg->queue, iter) {
  997. qseq = carl9170_get_seq(iter);
  998. if (BAW_WITHIN(qseq, CARL9170_BAW_BITS, seq)) {
  999. __skb_queue_after(&agg->queue, iter, skb);
  1000. goto queued;
  1001. }
  1002. }
  1003. __skb_queue_head(&agg->queue, skb);
  1004. queued:
  1005. if (unlikely(agg->state != CARL9170_TID_STATE_XMIT)) {
  1006. if (agg->snx == carl9170_get_seq(skb_peek(&agg->queue))) {
  1007. agg->state = CARL9170_TID_STATE_XMIT;
  1008. run = true;
  1009. }
  1010. }
  1011. spin_unlock_bh(&agg->lock);
  1012. rcu_read_unlock();
  1013. return run;
  1014. err_unlock:
  1015. spin_unlock_bh(&agg->lock);
  1016. err_unlock_rcu:
  1017. rcu_read_unlock();
  1018. carl9170_tx_status(ar, skb, false);
  1019. ar->tx_dropped++;
  1020. return false;
  1021. }
  1022. int carl9170_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  1023. {
  1024. struct ar9170 *ar = hw->priv;
  1025. struct ieee80211_tx_info *info;
  1026. struct ieee80211_sta *sta;
  1027. bool run;
  1028. if (unlikely(!IS_STARTED(ar)))
  1029. goto err_free;
  1030. info = IEEE80211_SKB_CB(skb);
  1031. sta = info->control.sta;
  1032. if (unlikely(carl9170_tx_prepare(ar, skb)))
  1033. goto err_free;
  1034. carl9170_tx_accounting(ar, skb);
  1035. /*
  1036. * from now on, one has to use carl9170_tx_status to free
  1037. * all ressouces which are associated with the frame.
  1038. */
  1039. if (info->flags & IEEE80211_TX_CTL_AMPDU) {
  1040. if (WARN_ON_ONCE(!sta))
  1041. goto err_free;
  1042. run = carl9170_tx_ampdu_queue(ar, sta, skb);
  1043. if (run)
  1044. carl9170_tx_ampdu(ar);
  1045. } else {
  1046. unsigned int queue = skb_get_queue_mapping(skb);
  1047. skb_queue_tail(&ar->tx_pending[queue], skb);
  1048. }
  1049. carl9170_tx(ar);
  1050. return NETDEV_TX_OK;
  1051. err_free:
  1052. ar->tx_dropped++;
  1053. dev_kfree_skb_any(skb);
  1054. return NETDEV_TX_OK;
  1055. }
  1056. void carl9170_tx_scheduler(struct ar9170 *ar)
  1057. {
  1058. if (ar->tx_ampdu_schedule)
  1059. carl9170_tx_ampdu(ar);
  1060. if (ar->tx_schedule)
  1061. carl9170_tx(ar);
  1062. }