diff options
author | Luis R. Rodriguez <lrodriguez@atheros.com> | 2009-11-05 11:44:39 -0500 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2009-11-11 17:09:11 -0500 |
commit | db86f07ec6cdea9670a0928bd1289109d2a989dc (patch) | |
tree | af3484cd4d43c4d89fb1d597369f0df36478bfb2 /drivers | |
parent | c9b1417055cd2518e8a3b4b27e1f8e4b72821dff (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')
-rw-r--r-- | drivers/net/wireless/ath/ath9k/Kconfig | 3 | ||||
-rw-r--r-- | drivers/net/wireless/ath/ath9k/Makefile | 3 | ||||
-rw-r--r-- | drivers/net/wireless/ath/ath9k/ath9k.h | 95 | ||||
-rw-r--r-- | drivers/net/wireless/ath/ath9k/common.c | 326 | ||||
-rw-r--r-- | drivers/net/wireless/ath/ath9k/common.h | 123 | ||||
-rw-r--r-- | drivers/net/wireless/ath/ath9k/rc.h | 2 | ||||
-rw-r--r-- | drivers/net/wireless/ath/ath9k/recv.c | 284 |
7 files changed, 467 insertions, 369 deletions
diff --git a/drivers/net/wireless/ath/ath9k/Kconfig b/drivers/net/wireless/ath/ath9k/Kconfig index b735fb399fb1..006364f76bb4 100644 --- a/drivers/net/wireless/ath/ath9k/Kconfig +++ b/drivers/net/wireless/ath/ath9k/Kconfig | |||
@@ -1,5 +1,7 @@ | |||
1 | config ATH9K_HW | 1 | config ATH9K_HW |
2 | tristate | 2 | tristate |
3 | config ATH9K_COMMON | ||
4 | tristate | ||
3 | 5 | ||
4 | config ATH9K | 6 | config ATH9K |
5 | tristate "Atheros 802.11n wireless cards support" | 7 | tristate "Atheros 802.11n wireless cards support" |
@@ -8,6 +10,7 @@ config ATH9K | |||
8 | select MAC80211_LEDS | 10 | select MAC80211_LEDS |
9 | select LEDS_CLASS | 11 | select LEDS_CLASS |
10 | select NEW_LEDS | 12 | select NEW_LEDS |
13 | select ATH9K_COMMON | ||
11 | ---help--- | 14 | ---help--- |
12 | This module adds support for wireless adapters based on | 15 | This module adds support for wireless adapters based on |
13 | Atheros IEEE 802.11n AR5008, AR9001 and AR9002 family | 16 | Atheros IEEE 802.11n AR5008, AR9001 and AR9002 family |
diff --git a/drivers/net/wireless/ath/ath9k/Makefile b/drivers/net/wireless/ath/ath9k/Makefile index 8caf2a8f8953..e53f9680a385 100644 --- a/drivers/net/wireless/ath/ath9k/Makefile +++ b/drivers/net/wireless/ath/ath9k/Makefile | |||
@@ -23,3 +23,6 @@ ath9k_hw-y:= hw.o \ | |||
23 | mac.o \ | 23 | mac.o \ |
24 | 24 | ||
25 | obj-$(CONFIG_ATH9K_HW) += ath9k_hw.o | 25 | obj-$(CONFIG_ATH9K_HW) += ath9k_hw.o |
26 | |||
27 | obj-$(CONFIG_ATH9K_COMMON) += ath9k_common.o | ||
28 | ath9k_common-y:= common.o | ||
diff --git a/drivers/net/wireless/ath/ath9k/ath9k.h b/drivers/net/wireless/ath/ath9k/ath9k.h index 88969cbae132..d9bcc3abb425 100644 --- a/drivers/net/wireless/ath/ath9k/ath9k.h +++ b/drivers/net/wireless/ath/ath9k/ath9k.h | |||
@@ -19,14 +19,16 @@ | |||
19 | 19 | ||
20 | #include <linux/etherdevice.h> | 20 | #include <linux/etherdevice.h> |
21 | #include <linux/device.h> | 21 | #include <linux/device.h> |
22 | #include <net/mac80211.h> | ||
23 | #include <linux/leds.h> | 22 | #include <linux/leds.h> |
24 | 23 | ||
25 | #include "hw.h" | ||
26 | #include "rc.h" | 24 | #include "rc.h" |
27 | #include "debug.h" | 25 | #include "debug.h" |
28 | #include "../ath.h" | 26 | #include "common.h" |
29 | #include "../debug.h" | 27 | |
28 | /* | ||
29 | * Header for the ath9k.ko driver core *only* -- hw code nor any other driver | ||
30 | * should rely on this file or its contents. | ||
31 | */ | ||
30 | 32 | ||
31 | struct ath_node; | 33 | struct ath_node; |
32 | 34 | ||
@@ -99,18 +101,6 @@ enum buffer_type { | |||
99 | BUF_XRETRY = BIT(5), | 101 | BUF_XRETRY = BIT(5), |
100 | }; | 102 | }; |
101 | 103 | ||
102 | struct ath_buf_state { | ||
103 | int bfs_nframes; | ||
104 | u16 bfs_al; | ||
105 | u16 bfs_frmlen; | ||
106 | int bfs_seqno; | ||
107 | int bfs_tidno; | ||
108 | int bfs_retries; | ||
109 | u8 bf_type; | ||
110 | u32 bfs_keyix; | ||
111 | enum ath9k_key_type bfs_keytype; | ||
112 | }; | ||
113 | |||
114 | #define bf_nframes bf_state.bfs_nframes | 104 | #define bf_nframes bf_state.bfs_nframes |
115 | #define bf_al bf_state.bfs_al | 105 | #define bf_al bf_state.bfs_al |
116 | #define bf_frmlen bf_state.bfs_frmlen | 106 | #define bf_frmlen bf_state.bfs_frmlen |
@@ -125,21 +115,6 @@ struct ath_buf_state { | |||
125 | #define bf_isretried(bf) (bf->bf_state.bf_type & BUF_RETRY) | 115 | #define bf_isretried(bf) (bf->bf_state.bf_type & BUF_RETRY) |
126 | #define bf_isxretried(bf) (bf->bf_state.bf_type & BUF_XRETRY) | 116 | #define bf_isxretried(bf) (bf->bf_state.bf_type & BUF_XRETRY) |
127 | 117 | ||
128 | struct ath_buf { | ||
129 | struct list_head list; | ||
130 | struct ath_buf *bf_lastbf; /* last buf of this unit (a frame or | ||
131 | an aggregate) */ | ||
132 | struct ath_buf *bf_next; /* next subframe in the aggregate */ | ||
133 | struct sk_buff *bf_mpdu; /* enclosing frame structure */ | ||
134 | struct ath_desc *bf_desc; /* virtual addr of desc */ | ||
135 | dma_addr_t bf_daddr; /* physical addr of desc */ | ||
136 | dma_addr_t bf_buf_addr; /* physical addr of data buffer */ | ||
137 | bool bf_stale; | ||
138 | u16 bf_flags; | ||
139 | struct ath_buf_state bf_state; | ||
140 | dma_addr_t bf_dmacontext; | ||
141 | }; | ||
142 | |||
143 | struct ath_descdma { | 118 | struct ath_descdma { |
144 | struct ath_desc *dd_desc; | 119 | struct ath_desc *dd_desc; |
145 | dma_addr_t dd_desc_paddr; | 120 | dma_addr_t dd_desc_paddr; |
@@ -159,13 +134,9 @@ void ath_descdma_cleanup(struct ath_softc *sc, struct ath_descdma *dd, | |||
159 | 134 | ||
160 | #define ATH_MAX_ANTENNA 3 | 135 | #define ATH_MAX_ANTENNA 3 |
161 | #define ATH_RXBUF 512 | 136 | #define ATH_RXBUF 512 |
162 | #define WME_NUM_TID 16 | ||
163 | #define ATH_TXBUF 512 | 137 | #define ATH_TXBUF 512 |
164 | #define ATH_TXMAXTRY 13 | 138 | #define ATH_TXMAXTRY 13 |
165 | #define ATH_MGT_TXMAXTRY 4 | 139 | #define ATH_MGT_TXMAXTRY 4 |
166 | #define WME_BA_BMP_SIZE 64 | ||
167 | #define WME_MAX_BA WME_BA_BMP_SIZE | ||
168 | #define ATH_TID_MAX_BUFS (2 * WME_MAX_BA) | ||
169 | 140 | ||
170 | #define TID_TO_WME_AC(_tid) \ | 141 | #define TID_TO_WME_AC(_tid) \ |
171 | ((((_tid) == 0) || ((_tid) == 3)) ? WME_AC_BE : \ | 142 | ((((_tid) == 0) || ((_tid) == 3)) ? WME_AC_BE : \ |
@@ -173,12 +144,6 @@ void ath_descdma_cleanup(struct ath_softc *sc, struct ath_descdma *dd, | |||
173 | (((_tid) == 4) || ((_tid) == 5)) ? WME_AC_VI : \ | 144 | (((_tid) == 4) || ((_tid) == 5)) ? WME_AC_VI : \ |
174 | WME_AC_VO) | 145 | WME_AC_VO) |
175 | 146 | ||
176 | #define WME_AC_BE 0 | ||
177 | #define WME_AC_BK 1 | ||
178 | #define WME_AC_VI 2 | ||
179 | #define WME_AC_VO 3 | ||
180 | #define WME_NUM_AC 4 | ||
181 | |||
182 | #define ADDBA_EXCHANGE_ATTEMPTS 10 | 147 | #define ADDBA_EXCHANGE_ATTEMPTS 10 |
183 | #define ATH_AGGR_DELIM_SZ 4 | 148 | #define ATH_AGGR_DELIM_SZ 4 |
184 | #define ATH_AGGR_MINPLEN 256 /* in bytes, minimum packet length */ | 149 | #define ATH_AGGR_MINPLEN 256 /* in bytes, minimum packet length */ |
@@ -252,30 +217,6 @@ struct ath_txq { | |||
252 | #define AGGR_ADDBA_COMPLETE BIT(2) | 217 | #define AGGR_ADDBA_COMPLETE BIT(2) |
253 | #define AGGR_ADDBA_PROGRESS BIT(3) | 218 | #define AGGR_ADDBA_PROGRESS BIT(3) |
254 | 219 | ||
255 | struct ath_atx_tid { | ||
256 | struct list_head list; | ||
257 | struct list_head buf_q; | ||
258 | struct ath_node *an; | ||
259 | struct ath_atx_ac *ac; | ||
260 | struct ath_buf *tx_buf[ATH_TID_MAX_BUFS]; | ||
261 | u16 seq_start; | ||
262 | u16 seq_next; | ||
263 | u16 baw_size; | ||
264 | int tidno; | ||
265 | int baw_head; /* first un-acked tx buffer */ | ||
266 | int baw_tail; /* next unused tx buffer slot */ | ||
267 | int sched; | ||
268 | int paused; | ||
269 | u8 state; | ||
270 | }; | ||
271 | |||
272 | struct ath_atx_ac { | ||
273 | int sched; | ||
274 | int qnum; | ||
275 | struct list_head list; | ||
276 | struct list_head tid_q; | ||
277 | }; | ||
278 | |||
279 | struct ath_tx_control { | 220 | struct ath_tx_control { |
280 | struct ath_txq *txq; | 221 | struct ath_txq *txq; |
281 | int if_id; | 222 | int if_id; |
@@ -286,29 +227,6 @@ struct ath_tx_control { | |||
286 | #define ATH_TX_XRETRY 0x02 | 227 | #define ATH_TX_XRETRY 0x02 |
287 | #define ATH_TX_BAR 0x04 | 228 | #define ATH_TX_BAR 0x04 |
288 | 229 | ||
289 | #define ATH_RSSI_LPF_LEN 10 | ||
290 | #define RSSI_LPF_THRESHOLD -20 | ||
291 | #define ATH_RSSI_EP_MULTIPLIER (1<<7) | ||
292 | #define ATH_EP_MUL(x, mul) ((x) * (mul)) | ||
293 | #define ATH_RSSI_IN(x) (ATH_EP_MUL((x), ATH_RSSI_EP_MULTIPLIER)) | ||
294 | #define ATH_LPF_RSSI(x, y, len) \ | ||
295 | ((x != ATH_RSSI_DUMMY_MARKER) ? (((x) * ((len) - 1) + (y)) / (len)) : (y)) | ||
296 | #define ATH_RSSI_LPF(x, y) do { \ | ||
297 | if ((y) >= RSSI_LPF_THRESHOLD) \ | ||
298 | x = ATH_LPF_RSSI((x), ATH_RSSI_IN((y)), ATH_RSSI_LPF_LEN); \ | ||
299 | } while (0) | ||
300 | #define ATH_EP_RND(x, mul) \ | ||
301 | ((((x)%(mul)) >= ((mul)/2)) ? ((x) + ((mul) - 1)) / (mul) : (x)/(mul)) | ||
302 | |||
303 | struct ath_node { | ||
304 | struct ath_softc *an_sc; | ||
305 | struct ath_atx_tid tid[WME_NUM_TID]; | ||
306 | struct ath_atx_ac ac[WME_NUM_AC]; | ||
307 | u16 maxampdu; | ||
308 | u8 mpdudensity; | ||
309 | int last_rssi; | ||
310 | }; | ||
311 | |||
312 | struct ath_tx { | 230 | struct ath_tx { |
313 | u16 seq_no; | 231 | u16 seq_no; |
314 | u32 txqsetup; | 232 | u32 txqsetup; |
@@ -493,7 +411,6 @@ struct ath_led { | |||
493 | #define IEEE80211_WEP_NKID 4 /* number of key ids */ | 411 | #define IEEE80211_WEP_NKID 4 /* number of key ids */ |
494 | 412 | ||
495 | #define ATH_TXPOWER_MAX 100 /* .5 dBm units */ | 413 | #define ATH_TXPOWER_MAX 100 /* .5 dBm units */ |
496 | #define ATH_RSSI_DUMMY_MARKER 0x127 | ||
497 | #define ATH_RATE_DUMMY_MARKER 0 | 414 | #define ATH_RATE_DUMMY_MARKER 0 |
498 | 415 | ||
499 | #define SC_OP_INVALID BIT(0) | 416 | #define SC_OP_INVALID BIT(0) |
diff --git a/drivers/net/wireless/ath/ath9k/common.c b/drivers/net/wireless/ath/ath9k/common.c new file mode 100644 index 000000000000..5fb164e294de --- /dev/null +++ b/drivers/net/wireless/ath/ath9k/common.c | |||
@@ -0,0 +1,326 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2009 Atheros Communications Inc. | ||
3 | * | ||
4 | * Permission to use, copy, modify, and/or distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | /* | ||
18 | * Module for common driver code between ath9k and ath9k_htc | ||
19 | */ | ||
20 | |||
21 | #include <linux/kernel.h> | ||
22 | #include <linux/module.h> | ||
23 | |||
24 | #include "common.h" | ||
25 | |||
26 | MODULE_AUTHOR("Atheros Communications"); | ||
27 | MODULE_DESCRIPTION("Shared library for Atheros wireless 802.11n LAN cards."); | ||
28 | MODULE_LICENSE("Dual BSD/GPL"); | ||
29 | |||
30 | /* Common RX processing */ | ||
31 | |||
32 | /* Assumes you've already done the endian to CPU conversion */ | ||
33 | static bool ath9k_rx_accept(struct ath_common *common, | ||
34 | struct sk_buff *skb, | ||
35 | struct ieee80211_rx_status *rxs, | ||
36 | struct ath_rx_status *rx_stats, | ||
37 | bool *decrypt_error) | ||
38 | { | ||
39 | struct ath_hw *ah = common->ah; | ||
40 | struct ieee80211_hdr *hdr; | ||
41 | __le16 fc; | ||
42 | |||
43 | hdr = (struct ieee80211_hdr *) skb->data; | ||
44 | fc = hdr->frame_control; | ||
45 | |||
46 | if (!rx_stats->rs_datalen) | ||
47 | return false; | ||
48 | /* | ||
49 | * rs_status follows rs_datalen so if rs_datalen is too large | ||
50 | * we can take a hint that hardware corrupted it, so ignore | ||
51 | * those frames. | ||
52 | */ | ||
53 | if (rx_stats->rs_datalen > common->rx_bufsize) | ||
54 | return false; | ||
55 | |||
56 | if (rx_stats->rs_more) { | ||
57 | /* | ||
58 | * Frame spans multiple descriptors; this cannot happen yet | ||
59 | * as we don't support jumbograms. If not in monitor mode, | ||
60 | * discard the frame. Enable this if you want to see | ||
61 | * error frames in Monitor mode. | ||
62 | */ | ||
63 | if (ah->opmode != NL80211_IFTYPE_MONITOR) | ||
64 | return false; | ||
65 | } else if (rx_stats->rs_status != 0) { | ||
66 | if (rx_stats->rs_status & ATH9K_RXERR_CRC) | ||
67 | rxs->flag |= RX_FLAG_FAILED_FCS_CRC; | ||
68 | if (rx_stats->rs_status & ATH9K_RXERR_PHY) | ||
69 | return false; | ||
70 | |||
71 | if (rx_stats->rs_status & ATH9K_RXERR_DECRYPT) { | ||
72 | *decrypt_error = true; | ||
73 | } else if (rx_stats->rs_status & ATH9K_RXERR_MIC) { | ||
74 | if (ieee80211_is_ctl(fc)) | ||
75 | /* | ||
76 | * Sometimes, we get invalid | ||
77 | * MIC failures on valid control frames. | ||
78 | * Remove these mic errors. | ||
79 | */ | ||
80 | rx_stats->rs_status &= ~ATH9K_RXERR_MIC; | ||
81 | else | ||
82 | rxs->flag |= RX_FLAG_MMIC_ERROR; | ||
83 | } | ||
84 | /* | ||
85 | * Reject error frames with the exception of | ||
86 | * decryption and MIC failures. For monitor mode, | ||
87 | * we also ignore the CRC error. | ||
88 | */ | ||
89 | if (ah->opmode == NL80211_IFTYPE_MONITOR) { | ||
90 | if (rx_stats->rs_status & | ||
91 | ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC | | ||
92 | ATH9K_RXERR_CRC)) | ||
93 | return false; | ||
94 | } else { | ||
95 | if (rx_stats->rs_status & | ||
96 | ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) { | ||
97 | return false; | ||
98 | } | ||
99 | } | ||
100 | } | ||
101 | return true; | ||
102 | } | ||
103 | |||
104 | static u8 ath9k_process_rate(struct ath_common *common, | ||
105 | struct ieee80211_hw *hw, | ||
106 | struct ath_rx_status *rx_stats, | ||
107 | struct ieee80211_rx_status *rxs, | ||
108 | struct sk_buff *skb) | ||
109 | { | ||
110 | struct ieee80211_supported_band *sband; | ||
111 | enum ieee80211_band band; | ||
112 | unsigned int i = 0; | ||
113 | |||
114 | band = hw->conf.channel->band; | ||
115 | sband = hw->wiphy->bands[band]; | ||
116 | |||
117 | if (rx_stats->rs_rate & 0x80) { | ||
118 | /* HT rate */ | ||
119 | rxs->flag |= RX_FLAG_HT; | ||
120 | if (rx_stats->rs_flags & ATH9K_RX_2040) | ||
121 | rxs->flag |= RX_FLAG_40MHZ; | ||
122 | if (rx_stats->rs_flags & ATH9K_RX_GI) | ||
123 | rxs->flag |= RX_FLAG_SHORT_GI; | ||
124 | return rx_stats->rs_rate & 0x7f; | ||
125 | } | ||
126 | |||
127 | for (i = 0; i < sband->n_bitrates; i++) { | ||
128 | if (sband->bitrates[i].hw_value == rx_stats->rs_rate) | ||
129 | return i; | ||
130 | if (sband->bitrates[i].hw_value_short == rx_stats->rs_rate) { | ||
131 | rxs->flag |= RX_FLAG_SHORTPRE; | ||
132 | return i; | ||
133 | } | ||
134 | } | ||
135 | |||
136 | /* No valid hardware bitrate found -- we should not get here */ | ||
137 | ath_print(common, ATH_DBG_XMIT, "unsupported hw bitrate detected " | ||
138 | "0x%02x using 1 Mbit\n", rx_stats->rs_rate); | ||
139 | if ((common->debug_mask & ATH_DBG_XMIT)) | ||
140 | print_hex_dump_bytes("", DUMP_PREFIX_NONE, skb->data, skb->len); | ||
141 | |||
142 | return 0; | ||
143 | } | ||
144 | |||
145 | /* | ||
146 | * Theory for reporting quality: | ||
147 | * | ||
148 | * At a hardware RSSI of 45 you will be able to use MCS 7 reliably. | ||
149 | * At a hardware RSSI of 45 you will be able to use MCS 15 reliably. | ||
150 | * At a hardware RSSI of 35 you should be able use 54 Mbps reliably. | ||
151 | * | ||
152 | * MCS 7 is the highets MCS index usable by a 1-stream device. | ||
153 | * MCS 15 is the highest MCS index usable by a 2-stream device. | ||
154 | * | ||
155 | * All ath9k devices are either 1-stream or 2-stream. | ||
156 | * | ||
157 | * How many bars you see is derived from the qual reporting. | ||
158 | * | ||
159 | * A more elaborate scheme can be used here but it requires tables | ||
160 | * of SNR/throughput for each possible mode used. For the MCS table | ||
161 | * you can refer to the wireless wiki: | ||
162 | * | ||
163 | * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n | ||
164 | * | ||
165 | */ | ||
166 | static int ath9k_compute_qual(struct ieee80211_hw *hw, | ||
167 | struct ath_rx_status *rx_stats) | ||
168 | { | ||
169 | int qual; | ||
170 | |||
171 | if (conf_is_ht(&hw->conf)) | ||
172 | qual = rx_stats->rs_rssi * 100 / 45; | ||
173 | else | ||
174 | qual = rx_stats->rs_rssi * 100 / 35; | ||
175 | |||
176 | /* | ||
177 | * rssi can be more than 45 though, anything above that | ||
178 | * should be considered at 100% | ||
179 | */ | ||
180 | if (qual > 100) | ||
181 | qual = 100; | ||
182 | |||
183 | return qual; | ||
184 | } | ||
185 | |||
186 | static void ath9k_process_rssi(struct ath_common *common, | ||
187 | struct ieee80211_hw *hw, | ||
188 | struct sk_buff *skb, | ||
189 | struct ath_rx_status *rx_stats) | ||
190 | { | ||
191 | struct ath_hw *ah = common->ah; | ||
192 | struct ieee80211_sta *sta; | ||
193 | struct ieee80211_hdr *hdr; | ||
194 | struct ath_node *an; | ||
195 | int last_rssi = ATH_RSSI_DUMMY_MARKER; | ||
196 | __le16 fc; | ||
197 | |||
198 | hdr = (struct ieee80211_hdr *)skb->data; | ||
199 | fc = hdr->frame_control; | ||
200 | |||
201 | rcu_read_lock(); | ||
202 | /* | ||
203 | * XXX: use ieee80211_find_sta! This requires quite a bit of work | ||
204 | * under the current ath9k virtual wiphy implementation as we have | ||
205 | * no way of tying a vif to wiphy. Typically vifs are attached to | ||
206 | * at least one sdata of a wiphy on mac80211 but with ath9k virtual | ||
207 | * wiphy you'd have to iterate over every wiphy and each sdata. | ||
208 | */ | ||
209 | sta = ieee80211_find_sta_by_hw(hw, hdr->addr2); | ||
210 | if (sta) { | ||
211 | an = (struct ath_node *) sta->drv_priv; | ||
212 | if (rx_stats->rs_rssi != ATH9K_RSSI_BAD && | ||
213 | !rx_stats->rs_moreaggr) | ||
214 | ATH_RSSI_LPF(an->last_rssi, rx_stats->rs_rssi); | ||
215 | last_rssi = an->last_rssi; | ||
216 | } | ||
217 | rcu_read_unlock(); | ||
218 | |||
219 | if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER)) | ||
220 | rx_stats->rs_rssi = ATH_EP_RND(last_rssi, | ||
221 | ATH_RSSI_EP_MULTIPLIER); | ||
222 | if (rx_stats->rs_rssi < 0) | ||
223 | rx_stats->rs_rssi = 0; | ||
224 | else if (rx_stats->rs_rssi > 127) | ||
225 | rx_stats->rs_rssi = 127; | ||
226 | |||
227 | /* Update Beacon RSSI, this is used by ANI. */ | ||
228 | if (ieee80211_is_beacon(fc)) | ||
229 | ah->stats.avgbrssi = rx_stats->rs_rssi; | ||
230 | } | ||
231 | |||
232 | /* | ||
233 | * For Decrypt or Demic errors, we only mark packet status here and always push | ||
234 | * up the frame up to let mac80211 handle the actual error case, be it no | ||
235 | * decryption key or real decryption error. This let us keep statistics there. | ||
236 | */ | ||
237 | int ath9k_cmn_rx_skb_preprocess(struct ath_common *common, | ||
238 | struct ieee80211_hw *hw, | ||
239 | struct sk_buff *skb, | ||
240 | struct ath_rx_status *rx_stats, | ||
241 | struct ieee80211_rx_status *rx_status, | ||
242 | bool *decrypt_error) | ||
243 | { | ||
244 | struct ath_hw *ah = common->ah; | ||
245 | |||
246 | if (!ath9k_rx_accept(common, skb, rx_status, rx_stats, decrypt_error)) | ||
247 | return -EINVAL; | ||
248 | |||
249 | ath9k_process_rssi(common, hw, skb, rx_stats); | ||
250 | |||
251 | rx_status->rate_idx = ath9k_process_rate(common, hw, | ||
252 | rx_stats, rx_status, skb); | ||
253 | rx_status->mactime = ath9k_hw_extend_tsf(ah, rx_stats->rs_tstamp); | ||
254 | rx_status->band = hw->conf.channel->band; | ||
255 | rx_status->freq = hw->conf.channel->center_freq; | ||
256 | rx_status->noise = common->ani.noise_floor; | ||
257 | rx_status->signal = ATH_DEFAULT_NOISE_FLOOR + rx_stats->rs_rssi; | ||
258 | rx_status->antenna = rx_stats->rs_antenna; | ||
259 | rx_status->qual = ath9k_compute_qual(hw, rx_stats); | ||
260 | rx_status->flag |= RX_FLAG_TSFT; | ||
261 | |||
262 | return 0; | ||
263 | } | ||
264 | EXPORT_SYMBOL(ath9k_cmn_rx_skb_preprocess); | ||
265 | |||
266 | void ath9k_cmn_rx_skb_postprocess(struct ath_common *common, | ||
267 | struct sk_buff *skb, | ||
268 | struct ath_rx_status *rx_stats, | ||
269 | struct ieee80211_rx_status *rxs, | ||
270 | bool decrypt_error) | ||
271 | { | ||
272 | struct ath_hw *ah = common->ah; | ||
273 | struct ieee80211_hdr *hdr; | ||
274 | int hdrlen, padsize; | ||
275 | u8 keyix; | ||
276 | __le16 fc; | ||
277 | |||
278 | /* see if any padding is done by the hw and remove it */ | ||
279 | hdr = (struct ieee80211_hdr *) skb->data; | ||
280 | hdrlen = ieee80211_get_hdrlen_from_skb(skb); | ||
281 | fc = hdr->frame_control; | ||
282 | |||
283 | /* The MAC header is padded to have 32-bit boundary if the | ||
284 | * packet payload is non-zero. The general calculation for | ||
285 | * padsize would take into account odd header lengths: | ||
286 | * padsize = (4 - hdrlen % 4) % 4; However, since only | ||
287 | * even-length headers are used, padding can only be 0 or 2 | ||
288 | * bytes and we can optimize this a bit. In addition, we must | ||
289 | * not try to remove padding from short control frames that do | ||
290 | * not have payload. */ | ||
291 | padsize = hdrlen & 3; | ||
292 | if (padsize && hdrlen >= 24) { | ||
293 | memmove(skb->data + padsize, skb->data, hdrlen); | ||
294 | skb_pull(skb, padsize); | ||
295 | } | ||
296 | |||
297 | keyix = rx_stats->rs_keyix; | ||
298 | |||
299 | if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error) { | ||
300 | rxs->flag |= RX_FLAG_DECRYPTED; | ||
301 | } else if (ieee80211_has_protected(fc) | ||
302 | && !decrypt_error && skb->len >= hdrlen + 4) { | ||
303 | keyix = skb->data[hdrlen + 3] >> 6; | ||
304 | |||
305 | if (test_bit(keyix, common->keymap)) | ||
306 | rxs->flag |= RX_FLAG_DECRYPTED; | ||
307 | } | ||
308 | if (ah->sw_mgmt_crypto && | ||
309 | (rxs->flag & RX_FLAG_DECRYPTED) && | ||
310 | ieee80211_is_mgmt(fc)) | ||
311 | /* Use software decrypt for management frames. */ | ||
312 | rxs->flag &= ~RX_FLAG_DECRYPTED; | ||
313 | } | ||
314 | EXPORT_SYMBOL(ath9k_cmn_rx_skb_postprocess); | ||
315 | |||
316 | static int __init ath9k_cmn_init(void) | ||
317 | { | ||
318 | return 0; | ||
319 | } | ||
320 | module_init(ath9k_cmn_init); | ||
321 | |||
322 | static void __exit ath9k_cmn_exit(void) | ||
323 | { | ||
324 | return; | ||
325 | } | ||
326 | module_exit(ath9k_cmn_exit); | ||
diff --git a/drivers/net/wireless/ath/ath9k/common.h b/drivers/net/wireless/ath/ath9k/common.h new file mode 100644 index 000000000000..292e3d860c0e --- /dev/null +++ b/drivers/net/wireless/ath/ath9k/common.h | |||
@@ -0,0 +1,123 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2009 Atheros Communications Inc. | ||
3 | * | ||
4 | * Permission to use, copy, modify, and/or distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include <net/mac80211.h> | ||
18 | |||
19 | #include "../ath.h" | ||
20 | #include "../debug.h" | ||
21 | |||
22 | #include "hw.h" | ||
23 | |||
24 | /* Common header for Atheros 802.11n base driver cores */ | ||
25 | |||
26 | #define WME_NUM_TID 16 | ||
27 | #define WME_BA_BMP_SIZE 64 | ||
28 | #define WME_MAX_BA WME_BA_BMP_SIZE | ||
29 | #define ATH_TID_MAX_BUFS (2 * WME_MAX_BA) | ||
30 | |||
31 | #define WME_AC_BE 0 | ||
32 | #define WME_AC_BK 1 | ||
33 | #define WME_AC_VI 2 | ||
34 | #define WME_AC_VO 3 | ||
35 | #define WME_NUM_AC 4 | ||
36 | |||
37 | #define ATH_RSSI_DUMMY_MARKER 0x127 | ||
38 | #define ATH_RSSI_LPF_LEN 10 | ||
39 | #define RSSI_LPF_THRESHOLD -20 | ||
40 | #define ATH_RSSI_EP_MULTIPLIER (1<<7) | ||
41 | #define ATH_EP_MUL(x, mul) ((x) * (mul)) | ||
42 | #define ATH_RSSI_IN(x) (ATH_EP_MUL((x), ATH_RSSI_EP_MULTIPLIER)) | ||
43 | #define ATH_LPF_RSSI(x, y, len) \ | ||
44 | ((x != ATH_RSSI_DUMMY_MARKER) ? (((x) * ((len) - 1) + (y)) / (len)) : (y)) | ||
45 | #define ATH_RSSI_LPF(x, y) do { \ | ||
46 | if ((y) >= RSSI_LPF_THRESHOLD) \ | ||
47 | x = ATH_LPF_RSSI((x), ATH_RSSI_IN((y)), ATH_RSSI_LPF_LEN); \ | ||
48 | } while (0) | ||
49 | #define ATH_EP_RND(x, mul) \ | ||
50 | ((((x)%(mul)) >= ((mul)/2)) ? ((x) + ((mul) - 1)) / (mul) : (x)/(mul)) | ||
51 | |||
52 | struct ath_atx_ac { | ||
53 | int sched; | ||
54 | int qnum; | ||
55 | struct list_head list; | ||
56 | struct list_head tid_q; | ||
57 | }; | ||
58 | |||
59 | struct ath_buf_state { | ||
60 | int bfs_nframes; | ||
61 | u16 bfs_al; | ||
62 | u16 bfs_frmlen; | ||
63 | int bfs_seqno; | ||
64 | int bfs_tidno; | ||
65 | int bfs_retries; | ||
66 | u8 bf_type; | ||
67 | u32 bfs_keyix; | ||
68 | enum ath9k_key_type bfs_keytype; | ||
69 | }; | ||
70 | |||
71 | struct ath_buf { | ||
72 | struct list_head list; | ||
73 | struct ath_buf *bf_lastbf; /* last buf of this unit (a frame or | ||
74 | an aggregate) */ | ||
75 | struct ath_buf *bf_next; /* next subframe in the aggregate */ | ||
76 | struct sk_buff *bf_mpdu; /* enclosing frame structure */ | ||
77 | struct ath_desc *bf_desc; /* virtual addr of desc */ | ||
78 | dma_addr_t bf_daddr; /* physical addr of desc */ | ||
79 | dma_addr_t bf_buf_addr; /* physical addr of data buffer */ | ||
80 | bool bf_stale; | ||
81 | u16 bf_flags; | ||
82 | struct ath_buf_state bf_state; | ||
83 | dma_addr_t bf_dmacontext; | ||
84 | }; | ||
85 | |||
86 | struct ath_atx_tid { | ||
87 | struct list_head list; | ||
88 | struct list_head buf_q; | ||
89 | struct ath_node *an; | ||
90 | struct ath_atx_ac *ac; | ||
91 | struct ath_buf *tx_buf[ATH_TID_MAX_BUFS]; | ||
92 | u16 seq_start; | ||
93 | u16 seq_next; | ||
94 | u16 baw_size; | ||
95 | int tidno; | ||
96 | int baw_head; /* first un-acked tx buffer */ | ||
97 | int baw_tail; /* next unused tx buffer slot */ | ||
98 | int sched; | ||
99 | int paused; | ||
100 | u8 state; | ||
101 | }; | ||
102 | |||
103 | struct ath_node { | ||
104 | struct ath_common *common; | ||
105 | struct ath_atx_tid tid[WME_NUM_TID]; | ||
106 | struct ath_atx_ac ac[WME_NUM_AC]; | ||
107 | u16 maxampdu; | ||
108 | u8 mpdudensity; | ||
109 | int last_rssi; | ||
110 | }; | ||
111 | |||
112 | int ath9k_cmn_rx_skb_preprocess(struct ath_common *common, | ||
113 | struct ieee80211_hw *hw, | ||
114 | struct sk_buff *skb, | ||
115 | struct ath_rx_status *rx_stats, | ||
116 | struct ieee80211_rx_status *rx_status, | ||
117 | bool *decrypt_error); | ||
118 | |||
119 | void ath9k_cmn_rx_skb_postprocess(struct ath_common *common, | ||
120 | struct sk_buff *skb, | ||
121 | struct ath_rx_status *rx_stats, | ||
122 | struct ieee80211_rx_status *rxs, | ||
123 | bool decrypt_error); | ||
diff --git a/drivers/net/wireless/ath/ath9k/rc.h b/drivers/net/wireless/ath/ath9k/rc.h index fa21a628ddd0..94cb9f8d2446 100644 --- a/drivers/net/wireless/ath/ath9k/rc.h +++ b/drivers/net/wireless/ath/ath9k/rc.h | |||
@@ -19,6 +19,8 @@ | |||
19 | #ifndef RC_H | 19 | #ifndef RC_H |
20 | #define RC_H | 20 | #define RC_H |
21 | 21 | ||
22 | #include "hw.h" | ||
23 | |||
22 | struct ath_softc; | 24 | struct ath_softc; |
23 | 25 | ||
24 | #define ATH_RATE_MAX 30 | 26 | #define ATH_RATE_MAX 30 |
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 */ | ||
93 | static 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 | |||
164 | static 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 | */ | ||
226 | static 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 | |||
246 | static 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 | */ | ||
291 | static 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 | |||
319 | static 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 | |||
368 | static void ath_opmode_init(struct ath_softc *sc) | 92 | static 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; |