htc_send.c 61 KB

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