ce_main.c 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067
  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_target_info *tgt_info;
  494. if (ce_state != NULL) {
  495. tgt_info = &ce_state->scn->target_info;
  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. * ce_srng_based() - Does this target use srng
  557. * @ce_state : pointer to the state context of the CE
  558. *
  559. * Description:
  560. * returns true if the target is SRNG based
  561. *
  562. * Return:
  563. * false (attribute set to false)
  564. * true (attribute set to true);
  565. */
  566. bool ce_srng_based(struct hif_softc *scn)
  567. {
  568. struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
  569. struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl);
  570. switch (tgt_info->target_type) {
  571. case TARGET_TYPE_QCA8074:
  572. case TARGET_TYPE_QCA6290:
  573. return true;
  574. default:
  575. return false;
  576. }
  577. return false;
  578. }
  579. struct ce_ops *ce_services_attach(struct hif_softc *scn)
  580. {
  581. if (ce_srng_based(scn))
  582. return ce_services_srng();
  583. return ce_services_legacy();
  584. }
  585. static inline uint32_t ce_get_desc_size(struct hif_softc *scn,
  586. uint8_t ring_type)
  587. {
  588. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  589. return hif_state->ce_services->ce_get_desc_size(ring_type);
  590. }
  591. struct CE_ring_state *ce_alloc_ring_state(struct CE_state *CE_state,
  592. uint8_t ring_type, uint32_t nentries)
  593. {
  594. uint32_t ce_nbytes;
  595. char *ptr;
  596. qdf_dma_addr_t base_addr;
  597. struct CE_ring_state *ce_ring;
  598. uint32_t desc_size;
  599. struct hif_softc *scn = CE_state->scn;
  600. ce_nbytes = sizeof(struct CE_ring_state)
  601. + (nentries * sizeof(void *));
  602. ptr = qdf_mem_malloc(ce_nbytes);
  603. if (!ptr)
  604. return NULL;
  605. qdf_mem_zero(ptr, ce_nbytes);
  606. ce_ring = (struct CE_ring_state *)ptr;
  607. ptr += sizeof(struct CE_ring_state);
  608. ce_ring->nentries = nentries;
  609. ce_ring->nentries_mask = nentries - 1;
  610. ce_ring->low_water_mark_nentries = 0;
  611. ce_ring->high_water_mark_nentries = nentries;
  612. ce_ring->per_transfer_context = (void **)ptr;
  613. desc_size = ce_get_desc_size(scn, ring_type);
  614. /* Legacy platforms that do not support cache
  615. * coherent DMA are unsupported
  616. */
  617. ce_ring->base_addr_owner_space_unaligned =
  618. qdf_mem_alloc_consistent(scn->qdf_dev,
  619. scn->qdf_dev->dev,
  620. (nentries *
  621. desc_size +
  622. CE_DESC_RING_ALIGN),
  623. &base_addr);
  624. if (ce_ring->base_addr_owner_space_unaligned
  625. == NULL) {
  626. HIF_ERROR("%s: ring has no DMA mem",
  627. __func__);
  628. qdf_mem_free(ptr);
  629. return NULL;
  630. }
  631. ce_ring->base_addr_CE_space_unaligned = base_addr;
  632. /* Correctly initialize memory to 0 to
  633. * prevent garbage data crashing system
  634. * when download firmware
  635. */
  636. qdf_mem_zero(ce_ring->base_addr_owner_space_unaligned,
  637. nentries * desc_size +
  638. CE_DESC_RING_ALIGN);
  639. if (ce_ring->base_addr_CE_space_unaligned & (CE_DESC_RING_ALIGN - 1)) {
  640. ce_ring->base_addr_CE_space =
  641. (ce_ring->base_addr_CE_space_unaligned +
  642. CE_DESC_RING_ALIGN - 1) & ~(CE_DESC_RING_ALIGN - 1);
  643. ce_ring->base_addr_owner_space = (void *)
  644. (((size_t) ce_ring->base_addr_owner_space_unaligned +
  645. CE_DESC_RING_ALIGN - 1) & ~(CE_DESC_RING_ALIGN - 1));
  646. } else {
  647. ce_ring->base_addr_CE_space =
  648. ce_ring->base_addr_CE_space_unaligned;
  649. ce_ring->base_addr_owner_space =
  650. ce_ring->base_addr_owner_space_unaligned;
  651. }
  652. return ce_ring;
  653. }
  654. static void ce_ring_setup(struct hif_softc *scn, uint8_t ring_type,
  655. uint32_t ce_id, struct CE_ring_state *ring,
  656. struct CE_attr *attr)
  657. {
  658. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  659. hif_state->ce_services->ce_ring_setup(scn, ring_type, ce_id, ring, attr);
  660. }
  661. /*
  662. * Initialize a Copy Engine based on caller-supplied attributes.
  663. * This may be called once to initialize both source and destination
  664. * rings or it may be called twice for separate source and destination
  665. * initialization. It may be that only one side or the other is
  666. * initialized by software/firmware.
  667. *
  668. * This should be called durring the initialization sequence before
  669. * interupts are enabled, so we don't have to worry about thread safety.
  670. */
  671. struct CE_handle *ce_init(struct hif_softc *scn,
  672. unsigned int CE_id, struct CE_attr *attr)
  673. {
  674. struct CE_state *CE_state;
  675. uint32_t ctrl_addr;
  676. unsigned int nentries;
  677. bool malloc_CE_state = false;
  678. bool malloc_src_ring = false;
  679. QDF_ASSERT(CE_id < scn->ce_count);
  680. ctrl_addr = CE_BASE_ADDRESS(CE_id);
  681. CE_state = scn->ce_id_to_state[CE_id];
  682. if (!CE_state) {
  683. CE_state =
  684. (struct CE_state *)qdf_mem_malloc(sizeof(*CE_state));
  685. if (!CE_state) {
  686. HIF_ERROR("%s: CE_state has no mem", __func__);
  687. return NULL;
  688. }
  689. malloc_CE_state = true;
  690. qdf_mem_zero(CE_state, sizeof(*CE_state));
  691. scn->ce_id_to_state[CE_id] = CE_state;
  692. qdf_spinlock_create(&CE_state->ce_index_lock);
  693. CE_state->id = CE_id;
  694. CE_state->ctrl_addr = ctrl_addr;
  695. CE_state->state = CE_RUNNING;
  696. CE_state->attr_flags = attr->flags;
  697. qdf_spinlock_create(&CE_state->lro_unloading_lock);
  698. }
  699. CE_state->scn = scn;
  700. qdf_atomic_init(&CE_state->rx_pending);
  701. if (attr == NULL) {
  702. /* Already initialized; caller wants the handle */
  703. return (struct CE_handle *)CE_state;
  704. }
  705. if (CE_state->src_sz_max)
  706. QDF_ASSERT(CE_state->src_sz_max == attr->src_sz_max);
  707. else
  708. CE_state->src_sz_max = attr->src_sz_max;
  709. ce_init_ce_desc_event_log(CE_id,
  710. attr->src_nentries + attr->dest_nentries);
  711. /* source ring setup */
  712. nentries = attr->src_nentries;
  713. if (nentries) {
  714. struct CE_ring_state *src_ring;
  715. nentries = roundup_pwr2(nentries);
  716. if (CE_state->src_ring) {
  717. QDF_ASSERT(CE_state->src_ring->nentries == nentries);
  718. } else {
  719. src_ring = CE_state->src_ring =
  720. ce_alloc_ring_state(CE_state,
  721. CE_RING_SRC,
  722. nentries);
  723. if (!src_ring) {
  724. /* cannot allocate src ring. If the
  725. * CE_state is allocated locally free
  726. * CE_State and return error.
  727. */
  728. HIF_ERROR("%s: src ring has no mem", __func__);
  729. if (malloc_CE_state) {
  730. /* allocated CE_state locally */
  731. scn->ce_id_to_state[CE_id] = NULL;
  732. qdf_mem_free(CE_state);
  733. malloc_CE_state = false;
  734. }
  735. return NULL;
  736. } else {
  737. /* we can allocate src ring.
  738. * Mark that the src ring is
  739. * allocated locally
  740. */
  741. malloc_src_ring = true;
  742. }
  743. /*
  744. * Also allocate a shadow src ring in
  745. * regular mem to use for faster access.
  746. */
  747. src_ring->shadow_base_unaligned =
  748. qdf_mem_malloc(nentries *
  749. sizeof(struct CE_src_desc) +
  750. CE_DESC_RING_ALIGN);
  751. if (src_ring->shadow_base_unaligned == NULL) {
  752. HIF_ERROR("%s: src ring no shadow_base mem",
  753. __func__);
  754. goto error_no_dma_mem;
  755. }
  756. src_ring->shadow_base = (struct CE_src_desc *)
  757. (((size_t) src_ring->shadow_base_unaligned +
  758. CE_DESC_RING_ALIGN - 1) &
  759. ~(CE_DESC_RING_ALIGN - 1));
  760. if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
  761. goto error_target_access;
  762. ce_ring_setup(scn, CE_RING_SRC, CE_id, src_ring, attr);
  763. if (Q_TARGET_ACCESS_END(scn) < 0)
  764. goto error_target_access;
  765. ce_ring_test_initial_indexes(CE_id, src_ring,
  766. "src_ring");
  767. }
  768. }
  769. /* destination ring setup */
  770. nentries = attr->dest_nentries;
  771. if (nentries) {
  772. struct CE_ring_state *dest_ring;
  773. nentries = roundup_pwr2(nentries);
  774. if (CE_state->dest_ring) {
  775. QDF_ASSERT(CE_state->dest_ring->nentries == nentries);
  776. } else {
  777. dest_ring = CE_state->dest_ring =
  778. ce_alloc_ring_state(CE_state,
  779. CE_RING_DEST,
  780. nentries);
  781. if (!dest_ring) {
  782. /* cannot allocate dst ring. If the CE_state
  783. * or src ring is allocated locally free
  784. * CE_State and src ring and return error.
  785. */
  786. HIF_ERROR("%s: dest ring has no mem",
  787. __func__);
  788. if (malloc_src_ring) {
  789. qdf_mem_free(CE_state->src_ring);
  790. CE_state->src_ring = NULL;
  791. malloc_src_ring = false;
  792. }
  793. if (malloc_CE_state) {
  794. /* allocated CE_state locally */
  795. scn->ce_id_to_state[CE_id] = NULL;
  796. qdf_mem_free(CE_state);
  797. malloc_CE_state = false;
  798. }
  799. return NULL;
  800. }
  801. if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
  802. goto error_target_access;
  803. ce_ring_setup(scn, CE_RING_DEST, CE_id, dest_ring, attr);
  804. if (Q_TARGET_ACCESS_END(scn) < 0)
  805. goto error_target_access;
  806. ce_ring_test_initial_indexes(CE_id, dest_ring,
  807. "dest_ring");
  808. /* For srng based target, init status ring here */
  809. if (ce_srng_based(CE_state->scn)) {
  810. CE_state->status_ring =
  811. ce_alloc_ring_state(CE_state,
  812. CE_RING_STATUS,
  813. nentries);
  814. if (CE_state->status_ring == NULL) {
  815. /*Allocation failed. Cleanup*/
  816. qdf_mem_free(CE_state->dest_ring);
  817. if (malloc_src_ring) {
  818. qdf_mem_free
  819. (CE_state->src_ring);
  820. CE_state->src_ring = NULL;
  821. malloc_src_ring = false;
  822. }
  823. if (malloc_CE_state) {
  824. /* allocated CE_state locally */
  825. scn->ce_id_to_state[CE_id] =
  826. NULL;
  827. qdf_mem_free(CE_state);
  828. malloc_CE_state = false;
  829. }
  830. return NULL;
  831. }
  832. if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
  833. goto error_target_access;
  834. ce_ring_setup(scn, CE_RING_STATUS, CE_id,
  835. CE_state->status_ring, attr);
  836. if (Q_TARGET_ACCESS_END(scn) < 0)
  837. goto error_target_access;
  838. }
  839. /* epping */
  840. /* poll timer */
  841. if ((CE_state->attr_flags & CE_ATTR_ENABLE_POLL)) {
  842. qdf_timer_init(scn->qdf_dev,
  843. &CE_state->poll_timer,
  844. ce_poll_timeout,
  845. CE_state,
  846. QDF_TIMER_TYPE_SW);
  847. CE_state->timer_inited = true;
  848. qdf_timer_mod(&CE_state->poll_timer,
  849. CE_POLL_TIMEOUT);
  850. }
  851. }
  852. }
  853. if (!ce_srng_based(scn)) {
  854. /* Enable CE error interrupts */
  855. if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
  856. goto error_target_access;
  857. CE_ERROR_INTR_ENABLE(scn, ctrl_addr);
  858. if (Q_TARGET_ACCESS_END(scn) < 0)
  859. goto error_target_access;
  860. }
  861. /* update the htt_data attribute */
  862. ce_mark_datapath(CE_state);
  863. return (struct CE_handle *)CE_state;
  864. error_target_access:
  865. error_no_dma_mem:
  866. ce_fini((struct CE_handle *)CE_state);
  867. return NULL;
  868. }
  869. #ifdef WLAN_FEATURE_FASTPATH
  870. /**
  871. * hif_enable_fastpath() Update that we have enabled fastpath mode
  872. * @hif_ctx: HIF context
  873. *
  874. * For use in data path
  875. *
  876. * Retrun: void
  877. */
  878. void hif_enable_fastpath(struct hif_opaque_softc *hif_ctx)
  879. {
  880. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  881. HIF_INFO("%s, Enabling fastpath mode", __func__);
  882. scn->fastpath_mode_on = true;
  883. }
  884. /**
  885. * hif_is_fastpath_mode_enabled - API to query if fasthpath mode is enabled
  886. * @hif_ctx: HIF Context
  887. *
  888. * For use in data path to skip HTC
  889. *
  890. * Return: bool
  891. */
  892. bool hif_is_fastpath_mode_enabled(struct hif_opaque_softc *hif_ctx)
  893. {
  894. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  895. return scn->fastpath_mode_on;
  896. }
  897. /**
  898. * hif_get_ce_handle - API to get CE handle for FastPath mode
  899. * @hif_ctx: HIF Context
  900. * @id: CopyEngine Id
  901. *
  902. * API to return CE handle for fastpath mode
  903. *
  904. * Return: void
  905. */
  906. void *hif_get_ce_handle(struct hif_opaque_softc *hif_ctx, int id)
  907. {
  908. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  909. return scn->ce_id_to_state[id];
  910. }
  911. /**
  912. * ce_h2t_tx_ce_cleanup() Place holder function for H2T CE cleanup.
  913. * No processing is required inside this function.
  914. * @ce_hdl: Cope engine handle
  915. * Using an assert, this function makes sure that,
  916. * the TX CE has been processed completely.
  917. *
  918. * This is called while dismantling CE structures. No other thread
  919. * should be using these structures while dismantling is occuring
  920. * therfore no locking is needed.
  921. *
  922. * Return: none
  923. */
  924. void
  925. ce_h2t_tx_ce_cleanup(struct CE_handle *ce_hdl)
  926. {
  927. struct CE_state *ce_state = (struct CE_state *)ce_hdl;
  928. struct CE_ring_state *src_ring = ce_state->src_ring;
  929. struct hif_softc *sc = ce_state->scn;
  930. uint32_t sw_index, write_index;
  931. if (hif_is_nss_wifi_enabled(sc))
  932. return;
  933. if (sc->fastpath_mode_on && ce_state->htt_tx_data) {
  934. HIF_INFO("%s %d Fastpath mode ON, Cleaning up HTT Tx CE",
  935. __func__, __LINE__);
  936. sw_index = src_ring->sw_index;
  937. write_index = src_ring->sw_index;
  938. /* At this point Tx CE should be clean */
  939. qdf_assert_always(sw_index == write_index);
  940. }
  941. }
  942. /**
  943. * ce_t2h_msg_ce_cleanup() - Cleanup buffers on the t2h datapath msg queue.
  944. * @ce_hdl: Handle to CE
  945. *
  946. * These buffers are never allocated on the fly, but
  947. * are allocated only once during HIF start and freed
  948. * only once during HIF stop.
  949. * NOTE:
  950. * The assumption here is there is no in-flight DMA in progress
  951. * currently, so that buffers can be freed up safely.
  952. *
  953. * Return: NONE
  954. */
  955. void ce_t2h_msg_ce_cleanup(struct CE_handle *ce_hdl)
  956. {
  957. struct CE_state *ce_state = (struct CE_state *)ce_hdl;
  958. struct CE_ring_state *dst_ring = ce_state->dest_ring;
  959. qdf_nbuf_t nbuf;
  960. int i;
  961. if (ce_state->scn->fastpath_mode_on == false)
  962. return;
  963. if (!ce_state->htt_rx_data)
  964. return;
  965. /*
  966. * when fastpath_mode is on and for datapath CEs. Unlike other CE's,
  967. * this CE is completely full: does not leave one blank space, to
  968. * distinguish between empty queue & full queue. So free all the
  969. * entries.
  970. */
  971. for (i = 0; i < dst_ring->nentries; i++) {
  972. nbuf = dst_ring->per_transfer_context[i];
  973. /*
  974. * The reasons for doing this check are:
  975. * 1) Protect against calling cleanup before allocating buffers
  976. * 2) In a corner case, FASTPATH_mode_on may be set, but we
  977. * could have a partially filled ring, because of a memory
  978. * allocation failure in the middle of allocating ring.
  979. * This check accounts for that case, checking
  980. * fastpath_mode_on flag or started flag would not have
  981. * covered that case. This is not in performance path,
  982. * so OK to do this.
  983. */
  984. if (nbuf)
  985. qdf_nbuf_free(nbuf);
  986. }
  987. }
  988. /**
  989. * hif_update_fastpath_recv_bufs_cnt() - Increments the Rx buf count by 1
  990. * @scn: HIF handle
  991. *
  992. * Datapath Rx CEs are special case, where we reuse all the message buffers.
  993. * Hence we have to post all the entries in the pipe, even, in the beginning
  994. * unlike for other CE pipes where one less than dest_nentries are filled in
  995. * the beginning.
  996. *
  997. * Return: None
  998. */
  999. static void hif_update_fastpath_recv_bufs_cnt(struct hif_softc *scn)
  1000. {
  1001. int pipe_num;
  1002. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  1003. if (scn->fastpath_mode_on == false)
  1004. return;
  1005. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  1006. struct HIF_CE_pipe_info *pipe_info =
  1007. &hif_state->pipe_info[pipe_num];
  1008. struct CE_state *ce_state =
  1009. scn->ce_id_to_state[pipe_info->pipe_num];
  1010. if (ce_state->htt_rx_data)
  1011. atomic_inc(&pipe_info->recv_bufs_needed);
  1012. }
  1013. }
  1014. #else
  1015. static inline void hif_update_fastpath_recv_bufs_cnt(struct hif_softc *scn)
  1016. {
  1017. }
  1018. static inline bool ce_is_fastpath_enabled(struct hif_softc *scn)
  1019. {
  1020. return false;
  1021. }
  1022. static inline bool ce_is_fastpath_handler_registered(struct CE_state *ce_state)
  1023. {
  1024. return false;
  1025. }
  1026. #endif /* WLAN_FEATURE_FASTPATH */
  1027. void ce_fini(struct CE_handle *copyeng)
  1028. {
  1029. struct CE_state *CE_state = (struct CE_state *)copyeng;
  1030. unsigned int CE_id = CE_state->id;
  1031. struct hif_softc *scn = CE_state->scn;
  1032. CE_state->state = CE_UNUSED;
  1033. scn->ce_id_to_state[CE_id] = NULL;
  1034. if (CE_state->src_ring) {
  1035. /* Cleanup the datapath Tx ring */
  1036. ce_h2t_tx_ce_cleanup(copyeng);
  1037. if (CE_state->src_ring->shadow_base_unaligned)
  1038. qdf_mem_free(CE_state->src_ring->shadow_base_unaligned);
  1039. if (CE_state->src_ring->base_addr_owner_space_unaligned)
  1040. qdf_mem_free_consistent(scn->qdf_dev,
  1041. scn->qdf_dev->dev,
  1042. (CE_state->src_ring->nentries *
  1043. sizeof(struct CE_src_desc) +
  1044. CE_DESC_RING_ALIGN),
  1045. CE_state->src_ring->
  1046. base_addr_owner_space_unaligned,
  1047. CE_state->src_ring->
  1048. base_addr_CE_space, 0);
  1049. qdf_mem_free(CE_state->src_ring);
  1050. }
  1051. if (CE_state->dest_ring) {
  1052. /* Cleanup the datapath Rx ring */
  1053. ce_t2h_msg_ce_cleanup(copyeng);
  1054. if (CE_state->dest_ring->base_addr_owner_space_unaligned)
  1055. qdf_mem_free_consistent(scn->qdf_dev,
  1056. scn->qdf_dev->dev,
  1057. (CE_state->dest_ring->nentries *
  1058. sizeof(struct CE_dest_desc) +
  1059. CE_DESC_RING_ALIGN),
  1060. CE_state->dest_ring->
  1061. base_addr_owner_space_unaligned,
  1062. CE_state->dest_ring->
  1063. base_addr_CE_space, 0);
  1064. qdf_mem_free(CE_state->dest_ring);
  1065. /* epping */
  1066. if (CE_state->timer_inited) {
  1067. CE_state->timer_inited = false;
  1068. qdf_timer_free(&CE_state->poll_timer);
  1069. }
  1070. }
  1071. if ((ce_srng_based(CE_state->scn)) && (CE_state->status_ring)) {
  1072. /* Cleanup the datapath Tx ring */
  1073. ce_h2t_tx_ce_cleanup(copyeng);
  1074. if (CE_state->status_ring->shadow_base_unaligned)
  1075. qdf_mem_free(
  1076. CE_state->status_ring->shadow_base_unaligned);
  1077. if (CE_state->status_ring->base_addr_owner_space_unaligned)
  1078. qdf_mem_free_consistent(scn->qdf_dev,
  1079. scn->qdf_dev->dev,
  1080. (CE_state->status_ring->nentries *
  1081. sizeof(struct CE_src_desc) +
  1082. CE_DESC_RING_ALIGN),
  1083. CE_state->status_ring->
  1084. base_addr_owner_space_unaligned,
  1085. CE_state->status_ring->
  1086. base_addr_CE_space, 0);
  1087. qdf_mem_free(CE_state->status_ring);
  1088. }
  1089. qdf_mem_free(CE_state);
  1090. }
  1091. void hif_detach_htc(struct hif_opaque_softc *hif_ctx)
  1092. {
  1093. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
  1094. qdf_mem_zero(&hif_state->msg_callbacks_pending,
  1095. sizeof(hif_state->msg_callbacks_pending));
  1096. qdf_mem_zero(&hif_state->msg_callbacks_current,
  1097. sizeof(hif_state->msg_callbacks_current));
  1098. }
  1099. /* Send the first nbytes bytes of the buffer */
  1100. QDF_STATUS
  1101. hif_send_head(struct hif_opaque_softc *hif_ctx,
  1102. uint8_t pipe, unsigned int transfer_id, unsigned int nbytes,
  1103. qdf_nbuf_t nbuf, unsigned int data_attr)
  1104. {
  1105. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  1106. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
  1107. struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
  1108. struct CE_handle *ce_hdl = pipe_info->ce_hdl;
  1109. int bytes = nbytes, nfrags = 0;
  1110. struct ce_sendlist sendlist;
  1111. int status, i = 0;
  1112. unsigned int mux_id = 0;
  1113. QDF_ASSERT(nbytes <= qdf_nbuf_len(nbuf));
  1114. transfer_id =
  1115. (mux_id & MUX_ID_MASK) |
  1116. (transfer_id & TRANSACTION_ID_MASK);
  1117. data_attr &= DESC_DATA_FLAG_MASK;
  1118. /*
  1119. * The common case involves sending multiple fragments within a
  1120. * single download (the tx descriptor and the tx frame header).
  1121. * So, optimize for the case of multiple fragments by not even
  1122. * checking whether it's necessary to use a sendlist.
  1123. * The overhead of using a sendlist for a single buffer download
  1124. * is not a big deal, since it happens rarely (for WMI messages).
  1125. */
  1126. ce_sendlist_init(&sendlist);
  1127. do {
  1128. qdf_dma_addr_t frag_paddr;
  1129. int frag_bytes;
  1130. frag_paddr = qdf_nbuf_get_frag_paddr(nbuf, nfrags);
  1131. frag_bytes = qdf_nbuf_get_frag_len(nbuf, nfrags);
  1132. /*
  1133. * Clear the packet offset for all but the first CE desc.
  1134. */
  1135. if (i++ > 0)
  1136. data_attr &= ~QDF_CE_TX_PKT_OFFSET_BIT_M;
  1137. status = ce_sendlist_buf_add(&sendlist, frag_paddr,
  1138. frag_bytes >
  1139. bytes ? bytes : frag_bytes,
  1140. qdf_nbuf_get_frag_is_wordstream
  1141. (nbuf,
  1142. nfrags) ? 0 :
  1143. CE_SEND_FLAG_SWAP_DISABLE,
  1144. data_attr);
  1145. if (status != QDF_STATUS_SUCCESS) {
  1146. HIF_ERROR("%s: error, frag_num %d larger than limit",
  1147. __func__, nfrags);
  1148. return status;
  1149. }
  1150. bytes -= frag_bytes;
  1151. nfrags++;
  1152. } while (bytes > 0);
  1153. /* Make sure we have resources to handle this request */
  1154. qdf_spin_lock_bh(&pipe_info->completion_freeq_lock);
  1155. if (pipe_info->num_sends_allowed < nfrags) {
  1156. qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
  1157. ce_pkt_error_count_incr(hif_state, HIF_PIPE_NO_RESOURCE);
  1158. return QDF_STATUS_E_RESOURCES;
  1159. }
  1160. pipe_info->num_sends_allowed -= nfrags;
  1161. qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
  1162. if (qdf_unlikely(ce_hdl == NULL)) {
  1163. HIF_ERROR("%s: error CE handle is null", __func__);
  1164. return A_ERROR;
  1165. }
  1166. QDF_NBUF_UPDATE_TX_PKT_COUNT(nbuf, QDF_NBUF_TX_PKT_HIF);
  1167. DPTRACE(qdf_dp_trace(nbuf, QDF_DP_TRACE_HIF_PACKET_PTR_RECORD,
  1168. qdf_nbuf_data_addr(nbuf),
  1169. sizeof(qdf_nbuf_data(nbuf)), QDF_TX));
  1170. status = ce_sendlist_send(ce_hdl, nbuf, &sendlist, transfer_id);
  1171. QDF_ASSERT(status == QDF_STATUS_SUCCESS);
  1172. return status;
  1173. }
  1174. void hif_send_complete_check(struct hif_opaque_softc *hif_ctx, uint8_t pipe,
  1175. int force)
  1176. {
  1177. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  1178. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
  1179. if (!force) {
  1180. int resources;
  1181. /*
  1182. * Decide whether to actually poll for completions, or just
  1183. * wait for a later chance. If there seem to be plenty of
  1184. * resources left, then just wait, since checking involves
  1185. * reading a CE register, which is a relatively expensive
  1186. * operation.
  1187. */
  1188. resources = hif_get_free_queue_number(hif_ctx, pipe);
  1189. /*
  1190. * If at least 50% of the total resources are still available,
  1191. * don't bother checking again yet.
  1192. */
  1193. if (resources > (hif_state->host_ce_config[pipe].src_nentries >> 1)) {
  1194. return;
  1195. }
  1196. }
  1197. #if ATH_11AC_TXCOMPACT
  1198. ce_per_engine_servicereap(scn, pipe);
  1199. #else
  1200. ce_per_engine_service(scn, pipe);
  1201. #endif
  1202. }
  1203. uint16_t
  1204. hif_get_free_queue_number(struct hif_opaque_softc *hif_ctx, uint8_t pipe)
  1205. {
  1206. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
  1207. struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
  1208. uint16_t rv;
  1209. qdf_spin_lock_bh(&pipe_info->completion_freeq_lock);
  1210. rv = pipe_info->num_sends_allowed;
  1211. qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
  1212. return rv;
  1213. }
  1214. /* Called by lower (CE) layer when a send to Target completes. */
  1215. void
  1216. hif_pci_ce_send_done(struct CE_handle *copyeng, void *ce_context,
  1217. void *transfer_context, qdf_dma_addr_t CE_data,
  1218. unsigned int nbytes, unsigned int transfer_id,
  1219. unsigned int sw_index, unsigned int hw_index,
  1220. unsigned int toeplitz_hash_result)
  1221. {
  1222. struct HIF_CE_pipe_info *pipe_info =
  1223. (struct HIF_CE_pipe_info *)ce_context;
  1224. struct HIF_CE_state *hif_state = pipe_info->HIF_CE_state;
  1225. struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
  1226. unsigned int sw_idx = sw_index, hw_idx = hw_index;
  1227. struct hif_msg_callbacks *msg_callbacks =
  1228. &pipe_info->pipe_callbacks;
  1229. do {
  1230. /*
  1231. * The upper layer callback will be triggered
  1232. * when last fragment is complteted.
  1233. */
  1234. if (transfer_context != CE_SENDLIST_ITEM_CTXT) {
  1235. if (scn->target_status == TARGET_STATUS_RESET)
  1236. qdf_nbuf_free(transfer_context);
  1237. else
  1238. msg_callbacks->txCompletionHandler(
  1239. msg_callbacks->Context,
  1240. transfer_context, transfer_id,
  1241. toeplitz_hash_result);
  1242. }
  1243. qdf_spin_lock(&pipe_info->completion_freeq_lock);
  1244. pipe_info->num_sends_allowed++;
  1245. qdf_spin_unlock(&pipe_info->completion_freeq_lock);
  1246. } while (ce_completed_send_next(copyeng,
  1247. &ce_context, &transfer_context,
  1248. &CE_data, &nbytes, &transfer_id,
  1249. &sw_idx, &hw_idx,
  1250. &toeplitz_hash_result) == QDF_STATUS_SUCCESS);
  1251. }
  1252. /**
  1253. * hif_ce_do_recv(): send message from copy engine to upper layers
  1254. * @msg_callbacks: structure containing callback and callback context
  1255. * @netbuff: skb containing message
  1256. * @nbytes: number of bytes in the message
  1257. * @pipe_info: used for the pipe_number info
  1258. *
  1259. * Checks the packet length, configures the lenght in the netbuff,
  1260. * and calls the upper layer callback.
  1261. *
  1262. * return: None
  1263. */
  1264. static inline void hif_ce_do_recv(struct hif_msg_callbacks *msg_callbacks,
  1265. qdf_nbuf_t netbuf, int nbytes,
  1266. struct HIF_CE_pipe_info *pipe_info) {
  1267. if (nbytes <= pipe_info->buf_sz) {
  1268. qdf_nbuf_set_pktlen(netbuf, nbytes);
  1269. msg_callbacks->
  1270. rxCompletionHandler(msg_callbacks->Context,
  1271. netbuf, pipe_info->pipe_num);
  1272. } else {
  1273. HIF_ERROR("%s: Invalid Rx msg buf:%p nbytes:%d",
  1274. __func__, netbuf, nbytes);
  1275. qdf_nbuf_free(netbuf);
  1276. }
  1277. }
  1278. /* Called by lower (CE) layer when data is received from the Target. */
  1279. void
  1280. hif_pci_ce_recv_data(struct CE_handle *copyeng, void *ce_context,
  1281. void *transfer_context, qdf_dma_addr_t CE_data,
  1282. unsigned int nbytes, unsigned int transfer_id,
  1283. unsigned int flags)
  1284. {
  1285. struct HIF_CE_pipe_info *pipe_info =
  1286. (struct HIF_CE_pipe_info *)ce_context;
  1287. struct HIF_CE_state *hif_state = pipe_info->HIF_CE_state;
  1288. struct CE_state *ce_state = (struct CE_state *) copyeng;
  1289. struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
  1290. #ifdef HIF_PCI
  1291. struct hif_pci_softc *hif_pci_sc = HIF_GET_PCI_SOFTC(hif_state);
  1292. #endif
  1293. struct hif_msg_callbacks *msg_callbacks =
  1294. &pipe_info->pipe_callbacks;
  1295. do {
  1296. #ifdef HIF_PCI
  1297. hif_pm_runtime_mark_last_busy(hif_pci_sc->dev);
  1298. #endif
  1299. qdf_nbuf_unmap_single(scn->qdf_dev,
  1300. (qdf_nbuf_t) transfer_context,
  1301. QDF_DMA_FROM_DEVICE);
  1302. atomic_inc(&pipe_info->recv_bufs_needed);
  1303. hif_post_recv_buffers_for_pipe(pipe_info);
  1304. if (scn->target_status == TARGET_STATUS_RESET)
  1305. qdf_nbuf_free(transfer_context);
  1306. else
  1307. hif_ce_do_recv(msg_callbacks, transfer_context,
  1308. nbytes, pipe_info);
  1309. /* Set up force_break flag if num of receices reaches
  1310. * MAX_NUM_OF_RECEIVES */
  1311. ce_state->receive_count++;
  1312. if (qdf_unlikely(hif_ce_service_should_yield(scn, ce_state))) {
  1313. ce_state->force_break = 1;
  1314. break;
  1315. }
  1316. } while (ce_completed_recv_next(copyeng, &ce_context, &transfer_context,
  1317. &CE_data, &nbytes, &transfer_id,
  1318. &flags) == QDF_STATUS_SUCCESS);
  1319. }
  1320. /* TBDXXX: Set CE High Watermark; invoke txResourceAvailHandler in response */
  1321. void
  1322. hif_post_init(struct hif_opaque_softc *hif_ctx, void *unused,
  1323. struct hif_msg_callbacks *callbacks)
  1324. {
  1325. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
  1326. #ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
  1327. spin_lock_init(&pcie_access_log_lock);
  1328. #endif
  1329. /* Save callbacks for later installation */
  1330. qdf_mem_copy(&hif_state->msg_callbacks_pending, callbacks,
  1331. sizeof(hif_state->msg_callbacks_pending));
  1332. }
  1333. int hif_completion_thread_startup(struct HIF_CE_state *hif_state)
  1334. {
  1335. struct CE_handle *ce_diag = hif_state->ce_diag;
  1336. int pipe_num;
  1337. struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
  1338. struct hif_msg_callbacks *hif_msg_callbacks =
  1339. &hif_state->msg_callbacks_current;
  1340. /* daemonize("hif_compl_thread"); */
  1341. if (scn->ce_count == 0) {
  1342. HIF_ERROR("%s: Invalid ce_count", __func__);
  1343. return -EINVAL;
  1344. }
  1345. if (!hif_msg_callbacks ||
  1346. !hif_msg_callbacks->rxCompletionHandler ||
  1347. !hif_msg_callbacks->txCompletionHandler) {
  1348. HIF_ERROR("%s: no completion handler registered", __func__);
  1349. return -EFAULT;
  1350. }
  1351. A_TARGET_ACCESS_LIKELY(scn);
  1352. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  1353. struct CE_attr attr;
  1354. struct HIF_CE_pipe_info *pipe_info;
  1355. pipe_info = &hif_state->pipe_info[pipe_num];
  1356. if (pipe_info->ce_hdl == ce_diag) {
  1357. continue; /* Handle Diagnostic CE specially */
  1358. }
  1359. attr = hif_state->host_ce_config[pipe_num];
  1360. if (attr.src_nentries) {
  1361. /* pipe used to send to target */
  1362. HIF_INFO_MED("%s: pipe_num:%d pipe_info:0x%p",
  1363. __func__, pipe_num, pipe_info);
  1364. ce_send_cb_register(pipe_info->ce_hdl,
  1365. hif_pci_ce_send_done, pipe_info,
  1366. attr.flags & CE_ATTR_DISABLE_INTR);
  1367. pipe_info->num_sends_allowed = attr.src_nentries - 1;
  1368. }
  1369. if (attr.dest_nentries) {
  1370. /* pipe used to receive from target */
  1371. ce_recv_cb_register(pipe_info->ce_hdl,
  1372. hif_pci_ce_recv_data, pipe_info,
  1373. attr.flags & CE_ATTR_DISABLE_INTR);
  1374. }
  1375. if (attr.src_nentries)
  1376. qdf_spinlock_create(&pipe_info->completion_freeq_lock);
  1377. qdf_mem_copy(&pipe_info->pipe_callbacks, hif_msg_callbacks,
  1378. sizeof(pipe_info->pipe_callbacks));
  1379. }
  1380. A_TARGET_ACCESS_UNLIKELY(scn);
  1381. return 0;
  1382. }
  1383. /*
  1384. * Install pending msg callbacks.
  1385. *
  1386. * TBDXXX: This hack is needed because upper layers install msg callbacks
  1387. * for use with HTC before BMI is done; yet this HIF implementation
  1388. * needs to continue to use BMI msg callbacks. Really, upper layers
  1389. * should not register HTC callbacks until AFTER BMI phase.
  1390. */
  1391. static void hif_msg_callbacks_install(struct hif_softc *scn)
  1392. {
  1393. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  1394. qdf_mem_copy(&hif_state->msg_callbacks_current,
  1395. &hif_state->msg_callbacks_pending,
  1396. sizeof(hif_state->msg_callbacks_pending));
  1397. }
  1398. void hif_get_default_pipe(struct hif_opaque_softc *hif_hdl, uint8_t *ULPipe,
  1399. uint8_t *DLPipe)
  1400. {
  1401. int ul_is_polled, dl_is_polled;
  1402. (void)hif_map_service_to_pipe(hif_hdl, HTC_CTRL_RSVD_SVC,
  1403. ULPipe, DLPipe, &ul_is_polled, &dl_is_polled);
  1404. }
  1405. /**
  1406. * hif_dump_pipe_debug_count() - Log error count
  1407. * @scn: hif_softc pointer.
  1408. *
  1409. * Output the pipe error counts of each pipe to log file
  1410. *
  1411. * Return: N/A
  1412. */
  1413. void hif_dump_pipe_debug_count(struct hif_softc *scn)
  1414. {
  1415. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  1416. int pipe_num;
  1417. if (hif_state == NULL) {
  1418. HIF_ERROR("%s hif_state is NULL", __func__);
  1419. return;
  1420. }
  1421. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  1422. struct HIF_CE_pipe_info *pipe_info;
  1423. pipe_info = &hif_state->pipe_info[pipe_num];
  1424. if (pipe_info->nbuf_alloc_err_count > 0 ||
  1425. pipe_info->nbuf_dma_err_count > 0 ||
  1426. pipe_info->nbuf_ce_enqueue_err_count)
  1427. HIF_ERROR(
  1428. "%s: pipe_id = %d, recv_bufs_needed = %d, nbuf_alloc_err_count = %u, nbuf_dma_err_count = %u, nbuf_ce_enqueue_err_count = %u",
  1429. __func__, pipe_info->pipe_num,
  1430. atomic_read(&pipe_info->recv_bufs_needed),
  1431. pipe_info->nbuf_alloc_err_count,
  1432. pipe_info->nbuf_dma_err_count,
  1433. pipe_info->nbuf_ce_enqueue_err_count);
  1434. }
  1435. }
  1436. static int hif_post_recv_buffers_for_pipe(struct HIF_CE_pipe_info *pipe_info)
  1437. {
  1438. struct CE_handle *ce_hdl;
  1439. qdf_size_t buf_sz;
  1440. struct hif_softc *scn = HIF_GET_SOFTC(pipe_info->HIF_CE_state);
  1441. QDF_STATUS ret;
  1442. uint32_t bufs_posted = 0;
  1443. buf_sz = pipe_info->buf_sz;
  1444. if (buf_sz == 0) {
  1445. /* Unused Copy Engine */
  1446. return 0;
  1447. }
  1448. ce_hdl = pipe_info->ce_hdl;
  1449. qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
  1450. while (atomic_read(&pipe_info->recv_bufs_needed) > 0) {
  1451. qdf_dma_addr_t CE_data; /* CE space buffer address */
  1452. qdf_nbuf_t nbuf;
  1453. int status;
  1454. atomic_dec(&pipe_info->recv_bufs_needed);
  1455. qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
  1456. nbuf = qdf_nbuf_alloc(scn->qdf_dev, buf_sz, 0, 4, false);
  1457. if (!nbuf) {
  1458. qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
  1459. pipe_info->nbuf_alloc_err_count++;
  1460. qdf_spin_unlock_bh(
  1461. &pipe_info->recv_bufs_needed_lock);
  1462. HIF_ERROR(
  1463. "%s buf alloc error [%d] needed %d, nbuf_alloc_err_count = %u",
  1464. __func__, pipe_info->pipe_num,
  1465. atomic_read(&pipe_info->recv_bufs_needed),
  1466. pipe_info->nbuf_alloc_err_count);
  1467. atomic_inc(&pipe_info->recv_bufs_needed);
  1468. return 1;
  1469. }
  1470. /*
  1471. * qdf_nbuf_peek_header(nbuf, &data, &unused);
  1472. * CE_data = dma_map_single(dev, data, buf_sz, );
  1473. * DMA_FROM_DEVICE);
  1474. */
  1475. ret =
  1476. qdf_nbuf_map_single(scn->qdf_dev, nbuf,
  1477. QDF_DMA_FROM_DEVICE);
  1478. if (unlikely(ret != QDF_STATUS_SUCCESS)) {
  1479. qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
  1480. pipe_info->nbuf_dma_err_count++;
  1481. qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
  1482. HIF_ERROR(
  1483. "%s buf alloc error [%d] needed %d, nbuf_dma_err_count = %u",
  1484. __func__, pipe_info->pipe_num,
  1485. atomic_read(&pipe_info->recv_bufs_needed),
  1486. pipe_info->nbuf_dma_err_count);
  1487. qdf_nbuf_free(nbuf);
  1488. atomic_inc(&pipe_info->recv_bufs_needed);
  1489. return 1;
  1490. }
  1491. CE_data = qdf_nbuf_get_frag_paddr(nbuf, 0);
  1492. qdf_mem_dma_sync_single_for_device(scn->qdf_dev, CE_data,
  1493. buf_sz, DMA_FROM_DEVICE);
  1494. status = ce_recv_buf_enqueue(ce_hdl, (void *)nbuf, CE_data);
  1495. QDF_ASSERT(status == QDF_STATUS_SUCCESS);
  1496. if (status != EOK) {
  1497. qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
  1498. pipe_info->nbuf_ce_enqueue_err_count++;
  1499. qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
  1500. HIF_ERROR(
  1501. "%s buf alloc error [%d] needed %d, nbuf_alloc_err_count = %u",
  1502. __func__, pipe_info->pipe_num,
  1503. atomic_read(&pipe_info->recv_bufs_needed),
  1504. pipe_info->nbuf_ce_enqueue_err_count);
  1505. qdf_nbuf_unmap_single(scn->qdf_dev, nbuf,
  1506. QDF_DMA_FROM_DEVICE);
  1507. atomic_inc(&pipe_info->recv_bufs_needed);
  1508. qdf_nbuf_free(nbuf);
  1509. return 1;
  1510. }
  1511. qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
  1512. bufs_posted++;
  1513. }
  1514. pipe_info->nbuf_alloc_err_count =
  1515. (pipe_info->nbuf_alloc_err_count > bufs_posted) ?
  1516. pipe_info->nbuf_alloc_err_count - bufs_posted : 0;
  1517. pipe_info->nbuf_dma_err_count =
  1518. (pipe_info->nbuf_dma_err_count > bufs_posted) ?
  1519. pipe_info->nbuf_dma_err_count - bufs_posted : 0;
  1520. pipe_info->nbuf_ce_enqueue_err_count =
  1521. (pipe_info->nbuf_ce_enqueue_err_count > bufs_posted) ?
  1522. pipe_info->nbuf_ce_enqueue_err_count - bufs_posted : 0;
  1523. qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
  1524. return 0;
  1525. }
  1526. /*
  1527. * Try to post all desired receive buffers for all pipes.
  1528. * Returns 0 if all desired buffers are posted,
  1529. * non-zero if were were unable to completely
  1530. * replenish receive buffers.
  1531. */
  1532. static int hif_post_recv_buffers(struct hif_softc *scn)
  1533. {
  1534. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  1535. int pipe_num, rv = 0;
  1536. struct CE_state *ce_state;
  1537. A_TARGET_ACCESS_LIKELY(scn);
  1538. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  1539. struct HIF_CE_pipe_info *pipe_info;
  1540. ce_state = scn->ce_id_to_state[pipe_num];
  1541. pipe_info = &hif_state->pipe_info[pipe_num];
  1542. if (hif_is_nss_wifi_enabled(scn) &&
  1543. ce_state && (ce_state->htt_rx_data)) {
  1544. continue;
  1545. }
  1546. if (hif_post_recv_buffers_for_pipe(pipe_info)) {
  1547. rv = 1;
  1548. goto done;
  1549. }
  1550. }
  1551. done:
  1552. A_TARGET_ACCESS_UNLIKELY(scn);
  1553. return rv;
  1554. }
  1555. QDF_STATUS hif_start(struct hif_opaque_softc *hif_ctx)
  1556. {
  1557. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  1558. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  1559. hif_update_fastpath_recv_bufs_cnt(scn);
  1560. hif_msg_callbacks_install(scn);
  1561. if (hif_completion_thread_startup(hif_state))
  1562. return QDF_STATUS_E_FAILURE;
  1563. /* enable buffer cleanup */
  1564. hif_state->started = true;
  1565. /* Post buffers once to start things off. */
  1566. if (hif_post_recv_buffers(scn)) {
  1567. /* cleanup is done in hif_ce_disable */
  1568. HIF_ERROR("%s:failed to post buffers", __func__);
  1569. return QDF_STATUS_E_FAILURE;
  1570. }
  1571. return QDF_STATUS_SUCCESS;
  1572. }
  1573. void hif_recv_buffer_cleanup_on_pipe(struct HIF_CE_pipe_info *pipe_info)
  1574. {
  1575. struct hif_softc *scn;
  1576. struct CE_handle *ce_hdl;
  1577. uint32_t buf_sz;
  1578. struct HIF_CE_state *hif_state;
  1579. qdf_nbuf_t netbuf;
  1580. qdf_dma_addr_t CE_data;
  1581. void *per_CE_context;
  1582. buf_sz = pipe_info->buf_sz;
  1583. if (buf_sz == 0) {
  1584. /* Unused Copy Engine */
  1585. return;
  1586. }
  1587. hif_state = pipe_info->HIF_CE_state;
  1588. if (!hif_state->started) {
  1589. return;
  1590. }
  1591. scn = HIF_GET_SOFTC(hif_state);
  1592. ce_hdl = pipe_info->ce_hdl;
  1593. if (scn->qdf_dev == NULL) {
  1594. return;
  1595. }
  1596. while (ce_revoke_recv_next
  1597. (ce_hdl, &per_CE_context, (void **)&netbuf,
  1598. &CE_data) == QDF_STATUS_SUCCESS) {
  1599. qdf_nbuf_unmap_single(scn->qdf_dev, netbuf,
  1600. QDF_DMA_FROM_DEVICE);
  1601. qdf_nbuf_free(netbuf);
  1602. }
  1603. }
  1604. void hif_send_buffer_cleanup_on_pipe(struct HIF_CE_pipe_info *pipe_info)
  1605. {
  1606. struct CE_handle *ce_hdl;
  1607. struct HIF_CE_state *hif_state;
  1608. struct hif_softc *scn;
  1609. qdf_nbuf_t netbuf;
  1610. void *per_CE_context;
  1611. qdf_dma_addr_t CE_data;
  1612. unsigned int nbytes;
  1613. unsigned int id;
  1614. uint32_t buf_sz;
  1615. uint32_t toeplitz_hash_result;
  1616. buf_sz = pipe_info->buf_sz;
  1617. if (buf_sz == 0) {
  1618. /* Unused Copy Engine */
  1619. return;
  1620. }
  1621. hif_state = pipe_info->HIF_CE_state;
  1622. if (!hif_state->started) {
  1623. return;
  1624. }
  1625. scn = HIF_GET_SOFTC(hif_state);
  1626. ce_hdl = pipe_info->ce_hdl;
  1627. while (ce_cancel_send_next
  1628. (ce_hdl, &per_CE_context,
  1629. (void **)&netbuf, &CE_data, &nbytes,
  1630. &id, &toeplitz_hash_result) == QDF_STATUS_SUCCESS) {
  1631. if (netbuf != CE_SENDLIST_ITEM_CTXT) {
  1632. /*
  1633. * Packets enqueued by htt_h2t_ver_req_msg() and
  1634. * htt_h2t_rx_ring_cfg_msg_ll() have already been
  1635. * freed in htt_htc_misc_pkt_pool_free() in
  1636. * wlantl_close(), so do not free them here again
  1637. * by checking whether it's the endpoint
  1638. * which they are queued in.
  1639. */
  1640. if (id == scn->htc_htt_tx_endpoint)
  1641. return;
  1642. /* Indicate the completion to higher
  1643. * layer to free the buffer */
  1644. if (pipe_info->pipe_callbacks.
  1645. txCompletionHandler)
  1646. pipe_info->pipe_callbacks.
  1647. txCompletionHandler(pipe_info->
  1648. pipe_callbacks.Context,
  1649. netbuf, id, toeplitz_hash_result);
  1650. }
  1651. }
  1652. }
  1653. /*
  1654. * Cleanup residual buffers for device shutdown:
  1655. * buffers that were enqueued for receive
  1656. * buffers that were to be sent
  1657. * Note: Buffers that had completed but which were
  1658. * not yet processed are on a completion queue. They
  1659. * are handled when the completion thread shuts down.
  1660. */
  1661. void hif_buffer_cleanup(struct HIF_CE_state *hif_state)
  1662. {
  1663. int pipe_num;
  1664. struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
  1665. struct CE_state *ce_state;
  1666. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  1667. struct HIF_CE_pipe_info *pipe_info;
  1668. ce_state = scn->ce_id_to_state[pipe_num];
  1669. if (hif_is_nss_wifi_enabled(scn) && ce_state &&
  1670. ((ce_state->htt_tx_data) ||
  1671. (ce_state->htt_rx_data))) {
  1672. continue;
  1673. }
  1674. pipe_info = &hif_state->pipe_info[pipe_num];
  1675. hif_recv_buffer_cleanup_on_pipe(pipe_info);
  1676. hif_send_buffer_cleanup_on_pipe(pipe_info);
  1677. }
  1678. }
  1679. void hif_flush_surprise_remove(struct hif_opaque_softc *hif_ctx)
  1680. {
  1681. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  1682. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  1683. hif_buffer_cleanup(hif_state);
  1684. }
  1685. void hif_ce_stop(struct hif_softc *scn)
  1686. {
  1687. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  1688. int pipe_num;
  1689. /*
  1690. * before cleaning up any memory, ensure irq &
  1691. * bottom half contexts will not be re-entered
  1692. */
  1693. hif_nointrs(scn);
  1694. scn->hif_init_done = false;
  1695. /*
  1696. * At this point, asynchronous threads are stopped,
  1697. * The Target should not DMA nor interrupt, Host code may
  1698. * not initiate anything more. So we just need to clean
  1699. * up Host-side state.
  1700. */
  1701. if (scn->athdiag_procfs_inited) {
  1702. athdiag_procfs_remove();
  1703. scn->athdiag_procfs_inited = false;
  1704. }
  1705. hif_buffer_cleanup(hif_state);
  1706. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  1707. struct HIF_CE_pipe_info *pipe_info;
  1708. pipe_info = &hif_state->pipe_info[pipe_num];
  1709. if (pipe_info->ce_hdl) {
  1710. ce_fini(pipe_info->ce_hdl);
  1711. pipe_info->ce_hdl = NULL;
  1712. pipe_info->buf_sz = 0;
  1713. }
  1714. }
  1715. if (hif_state->sleep_timer_init) {
  1716. qdf_timer_stop(&hif_state->sleep_timer);
  1717. qdf_timer_free(&hif_state->sleep_timer);
  1718. hif_state->sleep_timer_init = false;
  1719. }
  1720. hif_state->started = false;
  1721. }
  1722. /**
  1723. * hif_get_target_ce_config() - get copy engine configuration
  1724. * @target_ce_config_ret: basic copy engine configuration
  1725. * @target_ce_config_sz_ret: size of the basic configuration in bytes
  1726. * @target_service_to_ce_map_ret: service mapping for the copy engines
  1727. * @target_service_to_ce_map_sz_ret: size of the mapping in bytes
  1728. * @target_shadow_reg_cfg_ret: shadow register configuration
  1729. * @shadow_cfg_sz_ret: size of the shadow register configuration in bytes
  1730. *
  1731. * providing accessor to these values outside of this file.
  1732. * currently these are stored in static pointers to const sections.
  1733. * there are multiple configurations that are selected from at compile time.
  1734. * Runtime selection would need to consider mode, target type and bus type.
  1735. *
  1736. * Return: return by parameter.
  1737. */
  1738. void hif_get_target_ce_config(struct hif_softc *scn,
  1739. struct CE_pipe_config **target_ce_config_ret,
  1740. int *target_ce_config_sz_ret,
  1741. struct service_to_pipe **target_service_to_ce_map_ret,
  1742. int *target_service_to_ce_map_sz_ret,
  1743. struct shadow_reg_cfg **target_shadow_reg_cfg_ret,
  1744. int *shadow_cfg_sz_ret)
  1745. {
  1746. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  1747. *target_ce_config_ret = hif_state->target_ce_config;
  1748. *target_ce_config_sz_ret = hif_state->target_ce_config_sz;
  1749. *target_service_to_ce_map_ret = target_service_to_ce_map;
  1750. *target_service_to_ce_map_sz_ret = target_service_to_ce_map_sz;
  1751. if (target_shadow_reg_cfg_ret)
  1752. *target_shadow_reg_cfg_ret = target_shadow_reg_cfg;
  1753. if (shadow_cfg_sz_ret)
  1754. *shadow_cfg_sz_ret = shadow_cfg_sz;
  1755. }
  1756. /**
  1757. * hif_wlan_enable(): call the platform driver to enable wlan
  1758. * @scn: HIF Context
  1759. *
  1760. * This function passes the con_mode and CE configuration to
  1761. * platform driver to enable wlan.
  1762. *
  1763. * Return: linux error code
  1764. */
  1765. int hif_wlan_enable(struct hif_softc *scn)
  1766. {
  1767. struct pld_wlan_enable_cfg cfg;
  1768. enum pld_driver_mode mode;
  1769. uint32_t con_mode = hif_get_conparam(scn);
  1770. hif_get_target_ce_config(scn,
  1771. (struct CE_pipe_config **)&cfg.ce_tgt_cfg,
  1772. &cfg.num_ce_tgt_cfg,
  1773. (struct service_to_pipe **)&cfg.ce_svc_cfg,
  1774. &cfg.num_ce_svc_pipe_cfg,
  1775. (struct shadow_reg_cfg **)&cfg.shadow_reg_cfg,
  1776. &cfg.num_shadow_reg_cfg);
  1777. /* translate from structure size to array size */
  1778. cfg.num_ce_tgt_cfg /= sizeof(struct CE_pipe_config);
  1779. cfg.num_ce_svc_pipe_cfg /= sizeof(struct service_to_pipe);
  1780. cfg.num_shadow_reg_cfg /= sizeof(struct shadow_reg_cfg);
  1781. if (QDF_GLOBAL_FTM_MODE == con_mode)
  1782. mode = PLD_FTM;
  1783. else if (QDF_IS_EPPING_ENABLED(con_mode))
  1784. mode = PLD_EPPING;
  1785. else
  1786. mode = PLD_MISSION;
  1787. if (BYPASS_QMI)
  1788. return 0;
  1789. else
  1790. return pld_wlan_enable(scn->qdf_dev->dev, &cfg,
  1791. mode, QWLAN_VERSIONSTR);
  1792. }
  1793. #define CE_EPPING_USES_IRQ true
  1794. /**
  1795. * hif_ce_prepare_config() - load the correct static tables.
  1796. * @scn: hif context
  1797. *
  1798. * Epping uses different static attribute tables than mission mode.
  1799. */
  1800. void hif_ce_prepare_config(struct hif_softc *scn)
  1801. {
  1802. uint32_t mode = hif_get_conparam(scn);
  1803. struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
  1804. struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl);
  1805. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  1806. /* if epping is enabled we need to use the epping configuration. */
  1807. if (QDF_IS_EPPING_ENABLED(mode)) {
  1808. if (CE_EPPING_USES_IRQ)
  1809. hif_state->host_ce_config = host_ce_config_wlan_epping_irq;
  1810. else
  1811. hif_state->host_ce_config = host_ce_config_wlan_epping_poll;
  1812. hif_state->target_ce_config = target_ce_config_wlan_epping;
  1813. hif_state->target_ce_config_sz = sizeof(target_ce_config_wlan_epping);
  1814. target_service_to_ce_map =
  1815. target_service_to_ce_map_wlan_epping;
  1816. target_service_to_ce_map_sz =
  1817. sizeof(target_service_to_ce_map_wlan_epping);
  1818. target_shadow_reg_cfg = target_shadow_reg_cfg_epping;
  1819. shadow_cfg_sz = sizeof(target_shadow_reg_cfg_epping);
  1820. }
  1821. switch (tgt_info->target_type) {
  1822. default:
  1823. hif_state->host_ce_config = host_ce_config_wlan;
  1824. hif_state->target_ce_config = target_ce_config_wlan;
  1825. hif_state->target_ce_config_sz = sizeof(target_ce_config_wlan);
  1826. break;
  1827. case TARGET_TYPE_AR900B:
  1828. case TARGET_TYPE_QCA9984:
  1829. case TARGET_TYPE_IPQ4019:
  1830. case TARGET_TYPE_QCA9888:
  1831. if (hif_is_attribute_set(scn, HIF_LOWDESC_CE_NO_PKTLOG_CFG)) {
  1832. hif_state->host_ce_config =
  1833. host_lowdesc_ce_cfg_wlan_ar900b_nopktlog;
  1834. } else if (hif_is_attribute_set(scn, HIF_LOWDESC_CE_CFG)) {
  1835. hif_state->host_ce_config =
  1836. host_lowdesc_ce_cfg_wlan_ar900b;
  1837. } else {
  1838. hif_state->host_ce_config = host_ce_config_wlan_ar900b;
  1839. }
  1840. hif_state->target_ce_config = target_ce_config_wlan_ar900b;
  1841. hif_state->target_ce_config_sz =
  1842. sizeof(target_ce_config_wlan_ar900b);
  1843. target_service_to_ce_map = target_service_to_ce_map_ar900b;
  1844. target_service_to_ce_map_sz =
  1845. sizeof(target_service_to_ce_map_ar900b);
  1846. break;
  1847. case TARGET_TYPE_AR9888:
  1848. case TARGET_TYPE_AR9888V2:
  1849. if (hif_is_attribute_set(scn, HIF_LOWDESC_CE_CFG)) {
  1850. hif_state->host_ce_config = host_lowdesc_ce_cfg_wlan_ar9888;
  1851. } else {
  1852. hif_state->host_ce_config = host_ce_config_wlan_ar9888;
  1853. }
  1854. hif_state->target_ce_config = target_ce_config_wlan_ar9888;
  1855. hif_state->target_ce_config_sz =
  1856. sizeof(target_ce_config_wlan_ar9888);
  1857. target_service_to_ce_map = target_service_to_ce_map_ar900b;
  1858. target_service_to_ce_map_sz =
  1859. sizeof(target_service_to_ce_map_ar900b);
  1860. break;
  1861. case TARGET_TYPE_QCA8074:
  1862. hif_state->host_ce_config = host_ce_config_wlan_qca8074;
  1863. hif_state->target_ce_config = target_ce_config_wlan_qca8074;
  1864. hif_state->target_ce_config_sz =
  1865. sizeof(target_ce_config_wlan_qca8074);
  1866. break;
  1867. case TARGET_TYPE_QCA6290:
  1868. hif_state->host_ce_config = host_ce_config_wlan_qca6290;
  1869. hif_state->target_ce_config = target_ce_config_wlan_qca6290;
  1870. hif_state->target_ce_config_sz =
  1871. sizeof(target_ce_config_wlan_qca6290);
  1872. break;
  1873. }
  1874. }
  1875. /**
  1876. * hif_ce_open() - do ce specific allocations
  1877. * @hif_sc: pointer to hif context
  1878. *
  1879. * return: 0 for success or QDF_STATUS_E_NOMEM
  1880. */
  1881. QDF_STATUS hif_ce_open(struct hif_softc *hif_sc)
  1882. {
  1883. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc);
  1884. qdf_spinlock_create(&hif_state->irq_reg_lock);
  1885. qdf_spinlock_create(&hif_state->keep_awake_lock);
  1886. return QDF_STATUS_SUCCESS;
  1887. }
  1888. /**
  1889. * hif_ce_close() - do ce specific free
  1890. * @hif_sc: pointer to hif context
  1891. */
  1892. void hif_ce_close(struct hif_softc *hif_sc)
  1893. {
  1894. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc);
  1895. qdf_spinlock_destroy(&hif_state->irq_reg_lock);
  1896. }
  1897. /**
  1898. * hif_unconfig_ce() - ensure resources from hif_config_ce are freed
  1899. * @hif_sc: hif context
  1900. *
  1901. * uses state variables to support cleaning up when hif_config_ce fails.
  1902. */
  1903. void hif_unconfig_ce(struct hif_softc *hif_sc)
  1904. {
  1905. int pipe_num;
  1906. struct HIF_CE_pipe_info *pipe_info;
  1907. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc);
  1908. for (pipe_num = 0; pipe_num < hif_sc->ce_count; pipe_num++) {
  1909. pipe_info = &hif_state->pipe_info[pipe_num];
  1910. if (pipe_info->ce_hdl) {
  1911. ce_unregister_irq(hif_state, (1 << pipe_num));
  1912. hif_sc->request_irq_done = false;
  1913. ce_fini(pipe_info->ce_hdl);
  1914. pipe_info->ce_hdl = NULL;
  1915. pipe_info->buf_sz = 0;
  1916. }
  1917. }
  1918. if (hif_sc->athdiag_procfs_inited) {
  1919. athdiag_procfs_remove();
  1920. hif_sc->athdiag_procfs_inited = false;
  1921. }
  1922. }
  1923. #ifdef CONFIG_BYPASS_QMI
  1924. #define FW_SHARED_MEM (2 * 1024 * 1024)
  1925. /**
  1926. * hif_post_static_buf_to_target() - post static buffer to WLAN FW
  1927. * @scn: pointer to HIF structure
  1928. *
  1929. * WLAN FW needs 2MB memory from DDR when QMI is disabled.
  1930. *
  1931. * Return: void
  1932. */
  1933. static void hif_post_static_buf_to_target(struct hif_softc *scn)
  1934. {
  1935. void *target_va;
  1936. phys_addr_t target_pa;
  1937. target_va = qdf_mem_alloc_consistent(scn->qdf_dev, scn->qdf_dev->dev,
  1938. FW_SHARED_MEM, &target_pa);
  1939. if (NULL == target_va) {
  1940. HIF_TRACE("Memory allocation failed could not post target buf");
  1941. return;
  1942. }
  1943. hif_write32_mb(scn->mem + BYPASS_QMI_TEMP_REGISTER, target_pa);
  1944. HIF_TRACE("target va %pK target pa %pa", target_va, &target_pa);
  1945. }
  1946. #else
  1947. static inline void hif_post_static_buf_to_target(struct hif_softc *scn)
  1948. {
  1949. return;
  1950. }
  1951. #endif
  1952. #ifdef WLAN_SUSPEND_RESUME_TEST
  1953. static void hif_fake_apps_init_ctx(struct hif_softc *scn)
  1954. {
  1955. INIT_WORK(&scn->fake_apps_ctx.resume_work,
  1956. hif_fake_apps_resume_work);
  1957. }
  1958. #else
  1959. static inline void hif_fake_apps_init_ctx(struct hif_softc *scn) {}
  1960. #endif
  1961. /**
  1962. * hif_config_ce() - configure copy engines
  1963. * @scn: hif context
  1964. *
  1965. * Prepares fw, copy engine hardware and host sw according
  1966. * to the attributes selected by hif_ce_prepare_config.
  1967. *
  1968. * also calls athdiag_procfs_init
  1969. *
  1970. * return: 0 for success nonzero for failure.
  1971. */
  1972. int hif_config_ce(struct hif_softc *scn)
  1973. {
  1974. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  1975. struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
  1976. struct HIF_CE_pipe_info *pipe_info;
  1977. int pipe_num;
  1978. struct CE_state *ce_state;
  1979. #ifdef ADRASTEA_SHADOW_REGISTERS
  1980. int i;
  1981. #endif
  1982. QDF_STATUS rv = QDF_STATUS_SUCCESS;
  1983. scn->notice_send = true;
  1984. hif_post_static_buf_to_target(scn);
  1985. hif_state->fw_indicator_address = FW_INDICATOR_ADDRESS;
  1986. hif_config_rri_on_ddr(scn);
  1987. hif_state->ce_services = ce_services_attach(scn);
  1988. /* During CE initializtion */
  1989. scn->ce_count = HOST_CE_COUNT;
  1990. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  1991. struct CE_attr *attr;
  1992. pipe_info = &hif_state->pipe_info[pipe_num];
  1993. pipe_info->pipe_num = pipe_num;
  1994. pipe_info->HIF_CE_state = hif_state;
  1995. attr = &hif_state->host_ce_config[pipe_num];
  1996. pipe_info->ce_hdl = ce_init(scn, pipe_num, attr);
  1997. ce_state = scn->ce_id_to_state[pipe_num];
  1998. QDF_ASSERT(pipe_info->ce_hdl != NULL);
  1999. if (pipe_info->ce_hdl == NULL) {
  2000. rv = QDF_STATUS_E_FAILURE;
  2001. A_TARGET_ACCESS_UNLIKELY(scn);
  2002. goto err;
  2003. }
  2004. if (pipe_num == DIAG_CE_ID) {
  2005. /* Reserve the ultimate CE for
  2006. * Diagnostic Window support */
  2007. hif_state->ce_diag = pipe_info->ce_hdl;
  2008. continue;
  2009. }
  2010. if (hif_is_nss_wifi_enabled(scn) && ce_state &&
  2011. (ce_state->htt_rx_data))
  2012. continue;
  2013. pipe_info->buf_sz = (qdf_size_t) (attr->src_sz_max);
  2014. qdf_spinlock_create(&pipe_info->recv_bufs_needed_lock);
  2015. if (attr->dest_nentries > 0) {
  2016. atomic_set(&pipe_info->recv_bufs_needed,
  2017. init_buffer_count(attr->dest_nentries - 1));
  2018. /*SRNG based CE has one entry less */
  2019. if (ce_srng_based(scn))
  2020. atomic_dec(&pipe_info->recv_bufs_needed);
  2021. } else {
  2022. atomic_set(&pipe_info->recv_bufs_needed, 0);
  2023. }
  2024. ce_tasklet_init(hif_state, (1 << pipe_num));
  2025. ce_register_irq(hif_state, (1 << pipe_num));
  2026. scn->request_irq_done = true;
  2027. }
  2028. if (athdiag_procfs_init(scn) != 0) {
  2029. A_TARGET_ACCESS_UNLIKELY(scn);
  2030. goto err;
  2031. }
  2032. scn->athdiag_procfs_inited = true;
  2033. HIF_INFO_MED("%s: ce_init done", __func__);
  2034. init_tasklet_workers(hif_hdl);
  2035. hif_fake_apps_init_ctx(scn);
  2036. HIF_TRACE("%s: X, ret = %d", __func__, rv);
  2037. #ifdef ADRASTEA_SHADOW_REGISTERS
  2038. HIF_INFO("%s, Using Shadow Registers instead of CE Registers", __func__);
  2039. for (i = 0; i < NUM_SHADOW_REGISTERS; i++) {
  2040. HIF_INFO("%s Shadow Register%d is mapped to address %x",
  2041. __func__, i,
  2042. (A_TARGET_READ(scn, (SHADOW_ADDRESS(i))) << 2));
  2043. }
  2044. #endif
  2045. return rv != QDF_STATUS_SUCCESS;
  2046. err:
  2047. /* Failure, so clean up */
  2048. hif_unconfig_ce(scn);
  2049. HIF_TRACE("%s: X, ret = %d", __func__, rv);
  2050. return QDF_STATUS_SUCCESS != QDF_STATUS_E_FAILURE;
  2051. }
  2052. #ifdef WLAN_FEATURE_FASTPATH
  2053. /**
  2054. * hif_ce_fastpath_cb_register() - Register callback for fastpath msg handler
  2055. * @handler: Callback funtcion
  2056. * @context: handle for callback function
  2057. *
  2058. * Return: QDF_STATUS_SUCCESS on success or QDF_STATUS_E_FAILURE
  2059. */
  2060. int hif_ce_fastpath_cb_register(struct hif_opaque_softc *hif_ctx,
  2061. fastpath_msg_handler handler,
  2062. void *context)
  2063. {
  2064. struct CE_state *ce_state;
  2065. struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
  2066. int i;
  2067. if (!scn) {
  2068. HIF_ERROR("%s: scn is NULL", __func__);
  2069. QDF_ASSERT(0);
  2070. return QDF_STATUS_E_FAILURE;
  2071. }
  2072. if (!scn->fastpath_mode_on) {
  2073. HIF_WARN("%s: Fastpath mode disabled", __func__);
  2074. return QDF_STATUS_E_FAILURE;
  2075. }
  2076. for (i = 0; i < scn->ce_count; i++) {
  2077. ce_state = scn->ce_id_to_state[i];
  2078. if (ce_state->htt_rx_data) {
  2079. ce_state->fastpath_handler = handler;
  2080. ce_state->context = context;
  2081. }
  2082. }
  2083. return QDF_STATUS_SUCCESS;
  2084. }
  2085. #endif
  2086. #ifdef IPA_OFFLOAD
  2087. /**
  2088. * hif_ce_ipa_get_ce_resource() - get uc resource on hif
  2089. * @scn: bus context
  2090. * @ce_sr_base_paddr: copyengine source ring base physical address
  2091. * @ce_sr_ring_size: copyengine source ring size
  2092. * @ce_reg_paddr: copyengine register physical address
  2093. *
  2094. * IPA micro controller data path offload feature enabled,
  2095. * HIF should release copy engine related resource information to IPA UC
  2096. * IPA UC will access hardware resource with released information
  2097. *
  2098. * Return: None
  2099. */
  2100. void hif_ce_ipa_get_ce_resource(struct hif_softc *scn,
  2101. qdf_dma_addr_t *ce_sr_base_paddr,
  2102. uint32_t *ce_sr_ring_size,
  2103. qdf_dma_addr_t *ce_reg_paddr)
  2104. {
  2105. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  2106. struct HIF_CE_pipe_info *pipe_info =
  2107. &(hif_state->pipe_info[HIF_PCI_IPA_UC_ASSIGNED_CE]);
  2108. struct CE_handle *ce_hdl = pipe_info->ce_hdl;
  2109. ce_ipa_get_resource(ce_hdl, ce_sr_base_paddr, ce_sr_ring_size,
  2110. ce_reg_paddr);
  2111. return;
  2112. }
  2113. #endif /* IPA_OFFLOAD */
  2114. #ifdef ADRASTEA_SHADOW_REGISTERS
  2115. /*
  2116. Current shadow register config
  2117. -----------------------------------------------------------
  2118. Shadow Register | CE | src/dst write index
  2119. -----------------------------------------------------------
  2120. 0 | 0 | src
  2121. 1 No Config - Doesn't point to anything
  2122. 2 No Config - Doesn't point to anything
  2123. 3 | 3 | src
  2124. 4 | 4 | src
  2125. 5 | 5 | src
  2126. 6 No Config - Doesn't point to anything
  2127. 7 | 7 | src
  2128. 8 No Config - Doesn't point to anything
  2129. 9 No Config - Doesn't point to anything
  2130. 10 No Config - Doesn't point to anything
  2131. 11 No Config - Doesn't point to anything
  2132. -----------------------------------------------------------
  2133. 12 No Config - Doesn't point to anything
  2134. 13 | 1 | dst
  2135. 14 | 2 | dst
  2136. 15 No Config - Doesn't point to anything
  2137. 16 No Config - Doesn't point to anything
  2138. 17 No Config - Doesn't point to anything
  2139. 18 No Config - Doesn't point to anything
  2140. 19 | 7 | dst
  2141. 20 | 8 | dst
  2142. 21 No Config - Doesn't point to anything
  2143. 22 No Config - Doesn't point to anything
  2144. 23 No Config - Doesn't point to anything
  2145. -----------------------------------------------------------
  2146. ToDo - Move shadow register config to following in the future
  2147. This helps free up a block of shadow registers towards the end.
  2148. Can be used for other purposes
  2149. -----------------------------------------------------------
  2150. Shadow Register | CE | src/dst write index
  2151. -----------------------------------------------------------
  2152. 0 | 0 | src
  2153. 1 | 3 | src
  2154. 2 | 4 | src
  2155. 3 | 5 | src
  2156. 4 | 7 | src
  2157. -----------------------------------------------------------
  2158. 5 | 1 | dst
  2159. 6 | 2 | dst
  2160. 7 | 7 | dst
  2161. 8 | 8 | dst
  2162. -----------------------------------------------------------
  2163. 9 No Config - Doesn't point to anything
  2164. 12 No Config - Doesn't point to anything
  2165. 13 No Config - Doesn't point to anything
  2166. 14 No Config - Doesn't point to anything
  2167. 15 No Config - Doesn't point to anything
  2168. 16 No Config - Doesn't point to anything
  2169. 17 No Config - Doesn't point to anything
  2170. 18 No Config - Doesn't point to anything
  2171. 19 No Config - Doesn't point to anything
  2172. 20 No Config - Doesn't point to anything
  2173. 21 No Config - Doesn't point to anything
  2174. 22 No Config - Doesn't point to anything
  2175. 23 No Config - Doesn't point to anything
  2176. -----------------------------------------------------------
  2177. */
  2178. u32 shadow_sr_wr_ind_addr(struct hif_softc *scn, u32 ctrl_addr)
  2179. {
  2180. u32 addr = 0;
  2181. u32 ce = COPY_ENGINE_ID(ctrl_addr);
  2182. switch (ce) {
  2183. case 0:
  2184. addr = SHADOW_VALUE0;
  2185. break;
  2186. case 3:
  2187. addr = SHADOW_VALUE3;
  2188. break;
  2189. case 4:
  2190. addr = SHADOW_VALUE4;
  2191. break;
  2192. case 5:
  2193. addr = SHADOW_VALUE5;
  2194. break;
  2195. case 7:
  2196. addr = SHADOW_VALUE7;
  2197. break;
  2198. default:
  2199. HIF_ERROR("invalid CE ctrl_addr (CE=%d)", ce);
  2200. QDF_ASSERT(0);
  2201. }
  2202. return addr;
  2203. }
  2204. u32 shadow_dst_wr_ind_addr(struct hif_softc *scn, u32 ctrl_addr)
  2205. {
  2206. u32 addr = 0;
  2207. u32 ce = COPY_ENGINE_ID(ctrl_addr);
  2208. switch (ce) {
  2209. case 1:
  2210. addr = SHADOW_VALUE13;
  2211. break;
  2212. case 2:
  2213. addr = SHADOW_VALUE14;
  2214. break;
  2215. case 5:
  2216. addr = SHADOW_VALUE17;
  2217. break;
  2218. case 7:
  2219. addr = SHADOW_VALUE19;
  2220. break;
  2221. case 8:
  2222. addr = SHADOW_VALUE20;
  2223. break;
  2224. case 9:
  2225. addr = SHADOW_VALUE21;
  2226. break;
  2227. case 10:
  2228. addr = SHADOW_VALUE22;
  2229. break;
  2230. case 11:
  2231. addr = SHADOW_VALUE23;
  2232. break;
  2233. default:
  2234. HIF_ERROR("invalid CE ctrl_addr (CE=%d)", ce);
  2235. QDF_ASSERT(0);
  2236. }
  2237. return addr;
  2238. }
  2239. #endif
  2240. #if defined(FEATURE_LRO)
  2241. void *hif_ce_get_lro_ctx(struct hif_opaque_softc *hif_hdl, int ctx_id)
  2242. {
  2243. struct CE_state *ce_state;
  2244. struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
  2245. QDF_ASSERT(scn != NULL);
  2246. ce_state = scn->ce_id_to_state[ctx_id];
  2247. return ce_state->lro_data;
  2248. }
  2249. /**
  2250. * ce_lro_flush_cb_register() - register the LRO flush
  2251. * callback
  2252. * @scn: HIF context
  2253. * @handler: callback function
  2254. * @data: opaque data pointer to be passed back
  2255. *
  2256. * Store the LRO flush callback provided
  2257. *
  2258. * Return: Number of instances the callback is registered for
  2259. */
  2260. int ce_lro_flush_cb_register(struct hif_opaque_softc *hif_hdl,
  2261. void (handler)(void *),
  2262. void *(lro_init_handler)(void))
  2263. {
  2264. int rc = 0;
  2265. int i;
  2266. struct CE_state *ce_state;
  2267. struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
  2268. void *data = NULL;
  2269. QDF_ASSERT(scn != NULL);
  2270. if (scn != NULL) {
  2271. for (i = 0; i < scn->ce_count; i++) {
  2272. ce_state = scn->ce_id_to_state[i];
  2273. if ((ce_state != NULL) && (ce_state->htt_rx_data)) {
  2274. data = lro_init_handler();
  2275. if (data == NULL) {
  2276. HIF_ERROR("%s: Failed to init LRO for CE %d",
  2277. __func__, i);
  2278. continue;
  2279. }
  2280. ce_state->lro_flush_cb = handler;
  2281. ce_state->lro_data = data;
  2282. rc++;
  2283. }
  2284. }
  2285. } else {
  2286. HIF_ERROR("%s: hif_state NULL!", __func__);
  2287. }
  2288. return rc;
  2289. }
  2290. /**
  2291. * ce_lro_flush_cb_deregister() - deregister the LRO flush
  2292. * callback
  2293. * @scn: HIF context
  2294. *
  2295. * Remove the LRO flush callback
  2296. *
  2297. * Return: Number of instances the callback is de-registered
  2298. */
  2299. int ce_lro_flush_cb_deregister(struct hif_opaque_softc *hif_hdl,
  2300. void (lro_deinit_cb)(void *))
  2301. {
  2302. int rc = 0;
  2303. int i;
  2304. struct CE_state *ce_state;
  2305. struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
  2306. QDF_ASSERT(scn != NULL);
  2307. if (scn != NULL) {
  2308. for (i = 0; i < scn->ce_count; i++) {
  2309. ce_state = scn->ce_id_to_state[i];
  2310. if ((ce_state != NULL) && (ce_state->htt_rx_data)) {
  2311. qdf_spin_lock_bh(
  2312. &ce_state->lro_unloading_lock);
  2313. ce_state->lro_flush_cb = NULL;
  2314. lro_deinit_cb(ce_state->lro_data);
  2315. ce_state->lro_data = NULL;
  2316. qdf_spin_unlock_bh(
  2317. &ce_state->lro_unloading_lock);
  2318. qdf_spinlock_destroy(
  2319. &ce_state->lro_unloading_lock);
  2320. rc++;
  2321. }
  2322. }
  2323. } else {
  2324. HIF_ERROR("%s: hif_state NULL!", __func__);
  2325. }
  2326. return rc;
  2327. }
  2328. #endif
  2329. /**
  2330. * hif_map_service_to_pipe() - returns the ce ids pertaining to
  2331. * this service
  2332. * @scn: hif_softc pointer.
  2333. * @svc_id: Service ID for which the mapping is needed.
  2334. * @ul_pipe: address of the container in which ul pipe is returned.
  2335. * @dl_pipe: address of the container in which dl pipe is returned.
  2336. * @ul_is_polled: address of the container in which a bool
  2337. * indicating if the UL CE for this service
  2338. * is polled is returned.
  2339. * @dl_is_polled: address of the container in which a bool
  2340. * indicating if the DL CE for this service
  2341. * is polled is returned.
  2342. *
  2343. * Return: Indicates whether the service has been found in the table.
  2344. * Upon return, ul_is_polled is updated only if ul_pipe is updated.
  2345. * There will be warning logs if either leg has not been updated
  2346. * because it missed the entry in the table (but this is not an err).
  2347. */
  2348. int hif_map_service_to_pipe(struct hif_opaque_softc *hif_hdl, uint16_t svc_id,
  2349. uint8_t *ul_pipe, uint8_t *dl_pipe, int *ul_is_polled,
  2350. int *dl_is_polled)
  2351. {
  2352. int status = QDF_STATUS_E_INVAL;
  2353. unsigned int i;
  2354. struct service_to_pipe element;
  2355. struct service_to_pipe *tgt_svc_map_to_use;
  2356. size_t sz_tgt_svc_map_to_use;
  2357. struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
  2358. uint32_t mode = hif_get_conparam(scn);
  2359. struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl);
  2360. bool dl_updated = false;
  2361. bool ul_updated = false;
  2362. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  2363. if (QDF_IS_EPPING_ENABLED(mode)) {
  2364. tgt_svc_map_to_use = target_service_to_ce_map_wlan_epping;
  2365. sz_tgt_svc_map_to_use =
  2366. sizeof(target_service_to_ce_map_wlan_epping);
  2367. } else {
  2368. switch (tgt_info->target_type) {
  2369. default:
  2370. tgt_svc_map_to_use = target_service_to_ce_map_wlan;
  2371. sz_tgt_svc_map_to_use =
  2372. sizeof(target_service_to_ce_map_wlan);
  2373. break;
  2374. case TARGET_TYPE_AR900B:
  2375. case TARGET_TYPE_QCA9984:
  2376. case TARGET_TYPE_IPQ4019:
  2377. case TARGET_TYPE_QCA9888:
  2378. case TARGET_TYPE_AR9888:
  2379. case TARGET_TYPE_AR9888V2:
  2380. tgt_svc_map_to_use = target_service_to_ce_map_ar900b;
  2381. sz_tgt_svc_map_to_use =
  2382. sizeof(target_service_to_ce_map_ar900b);
  2383. break;
  2384. }
  2385. }
  2386. *dl_is_polled = 0; /* polling for received messages not supported */
  2387. for (i = 0; i < (sz_tgt_svc_map_to_use/sizeof(element)); i++) {
  2388. memcpy(&element, &tgt_svc_map_to_use[i], sizeof(element));
  2389. if (element.service_id == svc_id) {
  2390. if (element.pipedir == PIPEDIR_OUT) {
  2391. *ul_pipe = element.pipenum;
  2392. *ul_is_polled =
  2393. (hif_state->host_ce_config[*ul_pipe].flags &
  2394. CE_ATTR_DISABLE_INTR) != 0;
  2395. ul_updated = true;
  2396. } else if (element.pipedir == PIPEDIR_IN) {
  2397. *dl_pipe = element.pipenum;
  2398. dl_updated = true;
  2399. }
  2400. status = QDF_STATUS_SUCCESS;
  2401. }
  2402. }
  2403. if (ul_updated == false)
  2404. HIF_WARN("%s: ul pipe is NOT updated for service %d",
  2405. __func__, svc_id);
  2406. if (dl_updated == false)
  2407. HIF_WARN("%s: dl pipe is NOT updated for service %d",
  2408. __func__, svc_id);
  2409. return status;
  2410. }
  2411. #ifdef SHADOW_REG_DEBUG
  2412. inline uint32_t DEBUG_CE_SRC_RING_READ_IDX_GET(struct hif_softc *scn,
  2413. uint32_t CE_ctrl_addr)
  2414. {
  2415. uint32_t read_from_hw, srri_from_ddr = 0;
  2416. read_from_hw = A_TARGET_READ(scn, CE_ctrl_addr + CURRENT_SRRI_ADDRESS);
  2417. srri_from_ddr = SRRI_FROM_DDR_ADDR(VADDR_FOR_CE(scn, CE_ctrl_addr));
  2418. if (read_from_hw != srri_from_ddr) {
  2419. HIF_ERROR("%s: error: read from ddr = %d actual read from register = %d, CE_MISC_INT_STATUS_GET = 0x%x",
  2420. __func__, srri_from_ddr, read_from_hw,
  2421. CE_MISC_INT_STATUS_GET(scn, CE_ctrl_addr));
  2422. QDF_ASSERT(0);
  2423. }
  2424. return srri_from_ddr;
  2425. }
  2426. inline uint32_t DEBUG_CE_DEST_RING_READ_IDX_GET(struct hif_softc *scn,
  2427. uint32_t CE_ctrl_addr)
  2428. {
  2429. uint32_t read_from_hw, drri_from_ddr = 0;
  2430. read_from_hw = A_TARGET_READ(scn, CE_ctrl_addr + CURRENT_DRRI_ADDRESS);
  2431. drri_from_ddr = DRRI_FROM_DDR_ADDR(VADDR_FOR_CE(scn, CE_ctrl_addr));
  2432. if (read_from_hw != drri_from_ddr) {
  2433. HIF_ERROR("error: read from ddr = %d actual read from register = %d, CE_MISC_INT_STATUS_GET = 0x%x",
  2434. drri_from_ddr, read_from_hw,
  2435. CE_MISC_INT_STATUS_GET(scn, CE_ctrl_addr));
  2436. QDF_ASSERT(0);
  2437. }
  2438. return drri_from_ddr;
  2439. }
  2440. #endif
  2441. #ifdef ADRASTEA_RRI_ON_DDR
  2442. /**
  2443. * hif_get_src_ring_read_index(): Called to get the SRRI
  2444. *
  2445. * @scn: hif_softc pointer
  2446. * @CE_ctrl_addr: base address of the CE whose RRI is to be read
  2447. *
  2448. * This function returns the SRRI to the caller. For CEs that
  2449. * dont have interrupts enabled, we look at the DDR based SRRI
  2450. *
  2451. * Return: SRRI
  2452. */
  2453. inline unsigned int hif_get_src_ring_read_index(struct hif_softc *scn,
  2454. uint32_t CE_ctrl_addr)
  2455. {
  2456. struct CE_attr attr;
  2457. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  2458. attr = hif_state->host_ce_config[COPY_ENGINE_ID(CE_ctrl_addr)];
  2459. if (attr.flags & CE_ATTR_DISABLE_INTR)
  2460. return CE_SRC_RING_READ_IDX_GET_FROM_DDR(scn, CE_ctrl_addr);
  2461. else
  2462. return A_TARGET_READ(scn,
  2463. (CE_ctrl_addr) + CURRENT_SRRI_ADDRESS);
  2464. }
  2465. /**
  2466. * hif_get_dst_ring_read_index(): Called to get the DRRI
  2467. *
  2468. * @scn: hif_softc pointer
  2469. * @CE_ctrl_addr: base address of the CE whose RRI is to be read
  2470. *
  2471. * This function returns the DRRI to the caller. For CEs that
  2472. * dont have interrupts enabled, we look at the DDR based DRRI
  2473. *
  2474. * Return: DRRI
  2475. */
  2476. inline unsigned int hif_get_dst_ring_read_index(struct hif_softc *scn,
  2477. uint32_t CE_ctrl_addr)
  2478. {
  2479. struct CE_attr attr;
  2480. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  2481. attr = hif_state->host_ce_config[COPY_ENGINE_ID(CE_ctrl_addr)];
  2482. if (attr.flags & CE_ATTR_DISABLE_INTR)
  2483. return CE_DEST_RING_READ_IDX_GET_FROM_DDR(scn, CE_ctrl_addr);
  2484. else
  2485. return A_TARGET_READ(scn,
  2486. (CE_ctrl_addr) + CURRENT_DRRI_ADDRESS);
  2487. }
  2488. /**
  2489. * hif_config_rri_on_ddr(): Configure the RRI on DDR mechanism
  2490. *
  2491. * @scn: hif_softc pointer
  2492. *
  2493. * This function allocates non cached memory on ddr and sends
  2494. * the physical address of this memory to the CE hardware. The
  2495. * hardware updates the RRI on this particular location.
  2496. *
  2497. * Return: None
  2498. */
  2499. static inline void hif_config_rri_on_ddr(struct hif_softc *scn)
  2500. {
  2501. unsigned int i;
  2502. qdf_dma_addr_t paddr_rri_on_ddr;
  2503. uint32_t high_paddr, low_paddr;
  2504. scn->vaddr_rri_on_ddr =
  2505. (uint32_t *)qdf_mem_alloc_consistent(scn->qdf_dev,
  2506. scn->qdf_dev->dev, (CE_COUNT*sizeof(uint32_t)),
  2507. &paddr_rri_on_ddr);
  2508. low_paddr = BITS0_TO_31(paddr_rri_on_ddr);
  2509. high_paddr = BITS32_TO_35(paddr_rri_on_ddr);
  2510. HIF_INFO("%s using srri and drri from DDR", __func__);
  2511. WRITE_CE_DDR_ADDRESS_FOR_RRI_LOW(scn, low_paddr);
  2512. WRITE_CE_DDR_ADDRESS_FOR_RRI_HIGH(scn, high_paddr);
  2513. for (i = 0; i < CE_COUNT; i++)
  2514. CE_IDX_UPD_EN_SET(scn, CE_BASE_ADDRESS(i));
  2515. qdf_mem_zero(scn->vaddr_rri_on_ddr, CE_COUNT*sizeof(uint32_t));
  2516. return;
  2517. }
  2518. #else
  2519. /**
  2520. * hif_config_rri_on_ddr(): Configure the RRI on DDR mechanism
  2521. *
  2522. * @scn: hif_softc pointer
  2523. *
  2524. * This is a dummy implementation for platforms that don't
  2525. * support this functionality.
  2526. *
  2527. * Return: None
  2528. */
  2529. static inline void hif_config_rri_on_ddr(struct hif_softc *scn)
  2530. {
  2531. return;
  2532. }
  2533. #endif
  2534. /**
  2535. * hif_dump_ce_registers() - dump ce registers
  2536. * @scn: hif_opaque_softc pointer.
  2537. *
  2538. * Output the copy engine registers
  2539. *
  2540. * Return: 0 for success or error code
  2541. */
  2542. int hif_dump_ce_registers(struct hif_softc *scn)
  2543. {
  2544. struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
  2545. uint32_t ce_reg_address = CE0_BASE_ADDRESS;
  2546. uint32_t ce_reg_values[CE_USEFUL_SIZE >> 2];
  2547. uint32_t ce_reg_word_size = CE_USEFUL_SIZE >> 2;
  2548. uint16_t i;
  2549. QDF_STATUS status;
  2550. for (i = 0; i < scn->ce_count; i++, ce_reg_address += CE_OFFSET) {
  2551. if (scn->ce_id_to_state[i] == NULL) {
  2552. HIF_DBG("CE%d not used.", i);
  2553. continue;
  2554. }
  2555. status = hif_diag_read_mem(hif_hdl, ce_reg_address,
  2556. (uint8_t *) &ce_reg_values[0],
  2557. ce_reg_word_size * sizeof(uint32_t));
  2558. if (status != QDF_STATUS_SUCCESS) {
  2559. HIF_ERROR("Dumping CE register failed!");
  2560. return -EACCES;
  2561. }
  2562. HIF_ERROR("CE%d=>\n", i);
  2563. qdf_trace_hex_dump(QDF_MODULE_ID_HIF, QDF_TRACE_LEVEL_DEBUG,
  2564. (uint8_t *) &ce_reg_values[0],
  2565. ce_reg_word_size * sizeof(uint32_t));
  2566. qdf_print("ADDR:[0x%08X], SR_WR_INDEX:%d\n", (ce_reg_address
  2567. + SR_WR_INDEX_ADDRESS),
  2568. ce_reg_values[SR_WR_INDEX_ADDRESS/4]);
  2569. qdf_print("ADDR:[0x%08X], CURRENT_SRRI:%d\n", (ce_reg_address
  2570. + CURRENT_SRRI_ADDRESS),
  2571. ce_reg_values[CURRENT_SRRI_ADDRESS/4]);
  2572. qdf_print("ADDR:[0x%08X], DST_WR_INDEX:%d\n", (ce_reg_address
  2573. + DST_WR_INDEX_ADDRESS),
  2574. ce_reg_values[DST_WR_INDEX_ADDRESS/4]);
  2575. qdf_print("ADDR:[0x%08X], CURRENT_DRRI:%d\n", (ce_reg_address
  2576. + CURRENT_DRRI_ADDRESS),
  2577. ce_reg_values[CURRENT_DRRI_ADDRESS/4]);
  2578. qdf_print("---\n");
  2579. }
  2580. return 0;
  2581. }
  2582. #ifdef QCA_NSS_WIFI_OFFLOAD_SUPPORT
  2583. struct hif_pipe_addl_info *hif_get_addl_pipe_info(struct hif_opaque_softc *osc,
  2584. struct hif_pipe_addl_info *hif_info, uint32_t pipe)
  2585. {
  2586. struct hif_softc *scn = HIF_GET_SOFTC(osc);
  2587. struct hif_pci_softc *sc = HIF_GET_PCI_SOFTC(scn);
  2588. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(osc);
  2589. struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
  2590. struct CE_handle *ce_hdl = pipe_info->ce_hdl;
  2591. struct CE_state *ce_state = (struct CE_state *)ce_hdl;
  2592. struct CE_ring_state *src_ring = ce_state->src_ring;
  2593. struct CE_ring_state *dest_ring = ce_state->dest_ring;
  2594. if (src_ring) {
  2595. hif_info->ul_pipe.nentries = src_ring->nentries;
  2596. hif_info->ul_pipe.nentries_mask = src_ring->nentries_mask;
  2597. hif_info->ul_pipe.sw_index = src_ring->sw_index;
  2598. hif_info->ul_pipe.write_index = src_ring->write_index;
  2599. hif_info->ul_pipe.hw_index = src_ring->hw_index;
  2600. hif_info->ul_pipe.base_addr_CE_space =
  2601. src_ring->base_addr_CE_space;
  2602. hif_info->ul_pipe.base_addr_owner_space =
  2603. src_ring->base_addr_owner_space;
  2604. }
  2605. if (dest_ring) {
  2606. hif_info->dl_pipe.nentries = dest_ring->nentries;
  2607. hif_info->dl_pipe.nentries_mask = dest_ring->nentries_mask;
  2608. hif_info->dl_pipe.sw_index = dest_ring->sw_index;
  2609. hif_info->dl_pipe.write_index = dest_ring->write_index;
  2610. hif_info->dl_pipe.hw_index = dest_ring->hw_index;
  2611. hif_info->dl_pipe.base_addr_CE_space =
  2612. dest_ring->base_addr_CE_space;
  2613. hif_info->dl_pipe.base_addr_owner_space =
  2614. dest_ring->base_addr_owner_space;
  2615. }
  2616. hif_info->pci_mem = pci_resource_start(sc->pdev, 0);
  2617. hif_info->ctrl_addr = ce_state->ctrl_addr;
  2618. return hif_info;
  2619. }
  2620. uint32_t hif_set_nss_wifiol_mode(struct hif_opaque_softc *osc, uint32_t mode)
  2621. {
  2622. struct hif_softc *scn = HIF_GET_SOFTC(osc);
  2623. scn->nss_wifi_ol_mode = mode;
  2624. return 0;
  2625. }
  2626. #endif
  2627. void hif_set_attribute(struct hif_opaque_softc *osc, uint8_t hif_attrib)
  2628. {
  2629. struct hif_softc *scn = HIF_GET_SOFTC(osc);
  2630. scn->hif_attribute = hif_attrib;
  2631. }
  2632. void hif_disable_interrupt(struct hif_opaque_softc *osc, uint32_t pipe_num)
  2633. {
  2634. struct hif_softc *scn = HIF_GET_SOFTC(osc);
  2635. struct CE_state *CE_state = scn->ce_id_to_state[pipe_num];
  2636. uint32_t ctrl_addr = CE_state->ctrl_addr;
  2637. Q_TARGET_ACCESS_BEGIN(scn);
  2638. CE_COPY_COMPLETE_INTR_DISABLE(scn, ctrl_addr);
  2639. Q_TARGET_ACCESS_END(scn);
  2640. }
  2641. /**
  2642. * hif_fw_event_handler() - hif fw event handler
  2643. * @hif_state: pointer to hif ce state structure
  2644. *
  2645. * Process fw events and raise HTC callback to process fw events.
  2646. *
  2647. * Return: none
  2648. */
  2649. static inline void hif_fw_event_handler(struct HIF_CE_state *hif_state)
  2650. {
  2651. struct hif_msg_callbacks *msg_callbacks =
  2652. &hif_state->msg_callbacks_current;
  2653. if (!msg_callbacks->fwEventHandler)
  2654. return;
  2655. msg_callbacks->fwEventHandler(msg_callbacks->Context,
  2656. QDF_STATUS_E_FAILURE);
  2657. }
  2658. #ifndef QCA_WIFI_3_0
  2659. /**
  2660. * hif_fw_interrupt_handler() - FW interrupt handler
  2661. * @irq: irq number
  2662. * @arg: the user pointer
  2663. *
  2664. * Called from the PCI interrupt handler when a
  2665. * firmware-generated interrupt to the Host.
  2666. *
  2667. * Return: status of handled irq
  2668. */
  2669. irqreturn_t hif_fw_interrupt_handler(int irq, void *arg)
  2670. {
  2671. struct hif_softc *scn = arg;
  2672. struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
  2673. uint32_t fw_indicator_address, fw_indicator;
  2674. if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
  2675. return ATH_ISR_NOSCHED;
  2676. fw_indicator_address = hif_state->fw_indicator_address;
  2677. /* For sudden unplug this will return ~0 */
  2678. fw_indicator = A_TARGET_READ(scn, fw_indicator_address);
  2679. if ((fw_indicator != ~0) && (fw_indicator & FW_IND_EVENT_PENDING)) {
  2680. /* ACK: clear Target-side pending event */
  2681. A_TARGET_WRITE(scn, fw_indicator_address,
  2682. fw_indicator & ~FW_IND_EVENT_PENDING);
  2683. if (Q_TARGET_ACCESS_END(scn) < 0)
  2684. return ATH_ISR_SCHED;
  2685. if (hif_state->started) {
  2686. hif_fw_event_handler(hif_state);
  2687. } else {
  2688. /*
  2689. * Probable Target failure before we're prepared
  2690. * to handle it. Generally unexpected.
  2691. */
  2692. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  2693. ("%s: Early firmware event indicated\n",
  2694. __func__));
  2695. }
  2696. } else {
  2697. if (Q_TARGET_ACCESS_END(scn) < 0)
  2698. return ATH_ISR_SCHED;
  2699. }
  2700. return ATH_ISR_SCHED;
  2701. }
  2702. #else
  2703. irqreturn_t hif_fw_interrupt_handler(int irq, void *arg)
  2704. {
  2705. return ATH_ISR_SCHED;
  2706. }
  2707. #endif /* #ifdef QCA_WIFI_3_0 */
  2708. /**
  2709. * hif_wlan_disable(): call the platform driver to disable wlan
  2710. * @scn: HIF Context
  2711. *
  2712. * This function passes the con_mode to platform driver to disable
  2713. * wlan.
  2714. *
  2715. * Return: void
  2716. */
  2717. void hif_wlan_disable(struct hif_softc *scn)
  2718. {
  2719. enum pld_driver_mode mode;
  2720. uint32_t con_mode = hif_get_conparam(scn);
  2721. if (QDF_GLOBAL_FTM_MODE == con_mode)
  2722. mode = PLD_FTM;
  2723. else if (QDF_IS_EPPING_ENABLED(con_mode))
  2724. mode = PLD_EPPING;
  2725. else
  2726. mode = PLD_MISSION;
  2727. pld_wlan_disable(scn->qdf_dev->dev, mode);
  2728. }