wl1271_rx.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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_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. memset(status, 0, sizeof(struct ieee80211_rx_status));
  47. status->band = wl->band;
  48. status->rate_idx = wl1271_rate_to_idx(wl, desc->rate);
  49. status->signal = desc->rssi;
  50. status->freq = ieee80211_channel_to_frequency(desc->channel);
  51. if (desc->flags & WL1271_RX_DESC_ENCRYPT_MASK) {
  52. status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED;
  53. if (likely(!(desc->status & WL1271_RX_DESC_DECRYPT_FAIL)))
  54. status->flag |= RX_FLAG_DECRYPTED;
  55. if (unlikely(desc->status & WL1271_RX_DESC_MIC_FAIL))
  56. status->flag |= RX_FLAG_MMIC_ERROR;
  57. }
  58. }
  59. static void wl1271_rx_handle_data(struct wl1271 *wl, u32 length)
  60. {
  61. struct ieee80211_rx_status rx_status;
  62. struct wl1271_rx_descriptor *desc;
  63. struct sk_buff *skb;
  64. u16 *fc;
  65. u8 *buf;
  66. u8 beacon = 0;
  67. /*
  68. * In PLT mode we seem to get frames and mac80211 warns about them,
  69. * workaround this by not retrieving them at all.
  70. */
  71. if (unlikely(wl->state == WL1271_STATE_PLT))
  72. return;
  73. skb = __dev_alloc_skb(length, GFP_KERNEL);
  74. if (!skb) {
  75. wl1271_error("Couldn't allocate RX frame");
  76. return;
  77. }
  78. buf = skb_put(skb, length);
  79. wl1271_read(wl, WL1271_SLV_MEM_DATA, buf, length, true);
  80. /* the data read starts with the descriptor */
  81. desc = (struct wl1271_rx_descriptor *) buf;
  82. /* now we pull the descriptor out of the buffer */
  83. skb_pull(skb, sizeof(*desc));
  84. fc = (u16 *)skb->data;
  85. if ((*fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON)
  86. beacon = 1;
  87. wl1271_rx_status(wl, desc, &rx_status, beacon);
  88. wl1271_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, skb->len,
  89. beacon ? "beacon" : "");
  90. skb_trim(skb, skb->len - desc->pad_len);
  91. memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
  92. ieee80211_rx_ni(wl->hw, skb);
  93. }
  94. void wl1271_rx(struct wl1271 *wl, struct wl1271_fw_status *status)
  95. {
  96. struct wl1271_acx_mem_map *wl_mem_map = wl->target_mem_map;
  97. u32 buf_size;
  98. u32 fw_rx_counter = status->fw_rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
  99. u32 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
  100. u32 mem_block;
  101. while (drv_rx_counter != fw_rx_counter) {
  102. mem_block = wl1271_rx_get_mem_block(status, drv_rx_counter);
  103. buf_size = wl1271_rx_get_buf_size(status, drv_rx_counter);
  104. if (buf_size == 0) {
  105. wl1271_warning("received empty data");
  106. break;
  107. }
  108. wl->rx_mem_pool_addr.addr = (mem_block << 8) +
  109. le32_to_cpu(wl_mem_map->packet_memory_pool_start);
  110. wl->rx_mem_pool_addr.addr_extra =
  111. wl->rx_mem_pool_addr.addr + 4;
  112. /* Choose the block we want to read */
  113. wl1271_write(wl, WL1271_SLV_REG_DATA, &wl->rx_mem_pool_addr,
  114. sizeof(wl->rx_mem_pool_addr), false);
  115. wl1271_rx_handle_data(wl, buf_size);
  116. wl->rx_counter++;
  117. drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
  118. }
  119. wl1271_write32(wl, RX_DRIVER_COUNTER_ADDRESS, wl->rx_counter);
  120. }