ce_main.c 125 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499
  1. /*
  2. * Copyright (c) 2013-2021 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #include "targcfg.h"
  19. #include "qdf_lock.h"
  20. #include "qdf_status.h"
  21. #include "qdf_status.h"
  22. #include <qdf_atomic.h> /* qdf_atomic_read */
  23. #include <targaddrs.h>
  24. #include "hif_io32.h"
  25. #include <hif.h>
  26. #include <target_type.h>
  27. #include "regtable.h"
  28. #define ATH_MODULE_NAME hif
  29. #include <a_debug.h>
  30. #include "hif_main.h"
  31. #include "ce_api.h"
  32. #include "qdf_trace.h"
  33. #include "pld_common.h"
  34. #include "hif_debug.h"
  35. #include "ce_internal.h"
  36. #include "ce_reg.h"
  37. #include "ce_assignment.h"
  38. #include "ce_tasklet.h"
  39. #include "qdf_module.h"
  40. #define CE_POLL_TIMEOUT 10 /* ms */
  41. #define AGC_DUMP 1
  42. #define CHANINFO_DUMP 2
  43. #define BB_WATCHDOG_DUMP 3
  44. #ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
  45. #define PCIE_ACCESS_DUMP 4
  46. #endif
  47. #include "mp_dev.h"
  48. #ifdef HIF_CE_LOG_INFO
  49. #include "qdf_hang_event_notifier.h"
  50. #endif
  51. #if (defined(QCA_WIFI_QCA8074) || defined(QCA_WIFI_QCA6290) || \
  52. defined(QCA_WIFI_QCA6018) || defined(QCA_WIFI_QCA5018)) && \
  53. !defined(QCA_WIFI_SUPPORT_SRNG)
  54. #define QCA_WIFI_SUPPORT_SRNG
  55. #endif
  56. #ifdef QCA_WIFI_SUPPORT_SRNG
  57. #include <hal_api.h>
  58. #endif
  59. /* Forward references */
  60. QDF_STATUS hif_post_recv_buffers_for_pipe(struct HIF_CE_pipe_info *pipe_info);
  61. /*
  62. * Fix EV118783, poll to check whether a BMI response comes
  63. * other than waiting for the interruption which may be lost.
  64. */
  65. /* #define BMI_RSP_POLLING */
  66. #define BMI_RSP_TO_MILLISEC 1000
  67. #ifdef CONFIG_BYPASS_QMI
  68. #define BYPASS_QMI 1
  69. #else
  70. #define BYPASS_QMI 0
  71. #endif
  72. #ifdef ENABLE_10_4_FW_HDR
  73. #if (ENABLE_10_4_FW_HDR == 1)
  74. #define WDI_IPA_SERVICE_GROUP 5
  75. #define WDI_IPA_TX_SVC MAKE_SERVICE_ID(WDI_IPA_SERVICE_GROUP, 0)
  76. #define HTT_DATA2_MSG_SVC MAKE_SERVICE_ID(HTT_SERVICE_GROUP, 1)
  77. #define HTT_DATA3_MSG_SVC MAKE_SERVICE_ID(HTT_SERVICE_GROUP, 2)
  78. #endif /* ENABLE_10_4_FW_HDR == 1 */
  79. #endif /* ENABLE_10_4_FW_HDR */
  80. static void hif_config_rri_on_ddr(struct hif_softc *scn);
  81. /**
  82. * hif_target_access_log_dump() - dump access log
  83. *
  84. * dump access log
  85. *
  86. * Return: n/a
  87. */
  88. #ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
  89. static void hif_target_access_log_dump(void)
  90. {
  91. hif_target_dump_access_log();
  92. }
  93. #endif
  94. void hif_trigger_dump(struct hif_opaque_softc *hif_ctx,
  95. uint8_t cmd_id, bool start)
  96. {
  97. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  98. switch (cmd_id) {
  99. case AGC_DUMP:
  100. if (start)
  101. priv_start_agc(scn);
  102. else
  103. priv_dump_agc(scn);
  104. break;
  105. case CHANINFO_DUMP:
  106. if (start)
  107. priv_start_cap_chaninfo(scn);
  108. else
  109. priv_dump_chaninfo(scn);
  110. break;
  111. case BB_WATCHDOG_DUMP:
  112. priv_dump_bbwatchdog(scn);
  113. break;
  114. #ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
  115. case PCIE_ACCESS_DUMP:
  116. hif_target_access_log_dump();
  117. break;
  118. #endif
  119. default:
  120. hif_err("Invalid htc dump command: %d", cmd_id);
  121. break;
  122. }
  123. }
  124. static void ce_poll_timeout(void *arg)
  125. {
  126. struct CE_state *CE_state = (struct CE_state *)arg;
  127. if (CE_state->timer_inited) {
  128. ce_per_engine_service(CE_state->scn, CE_state->id);
  129. qdf_timer_mod(&CE_state->poll_timer, CE_POLL_TIMEOUT);
  130. }
  131. }
  132. static unsigned int roundup_pwr2(unsigned int n)
  133. {
  134. int i;
  135. unsigned int test_pwr2;
  136. if (!(n & (n - 1)))
  137. return n; /* already a power of 2 */
  138. test_pwr2 = 4;
  139. for (i = 0; i < 29; i++) {
  140. if (test_pwr2 > n)
  141. return test_pwr2;
  142. test_pwr2 = test_pwr2 << 1;
  143. }
  144. QDF_ASSERT(0); /* n too large */
  145. return 0;
  146. }
  147. #define ADRASTEA_SRC_WR_INDEX_OFFSET 0x3C
  148. #define ADRASTEA_DST_WR_INDEX_OFFSET 0x40
  149. static struct shadow_reg_cfg target_shadow_reg_cfg_map[] = {
  150. { 0, ADRASTEA_SRC_WR_INDEX_OFFSET},
  151. { 3, ADRASTEA_SRC_WR_INDEX_OFFSET},
  152. { 4, ADRASTEA_SRC_WR_INDEX_OFFSET},
  153. { 5, ADRASTEA_SRC_WR_INDEX_OFFSET},
  154. { 7, ADRASTEA_SRC_WR_INDEX_OFFSET},
  155. { 1, ADRASTEA_DST_WR_INDEX_OFFSET},
  156. { 2, ADRASTEA_DST_WR_INDEX_OFFSET},
  157. { 7, ADRASTEA_DST_WR_INDEX_OFFSET},
  158. { 8, ADRASTEA_DST_WR_INDEX_OFFSET},
  159. #ifdef QCA_WIFI_3_0_ADRASTEA
  160. { 9, ADRASTEA_DST_WR_INDEX_OFFSET},
  161. { 10, ADRASTEA_DST_WR_INDEX_OFFSET},
  162. { 11, ADRASTEA_DST_WR_INDEX_OFFSET},
  163. #endif
  164. };
  165. #ifdef QCN7605_SUPPORT
  166. static struct shadow_reg_cfg target_shadow_reg_cfg_map_qcn7605[] = {
  167. { 0, ADRASTEA_SRC_WR_INDEX_OFFSET},
  168. { 4, ADRASTEA_SRC_WR_INDEX_OFFSET},
  169. { 5, ADRASTEA_SRC_WR_INDEX_OFFSET},
  170. { 3, ADRASTEA_DST_WR_INDEX_OFFSET},
  171. { 1, ADRASTEA_DST_WR_INDEX_OFFSET},
  172. { 2, ADRASTEA_DST_WR_INDEX_OFFSET},
  173. { 7, ADRASTEA_DST_WR_INDEX_OFFSET},
  174. { 8, ADRASTEA_DST_WR_INDEX_OFFSET},
  175. };
  176. #endif
  177. #ifdef WLAN_FEATURE_EPPING
  178. static struct shadow_reg_cfg target_shadow_reg_cfg_epping[] = {
  179. { 0, ADRASTEA_SRC_WR_INDEX_OFFSET},
  180. { 3, ADRASTEA_SRC_WR_INDEX_OFFSET},
  181. { 4, ADRASTEA_SRC_WR_INDEX_OFFSET},
  182. { 7, ADRASTEA_SRC_WR_INDEX_OFFSET},
  183. { 1, ADRASTEA_DST_WR_INDEX_OFFSET},
  184. { 2, ADRASTEA_DST_WR_INDEX_OFFSET},
  185. { 5, ADRASTEA_DST_WR_INDEX_OFFSET},
  186. { 7, ADRASTEA_DST_WR_INDEX_OFFSET},
  187. { 8, ADRASTEA_DST_WR_INDEX_OFFSET},
  188. };
  189. #endif
  190. /* CE_PCI TABLE */
  191. /*
  192. * NOTE: the table below is out of date, though still a useful reference.
  193. * Refer to target_service_to_ce_map and hif_map_service_to_pipe for the actual
  194. * mapping of HTC services to HIF pipes.
  195. */
  196. /*
  197. * This authoritative table defines Copy Engine configuration and the mapping
  198. * of services/endpoints to CEs. A subset of this information is passed to
  199. * the Target during startup as a prerequisite to entering BMI phase.
  200. * See:
  201. * target_service_to_ce_map - Target-side mapping
  202. * hif_map_service_to_pipe - Host-side mapping
  203. * target_ce_config - Target-side configuration
  204. * host_ce_config - Host-side configuration
  205. ============================================================================
  206. Purpose | Service / Endpoint | CE | Dire | Xfer | Xfer
  207. | | | ctio | Size | Frequency
  208. | | | n | |
  209. ============================================================================
  210. tx | HTT_DATA (downlink) | CE 0 | h->t | medium - | very frequent
  211. descriptor | | | | O(100B) | and regular
  212. download | | | | |
  213. ----------------------------------------------------------------------------
  214. rx | HTT_DATA (uplink) | CE 1 | t->h | small - | frequent and
  215. indication | | | | O(10B) | regular
  216. upload | | | | |
  217. ----------------------------------------------------------------------------
  218. MSDU | DATA_BK (uplink) | CE 2 | t->h | large - | rare
  219. upload | | | | O(1000B) | (frequent
  220. e.g. noise | | | | | during IP1.0
  221. packets | | | | | testing)
  222. ----------------------------------------------------------------------------
  223. MSDU | DATA_BK (downlink) | CE 3 | h->t | large - | very rare
  224. download | | | | O(1000B) | (frequent
  225. e.g. | | | | | during IP1.0
  226. misdirecte | | | | | testing)
  227. d EAPOL | | | | |
  228. packets | | | | |
  229. ----------------------------------------------------------------------------
  230. n/a | DATA_BE, DATA_VI | CE 2 | t->h | | never(?)
  231. | DATA_VO (uplink) | | | |
  232. ----------------------------------------------------------------------------
  233. n/a | DATA_BE, DATA_VI | CE 3 | h->t | | never(?)
  234. | DATA_VO (downlink) | | | |
  235. ----------------------------------------------------------------------------
  236. WMI events | WMI_CONTROL (uplink) | CE 4 | t->h | medium - | infrequent
  237. | | | | O(100B) |
  238. ----------------------------------------------------------------------------
  239. WMI | WMI_CONTROL | CE 5 | h->t | medium - | infrequent
  240. messages | (downlink) | | | O(100B) |
  241. | | | | |
  242. ----------------------------------------------------------------------------
  243. n/a | HTC_CTRL_RSVD, | CE 1 | t->h | | never(?)
  244. | HTC_RAW_STREAMS | | | |
  245. | (uplink) | | | |
  246. ----------------------------------------------------------------------------
  247. n/a | HTC_CTRL_RSVD, | CE 0 | h->t | | never(?)
  248. | HTC_RAW_STREAMS | | | |
  249. | (downlink) | | | |
  250. ----------------------------------------------------------------------------
  251. diag | none (raw CE) | CE 7 | t<>h | 4 | Diag Window
  252. | | | | | infrequent
  253. ============================================================================
  254. */
  255. /*
  256. * Map from service/endpoint to Copy Engine.
  257. * This table is derived from the CE_PCI TABLE, above.
  258. * It is passed to the Target at startup for use by firmware.
  259. */
  260. static struct service_to_pipe target_service_to_ce_map_wlan[] = {
  261. {
  262. WMI_DATA_VO_SVC,
  263. PIPEDIR_OUT, /* out = UL = host -> target */
  264. 3,
  265. },
  266. {
  267. WMI_DATA_VO_SVC,
  268. PIPEDIR_IN, /* in = DL = target -> host */
  269. 2,
  270. },
  271. {
  272. WMI_DATA_BK_SVC,
  273. PIPEDIR_OUT, /* out = UL = host -> target */
  274. 3,
  275. },
  276. {
  277. WMI_DATA_BK_SVC,
  278. PIPEDIR_IN, /* in = DL = target -> host */
  279. 2,
  280. },
  281. {
  282. WMI_DATA_BE_SVC,
  283. PIPEDIR_OUT, /* out = UL = host -> target */
  284. 3,
  285. },
  286. {
  287. WMI_DATA_BE_SVC,
  288. PIPEDIR_IN, /* in = DL = target -> host */
  289. 2,
  290. },
  291. {
  292. WMI_DATA_VI_SVC,
  293. PIPEDIR_OUT, /* out = UL = host -> target */
  294. 3,
  295. },
  296. {
  297. WMI_DATA_VI_SVC,
  298. PIPEDIR_IN, /* in = DL = target -> host */
  299. 2,
  300. },
  301. {
  302. WMI_CONTROL_SVC,
  303. PIPEDIR_OUT, /* out = UL = host -> target */
  304. 3,
  305. },
  306. {
  307. WMI_CONTROL_SVC,
  308. PIPEDIR_IN, /* in = DL = target -> host */
  309. 2,
  310. },
  311. {
  312. HTC_CTRL_RSVD_SVC,
  313. PIPEDIR_OUT, /* out = UL = host -> target */
  314. 0, /* could be moved to 3 (share with WMI) */
  315. },
  316. {
  317. HTC_CTRL_RSVD_SVC,
  318. PIPEDIR_IN, /* in = DL = target -> host */
  319. 2,
  320. },
  321. {
  322. HTC_RAW_STREAMS_SVC, /* not currently used */
  323. PIPEDIR_OUT, /* out = UL = host -> target */
  324. 0,
  325. },
  326. {
  327. HTC_RAW_STREAMS_SVC, /* not currently used */
  328. PIPEDIR_IN, /* in = DL = target -> host */
  329. 2,
  330. },
  331. {
  332. HTT_DATA_MSG_SVC,
  333. PIPEDIR_OUT, /* out = UL = host -> target */
  334. 4,
  335. },
  336. {
  337. HTT_DATA_MSG_SVC,
  338. PIPEDIR_IN, /* in = DL = target -> host */
  339. 1,
  340. },
  341. {
  342. WDI_IPA_TX_SVC,
  343. PIPEDIR_OUT, /* in = DL = target -> host */
  344. 5,
  345. },
  346. #if defined(QCA_WIFI_3_0_ADRASTEA)
  347. {
  348. HTT_DATA2_MSG_SVC,
  349. PIPEDIR_IN, /* in = DL = target -> host */
  350. 9,
  351. },
  352. {
  353. HTT_DATA3_MSG_SVC,
  354. PIPEDIR_IN, /* in = DL = target -> host */
  355. 10,
  356. },
  357. {
  358. PACKET_LOG_SVC,
  359. PIPEDIR_IN, /* in = DL = target -> host */
  360. 11,
  361. },
  362. #endif
  363. /* (Additions here) */
  364. { /* Must be last */
  365. 0,
  366. 0,
  367. 0,
  368. },
  369. };
  370. /* PIPEDIR_OUT = HOST to Target */
  371. /* PIPEDIR_IN = TARGET to HOST */
  372. #if (defined(QCA_WIFI_QCA8074))
  373. static struct service_to_pipe target_service_to_ce_map_qca8074[] = {
  374. { WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
  375. { WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
  376. { WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
  377. { WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
  378. { WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
  379. { WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
  380. { WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
  381. { WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
  382. { WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
  383. { WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
  384. { WMI_CONTROL_SVC_WMAC1, PIPEDIR_OUT, 7},
  385. { WMI_CONTROL_SVC_WMAC1, PIPEDIR_IN, 2},
  386. { HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
  387. { HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 1, },
  388. { HTC_RAW_STREAMS_SVC, PIPEDIR_OUT, 0},
  389. { HTC_RAW_STREAMS_SVC, PIPEDIR_IN, 1 },
  390. { HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
  391. { HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
  392. { PACKET_LOG_SVC, PIPEDIR_IN, 5, },
  393. /* (Additions here) */
  394. { 0, 0, 0, },
  395. };
  396. #else
  397. static struct service_to_pipe target_service_to_ce_map_qca8074[] = {
  398. };
  399. #endif
  400. #if (defined(QCA_WIFI_QCA8074V2))
  401. static struct service_to_pipe target_service_to_ce_map_qca8074_v2[] = {
  402. { WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
  403. { WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
  404. { WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
  405. { WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
  406. { WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
  407. { WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
  408. { WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
  409. { WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
  410. { WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
  411. { WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
  412. { WMI_CONTROL_SVC_WMAC1, PIPEDIR_OUT, 7},
  413. { WMI_CONTROL_SVC_WMAC1, PIPEDIR_IN, 2},
  414. { WMI_CONTROL_SVC_WMAC2, PIPEDIR_OUT, 9},
  415. { WMI_CONTROL_SVC_WMAC2, PIPEDIR_IN, 2},
  416. { HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
  417. { HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 1, },
  418. { HTC_RAW_STREAMS_SVC, PIPEDIR_OUT, 0},
  419. { HTC_RAW_STREAMS_SVC, PIPEDIR_IN, 1 },
  420. { HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
  421. { HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
  422. { PACKET_LOG_SVC, PIPEDIR_IN, 5, },
  423. /* (Additions here) */
  424. { 0, 0, 0, },
  425. };
  426. #else
  427. static struct service_to_pipe target_service_to_ce_map_qca8074_v2[] = {
  428. };
  429. #endif
  430. #if (defined(QCA_WIFI_QCA6018))
  431. static struct service_to_pipe target_service_to_ce_map_qca6018[] = {
  432. { WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
  433. { WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
  434. { WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
  435. { WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
  436. { WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
  437. { WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
  438. { WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
  439. { WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
  440. { WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
  441. { WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
  442. { WMI_CONTROL_SVC_WMAC1, PIPEDIR_OUT, 7},
  443. { WMI_CONTROL_SVC_WMAC1, PIPEDIR_IN, 2},
  444. { HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
  445. { HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 1, },
  446. { HTC_RAW_STREAMS_SVC, PIPEDIR_OUT, 0},
  447. { HTC_RAW_STREAMS_SVC, PIPEDIR_IN, 1 },
  448. { HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
  449. { HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
  450. { PACKET_LOG_SVC, PIPEDIR_IN, 5, },
  451. /* (Additions here) */
  452. { 0, 0, 0, },
  453. };
  454. #else
  455. static struct service_to_pipe target_service_to_ce_map_qca6018[] = {
  456. };
  457. #endif
  458. #if (defined(QCA_WIFI_QCN9000))
  459. static struct service_to_pipe target_service_to_ce_map_qcn9000[] = {
  460. { WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
  461. { WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
  462. { WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
  463. { WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
  464. { WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
  465. { WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
  466. { WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
  467. { WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
  468. { WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
  469. { WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
  470. { HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
  471. { HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 1, },
  472. { HTC_RAW_STREAMS_SVC, PIPEDIR_OUT, 0},
  473. { HTC_RAW_STREAMS_SVC, PIPEDIR_IN, 1 },
  474. { HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
  475. { HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
  476. { PACKET_LOG_SVC, PIPEDIR_IN, 5, },
  477. /* (Additions here) */
  478. { 0, 0, 0, },
  479. };
  480. #else
  481. static struct service_to_pipe target_service_to_ce_map_qcn9000[] = {
  482. };
  483. #endif
  484. #if (defined(QCA_WIFI_QCA5018))
  485. static struct service_to_pipe target_service_to_ce_map_qca5018[] = {
  486. { WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
  487. { WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
  488. { WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
  489. { WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
  490. { WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
  491. { WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
  492. { WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
  493. { WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
  494. { WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
  495. { WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
  496. { HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
  497. { HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 1, },
  498. { HTC_RAW_STREAMS_SVC, PIPEDIR_OUT, 0},
  499. { HTC_RAW_STREAMS_SVC, PIPEDIR_IN, 1 },
  500. { HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
  501. { HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
  502. { PACKET_LOG_SVC, PIPEDIR_IN, 5, },
  503. /* (Additions here) */
  504. { 0, 0, 0, },
  505. };
  506. #else
  507. static struct service_to_pipe target_service_to_ce_map_qca5018[] = {
  508. };
  509. #endif
  510. /* PIPEDIR_OUT = HOST to Target */
  511. /* PIPEDIR_IN = TARGET to HOST */
  512. #ifdef QCN7605_SUPPORT
  513. static struct service_to_pipe target_service_to_ce_map_qcn7605[] = {
  514. { WMI_DATA_VO_SVC, PIPEDIR_OUT, 0, },
  515. { WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
  516. { WMI_DATA_BK_SVC, PIPEDIR_OUT, 0, },
  517. { WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
  518. { WMI_DATA_BE_SVC, PIPEDIR_OUT, 0, },
  519. { WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
  520. { WMI_DATA_VI_SVC, PIPEDIR_OUT, 0, },
  521. { WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
  522. { WMI_CONTROL_SVC, PIPEDIR_OUT, 0, },
  523. { WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
  524. { HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
  525. { HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 2, },
  526. { HTC_RAW_STREAMS_SVC, PIPEDIR_OUT, 0, },
  527. { HTC_RAW_STREAMS_SVC, PIPEDIR_IN, 2, },
  528. { HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
  529. { HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
  530. { HTT_DATA2_MSG_SVC, PIPEDIR_IN, 3, },
  531. #ifdef IPA_OFFLOAD
  532. { WDI_IPA_TX_SVC, PIPEDIR_OUT, 5, },
  533. #else
  534. { HTT_DATA3_MSG_SVC, PIPEDIR_IN, 8, },
  535. #endif
  536. { PACKET_LOG_SVC, PIPEDIR_IN, 7, },
  537. /* (Additions here) */
  538. { 0, 0, 0, },
  539. };
  540. #endif
  541. #if (defined(QCA_WIFI_QCA6290))
  542. #ifdef QCA_6290_AP_MODE
  543. static struct service_to_pipe target_service_to_ce_map_qca6290[] = {
  544. { WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
  545. { WMI_DATA_VO_SVC, PIPEDIR_IN , 2, },
  546. { WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
  547. { WMI_DATA_BK_SVC, PIPEDIR_IN , 2, },
  548. { WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
  549. { WMI_DATA_BE_SVC, PIPEDIR_IN , 2, },
  550. { WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
  551. { WMI_DATA_VI_SVC, PIPEDIR_IN , 2, },
  552. { WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
  553. { WMI_CONTROL_SVC, PIPEDIR_IN , 2, },
  554. { HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
  555. { HTC_CTRL_RSVD_SVC, PIPEDIR_IN , 2, },
  556. { HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
  557. { HTT_DATA_MSG_SVC, PIPEDIR_IN , 1, },
  558. { WMI_CONTROL_SVC_WMAC1, PIPEDIR_OUT, 7},
  559. { WMI_CONTROL_SVC_WMAC1, PIPEDIR_IN, 2},
  560. { PACKET_LOG_SVC, PIPEDIR_IN, 5, },
  561. /* (Additions here) */
  562. { 0, 0, 0, },
  563. };
  564. #else
  565. static struct service_to_pipe target_service_to_ce_map_qca6290[] = {
  566. { WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
  567. { WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
  568. { WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
  569. { WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
  570. { WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
  571. { WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
  572. { WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
  573. { WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
  574. { WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
  575. { WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
  576. { HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
  577. { HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 2, },
  578. { HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
  579. { HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
  580. /* (Additions here) */
  581. { 0, 0, 0, },
  582. };
  583. #endif
  584. #else
  585. static struct service_to_pipe target_service_to_ce_map_qca6290[] = {
  586. };
  587. #endif
  588. #if (defined(QCA_WIFI_QCA6390))
  589. static struct service_to_pipe target_service_to_ce_map_qca6390[] = {
  590. { WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
  591. { WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
  592. { WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
  593. { WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
  594. { WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
  595. { WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
  596. { WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
  597. { WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
  598. { WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
  599. { WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
  600. { HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
  601. { HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 2, },
  602. { HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
  603. { HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
  604. { PACKET_LOG_SVC, PIPEDIR_IN, 5, },
  605. /* (Additions here) */
  606. { 0, 0, 0, },
  607. };
  608. #else
  609. static struct service_to_pipe target_service_to_ce_map_qca6390[] = {
  610. };
  611. #endif
  612. static struct service_to_pipe target_service_to_ce_map_qca6490[] = {
  613. { WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
  614. { WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
  615. { WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
  616. { WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
  617. { WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
  618. { WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
  619. { WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
  620. { WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
  621. { WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
  622. { WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
  623. { HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
  624. { HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 2, },
  625. { HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
  626. { HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
  627. { PACKET_LOG_SVC, PIPEDIR_IN, 5, },
  628. /* (Additions here) */
  629. { 0, 0, 0, },
  630. };
  631. #if (defined(QCA_WIFI_QCA6750))
  632. static struct service_to_pipe target_service_to_ce_map_qca6750[] = {
  633. { WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
  634. { WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
  635. { WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
  636. { WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
  637. { WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
  638. { WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
  639. { WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
  640. { WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
  641. { WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
  642. { WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
  643. { HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
  644. { HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 2, },
  645. { HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
  646. { HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
  647. { PACKET_LOG_SVC, PIPEDIR_IN, 5, },
  648. #ifdef WLAN_FEATURE_WMI_DIAG_OVER_CE7
  649. { WMI_CONTROL_DIAG_SVC, PIPEDIR_IN, 7, },
  650. #endif
  651. /* (Additions here) */
  652. { 0, 0, 0, },
  653. };
  654. #else
  655. static struct service_to_pipe target_service_to_ce_map_qca6750[] = {
  656. };
  657. #endif
  658. static struct service_to_pipe target_service_to_ce_map_ar900b[] = {
  659. {
  660. WMI_DATA_VO_SVC,
  661. PIPEDIR_OUT, /* out = UL = host -> target */
  662. 3,
  663. },
  664. {
  665. WMI_DATA_VO_SVC,
  666. PIPEDIR_IN, /* in = DL = target -> host */
  667. 2,
  668. },
  669. {
  670. WMI_DATA_BK_SVC,
  671. PIPEDIR_OUT, /* out = UL = host -> target */
  672. 3,
  673. },
  674. {
  675. WMI_DATA_BK_SVC,
  676. PIPEDIR_IN, /* in = DL = target -> host */
  677. 2,
  678. },
  679. {
  680. WMI_DATA_BE_SVC,
  681. PIPEDIR_OUT, /* out = UL = host -> target */
  682. 3,
  683. },
  684. {
  685. WMI_DATA_BE_SVC,
  686. PIPEDIR_IN, /* in = DL = target -> host */
  687. 2,
  688. },
  689. {
  690. WMI_DATA_VI_SVC,
  691. PIPEDIR_OUT, /* out = UL = host -> target */
  692. 3,
  693. },
  694. {
  695. WMI_DATA_VI_SVC,
  696. PIPEDIR_IN, /* in = DL = target -> host */
  697. 2,
  698. },
  699. {
  700. WMI_CONTROL_SVC,
  701. PIPEDIR_OUT, /* out = UL = host -> target */
  702. 3,
  703. },
  704. {
  705. WMI_CONTROL_SVC,
  706. PIPEDIR_IN, /* in = DL = target -> host */
  707. 2,
  708. },
  709. {
  710. HTC_CTRL_RSVD_SVC,
  711. PIPEDIR_OUT, /* out = UL = host -> target */
  712. 0, /* could be moved to 3 (share with WMI) */
  713. },
  714. {
  715. HTC_CTRL_RSVD_SVC,
  716. PIPEDIR_IN, /* in = DL = target -> host */
  717. 1,
  718. },
  719. {
  720. HTC_RAW_STREAMS_SVC, /* not currently used */
  721. PIPEDIR_OUT, /* out = UL = host -> target */
  722. 0,
  723. },
  724. {
  725. HTC_RAW_STREAMS_SVC, /* not currently used */
  726. PIPEDIR_IN, /* in = DL = target -> host */
  727. 1,
  728. },
  729. {
  730. HTT_DATA_MSG_SVC,
  731. PIPEDIR_OUT, /* out = UL = host -> target */
  732. 4,
  733. },
  734. #ifdef WLAN_FEATURE_FASTPATH
  735. {
  736. HTT_DATA_MSG_SVC,
  737. PIPEDIR_IN, /* in = DL = target -> host */
  738. 5,
  739. },
  740. #else /* WLAN_FEATURE_FASTPATH */
  741. {
  742. HTT_DATA_MSG_SVC,
  743. PIPEDIR_IN, /* in = DL = target -> host */
  744. 1,
  745. },
  746. #endif /* WLAN_FEATURE_FASTPATH */
  747. /* (Additions here) */
  748. { /* Must be last */
  749. 0,
  750. 0,
  751. 0,
  752. },
  753. };
  754. static struct shadow_reg_cfg *target_shadow_reg_cfg = target_shadow_reg_cfg_map;
  755. static int shadow_cfg_sz = sizeof(target_shadow_reg_cfg_map);
  756. #ifdef WLAN_FEATURE_EPPING
  757. static struct service_to_pipe target_service_to_ce_map_wlan_epping[] = {
  758. {WMI_DATA_VO_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
  759. {WMI_DATA_VO_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
  760. {WMI_DATA_BK_SVC, PIPEDIR_OUT, 4,}, /* out = UL = host -> target */
  761. {WMI_DATA_BK_SVC, PIPEDIR_IN, 1,}, /* in = DL = target -> host */
  762. {WMI_DATA_BE_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
  763. {WMI_DATA_BE_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
  764. {WMI_DATA_VI_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
  765. {WMI_DATA_VI_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
  766. {WMI_CONTROL_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
  767. {WMI_CONTROL_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
  768. {HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0,}, /* out = UL = host -> target */
  769. {HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
  770. {HTC_RAW_STREAMS_SVC, PIPEDIR_OUT, 0,}, /* out = UL = host -> target */
  771. {HTC_RAW_STREAMS_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
  772. {HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4,}, /* out = UL = host -> target */
  773. {HTT_DATA_MSG_SVC, PIPEDIR_IN, 1,}, /* in = DL = target -> host */
  774. {0, 0, 0,}, /* Must be last */
  775. };
  776. void hif_select_epping_service_to_pipe_map(struct service_to_pipe
  777. **tgt_svc_map_to_use,
  778. uint32_t *sz_tgt_svc_map_to_use)
  779. {
  780. *tgt_svc_map_to_use = target_service_to_ce_map_wlan_epping;
  781. *sz_tgt_svc_map_to_use =
  782. sizeof(target_service_to_ce_map_wlan_epping);
  783. }
  784. #endif
  785. #ifdef QCN7605_SUPPORT
  786. static inline
  787. void hif_select_ce_map_qcn7605(struct service_to_pipe **tgt_svc_map_to_use,
  788. uint32_t *sz_tgt_svc_map_to_use)
  789. {
  790. *tgt_svc_map_to_use = target_service_to_ce_map_qcn7605;
  791. *sz_tgt_svc_map_to_use = sizeof(target_service_to_ce_map_qcn7605);
  792. }
  793. #else
  794. static inline
  795. void hif_select_ce_map_qcn7605(struct service_to_pipe **tgt_svc_map_to_use,
  796. uint32_t *sz_tgt_svc_map_to_use)
  797. {
  798. hif_err("QCN7605 not supported");
  799. }
  800. #endif
  801. static void hif_select_service_to_pipe_map(struct hif_softc *scn,
  802. struct service_to_pipe **tgt_svc_map_to_use,
  803. uint32_t *sz_tgt_svc_map_to_use)
  804. {
  805. uint32_t mode = hif_get_conparam(scn);
  806. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  807. struct hif_target_info *tgt_info = &scn->target_info;
  808. if (QDF_IS_EPPING_ENABLED(mode)) {
  809. hif_select_epping_service_to_pipe_map(tgt_svc_map_to_use,
  810. sz_tgt_svc_map_to_use);
  811. } else {
  812. switch (tgt_info->target_type) {
  813. default:
  814. *tgt_svc_map_to_use = target_service_to_ce_map_wlan;
  815. *sz_tgt_svc_map_to_use =
  816. sizeof(target_service_to_ce_map_wlan);
  817. break;
  818. case TARGET_TYPE_QCN7605:
  819. hif_select_ce_map_qcn7605(tgt_svc_map_to_use,
  820. sz_tgt_svc_map_to_use);
  821. break;
  822. case TARGET_TYPE_AR900B:
  823. case TARGET_TYPE_QCA9984:
  824. case TARGET_TYPE_IPQ4019:
  825. case TARGET_TYPE_QCA9888:
  826. case TARGET_TYPE_AR9888:
  827. case TARGET_TYPE_AR9888V2:
  828. *tgt_svc_map_to_use = target_service_to_ce_map_ar900b;
  829. *sz_tgt_svc_map_to_use =
  830. sizeof(target_service_to_ce_map_ar900b);
  831. break;
  832. case TARGET_TYPE_QCA6290:
  833. *tgt_svc_map_to_use = target_service_to_ce_map_qca6290;
  834. *sz_tgt_svc_map_to_use =
  835. sizeof(target_service_to_ce_map_qca6290);
  836. break;
  837. case TARGET_TYPE_QCA6390:
  838. *tgt_svc_map_to_use = target_service_to_ce_map_qca6390;
  839. *sz_tgt_svc_map_to_use =
  840. sizeof(target_service_to_ce_map_qca6390);
  841. break;
  842. case TARGET_TYPE_QCA6490:
  843. *tgt_svc_map_to_use = target_service_to_ce_map_qca6490;
  844. *sz_tgt_svc_map_to_use =
  845. sizeof(target_service_to_ce_map_qca6490);
  846. break;
  847. case TARGET_TYPE_QCA6750:
  848. *tgt_svc_map_to_use = target_service_to_ce_map_qca6750;
  849. *sz_tgt_svc_map_to_use =
  850. sizeof(target_service_to_ce_map_qca6750);
  851. break;
  852. case TARGET_TYPE_QCA8074:
  853. *tgt_svc_map_to_use = target_service_to_ce_map_qca8074;
  854. *sz_tgt_svc_map_to_use =
  855. sizeof(target_service_to_ce_map_qca8074);
  856. break;
  857. case TARGET_TYPE_QCA8074V2:
  858. *tgt_svc_map_to_use =
  859. target_service_to_ce_map_qca8074_v2;
  860. *sz_tgt_svc_map_to_use =
  861. sizeof(target_service_to_ce_map_qca8074_v2);
  862. break;
  863. case TARGET_TYPE_QCA6018:
  864. *tgt_svc_map_to_use =
  865. target_service_to_ce_map_qca6018;
  866. *sz_tgt_svc_map_to_use =
  867. sizeof(target_service_to_ce_map_qca6018);
  868. break;
  869. case TARGET_TYPE_QCN9000:
  870. *tgt_svc_map_to_use =
  871. target_service_to_ce_map_qcn9000;
  872. *sz_tgt_svc_map_to_use =
  873. sizeof(target_service_to_ce_map_qcn9000);
  874. break;
  875. case TARGET_TYPE_QCA5018:
  876. case TARGET_TYPE_QCN6122:
  877. *tgt_svc_map_to_use =
  878. target_service_to_ce_map_qca5018;
  879. *sz_tgt_svc_map_to_use =
  880. sizeof(target_service_to_ce_map_qca5018);
  881. break;
  882. }
  883. }
  884. hif_state->tgt_svc_map = *tgt_svc_map_to_use;
  885. hif_state->sz_tgt_svc_map = *sz_tgt_svc_map_to_use /
  886. sizeof(struct service_to_pipe);
  887. }
  888. /**
  889. * ce_mark_datapath() - marks the ce_state->htt_rx_data accordingly
  890. * @ce_state : pointer to the state context of the CE
  891. *
  892. * Description:
  893. * Sets htt_rx_data attribute of the state structure if the
  894. * CE serves one of the HTT DATA services.
  895. *
  896. * Return:
  897. * false (attribute set to false)
  898. * true (attribute set to true);
  899. */
  900. static bool ce_mark_datapath(struct CE_state *ce_state)
  901. {
  902. struct service_to_pipe *svc_map;
  903. uint32_t map_sz, map_len;
  904. int i;
  905. bool rc = false;
  906. if (ce_state) {
  907. hif_select_service_to_pipe_map(ce_state->scn, &svc_map,
  908. &map_sz);
  909. map_len = map_sz / sizeof(struct service_to_pipe);
  910. for (i = 0; i < map_len; i++) {
  911. if ((svc_map[i].pipenum == ce_state->id) &&
  912. ((svc_map[i].service_id == HTT_DATA_MSG_SVC) ||
  913. (svc_map[i].service_id == HTT_DATA2_MSG_SVC) ||
  914. (svc_map[i].service_id == HTT_DATA3_MSG_SVC))) {
  915. /* HTT CEs are unidirectional */
  916. if (svc_map[i].pipedir == PIPEDIR_IN)
  917. ce_state->htt_rx_data = true;
  918. else
  919. ce_state->htt_tx_data = true;
  920. rc = true;
  921. }
  922. }
  923. }
  924. return rc;
  925. }
  926. /**
  927. * ce_ring_test_initial_indexes() - tests the initial ce ring indexes
  928. * @ce_id: ce in question
  929. * @ring: ring state being examined
  930. * @type: "src_ring" or "dest_ring" string for identifying the ring
  931. *
  932. * Warns on non-zero index values.
  933. * Causes a kernel panic if the ring is not empty durring initialization.
  934. */
  935. static void ce_ring_test_initial_indexes(int ce_id, struct CE_ring_state *ring,
  936. char *type)
  937. {
  938. if (ring->write_index != 0 || ring->sw_index != 0)
  939. hif_err("ce %d, %s, initial sw_index = %d, initial write_index =%d",
  940. ce_id, type, ring->sw_index, ring->write_index);
  941. if (ring->write_index != ring->sw_index)
  942. QDF_BUG(0);
  943. }
  944. #ifdef IPA_OFFLOAD
  945. /**
  946. * ce_alloc_desc_ring() - Allocate copyengine descriptor ring
  947. * @scn: softc instance
  948. * @ce_id: ce in question
  949. * @base_addr: pointer to copyengine ring base address
  950. * @ce_ring: copyengine instance
  951. * @nentries: number of entries should be allocated
  952. * @desc_size: ce desc size
  953. *
  954. * Return: QDF_STATUS_SUCCESS - for success
  955. */
  956. static QDF_STATUS ce_alloc_desc_ring(struct hif_softc *scn, unsigned int CE_id,
  957. qdf_dma_addr_t *base_addr,
  958. struct CE_ring_state *ce_ring,
  959. unsigned int nentries, uint32_t desc_size)
  960. {
  961. if ((CE_id == HIF_PCI_IPA_UC_ASSIGNED_CE) &&
  962. !ce_srng_based(scn)) {
  963. if (!scn->ipa_ce_ring) {
  964. scn->ipa_ce_ring = qdf_mem_shared_mem_alloc(
  965. scn->qdf_dev,
  966. nentries * desc_size + CE_DESC_RING_ALIGN);
  967. if (!scn->ipa_ce_ring) {
  968. hif_err(
  969. "Failed to allocate memory for IPA ce ring");
  970. return QDF_STATUS_E_NOMEM;
  971. }
  972. }
  973. *base_addr = qdf_mem_get_dma_addr(scn->qdf_dev,
  974. &scn->ipa_ce_ring->mem_info);
  975. ce_ring->base_addr_owner_space_unaligned =
  976. scn->ipa_ce_ring->vaddr;
  977. } else {
  978. ce_ring->base_addr_owner_space_unaligned =
  979. hif_mem_alloc_consistent_unaligned
  980. (scn,
  981. (nentries * desc_size +
  982. CE_DESC_RING_ALIGN),
  983. base_addr,
  984. ce_ring->hal_ring_type,
  985. &ce_ring->is_ring_prealloc);
  986. if (!ce_ring->base_addr_owner_space_unaligned) {
  987. hif_err("Failed to allocate DMA memory for ce ring id: %u",
  988. CE_id);
  989. return QDF_STATUS_E_NOMEM;
  990. }
  991. }
  992. return QDF_STATUS_SUCCESS;
  993. }
  994. /**
  995. * ce_free_desc_ring() - Frees copyengine descriptor ring
  996. * @scn: softc instance
  997. * @ce_id: ce in question
  998. * @ce_ring: copyengine instance
  999. * @desc_size: ce desc size
  1000. *
  1001. * Return: None
  1002. */
  1003. static void ce_free_desc_ring(struct hif_softc *scn, unsigned int CE_id,
  1004. struct CE_ring_state *ce_ring, uint32_t desc_size)
  1005. {
  1006. if ((CE_id == HIF_PCI_IPA_UC_ASSIGNED_CE) &&
  1007. !ce_srng_based(scn)) {
  1008. if (scn->ipa_ce_ring) {
  1009. qdf_mem_shared_mem_free(scn->qdf_dev,
  1010. scn->ipa_ce_ring);
  1011. scn->ipa_ce_ring = NULL;
  1012. }
  1013. ce_ring->base_addr_owner_space_unaligned = NULL;
  1014. } else {
  1015. hif_mem_free_consistent_unaligned
  1016. (scn,
  1017. ce_ring->nentries * desc_size + CE_DESC_RING_ALIGN,
  1018. ce_ring->base_addr_owner_space_unaligned,
  1019. ce_ring->base_addr_CE_space, 0,
  1020. ce_ring->is_ring_prealloc);
  1021. ce_ring->base_addr_owner_space_unaligned = NULL;
  1022. }
  1023. }
  1024. #else
  1025. static QDF_STATUS ce_alloc_desc_ring(struct hif_softc *scn, unsigned int CE_id,
  1026. qdf_dma_addr_t *base_addr,
  1027. struct CE_ring_state *ce_ring,
  1028. unsigned int nentries, uint32_t desc_size)
  1029. {
  1030. ce_ring->base_addr_owner_space_unaligned =
  1031. hif_mem_alloc_consistent_unaligned
  1032. (scn,
  1033. (nentries * desc_size +
  1034. CE_DESC_RING_ALIGN),
  1035. base_addr,
  1036. ce_ring->hal_ring_type,
  1037. &ce_ring->is_ring_prealloc);
  1038. if (!ce_ring->base_addr_owner_space_unaligned) {
  1039. hif_err("Failed to allocate DMA memory for ce ring id: %u",
  1040. CE_id);
  1041. return QDF_STATUS_E_NOMEM;
  1042. }
  1043. return QDF_STATUS_SUCCESS;
  1044. }
  1045. static void ce_free_desc_ring(struct hif_softc *scn, unsigned int CE_id,
  1046. struct CE_ring_state *ce_ring, uint32_t desc_size)
  1047. {
  1048. hif_mem_free_consistent_unaligned
  1049. (scn,
  1050. ce_ring->nentries * desc_size + CE_DESC_RING_ALIGN,
  1051. ce_ring->base_addr_owner_space_unaligned,
  1052. ce_ring->base_addr_CE_space, 0,
  1053. ce_ring->is_ring_prealloc);
  1054. ce_ring->base_addr_owner_space_unaligned = NULL;
  1055. }
  1056. #endif /* IPA_OFFLOAD */
  1057. /*
  1058. * TODO: Need to explore the possibility of having this as part of a
  1059. * target context instead of a global array.
  1060. */
  1061. static struct ce_ops* (*ce_attach_register[CE_MAX_TARGET_TYPE])(void);
  1062. void ce_service_register_module(enum ce_target_type target_type,
  1063. struct ce_ops* (*ce_attach)(void))
  1064. {
  1065. if (target_type < CE_MAX_TARGET_TYPE)
  1066. ce_attach_register[target_type] = ce_attach;
  1067. }
  1068. qdf_export_symbol(ce_service_register_module);
  1069. /**
  1070. * ce_srng_based() - Does this target use srng
  1071. * @ce_state : pointer to the state context of the CE
  1072. *
  1073. * Description:
  1074. * returns true if the target is SRNG based
  1075. *
  1076. * Return:
  1077. * false (attribute set to false)
  1078. * true (attribute set to true);
  1079. */
  1080. bool ce_srng_based(struct hif_softc *scn)
  1081. {
  1082. struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
  1083. struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl);
  1084. switch (tgt_info->target_type) {
  1085. case TARGET_TYPE_QCA8074:
  1086. case TARGET_TYPE_QCA8074V2:
  1087. case TARGET_TYPE_QCA6290:
  1088. case TARGET_TYPE_QCA6390:
  1089. case TARGET_TYPE_QCA6490:
  1090. case TARGET_TYPE_QCA6750:
  1091. case TARGET_TYPE_QCA6018:
  1092. case TARGET_TYPE_QCN9000:
  1093. case TARGET_TYPE_QCN6122:
  1094. case TARGET_TYPE_QCA5018:
  1095. return true;
  1096. default:
  1097. return false;
  1098. }
  1099. return false;
  1100. }
  1101. qdf_export_symbol(ce_srng_based);
  1102. #ifdef QCA_WIFI_SUPPORT_SRNG
  1103. static struct ce_ops *ce_services_attach(struct hif_softc *scn)
  1104. {
  1105. struct ce_ops *ops = NULL;
  1106. if (ce_srng_based(scn)) {
  1107. if (ce_attach_register[CE_SVC_SRNG])
  1108. ops = ce_attach_register[CE_SVC_SRNG]();
  1109. } else if (ce_attach_register[CE_SVC_LEGACY]) {
  1110. ops = ce_attach_register[CE_SVC_LEGACY]();
  1111. }
  1112. return ops;
  1113. }
  1114. #else /* QCA_LITHIUM */
  1115. static struct ce_ops *ce_services_attach(struct hif_softc *scn)
  1116. {
  1117. if (ce_attach_register[CE_SVC_LEGACY])
  1118. return ce_attach_register[CE_SVC_LEGACY]();
  1119. return NULL;
  1120. }
  1121. #endif /* QCA_LITHIUM */
  1122. static void hif_prepare_hal_shadow_register_cfg(struct hif_softc *scn,
  1123. struct pld_shadow_reg_v2_cfg **shadow_config,
  1124. int *num_shadow_registers_configured) {
  1125. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  1126. hif_state->ce_services->ce_prepare_shadow_register_v2_cfg(
  1127. scn, shadow_config, num_shadow_registers_configured);
  1128. return;
  1129. }
  1130. static inline uint32_t ce_get_desc_size(struct hif_softc *scn,
  1131. uint8_t ring_type)
  1132. {
  1133. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  1134. return hif_state->ce_services->ce_get_desc_size(ring_type);
  1135. }
  1136. #ifdef QCA_WIFI_SUPPORT_SRNG
  1137. static inline int32_t ce_ring_type_to_hal_ring_type(uint32_t ce_ring_type)
  1138. {
  1139. switch (ce_ring_type) {
  1140. case CE_RING_SRC:
  1141. return CE_SRC;
  1142. case CE_RING_DEST:
  1143. return CE_DST;
  1144. case CE_RING_STATUS:
  1145. return CE_DST_STATUS;
  1146. default:
  1147. return -EINVAL;
  1148. }
  1149. }
  1150. #else
  1151. static int32_t ce_ring_type_to_hal_ring_type(uint32_t ce_ring_type)
  1152. {
  1153. return 0;
  1154. }
  1155. #endif
  1156. static struct CE_ring_state *ce_alloc_ring_state(struct CE_state *CE_state,
  1157. uint8_t ring_type, uint32_t nentries)
  1158. {
  1159. uint32_t ce_nbytes;
  1160. char *ptr;
  1161. qdf_dma_addr_t base_addr;
  1162. struct CE_ring_state *ce_ring;
  1163. uint32_t desc_size;
  1164. struct hif_softc *scn = CE_state->scn;
  1165. ce_nbytes = sizeof(struct CE_ring_state)
  1166. + (nentries * sizeof(void *));
  1167. ptr = qdf_mem_malloc(ce_nbytes);
  1168. if (!ptr)
  1169. return NULL;
  1170. ce_ring = (struct CE_ring_state *)ptr;
  1171. ptr += sizeof(struct CE_ring_state);
  1172. ce_ring->nentries = nentries;
  1173. ce_ring->nentries_mask = nentries - 1;
  1174. ce_ring->low_water_mark_nentries = 0;
  1175. ce_ring->high_water_mark_nentries = nentries;
  1176. ce_ring->per_transfer_context = (void **)ptr;
  1177. ce_ring->hal_ring_type = ce_ring_type_to_hal_ring_type(ring_type);
  1178. desc_size = ce_get_desc_size(scn, ring_type);
  1179. /* Legacy platforms that do not support cache
  1180. * coherent DMA are unsupported
  1181. */
  1182. if (ce_alloc_desc_ring(scn, CE_state->id, &base_addr,
  1183. ce_ring, nentries,
  1184. desc_size) !=
  1185. QDF_STATUS_SUCCESS) {
  1186. hif_err("ring has no DMA mem");
  1187. qdf_mem_free(ce_ring);
  1188. return NULL;
  1189. }
  1190. ce_ring->base_addr_CE_space_unaligned = base_addr;
  1191. /* Correctly initialize memory to 0 to
  1192. * prevent garbage data crashing system
  1193. * when download firmware
  1194. */
  1195. qdf_mem_zero(ce_ring->base_addr_owner_space_unaligned,
  1196. nentries * desc_size +
  1197. CE_DESC_RING_ALIGN);
  1198. if (ce_ring->base_addr_CE_space_unaligned & (CE_DESC_RING_ALIGN - 1)) {
  1199. ce_ring->base_addr_CE_space =
  1200. (ce_ring->base_addr_CE_space_unaligned +
  1201. CE_DESC_RING_ALIGN - 1) & ~(CE_DESC_RING_ALIGN - 1);
  1202. ce_ring->base_addr_owner_space = (void *)
  1203. (((size_t) ce_ring->base_addr_owner_space_unaligned +
  1204. CE_DESC_RING_ALIGN - 1) & ~(CE_DESC_RING_ALIGN - 1));
  1205. } else {
  1206. ce_ring->base_addr_CE_space =
  1207. ce_ring->base_addr_CE_space_unaligned;
  1208. ce_ring->base_addr_owner_space =
  1209. ce_ring->base_addr_owner_space_unaligned;
  1210. }
  1211. return ce_ring;
  1212. }
  1213. static int ce_ring_setup(struct hif_softc *scn, uint8_t ring_type,
  1214. uint32_t ce_id, struct CE_ring_state *ring,
  1215. struct CE_attr *attr)
  1216. {
  1217. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  1218. return hif_state->ce_services->ce_ring_setup(scn, ring_type, ce_id,
  1219. ring, attr);
  1220. }
  1221. int hif_ce_bus_early_suspend(struct hif_softc *scn)
  1222. {
  1223. uint8_t ul_pipe, dl_pipe;
  1224. int ce_id, status, ul_is_polled, dl_is_polled;
  1225. struct CE_state *ce_state;
  1226. status = hif_map_service_to_pipe(&scn->osc, WMI_CONTROL_SVC,
  1227. &ul_pipe, &dl_pipe,
  1228. &ul_is_polled, &dl_is_polled);
  1229. if (status) {
  1230. hif_err("pipe_mapping failure");
  1231. return status;
  1232. }
  1233. for (ce_id = 0; ce_id < scn->ce_count; ce_id++) {
  1234. if (ce_id == ul_pipe)
  1235. continue;
  1236. if (ce_id == dl_pipe)
  1237. continue;
  1238. ce_state = scn->ce_id_to_state[ce_id];
  1239. qdf_spin_lock_bh(&ce_state->ce_index_lock);
  1240. if (ce_state->state == CE_RUNNING)
  1241. ce_state->state = CE_PAUSED;
  1242. qdf_spin_unlock_bh(&ce_state->ce_index_lock);
  1243. }
  1244. return status;
  1245. }
  1246. int hif_ce_bus_late_resume(struct hif_softc *scn)
  1247. {
  1248. int ce_id;
  1249. struct CE_state *ce_state;
  1250. int write_index = 0;
  1251. bool index_updated;
  1252. for (ce_id = 0; ce_id < scn->ce_count; ce_id++) {
  1253. ce_state = scn->ce_id_to_state[ce_id];
  1254. qdf_spin_lock_bh(&ce_state->ce_index_lock);
  1255. if (ce_state->state == CE_PENDING) {
  1256. write_index = ce_state->src_ring->write_index;
  1257. CE_SRC_RING_WRITE_IDX_SET(scn, ce_state->ctrl_addr,
  1258. write_index);
  1259. ce_state->state = CE_RUNNING;
  1260. index_updated = true;
  1261. } else {
  1262. index_updated = false;
  1263. }
  1264. if (ce_state->state == CE_PAUSED)
  1265. ce_state->state = CE_RUNNING;
  1266. qdf_spin_unlock_bh(&ce_state->ce_index_lock);
  1267. if (index_updated)
  1268. hif_record_ce_desc_event(scn, ce_id,
  1269. RESUME_WRITE_INDEX_UPDATE,
  1270. NULL, NULL, write_index, 0);
  1271. }
  1272. return 0;
  1273. }
  1274. /**
  1275. * ce_oom_recovery() - try to recover rx ce from oom condition
  1276. * @context: CE_state of the CE with oom rx ring
  1277. *
  1278. * the executing work Will continue to be rescheduled until
  1279. * at least 1 descriptor is successfully posted to the rx ring.
  1280. *
  1281. * return: none
  1282. */
  1283. static void ce_oom_recovery(void *context)
  1284. {
  1285. struct CE_state *ce_state = context;
  1286. struct hif_softc *scn = ce_state->scn;
  1287. struct HIF_CE_state *ce_softc = HIF_GET_CE_STATE(scn);
  1288. struct HIF_CE_pipe_info *pipe_info =
  1289. &ce_softc->pipe_info[ce_state->id];
  1290. hif_post_recv_buffers_for_pipe(pipe_info);
  1291. }
  1292. #ifdef HIF_CE_DEBUG_DATA_BUF
  1293. /**
  1294. * alloc_mem_ce_debug_hist_data() - Allocate mem for the data pointed by
  1295. * the CE descriptors.
  1296. * Allocate HIF_CE_HISTORY_MAX records by CE_DEBUG_MAX_DATA_BUF_SIZE
  1297. * @scn: hif scn handle
  1298. * ce_id: Copy Engine Id
  1299. *
  1300. * Return: QDF_STATUS
  1301. */
  1302. QDF_STATUS alloc_mem_ce_debug_hist_data(struct hif_softc *scn, uint32_t ce_id)
  1303. {
  1304. struct hif_ce_desc_event *event = NULL;
  1305. struct hif_ce_desc_event *hist_ev = NULL;
  1306. uint32_t index = 0;
  1307. hist_ev =
  1308. (struct hif_ce_desc_event *)scn->hif_ce_desc_hist.hist_ev[ce_id];
  1309. if (!hist_ev)
  1310. return QDF_STATUS_E_NOMEM;
  1311. scn->hif_ce_desc_hist.data_enable[ce_id] = true;
  1312. for (index = 0; index < HIF_CE_HISTORY_MAX; index++) {
  1313. event = &hist_ev[index];
  1314. event->data =
  1315. (uint8_t *)qdf_mem_malloc(CE_DEBUG_MAX_DATA_BUF_SIZE);
  1316. if (!event->data) {
  1317. hif_err_rl("ce debug data alloc failed");
  1318. return QDF_STATUS_E_NOMEM;
  1319. }
  1320. }
  1321. return QDF_STATUS_SUCCESS;
  1322. }
  1323. /**
  1324. * free_mem_ce_debug_hist_data() - Free mem of the data pointed by
  1325. * the CE descriptors.
  1326. * @scn: hif scn handle
  1327. * ce_id: Copy Engine Id
  1328. *
  1329. * Return:
  1330. */
  1331. void free_mem_ce_debug_hist_data(struct hif_softc *scn, uint32_t ce_id)
  1332. {
  1333. struct hif_ce_desc_event *event = NULL;
  1334. struct hif_ce_desc_event *hist_ev = NULL;
  1335. uint32_t index = 0;
  1336. hist_ev =
  1337. (struct hif_ce_desc_event *)scn->hif_ce_desc_hist.hist_ev[ce_id];
  1338. if (!hist_ev)
  1339. return;
  1340. for (index = 0; index < HIF_CE_HISTORY_MAX; index++) {
  1341. event = &hist_ev[index];
  1342. if (event->data)
  1343. qdf_mem_free(event->data);
  1344. event->data = NULL;
  1345. event = NULL;
  1346. }
  1347. }
  1348. #endif /* HIF_CE_DEBUG_DATA_BUF */
  1349. #ifndef HIF_CE_DEBUG_DATA_DYNAMIC_BUF
  1350. #if defined(HIF_CONFIG_SLUB_DEBUG_ON) || defined(HIF_CE_DEBUG_DATA_BUF)
  1351. struct hif_ce_desc_event hif_ce_desc_history[CE_COUNT_MAX][HIF_CE_HISTORY_MAX];
  1352. /**
  1353. * alloc_mem_ce_debug_history() - Allocate CE descriptor history
  1354. * @scn: hif scn handle
  1355. * @ce_id: Copy Engine Id
  1356. * @src_nentries: source ce ring entries
  1357. * Return: QDF_STATUS
  1358. */
  1359. static QDF_STATUS
  1360. alloc_mem_ce_debug_history(struct hif_softc *scn, unsigned int ce_id,
  1361. uint32_t src_nentries)
  1362. {
  1363. struct ce_desc_hist *ce_hist = &scn->hif_ce_desc_hist;
  1364. ce_hist->hist_ev[ce_id] = hif_ce_desc_history[ce_id];
  1365. ce_hist->enable[ce_id] = 1;
  1366. if (src_nentries)
  1367. alloc_mem_ce_debug_hist_data(scn, ce_id);
  1368. else
  1369. ce_hist->data_enable[ce_id] = false;
  1370. return QDF_STATUS_SUCCESS;
  1371. }
  1372. /**
  1373. * free_mem_ce_debug_history() - Free CE descriptor history
  1374. * @scn: hif scn handle
  1375. * @ce_id: Copy Engine Id
  1376. *
  1377. * Return: None
  1378. */
  1379. static void free_mem_ce_debug_history(struct hif_softc *scn, unsigned int ce_id)
  1380. {
  1381. struct ce_desc_hist *ce_hist = &scn->hif_ce_desc_hist;
  1382. ce_hist->enable[ce_id] = 0;
  1383. if (ce_hist->data_enable[ce_id]) {
  1384. ce_hist->data_enable[ce_id] = false;
  1385. free_mem_ce_debug_hist_data(scn, ce_id);
  1386. }
  1387. ce_hist->hist_ev[ce_id] = NULL;
  1388. }
  1389. #else
  1390. static inline QDF_STATUS
  1391. alloc_mem_ce_debug_history(struct hif_softc *scn, unsigned int CE_id,
  1392. uint32_t src_nentries)
  1393. {
  1394. return QDF_STATUS_SUCCESS;
  1395. }
  1396. static inline void
  1397. free_mem_ce_debug_history(struct hif_softc *scn, unsigned int CE_id) { }
  1398. #endif /* (HIF_CONFIG_SLUB_DEBUG_ON) || (HIF_CE_DEBUG_DATA_BUF) */
  1399. #else
  1400. #if defined(HIF_CE_DEBUG_DATA_BUF)
  1401. static QDF_STATUS
  1402. alloc_mem_ce_debug_history(struct hif_softc *scn, unsigned int CE_id,
  1403. uint32_t src_nentries)
  1404. {
  1405. scn->hif_ce_desc_hist.hist_ev[CE_id] = (struct hif_ce_desc_event *)
  1406. qdf_mem_malloc(HIF_CE_HISTORY_MAX * sizeof(struct hif_ce_desc_event));
  1407. if (!scn->hif_ce_desc_hist.hist_ev[CE_id]) {
  1408. scn->hif_ce_desc_hist.enable[CE_id] = 0;
  1409. return QDF_STATUS_E_NOMEM;
  1410. } else {
  1411. scn->hif_ce_desc_hist.enable[CE_id] = 1;
  1412. return QDF_STATUS_SUCCESS;
  1413. }
  1414. }
  1415. static void free_mem_ce_debug_history(struct hif_softc *scn, unsigned int CE_id)
  1416. {
  1417. struct ce_desc_hist *ce_hist = &scn->hif_ce_desc_hist;
  1418. struct hif_ce_desc_event *hist_ev = ce_hist->hist_ev[CE_id];
  1419. if (!hist_ev)
  1420. return;
  1421. if (ce_hist->data_enable[CE_id]) {
  1422. ce_hist->data_enable[CE_id] = false;
  1423. free_mem_ce_debug_hist_data(scn, CE_id);
  1424. }
  1425. ce_hist->enable[CE_id] = 0;
  1426. qdf_mem_free(ce_hist->hist_ev[CE_id]);
  1427. ce_hist->hist_ev[CE_id] = NULL;
  1428. }
  1429. #else
  1430. static inline QDF_STATUS
  1431. alloc_mem_ce_debug_history(struct hif_softc *scn, unsigned int CE_id,
  1432. uint32_t src_nentries)
  1433. {
  1434. return QDF_STATUS_SUCCESS;
  1435. }
  1436. static inline void
  1437. free_mem_ce_debug_history(struct hif_softc *scn, unsigned int CE_id) { }
  1438. #endif /* HIF_CE_DEBUG_DATA_BUF */
  1439. #endif /* HIF_CE_DEBUG_DATA_DYNAMIC_BUF */
  1440. #if defined(HIF_CONFIG_SLUB_DEBUG_ON) || defined(HIF_CE_DEBUG_DATA_BUF)
  1441. /**
  1442. * reset_ce_debug_history() - reset the index and ce id used for dumping the
  1443. * CE records on the console using sysfs.
  1444. * @scn: hif scn handle
  1445. *
  1446. * Return:
  1447. */
  1448. static inline void reset_ce_debug_history(struct hif_softc *scn)
  1449. {
  1450. struct ce_desc_hist *ce_hist = &scn->hif_ce_desc_hist;
  1451. /* Initialise the CE debug history sysfs interface inputs ce_id and
  1452. * index. Disable data storing
  1453. */
  1454. ce_hist->hist_index = 0;
  1455. ce_hist->hist_id = 0;
  1456. }
  1457. #else /* defined(HIF_CONFIG_SLUB_DEBUG_ON) || defined(HIF_CE_DEBUG_DATA_BUF) */
  1458. static inline void reset_ce_debug_history(struct hif_softc *scn) { }
  1459. #endif /*defined(HIF_CONFIG_SLUB_DEBUG_ON) || defined(HIF_CE_DEBUG_DATA_BUF) */
  1460. void ce_enable_polling(void *cestate)
  1461. {
  1462. struct CE_state *CE_state = (struct CE_state *)cestate;
  1463. if (CE_state && CE_state->attr_flags & CE_ATTR_ENABLE_POLL)
  1464. CE_state->timer_inited = true;
  1465. }
  1466. void ce_disable_polling(void *cestate)
  1467. {
  1468. struct CE_state *CE_state = (struct CE_state *)cestate;
  1469. if (CE_state && CE_state->attr_flags & CE_ATTR_ENABLE_POLL)
  1470. CE_state->timer_inited = false;
  1471. }
  1472. /*
  1473. * Initialize a Copy Engine based on caller-supplied attributes.
  1474. * This may be called once to initialize both source and destination
  1475. * rings or it may be called twice for separate source and destination
  1476. * initialization. It may be that only one side or the other is
  1477. * initialized by software/firmware.
  1478. *
  1479. * This should be called durring the initialization sequence before
  1480. * interupts are enabled, so we don't have to worry about thread safety.
  1481. */
  1482. struct CE_handle *ce_init(struct hif_softc *scn,
  1483. unsigned int CE_id, struct CE_attr *attr)
  1484. {
  1485. struct CE_state *CE_state;
  1486. uint32_t ctrl_addr;
  1487. unsigned int nentries;
  1488. bool malloc_CE_state = false;
  1489. bool malloc_src_ring = false;
  1490. int status;
  1491. QDF_ASSERT(CE_id < scn->ce_count);
  1492. ctrl_addr = CE_BASE_ADDRESS(CE_id);
  1493. CE_state = scn->ce_id_to_state[CE_id];
  1494. if (!CE_state) {
  1495. CE_state =
  1496. (struct CE_state *)qdf_mem_malloc(sizeof(*CE_state));
  1497. if (!CE_state)
  1498. return NULL;
  1499. malloc_CE_state = true;
  1500. qdf_spinlock_create(&CE_state->ce_index_lock);
  1501. CE_state->id = CE_id;
  1502. CE_state->ctrl_addr = ctrl_addr;
  1503. CE_state->state = CE_RUNNING;
  1504. CE_state->attr_flags = attr->flags;
  1505. }
  1506. CE_state->scn = scn;
  1507. CE_state->service = ce_engine_service_reg;
  1508. qdf_atomic_init(&CE_state->rx_pending);
  1509. if (!attr) {
  1510. /* Already initialized; caller wants the handle */
  1511. return (struct CE_handle *)CE_state;
  1512. }
  1513. if (CE_state->src_sz_max)
  1514. QDF_ASSERT(CE_state->src_sz_max == attr->src_sz_max);
  1515. else
  1516. CE_state->src_sz_max = attr->src_sz_max;
  1517. ce_init_ce_desc_event_log(scn, CE_id,
  1518. attr->src_nentries + attr->dest_nentries);
  1519. /* source ring setup */
  1520. nentries = attr->src_nentries;
  1521. if (nentries) {
  1522. struct CE_ring_state *src_ring;
  1523. nentries = roundup_pwr2(nentries);
  1524. if (CE_state->src_ring) {
  1525. QDF_ASSERT(CE_state->src_ring->nentries == nentries);
  1526. } else {
  1527. src_ring = CE_state->src_ring =
  1528. ce_alloc_ring_state(CE_state,
  1529. CE_RING_SRC,
  1530. nentries);
  1531. if (!src_ring) {
  1532. /* cannot allocate src ring. If the
  1533. * CE_state is allocated locally free
  1534. * CE_State and return error.
  1535. */
  1536. hif_err("src ring has no mem");
  1537. if (malloc_CE_state) {
  1538. /* allocated CE_state locally */
  1539. qdf_mem_free(CE_state);
  1540. malloc_CE_state = false;
  1541. }
  1542. return NULL;
  1543. }
  1544. /* we can allocate src ring. Mark that the src ring is
  1545. * allocated locally
  1546. */
  1547. malloc_src_ring = true;
  1548. /*
  1549. * Also allocate a shadow src ring in
  1550. * regular mem to use for faster access.
  1551. */
  1552. src_ring->shadow_base_unaligned =
  1553. qdf_mem_malloc(nentries *
  1554. sizeof(struct CE_src_desc) +
  1555. CE_DESC_RING_ALIGN);
  1556. if (!src_ring->shadow_base_unaligned)
  1557. goto error_no_dma_mem;
  1558. src_ring->shadow_base = (struct CE_src_desc *)
  1559. (((size_t) src_ring->shadow_base_unaligned +
  1560. CE_DESC_RING_ALIGN - 1) &
  1561. ~(CE_DESC_RING_ALIGN - 1));
  1562. status = ce_ring_setup(scn, CE_RING_SRC, CE_id,
  1563. src_ring, attr);
  1564. if (status < 0)
  1565. goto error_target_access;
  1566. ce_ring_test_initial_indexes(CE_id, src_ring,
  1567. "src_ring");
  1568. }
  1569. }
  1570. /* destination ring setup */
  1571. nentries = attr->dest_nentries;
  1572. if (nentries) {
  1573. struct CE_ring_state *dest_ring;
  1574. nentries = roundup_pwr2(nentries);
  1575. if (CE_state->dest_ring) {
  1576. QDF_ASSERT(CE_state->dest_ring->nentries == nentries);
  1577. } else {
  1578. dest_ring = CE_state->dest_ring =
  1579. ce_alloc_ring_state(CE_state,
  1580. CE_RING_DEST,
  1581. nentries);
  1582. if (!dest_ring) {
  1583. /* cannot allocate dst ring. If the CE_state
  1584. * or src ring is allocated locally free
  1585. * CE_State and src ring and return error.
  1586. */
  1587. hif_err("dest ring has no mem");
  1588. goto error_no_dma_mem;
  1589. }
  1590. status = ce_ring_setup(scn, CE_RING_DEST, CE_id,
  1591. dest_ring, attr);
  1592. if (status < 0)
  1593. goto error_target_access;
  1594. ce_ring_test_initial_indexes(CE_id, dest_ring,
  1595. "dest_ring");
  1596. /* For srng based target, init status ring here */
  1597. if (ce_srng_based(CE_state->scn)) {
  1598. CE_state->status_ring =
  1599. ce_alloc_ring_state(CE_state,
  1600. CE_RING_STATUS,
  1601. nentries);
  1602. if (!CE_state->status_ring) {
  1603. /*Allocation failed. Cleanup*/
  1604. qdf_mem_free(CE_state->dest_ring);
  1605. if (malloc_src_ring) {
  1606. qdf_mem_free
  1607. (CE_state->src_ring);
  1608. CE_state->src_ring = NULL;
  1609. malloc_src_ring = false;
  1610. }
  1611. if (malloc_CE_state) {
  1612. /* allocated CE_state locally */
  1613. scn->ce_id_to_state[CE_id] =
  1614. NULL;
  1615. qdf_mem_free(CE_state);
  1616. malloc_CE_state = false;
  1617. }
  1618. return NULL;
  1619. }
  1620. status = ce_ring_setup(scn, CE_RING_STATUS,
  1621. CE_id, CE_state->status_ring,
  1622. attr);
  1623. if (status < 0)
  1624. goto error_target_access;
  1625. }
  1626. /* epping */
  1627. /* poll timer */
  1628. if (CE_state->attr_flags & CE_ATTR_ENABLE_POLL) {
  1629. qdf_timer_init(scn->qdf_dev,
  1630. &CE_state->poll_timer,
  1631. ce_poll_timeout,
  1632. CE_state,
  1633. QDF_TIMER_TYPE_WAKE_APPS);
  1634. ce_enable_polling(CE_state);
  1635. qdf_timer_mod(&CE_state->poll_timer,
  1636. CE_POLL_TIMEOUT);
  1637. }
  1638. }
  1639. }
  1640. if (!ce_srng_based(scn)) {
  1641. /* Enable CE error interrupts */
  1642. if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
  1643. goto error_target_access;
  1644. CE_ERROR_INTR_ENABLE(scn, ctrl_addr);
  1645. if (Q_TARGET_ACCESS_END(scn) < 0)
  1646. goto error_target_access;
  1647. }
  1648. qdf_create_work(scn->qdf_dev, &CE_state->oom_allocation_work,
  1649. ce_oom_recovery, CE_state);
  1650. /* update the htt_data attribute */
  1651. ce_mark_datapath(CE_state);
  1652. scn->ce_id_to_state[CE_id] = CE_state;
  1653. alloc_mem_ce_debug_history(scn, CE_id, attr->src_nentries);
  1654. return (struct CE_handle *)CE_state;
  1655. error_target_access:
  1656. error_no_dma_mem:
  1657. ce_fini((struct CE_handle *)CE_state);
  1658. return NULL;
  1659. }
  1660. /**
  1661. * hif_is_polled_mode_enabled - API to query if polling is enabled on all CEs
  1662. * @hif_ctx: HIF Context
  1663. *
  1664. * API to check if polling is enabled on all CEs. Returns true when polling
  1665. * is enabled on all CEs.
  1666. *
  1667. * Return: bool
  1668. */
  1669. bool hif_is_polled_mode_enabled(struct hif_opaque_softc *hif_ctx)
  1670. {
  1671. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  1672. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  1673. struct CE_attr *attr;
  1674. int id;
  1675. for (id = 0; id < scn->ce_count; id++) {
  1676. attr = &hif_state->host_ce_config[id];
  1677. if (attr && (attr->dest_nentries) &&
  1678. !(attr->flags & CE_ATTR_ENABLE_POLL))
  1679. return false;
  1680. }
  1681. return true;
  1682. }
  1683. qdf_export_symbol(hif_is_polled_mode_enabled);
  1684. static int hif_get_pktlog_ce_num(struct hif_softc *scn)
  1685. {
  1686. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  1687. int id;
  1688. for (id = 0; id < hif_state->sz_tgt_svc_map; id++) {
  1689. if (hif_state->tgt_svc_map[id].service_id == PACKET_LOG_SVC)
  1690. return hif_state->tgt_svc_map[id].pipenum;
  1691. }
  1692. return -EINVAL;
  1693. }
  1694. #ifdef WLAN_FEATURE_FASTPATH
  1695. /**
  1696. * hif_enable_fastpath() Update that we have enabled fastpath mode
  1697. * @hif_ctx: HIF context
  1698. *
  1699. * For use in data path
  1700. *
  1701. * Retrun: void
  1702. */
  1703. void hif_enable_fastpath(struct hif_opaque_softc *hif_ctx)
  1704. {
  1705. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  1706. if (ce_srng_based(scn)) {
  1707. hif_warn("srng rings do not support fastpath");
  1708. return;
  1709. }
  1710. hif_debug("Enabling fastpath mode");
  1711. scn->fastpath_mode_on = true;
  1712. }
  1713. /**
  1714. * hif_is_fastpath_mode_enabled - API to query if fasthpath mode is enabled
  1715. * @hif_ctx: HIF Context
  1716. *
  1717. * For use in data path to skip HTC
  1718. *
  1719. * Return: bool
  1720. */
  1721. bool hif_is_fastpath_mode_enabled(struct hif_opaque_softc *hif_ctx)
  1722. {
  1723. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  1724. return scn->fastpath_mode_on;
  1725. }
  1726. /**
  1727. * hif_get_ce_handle - API to get CE handle for FastPath mode
  1728. * @hif_ctx: HIF Context
  1729. * @id: CopyEngine Id
  1730. *
  1731. * API to return CE handle for fastpath mode
  1732. *
  1733. * Return: void
  1734. */
  1735. void *hif_get_ce_handle(struct hif_opaque_softc *hif_ctx, int id)
  1736. {
  1737. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  1738. return scn->ce_id_to_state[id];
  1739. }
  1740. qdf_export_symbol(hif_get_ce_handle);
  1741. /**
  1742. * ce_h2t_tx_ce_cleanup() Place holder function for H2T CE cleanup.
  1743. * No processing is required inside this function.
  1744. * @ce_hdl: Cope engine handle
  1745. * Using an assert, this function makes sure that,
  1746. * the TX CE has been processed completely.
  1747. *
  1748. * This is called while dismantling CE structures. No other thread
  1749. * should be using these structures while dismantling is occurring
  1750. * therfore no locking is needed.
  1751. *
  1752. * Return: none
  1753. */
  1754. void ce_h2t_tx_ce_cleanup(struct CE_handle *ce_hdl)
  1755. {
  1756. struct CE_state *ce_state = (struct CE_state *)ce_hdl;
  1757. struct CE_ring_state *src_ring = ce_state->src_ring;
  1758. struct hif_softc *sc = ce_state->scn;
  1759. uint32_t sw_index, write_index;
  1760. if (hif_is_nss_wifi_enabled(sc))
  1761. return;
  1762. if (sc->fastpath_mode_on && ce_state->htt_tx_data) {
  1763. hif_debug("Fastpath mode ON, Cleaning up HTT Tx CE");
  1764. sw_index = src_ring->sw_index;
  1765. write_index = src_ring->sw_index;
  1766. /* At this point Tx CE should be clean */
  1767. qdf_assert_always(sw_index == write_index);
  1768. }
  1769. }
  1770. /**
  1771. * ce_t2h_msg_ce_cleanup() - Cleanup buffers on the t2h datapath msg queue.
  1772. * @ce_hdl: Handle to CE
  1773. *
  1774. * These buffers are never allocated on the fly, but
  1775. * are allocated only once during HIF start and freed
  1776. * only once during HIF stop.
  1777. * NOTE:
  1778. * The assumption here is there is no in-flight DMA in progress
  1779. * currently, so that buffers can be freed up safely.
  1780. *
  1781. * Return: NONE
  1782. */
  1783. void ce_t2h_msg_ce_cleanup(struct CE_handle *ce_hdl)
  1784. {
  1785. struct CE_state *ce_state = (struct CE_state *)ce_hdl;
  1786. struct CE_ring_state *dst_ring = ce_state->dest_ring;
  1787. qdf_nbuf_t nbuf;
  1788. int i;
  1789. if (ce_state->scn->fastpath_mode_on == false)
  1790. return;
  1791. if (!ce_state->htt_rx_data)
  1792. return;
  1793. /*
  1794. * when fastpath_mode is on and for datapath CEs. Unlike other CE's,
  1795. * this CE is completely full: does not leave one blank space, to
  1796. * distinguish between empty queue & full queue. So free all the
  1797. * entries.
  1798. */
  1799. for (i = 0; i < dst_ring->nentries; i++) {
  1800. nbuf = dst_ring->per_transfer_context[i];
  1801. /*
  1802. * The reasons for doing this check are:
  1803. * 1) Protect against calling cleanup before allocating buffers
  1804. * 2) In a corner case, FASTPATH_mode_on may be set, but we
  1805. * could have a partially filled ring, because of a memory
  1806. * allocation failure in the middle of allocating ring.
  1807. * This check accounts for that case, checking
  1808. * fastpath_mode_on flag or started flag would not have
  1809. * covered that case. This is not in performance path,
  1810. * so OK to do this.
  1811. */
  1812. if (nbuf) {
  1813. qdf_nbuf_unmap_single(ce_state->scn->qdf_dev, nbuf,
  1814. QDF_DMA_FROM_DEVICE);
  1815. qdf_nbuf_free(nbuf);
  1816. }
  1817. }
  1818. }
  1819. /**
  1820. * hif_update_fastpath_recv_bufs_cnt() - Increments the Rx buf count by 1
  1821. * @scn: HIF handle
  1822. *
  1823. * Datapath Rx CEs are special case, where we reuse all the message buffers.
  1824. * Hence we have to post all the entries in the pipe, even, in the beginning
  1825. * unlike for other CE pipes where one less than dest_nentries are filled in
  1826. * the beginning.
  1827. *
  1828. * Return: None
  1829. */
  1830. static void hif_update_fastpath_recv_bufs_cnt(struct hif_softc *scn)
  1831. {
  1832. int pipe_num;
  1833. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  1834. if (scn->fastpath_mode_on == false)
  1835. return;
  1836. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  1837. struct HIF_CE_pipe_info *pipe_info =
  1838. &hif_state->pipe_info[pipe_num];
  1839. struct CE_state *ce_state =
  1840. scn->ce_id_to_state[pipe_info->pipe_num];
  1841. if (ce_state->htt_rx_data)
  1842. atomic_inc(&pipe_info->recv_bufs_needed);
  1843. }
  1844. }
  1845. #else
  1846. static inline void hif_update_fastpath_recv_bufs_cnt(struct hif_softc *scn)
  1847. {
  1848. }
  1849. static inline bool ce_is_fastpath_enabled(struct hif_softc *scn)
  1850. {
  1851. return false;
  1852. }
  1853. #endif /* WLAN_FEATURE_FASTPATH */
  1854. void ce_fini(struct CE_handle *copyeng)
  1855. {
  1856. struct CE_state *CE_state = (struct CE_state *)copyeng;
  1857. unsigned int CE_id = CE_state->id;
  1858. struct hif_softc *scn = CE_state->scn;
  1859. uint32_t desc_size;
  1860. bool inited = CE_state->timer_inited;
  1861. CE_state->state = CE_UNUSED;
  1862. scn->ce_id_to_state[CE_id] = NULL;
  1863. /* Set the flag to false first to stop processing in ce_poll_timeout */
  1864. ce_disable_polling(CE_state);
  1865. qdf_lro_deinit(CE_state->lro_data);
  1866. if (CE_state->src_ring) {
  1867. /* Cleanup the datapath Tx ring */
  1868. ce_h2t_tx_ce_cleanup(copyeng);
  1869. desc_size = ce_get_desc_size(scn, CE_RING_SRC);
  1870. if (CE_state->src_ring->shadow_base_unaligned)
  1871. qdf_mem_free(CE_state->src_ring->shadow_base_unaligned);
  1872. if (CE_state->src_ring->base_addr_owner_space_unaligned)
  1873. ce_free_desc_ring(scn, CE_state->id,
  1874. CE_state->src_ring,
  1875. desc_size);
  1876. qdf_mem_free(CE_state->src_ring);
  1877. }
  1878. if (CE_state->dest_ring) {
  1879. /* Cleanup the datapath Rx ring */
  1880. ce_t2h_msg_ce_cleanup(copyeng);
  1881. desc_size = ce_get_desc_size(scn, CE_RING_DEST);
  1882. if (CE_state->dest_ring->base_addr_owner_space_unaligned)
  1883. ce_free_desc_ring(scn, CE_state->id,
  1884. CE_state->dest_ring,
  1885. desc_size);
  1886. qdf_mem_free(CE_state->dest_ring);
  1887. /* epping */
  1888. if (inited) {
  1889. qdf_timer_free(&CE_state->poll_timer);
  1890. }
  1891. }
  1892. if ((ce_srng_based(CE_state->scn)) && (CE_state->status_ring)) {
  1893. /* Cleanup the datapath Tx ring */
  1894. ce_h2t_tx_ce_cleanup(copyeng);
  1895. if (CE_state->status_ring->shadow_base_unaligned)
  1896. qdf_mem_free(
  1897. CE_state->status_ring->shadow_base_unaligned);
  1898. desc_size = ce_get_desc_size(scn, CE_RING_STATUS);
  1899. if (CE_state->status_ring->base_addr_owner_space_unaligned)
  1900. ce_free_desc_ring(scn, CE_state->id,
  1901. CE_state->status_ring,
  1902. desc_size);
  1903. qdf_mem_free(CE_state->status_ring);
  1904. }
  1905. free_mem_ce_debug_history(scn, CE_id);
  1906. reset_ce_debug_history(scn);
  1907. ce_deinit_ce_desc_event_log(scn, CE_id);
  1908. qdf_spinlock_destroy(&CE_state->ce_index_lock);
  1909. qdf_mem_free(CE_state);
  1910. }
  1911. void hif_detach_htc(struct hif_opaque_softc *hif_ctx)
  1912. {
  1913. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
  1914. qdf_mem_zero(&hif_state->msg_callbacks_pending,
  1915. sizeof(hif_state->msg_callbacks_pending));
  1916. qdf_mem_zero(&hif_state->msg_callbacks_current,
  1917. sizeof(hif_state->msg_callbacks_current));
  1918. }
  1919. /* Send the first nbytes bytes of the buffer */
  1920. QDF_STATUS
  1921. hif_send_head(struct hif_opaque_softc *hif_ctx,
  1922. uint8_t pipe, unsigned int transfer_id, unsigned int nbytes,
  1923. qdf_nbuf_t nbuf, unsigned int data_attr)
  1924. {
  1925. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  1926. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
  1927. struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
  1928. struct CE_handle *ce_hdl = pipe_info->ce_hdl;
  1929. int bytes = nbytes, nfrags = 0;
  1930. struct ce_sendlist sendlist;
  1931. int i = 0;
  1932. QDF_STATUS status;
  1933. unsigned int mux_id = 0;
  1934. if (nbytes > qdf_nbuf_len(nbuf)) {
  1935. hif_err("nbytes: %d nbuf_len: %d", nbytes,
  1936. (uint32_t)qdf_nbuf_len(nbuf));
  1937. QDF_ASSERT(0);
  1938. }
  1939. transfer_id =
  1940. (mux_id & MUX_ID_MASK) |
  1941. (transfer_id & TRANSACTION_ID_MASK);
  1942. data_attr &= DESC_DATA_FLAG_MASK;
  1943. /*
  1944. * The common case involves sending multiple fragments within a
  1945. * single download (the tx descriptor and the tx frame header).
  1946. * So, optimize for the case of multiple fragments by not even
  1947. * checking whether it's necessary to use a sendlist.
  1948. * The overhead of using a sendlist for a single buffer download
  1949. * is not a big deal, since it happens rarely (for WMI messages).
  1950. */
  1951. ce_sendlist_init(&sendlist);
  1952. do {
  1953. qdf_dma_addr_t frag_paddr;
  1954. int frag_bytes;
  1955. frag_paddr = qdf_nbuf_get_frag_paddr(nbuf, nfrags);
  1956. frag_bytes = qdf_nbuf_get_frag_len(nbuf, nfrags);
  1957. /*
  1958. * Clear the packet offset for all but the first CE desc.
  1959. */
  1960. if (i++ > 0)
  1961. data_attr &= ~QDF_CE_TX_PKT_OFFSET_BIT_M;
  1962. status = ce_sendlist_buf_add(&sendlist, frag_paddr,
  1963. frag_bytes >
  1964. bytes ? bytes : frag_bytes,
  1965. qdf_nbuf_get_frag_is_wordstream
  1966. (nbuf,
  1967. nfrags) ? 0 :
  1968. CE_SEND_FLAG_SWAP_DISABLE,
  1969. data_attr);
  1970. if (status != QDF_STATUS_SUCCESS) {
  1971. hif_err("frag_num: %d larger than limit (status=%d)",
  1972. nfrags, status);
  1973. return status;
  1974. }
  1975. bytes -= frag_bytes;
  1976. nfrags++;
  1977. } while (bytes > 0);
  1978. /* Make sure we have resources to handle this request */
  1979. qdf_spin_lock_bh(&pipe_info->completion_freeq_lock);
  1980. if (pipe_info->num_sends_allowed < nfrags) {
  1981. qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
  1982. ce_pkt_error_count_incr(hif_state, HIF_PIPE_NO_RESOURCE);
  1983. return QDF_STATUS_E_RESOURCES;
  1984. }
  1985. pipe_info->num_sends_allowed -= nfrags;
  1986. qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
  1987. if (qdf_unlikely(!ce_hdl)) {
  1988. hif_err("CE handle is null");
  1989. return A_ERROR;
  1990. }
  1991. QDF_NBUF_UPDATE_TX_PKT_COUNT(nbuf, QDF_NBUF_TX_PKT_HIF);
  1992. DPTRACE(qdf_dp_trace(nbuf, QDF_DP_TRACE_HIF_PACKET_PTR_RECORD,
  1993. QDF_TRACE_DEFAULT_PDEV_ID, qdf_nbuf_data_addr(nbuf),
  1994. sizeof(qdf_nbuf_data(nbuf)), QDF_TX));
  1995. status = ce_sendlist_send(ce_hdl, nbuf, &sendlist, transfer_id);
  1996. QDF_ASSERT(status == QDF_STATUS_SUCCESS);
  1997. return status;
  1998. }
  1999. void hif_send_complete_check(struct hif_opaque_softc *hif_ctx, uint8_t pipe,
  2000. int force)
  2001. {
  2002. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  2003. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
  2004. if (!force) {
  2005. int resources;
  2006. /*
  2007. * Decide whether to actually poll for completions, or just
  2008. * wait for a later chance. If there seem to be plenty of
  2009. * resources left, then just wait, since checking involves
  2010. * reading a CE register, which is a relatively expensive
  2011. * operation.
  2012. */
  2013. resources = hif_get_free_queue_number(hif_ctx, pipe);
  2014. /*
  2015. * If at least 50% of the total resources are still available,
  2016. * don't bother checking again yet.
  2017. */
  2018. if (resources > (hif_state->host_ce_config[pipe].src_nentries >>
  2019. 1))
  2020. return;
  2021. }
  2022. #if ATH_11AC_TXCOMPACT
  2023. ce_per_engine_servicereap(scn, pipe);
  2024. #else
  2025. ce_per_engine_service(scn, pipe);
  2026. #endif
  2027. }
  2028. uint16_t
  2029. hif_get_free_queue_number(struct hif_opaque_softc *hif_ctx, uint8_t pipe)
  2030. {
  2031. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
  2032. struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
  2033. uint16_t rv;
  2034. qdf_spin_lock_bh(&pipe_info->completion_freeq_lock);
  2035. rv = pipe_info->num_sends_allowed;
  2036. qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
  2037. return rv;
  2038. }
  2039. /* Called by lower (CE) layer when a send to Target completes. */
  2040. static void
  2041. hif_pci_ce_send_done(struct CE_handle *copyeng, void *ce_context,
  2042. void *transfer_context, qdf_dma_addr_t CE_data,
  2043. unsigned int nbytes, unsigned int transfer_id,
  2044. unsigned int sw_index, unsigned int hw_index,
  2045. unsigned int toeplitz_hash_result)
  2046. {
  2047. struct HIF_CE_pipe_info *pipe_info =
  2048. (struct HIF_CE_pipe_info *)ce_context;
  2049. unsigned int sw_idx = sw_index, hw_idx = hw_index;
  2050. struct hif_msg_callbacks *msg_callbacks =
  2051. &pipe_info->pipe_callbacks;
  2052. do {
  2053. /*
  2054. * The upper layer callback will be triggered
  2055. * when last fragment is complteted.
  2056. */
  2057. if (transfer_context != CE_SENDLIST_ITEM_CTXT)
  2058. msg_callbacks->txCompletionHandler(
  2059. msg_callbacks->Context,
  2060. transfer_context, transfer_id,
  2061. toeplitz_hash_result);
  2062. qdf_spin_lock_bh(&pipe_info->completion_freeq_lock);
  2063. pipe_info->num_sends_allowed++;
  2064. qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
  2065. } while (ce_completed_send_next(copyeng,
  2066. &ce_context, &transfer_context,
  2067. &CE_data, &nbytes, &transfer_id,
  2068. &sw_idx, &hw_idx,
  2069. &toeplitz_hash_result) == QDF_STATUS_SUCCESS);
  2070. }
  2071. /**
  2072. * hif_ce_do_recv(): send message from copy engine to upper layers
  2073. * @msg_callbacks: structure containing callback and callback context
  2074. * @netbuff: skb containing message
  2075. * @nbytes: number of bytes in the message
  2076. * @pipe_info: used for the pipe_number info
  2077. *
  2078. * Checks the packet length, configures the length in the netbuff,
  2079. * and calls the upper layer callback.
  2080. *
  2081. * return: None
  2082. */
  2083. static inline void hif_ce_do_recv(struct hif_msg_callbacks *msg_callbacks,
  2084. qdf_nbuf_t netbuf, int nbytes,
  2085. struct HIF_CE_pipe_info *pipe_info) {
  2086. if (nbytes <= pipe_info->buf_sz) {
  2087. qdf_nbuf_set_pktlen(netbuf, nbytes);
  2088. msg_callbacks->
  2089. rxCompletionHandler(msg_callbacks->Context,
  2090. netbuf, pipe_info->pipe_num);
  2091. } else {
  2092. hif_err("Invalid Rx msg buf: %pK nbytes: %d", netbuf, nbytes);
  2093. qdf_nbuf_free(netbuf);
  2094. }
  2095. }
  2096. /* Called by lower (CE) layer when data is received from the Target. */
  2097. static void
  2098. hif_pci_ce_recv_data(struct CE_handle *copyeng, void *ce_context,
  2099. void *transfer_context, qdf_dma_addr_t CE_data,
  2100. unsigned int nbytes, unsigned int transfer_id,
  2101. unsigned int flags)
  2102. {
  2103. struct HIF_CE_pipe_info *pipe_info =
  2104. (struct HIF_CE_pipe_info *)ce_context;
  2105. struct HIF_CE_state *hif_state = pipe_info->HIF_CE_state;
  2106. struct CE_state *ce_state = (struct CE_state *) copyeng;
  2107. struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
  2108. struct hif_opaque_softc *hif_ctx = GET_HIF_OPAQUE_HDL(scn);
  2109. struct hif_msg_callbacks *msg_callbacks =
  2110. &pipe_info->pipe_callbacks;
  2111. do {
  2112. hif_pm_runtime_mark_last_busy(hif_ctx);
  2113. qdf_nbuf_unmap_single(scn->qdf_dev,
  2114. (qdf_nbuf_t) transfer_context,
  2115. QDF_DMA_FROM_DEVICE);
  2116. atomic_inc(&pipe_info->recv_bufs_needed);
  2117. hif_post_recv_buffers_for_pipe(pipe_info);
  2118. if (scn->target_status == TARGET_STATUS_RESET)
  2119. qdf_nbuf_free(transfer_context);
  2120. else
  2121. hif_ce_do_recv(msg_callbacks, transfer_context,
  2122. nbytes, pipe_info);
  2123. /* Set up force_break flag if num of receices reaches
  2124. * MAX_NUM_OF_RECEIVES
  2125. */
  2126. ce_state->receive_count++;
  2127. if (qdf_unlikely(hif_ce_service_should_yield(scn, ce_state))) {
  2128. ce_state->force_break = 1;
  2129. break;
  2130. }
  2131. } while (ce_completed_recv_next(copyeng, &ce_context, &transfer_context,
  2132. &CE_data, &nbytes, &transfer_id,
  2133. &flags) == QDF_STATUS_SUCCESS);
  2134. }
  2135. /* TBDXXX: Set CE High Watermark; invoke txResourceAvailHandler in response */
  2136. void
  2137. hif_post_init(struct hif_opaque_softc *hif_ctx, void *unused,
  2138. struct hif_msg_callbacks *callbacks)
  2139. {
  2140. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
  2141. #ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
  2142. spin_lock_init(&pcie_access_log_lock);
  2143. #endif
  2144. /* Save callbacks for later installation */
  2145. qdf_mem_copy(&hif_state->msg_callbacks_pending, callbacks,
  2146. sizeof(hif_state->msg_callbacks_pending));
  2147. }
  2148. static int hif_completion_thread_startup_by_ceid(struct HIF_CE_state *hif_state,
  2149. int pipe_num)
  2150. {
  2151. struct CE_attr attr;
  2152. struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
  2153. struct hif_msg_callbacks *hif_msg_callbacks =
  2154. &hif_state->msg_callbacks_current;
  2155. struct HIF_CE_pipe_info *pipe_info;
  2156. struct CE_state *ce_state;
  2157. if (pipe_num >= CE_COUNT_MAX)
  2158. return -EINVAL;
  2159. pipe_info = &hif_state->pipe_info[pipe_num];
  2160. ce_state = scn->ce_id_to_state[pipe_num];
  2161. if (!hif_msg_callbacks ||
  2162. !hif_msg_callbacks->rxCompletionHandler ||
  2163. !hif_msg_callbacks->txCompletionHandler) {
  2164. hif_err("%s: no completion handler registered", __func__);
  2165. return -EFAULT;
  2166. }
  2167. attr = hif_state->host_ce_config[pipe_num];
  2168. if (attr.src_nentries) {
  2169. /* pipe used to send to target */
  2170. hif_debug("%s: pipe_num:%d pipe_info:0x%pK\n",
  2171. __func__, pipe_num, pipe_info);
  2172. ce_send_cb_register(pipe_info->ce_hdl,
  2173. hif_pci_ce_send_done, pipe_info,
  2174. attr.flags & CE_ATTR_DISABLE_INTR);
  2175. pipe_info->num_sends_allowed = attr.src_nentries - 1;
  2176. }
  2177. if (attr.dest_nentries) {
  2178. hif_debug("%s: pipe_num:%d pipe_info:0x%pK\n",
  2179. __func__, pipe_num, pipe_info);
  2180. /* pipe used to receive from target */
  2181. ce_recv_cb_register(pipe_info->ce_hdl,
  2182. hif_pci_ce_recv_data, pipe_info,
  2183. attr.flags & CE_ATTR_DISABLE_INTR);
  2184. }
  2185. if (attr.src_nentries)
  2186. qdf_spinlock_create(&pipe_info->completion_freeq_lock);
  2187. if (!(ce_state->attr_flags & CE_ATTR_INIT_ON_DEMAND))
  2188. qdf_mem_copy(&pipe_info->pipe_callbacks, hif_msg_callbacks,
  2189. sizeof(pipe_info->pipe_callbacks));
  2190. return 0;
  2191. }
  2192. static int hif_completion_thread_startup(struct HIF_CE_state *hif_state)
  2193. {
  2194. struct CE_handle *ce_diag = hif_state->ce_diag;
  2195. int pipe_num, ret;
  2196. struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
  2197. /* daemonize("hif_compl_thread"); */
  2198. if (scn->ce_count == 0) {
  2199. hif_err("ce_count is 0");
  2200. return -EINVAL;
  2201. }
  2202. A_TARGET_ACCESS_LIKELY(scn);
  2203. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  2204. struct HIF_CE_pipe_info *pipe_info;
  2205. pipe_info = &hif_state->pipe_info[pipe_num];
  2206. if (pipe_info->ce_hdl == ce_diag)
  2207. continue; /* Handle Diagnostic CE specially */
  2208. ret = hif_completion_thread_startup_by_ceid(hif_state,
  2209. pipe_num);
  2210. if (ret < 0)
  2211. return ret;
  2212. }
  2213. A_TARGET_ACCESS_UNLIKELY(scn);
  2214. return 0;
  2215. }
  2216. /*
  2217. * Install pending msg callbacks.
  2218. *
  2219. * TBDXXX: This hack is needed because upper layers install msg callbacks
  2220. * for use with HTC before BMI is done; yet this HIF implementation
  2221. * needs to continue to use BMI msg callbacks. Really, upper layers
  2222. * should not register HTC callbacks until AFTER BMI phase.
  2223. */
  2224. static void hif_msg_callbacks_install(struct hif_softc *scn)
  2225. {
  2226. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  2227. qdf_mem_copy(&hif_state->msg_callbacks_current,
  2228. &hif_state->msg_callbacks_pending,
  2229. sizeof(hif_state->msg_callbacks_pending));
  2230. }
  2231. void hif_get_default_pipe(struct hif_opaque_softc *hif_hdl, uint8_t *ULPipe,
  2232. uint8_t *DLPipe)
  2233. {
  2234. int ul_is_polled, dl_is_polled;
  2235. (void)hif_map_service_to_pipe(hif_hdl, HTC_CTRL_RSVD_SVC,
  2236. ULPipe, DLPipe, &ul_is_polled, &dl_is_polled);
  2237. }
  2238. /**
  2239. * hif_dump_pipe_debug_count() - Log error count
  2240. * @scn: hif_softc pointer.
  2241. *
  2242. * Output the pipe error counts of each pipe to log file
  2243. *
  2244. * Return: N/A
  2245. */
  2246. void hif_dump_pipe_debug_count(struct hif_softc *scn)
  2247. {
  2248. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  2249. int pipe_num;
  2250. if (!hif_state) {
  2251. hif_err("hif_state is NULL");
  2252. return;
  2253. }
  2254. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  2255. struct HIF_CE_pipe_info *pipe_info;
  2256. pipe_info = &hif_state->pipe_info[pipe_num];
  2257. if (pipe_info->nbuf_alloc_err_count > 0 ||
  2258. pipe_info->nbuf_dma_err_count > 0 ||
  2259. pipe_info->nbuf_ce_enqueue_err_count)
  2260. hif_err(
  2261. "pipe_id = %d, recv_bufs_needed = %d, nbuf_alloc_err_count = %u, nbuf_dma_err_count = %u, nbuf_ce_enqueue_err_count = %u",
  2262. pipe_info->pipe_num,
  2263. atomic_read(&pipe_info->recv_bufs_needed),
  2264. pipe_info->nbuf_alloc_err_count,
  2265. pipe_info->nbuf_dma_err_count,
  2266. pipe_info->nbuf_ce_enqueue_err_count);
  2267. }
  2268. }
  2269. static void hif_post_recv_buffers_failure(struct HIF_CE_pipe_info *pipe_info,
  2270. void *nbuf, uint32_t *error_cnt,
  2271. enum hif_ce_event_type failure_type,
  2272. const char *failure_type_string)
  2273. {
  2274. int bufs_needed_tmp = atomic_inc_return(&pipe_info->recv_bufs_needed);
  2275. struct CE_state *CE_state = (struct CE_state *)pipe_info->ce_hdl;
  2276. struct hif_softc *scn = HIF_GET_SOFTC(pipe_info->HIF_CE_state);
  2277. int ce_id = CE_state->id;
  2278. uint32_t error_cnt_tmp;
  2279. qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
  2280. error_cnt_tmp = ++(*error_cnt);
  2281. qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
  2282. hif_debug("pipe_num: %d, needed: %d, err_cnt: %u, fail_type: %s",
  2283. pipe_info->pipe_num, bufs_needed_tmp, error_cnt_tmp,
  2284. failure_type_string);
  2285. hif_record_ce_desc_event(scn, ce_id, failure_type,
  2286. NULL, nbuf, bufs_needed_tmp, 0);
  2287. /* if we fail to allocate the last buffer for an rx pipe,
  2288. * there is no trigger to refill the ce and we will
  2289. * eventually crash
  2290. */
  2291. if (bufs_needed_tmp == CE_state->dest_ring->nentries - 1 ||
  2292. (ce_srng_based(scn) &&
  2293. bufs_needed_tmp == CE_state->dest_ring->nentries - 2))
  2294. qdf_sched_work(scn->qdf_dev, &CE_state->oom_allocation_work);
  2295. }
  2296. QDF_STATUS hif_post_recv_buffers_for_pipe(struct HIF_CE_pipe_info *pipe_info)
  2297. {
  2298. struct CE_handle *ce_hdl;
  2299. qdf_size_t buf_sz;
  2300. struct hif_softc *scn = HIF_GET_SOFTC(pipe_info->HIF_CE_state);
  2301. QDF_STATUS status;
  2302. uint32_t bufs_posted = 0;
  2303. unsigned int ce_id;
  2304. buf_sz = pipe_info->buf_sz;
  2305. if (buf_sz == 0) {
  2306. /* Unused Copy Engine */
  2307. return QDF_STATUS_SUCCESS;
  2308. }
  2309. ce_hdl = pipe_info->ce_hdl;
  2310. ce_id = ((struct CE_state *)ce_hdl)->id;
  2311. qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
  2312. while (atomic_read(&pipe_info->recv_bufs_needed) > 0) {
  2313. qdf_dma_addr_t CE_data; /* CE space buffer address */
  2314. qdf_nbuf_t nbuf;
  2315. atomic_dec(&pipe_info->recv_bufs_needed);
  2316. qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
  2317. hif_record_ce_desc_event(scn, ce_id,
  2318. HIF_RX_DESC_PRE_NBUF_ALLOC, NULL, NULL,
  2319. 0, 0);
  2320. nbuf = qdf_nbuf_alloc(scn->qdf_dev, buf_sz, 0, 4, false);
  2321. if (!nbuf) {
  2322. hif_post_recv_buffers_failure(pipe_info, nbuf,
  2323. &pipe_info->nbuf_alloc_err_count,
  2324. HIF_RX_NBUF_ALLOC_FAILURE,
  2325. "HIF_RX_NBUF_ALLOC_FAILURE");
  2326. return QDF_STATUS_E_NOMEM;
  2327. }
  2328. hif_record_ce_desc_event(scn, ce_id,
  2329. HIF_RX_DESC_PRE_NBUF_MAP, NULL, nbuf,
  2330. 0, 0);
  2331. /*
  2332. * qdf_nbuf_peek_header(nbuf, &data, &unused);
  2333. * CE_data = dma_map_single(dev, data, buf_sz, );
  2334. * DMA_FROM_DEVICE);
  2335. */
  2336. status = qdf_nbuf_map_single(scn->qdf_dev, nbuf,
  2337. QDF_DMA_FROM_DEVICE);
  2338. if (qdf_unlikely(status != QDF_STATUS_SUCCESS)) {
  2339. hif_post_recv_buffers_failure(pipe_info, nbuf,
  2340. &pipe_info->nbuf_dma_err_count,
  2341. HIF_RX_NBUF_MAP_FAILURE,
  2342. "HIF_RX_NBUF_MAP_FAILURE");
  2343. qdf_nbuf_free(nbuf);
  2344. return status;
  2345. }
  2346. CE_data = qdf_nbuf_get_frag_paddr(nbuf, 0);
  2347. hif_record_ce_desc_event(scn, ce_id,
  2348. HIF_RX_DESC_POST_NBUF_MAP, NULL, nbuf,
  2349. 0, 0);
  2350. qdf_mem_dma_sync_single_for_device(scn->qdf_dev, CE_data,
  2351. buf_sz, DMA_FROM_DEVICE);
  2352. status = ce_recv_buf_enqueue(ce_hdl, (void *)nbuf, CE_data);
  2353. if (qdf_unlikely(status != QDF_STATUS_SUCCESS)) {
  2354. hif_post_recv_buffers_failure(pipe_info, nbuf,
  2355. &pipe_info->nbuf_ce_enqueue_err_count,
  2356. HIF_RX_NBUF_ENQUEUE_FAILURE,
  2357. "HIF_RX_NBUF_ENQUEUE_FAILURE");
  2358. qdf_nbuf_unmap_single(scn->qdf_dev, nbuf,
  2359. QDF_DMA_FROM_DEVICE);
  2360. qdf_nbuf_free(nbuf);
  2361. return status;
  2362. }
  2363. qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
  2364. bufs_posted++;
  2365. }
  2366. pipe_info->nbuf_alloc_err_count =
  2367. (pipe_info->nbuf_alloc_err_count > bufs_posted) ?
  2368. pipe_info->nbuf_alloc_err_count - bufs_posted : 0;
  2369. pipe_info->nbuf_dma_err_count =
  2370. (pipe_info->nbuf_dma_err_count > bufs_posted) ?
  2371. pipe_info->nbuf_dma_err_count - bufs_posted : 0;
  2372. pipe_info->nbuf_ce_enqueue_err_count =
  2373. (pipe_info->nbuf_ce_enqueue_err_count > bufs_posted) ?
  2374. pipe_info->nbuf_ce_enqueue_err_count - bufs_posted : 0;
  2375. qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
  2376. return QDF_STATUS_SUCCESS;
  2377. }
  2378. /*
  2379. * Try to post all desired receive buffers for all pipes.
  2380. * Returns 0 for non fastpath rx copy engine as
  2381. * oom_allocation_work will be scheduled to recover any
  2382. * failures, non-zero if unable to completely replenish
  2383. * receive buffers for fastpath rx Copy engine.
  2384. */
  2385. static QDF_STATUS hif_post_recv_buffers(struct hif_softc *scn)
  2386. {
  2387. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  2388. int pipe_num;
  2389. struct CE_state *ce_state = NULL;
  2390. QDF_STATUS qdf_status;
  2391. A_TARGET_ACCESS_LIKELY(scn);
  2392. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  2393. struct HIF_CE_pipe_info *pipe_info;
  2394. ce_state = scn->ce_id_to_state[pipe_num];
  2395. pipe_info = &hif_state->pipe_info[pipe_num];
  2396. if (!ce_state)
  2397. continue;
  2398. /* Do not init dynamic CEs, during initial load */
  2399. if (ce_state->attr_flags & CE_ATTR_INIT_ON_DEMAND)
  2400. continue;
  2401. if (hif_is_nss_wifi_enabled(scn) &&
  2402. ce_state && (ce_state->htt_rx_data))
  2403. continue;
  2404. qdf_status = hif_post_recv_buffers_for_pipe(pipe_info);
  2405. if (!QDF_IS_STATUS_SUCCESS(qdf_status) && ce_state &&
  2406. ce_state->htt_rx_data &&
  2407. scn->fastpath_mode_on) {
  2408. A_TARGET_ACCESS_UNLIKELY(scn);
  2409. return qdf_status;
  2410. }
  2411. }
  2412. A_TARGET_ACCESS_UNLIKELY(scn);
  2413. return QDF_STATUS_SUCCESS;
  2414. }
  2415. QDF_STATUS hif_start(struct hif_opaque_softc *hif_ctx)
  2416. {
  2417. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  2418. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  2419. QDF_STATUS qdf_status = QDF_STATUS_SUCCESS;
  2420. hif_update_fastpath_recv_bufs_cnt(scn);
  2421. hif_msg_callbacks_install(scn);
  2422. if (hif_completion_thread_startup(hif_state))
  2423. return QDF_STATUS_E_FAILURE;
  2424. /* enable buffer cleanup */
  2425. hif_state->started = true;
  2426. /* Post buffers once to start things off. */
  2427. qdf_status = hif_post_recv_buffers(scn);
  2428. if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
  2429. /* cleanup is done in hif_ce_disable */
  2430. hif_err("Failed to post buffers");
  2431. return qdf_status;
  2432. }
  2433. return qdf_status;
  2434. }
  2435. static void hif_recv_buffer_cleanup_on_pipe(struct HIF_CE_pipe_info *pipe_info)
  2436. {
  2437. struct hif_softc *scn;
  2438. struct CE_handle *ce_hdl;
  2439. uint32_t buf_sz;
  2440. struct HIF_CE_state *hif_state;
  2441. qdf_nbuf_t netbuf;
  2442. qdf_dma_addr_t CE_data;
  2443. void *per_CE_context;
  2444. buf_sz = pipe_info->buf_sz;
  2445. /* Unused Copy Engine */
  2446. if (buf_sz == 0)
  2447. return;
  2448. hif_state = pipe_info->HIF_CE_state;
  2449. if (!hif_state->started)
  2450. return;
  2451. scn = HIF_GET_SOFTC(hif_state);
  2452. ce_hdl = pipe_info->ce_hdl;
  2453. if (!scn->qdf_dev)
  2454. return;
  2455. while (ce_revoke_recv_next
  2456. (ce_hdl, &per_CE_context, (void **)&netbuf,
  2457. &CE_data) == QDF_STATUS_SUCCESS) {
  2458. if (netbuf) {
  2459. qdf_nbuf_unmap_single(scn->qdf_dev, netbuf,
  2460. QDF_DMA_FROM_DEVICE);
  2461. qdf_nbuf_free(netbuf);
  2462. }
  2463. }
  2464. }
  2465. static void hif_send_buffer_cleanup_on_pipe(struct HIF_CE_pipe_info *pipe_info)
  2466. {
  2467. struct CE_handle *ce_hdl;
  2468. struct HIF_CE_state *hif_state;
  2469. struct hif_softc *scn;
  2470. qdf_nbuf_t netbuf;
  2471. void *per_CE_context;
  2472. qdf_dma_addr_t CE_data;
  2473. unsigned int nbytes;
  2474. unsigned int id;
  2475. uint32_t buf_sz;
  2476. uint32_t toeplitz_hash_result;
  2477. buf_sz = pipe_info->buf_sz;
  2478. if (buf_sz == 0) {
  2479. /* Unused Copy Engine */
  2480. return;
  2481. }
  2482. hif_state = pipe_info->HIF_CE_state;
  2483. if (!hif_state->started) {
  2484. return;
  2485. }
  2486. scn = HIF_GET_SOFTC(hif_state);
  2487. ce_hdl = pipe_info->ce_hdl;
  2488. while (ce_cancel_send_next
  2489. (ce_hdl, &per_CE_context,
  2490. (void **)&netbuf, &CE_data, &nbytes,
  2491. &id, &toeplitz_hash_result) == QDF_STATUS_SUCCESS) {
  2492. if (netbuf != CE_SENDLIST_ITEM_CTXT) {
  2493. /*
  2494. * Packets enqueued by htt_h2t_ver_req_msg() and
  2495. * htt_h2t_rx_ring_cfg_msg_ll() have already been
  2496. * freed in htt_htc_misc_pkt_pool_free() in
  2497. * wlantl_close(), so do not free them here again
  2498. * by checking whether it's the endpoint
  2499. * which they are queued in.
  2500. */
  2501. if (id == scn->htc_htt_tx_endpoint)
  2502. return;
  2503. /* Indicate the completion to higher
  2504. * layer to free the buffer
  2505. */
  2506. if (pipe_info->pipe_callbacks.txCompletionHandler)
  2507. pipe_info->pipe_callbacks.
  2508. txCompletionHandler(pipe_info->
  2509. pipe_callbacks.Context,
  2510. netbuf, id, toeplitz_hash_result);
  2511. }
  2512. }
  2513. }
  2514. /*
  2515. * Cleanup residual buffers for device shutdown:
  2516. * buffers that were enqueued for receive
  2517. * buffers that were to be sent
  2518. * Note: Buffers that had completed but which were
  2519. * not yet processed are on a completion queue. They
  2520. * are handled when the completion thread shuts down.
  2521. */
  2522. static void hif_buffer_cleanup(struct HIF_CE_state *hif_state)
  2523. {
  2524. int pipe_num;
  2525. struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
  2526. struct CE_state *ce_state;
  2527. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  2528. struct HIF_CE_pipe_info *pipe_info;
  2529. ce_state = scn->ce_id_to_state[pipe_num];
  2530. if (hif_is_nss_wifi_enabled(scn) && ce_state &&
  2531. ((ce_state->htt_tx_data) ||
  2532. (ce_state->htt_rx_data))) {
  2533. continue;
  2534. }
  2535. pipe_info = &hif_state->pipe_info[pipe_num];
  2536. hif_recv_buffer_cleanup_on_pipe(pipe_info);
  2537. hif_send_buffer_cleanup_on_pipe(pipe_info);
  2538. }
  2539. }
  2540. void hif_flush_surprise_remove(struct hif_opaque_softc *hif_ctx)
  2541. {
  2542. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  2543. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  2544. hif_buffer_cleanup(hif_state);
  2545. }
  2546. static void hif_destroy_oom_work(struct hif_softc *scn)
  2547. {
  2548. struct CE_state *ce_state;
  2549. int ce_id;
  2550. for (ce_id = 0; ce_id < scn->ce_count; ce_id++) {
  2551. ce_state = scn->ce_id_to_state[ce_id];
  2552. if (ce_state)
  2553. qdf_destroy_work(scn->qdf_dev,
  2554. &ce_state->oom_allocation_work);
  2555. }
  2556. }
  2557. void hif_ce_stop(struct hif_softc *scn)
  2558. {
  2559. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  2560. int pipe_num;
  2561. /*
  2562. * before cleaning up any memory, ensure irq &
  2563. * bottom half contexts will not be re-entered
  2564. */
  2565. hif_disable_isr(&scn->osc);
  2566. hif_destroy_oom_work(scn);
  2567. scn->hif_init_done = false;
  2568. /*
  2569. * At this point, asynchronous threads are stopped,
  2570. * The Target should not DMA nor interrupt, Host code may
  2571. * not initiate anything more. So we just need to clean
  2572. * up Host-side state.
  2573. */
  2574. if (scn->athdiag_procfs_inited) {
  2575. athdiag_procfs_remove();
  2576. scn->athdiag_procfs_inited = false;
  2577. }
  2578. hif_buffer_cleanup(hif_state);
  2579. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  2580. struct HIF_CE_pipe_info *pipe_info;
  2581. struct CE_attr attr;
  2582. struct CE_handle *ce_diag = hif_state->ce_diag;
  2583. pipe_info = &hif_state->pipe_info[pipe_num];
  2584. if (pipe_info->ce_hdl) {
  2585. if (pipe_info->ce_hdl != ce_diag &&
  2586. hif_state->started) {
  2587. attr = hif_state->host_ce_config[pipe_num];
  2588. if (attr.src_nentries)
  2589. qdf_spinlock_destroy(&pipe_info->
  2590. completion_freeq_lock);
  2591. }
  2592. ce_fini(pipe_info->ce_hdl);
  2593. pipe_info->ce_hdl = NULL;
  2594. pipe_info->buf_sz = 0;
  2595. qdf_spinlock_destroy(&pipe_info->recv_bufs_needed_lock);
  2596. }
  2597. }
  2598. if (hif_state->sleep_timer_init) {
  2599. qdf_timer_stop(&hif_state->sleep_timer);
  2600. qdf_timer_free(&hif_state->sleep_timer);
  2601. hif_state->sleep_timer_init = false;
  2602. }
  2603. hif_state->started = false;
  2604. }
  2605. static void hif_get_shadow_reg_cfg(struct hif_softc *scn,
  2606. struct shadow_reg_cfg
  2607. **target_shadow_reg_cfg_ret,
  2608. uint32_t *shadow_cfg_sz_ret)
  2609. {
  2610. if (target_shadow_reg_cfg_ret)
  2611. *target_shadow_reg_cfg_ret = target_shadow_reg_cfg;
  2612. if (shadow_cfg_sz_ret)
  2613. *shadow_cfg_sz_ret = shadow_cfg_sz;
  2614. }
  2615. /**
  2616. * hif_get_target_ce_config() - get copy engine configuration
  2617. * @target_ce_config_ret: basic copy engine configuration
  2618. * @target_ce_config_sz_ret: size of the basic configuration in bytes
  2619. * @target_service_to_ce_map_ret: service mapping for the copy engines
  2620. * @target_service_to_ce_map_sz_ret: size of the mapping in bytes
  2621. * @target_shadow_reg_cfg_ret: shadow register configuration
  2622. * @shadow_cfg_sz_ret: size of the shadow register configuration in bytes
  2623. *
  2624. * providing accessor to these values outside of this file.
  2625. * currently these are stored in static pointers to const sections.
  2626. * there are multiple configurations that are selected from at compile time.
  2627. * Runtime selection would need to consider mode, target type and bus type.
  2628. *
  2629. * Return: return by parameter.
  2630. */
  2631. void hif_get_target_ce_config(struct hif_softc *scn,
  2632. struct CE_pipe_config **target_ce_config_ret,
  2633. uint32_t *target_ce_config_sz_ret,
  2634. struct service_to_pipe **target_service_to_ce_map_ret,
  2635. uint32_t *target_service_to_ce_map_sz_ret,
  2636. struct shadow_reg_cfg **target_shadow_reg_cfg_ret,
  2637. uint32_t *shadow_cfg_sz_ret)
  2638. {
  2639. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  2640. *target_ce_config_ret = hif_state->target_ce_config;
  2641. *target_ce_config_sz_ret = hif_state->target_ce_config_sz;
  2642. hif_select_service_to_pipe_map(scn, target_service_to_ce_map_ret,
  2643. target_service_to_ce_map_sz_ret);
  2644. hif_get_shadow_reg_cfg(scn, target_shadow_reg_cfg_ret,
  2645. shadow_cfg_sz_ret);
  2646. }
  2647. #ifdef CONFIG_SHADOW_V2
  2648. static void hif_print_hal_shadow_register_cfg(struct pld_wlan_enable_cfg *cfg)
  2649. {
  2650. int i;
  2651. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  2652. "%s: num_config %d", __func__, cfg->num_shadow_reg_v2_cfg);
  2653. for (i = 0; i < cfg->num_shadow_reg_v2_cfg; i++) {
  2654. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO,
  2655. "%s: i %d, val %x", __func__, i,
  2656. cfg->shadow_reg_v2_cfg[i].addr);
  2657. }
  2658. }
  2659. #else
  2660. static void hif_print_hal_shadow_register_cfg(struct pld_wlan_enable_cfg *cfg)
  2661. {
  2662. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  2663. "%s: CONFIG_SHADOW_V2 not defined", __func__);
  2664. }
  2665. #endif
  2666. #ifdef ADRASTEA_RRI_ON_DDR
  2667. /**
  2668. * hif_get_src_ring_read_index(): Called to get the SRRI
  2669. *
  2670. * @scn: hif_softc pointer
  2671. * @CE_ctrl_addr: base address of the CE whose RRI is to be read
  2672. *
  2673. * This function returns the SRRI to the caller. For CEs that
  2674. * dont have interrupts enabled, we look at the DDR based SRRI
  2675. *
  2676. * Return: SRRI
  2677. */
  2678. inline unsigned int hif_get_src_ring_read_index(struct hif_softc *scn,
  2679. uint32_t CE_ctrl_addr)
  2680. {
  2681. struct CE_attr attr;
  2682. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  2683. attr = hif_state->host_ce_config[COPY_ENGINE_ID(CE_ctrl_addr)];
  2684. if (attr.flags & CE_ATTR_DISABLE_INTR) {
  2685. return CE_SRC_RING_READ_IDX_GET_FROM_DDR(scn, CE_ctrl_addr);
  2686. } else {
  2687. if (TARGET_REGISTER_ACCESS_ALLOWED(scn))
  2688. return A_TARGET_READ(scn,
  2689. (CE_ctrl_addr) + CURRENT_SRRI_ADDRESS);
  2690. else
  2691. return CE_SRC_RING_READ_IDX_GET_FROM_DDR(scn,
  2692. CE_ctrl_addr);
  2693. }
  2694. }
  2695. /**
  2696. * hif_get_dst_ring_read_index(): Called to get the DRRI
  2697. *
  2698. * @scn: hif_softc pointer
  2699. * @CE_ctrl_addr: base address of the CE whose RRI is to be read
  2700. *
  2701. * This function returns the DRRI to the caller. For CEs that
  2702. * dont have interrupts enabled, we look at the DDR based DRRI
  2703. *
  2704. * Return: DRRI
  2705. */
  2706. inline unsigned int hif_get_dst_ring_read_index(struct hif_softc *scn,
  2707. uint32_t CE_ctrl_addr)
  2708. {
  2709. struct CE_attr attr;
  2710. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  2711. attr = hif_state->host_ce_config[COPY_ENGINE_ID(CE_ctrl_addr)];
  2712. if (attr.flags & CE_ATTR_DISABLE_INTR) {
  2713. return CE_DEST_RING_READ_IDX_GET_FROM_DDR(scn, CE_ctrl_addr);
  2714. } else {
  2715. if (TARGET_REGISTER_ACCESS_ALLOWED(scn))
  2716. return A_TARGET_READ(scn,
  2717. (CE_ctrl_addr) + CURRENT_DRRI_ADDRESS);
  2718. else
  2719. return CE_DEST_RING_READ_IDX_GET_FROM_DDR(scn,
  2720. CE_ctrl_addr);
  2721. }
  2722. }
  2723. /**
  2724. * hif_alloc_rri_on_ddr() - Allocate memory for rri on ddr
  2725. * @scn: hif_softc pointer
  2726. *
  2727. * Return: qdf status
  2728. */
  2729. static inline QDF_STATUS hif_alloc_rri_on_ddr(struct hif_softc *scn)
  2730. {
  2731. qdf_dma_addr_t paddr_rri_on_ddr = 0;
  2732. scn->vaddr_rri_on_ddr =
  2733. (uint32_t *)qdf_mem_alloc_consistent(scn->qdf_dev,
  2734. scn->qdf_dev->dev, (CE_COUNT * sizeof(uint32_t)),
  2735. &paddr_rri_on_ddr);
  2736. if (!scn->vaddr_rri_on_ddr) {
  2737. hif_err("dmaable page alloc fail");
  2738. return QDF_STATUS_E_NOMEM;
  2739. }
  2740. scn->paddr_rri_on_ddr = paddr_rri_on_ddr;
  2741. qdf_mem_zero(scn->vaddr_rri_on_ddr, CE_COUNT * sizeof(uint32_t));
  2742. return QDF_STATUS_SUCCESS;
  2743. }
  2744. #endif
  2745. #if (!defined(QCN7605_SUPPORT)) && defined(ADRASTEA_RRI_ON_DDR)
  2746. /**
  2747. * hif_config_rri_on_ddr(): Configure the RRI on DDR mechanism
  2748. *
  2749. * @scn: hif_softc pointer
  2750. *
  2751. * This function allocates non cached memory on ddr and sends
  2752. * the physical address of this memory to the CE hardware. The
  2753. * hardware updates the RRI on this particular location.
  2754. *
  2755. * Return: None
  2756. */
  2757. static inline void hif_config_rri_on_ddr(struct hif_softc *scn)
  2758. {
  2759. unsigned int i;
  2760. uint32_t high_paddr, low_paddr;
  2761. if (hif_alloc_rri_on_ddr(scn) != QDF_STATUS_SUCCESS)
  2762. return;
  2763. low_paddr = BITS0_TO_31(scn->paddr_rri_on_ddr);
  2764. high_paddr = BITS32_TO_35(scn->paddr_rri_on_ddr);
  2765. hif_debug("using srri and drri from DDR");
  2766. WRITE_CE_DDR_ADDRESS_FOR_RRI_LOW(scn, low_paddr);
  2767. WRITE_CE_DDR_ADDRESS_FOR_RRI_HIGH(scn, high_paddr);
  2768. for (i = 0; i < CE_COUNT; i++)
  2769. CE_IDX_UPD_EN_SET(scn, CE_BASE_ADDRESS(i));
  2770. }
  2771. #else
  2772. /**
  2773. * hif_config_rri_on_ddr(): Configure the RRI on DDR mechanism
  2774. *
  2775. * @scn: hif_softc pointer
  2776. *
  2777. * This is a dummy implementation for platforms that don't
  2778. * support this functionality.
  2779. *
  2780. * Return: None
  2781. */
  2782. static inline void hif_config_rri_on_ddr(struct hif_softc *scn)
  2783. {
  2784. }
  2785. #endif
  2786. /**
  2787. * hif_update_rri_over_ddr_config() - update rri_over_ddr config for
  2788. * QMI command
  2789. * @scn: hif context
  2790. * @cfg: wlan enable config
  2791. *
  2792. * In case of Genoa, rri_over_ddr memory configuration is passed
  2793. * to firmware through QMI configure command.
  2794. */
  2795. #if defined(QCN7605_SUPPORT) && defined(ADRASTEA_RRI_ON_DDR)
  2796. static void hif_update_rri_over_ddr_config(struct hif_softc *scn,
  2797. struct pld_wlan_enable_cfg *cfg)
  2798. {
  2799. if (hif_alloc_rri_on_ddr(scn) != QDF_STATUS_SUCCESS)
  2800. return;
  2801. cfg->rri_over_ddr_cfg_valid = true;
  2802. cfg->rri_over_ddr_cfg.base_addr_low =
  2803. BITS0_TO_31(scn->paddr_rri_on_ddr);
  2804. cfg->rri_over_ddr_cfg.base_addr_high =
  2805. BITS32_TO_35(scn->paddr_rri_on_ddr);
  2806. }
  2807. #else
  2808. static void hif_update_rri_over_ddr_config(struct hif_softc *scn,
  2809. struct pld_wlan_enable_cfg *cfg)
  2810. {
  2811. }
  2812. #endif
  2813. /**
  2814. * hif_wlan_enable(): call the platform driver to enable wlan
  2815. * @scn: HIF Context
  2816. *
  2817. * This function passes the con_mode and CE configuration to
  2818. * platform driver to enable wlan.
  2819. *
  2820. * Return: linux error code
  2821. */
  2822. int hif_wlan_enable(struct hif_softc *scn)
  2823. {
  2824. struct pld_wlan_enable_cfg cfg;
  2825. enum pld_driver_mode mode;
  2826. uint32_t con_mode = hif_get_conparam(scn);
  2827. hif_get_target_ce_config(scn,
  2828. (struct CE_pipe_config **)&cfg.ce_tgt_cfg,
  2829. &cfg.num_ce_tgt_cfg,
  2830. (struct service_to_pipe **)&cfg.ce_svc_cfg,
  2831. &cfg.num_ce_svc_pipe_cfg,
  2832. (struct shadow_reg_cfg **)&cfg.shadow_reg_cfg,
  2833. &cfg.num_shadow_reg_cfg);
  2834. /* translate from structure size to array size */
  2835. cfg.num_ce_tgt_cfg /= sizeof(struct CE_pipe_config);
  2836. cfg.num_ce_svc_pipe_cfg /= sizeof(struct service_to_pipe);
  2837. cfg.num_shadow_reg_cfg /= sizeof(struct shadow_reg_cfg);
  2838. hif_prepare_hal_shadow_register_cfg(scn, &cfg.shadow_reg_v2_cfg,
  2839. &cfg.num_shadow_reg_v2_cfg);
  2840. hif_print_hal_shadow_register_cfg(&cfg);
  2841. hif_update_rri_over_ddr_config(scn, &cfg);
  2842. if (QDF_GLOBAL_FTM_MODE == con_mode)
  2843. mode = PLD_FTM;
  2844. else if (QDF_GLOBAL_COLDBOOT_CALIB_MODE == con_mode)
  2845. mode = PLD_COLDBOOT_CALIBRATION;
  2846. else if (QDF_GLOBAL_FTM_COLDBOOT_CALIB_MODE == con_mode)
  2847. mode = PLD_FTM_COLDBOOT_CALIBRATION;
  2848. else if (QDF_IS_EPPING_ENABLED(con_mode))
  2849. mode = PLD_EPPING;
  2850. else
  2851. mode = PLD_MISSION;
  2852. if (BYPASS_QMI)
  2853. return 0;
  2854. else
  2855. return pld_wlan_enable(scn->qdf_dev->dev, &cfg, mode);
  2856. }
  2857. #ifdef WLAN_FEATURE_EPPING
  2858. #define CE_EPPING_USES_IRQ true
  2859. void hif_ce_prepare_epping_config(struct HIF_CE_state *hif_state)
  2860. {
  2861. if (CE_EPPING_USES_IRQ)
  2862. hif_state->host_ce_config = host_ce_config_wlan_epping_irq;
  2863. else
  2864. hif_state->host_ce_config = host_ce_config_wlan_epping_poll;
  2865. hif_state->target_ce_config = target_ce_config_wlan_epping;
  2866. hif_state->target_ce_config_sz = sizeof(target_ce_config_wlan_epping);
  2867. target_shadow_reg_cfg = target_shadow_reg_cfg_epping;
  2868. shadow_cfg_sz = sizeof(target_shadow_reg_cfg_epping);
  2869. }
  2870. #endif
  2871. #ifdef QCN7605_SUPPORT
  2872. static inline
  2873. void hif_set_ce_config_qcn7605(struct hif_softc *scn,
  2874. struct HIF_CE_state *hif_state)
  2875. {
  2876. hif_state->host_ce_config = host_ce_config_wlan_qcn7605;
  2877. hif_state->target_ce_config = target_ce_config_wlan_qcn7605;
  2878. hif_state->target_ce_config_sz =
  2879. sizeof(target_ce_config_wlan_qcn7605);
  2880. target_shadow_reg_cfg = target_shadow_reg_cfg_map_qcn7605;
  2881. shadow_cfg_sz = sizeof(target_shadow_reg_cfg_map_qcn7605);
  2882. scn->ce_count = QCN7605_CE_COUNT;
  2883. }
  2884. #else
  2885. static inline
  2886. void hif_set_ce_config_qcn7605(struct hif_softc *scn,
  2887. struct HIF_CE_state *hif_state)
  2888. {
  2889. hif_err("QCN7605 not supported");
  2890. }
  2891. #endif
  2892. #ifdef CE_SVC_CMN_INIT
  2893. #ifdef QCA_WIFI_SUPPORT_SRNG
  2894. static inline void hif_ce_service_init(void)
  2895. {
  2896. ce_service_srng_init();
  2897. }
  2898. #else
  2899. static inline void hif_ce_service_init(void)
  2900. {
  2901. ce_service_legacy_init();
  2902. }
  2903. #endif
  2904. #else
  2905. static inline void hif_ce_service_init(void)
  2906. {
  2907. }
  2908. #endif
  2909. /**
  2910. * hif_ce_prepare_config() - load the correct static tables.
  2911. * @scn: hif context
  2912. *
  2913. * Epping uses different static attribute tables than mission mode.
  2914. */
  2915. void hif_ce_prepare_config(struct hif_softc *scn)
  2916. {
  2917. uint32_t mode = hif_get_conparam(scn);
  2918. struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
  2919. struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl);
  2920. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  2921. hif_ce_service_init();
  2922. hif_state->ce_services = ce_services_attach(scn);
  2923. scn->ce_count = HOST_CE_COUNT;
  2924. /* if epping is enabled we need to use the epping configuration. */
  2925. if (QDF_IS_EPPING_ENABLED(mode)) {
  2926. hif_ce_prepare_epping_config(hif_state);
  2927. return;
  2928. }
  2929. switch (tgt_info->target_type) {
  2930. default:
  2931. hif_state->host_ce_config = host_ce_config_wlan;
  2932. hif_state->target_ce_config = target_ce_config_wlan;
  2933. hif_state->target_ce_config_sz = sizeof(target_ce_config_wlan);
  2934. break;
  2935. case TARGET_TYPE_QCN7605:
  2936. hif_set_ce_config_qcn7605(scn, hif_state);
  2937. break;
  2938. case TARGET_TYPE_AR900B:
  2939. case TARGET_TYPE_QCA9984:
  2940. case TARGET_TYPE_IPQ4019:
  2941. case TARGET_TYPE_QCA9888:
  2942. if (hif_is_attribute_set(scn, HIF_LOWDESC_CE_NO_PKTLOG_CFG)) {
  2943. hif_state->host_ce_config =
  2944. host_lowdesc_ce_cfg_wlan_ar900b_nopktlog;
  2945. } else if (hif_is_attribute_set(scn, HIF_LOWDESC_CE_CFG)) {
  2946. hif_state->host_ce_config =
  2947. host_lowdesc_ce_cfg_wlan_ar900b;
  2948. } else {
  2949. hif_state->host_ce_config = host_ce_config_wlan_ar900b;
  2950. }
  2951. hif_state->target_ce_config = target_ce_config_wlan_ar900b;
  2952. hif_state->target_ce_config_sz =
  2953. sizeof(target_ce_config_wlan_ar900b);
  2954. break;
  2955. case TARGET_TYPE_AR9888:
  2956. case TARGET_TYPE_AR9888V2:
  2957. if (hif_is_attribute_set(scn, HIF_LOWDESC_CE_CFG)) {
  2958. hif_state->host_ce_config = host_lowdesc_ce_cfg_wlan_ar9888;
  2959. } else {
  2960. hif_state->host_ce_config = host_ce_config_wlan_ar9888;
  2961. }
  2962. hif_state->target_ce_config = target_ce_config_wlan_ar9888;
  2963. hif_state->target_ce_config_sz =
  2964. sizeof(target_ce_config_wlan_ar9888);
  2965. break;
  2966. case TARGET_TYPE_QCA8074:
  2967. case TARGET_TYPE_QCA8074V2:
  2968. case TARGET_TYPE_QCA6018:
  2969. if (scn->bus_type == QDF_BUS_TYPE_PCI) {
  2970. hif_state->host_ce_config =
  2971. host_ce_config_wlan_qca8074_pci;
  2972. hif_state->target_ce_config =
  2973. target_ce_config_wlan_qca8074_pci;
  2974. hif_state->target_ce_config_sz =
  2975. sizeof(target_ce_config_wlan_qca8074_pci);
  2976. } else {
  2977. hif_state->host_ce_config = host_ce_config_wlan_qca8074;
  2978. hif_state->target_ce_config =
  2979. target_ce_config_wlan_qca8074;
  2980. hif_state->target_ce_config_sz =
  2981. sizeof(target_ce_config_wlan_qca8074);
  2982. }
  2983. break;
  2984. case TARGET_TYPE_QCA6290:
  2985. hif_state->host_ce_config = host_ce_config_wlan_qca6290;
  2986. hif_state->target_ce_config = target_ce_config_wlan_qca6290;
  2987. hif_state->target_ce_config_sz =
  2988. sizeof(target_ce_config_wlan_qca6290);
  2989. scn->ce_count = QCA_6290_CE_COUNT;
  2990. break;
  2991. case TARGET_TYPE_QCN9000:
  2992. hif_state->host_ce_config = host_ce_config_wlan_qcn9000;
  2993. hif_state->target_ce_config = target_ce_config_wlan_qcn9000;
  2994. hif_state->target_ce_config_sz =
  2995. sizeof(target_ce_config_wlan_qcn9000);
  2996. scn->ce_count = QCN_9000_CE_COUNT;
  2997. scn->disable_wake_irq = 1;
  2998. break;
  2999. case TARGET_TYPE_QCN6122:
  3000. hif_state->host_ce_config = host_ce_config_wlan_qcn6122;
  3001. hif_state->target_ce_config = target_ce_config_wlan_qcn6122;
  3002. hif_state->target_ce_config_sz =
  3003. sizeof(target_ce_config_wlan_qcn6122);
  3004. scn->ce_count = QCN_6122_CE_COUNT;
  3005. scn->disable_wake_irq = 1;
  3006. break;
  3007. case TARGET_TYPE_QCA5018:
  3008. hif_state->host_ce_config = host_ce_config_wlan_qca5018;
  3009. hif_state->target_ce_config = target_ce_config_wlan_qca5018;
  3010. hif_state->target_ce_config_sz =
  3011. sizeof(target_ce_config_wlan_qca5018);
  3012. scn->ce_count = QCA_5018_CE_COUNT;
  3013. break;
  3014. case TARGET_TYPE_QCA6390:
  3015. hif_state->host_ce_config = host_ce_config_wlan_qca6390;
  3016. hif_state->target_ce_config = target_ce_config_wlan_qca6390;
  3017. hif_state->target_ce_config_sz =
  3018. sizeof(target_ce_config_wlan_qca6390);
  3019. scn->ce_count = QCA_6390_CE_COUNT;
  3020. break;
  3021. case TARGET_TYPE_QCA6490:
  3022. hif_state->host_ce_config = host_ce_config_wlan_qca6490;
  3023. hif_state->target_ce_config = target_ce_config_wlan_qca6490;
  3024. hif_state->target_ce_config_sz =
  3025. sizeof(target_ce_config_wlan_qca6490);
  3026. scn->ce_count = QCA_6490_CE_COUNT;
  3027. break;
  3028. case TARGET_TYPE_QCA6750:
  3029. hif_state->host_ce_config = host_ce_config_wlan_qca6750;
  3030. hif_state->target_ce_config = target_ce_config_wlan_qca6750;
  3031. hif_state->target_ce_config_sz =
  3032. sizeof(target_ce_config_wlan_qca6750);
  3033. scn->ce_count = QCA_6750_CE_COUNT;
  3034. break;
  3035. case TARGET_TYPE_ADRASTEA:
  3036. if (hif_is_attribute_set(scn, HIF_LOWDESC_CE_NO_PKTLOG_CFG)) {
  3037. hif_state->host_ce_config =
  3038. host_lowdesc_ce_config_wlan_adrastea_nopktlog;
  3039. hif_state->target_ce_config =
  3040. target_lowdesc_ce_config_wlan_adrastea_nopktlog;
  3041. hif_state->target_ce_config_sz =
  3042. sizeof(target_lowdesc_ce_config_wlan_adrastea_nopktlog);
  3043. } else {
  3044. hif_state->host_ce_config =
  3045. host_ce_config_wlan_adrastea;
  3046. hif_state->target_ce_config =
  3047. target_ce_config_wlan_adrastea;
  3048. hif_state->target_ce_config_sz =
  3049. sizeof(target_ce_config_wlan_adrastea);
  3050. }
  3051. break;
  3052. }
  3053. QDF_BUG(scn->ce_count <= CE_COUNT_MAX);
  3054. }
  3055. /**
  3056. * hif_ce_open() - do ce specific allocations
  3057. * @hif_sc: pointer to hif context
  3058. *
  3059. * return: 0 for success or QDF_STATUS_E_NOMEM
  3060. */
  3061. QDF_STATUS hif_ce_open(struct hif_softc *hif_sc)
  3062. {
  3063. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc);
  3064. qdf_spinlock_create(&hif_state->irq_reg_lock);
  3065. qdf_spinlock_create(&hif_state->keep_awake_lock);
  3066. return QDF_STATUS_SUCCESS;
  3067. }
  3068. /**
  3069. * hif_ce_close() - do ce specific free
  3070. * @hif_sc: pointer to hif context
  3071. */
  3072. void hif_ce_close(struct hif_softc *hif_sc)
  3073. {
  3074. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc);
  3075. qdf_spinlock_destroy(&hif_state->irq_reg_lock);
  3076. qdf_spinlock_destroy(&hif_state->keep_awake_lock);
  3077. }
  3078. /**
  3079. * hif_unconfig_ce() - ensure resources from hif_config_ce are freed
  3080. * @hif_sc: hif context
  3081. *
  3082. * uses state variables to support cleaning up when hif_config_ce fails.
  3083. */
  3084. void hif_unconfig_ce(struct hif_softc *hif_sc)
  3085. {
  3086. int pipe_num;
  3087. struct HIF_CE_pipe_info *pipe_info;
  3088. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc);
  3089. struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(hif_sc);
  3090. for (pipe_num = 0; pipe_num < hif_sc->ce_count; pipe_num++) {
  3091. pipe_info = &hif_state->pipe_info[pipe_num];
  3092. if (pipe_info->ce_hdl) {
  3093. ce_unregister_irq(hif_state, (1 << pipe_num));
  3094. }
  3095. }
  3096. deinit_tasklet_workers(hif_hdl);
  3097. for (pipe_num = 0; pipe_num < hif_sc->ce_count; pipe_num++) {
  3098. pipe_info = &hif_state->pipe_info[pipe_num];
  3099. if (pipe_info->ce_hdl) {
  3100. ce_fini(pipe_info->ce_hdl);
  3101. pipe_info->ce_hdl = NULL;
  3102. pipe_info->buf_sz = 0;
  3103. qdf_spinlock_destroy(&pipe_info->recv_bufs_needed_lock);
  3104. }
  3105. }
  3106. if (hif_sc->athdiag_procfs_inited) {
  3107. athdiag_procfs_remove();
  3108. hif_sc->athdiag_procfs_inited = false;
  3109. }
  3110. }
  3111. #ifdef CONFIG_BYPASS_QMI
  3112. #ifdef QCN7605_SUPPORT
  3113. /**
  3114. * hif_post_static_buf_to_target() - post static buffer to WLAN FW
  3115. * @scn: pointer to HIF structure
  3116. *
  3117. * WLAN FW needs 2MB memory from DDR when QMI is disabled.
  3118. *
  3119. * Return: void
  3120. */
  3121. static void hif_post_static_buf_to_target(struct hif_softc *scn)
  3122. {
  3123. phys_addr_t target_pa;
  3124. struct ce_info *ce_info_ptr;
  3125. uint32_t msi_data_start;
  3126. uint32_t msi_data_count;
  3127. uint32_t msi_irq_start;
  3128. uint32_t i = 0;
  3129. int ret;
  3130. scn->vaddr_qmi_bypass =
  3131. (uint32_t *)qdf_mem_alloc_consistent(scn->qdf_dev,
  3132. scn->qdf_dev->dev,
  3133. FW_SHARED_MEM,
  3134. &target_pa);
  3135. if (!scn->vaddr_qmi_bypass) {
  3136. hif_err("Memory allocation failed could not post target buf");
  3137. return;
  3138. }
  3139. scn->paddr_qmi_bypass = target_pa;
  3140. ce_info_ptr = (struct ce_info *)scn->vaddr_qmi_bypass;
  3141. if (scn->vaddr_rri_on_ddr) {
  3142. ce_info_ptr->rri_over_ddr_low_paddr =
  3143. BITS0_TO_31(scn->paddr_rri_on_ddr);
  3144. ce_info_ptr->rri_over_ddr_high_paddr =
  3145. BITS32_TO_35(scn->paddr_rri_on_ddr);
  3146. }
  3147. ret = pld_get_user_msi_assignment(scn->qdf_dev->dev, "CE",
  3148. &msi_data_count, &msi_data_start,
  3149. &msi_irq_start);
  3150. if (ret) {
  3151. hif_err("Failed to get CE msi config");
  3152. return;
  3153. }
  3154. for (i = 0; i < CE_COUNT_MAX; i++) {
  3155. ce_info_ptr->cfg[i].ce_id = i;
  3156. ce_info_ptr->cfg[i].msi_vector =
  3157. (i % msi_data_count) + msi_irq_start;
  3158. }
  3159. hif_write32_mb(scn, scn->mem + BYPASS_QMI_TEMP_REGISTER, target_pa);
  3160. hif_info("target va %pK target pa %pa", scn->vaddr_qmi_bypass,
  3161. &target_pa);
  3162. }
  3163. /**
  3164. * hif_cleanup_static_buf_to_target() - clean up static buffer to WLAN FW
  3165. * @scn: pointer to HIF structure
  3166. *
  3167. *
  3168. * Return: void
  3169. */
  3170. void hif_cleanup_static_buf_to_target(struct hif_softc *scn)
  3171. {
  3172. void *target_va = scn->vaddr_qmi_bypass;
  3173. phys_addr_t target_pa = scn->paddr_qmi_bypass;
  3174. qdf_mem_free_consistent(scn->qdf_dev, scn->qdf_dev->dev,
  3175. FW_SHARED_MEM, target_va,
  3176. target_pa, 0);
  3177. hif_write32_mb(scn, scn->mem + BYPASS_QMI_TEMP_REGISTER, 0);
  3178. }
  3179. #else
  3180. /**
  3181. * hif_post_static_buf_to_target() - post static buffer to WLAN FW
  3182. * @scn: pointer to HIF structure
  3183. *
  3184. * WLAN FW needs 2MB memory from DDR when QMI is disabled.
  3185. *
  3186. * Return: void
  3187. */
  3188. static void hif_post_static_buf_to_target(struct hif_softc *scn)
  3189. {
  3190. qdf_dma_addr_t target_pa;
  3191. scn->vaddr_qmi_bypass =
  3192. (uint32_t *)qdf_mem_alloc_consistent(scn->qdf_dev,
  3193. scn->qdf_dev->dev,
  3194. FW_SHARED_MEM,
  3195. &target_pa);
  3196. if (!scn->vaddr_qmi_bypass) {
  3197. hif_err("Memory allocation failed could not post target buf");
  3198. return;
  3199. }
  3200. scn->paddr_qmi_bypass = target_pa;
  3201. hif_write32_mb(scn, scn->mem + BYPASS_QMI_TEMP_REGISTER, target_pa);
  3202. }
  3203. /**
  3204. * hif_cleanup_static_buf_to_target() - clean up static buffer to WLAN FW
  3205. * @scn: pointer to HIF structure
  3206. *
  3207. *
  3208. * Return: void
  3209. */
  3210. void hif_cleanup_static_buf_to_target(struct hif_softc *scn)
  3211. {
  3212. void *target_va = scn->vaddr_qmi_bypass;
  3213. phys_addr_t target_pa = scn->paddr_qmi_bypass;
  3214. qdf_mem_free_consistent(scn->qdf_dev, scn->qdf_dev->dev,
  3215. FW_SHARED_MEM, target_va,
  3216. target_pa, 0);
  3217. hif_write32_mb(snc, scn->mem + BYPASS_QMI_TEMP_REGISTER, 0);
  3218. }
  3219. #endif
  3220. #else
  3221. static inline void hif_post_static_buf_to_target(struct hif_softc *scn)
  3222. {
  3223. }
  3224. void hif_cleanup_static_buf_to_target(struct hif_softc *scn)
  3225. {
  3226. }
  3227. #endif
  3228. static int hif_srng_sleep_state_adjust(struct hif_softc *scn, bool sleep_ok,
  3229. bool wait_for_it)
  3230. {
  3231. /* todo */
  3232. return 0;
  3233. }
  3234. int hif_config_ce_by_id(struct hif_softc *scn, int pipe_num)
  3235. {
  3236. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  3237. struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
  3238. struct HIF_CE_pipe_info *pipe_info;
  3239. struct CE_state *ce_state = NULL;
  3240. struct CE_attr *attr;
  3241. int rv = 0;
  3242. if (pipe_num >= CE_COUNT_MAX)
  3243. return -EINVAL;
  3244. pipe_info = &hif_state->pipe_info[pipe_num];
  3245. pipe_info->pipe_num = pipe_num;
  3246. pipe_info->HIF_CE_state = hif_state;
  3247. attr = &hif_state->host_ce_config[pipe_num];
  3248. ce_state = scn->ce_id_to_state[pipe_num];
  3249. if (ce_state) {
  3250. /* Do not reinitialize the CE if its done already */
  3251. rv = QDF_STATUS_E_BUSY;
  3252. goto err;
  3253. }
  3254. pipe_info->ce_hdl = ce_init(scn, pipe_num, attr);
  3255. ce_state = scn->ce_id_to_state[pipe_num];
  3256. if (!ce_state) {
  3257. A_TARGET_ACCESS_UNLIKELY(scn);
  3258. rv = QDF_STATUS_E_FAILURE;
  3259. goto err;
  3260. }
  3261. qdf_spinlock_create(&pipe_info->recv_bufs_needed_lock);
  3262. QDF_ASSERT(pipe_info->ce_hdl);
  3263. if (!pipe_info->ce_hdl) {
  3264. rv = QDF_STATUS_E_FAILURE;
  3265. A_TARGET_ACCESS_UNLIKELY(scn);
  3266. goto err;
  3267. }
  3268. ce_state->lro_data = qdf_lro_init();
  3269. if (attr->flags & CE_ATTR_DIAG) {
  3270. /* Reserve the ultimate CE for
  3271. * Diagnostic Window support
  3272. */
  3273. hif_state->ce_diag = pipe_info->ce_hdl;
  3274. goto skip;
  3275. }
  3276. if (hif_is_nss_wifi_enabled(scn) && ce_state &&
  3277. (ce_state->htt_rx_data)) {
  3278. goto skip;
  3279. }
  3280. pipe_info->buf_sz = (qdf_size_t)(attr->src_sz_max);
  3281. if (attr->dest_nentries > 0) {
  3282. atomic_set(&pipe_info->recv_bufs_needed,
  3283. init_buffer_count(attr->dest_nentries - 1));
  3284. /*SRNG based CE has one entry less */
  3285. if (ce_srng_based(scn))
  3286. atomic_dec(&pipe_info->recv_bufs_needed);
  3287. } else {
  3288. atomic_set(&pipe_info->recv_bufs_needed, 0);
  3289. }
  3290. ce_tasklet_init(hif_state, (1 << pipe_num));
  3291. ce_register_irq(hif_state, (1 << pipe_num));
  3292. init_tasklet_worker_by_ceid(hif_hdl, pipe_num);
  3293. skip:
  3294. return 0;
  3295. err:
  3296. return rv;
  3297. }
  3298. /**
  3299. * hif_config_ce() - configure copy engines
  3300. * @scn: hif context
  3301. *
  3302. * Prepares fw, copy engine hardware and host sw according
  3303. * to the attributes selected by hif_ce_prepare_config.
  3304. *
  3305. * also calls athdiag_procfs_init
  3306. *
  3307. * return: 0 for success nonzero for failure.
  3308. */
  3309. int hif_config_ce(struct hif_softc *scn)
  3310. {
  3311. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  3312. struct HIF_CE_pipe_info *pipe_info;
  3313. int pipe_num;
  3314. #ifdef ADRASTEA_SHADOW_REGISTERS
  3315. int i;
  3316. #endif
  3317. QDF_STATUS rv = QDF_STATUS_SUCCESS;
  3318. scn->notice_send = true;
  3319. scn->ce_service_max_rx_ind_flush = MSG_FLUSH_NUM;
  3320. hif_post_static_buf_to_target(scn);
  3321. hif_state->fw_indicator_address = FW_INDICATOR_ADDRESS;
  3322. hif_config_rri_on_ddr(scn);
  3323. if (ce_srng_based(scn))
  3324. scn->bus_ops.hif_target_sleep_state_adjust =
  3325. &hif_srng_sleep_state_adjust;
  3326. /* Initialise the CE debug history sysfs interface inputs ce_id and
  3327. * index. Disable data storing
  3328. */
  3329. reset_ce_debug_history(scn);
  3330. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  3331. struct CE_attr *attr;
  3332. pipe_info = &hif_state->pipe_info[pipe_num];
  3333. attr = &hif_state->host_ce_config[pipe_num];
  3334. if (attr->flags & CE_ATTR_INIT_ON_DEMAND)
  3335. continue;
  3336. if (hif_config_ce_by_id(scn, pipe_num))
  3337. goto err;
  3338. }
  3339. if (athdiag_procfs_init(scn) != 0) {
  3340. A_TARGET_ACCESS_UNLIKELY(scn);
  3341. goto err;
  3342. }
  3343. scn->athdiag_procfs_inited = true;
  3344. hif_debug("ce_init done");
  3345. hif_debug("%s: X, ret = %d", __func__, rv);
  3346. #ifdef ADRASTEA_SHADOW_REGISTERS
  3347. hif_debug("Using Shadow Registers instead of CE Registers");
  3348. for (i = 0; i < NUM_SHADOW_REGISTERS; i++) {
  3349. hif_debug("Shadow Register%d is mapped to address %x",
  3350. i,
  3351. (A_TARGET_READ(scn, (SHADOW_ADDRESS(i))) << 2));
  3352. }
  3353. #endif
  3354. return rv != QDF_STATUS_SUCCESS;
  3355. err:
  3356. /* Failure, so clean up */
  3357. hif_unconfig_ce(scn);
  3358. hif_info("X, ret = %d", rv);
  3359. return QDF_STATUS_SUCCESS != QDF_STATUS_E_FAILURE;
  3360. }
  3361. /**
  3362. * hif_config_ce_pktlog() - configure copy engines
  3363. * @scn: hif context
  3364. *
  3365. * Prepares fw, copy engine hardware and host sw according
  3366. * to the attributes selected by hif_ce_prepare_config.
  3367. *
  3368. * also calls athdiag_procfs_init
  3369. *
  3370. * return: 0 for success nonzero for failure.
  3371. */
  3372. int hif_config_ce_pktlog(struct hif_opaque_softc *hif_hdl)
  3373. {
  3374. struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
  3375. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  3376. int pipe_num;
  3377. QDF_STATUS qdf_status = QDF_STATUS_E_FAILURE;
  3378. struct HIF_CE_pipe_info *pipe_info;
  3379. if (!scn)
  3380. goto err;
  3381. if (scn->pktlog_init)
  3382. return QDF_STATUS_SUCCESS;
  3383. pipe_num = hif_get_pktlog_ce_num(scn);
  3384. if (pipe_num < 0) {
  3385. qdf_status = QDF_STATUS_E_FAILURE;
  3386. goto err;
  3387. }
  3388. pipe_info = &hif_state->pipe_info[pipe_num];
  3389. qdf_status = hif_config_ce_by_id(scn, pipe_num);
  3390. /* CE Already initialized. Do not try to reinitialized again */
  3391. if (qdf_status == QDF_STATUS_E_BUSY)
  3392. return QDF_STATUS_SUCCESS;
  3393. qdf_status = hif_config_irq_by_ceid(scn, pipe_num);
  3394. if (qdf_status < 0)
  3395. goto err;
  3396. qdf_status = hif_completion_thread_startup_by_ceid(hif_state, pipe_num);
  3397. if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
  3398. hif_err("%s:failed to start hif thread", __func__);
  3399. goto err;
  3400. }
  3401. /* Post buffers for pktlog copy engine. */
  3402. qdf_status = hif_post_recv_buffers_for_pipe(pipe_info);
  3403. if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
  3404. /* cleanup is done in hif_ce_disable */
  3405. hif_err("%s:failed to post buffers", __func__);
  3406. return qdf_status;
  3407. }
  3408. scn->pktlog_init = true;
  3409. return qdf_status != QDF_STATUS_SUCCESS;
  3410. err:
  3411. hif_debug("%s: X, ret = %d", __func__, qdf_status);
  3412. return QDF_STATUS_SUCCESS != QDF_STATUS_E_FAILURE;
  3413. }
  3414. #ifdef IPA_OFFLOAD
  3415. /**
  3416. * hif_ce_ipa_get_ce_resource() - get uc resource on hif
  3417. * @scn: bus context
  3418. * @ce_sr_base_paddr: copyengine source ring base physical address
  3419. * @ce_sr_ring_size: copyengine source ring size
  3420. * @ce_reg_paddr: copyengine register physical address
  3421. *
  3422. * IPA micro controller data path offload feature enabled,
  3423. * HIF should release copy engine related resource information to IPA UC
  3424. * IPA UC will access hardware resource with released information
  3425. *
  3426. * Return: None
  3427. */
  3428. void hif_ce_ipa_get_ce_resource(struct hif_softc *scn,
  3429. qdf_shared_mem_t **ce_sr,
  3430. uint32_t *ce_sr_ring_size,
  3431. qdf_dma_addr_t *ce_reg_paddr)
  3432. {
  3433. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  3434. struct HIF_CE_pipe_info *pipe_info =
  3435. &(hif_state->pipe_info[HIF_PCI_IPA_UC_ASSIGNED_CE]);
  3436. struct CE_handle *ce_hdl = pipe_info->ce_hdl;
  3437. ce_ipa_get_resource(ce_hdl, ce_sr, ce_sr_ring_size,
  3438. ce_reg_paddr);
  3439. }
  3440. #endif /* IPA_OFFLOAD */
  3441. #ifdef ADRASTEA_SHADOW_REGISTERS
  3442. /*
  3443. * Current shadow register config
  3444. *
  3445. * -----------------------------------------------------------
  3446. * Shadow Register | CE | src/dst write index
  3447. * -----------------------------------------------------------
  3448. * 0 | 0 | src
  3449. * 1 No Config - Doesn't point to anything
  3450. * 2 No Config - Doesn't point to anything
  3451. * 3 | 3 | src
  3452. * 4 | 4 | src
  3453. * 5 | 5 | src
  3454. * 6 No Config - Doesn't point to anything
  3455. * 7 | 7 | src
  3456. * 8 No Config - Doesn't point to anything
  3457. * 9 No Config - Doesn't point to anything
  3458. * 10 No Config - Doesn't point to anything
  3459. * 11 No Config - Doesn't point to anything
  3460. * -----------------------------------------------------------
  3461. * 12 No Config - Doesn't point to anything
  3462. * 13 | 1 | dst
  3463. * 14 | 2 | dst
  3464. * 15 No Config - Doesn't point to anything
  3465. * 16 No Config - Doesn't point to anything
  3466. * 17 No Config - Doesn't point to anything
  3467. * 18 No Config - Doesn't point to anything
  3468. * 19 | 7 | dst
  3469. * 20 | 8 | dst
  3470. * 21 No Config - Doesn't point to anything
  3471. * 22 No Config - Doesn't point to anything
  3472. * 23 No Config - Doesn't point to anything
  3473. * -----------------------------------------------------------
  3474. *
  3475. *
  3476. * ToDo - Move shadow register config to following in the future
  3477. * This helps free up a block of shadow registers towards the end.
  3478. * Can be used for other purposes
  3479. *
  3480. * -----------------------------------------------------------
  3481. * Shadow Register | CE | src/dst write index
  3482. * -----------------------------------------------------------
  3483. * 0 | 0 | src
  3484. * 1 | 3 | src
  3485. * 2 | 4 | src
  3486. * 3 | 5 | src
  3487. * 4 | 7 | src
  3488. * -----------------------------------------------------------
  3489. * 5 | 1 | dst
  3490. * 6 | 2 | dst
  3491. * 7 | 7 | dst
  3492. * 8 | 8 | dst
  3493. * -----------------------------------------------------------
  3494. * 9 No Config - Doesn't point to anything
  3495. * 12 No Config - Doesn't point to anything
  3496. * 13 No Config - Doesn't point to anything
  3497. * 14 No Config - Doesn't point to anything
  3498. * 15 No Config - Doesn't point to anything
  3499. * 16 No Config - Doesn't point to anything
  3500. * 17 No Config - Doesn't point to anything
  3501. * 18 No Config - Doesn't point to anything
  3502. * 19 No Config - Doesn't point to anything
  3503. * 20 No Config - Doesn't point to anything
  3504. * 21 No Config - Doesn't point to anything
  3505. * 22 No Config - Doesn't point to anything
  3506. * 23 No Config - Doesn't point to anything
  3507. * -----------------------------------------------------------
  3508. */
  3509. #ifndef QCN7605_SUPPORT
  3510. u32 shadow_sr_wr_ind_addr(struct hif_softc *scn, u32 ctrl_addr)
  3511. {
  3512. u32 addr = 0;
  3513. u32 ce = COPY_ENGINE_ID(ctrl_addr);
  3514. switch (ce) {
  3515. case 0:
  3516. addr = SHADOW_VALUE0;
  3517. break;
  3518. case 3:
  3519. addr = SHADOW_VALUE3;
  3520. break;
  3521. case 4:
  3522. addr = SHADOW_VALUE4;
  3523. break;
  3524. case 5:
  3525. addr = SHADOW_VALUE5;
  3526. break;
  3527. case 7:
  3528. addr = SHADOW_VALUE7;
  3529. break;
  3530. default:
  3531. hif_err("Invalid CE ctrl_addr (CE=%d)", ce);
  3532. QDF_ASSERT(0);
  3533. }
  3534. return addr;
  3535. }
  3536. u32 shadow_dst_wr_ind_addr(struct hif_softc *scn, u32 ctrl_addr)
  3537. {
  3538. u32 addr = 0;
  3539. u32 ce = COPY_ENGINE_ID(ctrl_addr);
  3540. switch (ce) {
  3541. case 1:
  3542. addr = SHADOW_VALUE13;
  3543. break;
  3544. case 2:
  3545. addr = SHADOW_VALUE14;
  3546. break;
  3547. case 5:
  3548. addr = SHADOW_VALUE17;
  3549. break;
  3550. case 7:
  3551. addr = SHADOW_VALUE19;
  3552. break;
  3553. case 8:
  3554. addr = SHADOW_VALUE20;
  3555. break;
  3556. case 9:
  3557. addr = SHADOW_VALUE21;
  3558. break;
  3559. case 10:
  3560. addr = SHADOW_VALUE22;
  3561. break;
  3562. case 11:
  3563. addr = SHADOW_VALUE23;
  3564. break;
  3565. default:
  3566. hif_err("Invalid CE ctrl_addr (CE=%d)", ce);
  3567. QDF_ASSERT(0);
  3568. }
  3569. return addr;
  3570. }
  3571. #else
  3572. u32 shadow_sr_wr_ind_addr(struct hif_softc *scn, u32 ctrl_addr)
  3573. {
  3574. u32 addr = 0;
  3575. u32 ce = COPY_ENGINE_ID(ctrl_addr);
  3576. switch (ce) {
  3577. case 0:
  3578. addr = SHADOW_VALUE0;
  3579. break;
  3580. case 4:
  3581. addr = SHADOW_VALUE4;
  3582. break;
  3583. case 5:
  3584. addr = SHADOW_VALUE5;
  3585. break;
  3586. default:
  3587. hif_err("Invalid CE ctrl_addr (CE=%d)", ce);
  3588. QDF_ASSERT(0);
  3589. }
  3590. return addr;
  3591. }
  3592. u32 shadow_dst_wr_ind_addr(struct hif_softc *scn, u32 ctrl_addr)
  3593. {
  3594. u32 addr = 0;
  3595. u32 ce = COPY_ENGINE_ID(ctrl_addr);
  3596. switch (ce) {
  3597. case 1:
  3598. addr = SHADOW_VALUE13;
  3599. break;
  3600. case 2:
  3601. addr = SHADOW_VALUE14;
  3602. break;
  3603. case 3:
  3604. addr = SHADOW_VALUE15;
  3605. break;
  3606. case 5:
  3607. addr = SHADOW_VALUE17;
  3608. break;
  3609. case 7:
  3610. addr = SHADOW_VALUE19;
  3611. break;
  3612. case 8:
  3613. addr = SHADOW_VALUE20;
  3614. break;
  3615. case 9:
  3616. addr = SHADOW_VALUE21;
  3617. break;
  3618. case 10:
  3619. addr = SHADOW_VALUE22;
  3620. break;
  3621. case 11:
  3622. addr = SHADOW_VALUE23;
  3623. break;
  3624. default:
  3625. hif_err("Invalid CE ctrl_addr (CE=%d)", ce);
  3626. QDF_ASSERT(0);
  3627. }
  3628. return addr;
  3629. }
  3630. #endif
  3631. #endif
  3632. #if defined(FEATURE_LRO)
  3633. void *hif_ce_get_lro_ctx(struct hif_opaque_softc *hif_hdl, int ctx_id)
  3634. {
  3635. struct CE_state *ce_state;
  3636. struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
  3637. ce_state = scn->ce_id_to_state[ctx_id];
  3638. return ce_state->lro_data;
  3639. }
  3640. #endif
  3641. /**
  3642. * hif_map_service_to_pipe() - returns the ce ids pertaining to
  3643. * this service
  3644. * @scn: hif_softc pointer.
  3645. * @svc_id: Service ID for which the mapping is needed.
  3646. * @ul_pipe: address of the container in which ul pipe is returned.
  3647. * @dl_pipe: address of the container in which dl pipe is returned.
  3648. * @ul_is_polled: address of the container in which a bool
  3649. * indicating if the UL CE for this service
  3650. * is polled is returned.
  3651. * @dl_is_polled: address of the container in which a bool
  3652. * indicating if the DL CE for this service
  3653. * is polled is returned.
  3654. *
  3655. * Return: Indicates whether the service has been found in the table.
  3656. * Upon return, ul_is_polled is updated only if ul_pipe is updated.
  3657. * There will be warning logs if either leg has not been updated
  3658. * because it missed the entry in the table (but this is not an err).
  3659. */
  3660. int hif_map_service_to_pipe(struct hif_opaque_softc *hif_hdl, uint16_t svc_id,
  3661. uint8_t *ul_pipe, uint8_t *dl_pipe, int *ul_is_polled,
  3662. int *dl_is_polled)
  3663. {
  3664. int status = -EINVAL;
  3665. unsigned int i;
  3666. struct service_to_pipe element;
  3667. struct service_to_pipe *tgt_svc_map_to_use;
  3668. uint32_t sz_tgt_svc_map_to_use;
  3669. struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
  3670. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  3671. bool dl_updated = false;
  3672. bool ul_updated = false;
  3673. hif_select_service_to_pipe_map(scn, &tgt_svc_map_to_use,
  3674. &sz_tgt_svc_map_to_use);
  3675. *dl_is_polled = 0; /* polling for received messages not supported */
  3676. for (i = 0; i < (sz_tgt_svc_map_to_use/sizeof(element)); i++) {
  3677. memcpy(&element, &tgt_svc_map_to_use[i], sizeof(element));
  3678. if (element.service_id == svc_id) {
  3679. if (element.pipedir == PIPEDIR_OUT) {
  3680. *ul_pipe = element.pipenum;
  3681. *ul_is_polled =
  3682. (hif_state->host_ce_config[*ul_pipe].flags &
  3683. CE_ATTR_DISABLE_INTR) != 0;
  3684. ul_updated = true;
  3685. } else if (element.pipedir == PIPEDIR_IN) {
  3686. *dl_pipe = element.pipenum;
  3687. dl_updated = true;
  3688. }
  3689. status = 0;
  3690. }
  3691. }
  3692. if (ul_updated == false)
  3693. hif_debug("ul pipe is NOT updated for service %d", svc_id);
  3694. if (dl_updated == false)
  3695. hif_debug("dl pipe is NOT updated for service %d", svc_id);
  3696. return status;
  3697. }
  3698. #ifdef SHADOW_REG_DEBUG
  3699. inline uint32_t DEBUG_CE_SRC_RING_READ_IDX_GET(struct hif_softc *scn,
  3700. uint32_t CE_ctrl_addr)
  3701. {
  3702. uint32_t read_from_hw, srri_from_ddr = 0;
  3703. read_from_hw = A_TARGET_READ(scn, CE_ctrl_addr + CURRENT_SRRI_ADDRESS);
  3704. srri_from_ddr = SRRI_FROM_DDR_ADDR(VADDR_FOR_CE(scn, CE_ctrl_addr));
  3705. if (read_from_hw != srri_from_ddr) {
  3706. hif_err("read from ddr = %d actual read from register = %d, CE_MISC_INT_STATUS_GET = 0x%x",
  3707. srri_from_ddr, read_from_hw,
  3708. CE_MISC_INT_STATUS_GET(scn, CE_ctrl_addr));
  3709. QDF_ASSERT(0);
  3710. }
  3711. return srri_from_ddr;
  3712. }
  3713. inline uint32_t DEBUG_CE_DEST_RING_READ_IDX_GET(struct hif_softc *scn,
  3714. uint32_t CE_ctrl_addr)
  3715. {
  3716. uint32_t read_from_hw, drri_from_ddr = 0;
  3717. read_from_hw = A_TARGET_READ(scn, CE_ctrl_addr + CURRENT_DRRI_ADDRESS);
  3718. drri_from_ddr = DRRI_FROM_DDR_ADDR(VADDR_FOR_CE(scn, CE_ctrl_addr));
  3719. if (read_from_hw != drri_from_ddr) {
  3720. hif_err("read from ddr = %d actual read from register = %d, CE_MISC_INT_STATUS_GET = 0x%x",
  3721. drri_from_ddr, read_from_hw,
  3722. CE_MISC_INT_STATUS_GET(scn, CE_ctrl_addr));
  3723. QDF_ASSERT(0);
  3724. }
  3725. return drri_from_ddr;
  3726. }
  3727. #endif
  3728. /**
  3729. * hif_dump_ce_registers() - dump ce registers
  3730. * @scn: hif_opaque_softc pointer.
  3731. *
  3732. * Output the copy engine registers
  3733. *
  3734. * Return: 0 for success or error code
  3735. */
  3736. int hif_dump_ce_registers(struct hif_softc *scn)
  3737. {
  3738. struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
  3739. uint32_t ce_reg_address = CE0_BASE_ADDRESS;
  3740. uint32_t ce_reg_values[CE_USEFUL_SIZE >> 2];
  3741. uint32_t ce_reg_word_size = CE_USEFUL_SIZE >> 2;
  3742. uint16_t i;
  3743. QDF_STATUS status;
  3744. for (i = 0; i < scn->ce_count; i++, ce_reg_address += CE_OFFSET) {
  3745. if (!scn->ce_id_to_state[i]) {
  3746. hif_debug("CE%d not used", i);
  3747. continue;
  3748. }
  3749. status = hif_diag_read_mem(hif_hdl, ce_reg_address,
  3750. (uint8_t *) &ce_reg_values[0],
  3751. ce_reg_word_size * sizeof(uint32_t));
  3752. if (status != QDF_STATUS_SUCCESS) {
  3753. hif_err("Dumping CE register failed!");
  3754. return -EACCES;
  3755. }
  3756. hif_debug("CE%d=>", i);
  3757. qdf_trace_hex_dump(QDF_MODULE_ID_HIF, QDF_TRACE_LEVEL_DEBUG,
  3758. (uint8_t *) &ce_reg_values[0],
  3759. ce_reg_word_size * sizeof(uint32_t));
  3760. qdf_print("ADDR:[0x%08X], SR_WR_INDEX:%d", (ce_reg_address
  3761. + SR_WR_INDEX_ADDRESS),
  3762. ce_reg_values[SR_WR_INDEX_ADDRESS/4]);
  3763. qdf_print("ADDR:[0x%08X], CURRENT_SRRI:%d", (ce_reg_address
  3764. + CURRENT_SRRI_ADDRESS),
  3765. ce_reg_values[CURRENT_SRRI_ADDRESS/4]);
  3766. qdf_print("ADDR:[0x%08X], DST_WR_INDEX:%d", (ce_reg_address
  3767. + DST_WR_INDEX_ADDRESS),
  3768. ce_reg_values[DST_WR_INDEX_ADDRESS/4]);
  3769. qdf_print("ADDR:[0x%08X], CURRENT_DRRI:%d", (ce_reg_address
  3770. + CURRENT_DRRI_ADDRESS),
  3771. ce_reg_values[CURRENT_DRRI_ADDRESS/4]);
  3772. qdf_print("---");
  3773. }
  3774. return 0;
  3775. }
  3776. qdf_export_symbol(hif_dump_ce_registers);
  3777. #ifdef QCA_NSS_WIFI_OFFLOAD_SUPPORT
  3778. struct hif_pipe_addl_info *hif_get_addl_pipe_info(struct hif_opaque_softc *osc,
  3779. struct hif_pipe_addl_info *hif_info, uint32_t pipe)
  3780. {
  3781. struct hif_softc *scn = HIF_GET_SOFTC(osc);
  3782. struct hif_pci_softc *sc = HIF_GET_PCI_SOFTC(scn);
  3783. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(osc);
  3784. struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
  3785. struct CE_handle *ce_hdl = pipe_info->ce_hdl;
  3786. struct CE_state *ce_state = (struct CE_state *)ce_hdl;
  3787. struct CE_ring_state *src_ring = ce_state->src_ring;
  3788. struct CE_ring_state *dest_ring = ce_state->dest_ring;
  3789. if (src_ring) {
  3790. hif_info->ul_pipe.nentries = src_ring->nentries;
  3791. hif_info->ul_pipe.nentries_mask = src_ring->nentries_mask;
  3792. hif_info->ul_pipe.sw_index = src_ring->sw_index;
  3793. hif_info->ul_pipe.write_index = src_ring->write_index;
  3794. hif_info->ul_pipe.hw_index = src_ring->hw_index;
  3795. hif_info->ul_pipe.base_addr_CE_space =
  3796. src_ring->base_addr_CE_space;
  3797. hif_info->ul_pipe.base_addr_owner_space =
  3798. src_ring->base_addr_owner_space;
  3799. }
  3800. if (dest_ring) {
  3801. hif_info->dl_pipe.nentries = dest_ring->nentries;
  3802. hif_info->dl_pipe.nentries_mask = dest_ring->nentries_mask;
  3803. hif_info->dl_pipe.sw_index = dest_ring->sw_index;
  3804. hif_info->dl_pipe.write_index = dest_ring->write_index;
  3805. hif_info->dl_pipe.hw_index = dest_ring->hw_index;
  3806. hif_info->dl_pipe.base_addr_CE_space =
  3807. dest_ring->base_addr_CE_space;
  3808. hif_info->dl_pipe.base_addr_owner_space =
  3809. dest_ring->base_addr_owner_space;
  3810. }
  3811. hif_info->pci_mem = pci_resource_start(sc->pdev, 0);
  3812. hif_info->ctrl_addr = ce_state->ctrl_addr;
  3813. return hif_info;
  3814. }
  3815. qdf_export_symbol(hif_get_addl_pipe_info);
  3816. uint32_t hif_set_nss_wifiol_mode(struct hif_opaque_softc *osc, uint32_t mode)
  3817. {
  3818. struct hif_softc *scn = HIF_GET_SOFTC(osc);
  3819. scn->nss_wifi_ol_mode = mode;
  3820. return 0;
  3821. }
  3822. qdf_export_symbol(hif_set_nss_wifiol_mode);
  3823. #endif
  3824. void hif_set_attribute(struct hif_opaque_softc *osc, uint8_t hif_attrib)
  3825. {
  3826. struct hif_softc *scn = HIF_GET_SOFTC(osc);
  3827. scn->hif_attribute = hif_attrib;
  3828. }
  3829. /* disable interrupts (only applicable for legacy copy engine currently */
  3830. void hif_disable_interrupt(struct hif_opaque_softc *osc, uint32_t pipe_num)
  3831. {
  3832. struct hif_softc *scn = HIF_GET_SOFTC(osc);
  3833. struct CE_state *CE_state = scn->ce_id_to_state[pipe_num];
  3834. uint32_t ctrl_addr = CE_state->ctrl_addr;
  3835. Q_TARGET_ACCESS_BEGIN(scn);
  3836. CE_COPY_COMPLETE_INTR_DISABLE(scn, ctrl_addr);
  3837. Q_TARGET_ACCESS_END(scn);
  3838. }
  3839. qdf_export_symbol(hif_disable_interrupt);
  3840. /**
  3841. * hif_fw_event_handler() - hif fw event handler
  3842. * @hif_state: pointer to hif ce state structure
  3843. *
  3844. * Process fw events and raise HTC callback to process fw events.
  3845. *
  3846. * Return: none
  3847. */
  3848. static inline void hif_fw_event_handler(struct HIF_CE_state *hif_state)
  3849. {
  3850. struct hif_msg_callbacks *msg_callbacks =
  3851. &hif_state->msg_callbacks_current;
  3852. if (!msg_callbacks->fwEventHandler)
  3853. return;
  3854. msg_callbacks->fwEventHandler(msg_callbacks->Context,
  3855. QDF_STATUS_E_FAILURE);
  3856. }
  3857. #ifndef QCA_WIFI_3_0
  3858. /**
  3859. * hif_fw_interrupt_handler() - FW interrupt handler
  3860. * @irq: irq number
  3861. * @arg: the user pointer
  3862. *
  3863. * Called from the PCI interrupt handler when a
  3864. * firmware-generated interrupt to the Host.
  3865. *
  3866. * only registered for legacy ce devices
  3867. *
  3868. * Return: status of handled irq
  3869. */
  3870. irqreturn_t hif_fw_interrupt_handler(int irq, void *arg)
  3871. {
  3872. struct hif_softc *scn = arg;
  3873. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  3874. uint32_t fw_indicator_address, fw_indicator;
  3875. if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
  3876. return ATH_ISR_NOSCHED;
  3877. fw_indicator_address = hif_state->fw_indicator_address;
  3878. /* For sudden unplug this will return ~0 */
  3879. fw_indicator = A_TARGET_READ(scn, fw_indicator_address);
  3880. if ((fw_indicator != ~0) && (fw_indicator & FW_IND_EVENT_PENDING)) {
  3881. /* ACK: clear Target-side pending event */
  3882. A_TARGET_WRITE(scn, fw_indicator_address,
  3883. fw_indicator & ~FW_IND_EVENT_PENDING);
  3884. if (Q_TARGET_ACCESS_END(scn) < 0)
  3885. return ATH_ISR_SCHED;
  3886. if (hif_state->started) {
  3887. hif_fw_event_handler(hif_state);
  3888. } else {
  3889. /*
  3890. * Probable Target failure before we're prepared
  3891. * to handle it. Generally unexpected.
  3892. * fw_indicator used as bitmap, and defined as below:
  3893. * FW_IND_EVENT_PENDING 0x1
  3894. * FW_IND_INITIALIZED 0x2
  3895. * FW_IND_NEEDRECOVER 0x4
  3896. */
  3897. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  3898. ("%s: Early firmware event indicated 0x%x\n",
  3899. __func__, fw_indicator));
  3900. }
  3901. } else {
  3902. if (Q_TARGET_ACCESS_END(scn) < 0)
  3903. return ATH_ISR_SCHED;
  3904. }
  3905. return ATH_ISR_SCHED;
  3906. }
  3907. #else
  3908. irqreturn_t hif_fw_interrupt_handler(int irq, void *arg)
  3909. {
  3910. return ATH_ISR_SCHED;
  3911. }
  3912. #endif /* #ifdef QCA_WIFI_3_0 */
  3913. /**
  3914. * hif_wlan_disable(): call the platform driver to disable wlan
  3915. * @scn: HIF Context
  3916. *
  3917. * This function passes the con_mode to platform driver to disable
  3918. * wlan.
  3919. *
  3920. * Return: void
  3921. */
  3922. void hif_wlan_disable(struct hif_softc *scn)
  3923. {
  3924. enum pld_driver_mode mode;
  3925. uint32_t con_mode = hif_get_conparam(scn);
  3926. if (scn->target_status == TARGET_STATUS_RESET)
  3927. return;
  3928. if (QDF_GLOBAL_FTM_MODE == con_mode)
  3929. mode = PLD_FTM;
  3930. else if (QDF_IS_EPPING_ENABLED(con_mode))
  3931. mode = PLD_EPPING;
  3932. else
  3933. mode = PLD_MISSION;
  3934. pld_wlan_disable(scn->qdf_dev->dev, mode);
  3935. }
  3936. int hif_get_wake_ce_id(struct hif_softc *scn, uint8_t *ce_id)
  3937. {
  3938. int status;
  3939. uint8_t ul_pipe, dl_pipe;
  3940. int ul_is_polled, dl_is_polled;
  3941. /* DL pipe for HTC_CTRL_RSVD_SVC should map to the wake CE */
  3942. status = hif_map_service_to_pipe(GET_HIF_OPAQUE_HDL(scn),
  3943. HTC_CTRL_RSVD_SVC,
  3944. &ul_pipe, &dl_pipe,
  3945. &ul_is_polled, &dl_is_polled);
  3946. if (status) {
  3947. hif_err("Failed to map pipe: %d", status);
  3948. return status;
  3949. }
  3950. *ce_id = dl_pipe;
  3951. return 0;
  3952. }
  3953. #ifdef HIF_CE_LOG_INFO
  3954. /**
  3955. * ce_get_index_info(): Get CE index info
  3956. * @scn: HIF Context
  3957. * @ce_state: CE opaque handle
  3958. * @info: CE info
  3959. *
  3960. * Return: 0 for success and non zero for failure
  3961. */
  3962. static
  3963. int ce_get_index_info(struct hif_softc *scn, void *ce_state,
  3964. struct ce_index *info)
  3965. {
  3966. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  3967. return hif_state->ce_services->ce_get_index_info(scn, ce_state, info);
  3968. }
  3969. void hif_log_ce_info(struct hif_softc *scn, uint8_t *data,
  3970. unsigned int *offset)
  3971. {
  3972. struct hang_event_info info = {0};
  3973. static uint32_t tracked_ce = BIT(CE_ID_1) | BIT(CE_ID_2) |
  3974. BIT(CE_ID_3) | BIT(CE_ID_4) | BIT(CE_ID_9) | BIT(CE_ID_10);
  3975. uint8_t curr_index = 0;
  3976. uint8_t i;
  3977. uint16_t size;
  3978. info.active_tasklet_count = qdf_atomic_read(&scn->active_tasklet_cnt);
  3979. info.active_grp_tasklet_cnt =
  3980. qdf_atomic_read(&scn->active_grp_tasklet_cnt);
  3981. for (i = 0; i < scn->ce_count; i++) {
  3982. if (!(tracked_ce & BIT(i)) || !scn->ce_id_to_state[i])
  3983. continue;
  3984. if (ce_get_index_info(scn, scn->ce_id_to_state[i],
  3985. &info.ce_info[curr_index]))
  3986. continue;
  3987. curr_index++;
  3988. }
  3989. info.ce_count = curr_index;
  3990. size = sizeof(info) -
  3991. (CE_COUNT_MAX - info.ce_count) * sizeof(struct ce_index);
  3992. if (*offset + size > QDF_WLAN_HANG_FW_OFFSET)
  3993. return;
  3994. QDF_HANG_EVT_SET_HDR(&info.tlv_header, HANG_EVT_TAG_CE_INFO,
  3995. size - QDF_HANG_EVENT_TLV_HDR_SIZE);
  3996. qdf_mem_copy(data + *offset, &info, size);
  3997. *offset = *offset + size;
  3998. }
  3999. #endif