target_if_spectral.h 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002
  1. /*
  2. * Copyright (c) 2011,2017-2019 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 <wlan_objmgr_vdev_obj.h>
  25. #include <qdf_lock.h>
  26. #include <wlan_spectral_public_structs.h>
  27. #include <reg_services_public_struct.h>
  28. #ifdef DIRECT_BUF_RX_ENABLE
  29. #include <target_if_direct_buf_rx_api.h>
  30. #endif
  31. #ifdef WIN32
  32. #pragma pack(push, target_if_spectral, 1)
  33. #define __ATTRIB_PACK
  34. #else
  35. #ifndef __ATTRIB_PACK
  36. #define __ATTRIB_PACK __attribute__ ((packed))
  37. #endif
  38. #endif
  39. #include <spectral_defs_i.h>
  40. #ifndef SPECTRAL_USE_NL_BCAST
  41. #define SPECTRAL_USE_NL_BCAST (0)
  42. #endif
  43. #define STATUS_PASS 1
  44. #define STATUS_FAIL 0
  45. #undef spectral_dbg_line
  46. #define spectral_dbg_line() \
  47. spectral_debug("----------------------------------------------------")
  48. #undef spectral_ops_not_registered
  49. #define spectral_ops_not_registered(str) \
  50. spectral_info("SPECTRAL : %s not registered\n", (str))
  51. #undef not_yet_implemented
  52. #define not_yet_implemented() \
  53. spectral_info("SPECTRAL : %s : %d Not yet implemented\n", \
  54. __func__, __LINE__)
  55. #define SPECTRAL_HT20_NUM_BINS 56
  56. #define SPECTRAL_HT20_FFT_LEN 56
  57. #define SPECTRAL_HT20_DC_INDEX (SPECTRAL_HT20_FFT_LEN / 2)
  58. #define SPECTRAL_HT20_DATA_LEN 60
  59. #define SPECTRAL_HT20_TOTAL_DATA_LEN (SPECTRAL_HT20_DATA_LEN + 3)
  60. #define SPECTRAL_HT40_TOTAL_NUM_BINS 128
  61. #define SPECTRAL_HT40_DATA_LEN 135
  62. #define SPECTRAL_HT40_TOTAL_DATA_LEN (SPECTRAL_HT40_DATA_LEN + 3)
  63. #define SPECTRAL_HT40_FFT_LEN 128
  64. #define SPECTRAL_HT40_DC_INDEX (SPECTRAL_HT40_FFT_LEN / 2)
  65. /*
  66. * Used for the SWAR to obtain approximate combined rssi
  67. * in secondary 80Mhz segment
  68. */
  69. #define OFFSET_CH_WIDTH_20 65
  70. #define OFFSET_CH_WIDTH_40 62
  71. #define OFFSET_CH_WIDTH_80 56
  72. #define OFFSET_CH_WIDTH_160 50
  73. /* Min and max for relevant Spectral params */
  74. #define SPECTRAL_PARAM_FFT_SIZE_MIN_GEN2 (1)
  75. #define SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2 (9)
  76. #define SPECTRAL_PARAM_FFT_SIZE_MIN_GEN3 (5)
  77. #define SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3 (9)
  78. #define SPECTRAL_PARAM_RPT_MODE_MIN (0)
  79. #define SPECTRAL_PARAM_RPT_MODE_MAX (3)
  80. #ifdef BIG_ENDIAN_HOST
  81. #define SPECTRAL_MESSAGE_COPY_CHAR_ARRAY(destp, srcp, len) do { \
  82. int j; \
  83. uint32_t *src, *dest; \
  84. src = (uint32_t *)(srcp); \
  85. dest = (uint32_t *)(destp); \
  86. for (j = 0; j < roundup((len), sizeof(uint32_t)) / 4; j++) { \
  87. *(dest + j) = qdf_le32_to_cpu(*(src + j)); \
  88. } \
  89. } while (0)
  90. #else
  91. #define SPECTRAL_MESSAGE_COPY_CHAR_ARRAY(destp, srcp, len) \
  92. OS_MEMCPY((destp), (srcp), (len));
  93. #endif
  94. #define DUMMY_NF_VALUE (-123)
  95. /* 5 categories x (lower + upper) bands */
  96. #define MAX_INTERF 10
  97. #define HOST_MAX_ANTENNA 3
  98. /* Mask for time stamp from descriptor */
  99. #define SPECTRAL_TSMASK 0xFFFFFFFF
  100. #define SPECTRAL_SIGNATURE 0xdeadbeef
  101. /* START of spectral GEN II HW specific details */
  102. #define SPECTRAL_PHYERR_SIGNATURE_GEN2 0xbb
  103. #define TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2 0xF9
  104. #define TLV_TAG_ADC_REPORT_GEN2 0xFA
  105. #define TLV_TAG_SEARCH_FFT_REPORT_GEN2 0xFB
  106. /**
  107. * enum spectral_160mhz_report_delivery_state - 160 MHz state machine states
  108. * @SPECTRAL_REPORT_WAIT_PRIMARY80: Wait for primary80 report
  109. * @SPECTRAL_REPORT_RX_PRIMARY80: Receive primary 80 report
  110. * @SPECTRAL_REPORT_WAIT_SECONDARY80: Wait for secondory 80 report
  111. * @SPECTRAL_REPORT_RX_SECONDARY80: Receive secondary 80 report
  112. */
  113. enum spectral_160mhz_report_delivery_state {
  114. SPECTRAL_REPORT_WAIT_PRIMARY80,
  115. SPECTRAL_REPORT_RX_PRIMARY80,
  116. SPECTRAL_REPORT_WAIT_SECONDARY80,
  117. SPECTRAL_REPORT_RX_SECONDARY80,
  118. };
  119. /**
  120. * enum spectral_detector_id - Spectral detector id
  121. * @SPECTRAL_DETECTOR_PRIMARY: Primary detector
  122. * @SPECTRAL_DETECTOR_SECONDARY: Secondary detector
  123. * @SPECTRAL_DETECTOR_AGILE: Agile detector
  124. * @SPECTRAL_DETECTOR_INVALID: Invalid detector
  125. */
  126. enum spectral_detector_id {
  127. SPECTRAL_DETECTOR_PRIMARY,
  128. SPECTRAL_DETECTOR_SECONDARY,
  129. SPECTRAL_DETECTOR_AGILE,
  130. SPECTRAL_DETECTOR_INVALID,
  131. };
  132. /**
  133. * struct spectral_search_fft_info_gen2 - spectral search fft report for gen2
  134. * @relpwr_db: Total bin power in db
  135. * @num_str_bins_ib: Number of strong bins
  136. * @base_pwr: Base power
  137. * @total_gain_info: Total gain
  138. * @fft_chn_idx: FFT chain on which report is originated
  139. * @avgpwr_db: Average power in db
  140. * @peak_mag: Peak power seen in the bins
  141. * @peak_inx: Index of bin holding peak power
  142. */
  143. struct spectral_search_fft_info_gen2 {
  144. uint32_t relpwr_db;
  145. uint32_t num_str_bins_ib;
  146. uint32_t base_pwr;
  147. uint32_t total_gain_info;
  148. uint32_t fft_chn_idx;
  149. uint32_t avgpwr_db;
  150. uint32_t peak_mag;
  151. int16_t peak_inx;
  152. };
  153. /*
  154. * XXX Check if we should be handling the endinness difference in some
  155. * other way opaque to the host
  156. */
  157. #ifdef BIG_ENDIAN_HOST
  158. /**
  159. * struct spectral_phyerr_tlv_gen2 - phyerr tlv info for big endian host
  160. * @signature: signature
  161. * @tag: tag
  162. * @length: length
  163. */
  164. struct spectral_phyerr_tlv_gen2 {
  165. uint8_t signature;
  166. uint8_t tag;
  167. uint16_t length;
  168. } __ATTRIB_PACK;
  169. #else
  170. /**
  171. * struct spectral_phyerr_tlv_gen2 - phyerr tlv info for little endian host
  172. * @length: length
  173. * @tag: tag
  174. * @signature: signature
  175. */
  176. struct spectral_phyerr_tlv_gen2 {
  177. uint16_t length;
  178. uint8_t tag;
  179. uint8_t signature;
  180. } __ATTRIB_PACK;
  181. #endif /* BIG_ENDIAN_HOST */
  182. /**
  183. * struct spectral_phyerr_hdr_gen2 - phyerr header for gen2 HW
  184. * @hdr_a: Header[0:31]
  185. * @hdr_b: Header[32:63]
  186. */
  187. struct spectral_phyerr_hdr_gen2 {
  188. uint32_t hdr_a;
  189. uint32_t hdr_b;
  190. };
  191. /*
  192. * Segment ID information for 80+80.
  193. *
  194. * If the HW micro-architecture specification extends this DWORD for other
  195. * purposes, then redefine+rename accordingly. For now, the specification
  196. * mentions only segment ID (though this doesn't require an entire DWORD)
  197. * without mention of any generic terminology for the DWORD, or any reservation.
  198. * We use nomenclature accordingly.
  199. */
  200. typedef uint32_t SPECTRAL_SEGID_INFO;
  201. /**
  202. * struct spectral_phyerr_fft_gen2 - fft info in phyerr event
  203. * @buf: fft report
  204. */
  205. struct spectral_phyerr_fft_gen2 {
  206. uint8_t buf[0];
  207. };
  208. /* END of spectral GEN II HW specific details */
  209. /* START of spectral GEN III HW specific details */
  210. #define get_bitfield(value, size, pos) \
  211. (((value) >> (pos)) & ((1 << (size)) - 1))
  212. #define unsigned_to_signed(value, width) \
  213. (((value) >= (1 << ((width) - 1))) ? \
  214. (value - (1 << (width))) : (value))
  215. #define SSCAN_SUMMARY_REPORT_HDR_A_DETECTOR_ID_POS_GEN3 (29)
  216. #define SSCAN_SUMMARY_REPORT_HDR_A_DETECTOR_ID_SIZE_GEN3 (2)
  217. #define SSCAN_SUMMARY_REPORT_HDR_A_AGC_TOTAL_GAIN_POS_GEN3 (0)
  218. #define SSCAN_SUMMARY_REPORT_HDR_A_AGC_TOTAL_GAIN_SIZE_GEN3 (8)
  219. #define SSCAN_SUMMARY_REPORT_HDR_A_INBAND_PWR_DB_POS_GEN3 (18)
  220. #define SSCAN_SUMMARY_REPORT_HDR_A_INBAND_PWR_DB_SIZE_GEN3 (10)
  221. #define SSCAN_SUMMARY_REPORT_HDR_A_PRI80_POS_GEN3 (31)
  222. #define SSCAN_SUMMARY_REPORT_HDR_A_PRI80_SIZE_GEN3 (1)
  223. #define SSCAN_SUMMARY_REPORT_HDR_B_GAINCHANGE_POS_GEN3 (30)
  224. #define SSCAN_SUMMARY_REPORT_HDR_B_GAINCHANGE_SIZE_GEN3 (1)
  225. #define SPECTRAL_PHYERR_SIGNATURE_GEN3 (0xFA)
  226. #define TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3 (0x02)
  227. #define TLV_TAG_SEARCH_FFT_REPORT_GEN3 (0x03)
  228. #define SPECTRAL_PHYERR_TLVSIZE_GEN3 (4)
  229. #define PHYERR_HDR_SIG_POS \
  230. (offsetof(struct spectral_phyerr_fft_report_gen3, fft_hdr_sig))
  231. #define PHYERR_HDR_TAG_POS \
  232. (offsetof(struct spectral_phyerr_fft_report_gen3, fft_hdr_tag))
  233. #define SPECTRAL_FFT_BINS_POS \
  234. (offsetof(struct spectral_phyerr_fft_report_gen3, buf))
  235. /**
  236. * struct phyerr_info - spectral search fft report for gen3
  237. * @data: handle to phyerror buffer
  238. * @datalen: length of phyerror bufer
  239. * @p_rfqual: rf quality matrices
  240. * @p_chaninfo: pointer to chaninfo
  241. * @tsf64: 64 bit TSF
  242. * @acs_stats: acs stats
  243. */
  244. struct phyerr_info {
  245. uint8_t *data;
  246. uint32_t datalen;
  247. struct target_if_spectral_rfqual_info *p_rfqual;
  248. struct target_if_spectral_chan_info *p_chaninfo;
  249. uint64_t tsf64;
  250. struct target_if_spectral_acs_stats *acs_stats;
  251. };
  252. /**
  253. * struct spectral_search_fft_info_gen3 - spectral search fft report for gen3
  254. * @timestamp: Timestamp at which fft report was generated
  255. * @fft_detector_id: Which radio generated this report
  256. * @fft_num: The FFT count number. Set to 0 for short FFT.
  257. * @fft_radar_check: NA for spectral
  258. * @fft_peak_sidx: Index of bin with maximum power
  259. * @fft_chn_idx: Rx chain index
  260. * @fft_base_pwr_db: Base power in dB
  261. * @fft_total_gain_db: Total gain in dB
  262. * @fft_num_str_bins_ib: Number of strong bins in the report
  263. * @fft_peak_mag: Peak magnitude
  264. * @fft_avgpwr_db: Average power in dB
  265. * @fft_relpwr_db: Relative power in dB
  266. */
  267. struct spectral_search_fft_info_gen3 {
  268. uint32_t timestamp;
  269. uint32_t fft_detector_id;
  270. uint32_t fft_num;
  271. uint32_t fft_radar_check;
  272. int32_t fft_peak_sidx;
  273. uint32_t fft_chn_idx;
  274. uint32_t fft_base_pwr_db;
  275. uint32_t fft_total_gain_db;
  276. uint32_t fft_num_str_bins_ib;
  277. int32_t fft_peak_mag;
  278. uint32_t fft_avgpwr_db;
  279. uint32_t fft_relpwr_db;
  280. };
  281. /**
  282. * struct spectral_phyerr_sfftreport_gen3 - fft info in phyerr event
  283. * @fft_timestamp: Timestamp at which fft report was generated
  284. * @fft_hdr_sig: signature
  285. * @fft_hdr_tag: tag
  286. * @fft_hdr_length: length
  287. * @hdr_a: Header[0:31]
  288. * @hdr_b: Header[32:63]
  289. * @hdr_c: Header[64:95]
  290. * @resv: Header[96:127]
  291. * @buf: fft bins
  292. */
  293. struct spectral_phyerr_fft_report_gen3 {
  294. uint32_t fft_timestamp;
  295. #ifdef BIG_ENDIAN_HOST
  296. uint8_t fft_hdr_sig;
  297. uint8_t fft_hdr_tag;
  298. uint16_t fft_hdr_length;
  299. #else
  300. uint16_t fft_hdr_length;
  301. uint8_t fft_hdr_tag;
  302. uint8_t fft_hdr_sig;
  303. #endif /* BIG_ENDIAN_HOST */
  304. uint32_t hdr_a;
  305. uint32_t hdr_b;
  306. uint32_t hdr_c;
  307. uint32_t resv;
  308. uint8_t buf[0];
  309. } __ATTRIB_PACK;
  310. /**
  311. * struct sscan_report_fields_gen3 - Fields of spectral report
  312. * @sscan_agc_total_gain: The AGC total gain in DB.
  313. * @inband_pwr_db: The in-band power of the signal in 1/2 DB steps
  314. * @sscan_gainchange: This bit is set to 1 if a gainchange occurred during
  315. * the spectral scan FFT. Software may choose to
  316. * disregard the results.
  317. * @sscan_pri80: This is set to 1 to indicate that the Spectral scan was
  318. * performed on the pri80 segment. Software may choose to
  319. * disregard the FFT sample if this is set to 1 but detector ID
  320. * does not correspond to the ID for the pri80 segment.
  321. */
  322. struct sscan_report_fields_gen3 {
  323. uint8_t sscan_agc_total_gain;
  324. int16_t inband_pwr_db;
  325. uint8_t sscan_gainchange;
  326. uint8_t sscan_pri80;
  327. };
  328. /**
  329. * struct spectral_sscan_summary_report_gen3 - Spectral summary report
  330. * event
  331. * @sscan_timestamp: Timestamp at which fft report was generated
  332. * @sscan_hdr_sig: signature
  333. * @sscan_hdr_tag: tag
  334. * @sscan_hdr_length: length
  335. * @hdr_a: Header[0:31]
  336. * @resv: Header[32:63]
  337. * @hdr_b: Header[64:95]
  338. * @resv: Header[96:127]
  339. */
  340. struct spectral_sscan_summary_report_gen3 {
  341. u_int32_t sscan_timestamp;
  342. #ifdef BIG_ENDIAN_HOST
  343. u_int8_t sscan_hdr_sig;
  344. u_int8_t sscan_hdr_tag;
  345. u_int16_t sscan_hdr_length;
  346. #else
  347. u_int16_t sscan_hdr_length;
  348. u_int8_t sscan_hdr_tag;
  349. u_int8_t sscan_hdr_sig;
  350. #endif /* BIG_ENDIAN_HOST */
  351. u_int32_t hdr_a;
  352. u_int32_t res1;
  353. u_int32_t hdr_b;
  354. u_int32_t res2;
  355. } __ATTRIB_PACK;
  356. #ifdef DIRECT_BUF_RX_ENABLE
  357. /**
  358. * struct Spectral_report - spectral report
  359. * @data: Report buffer
  360. * @noisefloor: Noise floor values
  361. * @reset_delay: Time taken for warm reset in us
  362. */
  363. struct spectral_report {
  364. uint8_t *data;
  365. int32_t noisefloor[DBR_MAX_CHAINS];
  366. uint32_t reset_delay;
  367. };
  368. #endif
  369. /* END of spectral GEN III HW specific details */
  370. typedef signed char pwr_dbm;
  371. /**
  372. * enum spectral_gen - spectral hw generation
  373. * @SPECTRAL_GEN1 : spectral hw gen 1
  374. * @SPECTRAL_GEN2 : spectral hw gen 2
  375. * @SPECTRAL_GEN3 : spectral hw gen 3
  376. */
  377. enum spectral_gen {
  378. SPECTRAL_GEN1,
  379. SPECTRAL_GEN2,
  380. SPECTRAL_GEN3,
  381. };
  382. /**
  383. * enum spectral_fftbin_size_war - spectral fft bin size war
  384. * @SPECTRAL_FFTBIN_SIZE_NO_WAR : No WAR applicable for Spectral FFT bin size
  385. * @SPECTRAL_FFTBIN_SIZE_2BYTE_TO_1BYTE : Spectral FFT bin size: Retain only
  386. * least significant byte from 2 byte
  387. * FFT bin transferred by HW
  388. * @SPECTRAL_FFTBIN_SIZE_4BYTE_TO_1BYTE : Spectral FFT bin size: Retain only
  389. * least significant byte from 4 byte
  390. * FFT bin transferred by HW
  391. */
  392. enum spectral_fftbin_size_war {
  393. SPECTRAL_FFTBIN_SIZE_NO_WAR = 0,
  394. SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE = 1,
  395. SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE = 2,
  396. };
  397. #if ATH_PERF_PWR_OFFLOAD
  398. /**
  399. * enum target_if_spectral_info - Enumerations for specifying which spectral
  400. * information (among parameters and states)
  401. * is desired.
  402. * @TARGET_IF_SPECTRAL_INFO_ACTIVE: Indicated whether spectral is active
  403. * @TARGET_IF_SPECTRAL_INFO_ENABLED: Indicated whether spectral is enabled
  404. * @TARGET_IF_SPECTRAL_INFO_PARAMS: Config params
  405. */
  406. enum target_if_spectral_info {
  407. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  408. TARGET_IF_SPECTRAL_INFO_ENABLED,
  409. TARGET_IF_SPECTRAL_INFO_PARAMS,
  410. };
  411. #endif /* ATH_PERF_PWR_OFFLOAD */
  412. /* forward declaration */
  413. struct target_if_spectral;
  414. /**
  415. * struct target_if_spectral_chan_info - Channel information
  416. * @center_freq1: center frequency 1 in MHz
  417. * @center_freq2: center frequency 2 in MHz -valid only for
  418. * 11ACVHT 80PLUS80 mode
  419. * @chan_width: channel width in MHz
  420. */
  421. struct target_if_spectral_chan_info {
  422. uint16_t center_freq1;
  423. uint16_t center_freq2;
  424. uint8_t chan_width;
  425. };
  426. /**
  427. * struct target_if_spectral_acs_stats - EACS stats from spectral samples
  428. * @nfc_ctl_rssi: Control chan rssi
  429. * @nfc_ext_rssi: Extension chan rssi
  430. * @ctrl_nf: Control chan Noise Floor
  431. * @ext_nf: Extension chan Noise Floor
  432. */
  433. struct target_if_spectral_acs_stats {
  434. int8_t nfc_ctl_rssi;
  435. int8_t nfc_ext_rssi;
  436. int8_t ctrl_nf;
  437. int8_t ext_nf;
  438. };
  439. /**
  440. * struct target_if_spectral_perchain_rssi_info - per chain rssi info
  441. * @rssi_pri20: Rssi of primary 20 Mhz
  442. * @rssi_sec20: Rssi of secondary 20 Mhz
  443. * @rssi_sec40: Rssi of secondary 40 Mhz
  444. * @rssi_sec80: Rssi of secondary 80 Mhz
  445. */
  446. struct target_if_spectral_perchain_rssi_info {
  447. int8_t rssi_pri20;
  448. int8_t rssi_sec20;
  449. int8_t rssi_sec40;
  450. int8_t rssi_sec80;
  451. };
  452. /**
  453. * struct target_if_spectral_rfqual_info - RF measurement information
  454. * @rssi_comb: RSSI Information
  455. * @pc_rssi_info: XXX : For now, we know we are getting information
  456. * for only 4 chains at max. For future extensions
  457. * use a define
  458. * @noise_floor: Noise floor information
  459. */
  460. struct target_if_spectral_rfqual_info {
  461. int8_t rssi_comb;
  462. struct target_if_spectral_perchain_rssi_info pc_rssi_info[4];
  463. int16_t noise_floor[4];
  464. };
  465. #define GET_TARGET_IF_SPECTRAL_OPS(spectral) \
  466. ((struct target_if_spectral_ops *)(&((spectral)->spectral_ops)))
  467. /**
  468. * struct target_if_spectral_ops - spectral low level ops table
  469. * @get_tsf64: Get 64 bit TSF value
  470. * @get_capability: Get capability info
  471. * @set_rxfilter: Set rx filter
  472. * @get_rxfilter: Get rx filter
  473. * @is_spectral_active: Check whether icm is active
  474. * @is_spectral_enabled: Check whether spectral is enabled
  475. * @start_spectral_scan: Start spectral scan
  476. * @stop_spectral_scan: Stop spectral scan
  477. * @get_extension_channel: Get extension channel
  478. * @get_ctl_noisefloor: Get control noise floor
  479. * @get_ext_noisefloor: Get extension noise floor
  480. * @configure_spectral: Set spectral configurations
  481. * @get_spectral_config: Get spectral configurations
  482. * @get_ent_spectral_mask: Get spectral mask
  483. * @get_mac_address: Get mac address
  484. * @get_current_channel: Get current channel
  485. * @reset_hw: Reset HW
  486. * @get_chain_noise_floor: Get Channel noise floor
  487. * @spectral_process_phyerr: Process phyerr event
  488. * @process_spectral_report: Process spectral report
  489. */
  490. struct target_if_spectral_ops {
  491. uint64_t (*get_tsf64)(void *arg);
  492. uint32_t (*get_capability)(
  493. void *arg, enum spectral_capability_type type);
  494. uint32_t (*set_rxfilter)(void *arg, int rxfilter);
  495. uint32_t (*get_rxfilter)(void *arg);
  496. uint32_t (*is_spectral_active)(void *arg,
  497. enum spectral_scan_mode smode);
  498. uint32_t (*is_spectral_enabled)(void *arg,
  499. enum spectral_scan_mode smode);
  500. uint32_t (*start_spectral_scan)(void *arg,
  501. enum spectral_scan_mode smode,
  502. enum spectral_cp_error_code *err);
  503. uint32_t (*stop_spectral_scan)(void *arg,
  504. enum spectral_scan_mode smode);
  505. uint32_t (*get_extension_channel)(void *arg);
  506. int8_t (*get_ctl_noisefloor)(void *arg);
  507. int8_t (*get_ext_noisefloor)(void *arg);
  508. uint32_t (*configure_spectral)(
  509. void *arg,
  510. struct spectral_config *params,
  511. enum spectral_scan_mode smode);
  512. uint32_t (*get_spectral_config)(
  513. void *arg,
  514. struct spectral_config *params,
  515. enum spectral_scan_mode smode);
  516. uint32_t (*get_ent_spectral_mask)(void *arg);
  517. uint32_t (*get_mac_address)(void *arg, char *addr);
  518. uint32_t (*get_current_channel)(void *arg);
  519. uint32_t (*reset_hw)(void *arg);
  520. uint32_t (*get_chain_noise_floor)(void *arg, int16_t *nf_buf);
  521. int (*spectral_process_phyerr)(struct target_if_spectral *spectral,
  522. uint8_t *data, uint32_t datalen,
  523. struct target_if_spectral_rfqual_info *p_rfqual,
  524. struct target_if_spectral_chan_info *p_chaninfo,
  525. uint64_t tsf64,
  526. struct target_if_spectral_acs_stats *acs_stats);
  527. int (*process_spectral_report)(struct wlan_objmgr_pdev *pdev,
  528. void *payload);
  529. };
  530. /**
  531. * struct target_if_spectral_stats - spectral stats info
  532. * @num_spectral_detects: Total num. of spectral detects
  533. * @total_phy_errors: Total number of phyerrors
  534. * @owl_phy_errors: Indicated phyerrors in old gen1 chipsets
  535. * @pri_phy_errors: Phyerrors in primary channel
  536. * @ext_phy_errors: Phyerrors in secondary channel
  537. * @dc_phy_errors: Phyerrors due to dc
  538. * @early_ext_phy_errors: Early secondary channel phyerrors
  539. * @bwinfo_errors: Bandwidth info errors
  540. * @datalen_discards: Invalid data length errors, seen in gen1 chipsets
  541. * @rssi_discards bw: Indicates reports dropped due to RSSI threshold
  542. * @last_reset_tstamp: Last reset time stamp
  543. */
  544. struct target_if_spectral_stats {
  545. uint32_t num_spectral_detects;
  546. uint32_t total_phy_errors;
  547. uint32_t owl_phy_errors;
  548. uint32_t pri_phy_errors;
  549. uint32_t ext_phy_errors;
  550. uint32_t dc_phy_errors;
  551. uint32_t early_ext_phy_errors;
  552. uint32_t bwinfo_errors;
  553. uint32_t datalen_discards;
  554. uint32_t rssi_discards;
  555. uint64_t last_reset_tstamp;
  556. };
  557. /**
  558. * struct target_if_spectral_event - spectral event structure
  559. * @se_ts: Original 15 bit recv timestamp
  560. * @se_full_ts: 64-bit full timestamp from interrupt time
  561. * @se_rssi: Rssi of spectral event
  562. * @se_bwinfo: Rssi of spectral event
  563. * @se_dur: Duration of spectral pulse
  564. * @se_chanindex: Channel of event
  565. * @se_list: List of spectral events
  566. */
  567. struct target_if_spectral_event {
  568. uint32_t se_ts;
  569. uint64_t se_full_ts;
  570. uint8_t se_rssi;
  571. uint8_t se_bwinfo;
  572. uint8_t se_dur;
  573. uint8_t se_chanindex;
  574. STAILQ_ENTRY(spectral_event) se_list;
  575. };
  576. /**
  577. * struct target_if_chain_noise_pwr_info - Noise power info for each channel
  578. * @rptcount: Count of reports in pwr array
  579. * @un_cal_nf: Uncalibrated noise floor
  580. * @factory_cal_nf: Noise floor as calibrated at the factory for module
  581. * @median_pwr: Median power (median of pwr array)
  582. * @pwr: Power reports
  583. */
  584. struct target_if_chain_noise_pwr_info {
  585. int rptcount;
  586. pwr_dbm un_cal_nf;
  587. pwr_dbm factory_cal_nf;
  588. pwr_dbm median_pwr;
  589. pwr_dbm pwr[];
  590. } __ATTRIB_PACK;
  591. /**
  592. * struct target_if_spectral_chan_stats - Channel information
  593. * @cycle_count: Cycle count
  594. * @channel_load: Channel load
  595. * @per: Period
  596. * @noisefloor: Noise floor
  597. * @comp_usablity: Computed usability
  598. * @maxregpower: Maximum allowed regulatary power
  599. * @comp_usablity_sec80: Computed usability of secondary 80 Mhz
  600. * @maxregpower_sec80: Max regulatory power in secondary 80 Mhz
  601. */
  602. struct target_if_spectral_chan_stats {
  603. int cycle_count;
  604. int channel_load;
  605. int per;
  606. int noisefloor;
  607. uint16_t comp_usablity;
  608. int8_t maxregpower;
  609. uint16_t comp_usablity_sec80;
  610. int8_t maxregpower_sec80;
  611. };
  612. #if ATH_PERF_PWR_OFFLOAD
  613. /**
  614. * struct target_if_spectral_cache - Cache used to minimize WMI operations
  615. * in offload architecture
  616. * @osc_spectral_enabled: Whether Spectral is enabled
  617. * @osc_spectral_active: Whether spectral is active
  618. * XXX: Ideally, we should NOT cache this
  619. * since the hardware can self clear the bit,
  620. * the firmware can possibly stop spectral due to
  621. * intermittent off-channel activity, etc
  622. * A WMI read command should be introduced to handle
  623. * this This will be discussed.
  624. * @osc_params: Spectral parameters
  625. * @osc_is_valid: Whether the cache is valid
  626. */
  627. struct target_if_spectral_cache {
  628. uint8_t osc_spectral_enabled;
  629. uint8_t osc_spectral_active;
  630. struct spectral_config osc_params;
  631. uint8_t osc_is_valid;
  632. };
  633. /**
  634. * struct target_if_spectral_param_state_info - Structure used to represent and
  635. * manage spectral information
  636. * (parameters and states)
  637. * @osps_lock: Lock to synchronize accesses to information
  638. * @osps_cache: Cacheable' information
  639. */
  640. struct target_if_spectral_param_state_info {
  641. qdf_spinlock_t osps_lock;
  642. struct target_if_spectral_cache osps_cache;
  643. /* XXX - Non-cacheable information goes here, in the future */
  644. };
  645. #endif /* ATH_PERF_PWR_OFFLOAD */
  646. struct vdev_spectral_configure_params;
  647. struct vdev_spectral_enable_params;
  648. /**
  649. * struct wmi_spectral_cmd_ops - structure used holding the operations
  650. * related to wmi commands on spectral parameters.
  651. * @wmi_spectral_configure_cmd_send: Configure Spectral parameters
  652. * @wmi_spectral_enable_cmd_send: Enable/Disable Spectral
  653. * @wmi_spectral_crash_inject: Inject FW crash
  654. */
  655. struct wmi_spectral_cmd_ops {
  656. QDF_STATUS (*wmi_spectral_configure_cmd_send)(
  657. wmi_unified_t wmi_hdl,
  658. struct vdev_spectral_configure_params *param);
  659. QDF_STATUS (*wmi_spectral_enable_cmd_send)(
  660. wmi_unified_t wmi_hdl,
  661. struct vdev_spectral_enable_params *param);
  662. QDF_STATUS(*wmi_spectral_crash_inject)(
  663. wmi_unified_t wmi_handle, struct crash_inject *param);
  664. };
  665. /**
  666. * struct spectral_param_properties - structure holding Spectral
  667. * parameter properties
  668. * @supported: Parameter is supported or not
  669. * @common_all_modes: Parameter should be common for all modes or not
  670. */
  671. struct spectral_param_properties {
  672. bool supported;
  673. bool common_all_modes;
  674. };
  675. /**
  676. * struct target_if_spectral - main spectral structure
  677. * @pdev: Pointer to pdev
  678. * @spectral_ops: Target if internal Spectral low level operations table
  679. * @capability: Spectral capabilities structure
  680. * @properties: Spectral parameter properties per mode
  681. * @spectral_lock: Lock used for internal Spectral operations
  682. * @spectral_curchan_radindex: Current channel spectral index
  683. * @spectral_extchan_radindex: Extension channel spectral index
  684. * @spectraldomain: Current Spectral domain
  685. * @spectral_proc_phyerr: Flags to process for PHY errors
  686. * @spectral_defaultparams: Default PHY params per Spectral stat
  687. * @spectral_stats: Spectral related stats
  688. * @events: Events structure
  689. * @sc_spectral_ext_chan_ok: Can spectral be detected on the extension channel?
  690. * @sc_spectral_combined_rssi_ok: Can use combined spectral RSSI?
  691. * @sc_spectral_20_40_mode: Is AP in 20-40 mode?
  692. * @sc_spectral_noise_pwr_cal: Noise power cal required?
  693. * @sc_spectral_non_edma: Is the spectral capable device Non-EDMA?
  694. * @upper_is_control: Upper segment is primary
  695. * @upper_is_extension: Upper segment is secondary
  696. * @lower_is_control: Lower segment is primary
  697. * @lower_is_extension: Lower segment is secondary
  698. * @sc_spectraltest_ieeechan: IEEE channel number to return to after a spectral
  699. * mute test
  700. * @spectral_numbins: Number of bins
  701. * @spectral_fft_len: FFT length
  702. * @spectral_data_len: Total phyerror report length
  703. * @lb_edge_extrabins: Number of extra bins on left band edge
  704. * @rb_edge_extrabins: Number of extra bins on right band edge
  705. * @spectral_max_index_offset: Max FFT index offset (20 MHz mode)
  706. * @spectral_upper_max_index_offset: Upper max FFT index offset (20/40 MHz mode)
  707. * @spectral_lower_max_index_offset: Lower max FFT index offset (20/40 MHz mode)
  708. * @spectral_dc_index: At which index DC is present
  709. * @send_single_packet: Deprecated
  710. * @spectral_sent_msg: Indicates whether we send report to upper layers
  711. * @params: Spectral parameters
  712. * @last_capture_time: Indicates timestamp of previouse report
  713. * @num_spectral_data: Number of Spectral samples received in current session
  714. * @total_spectral_data: Total number of Spectral samples received
  715. * @max_rssi: Maximum RSSI
  716. * @detects_control_channel: NA
  717. * @detects_extension_channel: NA
  718. * @detects_below_dc: NA
  719. * @detects_above_dc: NA
  720. * @sc_scanning: Indicates active wifi scan
  721. * @sc_spectral_scan: Indicates active specral scan
  722. * @sc_spectral_full_scan: Deprecated
  723. * @scan_start_tstamp: Deprecated
  724. * @last_tstamp: Deprecated
  725. * @first_tstamp: Deprecated
  726. * @spectral_samp_count: Deprecated
  727. * @sc_spectral_samp_count: Deprecated
  728. * @noise_pwr_reports_reqd: Number of noise power reports required
  729. * @noise_pwr_reports_recv: Number of noise power reports received
  730. * @noise_pwr_reports_lock: Lock used for Noise power report processing
  731. * @noise_pwr_chain_ctl: Noise power report - control channel
  732. * @noise_pwr_chain_ext: Noise power report - extension channel
  733. * @chaninfo: Channel statistics
  734. * @tsf64: Latest TSF Value
  735. * @param_info: Offload architecture Spectral parameter cache information
  736. * @ch_width: Indicates Channel Width 20/40/80/160 MHz with values 0, 1, 2, 3
  737. * respectively
  738. * @diag_stats: Diagnostic statistics
  739. * @is_160_format: Indicates whether information provided by HW is in altered
  740. * format for 802.11ac 160/80+80 MHz support (QCA9984 onwards)
  741. * @is_lb_edge_extrabins_format: Indicates whether information provided by
  742. * HW has 4 extra bins, at left band edge, for report mode 2
  743. * @is_rb_edge_extrabins_format: Indicates whether information provided
  744. * by HW has 4 extra bins, at right band edge, for report mode 2
  745. * @is_sec80_rssi_war_required: Indicates whether the software workaround is
  746. * required to obtain approximate combined RSSI for secondary 80Mhz segment
  747. * @simctx: Spectral Simulation context
  748. * @spectral_gen: Spectral hardware generation
  749. * @hdr_sig_exp: Expected signature in PHYERR TLV header, for the given hardware
  750. * generation
  751. * @tag_sscan_summary_exp: Expected Spectral Scan Summary tag in PHYERR TLV
  752. * header, for the given hardware generation
  753. * @tag_sscan_fft_exp: Expected Spectral Scan FFT report tag in PHYERR TLV
  754. * header, for the given hardware generation
  755. * @tlvhdr_size: Expected PHYERR TLV header size, for the given hardware
  756. * generation
  757. * @nl_cb: Netlink callbacks
  758. * @use_nl_bcast: Whether to use Netlink broadcast/unicast
  759. * @send_phy_data: Send data to the application layer for a particular msg type
  760. * @inband_fftbin_size_adj: Whether to carry out FFT bin size adjustment for
  761. * in-band report format. This would be required on some chipsets under the
  762. * following circumstances: In report mode 2 only the in-band bins are DMA'ed.
  763. * Scatter/gather is used. However, the HW generates all bins, not just in-band,
  764. * and reports the number of bins accordingly. The subsystem arranging for the
  765. * DMA cannot change this value. On such chipsets the adjustment required at the
  766. * host driver is to check if report format is 2, and if so halve the number of
  767. * bins reported to get the number actually DMA'ed.
  768. * @null_fftbin_adj: Whether to remove NULL FFT bins for report mode (1) in
  769. * which only summary of metrics for each completed FFT + spectral scan summary
  770. * report are to be provided. This would be required on some chipsets under the
  771. * following circumstances: In report mode 1, HW reports a length corresponding
  772. * to all bins, and provides bins with value 0. This is because the subsystem
  773. * arranging for the FFT information does not arrange for DMA of FFT bin values
  774. * (as expected), but cannot arrange for a smaller length to be reported by HW.
  775. * In these circumstances, the driver would have to disregard the NULL bins and
  776. * report a bin count of 0 to higher layers.
  777. * @last_fft_timestamp: last fft report timestamp
  778. * @timestamp_war_offset: Offset to be added to correct timestamp
  779. */
  780. struct target_if_spectral {
  781. struct wlan_objmgr_pdev *pdev_obj;
  782. struct target_if_spectral_ops spectral_ops;
  783. struct spectral_caps capability;
  784. struct spectral_param_properties
  785. properties[SPECTRAL_SCAN_MODE_MAX][SPECTRAL_PARAM_MAX];
  786. qdf_spinlock_t spectral_lock;
  787. int16_t spectral_curchan_radindex;
  788. int16_t spectral_extchan_radindex;
  789. uint32_t spectraldomain;
  790. uint32_t spectral_proc_phyerr;
  791. struct spectral_config spectral_defaultparams;
  792. struct target_if_spectral_stats spectral_stats;
  793. struct target_if_spectral_event *events;
  794. unsigned int sc_spectral_ext_chan_ok:1,
  795. sc_spectral_combined_rssi_ok:1,
  796. sc_spectral_20_40_mode:1,
  797. sc_spectral_noise_pwr_cal:1,
  798. sc_spectral_non_edma:1;
  799. int upper_is_control;
  800. int upper_is_extension;
  801. int lower_is_control;
  802. int lower_is_extension;
  803. uint8_t sc_spectraltest_ieeechan;
  804. int spectral_numbins;
  805. int spectral_fft_len;
  806. int spectral_data_len;
  807. /*
  808. * For 11ac chipsets prior to AR900B version 2.0, a max of 512 bins are
  809. * delivered. However, there can be additional bins reported for
  810. * AR900B version 2.0 and QCA9984 as described next:
  811. *
  812. * AR900B version 2.0: An additional tone is processed on the right
  813. * hand side in order to facilitate detection of radar pulses out to
  814. * the extreme band-edge of the channel frequency. Since the HW design
  815. * processes four tones at a time, this requires one additional Dword
  816. * to be added to the search FFT report.
  817. *
  818. * QCA9984: When spectral_scan_rpt_mode = 2, i.e 2-dword summary +
  819. * 1x-oversampled bins (in-band) per FFT, then 8 more bins
  820. * (4 more on left side and 4 more on right side)are added.
  821. */
  822. int lb_edge_extrabins;
  823. int rb_edge_extrabins;
  824. int spectral_max_index_offset;
  825. int spectral_upper_max_index_offset;
  826. int spectral_lower_max_index_offset;
  827. int spectral_dc_index;
  828. int send_single_packet;
  829. int spectral_sent_msg;
  830. int classify_scan;
  831. qdf_timer_t classify_timer;
  832. struct spectral_config params[SPECTRAL_SCAN_MODE_MAX];
  833. bool params_valid[SPECTRAL_SCAN_MODE_MAX];
  834. struct spectral_classifier_params classifier_params;
  835. int last_capture_time;
  836. int num_spectral_data;
  837. int total_spectral_data;
  838. int max_rssi;
  839. int detects_control_channel;
  840. int detects_extension_channel;
  841. int detects_below_dc;
  842. int detects_above_dc;
  843. int sc_scanning;
  844. int sc_spectral_scan;
  845. int sc_spectral_full_scan;
  846. uint64_t scan_start_tstamp;
  847. uint32_t last_tstamp;
  848. uint32_t first_tstamp;
  849. uint32_t spectral_samp_count;
  850. uint32_t sc_spectral_samp_count;
  851. int noise_pwr_reports_reqd;
  852. int noise_pwr_reports_recv;
  853. qdf_spinlock_t noise_pwr_reports_lock;
  854. struct target_if_chain_noise_pwr_info
  855. *noise_pwr_chain_ctl[HOST_MAX_ANTENNA];
  856. struct target_if_chain_noise_pwr_info
  857. *noise_pwr_chain_ext[HOST_MAX_ANTENNA];
  858. uint64_t tsf64;
  859. #if ATH_PERF_PWR_OFFLOAD
  860. struct target_if_spectral_param_state_info
  861. param_info[SPECTRAL_SCAN_MODE_MAX];
  862. #endif
  863. uint32_t ch_width;
  864. struct spectral_diag_stats diag_stats;
  865. bool is_160_format;
  866. bool is_lb_edge_extrabins_format;
  867. bool is_rb_edge_extrabins_format;
  868. bool is_sec80_rssi_war_required;
  869. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  870. void *simctx;
  871. #endif
  872. enum spectral_gen spectral_gen;
  873. uint8_t hdr_sig_exp;
  874. uint8_t tag_sscan_summary_exp;
  875. uint8_t tag_sscan_fft_exp;
  876. uint8_t tlvhdr_size;
  877. struct wmi_spectral_cmd_ops param_wmi_cmd_ops;
  878. struct spectral_nl_cb nl_cb;
  879. bool use_nl_bcast;
  880. int (*send_phy_data)(struct wlan_objmgr_pdev *pdev,
  881. enum spectral_msg_type smsg_type);
  882. enum spectral_fftbin_size_war fftbin_size_war;
  883. u_int8_t inband_fftbin_size_adj;
  884. u_int8_t null_fftbin_adj;
  885. enum spectral_160mhz_report_delivery_state state_160mhz_delivery;
  886. void *spectral_report_cache;
  887. uint32_t last_fft_timestamp[SPECTRAL_SCAN_MODE_MAX];
  888. uint32_t timestamp_war_offset[SPECTRAL_SCAN_MODE_MAX];
  889. uint16_t fft_size_min;
  890. uint16_t fft_size_max;
  891. };
  892. /**
  893. * struct target_if_samp_msg_params - Spectral Analysis Messaging Protocol
  894. * data format
  895. * @rssi: RSSI (except for secondary 80 segment)
  896. * @rssi_sec80: RSSI for secondary 80 segment
  897. * @lower_rssi: RSSI of lower band
  898. * @upper_rssi: RSSI of upper band
  899. * @chain_ctl_rssi: RSSI for control channel, for all antennas
  900. * @chain_ext_rssi: RSSI for extension channel, for all antennas
  901. * @bwinfo: bandwidth info
  902. * @data_len: length of FFT data (except for secondary 80 segment)
  903. * @data_len_sec80: length of FFT data for secondary 80 segment
  904. * @tstamp: timestamp
  905. * @last_tstamp: last time stamp
  906. * @max_mag: maximum magnitude (except for secondary 80 segment)
  907. * @max_mag_sec80: maximum magnitude for secondary 80 segment
  908. * @max_index: index of max magnitude (except for secondary 80 segment)
  909. * @max_index_sec80: index of max magnitude for secondary 80 segment
  910. * @max_exp: max exp
  911. * @peak: peak frequency (obsolete)
  912. * @pwr_count: number of FFT bins (except for secondary 80 segment)
  913. * @pwr_count_sec80: number of FFT bins in secondary 80 segment
  914. * @nb_lower: This is deprecated
  915. * @nb_upper: This is deprecated
  916. * @max_upper_index: index of max mag in upper band
  917. * @max_lower_index: index of max mag in lower band
  918. * @bin_pwr_data: Contains FFT magnitudes (except for secondary 80 segment)
  919. * @bin_pwr_data_sec80: Contains FFT magnitudes for the secondary 80 segment
  920. * @freq: Center frequency of primary 20MHz channel in MHz
  921. * @vhtop_ch_freq_seg1: VHT operation first segment center frequency in MHz
  922. * @vhtop_ch_freq_seg2: VHT operation second segment center frequency in MHz
  923. * @freq_loading: spectral control duty cycles
  924. * @noise_floor: current noise floor (except for secondary 80 segment)
  925. * @noise_floor_sec80: current noise floor for secondary 80 segment
  926. * @interf_list: List of interfernce sources
  927. * @classifier_params: classifier parameters
  928. * @sc: classifier parameters
  929. * @pri80ind: Indication from hardware that the sample was received on the
  930. * primary 80 MHz segment. If this is set when smode =
  931. * SPECTRAL_SCAN_MODE_AGILE, it indicates that Spectral was carried out on
  932. * pri80 instead of the Agile frequency due to a channel switch - Software may
  933. * choose to ignore the sample in this case.
  934. * @pri80ind_sec80: Indication from hardware that the sample was received on the
  935. * primary 80 MHz segment instead of the secondary 80 MHz segment due to a
  936. * channel switch - Software may choose to ignore the sample if this is set.
  937. * Applicable only if smode = SPECTRAL_SCAN_MODE_NORMAL and for 160/80+80 MHz
  938. * Spectral operation.
  939. */
  940. struct target_if_samp_msg_params {
  941. int8_t rssi;
  942. int8_t rssi_sec80;
  943. int8_t lower_rssi;
  944. int8_t upper_rssi;
  945. int8_t chain_ctl_rssi[HOST_MAX_ANTENNA];
  946. int8_t chain_ext_rssi[HOST_MAX_ANTENNA];
  947. uint16_t bwinfo;
  948. uint16_t datalen;
  949. uint16_t datalen_sec80;
  950. uint32_t tstamp;
  951. uint32_t last_tstamp;
  952. uint16_t max_mag;
  953. uint16_t max_mag_sec80;
  954. uint16_t max_index;
  955. uint16_t max_index_sec80;
  956. uint8_t max_exp;
  957. int peak;
  958. int pwr_count;
  959. int pwr_count_sec80;
  960. int8_t nb_lower;
  961. int8_t nb_upper;
  962. uint16_t max_lower_index;
  963. uint16_t max_upper_index;
  964. uint8_t *bin_pwr_data;
  965. uint8_t *bin_pwr_data_sec80;
  966. uint16_t freq;
  967. uint16_t vhtop_ch_freq_seg1;
  968. uint16_t vhtop_ch_freq_seg2;
  969. uint16_t freq_loading;
  970. int16_t noise_floor;
  971. int16_t noise_floor_sec80;
  972. struct interf_src_rsp interf_list;
  973. struct spectral_classifier_params classifier_params;
  974. struct ath_softc *sc;
  975. uint8_t agc_total_gain;
  976. uint8_t agc_total_gain_sec80;
  977. uint8_t gainchange;
  978. uint8_t gainchange_sec80;
  979. enum spectral_scan_mode smode;
  980. uint8_t pri80ind;
  981. uint8_t pri80ind_sec80;
  982. };
  983. #ifdef WLAN_CONV_SPECTRAL_ENABLE
  984. /**
  985. * target_if_spectral_dump_fft() - Dump Spectral FFT
  986. * @pfft: Pointer to Spectral Phyerr FFT
  987. * @fftlen: FFT length
  988. *
  989. * Return: Success or failure
  990. */
  991. int target_if_spectral_dump_fft(uint8_t *pfft, int fftlen);
  992. /**
  993. * target_if_dbg_print_samp_param() - Print contents of SAMP struct
  994. * @p: Pointer to SAMP message
  995. *
  996. * Return: Void
  997. */
  998. void target_if_dbg_print_samp_param(struct target_if_samp_msg_params *p);
  999. /**
  1000. * target_if_get_offset_swar_sec80() - Get offset for SWAR according to
  1001. * the channel width
  1002. * @channel_width: Channel width
  1003. *
  1004. * Return: Offset for SWAR
  1005. */
  1006. uint32_t target_if_get_offset_swar_sec80(uint32_t channel_width);
  1007. /**
  1008. * target_if_sptrl_register_tx_ops() - Register Spectral target_if Tx Ops
  1009. * @tx_ops: Tx Ops
  1010. *
  1011. * Return: void
  1012. */
  1013. void target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops);
  1014. /**
  1015. * target_if_spectral_create_samp_msg() - Create the spectral samp message
  1016. * @spectral : Pointer to spectral internal structure
  1017. * @params : spectral samp message parameters
  1018. *
  1019. * API to create the spectral samp message
  1020. *
  1021. * Return: void
  1022. */
  1023. void target_if_spectral_create_samp_msg(
  1024. struct target_if_spectral *spectral,
  1025. struct target_if_samp_msg_params *params);
  1026. /**
  1027. * target_if_spectral_process_phyerr_gen3() - Process phyerror event for gen3
  1028. * @pdev: Pointer to pdev object
  1029. * @payload: Pointer to spectral report
  1030. *
  1031. * Process phyerror event for gen3
  1032. *
  1033. * Return: Success/Failure
  1034. */
  1035. int target_if_spectral_process_report_gen3(
  1036. struct wlan_objmgr_pdev *pdev,
  1037. void *buf);
  1038. /**
  1039. * target_if_process_phyerr_gen2() - Process PHY Error for gen2
  1040. * @spectral: Pointer to Spectral object
  1041. * @data: Pointer to phyerror event buffer
  1042. * @datalen: Data length
  1043. * @p_rfqual: RF quality info
  1044. * @p_chaninfo: Channel info
  1045. * @tsf64: 64 bit tsf timestamp
  1046. * @acs_stats: ACS stats
  1047. *
  1048. * Process PHY Error for gen2
  1049. *
  1050. * Return: Success/Failure
  1051. */
  1052. int target_if_process_phyerr_gen2(
  1053. struct target_if_spectral *spectral,
  1054. uint8_t *data,
  1055. uint32_t datalen, struct target_if_spectral_rfqual_info *p_rfqual,
  1056. struct target_if_spectral_chan_info *p_chaninfo,
  1057. uint64_t tsf64,
  1058. struct target_if_spectral_acs_stats *acs_stats);
  1059. /**
  1060. * target_if_spectral_send_intf_found_msg() - Indicate to application layer that
  1061. * interference has been found
  1062. * @pdev: Pointer to pdev
  1063. * @cw_int: 1 if CW interference is found, 0 if WLAN interference is found
  1064. * @dcs_enabled: 1 if DCS is enabled, 0 if DCS is disabled
  1065. *
  1066. * Send message to application layer
  1067. * indicating that interference has been found
  1068. *
  1069. * Return: None
  1070. */
  1071. void target_if_spectral_send_intf_found_msg(
  1072. struct wlan_objmgr_pdev *pdev,
  1073. uint16_t cw_int, uint32_t dcs_enabled);
  1074. /**
  1075. * target_if_stop_spectral_scan() - Stop spectral scan
  1076. * @pdev: Pointer to pdev object
  1077. * @smode: Spectral scan mode
  1078. * @err: Pointer to error code
  1079. *
  1080. * API to stop the current on-going spectral scan
  1081. *
  1082. * Return: QDF_STATUS_SUCCESS in case of success, else QDF_STATUS_E_FAILURE
  1083. */
  1084. QDF_STATUS target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev,
  1085. const enum spectral_scan_mode smode,
  1086. enum spectral_cp_error_code *err);
  1087. /**
  1088. * target_if_spectral_get_vdev() - Get pointer to vdev to be used for Spectral
  1089. * operations
  1090. * @spectral: Pointer to Spectral target_if internal private data
  1091. *
  1092. * Spectral operates on pdev. However, in order to retrieve some WLAN
  1093. * properties, a vdev is required. To facilitate this, the function returns the
  1094. * first vdev in our pdev. The caller should release the reference to the vdev
  1095. * once it is done using it.
  1096. * TODO: If the framework later provides an API to obtain the first active
  1097. * vdev, then it would be preferable to use this API.
  1098. *
  1099. * Return: Pointer to vdev on success, NULL on failure
  1100. */
  1101. struct wlan_objmgr_vdev *target_if_spectral_get_vdev(
  1102. struct target_if_spectral *spectral);
  1103. /**
  1104. * target_if_spectral_dump_hdr_gen2() - Dump Spectral header for gen2
  1105. * @phdr: Pointer to Spectral Phyerr Header
  1106. *
  1107. * Dump Spectral header
  1108. *
  1109. * Return: Success/Failure
  1110. */
  1111. int target_if_spectral_dump_hdr_gen2(struct spectral_phyerr_hdr_gen2 *phdr);
  1112. /**
  1113. * target_if_get_combrssi_sec80_seg_gen2() - Get approximate combined RSSI
  1114. * for Secondary 80 segment
  1115. * @spectral: Pointer to spectral object
  1116. * @p_sfft_sec80: Pointer to search fft info of secondary 80 segment
  1117. *
  1118. * Get approximate combined RSSI for Secondary 80 segment
  1119. *
  1120. * Return: Combined RSSI for secondary 80Mhz segment
  1121. */
  1122. int8_t target_if_get_combrssi_sec80_seg_gen2(
  1123. struct target_if_spectral *spectral,
  1124. struct spectral_search_fft_info_gen2 *p_sfft_sec80);
  1125. /**
  1126. * target_if_spectral_dump_tlv_gen2() - Dump Spectral TLV for gen2
  1127. * @ptlv: Pointer to Spectral Phyerr TLV
  1128. * @is_160_format: Indicates 160 format
  1129. *
  1130. * Dump Spectral TLV for gen2
  1131. *
  1132. * Return: Success/Failure
  1133. */
  1134. int target_if_spectral_dump_tlv_gen2(
  1135. struct spectral_phyerr_tlv_gen2 *ptlv, bool is_160_format);
  1136. /**
  1137. * target_if_spectral_dump_phyerr_data_gen2() - Dump Spectral
  1138. * related PHY Error for gen2
  1139. * @data: Pointer to phyerror buffer
  1140. * @datalen: Data length
  1141. * @is_160_format: Indicates 160 format
  1142. *
  1143. * Dump Spectral related PHY Error for gen2
  1144. *
  1145. * Return: Success/Failure
  1146. */
  1147. int target_if_spectral_dump_phyerr_data_gen2(
  1148. uint8_t *data,
  1149. uint32_t datalen,
  1150. bool is_160_format);
  1151. /**
  1152. * target_if_dump_fft_report_gen3() - Dump FFT Report for gen3
  1153. * @spectral: Pointer to Spectral object
  1154. * @smode: Spectral scan mode
  1155. * @p_fft_report: Pointer to fft report
  1156. * @p_sfft: Pointer to search fft report
  1157. *
  1158. * Dump FFT Report for gen3
  1159. *
  1160. * Return: Success/Failure
  1161. */
  1162. int target_if_dump_fft_report_gen3(struct target_if_spectral *spectral,
  1163. enum spectral_scan_mode smode,
  1164. struct spectral_phyerr_fft_report_gen3 *p_fft_report,
  1165. struct spectral_search_fft_info_gen3 *p_sfft);
  1166. /**
  1167. * target_if_dbg_print_samp_msg() - Print contents of SAMP Message
  1168. * @p: Pointer to SAMP message
  1169. *
  1170. * Print contents of SAMP Message
  1171. *
  1172. * Return: Void
  1173. */
  1174. void target_if_dbg_print_samp_msg(struct spectral_samp_msg *pmsg);
  1175. /**
  1176. * target_if_process_sfft_report_gen3() - Process Search FFT Report for gen3
  1177. * @p_fft_report: Pointer to fft report
  1178. * @p_sfft: Pointer to search fft report
  1179. *
  1180. * Process Search FFT Report for gen3
  1181. *
  1182. * Return: Success/Failure
  1183. */
  1184. int target_if_process_sfft_report_gen3(
  1185. struct spectral_phyerr_fft_report_gen3 *p_fft_report,
  1186. struct spectral_search_fft_info_gen3 *p_fft_info);
  1187. /**
  1188. * get_target_if_spectral_handle_from_pdev() - Get handle to target_if internal
  1189. * Spectral data
  1190. * @pdev: Pointer to pdev
  1191. *
  1192. * Return: Handle to target_if internal Spectral data on success, NULL on
  1193. * failure
  1194. */
  1195. static inline
  1196. struct target_if_spectral *get_target_if_spectral_handle_from_pdev(
  1197. struct wlan_objmgr_pdev *pdev)
  1198. {
  1199. struct target_if_spectral *spectral;
  1200. struct wlan_objmgr_psoc *psoc;
  1201. if (!pdev) {
  1202. spectral_err("pdev is null");
  1203. return NULL;
  1204. }
  1205. psoc = wlan_pdev_get_psoc(pdev);
  1206. if (!psoc) {
  1207. spectral_err("psoc is null");
  1208. return NULL;
  1209. }
  1210. spectral = (struct target_if_spectral *)
  1211. psoc->soc_cb.rx_ops.sptrl_rx_ops.sptrlro_get_target_handle(
  1212. pdev);
  1213. return spectral;
  1214. }
  1215. /**
  1216. * target_if_vdev_get_chan_freq() - Get the operating channel frequency of a
  1217. * given vdev
  1218. * @pdev: Pointer to vdev
  1219. *
  1220. * Get the operating channel frequency of a given vdev
  1221. *
  1222. * Return: Operating channel frequency of a vdev
  1223. */
  1224. static inline
  1225. int16_t target_if_vdev_get_chan_freq(struct wlan_objmgr_vdev *vdev)
  1226. {
  1227. struct wlan_objmgr_psoc *psoc = NULL;
  1228. psoc = wlan_vdev_get_psoc(vdev);
  1229. if (!psoc) {
  1230. spectral_err("psoc is NULL");
  1231. return -EINVAL;
  1232. }
  1233. return psoc->soc_cb.rx_ops.sptrl_rx_ops.sptrlro_vdev_get_chan_freq(
  1234. vdev);
  1235. }
  1236. /**
  1237. * target_if_vdev_get_chan_freq_seg2() - Get center frequency of secondary 80 of
  1238. * given vdev
  1239. * @vdev: Pointer to vdev
  1240. *
  1241. * Get the center frequency of secondary 80 of given vdev
  1242. *
  1243. * Return: center frequency of secondary 80
  1244. */
  1245. static inline
  1246. int16_t target_if_vdev_get_chan_freq_seg2(struct wlan_objmgr_vdev *vdev)
  1247. {
  1248. struct wlan_objmgr_psoc *psoc = NULL;
  1249. psoc = wlan_vdev_get_psoc(vdev);
  1250. if (!psoc) {
  1251. spectral_err("psoc is NULL");
  1252. return -EINVAL;
  1253. }
  1254. return psoc->soc_cb.rx_ops.sptrl_rx_ops.sptrlro_vdev_get_chan_freq_seg2(
  1255. vdev);
  1256. }
  1257. /**
  1258. * target_if_vdev_get_ch_width() - Get the operating channel bandwidth of a
  1259. * given vdev
  1260. * @pdev: Pointer to vdev
  1261. *
  1262. * Get the operating channel bandwidth of a given vdev
  1263. *
  1264. * Return: channel bandwidth enumeration corresponding to the vdev
  1265. */
  1266. static inline
  1267. enum phy_ch_width target_if_vdev_get_ch_width(struct wlan_objmgr_vdev *vdev)
  1268. {
  1269. struct wlan_objmgr_psoc *psoc = NULL;
  1270. psoc = wlan_vdev_get_psoc(vdev);
  1271. if (!psoc) {
  1272. spectral_err("psoc is NULL");
  1273. return CH_WIDTH_INVALID;
  1274. }
  1275. return psoc->soc_cb.rx_ops.sptrl_rx_ops.sptrlro_vdev_get_ch_width(
  1276. vdev);
  1277. }
  1278. /**
  1279. * target_if_vdev_get_sec20chan_freq_mhz() - Get the frequency of secondary
  1280. * 20 MHz channel for a given vdev
  1281. * @pdev: Pointer to vdev
  1282. *
  1283. * Get the frequency of secondary 20Mhz channel for a given vdev
  1284. *
  1285. * Return: Frequency of secondary 20Mhz channel for a given vdev
  1286. */
  1287. static inline
  1288. int target_if_vdev_get_sec20chan_freq_mhz(
  1289. struct wlan_objmgr_vdev *vdev,
  1290. uint16_t *sec20chan_freq)
  1291. {
  1292. struct wlan_objmgr_psoc *psoc = NULL;
  1293. psoc = wlan_vdev_get_psoc(vdev);
  1294. if (!psoc) {
  1295. spectral_err("psoc is NULL");
  1296. return -EINVAL;
  1297. }
  1298. return psoc->soc_cb.rx_ops.sptrl_rx_ops.
  1299. sptrlro_vdev_get_sec20chan_freq_mhz(vdev, sec20chan_freq);
  1300. }
  1301. /**
  1302. * target_if_spectral_set_rxchainmask() - Set Spectral Rx chainmask
  1303. * @pdev: Pointer to pdev
  1304. * @spectral_rx_chainmask: Spectral Rx chainmask
  1305. *
  1306. * Return: None
  1307. */
  1308. static inline
  1309. void target_if_spectral_set_rxchainmask(struct wlan_objmgr_pdev *pdev,
  1310. uint8_t spectral_rx_chainmask)
  1311. {
  1312. struct wlan_objmgr_psoc *psoc = NULL;
  1313. struct target_if_spectral *spectral = NULL;
  1314. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1315. psoc = wlan_pdev_get_psoc(pdev);
  1316. if (!psoc) {
  1317. spectral_err("psoc is NULL");
  1318. return;
  1319. }
  1320. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  1321. spectral_err("Invalid Spectral mode %u", smode);
  1322. return;
  1323. }
  1324. if (psoc->soc_cb.rx_ops.sptrl_rx_ops.
  1325. sptrlro_spectral_is_feature_disabled(psoc)) {
  1326. spectral_info("Spectral is disabled");
  1327. return;
  1328. }
  1329. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  1330. if (!spectral) {
  1331. spectral_err("Spectral target if object is null");
  1332. return;
  1333. }
  1334. /* set chainmask for all the modes */
  1335. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  1336. spectral->params[smode].ss_chn_mask = spectral_rx_chainmask;
  1337. }
  1338. /**
  1339. * target_if_spectral_process_phyerr() - Process Spectral PHY error
  1340. * @pdev: Pointer to pdev
  1341. * @data: PHY error data received from FW
  1342. * @datalen: Length of data
  1343. * @p_rfqual: Pointer to RF Quality information
  1344. * @p_chaninfo: Pointer to channel information
  1345. * @tsf: TSF time instance at which the Spectral sample was received
  1346. * @acs_stats: ACS stats
  1347. *
  1348. * Process Spectral PHY error by extracting necessary information from the data
  1349. * sent by FW, and send the extracted information to application layer.
  1350. *
  1351. * Return: None
  1352. */
  1353. static inline
  1354. void target_if_spectral_process_phyerr(
  1355. struct wlan_objmgr_pdev *pdev,
  1356. uint8_t *data, uint32_t datalen,
  1357. struct target_if_spectral_rfqual_info *p_rfqual,
  1358. struct target_if_spectral_chan_info *p_chaninfo,
  1359. uint64_t tsf64,
  1360. struct target_if_spectral_acs_stats *acs_stats)
  1361. {
  1362. struct target_if_spectral *spectral = NULL;
  1363. struct target_if_spectral_ops *p_sops = NULL;
  1364. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  1365. if (!spectral) {
  1366. spectral_err("Spectral target if object is null");
  1367. return;
  1368. }
  1369. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1370. p_sops->spectral_process_phyerr(spectral, data, datalen,
  1371. p_rfqual, p_chaninfo,
  1372. tsf64, acs_stats);
  1373. }
  1374. static QDF_STATUS
  1375. target_if_get_spectral_msg_type(enum spectral_scan_mode smode,
  1376. enum spectral_msg_type *msg_type) {
  1377. switch (smode) {
  1378. case SPECTRAL_SCAN_MODE_NORMAL:
  1379. *msg_type = SPECTRAL_MSG_NORMAL_MODE;
  1380. break;
  1381. case SPECTRAL_SCAN_MODE_AGILE:
  1382. *msg_type = SPECTRAL_MSG_AGILE_MODE;
  1383. break;
  1384. default:
  1385. spectral_err("Invalid spectral mode");
  1386. return QDF_STATUS_E_FAILURE;
  1387. }
  1388. return QDF_STATUS_SUCCESS;
  1389. }
  1390. /**
  1391. * init_160mhz_delivery_state_machine() - Initialize 160MHz Spectral
  1392. * state machine
  1393. * @spectral: Pointer to Spectral
  1394. *
  1395. * Initialize 160MHz Spectral state machine
  1396. *
  1397. * Return: void
  1398. */
  1399. static inline void
  1400. init_160mhz_delivery_state_machine(struct target_if_spectral *spectral)
  1401. {
  1402. spectral->state_160mhz_delivery =
  1403. SPECTRAL_REPORT_WAIT_PRIMARY80;
  1404. }
  1405. /**
  1406. * reset_160mhz_delivery_state_machine() - Reset 160MHz Spectral state machine
  1407. * @spectral: Pointer to Spectral
  1408. *
  1409. * Reset 160MHz Spectral state machine
  1410. *
  1411. * Return: void
  1412. */
  1413. static inline void
  1414. reset_160mhz_delivery_state_machine(struct target_if_spectral *spectral,
  1415. enum spectral_scan_mode smode)
  1416. {
  1417. enum spectral_msg_type smsg_type;
  1418. QDF_STATUS ret;
  1419. if (spectral->ch_width == CH_WIDTH_160MHZ) {
  1420. spectral->state_160mhz_delivery =
  1421. SPECTRAL_REPORT_WAIT_PRIMARY80;
  1422. ret = target_if_get_spectral_msg_type(smode, &smsg_type);
  1423. if (QDF_IS_STATUS_ERROR(ret)) {
  1424. spectral_err("Failed to reset 160 MHz state machine");
  1425. return;
  1426. }
  1427. spectral->nl_cb.free_sbuff(spectral->pdev_obj,
  1428. smsg_type);
  1429. }
  1430. }
  1431. /**
  1432. * is_secondaryseg_expected() - Is waiting for secondary 80 report
  1433. * @spectral: Pointer to Spectral
  1434. *
  1435. * Return true if secondary 80 report expected and mode is 160 MHz
  1436. *
  1437. * Return: true or false
  1438. */
  1439. static inline
  1440. bool is_secondaryseg_expected(struct target_if_spectral *spectral)
  1441. {
  1442. return
  1443. ((spectral->ch_width == CH_WIDTH_160MHZ) &&
  1444. (spectral->state_160mhz_delivery == SPECTRAL_REPORT_WAIT_SECONDARY80));
  1445. }
  1446. /**
  1447. * is_primaryseg_expected() - Is waiting for primary 80 report
  1448. * @spectral: Pointer to Spectral
  1449. *
  1450. * Return true if mode is 160 Mhz and primary 80 report expected or
  1451. * mode is not 160 Mhz
  1452. *
  1453. * Return: true or false
  1454. */
  1455. static inline
  1456. bool is_primaryseg_expected(struct target_if_spectral *spectral)
  1457. {
  1458. return
  1459. ((spectral->ch_width != CH_WIDTH_160MHZ) ||
  1460. ((spectral->ch_width == CH_WIDTH_160MHZ) &&
  1461. (spectral->state_160mhz_delivery == SPECTRAL_REPORT_WAIT_PRIMARY80)));
  1462. }
  1463. /**
  1464. * is_primaryseg_rx_inprog() - Is primary 80 report processing is in progress
  1465. * @spectral: Pointer to Spectral
  1466. *
  1467. * Is primary 80 report processing is in progress
  1468. *
  1469. * Return: true or false
  1470. */
  1471. static inline
  1472. bool is_primaryseg_rx_inprog(struct target_if_spectral *spectral)
  1473. {
  1474. return
  1475. ((spectral->ch_width != CH_WIDTH_160MHZ) ||
  1476. ((spectral->ch_width == CH_WIDTH_160MHZ) &&
  1477. ((spectral->spectral_gen == SPECTRAL_GEN2) ||
  1478. ((spectral->spectral_gen == SPECTRAL_GEN3) &&
  1479. (spectral->state_160mhz_delivery == SPECTRAL_REPORT_RX_PRIMARY80)))));
  1480. }
  1481. /**
  1482. * is_secondaryseg_rx_inprog() - Is secondary80 report processing is in progress
  1483. * @spectral: Pointer to Spectral
  1484. *
  1485. * Is secondary 80 report processing is in progress
  1486. *
  1487. * Return: true or false
  1488. */
  1489. static inline
  1490. bool is_secondaryseg_rx_inprog(struct target_if_spectral *spectral)
  1491. {
  1492. return
  1493. ((spectral->ch_width == CH_WIDTH_160MHZ) &&
  1494. ((spectral->spectral_gen == SPECTRAL_GEN2) ||
  1495. ((spectral->spectral_gen == SPECTRAL_GEN3) &&
  1496. (spectral->state_160mhz_delivery == SPECTRAL_REPORT_RX_SECONDARY80))));
  1497. }
  1498. /**
  1499. * target_if_160mhz_delivery_state_change() - State transition for 160Mhz
  1500. * Spectral
  1501. * @spectral: Pointer to spectral object
  1502. * @detector_id: Detector id
  1503. *
  1504. * Move the states of state machine for 160MHz spectral scan report receive
  1505. *
  1506. * Return: QDF_STATUS
  1507. */
  1508. QDF_STATUS
  1509. target_if_160mhz_delivery_state_change(struct target_if_spectral *spectral,
  1510. uint8_t detector_id);
  1511. /**
  1512. * target_if_sops_is_spectral_enabled() - Get whether Spectral is enabled
  1513. * @arg: Pointer to handle for Spectral target_if internal private data
  1514. * @smode: Spectral scan mode
  1515. *
  1516. * Function to check whether Spectral is enabled
  1517. *
  1518. * Return: True if Spectral is enabled, false if Spectral is not enabled
  1519. */
  1520. uint32_t target_if_sops_is_spectral_enabled(void *arg,
  1521. enum spectral_scan_mode smode);
  1522. /**
  1523. * target_if_sops_is_spectral_active() - Get whether Spectral is active
  1524. * @arg: Pointer to handle for Spectral target_if internal private data
  1525. * @smode: Spectral scan mode
  1526. *
  1527. * Function to check whether Spectral is active
  1528. *
  1529. * Return: True if Spectral is active, false if Spectral is not active
  1530. */
  1531. uint32_t target_if_sops_is_spectral_active(void *arg,
  1532. enum spectral_scan_mode smode);
  1533. /**
  1534. * target_if_sops_start_spectral_scan() - Start Spectral scan
  1535. * @arg: Pointer to handle for Spectral target_if internal private data
  1536. * @smode: Spectral scan mode
  1537. * @err: Pointer to error code
  1538. *
  1539. * Function to start spectral scan
  1540. *
  1541. * Return: 0 on success else failure
  1542. */
  1543. uint32_t target_if_sops_start_spectral_scan(void *arg,
  1544. enum spectral_scan_mode smode,
  1545. enum spectral_cp_error_code *err);
  1546. /**
  1547. * target_if_sops_stop_spectral_scan() - Stop Spectral scan
  1548. * @arg: Pointer to handle for Spectral target_if internal private data
  1549. * @smode: Spectral scan mode
  1550. *
  1551. * Function to stop spectral scan
  1552. *
  1553. * Return: 0 in case of success, -1 on failure
  1554. */
  1555. uint32_t target_if_sops_stop_spectral_scan(void *arg,
  1556. enum spectral_scan_mode smode);
  1557. /**
  1558. * target_if_spectral_get_extension_channel() - Get the current Extension
  1559. * channel (in MHz)
  1560. * @arg: Pointer to handle for Spectral target_if internal private data
  1561. *
  1562. * Return: Current Extension channel (in MHz) on success, 0 on failure or if
  1563. * extension channel is not present.
  1564. */
  1565. uint32_t target_if_spectral_get_extension_channel(void *arg);
  1566. /**
  1567. * target_if_spectral_get_current_channel() - Get the current channel (in MHz)
  1568. * @arg: Pointer to handle for Spectral target_if internal private data
  1569. *
  1570. * Return: Current channel (in MHz) on success, 0 on failure
  1571. */
  1572. uint32_t target_if_spectral_get_current_channel(void *arg);
  1573. /**
  1574. * target_if_spectral_reset_hw() - Reset the hardware
  1575. * @arg: Pointer to handle for Spectral target_if internal private data
  1576. *
  1577. * This is only a placeholder since it is not currently required in the offload
  1578. * case.
  1579. *
  1580. * Return: 0
  1581. */
  1582. uint32_t target_if_spectral_reset_hw(void *arg);
  1583. /**
  1584. * target_if_spectral_get_chain_noise_floor() - Get the Chain noise floor from
  1585. * Noisefloor history buffer
  1586. * @arg: Pointer to handle for Spectral target_if internal private data
  1587. * @nf_buf: Pointer to buffer into which chain Noise Floor data should be copied
  1588. *
  1589. * This is only a placeholder since it is not currently required in the offload
  1590. * case.
  1591. *
  1592. * Return: 0
  1593. */
  1594. uint32_t target_if_spectral_get_chain_noise_floor(void *arg, int16_t *nf_buf);
  1595. /**
  1596. * target_if_spectral_get_ext_noisefloor() - Get the extension channel
  1597. * noisefloor
  1598. * @arg: Pointer to handle for Spectral target_if internal private data
  1599. *
  1600. * This is only a placeholder since it is not currently required in the offload
  1601. * case.
  1602. *
  1603. * Return: 0
  1604. */
  1605. int8_t target_if_spectral_get_ext_noisefloor(void *arg);
  1606. /**
  1607. * target_if_spectral_get_ctl_noisefloor() - Get the control channel noisefloor
  1608. * @arg: Pointer to handle for Spectral target_if internal private data
  1609. *
  1610. * This is only a placeholder since it is not currently required in the offload
  1611. * case.
  1612. *
  1613. * Return: 0
  1614. */
  1615. int8_t target_if_spectral_get_ctl_noisefloor(void *arg);
  1616. /**
  1617. * target_if_spectral_get_capability() - Get whether a given Spectral hardware
  1618. * capability is available
  1619. * @arg: Pointer to handle for Spectral target_if internal private data
  1620. * @type: Spectral hardware capability type
  1621. *
  1622. * Return: True if the capability is available, false if the capability is not
  1623. * available
  1624. */
  1625. uint32_t target_if_spectral_get_capability(
  1626. void *arg, enum spectral_capability_type type);
  1627. /**
  1628. * target_if_spectral_set_rxfilter() - Set the RX Filter before Spectral start
  1629. * @arg: Pointer to handle for Spectral target_if internal private data
  1630. * @rxfilter: Rx filter to be used
  1631. *
  1632. * Note: This is only a placeholder function. It is not currently required since
  1633. * FW should be taking care of setting the required filters.
  1634. *
  1635. * Return: 0
  1636. */
  1637. uint32_t target_if_spectral_set_rxfilter(void *arg, int rxfilter);
  1638. /**
  1639. * target_if_spectral_sops_configure_params() - Configure user supplied Spectral
  1640. * parameters
  1641. * @arg: Pointer to handle for Spectral target_if internal private data
  1642. * @params: Spectral parameters
  1643. * @smode: Spectral scan mode
  1644. *
  1645. * Return: 0 in case of success, -1 on failure
  1646. */
  1647. uint32_t target_if_spectral_sops_configure_params(
  1648. void *arg, struct spectral_config *params,
  1649. enum spectral_scan_mode smode);
  1650. /**
  1651. * target_if_spectral_get_rxfilter() - Get the current RX Filter settings
  1652. * @arg: Pointer to handle for Spectral target_if internal private data
  1653. *
  1654. * Note: This is only a placeholder function. It is not currently required since
  1655. * FW should be taking care of setting the required filters.
  1656. *
  1657. * Return: 0
  1658. */
  1659. uint32_t target_if_spectral_get_rxfilter(void *arg);
  1660. /**
  1661. * target_if_pdev_spectral_deinit() - De-initialize target_if Spectral
  1662. * functionality for the given pdev
  1663. * @pdev: Pointer to pdev object
  1664. *
  1665. * Return: None
  1666. */
  1667. void target_if_pdev_spectral_deinit(struct wlan_objmgr_pdev *pdev);
  1668. /**
  1669. * target_if_set_spectral_config() - Set spectral config
  1670. * @pdev: Pointer to pdev object
  1671. * @threshtype: config type
  1672. * @value: config value
  1673. * @smode: Spectral scan mode
  1674. * @err: Pointer to Spectral error code
  1675. *
  1676. * API to set spectral configurations
  1677. *
  1678. * Return: QDF_STATUS_SUCCESS in case of success, else QDF_STATUS_E_FAILURE
  1679. */
  1680. QDF_STATUS target_if_set_spectral_config(struct wlan_objmgr_pdev *pdev,
  1681. const uint32_t threshtype,
  1682. const uint32_t value,
  1683. const enum spectral_scan_mode smode,
  1684. enum spectral_cp_error_code *err);
  1685. /**
  1686. * target_if_pdev_spectral_init() - Initialize target_if Spectral
  1687. * functionality for the given pdev
  1688. * @pdev: Pointer to pdev object
  1689. *
  1690. * Return: On success, pointer to Spectral target_if internal private data, on
  1691. * failure, NULL
  1692. */
  1693. void *target_if_pdev_spectral_init(struct wlan_objmgr_pdev *pdev);
  1694. /**
  1695. * target_if_spectral_sops_get_params() - Get user configured Spectral
  1696. * parameters
  1697. * @arg: Pointer to handle for Spectral target_if internal private data
  1698. * @params: Pointer to buffer into which Spectral parameters should be copied
  1699. * @smode: Spectral scan mode
  1700. *
  1701. * Return: 0 in case of success, -1 on failure
  1702. */
  1703. uint32_t target_if_spectral_sops_get_params(
  1704. void *arg, struct spectral_config *params,
  1705. enum spectral_scan_mode smode);
  1706. /**
  1707. * target_if_init_spectral_capability() - Initialize Spectral capability
  1708. * @spectral: Pointer to Spectral target_if internal private data
  1709. *
  1710. * This is a workaround.
  1711. *
  1712. * Return: QDF_STATUS
  1713. */
  1714. QDF_STATUS
  1715. target_if_init_spectral_capability(struct target_if_spectral *spectral);
  1716. /**
  1717. * target_if_start_spectral_scan() - Start spectral scan
  1718. * @pdev: Pointer to pdev object
  1719. * @smode: Spectral scan mode
  1720. * @err: Spectral error code
  1721. *
  1722. * API to start spectral scan
  1723. *
  1724. * Return: QDF_STATUS_SUCCESS in case of success, else QDF_STATUS_E_FAILURE
  1725. */
  1726. QDF_STATUS target_if_start_spectral_scan(struct wlan_objmgr_pdev *pdev,
  1727. enum spectral_scan_mode smode,
  1728. enum spectral_cp_error_code *err);
  1729. /**
  1730. * target_if_get_spectral_config() - Get spectral configuration
  1731. * @pdev: Pointer to pdev object
  1732. * @param: Pointer to spectral_config structure in which the configuration
  1733. * should be returned
  1734. * @smode: Spectral scan mode
  1735. *
  1736. * API to get the current spectral configuration
  1737. *
  1738. * Return: QDF_STATUS_SUCCESS in case of success, else QDF_STATUS_E_FAILURE
  1739. */
  1740. QDF_STATUS target_if_get_spectral_config(struct wlan_objmgr_pdev *pdev,
  1741. struct spectral_config *param,
  1742. enum spectral_scan_mode smode);
  1743. /**
  1744. * target_if_spectral_scan_enable_params() - Enable use of desired Spectral
  1745. * parameters
  1746. * @spectral: Pointer to Spectral target_if internal private data
  1747. * @spectral_params: Pointer to Spectral parameters
  1748. * @smode: Spectral scan mode
  1749. * @err: Spectral error code
  1750. *
  1751. * Enable use of desired Spectral parameters by configuring them into HW, and
  1752. * starting Spectral scan
  1753. *
  1754. * Return: 0 on success, 1 on failure
  1755. */
  1756. int target_if_spectral_scan_enable_params(
  1757. struct target_if_spectral *spectral,
  1758. struct spectral_config *spectral_params,
  1759. enum spectral_scan_mode smode,
  1760. enum spectral_cp_error_code *err);
  1761. /**
  1762. * target_if_is_spectral_active() - Get whether Spectral is active
  1763. * @pdev: Pointer to pdev object
  1764. * @smode: Spectral scan mode
  1765. *
  1766. * Return: True if Spectral is active, false if Spectral is not active
  1767. */
  1768. bool target_if_is_spectral_active(struct wlan_objmgr_pdev *pdev,
  1769. enum spectral_scan_mode smode);
  1770. /**
  1771. * target_if_is_spectral_enabled() - Get whether Spectral is enabled
  1772. * @pdev: Pointer to pdev object
  1773. * @smode: Spectral scan mode
  1774. *
  1775. * Return: True if Spectral is enabled, false if Spectral is not enabled
  1776. */
  1777. bool target_if_is_spectral_enabled(struct wlan_objmgr_pdev *pdev,
  1778. enum spectral_scan_mode smode);
  1779. /**
  1780. * target_if_set_debug_level() - Set debug level for Spectral
  1781. * @pdev: Pointer to pdev object
  1782. * @debug_level: Debug level
  1783. *
  1784. * Return: QDF_STATUS_SUCCESS in case of success, else QDF_STATUS_E_FAILURE
  1785. *
  1786. */
  1787. QDF_STATUS target_if_set_debug_level(struct wlan_objmgr_pdev *pdev,
  1788. uint32_t debug_level);
  1789. /**
  1790. * target_if_get_debug_level() - Get debug level for Spectral
  1791. * @pdev: Pointer to pdev object
  1792. *
  1793. * Return: Current debug level
  1794. */
  1795. uint32_t target_if_get_debug_level(struct wlan_objmgr_pdev *pdev);
  1796. /**
  1797. * target_if_get_spectral_capinfo() - Get Spectral capability information
  1798. * @pdev: Pointer to pdev object
  1799. * @scaps: Buffer into which data should be copied
  1800. *
  1801. * Return: QDF_STATUS_SUCCESS in case of success, else QDF_STATUS_E_FAILURE
  1802. */
  1803. QDF_STATUS target_if_get_spectral_capinfo(struct wlan_objmgr_pdev *pdev,
  1804. struct spectral_caps *scaps);
  1805. /**
  1806. * target_if_get_spectral_diagstats() - Get Spectral diagnostic statistics
  1807. * @pdev: Pointer to pdev object
  1808. * @stats: Buffer into which data should be copied
  1809. *
  1810. * Return: QDF_STATUS_SUCCESS in case of success, else QDF_STATUS_E_FAILURE
  1811. */
  1812. QDF_STATUS target_if_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev,
  1813. struct spectral_diag_stats *stats);
  1814. void target_if_register_wmi_spectral_cmd_ops(
  1815. struct wlan_objmgr_pdev *pdev,
  1816. struct wmi_spectral_cmd_ops *cmd_ops);
  1817. QDF_STATUS
  1818. target_if_160mhz_delivery_state_change(struct target_if_spectral *spectral,
  1819. uint8_t detector_id);
  1820. #ifdef DIRECT_BUF_RX_ENABLE
  1821. /**
  1822. * target_if_consume_sfft_report_gen3() - Process fft report for gen3
  1823. * @spectral: Pointer to spectral object
  1824. * @report: Pointer to spectral report
  1825. *
  1826. * Process fft report for gen3
  1827. *
  1828. * Return: Success/Failure
  1829. */
  1830. int
  1831. target_if_consume_spectral_report_gen3(
  1832. struct target_if_spectral *spectral,
  1833. struct spectral_report *report);
  1834. #endif
  1835. /**
  1836. * target_if_spectral_fw_hang() - Crash the FW from Spectral module
  1837. * @spectral: Pointer to Spectral LMAC object
  1838. *
  1839. * Return: QDF_STATUS of operation
  1840. */
  1841. QDF_STATUS target_if_spectral_fw_hang(struct target_if_spectral *spectral);
  1842. #ifdef WIN32
  1843. #pragma pack(pop, target_if_spectral)
  1844. #endif
  1845. #ifdef __ATTRIB_PACK
  1846. #undef __ATTRIB_PACK
  1847. #endif
  1848. #endif /* WLAN_CONV_SPECTRAL_ENABLE */
  1849. #endif /* _TARGET_IF_SPECTRAL_H_ */