This source file includes following definitions.
- wl1251_rx_header
- wl1251_rx_status
- wl1251_rx_body
- wl1251_rx_ack
- wl1251_rx
1
2
3
4
5
6
7
8
9 #include <linux/skbuff.h>
10 #include <linux/gfp.h>
11 #include <net/mac80211.h>
12
13 #include "wl1251.h"
14 #include "reg.h"
15 #include "io.h"
16 #include "rx.h"
17 #include "cmd.h"
18 #include "acx.h"
19
20 static void wl1251_rx_header(struct wl1251 *wl,
21 struct wl1251_rx_descriptor *desc)
22 {
23 u32 rx_packet_ring_addr;
24
25 rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr;
26 if (wl->rx_current_buffer)
27 rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size;
28
29 wl1251_mem_read(wl, rx_packet_ring_addr, desc, sizeof(*desc));
30 }
31
32 static void wl1251_rx_status(struct wl1251 *wl,
33 struct wl1251_rx_descriptor *desc,
34 struct ieee80211_rx_status *status,
35 u8 beacon)
36 {
37 u64 mactime;
38 int ret;
39
40 memset(status, 0, sizeof(struct ieee80211_rx_status));
41
42 status->band = NL80211_BAND_2GHZ;
43 status->mactime = desc->timestamp;
44
45
46
47
48
49
50
51
52
53 if ((wl->bss_type == BSS_TYPE_IBSS) && beacon) {
54 ret = wl1251_acx_tsf_info(wl, &mactime);
55 if (ret == 0)
56 status->mactime = mactime;
57 }
58
59 status->signal = desc->rssi;
60
61
62
63
64
65 wl->noise = desc->rssi - desc->snr / 2;
66
67 status->freq = ieee80211_channel_to_frequency(desc->channel,
68 status->band);
69
70 status->flag |= RX_FLAG_MACTIME_START;
71
72 if (!wl->monitor_present && (desc->flags & RX_DESC_ENCRYPTION_MASK)) {
73 status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED;
74
75 if (likely(!(desc->flags & RX_DESC_DECRYPT_FAIL)))
76 status->flag |= RX_FLAG_DECRYPTED;
77
78 if (unlikely(desc->flags & RX_DESC_MIC_FAIL))
79 status->flag |= RX_FLAG_MMIC_ERROR;
80 }
81
82 if (unlikely(!(desc->flags & RX_DESC_VALID_FCS)))
83 status->flag |= RX_FLAG_FAILED_FCS_CRC;
84
85 switch (desc->rate) {
86
87 case RATE_2MBPS:
88 status->rate_idx = 1;
89 break;
90 case RATE_5_5MBPS:
91 status->rate_idx = 2;
92 break;
93 case RATE_11MBPS:
94 status->rate_idx = 3;
95 break;
96 case RATE_6MBPS:
97 status->rate_idx = 4;
98 break;
99 case RATE_9MBPS:
100 status->rate_idx = 5;
101 break;
102 case RATE_18MBPS:
103 status->rate_idx = 7;
104 break;
105 case RATE_24MBPS:
106 status->rate_idx = 8;
107 break;
108 case RATE_36MBPS:
109 status->rate_idx = 9;
110 break;
111 case RATE_48MBPS:
112 status->rate_idx = 10;
113 break;
114 case RATE_54MBPS:
115 status->rate_idx = 11;
116 break;
117 }
118
119
120 if (desc->rate == RATE_1MBPS) {
121 if (!(desc->mod_pre & OFDM_RATE_BIT))
122
123 status->rate_idx = 0;
124 else
125
126 status->rate_idx = 6;
127 }
128
129 if (desc->mod_pre & SHORT_PREAMBLE_BIT)
130 status->enc_flags |= RX_ENC_FLAG_SHORTPRE;
131 }
132
133 static void wl1251_rx_body(struct wl1251 *wl,
134 struct wl1251_rx_descriptor *desc)
135 {
136 struct sk_buff *skb;
137 struct ieee80211_rx_status status;
138 u8 *rx_buffer, beacon = 0;
139 u16 length, *fc;
140 u32 curr_id, last_id_inc, rx_packet_ring_addr;
141
142 length = WL1251_RX_ALIGN(desc->length - PLCP_HEADER_LENGTH);
143 curr_id = (desc->flags & RX_DESC_SEQNUM_MASK) >> RX_DESC_PACKETID_SHIFT;
144 last_id_inc = (wl->rx_last_id + 1) % (RX_MAX_PACKET_ID + 1);
145
146 if (last_id_inc != curr_id) {
147 wl1251_warning("curr ID:%d, last ID inc:%d",
148 curr_id, last_id_inc);
149 wl->rx_last_id = curr_id;
150 } else {
151 wl->rx_last_id = last_id_inc;
152 }
153
154 rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr +
155 sizeof(struct wl1251_rx_descriptor) + 20;
156 if (wl->rx_current_buffer)
157 rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size;
158
159 skb = __dev_alloc_skb(length, GFP_KERNEL);
160 if (!skb) {
161 wl1251_error("Couldn't allocate RX frame");
162 return;
163 }
164
165 rx_buffer = skb_put(skb, length);
166 wl1251_mem_read(wl, rx_packet_ring_addr, rx_buffer, length);
167
168
169 skb_trim(skb, desc->length - PLCP_HEADER_LENGTH);
170
171 fc = (u16 *)skb->data;
172
173 if ((*fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON)
174 beacon = 1;
175
176 wl1251_rx_status(wl, desc, &status, beacon);
177
178 wl1251_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, skb->len,
179 beacon ? "beacon" : "");
180
181 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
182 ieee80211_rx_ni(wl->hw, skb);
183 }
184
185 static void wl1251_rx_ack(struct wl1251 *wl)
186 {
187 u32 data, addr;
188
189 if (wl->rx_current_buffer) {
190 addr = ACX_REG_INTERRUPT_TRIG_H;
191 data = INTR_TRIG_RX_PROC1;
192 } else {
193 addr = ACX_REG_INTERRUPT_TRIG;
194 data = INTR_TRIG_RX_PROC0;
195 }
196
197 wl1251_reg_write32(wl, addr, data);
198
199
200 wl->rx_current_buffer = !wl->rx_current_buffer;
201 }
202
203
204 void wl1251_rx(struct wl1251 *wl)
205 {
206 struct wl1251_rx_descriptor *rx_desc;
207
208 if (wl->state != WL1251_STATE_ON)
209 return;
210
211 rx_desc = wl->rx_descriptor;
212
213
214 wl1251_rx_header(wl, rx_desc);
215
216
217 wl1251_rx_body(wl, rx_desc);
218
219
220 wl1251_rx_ack(wl);
221 }