htc_send.c 65 KB

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