tx.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  1. /*
  2. * This file is part of wl1271
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. *
  6. * Contact: Luciano Coelho <luciano.coelho@nokia.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. */
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #include <linux/etherdevice.h>
  26. #include "wl12xx.h"
  27. #include "io.h"
  28. #include "reg.h"
  29. #include "ps.h"
  30. #include "tx.h"
  31. static int wl1271_set_default_wep_key(struct wl1271 *wl, u8 id)
  32. {
  33. int ret;
  34. bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
  35. if (is_ap)
  36. ret = wl1271_cmd_set_ap_default_wep_key(wl, id);
  37. else
  38. ret = wl1271_cmd_set_sta_default_wep_key(wl, id);
  39. if (ret < 0)
  40. return ret;
  41. wl1271_debug(DEBUG_CRYPT, "default wep key idx: %d", (int)id);
  42. return 0;
  43. }
  44. static int wl1271_alloc_tx_id(struct wl1271 *wl, struct sk_buff *skb)
  45. {
  46. int id;
  47. id = find_first_zero_bit(wl->tx_frames_map, ACX_TX_DESCRIPTORS);
  48. if (id >= ACX_TX_DESCRIPTORS)
  49. return -EBUSY;
  50. __set_bit(id, wl->tx_frames_map);
  51. wl->tx_frames[id] = skb;
  52. wl->tx_frames_cnt++;
  53. return id;
  54. }
  55. static void wl1271_free_tx_id(struct wl1271 *wl, int id)
  56. {
  57. if (__test_and_clear_bit(id, wl->tx_frames_map)) {
  58. wl->tx_frames[id] = NULL;
  59. wl->tx_frames_cnt--;
  60. }
  61. }
  62. static int wl1271_tx_update_filters(struct wl1271 *wl,
  63. struct sk_buff *skb)
  64. {
  65. struct ieee80211_hdr *hdr;
  66. hdr = (struct ieee80211_hdr *)(skb->data +
  67. sizeof(struct wl1271_tx_hw_descr));
  68. /*
  69. * stop bssid-based filtering before transmitting authentication
  70. * requests. this way the hw will never drop authentication
  71. * responses coming from BSSIDs it isn't familiar with (e.g. on
  72. * roaming)
  73. */
  74. if (!ieee80211_is_auth(hdr->frame_control))
  75. return 0;
  76. wl1271_configure_filters(wl, FIF_OTHER_BSS);
  77. return wl1271_acx_rx_config(wl, wl->rx_config, wl->rx_filter);
  78. }
  79. static void wl1271_tx_ap_update_inconnection_sta(struct wl1271 *wl,
  80. struct sk_buff *skb)
  81. {
  82. struct ieee80211_hdr *hdr;
  83. /*
  84. * add the station to the known list before transmitting the
  85. * authentication response. this way it won't get de-authed by FW
  86. * when transmitting too soon.
  87. */
  88. hdr = (struct ieee80211_hdr *)(skb->data +
  89. sizeof(struct wl1271_tx_hw_descr));
  90. if (ieee80211_is_auth(hdr->frame_control))
  91. wl1271_acx_set_inconnection_sta(wl, hdr->addr1);
  92. }
  93. static void wl1271_tx_regulate_link(struct wl1271 *wl, u8 hlid)
  94. {
  95. bool fw_ps;
  96. u8 tx_blks;
  97. /* only regulate station links */
  98. if (hlid < WL1271_AP_STA_HLID_START)
  99. return;
  100. fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
  101. tx_blks = wl->links[hlid].allocated_blks;
  102. /*
  103. * if in FW PS and there is enough data in FW we can put the link
  104. * into high-level PS and clean out its TX queues.
  105. */
  106. if (fw_ps && tx_blks >= WL1271_PS_STA_MAX_BLOCKS)
  107. wl1271_ps_link_start(wl, hlid, true);
  108. }
  109. u8 wl1271_tx_get_hlid(struct sk_buff *skb)
  110. {
  111. struct ieee80211_tx_info *control = IEEE80211_SKB_CB(skb);
  112. if (control->control.sta) {
  113. struct wl1271_station *wl_sta;
  114. wl_sta = (struct wl1271_station *)
  115. control->control.sta->drv_priv;
  116. return wl_sta->hlid;
  117. } else {
  118. struct ieee80211_hdr *hdr;
  119. hdr = (struct ieee80211_hdr *)skb->data;
  120. if (ieee80211_is_mgmt(hdr->frame_control))
  121. return WL1271_AP_GLOBAL_HLID;
  122. else
  123. return WL1271_AP_BROADCAST_HLID;
  124. }
  125. }
  126. static unsigned int wl12xx_calc_packet_alignment(struct wl1271 *wl,
  127. unsigned int packet_length)
  128. {
  129. if (wl->quirks & WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT)
  130. return ALIGN(packet_length, WL12XX_BUS_BLOCK_SIZE);
  131. else
  132. return ALIGN(packet_length, WL1271_TX_ALIGN_TO);
  133. }
  134. static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra,
  135. u32 buf_offset, u8 hlid)
  136. {
  137. struct wl1271_tx_hw_descr *desc;
  138. u32 total_len = skb->len + sizeof(struct wl1271_tx_hw_descr) + extra;
  139. u32 len;
  140. u32 total_blocks;
  141. int id, ret = -EBUSY;
  142. u32 spare_blocks;
  143. if (unlikely(wl->quirks & WL12XX_QUIRK_USE_2_SPARE_BLOCKS))
  144. spare_blocks = 2;
  145. else
  146. spare_blocks = 1;
  147. if (buf_offset + total_len > WL1271_AGGR_BUFFER_SIZE)
  148. return -EAGAIN;
  149. /* allocate free identifier for the packet */
  150. id = wl1271_alloc_tx_id(wl, skb);
  151. if (id < 0)
  152. return id;
  153. /* approximate the number of blocks required for this packet
  154. in the firmware */
  155. len = wl12xx_calc_packet_alignment(wl, total_len);
  156. total_blocks = (len + TX_HW_BLOCK_SIZE - 1) / TX_HW_BLOCK_SIZE +
  157. spare_blocks;
  158. if (total_blocks <= wl->tx_blocks_available) {
  159. desc = (struct wl1271_tx_hw_descr *)skb_push(
  160. skb, total_len - skb->len);
  161. /* HW descriptor fields change between wl127x and wl128x */
  162. if (wl->chip.id == CHIP_ID_1283_PG20) {
  163. desc->wl128x_mem.total_mem_blocks = total_blocks;
  164. } else {
  165. desc->wl127x_mem.extra_blocks = spare_blocks;
  166. desc->wl127x_mem.total_mem_blocks = total_blocks;
  167. }
  168. desc->id = id;
  169. wl->tx_blocks_available -= total_blocks;
  170. if (wl->bss_type == BSS_TYPE_AP_BSS)
  171. wl->links[hlid].allocated_blks += total_blocks;
  172. ret = 0;
  173. wl1271_debug(DEBUG_TX,
  174. "tx_allocate: size: %d, blocks: %d, id: %d",
  175. total_len, total_blocks, id);
  176. } else {
  177. wl1271_free_tx_id(wl, id);
  178. }
  179. return ret;
  180. }
  181. static bool wl12xx_is_dummy_packet(struct wl1271 *wl, struct sk_buff *skb)
  182. {
  183. return wl->dummy_packet == skb;
  184. }
  185. static void wl1271_tx_fill_hdr(struct wl1271 *wl, struct sk_buff *skb,
  186. u32 extra, struct ieee80211_tx_info *control,
  187. u8 hlid)
  188. {
  189. struct timespec ts;
  190. struct wl1271_tx_hw_descr *desc;
  191. int aligned_len, ac, rate_idx;
  192. s64 hosttime;
  193. u16 tx_attr;
  194. desc = (struct wl1271_tx_hw_descr *) skb->data;
  195. /* relocate space for security header */
  196. if (extra) {
  197. void *framestart = skb->data + sizeof(*desc);
  198. u16 fc = *(u16 *)(framestart + extra);
  199. int hdrlen = ieee80211_hdrlen(cpu_to_le16(fc));
  200. memmove(framestart, framestart + extra, hdrlen);
  201. }
  202. /* configure packet life time */
  203. getnstimeofday(&ts);
  204. hosttime = (timespec_to_ns(&ts) >> 10);
  205. desc->start_time = cpu_to_le32(hosttime - wl->time_offset);
  206. if (wl->bss_type != BSS_TYPE_AP_BSS)
  207. desc->life_time = cpu_to_le16(TX_HW_MGMT_PKT_LIFETIME_TU);
  208. else
  209. desc->life_time = cpu_to_le16(TX_HW_AP_MODE_PKT_LIFETIME_TU);
  210. /* queue */
  211. ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
  212. desc->tid = skb->priority;
  213. if (wl12xx_is_dummy_packet(wl, skb)) {
  214. /*
  215. * FW expects the dummy packet to have an invalid session id -
  216. * any session id that is different than the one set in the join
  217. */
  218. tx_attr = ((~wl->session_counter) <<
  219. TX_HW_ATTR_OFST_SESSION_COUNTER) &
  220. TX_HW_ATTR_SESSION_COUNTER;
  221. tx_attr |= TX_HW_ATTR_TX_DUMMY_REQ;
  222. } else {
  223. /* configure the tx attributes */
  224. tx_attr =
  225. wl->session_counter << TX_HW_ATTR_OFST_SESSION_COUNTER;
  226. }
  227. if (wl->bss_type != BSS_TYPE_AP_BSS) {
  228. desc->aid = hlid;
  229. /* if the packets are destined for AP (have a STA entry)
  230. send them with AP rate policies, otherwise use default
  231. basic rates */
  232. if (control->control.sta)
  233. rate_idx = ACX_TX_AP_FULL_RATE;
  234. else
  235. rate_idx = ACX_TX_BASIC_RATE;
  236. } else {
  237. desc->hlid = hlid;
  238. switch (hlid) {
  239. case WL1271_AP_GLOBAL_HLID:
  240. rate_idx = ACX_TX_AP_MODE_MGMT_RATE;
  241. break;
  242. case WL1271_AP_BROADCAST_HLID:
  243. rate_idx = ACX_TX_AP_MODE_BCST_RATE;
  244. break;
  245. default:
  246. rate_idx = ac;
  247. break;
  248. }
  249. }
  250. tx_attr |= rate_idx << TX_HW_ATTR_OFST_RATE_POLICY;
  251. desc->reserved = 0;
  252. aligned_len = wl12xx_calc_packet_alignment(wl, skb->len);
  253. if (wl->chip.id == CHIP_ID_1283_PG20) {
  254. desc->wl128x_mem.extra_bytes = aligned_len - skb->len;
  255. desc->length = cpu_to_le16(aligned_len >> 2);
  256. wl1271_debug(DEBUG_TX, "tx_fill_hdr: hlid: %d "
  257. "tx_attr: 0x%x len: %d life: %d mem: %d",
  258. desc->hlid, tx_attr,
  259. le16_to_cpu(desc->length),
  260. le16_to_cpu(desc->life_time),
  261. desc->wl128x_mem.total_mem_blocks);
  262. } else {
  263. int pad;
  264. /* Store the aligned length in terms of words */
  265. desc->length = cpu_to_le16(aligned_len >> 2);
  266. /* calculate number of padding bytes */
  267. pad = aligned_len - skb->len;
  268. tx_attr |= pad << TX_HW_ATTR_OFST_LAST_WORD_PAD;
  269. wl1271_debug(DEBUG_TX, "tx_fill_hdr: pad: %d hlid: %d "
  270. "tx_attr: 0x%x len: %d life: %d mem: %d", pad,
  271. desc->hlid, tx_attr,
  272. le16_to_cpu(desc->length),
  273. le16_to_cpu(desc->life_time),
  274. desc->wl127x_mem.total_mem_blocks);
  275. }
  276. desc->tx_attr = cpu_to_le16(tx_attr);
  277. }
  278. /* caller must hold wl->mutex */
  279. static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct sk_buff *skb,
  280. u32 buf_offset)
  281. {
  282. struct ieee80211_tx_info *info;
  283. u32 extra = 0;
  284. int ret = 0;
  285. u32 total_len;
  286. u8 hlid;
  287. if (!skb)
  288. return -EINVAL;
  289. info = IEEE80211_SKB_CB(skb);
  290. if (info->control.hw_key &&
  291. info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP)
  292. extra = WL1271_TKIP_IV_SPACE;
  293. if (info->control.hw_key) {
  294. bool is_wep;
  295. u8 idx = info->control.hw_key->hw_key_idx;
  296. u32 cipher = info->control.hw_key->cipher;
  297. is_wep = (cipher == WLAN_CIPHER_SUITE_WEP40) ||
  298. (cipher == WLAN_CIPHER_SUITE_WEP104);
  299. if (unlikely(is_wep && wl->default_key != idx)) {
  300. ret = wl1271_set_default_wep_key(wl, idx);
  301. if (ret < 0)
  302. return ret;
  303. wl->default_key = idx;
  304. }
  305. }
  306. if (wl->bss_type == BSS_TYPE_AP_BSS)
  307. hlid = wl1271_tx_get_hlid(skb);
  308. else
  309. hlid = TX_HW_DEFAULT_AID;
  310. ret = wl1271_tx_allocate(wl, skb, extra, buf_offset, hlid);
  311. if (ret < 0)
  312. return ret;
  313. if (wl->bss_type == BSS_TYPE_AP_BSS) {
  314. wl1271_tx_ap_update_inconnection_sta(wl, skb);
  315. wl1271_tx_regulate_link(wl, hlid);
  316. } else {
  317. wl1271_tx_update_filters(wl, skb);
  318. }
  319. wl1271_tx_fill_hdr(wl, skb, extra, info, hlid);
  320. /*
  321. * The length of each packet is stored in terms of
  322. * words. Thus, we must pad the skb data to make sure its
  323. * length is aligned. The number of padding bytes is computed
  324. * and set in wl1271_tx_fill_hdr.
  325. * In special cases, we want to align to a specific block size
  326. * (eg. for wl128x with SDIO we align to 256).
  327. */
  328. total_len = wl12xx_calc_packet_alignment(wl, skb->len);
  329. memcpy(wl->aggr_buf + buf_offset, skb->data, skb->len);
  330. memset(wl->aggr_buf + buf_offset + skb->len, 0, total_len - skb->len);
  331. /* Revert side effects in the dummy packet skb, so it can be reused */
  332. if (wl12xx_is_dummy_packet(wl, skb))
  333. skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
  334. return total_len;
  335. }
  336. u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set)
  337. {
  338. struct ieee80211_supported_band *band;
  339. u32 enabled_rates = 0;
  340. int bit;
  341. band = wl->hw->wiphy->bands[wl->band];
  342. for (bit = 0; bit < band->n_bitrates; bit++) {
  343. if (rate_set & 0x1)
  344. enabled_rates |= band->bitrates[bit].hw_value;
  345. rate_set >>= 1;
  346. }
  347. #ifdef CONFIG_WL12XX_HT
  348. /* MCS rates indication are on bits 16 - 23 */
  349. rate_set >>= HW_HT_RATES_OFFSET - band->n_bitrates;
  350. for (bit = 0; bit < 8; bit++) {
  351. if (rate_set & 0x1)
  352. enabled_rates |= (CONF_HW_BIT_RATE_MCS_0 << bit);
  353. rate_set >>= 1;
  354. }
  355. #endif
  356. return enabled_rates;
  357. }
  358. void wl1271_handle_tx_low_watermark(struct wl1271 *wl)
  359. {
  360. unsigned long flags;
  361. if (test_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags) &&
  362. wl->tx_queue_count <= WL1271_TX_QUEUE_LOW_WATERMARK) {
  363. /* firmware buffer has space, restart queues */
  364. spin_lock_irqsave(&wl->wl_lock, flags);
  365. ieee80211_wake_queues(wl->hw);
  366. clear_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags);
  367. spin_unlock_irqrestore(&wl->wl_lock, flags);
  368. }
  369. }
  370. static struct sk_buff *wl1271_sta_skb_dequeue(struct wl1271 *wl)
  371. {
  372. struct sk_buff *skb = NULL;
  373. unsigned long flags;
  374. skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_VO]);
  375. if (skb)
  376. goto out;
  377. skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_VI]);
  378. if (skb)
  379. goto out;
  380. skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_BE]);
  381. if (skb)
  382. goto out;
  383. skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_BK]);
  384. out:
  385. if (skb) {
  386. spin_lock_irqsave(&wl->wl_lock, flags);
  387. wl->tx_queue_count--;
  388. spin_unlock_irqrestore(&wl->wl_lock, flags);
  389. }
  390. return skb;
  391. }
  392. static struct sk_buff *wl1271_ap_skb_dequeue(struct wl1271 *wl)
  393. {
  394. struct sk_buff *skb = NULL;
  395. unsigned long flags;
  396. int i, h, start_hlid;
  397. /* start from the link after the last one */
  398. start_hlid = (wl->last_tx_hlid + 1) % AP_MAX_LINKS;
  399. /* dequeue according to AC, round robin on each link */
  400. for (i = 0; i < AP_MAX_LINKS; i++) {
  401. h = (start_hlid + i) % AP_MAX_LINKS;
  402. skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_VO]);
  403. if (skb)
  404. goto out;
  405. skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_VI]);
  406. if (skb)
  407. goto out;
  408. skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_BE]);
  409. if (skb)
  410. goto out;
  411. skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_BK]);
  412. if (skb)
  413. goto out;
  414. }
  415. out:
  416. if (skb) {
  417. wl->last_tx_hlid = h;
  418. spin_lock_irqsave(&wl->wl_lock, flags);
  419. wl->tx_queue_count--;
  420. spin_unlock_irqrestore(&wl->wl_lock, flags);
  421. } else {
  422. wl->last_tx_hlid = 0;
  423. }
  424. return skb;
  425. }
  426. static struct sk_buff *wl1271_skb_dequeue(struct wl1271 *wl)
  427. {
  428. unsigned long flags;
  429. struct sk_buff *skb = NULL;
  430. if (wl->bss_type == BSS_TYPE_AP_BSS)
  431. skb = wl1271_ap_skb_dequeue(wl);
  432. else
  433. skb = wl1271_sta_skb_dequeue(wl);
  434. if (!skb &&
  435. test_and_clear_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags)) {
  436. skb = wl->dummy_packet;
  437. spin_lock_irqsave(&wl->wl_lock, flags);
  438. wl->tx_queue_count--;
  439. spin_unlock_irqrestore(&wl->wl_lock, flags);
  440. }
  441. return skb;
  442. }
  443. static void wl1271_skb_queue_head(struct wl1271 *wl, struct sk_buff *skb)
  444. {
  445. unsigned long flags;
  446. int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
  447. if (wl12xx_is_dummy_packet(wl, skb)) {
  448. set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags);
  449. } else if (wl->bss_type == BSS_TYPE_AP_BSS) {
  450. u8 hlid = wl1271_tx_get_hlid(skb);
  451. skb_queue_head(&wl->links[hlid].tx_queue[q], skb);
  452. /* make sure we dequeue the same packet next time */
  453. wl->last_tx_hlid = (hlid + AP_MAX_LINKS - 1) % AP_MAX_LINKS;
  454. } else {
  455. skb_queue_head(&wl->tx_queue[q], skb);
  456. }
  457. spin_lock_irqsave(&wl->wl_lock, flags);
  458. wl->tx_queue_count++;
  459. spin_unlock_irqrestore(&wl->wl_lock, flags);
  460. }
  461. void wl1271_tx_work_locked(struct wl1271 *wl)
  462. {
  463. struct sk_buff *skb;
  464. u32 buf_offset = 0;
  465. bool sent_packets = false;
  466. int ret;
  467. if (unlikely(wl->state == WL1271_STATE_OFF))
  468. return;
  469. while ((skb = wl1271_skb_dequeue(wl))) {
  470. ret = wl1271_prepare_tx_frame(wl, skb, buf_offset);
  471. if (ret == -EAGAIN) {
  472. /*
  473. * Aggregation buffer is full.
  474. * Flush buffer and try again.
  475. */
  476. wl1271_skb_queue_head(wl, skb);
  477. wl1271_write(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf,
  478. buf_offset, true);
  479. sent_packets = true;
  480. buf_offset = 0;
  481. continue;
  482. } else if (ret == -EBUSY) {
  483. /*
  484. * Firmware buffer is full.
  485. * Queue back last skb, and stop aggregating.
  486. */
  487. wl1271_skb_queue_head(wl, skb);
  488. /* No work left, avoid scheduling redundant tx work */
  489. set_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
  490. goto out_ack;
  491. } else if (ret < 0) {
  492. dev_kfree_skb(skb);
  493. goto out_ack;
  494. }
  495. buf_offset += ret;
  496. wl->tx_packets_count++;
  497. }
  498. out_ack:
  499. if (buf_offset) {
  500. wl1271_write(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf,
  501. buf_offset, true);
  502. sent_packets = true;
  503. }
  504. if (sent_packets) {
  505. /*
  506. * Interrupt the firmware with the new packets. This is only
  507. * required for older hardware revisions
  508. */
  509. if (wl->quirks & WL12XX_QUIRK_END_OF_TRANSACTION)
  510. wl1271_write32(wl, WL1271_HOST_WR_ACCESS,
  511. wl->tx_packets_count);
  512. wl1271_handle_tx_low_watermark(wl);
  513. }
  514. }
  515. void wl1271_tx_work(struct work_struct *work)
  516. {
  517. struct wl1271 *wl = container_of(work, struct wl1271, tx_work);
  518. int ret;
  519. mutex_lock(&wl->mutex);
  520. ret = wl1271_ps_elp_wakeup(wl);
  521. if (ret < 0)
  522. goto out;
  523. wl1271_tx_work_locked(wl);
  524. wl1271_ps_elp_wakeup(wl);
  525. out:
  526. mutex_unlock(&wl->mutex);
  527. }
  528. static void wl1271_tx_complete_packet(struct wl1271 *wl,
  529. struct wl1271_tx_hw_res_descr *result)
  530. {
  531. struct ieee80211_tx_info *info;
  532. struct sk_buff *skb;
  533. int id = result->id;
  534. int rate = -1;
  535. u8 retries = 0;
  536. /* check for id legality */
  537. if (unlikely(id >= ACX_TX_DESCRIPTORS || wl->tx_frames[id] == NULL)) {
  538. wl1271_warning("TX result illegal id: %d", id);
  539. return;
  540. }
  541. skb = wl->tx_frames[id];
  542. info = IEEE80211_SKB_CB(skb);
  543. if (wl12xx_is_dummy_packet(wl, skb)) {
  544. wl1271_free_tx_id(wl, id);
  545. return;
  546. }
  547. /* update the TX status info */
  548. if (result->status == TX_SUCCESS) {
  549. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
  550. info->flags |= IEEE80211_TX_STAT_ACK;
  551. rate = wl1271_rate_to_idx(result->rate_class_index, wl->band);
  552. retries = result->ack_failures;
  553. } else if (result->status == TX_RETRY_EXCEEDED) {
  554. wl->stats.excessive_retries++;
  555. retries = result->ack_failures;
  556. }
  557. info->status.rates[0].idx = rate;
  558. info->status.rates[0].count = retries;
  559. info->status.rates[0].flags = 0;
  560. info->status.ack_signal = -1;
  561. wl->stats.retry_count += result->ack_failures;
  562. /* update security sequence number */
  563. wl->tx_security_seq += (result->lsb_security_sequence_number -
  564. wl->tx_security_last_seq);
  565. wl->tx_security_last_seq = result->lsb_security_sequence_number;
  566. /* remove private header from packet */
  567. skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
  568. /* remove TKIP header space if present */
  569. if (info->control.hw_key &&
  570. info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) {
  571. int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  572. memmove(skb->data + WL1271_TKIP_IV_SPACE, skb->data, hdrlen);
  573. skb_pull(skb, WL1271_TKIP_IV_SPACE);
  574. }
  575. wl1271_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x"
  576. " status 0x%x",
  577. result->id, skb, result->ack_failures,
  578. result->rate_class_index, result->status);
  579. /* return the packet to the stack */
  580. skb_queue_tail(&wl->deferred_tx_queue, skb);
  581. ieee80211_queue_work(wl->hw, &wl->netstack_work);
  582. wl1271_free_tx_id(wl, result->id);
  583. }
  584. /* Called upon reception of a TX complete interrupt */
  585. void wl1271_tx_complete(struct wl1271 *wl)
  586. {
  587. struct wl1271_acx_mem_map *memmap =
  588. (struct wl1271_acx_mem_map *)wl->target_mem_map;
  589. u32 count, fw_counter;
  590. u32 i;
  591. /* read the tx results from the chipset */
  592. wl1271_read(wl, le32_to_cpu(memmap->tx_result),
  593. wl->tx_res_if, sizeof(*wl->tx_res_if), false);
  594. fw_counter = le32_to_cpu(wl->tx_res_if->tx_result_fw_counter);
  595. /* write host counter to chipset (to ack) */
  596. wl1271_write32(wl, le32_to_cpu(memmap->tx_result) +
  597. offsetof(struct wl1271_tx_hw_res_if,
  598. tx_result_host_counter), fw_counter);
  599. count = fw_counter - wl->tx_results_count;
  600. wl1271_debug(DEBUG_TX, "tx_complete received, packets: %d", count);
  601. /* verify that the result buffer is not getting overrun */
  602. if (unlikely(count > TX_HW_RESULT_QUEUE_LEN))
  603. wl1271_warning("TX result overflow from chipset: %d", count);
  604. /* process the results */
  605. for (i = 0; i < count; i++) {
  606. struct wl1271_tx_hw_res_descr *result;
  607. u8 offset = wl->tx_results_count & TX_HW_RESULT_QUEUE_LEN_MASK;
  608. /* process the packet */
  609. result = &(wl->tx_res_if->tx_results_queue[offset]);
  610. wl1271_tx_complete_packet(wl, result);
  611. wl->tx_results_count++;
  612. }
  613. }
  614. void wl1271_tx_reset_link_queues(struct wl1271 *wl, u8 hlid)
  615. {
  616. struct sk_buff *skb;
  617. int i, total = 0;
  618. unsigned long flags;
  619. struct ieee80211_tx_info *info;
  620. for (i = 0; i < NUM_TX_QUEUES; i++) {
  621. while ((skb = skb_dequeue(&wl->links[hlid].tx_queue[i]))) {
  622. wl1271_debug(DEBUG_TX, "link freeing skb 0x%p", skb);
  623. info = IEEE80211_SKB_CB(skb);
  624. info->status.rates[0].idx = -1;
  625. info->status.rates[0].count = 0;
  626. ieee80211_tx_status(wl->hw, skb);
  627. total++;
  628. }
  629. }
  630. spin_lock_irqsave(&wl->wl_lock, flags);
  631. wl->tx_queue_count -= total;
  632. spin_unlock_irqrestore(&wl->wl_lock, flags);
  633. wl1271_handle_tx_low_watermark(wl);
  634. }
  635. /* caller must hold wl->mutex */
  636. void wl1271_tx_reset(struct wl1271 *wl)
  637. {
  638. int i;
  639. struct sk_buff *skb;
  640. struct ieee80211_tx_info *info;
  641. /* TX failure */
  642. if (wl->bss_type == BSS_TYPE_AP_BSS) {
  643. for (i = 0; i < AP_MAX_LINKS; i++) {
  644. wl1271_tx_reset_link_queues(wl, i);
  645. wl->links[i].allocated_blks = 0;
  646. wl->links[i].prev_freed_blks = 0;
  647. }
  648. wl->last_tx_hlid = 0;
  649. } else {
  650. for (i = 0; i < NUM_TX_QUEUES; i++) {
  651. while ((skb = skb_dequeue(&wl->tx_queue[i]))) {
  652. wl1271_debug(DEBUG_TX, "freeing skb 0x%p",
  653. skb);
  654. if (!wl12xx_is_dummy_packet(wl, skb)) {
  655. info = IEEE80211_SKB_CB(skb);
  656. info->status.rates[0].idx = -1;
  657. info->status.rates[0].count = 0;
  658. ieee80211_tx_status(wl->hw, skb);
  659. }
  660. }
  661. }
  662. }
  663. wl->tx_queue_count = 0;
  664. /*
  665. * Make sure the driver is at a consistent state, in case this
  666. * function is called from a context other than interface removal.
  667. */
  668. wl1271_handle_tx_low_watermark(wl);
  669. for (i = 0; i < ACX_TX_DESCRIPTORS; i++) {
  670. if (wl->tx_frames[i] == NULL)
  671. continue;
  672. skb = wl->tx_frames[i];
  673. wl1271_free_tx_id(wl, i);
  674. wl1271_debug(DEBUG_TX, "freeing skb 0x%p", skb);
  675. if (!wl12xx_is_dummy_packet(wl, skb)) {
  676. /*
  677. * Remove private headers before passing the skb to
  678. * mac80211
  679. */
  680. info = IEEE80211_SKB_CB(skb);
  681. skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
  682. if (info->control.hw_key &&
  683. info->control.hw_key->cipher ==
  684. WLAN_CIPHER_SUITE_TKIP) {
  685. int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  686. memmove(skb->data + WL1271_TKIP_IV_SPACE,
  687. skb->data, hdrlen);
  688. skb_pull(skb, WL1271_TKIP_IV_SPACE);
  689. }
  690. info->status.rates[0].idx = -1;
  691. info->status.rates[0].count = 0;
  692. ieee80211_tx_status(wl->hw, skb);
  693. }
  694. }
  695. }
  696. #define WL1271_TX_FLUSH_TIMEOUT 500000
  697. /* caller must *NOT* hold wl->mutex */
  698. void wl1271_tx_flush(struct wl1271 *wl)
  699. {
  700. unsigned long timeout;
  701. timeout = jiffies + usecs_to_jiffies(WL1271_TX_FLUSH_TIMEOUT);
  702. while (!time_after(jiffies, timeout)) {
  703. mutex_lock(&wl->mutex);
  704. wl1271_debug(DEBUG_TX, "flushing tx buffer: %d %d",
  705. wl->tx_frames_cnt, wl->tx_queue_count);
  706. if ((wl->tx_frames_cnt == 0) && (wl->tx_queue_count == 0)) {
  707. mutex_unlock(&wl->mutex);
  708. return;
  709. }
  710. mutex_unlock(&wl->mutex);
  711. msleep(1);
  712. }
  713. wl1271_warning("Unable to flush all TX buffers, timed out.");
  714. }
  715. u32 wl1271_tx_min_rate_get(struct wl1271 *wl)
  716. {
  717. int i;
  718. u32 rate = 0;
  719. if (!wl->basic_rate_set) {
  720. WARN_ON(1);
  721. wl->basic_rate_set = wl->conf.tx.basic_rate;
  722. }
  723. for (i = 0; !rate; i++) {
  724. if ((wl->basic_rate_set >> i) & 0x1)
  725. rate = 1 << i;
  726. }
  727. return rate;
  728. }