ce_main.c 69 KB

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