target_if_spectral.h 68 KB

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