rx.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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/gfp.h>
  24. #include "wl12xx.h"
  25. #include "acx.h"
  26. #include "reg.h"
  27. #include "rx.h"
  28. #include "io.h"
  29. static u8 wl1271_rx_get_mem_block(struct wl1271_fw_status *status,
  30. u32 drv_rx_counter)
  31. {
  32. return le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) &
  33. RX_MEM_BLOCK_MASK;
  34. }
  35. static u32 wl1271_rx_get_buf_size(struct wl1271_fw_status *status,
  36. u32 drv_rx_counter)
  37. {
  38. return (le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) &
  39. RX_BUF_SIZE_MASK) >> RX_BUF_SIZE_SHIFT_DIV;
  40. }
  41. static void wl1271_rx_status(struct wl1271 *wl,
  42. struct wl1271_rx_descriptor *desc,
  43. struct ieee80211_rx_status *status,
  44. u8 beacon)
  45. {
  46. enum ieee80211_band desc_band;
  47. memset(status, 0, sizeof(struct ieee80211_rx_status));
  48. status->band = wl->band;
  49. if ((desc->flags & WL1271_RX_DESC_BAND_MASK) == WL1271_RX_DESC_BAND_BG)
  50. desc_band = IEEE80211_BAND_2GHZ;
  51. else
  52. desc_band = IEEE80211_BAND_5GHZ;
  53. status->rate_idx = wl1271_rate_to_idx(desc->rate, desc_band);
  54. #ifdef CONFIG_WL12XX_HT
  55. /* 11n support */
  56. if (desc->rate <= CONF_HW_RXTX_RATE_MCS0)
  57. status->flag |= RX_FLAG_HT;
  58. #endif
  59. status->signal = desc->rssi;
  60. /*
  61. * FIXME: In wl1251, the SNR should be divided by two. In wl1271 we
  62. * need to divide by two for now, but TI has been discussing about
  63. * changing it. This needs to be rechecked.
  64. */
  65. wl->noise = desc->rssi - (desc->snr >> 1);
  66. status->freq = ieee80211_channel_to_frequency(desc->channel);
  67. if (desc->flags & WL1271_RX_DESC_ENCRYPT_MASK) {
  68. status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED;
  69. if (likely(!(desc->status & WL1271_RX_DESC_DECRYPT_FAIL)))
  70. status->flag |= RX_FLAG_DECRYPTED;
  71. if (unlikely(desc->status & WL1271_RX_DESC_MIC_FAIL))
  72. status->flag |= RX_FLAG_MMIC_ERROR;
  73. }
  74. }
  75. static int wl1271_rx_handle_data(struct wl1271 *wl, u8 *data, u32 length)
  76. {
  77. struct wl1271_rx_descriptor *desc;
  78. struct sk_buff *skb;
  79. u16 *fc;
  80. u8 *buf;
  81. u8 beacon = 0;
  82. /*
  83. * In PLT mode we seem to get frames and mac80211 warns about them,
  84. * workaround this by not retrieving them at all.
  85. */
  86. if (unlikely(wl->state == WL1271_STATE_PLT))
  87. return -EINVAL;
  88. skb = __dev_alloc_skb(length, GFP_KERNEL);
  89. if (!skb) {
  90. wl1271_error("Couldn't allocate RX frame");
  91. return -ENOMEM;
  92. }
  93. buf = skb_put(skb, length);
  94. memcpy(buf, data, length);
  95. /* the data read starts with the descriptor */
  96. desc = (struct wl1271_rx_descriptor *) buf;
  97. /* now we pull the descriptor out of the buffer */
  98. skb_pull(skb, sizeof(*desc));
  99. fc = (u16 *)skb->data;
  100. if ((*fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON)
  101. beacon = 1;
  102. wl1271_rx_status(wl, desc, IEEE80211_SKB_RXCB(skb), beacon);
  103. wl1271_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, skb->len,
  104. beacon ? "beacon" : "");
  105. skb_trim(skb, skb->len - desc->pad_len);
  106. ieee80211_rx_ni(wl->hw, skb);
  107. return 0;
  108. }
  109. void wl1271_rx(struct wl1271 *wl, struct wl1271_fw_status *status)
  110. {
  111. struct wl1271_acx_mem_map *wl_mem_map = wl->target_mem_map;
  112. u32 buf_size;
  113. u32 fw_rx_counter = status->fw_rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
  114. u32 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
  115. u32 rx_counter;
  116. u32 mem_block;
  117. u32 pkt_length;
  118. u32 pkt_offset;
  119. while (drv_rx_counter != fw_rx_counter) {
  120. buf_size = 0;
  121. rx_counter = drv_rx_counter;
  122. while (rx_counter != fw_rx_counter) {
  123. pkt_length = wl1271_rx_get_buf_size(status, rx_counter);
  124. if (buf_size + pkt_length > WL1271_AGGR_BUFFER_SIZE)
  125. break;
  126. buf_size += pkt_length;
  127. rx_counter++;
  128. rx_counter &= NUM_RX_PKT_DESC_MOD_MASK;
  129. }
  130. if (buf_size == 0) {
  131. wl1271_warning("received empty data");
  132. break;
  133. }
  134. /*
  135. * Choose the block we want to read
  136. * For aggregated packets, only the first memory block should
  137. * be retrieved. The FW takes care of the rest.
  138. */
  139. mem_block = wl1271_rx_get_mem_block(status, drv_rx_counter);
  140. wl->rx_mem_pool_addr.addr = (mem_block << 8) +
  141. le32_to_cpu(wl_mem_map->packet_memory_pool_start);
  142. wl->rx_mem_pool_addr.addr_extra =
  143. wl->rx_mem_pool_addr.addr + 4;
  144. wl1271_write(wl, WL1271_SLV_REG_DATA, &wl->rx_mem_pool_addr,
  145. sizeof(wl->rx_mem_pool_addr), false);
  146. /* Read all available packets at once */
  147. wl1271_read(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf,
  148. buf_size, true);
  149. /* Split data into separate packets */
  150. pkt_offset = 0;
  151. while (pkt_offset < buf_size) {
  152. pkt_length = wl1271_rx_get_buf_size(status,
  153. drv_rx_counter);
  154. /*
  155. * the handle data call can only fail in memory-outage
  156. * conditions, in that case the received frame will just
  157. * be dropped.
  158. */
  159. wl1271_rx_handle_data(wl,
  160. wl->aggr_buf + pkt_offset,
  161. pkt_length);
  162. wl->rx_counter++;
  163. drv_rx_counter++;
  164. drv_rx_counter &= NUM_RX_PKT_DESC_MOD_MASK;
  165. pkt_offset += pkt_length;
  166. }
  167. }
  168. wl1271_write32(wl, RX_DRIVER_COUNTER_ADDRESS,
  169. cpu_to_le32(wl->rx_counter));
  170. }