ce_main.c 115 KB

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