wl1271_rx.c 7.4 KB

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