ce_main.c 78 KB

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