htc_send.c 61 KB

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