1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright (c) 2013 Qualcomm Atheros, Inc.
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Permission to use, copy, modify, and/or distribute this software for any
5*4882a593Smuzhiyun * purpose with or without fee is hereby granted, provided that the above
6*4882a593Smuzhiyun * copyright notice and this permission notice appear in all copies.
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9*4882a593Smuzhiyun * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10*4882a593Smuzhiyun * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11*4882a593Smuzhiyun * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12*4882a593Smuzhiyun * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13*4882a593Smuzhiyun * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14*4882a593Smuzhiyun * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*4882a593Smuzhiyun */
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun #ifndef SPECTRAL_H
18*4882a593Smuzhiyun #define SPECTRAL_H
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun #include "../spectral_common.h"
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun /* enum spectral_mode:
23*4882a593Smuzhiyun *
24*4882a593Smuzhiyun * @SPECTRAL_DISABLED: spectral mode is disabled
25*4882a593Smuzhiyun * @SPECTRAL_BACKGROUND: hardware sends samples when it is not busy with
26*4882a593Smuzhiyun * something else.
27*4882a593Smuzhiyun * @SPECTRAL_MANUAL: spectral scan is enabled, triggering for samples
28*4882a593Smuzhiyun * is performed manually.
29*4882a593Smuzhiyun * @SPECTRAL_CHANSCAN: Like manual, but also triggered when changing channels
30*4882a593Smuzhiyun * during a channel scan.
31*4882a593Smuzhiyun */
32*4882a593Smuzhiyun enum spectral_mode {
33*4882a593Smuzhiyun SPECTRAL_DISABLED = 0,
34*4882a593Smuzhiyun SPECTRAL_BACKGROUND,
35*4882a593Smuzhiyun SPECTRAL_MANUAL,
36*4882a593Smuzhiyun SPECTRAL_CHANSCAN,
37*4882a593Smuzhiyun };
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun #define SPECTRAL_SCAN_BITMASK 0x10
40*4882a593Smuzhiyun /* Radar info packet format, used for DFS and spectral formats. */
41*4882a593Smuzhiyun struct ath_radar_info {
42*4882a593Smuzhiyun u8 pulse_length_pri;
43*4882a593Smuzhiyun u8 pulse_length_ext;
44*4882a593Smuzhiyun u8 pulse_bw_info;
45*4882a593Smuzhiyun } __packed;
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun /* The HT20 spectral data has 4 bytes of additional information at it's end.
48*4882a593Smuzhiyun *
49*4882a593Smuzhiyun * [7:0]: all bins {max_magnitude[1:0], bitmap_weight[5:0]}
50*4882a593Smuzhiyun * [7:0]: all bins max_magnitude[9:2]
51*4882a593Smuzhiyun * [7:0]: all bins {max_index[5:0], max_magnitude[11:10]}
52*4882a593Smuzhiyun * [3:0]: max_exp (shift amount to size max bin to 8-bit unsigned)
53*4882a593Smuzhiyun */
54*4882a593Smuzhiyun struct ath_ht20_mag_info {
55*4882a593Smuzhiyun u8 all_bins[3];
56*4882a593Smuzhiyun u8 max_exp;
57*4882a593Smuzhiyun } __packed;
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun /* WARNING: don't actually use this struct! MAC may vary the amount of
60*4882a593Smuzhiyun * data by -1/+2. This struct is for reference only.
61*4882a593Smuzhiyun */
62*4882a593Smuzhiyun struct ath_ht20_fft_packet {
63*4882a593Smuzhiyun u8 data[SPECTRAL_HT20_NUM_BINS];
64*4882a593Smuzhiyun struct ath_ht20_mag_info mag_info;
65*4882a593Smuzhiyun struct ath_radar_info radar_info;
66*4882a593Smuzhiyun } __packed;
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun #define SPECTRAL_HT20_TOTAL_DATA_LEN (sizeof(struct ath_ht20_fft_packet))
69*4882a593Smuzhiyun #define SPECTRAL_HT20_SAMPLE_LEN (sizeof(struct ath_ht20_mag_info) +\
70*4882a593Smuzhiyun SPECTRAL_HT20_NUM_BINS)
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun /* Dynamic 20/40 mode:
73*4882a593Smuzhiyun *
74*4882a593Smuzhiyun * [7:0]: lower bins {max_magnitude[1:0], bitmap_weight[5:0]}
75*4882a593Smuzhiyun * [7:0]: lower bins max_magnitude[9:2]
76*4882a593Smuzhiyun * [7:0]: lower bins {max_index[5:0], max_magnitude[11:10]}
77*4882a593Smuzhiyun * [7:0]: upper bins {max_magnitude[1:0], bitmap_weight[5:0]}
78*4882a593Smuzhiyun * [7:0]: upper bins max_magnitude[9:2]
79*4882a593Smuzhiyun * [7:0]: upper bins {max_index[5:0], max_magnitude[11:10]}
80*4882a593Smuzhiyun * [3:0]: max_exp (shift amount to size max bin to 8-bit unsigned)
81*4882a593Smuzhiyun */
82*4882a593Smuzhiyun struct ath_ht20_40_mag_info {
83*4882a593Smuzhiyun u8 lower_bins[3];
84*4882a593Smuzhiyun u8 upper_bins[3];
85*4882a593Smuzhiyun u8 max_exp;
86*4882a593Smuzhiyun } __packed;
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun /* WARNING: don't actually use this struct! MAC may vary the amount of
89*4882a593Smuzhiyun * data. This struct is for reference only.
90*4882a593Smuzhiyun */
91*4882a593Smuzhiyun struct ath_ht20_40_fft_packet {
92*4882a593Smuzhiyun u8 data[SPECTRAL_HT20_40_NUM_BINS];
93*4882a593Smuzhiyun struct ath_ht20_40_mag_info mag_info;
94*4882a593Smuzhiyun struct ath_radar_info radar_info;
95*4882a593Smuzhiyun } __packed;
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun struct ath_spec_scan_priv {
98*4882a593Smuzhiyun struct ath_hw *ah;
99*4882a593Smuzhiyun /* relay(fs) channel for spectral scan */
100*4882a593Smuzhiyun struct rchan *rfs_chan_spec_scan;
101*4882a593Smuzhiyun enum spectral_mode spectral_mode;
102*4882a593Smuzhiyun struct ath_spec_scan spec_config;
103*4882a593Smuzhiyun };
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun #define SPECTRAL_HT20_40_TOTAL_DATA_LEN (sizeof(struct ath_ht20_40_fft_packet))
106*4882a593Smuzhiyun #define SPECTRAL_HT20_40_SAMPLE_LEN (sizeof(struct ath_ht20_40_mag_info) +\
107*4882a593Smuzhiyun SPECTRAL_HT20_40_NUM_BINS)
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun #define SPECTRAL_SAMPLE_MAX_LEN SPECTRAL_HT20_40_SAMPLE_LEN
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun /* grabs the max magnitude from the all/upper/lower bins */
spectral_max_magnitude(u8 * bins)112*4882a593Smuzhiyun static inline u16 spectral_max_magnitude(u8 *bins)
113*4882a593Smuzhiyun {
114*4882a593Smuzhiyun return (bins[0] & 0xc0) >> 6 |
115*4882a593Smuzhiyun (bins[1] & 0xff) << 2 |
116*4882a593Smuzhiyun (bins[2] & 0x03) << 10;
117*4882a593Smuzhiyun }
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun /* return the max magnitude from the all/upper/lower bins */
spectral_max_index(u8 * bins,int num_bins)120*4882a593Smuzhiyun static inline u8 spectral_max_index(u8 *bins, int num_bins)
121*4882a593Smuzhiyun {
122*4882a593Smuzhiyun s8 m = (bins[2] & 0xfc) >> 2;
123*4882a593Smuzhiyun u8 zero_idx = num_bins / 2;
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun /* It's a 5 bit signed int, remove its sign and use one's
126*4882a593Smuzhiyun * complement interpretation to add the sign back to the 8
127*4882a593Smuzhiyun * bit int
128*4882a593Smuzhiyun */
129*4882a593Smuzhiyun if (m & 0x20) {
130*4882a593Smuzhiyun m &= ~0x20;
131*4882a593Smuzhiyun m |= 0xe0;
132*4882a593Smuzhiyun }
133*4882a593Smuzhiyun
134*4882a593Smuzhiyun /* Bring the zero point to the beginning
135*4882a593Smuzhiyun * instead of the middle so that we can use
136*4882a593Smuzhiyun * it for array lookup and that we don't deal
137*4882a593Smuzhiyun * with negative values later
138*4882a593Smuzhiyun */
139*4882a593Smuzhiyun m += zero_idx;
140*4882a593Smuzhiyun
141*4882a593Smuzhiyun /* Sanity check to make sure index is within bounds */
142*4882a593Smuzhiyun if (m < 0 || m > num_bins - 1)
143*4882a593Smuzhiyun m = 0;
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun return m;
146*4882a593Smuzhiyun }
147*4882a593Smuzhiyun
spectral_max_index_ht40(u8 * bins)148*4882a593Smuzhiyun static inline u8 spectral_max_index_ht40(u8 *bins)
149*4882a593Smuzhiyun {
150*4882a593Smuzhiyun u8 idx;
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun idx = spectral_max_index(bins, SPECTRAL_HT20_40_NUM_BINS);
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun /* positive values and zero are starting at the beginning
155*4882a593Smuzhiyun * of the data field.
156*4882a593Smuzhiyun */
157*4882a593Smuzhiyun return idx % (SPECTRAL_HT20_40_NUM_BINS / 2);
158*4882a593Smuzhiyun }
159*4882a593Smuzhiyun
spectral_max_index_ht20(u8 * bins)160*4882a593Smuzhiyun static inline u8 spectral_max_index_ht20(u8 *bins)
161*4882a593Smuzhiyun {
162*4882a593Smuzhiyun return spectral_max_index(bins, SPECTRAL_HT20_NUM_BINS);
163*4882a593Smuzhiyun }
164*4882a593Smuzhiyun
165*4882a593Smuzhiyun /* return the bitmap weight from the all/upper/lower bins */
spectral_bitmap_weight(u8 * bins)166*4882a593Smuzhiyun static inline u8 spectral_bitmap_weight(u8 *bins)
167*4882a593Smuzhiyun {
168*4882a593Smuzhiyun return bins[0] & 0x3f;
169*4882a593Smuzhiyun }
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun #ifdef CONFIG_ATH9K_COMMON_SPECTRAL
172*4882a593Smuzhiyun void ath9k_cmn_spectral_init_debug(struct ath_spec_scan_priv *spec_priv, struct dentry *debugfs_phy);
173*4882a593Smuzhiyun void ath9k_cmn_spectral_deinit_debug(struct ath_spec_scan_priv *spec_priv);
174*4882a593Smuzhiyun
175*4882a593Smuzhiyun void ath9k_cmn_spectral_scan_trigger(struct ath_common *common,
176*4882a593Smuzhiyun struct ath_spec_scan_priv *spec_priv);
177*4882a593Smuzhiyun int ath9k_cmn_spectral_scan_config(struct ath_common *common,
178*4882a593Smuzhiyun struct ath_spec_scan_priv *spec_priv,
179*4882a593Smuzhiyun enum spectral_mode spectral_mode);
180*4882a593Smuzhiyun int ath_cmn_process_fft(struct ath_spec_scan_priv *spec_priv, struct ieee80211_hdr *hdr,
181*4882a593Smuzhiyun struct ath_rx_status *rs, u64 tsf);
182*4882a593Smuzhiyun #else
ath9k_cmn_spectral_init_debug(struct ath_spec_scan_priv * spec_priv,struct dentry * debugfs_phy)183*4882a593Smuzhiyun static inline void ath9k_cmn_spectral_init_debug(struct ath_spec_scan_priv *spec_priv,
184*4882a593Smuzhiyun struct dentry *debugfs_phy)
185*4882a593Smuzhiyun {
186*4882a593Smuzhiyun }
187*4882a593Smuzhiyun
ath9k_cmn_spectral_deinit_debug(struct ath_spec_scan_priv * spec_priv)188*4882a593Smuzhiyun static inline void ath9k_cmn_spectral_deinit_debug(struct ath_spec_scan_priv *spec_priv)
189*4882a593Smuzhiyun {
190*4882a593Smuzhiyun }
191*4882a593Smuzhiyun
ath9k_cmn_spectral_scan_trigger(struct ath_common * common,struct ath_spec_scan_priv * spec_priv)192*4882a593Smuzhiyun static inline void ath9k_cmn_spectral_scan_trigger(struct ath_common *common,
193*4882a593Smuzhiyun struct ath_spec_scan_priv *spec_priv)
194*4882a593Smuzhiyun {
195*4882a593Smuzhiyun }
196*4882a593Smuzhiyun
ath_cmn_process_fft(struct ath_spec_scan_priv * spec_priv,struct ieee80211_hdr * hdr,struct ath_rx_status * rs,u64 tsf)197*4882a593Smuzhiyun static inline int ath_cmn_process_fft(struct ath_spec_scan_priv *spec_priv,
198*4882a593Smuzhiyun struct ieee80211_hdr *hdr,
199*4882a593Smuzhiyun struct ath_rx_status *rs, u64 tsf)
200*4882a593Smuzhiyun {
201*4882a593Smuzhiyun return 0;
202*4882a593Smuzhiyun }
203*4882a593Smuzhiyun #endif /* CONFIG_ATH9K_COMMON_SPECTRAL */
204*4882a593Smuzhiyun
205*4882a593Smuzhiyun #endif /* SPECTRAL_H */
206