tx.c 4.7 KB

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