tx.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * This file is part of wl18xx
  3. *
  4. * Copyright (C) 2011 Texas Instruments Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  18. * 02110-1301 USA
  19. *
  20. */
  21. #include "../wlcore/wlcore.h"
  22. #include "../wlcore/cmd.h"
  23. #include "../wlcore/debug.h"
  24. #include "../wlcore/acx.h"
  25. #include "../wlcore/tx.h"
  26. #include "wl18xx.h"
  27. #include "tx.h"
  28. static
  29. void wl18xx_get_last_tx_rate(struct wl1271 *wl, struct ieee80211_vif *vif,
  30. u8 band, struct ieee80211_tx_rate *rate)
  31. {
  32. u8 fw_rate = wl->fw_status->counters.tx_last_rate;
  33. if (fw_rate > CONF_HW_RATE_INDEX_MAX) {
  34. wl1271_error("last Tx rate invalid: %d", fw_rate);
  35. rate->idx = 0;
  36. rate->flags = 0;
  37. return;
  38. }
  39. if (fw_rate <= CONF_HW_RATE_INDEX_54MBPS) {
  40. rate->idx = fw_rate;
  41. if (band == IEEE80211_BAND_5GHZ)
  42. rate->idx -= CONF_HW_RATE_INDEX_6MBPS;
  43. rate->flags = 0;
  44. } else {
  45. rate->flags = IEEE80211_TX_RC_MCS;
  46. rate->idx = fw_rate - CONF_HW_RATE_INDEX_MCS0;
  47. /* SGI modifier is counted as a separate rate */
  48. if (fw_rate >= CONF_HW_RATE_INDEX_MCS7_SGI)
  49. (rate->idx)--;
  50. if (fw_rate == CONF_HW_RATE_INDEX_MCS15_SGI)
  51. (rate->idx)--;
  52. /* this also covers the 40Mhz SGI case (= MCS15) */
  53. if (fw_rate == CONF_HW_RATE_INDEX_MCS7_SGI ||
  54. fw_rate == CONF_HW_RATE_INDEX_MCS15_SGI)
  55. rate->flags |= IEEE80211_TX_RC_SHORT_GI;
  56. if (fw_rate > CONF_HW_RATE_INDEX_MCS7_SGI && vif) {
  57. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  58. if (wlvif->channel_type == NL80211_CHAN_HT40MINUS ||
  59. wlvif->channel_type == NL80211_CHAN_HT40PLUS) {
  60. /* adjustment needed for range 0-7 */
  61. rate->idx -= 8;
  62. rate->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
  63. }
  64. }
  65. }
  66. }
  67. static void wl18xx_tx_complete_packet(struct wl1271 *wl, u8 tx_stat_byte)
  68. {
  69. struct ieee80211_tx_info *info;
  70. struct sk_buff *skb;
  71. int id = tx_stat_byte & WL18XX_TX_STATUS_DESC_ID_MASK;
  72. bool tx_success;
  73. /* check for id legality */
  74. if (unlikely(id >= wl->num_tx_desc || wl->tx_frames[id] == NULL)) {
  75. wl1271_warning("illegal id in tx completion: %d", id);
  76. return;
  77. }
  78. /* a zero bit indicates Tx success */
  79. tx_success = !(tx_stat_byte & BIT(WL18XX_TX_STATUS_STAT_BIT_IDX));
  80. skb = wl->tx_frames[id];
  81. info = IEEE80211_SKB_CB(skb);
  82. if (wl12xx_is_dummy_packet(wl, skb)) {
  83. wl1271_free_tx_id(wl, id);
  84. return;
  85. }
  86. /* update the TX status info */
  87. if (tx_success && !(info->flags & IEEE80211_TX_CTL_NO_ACK))
  88. info->flags |= IEEE80211_TX_STAT_ACK;
  89. /*
  90. * first pass info->control.vif while it's valid, and then fill out
  91. * the info->status structures
  92. */
  93. wl18xx_get_last_tx_rate(wl, info->control.vif,
  94. info->band, &info->status.rates[0]);
  95. info->status.rates[0].count = 1; /* no data about retries */
  96. info->status.ack_signal = -1;
  97. if (!tx_success)
  98. wl->stats.retry_count++;
  99. /*
  100. * TODO: update sequence number for encryption? seems to be
  101. * unsupported for now. needed for recovery with encryption.
  102. */
  103. /* remove private header from packet */
  104. skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
  105. /* remove TKIP header space if present */
  106. if ((wl->quirks & WLCORE_QUIRK_TKIP_HEADER_SPACE) &&
  107. info->control.hw_key &&
  108. info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) {
  109. int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  110. memmove(skb->data + WL1271_EXTRA_SPACE_TKIP, skb->data, hdrlen);
  111. skb_pull(skb, WL1271_EXTRA_SPACE_TKIP);
  112. }
  113. wl1271_debug(DEBUG_TX, "tx status id %u skb 0x%p success %d",
  114. id, skb, tx_success);
  115. /* return the packet to the stack */
  116. skb_queue_tail(&wl->deferred_tx_queue, skb);
  117. queue_work(wl->freezable_wq, &wl->netstack_work);
  118. wl1271_free_tx_id(wl, id);
  119. }
  120. void wl18xx_tx_immediate_complete(struct wl1271 *wl)
  121. {
  122. struct wl18xx_fw_status_priv *status_priv =
  123. (struct wl18xx_fw_status_priv *)wl->fw_status->priv;
  124. struct wl18xx_priv *priv = wl->priv;
  125. u8 i;
  126. /* nothing to do here */
  127. if (priv->last_fw_rls_idx == status_priv->fw_release_idx)
  128. return;
  129. /* freed Tx descriptors */
  130. wl1271_debug(DEBUG_TX, "last released desc = %d, current idx = %d",
  131. priv->last_fw_rls_idx, status_priv->fw_release_idx);
  132. if (status_priv->fw_release_idx >= WL18XX_FW_MAX_TX_STATUS_DESC) {
  133. wl1271_error("invalid desc release index %d",
  134. status_priv->fw_release_idx);
  135. WARN_ON(1);
  136. return;
  137. }
  138. for (i = priv->last_fw_rls_idx;
  139. i != status_priv->fw_release_idx;
  140. i = (i + 1) % WL18XX_FW_MAX_TX_STATUS_DESC) {
  141. wl18xx_tx_complete_packet(wl,
  142. status_priv->released_tx_desc[i]);
  143. wl->tx_results_count++;
  144. }
  145. priv->last_fw_rls_idx = status_priv->fw_release_idx;
  146. }