htc_send.c 64 KB

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