target_if_spectral.h 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  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. struct vdev_spectral_configure_params;
  534. struct vdev_spectral_enable_params;
  535. /**
  536. * struct wmi_spectral_cmd_ops - structure used holding the operations
  537. * related to wmi commands on spectral parameters.
  538. * @wmi_spectral_configure_cmd_send:
  539. * @wmi_spectral_enable_cmd_send:
  540. */
  541. struct wmi_spectral_cmd_ops {
  542. QDF_STATUS (*wmi_spectral_configure_cmd_send)(
  543. void *wmi_hdl,
  544. struct vdev_spectral_configure_params *param);
  545. QDF_STATUS (*wmi_spectral_enable_cmd_send)(
  546. void *wmi_hdl,
  547. struct vdev_spectral_enable_params *param);
  548. };
  549. /**
  550. * struct target_if_spectral - main spectral structure
  551. * @pdev: Pointer to pdev
  552. * @spectral_ops: Target if internal Spectral low level operations table
  553. * @capability: Spectral capabilities structure
  554. * @ath_spectral_lock: Lock used for internal Spectral operations
  555. * @spectral_curchan_radindex: Current channel spectral index
  556. * @spectral_extchan_radindex: Extension channel spectral index
  557. * @spectraldomain: Current Spectral domain
  558. * @spectral_proc_phyerr: Flags to process for PHY errors
  559. * @spectral_defaultparams: Default PHY params per Spectral stat
  560. * @ath_spectral_stats: Spectral related stats
  561. * @events: Events structure
  562. * @sc_spectral_ext_chan_ok: Can spectral be detected on the extension channel?
  563. * @sc_spectral_combined_rssi_ok: Can use combined spectral RSSI?
  564. * @sc_spectral_20_40_mode: Is AP in 20-40 mode?
  565. * @sc_spectral_noise_pwr_cal: Noise power cal required?
  566. * @sc_spectral_non_edma: Is the spectral capable device Non-EDMA?
  567. * @upper_is_control: Upper segment is primary
  568. * @upper_is_extension: Upper segment is secondary
  569. * @lower_is_control: Lower segment is primary
  570. * @lower_is_extension: Lower segment is secondary
  571. * @sc_spectraltest_ieeechan: IEEE channel number to return to after a spectral
  572. * mute test
  573. * @spectral_numbins: Number of bins
  574. * @spectral_fft_len: FFT length
  575. * @spectral_data_len: Total phyerror report length
  576. * @lb_edge_extrabins: Number of extra bins on left band edge
  577. * @rb_edge_extrabins: Number of extra bins on right band edge
  578. * @spectral_max_index_offset: Max FFT index offset (20 MHz mode)
  579. * @spectral_upper_max_index_offset: Upper max FFT index offset (20/40 MHz mode)
  580. * @spectral_lower_max_index_offset: Lower max FFT index offset (20/40 MHz mode)
  581. * @spectral_dc_index: At which index DC is present
  582. * @send_single_packet: Deprecated
  583. * @spectral_sent_msg: Indicates whether we send report to upper layers
  584. * @params: Spectral parameters
  585. * @last_capture_time: Indicates timestamp of previouse report
  586. * @num_spectral_data: Number of Spectral samples received in current session
  587. * @total_spectral_data: Total number of Spectral samples received
  588. * @max_rssi: Maximum RSSI
  589. * @detects_control_channel: NA
  590. * @detects_extension_channel: NA
  591. * @detects_below_dc: NA
  592. * @detects_above_dc: NA
  593. * @sc_scanning: Indicates active wifi scan
  594. * @sc_spectral_scan: Indicates active specral scan
  595. * @sc_spectral_full_scan: Deprecated
  596. * @scan_start_tstamp: Deprecated
  597. * @last_tstamp: Deprecated
  598. * @first_tstamp: Deprecated
  599. * @spectral_samp_count: Deprecated
  600. * @sc_spectral_samp_count: Deprecated
  601. * @noise_pwr_reports_reqd: Number of noise power reports required
  602. * @noise_pwr_reports_recv: Number of noise power reports received
  603. * @noise_pwr_reports_lock: Lock used for Noise power report processing
  604. * @noise_pwr_chain_ctl: Noise power report - control channel
  605. * @noise_pwr_chain_ext: Noise power report - extension channel
  606. * @chaninfo: Channel statistics
  607. * @tsf64: Latest TSF Value
  608. * @ol_info: Offload architecture Spectral parameter cache information
  609. * @ch_width: Indicates Channel Width 20/40/80/160 MHz with values 0, 1, 2, 3
  610. * respectively
  611. * @diag_stats: Diagnostic statistics
  612. * @is_160_format: Indicates whether information provided by HW is in altered
  613. * format for 802.11ac 160/80+80 MHz support (QCA9984 onwards)
  614. * @is_lb_edge_extrabins_format: Indicates whether information provided by
  615. * HW has 4 extra bins, at left band edge, for report mode 2
  616. * @is_rb_edge_extrabins_format: Indicates whether information provided
  617. * by HW has 4 extra bins, at right band edge, for report mode 2
  618. * @is_sec80_rssi_war_required: Indicates whether the software workaround is
  619. * required to obtain approximate combined RSSI for secondary 80Mhz segment
  620. * @simctx: Spectral Simulation context
  621. * @spectral_gen: Spectral hardware generation
  622. * @hdr_sig_exp: Expected signature in PHYERR TLV header, for the given hardware
  623. * generation
  624. * @tag_sscan_summary_exp: Expected Spectral Scan Summary tag in PHYERR TLV
  625. * header, for the given hardware generation
  626. * @tag_sscan_fft_exp: Expected Spectral Scan FFT report tag in PHYERR TLV
  627. * header, for the given hardware generation
  628. * @tlvhdr_size: Expected PHYERR TLV header size, for the given hardware
  629. * generation
  630. */
  631. struct target_if_spectral {
  632. struct wlan_objmgr_pdev *pdev_obj;
  633. struct target_if_spectral_ops spectral_ops;
  634. struct spectral_caps capability;
  635. qdf_spinlock_t ath_spectral_lock;
  636. int16_t spectral_curchan_radindex;
  637. int16_t spectral_extchan_radindex;
  638. u_int32_t spectraldomain;
  639. u_int32_t spectral_proc_phyerr;
  640. struct spectral_config spectral_defaultparams;
  641. struct target_if_spectral_stats ath_spectral_stats;
  642. struct target_if_spectral_event *events;
  643. unsigned int sc_spectral_ext_chan_ok:1,
  644. sc_spectral_combined_rssi_ok:1,
  645. sc_spectral_20_40_mode:1,
  646. sc_spectral_noise_pwr_cal:1,
  647. sc_spectral_non_edma:1;
  648. int upper_is_control;
  649. int upper_is_extension;
  650. int lower_is_control;
  651. int lower_is_extension;
  652. u_int8_t sc_spectraltest_ieeechan;
  653. struct sock *spectral_sock;
  654. struct sk_buff *spectral_skb;
  655. struct nlmsghdr *spectral_nlh;
  656. u_int32_t spectral_pid;
  657. STAILQ_HEAD(, target_if_spectral_skb_event) spectral_skbq;
  658. qdf_spinlock_t spectral_skbqlock;
  659. int spectral_numbins;
  660. int spectral_fft_len;
  661. int spectral_data_len;
  662. /* For 11ac chipsets prior to AR900B version 2.0, a max of 512 bins are
  663. * delivered. However, there can be additional bins reported for
  664. * AR900B version 2.0 and QCA9984 as described next:
  665. *
  666. * AR900B version 2.0: An additional tone is processed on the right
  667. * hand side in order to facilitate detection of radar pulses out to
  668. * the extreme band-edge of the channel frequency. Since the HW design
  669. * processes four tones at a time, this requires one additional Dword
  670. * to be added to the search FFT report.
  671. *
  672. * QCA9984: When spectral_scan_rpt_mode = 2, i.e 2-dword summary +
  673. * 1x-oversampled bins (in-band) per FFT, then 8 more bins
  674. * (4 more on left side and 4 more on right side)are added.
  675. */
  676. int lb_edge_extrabins;
  677. int rb_edge_extrabins;
  678. int spectral_max_index_offset;
  679. int spectral_upper_max_index_offset;
  680. int spectral_lower_max_index_offset;
  681. int spectral_dc_index;
  682. int send_single_packet;
  683. int spectral_sent_msg;
  684. int classify_scan;
  685. os_timer_t classify_timer;
  686. struct spectral_config params;
  687. struct spectral_classifier_params classifier_params;
  688. int last_capture_time;
  689. int num_spectral_data;
  690. int total_spectral_data;
  691. int max_rssi;
  692. int detects_control_channel;
  693. int detects_extension_channel;
  694. int detects_below_dc;
  695. int detects_above_dc;
  696. int sc_scanning;
  697. int sc_spectral_scan;
  698. int sc_spectral_full_scan;
  699. u_int64_t scan_start_tstamp;
  700. u_int32_t last_tstamp;
  701. u_int32_t first_tstamp;
  702. u_int32_t spectral_samp_count;
  703. u_int32_t sc_spectral_samp_count;
  704. int noise_pwr_reports_reqd;
  705. int noise_pwr_reports_recv;
  706. qdf_spinlock_t noise_pwr_reports_lock;
  707. struct target_if_chain_noise_pwr_info
  708. *noise_pwr_chain_ctl[ATH_HOST_MAX_ANTENNA];
  709. struct target_if_chain_noise_pwr_info
  710. *noise_pwr_chain_ext[ATH_HOST_MAX_ANTENNA];
  711. u_int64_t tsf64;
  712. #if ATH_PERF_PWR_OFFLOAD
  713. struct target_if_spectral_param_state_info ol_info;
  714. #endif
  715. u_int32_t ch_width;
  716. struct spectral_diag_stats diag_stats;
  717. bool is_160_format;
  718. bool is_lb_edge_extrabins_format;
  719. bool is_rb_edge_extrabins_format;
  720. bool is_sec80_rssi_war_required;
  721. #if QCA_SUPPORT_SPECTRAL_SIMULATION
  722. void *simctx;
  723. #endif
  724. enum spectral_gen spectral_gen;
  725. u_int8_t hdr_sig_exp;
  726. u_int8_t tag_sscan_summary_exp;
  727. u_int8_t tag_sscan_fft_exp;
  728. u_int8_t tlvhdr_size;
  729. struct wmi_spectral_cmd_ops param_wmi_cmd_ops;
  730. };
  731. /**
  732. * struct target_if_spectral_skb_event - Used to broadcast FFT report to
  733. * applications
  734. * @sp_skb: Pointer to skb
  735. * @sp_nlh: Pointer to nl message header
  736. * @spectral_skb_list: Linked list to manipulate the reports
  737. */
  738. struct target_if_spectral_skb_event {
  739. struct sk_buff *sp_skb;
  740. struct nlmsghdr *sp_nlh;
  741. STAILQ_ENTRY(target_if_spectral_skb_event) spectral_skb_list;
  742. };
  743. /* TODO:COMMENTS */
  744. struct target_if_samp_msg_params {
  745. int8_t rssi;
  746. int8_t rssi_sec80;
  747. int8_t lower_rssi;
  748. int8_t upper_rssi;
  749. int8_t chain_ctl_rssi[ATH_HOST_MAX_ANTENNA];
  750. int8_t chain_ext_rssi[ATH_HOST_MAX_ANTENNA];
  751. uint16_t bwinfo;
  752. uint16_t datalen;
  753. uint16_t datalen_sec80;
  754. uint32_t tstamp;
  755. uint32_t last_tstamp;
  756. uint16_t max_mag;
  757. uint16_t max_mag_sec80;
  758. uint16_t max_index;
  759. uint16_t max_index_sec80;
  760. uint8_t max_exp;
  761. int peak;
  762. int pwr_count;
  763. int pwr_count_sec80;
  764. int8_t nb_lower;
  765. int8_t nb_upper;
  766. uint16_t max_lower_index;
  767. uint16_t max_upper_index;
  768. u_int8_t *bin_pwr_data;
  769. u_int8_t *bin_pwr_data_sec80;
  770. u_int16_t freq;
  771. u_int16_t vhtop_ch_freq_seg1;
  772. u_int16_t vhtop_ch_freq_seg2;
  773. u_int16_t freq_loading;
  774. int16_t noise_floor;
  775. int16_t noise_floor_sec80;
  776. struct INTERF_SRC_RSP interf_list;
  777. SPECTRAL_CLASSIFIER_PARAMS classifier_params;
  778. struct ath_softc *sc;
  779. };
  780. /* NETLINK related declarations */
  781. #ifdef SPECTRAL_USE_NETLINK_SOCKETS
  782. #if (KERNEL_VERSION(2, 6, 31) > LINUX_VERSION_CODE)
  783. void spectral_nl_data_ready(struct sock *sk, int len);
  784. #else
  785. void spectral_nl_data_ready(struct sk_buff *skb);
  786. #endif /* VERSION CHECK */
  787. #endif /* SPECTRAL_USE_NETLINK_SOCKETS defined */
  788. void target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops);
  789. extern struct net init_net;
  790. int target_if_spectral_init_netlink(struct target_if_spectral *spectral);
  791. int target_if_spectral_destroy_netlink(struct target_if_spectral *spectral);
  792. void target_if_spectral_unicast_msg(struct target_if_spectral *spectral);
  793. void target_if_spectral_bcast_msg(struct target_if_spectral *spectral);
  794. void target_if_spectral_prep_skb(struct target_if_spectral *spectral);
  795. void target_if_spectral_skb_dequeue(unsigned long data);
  796. void target_if_spectral_create_samp_msg(
  797. struct target_if_spectral *spectral,
  798. struct target_if_samp_msg_params *params);
  799. int spectral_process_phyerr_gen3(
  800. struct target_if_spectral *spectral,
  801. u_int8_t *data,
  802. u_int32_t datalen, struct target_if_spectral_rfqual_info *p_rfqual,
  803. struct target_if_spectral_chan_info *p_chaninfo,
  804. u_int64_t tsf64,
  805. struct target_if_spectral_acs_stats *acs_stats);
  806. int spectral_process_phyerr_gen2(
  807. struct target_if_spectral *spectral,
  808. u_int8_t *data,
  809. u_int32_t datalen, struct target_if_spectral_rfqual_info *p_rfqual,
  810. struct target_if_spectral_chan_info *p_chaninfo,
  811. u_int64_t tsf64,
  812. struct target_if_spectral_acs_stats *acs_stats);
  813. void target_if_spectral_send_intf_found_msg(
  814. struct wlan_objmgr_pdev *pdev,
  815. u_int16_t cw_int, u_int32_t dcs_enabled);
  816. void target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev);
  817. struct wlan_objmgr_vdev *target_if_spectral_get_vdev(
  818. struct target_if_spectral *spectral);
  819. int spectral_dump_header_gen2(SPECTRAL_PHYERR_HDR_GEN2 *phdr);
  820. int8_t get_combined_rssi_sec80_segment_gen2(
  821. struct target_if_spectral *spectral,
  822. SPECTRAL_SEARCH_FFT_INFO_GEN2 *p_sfft_sec80);
  823. int spectral_dump_tlv_gen2(SPECTRAL_PHYERR_TLV_GEN2 *ptlv, bool is_160_format);
  824. int spectral_dump_phyerr_data_gen2(
  825. u_int8_t *data,
  826. u_int32_t datalen,
  827. bool is_160_format);
  828. int spectral_dump_fft_report_gen3(
  829. struct spectral_phyerr_fft_report_gen3 *p_fft_report,
  830. struct spectral_search_fft_info_gen3 *p_sfft);
  831. void target_if_dbg_print_SAMP_msg(SPECTRAL_SAMP_MSG *pmsg);
  832. /* START of spectral GEN III HW specific function declarations */
  833. /* [FIXME] fix the declaration */
  834. int process_search_fft_report_gen3(
  835. struct spectral_phyerr_fft_report_gen3 *p_fft_report,
  836. struct spectral_search_fft_info_gen3 *p_fft_info);
  837. /* END of spectral GEN III HW specific function declarations */
  838. /**
  839. * target_if_send_phydata() - Send Spectral PHY data over netlink
  840. * @pdev: Pointer to pdev
  841. * @sock: Netlink socket to use
  842. * @nbuf: Network buffer containing PHY data to send
  843. *
  844. * Return: 0 on success, negative value on failure
  845. */
  846. static inline uint32_t target_if_send_phydata(
  847. struct wlan_objmgr_pdev *pdev,
  848. struct sock *sock, qdf_nbuf_t nbuf)
  849. {
  850. struct wlan_objmgr_psoc *psoc = NULL;
  851. psoc = wlan_pdev_get_psoc(pdev);
  852. return psoc->soc_cb.rx_ops.sptrl_rx_ops.sptrlro_send_phydata(pdev,
  853. sock, nbuf);
  854. }
  855. /**
  856. * get_target_if_spectral_handle_from_pdev() - Get handle to target_if internal
  857. * Spectral data
  858. * @pdev: Pointer to pdev
  859. *
  860. * Return: Handle to target_if internal Spectral data on success, NULL on
  861. * failure
  862. */
  863. static inline
  864. struct target_if_spectral *get_target_if_spectral_handle_from_pdev(
  865. struct wlan_objmgr_pdev *pdev)
  866. {
  867. struct target_if_spectral *spectral = NULL;
  868. struct wlan_objmgr_psoc *psoc = NULL;
  869. psoc = wlan_pdev_get_psoc(pdev);
  870. spectral = (struct target_if_spectral *)
  871. psoc->soc_cb.rx_ops.sptrl_rx_ops.sptrlro_get_target_handle(
  872. pdev);
  873. return spectral;
  874. }
  875. /**
  876. * target_if_spectral_set_rxchainmask() - Set Spectral Rx chainmask
  877. * @pdev: Pointer to pdev
  878. * @spectral_rx_chainmask: Spectral Rx chainmask
  879. *
  880. * Return: None
  881. */
  882. static inline
  883. void target_if_spectral_set_rxchainmask(struct wlan_objmgr_pdev *pdev,
  884. u_int8_t spectral_rx_chainmask)
  885. {
  886. struct target_if_spectral *spectral = NULL;
  887. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  888. spectral->params.ss_chn_mask = spectral_rx_chainmask;
  889. }
  890. /**
  891. * target_if_spectral_process_phyerr() - Process Spectral PHY error
  892. * @pdev: Pointer to pdev
  893. * @data: PHY error data received from FW
  894. * @datalen: Length of data
  895. * @p_rfqual: Pointer to RF Quality information
  896. * @p_chaninfo: Pointer to channel information
  897. * @tsf: TSF time instance at which the Spectral sample was received
  898. * @acs_stats: ACS stats
  899. *
  900. * Process Spectral PHY error by extracting necessary information from the data
  901. * sent by FW, and send the extracted information to application layer.
  902. *
  903. * Return: None
  904. */
  905. static inline
  906. void target_if_spectral_process_phyerr(
  907. struct wlan_objmgr_pdev *pdev,
  908. u_int8_t *data, u_int32_t datalen,
  909. struct target_if_spectral_rfqual_info *p_rfqual,
  910. struct target_if_spectral_chan_info *p_chaninfo,
  911. u_int64_t tsf64,
  912. struct target_if_spectral_acs_stats *acs_stats)
  913. {
  914. struct target_if_spectral *spectral = NULL;
  915. struct target_if_spectral_ops *p_sops = NULL;
  916. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  917. p_sops = GET_TIF_SPECTRAL_OPS(spectral);
  918. p_sops->spectral_process_phyerr(spectral, data, datalen,
  919. p_rfqual, p_chaninfo,
  920. tsf64, acs_stats);
  921. }
  922. #ifdef WIN32
  923. #pragma pack(pop, target_if_spectral)
  924. #endif
  925. #ifdef __ATTRIB_PACK
  926. #undef __ATTRIB_PACK
  927. #endif
  928. #endif /* _TARGET_IF_SPECTRAL_H_ */