ce_main.c 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480
  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 <osdep.h>
  27. #include "a_types.h"
  28. #include "athdefs.h"
  29. #include "osapi_linux.h"
  30. #include "targcfg.h"
  31. #include "cdf_lock.h"
  32. #include "cdf_status.h"
  33. #include <cdf_atomic.h> /* cdf_atomic_read */
  34. #include <targaddrs.h>
  35. #include <bmi_msg.h>
  36. #include "hif_io32.h"
  37. #include <hif.h>
  38. #include "regtable.h"
  39. #define ATH_MODULE_NAME hif
  40. #include <a_debug.h>
  41. #include "hif_main.h"
  42. #ifdef HIF_PCI
  43. #include "ce_bmi.h"
  44. #endif
  45. #include "ce_api.h"
  46. #include "cdf_trace.h"
  47. #include "cds_api.h"
  48. #ifdef CONFIG_CNSS
  49. #include <net/cnss.h>
  50. #endif
  51. #include "epping_main.h"
  52. #include "hif_debug.h"
  53. #include "ce_internal.h"
  54. #include "ce_reg.h"
  55. #include "ce_assignment.h"
  56. #include "ce_tasklet.h"
  57. #ifdef HIF_PCI
  58. #include "icnss_stub.h"
  59. #else
  60. #include <soc/qcom/icnss.h>
  61. #endif
  62. #include "qwlan_version.h"
  63. #include "cds_concurrency.h"
  64. #define CE_POLL_TIMEOUT 10 /* ms */
  65. /* Forward references */
  66. static int hif_post_recv_buffers_for_pipe(struct HIF_CE_pipe_info *pipe_info);
  67. /*
  68. * Fix EV118783, poll to check whether a BMI response comes
  69. * other than waiting for the interruption which may be lost.
  70. */
  71. /* #define BMI_RSP_POLLING */
  72. #define BMI_RSP_TO_MILLISEC 1000
  73. static int hif_post_recv_buffers(struct ol_softc *scn);
  74. static void hif_config_rri_on_ddr(struct ol_softc *scn);
  75. static void ce_poll_timeout(void *arg)
  76. {
  77. struct CE_state *CE_state = (struct CE_state *)arg;
  78. if (CE_state->timer_inited) {
  79. ce_per_engine_service(CE_state->scn, CE_state->id);
  80. cdf_softirq_timer_mod(&CE_state->poll_timer, CE_POLL_TIMEOUT);
  81. }
  82. }
  83. static unsigned int roundup_pwr2(unsigned int n)
  84. {
  85. int i;
  86. unsigned int test_pwr2;
  87. if (!(n & (n - 1)))
  88. return n; /* already a power of 2 */
  89. test_pwr2 = 4;
  90. for (i = 0; i < 29; i++) {
  91. if (test_pwr2 > n)
  92. return test_pwr2;
  93. test_pwr2 = test_pwr2 << 1;
  94. }
  95. CDF_ASSERT(0); /* n too large */
  96. return 0;
  97. }
  98. /*
  99. * Initialize a Copy Engine based on caller-supplied attributes.
  100. * This may be called once to initialize both source and destination
  101. * rings or it may be called twice for separate source and destination
  102. * initialization. It may be that only one side or the other is
  103. * initialized by software/firmware.
  104. *
  105. * This should be called durring the initialization sequence before
  106. * interupts are enabled, so we don't have to worry about thread safety.
  107. */
  108. struct CE_handle *ce_init(struct ol_softc *scn,
  109. unsigned int CE_id, struct CE_attr *attr)
  110. {
  111. struct CE_state *CE_state;
  112. uint32_t ctrl_addr;
  113. unsigned int nentries;
  114. cdf_dma_addr_t base_addr;
  115. bool malloc_CE_state = false;
  116. bool malloc_src_ring = false;
  117. CDF_ASSERT(CE_id < scn->ce_count);
  118. ctrl_addr = CE_BASE_ADDRESS(CE_id);
  119. CE_state = scn->ce_id_to_state[CE_id];
  120. if (!CE_state) {
  121. CE_state =
  122. (struct CE_state *)cdf_mem_malloc(sizeof(*CE_state));
  123. if (!CE_state) {
  124. HIF_ERROR("%s: CE_state has no mem", __func__);
  125. return NULL;
  126. }
  127. malloc_CE_state = true;
  128. cdf_mem_zero(CE_state, sizeof(*CE_state));
  129. scn->ce_id_to_state[CE_id] = CE_state;
  130. cdf_spinlock_init(&CE_state->ce_index_lock);
  131. CE_state->id = CE_id;
  132. CE_state->ctrl_addr = ctrl_addr;
  133. CE_state->state = CE_RUNNING;
  134. CE_state->attr_flags = attr->flags;
  135. }
  136. CE_state->scn = scn;
  137. cdf_atomic_init(&CE_state->rx_pending);
  138. if (attr == NULL) {
  139. /* Already initialized; caller wants the handle */
  140. return (struct CE_handle *)CE_state;
  141. }
  142. #ifdef ADRASTEA_SHADOW_REGISTERS
  143. HIF_ERROR("%s: Using Shadow Registers instead of CE Registers\n",
  144. __func__);
  145. #endif
  146. if (CE_state->src_sz_max)
  147. CDF_ASSERT(CE_state->src_sz_max == attr->src_sz_max);
  148. else
  149. CE_state->src_sz_max = attr->src_sz_max;
  150. ce_init_ce_desc_event_log(CE_id,
  151. attr->src_nentries + attr->dest_nentries);
  152. /* source ring setup */
  153. nentries = attr->src_nentries;
  154. if (nentries) {
  155. struct CE_ring_state *src_ring;
  156. unsigned CE_nbytes;
  157. char *ptr;
  158. uint64_t dma_addr;
  159. nentries = roundup_pwr2(nentries);
  160. if (CE_state->src_ring) {
  161. CDF_ASSERT(CE_state->src_ring->nentries == nentries);
  162. } else {
  163. CE_nbytes = sizeof(struct CE_ring_state)
  164. + (nentries * sizeof(void *));
  165. ptr = cdf_mem_malloc(CE_nbytes);
  166. if (!ptr) {
  167. /* cannot allocate src ring. If the
  168. * CE_state is allocated locally free
  169. * CE_State and return error.
  170. */
  171. HIF_ERROR("%s: src ring has no mem", __func__);
  172. if (malloc_CE_state) {
  173. /* allocated CE_state locally */
  174. scn->ce_id_to_state[CE_id] = NULL;
  175. cdf_mem_free(CE_state);
  176. malloc_CE_state = false;
  177. }
  178. return NULL;
  179. } else {
  180. /* we can allocate src ring.
  181. * Mark that the src ring is
  182. * allocated locally
  183. */
  184. malloc_src_ring = true;
  185. }
  186. cdf_mem_zero(ptr, CE_nbytes);
  187. src_ring = CE_state->src_ring =
  188. (struct CE_ring_state *)ptr;
  189. ptr += sizeof(struct CE_ring_state);
  190. src_ring->nentries = nentries;
  191. src_ring->nentries_mask = nentries - 1;
  192. A_TARGET_ACCESS_BEGIN_RET_PTR(scn);
  193. src_ring->hw_index =
  194. CE_SRC_RING_READ_IDX_GET(scn, ctrl_addr);
  195. src_ring->sw_index = src_ring->hw_index;
  196. src_ring->write_index =
  197. CE_SRC_RING_WRITE_IDX_GET(scn, ctrl_addr);
  198. A_TARGET_ACCESS_END_RET_PTR(scn);
  199. src_ring->low_water_mark_nentries = 0;
  200. src_ring->high_water_mark_nentries = nentries;
  201. src_ring->per_transfer_context = (void **)ptr;
  202. /* Legacy platforms that do not support cache
  203. * coherent DMA are unsupported
  204. */
  205. src_ring->base_addr_owner_space_unaligned =
  206. cdf_os_mem_alloc_consistent(scn->cdf_dev,
  207. (nentries *
  208. sizeof(struct CE_src_desc) +
  209. CE_DESC_RING_ALIGN),
  210. &base_addr, 0);
  211. if (src_ring->base_addr_owner_space_unaligned
  212. == NULL) {
  213. HIF_ERROR("%s: src ring has no DMA mem",
  214. __func__);
  215. goto error_no_dma_mem;
  216. }
  217. src_ring->base_addr_CE_space_unaligned = base_addr;
  218. if (src_ring->
  219. base_addr_CE_space_unaligned & (CE_DESC_RING_ALIGN
  220. - 1)) {
  221. src_ring->base_addr_CE_space =
  222. (src_ring->base_addr_CE_space_unaligned
  223. + CE_DESC_RING_ALIGN -
  224. 1) & ~(CE_DESC_RING_ALIGN - 1);
  225. src_ring->base_addr_owner_space =
  226. (void
  227. *)(((size_t) src_ring->
  228. base_addr_owner_space_unaligned +
  229. CE_DESC_RING_ALIGN -
  230. 1) & ~(CE_DESC_RING_ALIGN - 1));
  231. } else {
  232. src_ring->base_addr_CE_space =
  233. src_ring->base_addr_CE_space_unaligned;
  234. src_ring->base_addr_owner_space =
  235. src_ring->
  236. base_addr_owner_space_unaligned;
  237. }
  238. /*
  239. * Also allocate a shadow src ring in
  240. * regular mem to use for faster access.
  241. */
  242. src_ring->shadow_base_unaligned =
  243. cdf_mem_malloc(nentries *
  244. sizeof(struct CE_src_desc) +
  245. CE_DESC_RING_ALIGN);
  246. if (src_ring->shadow_base_unaligned == NULL) {
  247. HIF_ERROR("%s: src ring no shadow_base mem",
  248. __func__);
  249. goto error_no_dma_mem;
  250. }
  251. src_ring->shadow_base = (struct CE_src_desc *)
  252. (((size_t) src_ring->shadow_base_unaligned +
  253. CE_DESC_RING_ALIGN - 1) &
  254. ~(CE_DESC_RING_ALIGN - 1));
  255. A_TARGET_ACCESS_BEGIN_RET_PTR(scn);
  256. dma_addr = src_ring->base_addr_CE_space;
  257. CE_SRC_RING_BASE_ADDR_SET(scn, ctrl_addr,
  258. (uint32_t)(dma_addr & 0xFFFFFFFF));
  259. #ifdef WLAN_ENABLE_QCA6180
  260. {
  261. uint32_t tmp;
  262. tmp = CE_SRC_RING_BASE_ADDR_HIGH_GET(
  263. scn, ctrl_addr);
  264. tmp &= ~0x1F;
  265. dma_addr = ((dma_addr >> 32) & 0x1F)|tmp;
  266. CE_SRC_RING_BASE_ADDR_HIGH_SET(scn,
  267. ctrl_addr, (uint32_t)dma_addr);
  268. }
  269. #endif
  270. CE_SRC_RING_SZ_SET(scn, ctrl_addr, nentries);
  271. CE_SRC_RING_DMAX_SET(scn, ctrl_addr, attr->src_sz_max);
  272. #ifdef BIG_ENDIAN_HOST
  273. /* Enable source ring byte swap for big endian host */
  274. CE_SRC_RING_BYTE_SWAP_SET(scn, ctrl_addr, 1);
  275. #endif
  276. CE_SRC_RING_LOWMARK_SET(scn, ctrl_addr, 0);
  277. CE_SRC_RING_HIGHMARK_SET(scn, ctrl_addr, nentries);
  278. A_TARGET_ACCESS_END_RET_PTR(scn);
  279. }
  280. }
  281. /* destination ring setup */
  282. nentries = attr->dest_nentries;
  283. if (nentries) {
  284. struct CE_ring_state *dest_ring;
  285. unsigned CE_nbytes;
  286. char *ptr;
  287. uint64_t dma_addr;
  288. nentries = roundup_pwr2(nentries);
  289. if (CE_state->dest_ring) {
  290. CDF_ASSERT(CE_state->dest_ring->nentries == nentries);
  291. } else {
  292. CE_nbytes = sizeof(struct CE_ring_state)
  293. + (nentries * sizeof(void *));
  294. ptr = cdf_mem_malloc(CE_nbytes);
  295. if (!ptr) {
  296. /* cannot allocate dst ring. If the CE_state
  297. * or src ring is allocated locally free
  298. * CE_State and src ring and return error.
  299. */
  300. HIF_ERROR("%s: dest ring has no mem",
  301. __func__);
  302. if (malloc_src_ring) {
  303. cdf_mem_free(CE_state->src_ring);
  304. CE_state->src_ring = NULL;
  305. malloc_src_ring = false;
  306. }
  307. if (malloc_CE_state) {
  308. /* allocated CE_state locally */
  309. scn->ce_id_to_state[CE_id] = NULL;
  310. cdf_mem_free(CE_state);
  311. malloc_CE_state = false;
  312. }
  313. return NULL;
  314. }
  315. cdf_mem_zero(ptr, CE_nbytes);
  316. dest_ring = CE_state->dest_ring =
  317. (struct CE_ring_state *)ptr;
  318. ptr += sizeof(struct CE_ring_state);
  319. dest_ring->nentries = nentries;
  320. dest_ring->nentries_mask = nentries - 1;
  321. A_TARGET_ACCESS_BEGIN_RET_PTR(scn);
  322. dest_ring->sw_index =
  323. CE_DEST_RING_READ_IDX_GET(scn, ctrl_addr);
  324. dest_ring->write_index =
  325. CE_DEST_RING_WRITE_IDX_GET(scn, ctrl_addr);
  326. A_TARGET_ACCESS_END_RET_PTR(scn);
  327. dest_ring->low_water_mark_nentries = 0;
  328. dest_ring->high_water_mark_nentries = nentries;
  329. dest_ring->per_transfer_context = (void **)ptr;
  330. /* Legacy platforms that do not support cache
  331. * coherent DMA are unsupported */
  332. dest_ring->base_addr_owner_space_unaligned =
  333. cdf_os_mem_alloc_consistent(scn->cdf_dev,
  334. (nentries *
  335. sizeof(struct CE_dest_desc) +
  336. CE_DESC_RING_ALIGN),
  337. &base_addr, 0);
  338. if (dest_ring->base_addr_owner_space_unaligned
  339. == NULL) {
  340. HIF_ERROR("%s: dest ring has no DMA mem",
  341. __func__);
  342. goto error_no_dma_mem;
  343. }
  344. dest_ring->base_addr_CE_space_unaligned = base_addr;
  345. /* Correctly initialize memory to 0 to
  346. * prevent garbage data crashing system
  347. * when download firmware
  348. */
  349. cdf_mem_zero(dest_ring->base_addr_owner_space_unaligned,
  350. nentries * sizeof(struct CE_dest_desc) +
  351. CE_DESC_RING_ALIGN);
  352. if (dest_ring->
  353. base_addr_CE_space_unaligned & (CE_DESC_RING_ALIGN -
  354. 1)) {
  355. dest_ring->base_addr_CE_space =
  356. (dest_ring->
  357. base_addr_CE_space_unaligned +
  358. CE_DESC_RING_ALIGN -
  359. 1) & ~(CE_DESC_RING_ALIGN - 1);
  360. dest_ring->base_addr_owner_space =
  361. (void
  362. *)(((size_t) dest_ring->
  363. base_addr_owner_space_unaligned +
  364. CE_DESC_RING_ALIGN -
  365. 1) & ~(CE_DESC_RING_ALIGN - 1));
  366. } else {
  367. dest_ring->base_addr_CE_space =
  368. dest_ring->base_addr_CE_space_unaligned;
  369. dest_ring->base_addr_owner_space =
  370. dest_ring->
  371. base_addr_owner_space_unaligned;
  372. }
  373. A_TARGET_ACCESS_BEGIN_RET_PTR(scn);
  374. dma_addr = dest_ring->base_addr_CE_space;
  375. CE_DEST_RING_BASE_ADDR_SET(scn, ctrl_addr,
  376. (uint32_t)(dma_addr & 0xFFFFFFFF));
  377. #ifdef WLAN_ENABLE_QCA6180
  378. {
  379. uint32_t tmp;
  380. tmp = CE_DEST_RING_BASE_ADDR_HIGH_GET(scn,
  381. ctrl_addr);
  382. tmp &= ~0x1F;
  383. dma_addr = ((dma_addr >> 32) & 0x1F)|tmp;
  384. CE_DEST_RING_BASE_ADDR_HIGH_SET(scn,
  385. ctrl_addr, (uint32_t)dma_addr);
  386. }
  387. #endif
  388. CE_DEST_RING_SZ_SET(scn, ctrl_addr, nentries);
  389. #ifdef BIG_ENDIAN_HOST
  390. /* Enable Dest ring byte swap for big endian host */
  391. CE_DEST_RING_BYTE_SWAP_SET(scn, ctrl_addr, 1);
  392. #endif
  393. CE_DEST_RING_LOWMARK_SET(scn, ctrl_addr, 0);
  394. CE_DEST_RING_HIGHMARK_SET(scn, ctrl_addr, nentries);
  395. A_TARGET_ACCESS_END_RET_PTR(scn);
  396. /* epping */
  397. /* poll timer */
  398. if ((CE_state->attr_flags & CE_ATTR_ENABLE_POLL)) {
  399. cdf_softirq_timer_init(scn->cdf_dev,
  400. &CE_state->poll_timer,
  401. ce_poll_timeout,
  402. CE_state,
  403. CDF_TIMER_TYPE_SW);
  404. CE_state->timer_inited = true;
  405. cdf_softirq_timer_mod(&CE_state->poll_timer,
  406. CE_POLL_TIMEOUT);
  407. }
  408. }
  409. }
  410. /* Enable CE error interrupts */
  411. A_TARGET_ACCESS_BEGIN_RET_PTR(scn);
  412. CE_ERROR_INTR_ENABLE(scn, ctrl_addr);
  413. A_TARGET_ACCESS_END_RET_PTR(scn);
  414. return (struct CE_handle *)CE_state;
  415. error_no_dma_mem:
  416. ce_fini((struct CE_handle *)CE_state);
  417. return NULL;
  418. }
  419. #ifdef WLAN_FEATURE_FASTPATH
  420. /**
  421. * ce_h2t_tx_ce_cleanup() Place holder function for H2T CE cleanup.
  422. * No processing is required inside this function.
  423. * @ce_hdl: Cope engine handle
  424. * Using an assert, this function makes sure that,
  425. * the TX CE has been processed completely.
  426. *
  427. * This is called while dismantling CE structures. No other thread
  428. * should be using these structures while dismantling is occuring
  429. * therfore no locking is needed.
  430. *
  431. * Return: none
  432. */
  433. void
  434. ce_h2t_tx_ce_cleanup(struct CE_handle *ce_hdl)
  435. {
  436. struct CE_state *ce_state = (struct CE_state *)ce_hdl;
  437. struct CE_ring_state *src_ring = ce_state->src_ring;
  438. struct ol_softc *sc = ce_state->scn;
  439. uint32_t sw_index, write_index;
  440. if (sc->fastpath_mode_on && (ce_state->id == CE_HTT_H2T_MSG)) {
  441. HIF_INFO("%s %d Fastpath mode ON, Cleaning up HTT Tx CE\n",
  442. __func__, __LINE__);
  443. sw_index = src_ring->sw_index;
  444. write_index = src_ring->sw_index;
  445. /* At this point Tx CE should be clean */
  446. cdf_assert_always(sw_index == write_index);
  447. }
  448. }
  449. #else
  450. void ce_h2t_tx_ce_cleanup(struct CE_handle *ce_hdl)
  451. {
  452. }
  453. #endif /* WLAN_FEATURE_FASTPATH */
  454. void ce_fini(struct CE_handle *copyeng)
  455. {
  456. struct CE_state *CE_state = (struct CE_state *)copyeng;
  457. unsigned int CE_id = CE_state->id;
  458. struct ol_softc *scn = CE_state->scn;
  459. CE_state->state = CE_UNUSED;
  460. scn->ce_id_to_state[CE_id] = NULL;
  461. if (CE_state->src_ring) {
  462. /* Cleanup the HTT Tx ring */
  463. ce_h2t_tx_ce_cleanup(copyeng);
  464. if (CE_state->src_ring->shadow_base_unaligned)
  465. cdf_mem_free(CE_state->src_ring->shadow_base_unaligned);
  466. if (CE_state->src_ring->base_addr_owner_space_unaligned)
  467. cdf_os_mem_free_consistent(scn->cdf_dev,
  468. (CE_state->src_ring->nentries *
  469. sizeof(struct CE_src_desc) +
  470. CE_DESC_RING_ALIGN),
  471. CE_state->src_ring->
  472. base_addr_owner_space_unaligned,
  473. CE_state->src_ring->
  474. base_addr_CE_space, 0);
  475. cdf_mem_free(CE_state->src_ring);
  476. }
  477. if (CE_state->dest_ring) {
  478. if (CE_state->dest_ring->base_addr_owner_space_unaligned)
  479. cdf_os_mem_free_consistent(scn->cdf_dev,
  480. (CE_state->dest_ring->nentries *
  481. sizeof(struct CE_dest_desc) +
  482. CE_DESC_RING_ALIGN),
  483. CE_state->dest_ring->
  484. base_addr_owner_space_unaligned,
  485. CE_state->dest_ring->
  486. base_addr_CE_space, 0);
  487. cdf_mem_free(CE_state->dest_ring);
  488. /* epping */
  489. if (CE_state->timer_inited) {
  490. CE_state->timer_inited = false;
  491. cdf_softirq_timer_free(&CE_state->poll_timer);
  492. }
  493. }
  494. cdf_mem_free(CE_state);
  495. }
  496. void hif_detach_htc(struct ol_softc *scn)
  497. {
  498. struct HIF_CE_state *hif_state = (struct HIF_CE_state *)scn->hif_hdl;
  499. cdf_mem_zero(&hif_state->msg_callbacks_pending,
  500. sizeof(hif_state->msg_callbacks_pending));
  501. cdf_mem_zero(&hif_state->msg_callbacks_current,
  502. sizeof(hif_state->msg_callbacks_current));
  503. }
  504. /* Send the first nbytes bytes of the buffer */
  505. CDF_STATUS
  506. hif_send_head(struct ol_softc *scn,
  507. uint8_t pipe, unsigned int transfer_id, unsigned int nbytes,
  508. cdf_nbuf_t nbuf, unsigned int data_attr)
  509. {
  510. struct HIF_CE_state *hif_state = (struct HIF_CE_state *)scn->hif_hdl;
  511. struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
  512. struct CE_handle *ce_hdl = pipe_info->ce_hdl;
  513. int bytes = nbytes, nfrags = 0;
  514. struct ce_sendlist sendlist;
  515. int status, i = 0;
  516. unsigned int mux_id = 0;
  517. CDF_ASSERT(nbytes <= cdf_nbuf_len(nbuf));
  518. transfer_id =
  519. (mux_id & MUX_ID_MASK) |
  520. (transfer_id & TRANSACTION_ID_MASK);
  521. data_attr &= DESC_DATA_FLAG_MASK;
  522. /*
  523. * The common case involves sending multiple fragments within a
  524. * single download (the tx descriptor and the tx frame header).
  525. * So, optimize for the case of multiple fragments by not even
  526. * checking whether it's necessary to use a sendlist.
  527. * The overhead of using a sendlist for a single buffer download
  528. * is not a big deal, since it happens rarely (for WMI messages).
  529. */
  530. ce_sendlist_init(&sendlist);
  531. do {
  532. uint32_t frag_paddr;
  533. int frag_bytes;
  534. frag_paddr = cdf_nbuf_get_frag_paddr_lo(nbuf, nfrags);
  535. frag_bytes = cdf_nbuf_get_frag_len(nbuf, nfrags);
  536. /*
  537. * Clear the packet offset for all but the first CE desc.
  538. */
  539. if (i++ > 0)
  540. data_attr &= ~CDF_CE_TX_PKT_OFFSET_BIT_M;
  541. status = ce_sendlist_buf_add(&sendlist, frag_paddr,
  542. frag_bytes >
  543. bytes ? bytes : frag_bytes,
  544. cdf_nbuf_get_frag_is_wordstream
  545. (nbuf,
  546. nfrags) ? 0 :
  547. CE_SEND_FLAG_SWAP_DISABLE,
  548. data_attr);
  549. if (status != CDF_STATUS_SUCCESS) {
  550. HIF_ERROR("%s: error, frag_num %d larger than limit",
  551. __func__, nfrags);
  552. return status;
  553. }
  554. bytes -= frag_bytes;
  555. nfrags++;
  556. } while (bytes > 0);
  557. /* Make sure we have resources to handle this request */
  558. cdf_spin_lock_bh(&pipe_info->completion_freeq_lock);
  559. if (pipe_info->num_sends_allowed < nfrags) {
  560. cdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
  561. ce_pkt_error_count_incr(hif_state, HIF_PIPE_NO_RESOURCE);
  562. return CDF_STATUS_E_RESOURCES;
  563. }
  564. pipe_info->num_sends_allowed -= nfrags;
  565. cdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
  566. if (cdf_unlikely(ce_hdl == NULL)) {
  567. HIF_ERROR("%s: error CE handle is null", __func__);
  568. return A_ERROR;
  569. }
  570. NBUF_UPDATE_TX_PKT_COUNT(nbuf, NBUF_TX_PKT_HIF);
  571. DPTRACE(cdf_dp_trace(nbuf, CDF_DP_TRACE_HIF_PACKET_PTR_RECORD,
  572. (uint8_t *)(cdf_nbuf_data(nbuf)),
  573. sizeof(cdf_nbuf_data(nbuf))));
  574. status = ce_sendlist_send(ce_hdl, nbuf, &sendlist, transfer_id);
  575. CDF_ASSERT(status == CDF_STATUS_SUCCESS);
  576. return status;
  577. }
  578. void hif_send_complete_check(struct ol_softc *scn, uint8_t pipe, int force)
  579. {
  580. if (!force) {
  581. int resources;
  582. /*
  583. * Decide whether to actually poll for completions, or just
  584. * wait for a later chance. If there seem to be plenty of
  585. * resources left, then just wait, since checking involves
  586. * reading a CE register, which is a relatively expensive
  587. * operation.
  588. */
  589. resources = hif_get_free_queue_number(scn, pipe);
  590. /*
  591. * If at least 50% of the total resources are still available,
  592. * don't bother checking again yet.
  593. */
  594. if (resources > (host_ce_config[pipe].src_nentries >> 1)) {
  595. return;
  596. }
  597. }
  598. #ifdef ATH_11AC_TXCOMPACT
  599. ce_per_engine_servicereap(scn, pipe);
  600. #else
  601. ce_per_engine_service(scn, pipe);
  602. #endif
  603. }
  604. uint16_t hif_get_free_queue_number(struct ol_softc *scn, uint8_t pipe)
  605. {
  606. struct HIF_CE_state *hif_state = (struct HIF_CE_state *)scn->hif_hdl;
  607. struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
  608. uint16_t rv;
  609. cdf_spin_lock_bh(&pipe_info->completion_freeq_lock);
  610. rv = pipe_info->num_sends_allowed;
  611. cdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
  612. return rv;
  613. }
  614. /* Called by lower (CE) layer when a send to Target completes. */
  615. void
  616. hif_pci_ce_send_done(struct CE_handle *copyeng, void *ce_context,
  617. void *transfer_context, cdf_dma_addr_t CE_data,
  618. unsigned int nbytes, unsigned int transfer_id,
  619. unsigned int sw_index, unsigned int hw_index,
  620. unsigned int toeplitz_hash_result)
  621. {
  622. struct HIF_CE_pipe_info *pipe_info =
  623. (struct HIF_CE_pipe_info *)ce_context;
  624. struct HIF_CE_state *hif_state = pipe_info->HIF_CE_state;
  625. unsigned int sw_idx = sw_index, hw_idx = hw_index;
  626. struct hif_msg_callbacks *msg_callbacks =
  627. &hif_state->msg_callbacks_current;
  628. do {
  629. /*
  630. * The upper layer callback will be triggered
  631. * when last fragment is complteted.
  632. */
  633. if (transfer_context != CE_SENDLIST_ITEM_CTXT) {
  634. if (hif_state->scn->target_status
  635. == OL_TRGET_STATUS_RESET)
  636. cdf_nbuf_free(transfer_context);
  637. else
  638. msg_callbacks->txCompletionHandler(
  639. msg_callbacks->Context,
  640. transfer_context, transfer_id,
  641. toeplitz_hash_result);
  642. }
  643. cdf_spin_lock(&pipe_info->completion_freeq_lock);
  644. pipe_info->num_sends_allowed++;
  645. cdf_spin_unlock(&pipe_info->completion_freeq_lock);
  646. } while (ce_completed_send_next(copyeng,
  647. &ce_context, &transfer_context,
  648. &CE_data, &nbytes, &transfer_id,
  649. &sw_idx, &hw_idx,
  650. &toeplitz_hash_result) == CDF_STATUS_SUCCESS);
  651. }
  652. /**
  653. * hif_ce_do_recv(): send message from copy engine to upper layers
  654. * @msg_callbacks: structure containing callback and callback context
  655. * @netbuff: skb containing message
  656. * @nbytes: number of bytes in the message
  657. * @pipe_info: used for the pipe_number info
  658. *
  659. * Checks the packet length, configures the lenght in the netbuff,
  660. * and calls the upper layer callback.
  661. *
  662. * return: None
  663. */
  664. static inline void hif_ce_do_recv(struct hif_msg_callbacks *msg_callbacks,
  665. cdf_nbuf_t netbuf, int nbytes,
  666. struct HIF_CE_pipe_info *pipe_info) {
  667. if (nbytes <= pipe_info->buf_sz) {
  668. cdf_nbuf_set_pktlen(netbuf, nbytes);
  669. msg_callbacks->
  670. rxCompletionHandler(msg_callbacks->Context,
  671. netbuf, pipe_info->pipe_num);
  672. } else {
  673. HIF_ERROR("%s: Invalid Rx msg buf:%p nbytes:%d",
  674. __func__, netbuf, nbytes);
  675. cdf_nbuf_free(netbuf);
  676. }
  677. }
  678. /* Called by lower (CE) layer when data is received from the Target. */
  679. void
  680. hif_pci_ce_recv_data(struct CE_handle *copyeng, void *ce_context,
  681. void *transfer_context, cdf_dma_addr_t CE_data,
  682. unsigned int nbytes, unsigned int transfer_id,
  683. unsigned int flags)
  684. {
  685. struct HIF_CE_pipe_info *pipe_info =
  686. (struct HIF_CE_pipe_info *)ce_context;
  687. struct HIF_CE_state *hif_state = pipe_info->HIF_CE_state;
  688. struct CE_state *ce_state = (struct CE_state *) copyeng;
  689. struct ol_softc *scn = hif_state->scn;
  690. struct hif_msg_callbacks *msg_callbacks =
  691. &hif_state->msg_callbacks_current;
  692. do {
  693. hif_pm_runtime_mark_last_busy(scn->hif_sc->dev);
  694. cdf_nbuf_unmap_single(scn->cdf_dev,
  695. (cdf_nbuf_t) transfer_context,
  696. CDF_DMA_FROM_DEVICE);
  697. atomic_inc(&pipe_info->recv_bufs_needed);
  698. hif_post_recv_buffers_for_pipe(pipe_info);
  699. if (hif_state->scn->target_status == OL_TRGET_STATUS_RESET)
  700. cdf_nbuf_free(transfer_context);
  701. else
  702. hif_ce_do_recv(msg_callbacks, transfer_context,
  703. nbytes, pipe_info);
  704. /* Set up force_break flag if num of receices reaches
  705. * MAX_NUM_OF_RECEIVES */
  706. ce_state->receive_count++;
  707. if (cdf_unlikely(hif_max_num_receives_reached(
  708. ce_state->receive_count))) {
  709. ce_state->force_break = 1;
  710. break;
  711. }
  712. } while (ce_completed_recv_next(copyeng, &ce_context, &transfer_context,
  713. &CE_data, &nbytes, &transfer_id,
  714. &flags) == CDF_STATUS_SUCCESS);
  715. }
  716. /* TBDXXX: Set CE High Watermark; invoke txResourceAvailHandler in response */
  717. void
  718. hif_post_init(struct ol_softc *scn, void *unused,
  719. struct hif_msg_callbacks *callbacks)
  720. {
  721. struct HIF_CE_state *hif_state = (struct HIF_CE_state *)scn->hif_hdl;
  722. #ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
  723. spin_lock_init(&pcie_access_log_lock);
  724. #endif
  725. /* Save callbacks for later installation */
  726. cdf_mem_copy(&hif_state->msg_callbacks_pending, callbacks,
  727. sizeof(hif_state->msg_callbacks_pending));
  728. }
  729. int hif_completion_thread_startup(struct HIF_CE_state *hif_state)
  730. {
  731. struct CE_handle *ce_diag = hif_state->ce_diag;
  732. int pipe_num;
  733. struct ol_softc *scn = hif_state->scn;
  734. struct hif_msg_callbacks *hif_msg_callbacks =
  735. &hif_state->msg_callbacks_current;
  736. /* daemonize("hif_compl_thread"); */
  737. if (scn->ce_count == 0) {
  738. HIF_ERROR("%s: Invalid ce_count\n", __func__);
  739. return -EINVAL;
  740. }
  741. if (!hif_msg_callbacks ||
  742. !hif_msg_callbacks->rxCompletionHandler ||
  743. !hif_msg_callbacks->txCompletionHandler) {
  744. HIF_ERROR("%s: no completion handler registered", __func__);
  745. return -EFAULT;
  746. }
  747. A_TARGET_ACCESS_LIKELY(scn);
  748. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  749. struct CE_attr attr;
  750. struct HIF_CE_pipe_info *pipe_info;
  751. pipe_info = &hif_state->pipe_info[pipe_num];
  752. if (pipe_info->ce_hdl == ce_diag) {
  753. continue; /* Handle Diagnostic CE specially */
  754. }
  755. attr = host_ce_config[pipe_num];
  756. if (attr.src_nentries) {
  757. /* pipe used to send to target */
  758. HIF_INFO_MED("%s: pipe_num:%d pipe_info:0x%p",
  759. __func__, pipe_num, pipe_info);
  760. ce_send_cb_register(pipe_info->ce_hdl,
  761. hif_pci_ce_send_done, pipe_info,
  762. attr.flags & CE_ATTR_DISABLE_INTR);
  763. pipe_info->num_sends_allowed = attr.src_nentries - 1;
  764. }
  765. if (attr.dest_nentries) {
  766. /* pipe used to receive from target */
  767. ce_recv_cb_register(pipe_info->ce_hdl,
  768. hif_pci_ce_recv_data, pipe_info,
  769. attr.flags & CE_ATTR_DISABLE_INTR);
  770. }
  771. if (attr.src_nentries)
  772. cdf_spinlock_init(&pipe_info->completion_freeq_lock);
  773. }
  774. A_TARGET_ACCESS_UNLIKELY(scn);
  775. return 0;
  776. }
  777. /*
  778. * Install pending msg callbacks.
  779. *
  780. * TBDXXX: This hack is needed because upper layers install msg callbacks
  781. * for use with HTC before BMI is done; yet this HIF implementation
  782. * needs to continue to use BMI msg callbacks. Really, upper layers
  783. * should not register HTC callbacks until AFTER BMI phase.
  784. */
  785. static void hif_msg_callbacks_install(struct ol_softc *scn)
  786. {
  787. struct HIF_CE_state *hif_state = (struct HIF_CE_state *)scn->hif_hdl;
  788. cdf_mem_copy(&hif_state->msg_callbacks_current,
  789. &hif_state->msg_callbacks_pending,
  790. sizeof(hif_state->msg_callbacks_pending));
  791. }
  792. void
  793. hif_get_default_pipe(struct ol_softc *scn, uint8_t *ULPipe, uint8_t *DLPipe)
  794. {
  795. int ul_is_polled, dl_is_polled;
  796. (void)hif_map_service_to_pipe(scn, HTC_CTRL_RSVD_SVC,
  797. ULPipe, DLPipe, &ul_is_polled, &dl_is_polled);
  798. }
  799. /**
  800. * hif_dump_pipe_debug_count() - Log error count
  801. * @scn: ol_softc pointer.
  802. *
  803. * Output the pipe error counts of each pipe to log file
  804. *
  805. * Return: N/A
  806. */
  807. void hif_dump_pipe_debug_count(struct ol_softc *scn)
  808. {
  809. struct HIF_CE_state *hif_state;
  810. int pipe_num;
  811. if (scn == NULL) {
  812. HIF_ERROR("%s scn is NULL", __func__);
  813. return;
  814. }
  815. hif_state = (struct HIF_CE_state *)scn->hif_hdl;
  816. if (hif_state == NULL) {
  817. HIF_ERROR("%s hif_state is NULL", __func__);
  818. return;
  819. }
  820. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  821. struct HIF_CE_pipe_info *pipe_info;
  822. pipe_info = &hif_state->pipe_info[pipe_num];
  823. if (pipe_info->nbuf_alloc_err_count > 0 ||
  824. pipe_info->nbuf_dma_err_count > 0 ||
  825. pipe_info->nbuf_ce_enqueue_err_count)
  826. HIF_ERROR(
  827. "%s: pipe_id = %d, recv_bufs_needed = %d, nbuf_alloc_err_count = %u, nbuf_dma_err_count = %u, nbuf_ce_enqueue_err_count = %u",
  828. __func__, pipe_info->pipe_num,
  829. atomic_read(&pipe_info->recv_bufs_needed),
  830. pipe_info->nbuf_alloc_err_count,
  831. pipe_info->nbuf_dma_err_count,
  832. pipe_info->nbuf_ce_enqueue_err_count);
  833. }
  834. }
  835. static int hif_post_recv_buffers_for_pipe(struct HIF_CE_pipe_info *pipe_info)
  836. {
  837. struct CE_handle *ce_hdl;
  838. cdf_size_t buf_sz;
  839. struct HIF_CE_state *hif_state = pipe_info->HIF_CE_state;
  840. struct ol_softc *scn = hif_state->scn;
  841. CDF_STATUS ret;
  842. uint32_t bufs_posted = 0;
  843. buf_sz = pipe_info->buf_sz;
  844. if (buf_sz == 0) {
  845. /* Unused Copy Engine */
  846. return 0;
  847. }
  848. ce_hdl = pipe_info->ce_hdl;
  849. cdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
  850. while (atomic_read(&pipe_info->recv_bufs_needed) > 0) {
  851. cdf_dma_addr_t CE_data; /* CE space buffer address */
  852. cdf_nbuf_t nbuf;
  853. int status;
  854. atomic_dec(&pipe_info->recv_bufs_needed);
  855. cdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
  856. nbuf = cdf_nbuf_alloc(scn->cdf_dev, buf_sz, 0, 4, false);
  857. if (!nbuf) {
  858. cdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
  859. pipe_info->nbuf_alloc_err_count++;
  860. cdf_spin_unlock_bh(
  861. &pipe_info->recv_bufs_needed_lock);
  862. HIF_ERROR(
  863. "%s buf alloc error [%d] needed %d, nbuf_alloc_err_count = %u",
  864. __func__, pipe_info->pipe_num,
  865. atomic_read(&pipe_info->recv_bufs_needed),
  866. pipe_info->nbuf_alloc_err_count);
  867. atomic_inc(&pipe_info->recv_bufs_needed);
  868. return 1;
  869. }
  870. /*
  871. * cdf_nbuf_peek_header(nbuf, &data, &unused);
  872. * CE_data = dma_map_single(dev, data, buf_sz, );
  873. * DMA_FROM_DEVICE);
  874. */
  875. ret =
  876. cdf_nbuf_map_single(scn->cdf_dev, nbuf,
  877. CDF_DMA_FROM_DEVICE);
  878. if (unlikely(ret != CDF_STATUS_SUCCESS)) {
  879. cdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
  880. pipe_info->nbuf_dma_err_count++;
  881. cdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
  882. HIF_ERROR(
  883. "%s buf alloc error [%d] needed %d, nbuf_dma_err_count = %u",
  884. __func__, pipe_info->pipe_num,
  885. atomic_read(&pipe_info->recv_bufs_needed),
  886. pipe_info->nbuf_dma_err_count);
  887. cdf_nbuf_free(nbuf);
  888. atomic_inc(&pipe_info->recv_bufs_needed);
  889. return 1;
  890. }
  891. CE_data = cdf_nbuf_get_frag_paddr_lo(nbuf, 0);
  892. cdf_os_mem_dma_sync_single_for_device(scn->cdf_dev, CE_data,
  893. buf_sz, DMA_FROM_DEVICE);
  894. status = ce_recv_buf_enqueue(ce_hdl, (void *)nbuf, CE_data);
  895. CDF_ASSERT(status == CDF_STATUS_SUCCESS);
  896. if (status != EOK) {
  897. cdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
  898. pipe_info->nbuf_ce_enqueue_err_count++;
  899. cdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
  900. HIF_ERROR(
  901. "%s buf alloc error [%d] needed %d, nbuf_alloc_err_count = %u",
  902. __func__, pipe_info->pipe_num,
  903. atomic_read(&pipe_info->recv_bufs_needed),
  904. pipe_info->nbuf_ce_enqueue_err_count);
  905. atomic_inc(&pipe_info->recv_bufs_needed);
  906. cdf_nbuf_free(nbuf);
  907. return 1;
  908. }
  909. cdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
  910. bufs_posted++;
  911. }
  912. pipe_info->nbuf_alloc_err_count =
  913. (pipe_info->nbuf_alloc_err_count > bufs_posted)?
  914. pipe_info->nbuf_alloc_err_count - bufs_posted : 0;
  915. pipe_info->nbuf_dma_err_count =
  916. (pipe_info->nbuf_dma_err_count > bufs_posted)?
  917. pipe_info->nbuf_dma_err_count - bufs_posted : 0;
  918. pipe_info->nbuf_ce_enqueue_err_count =
  919. (pipe_info->nbuf_ce_enqueue_err_count > bufs_posted)?
  920. pipe_info->nbuf_ce_enqueue_err_count - bufs_posted : 0;
  921. cdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
  922. return 0;
  923. }
  924. /*
  925. * Try to post all desired receive buffers for all pipes.
  926. * Returns 0 if all desired buffers are posted,
  927. * non-zero if were were unable to completely
  928. * replenish receive buffers.
  929. */
  930. static int hif_post_recv_buffers(struct ol_softc *scn)
  931. {
  932. struct HIF_CE_state *hif_state = (struct HIF_CE_state *)scn->hif_hdl;
  933. int pipe_num, rv = 0;
  934. A_TARGET_ACCESS_LIKELY(scn);
  935. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  936. struct HIF_CE_pipe_info *pipe_info;
  937. pipe_info = &hif_state->pipe_info[pipe_num];
  938. if (hif_post_recv_buffers_for_pipe(pipe_info)) {
  939. rv = 1;
  940. goto done;
  941. }
  942. }
  943. done:
  944. A_TARGET_ACCESS_UNLIKELY(scn);
  945. return rv;
  946. }
  947. CDF_STATUS hif_start(struct ol_softc *scn)
  948. {
  949. struct HIF_CE_state *hif_state = (struct HIF_CE_state *)scn->hif_hdl;
  950. hif_msg_callbacks_install(scn);
  951. if (hif_completion_thread_startup(hif_state))
  952. return CDF_STATUS_E_FAILURE;
  953. /* Post buffers once to start things off. */
  954. (void)hif_post_recv_buffers(scn);
  955. hif_state->started = true;
  956. return CDF_STATUS_SUCCESS;
  957. }
  958. #ifdef WLAN_FEATURE_FASTPATH
  959. /**
  960. * hif_enable_fastpath() Update that we have enabled fastpath mode
  961. * @hif_ctx: HIF context
  962. *
  963. * For use in data path
  964. *
  965. * Retrun: void
  966. */
  967. void hif_enable_fastpath(struct ol_softc *hif_ctx)
  968. {
  969. HIF_INFO("Enabling fastpath mode\n");
  970. hif_ctx->fastpath_mode_on = 1;
  971. }
  972. /**
  973. * hif_is_fastpath_mode_enabled - API to query if fasthpath mode is enabled
  974. * @hif_ctx: HIF Context
  975. *
  976. * For use in data path to skip HTC
  977. *
  978. * Return: bool
  979. */
  980. bool hif_is_fastpath_mode_enabled(struct ol_softc *hif_ctx)
  981. {
  982. return hif_ctx->fastpath_mode_on;
  983. }
  984. /**
  985. * hif_get_ce_handle - API to get CE handle for FastPath mode
  986. * @hif_ctx: HIF Context
  987. * @id: CopyEngine Id
  988. *
  989. * API to return CE handle for fastpath mode
  990. *
  991. * Return: void
  992. */
  993. void *hif_get_ce_handle(struct ol_softc *hif_ctx, int id)
  994. {
  995. return hif_ctx->ce_id_to_state[id];
  996. }
  997. #endif /* WLAN_FEATURE_FASTPATH */
  998. void hif_recv_buffer_cleanup_on_pipe(struct HIF_CE_pipe_info *pipe_info)
  999. {
  1000. struct ol_softc *scn;
  1001. struct CE_handle *ce_hdl;
  1002. uint32_t buf_sz;
  1003. struct HIF_CE_state *hif_state;
  1004. cdf_nbuf_t netbuf;
  1005. cdf_dma_addr_t CE_data;
  1006. void *per_CE_context;
  1007. buf_sz = pipe_info->buf_sz;
  1008. if (buf_sz == 0) {
  1009. /* Unused Copy Engine */
  1010. return;
  1011. }
  1012. hif_state = pipe_info->HIF_CE_state;
  1013. if (!hif_state->started) {
  1014. return;
  1015. }
  1016. scn = hif_state->scn;
  1017. ce_hdl = pipe_info->ce_hdl;
  1018. if (scn->cdf_dev == NULL) {
  1019. return;
  1020. }
  1021. while (ce_revoke_recv_next
  1022. (ce_hdl, &per_CE_context, (void **)&netbuf,
  1023. &CE_data) == CDF_STATUS_SUCCESS) {
  1024. cdf_nbuf_unmap_single(scn->cdf_dev, netbuf,
  1025. CDF_DMA_FROM_DEVICE);
  1026. cdf_nbuf_free(netbuf);
  1027. }
  1028. }
  1029. void hif_send_buffer_cleanup_on_pipe(struct HIF_CE_pipe_info *pipe_info)
  1030. {
  1031. struct CE_handle *ce_hdl;
  1032. struct HIF_CE_state *hif_state;
  1033. cdf_nbuf_t netbuf;
  1034. void *per_CE_context;
  1035. cdf_dma_addr_t CE_data;
  1036. unsigned int nbytes;
  1037. unsigned int id;
  1038. uint32_t buf_sz;
  1039. uint32_t toeplitz_hash_result;
  1040. buf_sz = pipe_info->buf_sz;
  1041. if (buf_sz == 0) {
  1042. /* Unused Copy Engine */
  1043. return;
  1044. }
  1045. hif_state = pipe_info->HIF_CE_state;
  1046. if (!hif_state->started) {
  1047. return;
  1048. }
  1049. ce_hdl = pipe_info->ce_hdl;
  1050. while (ce_cancel_send_next
  1051. (ce_hdl, &per_CE_context,
  1052. (void **)&netbuf, &CE_data, &nbytes,
  1053. &id, &toeplitz_hash_result) == CDF_STATUS_SUCCESS) {
  1054. if (netbuf != CE_SENDLIST_ITEM_CTXT) {
  1055. /*
  1056. * Packets enqueued by htt_h2t_ver_req_msg() and
  1057. * htt_h2t_rx_ring_cfg_msg_ll() have already been
  1058. * freed in htt_htc_misc_pkt_pool_free() in
  1059. * wlantl_close(), so do not free them here again
  1060. * by checking whether it's the endpoint
  1061. * which they are queued in.
  1062. */
  1063. if (id == hif_state->scn->htc_endpoint)
  1064. return;
  1065. /* Indicate the completion to higer
  1066. * layer to free the buffer */
  1067. hif_state->msg_callbacks_current.
  1068. txCompletionHandler(hif_state->
  1069. msg_callbacks_current.Context,
  1070. netbuf, id, toeplitz_hash_result);
  1071. }
  1072. }
  1073. }
  1074. /*
  1075. * Cleanup residual buffers for device shutdown:
  1076. * buffers that were enqueued for receive
  1077. * buffers that were to be sent
  1078. * Note: Buffers that had completed but which were
  1079. * not yet processed are on a completion queue. They
  1080. * are handled when the completion thread shuts down.
  1081. */
  1082. void hif_buffer_cleanup(struct HIF_CE_state *hif_state)
  1083. {
  1084. int pipe_num;
  1085. for (pipe_num = 0; pipe_num < hif_state->scn->ce_count; pipe_num++) {
  1086. struct HIF_CE_pipe_info *pipe_info;
  1087. pipe_info = &hif_state->pipe_info[pipe_num];
  1088. hif_recv_buffer_cleanup_on_pipe(pipe_info);
  1089. hif_send_buffer_cleanup_on_pipe(pipe_info);
  1090. }
  1091. }
  1092. void hif_flush_surprise_remove(struct ol_softc *scn)
  1093. {
  1094. struct HIF_CE_state *hif_state = (struct HIF_CE_state *)scn->hif_hdl;
  1095. hif_buffer_cleanup(hif_state);
  1096. }
  1097. void hif_stop(struct ol_softc *scn)
  1098. {
  1099. struct HIF_CE_state *hif_state = (struct HIF_CE_state *)scn->hif_hdl;
  1100. int pipe_num;
  1101. scn->hif_init_done = false;
  1102. /*
  1103. * At this point, asynchronous threads are stopped,
  1104. * The Target should not DMA nor interrupt, Host code may
  1105. * not initiate anything more. So we just need to clean
  1106. * up Host-side state.
  1107. */
  1108. if (scn->athdiag_procfs_inited) {
  1109. athdiag_procfs_remove();
  1110. scn->athdiag_procfs_inited = false;
  1111. }
  1112. hif_buffer_cleanup(hif_state);
  1113. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  1114. struct HIF_CE_pipe_info *pipe_info;
  1115. pipe_info = &hif_state->pipe_info[pipe_num];
  1116. if (pipe_info->ce_hdl) {
  1117. ce_fini(pipe_info->ce_hdl);
  1118. pipe_info->ce_hdl = NULL;
  1119. pipe_info->buf_sz = 0;
  1120. }
  1121. }
  1122. if (hif_state->sleep_timer_init) {
  1123. cdf_softirq_timer_cancel(&hif_state->sleep_timer);
  1124. cdf_softirq_timer_free(&hif_state->sleep_timer);
  1125. hif_state->sleep_timer_init = false;
  1126. }
  1127. hif_state->started = false;
  1128. }
  1129. #define ADRASTEA_SRC_WR_INDEX_OFFSET 0x3C
  1130. #define ADRASTEA_DST_WR_INDEX_OFFSET 0x40
  1131. static struct shadow_reg_cfg target_shadow_reg_cfg_map[] = {
  1132. { 0, ADRASTEA_SRC_WR_INDEX_OFFSET},
  1133. { 3, ADRASTEA_SRC_WR_INDEX_OFFSET},
  1134. { 4, ADRASTEA_SRC_WR_INDEX_OFFSET},
  1135. { 5, ADRASTEA_SRC_WR_INDEX_OFFSET},
  1136. { 7, ADRASTEA_SRC_WR_INDEX_OFFSET},
  1137. { 1, ADRASTEA_DST_WR_INDEX_OFFSET},
  1138. { 2, ADRASTEA_DST_WR_INDEX_OFFSET},
  1139. { 7, ADRASTEA_DST_WR_INDEX_OFFSET},
  1140. { 8, ADRASTEA_DST_WR_INDEX_OFFSET},
  1141. };
  1142. /* CE_PCI TABLE */
  1143. /*
  1144. * NOTE: the table below is out of date, though still a useful reference.
  1145. * Refer to target_service_to_ce_map and hif_map_service_to_pipe for the actual
  1146. * mapping of HTC services to HIF pipes.
  1147. */
  1148. /*
  1149. * This authoritative table defines Copy Engine configuration and the mapping
  1150. * of services/endpoints to CEs. A subset of this information is passed to
  1151. * the Target during startup as a prerequisite to entering BMI phase.
  1152. * See:
  1153. * target_service_to_ce_map - Target-side mapping
  1154. * hif_map_service_to_pipe - Host-side mapping
  1155. * target_ce_config - Target-side configuration
  1156. * host_ce_config - Host-side configuration
  1157. ============================================================================
  1158. Purpose | Service / Endpoint | CE | Dire | Xfer | Xfer
  1159. | | | ctio | Size | Frequency
  1160. | | | n | |
  1161. ============================================================================
  1162. tx | HTT_DATA (downlink) | CE 0 | h->t | medium - | very frequent
  1163. descriptor | | | | O(100B) | and regular
  1164. download | | | | |
  1165. ----------------------------------------------------------------------------
  1166. rx | HTT_DATA (uplink) | CE 1 | t->h | small - | frequent and
  1167. indication | | | | O(10B) | regular
  1168. upload | | | | |
  1169. ----------------------------------------------------------------------------
  1170. MSDU | DATA_BK (uplink) | CE 2 | t->h | large - | rare
  1171. upload | | | | O(1000B) | (frequent
  1172. e.g. noise | | | | | during IP1.0
  1173. packets | | | | | testing)
  1174. ----------------------------------------------------------------------------
  1175. MSDU | DATA_BK (downlink) | CE 3 | h->t | large - | very rare
  1176. download | | | | O(1000B) | (frequent
  1177. e.g. | | | | | during IP1.0
  1178. misdirecte | | | | | testing)
  1179. d EAPOL | | | | |
  1180. packets | | | | |
  1181. ----------------------------------------------------------------------------
  1182. n/a | DATA_BE, DATA_VI | CE 2 | t->h | | never(?)
  1183. | DATA_VO (uplink) | | | |
  1184. ----------------------------------------------------------------------------
  1185. n/a | DATA_BE, DATA_VI | CE 3 | h->t | | never(?)
  1186. | DATA_VO (downlink) | | | |
  1187. ----------------------------------------------------------------------------
  1188. WMI events | WMI_CONTROL (uplink) | CE 4 | t->h | medium - | infrequent
  1189. | | | | O(100B) |
  1190. ----------------------------------------------------------------------------
  1191. WMI | WMI_CONTROL | CE 5 | h->t | medium - | infrequent
  1192. messages | (downlink) | | | O(100B) |
  1193. | | | | |
  1194. ----------------------------------------------------------------------------
  1195. n/a | HTC_CTRL_RSVD, | CE 1 | t->h | | never(?)
  1196. | HTC_RAW_STREAMS | | | |
  1197. | (uplink) | | | |
  1198. ----------------------------------------------------------------------------
  1199. n/a | HTC_CTRL_RSVD, | CE 0 | h->t | | never(?)
  1200. | HTC_RAW_STREAMS | | | |
  1201. | (downlink) | | | |
  1202. ----------------------------------------------------------------------------
  1203. diag | none (raw CE) | CE 7 | t<>h | 4 | Diag Window
  1204. | | | | | infrequent
  1205. ============================================================================
  1206. */
  1207. /*
  1208. * Map from service/endpoint to Copy Engine.
  1209. * This table is derived from the CE_PCI TABLE, above.
  1210. * It is passed to the Target at startup for use by firmware.
  1211. */
  1212. static struct service_to_pipe target_service_to_ce_map_wlan[] = {
  1213. {
  1214. WMI_DATA_VO_SVC,
  1215. PIPEDIR_OUT, /* out = UL = host -> target */
  1216. 3,
  1217. },
  1218. {
  1219. WMI_DATA_VO_SVC,
  1220. PIPEDIR_IN, /* in = DL = target -> host */
  1221. 2,
  1222. },
  1223. {
  1224. WMI_DATA_BK_SVC,
  1225. PIPEDIR_OUT, /* out = UL = host -> target */
  1226. 3,
  1227. },
  1228. {
  1229. WMI_DATA_BK_SVC,
  1230. PIPEDIR_IN, /* in = DL = target -> host */
  1231. 2,
  1232. },
  1233. {
  1234. WMI_DATA_BE_SVC,
  1235. PIPEDIR_OUT, /* out = UL = host -> target */
  1236. 3,
  1237. },
  1238. {
  1239. WMI_DATA_BE_SVC,
  1240. PIPEDIR_IN, /* in = DL = target -> host */
  1241. 2,
  1242. },
  1243. {
  1244. WMI_DATA_VI_SVC,
  1245. PIPEDIR_OUT, /* out = UL = host -> target */
  1246. 3,
  1247. },
  1248. {
  1249. WMI_DATA_VI_SVC,
  1250. PIPEDIR_IN, /* in = DL = target -> host */
  1251. 2,
  1252. },
  1253. {
  1254. WMI_CONTROL_SVC,
  1255. PIPEDIR_OUT, /* out = UL = host -> target */
  1256. 3,
  1257. },
  1258. {
  1259. WMI_CONTROL_SVC,
  1260. PIPEDIR_IN, /* in = DL = target -> host */
  1261. 2,
  1262. },
  1263. {
  1264. HTC_CTRL_RSVD_SVC,
  1265. PIPEDIR_OUT, /* out = UL = host -> target */
  1266. 0, /* could be moved to 3 (share with WMI) */
  1267. },
  1268. {
  1269. HTC_CTRL_RSVD_SVC,
  1270. PIPEDIR_IN, /* in = DL = target -> host */
  1271. 2,
  1272. },
  1273. {
  1274. HTC_RAW_STREAMS_SVC, /* not currently used */
  1275. PIPEDIR_OUT, /* out = UL = host -> target */
  1276. 0,
  1277. },
  1278. {
  1279. HTC_RAW_STREAMS_SVC, /* not currently used */
  1280. PIPEDIR_IN, /* in = DL = target -> host */
  1281. 2,
  1282. },
  1283. {
  1284. HTT_DATA_MSG_SVC,
  1285. PIPEDIR_OUT, /* out = UL = host -> target */
  1286. 4,
  1287. },
  1288. {
  1289. HTT_DATA_MSG_SVC,
  1290. PIPEDIR_IN, /* in = DL = target -> host */
  1291. 1,
  1292. },
  1293. {
  1294. WDI_IPA_TX_SVC,
  1295. PIPEDIR_OUT, /* in = DL = target -> host */
  1296. 5,
  1297. },
  1298. /* (Additions here) */
  1299. { /* Must be last */
  1300. 0,
  1301. 0,
  1302. 0,
  1303. },
  1304. };
  1305. static struct service_to_pipe *target_service_to_ce_map =
  1306. target_service_to_ce_map_wlan;
  1307. static int target_service_to_ce_map_sz = sizeof(target_service_to_ce_map_wlan);
  1308. static struct shadow_reg_cfg *target_shadow_reg_cfg = target_shadow_reg_cfg_map;
  1309. static int shadow_cfg_sz = sizeof(target_shadow_reg_cfg_map);
  1310. static struct service_to_pipe target_service_to_ce_map_wlan_epping[] = {
  1311. {WMI_DATA_VO_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
  1312. {WMI_DATA_VO_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
  1313. {WMI_DATA_BK_SVC, PIPEDIR_OUT, 4,}, /* out = UL = host -> target */
  1314. {WMI_DATA_BK_SVC, PIPEDIR_IN, 1,}, /* in = DL = target -> host */
  1315. {WMI_DATA_BE_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
  1316. {WMI_DATA_BE_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
  1317. {WMI_DATA_VI_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
  1318. {WMI_DATA_VI_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
  1319. {WMI_CONTROL_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
  1320. {WMI_CONTROL_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
  1321. {HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0,}, /* out = UL = host -> target */
  1322. {HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
  1323. {HTC_RAW_STREAMS_SVC, PIPEDIR_OUT, 0,}, /* out = UL = host -> target */
  1324. {HTC_RAW_STREAMS_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
  1325. {HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4,}, /* out = UL = host -> target */
  1326. {HTT_DATA_MSG_SVC, PIPEDIR_IN, 1,}, /* in = DL = target -> host */
  1327. {0, 0, 0,}, /* Must be last */
  1328. };
  1329. #ifdef HIF_PCI
  1330. /*
  1331. * Send an interrupt to the device to wake up the Target CPU
  1332. * so it has an opportunity to notice any changed state.
  1333. */
  1334. void hif_wake_target_cpu(struct ol_softc *scn)
  1335. {
  1336. CDF_STATUS rv;
  1337. uint32_t core_ctrl;
  1338. rv = hif_diag_read_access(scn,
  1339. SOC_CORE_BASE_ADDRESS | CORE_CTRL_ADDRESS,
  1340. &core_ctrl);
  1341. CDF_ASSERT(rv == CDF_STATUS_SUCCESS);
  1342. /* A_INUM_FIRMWARE interrupt to Target CPU */
  1343. core_ctrl |= CORE_CTRL_CPU_INTR_MASK;
  1344. rv = hif_diag_write_access(scn,
  1345. SOC_CORE_BASE_ADDRESS | CORE_CTRL_ADDRESS,
  1346. core_ctrl);
  1347. CDF_ASSERT(rv == CDF_STATUS_SUCCESS);
  1348. }
  1349. #endif
  1350. static void hif_sleep_entry(void *arg)
  1351. {
  1352. struct HIF_CE_state *hif_state = (struct HIF_CE_state *)arg;
  1353. struct ol_softc *scn = hif_state->scn;
  1354. uint32_t idle_ms;
  1355. if (scn->recovery)
  1356. return;
  1357. if (cds_is_driver_unloading())
  1358. return;
  1359. cdf_spin_lock_irqsave(&hif_state->keep_awake_lock);
  1360. if (hif_state->verified_awake == false) {
  1361. idle_ms = cdf_system_ticks_to_msecs(cdf_system_ticks()
  1362. - hif_state->sleep_ticks);
  1363. if (idle_ms >= HIF_MIN_SLEEP_INACTIVITY_TIME_MS) {
  1364. if (!cdf_atomic_read(&scn->link_suspended)) {
  1365. soc_wake_reset(scn);
  1366. hif_state->fake_sleep = false;
  1367. }
  1368. } else {
  1369. cdf_softirq_timer_cancel(&hif_state->sleep_timer);
  1370. cdf_softirq_timer_start(&hif_state->sleep_timer,
  1371. HIF_SLEEP_INACTIVITY_TIMER_PERIOD_MS);
  1372. }
  1373. } else {
  1374. cdf_softirq_timer_cancel(&hif_state->sleep_timer);
  1375. cdf_softirq_timer_start(&hif_state->sleep_timer,
  1376. HIF_SLEEP_INACTIVITY_TIMER_PERIOD_MS);
  1377. }
  1378. cdf_spin_unlock_irqrestore(&hif_state->keep_awake_lock);
  1379. }
  1380. #define HIF_HIA_MAX_POLL_LOOP 1000000
  1381. #define HIF_HIA_POLLING_DELAY_MS 10
  1382. #ifndef HIF_PCI
  1383. int hif_set_hia(struct ol_softc *scn)
  1384. {
  1385. return 0;
  1386. }
  1387. #else
  1388. int hif_set_hia(struct ol_softc *scn)
  1389. {
  1390. CDF_STATUS rv;
  1391. uint32_t interconnect_targ_addr = 0;
  1392. uint32_t pcie_state_targ_addr = 0;
  1393. uint32_t pipe_cfg_targ_addr = 0;
  1394. uint32_t svc_to_pipe_map = 0;
  1395. uint32_t pcie_config_flags = 0;
  1396. uint32_t flag2_value = 0;
  1397. uint32_t flag2_targ_addr = 0;
  1398. #ifdef QCA_WIFI_3_0
  1399. uint32_t host_interest_area = 0;
  1400. uint8_t i;
  1401. #else
  1402. uint32_t ealloc_value = 0;
  1403. uint32_t ealloc_targ_addr = 0;
  1404. uint8_t banks_switched = 1;
  1405. uint32_t chip_id;
  1406. #endif
  1407. uint32_t pipe_cfg_addr;
  1408. struct hif_target_info *tgt_info = hif_get_target_info_handle(scn);
  1409. uint32_t target_type = tgt_info->target_type;
  1410. HIF_TRACE("%s: E", __func__);
  1411. if (ADRASTEA_BU)
  1412. return CDF_STATUS_SUCCESS;
  1413. #ifdef QCA_WIFI_3_0
  1414. i = 0;
  1415. while (i < HIF_HIA_MAX_POLL_LOOP) {
  1416. host_interest_area = hif_read32_mb(scn->mem +
  1417. A_SOC_CORE_SCRATCH_0_ADDRESS);
  1418. if ((host_interest_area & 0x01) == 0) {
  1419. cdf_mdelay(HIF_HIA_POLLING_DELAY_MS);
  1420. host_interest_area = 0;
  1421. i++;
  1422. if (i > HIF_HIA_MAX_POLL_LOOP && (i % 1000 == 0)) {
  1423. HIF_ERROR("%s: poll timeout(%d)", __func__, i);
  1424. }
  1425. } else {
  1426. host_interest_area &= (~0x01);
  1427. hif_write32_mb(scn->mem + 0x113014, 0);
  1428. break;
  1429. }
  1430. }
  1431. if (i >= HIF_HIA_MAX_POLL_LOOP) {
  1432. HIF_ERROR("%s: hia polling timeout", __func__);
  1433. return -EIO;
  1434. }
  1435. if (host_interest_area == 0) {
  1436. HIF_ERROR("%s: host_interest_area = 0", __func__);
  1437. return -EIO;
  1438. }
  1439. interconnect_targ_addr = host_interest_area +
  1440. offsetof(struct host_interest_area_t,
  1441. hi_interconnect_state);
  1442. flag2_targ_addr = host_interest_area +
  1443. offsetof(struct host_interest_area_t, hi_option_flag2);
  1444. #else
  1445. interconnect_targ_addr = hif_hia_item_address(target_type,
  1446. offsetof(struct host_interest_s, hi_interconnect_state));
  1447. ealloc_targ_addr = hif_hia_item_address(target_type,
  1448. offsetof(struct host_interest_s, hi_early_alloc));
  1449. flag2_targ_addr = hif_hia_item_address(target_type,
  1450. offsetof(struct host_interest_s, hi_option_flag2));
  1451. #endif
  1452. /* Supply Target-side CE configuration */
  1453. rv = hif_diag_read_access(scn, interconnect_targ_addr,
  1454. &pcie_state_targ_addr);
  1455. if (rv != CDF_STATUS_SUCCESS) {
  1456. HIF_ERROR("%s: interconnect_targ_addr = 0x%0x, ret = %d",
  1457. __func__, interconnect_targ_addr, rv);
  1458. goto done;
  1459. }
  1460. if (pcie_state_targ_addr == 0) {
  1461. rv = CDF_STATUS_E_FAILURE;
  1462. HIF_ERROR("%s: pcie state addr is 0", __func__);
  1463. goto done;
  1464. }
  1465. pipe_cfg_addr = pcie_state_targ_addr +
  1466. offsetof(struct pcie_state_s,
  1467. pipe_cfg_addr);
  1468. rv = hif_diag_read_access(scn,
  1469. pipe_cfg_addr,
  1470. &pipe_cfg_targ_addr);
  1471. if (rv != CDF_STATUS_SUCCESS) {
  1472. HIF_ERROR("%s: pipe_cfg_addr = 0x%0x, ret = %d",
  1473. __func__, pipe_cfg_addr, rv);
  1474. goto done;
  1475. }
  1476. if (pipe_cfg_targ_addr == 0) {
  1477. rv = CDF_STATUS_E_FAILURE;
  1478. HIF_ERROR("%s: pipe cfg addr is 0", __func__);
  1479. goto done;
  1480. }
  1481. rv = hif_diag_write_mem(scn, pipe_cfg_targ_addr,
  1482. (uint8_t *) target_ce_config,
  1483. target_ce_config_sz);
  1484. if (rv != CDF_STATUS_SUCCESS) {
  1485. HIF_ERROR("%s: write pipe cfg (%d)", __func__, rv);
  1486. goto done;
  1487. }
  1488. rv = hif_diag_read_access(scn,
  1489. pcie_state_targ_addr +
  1490. offsetof(struct pcie_state_s,
  1491. svc_to_pipe_map),
  1492. &svc_to_pipe_map);
  1493. if (rv != CDF_STATUS_SUCCESS) {
  1494. HIF_ERROR("%s: get svc/pipe map (%d)", __func__, rv);
  1495. goto done;
  1496. }
  1497. if (svc_to_pipe_map == 0) {
  1498. rv = CDF_STATUS_E_FAILURE;
  1499. HIF_ERROR("%s: svc_to_pipe map is 0", __func__);
  1500. goto done;
  1501. }
  1502. rv = hif_diag_write_mem(scn,
  1503. svc_to_pipe_map,
  1504. (uint8_t *) target_service_to_ce_map,
  1505. target_service_to_ce_map_sz);
  1506. if (rv != CDF_STATUS_SUCCESS) {
  1507. HIF_ERROR("%s: write svc/pipe map (%d)", __func__, rv);
  1508. goto done;
  1509. }
  1510. rv = hif_diag_read_access(scn,
  1511. pcie_state_targ_addr +
  1512. offsetof(struct pcie_state_s,
  1513. config_flags),
  1514. &pcie_config_flags);
  1515. if (rv != CDF_STATUS_SUCCESS) {
  1516. HIF_ERROR("%s: get pcie config_flags (%d)", __func__, rv);
  1517. goto done;
  1518. }
  1519. #if (CONFIG_PCIE_ENABLE_L1_CLOCK_GATE)
  1520. pcie_config_flags |= PCIE_CONFIG_FLAG_ENABLE_L1;
  1521. #else
  1522. pcie_config_flags &= ~PCIE_CONFIG_FLAG_ENABLE_L1;
  1523. #endif /* CONFIG_PCIE_ENABLE_L1_CLOCK_GATE */
  1524. pcie_config_flags |= PCIE_CONFIG_FLAG_CLK_SWITCH_WAIT;
  1525. #if (CONFIG_PCIE_ENABLE_AXI_CLK_GATE)
  1526. pcie_config_flags |= PCIE_CONFIG_FLAG_AXI_CLK_GATE;
  1527. #endif
  1528. rv = hif_diag_write_mem(scn,
  1529. pcie_state_targ_addr +
  1530. offsetof(struct pcie_state_s,
  1531. config_flags),
  1532. (uint8_t *) &pcie_config_flags,
  1533. sizeof(pcie_config_flags));
  1534. if (rv != CDF_STATUS_SUCCESS) {
  1535. HIF_ERROR("%s: write pcie config_flags (%d)", __func__, rv);
  1536. goto done;
  1537. }
  1538. #ifndef QCA_WIFI_3_0
  1539. /* configure early allocation */
  1540. ealloc_targ_addr = hif_hia_item_address(target_type,
  1541. offsetof(
  1542. struct host_interest_s,
  1543. hi_early_alloc));
  1544. rv = hif_diag_read_access(scn, ealloc_targ_addr,
  1545. &ealloc_value);
  1546. if (rv != CDF_STATUS_SUCCESS) {
  1547. HIF_ERROR("%s: get early alloc val (%d)", __func__, rv);
  1548. goto done;
  1549. }
  1550. /* 1 bank is switched to IRAM, except ROME 1.0 */
  1551. ealloc_value |=
  1552. ((HI_EARLY_ALLOC_MAGIC << HI_EARLY_ALLOC_MAGIC_SHIFT) &
  1553. HI_EARLY_ALLOC_MAGIC_MASK);
  1554. rv = hif_diag_read_access(scn,
  1555. CHIP_ID_ADDRESS |
  1556. RTC_SOC_BASE_ADDRESS, &chip_id);
  1557. if (rv != CDF_STATUS_SUCCESS) {
  1558. HIF_ERROR("%s: get chip id val (%d)", __func__, rv);
  1559. goto done;
  1560. }
  1561. if (CHIP_ID_VERSION_GET(chip_id) == 0xD) {
  1562. tgt_info->target_revision = CHIP_ID_REVISION_GET(chip_id);
  1563. switch (CHIP_ID_REVISION_GET(chip_id)) {
  1564. case 0x2: /* ROME 1.3 */
  1565. /* 2 banks are switched to IRAM */
  1566. banks_switched = 2;
  1567. break;
  1568. case 0x4: /* ROME 2.1 */
  1569. case 0x5: /* ROME 2.2 */
  1570. banks_switched = 6;
  1571. break;
  1572. case 0x8: /* ROME 3.0 */
  1573. case 0x9: /* ROME 3.1 */
  1574. case 0xA: /* ROME 3.2 */
  1575. banks_switched = 9;
  1576. break;
  1577. case 0x0: /* ROME 1.0 */
  1578. case 0x1: /* ROME 1.1 */
  1579. default:
  1580. /* 3 banks are switched to IRAM */
  1581. banks_switched = 3;
  1582. break;
  1583. }
  1584. }
  1585. ealloc_value |=
  1586. ((banks_switched << HI_EARLY_ALLOC_IRAM_BANKS_SHIFT)
  1587. & HI_EARLY_ALLOC_IRAM_BANKS_MASK);
  1588. rv = hif_diag_write_access(scn,
  1589. ealloc_targ_addr,
  1590. ealloc_value);
  1591. if (rv != CDF_STATUS_SUCCESS) {
  1592. HIF_ERROR("%s: set early alloc val (%d)", __func__, rv);
  1593. goto done;
  1594. }
  1595. #endif
  1596. /* Tell Target to proceed with initialization */
  1597. flag2_targ_addr = hif_hia_item_address(target_type,
  1598. offsetof(
  1599. struct host_interest_s,
  1600. hi_option_flag2));
  1601. rv = hif_diag_read_access(scn, flag2_targ_addr,
  1602. &flag2_value);
  1603. if (rv != CDF_STATUS_SUCCESS) {
  1604. HIF_ERROR("%s: get option val (%d)", __func__, rv);
  1605. goto done;
  1606. }
  1607. flag2_value |= HI_OPTION_EARLY_CFG_DONE;
  1608. rv = hif_diag_write_access(scn, flag2_targ_addr,
  1609. flag2_value);
  1610. if (rv != CDF_STATUS_SUCCESS) {
  1611. HIF_ERROR("%s: set option val (%d)", __func__, rv);
  1612. goto done;
  1613. }
  1614. hif_wake_target_cpu(scn);
  1615. done:
  1616. return rv;
  1617. }
  1618. #endif
  1619. /**
  1620. * hif_wlan_enable(): call the platform driver to enable wlan
  1621. *
  1622. * This function passes the con_mode and CE configuration to
  1623. * platform driver to enable wlan.
  1624. *
  1625. * Return: void
  1626. */
  1627. static int hif_wlan_enable(void)
  1628. {
  1629. struct icnss_wlan_enable_cfg cfg;
  1630. enum icnss_driver_mode mode;
  1631. uint32_t con_mode = cds_get_conparam();
  1632. cfg.num_ce_tgt_cfg = target_ce_config_sz /
  1633. sizeof(struct CE_pipe_config);
  1634. cfg.ce_tgt_cfg = (struct ce_tgt_pipe_cfg *)target_ce_config;
  1635. cfg.num_ce_svc_pipe_cfg = target_service_to_ce_map_sz /
  1636. sizeof(struct service_to_pipe);
  1637. cfg.ce_svc_cfg = (struct ce_svc_pipe_cfg *)target_service_to_ce_map;
  1638. cfg.num_shadow_reg_cfg = shadow_cfg_sz / sizeof(struct shadow_reg_cfg);
  1639. cfg.shadow_reg_cfg = (struct icnss_shadow_reg_cfg *) target_shadow_reg_cfg;
  1640. if (CDF_GLOBAL_FTM_MODE == con_mode)
  1641. mode = ICNSS_FTM;
  1642. else if (WLAN_IS_EPPING_ENABLED(cds_get_conparam()))
  1643. mode = ICNSS_EPPING;
  1644. else
  1645. mode = ICNSS_MISSION;
  1646. return icnss_wlan_enable(&cfg, mode, QWLAN_VERSIONSTR);
  1647. }
  1648. /*
  1649. * Called from PCI layer whenever a new PCI device is probed.
  1650. * Initializes per-device HIF state and notifies the main
  1651. * driver that a new HIF device is present.
  1652. */
  1653. int hif_config_ce(hif_handle_t hif_hdl)
  1654. {
  1655. struct HIF_CE_pipe_info *pipe_info;
  1656. int pipe_num;
  1657. #ifdef ADRASTEA_SHADOW_REGISTERS
  1658. int i;
  1659. #endif
  1660. CDF_STATUS rv = CDF_STATUS_SUCCESS;
  1661. int ret;
  1662. struct ol_softc *scn = hif_hdl;
  1663. struct HIF_CE_state *hif_state = (struct HIF_CE_state *)scn;
  1664. struct icnss_soc_info soc_info;
  1665. struct hif_target_info *tgt_info = hif_get_target_info_handle(scn);
  1666. /* if epping is enabled we need to use the epping configuration. */
  1667. if (WLAN_IS_EPPING_ENABLED(cds_get_conparam())) {
  1668. if (WLAN_IS_EPPING_IRQ(cds_get_conparam()))
  1669. host_ce_config = host_ce_config_wlan_epping_irq;
  1670. else
  1671. host_ce_config = host_ce_config_wlan_epping_poll;
  1672. target_ce_config = target_ce_config_wlan_epping;
  1673. target_ce_config_sz = sizeof(target_ce_config_wlan_epping);
  1674. target_service_to_ce_map =
  1675. target_service_to_ce_map_wlan_epping;
  1676. target_service_to_ce_map_sz =
  1677. sizeof(target_service_to_ce_map_wlan_epping);
  1678. }
  1679. ret = hif_wlan_enable();
  1680. if (ret) {
  1681. HIF_ERROR("%s: hif_wlan_enable error = %d", __func__, ret);
  1682. return CDF_STATUS_NOT_INITIALIZED;
  1683. }
  1684. scn->notice_send = true;
  1685. cdf_mem_zero(&soc_info, sizeof(soc_info));
  1686. ret = icnss_get_soc_info(scn, &soc_info);
  1687. if (ret < 0) {
  1688. HIF_ERROR("%s: icnss_get_soc_info error = %d", __func__, ret);
  1689. return CDF_STATUS_NOT_INITIALIZED;
  1690. }
  1691. hif_state->scn = scn;
  1692. scn->hif_hdl = hif_state;
  1693. scn->mem = soc_info.v_addr;
  1694. scn->mem_pa = soc_info.p_addr;
  1695. tgt_info->soc_version = soc_info.version;
  1696. cdf_spinlock_init(&hif_state->keep_awake_lock);
  1697. hif_state->keep_awake_count = 0;
  1698. hif_state->fake_sleep = false;
  1699. hif_state->sleep_ticks = 0;
  1700. cdf_softirq_timer_init(NULL, &hif_state->sleep_timer,
  1701. hif_sleep_entry, (void *)hif_state,
  1702. CDF_TIMER_TYPE_WAKE_APPS);
  1703. hif_state->sleep_timer_init = true;
  1704. hif_state->fw_indicator_address = FW_INDICATOR_ADDRESS;
  1705. #ifdef HIF_PCI
  1706. #if CONFIG_ATH_PCIE_MAX_PERF || CONFIG_ATH_PCIE_AWAKE_WHILE_DRIVER_LOAD
  1707. /* Force AWAKE forever/till the driver is loaded */
  1708. if (hif_target_sleep_state_adjust(scn, false, true) < 0)
  1709. return -EACCES;
  1710. #endif
  1711. #endif
  1712. hif_config_rri_on_ddr(scn);
  1713. /* During CE initializtion */
  1714. scn->ce_count = HOST_CE_COUNT;
  1715. A_TARGET_ACCESS_LIKELY(scn);
  1716. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  1717. struct CE_attr *attr;
  1718. pipe_info = &hif_state->pipe_info[pipe_num];
  1719. pipe_info->pipe_num = pipe_num;
  1720. pipe_info->HIF_CE_state = hif_state;
  1721. attr = &host_ce_config[pipe_num];
  1722. pipe_info->ce_hdl = ce_init(scn, pipe_num, attr);
  1723. CDF_ASSERT(pipe_info->ce_hdl != NULL);
  1724. if (pipe_info->ce_hdl == NULL) {
  1725. rv = CDF_STATUS_E_FAILURE;
  1726. A_TARGET_ACCESS_UNLIKELY(scn);
  1727. goto err;
  1728. }
  1729. if (pipe_num == DIAG_CE_ID) {
  1730. /* Reserve the ultimate CE for
  1731. * Diagnostic Window support */
  1732. hif_state->ce_diag =
  1733. hif_state->pipe_info[scn->ce_count - 1].ce_hdl;
  1734. continue;
  1735. }
  1736. pipe_info->buf_sz = (cdf_size_t) (attr->src_sz_max);
  1737. cdf_spinlock_init(&pipe_info->recv_bufs_needed_lock);
  1738. if (attr->dest_nentries > 0) {
  1739. atomic_set(&pipe_info->recv_bufs_needed,
  1740. init_buffer_count(attr->dest_nentries - 1));
  1741. } else {
  1742. atomic_set(&pipe_info->recv_bufs_needed, 0);
  1743. }
  1744. ce_tasklet_init(hif_state, (1 << pipe_num));
  1745. ce_register_irq(hif_state, (1 << pipe_num));
  1746. scn->request_irq_done = true;
  1747. }
  1748. if (athdiag_procfs_init(scn) != 0) {
  1749. A_TARGET_ACCESS_UNLIKELY(scn);
  1750. goto err;
  1751. }
  1752. scn->athdiag_procfs_inited = true;
  1753. /*
  1754. * Initially, establish CE completion handlers for use with BMI.
  1755. * These are overwritten with generic handlers after we exit BMI phase.
  1756. */
  1757. pipe_info = &hif_state->pipe_info[BMI_CE_NUM_TO_TARG];
  1758. #ifdef HIF_PCI
  1759. ce_send_cb_register(
  1760. pipe_info->ce_hdl, hif_bmi_send_done, pipe_info, 0);
  1761. #ifndef BMI_RSP_POLLING
  1762. pipe_info = &hif_state->pipe_info[BMI_CE_NUM_TO_HOST];
  1763. ce_recv_cb_register(
  1764. pipe_info->ce_hdl, hif_bmi_recv_data, pipe_info, 0);
  1765. #endif
  1766. #endif
  1767. HIF_INFO_MED("%s: ce_init done", __func__);
  1768. rv = hif_set_hia(scn);
  1769. HIF_INFO_MED("%s: hif_set_hia done", __func__);
  1770. A_TARGET_ACCESS_UNLIKELY(scn);
  1771. if (rv != CDF_STATUS_SUCCESS)
  1772. goto err;
  1773. else
  1774. init_tasklet_workers(scn);
  1775. HIF_TRACE("%s: X, ret = %d\n", __func__, rv);
  1776. #ifdef ADRASTEA_SHADOW_REGISTERS
  1777. HIF_ERROR("Using Shadow Registers instead of CE Registers\n");
  1778. for (i = 0; i < NUM_SHADOW_REGISTERS; i++) {
  1779. HIF_ERROR("%s Shadow Register%d is mapped to address %x\n",
  1780. __func__, i,
  1781. (A_TARGET_READ(scn, (SHADOW_ADDRESS(i))) << 2));
  1782. }
  1783. #endif
  1784. return rv != CDF_STATUS_SUCCESS;
  1785. err:
  1786. /* Failure, so clean up */
  1787. for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
  1788. pipe_info = &hif_state->pipe_info[pipe_num];
  1789. if (pipe_info->ce_hdl) {
  1790. ce_unregister_irq(hif_state, (1 << pipe_num));
  1791. scn->request_irq_done = false;
  1792. ce_fini(pipe_info->ce_hdl);
  1793. pipe_info->ce_hdl = NULL;
  1794. pipe_info->buf_sz = 0;
  1795. }
  1796. }
  1797. if (hif_state->sleep_timer_init) {
  1798. cdf_softirq_timer_cancel(&hif_state->sleep_timer);
  1799. cdf_softirq_timer_free(&hif_state->sleep_timer);
  1800. hif_state->sleep_timer_init = false;
  1801. }
  1802. scn->hif_hdl = NULL;
  1803. athdiag_procfs_remove();
  1804. scn->athdiag_procfs_inited = false;
  1805. HIF_TRACE("%s: X, ret = %d\n", __func__, rv);
  1806. return CDF_STATUS_SUCCESS != CDF_STATUS_E_FAILURE;
  1807. }
  1808. #ifdef IPA_OFFLOAD
  1809. /**
  1810. * hif_ipa_get_ce_resource() - get uc resource on hif
  1811. * @scn: bus context
  1812. * @ce_sr_base_paddr: copyengine source ring base physical address
  1813. * @ce_sr_ring_size: copyengine source ring size
  1814. * @ce_reg_paddr: copyengine register physical address
  1815. *
  1816. * IPA micro controller data path offload feature enabled,
  1817. * HIF should release copy engine related resource information to IPA UC
  1818. * IPA UC will access hardware resource with released information
  1819. *
  1820. * Return: None
  1821. */
  1822. void hif_ipa_get_ce_resource(struct ol_softc *scn,
  1823. cdf_dma_addr_t *ce_sr_base_paddr,
  1824. uint32_t *ce_sr_ring_size,
  1825. cdf_dma_addr_t *ce_reg_paddr)
  1826. {
  1827. struct HIF_CE_state *hif_state = (struct HIF_CE_state *)scn->hif_hdl;
  1828. struct HIF_CE_pipe_info *pipe_info =
  1829. &(hif_state->pipe_info[HIF_PCI_IPA_UC_ASSIGNED_CE]);
  1830. struct CE_handle *ce_hdl = pipe_info->ce_hdl;
  1831. ce_ipa_get_resource(ce_hdl, ce_sr_base_paddr, ce_sr_ring_size,
  1832. ce_reg_paddr);
  1833. return;
  1834. }
  1835. #endif /* IPA_OFFLOAD */
  1836. #ifdef ADRASTEA_SHADOW_REGISTERS
  1837. /*
  1838. Current shadow register config
  1839. -----------------------------------------------------------
  1840. Shadow Register | CE | src/dst write index
  1841. -----------------------------------------------------------
  1842. 0 | 0 | src
  1843. 1 No Config - Doesn't point to anything
  1844. 2 No Config - Doesn't point to anything
  1845. 3 | 3 | src
  1846. 4 | 4 | src
  1847. 5 | 5 | src
  1848. 6 No Config - Doesn't point to anything
  1849. 7 | 7 | src
  1850. 8 No Config - Doesn't point to anything
  1851. 9 No Config - Doesn't point to anything
  1852. 10 No Config - Doesn't point to anything
  1853. 11 No Config - Doesn't point to anything
  1854. -----------------------------------------------------------
  1855. 12 No Config - Doesn't point to anything
  1856. 13 | 1 | dst
  1857. 14 | 2 | dst
  1858. 15 No Config - Doesn't point to anything
  1859. 16 No Config - Doesn't point to anything
  1860. 17 No Config - Doesn't point to anything
  1861. 18 No Config - Doesn't point to anything
  1862. 19 | 7 | dst
  1863. 20 | 8 | dst
  1864. 21 No Config - Doesn't point to anything
  1865. 22 No Config - Doesn't point to anything
  1866. 23 No Config - Doesn't point to anything
  1867. -----------------------------------------------------------
  1868. ToDo - Move shadow register config to following in the future
  1869. This helps free up a block of shadow registers towards the end.
  1870. Can be used for other purposes
  1871. -----------------------------------------------------------
  1872. Shadow Register | CE | src/dst write index
  1873. -----------------------------------------------------------
  1874. 0 | 0 | src
  1875. 1 | 3 | src
  1876. 2 | 4 | src
  1877. 3 | 5 | src
  1878. 4 | 7 | src
  1879. -----------------------------------------------------------
  1880. 5 | 1 | dst
  1881. 6 | 2 | dst
  1882. 7 | 7 | dst
  1883. 8 | 8 | dst
  1884. -----------------------------------------------------------
  1885. 9 No Config - Doesn't point to anything
  1886. 12 No Config - Doesn't point to anything
  1887. 13 No Config - Doesn't point to anything
  1888. 14 No Config - Doesn't point to anything
  1889. 15 No Config - Doesn't point to anything
  1890. 16 No Config - Doesn't point to anything
  1891. 17 No Config - Doesn't point to anything
  1892. 18 No Config - Doesn't point to anything
  1893. 19 No Config - Doesn't point to anything
  1894. 20 No Config - Doesn't point to anything
  1895. 21 No Config - Doesn't point to anything
  1896. 22 No Config - Doesn't point to anything
  1897. 23 No Config - Doesn't point to anything
  1898. -----------------------------------------------------------
  1899. */
  1900. u32 shadow_sr_wr_ind_addr(struct ol_softc *scn, u32 ctrl_addr)
  1901. {
  1902. u32 addr = 0;
  1903. switch (COPY_ENGINE_ID(ctrl_addr)) {
  1904. case 0:
  1905. addr = SHADOW_VALUE0;
  1906. break;
  1907. case 3:
  1908. addr = SHADOW_VALUE3;
  1909. break;
  1910. case 4:
  1911. addr = SHADOW_VALUE4;
  1912. break;
  1913. case 5:
  1914. addr = SHADOW_VALUE5;
  1915. break;
  1916. case 7:
  1917. addr = SHADOW_VALUE7;
  1918. break;
  1919. default:
  1920. HIF_ERROR("invalid CE ctrl_addr\n");
  1921. CDF_ASSERT(0);
  1922. }
  1923. return addr;
  1924. }
  1925. u32 shadow_dst_wr_ind_addr(struct ol_softc *scn, u32 ctrl_addr)
  1926. {
  1927. u32 addr = 0;
  1928. switch (COPY_ENGINE_ID(ctrl_addr)) {
  1929. case 1:
  1930. addr = SHADOW_VALUE13;
  1931. break;
  1932. case 2:
  1933. addr = SHADOW_VALUE14;
  1934. break;
  1935. case 7:
  1936. addr = SHADOW_VALUE19;
  1937. break;
  1938. case 8:
  1939. addr = SHADOW_VALUE20;
  1940. break;
  1941. default:
  1942. HIF_ERROR("invalid CE ctrl_addr\n");
  1943. CDF_ASSERT(0);
  1944. }
  1945. return addr;
  1946. }
  1947. #endif
  1948. #if defined(FEATURE_LRO)
  1949. /**
  1950. * ce_lro_flush_cb_register() - register the LRO flush
  1951. * callback
  1952. * @scn: HIF context
  1953. * @handler: callback function
  1954. * @data: opaque data pointer to be passed back
  1955. *
  1956. * Store the LRO flush callback provided
  1957. *
  1958. * Return: none
  1959. */
  1960. void ce_lro_flush_cb_register(struct ol_softc *scn,
  1961. void (handler)(void *), void *data)
  1962. {
  1963. uint8_t ul, dl;
  1964. int ul_polled, dl_polled;
  1965. CDF_ASSERT(scn != NULL);
  1966. if (CDF_STATUS_SUCCESS !=
  1967. hif_map_service_to_pipe(scn, HTT_DATA_MSG_SVC,
  1968. &ul, &dl, &ul_polled, &dl_polled)) {
  1969. printk("%s cannot map service to pipe\n", __FUNCTION__);
  1970. return;
  1971. } else {
  1972. struct CE_state *ce_state;
  1973. ce_state = scn->ce_id_to_state[dl];
  1974. ce_state->lro_flush_cb = handler;
  1975. ce_state->lro_data = data;
  1976. }
  1977. }
  1978. /**
  1979. * ce_lro_flush_cb_deregister() - deregister the LRO flush
  1980. * callback
  1981. * @scn: HIF context
  1982. *
  1983. * Remove the LRO flush callback
  1984. *
  1985. * Return: none
  1986. */
  1987. void ce_lro_flush_cb_deregister(struct ol_softc *scn)
  1988. {
  1989. uint8_t ul, dl;
  1990. int ul_polled, dl_polled;
  1991. CDF_ASSERT(scn != NULL);
  1992. if (CDF_STATUS_SUCCESS !=
  1993. hif_map_service_to_pipe(scn, HTT_DATA_MSG_SVC,
  1994. &ul, &dl, &ul_polled, &dl_polled)) {
  1995. printk("%s cannot map service to pipe\n", __FUNCTION__);
  1996. return;
  1997. } else {
  1998. struct CE_state *ce_state;
  1999. ce_state = scn->ce_id_to_state[dl];
  2000. ce_state->lro_flush_cb = NULL;
  2001. ce_state->lro_data = NULL;
  2002. }
  2003. }
  2004. #endif
  2005. /**
  2006. * hif_map_service_to_pipe() - returns the ce ids pertaining to
  2007. * this service
  2008. * @scn: ol_softc pointer.
  2009. * @svc_id: Service ID for which the mapping is needed.
  2010. * @ul_pipe: address of the container in which ul pipe is returned.
  2011. * @dl_pipe: address of the container in which dl pipe is returned.
  2012. * @ul_is_polled: address of the container in which a bool
  2013. * indicating if the UL CE for this service
  2014. * is polled is returned.
  2015. * @dl_is_polled: address of the container in which a bool
  2016. * indicating if the DL CE for this service
  2017. * is polled is returned.
  2018. *
  2019. * Return: Indicates whether this operation was successful.
  2020. */
  2021. int hif_map_service_to_pipe(struct ol_softc *scn, uint16_t svc_id,
  2022. uint8_t *ul_pipe, uint8_t *dl_pipe, int *ul_is_polled,
  2023. int *dl_is_polled)
  2024. {
  2025. int status = CDF_STATUS_SUCCESS;
  2026. unsigned int i;
  2027. struct service_to_pipe element;
  2028. struct service_to_pipe *tgt_svc_map_to_use;
  2029. size_t sz_tgt_svc_map_to_use;
  2030. if (WLAN_IS_EPPING_ENABLED(cds_get_conparam())) {
  2031. tgt_svc_map_to_use = target_service_to_ce_map_wlan_epping;
  2032. sz_tgt_svc_map_to_use =
  2033. sizeof(target_service_to_ce_map_wlan_epping);
  2034. } else {
  2035. tgt_svc_map_to_use = target_service_to_ce_map_wlan;
  2036. sz_tgt_svc_map_to_use = sizeof(target_service_to_ce_map_wlan);
  2037. }
  2038. *dl_is_polled = 0; /* polling for received messages not supported */
  2039. for (i = 0; i < (sz_tgt_svc_map_to_use/sizeof(element)); i++) {
  2040. memcpy(&element, &tgt_svc_map_to_use[i], sizeof(element));
  2041. if (element.service_id == svc_id) {
  2042. if (element.pipedir == PIPEDIR_OUT)
  2043. *ul_pipe = element.pipenum;
  2044. else if (element.pipedir == PIPEDIR_IN)
  2045. *dl_pipe = element.pipenum;
  2046. }
  2047. }
  2048. *ul_is_polled =
  2049. (host_ce_config[*ul_pipe].flags & CE_ATTR_DISABLE_INTR) != 0;
  2050. return status;
  2051. }
  2052. #ifdef SHADOW_REG_DEBUG
  2053. inline uint32_t DEBUG_CE_SRC_RING_READ_IDX_GET(struct ol_softc *scn,
  2054. uint32_t CE_ctrl_addr)
  2055. {
  2056. uint32_t read_from_hw, srri_from_ddr = 0;
  2057. read_from_hw = A_TARGET_READ(scn, CE_ctrl_addr + CURRENT_SRRI_ADDRESS);
  2058. srri_from_ddr = SRRI_FROM_DDR_ADDR(VADDR_FOR_CE(scn, CE_ctrl_addr));
  2059. if (read_from_hw != srri_from_ddr) {
  2060. HIF_ERROR("error: read from ddr = %d actual read from register = %d, CE_MISC_INT_STATUS_GET = 0x%x\n",
  2061. srri_from_ddr, read_from_hw,
  2062. CE_MISC_INT_STATUS_GET(scn, CE_ctrl_addr));
  2063. CDF_ASSERT(0);
  2064. }
  2065. return srri_from_ddr;
  2066. }
  2067. inline uint32_t DEBUG_CE_DEST_RING_READ_IDX_GET(struct ol_softc *scn,
  2068. uint32_t CE_ctrl_addr)
  2069. {
  2070. uint32_t read_from_hw, drri_from_ddr = 0;
  2071. read_from_hw = A_TARGET_READ(scn, CE_ctrl_addr + CURRENT_DRRI_ADDRESS);
  2072. drri_from_ddr = DRRI_FROM_DDR_ADDR(VADDR_FOR_CE(scn, CE_ctrl_addr));
  2073. if (read_from_hw != drri_from_ddr) {
  2074. HIF_ERROR("error: read from ddr = %d actual read from register = %d, CE_MISC_INT_STATUS_GET = 0x%x\n",
  2075. drri_from_ddr, read_from_hw,
  2076. CE_MISC_INT_STATUS_GET(scn, CE_ctrl_addr));
  2077. CDF_ASSERT(0);
  2078. }
  2079. return drri_from_ddr;
  2080. }
  2081. #endif
  2082. #ifdef ADRASTEA_RRI_ON_DDR
  2083. /**
  2084. * hif_get_src_ring_read_index(): Called to get the SRRI
  2085. *
  2086. * @scn: ol_softc pointer
  2087. * @CE_ctrl_addr: base address of the CE whose RRI is to be read
  2088. *
  2089. * This function returns the SRRI to the caller. For CEs that
  2090. * dont have interrupts enabled, we look at the DDR based SRRI
  2091. *
  2092. * Return: SRRI
  2093. */
  2094. inline unsigned int hif_get_src_ring_read_index(struct ol_softc *scn,
  2095. uint32_t CE_ctrl_addr)
  2096. {
  2097. struct CE_attr attr;
  2098. attr = host_ce_config[COPY_ENGINE_ID(CE_ctrl_addr)];
  2099. if (attr.flags & CE_ATTR_DISABLE_INTR)
  2100. return CE_SRC_RING_READ_IDX_GET_FROM_DDR(scn, CE_ctrl_addr);
  2101. else
  2102. return A_TARGET_READ(scn,
  2103. (CE_ctrl_addr) + CURRENT_SRRI_ADDRESS);
  2104. }
  2105. /**
  2106. * hif_get_dst_ring_read_index(): Called to get the DRRI
  2107. *
  2108. * @scn: ol_softc pointer
  2109. * @CE_ctrl_addr: base address of the CE whose RRI is to be read
  2110. *
  2111. * This function returns the DRRI to the caller. For CEs that
  2112. * dont have interrupts enabled, we look at the DDR based DRRI
  2113. *
  2114. * Return: DRRI
  2115. */
  2116. inline unsigned int hif_get_dst_ring_read_index(struct ol_softc *scn,
  2117. uint32_t CE_ctrl_addr)
  2118. {
  2119. struct CE_attr attr;
  2120. attr = host_ce_config[COPY_ENGINE_ID(CE_ctrl_addr)];
  2121. if (attr.flags & CE_ATTR_DISABLE_INTR)
  2122. return CE_DEST_RING_READ_IDX_GET_FROM_DDR(scn, CE_ctrl_addr);
  2123. else
  2124. return A_TARGET_READ(scn,
  2125. (CE_ctrl_addr) + CURRENT_DRRI_ADDRESS);
  2126. }
  2127. /**
  2128. * hif_config_rri_on_ddr(): Configure the RRI on DDR mechanism
  2129. *
  2130. * @scn: ol_softc pointer
  2131. *
  2132. * This function allocates non cached memory on ddr and sends
  2133. * the physical address of this memory to the CE hardware. The
  2134. * hardware updates the RRI on this particular location.
  2135. *
  2136. * Return: None
  2137. */
  2138. static inline void hif_config_rri_on_ddr(struct ol_softc *scn)
  2139. {
  2140. unsigned int i;
  2141. cdf_dma_addr_t paddr_rri_on_ddr;
  2142. uint32_t high_paddr, low_paddr;
  2143. scn->vaddr_rri_on_ddr =
  2144. (uint32_t *)cdf_os_mem_alloc_consistent(scn->cdf_dev,
  2145. (CE_COUNT*sizeof(uint32_t)), &paddr_rri_on_ddr, 0);
  2146. low_paddr = BITS0_TO_31(paddr_rri_on_ddr);
  2147. high_paddr = BITS32_TO_35(paddr_rri_on_ddr);
  2148. HIF_ERROR("%s using srri and drri from DDR\n", __func__);
  2149. WRITE_CE_DDR_ADDRESS_FOR_RRI_LOW(scn, low_paddr);
  2150. WRITE_CE_DDR_ADDRESS_FOR_RRI_HIGH(scn, high_paddr);
  2151. for (i = 0; i < CE_COUNT; i++)
  2152. CE_IDX_UPD_EN_SET(scn, CE_BASE_ADDRESS(i));
  2153. cdf_mem_zero(scn->vaddr_rri_on_ddr, CE_COUNT*sizeof(uint32_t));
  2154. return;
  2155. }
  2156. #else
  2157. /**
  2158. * hif_config_rri_on_ddr(): Configure the RRI on DDR mechanism
  2159. *
  2160. * @scn: ol_softc pointer
  2161. *
  2162. * This is a dummy implementation for platforms that don't
  2163. * support this functionality.
  2164. *
  2165. * Return: None
  2166. */
  2167. static inline void hif_config_rri_on_ddr(struct ol_softc *scn)
  2168. {
  2169. return;
  2170. }
  2171. #endif
  2172. /**
  2173. * hif_dump_ce_registers() - dump ce registers
  2174. * @scn: ol_softc pointer.
  2175. *
  2176. * Output the copy engine registers
  2177. *
  2178. * Return: 0 for success or error code
  2179. */
  2180. int hif_dump_ce_registers(struct ol_softc *scn)
  2181. {
  2182. uint32_t ce_reg_address = CE0_BASE_ADDRESS;
  2183. uint32_t ce_reg_values[CE_COUNT_MAX][CE_USEFUL_SIZE >> 2];
  2184. uint32_t ce_reg_word_size = CE_USEFUL_SIZE >> 2;
  2185. uint16_t i;
  2186. CDF_STATUS status;
  2187. for (i = 0; i < CE_COUNT_MAX; i++, ce_reg_address += CE_OFFSET) {
  2188. status = hif_diag_read_mem(scn, ce_reg_address,
  2189. (uint8_t *) &ce_reg_values[i][0],
  2190. ce_reg_word_size * sizeof(uint32_t));
  2191. if (status != CDF_STATUS_SUCCESS) {
  2192. HIF_ERROR("Dumping CE register failed!");
  2193. return -EACCES;
  2194. }
  2195. HIF_ERROR("CE%d Registers:", i);
  2196. cdf_trace_hex_dump(CDF_MODULE_ID_HIF, CDF_TRACE_LEVEL_DEBUG,
  2197. (uint8_t *) &ce_reg_values[i][0],
  2198. ce_reg_word_size * sizeof(uint32_t));
  2199. }
  2200. return 0;
  2201. }