Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 1 | /* |
| 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 Eckelmann | 95752b7 | 2014-08-02 09:12:53 +0300 | [diff] [blame] | 20 | #include "../spectral_common.h" |
| 21 | |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 22 | /* 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 | */ |
| 32 | enum 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. */ |
| 41 | struct 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 | */ |
| 54 | struct ath_ht20_mag_info { |
| 55 | u8 all_bins[3]; |
| 56 | u8 max_exp; |
| 57 | } __packed; |
| 58 | |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 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. |
| 61 | */ |
| 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; |
| 67 | |
| 68 | #define SPECTRAL_HT20_TOTAL_DATA_LEN (sizeof(struct ath_ht20_fft_packet)) |
Nick Kossifidis | 58b5e4c | 2015-04-29 23:51:14 +0000 | [diff] [blame] | 69 | #define SPECTRAL_HT20_SAMPLE_LEN (sizeof(struct ath_ht20_mag_info) +\ |
| 70 | SPECTRAL_HT20_NUM_BINS) |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 71 | |
| 72 | /* Dynamic 20/40 mode: |
| 73 | * |
| 74 | * [7:0]: lower bins {max_magnitude[1:0], bitmap_weight[5:0]} |
| 75 | * [7:0]: lower bins max_magnitude[9:2] |
| 76 | * [7:0]: lower bins {max_index[5:0], max_magnitude[11:10]} |
| 77 | * [7:0]: upper bins {max_magnitude[1:0], bitmap_weight[5:0]} |
| 78 | * [7:0]: upper bins max_magnitude[9:2] |
| 79 | * [7:0]: upper bins {max_index[5:0], max_magnitude[11:10]} |
| 80 | * [3:0]: max_exp (shift amount to size max bin to 8-bit unsigned) |
| 81 | */ |
| 82 | struct ath_ht20_40_mag_info { |
| 83 | u8 lower_bins[3]; |
| 84 | u8 upper_bins[3]; |
| 85 | u8 max_exp; |
| 86 | } __packed; |
| 87 | |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 88 | /* WARNING: don't actually use this struct! MAC may vary the amount of |
| 89 | * data. This struct is for reference only. |
| 90 | */ |
| 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; |
| 96 | |
Oleksij Rempel | 911ea79 | 2014-11-06 08:53:18 +0100 | [diff] [blame] | 97 | struct ath_spec_scan_priv { |
Oleksij Rempel | dd7657b | 2014-11-06 08:53:22 +0100 | [diff] [blame] | 98 | struct ath_hw *ah; |
Oleksij Rempel | 21af25d | 2014-11-06 08:53:20 +0100 | [diff] [blame] | 99 | /* relay(fs) channel for spectral scan */ |
Oleksij Rempel | 911ea79 | 2014-11-06 08:53:18 +0100 | [diff] [blame] | 100 | struct rchan *rfs_chan_spec_scan; |
Oleksij Rempel | 8391f60 | 2014-11-06 08:53:19 +0100 | [diff] [blame] | 101 | enum spectral_mode spectral_mode; |
Oleksij Rempel | 21af25d | 2014-11-06 08:53:20 +0100 | [diff] [blame] | 102 | struct ath_spec_scan spec_config; |
Oleksij Rempel | 911ea79 | 2014-11-06 08:53:18 +0100 | [diff] [blame] | 103 | }; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 104 | |
| 105 | #define SPECTRAL_HT20_40_TOTAL_DATA_LEN (sizeof(struct ath_ht20_40_fft_packet)) |
Nick Kossifidis | 58b5e4c | 2015-04-29 23:51:14 +0000 | [diff] [blame] | 106 | #define SPECTRAL_HT20_40_SAMPLE_LEN (sizeof(struct ath_ht20_40_mag_info) +\ |
| 107 | SPECTRAL_HT20_40_NUM_BINS) |
| 108 | |
| 109 | #define SPECTRAL_SAMPLE_MAX_LEN SPECTRAL_HT20_40_SAMPLE_LEN |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 110 | |
| 111 | /* grabs the max magnitude from the all/upper/lower bins */ |
| 112 | static inline u16 spectral_max_magnitude(u8 *bins) |
| 113 | { |
| 114 | return (bins[0] & 0xc0) >> 6 | |
| 115 | (bins[1] & 0xff) << 2 | |
| 116 | (bins[2] & 0x03) << 10; |
| 117 | } |
| 118 | |
| 119 | /* return the max magnitude from the all/upper/lower bins */ |
Nick Kossifidis | e33f855 | 2015-04-29 23:51:13 +0000 | [diff] [blame] | 120 | static inline u8 spectral_max_index(u8 *bins, int num_bins) |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 121 | { |
| 122 | s8 m = (bins[2] & 0xfc) >> 2; |
Nick Kossifidis | e33f855 | 2015-04-29 23:51:13 +0000 | [diff] [blame] | 123 | u8 zero_idx = num_bins / 2; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 124 | |
Nick Kossifidis | e33f855 | 2015-04-29 23:51:13 +0000 | [diff] [blame] | 125 | /* It's a 5 bit signed int, remove its sign and use one's |
| 126 | * complement interpretation to add the sign back to the 8 |
| 127 | * bit int |
| 128 | */ |
| 129 | if (m & 0x20) { |
| 130 | m &= ~0x20; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 131 | m |= 0xe0; |
Nick Kossifidis | e33f855 | 2015-04-29 23:51:13 +0000 | [diff] [blame] | 132 | } |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 133 | |
Nick Kossifidis | e33f855 | 2015-04-29 23:51:13 +0000 | [diff] [blame] | 134 | /* Bring the zero point to the beginning |
| 135 | * instead of the middle so that we can use |
| 136 | * it for array lookup and that we don't deal |
| 137 | * with negative values later |
| 138 | */ |
| 139 | m += zero_idx; |
| 140 | |
| 141 | /* Sanity check to make sure index is within bounds */ |
| 142 | if (m < 0 || m > num_bins - 1) |
| 143 | m = 0; |
| 144 | |
| 145 | return m; |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | /* return the bitmap weight from the all/upper/lower bins */ |
| 149 | static inline u8 spectral_bitmap_weight(u8 *bins) |
| 150 | { |
| 151 | return bins[0] & 0x3f; |
| 152 | } |
| 153 | |
Matthias Schiffer | 9df7ddc | 2017-11-27 18:56:22 +0100 | [diff] [blame] | 154 | #ifdef CONFIG_ATH9K_COMMON_SPECTRAL |
Oleksij Rempel | 67dc74f | 2014-11-06 08:53:30 +0100 | [diff] [blame] | 155 | void ath9k_cmn_spectral_init_debug(struct ath_spec_scan_priv *spec_priv, struct dentry *debugfs_phy); |
| 156 | void ath9k_cmn_spectral_deinit_debug(struct ath_spec_scan_priv *spec_priv); |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 157 | |
Oleksij Rempel | 67dc74f | 2014-11-06 08:53:30 +0100 | [diff] [blame] | 158 | void ath9k_cmn_spectral_scan_trigger(struct ath_common *common, |
Oleksij Rempel | 963916d | 2014-11-06 08:53:28 +0100 | [diff] [blame] | 159 | struct ath_spec_scan_priv *spec_priv); |
Oleksij Rempel | 67dc74f | 2014-11-06 08:53:30 +0100 | [diff] [blame] | 160 | int ath9k_cmn_spectral_scan_config(struct ath_common *common, |
Oleksij Rempel | 963916d | 2014-11-06 08:53:28 +0100 | [diff] [blame] | 161 | struct ath_spec_scan_priv *spec_priv, |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 162 | enum spectral_mode spectral_mode); |
Oleksij Rempel | 67dc74f | 2014-11-06 08:53:30 +0100 | [diff] [blame] | 163 | int ath_cmn_process_fft(struct ath_spec_scan_priv *spec_priv, struct ieee80211_hdr *hdr, |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 164 | struct ath_rx_status *rs, u64 tsf); |
Christian Lamparter | 1077ec4 | 2017-01-12 13:02:23 +0200 | [diff] [blame] | 165 | #else |
| 166 | static inline void ath9k_cmn_spectral_init_debug(struct ath_spec_scan_priv *spec_priv, |
| 167 | struct dentry *debugfs_phy) |
| 168 | { |
| 169 | } |
| 170 | |
| 171 | static inline void ath9k_cmn_spectral_deinit_debug(struct ath_spec_scan_priv *spec_priv) |
| 172 | { |
| 173 | } |
| 174 | |
| 175 | static inline void ath9k_cmn_spectral_scan_trigger(struct ath_common *common, |
| 176 | struct ath_spec_scan_priv *spec_priv) |
| 177 | { |
| 178 | } |
| 179 | |
| 180 | static inline int ath_cmn_process_fft(struct ath_spec_scan_priv *spec_priv, |
| 181 | struct ieee80211_hdr *hdr, |
| 182 | struct ath_rx_status *rs, u64 tsf) |
| 183 | { |
| 184 | return 0; |
| 185 | } |
Matthias Schiffer | 9df7ddc | 2017-11-27 18:56:22 +0100 | [diff] [blame] | 186 | #endif /* CONFIG_ATH9K_COMMON_SPECTRAL */ |
Sujith Manoharan | f65c082 | 2013-12-18 09:53:18 +0530 | [diff] [blame] | 187 | |
| 188 | #endif /* SPECTRAL_H */ |