htc_send.c 63 KB

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