common-spectral.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. #include "../spectral_common.h"
  19. /* enum spectral_mode:
  20. *
  21. * @SPECTRAL_DISABLED: spectral mode is disabled
  22. * @SPECTRAL_BACKGROUND: hardware sends samples when it is not busy with
  23. * something else.
  24. * @SPECTRAL_MANUAL: spectral scan is enabled, triggering for samples
  25. * is performed manually.
  26. * @SPECTRAL_CHANSCAN: Like manual, but also triggered when changing channels
  27. * during a channel scan.
  28. */
  29. enum spectral_mode {
  30. SPECTRAL_DISABLED = 0,
  31. SPECTRAL_BACKGROUND,
  32. SPECTRAL_MANUAL,
  33. SPECTRAL_CHANSCAN,
  34. };
  35. #define SPECTRAL_SCAN_BITMASK 0x10
  36. /* Radar info packet format, used for DFS and spectral formats. */
  37. struct ath_radar_info {
  38. u8 pulse_length_pri;
  39. u8 pulse_length_ext;
  40. u8 pulse_bw_info;
  41. } __packed;
  42. /* The HT20 spectral data has 4 bytes of additional information at it's end.
  43. *
  44. * [7:0]: all bins {max_magnitude[1:0], bitmap_weight[5:0]}
  45. * [7:0]: all bins max_magnitude[9:2]
  46. * [7:0]: all bins {max_index[5:0], max_magnitude[11:10]}
  47. * [3:0]: max_exp (shift amount to size max bin to 8-bit unsigned)
  48. */
  49. struct ath_ht20_mag_info {
  50. u8 all_bins[3];
  51. u8 max_exp;
  52. } __packed;
  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. #define SPECTRAL_HT20_SAMPLE_LEN (sizeof(struct ath_ht20_mag_info) +\
  63. SPECTRAL_HT20_NUM_BINS)
  64. /* Dynamic 20/40 mode:
  65. *
  66. * [7:0]: lower bins {max_magnitude[1:0], bitmap_weight[5:0]}
  67. * [7:0]: lower bins max_magnitude[9:2]
  68. * [7:0]: lower bins {max_index[5:0], max_magnitude[11:10]}
  69. * [7:0]: upper bins {max_magnitude[1:0], bitmap_weight[5:0]}
  70. * [7:0]: upper bins max_magnitude[9:2]
  71. * [7:0]: upper bins {max_index[5:0], max_magnitude[11:10]}
  72. * [3:0]: max_exp (shift amount to size max bin to 8-bit unsigned)
  73. */
  74. struct ath_ht20_40_mag_info {
  75. u8 lower_bins[3];
  76. u8 upper_bins[3];
  77. u8 max_exp;
  78. } __packed;
  79. /* WARNING: don't actually use this struct! MAC may vary the amount of
  80. * data. This struct is for reference only.
  81. */
  82. struct ath_ht20_40_fft_packet {
  83. u8 data[SPECTRAL_HT20_40_NUM_BINS];
  84. struct ath_ht20_40_mag_info mag_info;
  85. struct ath_radar_info radar_info;
  86. } __packed;
  87. struct ath_spec_scan_priv {
  88. struct ath_hw *ah;
  89. /* relay(fs) channel for spectral scan */
  90. struct rchan *rfs_chan_spec_scan;
  91. enum spectral_mode spectral_mode;
  92. struct ath_spec_scan spec_config;
  93. };
  94. #define SPECTRAL_HT20_40_TOTAL_DATA_LEN (sizeof(struct ath_ht20_40_fft_packet))
  95. #define SPECTRAL_HT20_40_SAMPLE_LEN (sizeof(struct ath_ht20_40_mag_info) +\
  96. SPECTRAL_HT20_40_NUM_BINS)
  97. #define SPECTRAL_SAMPLE_MAX_LEN SPECTRAL_HT20_40_SAMPLE_LEN
  98. /* grabs the max magnitude from the all/upper/lower bins */
  99. static inline u16 spectral_max_magnitude(u8 *bins)
  100. {
  101. return (bins[0] & 0xc0) >> 6 |
  102. (bins[1] & 0xff) << 2 |
  103. (bins[2] & 0x03) << 10;
  104. }
  105. /* return the max magnitude from the all/upper/lower bins */
  106. static inline u8 spectral_max_index(u8 *bins, int num_bins)
  107. {
  108. s8 m = (bins[2] & 0xfc) >> 2;
  109. u8 zero_idx = num_bins / 2;
  110. /* It's a 5 bit signed int, remove its sign and use one's
  111. * complement interpretation to add the sign back to the 8
  112. * bit int
  113. */
  114. if (m & 0x20) {
  115. m &= ~0x20;
  116. m |= 0xe0;
  117. }
  118. /* Bring the zero point to the beginning
  119. * instead of the middle so that we can use
  120. * it for array lookup and that we don't deal
  121. * with negative values later
  122. */
  123. m += zero_idx;
  124. /* Sanity check to make sure index is within bounds */
  125. if (m < 0 || m > num_bins - 1)
  126. m = 0;
  127. return m;
  128. }
  129. /* return the bitmap weight from the all/upper/lower bins */
  130. static inline u8 spectral_bitmap_weight(u8 *bins)
  131. {
  132. return bins[0] & 0x3f;
  133. }
  134. void ath9k_cmn_spectral_init_debug(struct ath_spec_scan_priv *spec_priv, struct dentry *debugfs_phy);
  135. void ath9k_cmn_spectral_deinit_debug(struct ath_spec_scan_priv *spec_priv);
  136. void ath9k_cmn_spectral_scan_trigger(struct ath_common *common,
  137. struct ath_spec_scan_priv *spec_priv);
  138. int ath9k_cmn_spectral_scan_config(struct ath_common *common,
  139. struct ath_spec_scan_priv *spec_priv,
  140. enum spectral_mode spectral_mode);
  141. int ath_cmn_process_fft(struct ath_spec_scan_priv *spec_priv, struct ieee80211_hdr *hdr,
  142. struct ath_rx_status *rs, u64 tsf);
  143. #endif /* SPECTRAL_H */