target_if_spectral.h 99 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924
  1. /*
  2. * Copyright (c) 2011,2017-2021 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 <wlan_reg_services_api.h>
  26. #include <qdf_lock.h>
  27. #include <wlan_spectral_public_structs.h>
  28. #include <reg_services_public_struct.h>
  29. #ifdef DIRECT_BUF_RX_ENABLE
  30. #include <target_if_direct_buf_rx_api.h>
  31. #endif
  32. #ifdef WIN32
  33. #pragma pack(push, target_if_spectral, 1)
  34. #define __ATTRIB_PACK
  35. #else
  36. #ifndef __ATTRIB_PACK
  37. #define __ATTRIB_PACK __attribute__ ((packed))
  38. #endif
  39. #endif
  40. #include <spectral_defs_i.h>
  41. #include <wmi_unified_param.h>
  42. #define FREQ_OFFSET_10MHZ (10)
  43. #define FREQ_OFFSET_40MHZ (40)
  44. #define FREQ_OFFSET_80MHZ (80)
  45. #define FREQ_OFFSET_85MHZ (85)
  46. #ifndef SPECTRAL_USE_NL_BCAST
  47. #define SPECTRAL_USE_NL_BCAST (0)
  48. #endif
  49. #define STATUS_PASS 1
  50. #define STATUS_FAIL 0
  51. #undef spectral_dbg_line
  52. #define spectral_dbg_line() \
  53. spectral_debug("----------------------------------------------------")
  54. #undef spectral_ops_not_registered
  55. #define spectral_ops_not_registered(str) \
  56. spectral_info("SPECTRAL : %s not registered\n", (str))
  57. #undef not_yet_implemented
  58. #define not_yet_implemented() \
  59. spectral_info("SPECTRAL : %s : %d Not yet implemented\n", \
  60. __func__, __LINE__)
  61. #define SPECTRAL_HT20_NUM_BINS 56
  62. #define SPECTRAL_HT20_FFT_LEN 56
  63. #define SPECTRAL_HT20_DC_INDEX (SPECTRAL_HT20_FFT_LEN / 2)
  64. #define SPECTRAL_HT20_DATA_LEN 60
  65. #define SPECTRAL_HT20_TOTAL_DATA_LEN (SPECTRAL_HT20_DATA_LEN + 3)
  66. #define SPECTRAL_HT40_TOTAL_NUM_BINS 128
  67. #define SPECTRAL_HT40_DATA_LEN 135
  68. #define SPECTRAL_HT40_TOTAL_DATA_LEN (SPECTRAL_HT40_DATA_LEN + 3)
  69. #define SPECTRAL_HT40_FFT_LEN 128
  70. #define SPECTRAL_HT40_DC_INDEX (SPECTRAL_HT40_FFT_LEN / 2)
  71. /*
  72. * Used for the SWAR to obtain approximate combined rssi
  73. * in secondary 80Mhz segment
  74. */
  75. #define OFFSET_CH_WIDTH_20 65
  76. #define OFFSET_CH_WIDTH_40 62
  77. #define OFFSET_CH_WIDTH_80 56
  78. #define OFFSET_CH_WIDTH_160 50
  79. /* Min and max for relevant Spectral params */
  80. #define SPECTRAL_PARAM_FFT_SIZE_MIN_GEN2 (1)
  81. #define SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2 (9)
  82. #define SPECTRAL_PARAM_FFT_SIZE_MIN_GEN3 (5)
  83. #define SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT (9)
  84. #define SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000 (10)
  85. #define SPECTRAL_PARAM_FFT_SIZE_MIN_GEN3_BE (5)
  86. #define SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_BE (11)
  87. #define SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_BE_20MHZ (9)
  88. #define SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_BE_40MHZ (10)
  89. #define INVALID_FFT_SIZE (0xFFFF)
  90. #define SPECTRAL_PARAM_RPT_MODE_MIN (0)
  91. #define SPECTRAL_PARAM_RPT_MODE_MAX (3)
  92. #define MAX_FFTBIN_VALUE (255)
  93. #define SPECTRAL_DWORD_SIZE (4)
  94. /* DBR ring debug size for Spectral */
  95. #define SPECTRAL_DBR_RING_DEBUG_SIZE 512
  96. #ifdef BIG_ENDIAN_HOST
  97. #define SPECTRAL_MESSAGE_COPY_CHAR_ARRAY(destp, srcp, len) do { \
  98. int j; \
  99. uint32_t *src, *dest; \
  100. src = (uint32_t *)(srcp); \
  101. dest = (uint32_t *)(destp); \
  102. for (j = 0; j < roundup((len), sizeof(uint32_t)) / 4; j++) { \
  103. *(dest + j) = qdf_le32_to_cpu(*(src + j)); \
  104. } \
  105. } while (0)
  106. #else
  107. #define SPECTRAL_MESSAGE_COPY_CHAR_ARRAY(destp, srcp, len) \
  108. OS_MEMCPY((destp), (srcp), (len));
  109. #endif
  110. #define DUMMY_NF_VALUE (-123)
  111. /* 5 categories x (lower + upper) bands */
  112. #define MAX_INTERF 10
  113. #define HOST_MAX_ANTENNA 3
  114. /* Mask for time stamp from descriptor */
  115. #define SPECTRAL_TSMASK 0xFFFFFFFF
  116. #define SPECTRAL_SIGNATURE 0xdeadbeef
  117. /* Signature to write onto spectral buffer and then later validate */
  118. #define MEM_POISON_SIGNATURE (htobe32(0xdeadbeef))
  119. /* START of spectral GEN II HW specific details */
  120. #define SPECTRAL_PHYERR_SIGNATURE_GEN2 0xbb
  121. #define TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2 0xF9
  122. #define TLV_TAG_ADC_REPORT_GEN2 0xFA
  123. #define TLV_TAG_SEARCH_FFT_REPORT_GEN2 0xFB
  124. /**
  125. * The Maximum number of detector informations to be filled in the SAMP msg
  126. * is 3, only for 165MHz case. For all other cases this value will be 1.
  127. */
  128. #define MAX_NUM_DEST_DETECTOR_INFO (3)
  129. #define MAX_DETECTORS_PER_PDEV (3)
  130. #define FFT_BIN_SIZE_1BYTE (1)
  131. #ifdef OPTIMIZED_SAMP_MESSAGE
  132. /**
  133. * enum spectral_160mhz_report_delivery_state - 160 MHz state machine states
  134. * @SPECTRAL_REPORT_WAIT_PRIMARY80: Wait for primary80 report
  135. * @SPECTRAL_REPORT_WAIT_SECONDARY80: Wait for secondory 80 report
  136. */
  137. enum spectral_160mhz_report_delivery_state {
  138. SPECTRAL_REPORT_WAIT_PRIMARY80,
  139. SPECTRAL_REPORT_WAIT_SECONDARY80,
  140. };
  141. #else
  142. /**
  143. * enum spectral_160mhz_report_delivery_state - 160 MHz state machine states
  144. * @SPECTRAL_REPORT_WAIT_PRIMARY80: Wait for primary80 report
  145. * @SPECTRAL_REPORT_RX_PRIMARY80: Receive primary 80 report
  146. * @SPECTRAL_REPORT_WAIT_SECONDARY80: Wait for secondory 80 report
  147. * @SPECTRAL_REPORT_RX_SECONDARY80: Receive secondary 80 report
  148. */
  149. enum spectral_160mhz_report_delivery_state {
  150. SPECTRAL_REPORT_WAIT_PRIMARY80,
  151. SPECTRAL_REPORT_RX_PRIMARY80,
  152. SPECTRAL_REPORT_WAIT_SECONDARY80,
  153. SPECTRAL_REPORT_RX_SECONDARY80,
  154. };
  155. #endif /* OPTIMIZED_SAMP_MESSAGE */
  156. /**
  157. * enum spectral_freq_span_id - Spectral frequency span id
  158. * @SPECTRAL_FREQ_SPAN_ID_0: Frequency span 0
  159. * @SPECTRAL_FREQ_SPAN_ID_1: Frequency span 1
  160. * @SPECTRAL_FREQ_SPAN_ID_2: Frequency span 2
  161. */
  162. enum spectral_freq_span_id {
  163. SPECTRAL_FREQ_SPAN_ID_0,
  164. SPECTRAL_FREQ_SPAN_ID_1,
  165. SPECTRAL_FREQ_SPAN_ID_2,
  166. };
  167. /**
  168. * enum spectral_detector_id - Spectral detector id
  169. * @SPECTRAL_DETECTOR_ID_0: Spectral detector 0
  170. * @SPECTRAL_DETECTOR_ID_1: Spectral detector 1
  171. * @SPECTRAL_DETECTOR_ID_2: Spectral detector 2
  172. * @SPECTRAL_DETECTOR_ID_MAX: Max Spectral detector ID
  173. * @SPECTRAL_DETECTOR_ID_INVALID: Invalid Spectral detector ID
  174. */
  175. enum spectral_detector_id {
  176. SPECTRAL_DETECTOR_ID_0,
  177. SPECTRAL_DETECTOR_ID_1,
  178. SPECTRAL_DETECTOR_ID_2,
  179. SPECTRAL_DETECTOR_ID_MAX,
  180. SPECTRAL_DETECTOR_ID_INVALID = 0xff,
  181. };
  182. /**
  183. * struct spectral_search_fft_info_gen2 - spectral search fft report for gen2
  184. * @relpwr_db: Total bin power in db
  185. * @num_str_bins_ib: Number of strong bins
  186. * @base_pwr: Base power
  187. * @total_gain_info: Total gain
  188. * @fft_chn_idx: FFT chain on which report is originated
  189. * @avgpwr_db: Average power in db
  190. * @peak_mag: Peak power seen in the bins
  191. * @peak_inx: Index of bin holding peak power
  192. */
  193. struct spectral_search_fft_info_gen2 {
  194. uint32_t relpwr_db;
  195. uint32_t num_str_bins_ib;
  196. uint32_t base_pwr;
  197. uint32_t total_gain_info;
  198. uint32_t fft_chn_idx;
  199. uint32_t avgpwr_db;
  200. uint32_t peak_mag;
  201. int16_t peak_inx;
  202. };
  203. /*
  204. * XXX Check if we should be handling the endinness difference in some
  205. * other way opaque to the host
  206. */
  207. #ifdef BIG_ENDIAN_HOST
  208. /**
  209. * struct spectral_phyerr_tlv_gen2 - phyerr tlv info for big endian host
  210. * @signature: signature
  211. * @tag: tag
  212. * @length: length
  213. */
  214. struct spectral_phyerr_tlv_gen2 {
  215. uint8_t signature;
  216. uint8_t tag;
  217. uint16_t length;
  218. } __ATTRIB_PACK;
  219. #else
  220. /**
  221. * struct spectral_phyerr_tlv_gen2 - phyerr tlv info for little endian host
  222. * @length: length
  223. * @tag: tag
  224. * @signature: signature
  225. */
  226. struct spectral_phyerr_tlv_gen2 {
  227. uint16_t length;
  228. uint8_t tag;
  229. uint8_t signature;
  230. } __ATTRIB_PACK;
  231. #endif /* BIG_ENDIAN_HOST */
  232. /**
  233. * struct spectral_phyerr_hdr_gen2 - phyerr header for gen2 HW
  234. * @hdr_a: Header[0:31]
  235. * @hdr_b: Header[32:63]
  236. */
  237. struct spectral_phyerr_hdr_gen2 {
  238. uint32_t hdr_a;
  239. uint32_t hdr_b;
  240. };
  241. /*
  242. * Segment ID information for 80+80.
  243. *
  244. * If the HW micro-architecture specification extends this DWORD for other
  245. * purposes, then redefine+rename accordingly. For now, the specification
  246. * mentions only segment ID (though this doesn't require an entire DWORD)
  247. * without mention of any generic terminology for the DWORD, or any reservation.
  248. * We use nomenclature accordingly.
  249. */
  250. typedef uint32_t SPECTRAL_SEGID_INFO;
  251. /**
  252. * struct spectral_phyerr_fft_gen2 - fft info in phyerr event
  253. * @buf: fft report
  254. */
  255. struct spectral_phyerr_fft_gen2 {
  256. uint8_t buf[0];
  257. };
  258. /**
  259. * struct spectral_process_phyerr_info_gen2 - Processed phyerr info structures
  260. * needed to fill SAMP params for gen2
  261. * @p_rfqual: Pointer to RF quality info
  262. * @p_sfft: Pointer to Search fft report info
  263. * @pfft: Pointer to FFT info in Phyerr event
  264. * @acs_stats: Pointer to ACS stats struct
  265. * @tsf64: 64 bit TSF value
  266. * @seg_d : Segment ID
  267. */
  268. struct spectral_process_phyerr_info_gen2 {
  269. struct target_if_spectral_rfqual_info *p_rfqual;
  270. struct spectral_search_fft_info_gen2 *p_sfft;
  271. struct spectral_phyerr_fft_gen2 *pfft;
  272. struct target_if_spectral_acs_stats *acs_stats;
  273. uint64_t tsf64;
  274. uint8_t seg_id;
  275. };
  276. /* END of spectral GEN II HW specific details */
  277. /* START of spectral GEN III HW specific details */
  278. #define get_bitfield(value, size, pos) \
  279. (((value) >> (pos)) & ((1 << (size)) - 1))
  280. #define unsigned_to_signed(value, width) \
  281. (((value) >= (1 << ((width) - 1))) ? \
  282. (value - (1 << (width))) : (value))
  283. #define SSCAN_SUMMARY_REPORT_HDR_A_DETECTOR_ID_POS_GEN3 (29)
  284. #define SSCAN_SUMMARY_REPORT_HDR_A_DETECTOR_ID_SIZE_GEN3 (2)
  285. #define SSCAN_SUMMARY_REPORT_HDR_A_AGC_TOTAL_GAIN_POS_GEN3 (0)
  286. #define SSCAN_SUMMARY_REPORT_HDR_A_AGC_TOTAL_GAIN_SIZE_GEN3 (8)
  287. #define SSCAN_SUMMARY_REPORT_HDR_A_INBAND_PWR_DB_POS_GEN3 (18)
  288. #define SSCAN_SUMMARY_REPORT_HDR_A_INBAND_PWR_DB_SIZE_GEN3 (10)
  289. #define SSCAN_SUMMARY_REPORT_HDR_A_PRI80_POS_GEN3 (31)
  290. #define SSCAN_SUMMARY_REPORT_HDR_A_PRI80_SIZE_GEN3 (1)
  291. #define SSCAN_SUMMARY_REPORT_HDR_B_GAINCHANGE_POS_GEN3_V1 (30)
  292. #define SSCAN_SUMMARY_REPORT_HDR_B_GAINCHANGE_SIZE_GEN3_V1 (1)
  293. #define SSCAN_SUMMARY_REPORT_HDR_C_GAINCHANGE_POS_GEN3_V2 (16)
  294. #define SSCAN_SUMMARY_REPORT_HDR_C_GAINCHANGE_SIZE_GEN3_V2 (1)
  295. #define SPECTRAL_REPORT_LTS_HDR_LENGTH_POS_GEN3 (0)
  296. #define SPECTRAL_REPORT_LTS_HDR_LENGTH_SIZE_GEN3 (16)
  297. #define SPECTRAL_REPORT_LTS_TAG_POS_GEN3 (16)
  298. #define SPECTRAL_REPORT_LTS_TAG_SIZE_GEN3 (8)
  299. #define SPECTRAL_REPORT_LTS_SIGNATURE_POS_GEN3 (24)
  300. #define SPECTRAL_REPORT_LTS_SIGNATURE_SIZE_GEN3 (8)
  301. #define FFT_REPORT_HDR_A_DETECTOR_ID_POS_GEN3 (0)
  302. #define FFT_REPORT_HDR_A_DETECTOR_ID_SIZE_GEN3 (2)
  303. #define FFT_REPORT_HDR_A_FFT_NUM_POS_GEN3 (2)
  304. #define FFT_REPORT_HDR_A_FFT_NUM_SIZE_GEN3 (3)
  305. #define FFT_REPORT_HDR_A_RADAR_CHECK_POS_GEN3_V1 (5)
  306. #define FFT_REPORT_HDR_A_RADAR_CHECK_SIZE_GEN3_V1 (12)
  307. #define FFT_REPORT_HDR_A_RADAR_CHECK_POS_GEN3_V2 (5)
  308. #define FFT_REPORT_HDR_A_RADAR_CHECK_SIZE_GEN3_V2 (14)
  309. #define FFT_REPORT_HDR_A_PEAK_INDEX_POS_GEN3_V1 (17)
  310. #define FFT_REPORT_HDR_A_PEAK_INDEX_SIZE_GEN3_V1 (11)
  311. #define FFT_REPORT_HDR_A_PEAK_INDEX_POS_GEN3_V2 (19)
  312. #define FFT_REPORT_HDR_A_PEAK_INDEX_SIZE_GEN3_V2 (11)
  313. #define FFT_REPORT_HDR_A_CHAIN_INDEX_POS_GEN3_V1 (28)
  314. #define FFT_REPORT_HDR_A_CHAIN_INDEX_SIZE_GEN3_V1 (3)
  315. #define FFT_REPORT_HDR_B_CHAIN_INDEX_POS_GEN3_V2 (0)
  316. #define FFT_REPORT_HDR_B_CHAIN_INDEX_SIZE_GEN3_V2 (3)
  317. #define FFT_REPORT_HDR_B_BASE_PWR_POS_GEN3_V1 (0)
  318. #define FFT_REPORT_HDR_B_BASE_PWR_SIZE_GEN3_V1 (9)
  319. #define FFT_REPORT_HDR_B_BASE_PWR_POS_GEN3_V2 (3)
  320. #define FFT_REPORT_HDR_B_BASE_PWR_SIZE_GEN3_V2 (9)
  321. #define FFT_REPORT_HDR_B_TOTAL_GAIN_POS_GEN3_V1 (9)
  322. #define FFT_REPORT_HDR_B_TOTAL_GAIN_SIZE_GEN3_V1 (8)
  323. #define FFT_REPORT_HDR_B_TOTAL_GAIN_POS_GEN3_V2 (12)
  324. #define FFT_REPORT_HDR_B_TOTAL_GAIN_SIZE_GEN3_V2 (8)
  325. #define FFT_REPORT_HDR_C_NUM_STRONG_BINS_POS_GEN3 (0)
  326. #define FFT_REPORT_HDR_C_NUM_STRONG_BINS_SIZE_GEN3 (8)
  327. #define FFT_REPORT_HDR_C_PEAK_MAGNITUDE_POS_GEN3 (8)
  328. #define FFT_REPORT_HDR_C_PEAK_MAGNITUDE_SIZE_GEN3 (10)
  329. #define FFT_REPORT_HDR_C_AVG_PWR_POS_GEN3 (18)
  330. #define FFT_REPORT_HDR_C_AVG_PWR_SIZE_GEN3 (7)
  331. #define FFT_REPORT_HDR_C_RELATIVE_PWR_POS_GEN3 (25)
  332. #define FFT_REPORT_HDR_C_RELATIVE_PWR_SIZE_GEN3 (7)
  333. #define SPECTRAL_PHYERR_SIGNATURE_GEN3 (0xFA)
  334. #define TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3 (0x02)
  335. #define TLV_TAG_SEARCH_FFT_REPORT_GEN3 (0x03)
  336. #define SPECTRAL_PHYERR_TLVSIZE_GEN3 (4)
  337. #define NUM_SPECTRAL_DETECTORS_GEN3_V1 (3)
  338. #define NUM_SPECTRAL_DETECTORS_GEN3_V2 (2)
  339. #define FFT_REPORT_HEADER_LENGTH_GEN3_V2 (24)
  340. #define FFT_REPORT_HEADER_LENGTH_GEN3_V1 (16)
  341. #define NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V1 (0)
  342. #define NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V2 (16)
  343. #define SPECTRAL_PHYERR_HDR_LTS_POS \
  344. (offsetof(struct spectral_phyerr_fft_report_gen3, fft_hdr_lts))
  345. #define SPECTRAL_FFT_BINS_POS \
  346. (offsetof(struct spectral_phyerr_fft_report_gen3, buf))
  347. /**
  348. * struct phyerr_info - spectral search fft report for gen3
  349. * @data: handle to phyerror buffer
  350. * @datalen: length of phyerror bufer
  351. * @p_rfqual: rf quality matrices
  352. * @p_chaninfo: pointer to chaninfo
  353. * @tsf64: 64 bit TSF
  354. * @acs_stats: acs stats
  355. */
  356. struct phyerr_info {
  357. uint8_t *data;
  358. uint32_t datalen;
  359. struct target_if_spectral_rfqual_info *p_rfqual;
  360. struct target_if_spectral_chan_info *p_chaninfo;
  361. uint64_t tsf64;
  362. struct target_if_spectral_acs_stats *acs_stats;
  363. };
  364. /**
  365. * struct spectral_search_fft_info_gen3 - spectral search fft report for gen3
  366. * @timestamp: Timestamp at which fft report was generated
  367. * @last_raw_timestamp: Previous FFT report's raw timestamp
  368. * @adjusted_timestamp: Adjusted timestamp to account for target reset
  369. * @fft_detector_id: Which radio generated this report
  370. * @fft_num: The FFT count number. Set to 0 for short FFT.
  371. * @fft_radar_check: NA for spectral
  372. * @fft_peak_sidx: Index of bin with maximum power
  373. * @fft_chn_idx: Rx chain index
  374. * @fft_base_pwr_db: Base power in dB
  375. * @fft_total_gain_db: Total gain in dB
  376. * @fft_num_str_bins_ib: Number of strong bins in the report
  377. * @fft_peak_mag: Peak magnitude
  378. * @fft_avgpwr_db: Average power in dB
  379. * @fft_relpwr_db: Relative power in dB
  380. * @fft_bin_count: Number of FFT bins in the FFT report
  381. * @fft_bin_size: Size of one FFT bin in bytes
  382. * @bin_pwr_data: Contains FFT bins extracted from the report
  383. */
  384. struct spectral_search_fft_info_gen3 {
  385. uint32_t timestamp;
  386. uint32_t last_raw_timestamp;
  387. uint32_t adjusted_timestamp;
  388. uint32_t fft_detector_id;
  389. uint32_t fft_num;
  390. uint32_t fft_radar_check;
  391. int32_t fft_peak_sidx;
  392. uint32_t fft_chn_idx;
  393. uint32_t fft_base_pwr_db;
  394. uint32_t fft_total_gain_db;
  395. uint32_t fft_num_str_bins_ib;
  396. int32_t fft_peak_mag;
  397. uint32_t fft_avgpwr_db;
  398. uint32_t fft_relpwr_db;
  399. uint32_t fft_bin_count;
  400. uint8_t fft_bin_size;
  401. uint8_t *bin_pwr_data;
  402. };
  403. /**
  404. * struct spectral_phyerr_sfftreport_gen3 - fft info in phyerr event
  405. * @fft_timestamp: Timestamp at which fft report was generated
  406. * @fft_hdr_lts: length, tag, signature fields
  407. * @hdr_a: Header[0:31]
  408. * @hdr_b: Header[32:63]
  409. * @hdr_c: Header[64:95]
  410. * @resv: Header[96:127]
  411. * @buf: fft bins
  412. */
  413. struct spectral_phyerr_fft_report_gen3 {
  414. uint32_t fft_timestamp;
  415. uint32_t fft_hdr_lts;
  416. uint32_t hdr_a;
  417. uint32_t hdr_b;
  418. uint32_t hdr_c;
  419. uint32_t resv;
  420. uint8_t buf[0];
  421. } __ATTRIB_PACK;
  422. /**
  423. * struct sscan_report_fields_gen3 - Fields of spectral report
  424. * @sscan_agc_total_gain: The AGC total gain in DB.
  425. * @inband_pwr_db: The in-band power of the signal in 1/2 DB steps
  426. * @sscan_gainchange: This bit is set to 1 if a gainchange occurred during
  427. * the spectral scan FFT. Software may choose to
  428. * disregard the results.
  429. * @sscan_pri80: This is set to 1 to indicate that the Spectral scan was
  430. * performed on the pri80 segment. Software may choose to
  431. * disregard the FFT sample if this is set to 1 but detector ID
  432. * does not correspond to the ID for the pri80 segment.
  433. * @sscan_detector_id: Detector ID in Spectral scan report
  434. */
  435. struct sscan_report_fields_gen3 {
  436. uint8_t sscan_agc_total_gain;
  437. int16_t inband_pwr_db;
  438. uint8_t sscan_gainchange;
  439. uint8_t sscan_pri80;
  440. uint8_t sscan_detector_id;
  441. };
  442. /**
  443. * struct spectral_sscan_summary_report_gen3 - Spectral summary report
  444. * event
  445. * @sscan_timestamp: Timestamp at which fft report was generated
  446. * @sscan_hdr_lts: length, tag, signature fields
  447. * @hdr_a: Header[0:31]
  448. * @resv: Header[32:63]
  449. * @hdr_b: Header[64:95]
  450. * @hdr_c: Header[96:127]
  451. */
  452. struct spectral_sscan_summary_report_gen3 {
  453. u_int32_t sscan_timestamp;
  454. u_int32_t sscan_hdr_lts;
  455. u_int32_t hdr_a;
  456. u_int32_t res1;
  457. u_int32_t hdr_b;
  458. u_int32_t hdr_c;
  459. } __ATTRIB_PACK;
  460. #ifdef DIRECT_BUF_RX_ENABLE
  461. /**
  462. * struct Spectral_report - spectral report
  463. * @data: Report buffer
  464. * @noisefloor: Noise floor values
  465. * @reset_delay: Time taken for warm reset in us
  466. * @cfreq1: center frequency 1
  467. * @cfreq2: center frequency 2
  468. * @ch_width: channel width
  469. */
  470. struct spectral_report {
  471. uint8_t *data;
  472. int32_t noisefloor[DBR_MAX_CHAINS];
  473. uint32_t reset_delay;
  474. uint32_t cfreq1;
  475. uint32_t cfreq2;
  476. uint32_t ch_width;
  477. };
  478. #endif
  479. /* END of spectral GEN III HW specific details */
  480. typedef signed char pwr_dbm;
  481. /**
  482. * enum spectral_gen - spectral hw generation
  483. * @SPECTRAL_GEN1 : spectral hw gen 1
  484. * @SPECTRAL_GEN2 : spectral hw gen 2
  485. * @SPECTRAL_GEN3 : spectral hw gen 3
  486. */
  487. enum spectral_gen {
  488. SPECTRAL_GEN1,
  489. SPECTRAL_GEN2,
  490. SPECTRAL_GEN3,
  491. };
  492. /**
  493. * enum spectral_fftbin_size_war - spectral fft bin size war
  494. * @SPECTRAL_FFTBIN_SIZE_NO_WAR : No WAR applicable for Spectral FFT bin size
  495. * @SPECTRAL_FFTBIN_SIZE_2BYTE_TO_1BYTE : Spectral FFT bin size: Retain only
  496. * least significant byte from 2 byte
  497. * FFT bin transferred by HW
  498. * @SPECTRAL_FFTBIN_SIZE_4BYTE_TO_1BYTE : Spectral FFT bin size: Retain only
  499. * least significant byte from 4 byte
  500. * FFT bin transferred by HW
  501. */
  502. enum spectral_fftbin_size_war {
  503. SPECTRAL_FFTBIN_SIZE_NO_WAR = 0,
  504. SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE = 1,
  505. SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE = 2,
  506. };
  507. /**
  508. * enum spectral_report_format_version - This represents the report format
  509. * version number within each Spectral generation.
  510. * @SPECTRAL_REPORT_FORMAT_VERSION_1 : version 1
  511. * @SPECTRAL_REPORT_FORMAT_VERSION_2 : version 2
  512. */
  513. enum spectral_report_format_version {
  514. SPECTRAL_REPORT_FORMAT_VERSION_1,
  515. SPECTRAL_REPORT_FORMAT_VERSION_2,
  516. };
  517. /**
  518. * struct spectral_fft_bin_len_adj_swar - Encapsulate information required for
  519. * Spectral FFT bin length adjusting software WARS.
  520. * @inband_fftbin_size_adj: Whether to carry out FFT bin size adjustment for
  521. * in-band report format. This would be required on some chipsets under the
  522. * following circumstances: In report mode 2 only the in-band bins are DMA'ed.
  523. * Scatter/gather is used. However, the HW generates all bins, not just in-band,
  524. * and reports the number of bins accordingly. The subsystem arranging for the
  525. * DMA cannot change this value. On such chipsets the adjustment required at the
  526. * host driver is to check if report format is 2, and if so halve the number of
  527. * bins reported to get the number actually DMA'ed.
  528. * @null_fftbin_adj: Whether to remove NULL FFT bins for report mode (1) in
  529. * which only summary of metrics for each completed FFT + spectral scan summary
  530. * report are to be provided. This would be required on some chipsets under the
  531. * following circumstances: In report mode 1, HW reports a length corresponding
  532. * to all bins, and provides bins with value 0. This is because the subsystem
  533. * arranging for the FFT information does not arrange for DMA of FFT bin values
  534. * (as expected), but cannot arrange for a smaller length to be reported by HW.
  535. * In these circumstances, the driver would have to disregard the NULL bins and
  536. * report a bin count of 0 to higher layers.
  537. * @packmode_fftbin_size_adj: Pack mode in HW refers to packing of each Spectral
  538. * FFT bin into 2 bytes. But due to a bug HW reports 2 times the expected length
  539. * when packmode is enabled. This SWAR compensates this bug by dividing the
  540. * length with 2.
  541. * @fftbin_size_war: Type of FFT bin size SWAR
  542. */
  543. struct spectral_fft_bin_len_adj_swar {
  544. u_int8_t inband_fftbin_size_adj;
  545. u_int8_t null_fftbin_adj;
  546. uint8_t packmode_fftbin_size_adj;
  547. enum spectral_fftbin_size_war fftbin_size_war;
  548. };
  549. /**
  550. * struct spectral_report_params - Parameters related to format of Spectral
  551. * report.
  552. * @version: This represents the report format version number within each
  553. * Spectral generation.
  554. * @ssumaary_padding_bytes: Number of bytes of padding after Spectral summary
  555. * report
  556. * @fft_report_hdr_len: Number of bytes in the header of the FFT report. This
  557. * has to be subtracted from the length field of FFT report to find the length
  558. * of FFT bins.
  559. * @fragmentation_160: This indicates whether Spectral reports in 160/80p80 is
  560. * fragmented.
  561. * @detid_mode_table: Detector ID to Spectral scan mode table
  562. * @num_spectral_detectors: Total number of Spectral detectors
  563. * @marker: Describes the boundaries of pri80, 5 MHz and sec80 bins
  564. * @hw_fft_bin_width: FFT bin width reported by the HW
  565. */
  566. struct spectral_report_params {
  567. enum spectral_report_format_version version;
  568. uint8_t ssumaary_padding_bytes;
  569. uint8_t fft_report_hdr_len;
  570. bool fragmentation_160[SPECTRAL_SCAN_MODE_MAX];
  571. enum spectral_scan_mode detid_mode_table[SPECTRAL_DETECTOR_ID_MAX];
  572. uint8_t num_spectral_detectors;
  573. struct spectral_fft_bin_markers_160_165mhz
  574. marker[SPECTRAL_SCAN_MODE_MAX];
  575. uint8_t hw_fft_bin_width;
  576. };
  577. /**
  578. * struct spectral_param_min_max - Spectral parameter minimum and maximum values
  579. * @fft_size_min: Minimum value of fft_size
  580. * @fft_size_max: Maximum value of fft_size for each BW
  581. */
  582. struct spectral_param_min_max {
  583. uint16_t fft_size_min;
  584. uint16_t fft_size_max[CH_WIDTH_MAX];
  585. };
  586. /**
  587. * struct spectral_timestamp_swar - Spectral time stamp WAR related parameters
  588. * @timestamp_war_offset: Offset to be added to correct timestamp
  589. * @target_reset_count: Number of times target exercised the reset routine
  590. * @last_fft_timestamp: last fft report timestamp
  591. */
  592. struct spectral_timestamp_war {
  593. uint32_t timestamp_war_offset[SPECTRAL_SCAN_MODE_MAX];
  594. uint64_t target_reset_count;
  595. uint32_t last_fft_timestamp[SPECTRAL_SCAN_MODE_MAX];
  596. };
  597. #if ATH_PERF_PWR_OFFLOAD
  598. /**
  599. * enum target_if_spectral_info - Enumerations for specifying which spectral
  600. * information (among parameters and states)
  601. * is desired.
  602. * @TARGET_IF_SPECTRAL_INFO_ACTIVE: Indicated whether spectral is active
  603. * @TARGET_IF_SPECTRAL_INFO_ENABLED: Indicated whether spectral is enabled
  604. * @TARGET_IF_SPECTRAL_INFO_PARAMS: Config params
  605. */
  606. enum target_if_spectral_info {
  607. TARGET_IF_SPECTRAL_INFO_ACTIVE,
  608. TARGET_IF_SPECTRAL_INFO_ENABLED,
  609. TARGET_IF_SPECTRAL_INFO_PARAMS,
  610. };
  611. #endif /* ATH_PERF_PWR_OFFLOAD */
  612. /* forward declaration */
  613. struct target_if_spectral;
  614. /**
  615. * struct target_if_spectral_chan_info - Channel information
  616. * @center_freq1: center frequency 1 in MHz
  617. * @center_freq2: center frequency 2 in MHz -valid only for
  618. * 11ACVHT 80PLUS80 mode
  619. * @chan_width: channel width in MHz
  620. */
  621. struct target_if_spectral_chan_info {
  622. uint16_t center_freq1;
  623. uint16_t center_freq2;
  624. uint8_t chan_width;
  625. };
  626. /**
  627. * struct target_if_spectral_acs_stats - EACS stats from spectral samples
  628. * @nfc_ctl_rssi: Control chan rssi
  629. * @nfc_ext_rssi: Extension chan rssi
  630. * @ctrl_nf: Control chan Noise Floor
  631. * @ext_nf: Extension chan Noise Floor
  632. */
  633. struct target_if_spectral_acs_stats {
  634. int8_t nfc_ctl_rssi;
  635. int8_t nfc_ext_rssi;
  636. int8_t ctrl_nf;
  637. int8_t ext_nf;
  638. };
  639. /**
  640. * struct target_if_spectral_perchain_rssi_info - per chain rssi info
  641. * @rssi_pri20: Rssi of primary 20 Mhz
  642. * @rssi_sec20: Rssi of secondary 20 Mhz
  643. * @rssi_sec40: Rssi of secondary 40 Mhz
  644. * @rssi_sec80: Rssi of secondary 80 Mhz
  645. */
  646. struct target_if_spectral_perchain_rssi_info {
  647. int8_t rssi_pri20;
  648. int8_t rssi_sec20;
  649. int8_t rssi_sec40;
  650. int8_t rssi_sec80;
  651. };
  652. /**
  653. * struct target_if_spectral_rfqual_info - RF measurement information
  654. * @rssi_comb: RSSI Information
  655. * @pc_rssi_info: XXX : For now, we know we are getting information
  656. * for only 4 chains at max. For future extensions
  657. * use a define
  658. * @noise_floor: Noise floor information
  659. */
  660. struct target_if_spectral_rfqual_info {
  661. int8_t rssi_comb;
  662. struct target_if_spectral_perchain_rssi_info pc_rssi_info[4];
  663. int16_t noise_floor[4];
  664. };
  665. #define GET_TARGET_IF_SPECTRAL_OPS(spectral) \
  666. ((struct target_if_spectral_ops *)(&((spectral)->spectral_ops)))
  667. /**
  668. * struct target_if_spectral_ops - spectral low level ops table
  669. * @get_tsf64: Get 64 bit TSF value
  670. * @get_capability: Get capability info
  671. * @set_rxfilter: Set rx filter
  672. * @get_rxfilter: Get rx filter
  673. * @is_spectral_active: Check whether icm is active
  674. * @is_spectral_enabled: Check whether spectral is enabled
  675. * @start_spectral_scan: Start spectral scan
  676. * @stop_spectral_scan: Stop spectral scan
  677. * @get_extension_channel: Get extension channel
  678. * @get_ctl_noisefloor: Get control noise floor
  679. * @get_ext_noisefloor: Get extension noise floor
  680. * @configure_spectral: Set spectral configurations
  681. * @get_spectral_config: Get spectral configurations
  682. * @get_ent_spectral_mask: Get spectral mask
  683. * @get_mac_address: Get mac address
  684. * @get_current_channel: Get current channel
  685. * @reset_hw: Reset HW
  686. * @get_chain_noise_floor: Get Channel noise floor
  687. * @spectral_process_phyerr: Process phyerr event
  688. * @process_spectral_report: Process spectral report
  689. * @byte_swap_headers: Apply byte-swap on report headers
  690. * @byte_swap_fft_bins: Apply byte-swap on FFT bins
  691. */
  692. struct target_if_spectral_ops {
  693. uint64_t (*get_tsf64)(void *arg);
  694. uint32_t (*get_capability)(
  695. void *arg, enum spectral_capability_type type);
  696. uint32_t (*set_rxfilter)(void *arg, int rxfilter);
  697. uint32_t (*get_rxfilter)(void *arg);
  698. uint32_t (*is_spectral_active)(void *arg,
  699. enum spectral_scan_mode smode);
  700. uint32_t (*is_spectral_enabled)(void *arg,
  701. enum spectral_scan_mode smode);
  702. uint32_t (*start_spectral_scan)(void *arg,
  703. enum spectral_scan_mode smode,
  704. enum spectral_cp_error_code *err);
  705. uint32_t (*stop_spectral_scan)(void *arg,
  706. enum spectral_scan_mode smode);
  707. uint32_t (*get_extension_channel)(void *arg,
  708. enum spectral_scan_mode smode);
  709. int8_t (*get_ctl_noisefloor)(void *arg);
  710. int8_t (*get_ext_noisefloor)(void *arg);
  711. uint32_t (*configure_spectral)(
  712. void *arg,
  713. struct spectral_config *params,
  714. enum spectral_scan_mode smode);
  715. uint32_t (*get_spectral_config)(
  716. void *arg,
  717. struct spectral_config *params,
  718. enum spectral_scan_mode smode);
  719. uint32_t (*get_ent_spectral_mask)(void *arg);
  720. uint32_t (*get_mac_address)(void *arg, char *addr);
  721. uint32_t (*get_current_channel)(void *arg,
  722. enum spectral_scan_mode smode);
  723. uint32_t (*reset_hw)(void *arg);
  724. uint32_t (*get_chain_noise_floor)(void *arg, int16_t *nf_buf);
  725. int (*spectral_process_phyerr)(struct target_if_spectral *spectral,
  726. uint8_t *data, uint32_t datalen,
  727. struct target_if_spectral_rfqual_info *p_rfqual,
  728. struct target_if_spectral_chan_info *p_chaninfo,
  729. uint64_t tsf64,
  730. struct target_if_spectral_acs_stats *acs_stats);
  731. int (*process_spectral_report)(struct wlan_objmgr_pdev *pdev,
  732. void *payload);
  733. QDF_STATUS (*byte_swap_headers)(
  734. struct target_if_spectral *spectral,
  735. void *data);
  736. QDF_STATUS (*byte_swap_fft_bins)(
  737. const struct spectral_report_params *rparams,
  738. void *bin_pwr_data, size_t num_fftbins);
  739. };
  740. /**
  741. * struct target_if_spectral_stats - spectral stats info
  742. * @num_spectral_detects: Total num. of spectral detects
  743. * @total_phy_errors: Total number of phyerrors
  744. * @owl_phy_errors: Indicated phyerrors in old gen1 chipsets
  745. * @pri_phy_errors: Phyerrors in primary channel
  746. * @ext_phy_errors: Phyerrors in secondary channel
  747. * @dc_phy_errors: Phyerrors due to dc
  748. * @early_ext_phy_errors: Early secondary channel phyerrors
  749. * @bwinfo_errors: Bandwidth info errors
  750. * @datalen_discards: Invalid data length errors, seen in gen1 chipsets
  751. * @rssi_discards bw: Indicates reports dropped due to RSSI threshold
  752. * @last_reset_tstamp: Last reset time stamp
  753. */
  754. struct target_if_spectral_stats {
  755. uint32_t num_spectral_detects;
  756. uint32_t total_phy_errors;
  757. uint32_t owl_phy_errors;
  758. uint32_t pri_phy_errors;
  759. uint32_t ext_phy_errors;
  760. uint32_t dc_phy_errors;
  761. uint32_t early_ext_phy_errors;
  762. uint32_t bwinfo_errors;
  763. uint32_t datalen_discards;
  764. uint32_t rssi_discards;
  765. uint64_t last_reset_tstamp;
  766. };
  767. /**
  768. * struct target_if_spectral_event - spectral event structure
  769. * @se_ts: Original 15 bit recv timestamp
  770. * @se_full_ts: 64-bit full timestamp from interrupt time
  771. * @se_rssi: Rssi of spectral event
  772. * @se_bwinfo: Rssi of spectral event
  773. * @se_dur: Duration of spectral pulse
  774. * @se_chanindex: Channel of event
  775. * @se_list: List of spectral events
  776. */
  777. struct target_if_spectral_event {
  778. uint32_t se_ts;
  779. uint64_t se_full_ts;
  780. uint8_t se_rssi;
  781. uint8_t se_bwinfo;
  782. uint8_t se_dur;
  783. uint8_t se_chanindex;
  784. STAILQ_ENTRY(spectral_event) se_list;
  785. };
  786. /**
  787. * struct target_if_chain_noise_pwr_info - Noise power info for each channel
  788. * @rptcount: Count of reports in pwr array
  789. * @un_cal_nf: Uncalibrated noise floor
  790. * @factory_cal_nf: Noise floor as calibrated at the factory for module
  791. * @median_pwr: Median power (median of pwr array)
  792. * @pwr: Power reports
  793. */
  794. struct target_if_chain_noise_pwr_info {
  795. int rptcount;
  796. pwr_dbm un_cal_nf;
  797. pwr_dbm factory_cal_nf;
  798. pwr_dbm median_pwr;
  799. pwr_dbm pwr[];
  800. } __ATTRIB_PACK;
  801. /**
  802. * struct target_if_spectral_chan_stats - Channel information
  803. * @cycle_count: Cycle count
  804. * @channel_load: Channel load
  805. * @per: Period
  806. * @noisefloor: Noise floor
  807. * @comp_usablity: Computed usability
  808. * @maxregpower: Maximum allowed regulatary power
  809. * @comp_usablity_sec80: Computed usability of secondary 80 Mhz
  810. * @maxregpower_sec80: Max regulatory power in secondary 80 Mhz
  811. */
  812. struct target_if_spectral_chan_stats {
  813. int cycle_count;
  814. int channel_load;
  815. int per;
  816. int noisefloor;
  817. uint16_t comp_usablity;
  818. int8_t maxregpower;
  819. uint16_t comp_usablity_sec80;
  820. int8_t maxregpower_sec80;
  821. };
  822. #if ATH_PERF_PWR_OFFLOAD
  823. /**
  824. * struct target_if_spectral_cache - Cache used to minimize WMI operations
  825. * in offload architecture
  826. * @osc_spectral_enabled: Whether Spectral is enabled
  827. * @osc_spectral_active: Whether spectral is active
  828. * XXX: Ideally, we should NOT cache this
  829. * since the hardware can self clear the bit,
  830. * the firmware can possibly stop spectral due to
  831. * intermittent off-channel activity, etc
  832. * A WMI read command should be introduced to handle
  833. * this This will be discussed.
  834. * @osc_params: Spectral parameters
  835. * @osc_is_valid: Whether the cache is valid
  836. */
  837. struct target_if_spectral_cache {
  838. uint8_t osc_spectral_enabled;
  839. uint8_t osc_spectral_active;
  840. struct spectral_config osc_params;
  841. uint8_t osc_is_valid;
  842. };
  843. /**
  844. * struct target_if_spectral_param_state_info - Structure used to represent and
  845. * manage spectral information
  846. * (parameters and states)
  847. * @osps_lock: Lock to synchronize accesses to information
  848. * @osps_cache: Cacheable' information
  849. */
  850. struct target_if_spectral_param_state_info {
  851. qdf_spinlock_t osps_lock;
  852. struct target_if_spectral_cache osps_cache;
  853. /* XXX - Non-cacheable information goes here, in the future */
  854. };
  855. #endif /* ATH_PERF_PWR_OFFLOAD */
  856. struct vdev_spectral_configure_params;
  857. struct vdev_spectral_enable_params;
  858. /**
  859. * struct spectral_wmi_ops - structure used holding the operations
  860. * related to Spectral WMI
  861. * @wmi_spectral_configure_cmd_send: Configure Spectral parameters
  862. * @wmi_spectral_enable_cmd_send: Enable/Disable Spectral
  863. * @wmi_spectral_crash_inject: Inject FW crash
  864. * @wmi_extract_pdev_sscan_fw_cmd_fixed_param: Extract Fixed params from
  865. * start scan response event
  866. * @wmi_extract_pdev_sscan_fft_bin_index: Extract TLV which describes FFT
  867. * bin indices from start scan response event
  868. * @wmi_unified_register_event_handler: Register WMI event handler
  869. * @wmi_unified_unregister_event_handler: Unregister WMI event handler
  870. * @wmi_service_enabled: API to check whether a given WMI service is enabled
  871. * @extract_pdev_spectral_session_chan_info: Extract Spectral scan session
  872. * channel information
  873. * @extract_pdev_spectral_session_detector_info: Extract Spectral scan session
  874. * detector information
  875. */
  876. struct spectral_wmi_ops {
  877. QDF_STATUS (*wmi_spectral_configure_cmd_send)(
  878. wmi_unified_t wmi_hdl,
  879. struct vdev_spectral_configure_params *param);
  880. QDF_STATUS (*wmi_spectral_enable_cmd_send)(
  881. wmi_unified_t wmi_hdl,
  882. struct vdev_spectral_enable_params *param);
  883. QDF_STATUS (*wmi_spectral_crash_inject)(
  884. wmi_unified_t wmi_handle, struct crash_inject *param);
  885. QDF_STATUS (*wmi_extract_pdev_sscan_fw_cmd_fixed_param)(
  886. wmi_unified_t wmi_handle, uint8_t *evt_buf,
  887. struct spectral_startscan_resp_params *param);
  888. QDF_STATUS (*wmi_extract_pdev_sscan_fft_bin_index)(
  889. wmi_unified_t wmi_handle, uint8_t *evt_buf,
  890. struct spectral_fft_bin_markers_160_165mhz *param);
  891. QDF_STATUS (*wmi_unified_register_event_handler)(
  892. wmi_unified_t wmi_handle,
  893. wmi_conv_event_id event_id,
  894. wmi_unified_event_handler handler_func,
  895. uint8_t rx_ctx);
  896. QDF_STATUS (*wmi_unified_unregister_event_handler)(
  897. wmi_unified_t wmi_handle,
  898. wmi_conv_event_id event_id);
  899. bool (*wmi_service_enabled)(wmi_unified_t wmi_handle,
  900. uint32_t service_id);
  901. QDF_STATUS (*extract_pdev_spectral_session_chan_info)(
  902. wmi_unified_t wmi_handle, void *event,
  903. struct spectral_session_chan_info *chan_info);
  904. QDF_STATUS (*extract_pdev_spectral_session_detector_info)(
  905. wmi_unified_t wmi_handle, void *event,
  906. struct spectral_session_det_info *det_info,
  907. uint8_t det_info_idx);
  908. };
  909. /**
  910. * struct spectral_tgt_ops - structure used holding the operations
  911. * related to target operations
  912. * @tgt_get_psoc_from_scn_hdl: Function to get psoc from scn
  913. */
  914. struct spectral_tgt_ops {
  915. struct wlan_objmgr_psoc *(*tgt_get_psoc_from_scn_hdl)(void *scn_handle);
  916. };
  917. /**
  918. * struct spectral_param_properties - structure holding Spectral
  919. * parameter properties
  920. * @supported: Parameter is supported or not
  921. * @common_all_modes: Parameter should be common for all modes or not
  922. */
  923. struct spectral_param_properties {
  924. bool supported;
  925. bool common_all_modes;
  926. };
  927. /**
  928. * struct target_if_finite_spectral_scan_params - Parameters related to finite
  929. * Spectral scan
  930. * @finite_spectral_scan: Indicates the Spectrl scan is finite/infinite
  931. * @num_reports_expected: Number of Spectral reports expected from target for a
  932. * finite Spectral scan
  933. */
  934. struct target_if_finite_spectral_scan_params {
  935. bool finite_spectral_scan;
  936. uint32_t num_reports_expected;
  937. };
  938. /**
  939. * struct per_session_dest_det_info - Per-session Detector information to be
  940. * filled to samp_detector_info
  941. * @freq_span_id: Contiguous frequency span ID within the SAMP message
  942. * @is_sec80: Indicates pri80/sec80 segment for 160/80p80 BW
  943. * @det_id: Detector ID within samp_freq_span_info corresponding to
  944. * freq_span_id
  945. * @dest_start_bin_idx: Start index of FFT bins within SAMP msg's bin_pwr array
  946. * @dest_end_bin_idx: End index of FFT bins within SAMP msg's bin_pwr array
  947. * @lb_extrabins_start_idx: Left band edge extra bins start index
  948. * @lb_extrabins_num: Number of left band edge extra bins
  949. * @rb_extrabins_start_idx: Right band edge extra bins start index
  950. * @rb_extrabins_num: Number of right band edge extra bins
  951. * @start_freq: Indicates start frequency per-detector (in MHz)
  952. * @end_freq: Indicates last frequency per-detector (in MHz)
  953. * @src_start_bin_idx: Start index within the Spectral report's bin_pwr array,
  954. * where the FFT bins corresponding to this dest_det_id start
  955. */
  956. struct per_session_dest_det_info {
  957. uint8_t freq_span_id;
  958. bool is_sec80;
  959. uint8_t det_id;
  960. uint16_t dest_start_bin_idx;
  961. uint16_t dest_end_bin_idx;
  962. uint16_t lb_extrabins_start_idx;
  963. uint16_t lb_extrabins_num;
  964. uint16_t rb_extrabins_start_idx;
  965. uint16_t rb_extrabins_num;
  966. uint32_t start_freq;
  967. uint32_t end_freq;
  968. uint16_t src_start_bin_idx;
  969. };
  970. /**
  971. * struct per_session_det_map - A map of per-session detector information,
  972. * keyed by the detector id obtained from the Spectral FFT report, mapping to
  973. * detination detector info in SAMP message.
  974. * @dest_det_info: Struct containing per-session detector information
  975. * @num_dest_det_info: Number of destination detectors to which information
  976. * of this detector is to be filled
  977. * @spectral_msg_buf_type: Spectral message buffer type
  978. * @send_to_upper_layers: Indicates whether to send SAMP msg to upper layers
  979. * @det_map_valid: Indicates whether detector map is valid or not
  980. */
  981. struct per_session_det_map {
  982. struct per_session_dest_det_info
  983. dest_det_info[MAX_NUM_DEST_DETECTOR_INFO];
  984. uint8_t num_dest_det_info;
  985. enum spectral_msg_buf_type buf_type;
  986. bool send_to_upper_layers;
  987. bool det_map_valid;
  988. };
  989. /**
  990. * struct per_session_report_info - Consists of per-session Spectral report
  991. * information to be filled at report level in SAMP message.
  992. * @pri20_freq: Primary 20MHz operating frequency in MHz
  993. * @cfreq1: Centre frequency of the frequency span for 20/40/80 MHz BW.
  994. * Segment 1 centre frequency in MHz for 80p80/160 BW.
  995. * @cfreq2: For 80p80, indicates segment 2 centre frequency in MHz. For 160MHz,
  996. * indicates the center frequency of 160MHz span.
  997. * @operating_bw: Device's operating bandwidth.Valid values = enum phy_ch_width
  998. * @sscan_cfreq1: Normal/Agile scan Centre frequency of the frequency span for
  999. * 20/40/80 MHz BW. Center frequency of Primary Segment in MHz for 80p80/160 BW
  1000. * Based on Spectral scan mode.
  1001. * @sscan_cfreq2: For 80p80, Normal/Agile scan Center frequency for Sec80
  1002. * segment. For 160MHz, indicates the center frequency of 160MHz span. Based on
  1003. * spectral scan mode
  1004. * @sscan_bw: Normal/Agile Scan BW based on Spectral scan mode.
  1005. * Valid values = enum phy_ch_width
  1006. * @num_spans: Number of frequency spans
  1007. * @valid: Indicated whether report info is valid
  1008. */
  1009. struct per_session_report_info {
  1010. uint32_t pri20_freq;
  1011. uint32_t cfreq1;
  1012. uint32_t cfreq2;
  1013. enum phy_ch_width operating_bw;
  1014. uint32_t sscan_cfreq1;
  1015. uint32_t sscan_cfreq2;
  1016. enum phy_ch_width sscan_bw;
  1017. uint8_t num_spans;
  1018. bool valid;
  1019. };
  1020. /**
  1021. * struct sscan_detector_list - Spectral scan Detector list, for given Spectral
  1022. * scan mode and operating BW
  1023. * @detectors: List of detectors
  1024. * @num_detectors: Number of detectors for given spectral scan mode, BW
  1025. * and target type
  1026. */
  1027. struct sscan_detector_list {
  1028. uint8_t detectors[SPECTRAL_DETECTOR_ID_MAX];
  1029. uint8_t num_detectors;
  1030. };
  1031. /**
  1032. * struct spectral_supported_bws - Supported sscan bandwidths
  1033. * @bandwidths: bitmap of supported sscan bandwidths. Make sure to maintain this
  1034. * bitmap in the increasing order of bandwidths.
  1035. */
  1036. struct spectral_supported_bws {
  1037. union {
  1038. struct {
  1039. uint32_t supports_sscan_bw_5:1,
  1040. supports_sscan_bw_10:1,
  1041. supports_sscan_bw_20:1,
  1042. supports_sscan_bw_40:1,
  1043. supports_sscan_bw_80:1,
  1044. supports_sscan_bw_160:1,
  1045. supports_sscan_bw_80_80:1,
  1046. supports_sscan_bw_320:1,
  1047. reserved:24;
  1048. };
  1049. uint32_t bandwidths;
  1050. };
  1051. };
  1052. /**
  1053. * get_supported_sscan_bw_pos() - Get the position of a given sscan_bw inside
  1054. * the supported sscan bandwidths bitmap
  1055. * @sscan_bw: Spectral scan bandwidth
  1056. *
  1057. * Return: bit position for a valid sscan bandwidth, else -1
  1058. */
  1059. int get_supported_sscan_bw_pos(enum phy_ch_width sscan_bw);
  1060. /**
  1061. * struct target_if_spectral - main spectral structure
  1062. * @pdev: Pointer to pdev
  1063. * @spectral_ops: Target if internal Spectral low level operations table
  1064. * @capability: Spectral capabilities structure
  1065. * @properties: Spectral parameter properties per mode
  1066. * @spectral_lock: Lock used for internal Spectral operations
  1067. * @vdev_id: VDEV id for all spectral modes
  1068. * @spectral_curchan_radindex: Current channel spectral index
  1069. * @spectral_extchan_radindex: Extension channel spectral index
  1070. * @spectraldomain: Current Spectral domain
  1071. * @spectral_proc_phyerr: Flags to process for PHY errors
  1072. * @spectral_defaultparams: Default PHY params per Spectral stat
  1073. * @spectral_stats: Spectral related stats
  1074. * @events: Events structure
  1075. * @sc_spectral_ext_chan_ok: Can spectral be detected on the extension channel?
  1076. * @sc_spectral_combined_rssi_ok: Can use combined spectral RSSI?
  1077. * @sc_spectral_20_40_mode: Is AP in 20-40 mode?
  1078. * @sc_spectral_noise_pwr_cal: Noise power cal required?
  1079. * @sc_spectral_non_edma: Is the spectral capable device Non-EDMA?
  1080. * @upper_is_control: Upper segment is primary
  1081. * @upper_is_extension: Upper segment is secondary
  1082. * @lower_is_control: Lower segment is primary
  1083. * @lower_is_extension: Lower segment is secondary
  1084. * @sc_spectraltest_ieeechan: IEEE channel number to return to after a spectral
  1085. * mute test
  1086. * @spectral_numbins: Number of bins
  1087. * @spectral_fft_len: FFT length
  1088. * @spectral_data_len: Total phyerror report length
  1089. * @lb_edge_extrabins: Number of extra bins on left band edge
  1090. * @rb_edge_extrabins: Number of extra bins on right band edge
  1091. * @spectral_max_index_offset: Max FFT index offset (20 MHz mode)
  1092. * @spectral_upper_max_index_offset: Upper max FFT index offset (20/40 MHz mode)
  1093. * @spectral_lower_max_index_offset: Lower max FFT index offset (20/40 MHz mode)
  1094. * @spectral_dc_index: At which index DC is present
  1095. * @send_single_packet: Deprecated
  1096. * @spectral_sent_msg: Indicates whether we send report to upper layers
  1097. * @params: Spectral parameters
  1098. * @last_capture_time: Indicates timestamp of previouse report
  1099. * @num_spectral_data: Number of Spectral samples received in current session
  1100. * @total_spectral_data: Total number of Spectral samples received
  1101. * @max_rssi: Maximum RSSI
  1102. * @detects_control_channel: NA
  1103. * @detects_extension_channel: NA
  1104. * @detects_below_dc: NA
  1105. * @detects_above_dc: NA
  1106. * @sc_scanning: Indicates active wifi scan
  1107. * @sc_spectral_scan: Indicates active specral scan
  1108. * @sc_spectral_full_scan: Deprecated
  1109. * @scan_start_tstamp: Deprecated
  1110. * @last_tstamp: Deprecated
  1111. * @first_tstamp: Deprecated
  1112. * @spectral_samp_count: Deprecated
  1113. * @sc_spectral_samp_count: Deprecated
  1114. * @noise_pwr_reports_reqd: Number of noise power reports required
  1115. * @noise_pwr_reports_recv: Number of noise power reports received
  1116. * @noise_pwr_reports_lock: Lock used for Noise power report processing
  1117. * @noise_pwr_chain_ctl: Noise power report - control channel
  1118. * @noise_pwr_chain_ext: Noise power report - extension channel
  1119. * @chaninfo: Channel statistics
  1120. * @tsf64: Latest TSF Value
  1121. * @param_info: Offload architecture Spectral parameter cache information
  1122. * @ch_width: Indicates Channel Width 20/40/80/160 MHz for each Spectral mode
  1123. * @sscan_width_configured: Whether user has configured sscan bandwidth
  1124. * @diag_stats: Diagnostic statistics
  1125. * @is_160_format: Indicates whether information provided by HW is in altered
  1126. * format for 802.11ac 160/80+80 MHz support (QCA9984 onwards)
  1127. * @is_lb_edge_extrabins_format: Indicates whether information provided by
  1128. * HW has 4 extra bins, at left band edge, for report mode 2
  1129. * @is_rb_edge_extrabins_format: Indicates whether information provided
  1130. * by HW has 4 extra bins, at right band edge, for report mode 2
  1131. * @is_sec80_rssi_war_required: Indicates whether the software workaround is
  1132. * required to obtain approximate combined RSSI for secondary 80Mhz segment
  1133. * @simctx: Spectral Simulation context
  1134. * @spectral_gen: Spectral hardware generation
  1135. * @hdr_sig_exp: Expected signature in PHYERR TLV header, for the given hardware
  1136. * generation
  1137. * @tag_sscan_summary_exp: Expected Spectral Scan Summary tag in PHYERR TLV
  1138. * header, for the given hardware generation
  1139. * @tag_sscan_fft_exp: Expected Spectral Scan FFT report tag in PHYERR TLV
  1140. * header, for the given hardware generation
  1141. * @tlvhdr_size: Expected PHYERR TLV header size, for the given hardware
  1142. * generation
  1143. * @nl_cb: Netlink callbacks
  1144. * @use_nl_bcast: Whether to use Netlink broadcast/unicast
  1145. * @send_phy_data: Send data to the application layer for a particular msg type
  1146. * @len_adj_swar: Spectral fft bin length adjustment SWAR related info
  1147. * @timestamp_war: Spectral time stamp WAR related info
  1148. * @dbr_ring_debug: Whether Spectral DBR ring debug is enabled
  1149. * @dbr_buff_debug: Whether Spectral DBR buffer debug is enabled
  1150. * @direct_dma_support: Whether Direct-DMA is supported on the current radio
  1151. * @prev_tstamp: Timestamp of the previously received sample, which has to be
  1152. * compared with the current tstamp to check descrepancy
  1153. * @rparams: Parameters related to Spectral report structure
  1154. * @param_min_max: Spectral parameter's minimum and maximum values
  1155. * @finite_scan: Parameters for finite Spectral scan
  1156. * @detector_list: Detector list for a given Spectral scan mode and channel
  1157. * width, based on the target type.
  1158. * @detector_list_lock: Lock to synchronize accesses to detector list
  1159. * @det_map: Map of per-session detector information keyed by the Spectral HW
  1160. * detector id.
  1161. * @session_det_map_lock: Lock to synchronize accesses to session detector map
  1162. * @report_info: Per session info to be filled at report level in SAMP message
  1163. * @session_report_info_lock: Lock to synchronize access to session report info
  1164. * @supported_bws: Supported sscan bandwidths for all sscan modes and
  1165. * operating widths
  1166. * @supported_sscan_bw_list: List of supported sscan widths for all sscan modes
  1167. */
  1168. struct target_if_spectral {
  1169. struct wlan_objmgr_pdev *pdev_obj;
  1170. struct target_if_spectral_ops spectral_ops;
  1171. struct spectral_caps capability;
  1172. struct spectral_param_properties
  1173. properties[SPECTRAL_SCAN_MODE_MAX][SPECTRAL_PARAM_MAX];
  1174. qdf_spinlock_t spectral_lock;
  1175. uint8_t vdev_id[SPECTRAL_SCAN_MODE_MAX];
  1176. int16_t spectral_curchan_radindex;
  1177. int16_t spectral_extchan_radindex;
  1178. uint32_t spectraldomain;
  1179. uint32_t spectral_proc_phyerr;
  1180. struct spectral_config spectral_defaultparams;
  1181. struct target_if_spectral_stats spectral_stats;
  1182. struct target_if_spectral_event *events;
  1183. unsigned int sc_spectral_ext_chan_ok:1,
  1184. sc_spectral_combined_rssi_ok:1,
  1185. sc_spectral_20_40_mode:1,
  1186. sc_spectral_noise_pwr_cal:1,
  1187. sc_spectral_non_edma:1;
  1188. int upper_is_control;
  1189. int upper_is_extension;
  1190. int lower_is_control;
  1191. int lower_is_extension;
  1192. uint8_t sc_spectraltest_ieeechan;
  1193. int spectral_numbins;
  1194. int spectral_fft_len;
  1195. int spectral_data_len;
  1196. /*
  1197. * For 11ac chipsets prior to AR900B version 2.0, a max of 512 bins are
  1198. * delivered. However, there can be additional bins reported for
  1199. * AR900B version 2.0 and QCA9984 as described next:
  1200. *
  1201. * AR900B version 2.0: An additional tone is processed on the right
  1202. * hand side in order to facilitate detection of radar pulses out to
  1203. * the extreme band-edge of the channel frequency. Since the HW design
  1204. * processes four tones at a time, this requires one additional Dword
  1205. * to be added to the search FFT report.
  1206. *
  1207. * QCA9984: When spectral_scan_rpt_mode = 2, i.e 2-dword summary +
  1208. * 1x-oversampled bins (in-band) per FFT, then 8 more bins
  1209. * (4 more on left side and 4 more on right side)are added.
  1210. */
  1211. int lb_edge_extrabins;
  1212. int rb_edge_extrabins;
  1213. int spectral_max_index_offset;
  1214. int spectral_upper_max_index_offset;
  1215. int spectral_lower_max_index_offset;
  1216. int spectral_dc_index;
  1217. int send_single_packet;
  1218. int spectral_sent_msg;
  1219. int classify_scan;
  1220. qdf_timer_t classify_timer;
  1221. struct spectral_config params[SPECTRAL_SCAN_MODE_MAX];
  1222. bool params_valid[SPECTRAL_SCAN_MODE_MAX];
  1223. struct spectral_classifier_params classifier_params;
  1224. int last_capture_time;
  1225. int num_spectral_data;
  1226. int total_spectral_data;
  1227. int max_rssi;
  1228. int detects_control_channel;
  1229. int detects_extension_channel;
  1230. int detects_below_dc;
  1231. int detects_above_dc;
  1232. int sc_scanning;
  1233. int sc_spectral_scan;
  1234. int sc_spectral_full_scan;
  1235. uint64_t scan_start_tstamp;
  1236. uint32_t last_tstamp;
  1237. uint32_t first_tstamp;
  1238. uint32_t spectral_samp_count;
  1239. uint32_t sc_spectral_samp_count;
  1240. int noise_pwr_reports_reqd;
  1241. int noise_pwr_reports_recv;
  1242. qdf_spinlock_t noise_pwr_reports_lock;
  1243. struct target_if_chain_noise_pwr_info
  1244. *noise_pwr_chain_ctl[HOST_MAX_ANTENNA];
  1245. struct target_if_chain_noise_pwr_info
  1246. *noise_pwr_chain_ext[HOST_MAX_ANTENNA];
  1247. uint64_t tsf64;
  1248. #if ATH_PERF_PWR_OFFLOAD
  1249. struct target_if_spectral_param_state_info
  1250. param_info[SPECTRAL_SCAN_MODE_MAX];
  1251. #endif
  1252. enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
  1253. bool sscan_width_configured[SPECTRAL_SCAN_MODE_MAX];
  1254. struct spectral_diag_stats diag_stats;
  1255. bool is_160_format;
  1256. bool is_lb_edge_extrabins_format;
  1257. bool is_rb_edge_extrabins_format;
  1258. bool is_sec80_rssi_war_required;
  1259. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  1260. void *simctx;
  1261. #endif
  1262. enum spectral_gen spectral_gen;
  1263. uint8_t hdr_sig_exp;
  1264. uint8_t tag_sscan_summary_exp;
  1265. uint8_t tag_sscan_fft_exp;
  1266. uint8_t tlvhdr_size;
  1267. struct spectral_nl_cb nl_cb;
  1268. bool use_nl_bcast;
  1269. int (*send_phy_data)(struct wlan_objmgr_pdev *pdev,
  1270. enum spectral_msg_type smsg_type);
  1271. struct spectral_fft_bin_len_adj_swar len_adj_swar;
  1272. struct spectral_timestamp_war timestamp_war;
  1273. enum spectral_160mhz_report_delivery_state
  1274. state_160mhz_delivery[SPECTRAL_SCAN_MODE_MAX];
  1275. bool dbr_ring_debug;
  1276. bool dbr_buff_debug;
  1277. bool direct_dma_support;
  1278. #ifdef OPTIMIZED_SAMP_MESSAGE
  1279. uint32_t prev_tstamp[MAX_DETECTORS_PER_PDEV];
  1280. #else
  1281. uint32_t prev_tstamp;
  1282. #endif
  1283. struct spectral_report_params rparams;
  1284. struct spectral_param_min_max param_min_max;
  1285. struct target_if_finite_spectral_scan_params
  1286. finite_scan[SPECTRAL_SCAN_MODE_MAX];
  1287. struct sscan_detector_list
  1288. detector_list[SPECTRAL_SCAN_MODE_MAX][CH_WIDTH_MAX];
  1289. qdf_spinlock_t detector_list_lock;
  1290. struct per_session_det_map det_map[MAX_DETECTORS_PER_PDEV];
  1291. qdf_spinlock_t session_det_map_lock;
  1292. struct per_session_report_info report_info[SPECTRAL_SCAN_MODE_MAX];
  1293. qdf_spinlock_t session_report_info_lock;
  1294. struct spectral_supported_bws
  1295. supported_bws[SPECTRAL_SCAN_MODE_MAX][CH_WIDTH_MAX];
  1296. /* Whether a given sscan BW is supported on a given smode */
  1297. bool supported_sscan_bw_list[SPECTRAL_SCAN_MODE_MAX][CH_WIDTH_MAX];
  1298. };
  1299. /**
  1300. * struct target_if_psoc_spectral - Target if psoc Spectral object
  1301. * @psoc_obj: psoc object
  1302. * @wmi_ops: Spectral WMI operations
  1303. */
  1304. struct target_if_psoc_spectral {
  1305. struct wlan_objmgr_psoc *psoc_obj;
  1306. struct spectral_wmi_ops wmi_ops;
  1307. };
  1308. #ifdef OPTIMIZED_SAMP_MESSAGE
  1309. /**
  1310. * struct target_if_samp_msg_params - Spectral Analysis Messaging Protocol
  1311. * data format
  1312. * @hw_detector_id: Spectral HW detector ID
  1313. * @rssi: Spectral RSSI
  1314. * @lower_rssi: RSSI of lower band
  1315. * @upper_rssi: RSSI of upper band
  1316. * @chain_ctl_rssi: RSSI for control channel, for all antennas
  1317. * @chain_ext_rssi: RSSI for extension channel, for all antennas
  1318. * @last_raw_timestamp: Previous FFT report's raw timestamp.
  1319. * @raw_timestamp: FFT timestamp reported by HW on primary segment.
  1320. * @timestamp: timestamp
  1321. * @reset_delay: Time gap between the last spectral report before reset and the
  1322. * end of reset.
  1323. * @max_mag: maximum magnitude
  1324. * @max_index: index of max magnitude
  1325. * @noise_floor: current noise floor
  1326. * @pri80ind: Indication from hardware that the sample was received on the
  1327. * primary 80 MHz segment. If this is set when smode =
  1328. * SPECTRAL_SCAN_MODE_AGILE, it indicates that Spectral was carried
  1329. * out on pri80 instead of the Agile frequency due to a channel
  1330. * switch - Software may choose to ignore the sample in this case.
  1331. * @bin_pwr_data: Contains FFT magnitudes
  1332. */
  1333. struct target_if_samp_msg_params {
  1334. uint8_t hw_detector_id;
  1335. int8_t rssi;
  1336. int8_t lower_rssi;
  1337. int8_t upper_rssi;
  1338. int8_t chain_ctl_rssi[HOST_MAX_ANTENNA];
  1339. int8_t chain_ext_rssi[HOST_MAX_ANTENNA];
  1340. uint32_t last_raw_timestamp;
  1341. uint32_t raw_timestamp;
  1342. uint32_t timestamp;
  1343. uint32_t reset_delay;
  1344. uint16_t max_mag;
  1345. uint16_t max_index;
  1346. int16_t noise_floor;
  1347. uint8_t agc_total_gain;
  1348. uint8_t gainchange;
  1349. uint8_t pri80ind;
  1350. uint8_t *bin_pwr_data;
  1351. };
  1352. #else
  1353. /**
  1354. * struct target_if_samp_msg_params - Spectral Analysis Messaging Protocol
  1355. * data format
  1356. * @rssi: RSSI (except for secondary 80 segment)
  1357. * @rssi_sec80: RSSI for secondary 80 segment
  1358. * @lower_rssi: RSSI of lower band
  1359. * @upper_rssi: RSSI of upper band
  1360. * @chain_ctl_rssi: RSSI for control channel, for all antennas
  1361. * @chain_ext_rssi: RSSI for extension channel, for all antennas
  1362. * @bwinfo: bandwidth info
  1363. * @data_len: length of FFT data (except for secondary 80 segment)
  1364. * @data_len_sec80: length of FFT data for secondary 80 segment
  1365. * @tstamp: timestamp
  1366. * @last_tstamp: last time stamp
  1367. * @max_mag: maximum magnitude (except for secondary 80 segment)
  1368. * @max_mag_sec80: maximum magnitude for secondary 80 segment
  1369. * @max_index: index of max magnitude (except for secondary 80 segment)
  1370. * @max_index_sec80: index of max magnitude for secondary 80 segment
  1371. * @max_exp: max exp
  1372. * @peak: peak frequency (obsolete)
  1373. * @pwr_count: number of FFT bins (except for secondary 80 segment)
  1374. * @pwr_count_5mhz: number of FFT bins in extra 5 MHz in
  1375. * 165 MHz/restricted 80p80 mode
  1376. * @pwr_count_sec80: number of FFT bins in secondary 80 segment
  1377. * @nb_lower: This is deprecated
  1378. * @nb_upper: This is deprecated
  1379. * @max_upper_index: index of max mag in upper band
  1380. * @max_lower_index: index of max mag in lower band
  1381. * @bin_pwr_data: Contains FFT magnitudes (except for secondary 80 segment)
  1382. * @bin_pwr_data_5mhz: Contains FFT magnitudes for the extra 5 MHz
  1383. * in 165 MHz/restricted 80p80 mode
  1384. * @bin_pwr_data_sec80: Contains FFT magnitudes for the secondary 80 segment
  1385. * @freq: Center frequency of primary 20MHz channel in MHz
  1386. * @vhtop_ch_freq_seg1: VHT operation first segment center frequency in MHz
  1387. * @vhtop_ch_freq_seg2: VHT operation second segment center frequency in MHz
  1388. * @agile_freq1: Center frequency in MHz of the entire span(for 80+80 MHz
  1389. * agile Scan it is primary 80 MHz span) across which
  1390. * Agile Spectral is carried out. Applicable only for Agile
  1391. * Spectral samples.
  1392. * @agile_freq2: Center frequency in MHz of the secondary 80 MHz span
  1393. * across which Agile Spectral is carried out. Applicable
  1394. * only for Agile Spectral samples in 80+80 MHz mode.
  1395. * @freq_loading: spectral control duty cycles
  1396. * @noise_floor: current noise floor (except for secondary 80 segment)
  1397. * @noise_floor_sec80: current noise floor for secondary 80 segment
  1398. * @interf_list: List of interfernce sources
  1399. * @classifier_params: classifier parameters
  1400. * @sc: classifier parameters
  1401. * @pri80ind: Indication from hardware that the sample was received on the
  1402. * primary 80 MHz segment. If this is set when smode =
  1403. * SPECTRAL_SCAN_MODE_AGILE, it indicates that Spectral was carried out on
  1404. * pri80 instead of the Agile frequency due to a channel switch - Software may
  1405. * choose to ignore the sample in this case.
  1406. * @pri80ind_sec80: Indication from hardware that the sample was received on the
  1407. * primary 80 MHz segment instead of the secondary 80 MHz segment due to a
  1408. * channel switch - Software may choose to ignore the sample if this is set.
  1409. * Applicable only if smode = SPECTRAL_SCAN_MODE_NORMAL and for 160/80+80 MHz
  1410. * Spectral operation and if the chipset supports fragmented 160/80+80 MHz
  1411. * operation.
  1412. * @last_raw_timestamp: Previous FFT report's raw timestamp. In case of 160MHz
  1413. * it will be primary 80 segment's timestamp as both primary & secondary
  1414. * segment's timestamps are expected to be almost equal
  1415. * @timestamp_war_offset: Offset calculated based on reset_delay and
  1416. * last_raw_stamp. It will be added to raw_timestamp to get tstamp.
  1417. * @raw_timestamp: FFT timestamp reported by HW on primary segment.
  1418. * @raw_timestamp_sec80: FFT timestamp reported by HW on secondary 80 segment.
  1419. * @reset_delay: Time gap between the last spectral report before reset and the
  1420. * end of reset.
  1421. * @target_reset_count: Indicates the the number of times the target went
  1422. * through reset routine after spectral was enabled.
  1423. */
  1424. struct target_if_samp_msg_params {
  1425. int8_t rssi;
  1426. int8_t rssi_sec80;
  1427. int8_t lower_rssi;
  1428. int8_t upper_rssi;
  1429. int8_t chain_ctl_rssi[HOST_MAX_ANTENNA];
  1430. int8_t chain_ext_rssi[HOST_MAX_ANTENNA];
  1431. uint16_t bwinfo;
  1432. uint16_t datalen;
  1433. uint16_t datalen_sec80;
  1434. uint32_t tstamp;
  1435. uint32_t last_tstamp;
  1436. uint16_t max_mag;
  1437. uint16_t max_mag_sec80;
  1438. uint16_t max_index;
  1439. uint16_t max_index_sec80;
  1440. uint8_t max_exp;
  1441. int peak;
  1442. int pwr_count;
  1443. int pwr_count_5mhz;
  1444. int pwr_count_sec80;
  1445. int8_t nb_lower;
  1446. int8_t nb_upper;
  1447. uint16_t max_lower_index;
  1448. uint16_t max_upper_index;
  1449. uint8_t *bin_pwr_data;
  1450. uint8_t *bin_pwr_data_5mhz;
  1451. uint8_t *bin_pwr_data_sec80;
  1452. uint16_t freq;
  1453. uint16_t vhtop_ch_freq_seg1;
  1454. uint16_t vhtop_ch_freq_seg2;
  1455. uint16_t agile_freq1;
  1456. uint16_t agile_freq2;
  1457. uint16_t freq_loading;
  1458. int16_t noise_floor;
  1459. int16_t noise_floor_sec80;
  1460. struct interf_src_rsp interf_list;
  1461. struct spectral_classifier_params classifier_params;
  1462. struct ath_softc *sc;
  1463. uint8_t agc_total_gain;
  1464. uint8_t agc_total_gain_sec80;
  1465. uint8_t gainchange;
  1466. uint8_t gainchange_sec80;
  1467. enum spectral_scan_mode smode;
  1468. uint8_t pri80ind;
  1469. uint8_t pri80ind_sec80;
  1470. uint32_t last_raw_timestamp;
  1471. uint32_t timestamp_war_offset;
  1472. uint32_t raw_timestamp;
  1473. uint32_t raw_timestamp_sec80;
  1474. uint32_t reset_delay;
  1475. uint32_t target_reset_count;
  1476. };
  1477. #endif
  1478. /**
  1479. * struct target_if_spectral_agile_mode_cap - Structure to hold agile
  1480. * Spetcral scan capability
  1481. * @agile_spectral_cap: agile Spectral scan capability for 20/40/80 MHz
  1482. * @agile_spectral_cap_160: agile Spectral scan capability for 160 MHz
  1483. * @agile_spectral_cap_80p80: agile Spectral scan capability for 80+80 MHz
  1484. */
  1485. struct target_if_spectral_agile_mode_cap {
  1486. bool agile_spectral_cap;
  1487. bool agile_spectral_cap_160;
  1488. bool agile_spectral_cap_80p80;
  1489. };
  1490. #ifdef WLAN_CONV_SPECTRAL_ENABLE
  1491. /**
  1492. * target_if_spectral_dump_fft() - Dump Spectral FFT
  1493. * @pfft: Pointer to Spectral Phyerr FFT
  1494. * @fftlen: FFT length
  1495. *
  1496. * Return: Success or failure
  1497. */
  1498. int target_if_spectral_dump_fft(uint8_t *pfft, int fftlen);
  1499. /**
  1500. * target_if_dbg_print_samp_param() - Print contents of SAMP struct
  1501. * @p: Pointer to SAMP message
  1502. *
  1503. * Return: Void
  1504. */
  1505. void target_if_dbg_print_samp_param(struct target_if_samp_msg_params *p);
  1506. /**
  1507. * target_if_get_offset_swar_sec80() - Get offset for SWAR according to
  1508. * the channel width
  1509. * @channel_width: Channel width
  1510. *
  1511. * Return: Offset for SWAR
  1512. */
  1513. uint32_t target_if_get_offset_swar_sec80(uint32_t channel_width);
  1514. /**
  1515. * target_if_sptrl_register_tx_ops() - Register Spectral target_if Tx Ops
  1516. * @tx_ops: Tx Ops
  1517. *
  1518. * Return: void
  1519. */
  1520. void target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops);
  1521. #ifndef OPTIMIZED_SAMP_MESSAGE
  1522. /**
  1523. * target_if_spectral_create_samp_msg() - Create the spectral samp message
  1524. * @spectral : Pointer to spectral internal structure
  1525. * @params : spectral samp message parameters
  1526. *
  1527. * API to create the spectral samp message
  1528. *
  1529. * Return: void
  1530. */
  1531. void target_if_spectral_create_samp_msg(
  1532. struct target_if_spectral *spectral,
  1533. struct target_if_samp_msg_params *params);
  1534. #endif
  1535. #ifdef OPTIMIZED_SAMP_MESSAGE
  1536. /**
  1537. * target_if_spectral_fill_samp_msg() - Fill the Spectral SAMP message
  1538. * @spectral : Pointer to spectral internal structure
  1539. * @params: Spectral SAMP message fields
  1540. *
  1541. * Fill the spectral SAMP message fields using params and detector map.
  1542. *
  1543. * Return: Success/Failure
  1544. */
  1545. QDF_STATUS target_if_spectral_fill_samp_msg(
  1546. struct target_if_spectral *spectral,
  1547. struct target_if_samp_msg_params *params);
  1548. #endif
  1549. /**
  1550. * target_if_spectral_process_phyerr_gen3() - Process phyerror event for gen3
  1551. * @pdev: Pointer to pdev object
  1552. * @payload: Pointer to spectral report
  1553. *
  1554. * Process phyerror event for gen3
  1555. *
  1556. * Return: Success/Failure
  1557. */
  1558. int target_if_spectral_process_report_gen3(
  1559. struct wlan_objmgr_pdev *pdev,
  1560. void *buf);
  1561. /**
  1562. * target_if_process_phyerr_gen2() - Process PHY Error for gen2
  1563. * @spectral: Pointer to Spectral object
  1564. * @data: Pointer to phyerror event buffer
  1565. * @datalen: Data length
  1566. * @p_rfqual: RF quality info
  1567. * @p_chaninfo: Channel info
  1568. * @tsf64: 64 bit tsf timestamp
  1569. * @acs_stats: ACS stats
  1570. *
  1571. * Process PHY Error for gen2
  1572. *
  1573. * Return: Success/Failure
  1574. */
  1575. int target_if_process_phyerr_gen2(
  1576. struct target_if_spectral *spectral,
  1577. uint8_t *data,
  1578. uint32_t datalen, struct target_if_spectral_rfqual_info *p_rfqual,
  1579. struct target_if_spectral_chan_info *p_chaninfo,
  1580. uint64_t tsf64,
  1581. struct target_if_spectral_acs_stats *acs_stats);
  1582. /**
  1583. * target_if_spectral_send_intf_found_msg() - Indicate to application layer that
  1584. * interference has been found
  1585. * @pdev: Pointer to pdev
  1586. * @cw_int: 1 if CW interference is found, 0 if WLAN interference is found
  1587. * @dcs_enabled: 1 if DCS is enabled, 0 if DCS is disabled
  1588. *
  1589. * Send message to application layer
  1590. * indicating that interference has been found
  1591. *
  1592. * Return: None
  1593. */
  1594. void target_if_spectral_send_intf_found_msg(
  1595. struct wlan_objmgr_pdev *pdev,
  1596. uint16_t cw_int, uint32_t dcs_enabled);
  1597. /**
  1598. * target_if_stop_spectral_scan() - Stop spectral scan
  1599. * @pdev: Pointer to pdev object
  1600. * @smode: Spectral scan mode
  1601. * @err: Pointer to error code
  1602. *
  1603. * API to stop the current on-going spectral scan
  1604. *
  1605. * Return: QDF_STATUS_SUCCESS in case of success, else QDF_STATUS_E_FAILURE
  1606. */
  1607. QDF_STATUS target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev,
  1608. const enum spectral_scan_mode smode,
  1609. enum spectral_cp_error_code *err);
  1610. /**
  1611. * target_if_spectral_get_vdev() - Get pointer to vdev to be used for Spectral
  1612. * operations
  1613. * @spectral: Pointer to Spectral target_if internal private data
  1614. * @smode: spectral scan mode
  1615. *
  1616. * Spectral operates on pdev. However, in order to retrieve some WLAN
  1617. * properties, a vdev is required. To facilitate this, the function returns the
  1618. * first vdev in our pdev. The caller should release the reference to the vdev
  1619. * once it is done using it.
  1620. * TODO: If the framework later provides an API to obtain the first active
  1621. * vdev, then it would be preferable to use this API.
  1622. *
  1623. * Return: Pointer to vdev on success, NULL on failure
  1624. */
  1625. struct wlan_objmgr_vdev *target_if_spectral_get_vdev(
  1626. struct target_if_spectral *spectral,
  1627. enum spectral_scan_mode smode);
  1628. /**
  1629. * target_if_spectral_dump_hdr_gen2() - Dump Spectral header for gen2
  1630. * @phdr: Pointer to Spectral Phyerr Header
  1631. *
  1632. * Dump Spectral header
  1633. *
  1634. * Return: Success/Failure
  1635. */
  1636. int target_if_spectral_dump_hdr_gen2(struct spectral_phyerr_hdr_gen2 *phdr);
  1637. /**
  1638. * target_if_get_combrssi_sec80_seg_gen2() - Get approximate combined RSSI
  1639. * for Secondary 80 segment
  1640. * @spectral: Pointer to spectral object
  1641. * @p_sfft_sec80: Pointer to search fft info of secondary 80 segment
  1642. *
  1643. * Get approximate combined RSSI for Secondary 80 segment
  1644. *
  1645. * Return: Combined RSSI for secondary 80Mhz segment
  1646. */
  1647. int8_t target_if_get_combrssi_sec80_seg_gen2(
  1648. struct target_if_spectral *spectral,
  1649. struct spectral_search_fft_info_gen2 *p_sfft_sec80);
  1650. /**
  1651. * target_if_spectral_dump_tlv_gen2() - Dump Spectral TLV for gen2
  1652. * @ptlv: Pointer to Spectral Phyerr TLV
  1653. * @is_160_format: Indicates 160 format
  1654. *
  1655. * Dump Spectral TLV for gen2
  1656. *
  1657. * Return: Success/Failure
  1658. */
  1659. int target_if_spectral_dump_tlv_gen2(
  1660. struct spectral_phyerr_tlv_gen2 *ptlv, bool is_160_format);
  1661. /**
  1662. * target_if_spectral_dump_phyerr_data_gen2() - Dump Spectral
  1663. * related PHY Error for gen2
  1664. * @data: Pointer to phyerror buffer
  1665. * @datalen: Data length
  1666. * @is_160_format: Indicates 160 format
  1667. *
  1668. * Dump Spectral related PHY Error for gen2
  1669. *
  1670. * Return: Success/Failure
  1671. */
  1672. int target_if_spectral_dump_phyerr_data_gen2(
  1673. uint8_t *data,
  1674. uint32_t datalen,
  1675. bool is_160_format);
  1676. /**
  1677. * target_if_dbg_print_samp_msg() - Print contents of SAMP Message
  1678. * @p: Pointer to SAMP message
  1679. *
  1680. * Print contents of SAMP Message
  1681. *
  1682. * Return: Void
  1683. */
  1684. void target_if_dbg_print_samp_msg(struct spectral_samp_msg *pmsg);
  1685. /**
  1686. * get_target_if_spectral_handle_from_pdev() - Get handle to target_if internal
  1687. * Spectral data
  1688. * @pdev: Pointer to pdev
  1689. *
  1690. * Return: Handle to target_if internal Spectral data on success, NULL on
  1691. * failure
  1692. */
  1693. struct target_if_spectral *get_target_if_spectral_handle_from_pdev(
  1694. struct wlan_objmgr_pdev *pdev);
  1695. /**
  1696. * get_target_if_spectral_handle_from_psoc() - Get handle to psoc target_if
  1697. * internal Spectral data
  1698. * @psoc: Pointer to psoc
  1699. *
  1700. * Return: Handle to target_if psoc internal Spectral data on success, NULL on
  1701. * failure
  1702. */
  1703. static inline
  1704. struct target_if_psoc_spectral *get_target_if_spectral_handle_from_psoc(
  1705. struct wlan_objmgr_psoc *psoc)
  1706. {
  1707. struct wlan_lmac_if_rx_ops *rx_ops;
  1708. struct target_if_psoc_spectral *psoc_spectral;
  1709. if (!psoc) {
  1710. spectral_err("psoc is null");
  1711. return NULL;
  1712. }
  1713. rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
  1714. if (!rx_ops) {
  1715. spectral_err("rx_ops is null");
  1716. return NULL;
  1717. }
  1718. psoc_spectral = (struct target_if_psoc_spectral *)
  1719. rx_ops->sptrl_rx_ops.sptrlro_get_psoc_target_handle(psoc);
  1720. return psoc_spectral;
  1721. }
  1722. /**
  1723. * target_if_vdev_get_chan_freq() - Get the operating channel frequency of a
  1724. * given vdev
  1725. * @pdev: Pointer to vdev
  1726. *
  1727. * Get the operating channel frequency of a given vdev
  1728. *
  1729. * Return: Operating channel frequency of a vdev
  1730. */
  1731. static inline
  1732. int16_t target_if_vdev_get_chan_freq(struct wlan_objmgr_vdev *vdev)
  1733. {
  1734. struct wlan_objmgr_psoc *psoc = NULL;
  1735. struct wlan_lmac_if_rx_ops *rx_ops;
  1736. psoc = wlan_vdev_get_psoc(vdev);
  1737. if (!psoc) {
  1738. spectral_err("psoc is NULL");
  1739. return -EINVAL;
  1740. }
  1741. rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
  1742. if (!rx_ops) {
  1743. spectral_err("rx_ops is null");
  1744. return -EINVAL;
  1745. }
  1746. return rx_ops->sptrl_rx_ops.sptrlro_vdev_get_chan_freq(
  1747. vdev);
  1748. }
  1749. /**
  1750. * target_if_vdev_get_chan_freq_seg2() - Get center frequency of secondary 80 of
  1751. * given vdev
  1752. * @vdev: Pointer to vdev
  1753. *
  1754. * Get the center frequency of secondary 80 of given vdev
  1755. *
  1756. * Return: center frequency of secondary 80
  1757. */
  1758. static inline
  1759. int16_t target_if_vdev_get_chan_freq_seg2(struct wlan_objmgr_vdev *vdev)
  1760. {
  1761. struct wlan_objmgr_psoc *psoc = NULL;
  1762. struct wlan_lmac_if_rx_ops *rx_ops;
  1763. psoc = wlan_vdev_get_psoc(vdev);
  1764. if (!psoc) {
  1765. spectral_err("psoc is NULL");
  1766. return -EINVAL;
  1767. }
  1768. rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
  1769. if (!rx_ops) {
  1770. spectral_err("rx_ops is null");
  1771. return -EINVAL;
  1772. }
  1773. return rx_ops->sptrl_rx_ops.sptrlro_vdev_get_chan_freq_seg2(vdev);
  1774. }
  1775. /**
  1776. * target_if_vdev_get_ch_width() - Get the operating channel bandwidth of a
  1777. * given vdev
  1778. * @pdev: Pointer to vdev
  1779. *
  1780. * Get the operating channel bandwidth of a given vdev
  1781. *
  1782. * Return: channel bandwidth enumeration corresponding to the vdev
  1783. */
  1784. static inline
  1785. enum phy_ch_width target_if_vdev_get_ch_width(struct wlan_objmgr_vdev *vdev)
  1786. {
  1787. struct wlan_objmgr_psoc *psoc = NULL;
  1788. enum phy_ch_width ch_width;
  1789. struct wlan_lmac_if_rx_ops *rx_ops;
  1790. psoc = wlan_vdev_get_psoc(vdev);
  1791. if (!psoc) {
  1792. spectral_err("psoc is NULL");
  1793. return CH_WIDTH_INVALID;
  1794. }
  1795. rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
  1796. if (!rx_ops) {
  1797. spectral_err("rx_ops is null");
  1798. return CH_WIDTH_INVALID;
  1799. }
  1800. ch_width = rx_ops->sptrl_rx_ops.sptrlro_vdev_get_ch_width(vdev);
  1801. if (ch_width == CH_WIDTH_160MHZ) {
  1802. int16_t cfreq2;
  1803. cfreq2 = target_if_vdev_get_chan_freq_seg2(vdev);
  1804. if (cfreq2 < 0) {
  1805. spectral_err("Invalid value for cfreq2 %d", cfreq2);
  1806. return CH_WIDTH_INVALID;
  1807. }
  1808. /* Use non zero cfreq2 to identify 80p80 */
  1809. if (cfreq2)
  1810. ch_width = CH_WIDTH_80P80MHZ;
  1811. }
  1812. return ch_width;
  1813. }
  1814. /**
  1815. * target_if_vdev_get_sec20chan_freq_mhz() - Get the frequency of secondary
  1816. * 20 MHz channel for a given vdev
  1817. * @pdev: Pointer to vdev
  1818. *
  1819. * Get the frequency of secondary 20Mhz channel for a given vdev
  1820. *
  1821. * Return: Frequency of secondary 20Mhz channel for a given vdev
  1822. */
  1823. static inline
  1824. int target_if_vdev_get_sec20chan_freq_mhz(
  1825. struct wlan_objmgr_vdev *vdev,
  1826. uint16_t *sec20chan_freq)
  1827. {
  1828. struct wlan_objmgr_psoc *psoc = NULL;
  1829. struct wlan_lmac_if_rx_ops *rx_ops;
  1830. psoc = wlan_vdev_get_psoc(vdev);
  1831. if (!psoc) {
  1832. spectral_err("psoc is NULL");
  1833. return -EINVAL;
  1834. }
  1835. rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
  1836. if (!rx_ops) {
  1837. spectral_err("rx_ops is null");
  1838. return -EINVAL;
  1839. }
  1840. return rx_ops->sptrl_rx_ops.
  1841. sptrlro_vdev_get_sec20chan_freq_mhz(vdev, sec20chan_freq);
  1842. }
  1843. /**
  1844. * target_if_spectral_is_feature_disabled_psoc() - Check if Spectral feature is
  1845. * disabled for a given psoc
  1846. * @psoc: Pointer to psoc
  1847. *
  1848. * Return: true or false
  1849. */
  1850. static inline
  1851. bool target_if_spectral_is_feature_disabled_psoc(struct wlan_objmgr_psoc *psoc)
  1852. {
  1853. struct wlan_lmac_if_rx_ops *rx_ops;
  1854. if (!psoc) {
  1855. spectral_err("psoc is NULL");
  1856. return true;
  1857. }
  1858. rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
  1859. if (!rx_ops) {
  1860. spectral_err("rx_ops is null");
  1861. return true;
  1862. }
  1863. if (rx_ops->sptrl_rx_ops.
  1864. sptrlro_spectral_is_feature_disabled_psoc)
  1865. return rx_ops->sptrl_rx_ops.
  1866. sptrlro_spectral_is_feature_disabled_psoc(psoc);
  1867. return true;
  1868. }
  1869. /**
  1870. * target_if_spectral_is_feature_disabled_pdev() - Check if Spectral feature is
  1871. * disabled for a given pdev
  1872. * @pdev: Pointer to pdev
  1873. *
  1874. * Return: true or false
  1875. */
  1876. static inline
  1877. bool target_if_spectral_is_feature_disabled_pdev(struct wlan_objmgr_pdev *pdev)
  1878. {
  1879. struct wlan_lmac_if_rx_ops *rx_ops;
  1880. struct wlan_objmgr_psoc *psoc;
  1881. if (!pdev) {
  1882. spectral_err("pdev is NULL");
  1883. return true;
  1884. }
  1885. psoc = wlan_pdev_get_psoc(pdev);
  1886. if (!psoc) {
  1887. spectral_err("psoc is NULL");
  1888. return true;
  1889. }
  1890. rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
  1891. if (!rx_ops) {
  1892. spectral_err("rx_ops is null");
  1893. return true;
  1894. }
  1895. if (rx_ops->sptrl_rx_ops.
  1896. sptrlro_spectral_is_feature_disabled_pdev)
  1897. return rx_ops->sptrl_rx_ops.
  1898. sptrlro_spectral_is_feature_disabled_pdev(pdev);
  1899. return true;
  1900. }
  1901. /**
  1902. * target_if_spectral_set_rxchainmask() - Set Spectral Rx chainmask
  1903. * @pdev: Pointer to pdev
  1904. * @spectral_rx_chainmask: Spectral Rx chainmask
  1905. *
  1906. * Return: None
  1907. */
  1908. static inline
  1909. void target_if_spectral_set_rxchainmask(struct wlan_objmgr_pdev *pdev,
  1910. uint8_t spectral_rx_chainmask)
  1911. {
  1912. struct wlan_objmgr_psoc *psoc = NULL;
  1913. struct target_if_spectral *spectral = NULL;
  1914. enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
  1915. struct wlan_lmac_if_rx_ops *rx_ops;
  1916. psoc = wlan_pdev_get_psoc(pdev);
  1917. if (!psoc) {
  1918. spectral_err("psoc is NULL");
  1919. return;
  1920. }
  1921. rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
  1922. if (!rx_ops) {
  1923. spectral_err("rx_ops is null");
  1924. return;
  1925. }
  1926. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  1927. spectral_err("Invalid Spectral mode %u", smode);
  1928. return;
  1929. }
  1930. if (rx_ops->sptrl_rx_ops.
  1931. sptrlro_spectral_is_feature_disabled_pdev(pdev)) {
  1932. spectral_info("Spectral feature is disabled");
  1933. return;
  1934. }
  1935. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  1936. if (!spectral) {
  1937. spectral_err("Spectral target if object is null");
  1938. return;
  1939. }
  1940. /* set chainmask for all the modes */
  1941. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  1942. spectral->params[smode].ss_chn_mask = spectral_rx_chainmask;
  1943. }
  1944. /**
  1945. * target_if_spectral_process_phyerr() - Process Spectral PHY error
  1946. * @pdev: Pointer to pdev
  1947. * @data: PHY error data received from FW
  1948. * @datalen: Length of data
  1949. * @p_rfqual: Pointer to RF Quality information
  1950. * @p_chaninfo: Pointer to channel information
  1951. * @tsf: TSF time instance at which the Spectral sample was received
  1952. * @acs_stats: ACS stats
  1953. *
  1954. * Process Spectral PHY error by extracting necessary information from the data
  1955. * sent by FW, and send the extracted information to application layer.
  1956. *
  1957. * Return: None
  1958. */
  1959. static inline
  1960. void target_if_spectral_process_phyerr(
  1961. struct wlan_objmgr_pdev *pdev,
  1962. uint8_t *data, uint32_t datalen,
  1963. struct target_if_spectral_rfqual_info *p_rfqual,
  1964. struct target_if_spectral_chan_info *p_chaninfo,
  1965. uint64_t tsf64,
  1966. struct target_if_spectral_acs_stats *acs_stats)
  1967. {
  1968. struct target_if_spectral *spectral = NULL;
  1969. struct target_if_spectral_ops *p_sops = NULL;
  1970. spectral = get_target_if_spectral_handle_from_pdev(pdev);
  1971. if (!spectral) {
  1972. spectral_err("Spectral target if object is null");
  1973. return;
  1974. }
  1975. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  1976. p_sops->spectral_process_phyerr(spectral, data, datalen,
  1977. p_rfqual, p_chaninfo,
  1978. tsf64, acs_stats);
  1979. }
  1980. static QDF_STATUS
  1981. target_if_get_spectral_msg_type(enum spectral_scan_mode smode,
  1982. enum spectral_msg_type *msg_type) {
  1983. switch (smode) {
  1984. case SPECTRAL_SCAN_MODE_NORMAL:
  1985. *msg_type = SPECTRAL_MSG_NORMAL_MODE;
  1986. break;
  1987. case SPECTRAL_SCAN_MODE_AGILE:
  1988. *msg_type = SPECTRAL_MSG_AGILE_MODE;
  1989. break;
  1990. default:
  1991. spectral_err("Invalid spectral mode");
  1992. return QDF_STATUS_E_FAILURE;
  1993. }
  1994. return QDF_STATUS_SUCCESS;
  1995. }
  1996. static inline bool
  1997. is_ch_width_160_or_80p80(enum phy_ch_width ch_width)
  1998. {
  1999. return (ch_width == CH_WIDTH_160MHZ || ch_width == CH_WIDTH_80P80MHZ);
  2000. }
  2001. /**
  2002. * free_samp_msg_skb() - Free SAMP message skb
  2003. * @spectral: Pointer to Spectral
  2004. * @smode: Spectral Scan mode
  2005. *
  2006. * Free SAMP message skb, if error in report processing
  2007. *
  2008. * Return: void
  2009. */
  2010. static inline void
  2011. free_samp_msg_skb(struct target_if_spectral *spectral,
  2012. enum spectral_scan_mode smode)
  2013. {
  2014. enum spectral_msg_type smsg_type;
  2015. QDF_STATUS ret;
  2016. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2017. spectral_err_rl("Invalid Spectral mode %d", smode);
  2018. return;
  2019. }
  2020. if (is_ch_width_160_or_80p80(spectral->ch_width[smode])) {
  2021. ret = target_if_get_spectral_msg_type(smode, &smsg_type);
  2022. if (QDF_IS_STATUS_ERROR(ret)) {
  2023. spectral_err("Failed to get spectral message type");
  2024. return;
  2025. }
  2026. spectral->nl_cb.free_sbuff(spectral->pdev_obj,
  2027. smsg_type);
  2028. }
  2029. }
  2030. /**
  2031. * init_160mhz_delivery_state_machine() - Initialize 160MHz Spectral
  2032. * state machine
  2033. * @spectral: Pointer to Spectral
  2034. *
  2035. * Initialize 160MHz Spectral state machine
  2036. *
  2037. * Return: void
  2038. */
  2039. static inline void
  2040. init_160mhz_delivery_state_machine(struct target_if_spectral *spectral)
  2041. {
  2042. uint8_t smode;
  2043. smode = 0;
  2044. for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
  2045. spectral->state_160mhz_delivery[smode] =
  2046. SPECTRAL_REPORT_WAIT_PRIMARY80;
  2047. }
  2048. /**
  2049. * reset_160mhz_delivery_state_machine() - Reset 160MHz Spectral state machine
  2050. * @spectral: Pointer to Spectral
  2051. *
  2052. * Reset 160MHz Spectral state machine
  2053. *
  2054. * Return: void
  2055. */
  2056. static inline void
  2057. reset_160mhz_delivery_state_machine(struct target_if_spectral *spectral,
  2058. enum spectral_scan_mode smode)
  2059. {
  2060. if (smode >= SPECTRAL_SCAN_MODE_MAX) {
  2061. spectral_err_rl("Invalid Spectral mode %d", smode);
  2062. return;
  2063. }
  2064. free_samp_msg_skb(spectral, smode);
  2065. if (is_ch_width_160_or_80p80(spectral->ch_width[smode])) {
  2066. spectral->state_160mhz_delivery[smode] =
  2067. SPECTRAL_REPORT_WAIT_PRIMARY80;
  2068. }
  2069. }
  2070. /**
  2071. * is_secondaryseg_expected() - Is waiting for secondary 80 report
  2072. * @spectral: Pointer to Spectral
  2073. * @smode: Spectral scan mode
  2074. *
  2075. * Return true if secondary 80 report expected and mode is 160 MHz
  2076. *
  2077. * Return: true or false
  2078. */
  2079. static inline
  2080. bool is_secondaryseg_expected(struct target_if_spectral *spectral,
  2081. enum spectral_scan_mode smode)
  2082. {
  2083. return
  2084. (is_ch_width_160_or_80p80(spectral->ch_width[smode]) &&
  2085. spectral->rparams.fragmentation_160[smode] &&
  2086. (spectral->state_160mhz_delivery[smode] ==
  2087. SPECTRAL_REPORT_WAIT_SECONDARY80));
  2088. }
  2089. /**
  2090. * is_primaryseg_expected() - Is waiting for primary 80 report
  2091. * @spectral: Pointer to Spectral
  2092. * @smode: Spectral scan mode
  2093. *
  2094. * Return true if mode is 160 Mhz and primary 80 report expected or
  2095. * mode is not 160 Mhz
  2096. *
  2097. * Return: true or false
  2098. */
  2099. static inline
  2100. bool is_primaryseg_expected(struct target_if_spectral *spectral,
  2101. enum spectral_scan_mode smode)
  2102. {
  2103. return
  2104. (!is_ch_width_160_or_80p80(spectral->ch_width[smode]) ||
  2105. !spectral->rparams.fragmentation_160[smode] ||
  2106. (spectral->state_160mhz_delivery[smode] ==
  2107. SPECTRAL_REPORT_WAIT_PRIMARY80));
  2108. }
  2109. #ifndef OPTIMIZED_SAMP_MESSAGE
  2110. /**
  2111. * is_primaryseg_rx_inprog() - Is primary 80 report processing is in progress
  2112. * @spectral: Pointer to Spectral
  2113. * @smode: Spectral scan mode
  2114. *
  2115. * Is primary 80 report processing is in progress
  2116. *
  2117. * Return: true or false
  2118. */
  2119. static inline
  2120. bool is_primaryseg_rx_inprog(struct target_if_spectral *spectral,
  2121. enum spectral_scan_mode smode)
  2122. {
  2123. return
  2124. (!is_ch_width_160_or_80p80(spectral->ch_width[smode]) ||
  2125. spectral->spectral_gen == SPECTRAL_GEN2 ||
  2126. (spectral->spectral_gen == SPECTRAL_GEN3 &&
  2127. (!spectral->rparams.fragmentation_160[smode] ||
  2128. spectral->state_160mhz_delivery[smode] ==
  2129. SPECTRAL_REPORT_RX_PRIMARY80)));
  2130. }
  2131. /**
  2132. * is_secondaryseg_rx_inprog() - Is secondary80 report processing is in progress
  2133. * @spectral: Pointer to Spectral
  2134. * @smode: Spectral scan mode
  2135. *
  2136. * Is secondary 80 report processing is in progress
  2137. *
  2138. * Return: true or false
  2139. */
  2140. static inline
  2141. bool is_secondaryseg_rx_inprog(struct target_if_spectral *spectral,
  2142. enum spectral_scan_mode smode)
  2143. {
  2144. return
  2145. (is_ch_width_160_or_80p80(spectral->ch_width[smode]) &&
  2146. (spectral->spectral_gen == SPECTRAL_GEN2 ||
  2147. ((spectral->spectral_gen == SPECTRAL_GEN3) &&
  2148. (!spectral->rparams.fragmentation_160[smode] ||
  2149. spectral->state_160mhz_delivery[smode] ==
  2150. SPECTRAL_REPORT_RX_SECONDARY80))));
  2151. }
  2152. #endif
  2153. /**
  2154. * target_if_160mhz_delivery_state_change() - State transition for 160Mhz
  2155. * Spectral
  2156. * @spectral: Pointer to spectral object
  2157. * @smode: Spectral scan mode
  2158. * @detector_id: Detector id
  2159. *
  2160. * Move the states of state machine for 160MHz spectral scan report receive
  2161. *
  2162. * Return: QDF_STATUS
  2163. */
  2164. QDF_STATUS
  2165. target_if_160mhz_delivery_state_change(struct target_if_spectral *spectral,
  2166. enum spectral_scan_mode smode,
  2167. uint8_t detector_id);
  2168. /**
  2169. * target_if_sops_is_spectral_enabled() - Get whether Spectral is enabled
  2170. * @arg: Pointer to handle for Spectral target_if internal private data
  2171. * @smode: Spectral scan mode
  2172. *
  2173. * Function to check whether Spectral is enabled
  2174. *
  2175. * Return: True if Spectral is enabled, false if Spectral is not enabled
  2176. */
  2177. uint32_t target_if_sops_is_spectral_enabled(void *arg,
  2178. enum spectral_scan_mode smode);
  2179. /**
  2180. * target_if_sops_is_spectral_active() - Get whether Spectral is active
  2181. * @arg: Pointer to handle for Spectral target_if internal private data
  2182. * @smode: Spectral scan mode
  2183. *
  2184. * Function to check whether Spectral is active
  2185. *
  2186. * Return: True if Spectral is active, false if Spectral is not active
  2187. */
  2188. uint32_t target_if_sops_is_spectral_active(void *arg,
  2189. enum spectral_scan_mode smode);
  2190. /**
  2191. * target_if_sops_start_spectral_scan() - Start Spectral scan
  2192. * @arg: Pointer to handle for Spectral target_if internal private data
  2193. * @smode: Spectral scan mode
  2194. * @err: Pointer to error code
  2195. *
  2196. * Function to start spectral scan
  2197. *
  2198. * Return: 0 on success else failure
  2199. */
  2200. uint32_t target_if_sops_start_spectral_scan(void *arg,
  2201. enum spectral_scan_mode smode,
  2202. enum spectral_cp_error_code *err);
  2203. /**
  2204. * target_if_sops_stop_spectral_scan() - Stop Spectral scan
  2205. * @arg: Pointer to handle for Spectral target_if internal private data
  2206. * @smode: Spectral scan mode
  2207. *
  2208. * Function to stop spectral scan
  2209. *
  2210. * Return: 0 in case of success, -1 on failure
  2211. */
  2212. uint32_t target_if_sops_stop_spectral_scan(void *arg,
  2213. enum spectral_scan_mode smode);
  2214. /**
  2215. * target_if_spectral_get_extension_channel() - Get the current Extension
  2216. * channel (in MHz)
  2217. * @arg: Pointer to handle for Spectral target_if internal private data
  2218. * @smode: Spectral scan mode
  2219. *
  2220. * Return: Current Extension channel (in MHz) on success, 0 on failure or if
  2221. * extension channel is not present.
  2222. */
  2223. uint32_t
  2224. target_if_spectral_get_extension_channel(void *arg,
  2225. enum spectral_scan_mode smode);
  2226. /**
  2227. * target_if_spectral_get_current_channel() - Get the current channel (in MHz)
  2228. * @arg: Pointer to handle for Spectral target_if internal private data
  2229. * @smode: Spectral scan mode
  2230. *
  2231. * Return: Current channel (in MHz) on success, 0 on failure
  2232. */
  2233. uint32_t
  2234. target_if_spectral_get_current_channel(void *arg,
  2235. enum spectral_scan_mode smode);
  2236. /**
  2237. * target_if_spectral_reset_hw() - Reset the hardware
  2238. * @arg: Pointer to handle for Spectral target_if internal private data
  2239. *
  2240. * This is only a placeholder since it is not currently required in the offload
  2241. * case.
  2242. *
  2243. * Return: 0
  2244. */
  2245. uint32_t target_if_spectral_reset_hw(void *arg);
  2246. /**
  2247. * target_if_spectral_get_chain_noise_floor() - Get the Chain noise floor from
  2248. * Noisefloor history buffer
  2249. * @arg: Pointer to handle for Spectral target_if internal private data
  2250. * @nf_buf: Pointer to buffer into which chain Noise Floor data should be copied
  2251. *
  2252. * This is only a placeholder since it is not currently required in the offload
  2253. * case.
  2254. *
  2255. * Return: 0
  2256. */
  2257. uint32_t target_if_spectral_get_chain_noise_floor(void *arg, int16_t *nf_buf);
  2258. /**
  2259. * target_if_spectral_get_ext_noisefloor() - Get the extension channel
  2260. * noisefloor
  2261. * @arg: Pointer to handle for Spectral target_if internal private data
  2262. *
  2263. * This is only a placeholder since it is not currently required in the offload
  2264. * case.
  2265. *
  2266. * Return: 0
  2267. */
  2268. int8_t target_if_spectral_get_ext_noisefloor(void *arg);
  2269. /**
  2270. * target_if_spectral_get_ctl_noisefloor() - Get the control channel noisefloor
  2271. * @arg: Pointer to handle for Spectral target_if internal private data
  2272. *
  2273. * This is only a placeholder since it is not currently required in the offload
  2274. * case.
  2275. *
  2276. * Return: 0
  2277. */
  2278. int8_t target_if_spectral_get_ctl_noisefloor(void *arg);
  2279. /**
  2280. * target_if_spectral_get_capability() - Get whether a given Spectral hardware
  2281. * capability is available
  2282. * @arg: Pointer to handle for Spectral target_if internal private data
  2283. * @type: Spectral hardware capability type
  2284. *
  2285. * Return: True if the capability is available, false if the capability is not
  2286. * available
  2287. */
  2288. uint32_t target_if_spectral_get_capability(
  2289. void *arg, enum spectral_capability_type type);
  2290. /**
  2291. * target_if_spectral_set_rxfilter() - Set the RX Filter before Spectral start
  2292. * @arg: Pointer to handle for Spectral target_if internal private data
  2293. * @rxfilter: Rx filter to be used
  2294. *
  2295. * Note: This is only a placeholder function. It is not currently required since
  2296. * FW should be taking care of setting the required filters.
  2297. *
  2298. * Return: 0
  2299. */
  2300. uint32_t target_if_spectral_set_rxfilter(void *arg, int rxfilter);
  2301. /**
  2302. * target_if_spectral_sops_configure_params() - Configure user supplied Spectral
  2303. * parameters
  2304. * @arg: Pointer to handle for Spectral target_if internal private data
  2305. * @params: Spectral parameters
  2306. * @smode: Spectral scan mode
  2307. *
  2308. * Return: 0 in case of success, -1 on failure
  2309. */
  2310. uint32_t target_if_spectral_sops_configure_params(
  2311. void *arg, struct spectral_config *params,
  2312. enum spectral_scan_mode smode);
  2313. /**
  2314. * target_if_spectral_get_rxfilter() - Get the current RX Filter settings
  2315. * @arg: Pointer to handle for Spectral target_if internal private data
  2316. *
  2317. * Note: This is only a placeholder function. It is not currently required since
  2318. * FW should be taking care of setting the required filters.
  2319. *
  2320. * Return: 0
  2321. */
  2322. uint32_t target_if_spectral_get_rxfilter(void *arg);
  2323. /**
  2324. * target_if_pdev_spectral_deinit() - De-initialize target_if Spectral
  2325. * functionality for the given pdev
  2326. * @pdev: Pointer to pdev object
  2327. *
  2328. * Return: None
  2329. */
  2330. void target_if_pdev_spectral_deinit(struct wlan_objmgr_pdev *pdev);
  2331. /**
  2332. * target_if_set_spectral_config() - Set spectral config
  2333. * @pdev: Pointer to pdev object
  2334. * @param: Spectral parameter id and value
  2335. * @smode: Spectral scan mode
  2336. * @err: Pointer to Spectral error code
  2337. *
  2338. * API to set spectral configurations
  2339. *
  2340. * Return: QDF_STATUS_SUCCESS in case of success, else QDF_STATUS_E_FAILURE
  2341. */
  2342. QDF_STATUS target_if_set_spectral_config(struct wlan_objmgr_pdev *pdev,
  2343. const struct spectral_cp_param *param,
  2344. const enum spectral_scan_mode smode,
  2345. enum spectral_cp_error_code *err);
  2346. /**
  2347. * target_if_pdev_spectral_init() - Initialize target_if Spectral
  2348. * functionality for the given pdev
  2349. * @pdev: Pointer to pdev object
  2350. *
  2351. * Return: On success, pointer to Spectral target_if internal private data, on
  2352. * failure, NULL
  2353. */
  2354. void *target_if_pdev_spectral_init(struct wlan_objmgr_pdev *pdev);
  2355. /**
  2356. * target_if_spectral_sops_get_params() - Get user configured Spectral
  2357. * parameters
  2358. * @arg: Pointer to handle for Spectral target_if internal private data
  2359. * @params: Pointer to buffer into which Spectral parameters should be copied
  2360. * @smode: Spectral scan mode
  2361. *
  2362. * Return: 0 in case of success, -1 on failure
  2363. */
  2364. uint32_t target_if_spectral_sops_get_params(
  2365. void *arg, struct spectral_config *params,
  2366. enum spectral_scan_mode smode);
  2367. /**
  2368. * target_if_init_spectral_capability() - Initialize Spectral capability
  2369. *
  2370. * @spectral: Pointer to Spectral target_if internal private data
  2371. * @target_type: target type
  2372. *
  2373. * This is a workaround.
  2374. *
  2375. * Return: QDF_STATUS
  2376. */
  2377. QDF_STATUS
  2378. target_if_init_spectral_capability(struct target_if_spectral *spectral,
  2379. uint32_t target_type);
  2380. /**
  2381. * target_if_start_spectral_scan() - Start spectral scan
  2382. * @pdev: Pointer to pdev object
  2383. * @vdev_id: VDEV id
  2384. * @smode: Spectral scan mode
  2385. * @err: Spectral error code
  2386. *
  2387. * API to start spectral scan
  2388. *
  2389. * Return: QDF_STATUS_SUCCESS in case of success, else QDF_STATUS_E_FAILURE
  2390. */
  2391. QDF_STATUS target_if_start_spectral_scan(struct wlan_objmgr_pdev *pdev,
  2392. uint8_t vdev_id,
  2393. enum spectral_scan_mode smode,
  2394. enum spectral_cp_error_code *err);
  2395. /**
  2396. * target_if_get_spectral_config() - Get spectral configuration
  2397. * @pdev: Pointer to pdev object
  2398. * @param: Pointer to spectral_config structure in which the configuration
  2399. * should be returned
  2400. * @smode: Spectral scan mode
  2401. *
  2402. * API to get the current spectral configuration
  2403. *
  2404. * Return: QDF_STATUS_SUCCESS in case of success, else QDF_STATUS_E_FAILURE
  2405. */
  2406. QDF_STATUS target_if_get_spectral_config(struct wlan_objmgr_pdev *pdev,
  2407. struct spectral_config *param,
  2408. enum spectral_scan_mode smode);
  2409. /**
  2410. * target_if_spectral_scan_enable_params() - Enable use of desired Spectral
  2411. * parameters
  2412. * @spectral: Pointer to Spectral target_if internal private data
  2413. * @spectral_params: Pointer to Spectral parameters
  2414. * @smode: Spectral scan mode
  2415. * @err: Spectral error code
  2416. *
  2417. * Enable use of desired Spectral parameters by configuring them into HW, and
  2418. * starting Spectral scan
  2419. *
  2420. * Return: 0 on success, 1 on failure
  2421. */
  2422. int target_if_spectral_scan_enable_params(
  2423. struct target_if_spectral *spectral,
  2424. struct spectral_config *spectral_params,
  2425. enum spectral_scan_mode smode,
  2426. enum spectral_cp_error_code *err);
  2427. /**
  2428. * target_if_is_spectral_active() - Get whether Spectral is active
  2429. * @pdev: Pointer to pdev object
  2430. * @smode: Spectral scan mode
  2431. *
  2432. * Return: True if Spectral is active, false if Spectral is not active
  2433. */
  2434. bool target_if_is_spectral_active(struct wlan_objmgr_pdev *pdev,
  2435. enum spectral_scan_mode smode);
  2436. /**
  2437. * target_if_is_spectral_enabled() - Get whether Spectral is enabled
  2438. * @pdev: Pointer to pdev object
  2439. * @smode: Spectral scan mode
  2440. *
  2441. * Return: True if Spectral is enabled, false if Spectral is not enabled
  2442. */
  2443. bool target_if_is_spectral_enabled(struct wlan_objmgr_pdev *pdev,
  2444. enum spectral_scan_mode smode);
  2445. /**
  2446. * target_if_set_debug_level() - Set debug level for Spectral
  2447. * @pdev: Pointer to pdev object
  2448. * @debug_level: Debug level
  2449. *
  2450. * Return: QDF_STATUS_SUCCESS in case of success, else QDF_STATUS_E_FAILURE
  2451. *
  2452. */
  2453. QDF_STATUS target_if_set_debug_level(struct wlan_objmgr_pdev *pdev,
  2454. uint32_t debug_level);
  2455. /**
  2456. * target_if_get_debug_level() - Get debug level for Spectral
  2457. * @pdev: Pointer to pdev object
  2458. *
  2459. * Return: Current debug level
  2460. */
  2461. uint32_t target_if_get_debug_level(struct wlan_objmgr_pdev *pdev);
  2462. /**
  2463. * target_if_get_spectral_capinfo() - Get Spectral capability information
  2464. * @pdev: Pointer to pdev object
  2465. * @scaps: Buffer into which data should be copied
  2466. *
  2467. * Return: QDF_STATUS_SUCCESS in case of success, else QDF_STATUS_E_FAILURE
  2468. */
  2469. QDF_STATUS target_if_get_spectral_capinfo(struct wlan_objmgr_pdev *pdev,
  2470. struct spectral_caps *scaps);
  2471. /**
  2472. * target_if_get_spectral_diagstats() - Get Spectral diagnostic statistics
  2473. * @pdev: Pointer to pdev object
  2474. * @stats: Buffer into which data should be copied
  2475. *
  2476. * Return: QDF_STATUS_SUCCESS in case of success, else QDF_STATUS_E_FAILURE
  2477. */
  2478. QDF_STATUS target_if_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev,
  2479. struct spectral_diag_stats *stats);
  2480. QDF_STATUS
  2481. target_if_160mhz_delivery_state_change(struct target_if_spectral *spectral,
  2482. enum spectral_scan_mode smode,
  2483. uint8_t detector_id);
  2484. #ifdef OPTIMIZED_SAMP_MESSAGE
  2485. /**
  2486. * target_if_spectral_get_num_fft_bins() - Get number of FFT bins from FFT size
  2487. * according to the Spectral report mode.
  2488. * @fft_size: FFT length
  2489. * @report_mode: Spectral report mode
  2490. *
  2491. * Get number of FFT bins from FFT size according to the Spectral
  2492. * report mode.
  2493. *
  2494. * Return: Number of FFT bins
  2495. */
  2496. static inline uint32_t
  2497. target_if_spectral_get_num_fft_bins(uint32_t fft_size,
  2498. enum spectral_report_mode report_mode)
  2499. {
  2500. switch (report_mode) {
  2501. case SPECTRAL_REPORT_MODE_0:
  2502. case SPECTRAL_REPORT_MODE_1:
  2503. return 0;
  2504. case SPECTRAL_REPORT_MODE_2:
  2505. return (1 << (fft_size - 1));
  2506. case SPECTRAL_REPORT_MODE_3:
  2507. return (1 << fft_size);
  2508. default:
  2509. return -EINVAL;
  2510. }
  2511. }
  2512. #endif /* OPTIMIZED_SAMP_MESSAGE */
  2513. #ifdef OPTIMIZED_SAMP_MESSAGE
  2514. /**
  2515. * target_if_get_detector_chwidth() - Get per-detector bandwidth
  2516. * based on channel width and fragmentation.
  2517. * @ch_width: Spectral scan channel width
  2518. * @fragmentation_160: Target type has fragmentation or not
  2519. *
  2520. * Get per-detector BW.
  2521. *
  2522. * Return: detector BW
  2523. */
  2524. static inline
  2525. enum phy_ch_width target_if_get_detector_chwidth(enum phy_ch_width ch_width,
  2526. bool fragmentation_160)
  2527. {
  2528. return ((ch_width == CH_WIDTH_160MHZ && fragmentation_160) ?
  2529. CH_WIDTH_80MHZ : ((ch_width == CH_WIDTH_80P80MHZ) ?
  2530. CH_WIDTH_80MHZ : ch_width));
  2531. }
  2532. /**
  2533. * target_if_spectral_set_start_end_freq() - Set start and end frequencies for
  2534. * a given center frequency
  2535. * @cfreq: Center frequency for which start and end freq need to be set
  2536. * @ch_width: Spectral scan Channel width
  2537. * @fragmentation_160: Target type has fragmentation or not
  2538. * @start_end_freq: Array containing start and end frequency of detector
  2539. *
  2540. * Set the start and end frequencies for given center frequency in destination
  2541. * detector info struct
  2542. *
  2543. * Return: void
  2544. */
  2545. static inline
  2546. void target_if_spectral_set_start_end_freq(uint32_t cfreq,
  2547. enum phy_ch_width ch_width,
  2548. bool fragmentation_160,
  2549. uint32_t *start_end_freq)
  2550. {
  2551. enum phy_ch_width det_ch_width;
  2552. det_ch_width = target_if_get_detector_chwidth(ch_width,
  2553. fragmentation_160);
  2554. start_end_freq[0] = cfreq - (wlan_reg_get_bw_value(det_ch_width) >> 1);
  2555. start_end_freq[1] = cfreq + (wlan_reg_get_bw_value(det_ch_width) >> 1);
  2556. }
  2557. #endif /* OPTIMIZED_SAMP_MESSAGE */
  2558. #ifdef DIRECT_BUF_RX_ENABLE
  2559. /**
  2560. * target_if_consume_sfft_report_gen3() - Process fft report for gen3
  2561. * @spectral: Pointer to spectral object
  2562. * @report: Pointer to spectral report
  2563. *
  2564. * Process fft report for gen3
  2565. *
  2566. * Return: Success/Failure
  2567. */
  2568. int
  2569. target_if_consume_spectral_report_gen3(
  2570. struct target_if_spectral *spectral,
  2571. struct spectral_report *report);
  2572. #endif
  2573. /**
  2574. * target_if_spectral_fw_hang() - Crash the FW from Spectral module
  2575. * @spectral: Pointer to Spectral LMAC object
  2576. *
  2577. * Return: QDF_STATUS of operation
  2578. */
  2579. QDF_STATUS target_if_spectral_fw_hang(struct target_if_spectral *spectral);
  2580. /**
  2581. * target_if_spectral_finite_scan_update() - Update scan count for finite scan
  2582. * and stop Spectral scan when required
  2583. * @spectral: Pointer to Spectral target_if internal private data
  2584. * @smode: Spectral scan mode
  2585. *
  2586. * This API decrements the number of Spectral reports expected from target for
  2587. * a finite Spectral scan. When expected number of reports are received from
  2588. * target Spectral scan is stopped.
  2589. *
  2590. * Return: QDF_STATUS on success
  2591. */
  2592. QDF_STATUS
  2593. target_if_spectral_finite_scan_update(struct target_if_spectral *spectral,
  2594. enum spectral_scan_mode smode);
  2595. /**
  2596. * target_if_spectral_is_finite_scan() - Check Spectral scan is finite/infinite
  2597. * @spectral: Pointer to Spectral target_if internal private data
  2598. * @smode: Spectral scan mode
  2599. *
  2600. * API to check whether Spectral scan is finite/infinite for the give mode.
  2601. * A non zero scan count indicates that scan is finite. Scan count of 0
  2602. * indicates an infinite Spectral scan.
  2603. *
  2604. * Return: QDF_STATUS on success
  2605. */
  2606. QDF_STATUS
  2607. target_if_spectral_is_finite_scan(struct target_if_spectral *spectral,
  2608. enum spectral_scan_mode smode,
  2609. bool *finite_spectral_scan);
  2610. #ifdef BIG_ENDIAN_HOST
  2611. /**
  2612. * target_if_byte_swap_spectral_headers_gen3() - Apply byte-swap on headers
  2613. * @spectral: Pointer to Spectral target_if internal private data
  2614. * @data: Pointer to the start of Spectral Scan Summary report
  2615. *
  2616. * This API is only required for Big-endian Host platforms.
  2617. * It applies 32-bit byte-swap on Spectral Scan Summary and Search FFT reports
  2618. * and copies them back to the source location.
  2619. * Padding bytes that lie between the reports won't be touched.
  2620. *
  2621. * Return: QDF_STATUS_SUCCESS in case of success, else QDF_STATUS_E_FAILURE
  2622. */
  2623. QDF_STATUS target_if_byte_swap_spectral_headers_gen3(
  2624. struct target_if_spectral *spectral,
  2625. void *data);
  2626. /**
  2627. * target_if_byte_swap_spectral_fft_bins_gen3() - Apply byte-swap on FFT bins
  2628. * @rparams: Pointer to Spectral report parameters
  2629. * @bin_pwr_data: Pointer to the start of FFT bins
  2630. * @num_fftbins: Number of FFT bins
  2631. *
  2632. * This API is only required for Big-endian Host platforms.
  2633. * It applies pack-mode-aware byte-swap on the FFT bins as below:
  2634. * 1. pack-mode 0 (i.e., 1 FFT bin per DWORD):
  2635. * Reads the least significant 2 bytes of each DWORD, applies 16-bit
  2636. * byte-swap on that value, and copies it back to the source location.
  2637. * 2. pack-mode 1 (i.e., 2 FFT bins per DWORD):
  2638. * Reads each FFT bin, applies 16-bit byte-swap on that value,
  2639. * and copies it back to the source location.
  2640. * 3. pack-mode 2 (4 FFT bins per DWORD):
  2641. * Nothing
  2642. *
  2643. * Return: QDF_STATUS_SUCCESS in case of success, else QDF_STATUS_E_FAILURE
  2644. */
  2645. QDF_STATUS target_if_byte_swap_spectral_fft_bins_gen3(
  2646. const struct spectral_report_params *rparams,
  2647. void *bin_pwr_data, size_t num_fftbins);
  2648. #endif /* BIG_ENDIAN_HOST */
  2649. #ifdef OPTIMIZED_SAMP_MESSAGE
  2650. /**
  2651. * target_if_populate_fft_bins_info() - Populate the start and end bin
  2652. * indices, on per-detector level.
  2653. * @spectral: Pointer to target_if spectral internal structure
  2654. * @smode: Spectral scan mode
  2655. *
  2656. * Populate the start and end bin indices, on per-detector level.
  2657. *
  2658. * Return: Success/Failure
  2659. */
  2660. QDF_STATUS
  2661. target_if_populate_fft_bins_info(struct target_if_spectral *spectral,
  2662. enum spectral_scan_mode smode);
  2663. #else
  2664. static inline QDF_STATUS
  2665. target_if_populate_fft_bins_info(struct target_if_spectral *spectral,
  2666. enum spectral_scan_mode smode)
  2667. {
  2668. return QDF_STATUS_SUCCESS;
  2669. }
  2670. #endif
  2671. /**
  2672. * spectral_is_session_info_expected_from_target() - Check if spectral scan
  2673. * session is expected from target
  2674. * @pdev: pdev pointer
  2675. * @is_session_info_expected: Pointer to caller variable
  2676. *
  2677. * Return: QDF_STATUS of operation
  2678. */
  2679. QDF_STATUS
  2680. spectral_is_session_info_expected_from_target(struct wlan_objmgr_pdev *pdev,
  2681. bool *is_session_info_expected);
  2682. #ifdef WIN32
  2683. #pragma pack(pop, target_if_spectral)
  2684. #endif
  2685. #ifdef __ATTRIB_PACK
  2686. #undef __ATTRIB_PACK
  2687. #endif
  2688. /**
  2689. * target_if_spectral_copy_fft_bins() - Copy FFT bins from source buffer to
  2690. * destination buffer
  2691. * @spectral: Pointer to Spectral LMAC object
  2692. * @src_fft_buf: Pointer to source FFT buffer
  2693. * @dest_fft_buf: Pointer to destination FFT buffer
  2694. * @fft_bin_count: Number of FFT bins to copy
  2695. * @bytes_copied: Number of bytes copied by this API
  2696. *
  2697. * Different targets supports different FFT bin widths. This API encapsulates
  2698. * all those details and copies 8-bit FFT value into the destination buffer.
  2699. * Also, this API takes care of handling big-endian mode.
  2700. * In essence, it does the following.
  2701. * - Read DWORDs one by one
  2702. * - Extract individual FFT bins out of it
  2703. * - Copy the FFT bin to destination buffer
  2704. *
  2705. * Return: QDF_STATUS_SUCCESS in case of success, else QDF_STATUS_E_FAILURE
  2706. */
  2707. QDF_STATUS
  2708. target_if_spectral_copy_fft_bins(struct target_if_spectral *spectral,
  2709. const void *src_fft_buf,
  2710. void *dest_fft_buf,
  2711. uint32_t fft_bin_count,
  2712. uint32_t *bytes_copied);
  2713. #endif /* WLAN_CONV_SPECTRAL_ENABLE */
  2714. #endif /* _TARGET_IF_SPECTRAL_H_ */