ce_main.c 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934
  1. /*
  2. * Copyright (c) 2013-2016 The Linux Foundation. All rights reserved.
  3. *
  4. * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  5. *
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for
  8. * any purpose with or without fee is hereby granted, provided that the
  9. * above copyright notice and this permission notice appear in all
  10. * copies.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  13. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  14. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  15. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  16. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  17. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  18. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  19. * PERFORMANCE OF THIS SOFTWARE.
  20. */
  21. /*
  22. * This file was originally distributed by Qualcomm Atheros, Inc.
  23. * under proprietary terms before Copyright ownership was assigned
  24. * to the Linux Foundation.
  25. */
  26. #include "targcfg.h"
  27. #include "qdf_lock.h"
  28. #include "qdf_status.h"
  29. #include "qdf_status.h"
  30. #include <qdf_atomic.h> /* qdf_atomic_read */
  31. #include <targaddrs.h>
  32. #include "hif_io32.h"
  33. #include <hif.h>
  34. #include "regtable.h"
  35. #define ATH_MODULE_NAME hif
  36. #include <a_debug.h>
  37. #include "hif_main.h"
  38. #include "ce_api.h"
  39. #include "qdf_trace.h"
  40. #include "pld_common.h"
  41. #include "hif_debug.h"
  42. #include "ce_internal.h"
  43. #include "ce_reg.h"
  44. #include "ce_assignment.h"
  45. #include "ce_tasklet.h"
  46. #ifndef CONFIG_WIN
  47. #include "qwlan_version.h"
  48. #endif
  49. #define CE_POLL_TIMEOUT 10 /* ms */
  50. #define AGC_DUMP 1
  51. #define CHANINFO_DUMP 2
  52. #define BB_WATCHDOG_DUMP 3
  53. #ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
  54. #define PCIE_ACCESS_DUMP 4
  55. #endif
  56. #include "mp_dev.h"
  57. /* Forward references */
  58. static int hif_post_recv_buffers_for_pipe(struct HIF_CE_pipe_info *pipe_info);
  59. /*
  60. * Fix EV118783, poll to check whether a BMI response comes
  61. * other than waiting for the interruption which may be lost.
  62. */
  63. /* #define BMI_RSP_POLLING */
  64. #define BMI_RSP_TO_MILLISEC 1000
  65. #ifdef CONFIG_BYPASS_QMI
  66. #define BYPASS_QMI 1
  67. #else
  68. #define BYPASS_QMI 0
  69. #endif
  70. #ifdef CONFIG_WIN
  71. #if ENABLE_10_4_FW_HDR
  72. #define WDI_IPA_SERVICE_GROUP 5
  73. #define WDI_IPA_TX_SVC MAKE_SERVICE_ID(WDI_IPA_SERVICE_GROUP, 0)
  74. #define HTT_DATA2_MSG_SVC MAKE_SERVICE_ID(HTT_SERVICE_GROUP, 1)
  75. #define HTT_DATA3_MSG_SVC MAKE_SERVICE_ID(HTT_SERVICE_GROUP, 2)
  76. #endif /* ENABLE_10_4_FW_HDR */
  77. #endif
  78. static int hif_post_recv_buffers(struct hif_softc *scn);
  79. static void hif_config_rri_on_ddr(struct hif_softc *scn);
  80. /**
  81. * hif_target_access_log_dump() - dump access log
  82. *
  83. * dump access log
  84. *
  85. * Return: n/a
  86. */
  87. #ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
  88. static void hif_target_access_log_dump(void)
  89. {
  90. hif_target_dump_access_log();
  91. }
  92. #endif
  93. void hif_trigger_dump(struct hif_opaque_softc *hif_ctx,
  94. uint8_t cmd_id, bool start)
  95. {
  96. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  97. switch (cmd_id) {
  98. case AGC_DUMP:
  99. if (start)
  100. priv_start_agc(scn);
  101. else
  102. priv_dump_agc(scn);
  103. break;
  104. case CHANINFO_DUMP:
  105. if (start)
  106. priv_start_cap_chaninfo(scn);
  107. else
  108. priv_dump_chaninfo(scn);
  109. break;
  110. case BB_WATCHDOG_DUMP:
  111. priv_dump_bbwatchdog(scn);
  112. break;
  113. #ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
  114. case PCIE_ACCESS_DUMP:
  115. hif_target_access_log_dump();
  116. break;
  117. #endif
  118. default:
  119. HIF_ERROR("%s: Invalid htc dump command", __func__);
  120. break;
  121. }
  122. }
  123. static void ce_poll_timeout(void *arg)
  124. {
  125. struct CE_state *CE_state = (struct CE_state *)arg;
  126. if (CE_state->timer_inited) {
  127. ce_per_engine_service(CE_state->scn, CE_state->id);
  128. qdf_timer_mod(&CE_state->poll_timer, CE_POLL_TIMEOUT);
  129. }
  130. }
  131. static unsigned int roundup_pwr2(unsigned int n)
  132. {
  133. int i;
  134. unsigned int test_pwr2;
  135. if (!(n & (n - 1)))
  136. return n; /* already a power of 2 */
  137. test_pwr2 = 4;
  138. for (i = 0; i < 29; i++) {
  139. if (test_pwr2 > n)
  140. return test_pwr2;
  141. test_pwr2 = test_pwr2 << 1;
  142. }
  143. QDF_ASSERT(0); /* n too large */
  144. return 0;
  145. }
  146. #define ADRASTEA_SRC_WR_INDEX_OFFSET 0x3C
  147. #define ADRASTEA_DST_WR_INDEX_OFFSET 0x40
  148. static struct shadow_reg_cfg target_shadow_reg_cfg_map[] = {
  149. { 0, ADRASTEA_SRC_WR_INDEX_OFFSET},
  150. { 3, ADRASTEA_SRC_WR_INDEX_OFFSET},
  151. { 4, ADRASTEA_SRC_WR_INDEX_OFFSET},
  152. { 5, ADRASTEA_SRC_WR_INDEX_OFFSET},
  153. { 7, ADRASTEA_SRC_WR_INDEX_OFFSET},
  154. { 1, ADRASTEA_DST_WR_INDEX_OFFSET},
  155. { 2, ADRASTEA_DST_WR_INDEX_OFFSET},
  156. { 7, ADRASTEA_DST_WR_INDEX_OFFSET},
  157. { 8, ADRASTEA_DST_WR_INDEX_OFFSET},
  158. #ifdef QCA_WIFI_3_0_ADRASTEA
  159. { 9, ADRASTEA_DST_WR_INDEX_OFFSET},
  160. { 10, ADRASTEA_DST_WR_INDEX_OFFSET},
  161. { 11, ADRASTEA_DST_WR_INDEX_OFFSET},
  162. #endif
  163. };
  164. static struct shadow_reg_cfg target_shadow_reg_cfg_epping[] = {
  165. { 0, ADRASTEA_SRC_WR_INDEX_OFFSET},
  166. { 3, ADRASTEA_SRC_WR_INDEX_OFFSET},
  167. { 4, ADRASTEA_SRC_WR_INDEX_OFFSET},
  168. { 7, ADRASTEA_SRC_WR_INDEX_OFFSET},
  169. { 1, ADRASTEA_DST_WR_INDEX_OFFSET},
  170. { 2, ADRASTEA_DST_WR_INDEX_OFFSET},
  171. { 5, ADRASTEA_DST_WR_INDEX_OFFSET},
  172. { 7, ADRASTEA_DST_WR_INDEX_OFFSET},
  173. { 8, ADRASTEA_DST_WR_INDEX_OFFSET},
  174. };
  175. /* CE_PCI TABLE */
  176. /*
  177. * NOTE: the table below is out of date, though still a useful reference.
  178. * Refer to target_service_to_ce_map and hif_map_service_to_pipe for the actual
  179. * mapping of HTC services to HIF pipes.
  180. */
  181. /*
  182. * This authoritative table defines Copy Engine configuration and the mapping
  183. * of services/endpoints to CEs. A subset of this information is passed to
  184. * the Target during startup as a prerequisite to entering BMI phase.
  185. * See:
  186. * target_service_to_ce_map - Target-side mapping
  187. * hif_map_service_to_pipe - Host-side mapping
  188. * target_ce_config - Target-side configuration
  189. * host_ce_config - Host-side configuration
  190. ============================================================================
  191. Purpose | Service / Endpoint | CE | Dire | Xfer | Xfer
  192. | | | ctio | Size | Frequency
  193. | | | n | |
  194. ============================================================================
  195. tx | HTT_DATA (downlink) | CE 0 | h->t | medium - | very frequent
  196. descriptor | | | | O(100B) | and regular
  197. download | | | | |
  198. ----------------------------------------------------------------------------
  199. rx | HTT_DATA (uplink) | CE 1 | t->h | small - | frequent and
  200. indication | | | | O(10B) | regular
  201. upload | | | | |
  202. ----------------------------------------------------------------------------
  203. MSDU | DATA_BK (uplink) | CE 2 | t->h | large - | rare
  204. upload | | | | O(1000B) | (frequent
  205. e.g. noise | | | | | during IP1.0
  206. packets | | | | | testing)
  207. ----------------------------------------------------------------------------
  208. MSDU | DATA_BK (downlink) | CE 3 | h->t | large - | very rare
  209. download | | | | O(1000B) | (frequent
  210. e.g. | | | | | during IP1.0
  211. misdirecte | | | | | testing)
  212. d EAPOL | | | | |
  213. packets | | | | |
  214. ----------------------------------------------------------------------------
  215. n/a | DATA_BE, DATA_VI | CE 2 | t->h | | never(?)
  216. | DATA_VO (uplink) | | | |
  217. ----------------------------------------------------------------------------
  218. n/a | DATA_BE, DATA_VI | CE 3 | h->t | | never(?)
  219. | DATA_VO (downlink) | | | |
  220. ----------------------------------------------------------------------------
  221. WMI events | WMI_CONTROL (uplink) | CE 4 | t->h | medium - | infrequent
  222. | | | | O(100B) |
  223. ----------------------------------------------------------------------------
  224. WMI | WMI_CONTROL | CE 5 | h->t | medium - | infrequent
  225. messages | (downlink) | | | O(100B) |
  226. | | | | |
  227. ----------------------------------------------------------------------------
  228. n/a | HTC_CTRL_RSVD, | CE 1 | t->h | | never(?)
  229. | HTC_RAW_STREAMS | | | |
  230. | (uplink) | | | |
  231. ----------------------------------------------------------------------------
  232. n/a | HTC_CTRL_RSVD, | CE 0 | h->t | | never(?)
  233. | HTC_RAW_STREAMS | | | |
  234. | (downlink) | | | |
  235. ----------------------------------------------------------------------------
  236. diag | none (raw CE) | CE 7 | t<>h | 4 | Diag Window
  237. | | | | | infrequent
  238. ============================================================================
  239. */
  240. /*
  241. * Map from service/endpoint to Copy Engine.
  242. * This table is derived from the CE_PCI TABLE, above.
  243. * It is passed to the Target at startup for use by firmware.
  244. */
  245. static struct service_to_pipe target_service_to_ce_map_wlan[] = {
  246. {
  247. WMI_DATA_VO_SVC,
  248. PIPEDIR_OUT, /* out = UL = host -> target */
  249. 3,
  250. },
  251. {
  252. WMI_DATA_VO_SVC,
  253. PIPEDIR_IN, /* in = DL = target -> host */
  254. 2,
  255. },
  256. {
  257. WMI_DATA_BK_SVC,
  258. PIPEDIR_OUT, /* out = UL = host -> target */
  259. 3,
  260. },
  261. {
  262. WMI_DATA_BK_SVC,
  263. PIPEDIR_IN, /* in = DL = target -> host */
  264. 2,
  265. },
  266. {
  267. WMI_DATA_BE_SVC,
  268. PIPEDIR_OUT, /* out = UL = host -> target */
  269. 3,
  270. },
  271. {
  272. WMI_DATA_BE_SVC,
  273. PIPEDIR_IN, /* in = DL = target -> host */
  274. 2,
  275. },
  276. {
  277. WMI_DATA_VI_SVC,
  278. PIPEDIR_OUT, /* out = UL = host -> target */
  279. 3,
  280. },
  281. {
  282. WMI_DATA_VI_SVC,
  283. PIPEDIR_IN, /* in = DL = target -> host */
  284. 2,
  285. },
  286. {
  287. WMI_CONTROL_SVC,
  288. PIPEDIR_OUT, /* out = UL = host -> target */
  289. 3,
  290. },
  291. {
  292. WMI_CONTROL_SVC,
  293. PIPEDIR_IN, /* in = DL = target -> host */
  294. 2,
  295. },
  296. {
  297. HTC_CTRL_RSVD_SVC,
  298. PIPEDIR_OUT, /* out = UL = host -> target */
  299. 0, /* could be moved to 3 (share with WMI) */
  300. },
  301. {
  302. HTC_CTRL_RSVD_SVC,
  303. PIPEDIR_IN, /* in = DL = target -> host */
  304. 2,
  305. },
  306. {
  307. HTC_RAW_STREAMS_SVC, /* not currently used */
  308. PIPEDIR_OUT, /* out = UL = host -> target */
  309. 0,
  310. },
  311. {
  312. HTC_RAW_STREAMS_SVC, /* not currently used */
  313. PIPEDIR_IN, /* in = DL = target -> host */
  314. 2,
  315. },
  316. {
  317. HTT_DATA_MSG_SVC,
  318. PIPEDIR_OUT, /* out = UL = host -> target */
  319. 4,
  320. },
  321. {
  322. HTT_DATA_MSG_SVC,
  323. PIPEDIR_IN, /* in = DL = target -> host */
  324. 1,
  325. },
  326. {
  327. WDI_IPA_TX_SVC,
  328. PIPEDIR_OUT, /* in = DL = target -> host */
  329. 5,
  330. },
  331. #if defined(QCA_WIFI_3_0_ADRASTEA)
  332. {
  333. HTT_DATA2_MSG_SVC,
  334. PIPEDIR_IN, /* in = DL = target -> host */
  335. 9,
  336. },
  337. {
  338. HTT_DATA3_MSG_SVC,
  339. PIPEDIR_IN, /* in = DL = target -> host */
  340. 10,
  341. },
  342. {
  343. PACKET_LOG_SVC,
  344. PIPEDIR_IN, /* in = DL = target -> host */
  345. 11,
  346. },
  347. #endif
  348. /* (Additions here) */
  349. { /* Must be last */
  350. 0,
  351. 0,
  352. 0,
  353. },
  354. };
  355. static struct service_to_pipe target_service_to_ce_map_ar900b[] = {
  356. {
  357. WMI_DATA_VO_SVC,
  358. PIPEDIR_OUT, /* out = UL = host -> target */
  359. 3,
  360. },
  361. {
  362. WMI_DATA_VO_SVC,
  363. PIPEDIR_IN, /* in = DL = target -> host */
  364. 2,
  365. },
  366. {
  367. WMI_DATA_BK_SVC,
  368. PIPEDIR_OUT, /* out = UL = host -> target */
  369. 3,
  370. },
  371. {
  372. WMI_DATA_BK_SVC,
  373. PIPEDIR_IN, /* in = DL = target -> host */
  374. 2,
  375. },
  376. {
  377. WMI_DATA_BE_SVC,
  378. PIPEDIR_OUT, /* out = UL = host -> target */
  379. 3,
  380. },
  381. {
  382. WMI_DATA_BE_SVC,
  383. PIPEDIR_IN, /* in = DL = target -> host */
  384. 2,
  385. },
  386. {
  387. WMI_DATA_VI_SVC,
  388. PIPEDIR_OUT, /* out = UL = host -> target */
  389. 3,
  390. },
  391. {
  392. WMI_DATA_VI_SVC,
  393. PIPEDIR_IN, /* in = DL = target -> host */
  394. 2,
  395. },
  396. {
  397. WMI_CONTROL_SVC,
  398. PIPEDIR_OUT, /* out = UL = host -> target */
  399. 3,
  400. },
  401. {
  402. WMI_CONTROL_SVC,
  403. PIPEDIR_IN, /* in = DL = target -> host */
  404. 2,
  405. },
  406. {
  407. HTC_CTRL_RSVD_SVC,
  408. PIPEDIR_OUT, /* out = UL = host -> target */
  409. 0, /* could be moved to 3 (share with WMI) */
  410. },
  411. {
  412. HTC_CTRL_RSVD_SVC,
  413. PIPEDIR_IN, /* in = DL = target -> host */
  414. 1,
  415. },
  416. {
  417. HTC_RAW_STREAMS_SVC, /* not currently used */
  418. PIPEDIR_OUT, /* out = UL = host -> target */
  419. 0,
  420. },
  421. {
  422. HTC_RAW_STREAMS_SVC, /* not currently used */
  423. PIPEDIR_IN, /* in = DL = target -> host */
  424. 1,
  425. },
  426. {
  427. HTT_DATA_MSG_SVC,
  428. PIPEDIR_OUT, /* out = UL = host -> target */
  429. 4,
  430. },
  431. #if WLAN_FEATURE_FASTPATH
  432. {
  433. HTT_DATA_MSG_SVC,
  434. PIPEDIR_IN, /* in = DL = target -> host */
  435. 5,
  436. },
  437. #else /* WLAN_FEATURE_FASTPATH */
  438. {
  439. HTT_DATA_MSG_SVC,
  440. PIPEDIR_IN, /* in = DL = target -> host */
  441. 1,
  442. },
  443. #endif /* WLAN_FEATURE_FASTPATH */
  444. /* (Additions here) */
  445. { /* Must be last */
  446. 0,
  447. 0,
  448. 0,
  449. },
  450. };
  451. static struct service_to_pipe *target_service_to_ce_map =
  452. target_service_to_ce_map_wlan;
  453. static int target_service_to_ce_map_sz = sizeof(target_service_to_ce_map_wlan);
  454. static struct shadow_reg_cfg *target_shadow_reg_cfg = target_shadow_reg_cfg_map;
  455. static int shadow_cfg_sz = sizeof(target_shadow_reg_cfg_map);
  456. static struct service_to_pipe target_service_to_ce_map_wlan_epping[] = {
  457. {WMI_DATA_VO_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
  458. {WMI_DATA_VO_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
  459. {WMI_DATA_BK_SVC, PIPEDIR_OUT, 4,}, /* out = UL = host -> target */
  460. {WMI_DATA_BK_SVC, PIPEDIR_IN, 1,}, /* in = DL = target -> host */
  461. {WMI_DATA_BE_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
  462. {WMI_DATA_BE_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
  463. {WMI_DATA_VI_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
  464. {WMI_DATA_VI_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
  465. {WMI_CONTROL_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
  466. {WMI_CONTROL_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
  467. {HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0,}, /* out = UL = host -> target */
  468. {HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
  469. {HTC_RAW_STREAMS_SVC, PIPEDIR_OUT, 0,}, /* out = UL = host -> target */
  470. {HTC_RAW_STREAMS_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
  471. {HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4,}, /* out = UL = host -> target */
  472. {HTT_DATA_MSG_SVC, PIPEDIR_IN, 1,}, /* in = DL = target -> host */
  473. {0, 0, 0,}, /* Must be last */
  474. };
  475. /**
  476. * ce_mark_datapath() - marks the ce_state->htt_rx_data accordingly
  477. * @ce_state : pointer to the state context of the CE
  478. *
  479. * Description:
  480. * Sets htt_rx_data attribute of the state structure if the
  481. * CE serves one of the HTT DATA services.
  482. *
  483. * Return:
  484. * false (attribute set to false)
  485. * true (attribute set to true);
  486. */
  487. bool ce_mark_datapath(struct CE_state *ce_state)
  488. {
  489. struct service_to_pipe *svc_map;
  490. size_t map_sz;
  491. int i;
  492. bool rc = false;
  493. struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(ce_state->scn);
  494. struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl);
  495. if (ce_state != NULL) {
  496. if (QDF_IS_EPPING_ENABLED(hif_get_conparam(ce_state->scn))) {
  497. svc_map = target_service_to_ce_map_wlan_epping;
  498. map_sz = sizeof(target_service_to_ce_map_wlan_epping) /
  499. sizeof(struct service_to_pipe);
  500. } else {
  501. switch (tgt_info->target_type) {
  502. default:
  503. svc_map = target_service_to_ce_map_wlan;
  504. map_sz =
  505. sizeof(target_service_to_ce_map_wlan) /
  506. sizeof(struct service_to_pipe);
  507. break;
  508. case TARGET_TYPE_AR900B:
  509. case TARGET_TYPE_QCA9984:
  510. case TARGET_TYPE_IPQ4019:
  511. case TARGET_TYPE_QCA9888:
  512. case TARGET_TYPE_AR9888:
  513. case TARGET_TYPE_AR9888V2:
  514. svc_map = target_service_to_ce_map_ar900b;
  515. map_sz =
  516. sizeof(target_service_to_ce_map_ar900b)
  517. / sizeof(struct service_to_pipe);
  518. break;
  519. }
  520. }
  521. for (i = 0; i < map_sz; i++) {
  522. if ((svc_map[i].pipenum == ce_state->id) &&
  523. ((svc_map[i].service_id == HTT_DATA_MSG_SVC) ||
  524. (svc_map[i].service_id == HTT_DATA2_MSG_SVC) ||
  525. (svc_map[i].service_id == HTT_DATA3_MSG_SVC))) {
  526. /* HTT CEs are unidirectional */
  527. if (svc_map[i].pipedir == PIPEDIR_IN)
  528. ce_state->htt_rx_data = true;
  529. else
  530. ce_state->htt_tx_data = true;
  531. rc = true;
  532. }
  533. }
  534. }
  535. return rc;
  536. }
  537. /**
  538. * ce_ring_test_initial_indexes() - tests the initial ce ring indexes
  539. * @ce_id: ce in question
  540. * @ring: ring state being examined
  541. * @type: "src_ring" or "dest_ring" string for identifying the ring
  542. *
  543. * Warns on non-zero index values.
  544. * Causes a kernel panic if the ring is not empty durring initialization.
  545. */
  546. static void ce_ring_test_initial_indexes(int ce_id, struct CE_ring_state *ring,
  547. char *type)
  548. {
  549. if (ring->write_index != 0 || ring->sw_index != 0)
  550. HIF_ERROR("ce %d, %s, initial sw_index = %d, initial write_index =%d",
  551. ce_id, type, ring->sw_index, ring->write_index);
  552. if (ring->write_index != ring->sw_index)
  553. QDF_BUG(0);
  554. }
  555. /*
  556. * Initialize a Copy Engine based on caller-supplied attributes.
  557. * This may be called once to initialize both source and destination
  558. * rings or it may be called twice for separate source and destination
  559. * initialization. It may be that only one side or the other is
  560. * initialized by software/firmware.
  561. *
  562. * This should be called durring the initialization sequence before
  563. * interupts are enabled, so we don't have to worry about thread safety.
  564. */
  565. struct CE_handle *ce_init(struct hif_softc *scn,
  566. unsigned int CE_id, struct CE_attr *attr)
  567. {
  568. struct CE_state *CE_state;
  569. uint32_t ctrl_addr;
  570. unsigned int nentries;
  571. qdf_dma_addr_t base_addr;
  572. bool malloc_CE_state = false;
  573. bool malloc_src_ring = false;
  574. QDF_ASSERT(CE_id < scn->ce_count);
  575. ctrl_addr = CE_BASE_ADDRESS(CE_id);
  576. CE_state = scn->ce_id_to_state[CE_id];
  577. if (!CE_state) {
  578. CE_state =
  579. (struct CE_state *)qdf_mem_malloc(sizeof(*CE_state));
  580. if (!CE_state) {
  581. HIF_ERROR("%s: CE_state has no mem", __func__);
  582. return NULL;
  583. }
  584. malloc_CE_state = true;
  585. qdf_mem_zero(CE_state, sizeof(*CE_state));
  586. scn->ce_id_to_state[CE_id] = CE_state;
  587. qdf_spinlock_create(&CE_state->ce_index_lock);
  588. CE_state->id = CE_id;
  589. CE_state->ctrl_addr = ctrl_addr;
  590. CE_state->state = CE_RUNNING;
  591. CE_state->attr_flags = attr->flags;
  592. }
  593. CE_state->scn = scn;
  594. qdf_atomic_init(&CE_state->rx_pending);
  595. if (attr == NULL) {
  596. /* Already initialized; caller wants the handle */
  597. return (struct CE_handle *)CE_state;
  598. }
  599. if (CE_state->src_sz_max)
  600. QDF_ASSERT(CE_state->src_sz_max == attr->src_sz_max);
  601. else
  602. CE_state->src_sz_max = attr->src_sz_max;
  603. ce_init_ce_desc_event_log(CE_id,
  604. attr->src_nentries + attr->dest_nentries);
  605. /* source ring setup */
  606. nentries = attr->src_nentries;
  607. if (nentries) {
  608. struct CE_ring_state *src_ring;
  609. unsigned CE_nbytes;
  610. char *ptr;
  611. uint64_t dma_addr;
  612. nentries = roundup_pwr2(nentries);
  613. if (CE_state->src_ring) {
  614. QDF_ASSERT(CE_state->src_ring->nentries == nentries);
  615. } else {
  616. CE_nbytes = sizeof(struct CE_ring_state)
  617. + (nentries * sizeof(void *));
  618. ptr = qdf_mem_malloc(CE_nbytes);
  619. if (!ptr) {
  620. /* cannot allocate src ring. If the
  621. * CE_state is allocated locally free
  622. * CE_State and return error.
  623. */
  624. HIF_ERROR("%s: src ring has no mem", __func__);
  625. if (malloc_CE_state) {
  626. /* allocated CE_state locally */
  627. scn->ce_id_to_state[CE_id] = NULL;
  628. qdf_mem_free(CE_state);
  629. malloc_CE_state = false;
  630. }
  631. return NULL;
  632. } else {
  633. /* we can allocate src ring.
  634. * Mark that the src ring is
  635. * allocated locally
  636. */
  637. malloc_src_ring = true;
  638. }
  639. qdf_mem_zero(ptr, CE_nbytes);
  640. src_ring = CE_state->src_ring =
  641. (struct CE_ring_state *)ptr;
  642. ptr += sizeof(struct CE_ring_state);
  643. src_ring->nentries = nentries;
  644. src_ring->nentries_mask = nentries - 1;
  645. if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
  646. goto error_target_access;
  647. src_ring->hw_index =
  648. CE_SRC_RING_READ_IDX_GET_FROM_REGISTER(scn,
  649. ctrl_addr);
  650. src_ring->sw_index = src_ring->hw_index;
  651. src_ring->write_index =
  652. CE_SRC_RING_WRITE_IDX_GET_FROM_REGISTER(scn,
  653. ctrl_addr);
  654. ce_ring_test_initial_indexes(CE_id, src_ring,
  655. "src_ring");
  656. if (Q_TARGET_ACCESS_END(scn) < 0)
  657. goto error_target_access;
  658. src_ring->low_water_mark_nentries = 0;
  659. src_ring->high_water_mark_nentries = nentries;
  660. src_ring->per_transfer_context = (void **)ptr;
  661. /* Legacy platforms that do not support cache
  662. * coherent DMA are unsupported
  663. */
  664. src_ring->base_addr_owner_space_unaligned =
  665. qdf_mem_alloc_consistent(scn->qdf_dev,
  666. scn->qdf_dev->dev,
  667. (nentries *
  668. sizeof(struct CE_src_desc) +
  669. CE_DESC_RING_ALIGN),
  670. &base_addr);
  671. if (src_ring->base_addr_owner_space_unaligned
  672. == NULL) {
  673. HIF_ERROR("%s: src ring has no DMA mem",
  674. __func__);
  675. goto error_no_dma_mem;
  676. }
  677. src_ring->base_addr_CE_space_unaligned = base_addr;
  678. if (src_ring->
  679. base_addr_CE_space_unaligned & (CE_DESC_RING_ALIGN
  680. - 1)) {
  681. src_ring->base_addr_CE_space =
  682. (src_ring->base_addr_CE_space_unaligned
  683. + CE_DESC_RING_ALIGN -
  684. 1) & ~(CE_DESC_RING_ALIGN - 1);
  685. src_ring->base_addr_owner_space =
  686. (void
  687. *)(((size_t) src_ring->
  688. base_addr_owner_space_unaligned +
  689. CE_DESC_RING_ALIGN -
  690. 1) & ~(CE_DESC_RING_ALIGN - 1));
  691. } else {
  692. src_ring->base_addr_CE_space =
  693. src_ring->base_addr_CE_space_unaligned;
  694. src_ring->base_addr_owner_space =
  695. src_ring->
  696. base_addr_owner_space_unaligned;
  697. }
  698. /*
  699. * Also allocate a shadow src ring in
  700. * regular mem to use for faster access.
  701. */
  702. src_ring->shadow_base_unaligned =
  703. qdf_mem_malloc(nentries *
  704. sizeof(struct CE_src_desc) +
  705. CE_DESC_RING_ALIGN);
  706. if (src_ring->shadow_base_unaligned == NULL) {
  707. HIF_ERROR("%s: src ring no shadow_base mem",
  708. __func__);
  709. goto error_no_dma_mem;
  710. }
  711. src_ring->shadow_base = (struct CE_src_desc *)
  712. (((size_t) src_ring->shadow_base_unaligned +
  713. CE_DESC_RING_ALIGN - 1) &
  714. ~(CE_DESC_RING_ALIGN - 1));
  715. if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
  716. goto error_target_access;
  717. dma_addr = src_ring->base_addr_CE_space;
  718. CE_SRC_RING_BASE_ADDR_SET(scn, ctrl_addr,
  719. (uint32_t)(dma_addr & 0xFFFFFFFF));
  720. /* if SR_BA_ADDRESS_HIGH register exists */
  721. if (is_register_supported(SR_BA_ADDRESS_HIGH)) {
  722. uint32_t tmp;
  723. tmp = CE_SRC_RING_BASE_ADDR_HIGH_GET(
  724. scn, ctrl_addr);
  725. tmp &= ~0x1F;
  726. dma_addr = ((dma_addr >> 32) & 0x1F)|tmp;
  727. CE_SRC_RING_BASE_ADDR_HIGH_SET(scn,
  728. ctrl_addr, (uint32_t)dma_addr);
  729. }
  730. CE_SRC_RING_SZ_SET(scn, ctrl_addr, nentries);
  731. CE_SRC_RING_DMAX_SET(scn, ctrl_addr, attr->src_sz_max);
  732. #ifdef BIG_ENDIAN_HOST
  733. /* Enable source ring byte swap for big endian host */
  734. CE_SRC_RING_BYTE_SWAP_SET(scn, ctrl_addr, 1);
  735. #endif
  736. CE_SRC_RING_LOWMARK_SET(scn, ctrl_addr, 0);
  737. CE_SRC_RING_HIGHMARK_SET(scn, ctrl_addr, nentries);
  738. if (Q_TARGET_ACCESS_END(scn) < 0)
  739. goto error_target_access;
  740. }
  741. }
  742. /* destination ring setup */
  743. nentries = attr->dest_nentries;
  744. if (nentries) {
  745. struct CE_ring_state *dest_ring;
  746. unsigned CE_nbytes;
  747. char *ptr;
  748. uint64_t dma_addr;
  749. nentries = roundup_pwr2(nentries);
  750. if (CE_state->dest_ring) {
  751. QDF_ASSERT(CE_state->dest_ring->nentries == nentries);
  752. } else {
  753. CE_nbytes = sizeof(struct CE_ring_state)
  754. + (nentries * sizeof(void *));
  755. ptr = qdf_mem_malloc(CE_nbytes);
  756. if (!ptr) {
  757. /* cannot allocate dst ring. If the CE_state
  758. * or src ring is allocated locally free
  759. * CE_State and src ring and return error.
  760. */
  761. HIF_ERROR("%s: dest ring has no mem",
  762. __func__);
  763. if (malloc_src_ring) {
  764. qdf_mem_free(CE_state->src_ring);
  765. CE_state->src_ring = NULL;
  766. malloc_src_ring = false;
  767. }
  768. if (malloc_CE_state) {
  769. /* allocated CE_state locally */
  770. scn->ce_id_to_state[CE_id] = NULL;
  771. qdf_mem_free(CE_state);
  772. malloc_CE_state = false;
  773. }
  774. return NULL;
  775. }
  776. qdf_mem_zero(ptr, CE_nbytes);
  777. dest_ring = CE_state->dest_ring =
  778. (struct CE_ring_state *)ptr;
  779. ptr += sizeof(struct CE_ring_state);
  780. dest_ring->nentries = nentries;
  781. dest_ring->nentries_mask = nentries - 1;
  782. if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
  783. goto error_target_access;
  784. dest_ring->sw_index =
  785. CE_DEST_RING_READ_IDX_GET_FROM_REGISTER(scn,
  786. ctrl_addr);
  787. dest_ring->write_index =
  788. CE_DEST_RING_WRITE_IDX_GET_FROM_REGISTER(scn,
  789. ctrl_addr);
  790. ce_ring_test_initial_indexes(CE_id, dest_ring,
  791. "dest_ring");
  792. if (Q_TARGET_ACCESS_END(scn) < 0)
  793. goto error_target_access;
  794. dest_ring->low_water_mark_nentries = 0;
  795. dest_ring->high_water_mark_nentries = nentries;
  796. dest_ring->per_transfer_context = (void **)ptr;
  797. /* Legacy platforms that do not support cache
  798. * coherent DMA are unsupported */
  799. dest_ring->base_addr_owner_space_unaligned =
  800. qdf_mem_alloc_consistent(scn->qdf_dev,
  801. scn->qdf_dev->dev,
  802. (nentries *
  803. sizeof(struct CE_dest_desc) +
  804. CE_DESC_RING_ALIGN),
  805. &base_addr);
  806. if (dest_ring->base_addr_owner_space_unaligned
  807. == NULL) {
  808. HIF_ERROR("%s: dest ring has no DMA mem",
  809. __func__);
  810. goto error_no_dma_mem;
  811. }
  812. dest_ring->base_addr_CE_space_unaligned = base_addr;
  813. /* Correctly initialize memory to 0 to
  814. * prevent garbage data crashing system
  815. * when download firmware
  816. */
  817. qdf_mem_zero(dest_ring->base_addr_owner_space_unaligned,
  818. nentries * sizeof(struct CE_dest_desc) +
  819. CE_DESC_RING_ALIGN);
  820. if (dest_ring->
  821. base_addr_CE_space_unaligned & (CE_DESC_RING_ALIGN -
  822. 1)) {
  823. dest_ring->base_addr_CE_space =
  824. (dest_ring->
  825. base_addr_CE_space_unaligned +
  826. CE_DESC_RING_ALIGN -
  827. 1) & ~(CE_DESC_RING_ALIGN - 1);
  828. dest_ring->base_addr_owner_space =
  829. (void
  830. *)(((size_t) dest_ring->
  831. base_addr_owner_space_unaligned +
  832. CE_DESC_RING_ALIGN -
  833. 1) & ~(CE_DESC_RING_ALIGN - 1));
  834. } else {
  835. dest_ring->base_addr_CE_space =
  836. dest_ring->base_addr_CE_space_unaligned;
  837. dest_ring->base_addr_owner_space =
  838. dest_ring->
  839. base_addr_owner_space_unaligned;
  840. }
  841. if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
  842. goto error_target_access;
  843. dma_addr = dest_ring->base_addr_CE_space;
  844. CE_DEST_RING_BASE_ADDR_SET(scn, ctrl_addr,
  845. (uint32_t)(dma_addr & 0xFFFFFFFF));
  846. /* if DR_BA_ADDRESS_HIGH exists */
  847. if (is_register_supported(DR_BA_ADDRESS_HIGH)) {
  848. uint32_t tmp;
  849. tmp = CE_DEST_RING_BASE_ADDR_HIGH_GET(scn,
  850. ctrl_addr);
  851. tmp &= ~0x1F;
  852. dma_addr = ((dma_addr >> 32) & 0x1F)|tmp;
  853. CE_DEST_RING_BASE_ADDR_HIGH_SET(scn,
  854. ctrl_addr, (uint32_t)dma_addr);
  855. }
  856. CE_DEST_RING_SZ_SET(scn, ctrl_addr, nentries);
  857. #ifdef BIG_ENDIAN_HOST
  858. /* Enable Dest ring byte swap for big endian host */
  859. CE_DEST_RING_BYTE_SWAP_SET(scn, ctrl_addr, 1);
  860. #endif
  861. CE_DEST_RING_LOWMARK_SET(scn, ctrl_addr, 0);
  862. CE_DEST_RING_HIGHMARK_SET(scn, ctrl_addr, nentries);
  863. if (Q_TARGET_ACCESS_END(scn) < 0)
  864. goto error_target_access;
  865. /* epping */
  866. /* poll timer */
  867. if ((CE_state->attr_flags & CE_ATTR_ENABLE_POLL)) {
  868. qdf_timer_init(scn->qdf_dev,
  869. &CE_state->poll_timer,
  870. ce_poll_timeout,
  871. CE_state,
  872. QDF_TIMER_TYPE_SW);
  873. CE_state->timer_inited = true;
  874. qdf_timer_mod(&CE_state->poll_timer,
  875. CE_POLL_TIMEOUT);
  876. }
  877. }
  878. }
  879. /* Enable CE error interrupts */
  880. if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
  881. goto error_target_access;
  882. CE_ERROR_INTR_ENABLE(scn, ctrl_addr);
  883. if (Q_TARGET_ACCESS_END(scn) < 0)
  884. goto error_target_access;
  885. /* update the htt_data attribute */
  886. ce_mark_datapath(CE_state);
  887. return (struct CE_handle *)CE_state;
  888. error_target_access:
  889. error_no_dma_mem:
  890. ce_fini((struct CE_handle *)CE_state);
  891. return NULL;
  892. }
  893. #ifdef WLAN_FEATURE_FASTPATH
  894. /**
  895. * hif_enable_fastpath() Update that we have enabled fastpath mode
  896. * @hif_ctx: HIF context
  897. *
  898. * For use in data path
  899. *
  900. * Retrun: void
  901. */
  902. void hif_enable_fastpath(struct hif_opaque_softc *hif_ctx)
  903. {
  904. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  905. HIF_INFO("%s, Enabling fastpath mode", __func__);
  906. scn->fastpath_mode_on = true;
  907. }
  908. /**
  909. * hif_is_fastpath_mode_enabled - API to query if fasthpath mode is enabled
  910. * @hif_ctx: HIF Context
  911. *
  912. * For use in data path to skip HTC
  913. *
  914. * Return: bool
  915. */
  916. bool hif_is_fastpath_mode_enabled(struct hif_opaque_softc *hif_ctx)
  917. {
  918. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  919. return scn->fastpath_mode_on;
  920. }
  921. /**
  922. * hif_get_ce_handle - API to get CE handle for FastPath mode
  923. * @hif_ctx: HIF Context
  924. * @id: CopyEngine Id
  925. *
  926. * API to return CE handle for fastpath mode
  927. *
  928. * Return: void
  929. */
  930. void *hif_get_ce_handle(struct hif_opaque_softc *hif_ctx, int id)
  931. {
  932. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  933. return scn->ce_id_to_state[id];
  934. }
  935. /**
  936. * ce_h2t_tx_ce_cleanup() Place holder function for H2T CE cleanup.
  937. * No processing is required inside this function.
  938. * @ce_hdl: Cope engine handle
  939. * Using an assert, this function makes sure that,
  940. * the TX CE has been processed completely.
  941. *
  942. * This is called while dismantling CE structures. No other thread
  943. * should be using these structures while dismantling is occuring
  944. * therfore no locking is needed.
  945. *
  946. * Return: none
  947. */
  948. void
  949. ce_h2t_tx_ce_cleanup(struct CE_handle *ce_hdl)
  950. {
  951. struct CE_state *ce_state = (struct CE_state *)ce_hdl;
  952. struct CE_ring_state *src_ring = ce_state->src_ring;
  953. struct hif_softc *sc = ce_state->scn;
  954. uint32_t sw_index, write_index;
  955. if (hif_is_nss_wifi_enabled(sc))
  956. return;
  957. if (sc->fastpath_mode_on && ce_state->htt_tx_data) {
  958. HIF_INFO("%s %d Fastpath mode ON, Cleaning up HTT Tx CE",
  959. __func__, __LINE__);
  960. sw_index = src_ring->sw_index;
  961. write_index = src_ring->sw_index;
  962. /* At this point Tx CE should be clean */
  963. qdf_assert_always(sw_index == write_index);
  964. }
  965. }
  966. /**
  967. * ce_t2h_msg_ce_cleanup() - Cleanup buffers on the t2h datapath msg queue.
  968. * @ce_hdl: Handle to CE
  969. *
  970. * These buffers are never allocated on the fly, but
  971. * are allocated only once during HIF start and freed
  972. * only once during HIF stop.
  973. * NOTE:
  974. * The assumption here is there is no in-flight DMA in progress
  975. * currently, so that buffers can be freed up safely.
  976. *
  977. * Return: NONE
  978. */
  979. void ce_t2h_msg_ce_cleanup(struct CE_handle *ce_hdl)
  980. {
  981. struct CE_state *ce_state = (struct CE_state *)ce_hdl;
  982. struct CE_ring_state *dst_ring = ce_state->dest_ring;
  983. qdf_nbuf_t nbuf;
  984. int i;
  985. if (!ce_state->fastpath_handler)
  986. return;
  987. /*
  988. * when fastpath_mode is on and for datapath CEs. Unlike other CE's,
  989. * this CE is completely full: does not leave one blank space, to
  990. * distinguish between empty queue & full queue. So free all the
  991. * entries.
  992. */
  993. for (i = 0; i < dst_ring->nentries; i++) {
  994. nbuf = dst_ring->per_transfer_context[i];
  995. /*
  996. * The reasons for doing this check are:
  997. * 1) Protect against calling cleanup before allocating buffers
  998. * 2) In a corner case, FASTPATH_mode_on may be set, but we
  999. * could have a partially filled ring, because of a memory
  1000. * allocation failure in the middle of allocating ring.
  1001. * This check accounts for that case, checking
  1002. * fastpath_mode_on flag or started flag would not have
  1003. * covered that case. This is not in performance path,
  1004. * so OK to do this.
  1005. */
  1006. if (nbuf)
  1007. qdf_nbuf_free(nbuf);
  1008. }
  1009. }
  1010. /**
  1011. * hif_update_fastpath_recv_bufs_cnt() - Increments the Rx buf count by 1
  1012. * @scn: HIF handle
  1013. *
  1014. * Datapath Rx CEs are special case, where we reuse all the message buffers.
  1015. * Hence we have to post all the entries in the pipe, even, in the beginning
  1016. * unlike for other CE pipes where one less than dest_nentries are filled in
  1017. * the beginning.
  1018. *
  1019. * Return: None
  1020. */
  1021. static void hif_update_fastpath_recv_bufs_cnt(struct hif_softc *scn)
  1022. {
  1023. int pipe_num;
  1024. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  1025. if (scn->fastpath_mode_on == false)
  1026. return;
  1027. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  1028. struct HIF_CE_pipe_info *pipe_info =
  1029. &hif_state->pipe_info[pipe_num];
  1030. struct CE_state *ce_state =
  1031. scn->ce_id_to_state[pipe_info->pipe_num];
  1032. if (ce_state->htt_rx_data)
  1033. atomic_inc(&pipe_info->recv_bufs_needed);
  1034. }
  1035. }
  1036. #else
  1037. static inline void hif_update_fastpath_recv_bufs_cnt(struct hif_softc *scn)
  1038. {
  1039. }
  1040. static inline bool ce_is_fastpath_enabled(struct hif_softc *scn)
  1041. {
  1042. return false;
  1043. }
  1044. static inline bool ce_is_fastpath_handler_registered(struct CE_state *ce_state)
  1045. {
  1046. return false;
  1047. }
  1048. #endif /* WLAN_FEATURE_FASTPATH */
  1049. void ce_fini(struct CE_handle *copyeng)
  1050. {
  1051. struct CE_state *CE_state = (struct CE_state *)copyeng;
  1052. unsigned int CE_id = CE_state->id;
  1053. struct hif_softc *scn = CE_state->scn;
  1054. CE_state->state = CE_UNUSED;
  1055. scn->ce_id_to_state[CE_id] = NULL;
  1056. if (CE_state->src_ring) {
  1057. /* Cleanup the datapath Tx ring */
  1058. ce_h2t_tx_ce_cleanup(copyeng);
  1059. if (CE_state->src_ring->shadow_base_unaligned)
  1060. qdf_mem_free(CE_state->src_ring->shadow_base_unaligned);
  1061. if (CE_state->src_ring->base_addr_owner_space_unaligned)
  1062. qdf_mem_free_consistent(scn->qdf_dev,
  1063. scn->qdf_dev->dev,
  1064. (CE_state->src_ring->nentries *
  1065. sizeof(struct CE_src_desc) +
  1066. CE_DESC_RING_ALIGN),
  1067. CE_state->src_ring->
  1068. base_addr_owner_space_unaligned,
  1069. CE_state->src_ring->
  1070. base_addr_CE_space, 0);
  1071. qdf_mem_free(CE_state->src_ring);
  1072. }
  1073. if (CE_state->dest_ring) {
  1074. /* Cleanup the datapath Rx ring */
  1075. ce_t2h_msg_ce_cleanup(copyeng);
  1076. if (CE_state->dest_ring->base_addr_owner_space_unaligned)
  1077. qdf_mem_free_consistent(scn->qdf_dev,
  1078. scn->qdf_dev->dev,
  1079. (CE_state->dest_ring->nentries *
  1080. sizeof(struct CE_dest_desc) +
  1081. CE_DESC_RING_ALIGN),
  1082. CE_state->dest_ring->
  1083. base_addr_owner_space_unaligned,
  1084. CE_state->dest_ring->
  1085. base_addr_CE_space, 0);
  1086. qdf_mem_free(CE_state->dest_ring);
  1087. /* epping */
  1088. if (CE_state->timer_inited) {
  1089. CE_state->timer_inited = false;
  1090. qdf_timer_free(&CE_state->poll_timer);
  1091. }
  1092. }
  1093. qdf_mem_free(CE_state);
  1094. }
  1095. void hif_detach_htc(struct hif_opaque_softc *hif_ctx)
  1096. {
  1097. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
  1098. qdf_mem_zero(&hif_state->msg_callbacks_pending,
  1099. sizeof(hif_state->msg_callbacks_pending));
  1100. qdf_mem_zero(&hif_state->msg_callbacks_current,
  1101. sizeof(hif_state->msg_callbacks_current));
  1102. }
  1103. /* Send the first nbytes bytes of the buffer */
  1104. QDF_STATUS
  1105. hif_send_head(struct hif_opaque_softc *hif_ctx,
  1106. uint8_t pipe, unsigned int transfer_id, unsigned int nbytes,
  1107. qdf_nbuf_t nbuf, unsigned int data_attr)
  1108. {
  1109. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  1110. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
  1111. struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
  1112. struct CE_handle *ce_hdl = pipe_info->ce_hdl;
  1113. int bytes = nbytes, nfrags = 0;
  1114. struct ce_sendlist sendlist;
  1115. int status, i = 0;
  1116. unsigned int mux_id = 0;
  1117. QDF_ASSERT(nbytes <= qdf_nbuf_len(nbuf));
  1118. transfer_id =
  1119. (mux_id & MUX_ID_MASK) |
  1120. (transfer_id & TRANSACTION_ID_MASK);
  1121. data_attr &= DESC_DATA_FLAG_MASK;
  1122. /*
  1123. * The common case involves sending multiple fragments within a
  1124. * single download (the tx descriptor and the tx frame header).
  1125. * So, optimize for the case of multiple fragments by not even
  1126. * checking whether it's necessary to use a sendlist.
  1127. * The overhead of using a sendlist for a single buffer download
  1128. * is not a big deal, since it happens rarely (for WMI messages).
  1129. */
  1130. ce_sendlist_init(&sendlist);
  1131. do {
  1132. qdf_dma_addr_t frag_paddr;
  1133. int frag_bytes;
  1134. frag_paddr = qdf_nbuf_get_frag_paddr(nbuf, nfrags);
  1135. frag_bytes = qdf_nbuf_get_frag_len(nbuf, nfrags);
  1136. /*
  1137. * Clear the packet offset for all but the first CE desc.
  1138. */
  1139. if (i++ > 0)
  1140. data_attr &= ~QDF_CE_TX_PKT_OFFSET_BIT_M;
  1141. status = ce_sendlist_buf_add(&sendlist, frag_paddr,
  1142. frag_bytes >
  1143. bytes ? bytes : frag_bytes,
  1144. qdf_nbuf_get_frag_is_wordstream
  1145. (nbuf,
  1146. nfrags) ? 0 :
  1147. CE_SEND_FLAG_SWAP_DISABLE,
  1148. data_attr);
  1149. if (status != QDF_STATUS_SUCCESS) {
  1150. HIF_ERROR("%s: error, frag_num %d larger than limit",
  1151. __func__, nfrags);
  1152. return status;
  1153. }
  1154. bytes -= frag_bytes;
  1155. nfrags++;
  1156. } while (bytes > 0);
  1157. /* Make sure we have resources to handle this request */
  1158. qdf_spin_lock_bh(&pipe_info->completion_freeq_lock);
  1159. if (pipe_info->num_sends_allowed < nfrags) {
  1160. qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
  1161. ce_pkt_error_count_incr(hif_state, HIF_PIPE_NO_RESOURCE);
  1162. return QDF_STATUS_E_RESOURCES;
  1163. }
  1164. pipe_info->num_sends_allowed -= nfrags;
  1165. qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
  1166. if (qdf_unlikely(ce_hdl == NULL)) {
  1167. HIF_ERROR("%s: error CE handle is null", __func__);
  1168. return A_ERROR;
  1169. }
  1170. QDF_NBUF_UPDATE_TX_PKT_COUNT(nbuf, QDF_NBUF_TX_PKT_HIF);
  1171. DPTRACE(qdf_dp_trace(nbuf, QDF_DP_TRACE_HIF_PACKET_PTR_RECORD,
  1172. qdf_nbuf_data_addr(nbuf),
  1173. sizeof(qdf_nbuf_data(nbuf)), QDF_TX));
  1174. status = ce_sendlist_send(ce_hdl, nbuf, &sendlist, transfer_id);
  1175. QDF_ASSERT(status == QDF_STATUS_SUCCESS);
  1176. return status;
  1177. }
  1178. void hif_send_complete_check(struct hif_opaque_softc *hif_ctx, uint8_t pipe,
  1179. int force)
  1180. {
  1181. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  1182. if (!force) {
  1183. int resources;
  1184. /*
  1185. * Decide whether to actually poll for completions, or just
  1186. * wait for a later chance. If there seem to be plenty of
  1187. * resources left, then just wait, since checking involves
  1188. * reading a CE register, which is a relatively expensive
  1189. * operation.
  1190. */
  1191. resources = hif_get_free_queue_number(hif_ctx, pipe);
  1192. /*
  1193. * If at least 50% of the total resources are still available,
  1194. * don't bother checking again yet.
  1195. */
  1196. if (resources > (host_ce_config[pipe].src_nentries >> 1)) {
  1197. return;
  1198. }
  1199. }
  1200. #if ATH_11AC_TXCOMPACT
  1201. ce_per_engine_servicereap(scn, pipe);
  1202. #else
  1203. ce_per_engine_service(scn, pipe);
  1204. #endif
  1205. }
  1206. uint16_t
  1207. hif_get_free_queue_number(struct hif_opaque_softc *hif_ctx, uint8_t pipe)
  1208. {
  1209. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
  1210. struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
  1211. uint16_t rv;
  1212. qdf_spin_lock_bh(&pipe_info->completion_freeq_lock);
  1213. rv = pipe_info->num_sends_allowed;
  1214. qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
  1215. return rv;
  1216. }
  1217. /* Called by lower (CE) layer when a send to Target completes. */
  1218. void
  1219. hif_pci_ce_send_done(struct CE_handle *copyeng, void *ce_context,
  1220. void *transfer_context, qdf_dma_addr_t CE_data,
  1221. unsigned int nbytes, unsigned int transfer_id,
  1222. unsigned int sw_index, unsigned int hw_index,
  1223. unsigned int toeplitz_hash_result)
  1224. {
  1225. struct HIF_CE_pipe_info *pipe_info =
  1226. (struct HIF_CE_pipe_info *)ce_context;
  1227. struct HIF_CE_state *hif_state = pipe_info->HIF_CE_state;
  1228. struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
  1229. unsigned int sw_idx = sw_index, hw_idx = hw_index;
  1230. struct hif_msg_callbacks *msg_callbacks =
  1231. &hif_state->msg_callbacks_current;
  1232. do {
  1233. /*
  1234. * The upper layer callback will be triggered
  1235. * when last fragment is complteted.
  1236. */
  1237. if (transfer_context != CE_SENDLIST_ITEM_CTXT) {
  1238. if (scn->target_status == TARGET_STATUS_RESET)
  1239. qdf_nbuf_free(transfer_context);
  1240. else
  1241. msg_callbacks->txCompletionHandler(
  1242. msg_callbacks->Context,
  1243. transfer_context, transfer_id,
  1244. toeplitz_hash_result);
  1245. }
  1246. qdf_spin_lock(&pipe_info->completion_freeq_lock);
  1247. pipe_info->num_sends_allowed++;
  1248. qdf_spin_unlock(&pipe_info->completion_freeq_lock);
  1249. } while (ce_completed_send_next(copyeng,
  1250. &ce_context, &transfer_context,
  1251. &CE_data, &nbytes, &transfer_id,
  1252. &sw_idx, &hw_idx,
  1253. &toeplitz_hash_result) == QDF_STATUS_SUCCESS);
  1254. }
  1255. /**
  1256. * hif_ce_do_recv(): send message from copy engine to upper layers
  1257. * @msg_callbacks: structure containing callback and callback context
  1258. * @netbuff: skb containing message
  1259. * @nbytes: number of bytes in the message
  1260. * @pipe_info: used for the pipe_number info
  1261. *
  1262. * Checks the packet length, configures the lenght in the netbuff,
  1263. * and calls the upper layer callback.
  1264. *
  1265. * return: None
  1266. */
  1267. static inline void hif_ce_do_recv(struct hif_msg_callbacks *msg_callbacks,
  1268. qdf_nbuf_t netbuf, int nbytes,
  1269. struct HIF_CE_pipe_info *pipe_info) {
  1270. if (nbytes <= pipe_info->buf_sz) {
  1271. qdf_nbuf_set_pktlen(netbuf, nbytes);
  1272. msg_callbacks->
  1273. rxCompletionHandler(msg_callbacks->Context,
  1274. netbuf, pipe_info->pipe_num);
  1275. } else {
  1276. HIF_ERROR("%s: Invalid Rx msg buf:%p nbytes:%d",
  1277. __func__, netbuf, nbytes);
  1278. qdf_nbuf_free(netbuf);
  1279. }
  1280. }
  1281. /* Called by lower (CE) layer when data is received from the Target. */
  1282. void
  1283. hif_pci_ce_recv_data(struct CE_handle *copyeng, void *ce_context,
  1284. void *transfer_context, qdf_dma_addr_t CE_data,
  1285. unsigned int nbytes, unsigned int transfer_id,
  1286. unsigned int flags)
  1287. {
  1288. struct HIF_CE_pipe_info *pipe_info =
  1289. (struct HIF_CE_pipe_info *)ce_context;
  1290. struct HIF_CE_state *hif_state = pipe_info->HIF_CE_state;
  1291. struct CE_state *ce_state = (struct CE_state *) copyeng;
  1292. struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
  1293. #ifdef HIF_PCI
  1294. struct hif_pci_softc *hif_pci_sc = HIF_GET_PCI_SOFTC(hif_state);
  1295. #endif
  1296. struct hif_msg_callbacks *msg_callbacks =
  1297. &hif_state->msg_callbacks_current;
  1298. do {
  1299. #ifdef HIF_PCI
  1300. hif_pm_runtime_mark_last_busy(hif_pci_sc->dev);
  1301. #endif
  1302. qdf_nbuf_unmap_single(scn->qdf_dev,
  1303. (qdf_nbuf_t) transfer_context,
  1304. QDF_DMA_FROM_DEVICE);
  1305. atomic_inc(&pipe_info->recv_bufs_needed);
  1306. hif_post_recv_buffers_for_pipe(pipe_info);
  1307. if (scn->target_status == TARGET_STATUS_RESET)
  1308. qdf_nbuf_free(transfer_context);
  1309. else
  1310. hif_ce_do_recv(msg_callbacks, transfer_context,
  1311. nbytes, pipe_info);
  1312. /* Set up force_break flag if num of receices reaches
  1313. * MAX_NUM_OF_RECEIVES */
  1314. ce_state->receive_count++;
  1315. if (qdf_unlikely(hif_ce_service_should_yield(scn, ce_state))) {
  1316. ce_state->force_break = 1;
  1317. break;
  1318. }
  1319. } while (ce_completed_recv_next(copyeng, &ce_context, &transfer_context,
  1320. &CE_data, &nbytes, &transfer_id,
  1321. &flags) == QDF_STATUS_SUCCESS);
  1322. }
  1323. /* TBDXXX: Set CE High Watermark; invoke txResourceAvailHandler in response */
  1324. void
  1325. hif_post_init(struct hif_opaque_softc *hif_ctx, void *unused,
  1326. struct hif_msg_callbacks *callbacks)
  1327. {
  1328. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
  1329. #ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
  1330. spin_lock_init(&pcie_access_log_lock);
  1331. #endif
  1332. /* Save callbacks for later installation */
  1333. qdf_mem_copy(&hif_state->msg_callbacks_pending, callbacks,
  1334. sizeof(hif_state->msg_callbacks_pending));
  1335. }
  1336. int hif_completion_thread_startup(struct HIF_CE_state *hif_state)
  1337. {
  1338. struct CE_handle *ce_diag = hif_state->ce_diag;
  1339. int pipe_num;
  1340. struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
  1341. struct hif_msg_callbacks *hif_msg_callbacks =
  1342. &hif_state->msg_callbacks_current;
  1343. /* daemonize("hif_compl_thread"); */
  1344. if (scn->ce_count == 0) {
  1345. HIF_ERROR("%s: Invalid ce_count", __func__);
  1346. return -EINVAL;
  1347. }
  1348. if (!hif_msg_callbacks ||
  1349. !hif_msg_callbacks->rxCompletionHandler ||
  1350. !hif_msg_callbacks->txCompletionHandler) {
  1351. HIF_ERROR("%s: no completion handler registered", __func__);
  1352. return -EFAULT;
  1353. }
  1354. A_TARGET_ACCESS_LIKELY(scn);
  1355. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  1356. struct CE_attr attr;
  1357. struct HIF_CE_pipe_info *pipe_info;
  1358. pipe_info = &hif_state->pipe_info[pipe_num];
  1359. if (pipe_info->ce_hdl == ce_diag) {
  1360. continue; /* Handle Diagnostic CE specially */
  1361. }
  1362. attr = host_ce_config[pipe_num];
  1363. if (attr.src_nentries) {
  1364. /* pipe used to send to target */
  1365. HIF_INFO_MED("%s: pipe_num:%d pipe_info:0x%p",
  1366. __func__, pipe_num, pipe_info);
  1367. ce_send_cb_register(pipe_info->ce_hdl,
  1368. hif_pci_ce_send_done, pipe_info,
  1369. attr.flags & CE_ATTR_DISABLE_INTR);
  1370. pipe_info->num_sends_allowed = attr.src_nentries - 1;
  1371. }
  1372. if (attr.dest_nentries) {
  1373. /* pipe used to receive from target */
  1374. ce_recv_cb_register(pipe_info->ce_hdl,
  1375. hif_pci_ce_recv_data, pipe_info,
  1376. attr.flags & CE_ATTR_DISABLE_INTR);
  1377. }
  1378. if (attr.src_nentries)
  1379. qdf_spinlock_create(&pipe_info->completion_freeq_lock);
  1380. }
  1381. A_TARGET_ACCESS_UNLIKELY(scn);
  1382. return 0;
  1383. }
  1384. /*
  1385. * Install pending msg callbacks.
  1386. *
  1387. * TBDXXX: This hack is needed because upper layers install msg callbacks
  1388. * for use with HTC before BMI is done; yet this HIF implementation
  1389. * needs to continue to use BMI msg callbacks. Really, upper layers
  1390. * should not register HTC callbacks until AFTER BMI phase.
  1391. */
  1392. static void hif_msg_callbacks_install(struct hif_softc *scn)
  1393. {
  1394. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  1395. qdf_mem_copy(&hif_state->msg_callbacks_current,
  1396. &hif_state->msg_callbacks_pending,
  1397. sizeof(hif_state->msg_callbacks_pending));
  1398. }
  1399. void hif_get_default_pipe(struct hif_opaque_softc *hif_hdl, uint8_t *ULPipe,
  1400. uint8_t *DLPipe)
  1401. {
  1402. int ul_is_polled, dl_is_polled;
  1403. (void)hif_map_service_to_pipe(hif_hdl, HTC_CTRL_RSVD_SVC,
  1404. ULPipe, DLPipe, &ul_is_polled, &dl_is_polled);
  1405. }
  1406. /**
  1407. * hif_dump_pipe_debug_count() - Log error count
  1408. * @scn: hif_softc pointer.
  1409. *
  1410. * Output the pipe error counts of each pipe to log file
  1411. *
  1412. * Return: N/A
  1413. */
  1414. void hif_dump_pipe_debug_count(struct hif_softc *scn)
  1415. {
  1416. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  1417. int pipe_num;
  1418. if (hif_state == NULL) {
  1419. HIF_ERROR("%s hif_state is NULL", __func__);
  1420. return;
  1421. }
  1422. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  1423. struct HIF_CE_pipe_info *pipe_info;
  1424. pipe_info = &hif_state->pipe_info[pipe_num];
  1425. if (pipe_info->nbuf_alloc_err_count > 0 ||
  1426. pipe_info->nbuf_dma_err_count > 0 ||
  1427. pipe_info->nbuf_ce_enqueue_err_count)
  1428. HIF_ERROR(
  1429. "%s: pipe_id = %d, recv_bufs_needed = %d, nbuf_alloc_err_count = %u, nbuf_dma_err_count = %u, nbuf_ce_enqueue_err_count = %u",
  1430. __func__, pipe_info->pipe_num,
  1431. atomic_read(&pipe_info->recv_bufs_needed),
  1432. pipe_info->nbuf_alloc_err_count,
  1433. pipe_info->nbuf_dma_err_count,
  1434. pipe_info->nbuf_ce_enqueue_err_count);
  1435. }
  1436. }
  1437. static int hif_post_recv_buffers_for_pipe(struct HIF_CE_pipe_info *pipe_info)
  1438. {
  1439. struct CE_handle *ce_hdl;
  1440. qdf_size_t buf_sz;
  1441. struct hif_softc *scn = HIF_GET_SOFTC(pipe_info->HIF_CE_state);
  1442. QDF_STATUS ret;
  1443. uint32_t bufs_posted = 0;
  1444. buf_sz = pipe_info->buf_sz;
  1445. if (buf_sz == 0) {
  1446. /* Unused Copy Engine */
  1447. return 0;
  1448. }
  1449. ce_hdl = pipe_info->ce_hdl;
  1450. qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
  1451. while (atomic_read(&pipe_info->recv_bufs_needed) > 0) {
  1452. qdf_dma_addr_t CE_data; /* CE space buffer address */
  1453. qdf_nbuf_t nbuf;
  1454. int status;
  1455. atomic_dec(&pipe_info->recv_bufs_needed);
  1456. qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
  1457. nbuf = qdf_nbuf_alloc(scn->qdf_dev, buf_sz, 0, 4, false);
  1458. if (!nbuf) {
  1459. qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
  1460. pipe_info->nbuf_alloc_err_count++;
  1461. qdf_spin_unlock_bh(
  1462. &pipe_info->recv_bufs_needed_lock);
  1463. HIF_ERROR(
  1464. "%s buf alloc error [%d] needed %d, nbuf_alloc_err_count = %u",
  1465. __func__, pipe_info->pipe_num,
  1466. atomic_read(&pipe_info->recv_bufs_needed),
  1467. pipe_info->nbuf_alloc_err_count);
  1468. atomic_inc(&pipe_info->recv_bufs_needed);
  1469. return 1;
  1470. }
  1471. /*
  1472. * qdf_nbuf_peek_header(nbuf, &data, &unused);
  1473. * CE_data = dma_map_single(dev, data, buf_sz, );
  1474. * DMA_FROM_DEVICE);
  1475. */
  1476. ret =
  1477. qdf_nbuf_map_single(scn->qdf_dev, nbuf,
  1478. QDF_DMA_FROM_DEVICE);
  1479. if (unlikely(ret != QDF_STATUS_SUCCESS)) {
  1480. qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
  1481. pipe_info->nbuf_dma_err_count++;
  1482. qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
  1483. HIF_ERROR(
  1484. "%s buf alloc error [%d] needed %d, nbuf_dma_err_count = %u",
  1485. __func__, pipe_info->pipe_num,
  1486. atomic_read(&pipe_info->recv_bufs_needed),
  1487. pipe_info->nbuf_dma_err_count);
  1488. qdf_nbuf_free(nbuf);
  1489. atomic_inc(&pipe_info->recv_bufs_needed);
  1490. return 1;
  1491. }
  1492. CE_data = qdf_nbuf_get_frag_paddr(nbuf, 0);
  1493. qdf_mem_dma_sync_single_for_device(scn->qdf_dev, CE_data,
  1494. buf_sz, DMA_FROM_DEVICE);
  1495. status = ce_recv_buf_enqueue(ce_hdl, (void *)nbuf, CE_data);
  1496. QDF_ASSERT(status == QDF_STATUS_SUCCESS);
  1497. if (status != EOK) {
  1498. qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
  1499. pipe_info->nbuf_ce_enqueue_err_count++;
  1500. qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
  1501. HIF_ERROR(
  1502. "%s buf alloc error [%d] needed %d, nbuf_alloc_err_count = %u",
  1503. __func__, pipe_info->pipe_num,
  1504. atomic_read(&pipe_info->recv_bufs_needed),
  1505. pipe_info->nbuf_ce_enqueue_err_count);
  1506. qdf_nbuf_unmap_single(scn->qdf_dev, nbuf,
  1507. QDF_DMA_FROM_DEVICE);
  1508. atomic_inc(&pipe_info->recv_bufs_needed);
  1509. qdf_nbuf_free(nbuf);
  1510. return 1;
  1511. }
  1512. qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
  1513. bufs_posted++;
  1514. }
  1515. pipe_info->nbuf_alloc_err_count =
  1516. (pipe_info->nbuf_alloc_err_count > bufs_posted) ?
  1517. pipe_info->nbuf_alloc_err_count - bufs_posted : 0;
  1518. pipe_info->nbuf_dma_err_count =
  1519. (pipe_info->nbuf_dma_err_count > bufs_posted) ?
  1520. pipe_info->nbuf_dma_err_count - bufs_posted : 0;
  1521. pipe_info->nbuf_ce_enqueue_err_count =
  1522. (pipe_info->nbuf_ce_enqueue_err_count > bufs_posted) ?
  1523. pipe_info->nbuf_ce_enqueue_err_count - bufs_posted : 0;
  1524. qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
  1525. return 0;
  1526. }
  1527. /*
  1528. * Try to post all desired receive buffers for all pipes.
  1529. * Returns 0 if all desired buffers are posted,
  1530. * non-zero if were were unable to completely
  1531. * replenish receive buffers.
  1532. */
  1533. static int hif_post_recv_buffers(struct hif_softc *scn)
  1534. {
  1535. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  1536. int pipe_num, rv = 0;
  1537. struct CE_state *ce_state;
  1538. A_TARGET_ACCESS_LIKELY(scn);
  1539. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  1540. struct HIF_CE_pipe_info *pipe_info;
  1541. ce_state = scn->ce_id_to_state[pipe_num];
  1542. pipe_info = &hif_state->pipe_info[pipe_num];
  1543. if (hif_is_nss_wifi_enabled(scn) &&
  1544. ce_state && (ce_state->htt_rx_data)) {
  1545. continue;
  1546. }
  1547. if (hif_post_recv_buffers_for_pipe(pipe_info)) {
  1548. rv = 1;
  1549. goto done;
  1550. }
  1551. }
  1552. done:
  1553. A_TARGET_ACCESS_UNLIKELY(scn);
  1554. return rv;
  1555. }
  1556. QDF_STATUS hif_start(struct hif_opaque_softc *hif_ctx)
  1557. {
  1558. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  1559. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  1560. hif_update_fastpath_recv_bufs_cnt(scn);
  1561. hif_msg_callbacks_install(scn);
  1562. if (hif_completion_thread_startup(hif_state))
  1563. return QDF_STATUS_E_FAILURE;
  1564. /* Post buffers once to start things off. */
  1565. (void)hif_post_recv_buffers(scn);
  1566. hif_state->started = true;
  1567. return QDF_STATUS_SUCCESS;
  1568. }
  1569. void hif_recv_buffer_cleanup_on_pipe(struct HIF_CE_pipe_info *pipe_info)
  1570. {
  1571. struct hif_softc *scn;
  1572. struct CE_handle *ce_hdl;
  1573. uint32_t buf_sz;
  1574. struct HIF_CE_state *hif_state;
  1575. qdf_nbuf_t netbuf;
  1576. qdf_dma_addr_t CE_data;
  1577. void *per_CE_context;
  1578. buf_sz = pipe_info->buf_sz;
  1579. if (buf_sz == 0) {
  1580. /* Unused Copy Engine */
  1581. return;
  1582. }
  1583. hif_state = pipe_info->HIF_CE_state;
  1584. if (!hif_state->started) {
  1585. return;
  1586. }
  1587. scn = HIF_GET_SOFTC(hif_state);
  1588. ce_hdl = pipe_info->ce_hdl;
  1589. if (scn->qdf_dev == NULL) {
  1590. return;
  1591. }
  1592. while (ce_revoke_recv_next
  1593. (ce_hdl, &per_CE_context, (void **)&netbuf,
  1594. &CE_data) == QDF_STATUS_SUCCESS) {
  1595. qdf_nbuf_unmap_single(scn->qdf_dev, netbuf,
  1596. QDF_DMA_FROM_DEVICE);
  1597. qdf_nbuf_free(netbuf);
  1598. }
  1599. }
  1600. void hif_send_buffer_cleanup_on_pipe(struct HIF_CE_pipe_info *pipe_info)
  1601. {
  1602. struct CE_handle *ce_hdl;
  1603. struct HIF_CE_state *hif_state;
  1604. struct hif_softc *scn;
  1605. qdf_nbuf_t netbuf;
  1606. void *per_CE_context;
  1607. qdf_dma_addr_t CE_data;
  1608. unsigned int nbytes;
  1609. unsigned int id;
  1610. uint32_t buf_sz;
  1611. uint32_t toeplitz_hash_result;
  1612. buf_sz = pipe_info->buf_sz;
  1613. if (buf_sz == 0) {
  1614. /* Unused Copy Engine */
  1615. return;
  1616. }
  1617. hif_state = pipe_info->HIF_CE_state;
  1618. if (!hif_state->started) {
  1619. return;
  1620. }
  1621. scn = HIF_GET_SOFTC(hif_state);
  1622. ce_hdl = pipe_info->ce_hdl;
  1623. while (ce_cancel_send_next
  1624. (ce_hdl, &per_CE_context,
  1625. (void **)&netbuf, &CE_data, &nbytes,
  1626. &id, &toeplitz_hash_result) == QDF_STATUS_SUCCESS) {
  1627. if (netbuf != CE_SENDLIST_ITEM_CTXT) {
  1628. /*
  1629. * Packets enqueued by htt_h2t_ver_req_msg() and
  1630. * htt_h2t_rx_ring_cfg_msg_ll() have already been
  1631. * freed in htt_htc_misc_pkt_pool_free() in
  1632. * wlantl_close(), so do not free them here again
  1633. * by checking whether it's the endpoint
  1634. * which they are queued in.
  1635. */
  1636. if (id == scn->htc_htt_tx_endpoint)
  1637. return;
  1638. /* Indicate the completion to higher
  1639. * layer to free the buffer */
  1640. if (hif_state->msg_callbacks_current.
  1641. txCompletionHandler)
  1642. hif_state->msg_callbacks_current.
  1643. txCompletionHandler(hif_state->
  1644. msg_callbacks_current.Context,
  1645. netbuf, id, toeplitz_hash_result);
  1646. }
  1647. }
  1648. }
  1649. /*
  1650. * Cleanup residual buffers for device shutdown:
  1651. * buffers that were enqueued for receive
  1652. * buffers that were to be sent
  1653. * Note: Buffers that had completed but which were
  1654. * not yet processed are on a completion queue. They
  1655. * are handled when the completion thread shuts down.
  1656. */
  1657. void hif_buffer_cleanup(struct HIF_CE_state *hif_state)
  1658. {
  1659. int pipe_num;
  1660. struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
  1661. struct CE_state *ce_state;
  1662. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  1663. struct HIF_CE_pipe_info *pipe_info;
  1664. ce_state = scn->ce_id_to_state[pipe_num];
  1665. if (hif_is_nss_wifi_enabled(scn) && ce_state &&
  1666. ((ce_state->htt_tx_data) ||
  1667. (ce_state->htt_rx_data))) {
  1668. continue;
  1669. }
  1670. pipe_info = &hif_state->pipe_info[pipe_num];
  1671. hif_recv_buffer_cleanup_on_pipe(pipe_info);
  1672. hif_send_buffer_cleanup_on_pipe(pipe_info);
  1673. }
  1674. }
  1675. void hif_flush_surprise_remove(struct hif_opaque_softc *hif_ctx)
  1676. {
  1677. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  1678. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  1679. hif_buffer_cleanup(hif_state);
  1680. }
  1681. void hif_ce_stop(struct hif_softc *scn)
  1682. {
  1683. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  1684. int pipe_num;
  1685. scn->hif_init_done = false;
  1686. /*
  1687. * At this point, asynchronous threads are stopped,
  1688. * The Target should not DMA nor interrupt, Host code may
  1689. * not initiate anything more. So we just need to clean
  1690. * up Host-side state.
  1691. */
  1692. if (scn->athdiag_procfs_inited) {
  1693. athdiag_procfs_remove();
  1694. scn->athdiag_procfs_inited = false;
  1695. }
  1696. hif_buffer_cleanup(hif_state);
  1697. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  1698. struct HIF_CE_pipe_info *pipe_info;
  1699. pipe_info = &hif_state->pipe_info[pipe_num];
  1700. if (pipe_info->ce_hdl) {
  1701. ce_fini(pipe_info->ce_hdl);
  1702. pipe_info->ce_hdl = NULL;
  1703. pipe_info->buf_sz = 0;
  1704. }
  1705. }
  1706. if (hif_state->sleep_timer_init) {
  1707. qdf_timer_stop(&hif_state->sleep_timer);
  1708. qdf_timer_free(&hif_state->sleep_timer);
  1709. hif_state->sleep_timer_init = false;
  1710. }
  1711. hif_state->started = false;
  1712. }
  1713. /**
  1714. * hif_get_target_ce_config() - get copy engine configuration
  1715. * @target_ce_config_ret: basic copy engine configuration
  1716. * @target_ce_config_sz_ret: size of the basic configuration in bytes
  1717. * @target_service_to_ce_map_ret: service mapping for the copy engines
  1718. * @target_service_to_ce_map_sz_ret: size of the mapping in bytes
  1719. * @target_shadow_reg_cfg_ret: shadow register configuration
  1720. * @shadow_cfg_sz_ret: size of the shadow register configuration in bytes
  1721. *
  1722. * providing accessor to these values outside of this file.
  1723. * currently these are stored in static pointers to const sections.
  1724. * there are multiple configurations that are selected from at compile time.
  1725. * Runtime selection would need to consider mode, target type and bus type.
  1726. *
  1727. * Return: return by parameter.
  1728. */
  1729. void hif_get_target_ce_config(struct CE_pipe_config **target_ce_config_ret,
  1730. int *target_ce_config_sz_ret,
  1731. struct service_to_pipe **target_service_to_ce_map_ret,
  1732. int *target_service_to_ce_map_sz_ret,
  1733. struct shadow_reg_cfg **target_shadow_reg_cfg_ret,
  1734. int *shadow_cfg_sz_ret)
  1735. {
  1736. *target_ce_config_ret = target_ce_config;
  1737. *target_ce_config_sz_ret = target_ce_config_sz;
  1738. *target_service_to_ce_map_ret = target_service_to_ce_map;
  1739. *target_service_to_ce_map_sz_ret = target_service_to_ce_map_sz;
  1740. if (target_shadow_reg_cfg_ret)
  1741. *target_shadow_reg_cfg_ret = target_shadow_reg_cfg;
  1742. if (shadow_cfg_sz_ret)
  1743. *shadow_cfg_sz_ret = shadow_cfg_sz;
  1744. }
  1745. /**
  1746. * hif_wlan_enable(): call the platform driver to enable wlan
  1747. * @scn: HIF Context
  1748. *
  1749. * This function passes the con_mode and CE configuration to
  1750. * platform driver to enable wlan.
  1751. *
  1752. * Return: linux error code
  1753. */
  1754. int hif_wlan_enable(struct hif_softc *scn)
  1755. {
  1756. struct pld_wlan_enable_cfg cfg;
  1757. enum pld_driver_mode mode;
  1758. uint32_t con_mode = hif_get_conparam(scn);
  1759. hif_get_target_ce_config((struct CE_pipe_config **)&cfg.ce_tgt_cfg,
  1760. &cfg.num_ce_tgt_cfg,
  1761. (struct service_to_pipe **)&cfg.ce_svc_cfg,
  1762. &cfg.num_ce_svc_pipe_cfg,
  1763. (struct shadow_reg_cfg **)&cfg.shadow_reg_cfg,
  1764. &cfg.num_shadow_reg_cfg);
  1765. /* translate from structure size to array size */
  1766. cfg.num_ce_tgt_cfg /= sizeof(struct CE_pipe_config);
  1767. cfg.num_ce_svc_pipe_cfg /= sizeof(struct service_to_pipe);
  1768. cfg.num_shadow_reg_cfg /= sizeof(struct shadow_reg_cfg);
  1769. if (QDF_GLOBAL_FTM_MODE == con_mode)
  1770. mode = PLD_FTM;
  1771. else if (QDF_IS_EPPING_ENABLED(con_mode))
  1772. mode = PLD_EPPING;
  1773. else
  1774. mode = PLD_MISSION;
  1775. if (BYPASS_QMI)
  1776. return 0;
  1777. else
  1778. return pld_wlan_enable(scn->qdf_dev->dev, &cfg,
  1779. mode, QWLAN_VERSIONSTR);
  1780. }
  1781. #define CE_EPPING_USES_IRQ true
  1782. /**
  1783. * hif_ce_prepare_config() - load the correct static tables.
  1784. * @scn: hif context
  1785. *
  1786. * Epping uses different static attribute tables than mission mode.
  1787. */
  1788. void hif_ce_prepare_config(struct hif_softc *scn)
  1789. {
  1790. uint32_t mode = hif_get_conparam(scn);
  1791. struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
  1792. struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl);
  1793. /* if epping is enabled we need to use the epping configuration. */
  1794. if (QDF_IS_EPPING_ENABLED(mode)) {
  1795. if (CE_EPPING_USES_IRQ)
  1796. host_ce_config = host_ce_config_wlan_epping_irq;
  1797. else
  1798. host_ce_config = host_ce_config_wlan_epping_poll;
  1799. target_ce_config = target_ce_config_wlan_epping;
  1800. target_ce_config_sz = sizeof(target_ce_config_wlan_epping);
  1801. target_service_to_ce_map =
  1802. target_service_to_ce_map_wlan_epping;
  1803. target_service_to_ce_map_sz =
  1804. sizeof(target_service_to_ce_map_wlan_epping);
  1805. target_shadow_reg_cfg = target_shadow_reg_cfg_epping;
  1806. shadow_cfg_sz = sizeof(target_shadow_reg_cfg_epping);
  1807. }
  1808. switch (tgt_info->target_type) {
  1809. default:
  1810. break;
  1811. case TARGET_TYPE_AR900B:
  1812. case TARGET_TYPE_QCA9984:
  1813. case TARGET_TYPE_IPQ4019:
  1814. case TARGET_TYPE_QCA9888:
  1815. host_ce_config = host_ce_config_wlan_ar900b;
  1816. target_ce_config = target_ce_config_wlan_ar900b;
  1817. target_ce_config_sz = sizeof(target_ce_config_wlan_ar900b);
  1818. target_service_to_ce_map = target_service_to_ce_map_ar900b;
  1819. target_service_to_ce_map_sz =
  1820. sizeof(target_service_to_ce_map_ar900b);
  1821. break;
  1822. case TARGET_TYPE_AR9888:
  1823. case TARGET_TYPE_AR9888V2:
  1824. host_ce_config = host_ce_config_wlan_ar9888;
  1825. target_ce_config = target_ce_config_wlan_ar9888;
  1826. target_ce_config_sz = sizeof(target_ce_config_wlan_ar9888);
  1827. target_service_to_ce_map = target_service_to_ce_map_ar900b;
  1828. target_service_to_ce_map_sz =
  1829. sizeof(target_service_to_ce_map_ar900b);
  1830. break;
  1831. }
  1832. }
  1833. /**
  1834. * hif_ce_open() - do ce specific allocations
  1835. * @hif_sc: pointer to hif context
  1836. *
  1837. * return: 0 for success or QDF_STATUS_E_NOMEM
  1838. */
  1839. QDF_STATUS hif_ce_open(struct hif_softc *hif_sc)
  1840. {
  1841. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc);
  1842. qdf_spinlock_create(&hif_state->keep_awake_lock);
  1843. return QDF_STATUS_SUCCESS;
  1844. }
  1845. /**
  1846. * hif_ce_close() - do ce specific free
  1847. * @hif_sc: pointer to hif context
  1848. */
  1849. void hif_ce_close(struct hif_softc *hif_sc)
  1850. {
  1851. }
  1852. /**
  1853. * hif_unconfig_ce() - ensure resources from hif_config_ce are freed
  1854. * @hif_sc: hif context
  1855. *
  1856. * uses state variables to support cleaning up when hif_config_ce fails.
  1857. */
  1858. void hif_unconfig_ce(struct hif_softc *hif_sc)
  1859. {
  1860. int pipe_num;
  1861. struct HIF_CE_pipe_info *pipe_info;
  1862. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc);
  1863. for (pipe_num = 0; pipe_num < hif_sc->ce_count; pipe_num++) {
  1864. pipe_info = &hif_state->pipe_info[pipe_num];
  1865. if (pipe_info->ce_hdl) {
  1866. ce_unregister_irq(hif_state, (1 << pipe_num));
  1867. hif_sc->request_irq_done = false;
  1868. ce_fini(pipe_info->ce_hdl);
  1869. pipe_info->ce_hdl = NULL;
  1870. pipe_info->buf_sz = 0;
  1871. }
  1872. }
  1873. if (hif_sc->athdiag_procfs_inited) {
  1874. athdiag_procfs_remove();
  1875. hif_sc->athdiag_procfs_inited = false;
  1876. }
  1877. }
  1878. #ifdef CONFIG_BYPASS_QMI
  1879. #define FW_SHARED_MEM (2 * 1024 * 1024)
  1880. /**
  1881. * hif_post_static_buf_to_target() - post static buffer to WLAN FW
  1882. * @scn: pointer to HIF structure
  1883. *
  1884. * WLAN FW needs 2MB memory from DDR when QMI is disabled.
  1885. *
  1886. * Return: void
  1887. */
  1888. static void hif_post_static_buf_to_target(struct hif_softc *scn)
  1889. {
  1890. void *target_va;
  1891. phys_addr_t target_pa;
  1892. target_va = qdf_mem_alloc_consistent(scn->qdf_dev, scn->qdf_dev->dev,
  1893. FW_SHARED_MEM, &target_pa);
  1894. if (NULL == target_va) {
  1895. HIF_TRACE("Memory allocation failed could not post target buf");
  1896. return;
  1897. }
  1898. hif_write32_mb(scn->mem + BYPASS_QMI_TEMP_REGISTER, target_pa);
  1899. HIF_TRACE("target va %pK target pa %pa", target_va, &target_pa);
  1900. }
  1901. #else
  1902. static inline void hif_post_static_buf_to_target(struct hif_softc *scn)
  1903. {
  1904. return;
  1905. }
  1906. #endif
  1907. /**
  1908. * hif_config_ce() - configure copy engines
  1909. * @scn: hif context
  1910. *
  1911. * Prepares fw, copy engine hardware and host sw according
  1912. * to the attributes selected by hif_ce_prepare_config.
  1913. *
  1914. * also calls athdiag_procfs_init
  1915. *
  1916. * return: 0 for success nonzero for failure.
  1917. */
  1918. int hif_config_ce(struct hif_softc *scn)
  1919. {
  1920. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  1921. struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
  1922. struct HIF_CE_pipe_info *pipe_info;
  1923. int pipe_num;
  1924. struct CE_state *ce_state;
  1925. #ifdef ADRASTEA_SHADOW_REGISTERS
  1926. int i;
  1927. #endif
  1928. QDF_STATUS rv = QDF_STATUS_SUCCESS;
  1929. scn->notice_send = true;
  1930. hif_post_static_buf_to_target(scn);
  1931. hif_state->fw_indicator_address = FW_INDICATOR_ADDRESS;
  1932. hif_config_rri_on_ddr(scn);
  1933. /* During CE initializtion */
  1934. scn->ce_count = HOST_CE_COUNT;
  1935. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  1936. struct CE_attr *attr;
  1937. pipe_info = &hif_state->pipe_info[pipe_num];
  1938. pipe_info->pipe_num = pipe_num;
  1939. pipe_info->HIF_CE_state = hif_state;
  1940. attr = &host_ce_config[pipe_num];
  1941. pipe_info->ce_hdl = ce_init(scn, pipe_num, attr);
  1942. ce_state = scn->ce_id_to_state[pipe_num];
  1943. QDF_ASSERT(pipe_info->ce_hdl != NULL);
  1944. if (pipe_info->ce_hdl == NULL) {
  1945. rv = QDF_STATUS_E_FAILURE;
  1946. A_TARGET_ACCESS_UNLIKELY(scn);
  1947. goto err;
  1948. }
  1949. if (pipe_num == DIAG_CE_ID) {
  1950. /* Reserve the ultimate CE for
  1951. * Diagnostic Window support */
  1952. hif_state->ce_diag = pipe_info->ce_hdl;
  1953. continue;
  1954. }
  1955. if (hif_is_nss_wifi_enabled(scn) && ce_state &&
  1956. (ce_state->htt_rx_data))
  1957. continue;
  1958. pipe_info->buf_sz = (qdf_size_t) (attr->src_sz_max);
  1959. qdf_spinlock_create(&pipe_info->recv_bufs_needed_lock);
  1960. if (attr->dest_nentries > 0) {
  1961. atomic_set(&pipe_info->recv_bufs_needed,
  1962. init_buffer_count(attr->dest_nentries - 1));
  1963. } else {
  1964. atomic_set(&pipe_info->recv_bufs_needed, 0);
  1965. }
  1966. ce_tasklet_init(hif_state, (1 << pipe_num));
  1967. ce_register_irq(hif_state, (1 << pipe_num));
  1968. scn->request_irq_done = true;
  1969. }
  1970. if (athdiag_procfs_init(scn) != 0) {
  1971. A_TARGET_ACCESS_UNLIKELY(scn);
  1972. goto err;
  1973. }
  1974. scn->athdiag_procfs_inited = true;
  1975. HIF_INFO_MED("%s: ce_init done", __func__);
  1976. init_tasklet_workers(hif_hdl);
  1977. HIF_TRACE("%s: X, ret = %d", __func__, rv);
  1978. #ifdef ADRASTEA_SHADOW_REGISTERS
  1979. HIF_INFO("%s, Using Shadow Registers instead of CE Registers", __func__);
  1980. for (i = 0; i < NUM_SHADOW_REGISTERS; i++) {
  1981. HIF_INFO("%s Shadow Register%d is mapped to address %x",
  1982. __func__, i,
  1983. (A_TARGET_READ(scn, (SHADOW_ADDRESS(i))) << 2));
  1984. }
  1985. #endif
  1986. return rv != QDF_STATUS_SUCCESS;
  1987. err:
  1988. /* Failure, so clean up */
  1989. hif_unconfig_ce(scn);
  1990. HIF_TRACE("%s: X, ret = %d", __func__, rv);
  1991. return QDF_STATUS_SUCCESS != QDF_STATUS_E_FAILURE;
  1992. }
  1993. #ifdef WLAN_FEATURE_FASTPATH
  1994. /**
  1995. * hif_ce_fastpath_cb_register() - Register callback for fastpath msg handler
  1996. * @handler: Callback funtcion
  1997. * @context: handle for callback function
  1998. *
  1999. * Return: QDF_STATUS_SUCCESS on success or QDF_STATUS_E_FAILURE
  2000. */
  2001. int hif_ce_fastpath_cb_register(struct hif_opaque_softc *hif_ctx,
  2002. fastpath_msg_handler handler,
  2003. void *context)
  2004. {
  2005. struct CE_state *ce_state;
  2006. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  2007. int i;
  2008. if (!scn) {
  2009. HIF_ERROR("%s: scn is NULL", __func__);
  2010. QDF_ASSERT(0);
  2011. return QDF_STATUS_E_FAILURE;
  2012. }
  2013. if (!scn->fastpath_mode_on) {
  2014. HIF_WARN("%s: Fastpath mode disabled", __func__);
  2015. return QDF_STATUS_E_FAILURE;
  2016. }
  2017. for (i = 0; i < scn->ce_count; i++) {
  2018. ce_state = scn->ce_id_to_state[i];
  2019. if (ce_state->htt_rx_data) {
  2020. ce_state->fastpath_handler = handler;
  2021. ce_state->context = context;
  2022. }
  2023. }
  2024. return QDF_STATUS_SUCCESS;
  2025. }
  2026. #endif
  2027. #ifdef IPA_OFFLOAD
  2028. /**
  2029. * hif_ce_ipa_get_ce_resource() - get uc resource on hif
  2030. * @scn: bus context
  2031. * @ce_sr_base_paddr: copyengine source ring base physical address
  2032. * @ce_sr_ring_size: copyengine source ring size
  2033. * @ce_reg_paddr: copyengine register physical address
  2034. *
  2035. * IPA micro controller data path offload feature enabled,
  2036. * HIF should release copy engine related resource information to IPA UC
  2037. * IPA UC will access hardware resource with released information
  2038. *
  2039. * Return: None
  2040. */
  2041. void hif_ce_ipa_get_ce_resource(struct hif_softc *scn,
  2042. qdf_dma_addr_t *ce_sr_base_paddr,
  2043. uint32_t *ce_sr_ring_size,
  2044. qdf_dma_addr_t *ce_reg_paddr)
  2045. {
  2046. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  2047. struct HIF_CE_pipe_info *pipe_info =
  2048. &(hif_state->pipe_info[HIF_PCI_IPA_UC_ASSIGNED_CE]);
  2049. struct CE_handle *ce_hdl = pipe_info->ce_hdl;
  2050. ce_ipa_get_resource(ce_hdl, ce_sr_base_paddr, ce_sr_ring_size,
  2051. ce_reg_paddr);
  2052. return;
  2053. }
  2054. #endif /* IPA_OFFLOAD */
  2055. #ifdef ADRASTEA_SHADOW_REGISTERS
  2056. /*
  2057. Current shadow register config
  2058. -----------------------------------------------------------
  2059. Shadow Register | CE | src/dst write index
  2060. -----------------------------------------------------------
  2061. 0 | 0 | src
  2062. 1 No Config - Doesn't point to anything
  2063. 2 No Config - Doesn't point to anything
  2064. 3 | 3 | src
  2065. 4 | 4 | src
  2066. 5 | 5 | src
  2067. 6 No Config - Doesn't point to anything
  2068. 7 | 7 | src
  2069. 8 No Config - Doesn't point to anything
  2070. 9 No Config - Doesn't point to anything
  2071. 10 No Config - Doesn't point to anything
  2072. 11 No Config - Doesn't point to anything
  2073. -----------------------------------------------------------
  2074. 12 No Config - Doesn't point to anything
  2075. 13 | 1 | dst
  2076. 14 | 2 | dst
  2077. 15 No Config - Doesn't point to anything
  2078. 16 No Config - Doesn't point to anything
  2079. 17 No Config - Doesn't point to anything
  2080. 18 No Config - Doesn't point to anything
  2081. 19 | 7 | dst
  2082. 20 | 8 | dst
  2083. 21 No Config - Doesn't point to anything
  2084. 22 No Config - Doesn't point to anything
  2085. 23 No Config - Doesn't point to anything
  2086. -----------------------------------------------------------
  2087. ToDo - Move shadow register config to following in the future
  2088. This helps free up a block of shadow registers towards the end.
  2089. Can be used for other purposes
  2090. -----------------------------------------------------------
  2091. Shadow Register | CE | src/dst write index
  2092. -----------------------------------------------------------
  2093. 0 | 0 | src
  2094. 1 | 3 | src
  2095. 2 | 4 | src
  2096. 3 | 5 | src
  2097. 4 | 7 | src
  2098. -----------------------------------------------------------
  2099. 5 | 1 | dst
  2100. 6 | 2 | dst
  2101. 7 | 7 | dst
  2102. 8 | 8 | dst
  2103. -----------------------------------------------------------
  2104. 9 No Config - Doesn't point to anything
  2105. 12 No Config - Doesn't point to anything
  2106. 13 No Config - Doesn't point to anything
  2107. 14 No Config - Doesn't point to anything
  2108. 15 No Config - Doesn't point to anything
  2109. 16 No Config - Doesn't point to anything
  2110. 17 No Config - Doesn't point to anything
  2111. 18 No Config - Doesn't point to anything
  2112. 19 No Config - Doesn't point to anything
  2113. 20 No Config - Doesn't point to anything
  2114. 21 No Config - Doesn't point to anything
  2115. 22 No Config - Doesn't point to anything
  2116. 23 No Config - Doesn't point to anything
  2117. -----------------------------------------------------------
  2118. */
  2119. u32 shadow_sr_wr_ind_addr(struct hif_softc *scn, u32 ctrl_addr)
  2120. {
  2121. u32 addr = 0;
  2122. u32 ce = COPY_ENGINE_ID(ctrl_addr);
  2123. switch (ce) {
  2124. case 0:
  2125. addr = SHADOW_VALUE0;
  2126. break;
  2127. case 3:
  2128. addr = SHADOW_VALUE3;
  2129. break;
  2130. case 4:
  2131. addr = SHADOW_VALUE4;
  2132. break;
  2133. case 5:
  2134. addr = SHADOW_VALUE5;
  2135. break;
  2136. case 7:
  2137. addr = SHADOW_VALUE7;
  2138. break;
  2139. default:
  2140. HIF_ERROR("invalid CE ctrl_addr (CE=%d)", ce);
  2141. QDF_ASSERT(0);
  2142. }
  2143. return addr;
  2144. }
  2145. u32 shadow_dst_wr_ind_addr(struct hif_softc *scn, u32 ctrl_addr)
  2146. {
  2147. u32 addr = 0;
  2148. u32 ce = COPY_ENGINE_ID(ctrl_addr);
  2149. switch (ce) {
  2150. case 1:
  2151. addr = SHADOW_VALUE13;
  2152. break;
  2153. case 2:
  2154. addr = SHADOW_VALUE14;
  2155. break;
  2156. case 5:
  2157. addr = SHADOW_VALUE17;
  2158. break;
  2159. case 7:
  2160. addr = SHADOW_VALUE19;
  2161. break;
  2162. case 8:
  2163. addr = SHADOW_VALUE20;
  2164. break;
  2165. case 9:
  2166. addr = SHADOW_VALUE21;
  2167. break;
  2168. case 10:
  2169. addr = SHADOW_VALUE22;
  2170. break;
  2171. case 11:
  2172. addr = SHADOW_VALUE23;
  2173. break;
  2174. default:
  2175. HIF_ERROR("invalid CE ctrl_addr (CE=%d)", ce);
  2176. QDF_ASSERT(0);
  2177. }
  2178. return addr;
  2179. }
  2180. #endif
  2181. #if defined(FEATURE_LRO)
  2182. /**
  2183. * ce_lro_flush_cb_register() - register the LRO flush
  2184. * callback
  2185. * @scn: HIF context
  2186. * @handler: callback function
  2187. * @data: opaque data pointer to be passed back
  2188. *
  2189. * Store the LRO flush callback provided
  2190. *
  2191. * Return: Number of instances the callback is registered for
  2192. */
  2193. int ce_lro_flush_cb_register(struct hif_opaque_softc *hif_hdl,
  2194. void (handler)(void *), void *data)
  2195. {
  2196. int rc = 0;
  2197. int i;
  2198. struct CE_state *ce_state;
  2199. struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
  2200. QDF_ASSERT(scn != NULL);
  2201. if (scn != NULL) {
  2202. for (i = 0; i < scn->ce_count; i++) {
  2203. ce_state = scn->ce_id_to_state[i];
  2204. if ((ce_state != NULL) && (ce_state->htt_rx_data)) {
  2205. ce_state->lro_flush_cb = handler;
  2206. ce_state->lro_data = data;
  2207. rc++;
  2208. }
  2209. }
  2210. } else {
  2211. HIF_ERROR("%s: hif_state NULL!", __func__);
  2212. }
  2213. return rc;
  2214. }
  2215. /**
  2216. * ce_lro_flush_cb_deregister() - deregister the LRO flush
  2217. * callback
  2218. * @scn: HIF context
  2219. *
  2220. * Remove the LRO flush callback
  2221. *
  2222. * Return: Number of instances the callback is de-registered
  2223. */
  2224. int ce_lro_flush_cb_deregister(struct hif_opaque_softc *hif_hdl)
  2225. {
  2226. int rc = 0;
  2227. int i;
  2228. struct CE_state *ce_state;
  2229. struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
  2230. QDF_ASSERT(scn != NULL);
  2231. if (scn != NULL) {
  2232. for (i = 0; i < scn->ce_count; i++) {
  2233. ce_state = scn->ce_id_to_state[i];
  2234. if ((ce_state != NULL) && (ce_state->htt_rx_data)) {
  2235. ce_state->lro_flush_cb = NULL;
  2236. ce_state->lro_data = NULL;
  2237. rc++;
  2238. }
  2239. }
  2240. } else {
  2241. HIF_ERROR("%s: hif_state NULL!", __func__);
  2242. }
  2243. return rc;
  2244. }
  2245. #endif
  2246. /**
  2247. * hif_map_service_to_pipe() - returns the ce ids pertaining to
  2248. * this service
  2249. * @scn: hif_softc pointer.
  2250. * @svc_id: Service ID for which the mapping is needed.
  2251. * @ul_pipe: address of the container in which ul pipe is returned.
  2252. * @dl_pipe: address of the container in which dl pipe is returned.
  2253. * @ul_is_polled: address of the container in which a bool
  2254. * indicating if the UL CE for this service
  2255. * is polled is returned.
  2256. * @dl_is_polled: address of the container in which a bool
  2257. * indicating if the DL CE for this service
  2258. * is polled is returned.
  2259. *
  2260. * Return: Indicates whether the service has been found in the table.
  2261. * Upon return, ul_is_polled is updated only if ul_pipe is updated.
  2262. * There will be warning logs if either leg has not been updated
  2263. * because it missed the entry in the table (but this is not an err).
  2264. */
  2265. int hif_map_service_to_pipe(struct hif_opaque_softc *hif_hdl, uint16_t svc_id,
  2266. uint8_t *ul_pipe, uint8_t *dl_pipe, int *ul_is_polled,
  2267. int *dl_is_polled)
  2268. {
  2269. int status = QDF_STATUS_E_INVAL;
  2270. unsigned int i;
  2271. struct service_to_pipe element;
  2272. struct service_to_pipe *tgt_svc_map_to_use;
  2273. size_t sz_tgt_svc_map_to_use;
  2274. struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
  2275. uint32_t mode = hif_get_conparam(scn);
  2276. struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl);
  2277. bool dl_updated = false;
  2278. bool ul_updated = false;
  2279. if (QDF_IS_EPPING_ENABLED(mode)) {
  2280. tgt_svc_map_to_use = target_service_to_ce_map_wlan_epping;
  2281. sz_tgt_svc_map_to_use =
  2282. sizeof(target_service_to_ce_map_wlan_epping);
  2283. } else {
  2284. switch (tgt_info->target_type) {
  2285. default:
  2286. tgt_svc_map_to_use = target_service_to_ce_map_wlan;
  2287. sz_tgt_svc_map_to_use =
  2288. sizeof(target_service_to_ce_map_wlan);
  2289. break;
  2290. case TARGET_TYPE_AR900B:
  2291. case TARGET_TYPE_QCA9984:
  2292. case TARGET_TYPE_IPQ4019:
  2293. case TARGET_TYPE_QCA9888:
  2294. case TARGET_TYPE_AR9888:
  2295. case TARGET_TYPE_AR9888V2:
  2296. tgt_svc_map_to_use = target_service_to_ce_map_ar900b;
  2297. sz_tgt_svc_map_to_use =
  2298. sizeof(target_service_to_ce_map_ar900b);
  2299. break;
  2300. }
  2301. }
  2302. *dl_is_polled = 0; /* polling for received messages not supported */
  2303. for (i = 0; i < (sz_tgt_svc_map_to_use/sizeof(element)); i++) {
  2304. memcpy(&element, &tgt_svc_map_to_use[i], sizeof(element));
  2305. if (element.service_id == svc_id) {
  2306. if (element.pipedir == PIPEDIR_OUT) {
  2307. *ul_pipe = element.pipenum;
  2308. *ul_is_polled =
  2309. (host_ce_config[*ul_pipe].flags &
  2310. CE_ATTR_DISABLE_INTR) != 0;
  2311. ul_updated = true;
  2312. } else if (element.pipedir == PIPEDIR_IN) {
  2313. *dl_pipe = element.pipenum;
  2314. dl_updated = true;
  2315. }
  2316. status = QDF_STATUS_SUCCESS;
  2317. }
  2318. }
  2319. if (ul_updated == false)
  2320. HIF_WARN("%s: ul pipe is NOT updated for service %d",
  2321. __func__, svc_id);
  2322. if (dl_updated == false)
  2323. HIF_WARN("%s: dl pipe is NOT updated for service %d",
  2324. __func__, svc_id);
  2325. return status;
  2326. }
  2327. #ifdef SHADOW_REG_DEBUG
  2328. inline uint32_t DEBUG_CE_SRC_RING_READ_IDX_GET(struct hif_softc *scn,
  2329. uint32_t CE_ctrl_addr)
  2330. {
  2331. uint32_t read_from_hw, srri_from_ddr = 0;
  2332. read_from_hw = A_TARGET_READ(scn, CE_ctrl_addr + CURRENT_SRRI_ADDRESS);
  2333. srri_from_ddr = SRRI_FROM_DDR_ADDR(VADDR_FOR_CE(scn, CE_ctrl_addr));
  2334. if (read_from_hw != srri_from_ddr) {
  2335. HIF_ERROR("%s: error: read from ddr = %d actual read from register = %d, CE_MISC_INT_STATUS_GET = 0x%x",
  2336. __func__, srri_from_ddr, read_from_hw,
  2337. CE_MISC_INT_STATUS_GET(scn, CE_ctrl_addr));
  2338. QDF_ASSERT(0);
  2339. }
  2340. return srri_from_ddr;
  2341. }
  2342. inline uint32_t DEBUG_CE_DEST_RING_READ_IDX_GET(struct hif_softc *scn,
  2343. uint32_t CE_ctrl_addr)
  2344. {
  2345. uint32_t read_from_hw, drri_from_ddr = 0;
  2346. read_from_hw = A_TARGET_READ(scn, CE_ctrl_addr + CURRENT_DRRI_ADDRESS);
  2347. drri_from_ddr = DRRI_FROM_DDR_ADDR(VADDR_FOR_CE(scn, CE_ctrl_addr));
  2348. if (read_from_hw != drri_from_ddr) {
  2349. HIF_ERROR("error: read from ddr = %d actual read from register = %d, CE_MISC_INT_STATUS_GET = 0x%x",
  2350. drri_from_ddr, read_from_hw,
  2351. CE_MISC_INT_STATUS_GET(scn, CE_ctrl_addr));
  2352. QDF_ASSERT(0);
  2353. }
  2354. return drri_from_ddr;
  2355. }
  2356. #endif
  2357. #ifdef ADRASTEA_RRI_ON_DDR
  2358. /**
  2359. * hif_get_src_ring_read_index(): Called to get the SRRI
  2360. *
  2361. * @scn: hif_softc pointer
  2362. * @CE_ctrl_addr: base address of the CE whose RRI is to be read
  2363. *
  2364. * This function returns the SRRI to the caller. For CEs that
  2365. * dont have interrupts enabled, we look at the DDR based SRRI
  2366. *
  2367. * Return: SRRI
  2368. */
  2369. inline unsigned int hif_get_src_ring_read_index(struct hif_softc *scn,
  2370. uint32_t CE_ctrl_addr)
  2371. {
  2372. struct CE_attr attr;
  2373. attr = host_ce_config[COPY_ENGINE_ID(CE_ctrl_addr)];
  2374. if (attr.flags & CE_ATTR_DISABLE_INTR)
  2375. return CE_SRC_RING_READ_IDX_GET_FROM_DDR(scn, CE_ctrl_addr);
  2376. else
  2377. return A_TARGET_READ(scn,
  2378. (CE_ctrl_addr) + CURRENT_SRRI_ADDRESS);
  2379. }
  2380. /**
  2381. * hif_get_dst_ring_read_index(): Called to get the DRRI
  2382. *
  2383. * @scn: hif_softc pointer
  2384. * @CE_ctrl_addr: base address of the CE whose RRI is to be read
  2385. *
  2386. * This function returns the DRRI to the caller. For CEs that
  2387. * dont have interrupts enabled, we look at the DDR based DRRI
  2388. *
  2389. * Return: DRRI
  2390. */
  2391. inline unsigned int hif_get_dst_ring_read_index(struct hif_softc *scn,
  2392. uint32_t CE_ctrl_addr)
  2393. {
  2394. struct CE_attr attr;
  2395. attr = host_ce_config[COPY_ENGINE_ID(CE_ctrl_addr)];
  2396. if (attr.flags & CE_ATTR_DISABLE_INTR)
  2397. return CE_DEST_RING_READ_IDX_GET_FROM_DDR(scn, CE_ctrl_addr);
  2398. else
  2399. return A_TARGET_READ(scn,
  2400. (CE_ctrl_addr) + CURRENT_DRRI_ADDRESS);
  2401. }
  2402. /**
  2403. * hif_config_rri_on_ddr(): Configure the RRI on DDR mechanism
  2404. *
  2405. * @scn: hif_softc pointer
  2406. *
  2407. * This function allocates non cached memory on ddr and sends
  2408. * the physical address of this memory to the CE hardware. The
  2409. * hardware updates the RRI on this particular location.
  2410. *
  2411. * Return: None
  2412. */
  2413. static inline void hif_config_rri_on_ddr(struct hif_softc *scn)
  2414. {
  2415. unsigned int i;
  2416. qdf_dma_addr_t paddr_rri_on_ddr;
  2417. uint32_t high_paddr, low_paddr;
  2418. scn->vaddr_rri_on_ddr =
  2419. (uint32_t *)qdf_mem_alloc_consistent(scn->qdf_dev,
  2420. scn->qdf_dev->dev, (CE_COUNT*sizeof(uint32_t)),
  2421. &paddr_rri_on_ddr);
  2422. low_paddr = BITS0_TO_31(paddr_rri_on_ddr);
  2423. high_paddr = BITS32_TO_35(paddr_rri_on_ddr);
  2424. HIF_INFO("%s using srri and drri from DDR", __func__);
  2425. WRITE_CE_DDR_ADDRESS_FOR_RRI_LOW(scn, low_paddr);
  2426. WRITE_CE_DDR_ADDRESS_FOR_RRI_HIGH(scn, high_paddr);
  2427. for (i = 0; i < CE_COUNT; i++)
  2428. CE_IDX_UPD_EN_SET(scn, CE_BASE_ADDRESS(i));
  2429. qdf_mem_zero(scn->vaddr_rri_on_ddr, CE_COUNT*sizeof(uint32_t));
  2430. return;
  2431. }
  2432. #else
  2433. /**
  2434. * hif_config_rri_on_ddr(): Configure the RRI on DDR mechanism
  2435. *
  2436. * @scn: hif_softc pointer
  2437. *
  2438. * This is a dummy implementation for platforms that don't
  2439. * support this functionality.
  2440. *
  2441. * Return: None
  2442. */
  2443. static inline void hif_config_rri_on_ddr(struct hif_softc *scn)
  2444. {
  2445. return;
  2446. }
  2447. #endif
  2448. /**
  2449. * hif_dump_ce_registers() - dump ce registers
  2450. * @scn: hif_opaque_softc pointer.
  2451. *
  2452. * Output the copy engine registers
  2453. *
  2454. * Return: 0 for success or error code
  2455. */
  2456. int hif_dump_ce_registers(struct hif_softc *scn)
  2457. {
  2458. struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
  2459. uint32_t ce_reg_address = CE0_BASE_ADDRESS;
  2460. uint32_t ce_reg_values[CE_USEFUL_SIZE >> 2];
  2461. uint32_t ce_reg_word_size = CE_USEFUL_SIZE >> 2;
  2462. uint16_t i;
  2463. QDF_STATUS status;
  2464. for (i = 0; i < scn->ce_count; i++, ce_reg_address += CE_OFFSET) {
  2465. if (scn->ce_id_to_state[i] == NULL) {
  2466. HIF_DBG("CE%d not used.", i);
  2467. continue;
  2468. }
  2469. status = hif_diag_read_mem(hif_hdl, ce_reg_address,
  2470. (uint8_t *) &ce_reg_values[0],
  2471. ce_reg_word_size * sizeof(uint32_t));
  2472. if (status != QDF_STATUS_SUCCESS) {
  2473. HIF_ERROR("Dumping CE register failed!");
  2474. return -EACCES;
  2475. }
  2476. HIF_ERROR("CE%d Registers:", i);
  2477. qdf_trace_hex_dump(QDF_MODULE_ID_HIF, QDF_TRACE_LEVEL_DEBUG,
  2478. (uint8_t *) &ce_reg_values[0],
  2479. ce_reg_word_size * sizeof(uint32_t));
  2480. }
  2481. return 0;
  2482. }
  2483. #ifdef QCA_NSS_WIFI_OFFLOAD_SUPPORT
  2484. struct hif_pipe_addl_info *hif_get_addl_pipe_info(struct hif_opaque_softc *osc,
  2485. struct hif_pipe_addl_info *hif_info, uint32_t pipe)
  2486. {
  2487. struct hif_softc *scn = HIF_GET_SOFTC(osc);
  2488. struct hif_pci_softc *sc = HIF_GET_PCI_SOFTC(scn);
  2489. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(osc);
  2490. struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
  2491. struct CE_handle *ce_hdl = pipe_info->ce_hdl;
  2492. struct CE_state *ce_state = (struct CE_state *)ce_hdl;
  2493. struct CE_ring_state *src_ring = ce_state->src_ring;
  2494. struct CE_ring_state *dest_ring = ce_state->dest_ring;
  2495. if (src_ring) {
  2496. hif_info->ul_pipe.nentries = src_ring->nentries;
  2497. hif_info->ul_pipe.nentries_mask = src_ring->nentries_mask;
  2498. hif_info->ul_pipe.sw_index = src_ring->sw_index;
  2499. hif_info->ul_pipe.write_index = src_ring->write_index;
  2500. hif_info->ul_pipe.hw_index = src_ring->hw_index;
  2501. hif_info->ul_pipe.base_addr_CE_space =
  2502. src_ring->base_addr_CE_space;
  2503. hif_info->ul_pipe.base_addr_owner_space =
  2504. src_ring->base_addr_owner_space;
  2505. }
  2506. if (dest_ring) {
  2507. hif_info->dl_pipe.nentries = dest_ring->nentries;
  2508. hif_info->dl_pipe.nentries_mask = dest_ring->nentries_mask;
  2509. hif_info->dl_pipe.sw_index = dest_ring->sw_index;
  2510. hif_info->dl_pipe.write_index = dest_ring->write_index;
  2511. hif_info->dl_pipe.hw_index = dest_ring->hw_index;
  2512. hif_info->dl_pipe.base_addr_CE_space =
  2513. dest_ring->base_addr_CE_space;
  2514. hif_info->dl_pipe.base_addr_owner_space =
  2515. dest_ring->base_addr_owner_space;
  2516. }
  2517. hif_info->pci_mem = pci_resource_start(sc->pdev, 0);
  2518. hif_info->ctrl_addr = ce_state->ctrl_addr;
  2519. return hif_info;
  2520. }
  2521. uint32_t hif_set_nss_wifiol_mode(struct hif_opaque_softc *osc, uint32_t mode)
  2522. {
  2523. struct hif_softc *scn = HIF_GET_SOFTC(osc);
  2524. scn->nss_wifi_ol_mode = mode;
  2525. return 0;
  2526. }
  2527. #endif
  2528. void hif_disable_interrupt(struct hif_opaque_softc *osc, uint32_t pipe_num)
  2529. {
  2530. struct hif_softc *scn = HIF_GET_SOFTC(osc);
  2531. struct CE_state *CE_state = scn->ce_id_to_state[pipe_num];
  2532. uint32_t ctrl_addr = CE_state->ctrl_addr;
  2533. Q_TARGET_ACCESS_BEGIN(scn);
  2534. CE_COPY_COMPLETE_INTR_DISABLE(scn, ctrl_addr);
  2535. Q_TARGET_ACCESS_END(scn);
  2536. }
  2537. /**
  2538. * hif_fw_event_handler() - hif fw event handler
  2539. * @hif_state: pointer to hif ce state structure
  2540. *
  2541. * Process fw events and raise HTC callback to process fw events.
  2542. *
  2543. * Return: none
  2544. */
  2545. static inline void hif_fw_event_handler(struct HIF_CE_state *hif_state)
  2546. {
  2547. struct hif_msg_callbacks *msg_callbacks =
  2548. &hif_state->msg_callbacks_current;
  2549. if (!msg_callbacks->fwEventHandler)
  2550. return;
  2551. msg_callbacks->fwEventHandler(msg_callbacks->Context,
  2552. QDF_STATUS_E_FAILURE);
  2553. }
  2554. #ifndef QCA_WIFI_3_0
  2555. /**
  2556. * hif_fw_interrupt_handler() - FW interrupt handler
  2557. * @irq: irq number
  2558. * @arg: the user pointer
  2559. *
  2560. * Called from the PCI interrupt handler when a
  2561. * firmware-generated interrupt to the Host.
  2562. *
  2563. * Return: status of handled irq
  2564. */
  2565. irqreturn_t hif_fw_interrupt_handler(int irq, void *arg)
  2566. {
  2567. struct hif_softc *scn = arg;
  2568. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  2569. uint32_t fw_indicator_address, fw_indicator;
  2570. if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
  2571. return ATH_ISR_NOSCHED;
  2572. fw_indicator_address = hif_state->fw_indicator_address;
  2573. /* For sudden unplug this will return ~0 */
  2574. fw_indicator = A_TARGET_READ(scn, fw_indicator_address);
  2575. if ((fw_indicator != ~0) && (fw_indicator & FW_IND_EVENT_PENDING)) {
  2576. /* ACK: clear Target-side pending event */
  2577. A_TARGET_WRITE(scn, fw_indicator_address,
  2578. fw_indicator & ~FW_IND_EVENT_PENDING);
  2579. if (Q_TARGET_ACCESS_END(scn) < 0)
  2580. return ATH_ISR_SCHED;
  2581. if (hif_state->started) {
  2582. hif_fw_event_handler(hif_state);
  2583. } else {
  2584. /*
  2585. * Probable Target failure before we're prepared
  2586. * to handle it. Generally unexpected.
  2587. */
  2588. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  2589. ("%s: Early firmware event indicated\n",
  2590. __func__));
  2591. }
  2592. } else {
  2593. if (Q_TARGET_ACCESS_END(scn) < 0)
  2594. return ATH_ISR_SCHED;
  2595. }
  2596. return ATH_ISR_SCHED;
  2597. }
  2598. #else
  2599. irqreturn_t hif_fw_interrupt_handler(int irq, void *arg)
  2600. {
  2601. return ATH_ISR_SCHED;
  2602. }
  2603. #endif /* #ifdef QCA_WIFI_3_0 */
  2604. /**
  2605. * hif_wlan_disable(): call the platform driver to disable wlan
  2606. * @scn: HIF Context
  2607. *
  2608. * This function passes the con_mode to platform driver to disable
  2609. * wlan.
  2610. *
  2611. * Return: void
  2612. */
  2613. void hif_wlan_disable(struct hif_softc *scn)
  2614. {
  2615. enum pld_driver_mode mode;
  2616. uint32_t con_mode = hif_get_conparam(scn);
  2617. if (QDF_GLOBAL_FTM_MODE == con_mode)
  2618. mode = PLD_FTM;
  2619. else if (QDF_IS_EPPING_ENABLED(con_mode))
  2620. mode = PLD_EPPING;
  2621. else
  2622. mode = PLD_MISSION;
  2623. pld_wlan_disable(scn->qdf_dev->dev, mode);
  2624. }