target_if_spectral.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982
  1. /*
  2. * Copyright (c) 2011,2017 The Linux Foundation. All rights reserved.
  3. *
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #ifndef _TARGET_IF_SPECTRAL_H_
  20. #define _TARGET_IF_SPECTRAL_H_
  21. #include <wlan_objmgr_cmn.h>
  22. #include <wlan_objmgr_psoc_obj.h>
  23. #include <wlan_objmgr_pdev_obj.h>
  24. #include <qdf_lock.h>
  25. #include <wlan_spectral_public_structs.h>
  26. #include <reg_services_public_struct.h>
  27. extern int spectral_debug_level;
  28. #ifdef WIN32
  29. #pragma pack(push, target_if_spectral, 1)
  30. #define __ATTRIB_PACK
  31. #else
  32. #ifndef __ATTRIB_PACK
  33. #define __ATTRIB_PACK __attribute__ ((packed))
  34. #endif
  35. #endif
  36. #define spectral_log(level, args...) \
  37. QDF_PRINT_INFO(QDF_PRINT_IDX_SHARED, QDF_MODULE_ID_SPECTRAL, level, ## args)
  38. #define spectral_logfl(level, format, args...) \
  39. spectral_log(level, FL(format), ## args)
  40. #define spectral_fatal(format, args...) \
  41. spectral_logfl(QDF_TRACE_LEVEL_FATAL, format, ## args)
  42. #define spectral_err(format, args...) \
  43. spectral_logfl(QDF_TRACE_LEVEL_ERROR, format, ## args)
  44. #define spectral_warn(format, args...) \
  45. spectral_logfl(QDF_TRACE_LEVEL_WARN, format, ## args)
  46. #define spectral_info(format, args...) \
  47. spectral_logfl(QDF_TRACE_LEVEL_INFO, format, ## args)
  48. #define spectral_debug(format, args...) \
  49. spectral_logfl(QDF_TRACE_LEVEL_DEBUG, format, ## args)
  50. #define STATUS_PASS 1
  51. #define STATUS_FAIL 0
  52. #define line() \
  53. qdf_print("----------------------------------------------------\n")
  54. #define SPECTRAL_TODO(str) \
  55. qdf_print(KERN_INFO "SPECTRAL : %s (%s : %d)\n", \
  56. (str), __func__, __LINE__)
  57. #define spectral_ops_not_registered(str) \
  58. qdf_print(KERN_INFO "SPECTRAL : %s not registered\n", (str))
  59. #define not_yet_implemented() \
  60. qdf_print("SPECTRAL : %s : %d Not yet implemented\n", \
  61. __func__, __LINE__)
  62. #define SPECTRAL_HT20_NUM_BINS 56
  63. #define SPECTRAL_HT20_FFT_LEN 56
  64. #define SPECTRAL_HT20_DC_INDEX (SPECTRAL_HT20_FFT_LEN / 2)
  65. #define SPECTRAL_HT20_DATA_LEN 60
  66. #define SPECTRAL_HT20_TOTAL_DATA_LEN (SPECTRAL_HT20_DATA_LEN + 3)
  67. #define SPECTRAL_HT40_TOTAL_NUM_BINS 128
  68. #define SPECTRAL_HT40_DATA_LEN 135
  69. #define SPECTRAL_HT40_TOTAL_DATA_LEN (SPECTRAL_HT40_DATA_LEN + 3)
  70. #define SPECTRAL_HT40_FFT_LEN 128
  71. #define SPECTRAL_HT40_DC_INDEX (SPECTRAL_HT40_FFT_LEN / 2)
  72. /* Used for the SWAR to obtain approximate combined rssi
  73. * in secondary 80Mhz segment
  74. */
  75. #define OFFSET_CH_WIDTH_20 65
  76. #define OFFSET_CH_WIDTH_40 62
  77. #define OFFSET_CH_WIDTH_80 56
  78. #define OFFSET_CH_WIDTH_160 50
  79. #ifdef BIG_ENDIAN_HOST
  80. #define SPECTRAL_MSG_COPY_CHAR_ARRAY(destp, srcp, len) do { \
  81. int j; \
  82. u_int32_t *src, *dest; \
  83. src = (u_int32_t *)(srcp); \
  84. dest = (u_int32_t *)(destp); \
  85. for (j = 0; j < roundup((len), sizeof(u_int32_t)) / 4; j++) { \
  86. *(dest + j) = qdf_le32_to_cpu(*(src + j)); \
  87. } \
  88. } while (0)
  89. #else
  90. #define SPECTRAL_MSG_COPY_CHAR_ARRAY(destp, srcp, len) \
  91. OS_MEMCPY((destp), (srcp), (len));
  92. #endif
  93. /* 5 categories x (lower + upper) bands */
  94. #define MAX_INTERF 10
  95. #define ATH_HOST_MAX_ANTENNA 3
  96. /* Mask for time stamp from descriptor */
  97. #define SPECTRAL_TSMASK 0xFFFFFFFF
  98. #define SPECTRAL_SIGNATURE 0xdeadbeef
  99. #define MAX_SPECTRAL_PAYLOAD 1500
  100. #ifndef NETLINK_ATHEROS
  101. #define NETLINK_ATHEROS (NETLINK_GENERIC + 1)
  102. #endif
  103. /* START of spectral GEN II HW specific details */
  104. #define SPECTRAL_PHYERR_SIGNATURE_GEN2 0xbb
  105. #define TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2 0xF9
  106. #define TLV_TAG_ADC_REPORT_GEN2 0xFA
  107. #define TLV_TAG_SEARCH_FFT_REPORT_GEN2 0xFB
  108. /**
  109. * struct spectral_search_fft_info_gen2 - spectral search fft report for gen2
  110. * @relpwr_db: Total bin power in db
  111. * @num_str_bins_ib: Number of strong bins
  112. * @base_pwr: Base power
  113. * @total_gain_info: Total gain
  114. * @fft_chn_idx: FFT chain on which report is originated
  115. * @avgpwr_db: Average power in db
  116. * @peak_mag: Peak power seen in the bins
  117. * @peak_inx: Index of bin holding peak power
  118. */
  119. typedef struct spectral_search_fft_info_gen2 {
  120. uint32_t relpwr_db;
  121. uint32_t num_str_bins_ib;
  122. uint32_t base_pwr;
  123. uint32_t total_gain_info;
  124. uint32_t fft_chn_idx;
  125. uint32_t avgpwr_db;
  126. uint32_t peak_mag;
  127. int16_t peak_inx;
  128. } SPECTRAL_SEARCH_FFT_INFO_GEN2;
  129. /* XXX Check if we should be handling the endinness difference in some
  130. * other way opaque to the host
  131. */
  132. #ifdef BIG_ENDIAN_HOST
  133. /**
  134. * struct spectral_phyerr_tlv_gen2 - phyerr tlv info for big endian host
  135. * @signature: signature
  136. * @tag: tag
  137. * @length: length
  138. */
  139. typedef struct spectral_phyerr_tlv_gen2 {
  140. u_int8_t signature;
  141. u_int8_t tag;
  142. u_int16_t length;
  143. } __ATTRIB_PACK SPECTRAL_PHYERR_TLV_GEN2;
  144. #else
  145. /**
  146. * struct spectral_phyerr_tlv_gen2 - phyerr tlv info for little endian host
  147. * @length: length
  148. * @tag: tag
  149. * @signature: signature
  150. */
  151. typedef struct spectral_phyerr_tlv_gen2 {
  152. u_int16_t length;
  153. u_int8_t tag;
  154. u_int8_t signature;
  155. } __ATTRIB_PACK SPECTRAL_PHYERR_TLV_GEN2;
  156. #endif /* BIG_ENDIAN_HOST */
  157. /**
  158. * struct spectral_phyerr_hdr_gen2 - phyerr header for gen2 HW
  159. * @hdr_a: Header[0:31]
  160. * @hdr_b: Header[32:63]
  161. */
  162. typedef struct spectral_phyerr_hdr_gen2 {
  163. u_int32_t hdr_a;
  164. u_int32_t hdr_b;
  165. } SPECTRAL_PHYERR_HDR_GEN2;
  166. /* Segment ID information for 80+80.
  167. *
  168. * If the HW micro-architecture specification extends this DWORD for other
  169. * purposes, then redefine+rename accordingly. For now, the specification
  170. * mentions only segment ID (though this doesn't require an entire DWORD)
  171. * without mention of any generic terminology for the DWORD, or any reservation.
  172. * We use nomenclature accordingly.
  173. */
  174. typedef u_int32_t SPECTRAL_SEGID_INFO;
  175. /**
  176. * struct spectral_phyerr_fft_gen2 - fft info in phyerr event
  177. * @buf: fft report
  178. */
  179. typedef struct spectral_phyerr_fft_gen2 {
  180. u_int8_t buf[0];
  181. } SPECTRAL_PHYERR_FFT_GEN2;
  182. /* END of spectral GEN II HW specific details */
  183. /* START of spectral GEN III HW specific details */
  184. #define get_bitfield(value, size, pos) \
  185. (((value) >> (pos)) & ((1 << (size)) - 1))
  186. #define unsigned_to_signed(value, width) \
  187. (((value) >= (1 << ((width) - 1))) ? \
  188. (value - (1 << (width))) : (value))
  189. #define SPECTRAL_PHYERR_SIGNATURE_GEN3 (0xFA)
  190. #define TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3 (0x02)
  191. #define TLV_TAG_SEARCH_FFT_REPORT_GEN3 (0x03)
  192. #define SPECTRAL_PHYERR_TLVSIZE_GEN3 (4)
  193. #define PHYERR_HDR_SIG_POS \
  194. (offsetof(struct spectral_phyerr_fft_report_gen3, fft_hdr_sig))
  195. #define PHYERR_HDR_TAG_POS \
  196. (offsetof(struct spectral_phyerr_fft_report_gen3, fft_hdr_tag))
  197. #define SPECTRAL_FFT_BINS_POS \
  198. (offsetof(struct spectral_phyerr_fft_report_gen3, buf))
  199. /**
  200. * struct phyerr_info - spectral search fft report for gen3
  201. * @data: handle to phyerror buffer
  202. * @datalen: length of phyerror bufer
  203. * @p_rfqual: rf quality matrices
  204. * @p_chaninfo: pointer to chaninfo
  205. * @tsf64: 64 bit TSF
  206. * @acs_stats: acs stats
  207. */
  208. struct phyerr_info {
  209. u_int8_t *data;
  210. u_int32_t datalen;
  211. struct target_if_spectral_rfqual_info *p_rfqual;
  212. struct target_if_spectral_chan_info *p_chaninfo;
  213. u_int64_t tsf64;
  214. struct target_if_spectral_acs_stats *acs_stats;
  215. };
  216. /**
  217. * struct spectral_search_fft_info_gen3 - spectral search fft report for gen3
  218. * @timestamp: Timestamp at which fft report was generated
  219. * @fft_detector_id: Which radio generated this report
  220. * @fft_num: The FFT count number. Set to 0 for short FFT.
  221. * @fft_radar_check: NA for spectral
  222. * @fft_peak_sidx: Index of bin with maximum power
  223. * @fft_chn_idx: Rx chain index
  224. * @fft_base_pwr_db: Base power in dB
  225. * @fft_total_gain_db: Total gain in dB
  226. * @fft_num_str_bins_ib: Number of strong bins in the report
  227. * @fft_peak_mag: Peak magnitude
  228. * @fft_avgpwr_db: Average power in dB
  229. * @fft_relpwr_db: Relative power in dB
  230. */
  231. struct spectral_search_fft_info_gen3 {
  232. uint32_t timestamp;
  233. uint32_t fft_detector_id;
  234. uint32_t fft_num;
  235. uint32_t fft_radar_check;
  236. int32_t fft_peak_sidx;
  237. uint32_t fft_chn_idx;
  238. uint32_t fft_base_pwr_db;
  239. uint32_t fft_total_gain_db;
  240. uint32_t fft_num_str_bins_ib;
  241. int32_t fft_peak_mag;
  242. uint32_t fft_avgpwr_db;
  243. uint32_t fft_relpwr_db;
  244. };
  245. /**
  246. * struct spectral_phyerr_sfftreport_gen3 - fft info in phyerr event
  247. * @fft_timestamp: Timestamp at which fft report was generated
  248. * @fft_hdr_sig: signature
  249. * @fft_hdr_tag: tag
  250. * @fft_hdr_length: length
  251. * @hdr_a: Header[0:31]
  252. * @hdr_b: Header[32:63]
  253. * @hdr_c: Header[64:95]
  254. * @resv: Header[96:127]
  255. * @buf: fft bins
  256. */
  257. struct spectral_phyerr_fft_report_gen3 {
  258. u_int32_t fft_timestamp;
  259. #ifdef BIG_ENDIAN_HOST
  260. u_int8_t fft_hdr_sig;
  261. u_int8_t fft_hdr_tag;
  262. u_int16_t fft_hdr_length;
  263. #else
  264. u_int16_t fft_hdr_length;
  265. u_int8_t fft_hdr_tag;
  266. u_int8_t fft_hdr_sig;
  267. #endif /* BIG_ENDIAN_HOST */
  268. u_int32_t hdr_a;
  269. u_int32_t hdr_b;
  270. u_int32_t hdr_c;
  271. u_int32_t resv;
  272. u_int8_t buf[0];
  273. } __ATTRIB_PACK;
  274. /* END of spectral GEN III HW specific details */
  275. typedef signed char pwr_dbm;
  276. /**
  277. * enum spectral_gen - spectral hw generation
  278. * @SPECTRAL_GEN1 : spectral hw gen 1
  279. * @SPECTRAL_GEN2 : spectral hw gen 2
  280. * @SPECTRAL_GEN3 : spectral hw gen 3
  281. */
  282. enum spectral_gen {
  283. SPECTRAL_GEN1,
  284. SPECTRAL_GEN2,
  285. SPECTRAL_GEN3,
  286. };
  287. #if ATH_PERF_PWR_OFFLOAD
  288. /**
  289. * enum ol_spectral_info_spec - Enumerations for specifying which spectral
  290. * information (among parameters and states)
  291. * is desired.
  292. * @OL_SPECTRAL_INFO_SPEC_ACTIVE: Indicated whether spectral is active
  293. * @OL_SPECTRAL_INFO_SPEC_ENABLED: Indicated whether spectral is enabled
  294. * @OL_SPECTRAL_INFO_SPEC_PARAMS: Config params
  295. */
  296. enum ol_spectral_info_spec {
  297. OL_SPECTRAL_INFO_SPEC_ACTIVE,
  298. OL_SPECTRAL_INFO_SPEC_ENABLED,
  299. OL_SPECTRAL_INFO_SPEC_PARAMS,
  300. };
  301. #endif /* ATH_PERF_PWR_OFFLOAD */
  302. /* forward declaration */
  303. struct target_if_spectral;
  304. /**
  305. * struct target_if_spectral_chan_info - Channel information
  306. * @center_freq1: center frequency 1 in MHz
  307. * @center_freq2: center frequency 2 in MHz -valid only for
  308. * 11ACVHT 80PLUS80 mode
  309. * @chan_width: channel width in MHz
  310. */
  311. struct target_if_spectral_chan_info {
  312. u_int16_t center_freq1;
  313. u_int16_t center_freq2;
  314. u_int8_t chan_width;
  315. };
  316. /**
  317. * struct target_if_spectral_acs_stats - EACS stats from spectral samples
  318. * @nfc_ctl_rssi: Control chan rssi
  319. * @nfc_ext_rssi: Extension chan rssi
  320. * @ctrl_nf: Control chan Noise Floor
  321. * @ext_nf: Extension chan Noise Floor
  322. */
  323. struct target_if_spectral_acs_stats {
  324. int8_t nfc_ctl_rssi;
  325. int8_t nfc_ext_rssi;
  326. int8_t ctrl_nf;
  327. int8_t ext_nf;
  328. };
  329. /**
  330. * struct target_if_spectral_perchain_rssi_info - per chain rssi info
  331. * @rssi_pri20: Rssi of primary 20 Mhz
  332. * @rssi_sec20: Rssi of secondary 20 Mhz
  333. * @rssi_sec40: Rssi of secondary 40 Mhz
  334. * @rssi_sec80: Rssi of secondary 80 Mhz
  335. */
  336. struct target_if_spectral_perchain_rssi_info {
  337. int8_t rssi_pri20;
  338. int8_t rssi_sec20;
  339. int8_t rssi_sec40;
  340. int8_t rssi_sec80;
  341. };
  342. /**
  343. * struct target_if_spectral_rfqual_info - RF measurement information
  344. * @rssi_comb: RSSI Information
  345. * @pc_rssi_info: XXX : For now, we know we are getting information
  346. * for only 4 chains at max. For future extensions
  347. * use a define
  348. * @noise_floor: Noise floor information
  349. */
  350. struct target_if_spectral_rfqual_info {
  351. int8_t rssi_comb;
  352. struct target_if_spectral_perchain_rssi_info pc_rssi_info[4];
  353. int16_t noise_floor[4];
  354. };
  355. #define GET_TIF_SPECTRAL_OPS(spectral) \
  356. ((struct target_if_spectral_ops *)(&((spectral)->spectral_ops)))
  357. /**
  358. * struct target_if_spectral_ops - spectral low level ops table
  359. * @get_tsf64: Get 64 bit TSF value
  360. * @get_capability: Get capability info
  361. * @set_rxfilter: Set rx filter
  362. * @get_rxfilter: Get rx filter
  363. * @is_spectral_active: Check whether icm is active
  364. * @is_spectral_enabled: Check whether spectral is enabled
  365. * @start_spectral_scan: Start spectral scan
  366. * @stop_spectral_scan: Stop spectral scan
  367. * @get_extension_channel: Get extension channel
  368. * @get_ctl_noisefloor: Get control noise floor
  369. * @get_ext_noisefloor: Get extension noise floor
  370. * @configure_spectral: Set spectral configurations
  371. * @get_spectral_config: Get spectral configurations
  372. * @get_ent_spectral_mask: Get spectral mask
  373. * @get_mac_address: Get mac address
  374. * @get_current_channel: Get current channel
  375. * @reset_hw: Reset HW
  376. * @get_chain_noise_floor: Get Channel noise floor
  377. * @spectral_process_phyerr: Process phyerr event
  378. */
  379. struct target_if_spectral_ops {
  380. u_int64_t (*get_tsf64)(void *arg);
  381. u_int32_t (*get_capability)(void *arg, SPECTRAL_CAPABILITY_TYPE type);
  382. u_int32_t (*set_rxfilter)(void *arg, int rxfilter);
  383. u_int32_t (*get_rxfilter)(void *arg);
  384. u_int32_t (*is_spectral_active)(void *arg);
  385. u_int32_t (*is_spectral_enabled)(void *arg);
  386. u_int32_t (*start_spectral_scan)(void *arg);
  387. u_int32_t (*stop_spectral_scan)(void *arg);
  388. u_int32_t (*get_extension_channel)(void *arg);
  389. int8_t (*get_ctl_noisefloor)(void *arg);
  390. int8_t (*get_ext_noisefloor)(void *arg);
  391. u_int32_t (*configure_spectral)(
  392. void *arg,
  393. struct spectral_config *params);
  394. u_int32_t (*get_spectral_config)(
  395. void *arg,
  396. struct spectral_config *params);
  397. u_int32_t (*get_ent_spectral_mask)(void *arg);
  398. u_int32_t (*get_mac_address)(void *arg, char *addr);
  399. u_int32_t (*get_current_channel)(void *arg);
  400. u_int32_t (*reset_hw)(void *arg);
  401. u_int32_t (*get_chain_noise_floor)(void *arg, int16_t *nf_buf);
  402. int (*spectral_process_phyerr)(struct target_if_spectral *spectral,
  403. u_int8_t *data, u_int32_t datalen,
  404. struct target_if_spectral_rfqual_info *p_rfqual,
  405. struct target_if_spectral_chan_info *p_chaninfo,
  406. u_int64_t tsf64,
  407. struct target_if_spectral_acs_stats *acs_stats);
  408. };
  409. /**
  410. * struct target_if_spectral_stats - spectral stats info
  411. * @num_spectral_detects: Total num. of spectral detects
  412. * @total_phy_errors: Total number of phyerrors
  413. * @owl_phy_errors: Indicated phyerrors in old gen1 chipsets
  414. * @pri_phy_errors: Phyerrors in primary channel
  415. * @ext_phy_errors: Phyerrors in secondary channel
  416. * @dc_phy_errors: Phyerrors due to dc
  417. * @early_ext_phy_errors: Early secondary channel phyerrors
  418. * @bwinfo_errors: Bandwidth info errors
  419. * @datalen_discards: Invalid data length errors, seen in gen1 chipsets
  420. * @rssi_discards bw: Indicates reports dropped due to RSSI threshold
  421. * @last_reset_tstamp: Last reset time stamp
  422. */
  423. struct target_if_spectral_stats {
  424. u_int32_t num_spectral_detects;
  425. u_int32_t total_phy_errors;
  426. u_int32_t owl_phy_errors;
  427. u_int32_t pri_phy_errors;
  428. u_int32_t ext_phy_errors;
  429. u_int32_t dc_phy_errors;
  430. u_int32_t early_ext_phy_errors;
  431. u_int32_t bwinfo_errors;
  432. u_int32_t datalen_discards;
  433. u_int32_t rssi_discards;
  434. u_int64_t last_reset_tstamp;
  435. };
  436. /**
  437. * struct target_if_spectral_event - spectral event structure
  438. * @se_ts: Original 15 bit recv timestamp
  439. * @se_full_ts: 64-bit full timestamp from interrupt time
  440. * @se_rssi: Rssi of spectral event
  441. * @se_bwinfo: Rssi of spectral event
  442. * @se_dur: Duration of spectral pulse
  443. * @se_chanindex: Channel of event
  444. * @se_list: List of spectral events
  445. */
  446. struct target_if_spectral_event {
  447. u_int32_t se_ts;
  448. u_int64_t se_full_ts;
  449. u_int8_t se_rssi;
  450. u_int8_t se_bwinfo;
  451. u_int8_t se_dur;
  452. u_int8_t se_chanindex;
  453. STAILQ_ENTRY(spectral_event) se_list;
  454. };
  455. /**
  456. * struct target_if_chain_noise_pwr_info - Noise power info for each channel
  457. * @rptcount: Count of reports in pwr array
  458. * @un_cal_nf: Uncalibrated noise floor
  459. * @factory_cal_nf: Noise floor as calibrated at the factory for module
  460. * @median_pwr: Median power (median of pwr array)
  461. * @pwr: Power reports
  462. */
  463. struct target_if_chain_noise_pwr_info {
  464. int rptcount;
  465. pwr_dbm un_cal_nf;
  466. pwr_dbm factory_cal_nf;
  467. pwr_dbm median_pwr;
  468. pwr_dbm pwr[];
  469. } __ATTRIB_PACK;
  470. /**
  471. * struct target_if_spectral_chan_stats - Channel information
  472. * @cycle_count: Cycle count
  473. * @channel_load: Channel load
  474. * @per: Period
  475. * @noisefloor: Noise floor
  476. * @comp_usablity: Computed usability
  477. * @maxregpower: Maximum allowed regulatary power
  478. * @comp_usablity_sec80: Computed usability of secondary 80 Mhz
  479. * @maxregpower_sec80: Max regulatory power in secondary 80 Mhz
  480. */
  481. struct target_if_spectral_chan_stats {
  482. int cycle_count;
  483. int channel_load;
  484. int per;
  485. int noisefloor;
  486. u_int16_t comp_usablity;
  487. int8_t maxregpower;
  488. u_int16_t comp_usablity_sec80;
  489. int8_t maxregpower_sec80;
  490. };
  491. #if ATH_PERF_PWR_OFFLOAD
  492. /* Locking operations
  493. * We have a separate set of definitions for offload to accommodate
  494. * offload specific changes in the future.
  495. */
  496. #define OL_SPECTRAL_LOCK_INIT(_lock) qdf_spinlock_create((_lock))
  497. #define OL_SPECTRAL_LOCK_DESTROY(_lock) qdf_spinlock_destroy((_lock))
  498. #define OL_SPECTRAL_LOCK(_lock) qdf_spin_lock((_lock))
  499. #define OL_SPECTRAL_UNLOCK(_lock) qdf_spin_unlock((_lock))
  500. /**
  501. * struct target_if_spectral_cache - Cache used to minimize WMI operations
  502. * in offload architecture
  503. * @osc_spectral_enabled: Whether Spectral is enabled
  504. * @osc_spectral_active: Whether spectral is active
  505. * XXX: Ideally, we should NOT cache this
  506. * since the hardware can self clear the bit,
  507. * the firmware can possibly stop spectral due to
  508. * intermittent off-channel activity, etc
  509. * A WMI read command should be introduced to handle
  510. * this This will be discussed.
  511. * @osc_params: Spectral parameters
  512. * @osc_is_valid: Whether the cache is valid
  513. */
  514. struct target_if_spectral_cache {
  515. u_int8_t osc_spectral_enabled;
  516. u_int8_t osc_spectral_active;
  517. struct spectral_config osc_params;
  518. u_int8_t osc_is_valid;
  519. };
  520. /**
  521. * struct target_if_spectral_param_state_info - Structure used to represent and
  522. * manage spectral information
  523. * (parameters and states)
  524. * @osps_lock: Lock to synchronize accesses to information
  525. * @osps_cache: Cacheable' information
  526. */
  527. struct target_if_spectral_param_state_info {
  528. qdf_spinlock_t osps_lock;
  529. struct target_if_spectral_cache osps_cache;
  530. /* XXX - Non-cacheable information goes here, in the future */
  531. };
  532. #endif /* ATH_PERF_PWR_OFFLOAD */
  533. /**
  534. * struct target_if_spectral - main spectral structure
  535. * @pdev: Pointer to pdev
  536. * @spectral_ops: Target if internal Spectral low level operations table
  537. * @capability: Spectral capabilities structure
  538. * @ath_spectral_lock: Lock used for internal Spectral operations
  539. * @spectral_curchan_radindex: Current channel spectral index
  540. * @spectral_extchan_radindex: Extension channel spectral index
  541. * @spectraldomain: Current Spectral domain
  542. * @spectral_proc_phyerr: Flags to process for PHY errors
  543. * @spectral_defaultparams: Default PHY params per Spectral stat
  544. * @ath_spectral_stats: Spectral related stats
  545. * @events: Events structure
  546. * @sc_spectral_ext_chan_ok: Can spectral be detected on the extension channel?
  547. * @sc_spectral_combined_rssi_ok: Can use combined spectral RSSI?
  548. * @sc_spectral_20_40_mode: Is AP in 20-40 mode?
  549. * @sc_spectral_noise_pwr_cal: Noise power cal required?
  550. * @sc_spectral_non_edma: Is the spectral capable device Non-EDMA?
  551. * @upper_is_control: Upper segment is primary
  552. * @upper_is_extension: Upper segment is secondary
  553. * @lower_is_control: Lower segment is primary
  554. * @lower_is_extension: Lower segment is secondary
  555. * @sc_spectraltest_ieeechan: IEEE channel number to return to after a spectral
  556. * mute test
  557. * @spectral_numbins: Number of bins
  558. * @spectral_fft_len: FFT length
  559. * @spectral_data_len: Total phyerror report length
  560. * @lb_edge_extrabins: Number of extra bins on left band edge
  561. * @rb_edge_extrabins: Number of extra bins on right band edge
  562. * @spectral_max_index_offset: Max FFT index offset (20 MHz mode)
  563. * @spectral_upper_max_index_offset: Upper max FFT index offset (20/40 MHz mode)
  564. * @spectral_lower_max_index_offset: Lower max FFT index offset (20/40 MHz mode)
  565. * @spectral_dc_index: At which index DC is present
  566. * @send_single_packet: Deprecated
  567. * @spectral_sent_msg: Indicates whether we send report to upper layers
  568. * @params: Spectral parameters
  569. * @last_capture_time: Indicates timestamp of previouse report
  570. * @num_spectral_data: Number of Spectral samples received in current session
  571. * @total_spectral_data: Total number of Spectral samples received
  572. * @max_rssi: Maximum RSSI
  573. * @detects_control_channel: NA
  574. * @detects_extension_channel: NA
  575. * @detects_below_dc: NA
  576. * @detects_above_dc: NA
  577. * @sc_scanning: Indicates active wifi scan
  578. * @sc_spectral_scan: Indicates active specral scan
  579. * @sc_spectral_full_scan: Deprecated
  580. * @scan_start_tstamp: Deprecated
  581. * @last_tstamp: Deprecated
  582. * @first_tstamp: Deprecated
  583. * @spectral_samp_count: Deprecated
  584. * @sc_spectral_samp_count: Deprecated
  585. * @noise_pwr_reports_reqd: Number of noise power reports required
  586. * @noise_pwr_reports_recv: Number of noise power reports received
  587. * @noise_pwr_reports_lock: Lock used for Noise power report processing
  588. * @noise_pwr_chain_ctl: Noise power report - control channel
  589. * @noise_pwr_chain_ext: Noise power report - extension channel
  590. * @chaninfo: Channel statistics
  591. * @tsf64: Latest TSF Value
  592. * @ol_info: Offload architecture Spectral parameter cache information
  593. * @ch_width: Indicates Channel Width 20/40/80/160 MHz with values 0, 1, 2, 3
  594. * respectively
  595. * @diag_stats: Diagnostic statistics
  596. * @is_160_format: Indicates whether information provided by HW is in altered
  597. * format for 802.11ac 160/80+80 MHz support (QCA9984 onwards)
  598. * @is_lb_edge_extrabins_format: Indicates whether information provided by
  599. * HW has 4 extra bins, at left band edge, for report mode 2
  600. * @is_rb_edge_extrabins_format: Indicates whether information provided
  601. * by HW has 4 extra bins, at right band edge, for report mode 2
  602. * @is_sec80_rssi_war_required: Indicates whether the software workaround is
  603. * required to obtain approximate combined RSSI for secondary 80Mhz segment
  604. * @simctx: Spectral Simulation context
  605. * @spectral_gen: Spectral hardware generation
  606. * @hdr_sig_exp: Expected signature in PHYERR TLV header, for the given hardware
  607. * generation
  608. * @tag_sscan_summary_exp: Expected Spectral Scan Summary tag in PHYERR TLV
  609. * header, for the given hardware generation
  610. * @tag_sscan_fft_exp: Expected Spectral Scan FFT report tag in PHYERR TLV
  611. * header, for the given hardware generation
  612. * @tlvhdr_size: Expected PHYERR TLV header size, for the given hardware
  613. * generation
  614. */
  615. struct target_if_spectral {
  616. struct wlan_objmgr_pdev *pdev_obj;
  617. struct target_if_spectral_ops spectral_ops;
  618. struct spectral_caps capability;
  619. qdf_spinlock_t ath_spectral_lock;
  620. int16_t spectral_curchan_radindex;
  621. int16_t spectral_extchan_radindex;
  622. u_int32_t spectraldomain;
  623. u_int32_t spectral_proc_phyerr;
  624. struct spectral_config spectral_defaultparams;
  625. struct target_if_spectral_stats ath_spectral_stats;
  626. struct target_if_spectral_event *events;
  627. unsigned int sc_spectral_ext_chan_ok:1,
  628. sc_spectral_combined_rssi_ok:1,
  629. sc_spectral_20_40_mode:1,
  630. sc_spectral_noise_pwr_cal:1,
  631. sc_spectral_non_edma:1;
  632. int upper_is_control;
  633. int upper_is_extension;
  634. int lower_is_control;
  635. int lower_is_extension;
  636. u_int8_t sc_spectraltest_ieeechan;
  637. struct sock *spectral_sock;
  638. struct sk_buff *spectral_skb;
  639. struct nlmsghdr *spectral_nlh;
  640. u_int32_t spectral_pid;
  641. STAILQ_HEAD(, target_if_spectral_skb_event) spectral_skbq;
  642. qdf_spinlock_t spectral_skbqlock;
  643. int spectral_numbins;
  644. int spectral_fft_len;
  645. int spectral_data_len;
  646. /* For 11ac chipsets prior to AR900B version 2.0, a max of 512 bins are
  647. * delivered. However, there can be additional bins reported for
  648. * AR900B version 2.0 and QCA9984 as described next:
  649. *
  650. * AR900B version 2.0: An additional tone is processed on the right
  651. * hand side in order to facilitate detection of radar pulses out to
  652. * the extreme band-edge of the channel frequency. Since the HW design
  653. * processes four tones at a time, this requires one additional Dword
  654. * to be added to the search FFT report.
  655. *
  656. * QCA9984: When spectral_scan_rpt_mode = 2, i.e 2-dword summary +
  657. * 1x-oversampled bins (in-band) per FFT, then 8 more bins
  658. * (4 more on left side and 4 more on right side)are added.
  659. */
  660. int lb_edge_extrabins;
  661. int rb_edge_extrabins;
  662. int spectral_max_index_offset;
  663. int spectral_upper_max_index_offset;
  664. int spectral_lower_max_index_offset;
  665. int spectral_dc_index;
  666. int send_single_packet;
  667. int spectral_sent_msg;
  668. int classify_scan;
  669. os_timer_t classify_timer;
  670. struct spectral_config params;
  671. struct spectral_classifier_params classifier_params;
  672. int last_capture_time;
  673. int num_spectral_data;
  674. int total_spectral_data;
  675. int max_rssi;
  676. int detects_control_channel;
  677. int detects_extension_channel;
  678. int detects_below_dc;
  679. int detects_above_dc;
  680. int sc_scanning;
  681. int sc_spectral_scan;
  682. int sc_spectral_full_scan;
  683. u_int64_t scan_start_tstamp;
  684. u_int32_t last_tstamp;
  685. u_int32_t first_tstamp;
  686. u_int32_t spectral_samp_count;
  687. u_int32_t sc_spectral_samp_count;
  688. int noise_pwr_reports_reqd;
  689. int noise_pwr_reports_recv;
  690. qdf_spinlock_t noise_pwr_reports_lock;
  691. struct target_if_chain_noise_pwr_info
  692. *noise_pwr_chain_ctl[ATH_HOST_MAX_ANTENNA];
  693. struct target_if_chain_noise_pwr_info
  694. *noise_pwr_chain_ext[ATH_HOST_MAX_ANTENNA];
  695. u_int64_t tsf64;
  696. #if ATH_PERF_PWR_OFFLOAD
  697. struct target_if_spectral_param_state_info ol_info;
  698. #endif
  699. u_int32_t ch_width;
  700. struct spectral_diag_stats diag_stats;
  701. bool is_160_format;
  702. bool is_lb_edge_extrabins_format;
  703. bool is_rb_edge_extrabins_format;
  704. bool is_sec80_rssi_war_required;
  705. #if QCA_SUPPORT_SPECTRAL_SIMULATION
  706. void *simctx;
  707. #endif
  708. enum spectral_gen spectral_gen;
  709. u_int8_t hdr_sig_exp;
  710. u_int8_t tag_sscan_summary_exp;
  711. u_int8_t tag_sscan_fft_exp;
  712. u_int8_t tlvhdr_size;
  713. };
  714. /**
  715. * struct target_if_spectral_skb_event - Used to broadcast FFT report to
  716. * applications
  717. * @sp_skb: Pointer to skb
  718. * @sp_nlh: Pointer to nl message header
  719. * @spectral_skb_list: Linked list to manipulate the reports
  720. */
  721. struct target_if_spectral_skb_event {
  722. struct sk_buff *sp_skb;
  723. struct nlmsghdr *sp_nlh;
  724. STAILQ_ENTRY(target_if_spectral_skb_event) spectral_skb_list;
  725. };
  726. /* TODO:COMMENTS */
  727. struct target_if_samp_msg_params {
  728. int8_t rssi;
  729. int8_t rssi_sec80;
  730. int8_t lower_rssi;
  731. int8_t upper_rssi;
  732. int8_t chain_ctl_rssi[ATH_HOST_MAX_ANTENNA];
  733. int8_t chain_ext_rssi[ATH_HOST_MAX_ANTENNA];
  734. uint16_t bwinfo;
  735. uint16_t datalen;
  736. uint16_t datalen_sec80;
  737. uint32_t tstamp;
  738. uint32_t last_tstamp;
  739. uint16_t max_mag;
  740. uint16_t max_mag_sec80;
  741. uint16_t max_index;
  742. uint16_t max_index_sec80;
  743. uint8_t max_exp;
  744. int peak;
  745. int pwr_count;
  746. int pwr_count_sec80;
  747. int8_t nb_lower;
  748. int8_t nb_upper;
  749. uint16_t max_lower_index;
  750. uint16_t max_upper_index;
  751. u_int8_t *bin_pwr_data;
  752. u_int8_t *bin_pwr_data_sec80;
  753. u_int16_t freq;
  754. u_int16_t vhtop_ch_freq_seg1;
  755. u_int16_t vhtop_ch_freq_seg2;
  756. u_int16_t freq_loading;
  757. int16_t noise_floor;
  758. int16_t noise_floor_sec80;
  759. struct INTERF_SRC_RSP interf_list;
  760. SPECTRAL_CLASSIFIER_PARAMS classifier_params;
  761. struct ath_softc *sc;
  762. };
  763. /* NETLINK related declarations */
  764. #ifdef SPECTRAL_USE_NETLINK_SOCKETS
  765. #if (KERNEL_VERSION(2, 6, 31) > LINUX_VERSION_CODE)
  766. void spectral_nl_data_ready(struct sock *sk, int len);
  767. #else
  768. void spectral_nl_data_ready(struct sk_buff *skb);
  769. #endif /* VERSION CHECK */
  770. #endif /* SPECTRAL_USE_NETLINK_SOCKETS defined */
  771. void target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops);
  772. extern struct net init_net;
  773. int target_if_spectral_init_netlink(struct target_if_spectral *spectral);
  774. int target_if_spectral_destroy_netlink(struct target_if_spectral *spectral);
  775. void target_if_spectral_unicast_msg(struct target_if_spectral *spectral);
  776. void target_if_spectral_bcast_msg(struct target_if_spectral *spectral);
  777. void target_if_spectral_prep_skb(struct target_if_spectral *spectral);
  778. void target_if_spectral_skb_dequeue(unsigned long data);
  779. void target_if_spectral_create_samp_msg(
  780. struct target_if_spectral *spectral,
  781. struct target_if_samp_msg_params *params);
  782. int spectral_process_phyerr_gen3(
  783. struct target_if_spectral *spectral,
  784. u_int8_t *data,
  785. u_int32_t datalen, struct target_if_spectral_rfqual_info *p_rfqual,
  786. struct target_if_spectral_chan_info *p_chaninfo,
  787. u_int64_t tsf64,
  788. struct target_if_spectral_acs_stats *acs_stats);
  789. int spectral_process_phyerr_gen2(
  790. struct target_if_spectral *spectral,
  791. u_int8_t *data,
  792. u_int32_t datalen, struct target_if_spectral_rfqual_info *p_rfqual,
  793. struct target_if_spectral_chan_info *p_chaninfo,
  794. u_int64_t tsf64,
  795. struct target_if_spectral_acs_stats *acs_stats);
  796. void target_if_spectral_send_intf_found_msg(
  797. struct wlan_objmgr_pdev *pdev,
  798. u_int16_t cw_int, u_int32_t dcs_enabled);
  799. void target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev);
  800. struct wlan_objmgr_vdev *target_if_spectral_get_vdev(
  801. struct target_if_spectral *spectral);
  802. int spectral_dump_header_gen2(SPECTRAL_PHYERR_HDR_GEN2 *phdr);
  803. int8_t get_combined_rssi_sec80_segment_gen2(
  804. struct target_if_spectral *spectral,
  805. SPECTRAL_SEARCH_FFT_INFO_GEN2 *p_sfft_sec80);
  806. int spectral_dump_tlv_gen2(SPECTRAL_PHYERR_TLV_GEN2 *ptlv, bool is_160_format);
  807. int spectral_dump_phyerr_data_gen2(
  808. u_int8_t *data,
  809. u_int32_t datalen,
  810. bool is_160_format);
  811. int spectral_dump_fft_report_gen3(
  812. struct spectral_phyerr_fft_report_gen3 *p_fft_report,
  813. struct spectral_search_fft_info_gen3 *p_sfft);
  814. void target_if_dbg_print_SAMP_msg(SPECTRAL_SAMP_MSG *pmsg);
  815. /* START of spectral GEN III HW specific function declarations */
  816. /* [FIXME] fix the declaration */
  817. int process_search_fft_report_gen3(
  818. struct spectral_phyerr_fft_report_gen3 *p_fft_report,
  819. struct spectral_search_fft_info_gen3 *p_fft_info);
  820. /* END of spectral GEN III HW specific function declarations */
  821. /**
  822. * target_if_send_phydata() - Send Spectral PHY data over netlink
  823. * @pdev: Pointer to pdev
  824. * @sock: Netlink socket to use
  825. * @nbuf: Network buffer containing PHY data to send
  826. *
  827. * Return: 0 on success, negative value on failure
  828. */
  829. static inline uint32_t target_if_send_phydata(
  830. struct wlan_objmgr_pdev *pdev,
  831. struct sock *sock, qdf_nbuf_t nbuf)
  832. {
  833. struct wlan_objmgr_psoc *psoc = NULL;
  834. psoc = wlan_pdev_get_psoc(pdev);
  835. return psoc->soc_cb.rx_ops.sptrl_rx_ops.sptrlro_send_phydata(pdev,
  836. sock, nbuf);
  837. }
  838. /**
  839. * get_target_if_spectral_handle_from_pdev() - Get handle to target_if internal
  840. * Spectral data
  841. * @pdev: Pointer to pdev
  842. *
  843. * Return: Handle to target_if internal Spectral data on success, NULL on
  844. * failure
  845. */
  846. static inline
  847. struct target_if_spectral *get_target_if_spectral_handle_from_pdev(
  848. struct wlan_objmgr_pdev *pdev)
  849. {
  850. struct target_if_spectral *spectral = NULL;
  851. struct wlan_objmgr_psoc *psoc = NULL;
  852. psoc = wlan_pdev_get_psoc(pdev);
  853. spectral = (struct target_if_spectral *)
  854. psoc->soc_cb.rx_ops.sptrl_rx_ops.sptrlro_get_target_handle(
  855. pdev);
  856. return spectral;
  857. }
  858. /**
  859. * target_if_spectral_set_rxchainmask() - Set Spectral Rx chainmask
  860. * @pdev: Pointer to pdev
  861. * @spectral_rx_chainmask: Spectral Rx chainmask
  862. *
  863. * Return: None
  864. */
  865. static inline
  866. void target_if_spectral_set_rxchainmask(struct wlan_objmgr_pdev *pdev,
  867. u_int8_t spectral_rx_chainmask)
  868. {
  869. struct target_if_spectral *spectral = NULL;
  870. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  871. spectral->params.ss_chn_mask = spectral_rx_chainmask;
  872. }
  873. /**
  874. * target_if_spectral_process_phyerr() - Process Spectral PHY error
  875. * @pdev: Pointer to pdev
  876. * @data: PHY error data received from FW
  877. * @datalen: Length of data
  878. * @p_rfqual: Pointer to RF Quality information
  879. * @p_chaninfo: Pointer to channel information
  880. * @tsf: TSF time instance at which the Spectral sample was received
  881. * @acs_stats: ACS stats
  882. *
  883. * Process Spectral PHY error by extracting necessary information from the data
  884. * sent by FW, and send the extracted information to application layer.
  885. *
  886. * Return: None
  887. */
  888. static inline
  889. void target_if_spectral_process_phyerr(
  890. struct wlan_objmgr_pdev *pdev,
  891. u_int8_t *data, u_int32_t datalen,
  892. struct target_if_spectral_rfqual_info *p_rfqual,
  893. struct target_if_spectral_chan_info *p_chaninfo,
  894. u_int64_t tsf64,
  895. struct target_if_spectral_acs_stats *acs_stats)
  896. {
  897. struct target_if_spectral *spectral = NULL;
  898. struct target_if_spectral_ops *p_sops = NULL;
  899. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  900. p_sops = GET_TIF_SPECTRAL_OPS(spectral);
  901. p_sops->spectral_process_phyerr(spectral, data, datalen,
  902. p_rfqual, p_chaninfo,
  903. tsf64, acs_stats);
  904. }
  905. #ifdef WIN32
  906. #pragma pack(pop, target_if_spectral)
  907. #endif
  908. #ifdef __ATTRIB_PACK
  909. #undef __ATTRIB_PACK
  910. #endif
  911. #endif /* _TARGET_IF_SPECTRAL_H_ */