ce_main.c 119 KB

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