tx.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  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 void wl1271_tx_ap_update_inconnection_sta(struct wl1271 *wl,
  63. struct sk_buff *skb)
  64. {
  65. struct ieee80211_hdr *hdr;
  66. /*
  67. * add the station to the known list before transmitting the
  68. * authentication response. this way it won't get de-authed by FW
  69. * when transmitting too soon.
  70. */
  71. hdr = (struct ieee80211_hdr *)(skb->data +
  72. sizeof(struct wl1271_tx_hw_descr));
  73. if (ieee80211_is_auth(hdr->frame_control))
  74. wl1271_acx_set_inconnection_sta(wl, hdr->addr1);
  75. }
  76. u8 wl1271_tx_get_hlid(struct sk_buff *skb)
  77. {
  78. struct ieee80211_tx_info *control = IEEE80211_SKB_CB(skb);
  79. if (control->control.sta) {
  80. struct wl1271_station *wl_sta;
  81. wl_sta = (struct wl1271_station *)
  82. control->control.sta->drv_priv;
  83. return wl_sta->hlid;
  84. } else {
  85. struct ieee80211_hdr *hdr;
  86. hdr = (struct ieee80211_hdr *)skb->data;
  87. if (ieee80211_is_mgmt(hdr->frame_control))
  88. return WL1271_AP_GLOBAL_HLID;
  89. else
  90. return WL1271_AP_BROADCAST_HLID;
  91. }
  92. }
  93. static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra,
  94. u32 buf_offset)
  95. {
  96. struct wl1271_tx_hw_descr *desc;
  97. u32 total_len = skb->len + sizeof(struct wl1271_tx_hw_descr) + extra;
  98. u32 total_blocks;
  99. int id, ret = -EBUSY;
  100. if (buf_offset + total_len > WL1271_AGGR_BUFFER_SIZE)
  101. return -EAGAIN;
  102. /* allocate free identifier for the packet */
  103. id = wl1271_alloc_tx_id(wl, skb);
  104. if (id < 0)
  105. return id;
  106. /* approximate the number of blocks required for this packet
  107. in the firmware */
  108. total_blocks = total_len + TX_HW_BLOCK_SIZE - 1;
  109. total_blocks = total_blocks / TX_HW_BLOCK_SIZE + TX_HW_BLOCK_SPARE;
  110. if (total_blocks <= wl->tx_blocks_available) {
  111. desc = (struct wl1271_tx_hw_descr *)skb_push(
  112. skb, total_len - skb->len);
  113. desc->extra_mem_blocks = TX_HW_BLOCK_SPARE;
  114. desc->total_mem_blocks = total_blocks;
  115. desc->id = id;
  116. wl->tx_blocks_available -= total_blocks;
  117. ret = 0;
  118. wl1271_debug(DEBUG_TX,
  119. "tx_allocate: size: %d, blocks: %d, id: %d",
  120. total_len, total_blocks, id);
  121. } else {
  122. wl1271_free_tx_id(wl, id);
  123. }
  124. return ret;
  125. }
  126. static void wl1271_tx_fill_hdr(struct wl1271 *wl, struct sk_buff *skb,
  127. u32 extra, struct ieee80211_tx_info *control)
  128. {
  129. struct timespec ts;
  130. struct wl1271_tx_hw_descr *desc;
  131. int pad, ac, rate_idx;
  132. s64 hosttime;
  133. u16 tx_attr;
  134. desc = (struct wl1271_tx_hw_descr *) skb->data;
  135. /* relocate space for security header */
  136. if (extra) {
  137. void *framestart = skb->data + sizeof(*desc);
  138. u16 fc = *(u16 *)(framestart + extra);
  139. int hdrlen = ieee80211_hdrlen(cpu_to_le16(fc));
  140. memmove(framestart, framestart + extra, hdrlen);
  141. }
  142. /* configure packet life time */
  143. getnstimeofday(&ts);
  144. hosttime = (timespec_to_ns(&ts) >> 10);
  145. desc->start_time = cpu_to_le32(hosttime - wl->time_offset);
  146. if (wl->bss_type != BSS_TYPE_AP_BSS)
  147. desc->life_time = cpu_to_le16(TX_HW_MGMT_PKT_LIFETIME_TU);
  148. else
  149. desc->life_time = cpu_to_le16(TX_HW_AP_MODE_PKT_LIFETIME_TU);
  150. /* configure the tx attributes */
  151. tx_attr = wl->session_counter << TX_HW_ATTR_OFST_SESSION_COUNTER;
  152. /* queue (we use same identifiers for tid's and ac's */
  153. ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
  154. desc->tid = ac;
  155. if (wl->bss_type != BSS_TYPE_AP_BSS) {
  156. desc->aid = TX_HW_DEFAULT_AID;
  157. /* if the packets are destined for AP (have a STA entry)
  158. send them with AP rate policies, otherwise use default
  159. basic rates */
  160. if (control->control.sta)
  161. rate_idx = ACX_TX_AP_FULL_RATE;
  162. else
  163. rate_idx = ACX_TX_BASIC_RATE;
  164. } else {
  165. if (control->control.sta) {
  166. struct wl1271_station *wl_sta;
  167. wl_sta = (struct wl1271_station *)
  168. control->control.sta->drv_priv;
  169. desc->hlid = wl_sta->hlid;
  170. rate_idx = ac;
  171. } else {
  172. struct ieee80211_hdr *hdr;
  173. hdr = (struct ieee80211_hdr *)
  174. (skb->data + sizeof(*desc));
  175. if (ieee80211_is_mgmt(hdr->frame_control)) {
  176. desc->hlid = WL1271_AP_GLOBAL_HLID;
  177. rate_idx = ACX_TX_AP_MODE_MGMT_RATE;
  178. } else {
  179. desc->hlid = WL1271_AP_BROADCAST_HLID;
  180. rate_idx = ACX_TX_AP_MODE_BCST_RATE;
  181. }
  182. }
  183. }
  184. tx_attr |= rate_idx << TX_HW_ATTR_OFST_RATE_POLICY;
  185. desc->reserved = 0;
  186. /* align the length (and store in terms of words) */
  187. pad = ALIGN(skb->len, WL1271_TX_ALIGN_TO);
  188. desc->length = cpu_to_le16(pad >> 2);
  189. /* calculate number of padding bytes */
  190. pad = pad - skb->len;
  191. tx_attr |= pad << TX_HW_ATTR_OFST_LAST_WORD_PAD;
  192. desc->tx_attr = cpu_to_le16(tx_attr);
  193. wl1271_debug(DEBUG_TX, "tx_fill_hdr: pad: %d hlid: %d "
  194. "tx_attr: 0x%x len: %d life: %d mem: %d", pad, desc->hlid,
  195. le16_to_cpu(desc->tx_attr), le16_to_cpu(desc->length),
  196. le16_to_cpu(desc->life_time), desc->total_mem_blocks);
  197. }
  198. /* caller must hold wl->mutex */
  199. static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct sk_buff *skb,
  200. u32 buf_offset)
  201. {
  202. struct ieee80211_tx_info *info;
  203. u32 extra = 0;
  204. int ret = 0;
  205. u32 total_len;
  206. if (!skb)
  207. return -EINVAL;
  208. info = IEEE80211_SKB_CB(skb);
  209. if (info->control.hw_key &&
  210. info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP)
  211. extra = WL1271_TKIP_IV_SPACE;
  212. if (info->control.hw_key) {
  213. bool is_wep;
  214. u8 idx = info->control.hw_key->hw_key_idx;
  215. u32 cipher = info->control.hw_key->cipher;
  216. is_wep = (cipher == WLAN_CIPHER_SUITE_WEP40) ||
  217. (cipher == WLAN_CIPHER_SUITE_WEP104);
  218. if (unlikely(is_wep && wl->default_key != idx)) {
  219. ret = wl1271_set_default_wep_key(wl, idx);
  220. if (ret < 0)
  221. return ret;
  222. wl->default_key = idx;
  223. }
  224. }
  225. ret = wl1271_tx_allocate(wl, skb, extra, buf_offset);
  226. if (ret < 0)
  227. return ret;
  228. if (wl->bss_type == BSS_TYPE_AP_BSS)
  229. wl1271_tx_ap_update_inconnection_sta(wl, skb);
  230. wl1271_tx_fill_hdr(wl, skb, extra, info);
  231. /*
  232. * The length of each packet is stored in terms of words. Thus, we must
  233. * pad the skb data to make sure its length is aligned.
  234. * The number of padding bytes is computed and set in wl1271_tx_fill_hdr
  235. */
  236. total_len = ALIGN(skb->len, WL1271_TX_ALIGN_TO);
  237. memcpy(wl->aggr_buf + buf_offset, skb->data, skb->len);
  238. memset(wl->aggr_buf + buf_offset + skb->len, 0, total_len - skb->len);
  239. return total_len;
  240. }
  241. u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set)
  242. {
  243. struct ieee80211_supported_band *band;
  244. u32 enabled_rates = 0;
  245. int bit;
  246. band = wl->hw->wiphy->bands[wl->band];
  247. for (bit = 0; bit < band->n_bitrates; bit++) {
  248. if (rate_set & 0x1)
  249. enabled_rates |= band->bitrates[bit].hw_value;
  250. rate_set >>= 1;
  251. }
  252. #ifdef CONFIG_WL12XX_HT
  253. /* MCS rates indication are on bits 16 - 23 */
  254. rate_set >>= HW_HT_RATES_OFFSET - band->n_bitrates;
  255. for (bit = 0; bit < 8; bit++) {
  256. if (rate_set & 0x1)
  257. enabled_rates |= (CONF_HW_BIT_RATE_MCS_0 << bit);
  258. rate_set >>= 1;
  259. }
  260. #endif
  261. return enabled_rates;
  262. }
  263. void wl1271_handle_tx_low_watermark(struct wl1271 *wl)
  264. {
  265. unsigned long flags;
  266. if (test_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags) &&
  267. wl->tx_queue_count <= WL1271_TX_QUEUE_LOW_WATERMARK) {
  268. /* firmware buffer has space, restart queues */
  269. spin_lock_irqsave(&wl->wl_lock, flags);
  270. ieee80211_wake_queues(wl->hw);
  271. clear_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags);
  272. spin_unlock_irqrestore(&wl->wl_lock, flags);
  273. }
  274. }
  275. static struct sk_buff *wl1271_sta_skb_dequeue(struct wl1271 *wl)
  276. {
  277. struct sk_buff *skb = NULL;
  278. unsigned long flags;
  279. skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_VO]);
  280. if (skb)
  281. goto out;
  282. skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_VI]);
  283. if (skb)
  284. goto out;
  285. skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_BE]);
  286. if (skb)
  287. goto out;
  288. skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_BK]);
  289. out:
  290. if (skb) {
  291. spin_lock_irqsave(&wl->wl_lock, flags);
  292. wl->tx_queue_count--;
  293. spin_unlock_irqrestore(&wl->wl_lock, flags);
  294. }
  295. return skb;
  296. }
  297. static struct sk_buff *wl1271_ap_skb_dequeue(struct wl1271 *wl)
  298. {
  299. struct sk_buff *skb = NULL;
  300. unsigned long flags;
  301. int i, h, start_hlid;
  302. /* start from the link after the last one */
  303. start_hlid = (wl->last_tx_hlid + 1) % AP_MAX_LINKS;
  304. /* dequeue according to AC, round robin on each link */
  305. for (i = 0; i < AP_MAX_LINKS; i++) {
  306. h = (start_hlid + i) % AP_MAX_LINKS;
  307. skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_VO]);
  308. if (skb)
  309. goto out;
  310. skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_VI]);
  311. if (skb)
  312. goto out;
  313. skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_BE]);
  314. if (skb)
  315. goto out;
  316. skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_BK]);
  317. if (skb)
  318. goto out;
  319. }
  320. out:
  321. if (skb) {
  322. wl->last_tx_hlid = h;
  323. spin_lock_irqsave(&wl->wl_lock, flags);
  324. wl->tx_queue_count--;
  325. spin_unlock_irqrestore(&wl->wl_lock, flags);
  326. } else {
  327. wl->last_tx_hlid = 0;
  328. }
  329. return skb;
  330. }
  331. static struct sk_buff *wl1271_skb_dequeue(struct wl1271 *wl)
  332. {
  333. if (wl->bss_type == BSS_TYPE_AP_BSS)
  334. return wl1271_ap_skb_dequeue(wl);
  335. return wl1271_sta_skb_dequeue(wl);
  336. }
  337. static void wl1271_skb_queue_head(struct wl1271 *wl, struct sk_buff *skb)
  338. {
  339. unsigned long flags;
  340. int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
  341. if (wl->bss_type == BSS_TYPE_AP_BSS) {
  342. u8 hlid = wl1271_tx_get_hlid(skb);
  343. skb_queue_head(&wl->links[hlid].tx_queue[q], skb);
  344. /* make sure we dequeue the same packet next time */
  345. wl->last_tx_hlid = (hlid + AP_MAX_LINKS - 1) % AP_MAX_LINKS;
  346. } else {
  347. skb_queue_head(&wl->tx_queue[q], skb);
  348. }
  349. spin_lock_irqsave(&wl->wl_lock, flags);
  350. wl->tx_queue_count++;
  351. spin_unlock_irqrestore(&wl->wl_lock, flags);
  352. }
  353. void wl1271_tx_work_locked(struct wl1271 *wl)
  354. {
  355. struct sk_buff *skb;
  356. bool woken_up = false;
  357. u32 buf_offset = 0;
  358. bool sent_packets = false;
  359. int ret;
  360. if (unlikely(wl->state == WL1271_STATE_OFF))
  361. goto out;
  362. while ((skb = wl1271_skb_dequeue(wl))) {
  363. if (!woken_up) {
  364. ret = wl1271_ps_elp_wakeup(wl, false);
  365. if (ret < 0)
  366. goto out_ack;
  367. woken_up = true;
  368. }
  369. ret = wl1271_prepare_tx_frame(wl, skb, buf_offset);
  370. if (ret == -EAGAIN) {
  371. /*
  372. * Aggregation buffer is full.
  373. * Flush buffer and try again.
  374. */
  375. wl1271_skb_queue_head(wl, skb);
  376. wl1271_write(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf,
  377. buf_offset, true);
  378. sent_packets = true;
  379. buf_offset = 0;
  380. continue;
  381. } else if (ret == -EBUSY) {
  382. /*
  383. * Firmware buffer is full.
  384. * Queue back last skb, and stop aggregating.
  385. */
  386. wl1271_skb_queue_head(wl, skb);
  387. /* No work left, avoid scheduling redundant tx work */
  388. set_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
  389. goto out_ack;
  390. } else if (ret < 0) {
  391. dev_kfree_skb(skb);
  392. goto out_ack;
  393. }
  394. buf_offset += ret;
  395. wl->tx_packets_count++;
  396. }
  397. out_ack:
  398. if (buf_offset) {
  399. wl1271_write(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf,
  400. buf_offset, true);
  401. sent_packets = true;
  402. }
  403. if (sent_packets) {
  404. /* interrupt the firmware with the new packets */
  405. wl1271_write32(wl, WL1271_HOST_WR_ACCESS, wl->tx_packets_count);
  406. wl1271_handle_tx_low_watermark(wl);
  407. }
  408. out:
  409. if (woken_up)
  410. wl1271_ps_elp_sleep(wl);
  411. }
  412. void wl1271_tx_work(struct work_struct *work)
  413. {
  414. struct wl1271 *wl = container_of(work, struct wl1271, tx_work);
  415. mutex_lock(&wl->mutex);
  416. wl1271_tx_work_locked(wl);
  417. mutex_unlock(&wl->mutex);
  418. }
  419. static void wl1271_tx_complete_packet(struct wl1271 *wl,
  420. struct wl1271_tx_hw_res_descr *result)
  421. {
  422. struct ieee80211_tx_info *info;
  423. struct sk_buff *skb;
  424. int id = result->id;
  425. int rate = -1;
  426. u8 retries = 0;
  427. /* check for id legality */
  428. if (unlikely(id >= ACX_TX_DESCRIPTORS || wl->tx_frames[id] == NULL)) {
  429. wl1271_warning("TX result illegal id: %d", id);
  430. return;
  431. }
  432. skb = wl->tx_frames[id];
  433. info = IEEE80211_SKB_CB(skb);
  434. /* update the TX status info */
  435. if (result->status == TX_SUCCESS) {
  436. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
  437. info->flags |= IEEE80211_TX_STAT_ACK;
  438. rate = wl1271_rate_to_idx(result->rate_class_index, wl->band);
  439. retries = result->ack_failures;
  440. } else if (result->status == TX_RETRY_EXCEEDED) {
  441. wl->stats.excessive_retries++;
  442. retries = result->ack_failures;
  443. }
  444. info->status.rates[0].idx = rate;
  445. info->status.rates[0].count = retries;
  446. info->status.rates[0].flags = 0;
  447. info->status.ack_signal = -1;
  448. wl->stats.retry_count += result->ack_failures;
  449. /* update security sequence number */
  450. wl->tx_security_seq += (result->lsb_security_sequence_number -
  451. wl->tx_security_last_seq);
  452. wl->tx_security_last_seq = result->lsb_security_sequence_number;
  453. /* remove private header from packet */
  454. skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
  455. /* remove TKIP header space if present */
  456. if (info->control.hw_key &&
  457. info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) {
  458. int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  459. memmove(skb->data + WL1271_TKIP_IV_SPACE, skb->data, hdrlen);
  460. skb_pull(skb, WL1271_TKIP_IV_SPACE);
  461. }
  462. wl1271_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x"
  463. " status 0x%x",
  464. result->id, skb, result->ack_failures,
  465. result->rate_class_index, result->status);
  466. /* return the packet to the stack */
  467. ieee80211_tx_status(wl->hw, skb);
  468. wl1271_free_tx_id(wl, result->id);
  469. }
  470. /* Called upon reception of a TX complete interrupt */
  471. void wl1271_tx_complete(struct wl1271 *wl)
  472. {
  473. struct wl1271_acx_mem_map *memmap =
  474. (struct wl1271_acx_mem_map *)wl->target_mem_map;
  475. u32 count, fw_counter;
  476. u32 i;
  477. /* read the tx results from the chipset */
  478. wl1271_read(wl, le32_to_cpu(memmap->tx_result),
  479. wl->tx_res_if, sizeof(*wl->tx_res_if), false);
  480. fw_counter = le32_to_cpu(wl->tx_res_if->tx_result_fw_counter);
  481. /* write host counter to chipset (to ack) */
  482. wl1271_write32(wl, le32_to_cpu(memmap->tx_result) +
  483. offsetof(struct wl1271_tx_hw_res_if,
  484. tx_result_host_counter), fw_counter);
  485. count = fw_counter - wl->tx_results_count;
  486. wl1271_debug(DEBUG_TX, "tx_complete received, packets: %d", count);
  487. /* verify that the result buffer is not getting overrun */
  488. if (unlikely(count > TX_HW_RESULT_QUEUE_LEN))
  489. wl1271_warning("TX result overflow from chipset: %d", count);
  490. /* process the results */
  491. for (i = 0; i < count; i++) {
  492. struct wl1271_tx_hw_res_descr *result;
  493. u8 offset = wl->tx_results_count & TX_HW_RESULT_QUEUE_LEN_MASK;
  494. /* process the packet */
  495. result = &(wl->tx_res_if->tx_results_queue[offset]);
  496. wl1271_tx_complete_packet(wl, result);
  497. wl->tx_results_count++;
  498. }
  499. }
  500. void wl1271_tx_reset_link_queues(struct wl1271 *wl, u8 hlid)
  501. {
  502. struct sk_buff *skb;
  503. int i, total = 0;
  504. unsigned long flags;
  505. for (i = 0; i < NUM_TX_QUEUES; i++) {
  506. while ((skb = skb_dequeue(&wl->links[hlid].tx_queue[i]))) {
  507. wl1271_debug(DEBUG_TX, "link freeing skb 0x%p", skb);
  508. ieee80211_tx_status(wl->hw, skb);
  509. total++;
  510. }
  511. }
  512. spin_lock_irqsave(&wl->wl_lock, flags);
  513. wl->tx_queue_count -= total;
  514. spin_unlock_irqrestore(&wl->wl_lock, flags);
  515. wl1271_handle_tx_low_watermark(wl);
  516. }
  517. /* caller must hold wl->mutex */
  518. void wl1271_tx_reset(struct wl1271 *wl)
  519. {
  520. int i;
  521. struct sk_buff *skb;
  522. /* TX failure */
  523. if (wl->bss_type == BSS_TYPE_AP_BSS) {
  524. for (i = 0; i < AP_MAX_LINKS; i++)
  525. wl1271_tx_reset_link_queues(wl, i);
  526. wl->last_tx_hlid = 0;
  527. } else {
  528. for (i = 0; i < NUM_TX_QUEUES; i++) {
  529. while ((skb = skb_dequeue(&wl->tx_queue[i]))) {
  530. wl1271_debug(DEBUG_TX, "freeing skb 0x%p",
  531. skb);
  532. ieee80211_tx_status(wl->hw, skb);
  533. }
  534. }
  535. }
  536. wl->tx_queue_count = 0;
  537. /*
  538. * Make sure the driver is at a consistent state, in case this
  539. * function is called from a context other than interface removal.
  540. */
  541. wl1271_handle_tx_low_watermark(wl);
  542. for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
  543. if (wl->tx_frames[i] != NULL) {
  544. skb = wl->tx_frames[i];
  545. wl1271_free_tx_id(wl, i);
  546. wl1271_debug(DEBUG_TX, "freeing skb 0x%p", skb);
  547. ieee80211_tx_status(wl->hw, skb);
  548. }
  549. }
  550. #define WL1271_TX_FLUSH_TIMEOUT 500000
  551. /* caller must *NOT* hold wl->mutex */
  552. void wl1271_tx_flush(struct wl1271 *wl)
  553. {
  554. unsigned long timeout;
  555. timeout = jiffies + usecs_to_jiffies(WL1271_TX_FLUSH_TIMEOUT);
  556. while (!time_after(jiffies, timeout)) {
  557. mutex_lock(&wl->mutex);
  558. wl1271_debug(DEBUG_TX, "flushing tx buffer: %d %d",
  559. wl->tx_frames_cnt, wl->tx_queue_count);
  560. if ((wl->tx_frames_cnt == 0) && (wl->tx_queue_count == 0)) {
  561. mutex_unlock(&wl->mutex);
  562. return;
  563. }
  564. mutex_unlock(&wl->mutex);
  565. msleep(1);
  566. }
  567. wl1271_warning("Unable to flush all TX buffers, timed out.");
  568. }
  569. u32 wl1271_tx_min_rate_get(struct wl1271 *wl)
  570. {
  571. int i;
  572. u32 rate = 0;
  573. if (!wl->basic_rate_set) {
  574. WARN_ON(1);
  575. wl->basic_rate_set = wl->conf.tx.basic_rate;
  576. }
  577. for (i = 0; !rate; i++) {
  578. if ((wl->basic_rate_set >> i) & 0x1)
  579. rate = 1 << i;
  580. }
  581. return rate;
  582. }