aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/ath/ath9k/recv.c
diff options
context:
space:
mode:
authorLuis R. Rodriguez <lrodriguez@atheros.com>2009-11-05 11:44:39 -0500
committerJohn W. Linville <linville@tuxdriver.com>2009-11-11 17:09:11 -0500
commitdb86f07ec6cdea9670a0928bd1289109d2a989dc (patch)
treeaf3484cd4d43c4d89fb1d597369f0df36478bfb2 /drivers/net/wireless/ath/ath9k/recv.c
parentc9b1417055cd2518e8a3b4b27e1f8e4b72821dff (diff)
ath9k_common: add new module to share 802.11n driver helpers
ath9k and ath9k_htc share a lot of common hardware characteristics. They only differ in that ath9k_htc works with a target CPU and ath9k works directly with the hardware. ath9k_htc will do *some* things in the firmware, but a lot of others on the host. The common 802.11n hardware code is already shared through the ath9k_hw module. Common helpers amongst all Atheros drivers can use the ath module, this includes ath5k and ar9170 as users. But there is some common driver specific helpers which are not exactly hardware code which ath9k and ath9k_htc can share. We'll be using ath9k_common for this to avoid bloating the ath module and the common 802.11n hardware module ath9k_hw. We start by sharing skb pre and post processing in preparation for a hand off to mac80211. Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/ath/ath9k/recv.c')
-rw-r--r--drivers/net/wireless/ath/ath9k/recv.c284
1 files changed, 4 insertions, 280 deletions
diff --git a/drivers/net/wireless/ath/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c
index 8b7489d61d38..477365e5ae69 100644
--- a/drivers/net/wireless/ath/ath9k/recv.c
+++ b/drivers/net/wireless/ath/ath9k/recv.c
@@ -89,282 +89,6 @@ static void ath_setdefantenna(struct ath_softc *sc, u32 antenna)
89 sc->rx.rxotherant = 0; 89 sc->rx.rxotherant = 0;
90} 90}
91 91
92/* Assumes you've already done the endian to CPU conversion */
93static bool ath9k_rx_accept(struct ath_common *common,
94 struct sk_buff *skb,
95 struct ieee80211_rx_status *rxs,
96 struct ath_rx_status *rx_stats,
97 bool *decrypt_error)
98{
99 struct ath_hw *ah = common->ah;
100 struct ieee80211_hdr *hdr;
101 __le16 fc;
102
103 hdr = (struct ieee80211_hdr *) skb->data;
104 fc = hdr->frame_control;
105
106 if (!rx_stats->rs_datalen)
107 return false;
108 /*
109 * rs_status follows rs_datalen so if rs_datalen is too large
110 * we can take a hint that hardware corrupted it, so ignore
111 * those frames.
112 */
113 if (rx_stats->rs_datalen > common->rx_bufsize)
114 return false;
115
116 if (rx_stats->rs_more) {
117 /*
118 * Frame spans multiple descriptors; this cannot happen yet
119 * as we don't support jumbograms. If not in monitor mode,
120 * discard the frame. Enable this if you want to see
121 * error frames in Monitor mode.
122 */
123 if (ah->opmode != NL80211_IFTYPE_MONITOR)
124 return false;
125 } else if (rx_stats->rs_status != 0) {
126 if (rx_stats->rs_status & ATH9K_RXERR_CRC)
127 rxs->flag |= RX_FLAG_FAILED_FCS_CRC;
128 if (rx_stats->rs_status & ATH9K_RXERR_PHY)
129 return false;
130
131 if (rx_stats->rs_status & ATH9K_RXERR_DECRYPT) {
132 *decrypt_error = true;
133 } else if (rx_stats->rs_status & ATH9K_RXERR_MIC) {
134 if (ieee80211_is_ctl(fc))
135 /*
136 * Sometimes, we get invalid
137 * MIC failures on valid control frames.
138 * Remove these mic errors.
139 */
140 rx_stats->rs_status &= ~ATH9K_RXERR_MIC;
141 else
142 rxs->flag |= RX_FLAG_MMIC_ERROR;
143 }
144 /*
145 * Reject error frames with the exception of
146 * decryption and MIC failures. For monitor mode,
147 * we also ignore the CRC error.
148 */
149 if (ah->opmode == NL80211_IFTYPE_MONITOR) {
150 if (rx_stats->rs_status &
151 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
152 ATH9K_RXERR_CRC))
153 return false;
154 } else {
155 if (rx_stats->rs_status &
156 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) {
157 return false;
158 }
159 }
160 }
161 return true;
162}
163
164static u8 ath9k_process_rate(struct ath_common *common,
165 struct ieee80211_hw *hw,
166 struct ath_rx_status *rx_stats,
167 struct ieee80211_rx_status *rxs,
168 struct sk_buff *skb)
169{
170 struct ieee80211_supported_band *sband;
171 enum ieee80211_band band;
172 unsigned int i = 0;
173
174 band = hw->conf.channel->band;
175 sband = hw->wiphy->bands[band];
176
177 if (rx_stats->rs_rate & 0x80) {
178 /* HT rate */
179 rxs->flag |= RX_FLAG_HT;
180 if (rx_stats->rs_flags & ATH9K_RX_2040)
181 rxs->flag |= RX_FLAG_40MHZ;
182 if (rx_stats->rs_flags & ATH9K_RX_GI)
183 rxs->flag |= RX_FLAG_SHORT_GI;
184 return rx_stats->rs_rate & 0x7f;
185 }
186
187 for (i = 0; i < sband->n_bitrates; i++) {
188 if (sband->bitrates[i].hw_value == rx_stats->rs_rate)
189 return i;
190 if (sband->bitrates[i].hw_value_short == rx_stats->rs_rate) {
191 rxs->flag |= RX_FLAG_SHORTPRE;
192 return i;
193 }
194 }
195
196 /* No valid hardware bitrate found -- we should not get here */
197 ath_print(common, ATH_DBG_XMIT, "unsupported hw bitrate detected "
198 "0x%02x using 1 Mbit\n", rx_stats->rs_rate);
199 if ((common->debug_mask & ATH_DBG_XMIT))
200 print_hex_dump_bytes("", DUMP_PREFIX_NONE, skb->data, skb->len);
201
202 return 0;
203}
204
205/*
206 * Theory for reporting quality:
207 *
208 * At a hardware RSSI of 45 you will be able to use MCS 7 reliably.
209 * At a hardware RSSI of 45 you will be able to use MCS 15 reliably.
210 * At a hardware RSSI of 35 you should be able use 54 Mbps reliably.
211 *
212 * MCS 7 is the highets MCS index usable by a 1-stream device.
213 * MCS 15 is the highest MCS index usable by a 2-stream device.
214 *
215 * All ath9k devices are either 1-stream or 2-stream.
216 *
217 * How many bars you see is derived from the qual reporting.
218 *
219 * A more elaborate scheme can be used here but it requires tables
220 * of SNR/throughput for each possible mode used. For the MCS table
221 * you can refer to the wireless wiki:
222 *
223 * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
224 *
225 */
226static int ath9k_compute_qual(struct ieee80211_hw *hw,
227 struct ath_rx_status *rx_stats)
228{
229 int qual;
230
231 if (conf_is_ht(&hw->conf))
232 qual = rx_stats->rs_rssi * 100 / 45;
233 else
234 qual = rx_stats->rs_rssi * 100 / 35;
235
236 /*
237 * rssi can be more than 45 though, anything above that
238 * should be considered at 100%
239 */
240 if (qual > 100)
241 qual = 100;
242
243 return qual;
244}
245
246static void ath9k_process_rssi(struct ath_common *common,
247 struct ieee80211_hw *hw,
248 struct sk_buff *skb,
249 struct ath_rx_status *rx_stats)
250{
251 struct ath_hw *ah = common->ah;
252 struct ieee80211_sta *sta;
253 struct ieee80211_hdr *hdr;
254 struct ath_node *an;
255 int last_rssi = ATH_RSSI_DUMMY_MARKER;
256 __le16 fc;
257
258 hdr = (struct ieee80211_hdr *)skb->data;
259 fc = hdr->frame_control;
260
261 rcu_read_lock();
262 /* XXX: use ieee80211_find_sta! */
263 sta = ieee80211_find_sta_by_hw(hw, hdr->addr2);
264 if (sta) {
265 an = (struct ath_node *) sta->drv_priv;
266 if (rx_stats->rs_rssi != ATH9K_RSSI_BAD &&
267 !rx_stats->rs_moreaggr)
268 ATH_RSSI_LPF(an->last_rssi, rx_stats->rs_rssi);
269 last_rssi = an->last_rssi;
270 }
271 rcu_read_unlock();
272
273 if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
274 rx_stats->rs_rssi = ATH_EP_RND(last_rssi,
275 ATH_RSSI_EP_MULTIPLIER);
276 if (rx_stats->rs_rssi < 0)
277 rx_stats->rs_rssi = 0;
278 else if (rx_stats->rs_rssi > 127)
279 rx_stats->rs_rssi = 127;
280
281 /* Update Beacon RSSI, this is used by ANI. */
282 if (ieee80211_is_beacon(fc))
283 ah->stats.avgbrssi = rx_stats->rs_rssi;
284}
285
286/*
287 * For Decrypt or Demic errors, we only mark packet status here and always push
288 * up the frame up to let mac80211 handle the actual error case, be it no
289 * decryption key or real decryption error. This let us keep statistics there.
290 */
291static int ath9k_rx_skb_preprocess(struct ath_common *common,
292 struct ieee80211_hw *hw,
293 struct sk_buff *skb,
294 struct ath_rx_status *rx_stats,
295 struct ieee80211_rx_status *rx_status,
296 bool *decrypt_error)
297{
298 struct ath_hw *ah = common->ah;
299
300 if (!ath9k_rx_accept(common, skb, rx_status, rx_stats, decrypt_error))
301 return -EINVAL;
302
303 ath9k_process_rssi(common, hw, skb, rx_stats);
304
305 rx_status->rate_idx = ath9k_process_rate(common, hw,
306 rx_stats, rx_status, skb);
307 rx_status->mactime = ath9k_hw_extend_tsf(ah, rx_stats->rs_tstamp);
308 rx_status->band = hw->conf.channel->band;
309 rx_status->freq = hw->conf.channel->center_freq;
310 rx_status->noise = common->ani.noise_floor;
311 rx_status->signal = ATH_DEFAULT_NOISE_FLOOR + rx_stats->rs_rssi;
312 rx_status->antenna = rx_stats->rs_antenna;
313 rx_status->qual = ath9k_compute_qual(hw, rx_stats);
314 rx_status->flag |= RX_FLAG_TSFT;
315
316 return 0;
317}
318
319static void ath9k_rx_skb_postprocess(struct ath_common *common,
320 struct sk_buff *skb,
321 struct ath_rx_status *rx_stats,
322 struct ieee80211_rx_status *rxs,
323 bool decrypt_error)
324{
325 struct ath_hw *ah = common->ah;
326 struct ieee80211_hdr *hdr;
327 int hdrlen, padsize;
328 u8 keyix;
329 __le16 fc;
330
331 /* see if any padding is done by the hw and remove it */
332 hdr = (struct ieee80211_hdr *) skb->data;
333 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
334 fc = hdr->frame_control;
335
336 /* The MAC header is padded to have 32-bit boundary if the
337 * packet payload is non-zero. The general calculation for
338 * padsize would take into account odd header lengths:
339 * padsize = (4 - hdrlen % 4) % 4; However, since only
340 * even-length headers are used, padding can only be 0 or 2
341 * bytes and we can optimize this a bit. In addition, we must
342 * not try to remove padding from short control frames that do
343 * not have payload. */
344 padsize = hdrlen & 3;
345 if (padsize && hdrlen >= 24) {
346 memmove(skb->data + padsize, skb->data, hdrlen);
347 skb_pull(skb, padsize);
348 }
349
350 keyix = rx_stats->rs_keyix;
351
352 if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error) {
353 rxs->flag |= RX_FLAG_DECRYPTED;
354 } else if (ieee80211_has_protected(fc)
355 && !decrypt_error && skb->len >= hdrlen + 4) {
356 keyix = skb->data[hdrlen + 3] >> 6;
357
358 if (test_bit(keyix, common->keymap))
359 rxs->flag |= RX_FLAG_DECRYPTED;
360 }
361 if (ah->sw_mgmt_crypto &&
362 (rxs->flag & RX_FLAG_DECRYPTED) &&
363 ieee80211_is_mgmt(fc))
364 /* Use software decrypt for management frames. */
365 rxs->flag &= ~RX_FLAG_DECRYPTED;
366}
367
368static void ath_opmode_init(struct ath_softc *sc) 92static void ath_opmode_init(struct ath_softc *sc)
369{ 93{
370 struct ath_hw *ah = sc->sc_ah; 94 struct ath_hw *ah = sc->sc_ah;
@@ -854,8 +578,8 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush)
854 if (flush) 578 if (flush)
855 goto requeue; 579 goto requeue;
856 580
857 retval = ath9k_rx_skb_preprocess(common, hw, skb, rx_stats, 581 retval = ath9k_cmn_rx_skb_preprocess(common, hw, skb, rx_stats,
858 rxs, &decrypt_error); 582 rxs, &decrypt_error);
859 if (retval) 583 if (retval)
860 goto requeue; 584 goto requeue;
861 585
@@ -877,8 +601,8 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush)
877 601
878 skb_put(skb, rx_stats->rs_datalen); 602 skb_put(skb, rx_stats->rs_datalen);
879 603
880 ath9k_rx_skb_postprocess(common, skb, rx_stats, 604 ath9k_cmn_rx_skb_postprocess(common, skb, rx_stats,
881 rxs, decrypt_error); 605 rxs, decrypt_error);
882 606
883 /* We will now give hardware our shiny new allocated skb */ 607 /* We will now give hardware our shiny new allocated skb */
884 bf->bf_mpdu = requeue_skb; 608 bf->bf_mpdu = requeue_skb;