wl1271_rx.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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 "wl1271.h"
  25. #include "wl1271_acx.h"
  26. #include "wl1271_reg.h"
  27. #include "wl1271_rx.h"
  28. #include "wl1271_spi.h"
  29. #include "wl1271_io.h"
  30. static u8 wl1271_rx_get_mem_block(struct wl1271_fw_status *status,
  31. u32 drv_rx_counter)
  32. {
  33. return le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) &
  34. RX_MEM_BLOCK_MASK;
  35. }
  36. static u32 wl1271_rx_get_buf_size(struct wl1271_fw_status *status,
  37. u32 drv_rx_counter)
  38. {
  39. return (le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) &
  40. RX_BUF_SIZE_MASK) >> RX_BUF_SIZE_SHIFT_DIV;
  41. }
  42. /* The values of this table must match the wl1271_rates[] array */
  43. static u8 wl1271_rx_rate_to_idx[] = {
  44. /* MCS rates are used only with 11n */
  45. WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS7 */
  46. WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS6 */
  47. WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS5 */
  48. WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS4 */
  49. WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS3 */
  50. WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS2 */
  51. WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS1 */
  52. WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS0 */
  53. 11, /* WL1271_RATE_54 */
  54. 10, /* WL1271_RATE_48 */
  55. 9, /* WL1271_RATE_36 */
  56. 8, /* WL1271_RATE_24 */
  57. /* TI-specific rate */
  58. WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_22 */
  59. 7, /* WL1271_RATE_18 */
  60. 6, /* WL1271_RATE_12 */
  61. 3, /* WL1271_RATE_11 */
  62. 5, /* WL1271_RATE_9 */
  63. 4, /* WL1271_RATE_6 */
  64. 2, /* WL1271_RATE_5_5 */
  65. 1, /* WL1271_RATE_2 */
  66. 0 /* WL1271_RATE_1 */
  67. };
  68. /* The values of this table must match the wl1271_rates[] array */
  69. static u8 wl1271_5_ghz_rx_rate_to_idx[] = {
  70. /* MCS rates are used only with 11n */
  71. WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS7 */
  72. WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS6 */
  73. WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS5 */
  74. WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS4 */
  75. WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS3 */
  76. WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS2 */
  77. WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS1 */
  78. WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_MCS0 */
  79. 7, /* WL1271_RATE_54 */
  80. 6, /* WL1271_RATE_48 */
  81. 5, /* WL1271_RATE_36 */
  82. 4, /* WL1271_RATE_24 */
  83. /* TI-specific rate */
  84. WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_22 */
  85. 3, /* WL1271_RATE_18 */
  86. 2, /* WL1271_RATE_12 */
  87. WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_11 */
  88. 1, /* WL1271_RATE_9 */
  89. 0, /* WL1271_RATE_6 */
  90. WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_5_5 */
  91. WL1271_RX_RATE_UNSUPPORTED, /* WL1271_RATE_2 */
  92. WL1271_RX_RATE_UNSUPPORTED /* WL1271_RATE_1 */
  93. };
  94. static void wl1271_rx_status(struct wl1271 *wl,
  95. struct wl1271_rx_descriptor *desc,
  96. struct ieee80211_rx_status *status,
  97. u8 beacon)
  98. {
  99. memset(status, 0, sizeof(struct ieee80211_rx_status));
  100. if ((desc->flags & WL1271_RX_DESC_BAND_MASK) ==
  101. WL1271_RX_DESC_BAND_BG) {
  102. status->band = IEEE80211_BAND_2GHZ;
  103. status->rate_idx = wl1271_rx_rate_to_idx[desc->rate];
  104. } else if ((desc->flags & WL1271_RX_DESC_BAND_MASK) ==
  105. WL1271_RX_DESC_BAND_A) {
  106. status->band = IEEE80211_BAND_5GHZ;
  107. status->rate_idx = wl1271_5_ghz_rx_rate_to_idx[desc->rate];
  108. } else
  109. wl1271_warning("unsupported band 0x%x",
  110. desc->flags & WL1271_RX_DESC_BAND_MASK);
  111. if (unlikely(status->rate_idx == WL1271_RX_RATE_UNSUPPORTED))
  112. wl1271_warning("unsupported rate");
  113. /*
  114. * FIXME: Add mactime handling. For IBSS (ad-hoc) we need to get the
  115. * timestamp from the beacon (acx_tsf_info). In BSS mode (infra) we
  116. * only need the mactime for monitor mode. For now the mactime is
  117. * not valid, so RX_FLAG_TSFT should not be set
  118. */
  119. status->signal = desc->rssi;
  120. /*
  121. * FIXME: In wl1251, the SNR should be divided by two. In wl1271 we
  122. * need to divide by two for now, but TI has been discussing about
  123. * changing it. This needs to be rechecked.
  124. */
  125. status->noise = desc->rssi - (desc->snr >> 1);
  126. status->freq = ieee80211_channel_to_frequency(desc->channel);
  127. if (desc->flags & WL1271_RX_DESC_ENCRYPT_MASK) {
  128. status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED;
  129. if (likely(!(desc->status & WL1271_RX_DESC_DECRYPT_FAIL)))
  130. status->flag |= RX_FLAG_DECRYPTED;
  131. if (unlikely(desc->status & WL1271_RX_DESC_MIC_FAIL))
  132. status->flag |= RX_FLAG_MMIC_ERROR;
  133. }
  134. }
  135. static void wl1271_rx_handle_data(struct wl1271 *wl, u32 length)
  136. {
  137. struct ieee80211_rx_status rx_status;
  138. struct wl1271_rx_descriptor *desc;
  139. struct sk_buff *skb;
  140. u16 *fc;
  141. u8 *buf;
  142. u8 beacon = 0;
  143. skb = __dev_alloc_skb(length, GFP_KERNEL);
  144. if (!skb) {
  145. wl1271_error("Couldn't allocate RX frame");
  146. return;
  147. }
  148. buf = skb_put(skb, length);
  149. wl1271_read(wl, WL1271_SLV_MEM_DATA, buf, length, true);
  150. /* the data read starts with the descriptor */
  151. desc = (struct wl1271_rx_descriptor *) buf;
  152. /* now we pull the descriptor out of the buffer */
  153. skb_pull(skb, sizeof(*desc));
  154. fc = (u16 *)skb->data;
  155. if ((*fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON)
  156. beacon = 1;
  157. wl1271_rx_status(wl, desc, &rx_status, beacon);
  158. wl1271_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, skb->len,
  159. beacon ? "beacon" : "");
  160. memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
  161. ieee80211_rx_ni(wl->hw, skb);
  162. }
  163. void wl1271_rx(struct wl1271 *wl, struct wl1271_fw_status *status)
  164. {
  165. struct wl1271_acx_mem_map *wl_mem_map = wl->target_mem_map;
  166. u32 buf_size;
  167. u32 fw_rx_counter = status->fw_rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
  168. u32 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
  169. u32 mem_block;
  170. while (drv_rx_counter != fw_rx_counter) {
  171. mem_block = wl1271_rx_get_mem_block(status, drv_rx_counter);
  172. buf_size = wl1271_rx_get_buf_size(status, drv_rx_counter);
  173. if (buf_size == 0) {
  174. wl1271_warning("received empty data");
  175. break;
  176. }
  177. wl->rx_mem_pool_addr.addr = (mem_block << 8) +
  178. le32_to_cpu(wl_mem_map->packet_memory_pool_start);
  179. wl->rx_mem_pool_addr.addr_extra =
  180. wl->rx_mem_pool_addr.addr + 4;
  181. /* Choose the block we want to read */
  182. wl1271_write(wl, WL1271_SLV_REG_DATA, &wl->rx_mem_pool_addr,
  183. sizeof(wl->rx_mem_pool_addr), false);
  184. wl1271_rx_handle_data(wl, buf_size);
  185. wl->rx_counter++;
  186. drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
  187. wl1271_write32(wl, RX_DRIVER_COUNTER_ADDRESS, wl->rx_counter);
  188. }
  189. }