target_if_spectral.h 67 KB

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