htc_send.c 62 KB

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