htc_send.c 63 KB

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