blob: 0acdc432c77116b27a8079f26209056f97ef0f58 [file] [log] [blame]
Sujith Manoharanf65c0822013-12-18 09:53:18 +05301/*
2 * Copyright (c) 2013 Qualcomm Atheros, 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#ifndef SPECTRAL_H
18#define SPECTRAL_H
19
Sven Eckelmann95752b72014-08-02 09:12:53 +030020#include "../spectral_common.h"
21
Sujith Manoharanf65c0822013-12-18 09:53:18 +053022/* enum spectral_mode:
23 *
24 * @SPECTRAL_DISABLED: spectral mode is disabled
25 * @SPECTRAL_BACKGROUND: hardware sends samples when it is not busy with
26 * something else.
27 * @SPECTRAL_MANUAL: spectral scan is enabled, triggering for samples
28 * is performed manually.
29 * @SPECTRAL_CHANSCAN: Like manual, but also triggered when changing channels
30 * during a channel scan.
31 */
32enum spectral_mode {
33 SPECTRAL_DISABLED = 0,
34 SPECTRAL_BACKGROUND,
35 SPECTRAL_MANUAL,
36 SPECTRAL_CHANSCAN,
37};
38
39#define SPECTRAL_SCAN_BITMASK 0x10
40/* Radar info packet format, used for DFS and spectral formats. */
41struct ath_radar_info {
42 u8 pulse_length_pri;
43 u8 pulse_length_ext;
44 u8 pulse_bw_info;
45} __packed;
46
47/* The HT20 spectral data has 4 bytes of additional information at it's end.
48 *
49 * [7:0]: all bins {max_magnitude[1:0], bitmap_weight[5:0]}
50 * [7:0]: all bins max_magnitude[9:2]
51 * [7:0]: all bins {max_index[5:0], max_magnitude[11:10]}
52 * [3:0]: max_exp (shift amount to size max bin to 8-bit unsigned)
53 */
54struct ath_ht20_mag_info {
55 u8 all_bins[3];
56 u8 max_exp;
57} __packed;
58
Sujith Manoharanf65c0822013-12-18 09:53:18 +053059/* WARNING: don't actually use this struct! MAC may vary the amount of
60 * data by -1/+2. This struct is for reference only.
61 */
62struct 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;
67
68#define SPECTRAL_HT20_TOTAL_DATA_LEN (sizeof(struct ath_ht20_fft_packet))
69
70/* Dynamic 20/40 mode:
71 *
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)
79 */
80struct ath_ht20_40_mag_info {
81 u8 lower_bins[3];
82 u8 upper_bins[3];
83 u8 max_exp;
84} __packed;
85
Sujith Manoharanf65c0822013-12-18 09:53:18 +053086/* WARNING: don't actually use this struct! MAC may vary the amount of
87 * data. This struct is for reference only.
88 */
89struct ath_ht20_40_fft_packet {
90 u8 data[SPECTRAL_HT20_40_NUM_BINS];
91 struct ath_ht20_40_mag_info mag_info;
92 struct ath_radar_info radar_info;
93} __packed;
94
Oleksij Rempel911ea792014-11-06 08:53:18 +010095struct ath_spec_scan_priv {
96 struct rchan *rfs_chan_spec_scan;
Oleksij Rempel8391f602014-11-06 08:53:19 +010097 enum spectral_mode spectral_mode;
Oleksij Rempel911ea792014-11-06 08:53:18 +010098};
Sujith Manoharanf65c0822013-12-18 09:53:18 +053099
100#define SPECTRAL_HT20_40_TOTAL_DATA_LEN (sizeof(struct ath_ht20_40_fft_packet))
101
102/* grabs the max magnitude from the all/upper/lower bins */
103static inline u16 spectral_max_magnitude(u8 *bins)
104{
105 return (bins[0] & 0xc0) >> 6 |
106 (bins[1] & 0xff) << 2 |
107 (bins[2] & 0x03) << 10;
108}
109
110/* return the max magnitude from the all/upper/lower bins */
111static inline u8 spectral_max_index(u8 *bins)
112{
113 s8 m = (bins[2] & 0xfc) >> 2;
114
115 /* TODO: this still doesn't always report the right values ... */
116 if (m > 32)
117 m |= 0xe0;
118 else
119 m &= ~0xe0;
120
121 return m + 29;
122}
123
124/* return the bitmap weight from the all/upper/lower bins */
125static inline u8 spectral_bitmap_weight(u8 *bins)
126{
127 return bins[0] & 0x3f;
128}
129
Sujith Manoharanf65c0822013-12-18 09:53:18 +0530130void ath9k_spectral_init_debug(struct ath_softc *sc);
131void ath9k_spectral_deinit_debug(struct ath_softc *sc);
132
133void ath9k_spectral_scan_trigger(struct ieee80211_hw *hw);
134int ath9k_spectral_scan_config(struct ieee80211_hw *hw,
135 enum spectral_mode spectral_mode);
136
137#ifdef CONFIG_ATH9K_DEBUGFS
138int ath_process_fft(struct ath_softc *sc, struct ieee80211_hdr *hdr,
139 struct ath_rx_status *rs, u64 tsf);
140#else
141static inline int ath_process_fft(struct ath_softc *sc,
142 struct ieee80211_hdr *hdr,
143 struct ath_rx_status *rs, u64 tsf)
144{
145 return 0;
146}
147#endif /* CONFIG_ATH9K_DEBUGFS */
148
149#endif /* SPECTRAL_H */