Staging: unisys: Remove RETINT macro
[linux/fpc-iii.git] / drivers / net / wireless / ath / ath9k / spectral.h
blobead63412ee1ae9b6137f14b2299d3bbc243340d6
1 /*
2 * Copyright (c) 2013 Qualcomm Atheros, Inc.
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.
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.
17 #ifndef SPECTRAL_H
18 #define SPECTRAL_H
20 /* enum spectral_mode:
22 * @SPECTRAL_DISABLED: spectral mode is disabled
23 * @SPECTRAL_BACKGROUND: hardware sends samples when it is not busy with
24 * something else.
25 * @SPECTRAL_MANUAL: spectral scan is enabled, triggering for samples
26 * is performed manually.
27 * @SPECTRAL_CHANSCAN: Like manual, but also triggered when changing channels
28 * during a channel scan.
30 enum spectral_mode {
31 SPECTRAL_DISABLED = 0,
32 SPECTRAL_BACKGROUND,
33 SPECTRAL_MANUAL,
34 SPECTRAL_CHANSCAN,
37 #define SPECTRAL_SCAN_BITMASK 0x10
38 /* Radar info packet format, used for DFS and spectral formats. */
39 struct ath_radar_info {
40 u8 pulse_length_pri;
41 u8 pulse_length_ext;
42 u8 pulse_bw_info;
43 } __packed;
45 /* The HT20 spectral data has 4 bytes of additional information at it's end.
47 * [7:0]: all bins {max_magnitude[1:0], bitmap_weight[5:0]}
48 * [7:0]: all bins max_magnitude[9:2]
49 * [7:0]: all bins {max_index[5:0], max_magnitude[11:10]}
50 * [3:0]: max_exp (shift amount to size max bin to 8-bit unsigned)
52 struct ath_ht20_mag_info {
53 u8 all_bins[3];
54 u8 max_exp;
55 } __packed;
57 #define SPECTRAL_HT20_NUM_BINS 56
59 /* WARNING: don't actually use this struct! MAC may vary the amount of
60 * data by -1/+2. This struct is for reference only.
62 struct ath_ht20_fft_packet {
63 u8 data[SPECTRAL_HT20_NUM_BINS];
64 struct ath_ht20_mag_info mag_info;
65 struct ath_radar_info radar_info;
66 } __packed;
68 #define SPECTRAL_HT20_TOTAL_DATA_LEN (sizeof(struct ath_ht20_fft_packet))
70 /* Dynamic 20/40 mode:
72 * [7:0]: lower bins {max_magnitude[1:0], bitmap_weight[5:0]}
73 * [7:0]: lower bins max_magnitude[9:2]
74 * [7:0]: lower bins {max_index[5:0], max_magnitude[11:10]}
75 * [7:0]: upper bins {max_magnitude[1:0], bitmap_weight[5:0]}
76 * [7:0]: upper bins max_magnitude[9:2]
77 * [7:0]: upper bins {max_index[5:0], max_magnitude[11:10]}
78 * [3:0]: max_exp (shift amount to size max bin to 8-bit unsigned)
80 struct ath_ht20_40_mag_info {
81 u8 lower_bins[3];
82 u8 upper_bins[3];
83 u8 max_exp;
84 } __packed;
86 #define SPECTRAL_HT20_40_NUM_BINS 128
88 /* WARNING: don't actually use this struct! MAC may vary the amount of
89 * data. This struct is for reference only.
91 struct ath_ht20_40_fft_packet {
92 u8 data[SPECTRAL_HT20_40_NUM_BINS];
93 struct ath_ht20_40_mag_info mag_info;
94 struct ath_radar_info radar_info;
95 } __packed;
98 #define SPECTRAL_HT20_40_TOTAL_DATA_LEN (sizeof(struct ath_ht20_40_fft_packet))
100 /* grabs the max magnitude from the all/upper/lower bins */
101 static inline u16 spectral_max_magnitude(u8 *bins)
103 return (bins[0] & 0xc0) >> 6 |
104 (bins[1] & 0xff) << 2 |
105 (bins[2] & 0x03) << 10;
108 /* return the max magnitude from the all/upper/lower bins */
109 static inline u8 spectral_max_index(u8 *bins)
111 s8 m = (bins[2] & 0xfc) >> 2;
113 /* TODO: this still doesn't always report the right values ... */
114 if (m > 32)
115 m |= 0xe0;
116 else
117 m &= ~0xe0;
119 return m + 29;
122 /* return the bitmap weight from the all/upper/lower bins */
123 static inline u8 spectral_bitmap_weight(u8 *bins)
125 return bins[0] & 0x3f;
128 /* FFT sample format given to userspace via debugfs.
130 * Please keep the type/length at the front position and change
131 * other fields after adding another sample type
133 * TODO: this might need rework when switching to nl80211-based
134 * interface.
136 enum ath_fft_sample_type {
137 ATH_FFT_SAMPLE_HT20 = 1,
138 ATH_FFT_SAMPLE_HT20_40,
141 struct fft_sample_tlv {
142 u8 type; /* see ath_fft_sample */
143 __be16 length;
144 /* type dependent data follows */
145 } __packed;
147 struct fft_sample_ht20 {
148 struct fft_sample_tlv tlv;
150 u8 max_exp;
152 __be16 freq;
153 s8 rssi;
154 s8 noise;
156 __be16 max_magnitude;
157 u8 max_index;
158 u8 bitmap_weight;
160 __be64 tsf;
162 u8 data[SPECTRAL_HT20_NUM_BINS];
163 } __packed;
165 struct fft_sample_ht20_40 {
166 struct fft_sample_tlv tlv;
168 u8 channel_type;
169 __be16 freq;
171 s8 lower_rssi;
172 s8 upper_rssi;
174 __be64 tsf;
176 s8 lower_noise;
177 s8 upper_noise;
179 __be16 lower_max_magnitude;
180 __be16 upper_max_magnitude;
182 u8 lower_max_index;
183 u8 upper_max_index;
185 u8 lower_bitmap_weight;
186 u8 upper_bitmap_weight;
188 u8 max_exp;
190 u8 data[SPECTRAL_HT20_40_NUM_BINS];
191 } __packed;
193 void ath9k_spectral_init_debug(struct ath_softc *sc);
194 void ath9k_spectral_deinit_debug(struct ath_softc *sc);
196 void ath9k_spectral_scan_trigger(struct ieee80211_hw *hw);
197 int ath9k_spectral_scan_config(struct ieee80211_hw *hw,
198 enum spectral_mode spectral_mode);
200 #ifdef CONFIG_ATH9K_DEBUGFS
201 int ath_process_fft(struct ath_softc *sc, struct ieee80211_hdr *hdr,
202 struct ath_rx_status *rs, u64 tsf);
203 #else
204 static inline int ath_process_fft(struct ath_softc *sc,
205 struct ieee80211_hdr *hdr,
206 struct ath_rx_status *rs, u64 tsf)
208 return 0;
210 #endif /* CONFIG_ATH9K_DEBUGFS */
212 #endif /* SPECTRAL_H */