htc_send.c 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290
  1. /*
  2. * Copyright (c) 2013-2019 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #include "htc_debug.h"
  19. #include "htc_internal.h"
  20. #include "htc_credit_history.h"
  21. #include <qdf_mem.h> /* qdf_mem_malloc */
  22. #include <qdf_nbuf.h> /* qdf_nbuf_t */
  23. #include "qdf_module.h"
  24. /* #define USB_HIF_SINGLE_PIPE_DATA_SCHED */
  25. /* #ifdef USB_HIF_SINGLE_PIPE_DATA_SCHED */
  26. #define DATA_EP_SIZE 4
  27. /* #endif */
  28. #define HTC_DATA_RESOURCE_THRS 256
  29. #define HTC_DATA_MINDESC_PERPACKET 2
  30. enum HTC_SEND_QUEUE_RESULT {
  31. HTC_SEND_QUEUE_OK = 0, /* packet was queued */
  32. HTC_SEND_QUEUE_DROP = 1, /* this packet should be dropped */
  33. };
  34. #ifndef DEBUG_CREDIT
  35. #define DEBUG_CREDIT 0
  36. #endif
  37. #if DEBUG_CREDIT
  38. /* bit mask to enable debug certain endpoint */
  39. static unsigned int ep_debug_mask =
  40. (1 << ENDPOINT_0) | (1 << ENDPOINT_1) | (1 << ENDPOINT_2);
  41. #endif
  42. #ifdef QCA_WIFI_NAPIER_EMULATION
  43. #define HTC_EMULATION_DELAY_IN_MS 20
  44. /**
  45. * htc_add_delay(): Adds a delay in before proceeding, only for emulation
  46. *
  47. * Return: None
  48. */
  49. static inline void htc_add_emulation_delay(void)
  50. {
  51. qdf_mdelay(HTC_EMULATION_DELAY_IN_MS);
  52. }
  53. #else
  54. static inline void htc_add_emulation_delay(void)
  55. {
  56. }
  57. #endif
  58. void htc_dump_counter_info(HTC_HANDLE HTCHandle)
  59. {
  60. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  61. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  62. ("\n%s: ce_send_cnt = %d, TX_comp_cnt = %d\n",
  63. __func__, target->ce_send_cnt, target->TX_comp_cnt));
  64. }
  65. int htc_get_tx_queue_depth(HTC_HANDLE *htc_handle, HTC_ENDPOINT_ID endpoint_id)
  66. {
  67. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
  68. HTC_ENDPOINT *endpoint = &target->endpoint[endpoint_id];
  69. return HTC_PACKET_QUEUE_DEPTH(&endpoint->TxQueue);
  70. }
  71. qdf_export_symbol(htc_get_tx_queue_depth);
  72. void htc_get_control_endpoint_tx_host_credits(HTC_HANDLE HTCHandle,
  73. int *credits)
  74. {
  75. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  76. HTC_ENDPOINT *pEndpoint;
  77. int i;
  78. if (!credits || !target) {
  79. AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: invalid args", __func__));
  80. return;
  81. }
  82. *credits = 0;
  83. LOCK_HTC_TX(target);
  84. for (i = 0; i < ENDPOINT_MAX; i++) {
  85. pEndpoint = &target->endpoint[i];
  86. if (pEndpoint->service_id == WMI_CONTROL_SVC) {
  87. *credits = pEndpoint->TxCredits;
  88. break;
  89. }
  90. }
  91. UNLOCK_HTC_TX(target);
  92. }
  93. static inline void restore_tx_packet(HTC_TARGET *target, HTC_PACKET *pPacket)
  94. {
  95. qdf_nbuf_t netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  96. if (pPacket->PktInfo.AsTx.Flags & HTC_TX_PACKET_FLAG_FIXUP_NETBUF) {
  97. qdf_nbuf_unmap(target->osdev, netbuf, QDF_DMA_TO_DEVICE);
  98. pPacket->PktInfo.AsTx.Flags &= ~HTC_TX_PACKET_FLAG_FIXUP_NETBUF;
  99. }
  100. qdf_nbuf_pull_head(netbuf, sizeof(HTC_FRAME_HDR));
  101. }
  102. static void send_packet_completion(HTC_TARGET *target, HTC_PACKET *pPacket)
  103. {
  104. HTC_ENDPOINT *pEndpoint = &target->endpoint[pPacket->Endpoint];
  105. HTC_EP_SEND_PKT_COMPLETE EpTxComplete;
  106. restore_tx_packet(target, pPacket);
  107. /* do completion */
  108. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  109. ("HTC calling ep %d send complete callback on packet %pK\n",
  110. pEndpoint->Id, pPacket));
  111. EpTxComplete = pEndpoint->EpCallBacks.EpTxComplete;
  112. if (EpTxComplete)
  113. EpTxComplete(pEndpoint->EpCallBacks.pContext, pPacket);
  114. else
  115. qdf_nbuf_free(pPacket->pPktContext);
  116. }
  117. void htc_send_complete_check_cleanup(void *context)
  118. {
  119. HTC_ENDPOINT *pEndpoint = (HTC_ENDPOINT *) context;
  120. htc_send_complete_check(pEndpoint, 1);
  121. }
  122. HTC_PACKET *allocate_htc_bundle_packet(HTC_TARGET *target)
  123. {
  124. HTC_PACKET *pPacket;
  125. HTC_PACKET_QUEUE *pQueueSave;
  126. qdf_nbuf_t netbuf;
  127. LOCK_HTC_TX(target);
  128. if (!target->pBundleFreeList) {
  129. UNLOCK_HTC_TX(target);
  130. netbuf = qdf_nbuf_alloc(NULL,
  131. target->MaxMsgsPerHTCBundle *
  132. target->TargetCreditSize, 0, 4, false);
  133. AR_DEBUG_ASSERT(netbuf);
  134. if (!netbuf)
  135. return NULL;
  136. pPacket = qdf_mem_malloc(sizeof(HTC_PACKET));
  137. AR_DEBUG_ASSERT(pPacket);
  138. if (!pPacket) {
  139. qdf_nbuf_free(netbuf);
  140. return NULL;
  141. }
  142. pQueueSave = qdf_mem_malloc(sizeof(HTC_PACKET_QUEUE));
  143. AR_DEBUG_ASSERT(pQueueSave);
  144. if (!pQueueSave) {
  145. qdf_nbuf_free(netbuf);
  146. qdf_mem_free(pPacket);
  147. return NULL;
  148. }
  149. INIT_HTC_PACKET_QUEUE(pQueueSave);
  150. pPacket->pContext = pQueueSave;
  151. SET_HTC_PACKET_NET_BUF_CONTEXT(pPacket, netbuf);
  152. pPacket->pBuffer = qdf_nbuf_data(netbuf);
  153. pPacket->BufferLength = qdf_nbuf_len(netbuf);
  154. /* store the original head room so that we can restore this
  155. * when we "free" the packet.
  156. * free packet puts the packet back on the free list
  157. */
  158. pPacket->netbufOrigHeadRoom = qdf_nbuf_headroom(netbuf);
  159. return pPacket;
  160. }
  161. /* already done malloc - restore from free list */
  162. pPacket = target->pBundleFreeList;
  163. AR_DEBUG_ASSERT(pPacket);
  164. if (!pPacket) {
  165. UNLOCK_HTC_TX(target);
  166. return NULL;
  167. }
  168. target->pBundleFreeList = (HTC_PACKET *) pPacket->ListLink.pNext;
  169. UNLOCK_HTC_TX(target);
  170. pPacket->ListLink.pNext = NULL;
  171. return pPacket;
  172. }
  173. void free_htc_bundle_packet(HTC_TARGET *target, HTC_PACKET *pPacket)
  174. {
  175. uint32_t curentHeadRoom;
  176. qdf_nbuf_t netbuf;
  177. HTC_PACKET_QUEUE *pQueueSave;
  178. netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  179. AR_DEBUG_ASSERT(netbuf);
  180. if (!netbuf) {
  181. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  182. ("\n%s: Invalid netbuf in HTC Packet\n",
  183. __func__));
  184. return;
  185. }
  186. /* HIF adds data to the headroom section of the nbuf, restore thei
  187. * original size. If this is not done, headroom keeps shrinking with
  188. * every HIF send and eventually HIF ends up doing another malloc big
  189. * enough to store the data + its header
  190. */
  191. curentHeadRoom = qdf_nbuf_headroom(netbuf);
  192. qdf_nbuf_pull_head(netbuf,
  193. pPacket->netbufOrigHeadRoom - curentHeadRoom);
  194. qdf_nbuf_trim_tail(netbuf, qdf_nbuf_len(netbuf));
  195. /* restore the pBuffer pointer. HIF changes this */
  196. pPacket->pBuffer = qdf_nbuf_data(netbuf);
  197. pPacket->BufferLength = qdf_nbuf_len(netbuf);
  198. /* restore queue */
  199. pQueueSave = (HTC_PACKET_QUEUE *) pPacket->pContext;
  200. if (qdf_unlikely(!pQueueSave)) {
  201. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  202. ("\n%s: Invalid pQueueSave in HTC Packet\n",
  203. __func__));
  204. AR_DEBUG_ASSERT(pQueueSave);
  205. } else
  206. INIT_HTC_PACKET_QUEUE(pQueueSave);
  207. LOCK_HTC_TX(target);
  208. if (!target->pBundleFreeList) {
  209. target->pBundleFreeList = pPacket;
  210. pPacket->ListLink.pNext = NULL;
  211. } else {
  212. pPacket->ListLink.pNext = (DL_LIST *) target->pBundleFreeList;
  213. target->pBundleFreeList = pPacket;
  214. }
  215. UNLOCK_HTC_TX(target);
  216. }
  217. #if defined(DEBUG_HL_LOGGING) && defined(CONFIG_HL_SUPPORT)
  218. /**
  219. * htc_send_update_tx_bundle_stats() - update tx bundle stats depends
  220. * on max bundle size
  221. * @target: hif context
  222. * @data_len: tx data len
  223. * @TxCreditSize: endpoint tx credit size
  224. *
  225. * Return: None
  226. */
  227. static inline void
  228. htc_send_update_tx_bundle_stats(HTC_TARGET *target,
  229. qdf_size_t data_len,
  230. int TxCreditSize)
  231. {
  232. if ((data_len / TxCreditSize) <= HTC_MAX_MSG_PER_BUNDLE_TX)
  233. target->tx_bundle_stats[(data_len / TxCreditSize) - 1]++;
  234. }
  235. /**
  236. * htc_issue_tx_bundle_stats_inc() - increment in tx bundle stats
  237. * on max bundle size
  238. * @target: hif context
  239. *
  240. * Return: None
  241. */
  242. static inline void
  243. htc_issue_tx_bundle_stats_inc(HTC_TARGET *target)
  244. {
  245. target->tx_bundle_stats[0]++;
  246. }
  247. #else
  248. static inline void
  249. htc_send_update_tx_bundle_stats(HTC_TARGET *target,
  250. qdf_size_t data_len,
  251. int TxCreditSize)
  252. {
  253. }
  254. static inline void
  255. htc_issue_tx_bundle_stats_inc(HTC_TARGET *target)
  256. {
  257. }
  258. #endif
  259. #if defined(HIF_USB) || defined(HIF_SDIO)
  260. #ifdef ENABLE_BUNDLE_TX
  261. static QDF_STATUS htc_send_bundled_netbuf(HTC_TARGET *target,
  262. HTC_ENDPOINT *pEndpoint,
  263. unsigned char *pBundleBuffer,
  264. HTC_PACKET *pPacketTx)
  265. {
  266. qdf_size_t data_len;
  267. QDF_STATUS status;
  268. qdf_nbuf_t bundleBuf;
  269. uint32_t data_attr = 0;
  270. bundleBuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacketTx);
  271. data_len = pBundleBuffer - qdf_nbuf_data(bundleBuf);
  272. qdf_nbuf_put_tail(bundleBuf, data_len);
  273. SET_HTC_PACKET_INFO_TX(pPacketTx,
  274. target,
  275. pBundleBuffer,
  276. data_len,
  277. pEndpoint->Id, HTC_TX_PACKET_TAG_BUNDLED);
  278. LOCK_HTC_TX(target);
  279. HTC_PACKET_ENQUEUE(&pEndpoint->TxLookupQueue, pPacketTx);
  280. pEndpoint->ul_outstanding_cnt++;
  281. UNLOCK_HTC_TX(target);
  282. #if DEBUG_BUNDLE
  283. qdf_print(" Send bundle EP%d buffer size:0x%x, total:0x%x, count:%d.",
  284. pEndpoint->Id,
  285. pEndpoint->TxCreditSize,
  286. data_len, data_len / pEndpoint->TxCreditSize);
  287. #endif
  288. htc_send_update_tx_bundle_stats(target, data_len,
  289. pEndpoint->TxCreditSize);
  290. status = hif_send_head(target->hif_dev,
  291. pEndpoint->UL_PipeID,
  292. pEndpoint->Id, data_len,
  293. bundleBuf, data_attr);
  294. if (qdf_unlikely(QDF_IS_STATUS_ERROR(status))) {
  295. HTC_PACKET_QUEUE requeue;
  296. qdf_print("hif_send_head failed(len=%zu).", data_len);
  297. INIT_HTC_PACKET_QUEUE(&requeue);
  298. LOCK_HTC_TX(target);
  299. pEndpoint->ul_outstanding_cnt--;
  300. HTC_PACKET_REMOVE(&pEndpoint->TxLookupQueue, pPacketTx);
  301. if (pPacketTx->PktInfo.AsTx.Tag == HTC_TX_PACKET_TAG_BUNDLED) {
  302. HTC_PACKET *temp_packet;
  303. HTC_PACKET_QUEUE *packet_queue =
  304. (HTC_PACKET_QUEUE *)pPacketTx->pContext;
  305. HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(packet_queue,
  306. temp_packet) {
  307. HTC_PACKET_ENQUEUE(&requeue, temp_packet);
  308. } HTC_PACKET_QUEUE_ITERATE_END;
  309. UNLOCK_HTC_TX(target);
  310. free_htc_bundle_packet(target, pPacketTx);
  311. LOCK_HTC_TX(target);
  312. } else {
  313. HTC_PACKET_ENQUEUE(&requeue, pPacketTx);
  314. }
  315. HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&pEndpoint->TxQueue,
  316. &requeue);
  317. UNLOCK_HTC_TX(target);
  318. }
  319. return status;
  320. }
  321. /**
  322. * htc_issue_packets_bundle() - HTC function to send bundle packets from a queue
  323. * @target: HTC target on which packets need to be sent
  324. * @pEndpoint: logical endpoint on which packets needs to be sent
  325. * @pPktQueue: HTC packet queue containing the list of packets to be sent
  326. *
  327. * Return: void
  328. */
  329. static void htc_issue_packets_bundle(HTC_TARGET *target,
  330. HTC_ENDPOINT *pEndpoint,
  331. HTC_PACKET_QUEUE *pPktQueue)
  332. {
  333. int i, frag_count, nbytes;
  334. qdf_nbuf_t netbuf, bundleBuf;
  335. unsigned char *pBundleBuffer = NULL;
  336. HTC_PACKET *pPacket = NULL, *pPacketTx = NULL;
  337. HTC_FRAME_HDR *pHtcHdr;
  338. int last_credit_pad = 0;
  339. int creditPad, creditRemainder, transferLength, bundlesSpaceRemaining =
  340. 0;
  341. HTC_PACKET_QUEUE *pQueueSave = NULL;
  342. bundlesSpaceRemaining =
  343. target->MaxMsgsPerHTCBundle * pEndpoint->TxCreditSize;
  344. pPacketTx = allocate_htc_bundle_packet(target);
  345. if (!pPacketTx) {
  346. /* good time to panic */
  347. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  348. ("allocate_htc_bundle_packet failed\n"));
  349. AR_DEBUG_ASSERT(false);
  350. return;
  351. }
  352. bundleBuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacketTx);
  353. pBundleBuffer = qdf_nbuf_data(bundleBuf);
  354. pQueueSave = (HTC_PACKET_QUEUE *) pPacketTx->pContext;
  355. while (1) {
  356. pPacket = htc_packet_dequeue(pPktQueue);
  357. if (!pPacket)
  358. break;
  359. creditPad = 0;
  360. transferLength = pPacket->ActualLength + HTC_HDR_LENGTH;
  361. creditRemainder = transferLength % pEndpoint->TxCreditSize;
  362. if (creditRemainder != 0) {
  363. if (transferLength < pEndpoint->TxCreditSize) {
  364. creditPad = pEndpoint->TxCreditSize -
  365. transferLength;
  366. } else {
  367. creditPad = creditRemainder;
  368. }
  369. transferLength += creditPad;
  370. }
  371. if (bundlesSpaceRemaining < transferLength) {
  372. /* send out previous buffer */
  373. htc_send_bundled_netbuf(target, pEndpoint,
  374. pBundleBuffer - last_credit_pad,
  375. pPacketTx);
  376. /* One packet has been dequeued from sending queue when enter
  377. * this loop, so need to add 1 back for this checking.
  378. */
  379. if ((HTC_PACKET_QUEUE_DEPTH(pPktQueue) + 1) <
  380. HTC_MIN_MSG_PER_BUNDLE) {
  381. HTC_PACKET_ENQUEUE_TO_HEAD(pPktQueue, pPacket);
  382. return;
  383. }
  384. bundlesSpaceRemaining =
  385. target->MaxMsgsPerHTCBundle *
  386. pEndpoint->TxCreditSize;
  387. pPacketTx = allocate_htc_bundle_packet(target);
  388. if (!pPacketTx) {
  389. HTC_PACKET_ENQUEUE_TO_HEAD(pPktQueue, pPacket);
  390. /* good time to panic */
  391. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  392. ("allocate_htc_bundle_packet failed\n"));
  393. AR_DEBUG_ASSERT(false);
  394. return;
  395. }
  396. bundleBuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacketTx);
  397. pBundleBuffer = qdf_nbuf_data(bundleBuf);
  398. pQueueSave = (HTC_PACKET_QUEUE *) pPacketTx->pContext;
  399. }
  400. bundlesSpaceRemaining -= transferLength;
  401. netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  402. if (hif_get_bus_type(target->hif_dev) != QDF_BUS_TYPE_USB) {
  403. pHtcHdr = (HTC_FRAME_HDR *)qdf_nbuf_get_frag_vaddr(
  404. netbuf, 0);
  405. HTC_WRITE32(pHtcHdr,
  406. SM(pPacket->ActualLength,
  407. HTC_FRAME_HDR_PAYLOADLEN) |
  408. SM(pPacket->PktInfo.AsTx.SendFlags |
  409. HTC_FLAGS_SEND_BUNDLE,
  410. HTC_FRAME_HDR_FLAGS) |
  411. SM(pPacket->Endpoint,
  412. HTC_FRAME_HDR_ENDPOINTID));
  413. HTC_WRITE32((uint32_t *) pHtcHdr + 1,
  414. SM(pPacket->PktInfo.AsTx.SeqNo,
  415. HTC_FRAME_HDR_CONTROLBYTES1) | SM(creditPad,
  416. HTC_FRAME_HDR_RESERVED));
  417. pHtcHdr->reserved = creditPad;
  418. }
  419. frag_count = qdf_nbuf_get_num_frags(netbuf);
  420. nbytes = pPacket->ActualLength + HTC_HDR_LENGTH;
  421. for (i = 0; i < frag_count && nbytes > 0; i++) {
  422. int frag_len = qdf_nbuf_get_frag_len(netbuf, i);
  423. unsigned char *frag_addr =
  424. qdf_nbuf_get_frag_vaddr(netbuf, i);
  425. if (frag_len > nbytes)
  426. frag_len = nbytes;
  427. qdf_mem_copy(pBundleBuffer, frag_addr, frag_len);
  428. nbytes -= frag_len;
  429. pBundleBuffer += frag_len;
  430. }
  431. HTC_PACKET_ENQUEUE(pQueueSave, pPacket);
  432. pBundleBuffer += creditPad;
  433. /* last one can't be packed. */
  434. if (hif_get_bus_type(target->hif_dev) == QDF_BUS_TYPE_USB)
  435. last_credit_pad = creditPad;
  436. }
  437. /* send out remaining buffer */
  438. if (pBundleBuffer != qdf_nbuf_data(bundleBuf))
  439. htc_send_bundled_netbuf(target, pEndpoint,
  440. pBundleBuffer - last_credit_pad,
  441. pPacketTx);
  442. else
  443. free_htc_bundle_packet(target, pPacketTx);
  444. }
  445. #endif /* ENABLE_BUNDLE_TX */
  446. #else
  447. static void htc_issue_packets_bundle(HTC_TARGET *target,
  448. HTC_ENDPOINT *pEndpoint,
  449. HTC_PACKET_QUEUE *pPktQueue)
  450. {
  451. }
  452. #endif
  453. /**
  454. * htc_issue_packets() - HTC function to send packets from a queue
  455. * @target: HTC target on which packets need to be sent
  456. * @pEndpoint: logical endpoint on which packets needs to be sent
  457. * @pPktQueue: HTC packet queue containing the list of packets to be sent
  458. *
  459. * Return: QDF_STATUS_SUCCESS on success and error QDF status on failure
  460. */
  461. static QDF_STATUS htc_issue_packets(HTC_TARGET *target,
  462. HTC_ENDPOINT *pEndpoint,
  463. HTC_PACKET_QUEUE *pPktQueue)
  464. {
  465. QDF_STATUS status = QDF_STATUS_SUCCESS;
  466. qdf_nbuf_t netbuf;
  467. HTC_PACKET *pPacket = NULL;
  468. uint16_t payloadLen;
  469. HTC_FRAME_HDR *pHtcHdr;
  470. uint32_t data_attr = 0;
  471. enum qdf_bus_type bus_type;
  472. QDF_STATUS ret;
  473. bool rt_put = false;
  474. bus_type = hif_get_bus_type(target->hif_dev);
  475. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  476. ("+htc_issue_packets: Queue: %pK, Pkts %d\n", pPktQueue,
  477. HTC_PACKET_QUEUE_DEPTH(pPktQueue)));
  478. while (true) {
  479. if (HTC_TX_BUNDLE_ENABLED(target) &&
  480. HTC_PACKET_QUEUE_DEPTH(pPktQueue) >=
  481. HTC_MIN_MSG_PER_BUNDLE) {
  482. switch (bus_type) {
  483. case QDF_BUS_TYPE_SDIO:
  484. if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint))
  485. break;
  486. case QDF_BUS_TYPE_USB:
  487. htc_issue_packets_bundle(target,
  488. pEndpoint,
  489. pPktQueue);
  490. break;
  491. default:
  492. break;
  493. }
  494. }
  495. /* if not bundling or there was a packet that could not be
  496. * placed in a bundle, and send it by normal way
  497. */
  498. pPacket = htc_packet_dequeue(pPktQueue);
  499. if (!pPacket) {
  500. /* local queue is fully drained */
  501. break;
  502. }
  503. netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  504. AR_DEBUG_ASSERT(netbuf);
  505. /* Non-credit enabled endpoints have been mapped and setup by
  506. * now, so no need to revisit the HTC headers
  507. */
  508. if (IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  509. payloadLen = pPacket->ActualLength;
  510. /* setup HTC frame header */
  511. pHtcHdr = (HTC_FRAME_HDR *)
  512. qdf_nbuf_get_frag_vaddr(netbuf, 0);
  513. if (qdf_unlikely(!pHtcHdr)) {
  514. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  515. ("%s Invalid pHtcHdr\n",
  516. __func__));
  517. AR_DEBUG_ASSERT(pHtcHdr);
  518. status = QDF_STATUS_E_FAILURE;
  519. break;
  520. }
  521. HTC_WRITE32(pHtcHdr,
  522. SM(payloadLen,
  523. HTC_FRAME_HDR_PAYLOADLEN) |
  524. SM(pPacket->PktInfo.AsTx.SendFlags,
  525. HTC_FRAME_HDR_FLAGS) |
  526. SM(pPacket->Endpoint,
  527. HTC_FRAME_HDR_ENDPOINTID));
  528. HTC_WRITE32(((uint32_t *) pHtcHdr) + 1,
  529. SM(pPacket->PktInfo.AsTx.SeqNo,
  530. HTC_FRAME_HDR_CONTROLBYTES1));
  531. /*
  532. * Now that the HTC frame header has been added, the
  533. * netbuf can be mapped. This only applies to non-data
  534. * frames, since data frames were already mapped as they
  535. * entered into the driver.
  536. */
  537. pPacket->PktInfo.AsTx.Flags |=
  538. HTC_TX_PACKET_FLAG_FIXUP_NETBUF;
  539. ret = qdf_nbuf_map(target->osdev,
  540. GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket),
  541. QDF_DMA_TO_DEVICE);
  542. if (ret != QDF_STATUS_SUCCESS) {
  543. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  544. ("%s nbuf Map Fail Endpnt %pK\n",
  545. __func__, pEndpoint));
  546. HTC_PACKET_ENQUEUE_TO_HEAD(pPktQueue, pPacket);
  547. status = QDF_STATUS_E_FAILURE;
  548. break;
  549. }
  550. }
  551. if (!pEndpoint->async_update) {
  552. LOCK_HTC_TX(target);
  553. }
  554. /* store in look up queue to match completions */
  555. HTC_PACKET_ENQUEUE(&pEndpoint->TxLookupQueue, pPacket);
  556. INC_HTC_EP_STAT(pEndpoint, TxIssued, 1);
  557. pEndpoint->ul_outstanding_cnt++;
  558. if (!pEndpoint->async_update) {
  559. UNLOCK_HTC_TX(target);
  560. hif_send_complete_check(target->hif_dev,
  561. pEndpoint->UL_PipeID, false);
  562. }
  563. htc_packet_set_magic_cookie(pPacket, HTC_PACKET_MAGIC_COOKIE);
  564. /*
  565. * For HTT messages without a response from fw,
  566. * do the runtime put here.
  567. * otherwise runtime put will be done when the fw response comes
  568. */
  569. if (pPacket->PktInfo.AsTx.Tag == HTC_TX_PACKET_TAG_RUNTIME_PUT)
  570. rt_put = true;
  571. #if DEBUG_BUNDLE
  572. qdf_print(" Send single EP%d buffer size:0x%x, total:0x%x.",
  573. pEndpoint->Id,
  574. pEndpoint->TxCreditSize,
  575. HTC_HDR_LENGTH + pPacket->ActualLength);
  576. #endif
  577. status = hif_send_head(target->hif_dev,
  578. pEndpoint->UL_PipeID, pEndpoint->Id,
  579. HTC_HDR_LENGTH + pPacket->ActualLength,
  580. netbuf, data_attr);
  581. htc_issue_tx_bundle_stats_inc(target);
  582. target->ce_send_cnt++;
  583. if (qdf_unlikely(QDF_IS_STATUS_ERROR(status))) {
  584. if (status != QDF_STATUS_E_RESOURCES) {
  585. /* TODO : if more than 1 endpoint maps to the
  586. * same PipeID it is possible to run out of
  587. * resources in the HIF layer. Don't emit the
  588. * error
  589. */
  590. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  591. ("hif_send Failed status:%d\n",
  592. status));
  593. }
  594. /* only unmap if we mapped in this function */
  595. if (IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  596. qdf_nbuf_unmap(target->osdev,
  597. GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket),
  598. QDF_DMA_TO_DEVICE);
  599. pPacket->PktInfo.AsTx.Flags &=
  600. ~HTC_TX_PACKET_FLAG_FIXUP_NETBUF;
  601. }
  602. if (!pEndpoint->async_update) {
  603. LOCK_HTC_TX(target);
  604. }
  605. target->ce_send_cnt--;
  606. pEndpoint->ul_outstanding_cnt--;
  607. HTC_PACKET_REMOVE(&pEndpoint->TxLookupQueue, pPacket);
  608. htc_packet_set_magic_cookie(pPacket, 0);
  609. /* put it back into the callers queue */
  610. HTC_PACKET_ENQUEUE_TO_HEAD(pPktQueue, pPacket);
  611. /* reclaim credits */
  612. HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pPktQueue,
  613. pPacket) {
  614. pEndpoint->TxCredits +=
  615. pPacket->PktInfo.AsTx.CreditsUsed;
  616. } HTC_PACKET_QUEUE_ITERATE_END;
  617. if (!pEndpoint->async_update) {
  618. UNLOCK_HTC_TX(target);
  619. }
  620. break;
  621. }
  622. if (rt_put) {
  623. hif_pm_runtime_put(target->hif_dev);
  624. rt_put = false;
  625. }
  626. }
  627. if (qdf_unlikely(QDF_IS_STATUS_ERROR(status))) {
  628. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  629. ("htc_issue_packets, failed pkt:0x%pK status:%d",
  630. pPacket, status));
  631. }
  632. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_issue_packets\n"));
  633. return status;
  634. }
  635. #ifdef FEATURE_RUNTIME_PM
  636. /**
  637. * extract_htc_pm_packets(): move pm packets from endpoint into queue
  638. * @endpoint: which enpoint to extract packets from
  639. * @queue: a queue to store extracted packets in.
  640. *
  641. * remove pm packets from the endpoint's tx queue.
  642. * queue them into a queue
  643. */
  644. static void extract_htc_pm_packets(HTC_ENDPOINT *endpoint,
  645. HTC_PACKET_QUEUE *queue)
  646. {
  647. HTC_PACKET *packet;
  648. /* only WMI endpoint has power management packets */
  649. if (endpoint->service_id != WMI_CONTROL_SVC)
  650. return;
  651. ITERATE_OVER_LIST_ALLOW_REMOVE(&endpoint->TxQueue.QueueHead, packet,
  652. HTC_PACKET, ListLink) {
  653. if (packet->PktInfo.AsTx.Tag == HTC_TX_PACKET_TAG_AUTO_PM) {
  654. HTC_PACKET_REMOVE(&endpoint->TxQueue, packet);
  655. HTC_PACKET_ENQUEUE(queue, packet);
  656. }
  657. } ITERATE_END
  658. }
  659. /**
  660. * queue_htc_pm_packets(): queue pm packets with priority
  661. * @endpoint: enpoint to queue packets to
  662. * @queue: queue of pm packets to enque
  663. *
  664. * suspend resume packets get special treatment & priority.
  665. * need to queue them at the front of the queue.
  666. */
  667. static void queue_htc_pm_packets(HTC_ENDPOINT *endpoint,
  668. HTC_PACKET_QUEUE *queue)
  669. {
  670. if (endpoint->service_id != WMI_CONTROL_SVC)
  671. return;
  672. HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&endpoint->TxQueue, queue);
  673. }
  674. #else
  675. static void extract_htc_pm_packets(HTC_ENDPOINT *endpoint,
  676. HTC_PACKET_QUEUE *queue)
  677. {}
  678. static void queue_htc_pm_packets(HTC_ENDPOINT *endpoint,
  679. HTC_PACKET_QUEUE *queue)
  680. {}
  681. #endif
  682. /**
  683. * get_htc_send_packets_credit_based() - get packets based on available credits
  684. * @target: HTC target on which packets need to be sent
  685. * @pEndpoint: logical endpoint on which packets needs to be sent
  686. * @pQueue: HTC packet queue containing the list of packets to be sent
  687. *
  688. * Get HTC send packets from TX queue on an endpoint based on available credits.
  689. * The function moves the packets from TX queue of the endpoint to pQueue.
  690. *
  691. * Return: None
  692. */
  693. static void get_htc_send_packets_credit_based(HTC_TARGET *target,
  694. HTC_ENDPOINT *pEndpoint,
  695. HTC_PACKET_QUEUE *pQueue)
  696. {
  697. int creditsRequired;
  698. int remainder;
  699. uint8_t sendFlags;
  700. HTC_PACKET *pPacket;
  701. unsigned int transferLength;
  702. HTC_PACKET_QUEUE *tx_queue;
  703. HTC_PACKET_QUEUE pm_queue;
  704. bool do_pm_get = false;
  705. /*** NOTE : the TX lock is held when this function is called ***/
  706. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  707. ("+get_htc_send_packets_credit_based\n"));
  708. INIT_HTC_PACKET_QUEUE(&pm_queue);
  709. extract_htc_pm_packets(pEndpoint, &pm_queue);
  710. if (HTC_QUEUE_EMPTY(&pm_queue)) {
  711. tx_queue = &pEndpoint->TxQueue;
  712. do_pm_get = true;
  713. } else {
  714. tx_queue = &pm_queue;
  715. }
  716. /* loop until we can grab as many packets out of the queue as we can */
  717. while (true) {
  718. if (do_pm_get && hif_pm_runtime_get(target->hif_dev)) {
  719. /* bus suspended, runtime resume issued */
  720. QDF_ASSERT(HTC_PACKET_QUEUE_DEPTH(pQueue) == 0);
  721. break;
  722. }
  723. sendFlags = 0;
  724. /* get packet at head, but don't remove it */
  725. pPacket = htc_get_pkt_at_head(tx_queue);
  726. if (!pPacket) {
  727. if (do_pm_get)
  728. hif_pm_runtime_put(target->hif_dev);
  729. break;
  730. }
  731. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  732. (" Got head packet:%pK , Queue Depth: %d\n",
  733. pPacket,
  734. HTC_PACKET_QUEUE_DEPTH(tx_queue)));
  735. transferLength = pPacket->ActualLength + HTC_HDR_LENGTH;
  736. if (transferLength <= pEndpoint->TxCreditSize) {
  737. creditsRequired = 1;
  738. } else {
  739. /* figure out how many credits this message requires */
  740. creditsRequired =
  741. transferLength / pEndpoint->TxCreditSize;
  742. remainder = transferLength % pEndpoint->TxCreditSize;
  743. if (remainder)
  744. creditsRequired++;
  745. }
  746. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  747. (" Credits Required:%d Got:%d\n",
  748. creditsRequired, pEndpoint->TxCredits));
  749. if (pEndpoint->Id == ENDPOINT_0) {
  750. /*
  751. * endpoint 0 is special, it always has a credit and
  752. * does not require credit based flow control
  753. */
  754. creditsRequired = 0;
  755. } else {
  756. if (pEndpoint->TxCredits < creditsRequired) {
  757. #if DEBUG_CREDIT
  758. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  759. ("EP%d,No Credit now.%d < %d\n",
  760. pEndpoint->Id,
  761. pEndpoint->TxCredits,
  762. creditsRequired));
  763. #endif
  764. if (do_pm_get)
  765. hif_pm_runtime_put(target->hif_dev);
  766. break;
  767. }
  768. pEndpoint->TxCredits -= creditsRequired;
  769. INC_HTC_EP_STAT(pEndpoint, TxCreditsConsummed,
  770. creditsRequired);
  771. /* check if we need credits back from the target */
  772. if (pEndpoint->TxCredits <=
  773. pEndpoint->TxCreditsPerMaxMsg) {
  774. /* tell the target we need credits ASAP! */
  775. sendFlags |= HTC_FLAGS_NEED_CREDIT_UPDATE;
  776. if (pEndpoint->service_id == WMI_CONTROL_SVC) {
  777. htc_credit_record(HTC_REQUEST_CREDIT,
  778. pEndpoint->TxCredits,
  779. HTC_PACKET_QUEUE_DEPTH
  780. (tx_queue));
  781. }
  782. INC_HTC_EP_STAT(pEndpoint,
  783. TxCreditLowIndications, 1);
  784. #if DEBUG_CREDIT
  785. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  786. (" EP%d Needs Credits\n",
  787. pEndpoint->Id));
  788. #endif
  789. }
  790. }
  791. /* now we can fully dequeue */
  792. pPacket = htc_packet_dequeue(tx_queue);
  793. if (pPacket) {
  794. /* save the number of credits this packet consumed */
  795. pPacket->PktInfo.AsTx.CreditsUsed = creditsRequired;
  796. /* save send flags */
  797. pPacket->PktInfo.AsTx.SendFlags = sendFlags;
  798. /* queue this packet into the caller's queue */
  799. HTC_PACKET_ENQUEUE(pQueue, pPacket);
  800. }
  801. }
  802. if (!HTC_QUEUE_EMPTY(&pm_queue))
  803. queue_htc_pm_packets(pEndpoint, &pm_queue);
  804. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  805. ("-get_htc_send_packets_credit_based\n"));
  806. }
  807. static void get_htc_send_packets(HTC_TARGET *target,
  808. HTC_ENDPOINT *pEndpoint,
  809. HTC_PACKET_QUEUE *pQueue, int Resources)
  810. {
  811. HTC_PACKET *pPacket;
  812. HTC_PACKET_QUEUE *tx_queue;
  813. HTC_PACKET_QUEUE pm_queue;
  814. bool do_pm_get = false;
  815. /*** NOTE : the TX lock is held when this function is called ***/
  816. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  817. ("+get_htc_send_packets %d resources\n", Resources));
  818. INIT_HTC_PACKET_QUEUE(&pm_queue);
  819. extract_htc_pm_packets(pEndpoint, &pm_queue);
  820. if (HTC_QUEUE_EMPTY(&pm_queue)) {
  821. tx_queue = &pEndpoint->TxQueue;
  822. do_pm_get = true;
  823. } else {
  824. tx_queue = &pm_queue;
  825. }
  826. /* loop until we can grab as many packets out of the queue as we can */
  827. while (Resources > 0) {
  828. int num_frags;
  829. if (do_pm_get && hif_pm_runtime_get(target->hif_dev)) {
  830. /* bus suspended, runtime resume issued */
  831. QDF_ASSERT(HTC_PACKET_QUEUE_DEPTH(pQueue) == 0);
  832. break;
  833. }
  834. pPacket = htc_packet_dequeue(tx_queue);
  835. if (!pPacket) {
  836. if (do_pm_get)
  837. hif_pm_runtime_put(target->hif_dev);
  838. break;
  839. }
  840. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  841. (" Got packet:%pK , New Queue Depth: %d\n",
  842. pPacket,
  843. HTC_PACKET_QUEUE_DEPTH(tx_queue)));
  844. /* For non-credit path the sequence number is already embedded
  845. * in the constructed HTC header
  846. */
  847. pPacket->PktInfo.AsTx.SendFlags = 0;
  848. pPacket->PktInfo.AsTx.CreditsUsed = 0;
  849. /* queue this packet into the caller's queue */
  850. HTC_PACKET_ENQUEUE(pQueue, pPacket);
  851. /*
  852. * FIX THIS:
  853. * For now, avoid calling qdf_nbuf_get_num_frags before calling
  854. * qdf_nbuf_map, because the MacOS version of qdf_nbuf_t doesn't
  855. * support qdf_nbuf_get_num_frags until after qdf_nbuf_map has
  856. * been done.
  857. * Assume that the non-data netbufs, i.e. WMI message netbufs,
  858. * consist of a single fragment.
  859. */
  860. /* WMI messages are in a single-fragment network buf */
  861. num_frags =
  862. (pPacket->PktInfo.AsTx.
  863. Flags & HTC_TX_PACKET_FLAG_FIXUP_NETBUF) ? 1 :
  864. qdf_nbuf_get_num_frags(GET_HTC_PACKET_NET_BUF_CONTEXT
  865. (pPacket));
  866. Resources -= num_frags;
  867. }
  868. if (!HTC_QUEUE_EMPTY(&pm_queue))
  869. queue_htc_pm_packets(pEndpoint, &pm_queue);
  870. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-get_htc_send_packets\n"));
  871. }
  872. /**
  873. * htc_try_send() - Send packets in a queue on an endpoint
  874. * @target: HTC target on which packets need to be sent
  875. * @pEndpoint: logical endpoint on which packets needs to be sent
  876. * @pCallersSendQueue: packet queue containing the list of packets to be sent
  877. *
  878. * Return: enum HTC_SEND_QUEUE_RESULT indicates whether the packet was queued to
  879. * be sent or the packet should be dropped by the upper layer
  880. */
  881. static enum HTC_SEND_QUEUE_RESULT htc_try_send(HTC_TARGET *target,
  882. HTC_ENDPOINT *pEndpoint,
  883. HTC_PACKET_QUEUE *pCallersSendQueue)
  884. {
  885. /* temp queue to hold packets at various stages */
  886. HTC_PACKET_QUEUE sendQueue;
  887. HTC_PACKET *pPacket;
  888. int tx_resources;
  889. int overflow;
  890. enum HTC_SEND_QUEUE_RESULT result = HTC_SEND_QUEUE_OK;
  891. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("+htc_try_send (Queue:%pK Depth:%d)\n",
  892. pCallersSendQueue,
  893. (pCallersSendQueue ==
  894. NULL) ? 0 :
  895. HTC_PACKET_QUEUE_DEPTH
  896. (pCallersSendQueue)));
  897. /* init the local send queue */
  898. INIT_HTC_PACKET_QUEUE(&sendQueue);
  899. do {
  900. /* caller didn't provide a queue, just wants us to check
  901. * queues and send
  902. */
  903. if (!pCallersSendQueue)
  904. break;
  905. if (HTC_QUEUE_EMPTY(pCallersSendQueue)) {
  906. /* empty queue */
  907. OL_ATH_HTC_PKT_ERROR_COUNT_INCR(target,
  908. HTC_PKT_Q_EMPTY);
  909. result = HTC_SEND_QUEUE_DROP;
  910. break;
  911. }
  912. if (HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue) >=
  913. pEndpoint->MaxTxQueueDepth) {
  914. /* we've already overflowed */
  915. overflow = HTC_PACKET_QUEUE_DEPTH(pCallersSendQueue);
  916. } else {
  917. /* figure out how much we will overflow by */
  918. overflow = HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue);
  919. overflow += HTC_PACKET_QUEUE_DEPTH(pCallersSendQueue);
  920. /* get how much we will overflow the TX queue by */
  921. overflow -= pEndpoint->MaxTxQueueDepth;
  922. }
  923. /* if overflow is negative or zero, we are okay */
  924. if (overflow > 0) {
  925. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  926. ("Endpoint %d, TX queue will overflow :%d , Tx Depth:%d, Max:%d\n",
  927. pEndpoint->Id, overflow,
  928. HTC_PACKET_QUEUE_DEPTH(&pEndpoint->
  929. TxQueue),
  930. pEndpoint->MaxTxQueueDepth));
  931. }
  932. if ((overflow <= 0)
  933. || (!pEndpoint->EpCallBacks.EpSendFull)) {
  934. /* all packets will fit or caller did not provide send
  935. * full indication handler
  936. * just move all of them to local sendQueue object
  937. */
  938. HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&sendQueue,
  939. pCallersSendQueue);
  940. } else {
  941. int i;
  942. int goodPkts =
  943. HTC_PACKET_QUEUE_DEPTH(pCallersSendQueue) -
  944. overflow;
  945. A_ASSERT(goodPkts >= 0);
  946. /* we have overflowed and callback is provided. Dequeue
  947. * all non-overflow packets into the sendqueue
  948. */
  949. for (i = 0; i < goodPkts; i++) {
  950. /* pop off caller's queue */
  951. pPacket = htc_packet_dequeue(pCallersSendQueue);
  952. A_ASSERT(pPacket);
  953. if (pPacket)
  954. /* insert into local queue */
  955. HTC_PACKET_ENQUEUE(&sendQueue,
  956. pPacket);
  957. }
  958. /* the caller's queue has all the packets that won't fit
  959. * walk through the caller's queue and indicate each one
  960. * to the send full handler
  961. */
  962. ITERATE_OVER_LIST_ALLOW_REMOVE(&pCallersSendQueue->
  963. QueueHead, pPacket,
  964. HTC_PACKET, ListLink) {
  965. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  966. ("Indicating overflowed TX packet: %pK\n",
  967. pPacket));
  968. /*
  969. * Remove headroom reserved for HTC_FRAME_HDR
  970. * before giving the packet back to the user via
  971. * the EpSendFull callback.
  972. */
  973. restore_tx_packet(target, pPacket);
  974. if (pEndpoint->EpCallBacks.
  975. EpSendFull(pEndpoint->EpCallBacks.pContext,
  976. pPacket) == HTC_SEND_FULL_DROP) {
  977. /* callback wants the packet dropped */
  978. INC_HTC_EP_STAT(pEndpoint, TxDropped,
  979. 1);
  980. /* leave this one in the caller's queue
  981. * for cleanup
  982. */
  983. } else {
  984. /* callback wants to keep this packet,
  985. * remove from caller's queue
  986. */
  987. HTC_PACKET_REMOVE(pCallersSendQueue,
  988. pPacket);
  989. /* put it in the send queue
  990. * add HTC_FRAME_HDR space reservation
  991. * again
  992. */
  993. qdf_nbuf_push_head
  994. (GET_HTC_PACKET_NET_BUF_CONTEXT
  995. (pPacket),
  996. sizeof(HTC_FRAME_HDR));
  997. HTC_PACKET_ENQUEUE(&sendQueue, pPacket);
  998. }
  999. }
  1000. ITERATE_END;
  1001. if (HTC_QUEUE_EMPTY(&sendQueue)) {
  1002. /* no packets made it in, caller will cleanup */
  1003. OL_ATH_HTC_PKT_ERROR_COUNT_INCR(target,
  1004. HTC_SEND_Q_EMPTY);
  1005. result = HTC_SEND_QUEUE_DROP;
  1006. break;
  1007. }
  1008. }
  1009. } while (false);
  1010. if (result != HTC_SEND_QUEUE_OK) {
  1011. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_try_send: %d\n",
  1012. result));
  1013. return result;
  1014. }
  1015. LOCK_HTC_TX(target);
  1016. if (!HTC_QUEUE_EMPTY(&sendQueue)) {
  1017. if (target->is_nodrop_pkt) {
  1018. /*
  1019. * nodrop pkts have higher priority than normal pkts,
  1020. * insert nodrop pkt to head for proper
  1021. * start/termination of test.
  1022. */
  1023. HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&pEndpoint->TxQueue,
  1024. &sendQueue);
  1025. target->is_nodrop_pkt = false;
  1026. } else {
  1027. /* transfer packets to tail */
  1028. HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&pEndpoint->TxQueue,
  1029. &sendQueue);
  1030. A_ASSERT(HTC_QUEUE_EMPTY(&sendQueue));
  1031. INIT_HTC_PACKET_QUEUE(&sendQueue);
  1032. }
  1033. }
  1034. /* increment tx processing count on entry */
  1035. if (qdf_atomic_inc_return(&pEndpoint->TxProcessCount) > 1) {
  1036. /* another thread or task is draining the TX queues on this
  1037. * endpoint that thread will reset the tx processing count when
  1038. * the queue is drained
  1039. */
  1040. qdf_atomic_dec(&pEndpoint->TxProcessCount);
  1041. UNLOCK_HTC_TX(target);
  1042. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_try_send (busy)\n"));
  1043. return HTC_SEND_QUEUE_OK;
  1044. }
  1045. /***** beyond this point only 1 thread may enter ******/
  1046. /* now drain the endpoint TX queue for transmission as long as we have
  1047. * enough transmit resources
  1048. */
  1049. if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  1050. tx_resources =
  1051. hif_get_free_queue_number(target->hif_dev,
  1052. pEndpoint->UL_PipeID);
  1053. } else {
  1054. tx_resources = 0;
  1055. }
  1056. while (true) {
  1057. if (HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue) == 0)
  1058. break;
  1059. if (pEndpoint->async_update &&
  1060. (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) &&
  1061. (!tx_resources))
  1062. break;
  1063. if (IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  1064. #if DEBUG_CREDIT
  1065. int cred = pEndpoint->TxCredits;
  1066. #endif
  1067. /* credit based mechanism provides flow control based on
  1068. * target transmit resource availability, we assume that
  1069. * the HIF layer will always have bus resources greater
  1070. * than target transmit resources
  1071. */
  1072. get_htc_send_packets_credit_based(target, pEndpoint,
  1073. &sendQueue);
  1074. #if DEBUG_CREDIT
  1075. if (ep_debug_mask & (1 << pEndpoint->Id)) {
  1076. if (cred - pEndpoint->TxCredits > 0) {
  1077. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1078. (" <HTC> Decrease EP%d %d - %d = %d credits.\n",
  1079. pEndpoint->Id, cred,
  1080. cred -
  1081. pEndpoint->TxCredits,
  1082. pEndpoint->TxCredits));
  1083. }
  1084. }
  1085. #endif
  1086. } else {
  1087. /*
  1088. * Header and payload belongs to the different fragments and
  1089. * consume 2 resource for one HTC package but USB combine into
  1090. * one transfer.And one WMI message only consumes one single
  1091. * resource.
  1092. */
  1093. if (HTC_TX_BUNDLE_ENABLED(target) && tx_resources &&
  1094. hif_get_bus_type(target->hif_dev) ==
  1095. QDF_BUS_TYPE_USB) {
  1096. if (pEndpoint->service_id ==
  1097. WMI_CONTROL_SVC)
  1098. tx_resources =
  1099. HTC_MAX_MSG_PER_BUNDLE_TX;
  1100. else
  1101. tx_resources =
  1102. (HTC_MAX_MSG_PER_BUNDLE_TX * 2);
  1103. }
  1104. /* get all the packets for this endpoint that we can for
  1105. * this pass
  1106. */
  1107. get_htc_send_packets(target, pEndpoint, &sendQueue,
  1108. tx_resources);
  1109. }
  1110. if (HTC_PACKET_QUEUE_DEPTH(&sendQueue) == 0) {
  1111. /* didn't get any packets due to a lack of resources or
  1112. * TX queue was drained
  1113. */
  1114. break;
  1115. }
  1116. if (!pEndpoint->async_update)
  1117. UNLOCK_HTC_TX(target);
  1118. /* send what we can */
  1119. if (htc_issue_packets(target, pEndpoint, &sendQueue)) {
  1120. int i;
  1121. result = HTC_SEND_QUEUE_DROP;
  1122. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1123. ("htc_issue_packets, failed status:%d put it back to head of callersSendQueue",
  1124. result));
  1125. for (i = HTC_PACKET_QUEUE_DEPTH(&sendQueue); i > 0; i--)
  1126. hif_pm_runtime_put(target->hif_dev);
  1127. if (!pEndpoint->async_update) {
  1128. LOCK_HTC_TX(target);
  1129. }
  1130. HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&pEndpoint->TxQueue,
  1131. &sendQueue);
  1132. break;
  1133. }
  1134. if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  1135. tx_resources =
  1136. hif_get_free_queue_number(target->hif_dev,
  1137. pEndpoint->UL_PipeID);
  1138. }
  1139. if (!pEndpoint->async_update) {
  1140. LOCK_HTC_TX(target);
  1141. }
  1142. }
  1143. /* done with this endpoint, we can clear the count */
  1144. qdf_atomic_init(&pEndpoint->TxProcessCount);
  1145. UNLOCK_HTC_TX(target);
  1146. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_try_send:\n"));
  1147. return HTC_SEND_QUEUE_OK;
  1148. }
  1149. #ifdef USB_HIF_SINGLE_PIPE_DATA_SCHED
  1150. static uint16_t htc_send_pkts_sched_check(HTC_HANDLE HTCHandle,
  1151. HTC_ENDPOINT_ID id)
  1152. {
  1153. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1154. HTC_ENDPOINT *pEndpoint;
  1155. HTC_ENDPOINT_ID eid;
  1156. HTC_PACKET_QUEUE *pTxQueue;
  1157. uint16_t resources;
  1158. uint16_t acQueueStatus[DATA_EP_SIZE] = { 0, 0, 0, 0 };
  1159. if (id < ENDPOINT_2 || id > ENDPOINT_5)
  1160. return 1;
  1161. for (eid = ENDPOINT_2; eid <= ENDPOINT_5; eid++) {
  1162. pEndpoint = &target->endpoint[eid];
  1163. pTxQueue = &pEndpoint->TxQueue;
  1164. if (HTC_QUEUE_EMPTY(pTxQueue))
  1165. acQueueStatus[eid - 2] = 1;
  1166. }
  1167. switch (id) {
  1168. case ENDPOINT_2: /* BE */
  1169. return acQueueStatus[0] && acQueueStatus[2]
  1170. && acQueueStatus[3];
  1171. case ENDPOINT_3: /* BK */
  1172. return acQueueStatus[0] && acQueueStatus[1] && acQueueStatus[2]
  1173. && acQueueStatus[3];
  1174. case ENDPOINT_4: /* VI */
  1175. return acQueueStatus[2] && acQueueStatus[3];
  1176. case ENDPOINT_5: /* VO */
  1177. return acQueueStatus[3];
  1178. default:
  1179. return 0;
  1180. }
  1181. }
  1182. static A_STATUS htc_send_pkts_sched_queue(HTC_TARGET *target,
  1183. HTC_PACKET_QUEUE *pPktQueue,
  1184. HTC_ENDPOINT_ID eid)
  1185. {
  1186. HTC_ENDPOINT *pEndpoint;
  1187. HTC_PACKET_QUEUE *pTxQueue;
  1188. HTC_PACKET *pPacket;
  1189. int goodPkts;
  1190. pEndpoint = &target->endpoint[eid];
  1191. pTxQueue = &pEndpoint->TxQueue;
  1192. LOCK_HTC_TX(target);
  1193. goodPkts =
  1194. pEndpoint->MaxTxQueueDepth -
  1195. HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue);
  1196. if (goodPkts > 0) {
  1197. while (!HTC_QUEUE_EMPTY(pPktQueue)) {
  1198. pPacket = htc_packet_dequeue(pPktQueue);
  1199. HTC_PACKET_ENQUEUE(pTxQueue, pPacket);
  1200. goodPkts--;
  1201. if (goodPkts <= 0)
  1202. break;
  1203. }
  1204. }
  1205. if (HTC_PACKET_QUEUE_DEPTH(pPktQueue)) {
  1206. ITERATE_OVER_LIST_ALLOW_REMOVE(&pPktQueue->QueueHead, pPacket,
  1207. HTC_PACKET, ListLink) {
  1208. if (pEndpoint->EpCallBacks.
  1209. EpSendFull(pEndpoint->EpCallBacks.pContext,
  1210. pPacket) == HTC_SEND_FULL_DROP) {
  1211. INC_HTC_EP_STAT(pEndpoint, TxDropped, 1);
  1212. } else {
  1213. HTC_PACKET_REMOVE(pPktQueue, pPacket);
  1214. HTC_PACKET_ENQUEUE(pTxQueue, pPacket);
  1215. }
  1216. }
  1217. ITERATE_END;
  1218. }
  1219. UNLOCK_HTC_TX(target);
  1220. return A_OK;
  1221. }
  1222. #endif
  1223. static inline QDF_STATUS __htc_send_pkt(HTC_HANDLE HTCHandle,
  1224. HTC_PACKET *pPacket)
  1225. {
  1226. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1227. HTC_ENDPOINT *pEndpoint;
  1228. HTC_PACKET_QUEUE pPktQueue;
  1229. qdf_nbuf_t netbuf;
  1230. HTC_FRAME_HDR *htc_hdr;
  1231. QDF_STATUS status;
  1232. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  1233. ("+__htc_send_pkt\n"));
  1234. /* get packet at head to figure out which endpoint these packets will
  1235. * go into
  1236. */
  1237. if (!pPacket) {
  1238. OL_ATH_HTC_PKT_ERROR_COUNT_INCR(target, GET_HTC_PKT_Q_FAIL);
  1239. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-__htc_send_pkt\n"));
  1240. return QDF_STATUS_E_INVAL;
  1241. }
  1242. if ((pPacket->Endpoint >= ENDPOINT_MAX) ||
  1243. (pPacket->Endpoint <= ENDPOINT_UNUSED)) {
  1244. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  1245. ("%s endpoint is invalid\n", __func__));
  1246. AR_DEBUG_ASSERT(0);
  1247. return QDF_STATUS_E_INVAL;
  1248. }
  1249. pEndpoint = &target->endpoint[pPacket->Endpoint];
  1250. if (!pEndpoint->service_id) {
  1251. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("%s service_id is invalid\n",
  1252. __func__));
  1253. return QDF_STATUS_E_INVAL;
  1254. }
  1255. #ifdef HTC_EP_STAT_PROFILING
  1256. LOCK_HTC_TX(target);
  1257. INC_HTC_EP_STAT(pEndpoint, TxPosted, 1);
  1258. UNLOCK_HTC_TX(target);
  1259. #endif
  1260. /* provide room in each packet's netbuf for the HTC frame header */
  1261. netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  1262. AR_DEBUG_ASSERT(netbuf);
  1263. if (!netbuf)
  1264. return QDF_STATUS_E_INVAL;
  1265. qdf_nbuf_push_head(netbuf, sizeof(HTC_FRAME_HDR));
  1266. /* setup HTC frame header */
  1267. htc_hdr = (HTC_FRAME_HDR *)qdf_nbuf_get_frag_vaddr(netbuf, 0);
  1268. AR_DEBUG_ASSERT(htc_hdr);
  1269. if (!htc_hdr)
  1270. return QDF_STATUS_E_INVAL;
  1271. HTC_WRITE32(htc_hdr,
  1272. SM(pPacket->ActualLength,
  1273. HTC_FRAME_HDR_PAYLOADLEN) |
  1274. SM(pPacket->Endpoint,
  1275. HTC_FRAME_HDR_ENDPOINTID));
  1276. LOCK_HTC_TX(target);
  1277. pPacket->PktInfo.AsTx.SeqNo = pEndpoint->SeqNo;
  1278. pEndpoint->SeqNo++;
  1279. HTC_WRITE32(((uint32_t *)htc_hdr) + 1,
  1280. SM(pPacket->PktInfo.AsTx.SeqNo,
  1281. HTC_FRAME_HDR_CONTROLBYTES1));
  1282. UNLOCK_HTC_TX(target);
  1283. /*
  1284. * For flow control enabled endpoints mapping is done in
  1285. * htc_issue_packets and for non flow control enabled endpoints
  1286. * its done here.
  1287. */
  1288. if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  1289. pPacket->PktInfo.AsTx.Flags |= HTC_TX_PACKET_FLAG_FIXUP_NETBUF;
  1290. status = qdf_nbuf_map(target->osdev,
  1291. GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket),
  1292. QDF_DMA_TO_DEVICE);
  1293. if (status != QDF_STATUS_SUCCESS) {
  1294. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1295. ("%s: nbuf map failed, endpoint %pK, seq_no. %d\n",
  1296. __func__, pEndpoint, pEndpoint->SeqNo));
  1297. return status;
  1298. }
  1299. }
  1300. INIT_HTC_PACKET_QUEUE_AND_ADD(&pPktQueue, pPacket);
  1301. #ifdef USB_HIF_SINGLE_PIPE_DATA_SCHED
  1302. if (!htc_send_pkts_sched_check(HTCHandle, pEndpoint->Id))
  1303. htc_send_pkts_sched_queue(HTCHandle, &pPktQueue, pEndpoint->Id);
  1304. else
  1305. htc_try_send(target, pEndpoint, &pPktQueue);
  1306. #else
  1307. htc_try_send(target, pEndpoint, &pPktQueue);
  1308. #endif
  1309. /* do completion on any packets that couldn't get in */
  1310. while (!HTC_QUEUE_EMPTY(&pPktQueue)) {
  1311. pPacket = htc_packet_dequeue(&pPktQueue);
  1312. if (HTC_STOPPING(target))
  1313. pPacket->Status = QDF_STATUS_E_CANCELED;
  1314. else
  1315. pPacket->Status = QDF_STATUS_E_RESOURCES;
  1316. send_packet_completion(target, pPacket);
  1317. }
  1318. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-__htc_send_pkt\n"));
  1319. return QDF_STATUS_SUCCESS;
  1320. }
  1321. /* HTC API - htc_send_pkt */
  1322. QDF_STATUS htc_send_pkt(HTC_HANDLE htc_handle, HTC_PACKET *htc_packet)
  1323. {
  1324. if (!htc_handle) {
  1325. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1326. ("%s: HTCHandle is NULL \n", __func__));
  1327. return QDF_STATUS_E_FAILURE;
  1328. }
  1329. if (!htc_packet) {
  1330. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1331. ("%s: pPacket is NULL \n", __func__));
  1332. return QDF_STATUS_E_FAILURE;
  1333. }
  1334. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  1335. ("+-htc_send_pkt: Enter endPointId: %d, buffer: %pK, length: %d\n",
  1336. htc_packet->Endpoint, htc_packet->pBuffer,
  1337. htc_packet->ActualLength));
  1338. return __htc_send_pkt(htc_handle, htc_packet);
  1339. }
  1340. qdf_export_symbol(htc_send_pkt);
  1341. #ifdef ATH_11AC_TXCOMPACT
  1342. /**
  1343. * htc_send_data_pkt() - send single data packet on an endpoint
  1344. * @HTCHandle: pointer to HTC handle
  1345. * @netbuf: network buffer containing the data to be sent
  1346. * @ActualLength: length of data that needs to be transmitted
  1347. *
  1348. * Return: QDF_STATUS_SUCCESS for success or an appropriate QDF_STATUS error
  1349. */
  1350. QDF_STATUS htc_send_data_pkt(HTC_HANDLE htc_hdl, qdf_nbuf_t netbuf, int ep_id,
  1351. int actual_length)
  1352. {
  1353. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_hdl);
  1354. HTC_ENDPOINT *pEndpoint;
  1355. HTC_FRAME_HDR *p_htc_hdr;
  1356. QDF_STATUS status = QDF_STATUS_SUCCESS;
  1357. int tx_resources;
  1358. uint32_t data_attr = 0;
  1359. int htc_payload_len = actual_length;
  1360. pEndpoint = &target->endpoint[ep_id];
  1361. tx_resources = hif_get_free_queue_number(target->hif_dev,
  1362. pEndpoint->UL_PipeID);
  1363. if (tx_resources < HTC_DATA_RESOURCE_THRS) {
  1364. if (pEndpoint->ul_is_polled) {
  1365. hif_send_complete_check(pEndpoint->target->hif_dev,
  1366. pEndpoint->UL_PipeID, 1);
  1367. tx_resources =
  1368. hif_get_free_queue_number(target->hif_dev,
  1369. pEndpoint->UL_PipeID);
  1370. }
  1371. if (tx_resources < HTC_DATA_MINDESC_PERPACKET)
  1372. return QDF_STATUS_E_FAILURE;
  1373. }
  1374. if (hif_pm_runtime_get(target->hif_dev))
  1375. return QDF_STATUS_E_FAILURE;
  1376. p_htc_hdr = (HTC_FRAME_HDR *)qdf_nbuf_get_frag_vaddr(netbuf, 0);
  1377. AR_DEBUG_ASSERT(p_htc_hdr);
  1378. data_attr = qdf_nbuf_data_attr_get(netbuf);
  1379. if (target->htc_hdr_length_check)
  1380. htc_payload_len = actual_length - HTC_HEADER_LEN;
  1381. HTC_WRITE32(p_htc_hdr, SM(htc_payload_len, HTC_FRAME_HDR_PAYLOADLEN)
  1382. | SM(ep_id, HTC_FRAME_HDR_ENDPOINTID));
  1383. /*
  1384. * If the HIF pipe for the data endpoint is polled rather than
  1385. * interrupt-driven, this is a good point to check whether any
  1386. * data previously sent through the HIF pipe have finished being
  1387. * sent.
  1388. * Since this may result in callbacks to htc_tx_completion_handler,
  1389. * which can take the HTC tx lock, make the hif_send_complete_check
  1390. * call before acquiring the HTC tx lock.
  1391. * Call hif_send_complete_check directly, rather than calling
  1392. * htc_send_complete_check, and call the PollTimerStart separately
  1393. * after calling hif_send_head, so the timer will be started to
  1394. * check for completion of the new outstanding download (in the
  1395. * unexpected event that other polling calls don't catch it).
  1396. */
  1397. LOCK_HTC_TX(target);
  1398. HTC_WRITE32(((uint32_t *)p_htc_hdr) + 1,
  1399. SM(pEndpoint->SeqNo, HTC_FRAME_HDR_CONTROLBYTES1));
  1400. pEndpoint->SeqNo++;
  1401. QDF_NBUF_UPDATE_TX_PKT_COUNT(netbuf, QDF_NBUF_TX_PKT_HTC);
  1402. DPTRACE(qdf_dp_trace(netbuf, QDF_DP_TRACE_HTC_PACKET_PTR_RECORD,
  1403. QDF_TRACE_DEFAULT_PDEV_ID, qdf_nbuf_data_addr(netbuf),
  1404. sizeof(qdf_nbuf_data(netbuf)), QDF_TX));
  1405. status = hif_send_head(target->hif_dev,
  1406. pEndpoint->UL_PipeID,
  1407. pEndpoint->Id, actual_length, netbuf, data_attr);
  1408. UNLOCK_HTC_TX(target);
  1409. return status;
  1410. }
  1411. #else /*ATH_11AC_TXCOMPACT */
  1412. /**
  1413. * htc_send_data_pkt() - htc_send_data_pkt
  1414. * @HTCHandle: pointer to HTC handle
  1415. * @pPacket: pointer to HTC_PACKET
  1416. * @more_data: indicates whether more data is to follow
  1417. *
  1418. * Return: QDF_STATUS_SUCCESS for success or an appropriate QDF_STATUS error
  1419. */
  1420. QDF_STATUS htc_send_data_pkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket,
  1421. uint8_t more_data)
  1422. {
  1423. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1424. HTC_ENDPOINT *pEndpoint;
  1425. HTC_FRAME_HDR *pHtcHdr;
  1426. HTC_PACKET_QUEUE sendQueue;
  1427. qdf_nbuf_t netbuf = NULL;
  1428. int tx_resources;
  1429. QDF_STATUS status = QDF_STATUS_SUCCESS;
  1430. uint32_t data_attr = 0;
  1431. if (pPacket) {
  1432. if ((pPacket->Endpoint >= ENDPOINT_MAX) ||
  1433. (pPacket->Endpoint <= ENDPOINT_UNUSED)) {
  1434. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  1435. ("%s endpoint is invalid\n", __func__));
  1436. AR_DEBUG_ASSERT(0);
  1437. return QDF_STATUS_E_INVAL;
  1438. }
  1439. pEndpoint = &target->endpoint[pPacket->Endpoint];
  1440. /* add HTC_FRAME_HDR in the initial fragment */
  1441. netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  1442. pHtcHdr = (HTC_FRAME_HDR *) qdf_nbuf_get_frag_vaddr(netbuf, 0);
  1443. AR_DEBUG_ASSERT(pHtcHdr);
  1444. HTC_WRITE32(pHtcHdr,
  1445. SM(pPacket->ActualLength,
  1446. HTC_FRAME_HDR_PAYLOADLEN) |
  1447. SM(pPacket->PktInfo.AsTx.SendFlags,
  1448. HTC_FRAME_HDR_FLAGS) |
  1449. SM(pPacket->Endpoint,
  1450. HTC_FRAME_HDR_ENDPOINTID));
  1451. /*
  1452. * If the HIF pipe for the data endpoint is polled rather than
  1453. * interrupt-driven, this is a good point to check whether any
  1454. * data previously sent through the HIF pipe have finished being
  1455. * sent. Since this may result in callbacks to
  1456. * htc_tx_completion_handler, which can take the HTC tx lock,
  1457. * make the hif_send_complete_check call before acquiring the
  1458. * HTC tx lock.
  1459. * Call hif_send_complete_check directly, rather than calling
  1460. * htc_send_complete_check, and call the PollTimerStart
  1461. * separately after calling hif_send_head, so the timer will be
  1462. * started to check for completion of the new outstanding
  1463. * download (in the unexpected event that other polling calls
  1464. * don't catch it).
  1465. */
  1466. if (pEndpoint->ul_is_polled) {
  1467. htc_send_complete_poll_timer_stop(pEndpoint);
  1468. hif_send_complete_check(pEndpoint->target->hif_dev,
  1469. pEndpoint->UL_PipeID, 0);
  1470. }
  1471. LOCK_HTC_TX(target);
  1472. pPacket->PktInfo.AsTx.SeqNo = pEndpoint->SeqNo;
  1473. pEndpoint->SeqNo++;
  1474. HTC_WRITE32(((uint32_t *) pHtcHdr) + 1,
  1475. SM(pPacket->PktInfo.AsTx.SeqNo,
  1476. HTC_FRAME_HDR_CONTROLBYTES1));
  1477. /* append new packet to pEndpoint->TxQueue */
  1478. HTC_PACKET_ENQUEUE(&pEndpoint->TxQueue, pPacket);
  1479. if (HTC_TX_BUNDLE_ENABLED(target) && (more_data)) {
  1480. UNLOCK_HTC_TX(target);
  1481. return QDF_STATUS_SUCCESS;
  1482. }
  1483. QDF_NBUF_UPDATE_TX_PKT_COUNT(netbuf, QDF_NBUF_TX_PKT_HTC);
  1484. DPTRACE(qdf_dp_trace(netbuf, QDF_DP_TRACE_HTC_PACKET_PTR_RECORD,
  1485. QDF_TRACE_DEFAULT_PDEV_ID, qdf_nbuf_data_addr(netbuf),
  1486. sizeof(qdf_nbuf_data(netbuf)), QDF_TX));
  1487. } else {
  1488. LOCK_HTC_TX(target);
  1489. pEndpoint = &target->endpoint[1];
  1490. }
  1491. /* increment tx processing count on entry */
  1492. qdf_atomic_inc(&pEndpoint->TxProcessCount);
  1493. if (qdf_atomic_read(&pEndpoint->TxProcessCount) > 1) {
  1494. /*
  1495. * Another thread or task is draining the TX queues on this
  1496. * endpoint. That thread will reset the tx processing count when
  1497. * the queue is drained.
  1498. */
  1499. qdf_atomic_dec(&pEndpoint->TxProcessCount);
  1500. UNLOCK_HTC_TX(target);
  1501. return QDF_STATUS_SUCCESS;
  1502. }
  1503. /***** beyond this point only 1 thread may enter ******/
  1504. INIT_HTC_PACKET_QUEUE(&sendQueue);
  1505. if (IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  1506. #if DEBUG_CREDIT
  1507. int cred = pEndpoint->TxCredits;
  1508. #endif
  1509. get_htc_send_packets_credit_based(target, pEndpoint,
  1510. &sendQueue);
  1511. #if DEBUG_CREDIT
  1512. if (ep_debug_mask & (1 << pEndpoint->Id)) {
  1513. if (cred - pEndpoint->TxCredits > 0) {
  1514. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1515. (" <HTC> Decrease EP%d %d - %d = %d credits.\n",
  1516. pEndpoint->Id, cred,
  1517. cred - pEndpoint->TxCredits,
  1518. pEndpoint->TxCredits));
  1519. }
  1520. }
  1521. #endif
  1522. UNLOCK_HTC_TX(target);
  1523. }
  1524. else if (HTC_TX_BUNDLE_ENABLED(target)) {
  1525. if (hif_get_bus_type(target->hif_dev) == QDF_BUS_TYPE_USB) {
  1526. if (hif_get_free_queue_number(target->hif_dev,
  1527. pEndpoint->UL_PipeID))
  1528. /*
  1529. * Header and payload belongs to the different
  1530. * fragments and consume 2 resource for one HTC
  1531. * package but USB combine into one transfer.
  1532. */
  1533. get_htc_send_packets(target, pEndpoint,
  1534. &sendQueue,
  1535. HTC_MAX_MSG_PER_BUNDLE_TX
  1536. * 2);
  1537. } else {
  1538. /* Dequeue max packets from endpoint tx queue */
  1539. get_htc_send_packets(target, pEndpoint, &sendQueue,
  1540. HTC_MAX_TX_BUNDLE_SEND_LIMIT);
  1541. }
  1542. UNLOCK_HTC_TX(target);
  1543. } else {
  1544. /*
  1545. * Now drain the endpoint TX queue for transmission as long as
  1546. * we have enough transmit resources
  1547. */
  1548. tx_resources =
  1549. hif_get_free_queue_number(target->hif_dev,
  1550. pEndpoint->UL_PipeID);
  1551. get_htc_send_packets(target, pEndpoint, &sendQueue,
  1552. tx_resources);
  1553. UNLOCK_HTC_TX(target);
  1554. }
  1555. /* send what we can */
  1556. while (true) {
  1557. if (HTC_TX_BUNDLE_ENABLED(target) &&
  1558. (HTC_PACKET_QUEUE_DEPTH(&sendQueue) >=
  1559. HTC_MIN_MSG_PER_BUNDLE) &&
  1560. (hif_get_bus_type(target->hif_dev) == QDF_BUS_TYPE_SDIO ||
  1561. hif_get_bus_type(target->hif_dev) == QDF_BUS_TYPE_USB)) {
  1562. htc_issue_packets_bundle(target, pEndpoint, &sendQueue);
  1563. }
  1564. pPacket = htc_packet_dequeue(&sendQueue);
  1565. if (!pPacket)
  1566. break;
  1567. netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  1568. LOCK_HTC_TX(target);
  1569. /* store in look up queue to match completions */
  1570. HTC_PACKET_ENQUEUE(&pEndpoint->TxLookupQueue, pPacket);
  1571. INC_HTC_EP_STAT(pEndpoint, TxIssued, 1);
  1572. pEndpoint->ul_outstanding_cnt++;
  1573. UNLOCK_HTC_TX(target);
  1574. status = hif_send_head(target->hif_dev,
  1575. pEndpoint->UL_PipeID,
  1576. pEndpoint->Id,
  1577. HTC_HDR_LENGTH + pPacket->ActualLength,
  1578. netbuf, data_attr);
  1579. #if DEBUG_BUNDLE
  1580. qdf_print(" Send single EP%d buffer size:0x%x, total:0x%x.",
  1581. pEndpoint->Id,
  1582. pEndpoint->TxCreditSize,
  1583. HTC_HDR_LENGTH + pPacket->ActualLength);
  1584. #endif
  1585. htc_issue_tx_bundle_stats_inc(target);
  1586. if (qdf_unlikely(QDF_IS_STATUS_ERROR(status))) {
  1587. LOCK_HTC_TX(target);
  1588. pEndpoint->ul_outstanding_cnt--;
  1589. /* remove this packet from the tx completion queue */
  1590. HTC_PACKET_REMOVE(&pEndpoint->TxLookupQueue, pPacket);
  1591. /*
  1592. * Don't bother reclaiming credits - HTC flow control
  1593. * is not applicable to tx data.
  1594. * In LL systems, there is no download flow control,
  1595. * since there's virtually no download delay.
  1596. * In HL systems, the txrx SW explicitly performs the
  1597. * tx flow control.
  1598. */
  1599. /* pEndpoint->TxCredits +=
  1600. * pPacket->PktInfo.AsTx.CreditsUsed;
  1601. */
  1602. /* put this frame back at the front of the sendQueue */
  1603. HTC_PACKET_ENQUEUE_TO_HEAD(&sendQueue, pPacket);
  1604. /* put the sendQueue back at the front of
  1605. * pEndpoint->TxQueue
  1606. */
  1607. HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&pEndpoint->TxQueue,
  1608. &sendQueue);
  1609. UNLOCK_HTC_TX(target);
  1610. break; /* still need to reset TxProcessCount */
  1611. }
  1612. }
  1613. /* done with this endpoint, we can clear the count */
  1614. qdf_atomic_init(&pEndpoint->TxProcessCount);
  1615. if (pEndpoint->ul_is_polled) {
  1616. /*
  1617. * Start a cleanup timer to poll for download completion.
  1618. * The download completion should be noticed promptly from
  1619. * other polling calls, but the timer provides a safety net
  1620. * in case other polling calls don't occur as expected.
  1621. */
  1622. htc_send_complete_poll_timer_start(pEndpoint);
  1623. }
  1624. return status;
  1625. }
  1626. #endif /*ATH_11AC_TXCOMPACT */
  1627. qdf_export_symbol(htc_send_data_pkt);
  1628. /*
  1629. * In the adapted HIF layer, qdf_nbuf_t are passed between HIF and HTC,
  1630. * since upper layers expects HTC_PACKET containers we use the completed netbuf
  1631. * and lookup its corresponding HTC packet buffer from a lookup list.
  1632. * This is extra overhead that can be fixed by re-aligning HIF interfaces
  1633. * with HTC.
  1634. *
  1635. */
  1636. static HTC_PACKET *htc_lookup_tx_packet(HTC_TARGET *target,
  1637. HTC_ENDPOINT *pEndpoint,
  1638. qdf_nbuf_t netbuf)
  1639. {
  1640. HTC_PACKET *pPacket = NULL;
  1641. HTC_PACKET *pFoundPacket = NULL;
  1642. HTC_PACKET_QUEUE lookupQueue;
  1643. INIT_HTC_PACKET_QUEUE(&lookupQueue);
  1644. LOCK_HTC_EP_TX_LOOKUP(pEndpoint);
  1645. LOCK_HTC_TX(target);
  1646. /* mark that HIF has indicated the send complete for another packet */
  1647. pEndpoint->ul_outstanding_cnt--;
  1648. /* Dequeue first packet directly because of in-order completion */
  1649. pPacket = htc_packet_dequeue(&pEndpoint->TxLookupQueue);
  1650. if (qdf_unlikely(!pPacket)) {
  1651. UNLOCK_HTC_TX(target);
  1652. UNLOCK_HTC_EP_TX_LOOKUP(pEndpoint);
  1653. return NULL;
  1654. }
  1655. if (netbuf == (qdf_nbuf_t) GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket)) {
  1656. UNLOCK_HTC_TX(target);
  1657. UNLOCK_HTC_EP_TX_LOOKUP(pEndpoint);
  1658. return pPacket;
  1659. }
  1660. HTC_PACKET_ENQUEUE(&lookupQueue, pPacket);
  1661. /*
  1662. * Move TX lookup queue to temp queue because most of packets that are
  1663. * not index 0 are not top 10 packets.
  1664. */
  1665. HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&lookupQueue,
  1666. &pEndpoint->TxLookupQueue);
  1667. ITERATE_OVER_LIST_ALLOW_REMOVE(&lookupQueue.QueueHead, pPacket,
  1668. HTC_PACKET, ListLink) {
  1669. if (!pPacket) {
  1670. pFoundPacket = pPacket;
  1671. break;
  1672. }
  1673. /* check for removal */
  1674. if (netbuf ==
  1675. (qdf_nbuf_t) GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket)) {
  1676. /* found it */
  1677. HTC_PACKET_REMOVE(&lookupQueue, pPacket);
  1678. pFoundPacket = pPacket;
  1679. break;
  1680. }
  1681. }
  1682. ITERATE_END;
  1683. HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&pEndpoint->TxLookupQueue,
  1684. &lookupQueue);
  1685. UNLOCK_HTC_TX(target);
  1686. UNLOCK_HTC_EP_TX_LOOKUP(pEndpoint);
  1687. return pFoundPacket;
  1688. }
  1689. /**
  1690. * htc_tx_completion_handler() - htc tx completion handler
  1691. * @Context: pointer to HTC_TARGET structure
  1692. * @netbuf: pointer to netbuf for which completion handler is being called
  1693. * @EpID: end point Id on which the packet was sent
  1694. * @toeplitz_hash_result: toeplitz hash result
  1695. *
  1696. * Return: QDF_STATUS_SUCCESS for success or an appropriate QDF_STATUS error
  1697. */
  1698. QDF_STATUS htc_tx_completion_handler(void *Context,
  1699. qdf_nbuf_t netbuf, unsigned int EpID,
  1700. uint32_t toeplitz_hash_result)
  1701. {
  1702. HTC_TARGET *target = (HTC_TARGET *) Context;
  1703. HTC_ENDPOINT *pEndpoint;
  1704. HTC_PACKET *pPacket;
  1705. #ifdef USB_HIF_SINGLE_PIPE_DATA_SCHED
  1706. HTC_ENDPOINT_ID eid[DATA_EP_SIZE] = { ENDPOINT_5, ENDPOINT_4,
  1707. ENDPOINT_2, ENDPOINT_3 };
  1708. int epidIdx;
  1709. uint16_t resourcesThresh[DATA_EP_SIZE]; /* urb resources */
  1710. uint16_t resources;
  1711. uint16_t resourcesMax;
  1712. #endif
  1713. pEndpoint = &target->endpoint[EpID];
  1714. target->TX_comp_cnt++;
  1715. do {
  1716. pPacket = htc_lookup_tx_packet(target, pEndpoint, netbuf);
  1717. if (!pPacket) {
  1718. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1719. ("HTC TX lookup failed!\n"));
  1720. /* may have already been flushed and freed */
  1721. netbuf = NULL;
  1722. break;
  1723. }
  1724. if (pPacket->PktInfo.AsTx.Tag != HTC_TX_PACKET_TAG_AUTO_PM)
  1725. hif_pm_runtime_put(target->hif_dev);
  1726. if (pPacket->PktInfo.AsTx.Tag == HTC_TX_PACKET_TAG_BUNDLED) {
  1727. HTC_PACKET *pPacketTemp;
  1728. HTC_PACKET_QUEUE *pQueueSave =
  1729. (HTC_PACKET_QUEUE *) pPacket->pContext;
  1730. HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pQueueSave,
  1731. pPacketTemp) {
  1732. pPacket->Status = QDF_STATUS_SUCCESS;
  1733. send_packet_completion(target, pPacketTemp);
  1734. }
  1735. HTC_PACKET_QUEUE_ITERATE_END;
  1736. free_htc_bundle_packet(target, pPacket);
  1737. if (hif_get_bus_type(target->hif_dev) ==
  1738. QDF_BUS_TYPE_USB) {
  1739. if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint))
  1740. htc_try_send(target, pEndpoint, NULL);
  1741. }
  1742. return QDF_STATUS_SUCCESS;
  1743. }
  1744. /* will be giving this buffer back to upper layers */
  1745. netbuf = NULL;
  1746. pPacket->Status = QDF_STATUS_SUCCESS;
  1747. send_packet_completion(target, pPacket);
  1748. } while (false);
  1749. if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  1750. /* note: when using TX credit flow, the re-checking of queues
  1751. * happens when credits flow back from the target. In the non-TX
  1752. * credit case, we recheck after the packet completes
  1753. */
  1754. if ((qdf_atomic_read(&pEndpoint->TxProcessCount) == 0) ||
  1755. (!pEndpoint->async_update)) {
  1756. htc_try_send(target, pEndpoint, NULL);
  1757. }
  1758. }
  1759. return QDF_STATUS_SUCCESS;
  1760. }
  1761. #ifdef WLAN_FEATURE_FASTPATH
  1762. /**
  1763. * htc_ctrl_msg_cmpl(): checks for tx completion for the endpoint specified
  1764. * @HTC_HANDLE : pointer to the htc target context
  1765. * @htc_ep_id : end point id
  1766. *
  1767. * checks HTC tx completion
  1768. *
  1769. * Return: none
  1770. */
  1771. void htc_ctrl_msg_cmpl(HTC_HANDLE htc_pdev, HTC_ENDPOINT_ID htc_ep_id)
  1772. {
  1773. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_pdev);
  1774. HTC_ENDPOINT *pendpoint = &target->endpoint[htc_ep_id];
  1775. htc_send_complete_check(pendpoint, 1);
  1776. }
  1777. qdf_export_symbol(htc_ctrl_msg_cmpl);
  1778. #endif
  1779. /* callback when TX resources become available */
  1780. void htc_tx_resource_avail_handler(void *context, uint8_t pipeID)
  1781. {
  1782. int i;
  1783. HTC_TARGET *target = (HTC_TARGET *) context;
  1784. HTC_ENDPOINT *pEndpoint = NULL;
  1785. for (i = 0; i < ENDPOINT_MAX; i++) {
  1786. pEndpoint = &target->endpoint[i];
  1787. if (pEndpoint->service_id != 0) {
  1788. if (pEndpoint->UL_PipeID == pipeID)
  1789. break;
  1790. }
  1791. }
  1792. if (i >= ENDPOINT_MAX) {
  1793. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1794. ("Invalid pipe indicated for TX resource avail : %d!\n",
  1795. pipeID));
  1796. return;
  1797. }
  1798. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  1799. ("HIF indicated more resources for pipe:%d\n",
  1800. pipeID));
  1801. htc_try_send(target, pEndpoint, NULL);
  1802. }
  1803. #ifdef FEATURE_RUNTIME_PM
  1804. /**
  1805. * htc_kick_queues(): resumes tx transactions of suspended endpoints
  1806. * @context: pointer to the htc target context
  1807. *
  1808. * Iterates through the enpoints and provides a context to empty queues
  1809. * int the hif layer when they are stalled due to runtime suspend.
  1810. *
  1811. * Return: none
  1812. */
  1813. void htc_kick_queues(void *context)
  1814. {
  1815. int i;
  1816. HTC_TARGET *target = (HTC_TARGET *)context;
  1817. HTC_ENDPOINT *endpoint = NULL;
  1818. for (i = 0; i < ENDPOINT_MAX; i++) {
  1819. endpoint = &target->endpoint[i];
  1820. if (endpoint->service_id == 0)
  1821. continue;
  1822. if (endpoint->EpCallBacks.ep_resume_tx_queue)
  1823. endpoint->EpCallBacks.ep_resume_tx_queue(
  1824. endpoint->EpCallBacks.pContext);
  1825. htc_try_send(target, endpoint, NULL);
  1826. }
  1827. hif_fastpath_resume(target->hif_dev);
  1828. }
  1829. #endif
  1830. /* flush endpoint TX queue */
  1831. void htc_flush_endpoint_tx(HTC_TARGET *target, HTC_ENDPOINT *pEndpoint,
  1832. HTC_TX_TAG Tag)
  1833. {
  1834. HTC_PACKET *pPacket;
  1835. LOCK_HTC_TX(target);
  1836. while (HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue)) {
  1837. pPacket = htc_packet_dequeue(&pEndpoint->TxQueue);
  1838. if (pPacket) {
  1839. /* let the sender know the packet was not delivered */
  1840. pPacket->Status = QDF_STATUS_E_CANCELED;
  1841. send_packet_completion(target, pPacket);
  1842. }
  1843. }
  1844. UNLOCK_HTC_TX(target);
  1845. }
  1846. /* flush pending entries in endpoint TX Lookup queue */
  1847. void htc_flush_endpoint_txlookupQ(HTC_TARGET *target,
  1848. HTC_ENDPOINT_ID endpoint_id,
  1849. bool call_ep_callback)
  1850. {
  1851. HTC_PACKET *packet;
  1852. HTC_ENDPOINT *endpoint;
  1853. endpoint = &target->endpoint[endpoint_id];
  1854. if (!endpoint && endpoint->service_id == 0)
  1855. return;
  1856. LOCK_HTC_TX(target);
  1857. while (HTC_PACKET_QUEUE_DEPTH(&endpoint->TxLookupQueue)) {
  1858. packet = htc_packet_dequeue(&endpoint->TxLookupQueue);
  1859. if (packet) {
  1860. if (call_ep_callback == true) {
  1861. packet->Status = QDF_STATUS_E_CANCELED;
  1862. send_packet_completion(target, packet);
  1863. } else {
  1864. qdf_mem_free(packet);
  1865. }
  1866. }
  1867. }
  1868. UNLOCK_HTC_TX(target);
  1869. }
  1870. /* HTC API to flush an endpoint's TX queue*/
  1871. void htc_flush_endpoint(HTC_HANDLE HTCHandle, HTC_ENDPOINT_ID Endpoint,
  1872. HTC_TX_TAG Tag)
  1873. {
  1874. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1875. HTC_ENDPOINT *pEndpoint = &target->endpoint[Endpoint];
  1876. if (pEndpoint->service_id == 0) {
  1877. AR_DEBUG_ASSERT(false);
  1878. /* not in use.. */
  1879. return;
  1880. }
  1881. htc_flush_endpoint_tx(target, pEndpoint, Tag);
  1882. }
  1883. /* HTC API to indicate activity to the credit distribution function */
  1884. void htc_indicate_activity_change(HTC_HANDLE HTCHandle,
  1885. HTC_ENDPOINT_ID Endpoint, bool Active)
  1886. {
  1887. /* TODO */
  1888. }
  1889. bool htc_is_endpoint_active(HTC_HANDLE HTCHandle, HTC_ENDPOINT_ID Endpoint)
  1890. {
  1891. return true;
  1892. }
  1893. void htc_set_nodrop_pkt(HTC_HANDLE HTCHandle, A_BOOL isNodropPkt)
  1894. {
  1895. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1896. target->is_nodrop_pkt = isNodropPkt;
  1897. }
  1898. void htc_enable_hdr_length_check(HTC_HANDLE htc_hdl, bool htc_hdr_length_check)
  1899. {
  1900. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_hdl);
  1901. target->htc_hdr_length_check = htc_hdr_length_check;
  1902. }
  1903. /**
  1904. * htc_process_credit_rpt() - process credit report, call distribution function
  1905. * @target: pointer to HTC_TARGET
  1906. * @pRpt: pointer to HTC_CREDIT_REPORT
  1907. * @NumEntries: number of entries in credit report
  1908. * @FromEndpoint: endpoint for which credit report is received
  1909. *
  1910. * Return: A_OK for success or an appropriate A_STATUS error
  1911. */
  1912. void htc_process_credit_rpt(HTC_TARGET *target, HTC_CREDIT_REPORT *pRpt,
  1913. int NumEntries, HTC_ENDPOINT_ID FromEndpoint)
  1914. {
  1915. int i;
  1916. HTC_ENDPOINT *pEndpoint;
  1917. int totalCredits = 0;
  1918. uint8_t rpt_credits, rpt_ep_id;
  1919. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  1920. ("+htc_process_credit_rpt, Credit Report Entries:%d\n",
  1921. NumEntries));
  1922. /* lock out TX while we update credits */
  1923. LOCK_HTC_TX(target);
  1924. for (i = 0; i < NumEntries; i++, pRpt++) {
  1925. rpt_ep_id = HTC_GET_FIELD(pRpt, HTC_CREDIT_REPORT, ENDPOINTID);
  1926. if (rpt_ep_id >= ENDPOINT_MAX) {
  1927. AR_DEBUG_ASSERT(false);
  1928. break;
  1929. }
  1930. rpt_credits = HTC_GET_FIELD(pRpt, HTC_CREDIT_REPORT, CREDITS);
  1931. pEndpoint = &target->endpoint[rpt_ep_id];
  1932. #if DEBUG_CREDIT
  1933. if (ep_debug_mask & (1 << pEndpoint->Id)) {
  1934. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1935. (" <HTC> Increase EP%d %d + %d = %d credits\n",
  1936. rpt_ep_id, pEndpoint->TxCredits,
  1937. rpt_credits,
  1938. pEndpoint->TxCredits + rpt_credits));
  1939. }
  1940. #endif
  1941. #ifdef HTC_EP_STAT_PROFILING
  1942. INC_HTC_EP_STAT(pEndpoint, TxCreditRpts, 1);
  1943. INC_HTC_EP_STAT(pEndpoint, TxCreditsReturned, rpt_credits);
  1944. if (FromEndpoint == rpt_ep_id) {
  1945. /* this credit report arrived on the same endpoint
  1946. * indicating it arrived in an RX packet
  1947. */
  1948. INC_HTC_EP_STAT(pEndpoint, TxCreditsFromRx,
  1949. rpt_credits);
  1950. INC_HTC_EP_STAT(pEndpoint, TxCreditRptsFromRx, 1);
  1951. } else if (FromEndpoint == ENDPOINT_0) {
  1952. /* this credit arrived on endpoint 0 as a NULL msg */
  1953. INC_HTC_EP_STAT(pEndpoint, TxCreditsFromEp0,
  1954. rpt_credits);
  1955. INC_HTC_EP_STAT(pEndpoint, TxCreditRptsFromEp0, 1);
  1956. } else {
  1957. /* arrived on another endpoint */
  1958. INC_HTC_EP_STAT(pEndpoint, TxCreditsFromOther,
  1959. rpt_credits);
  1960. INC_HTC_EP_STAT(pEndpoint, TxCreditRptsFromOther, 1);
  1961. }
  1962. #endif
  1963. if (pEndpoint->service_id == WMI_CONTROL_SVC) {
  1964. htc_credit_record(HTC_PROCESS_CREDIT_REPORT,
  1965. pEndpoint->TxCredits + rpt_credits,
  1966. HTC_PACKET_QUEUE_DEPTH(&pEndpoint->
  1967. TxQueue));
  1968. }
  1969. pEndpoint->TxCredits += rpt_credits;
  1970. if (pEndpoint->TxCredits
  1971. && HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue)) {
  1972. UNLOCK_HTC_TX(target);
  1973. #ifdef ATH_11AC_TXCOMPACT
  1974. htc_try_send(target, pEndpoint, NULL);
  1975. #else
  1976. if (pEndpoint->service_id == HTT_DATA_MSG_SVC)
  1977. htc_send_data_pkt(target, NULL, 0);
  1978. else
  1979. htc_try_send(target, pEndpoint, NULL);
  1980. #endif
  1981. LOCK_HTC_TX(target);
  1982. }
  1983. totalCredits += rpt_credits;
  1984. }
  1985. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  1986. (" Report indicated %d credits to distribute\n",
  1987. totalCredits));
  1988. UNLOCK_HTC_TX(target);
  1989. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_process_credit_rpt\n"));
  1990. }
  1991. /* function to fetch stats from htc layer*/
  1992. struct ol_ath_htc_stats *ieee80211_ioctl_get_htc_stats(HTC_HANDLE HTCHandle)
  1993. {
  1994. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1995. return &(target->htc_pkt_stats);
  1996. }