wl1251_rx.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. status->freq = ieee80211_channel_to_frequency(desc->channel);
  67. status->flag |= RX_FLAG_TSFT;
  68. if (desc->flags & RX_DESC_ENCRYPTION_MASK) {
  69. status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED;
  70. if (likely(!(desc->flags & RX_DESC_DECRYPT_FAIL)))
  71. status->flag |= RX_FLAG_DECRYPTED;
  72. if (unlikely(desc->flags & RX_DESC_MIC_FAIL))
  73. status->flag |= RX_FLAG_MMIC_ERROR;
  74. }
  75. if (unlikely(!(desc->flags & RX_DESC_VALID_FCS)))
  76. status->flag |= RX_FLAG_FAILED_FCS_CRC;
  77. /* FIXME: set status->rate_idx */
  78. }
  79. static void wl1251_rx_body(struct wl1251 *wl,
  80. struct wl1251_rx_descriptor *desc)
  81. {
  82. struct sk_buff *skb;
  83. struct ieee80211_rx_status status;
  84. u8 *rx_buffer, beacon = 0;
  85. u16 length, *fc;
  86. u32 curr_id, last_id_inc, rx_packet_ring_addr;
  87. length = WL1251_RX_ALIGN(desc->length - PLCP_HEADER_LENGTH);
  88. curr_id = (desc->flags & RX_DESC_SEQNUM_MASK) >> RX_DESC_PACKETID_SHIFT;
  89. last_id_inc = (wl->rx_last_id + 1) % (RX_MAX_PACKET_ID + 1);
  90. if (last_id_inc != curr_id) {
  91. wl1251_warning("curr ID:%d, last ID inc:%d",
  92. curr_id, last_id_inc);
  93. wl->rx_last_id = curr_id;
  94. } else {
  95. wl->rx_last_id = last_id_inc;
  96. }
  97. rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr +
  98. sizeof(struct wl1251_rx_descriptor) + 20;
  99. if (wl->rx_current_buffer)
  100. rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size;
  101. skb = __dev_alloc_skb(length, GFP_KERNEL);
  102. if (!skb) {
  103. wl1251_error("Couldn't allocate RX frame");
  104. return;
  105. }
  106. rx_buffer = skb_put(skb, length);
  107. wl1251_mem_read(wl, rx_packet_ring_addr, rx_buffer, length);
  108. /* The actual lenght doesn't include the target's alignment */
  109. skb->len = desc->length - PLCP_HEADER_LENGTH;
  110. fc = (u16 *)skb->data;
  111. if ((*fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON)
  112. beacon = 1;
  113. wl1251_rx_status(wl, desc, &status, beacon);
  114. wl1251_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, skb->len,
  115. beacon ? "beacon" : "");
  116. memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
  117. ieee80211_rx_ni(wl->hw, skb);
  118. }
  119. static void wl1251_rx_ack(struct wl1251 *wl)
  120. {
  121. u32 data, addr;
  122. if (wl->rx_current_buffer) {
  123. addr = ACX_REG_INTERRUPT_TRIG_H;
  124. data = INTR_TRIG_RX_PROC1;
  125. } else {
  126. addr = ACX_REG_INTERRUPT_TRIG;
  127. data = INTR_TRIG_RX_PROC0;
  128. }
  129. wl1251_reg_write32(wl, addr, data);
  130. /* Toggle buffer ring */
  131. wl->rx_current_buffer = !wl->rx_current_buffer;
  132. }
  133. void wl1251_rx(struct wl1251 *wl)
  134. {
  135. struct wl1251_rx_descriptor *rx_desc;
  136. if (wl->state != WL1251_STATE_ON)
  137. return;
  138. rx_desc = wl->rx_descriptor;
  139. /* We first read the frame's header */
  140. wl1251_rx_header(wl, rx_desc);
  141. /* Now we can read the body */
  142. wl1251_rx_body(wl, rx_desc);
  143. /* Finally, we need to ACK the RX */
  144. wl1251_rx_ack(wl);
  145. }