htc_send.c 64 KB

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