wl1251_rx.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * This file is part of wl1251
  3. *
  4. * Copyright (c) 1998-2007 Texas Instruments Incorporated
  5. * Copyright (C) 2008 Nokia Corporation
  6. *
  7. * Contact: Kalle Valo <kalle.valo@nokia.com>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * version 2 as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  21. * 02110-1301 USA
  22. *
  23. */
  24. #include <linux/skbuff.h>
  25. #include <linux/gfp.h>
  26. #include <net/mac80211.h>
  27. #include "wl1251.h"
  28. #include "wl1251_reg.h"
  29. #include "wl1251_io.h"
  30. #include "wl1251_rx.h"
  31. #include "wl1251_cmd.h"
  32. #include "wl1251_acx.h"
  33. static void wl1251_rx_header(struct wl1251 *wl,
  34. struct wl1251_rx_descriptor *desc)
  35. {
  36. u32 rx_packet_ring_addr;
  37. rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr;
  38. if (wl->rx_current_buffer)
  39. rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size;
  40. wl1251_mem_read(wl, rx_packet_ring_addr, desc, sizeof(*desc));
  41. }
  42. static void wl1251_rx_status(struct wl1251 *wl,
  43. struct wl1251_rx_descriptor *desc,
  44. struct ieee80211_rx_status *status,
  45. u8 beacon)
  46. {
  47. u64 mactime;
  48. int ret;
  49. memset(status, 0, sizeof(struct ieee80211_rx_status));
  50. status->band = IEEE80211_BAND_2GHZ;
  51. status->mactime = desc->timestamp;
  52. /*
  53. * The rx status timestamp is a 32 bits value while the TSF is a
  54. * 64 bits one.
  55. * For IBSS merging, TSF is mandatory, so we have to get it
  56. * somehow, so we ask for ACX_TSF_INFO.
  57. * That could be moved to the get_tsf() hook, but unfortunately,
  58. * this one must be atomic, while our SPI routines can sleep.
  59. */
  60. if ((wl->bss_type == BSS_TYPE_IBSS) && beacon) {
  61. ret = wl1251_acx_tsf_info(wl, &mactime);
  62. if (ret == 0)
  63. status->mactime = mactime;
  64. }
  65. status->signal = desc->rssi;
  66. /*
  67. * FIXME: guessing that snr needs to be divided by two, otherwise
  68. * the values don't make any sense
  69. */
  70. status->noise = desc->rssi - desc->snr / 2;
  71. status->freq = ieee80211_channel_to_frequency(desc->channel);
  72. status->flag |= RX_FLAG_TSFT;
  73. if (desc->flags & RX_DESC_ENCRYPTION_MASK) {
  74. status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED;
  75. if (likely(!(desc->flags & RX_DESC_DECRYPT_FAIL)))
  76. status->flag |= RX_FLAG_DECRYPTED;
  77. if (unlikely(desc->flags & RX_DESC_MIC_FAIL))
  78. status->flag |= RX_FLAG_MMIC_ERROR;
  79. }
  80. if (unlikely(!(desc->flags & RX_DESC_VALID_FCS)))
  81. status->flag |= RX_FLAG_FAILED_FCS_CRC;
  82. /* FIXME: set status->rate_idx */
  83. }
  84. static void wl1251_rx_body(struct wl1251 *wl,
  85. struct wl1251_rx_descriptor *desc)
  86. {
  87. struct sk_buff *skb;
  88. struct ieee80211_rx_status status;
  89. u8 *rx_buffer, beacon = 0;
  90. u16 length, *fc;
  91. u32 curr_id, last_id_inc, rx_packet_ring_addr;
  92. length = WL1251_RX_ALIGN(desc->length - PLCP_HEADER_LENGTH);
  93. curr_id = (desc->flags & RX_DESC_SEQNUM_MASK) >> RX_DESC_PACKETID_SHIFT;
  94. last_id_inc = (wl->rx_last_id + 1) % (RX_MAX_PACKET_ID + 1);
  95. if (last_id_inc != curr_id) {
  96. wl1251_warning("curr ID:%d, last ID inc:%d",
  97. curr_id, last_id_inc);
  98. wl->rx_last_id = curr_id;
  99. } else {
  100. wl->rx_last_id = last_id_inc;
  101. }
  102. rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr +
  103. sizeof(struct wl1251_rx_descriptor) + 20;
  104. if (wl->rx_current_buffer)
  105. rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size;
  106. skb = __dev_alloc_skb(length, GFP_KERNEL);
  107. if (!skb) {
  108. wl1251_error("Couldn't allocate RX frame");
  109. return;
  110. }
  111. rx_buffer = skb_put(skb, length);
  112. wl1251_mem_read(wl, rx_packet_ring_addr, rx_buffer, length);
  113. /* The actual lenght doesn't include the target's alignment */
  114. skb->len = desc->length - PLCP_HEADER_LENGTH;
  115. fc = (u16 *)skb->data;
  116. if ((*fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON)
  117. beacon = 1;
  118. wl1251_rx_status(wl, desc, &status, beacon);
  119. wl1251_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, skb->len,
  120. beacon ? "beacon" : "");
  121. memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
  122. ieee80211_rx_ni(wl->hw, skb);
  123. }
  124. static void wl1251_rx_ack(struct wl1251 *wl)
  125. {
  126. u32 data, addr;
  127. if (wl->rx_current_buffer) {
  128. addr = ACX_REG_INTERRUPT_TRIG_H;
  129. data = INTR_TRIG_RX_PROC1;
  130. } else {
  131. addr = ACX_REG_INTERRUPT_TRIG;
  132. data = INTR_TRIG_RX_PROC0;
  133. }
  134. wl1251_reg_write32(wl, addr, data);
  135. /* Toggle buffer ring */
  136. wl->rx_current_buffer = !wl->rx_current_buffer;
  137. }
  138. void wl1251_rx(struct wl1251 *wl)
  139. {
  140. struct wl1251_rx_descriptor *rx_desc;
  141. if (wl->state != WL1251_STATE_ON)
  142. return;
  143. rx_desc = wl->rx_descriptor;
  144. /* We first read the frame's header */
  145. wl1251_rx_header(wl, rx_desc);
  146. /* Now we can read the body */
  147. wl1251_rx_body(wl, rx_desc);
  148. /* Finally, we need to ACK the RX */
  149. wl1251_rx_ack(wl);
  150. return;
  151. }