ce_main.c 87 KB

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