1 /*
2  * Copyright (c) 2009-2011 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 
21 #include "hw.h"
22 #include "hw-ops.h"
23 
24 #include "common-init.h"
25 #include "common-beacon.h"
26 
27 /* Common header for Atheros 802.11n base driver cores */
28 
29 #define WME_BA_BMP_SIZE         64
30 #define WME_MAX_BA              WME_BA_BMP_SIZE
31 #define ATH_TID_MAX_BUFS        (2 * WME_MAX_BA)
32 
33 #define ATH_RSSI_DUMMY_MARKER   127
34 #define ATH_RSSI_LPF_LEN 		10
35 #define RSSI_LPF_THRESHOLD		-20
36 #define ATH_RSSI_EP_MULTIPLIER     (1<<7)
37 #define ATH_EP_MUL(x, mul)         ((x) * (mul))
38 #define ATH_RSSI_IN(x)             (ATH_EP_MUL((x), ATH_RSSI_EP_MULTIPLIER))
39 #define ATH_LPF_RSSI(x, y, len) \
40     ((x != ATH_RSSI_DUMMY_MARKER) ? (((x) * ((len) - 1) + (y)) / (len)) : (y))
41 #define ATH_RSSI_LPF(x, y) do {                     			\
42     if ((y) >= RSSI_LPF_THRESHOLD)                         		\
43 	x = ATH_LPF_RSSI((x), ATH_RSSI_IN((y)), ATH_RSSI_LPF_LEN);  	\
44 } while (0)
45 #define ATH_EP_RND(x, mul) 						\
46 	(((x) + ((mul)/2)) / (mul))
47 
48 #define IEEE80211_MS_TO_TU(x)   (((x) * 1000) / 1024)
49 
50 struct ath_beacon_config {
51 	int beacon_interval;
52 	u16 dtim_period;
53 	u16 bmiss_timeout;
54 	u8 dtim_count;
55 	bool enable_beacon;
56 	bool ibss_creator;
57 	u32 nexttbtt;
58 	u32 intval;
59 };
60 
61 bool ath9k_cmn_rx_accept(struct ath_common *common,
62 			 struct ieee80211_hdr *hdr,
63 			 struct ieee80211_rx_status *rxs,
64 			 struct ath_rx_status *rx_stats,
65 			 bool *decrypt_error,
66 			 unsigned int rxfilter);
67 void ath9k_cmn_rx_skb_postprocess(struct ath_common *common,
68 				  struct sk_buff *skb,
69 				  struct ath_rx_status *rx_stats,
70 				  struct ieee80211_rx_status *rxs,
71 				  bool decrypt_error);
72 int ath9k_cmn_process_rate(struct ath_common *common,
73 			   struct ieee80211_hw *hw,
74 			   struct ath_rx_status *rx_stats,
75 			   struct ieee80211_rx_status *rxs);
76 void ath9k_cmn_process_rssi(struct ath_common *common,
77 			    struct ieee80211_hw *hw,
78 			    struct ath_rx_status *rx_stats,
79 			    struct ieee80211_rx_status *rxs);
80 int ath9k_cmn_get_hw_crypto_keytype(struct sk_buff *skb);
81 struct ath9k_channel *ath9k_cmn_get_channel(struct ieee80211_hw *hw,
82 					    struct ath_hw *ah,
83 					    struct cfg80211_chan_def *chandef);
84 int ath9k_cmn_count_streams(unsigned int chainmask, int max);
85 void ath9k_cmn_btcoex_bt_stomp(struct ath_common *common,
86 				  enum ath_stomp_type stomp_type);
87 void ath9k_cmn_update_txpow(struct ath_hw *ah, u16 cur_txpow,
88 			    u16 new_txpow, u16 *txpower);
89 void ath9k_cmn_init_crypto(struct ath_hw *ah);
90