spectral.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. #ifndef SPECTRAL_H
  17. #define SPECTRAL_H
  18. /* enum spectral_mode:
  19. *
  20. * @SPECTRAL_DISABLED: spectral mode is disabled
  21. * @SPECTRAL_BACKGROUND: hardware sends samples when it is not busy with
  22. * something else.
  23. * @SPECTRAL_MANUAL: spectral scan is enabled, triggering for samples
  24. * is performed manually.
  25. * @SPECTRAL_CHANSCAN: Like manual, but also triggered when changing channels
  26. * during a channel scan.
  27. */
  28. enum spectral_mode {
  29. SPECTRAL_DISABLED = 0,
  30. SPECTRAL_BACKGROUND,
  31. SPECTRAL_MANUAL,
  32. SPECTRAL_CHANSCAN,
  33. };
  34. #define SPECTRAL_SCAN_BITMASK 0x10
  35. /* Radar info packet format, used for DFS and spectral formats. */
  36. struct ath_radar_info {
  37. u8 pulse_length_pri;
  38. u8 pulse_length_ext;
  39. u8 pulse_bw_info;
  40. } __packed;
  41. /* The HT20 spectral data has 4 bytes of additional information at it's end.
  42. *
  43. * [7:0]: all bins {max_magnitude[1:0], bitmap_weight[5:0]}
  44. * [7:0]: all bins max_magnitude[9:2]
  45. * [7:0]: all bins {max_index[5:0], max_magnitude[11:10]}
  46. * [3:0]: max_exp (shift amount to size max bin to 8-bit unsigned)
  47. */
  48. struct ath_ht20_mag_info {
  49. u8 all_bins[3];
  50. u8 max_exp;
  51. } __packed;
  52. #define SPECTRAL_HT20_NUM_BINS 56
  53. /* WARNING: don't actually use this struct! MAC may vary the amount of
  54. * data by -1/+2. This struct is for reference only.
  55. */
  56. struct ath_ht20_fft_packet {
  57. u8 data[SPECTRAL_HT20_NUM_BINS];
  58. struct ath_ht20_mag_info mag_info;
  59. struct ath_radar_info radar_info;
  60. } __packed;
  61. #define SPECTRAL_HT20_TOTAL_DATA_LEN (sizeof(struct ath_ht20_fft_packet))
  62. /* Dynamic 20/40 mode:
  63. *
  64. * [7:0]: lower bins {max_magnitude[1:0], bitmap_weight[5:0]}
  65. * [7:0]: lower bins max_magnitude[9:2]
  66. * [7:0]: lower bins {max_index[5:0], max_magnitude[11:10]}
  67. * [7:0]: upper bins {max_magnitude[1:0], bitmap_weight[5:0]}
  68. * [7:0]: upper bins max_magnitude[9:2]
  69. * [7:0]: upper bins {max_index[5:0], max_magnitude[11:10]}
  70. * [3:0]: max_exp (shift amount to size max bin to 8-bit unsigned)
  71. */
  72. struct ath_ht20_40_mag_info {
  73. u8 lower_bins[3];
  74. u8 upper_bins[3];
  75. u8 max_exp;
  76. } __packed;
  77. #define SPECTRAL_HT20_40_NUM_BINS 128
  78. /* WARNING: don't actually use this struct! MAC may vary the amount of
  79. * data. This struct is for reference only.
  80. */
  81. struct ath_ht20_40_fft_packet {
  82. u8 data[SPECTRAL_HT20_40_NUM_BINS];
  83. struct ath_ht20_40_mag_info mag_info;
  84. struct ath_radar_info radar_info;
  85. } __packed;
  86. #define SPECTRAL_HT20_40_TOTAL_DATA_LEN (sizeof(struct ath_ht20_40_fft_packet))
  87. /* grabs the max magnitude from the all/upper/lower bins */
  88. static inline u16 spectral_max_magnitude(u8 *bins)
  89. {
  90. return (bins[0] & 0xc0) >> 6 |
  91. (bins[1] & 0xff) << 2 |
  92. (bins[2] & 0x03) << 10;
  93. }
  94. /* return the max magnitude from the all/upper/lower bins */
  95. static inline u8 spectral_max_index(u8 *bins)
  96. {
  97. s8 m = (bins[2] & 0xfc) >> 2;
  98. /* TODO: this still doesn't always report the right values ... */
  99. if (m > 32)
  100. m |= 0xe0;
  101. else
  102. m &= ~0xe0;
  103. return m + 29;
  104. }
  105. /* return the bitmap weight from the all/upper/lower bins */
  106. static inline u8 spectral_bitmap_weight(u8 *bins)
  107. {
  108. return bins[0] & 0x3f;
  109. }
  110. /* FFT sample format given to userspace via debugfs.
  111. *
  112. * Please keep the type/length at the front position and change
  113. * other fields after adding another sample type
  114. *
  115. * TODO: this might need rework when switching to nl80211-based
  116. * interface.
  117. */
  118. enum ath_fft_sample_type {
  119. ATH_FFT_SAMPLE_HT20 = 1,
  120. ATH_FFT_SAMPLE_HT20_40,
  121. };
  122. struct fft_sample_tlv {
  123. u8 type; /* see ath_fft_sample */
  124. __be16 length;
  125. /* type dependent data follows */
  126. } __packed;
  127. struct fft_sample_ht20 {
  128. struct fft_sample_tlv tlv;
  129. u8 max_exp;
  130. __be16 freq;
  131. s8 rssi;
  132. s8 noise;
  133. __be16 max_magnitude;
  134. u8 max_index;
  135. u8 bitmap_weight;
  136. __be64 tsf;
  137. u8 data[SPECTRAL_HT20_NUM_BINS];
  138. } __packed;
  139. struct fft_sample_ht20_40 {
  140. struct fft_sample_tlv tlv;
  141. u8 channel_type;
  142. __be16 freq;
  143. s8 lower_rssi;
  144. s8 upper_rssi;
  145. __be64 tsf;
  146. s8 lower_noise;
  147. s8 upper_noise;
  148. __be16 lower_max_magnitude;
  149. __be16 upper_max_magnitude;
  150. u8 lower_max_index;
  151. u8 upper_max_index;
  152. u8 lower_bitmap_weight;
  153. u8 upper_bitmap_weight;
  154. u8 max_exp;
  155. u8 data[SPECTRAL_HT20_40_NUM_BINS];
  156. } __packed;
  157. void ath9k_spectral_init_debug(struct ath_softc *sc);
  158. void ath9k_spectral_deinit_debug(struct ath_softc *sc);
  159. void ath9k_spectral_scan_trigger(struct ieee80211_hw *hw);
  160. int ath9k_spectral_scan_config(struct ieee80211_hw *hw,
  161. enum spectral_mode spectral_mode);
  162. #ifdef CONFIG_ATH9K_DEBUGFS
  163. int ath_process_fft(struct ath_softc *sc, struct ieee80211_hdr *hdr,
  164. struct ath_rx_status *rs, u64 tsf);
  165. #else
  166. static inline int ath_process_fft(struct ath_softc *sc,
  167. struct ieee80211_hdr *hdr,
  168. struct ath_rx_status *rs, u64 tsf)
  169. {
  170. return 0;
  171. }
  172. #endif /* CONFIG_ATH9K_DEBUGFS */
  173. #endif /* SPECTRAL_H */