ce_main.c 84 KB

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