htc_send.c 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281
  1. /*
  2. * Copyright (c) 2013-2018 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. qdf_nbuf_t netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  172. if (pPacket->PktInfo.AsTx.Flags & HTC_TX_PACKET_FLAG_FIXUP_NETBUF) {
  173. qdf_nbuf_unmap(target->osdev, netbuf, QDF_DMA_TO_DEVICE);
  174. pPacket->PktInfo.AsTx.Flags &= ~HTC_TX_PACKET_FLAG_FIXUP_NETBUF;
  175. }
  176. qdf_nbuf_pull_head(netbuf, sizeof(HTC_FRAME_HDR));
  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. bool rt_put = false;
  524. bus_type = hif_get_bus_type(target->hif_dev);
  525. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  526. ("+htc_issue_packets: Queue: %pK, Pkts %d\n", pPktQueue,
  527. HTC_PACKET_QUEUE_DEPTH(pPktQueue)));
  528. while (true) {
  529. if (HTC_TX_BUNDLE_ENABLED(target) &&
  530. HTC_PACKET_QUEUE_DEPTH(pPktQueue) >=
  531. HTC_MIN_MSG_PER_BUNDLE) {
  532. switch (bus_type) {
  533. case QDF_BUS_TYPE_SDIO:
  534. if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint))
  535. break;
  536. case QDF_BUS_TYPE_USB:
  537. htc_issue_packets_bundle(target,
  538. pEndpoint,
  539. pPktQueue);
  540. break;
  541. default:
  542. break;
  543. }
  544. }
  545. /* if not bundling or there was a packet that could not be
  546. * placed in a bundle, and send it by normal way
  547. */
  548. pPacket = htc_packet_dequeue(pPktQueue);
  549. if (NULL == pPacket) {
  550. /* local queue is fully drained */
  551. break;
  552. }
  553. netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  554. AR_DEBUG_ASSERT(netbuf);
  555. /* Non-credit enabled endpoints have been mapped and setup by
  556. * now, so no need to revisit the HTC headers
  557. */
  558. if (IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  559. payloadLen = pPacket->ActualLength;
  560. /* setup HTC frame header */
  561. pHtcHdr = (HTC_FRAME_HDR *)
  562. qdf_nbuf_get_frag_vaddr(netbuf, 0);
  563. AR_DEBUG_ASSERT(pHtcHdr);
  564. HTC_WRITE32(pHtcHdr,
  565. SM(payloadLen,
  566. HTC_FRAME_HDR_PAYLOADLEN) |
  567. SM(pPacket->PktInfo.AsTx.SendFlags,
  568. HTC_FRAME_HDR_FLAGS) |
  569. SM(pPacket->Endpoint,
  570. HTC_FRAME_HDR_ENDPOINTID));
  571. HTC_WRITE32(((uint32_t *) pHtcHdr) + 1,
  572. SM(pPacket->PktInfo.AsTx.SeqNo,
  573. HTC_FRAME_HDR_CONTROLBYTES1));
  574. /*
  575. * Now that the HTC frame header has been added, the
  576. * netbuf can be mapped. This only applies to non-data
  577. * frames, since data frames were already mapped as they
  578. * entered into the driver.
  579. */
  580. pPacket->PktInfo.AsTx.Flags |=
  581. HTC_TX_PACKET_FLAG_FIXUP_NETBUF;
  582. ret = qdf_nbuf_map(target->osdev,
  583. GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket),
  584. QDF_DMA_TO_DEVICE);
  585. if (ret != QDF_STATUS_SUCCESS) {
  586. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  587. ("%s nbuf Map Fail Endpnt %pK\n",
  588. __func__, pEndpoint));
  589. HTC_PACKET_ENQUEUE_TO_HEAD(pPktQueue, pPacket);
  590. status = QDF_STATUS_E_FAILURE;
  591. break;
  592. }
  593. }
  594. if (!pEndpoint->async_update) {
  595. LOCK_HTC_TX(target);
  596. }
  597. /* store in look up queue to match completions */
  598. HTC_PACKET_ENQUEUE(&pEndpoint->TxLookupQueue, pPacket);
  599. INC_HTC_EP_STAT(pEndpoint, TxIssued, 1);
  600. pEndpoint->ul_outstanding_cnt++;
  601. if (!pEndpoint->async_update) {
  602. UNLOCK_HTC_TX(target);
  603. hif_send_complete_check(target->hif_dev,
  604. pEndpoint->UL_PipeID, false);
  605. }
  606. htc_packet_set_magic_cookie(pPacket, HTC_PACKET_MAGIC_COOKIE);
  607. /*
  608. * For HTT messages without a response from fw,
  609. * do the runtime put here.
  610. * otherwise runtime put will be done when the fw response comes
  611. */
  612. if (pPacket->PktInfo.AsTx.Tag == HTC_TX_PACKET_TAG_RUNTIME_PUT)
  613. rt_put = true;
  614. #if DEBUG_BUNDLE
  615. qdf_print(" Send single EP%d buffer size:0x%x, total:0x%x.\n",
  616. pEndpoint->Id,
  617. pEndpoint->TxCreditSize,
  618. HTC_HDR_LENGTH + pPacket->ActualLength);
  619. #endif
  620. status = hif_send_head(target->hif_dev,
  621. pEndpoint->UL_PipeID, pEndpoint->Id,
  622. HTC_HDR_LENGTH + pPacket->ActualLength,
  623. netbuf, data_attr);
  624. htc_issue_tx_bundle_stats_inc(target);
  625. target->ce_send_cnt++;
  626. if (qdf_unlikely(QDF_IS_STATUS_ERROR(status))) {
  627. if (status != QDF_STATUS_E_RESOURCES) {
  628. /* TODO : if more than 1 endpoint maps to the
  629. * same PipeID it is possible to run out of
  630. * resources in the HIF layer. Don't emit the
  631. * error
  632. */
  633. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  634. ("hif_send Failed status:%d\n",
  635. status));
  636. }
  637. qdf_nbuf_unmap(target->osdev,
  638. GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket),
  639. QDF_DMA_TO_DEVICE);
  640. if (!pEndpoint->async_update) {
  641. LOCK_HTC_TX(target);
  642. }
  643. target->ce_send_cnt--;
  644. pEndpoint->ul_outstanding_cnt--;
  645. HTC_PACKET_REMOVE(&pEndpoint->TxLookupQueue, pPacket);
  646. /* reclaim credits */
  647. pEndpoint->TxCredits +=
  648. pPacket->PktInfo.AsTx.CreditsUsed;
  649. htc_packet_set_magic_cookie(pPacket, 0);
  650. /* put it back into the callers queue */
  651. HTC_PACKET_ENQUEUE_TO_HEAD(pPktQueue, pPacket);
  652. if (!pEndpoint->async_update) {
  653. UNLOCK_HTC_TX(target);
  654. }
  655. break;
  656. }
  657. if (rt_put) {
  658. hif_pm_runtime_put(target->hif_dev);
  659. rt_put = false;
  660. }
  661. }
  662. if (qdf_unlikely(QDF_IS_STATUS_ERROR(status))) {
  663. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  664. ("htc_issue_packets, failed pkt:0x%pK status:%d",
  665. pPacket, status));
  666. }
  667. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_issue_packets\n"));
  668. return status;
  669. }
  670. #ifdef FEATURE_RUNTIME_PM
  671. /**
  672. * extract_htc_pm_packtes(): move pm packets from endpoint into queue
  673. * @endpoint: which enpoint to extract packets from
  674. * @queue: a queue to store extracted packets in.
  675. *
  676. * remove pm packets from the endpoint's tx queue.
  677. * queue them into a queue
  678. */
  679. static void extract_htc_pm_packets(HTC_ENDPOINT *endpoint,
  680. HTC_PACKET_QUEUE *queue)
  681. {
  682. HTC_PACKET *packet;
  683. /* only WMI endpoint has power management packets */
  684. if (endpoint->service_id != WMI_CONTROL_SVC)
  685. return;
  686. ITERATE_OVER_LIST_ALLOW_REMOVE(&endpoint->TxQueue.QueueHead, packet,
  687. HTC_PACKET, ListLink) {
  688. if (packet->PktInfo.AsTx.Tag == HTC_TX_PACKET_TAG_AUTO_PM) {
  689. HTC_PACKET_REMOVE(&endpoint->TxQueue, packet);
  690. HTC_PACKET_ENQUEUE(queue, packet);
  691. }
  692. } ITERATE_END
  693. }
  694. /**
  695. * queue_htc_pm_packets(): queue pm packets with priority
  696. * @endpoint: enpoint to queue packets to
  697. * @queue: queue of pm packets to enque
  698. *
  699. * suspend resume packets get special treatment & priority.
  700. * need to queue them at the front of the queue.
  701. */
  702. static void queue_htc_pm_packets(HTC_ENDPOINT *endpoint,
  703. HTC_PACKET_QUEUE *queue)
  704. {
  705. if (endpoint->service_id != WMI_CONTROL_SVC)
  706. return;
  707. HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&endpoint->TxQueue, queue);
  708. }
  709. #else
  710. static void extract_htc_pm_packets(HTC_ENDPOINT *endpoint,
  711. HTC_PACKET_QUEUE *queue)
  712. {}
  713. static void queue_htc_pm_packets(HTC_ENDPOINT *endpoint,
  714. HTC_PACKET_QUEUE *queue)
  715. {}
  716. #endif
  717. /**
  718. * get_htc_send_packets_credit_based() - get packets based on available credits
  719. * @target: HTC target on which packets need to be sent
  720. * @pEndpoint: logical endpoint on which packets needs to be sent
  721. * @pQueue: HTC packet queue containing the list of packets to be sent
  722. *
  723. * Get HTC send packets from TX queue on an endpoint based on available credits.
  724. * The function moves the packets from TX queue of the endpoint to pQueue.
  725. *
  726. * Return: None
  727. */
  728. static void get_htc_send_packets_credit_based(HTC_TARGET *target,
  729. HTC_ENDPOINT *pEndpoint,
  730. HTC_PACKET_QUEUE *pQueue)
  731. {
  732. int creditsRequired;
  733. int remainder;
  734. uint8_t sendFlags;
  735. HTC_PACKET *pPacket;
  736. unsigned int transferLength;
  737. HTC_PACKET_QUEUE *tx_queue;
  738. HTC_PACKET_QUEUE pm_queue;
  739. bool do_pm_get = false;
  740. /*** NOTE : the TX lock is held when this function is called ***/
  741. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  742. ("+get_htc_send_packets_credit_based\n"));
  743. INIT_HTC_PACKET_QUEUE(&pm_queue);
  744. extract_htc_pm_packets(pEndpoint, &pm_queue);
  745. if (HTC_QUEUE_EMPTY(&pm_queue)) {
  746. tx_queue = &pEndpoint->TxQueue;
  747. do_pm_get = true;
  748. } else {
  749. tx_queue = &pm_queue;
  750. }
  751. /* loop until we can grab as many packets out of the queue as we can */
  752. while (true) {
  753. if (do_pm_get && hif_pm_runtime_get(target->hif_dev)) {
  754. /* bus suspended, runtime resume issued */
  755. QDF_ASSERT(HTC_PACKET_QUEUE_DEPTH(pQueue) == 0);
  756. break;
  757. }
  758. sendFlags = 0;
  759. /* get packet at head, but don't remove it */
  760. pPacket = htc_get_pkt_at_head(tx_queue);
  761. if (pPacket == NULL) {
  762. if (do_pm_get)
  763. hif_pm_runtime_put(target->hif_dev);
  764. break;
  765. }
  766. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  767. (" Got head packet:%pK , Queue Depth: %d\n",
  768. pPacket,
  769. HTC_PACKET_QUEUE_DEPTH(tx_queue)));
  770. transferLength = pPacket->ActualLength + HTC_HDR_LENGTH;
  771. if (transferLength <= pEndpoint->TxCreditSize) {
  772. creditsRequired = 1;
  773. } else {
  774. /* figure out how many credits this message requires */
  775. creditsRequired =
  776. transferLength / pEndpoint->TxCreditSize;
  777. remainder = transferLength % pEndpoint->TxCreditSize;
  778. if (remainder)
  779. creditsRequired++;
  780. }
  781. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  782. (" Credits Required:%d Got:%d\n",
  783. creditsRequired, pEndpoint->TxCredits));
  784. if (pEndpoint->Id == ENDPOINT_0) {
  785. /*
  786. * endpoint 0 is special, it always has a credit and
  787. * does not require credit based flow control
  788. */
  789. creditsRequired = 0;
  790. } else {
  791. if (pEndpoint->TxCredits < creditsRequired) {
  792. #if DEBUG_CREDIT
  793. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  794. ("EP%d,No Credit now.%d < %d\n",
  795. pEndpoint->Id,
  796. pEndpoint->TxCredits,
  797. creditsRequired));
  798. #endif
  799. if (do_pm_get)
  800. hif_pm_runtime_put(target->hif_dev);
  801. break;
  802. }
  803. pEndpoint->TxCredits -= creditsRequired;
  804. INC_HTC_EP_STAT(pEndpoint, TxCreditsConsummed,
  805. creditsRequired);
  806. /* check if we need credits back from the target */
  807. if (pEndpoint->TxCredits <=
  808. pEndpoint->TxCreditsPerMaxMsg) {
  809. /* tell the target we need credits ASAP! */
  810. sendFlags |= HTC_FLAGS_NEED_CREDIT_UPDATE;
  811. if (pEndpoint->service_id == WMI_CONTROL_SVC) {
  812. LOCK_HTC_CREDIT(target);
  813. htc_credit_record(HTC_REQUEST_CREDIT,
  814. pEndpoint->TxCredits,
  815. HTC_PACKET_QUEUE_DEPTH
  816. (tx_queue));
  817. UNLOCK_HTC_CREDIT(target);
  818. }
  819. INC_HTC_EP_STAT(pEndpoint,
  820. TxCreditLowIndications, 1);
  821. #if DEBUG_CREDIT
  822. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  823. (" EP%d Needs Credits\n",
  824. pEndpoint->Id));
  825. #endif
  826. }
  827. }
  828. /* now we can fully dequeue */
  829. pPacket = htc_packet_dequeue(tx_queue);
  830. if (pPacket) {
  831. /* save the number of credits this packet consumed */
  832. pPacket->PktInfo.AsTx.CreditsUsed = creditsRequired;
  833. /* save send flags */
  834. pPacket->PktInfo.AsTx.SendFlags = sendFlags;
  835. /* queue this packet into the caller's queue */
  836. HTC_PACKET_ENQUEUE(pQueue, pPacket);
  837. }
  838. }
  839. if (!HTC_QUEUE_EMPTY(&pm_queue))
  840. queue_htc_pm_packets(pEndpoint, &pm_queue);
  841. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  842. ("-get_htc_send_packets_credit_based\n"));
  843. }
  844. static void get_htc_send_packets(HTC_TARGET *target,
  845. HTC_ENDPOINT *pEndpoint,
  846. HTC_PACKET_QUEUE *pQueue, int Resources)
  847. {
  848. HTC_PACKET *pPacket;
  849. HTC_PACKET_QUEUE *tx_queue;
  850. HTC_PACKET_QUEUE pm_queue;
  851. bool do_pm_get;
  852. /*** NOTE : the TX lock is held when this function is called ***/
  853. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  854. ("+get_htc_send_packets %d resources\n", Resources));
  855. INIT_HTC_PACKET_QUEUE(&pm_queue);
  856. extract_htc_pm_packets(pEndpoint, &pm_queue);
  857. if (HTC_QUEUE_EMPTY(&pm_queue)) {
  858. tx_queue = &pEndpoint->TxQueue;
  859. do_pm_get = true;
  860. } else {
  861. tx_queue = &pm_queue;
  862. }
  863. /* loop until we can grab as many packets out of the queue as we can */
  864. while (Resources > 0) {
  865. int num_frags;
  866. if (do_pm_get && hif_pm_runtime_get(target->hif_dev)) {
  867. /* bus suspended, runtime resume issued */
  868. QDF_ASSERT(HTC_PACKET_QUEUE_DEPTH(pQueue) == 0);
  869. break;
  870. }
  871. pPacket = htc_packet_dequeue(tx_queue);
  872. if (pPacket == NULL) {
  873. if (do_pm_get)
  874. hif_pm_runtime_put(target->hif_dev);
  875. break;
  876. }
  877. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  878. (" Got packet:%pK , New Queue Depth: %d\n",
  879. pPacket,
  880. HTC_PACKET_QUEUE_DEPTH(tx_queue)));
  881. /* For non-credit path the sequence number is already embedded
  882. * in the constructed HTC header
  883. */
  884. pPacket->PktInfo.AsTx.SendFlags = 0;
  885. pPacket->PktInfo.AsTx.CreditsUsed = 0;
  886. /* queue this packet into the caller's queue */
  887. HTC_PACKET_ENQUEUE(pQueue, pPacket);
  888. /*
  889. * FIX THIS:
  890. * For now, avoid calling qdf_nbuf_get_num_frags before calling
  891. * qdf_nbuf_map, because the MacOS version of qdf_nbuf_t doesn't
  892. * support qdf_nbuf_get_num_frags until after qdf_nbuf_map has
  893. * been done.
  894. * Assume that the non-data netbufs, i.e. WMI message netbufs,
  895. * consist of a single fragment.
  896. */
  897. /* WMI messages are in a single-fragment network buf */
  898. num_frags =
  899. (pPacket->PktInfo.AsTx.
  900. Flags & HTC_TX_PACKET_FLAG_FIXUP_NETBUF) ? 1 :
  901. qdf_nbuf_get_num_frags(GET_HTC_PACKET_NET_BUF_CONTEXT
  902. (pPacket));
  903. Resources -= num_frags;
  904. }
  905. if (!HTC_QUEUE_EMPTY(&pm_queue))
  906. queue_htc_pm_packets(pEndpoint, &pm_queue);
  907. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-get_htc_send_packets\n"));
  908. }
  909. /**
  910. * htc_try_send() - Send packets in a queue on an endpoint
  911. * @target: HTC target on which packets need to be sent
  912. * @pEndpoint: logical endpoint on which packets needs to be sent
  913. * @pCallersSendQueue: packet queue containing the list of packets to be sent
  914. *
  915. * Return: enum HTC_SEND_QUEUE_RESULT indicates whether the packet was queued to
  916. * be sent or the packet should be dropped by the upper layer
  917. */
  918. static enum HTC_SEND_QUEUE_RESULT htc_try_send(HTC_TARGET *target,
  919. HTC_ENDPOINT *pEndpoint,
  920. HTC_PACKET_QUEUE *pCallersSendQueue)
  921. {
  922. /* temp queue to hold packets at various stages */
  923. HTC_PACKET_QUEUE sendQueue;
  924. HTC_PACKET *pPacket;
  925. int tx_resources;
  926. int overflow;
  927. enum HTC_SEND_QUEUE_RESULT result = HTC_SEND_QUEUE_OK;
  928. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("+htc_try_send (Queue:%pK Depth:%d)\n",
  929. pCallersSendQueue,
  930. (pCallersSendQueue ==
  931. NULL) ? 0 :
  932. HTC_PACKET_QUEUE_DEPTH
  933. (pCallersSendQueue)));
  934. /* init the local send queue */
  935. INIT_HTC_PACKET_QUEUE(&sendQueue);
  936. do {
  937. /* caller didn't provide a queue, just wants us to check
  938. * queues and send
  939. */
  940. if (pCallersSendQueue == NULL)
  941. break;
  942. if (HTC_QUEUE_EMPTY(pCallersSendQueue)) {
  943. /* empty queue */
  944. OL_ATH_HTC_PKT_ERROR_COUNT_INCR(target,
  945. HTC_PKT_Q_EMPTY);
  946. result = HTC_SEND_QUEUE_DROP;
  947. break;
  948. }
  949. if (HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue) >=
  950. pEndpoint->MaxTxQueueDepth) {
  951. /* we've already overflowed */
  952. overflow = HTC_PACKET_QUEUE_DEPTH(pCallersSendQueue);
  953. } else {
  954. /* figure out how much we will overflow by */
  955. overflow = HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue);
  956. overflow += HTC_PACKET_QUEUE_DEPTH(pCallersSendQueue);
  957. /* get how much we will overflow the TX queue by */
  958. overflow -= pEndpoint->MaxTxQueueDepth;
  959. }
  960. /* if overflow is negative or zero, we are okay */
  961. if (overflow > 0) {
  962. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  963. ("Endpoint %d, TX queue will overflow :%d , Tx Depth:%d, Max:%d\n",
  964. pEndpoint->Id, overflow,
  965. HTC_PACKET_QUEUE_DEPTH(&pEndpoint->
  966. TxQueue),
  967. pEndpoint->MaxTxQueueDepth));
  968. }
  969. if ((overflow <= 0)
  970. || (pEndpoint->EpCallBacks.EpSendFull == NULL)) {
  971. /* all packets will fit or caller did not provide send
  972. * full indication handler
  973. * just move all of them to local sendQueue object
  974. */
  975. HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&sendQueue,
  976. pCallersSendQueue);
  977. } else {
  978. int i;
  979. int goodPkts =
  980. HTC_PACKET_QUEUE_DEPTH(pCallersSendQueue) -
  981. overflow;
  982. A_ASSERT(goodPkts >= 0);
  983. /* we have overflowed and callback is provided. Dequeue
  984. * all non-overflow packets into the sendqueue
  985. */
  986. for (i = 0; i < goodPkts; i++) {
  987. /* pop off caller's queue */
  988. pPacket = htc_packet_dequeue(pCallersSendQueue);
  989. A_ASSERT(pPacket != NULL);
  990. /* insert into local queue */
  991. HTC_PACKET_ENQUEUE(&sendQueue, pPacket);
  992. }
  993. /* the caller's queue has all the packets that won't fit
  994. * walk through the caller's queue and indicate each one
  995. * to the send full handler
  996. */
  997. ITERATE_OVER_LIST_ALLOW_REMOVE(&pCallersSendQueue->
  998. QueueHead, pPacket,
  999. HTC_PACKET, ListLink) {
  1000. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  1001. ("Indicating overflowed TX packet: %pK\n",
  1002. pPacket));
  1003. /*
  1004. * Remove headroom reserved for HTC_FRAME_HDR
  1005. * before giving the packet back to the user via
  1006. * the EpSendFull callback.
  1007. */
  1008. restore_tx_packet(target, pPacket);
  1009. if (pEndpoint->EpCallBacks.
  1010. EpSendFull(pEndpoint->EpCallBacks.pContext,
  1011. pPacket) == HTC_SEND_FULL_DROP) {
  1012. /* callback wants the packet dropped */
  1013. INC_HTC_EP_STAT(pEndpoint, TxDropped,
  1014. 1);
  1015. /* leave this one in the caller's queue
  1016. * for cleanup
  1017. */
  1018. } else {
  1019. /* callback wants to keep this packet,
  1020. * remove from caller's queue
  1021. */
  1022. HTC_PACKET_REMOVE(pCallersSendQueue,
  1023. pPacket);
  1024. /* put it in the send queue
  1025. * add HTC_FRAME_HDR space reservation
  1026. * again
  1027. */
  1028. qdf_nbuf_push_head
  1029. (GET_HTC_PACKET_NET_BUF_CONTEXT
  1030. (pPacket),
  1031. sizeof(HTC_FRAME_HDR));
  1032. HTC_PACKET_ENQUEUE(&sendQueue, pPacket);
  1033. }
  1034. }
  1035. ITERATE_END;
  1036. if (HTC_QUEUE_EMPTY(&sendQueue)) {
  1037. /* no packets made it in, caller will cleanup */
  1038. OL_ATH_HTC_PKT_ERROR_COUNT_INCR(target,
  1039. HTC_SEND_Q_EMPTY);
  1040. result = HTC_SEND_QUEUE_DROP;
  1041. break;
  1042. }
  1043. }
  1044. } while (false);
  1045. if (result != HTC_SEND_QUEUE_OK) {
  1046. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_try_send: %d\n",
  1047. result));
  1048. return result;
  1049. }
  1050. if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  1051. tx_resources =
  1052. hif_get_free_queue_number(target->hif_dev,
  1053. pEndpoint->UL_PipeID);
  1054. } else {
  1055. tx_resources = 0;
  1056. }
  1057. LOCK_HTC_TX(target);
  1058. if (!HTC_QUEUE_EMPTY(&sendQueue)) {
  1059. if (target->is_nodrop_pkt) {
  1060. /*
  1061. * nodrop pkts have higher priority than normal pkts,
  1062. * insert nodrop pkt to head for proper
  1063. * start/termination of test.
  1064. */
  1065. HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&pEndpoint->TxQueue,
  1066. &sendQueue);
  1067. target->is_nodrop_pkt = false;
  1068. } else {
  1069. /* transfer packets to tail */
  1070. HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&pEndpoint->TxQueue,
  1071. &sendQueue);
  1072. A_ASSERT(HTC_QUEUE_EMPTY(&sendQueue));
  1073. INIT_HTC_PACKET_QUEUE(&sendQueue);
  1074. }
  1075. }
  1076. /* increment tx processing count on entry */
  1077. if (qdf_atomic_inc_return(&pEndpoint->TxProcessCount) > 1) {
  1078. /* another thread or task is draining the TX queues on this
  1079. * endpoint that thread will reset the tx processing count when
  1080. * the queue is drained
  1081. */
  1082. qdf_atomic_dec(&pEndpoint->TxProcessCount);
  1083. UNLOCK_HTC_TX(target);
  1084. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_try_send (busy)\n"));
  1085. return HTC_SEND_QUEUE_OK;
  1086. }
  1087. /***** beyond this point only 1 thread may enter ******/
  1088. /* now drain the endpoint TX queue for transmission as long as we have
  1089. * enough transmit resources
  1090. */
  1091. while (true) {
  1092. if (HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue) == 0)
  1093. break;
  1094. if (pEndpoint->async_update &&
  1095. (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) &&
  1096. (!tx_resources))
  1097. break;
  1098. if (IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  1099. #if DEBUG_CREDIT
  1100. int cred = pEndpoint->TxCredits;
  1101. #endif
  1102. /* credit based mechanism provides flow control based on
  1103. * target transmit resource availability, we assume that
  1104. * the HIF layer will always have bus resources greater
  1105. * than target transmit resources
  1106. */
  1107. get_htc_send_packets_credit_based(target, pEndpoint,
  1108. &sendQueue);
  1109. #if DEBUG_CREDIT
  1110. if (ep_debug_mask & (1 << pEndpoint->Id)) {
  1111. if (cred - pEndpoint->TxCredits > 0) {
  1112. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1113. (" <HTC> Decrease EP%d %d - %d = %d credits.\n",
  1114. pEndpoint->Id, cred,
  1115. cred -
  1116. pEndpoint->TxCredits,
  1117. pEndpoint->TxCredits));
  1118. }
  1119. }
  1120. #endif
  1121. } else {
  1122. /*
  1123. * Header and payload belongs to the different fragments and
  1124. * consume 2 resource for one HTC package but USB combine into
  1125. * one transfer.And one WMI message only consumes one single
  1126. * resource.
  1127. */
  1128. if (HTC_TX_BUNDLE_ENABLED(target) && tx_resources &&
  1129. hif_get_bus_type(target->hif_dev) ==
  1130. QDF_BUS_TYPE_USB) {
  1131. if (pEndpoint->service_id ==
  1132. WMI_CONTROL_SVC)
  1133. tx_resources =
  1134. HTC_MAX_MSG_PER_BUNDLE_TX;
  1135. else
  1136. tx_resources =
  1137. (HTC_MAX_MSG_PER_BUNDLE_TX * 2);
  1138. }
  1139. /* get all the packets for this endpoint that we can for
  1140. * this pass
  1141. */
  1142. get_htc_send_packets(target, pEndpoint, &sendQueue,
  1143. tx_resources);
  1144. }
  1145. if (HTC_PACKET_QUEUE_DEPTH(&sendQueue) == 0) {
  1146. /* didn't get any packets due to a lack of resources or
  1147. * TX queue was drained
  1148. */
  1149. break;
  1150. }
  1151. if (!pEndpoint->async_update)
  1152. UNLOCK_HTC_TX(target);
  1153. /* send what we can */
  1154. if (htc_issue_packets(target, pEndpoint, &sendQueue)) {
  1155. int i;
  1156. result = HTC_SEND_QUEUE_DROP;
  1157. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1158. ("htc_issue_packets, failed status:%d put it back to head of callersSendQueue",
  1159. result));
  1160. for (i = HTC_PACKET_QUEUE_DEPTH(&sendQueue); i > 0; i--)
  1161. hif_pm_runtime_put(target->hif_dev);
  1162. if (!pEndpoint->async_update) {
  1163. LOCK_HTC_TX(target);
  1164. }
  1165. HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&pEndpoint->TxQueue,
  1166. &sendQueue);
  1167. break;
  1168. }
  1169. if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  1170. tx_resources =
  1171. hif_get_free_queue_number(target->hif_dev,
  1172. pEndpoint->UL_PipeID);
  1173. }
  1174. if (!pEndpoint->async_update) {
  1175. LOCK_HTC_TX(target);
  1176. }
  1177. }
  1178. /* done with this endpoint, we can clear the count */
  1179. qdf_atomic_init(&pEndpoint->TxProcessCount);
  1180. UNLOCK_HTC_TX(target);
  1181. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_try_send:\n"));
  1182. return HTC_SEND_QUEUE_OK;
  1183. }
  1184. #ifdef USB_HIF_SINGLE_PIPE_DATA_SCHED
  1185. static uint16_t htc_send_pkts_sched_check(HTC_HANDLE HTCHandle,
  1186. HTC_ENDPOINT_ID id)
  1187. {
  1188. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1189. HTC_ENDPOINT *pEndpoint;
  1190. HTC_ENDPOINT_ID eid;
  1191. HTC_PACKET_QUEUE *pTxQueue;
  1192. uint16_t resources;
  1193. uint16_t acQueueStatus[DATA_EP_SIZE] = { 0, 0, 0, 0 };
  1194. if (id < ENDPOINT_2 || id > ENDPOINT_5)
  1195. return 1;
  1196. for (eid = ENDPOINT_2; eid <= ENDPOINT_5; eid++) {
  1197. pEndpoint = &target->endpoint[eid];
  1198. pTxQueue = &pEndpoint->TxQueue;
  1199. if (HTC_QUEUE_EMPTY(pTxQueue))
  1200. acQueueStatus[eid - 2] = 1;
  1201. }
  1202. switch (id) {
  1203. case ENDPOINT_2: /* BE */
  1204. return acQueueStatus[0] && acQueueStatus[2]
  1205. && acQueueStatus[3];
  1206. case ENDPOINT_3: /* BK */
  1207. return acQueueStatus[0] && acQueueStatus[1] && acQueueStatus[2]
  1208. && acQueueStatus[3];
  1209. case ENDPOINT_4: /* VI */
  1210. return acQueueStatus[2] && acQueueStatus[3];
  1211. case ENDPOINT_5: /* VO */
  1212. return acQueueStatus[3];
  1213. default:
  1214. return 0;
  1215. }
  1216. }
  1217. static A_STATUS htc_send_pkts_sched_queue(HTC_TARGET *target,
  1218. HTC_PACKET_QUEUE *pPktQueue,
  1219. HTC_ENDPOINT_ID eid)
  1220. {
  1221. HTC_ENDPOINT *pEndpoint;
  1222. HTC_PACKET_QUEUE *pTxQueue;
  1223. HTC_PACKET *pPacket;
  1224. int goodPkts;
  1225. pEndpoint = &target->endpoint[eid];
  1226. pTxQueue = &pEndpoint->TxQueue;
  1227. LOCK_HTC_TX(target);
  1228. goodPkts =
  1229. pEndpoint->MaxTxQueueDepth -
  1230. HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue);
  1231. if (goodPkts > 0) {
  1232. while (!HTC_QUEUE_EMPTY(pPktQueue)) {
  1233. pPacket = htc_packet_dequeue(pPktQueue);
  1234. HTC_PACKET_ENQUEUE(pTxQueue, pPacket);
  1235. goodPkts--;
  1236. if (goodPkts <= 0)
  1237. break;
  1238. }
  1239. }
  1240. if (HTC_PACKET_QUEUE_DEPTH(pPktQueue)) {
  1241. ITERATE_OVER_LIST_ALLOW_REMOVE(&pPktQueue->QueueHead, pPacket,
  1242. HTC_PACKET, ListLink) {
  1243. if (pEndpoint->EpCallBacks.
  1244. EpSendFull(pEndpoint->EpCallBacks.pContext,
  1245. pPacket) == HTC_SEND_FULL_DROP) {
  1246. INC_HTC_EP_STAT(pEndpoint, TxDropped, 1);
  1247. } else {
  1248. HTC_PACKET_REMOVE(pPktQueue, pPacket);
  1249. HTC_PACKET_ENQUEUE(pTxQueue, pPacket);
  1250. }
  1251. }
  1252. ITERATE_END;
  1253. }
  1254. UNLOCK_HTC_TX(target);
  1255. return A_OK;
  1256. }
  1257. #endif
  1258. static inline QDF_STATUS __htc_send_pkt(HTC_HANDLE HTCHandle,
  1259. HTC_PACKET *pPacket)
  1260. {
  1261. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1262. HTC_ENDPOINT *pEndpoint;
  1263. HTC_PACKET_QUEUE pPktQueue;
  1264. qdf_nbuf_t netbuf;
  1265. HTC_FRAME_HDR *pHtcHdr;
  1266. QDF_STATUS status;
  1267. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  1268. ("+__htc_send_pkt\n"));
  1269. /* get packet at head to figure out which endpoint these packets will
  1270. * go into
  1271. */
  1272. if (NULL == pPacket) {
  1273. OL_ATH_HTC_PKT_ERROR_COUNT_INCR(target, GET_HTC_PKT_Q_FAIL);
  1274. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-__htc_send_pkt\n"));
  1275. return QDF_STATUS_E_INVAL;
  1276. }
  1277. if ((pPacket->Endpoint >= ENDPOINT_MAX) ||
  1278. (pPacket->Endpoint <= ENDPOINT_UNUSED)) {
  1279. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  1280. ("%s endpoint is invalid\n", __func__));
  1281. AR_DEBUG_ASSERT(0);
  1282. return QDF_STATUS_E_INVAL;
  1283. }
  1284. pEndpoint = &target->endpoint[pPacket->Endpoint];
  1285. if (!pEndpoint->service_id) {
  1286. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("%s service_id is invalid\n",
  1287. __func__));
  1288. return QDF_STATUS_E_INVAL;
  1289. }
  1290. #ifdef HTC_EP_STAT_PROFILING
  1291. LOCK_HTC_TX(target);
  1292. INC_HTC_EP_STAT(pEndpoint, TxPosted, 1);
  1293. UNLOCK_HTC_TX(target);
  1294. #endif
  1295. /* provide room in each packet's netbuf for the HTC frame header */
  1296. netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  1297. AR_DEBUG_ASSERT(netbuf);
  1298. qdf_nbuf_push_head(netbuf, sizeof(HTC_FRAME_HDR));
  1299. /* setup HTC frame header */
  1300. pHtcHdr = (HTC_FRAME_HDR *) qdf_nbuf_get_frag_vaddr(netbuf, 0);
  1301. AR_DEBUG_ASSERT(pHtcHdr);
  1302. HTC_WRITE32(pHtcHdr,
  1303. SM(pPacket->ActualLength,
  1304. HTC_FRAME_HDR_PAYLOADLEN) |
  1305. SM(pPacket->Endpoint,
  1306. HTC_FRAME_HDR_ENDPOINTID));
  1307. LOCK_HTC_TX(target);
  1308. pPacket->PktInfo.AsTx.SeqNo = pEndpoint->SeqNo;
  1309. pEndpoint->SeqNo++;
  1310. HTC_WRITE32(((uint32_t *) pHtcHdr) + 1,
  1311. SM(pPacket->PktInfo.AsTx.SeqNo,
  1312. HTC_FRAME_HDR_CONTROLBYTES1));
  1313. UNLOCK_HTC_TX(target);
  1314. /*
  1315. * For flow control enabled endpoints mapping is done in
  1316. * htc_issue_packets and for non flow control enabled endpoints
  1317. * its done here.
  1318. */
  1319. if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  1320. pPacket->PktInfo.AsTx.Flags |= HTC_TX_PACKET_FLAG_FIXUP_NETBUF;
  1321. status = qdf_nbuf_map(target->osdev,
  1322. GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket),
  1323. QDF_DMA_TO_DEVICE);
  1324. if (status != QDF_STATUS_SUCCESS) {
  1325. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1326. ("%s: nbuf map failed, endpoint %pK, seq_no. %d\n",
  1327. __func__, pEndpoint, pEndpoint->SeqNo));
  1328. return status;
  1329. }
  1330. }
  1331. INIT_HTC_PACKET_QUEUE_AND_ADD(&pPktQueue, pPacket);
  1332. #ifdef USB_HIF_SINGLE_PIPE_DATA_SCHED
  1333. if (!htc_send_pkts_sched_check(HTCHandle, pEndpoint->Id))
  1334. htc_send_pkts_sched_queue(HTCHandle, &pPktQueue, pEndpoint->Id);
  1335. else
  1336. htc_try_send(target, pEndpoint, &pPktQueue);
  1337. #else
  1338. htc_try_send(target, pEndpoint, &pPktQueue);
  1339. #endif
  1340. /* do completion on any packets that couldn't get in */
  1341. while (!HTC_QUEUE_EMPTY(&pPktQueue)) {
  1342. pPacket = htc_packet_dequeue(&pPktQueue);
  1343. if (HTC_STOPPING(target))
  1344. pPacket->Status = QDF_STATUS_E_CANCELED;
  1345. else
  1346. pPacket->Status = QDF_STATUS_E_RESOURCES;
  1347. send_packet_completion(target, pPacket);
  1348. }
  1349. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-__htc_send_pkt\n"));
  1350. return QDF_STATUS_SUCCESS;
  1351. }
  1352. /* HTC API - htc_send_pkt */
  1353. QDF_STATUS htc_send_pkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket)
  1354. {
  1355. if (HTCHandle == NULL || pPacket == NULL)
  1356. return QDF_STATUS_E_FAILURE;
  1357. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  1358. ("+-htc_send_pkt: Enter endPointId: %d, buffer: %pK, length: %d\n",
  1359. pPacket->Endpoint, pPacket->pBuffer,
  1360. pPacket->ActualLength));
  1361. return __htc_send_pkt(HTCHandle, pPacket);
  1362. }
  1363. #ifdef ATH_11AC_TXCOMPACT
  1364. /**
  1365. * htc_send_data_pkt() - send single data packet on an endpoint
  1366. * @HTCHandle: pointer to HTC handle
  1367. * @netbuf: network buffer containing the data to be sent
  1368. * @ActualLength: length of data that needs to be transmitted
  1369. *
  1370. * Return: QDF_STATUS_SUCCESS for success or an appropriate QDF_STATUS error
  1371. */
  1372. QDF_STATUS htc_send_data_pkt(HTC_HANDLE HTCHandle, qdf_nbuf_t netbuf, int Epid,
  1373. int ActualLength)
  1374. {
  1375. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1376. HTC_ENDPOINT *pEndpoint;
  1377. HTC_FRAME_HDR *pHtcHdr;
  1378. QDF_STATUS status = QDF_STATUS_SUCCESS;
  1379. int tx_resources;
  1380. uint32_t data_attr = 0;
  1381. pEndpoint = &target->endpoint[Epid];
  1382. tx_resources = hif_get_free_queue_number(target->hif_dev,
  1383. pEndpoint->UL_PipeID);
  1384. if (tx_resources < HTC_DATA_RESOURCE_THRS) {
  1385. if (pEndpoint->ul_is_polled) {
  1386. hif_send_complete_check(pEndpoint->target->hif_dev,
  1387. pEndpoint->UL_PipeID, 1);
  1388. tx_resources =
  1389. hif_get_free_queue_number(target->hif_dev,
  1390. pEndpoint->UL_PipeID);
  1391. }
  1392. if (tx_resources < HTC_DATA_MINDESC_PERPACKET)
  1393. return QDF_STATUS_E_FAILURE;
  1394. }
  1395. if (hif_pm_runtime_get(target->hif_dev))
  1396. return QDF_STATUS_E_FAILURE;
  1397. pHtcHdr = (HTC_FRAME_HDR *) qdf_nbuf_get_frag_vaddr(netbuf, 0);
  1398. AR_DEBUG_ASSERT(pHtcHdr);
  1399. data_attr = qdf_nbuf_data_attr_get(netbuf);
  1400. HTC_WRITE32(pHtcHdr, SM(ActualLength, HTC_FRAME_HDR_PAYLOADLEN) |
  1401. SM(Epid, HTC_FRAME_HDR_ENDPOINTID));
  1402. /*
  1403. * If the HIF pipe for the data endpoint is polled rather than
  1404. * interrupt-driven, this is a good point to check whether any
  1405. * data previously sent through the HIF pipe have finished being
  1406. * sent.
  1407. * Since this may result in callbacks to htc_tx_completion_handler,
  1408. * which can take the HTC tx lock, make the hif_send_complete_check
  1409. * call before acquiring the HTC tx lock.
  1410. * Call hif_send_complete_check directly, rather than calling
  1411. * htc_send_complete_check, and call the PollTimerStart separately
  1412. * after calling hif_send_head, so the timer will be started to
  1413. * check for completion of the new outstanding download (in the
  1414. * unexpected event that other polling calls don't catch it).
  1415. */
  1416. LOCK_HTC_TX(target);
  1417. HTC_WRITE32(((uint32_t *) pHtcHdr) + 1,
  1418. SM(pEndpoint->SeqNo, HTC_FRAME_HDR_CONTROLBYTES1));
  1419. pEndpoint->SeqNo++;
  1420. QDF_NBUF_UPDATE_TX_PKT_COUNT(netbuf, QDF_NBUF_TX_PKT_HTC);
  1421. DPTRACE(qdf_dp_trace(netbuf, QDF_DP_TRACE_HTC_PACKET_PTR_RECORD,
  1422. QDF_TRACE_DEFAULT_PDEV_ID, qdf_nbuf_data_addr(netbuf),
  1423. sizeof(qdf_nbuf_data(netbuf)), QDF_TX));
  1424. status = hif_send_head(target->hif_dev,
  1425. pEndpoint->UL_PipeID,
  1426. pEndpoint->Id, ActualLength, netbuf, data_attr);
  1427. UNLOCK_HTC_TX(target);
  1428. return status;
  1429. }
  1430. #else /*ATH_11AC_TXCOMPACT */
  1431. /**
  1432. * htc_send_data_pkt() - htc_send_data_pkt
  1433. * @HTCHandle: pointer to HTC handle
  1434. * @pPacket: pointer to HTC_PACKET
  1435. * @more_data: indicates whether more data is to follow
  1436. *
  1437. * Return: QDF_STATUS_SUCCESS for success or an appropriate QDF_STATUS error
  1438. */
  1439. QDF_STATUS htc_send_data_pkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket,
  1440. uint8_t more_data)
  1441. {
  1442. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1443. HTC_ENDPOINT *pEndpoint;
  1444. HTC_FRAME_HDR *pHtcHdr;
  1445. HTC_PACKET_QUEUE sendQueue;
  1446. qdf_nbuf_t netbuf = NULL;
  1447. int tx_resources;
  1448. QDF_STATUS status = QDF_STATUS_SUCCESS;
  1449. uint32_t data_attr = 0;
  1450. if (pPacket) {
  1451. if ((pPacket->Endpoint >= ENDPOINT_MAX) ||
  1452. (pPacket->Endpoint <= ENDPOINT_UNUSED)) {
  1453. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  1454. ("%s endpoint is invalid\n", __func__));
  1455. AR_DEBUG_ASSERT(0);
  1456. return QDF_STATUS_E_INVAL;
  1457. }
  1458. pEndpoint = &target->endpoint[pPacket->Endpoint];
  1459. /* add HTC_FRAME_HDR in the initial fragment */
  1460. netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  1461. pHtcHdr = (HTC_FRAME_HDR *) qdf_nbuf_get_frag_vaddr(netbuf, 0);
  1462. AR_DEBUG_ASSERT(pHtcHdr);
  1463. HTC_WRITE32(pHtcHdr,
  1464. SM(pPacket->ActualLength,
  1465. HTC_FRAME_HDR_PAYLOADLEN) |
  1466. SM(pPacket->PktInfo.AsTx.SendFlags,
  1467. HTC_FRAME_HDR_FLAGS) |
  1468. SM(pPacket->Endpoint,
  1469. HTC_FRAME_HDR_ENDPOINTID));
  1470. /*
  1471. * If the HIF pipe for the data endpoint is polled rather than
  1472. * interrupt-driven, this is a good point to check whether any
  1473. * data previously sent through the HIF pipe have finished being
  1474. * sent. Since this may result in callbacks to
  1475. * htc_tx_completion_handler, which can take the HTC tx lock,
  1476. * make the hif_send_complete_check call before acquiring the
  1477. * HTC tx lock.
  1478. * Call hif_send_complete_check directly, rather than calling
  1479. * htc_send_complete_check, and call the PollTimerStart
  1480. * separately after calling hif_send_head, so the timer will be
  1481. * started to check for completion of the new outstanding
  1482. * download (in the unexpected event that other polling calls
  1483. * don't catch it).
  1484. */
  1485. if (pEndpoint->ul_is_polled) {
  1486. htc_send_complete_poll_timer_stop(pEndpoint);
  1487. hif_send_complete_check(pEndpoint->target->hif_dev,
  1488. pEndpoint->UL_PipeID, 0);
  1489. }
  1490. LOCK_HTC_TX(target);
  1491. pPacket->PktInfo.AsTx.SeqNo = pEndpoint->SeqNo;
  1492. pEndpoint->SeqNo++;
  1493. HTC_WRITE32(((uint32_t *) pHtcHdr) + 1,
  1494. SM(pPacket->PktInfo.AsTx.SeqNo,
  1495. HTC_FRAME_HDR_CONTROLBYTES1));
  1496. /* append new packet to pEndpoint->TxQueue */
  1497. HTC_PACKET_ENQUEUE(&pEndpoint->TxQueue, pPacket);
  1498. if (HTC_TX_BUNDLE_ENABLED(target) && (more_data)) {
  1499. UNLOCK_HTC_TX(target);
  1500. return QDF_STATUS_SUCCESS;
  1501. }
  1502. QDF_NBUF_UPDATE_TX_PKT_COUNT(netbuf, QDF_NBUF_TX_PKT_HTC);
  1503. DPTRACE(qdf_dp_trace(netbuf, QDF_DP_TRACE_HTC_PACKET_PTR_RECORD,
  1504. qdf_nbuf_data_addr(netbuf),
  1505. sizeof(qdf_nbuf_data(netbuf)), QDF_TX));
  1506. } else {
  1507. LOCK_HTC_TX(target);
  1508. pEndpoint = &target->endpoint[1];
  1509. }
  1510. /* increment tx processing count on entry */
  1511. qdf_atomic_inc(&pEndpoint->TxProcessCount);
  1512. if (qdf_atomic_read(&pEndpoint->TxProcessCount) > 1) {
  1513. /*
  1514. * Another thread or task is draining the TX queues on this
  1515. * endpoint. That thread will reset the tx processing count when
  1516. * the queue is drained.
  1517. */
  1518. qdf_atomic_dec(&pEndpoint->TxProcessCount);
  1519. UNLOCK_HTC_TX(target);
  1520. return QDF_STATUS_SUCCESS;
  1521. }
  1522. /***** beyond this point only 1 thread may enter ******/
  1523. INIT_HTC_PACKET_QUEUE(&sendQueue);
  1524. if (IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  1525. #if DEBUG_CREDIT
  1526. int cred = pEndpoint->TxCredits;
  1527. #endif
  1528. get_htc_send_packets_credit_based(target, pEndpoint,
  1529. &sendQueue);
  1530. #if DEBUG_CREDIT
  1531. if (ep_debug_mask & (1 << pEndpoint->Id)) {
  1532. if (cred - pEndpoint->TxCredits > 0) {
  1533. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1534. (" <HTC> Decrease EP%d %d - %d = %d credits.\n",
  1535. pEndpoint->Id, cred,
  1536. cred - pEndpoint->TxCredits,
  1537. pEndpoint->TxCredits));
  1538. }
  1539. }
  1540. #endif
  1541. UNLOCK_HTC_TX(target);
  1542. }
  1543. else if (HTC_TX_BUNDLE_ENABLED(target)) {
  1544. if ((hif_get_bus_type(target->hif_dev) == QDF_BUS_TYPE_USB) &&
  1545. hif_get_free_queue_number(target->hif_dev,
  1546. pEndpoint->UL_PipeID)) {
  1547. /*
  1548. * Header and payload belongs to the different fragments
  1549. * and consume 2 resource for one HTC package but USB
  1550. * combine into one transfer.
  1551. */
  1552. get_htc_send_packets(target, pEndpoint, &sendQueue,
  1553. (HTC_MAX_MSG_PER_BUNDLE_TX * 2));
  1554. } else {
  1555. /* Dequeue max packets from endpoint tx queue */
  1556. get_htc_send_packets(target, pEndpoint, &sendQueue,
  1557. HTC_MAX_TX_BUNDLE_SEND_LIMIT);
  1558. }
  1559. UNLOCK_HTC_TX(target);
  1560. } else {
  1561. /*
  1562. * Now drain the endpoint TX queue for transmission as long as
  1563. * we have enough transmit resources
  1564. */
  1565. tx_resources =
  1566. hif_get_free_queue_number(target->hif_dev,
  1567. pEndpoint->UL_PipeID);
  1568. get_htc_send_packets(target, pEndpoint, &sendQueue,
  1569. tx_resources);
  1570. UNLOCK_HTC_TX(target);
  1571. }
  1572. /* send what we can */
  1573. while (true) {
  1574. if (HTC_TX_BUNDLE_ENABLED(target) &&
  1575. (HTC_PACKET_QUEUE_DEPTH(&sendQueue) >=
  1576. HTC_MIN_MSG_PER_BUNDLE) &&
  1577. (hif_get_bus_type(target->hif_dev) == QDF_BUS_TYPE_SDIO ||
  1578. hif_get_bus_type(target->hif_dev) == QDF_BUS_TYPE_USB)) {
  1579. htc_issue_packets_bundle(target, pEndpoint, &sendQueue);
  1580. }
  1581. pPacket = htc_packet_dequeue(&sendQueue);
  1582. if (pPacket == NULL)
  1583. break;
  1584. netbuf = GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  1585. LOCK_HTC_TX(target);
  1586. /* store in look up queue to match completions */
  1587. HTC_PACKET_ENQUEUE(&pEndpoint->TxLookupQueue, pPacket);
  1588. INC_HTC_EP_STAT(pEndpoint, TxIssued, 1);
  1589. pEndpoint->ul_outstanding_cnt++;
  1590. UNLOCK_HTC_TX(target);
  1591. status = hif_send_head(target->hif_dev,
  1592. pEndpoint->UL_PipeID,
  1593. pEndpoint->Id,
  1594. HTC_HDR_LENGTH + pPacket->ActualLength,
  1595. netbuf, data_attr);
  1596. #if DEBUG_BUNDLE
  1597. qdf_print(" Send single EP%d buffer size:0x%x, total:0x%x.\n",
  1598. pEndpoint->Id,
  1599. pEndpoint->TxCreditSize,
  1600. HTC_HDR_LENGTH + pPacket->ActualLength);
  1601. #endif
  1602. htc_issue_tx_bundle_stats_inc(target);
  1603. if (qdf_unlikely(QDF_IS_STATUS_ERROR(status))) {
  1604. LOCK_HTC_TX(target);
  1605. pEndpoint->ul_outstanding_cnt--;
  1606. /* remove this packet from the tx completion queue */
  1607. HTC_PACKET_REMOVE(&pEndpoint->TxLookupQueue, pPacket);
  1608. /*
  1609. * Don't bother reclaiming credits - HTC flow control
  1610. * is not applicable to tx data.
  1611. * In LL systems, there is no download flow control,
  1612. * since there's virtually no download delay.
  1613. * In HL systems, the txrx SW explicitly performs the
  1614. * tx flow control.
  1615. */
  1616. /* pEndpoint->TxCredits +=
  1617. * pPacket->PktInfo.AsTx.CreditsUsed;
  1618. */
  1619. /* put this frame back at the front of the sendQueue */
  1620. HTC_PACKET_ENQUEUE_TO_HEAD(&sendQueue, pPacket);
  1621. /* put the sendQueue back at the front of
  1622. * pEndpoint->TxQueue
  1623. */
  1624. HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&pEndpoint->TxQueue,
  1625. &sendQueue);
  1626. UNLOCK_HTC_TX(target);
  1627. break; /* still need to reset TxProcessCount */
  1628. }
  1629. }
  1630. /* done with this endpoint, we can clear the count */
  1631. qdf_atomic_init(&pEndpoint->TxProcessCount);
  1632. if (pEndpoint->ul_is_polled) {
  1633. /*
  1634. * Start a cleanup timer to poll for download completion.
  1635. * The download completion should be noticed promptly from
  1636. * other polling calls, but the timer provides a safety net
  1637. * in case other polling calls don't occur as expected.
  1638. */
  1639. htc_send_complete_poll_timer_start(pEndpoint);
  1640. }
  1641. return status;
  1642. }
  1643. #endif /*ATH_11AC_TXCOMPACT */
  1644. /*
  1645. * In the adapted HIF layer, qdf_nbuf_t are passed between HIF and HTC,
  1646. * since upper layers expects HTC_PACKET containers we use the completed netbuf
  1647. * and lookup its corresponding HTC packet buffer from a lookup list.
  1648. * This is extra overhead that can be fixed by re-aligning HIF interfaces
  1649. * with HTC.
  1650. *
  1651. */
  1652. static HTC_PACKET *htc_lookup_tx_packet(HTC_TARGET *target,
  1653. HTC_ENDPOINT *pEndpoint,
  1654. qdf_nbuf_t netbuf)
  1655. {
  1656. HTC_PACKET *pPacket = NULL;
  1657. HTC_PACKET *pFoundPacket = NULL;
  1658. HTC_PACKET_QUEUE lookupQueue;
  1659. INIT_HTC_PACKET_QUEUE(&lookupQueue);
  1660. LOCK_HTC_EP_TX_LOOKUP(pEndpoint);
  1661. LOCK_HTC_TX(target);
  1662. /* mark that HIF has indicated the send complete for another packet */
  1663. pEndpoint->ul_outstanding_cnt--;
  1664. /* Dequeue first packet directly because of in-order completion */
  1665. pPacket = htc_packet_dequeue(&pEndpoint->TxLookupQueue);
  1666. if (qdf_unlikely(!pPacket)) {
  1667. UNLOCK_HTC_TX(target);
  1668. UNLOCK_HTC_EP_TX_LOOKUP(pEndpoint);
  1669. return NULL;
  1670. }
  1671. if (netbuf == (qdf_nbuf_t) GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket)) {
  1672. UNLOCK_HTC_TX(target);
  1673. UNLOCK_HTC_EP_TX_LOOKUP(pEndpoint);
  1674. return pPacket;
  1675. }
  1676. HTC_PACKET_ENQUEUE(&lookupQueue, pPacket);
  1677. /*
  1678. * Move TX lookup queue to temp queue because most of packets that are
  1679. * not index 0 are not top 10 packets.
  1680. */
  1681. HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&lookupQueue,
  1682. &pEndpoint->TxLookupQueue);
  1683. UNLOCK_HTC_TX(target);
  1684. ITERATE_OVER_LIST_ALLOW_REMOVE(&lookupQueue.QueueHead, pPacket,
  1685. HTC_PACKET, ListLink) {
  1686. if (NULL == pPacket) {
  1687. pFoundPacket = pPacket;
  1688. break;
  1689. }
  1690. /* check for removal */
  1691. if (netbuf ==
  1692. (qdf_nbuf_t) GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket)) {
  1693. /* found it */
  1694. HTC_PACKET_REMOVE(&lookupQueue, pPacket);
  1695. pFoundPacket = pPacket;
  1696. break;
  1697. }
  1698. }
  1699. ITERATE_END;
  1700. LOCK_HTC_TX(target);
  1701. HTC_PACKET_QUEUE_TRANSFER_TO_HEAD(&pEndpoint->TxLookupQueue,
  1702. &lookupQueue);
  1703. UNLOCK_HTC_TX(target);
  1704. UNLOCK_HTC_EP_TX_LOOKUP(pEndpoint);
  1705. return pFoundPacket;
  1706. }
  1707. /**
  1708. * htc_tx_completion_handler() - htc tx completion handler
  1709. * @Context: pointer to HTC_TARGET structure
  1710. * @netbuf: pointer to netbuf for which completion handler is being called
  1711. * @EpID: end point Id on which the packet was sent
  1712. * @toeplitz_hash_result: toeplitz hash result
  1713. *
  1714. * Return: QDF_STATUS_SUCCESS for success or an appropriate QDF_STATUS error
  1715. */
  1716. QDF_STATUS htc_tx_completion_handler(void *Context,
  1717. qdf_nbuf_t netbuf, unsigned int EpID,
  1718. uint32_t toeplitz_hash_result)
  1719. {
  1720. HTC_TARGET *target = (HTC_TARGET *) Context;
  1721. HTC_ENDPOINT *pEndpoint;
  1722. HTC_PACKET *pPacket;
  1723. #ifdef USB_HIF_SINGLE_PIPE_DATA_SCHED
  1724. HTC_ENDPOINT_ID eid[DATA_EP_SIZE] = { ENDPOINT_5, ENDPOINT_4,
  1725. ENDPOINT_2, ENDPOINT_3 };
  1726. int epidIdx;
  1727. uint16_t resourcesThresh[DATA_EP_SIZE]; /* urb resources */
  1728. uint16_t resources;
  1729. uint16_t resourcesMax;
  1730. #endif
  1731. pEndpoint = &target->endpoint[EpID];
  1732. target->TX_comp_cnt++;
  1733. do {
  1734. pPacket = htc_lookup_tx_packet(target, pEndpoint, netbuf);
  1735. if (NULL == pPacket) {
  1736. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1737. ("HTC TX lookup failed!\n"));
  1738. /* may have already been flushed and freed */
  1739. netbuf = NULL;
  1740. break;
  1741. }
  1742. if (pPacket->PktInfo.AsTx.Tag != HTC_TX_PACKET_TAG_AUTO_PM)
  1743. hif_pm_runtime_put(target->hif_dev);
  1744. if (pPacket->PktInfo.AsTx.Tag == HTC_TX_PACKET_TAG_BUNDLED) {
  1745. HTC_PACKET *pPacketTemp;
  1746. HTC_PACKET_QUEUE *pQueueSave =
  1747. (HTC_PACKET_QUEUE *) pPacket->pContext;
  1748. HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pQueueSave,
  1749. pPacketTemp) {
  1750. pPacket->Status = QDF_STATUS_SUCCESS;
  1751. send_packet_completion(target, pPacketTemp);
  1752. }
  1753. HTC_PACKET_QUEUE_ITERATE_END;
  1754. free_htc_bundle_packet(target, pPacket);
  1755. if (hif_get_bus_type(target->hif_dev) ==
  1756. QDF_BUS_TYPE_USB) {
  1757. if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint))
  1758. htc_try_send(target, pEndpoint, NULL);
  1759. }
  1760. return QDF_STATUS_SUCCESS;
  1761. }
  1762. /* will be giving this buffer back to upper layers */
  1763. netbuf = NULL;
  1764. pPacket->Status = QDF_STATUS_SUCCESS;
  1765. send_packet_completion(target, pPacket);
  1766. } while (false);
  1767. if (!IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) {
  1768. /* note: when using TX credit flow, the re-checking of queues
  1769. * happens when credits flow back from the target. In the non-TX
  1770. * credit case, we recheck after the packet completes
  1771. */
  1772. if ((qdf_atomic_read(&pEndpoint->TxProcessCount) == 0) ||
  1773. (!pEndpoint->async_update)) {
  1774. htc_try_send(target, pEndpoint, NULL);
  1775. }
  1776. }
  1777. return QDF_STATUS_SUCCESS;
  1778. }
  1779. #ifdef WLAN_FEATURE_FASTPATH
  1780. /**
  1781. * htc_ctrl_msg_cmpl(): checks for tx completion for the endpoint specified
  1782. * @HTC_HANDLE : pointer to the htc target context
  1783. * @htc_ep_id : end point id
  1784. *
  1785. * checks HTC tx completion
  1786. *
  1787. * Return: none
  1788. */
  1789. void htc_ctrl_msg_cmpl(HTC_HANDLE htc_pdev, HTC_ENDPOINT_ID htc_ep_id)
  1790. {
  1791. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_pdev);
  1792. HTC_ENDPOINT *pendpoint = &target->endpoint[htc_ep_id];
  1793. htc_send_complete_check(pendpoint, 1);
  1794. }
  1795. #endif
  1796. /* callback when TX resources become available */
  1797. void htc_tx_resource_avail_handler(void *context, uint8_t pipeID)
  1798. {
  1799. int i;
  1800. HTC_TARGET *target = (HTC_TARGET *) context;
  1801. HTC_ENDPOINT *pEndpoint = NULL;
  1802. for (i = 0; i < ENDPOINT_MAX; i++) {
  1803. pEndpoint = &target->endpoint[i];
  1804. if (pEndpoint->service_id != 0) {
  1805. if (pEndpoint->UL_PipeID == pipeID)
  1806. break;
  1807. }
  1808. }
  1809. if (i >= ENDPOINT_MAX) {
  1810. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1811. ("Invalid pipe indicated for TX resource avail : %d!\n",
  1812. pipeID));
  1813. return;
  1814. }
  1815. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  1816. ("HIF indicated more resources for pipe:%d\n",
  1817. pipeID));
  1818. htc_try_send(target, pEndpoint, NULL);
  1819. }
  1820. #ifdef FEATURE_RUNTIME_PM
  1821. /**
  1822. * htc_kick_queues(): resumes tx transactions of suspended endpoints
  1823. * @context: pointer to the htc target context
  1824. *
  1825. * Iterates throught the enpoints and provides a context to empty queues
  1826. * int the hif layer when they are stalled due to runtime suspend.
  1827. *
  1828. * Return: none
  1829. */
  1830. void htc_kick_queues(void *context)
  1831. {
  1832. int i;
  1833. HTC_TARGET *target = (HTC_TARGET *)context;
  1834. HTC_ENDPOINT *endpoint = NULL;
  1835. for (i = 0; i < ENDPOINT_MAX; i++) {
  1836. endpoint = &target->endpoint[i];
  1837. if (endpoint->service_id == 0)
  1838. continue;
  1839. if (endpoint->EpCallBacks.ep_resume_tx_queue)
  1840. endpoint->EpCallBacks.ep_resume_tx_queue(
  1841. endpoint->EpCallBacks.pContext);
  1842. htc_try_send(target, endpoint, NULL);
  1843. }
  1844. hif_fastpath_resume(target->hif_dev);
  1845. }
  1846. #endif
  1847. /* flush endpoint TX queue */
  1848. void htc_flush_endpoint_tx(HTC_TARGET *target, HTC_ENDPOINT *pEndpoint,
  1849. HTC_TX_TAG Tag)
  1850. {
  1851. HTC_PACKET *pPacket;
  1852. LOCK_HTC_TX(target);
  1853. while (HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue)) {
  1854. pPacket = htc_packet_dequeue(&pEndpoint->TxQueue);
  1855. if (pPacket) {
  1856. /* let the sender know the packet was not delivered */
  1857. pPacket->Status = QDF_STATUS_E_CANCELED;
  1858. send_packet_completion(target, pPacket);
  1859. }
  1860. }
  1861. UNLOCK_HTC_TX(target);
  1862. }
  1863. /* HTC API to flush an endpoint's TX queue*/
  1864. void htc_flush_endpoint(HTC_HANDLE HTCHandle, HTC_ENDPOINT_ID Endpoint,
  1865. HTC_TX_TAG Tag)
  1866. {
  1867. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1868. HTC_ENDPOINT *pEndpoint = &target->endpoint[Endpoint];
  1869. if (pEndpoint->service_id == 0) {
  1870. AR_DEBUG_ASSERT(false);
  1871. /* not in use.. */
  1872. return;
  1873. }
  1874. htc_flush_endpoint_tx(target, pEndpoint, Tag);
  1875. }
  1876. /* HTC API to indicate activity to the credit distribution function */
  1877. void htc_indicate_activity_change(HTC_HANDLE HTCHandle,
  1878. HTC_ENDPOINT_ID Endpoint, bool Active)
  1879. {
  1880. /* TODO */
  1881. }
  1882. bool htc_is_endpoint_active(HTC_HANDLE HTCHandle, HTC_ENDPOINT_ID Endpoint)
  1883. {
  1884. return true;
  1885. }
  1886. void htc_set_nodrop_pkt(HTC_HANDLE HTCHandle, A_BOOL isNodropPkt)
  1887. {
  1888. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1889. target->is_nodrop_pkt = isNodropPkt;
  1890. }
  1891. /**
  1892. * htc_process_credit_rpt() - process credit report, call distribution function
  1893. * @target: pointer to HTC_TARGET
  1894. * @pRpt: pointer to HTC_CREDIT_REPORT
  1895. * @NumEntries: number of entries in credit report
  1896. * @FromEndpoint: endpoint for which credit report is received
  1897. *
  1898. * Return: A_OK for success or an appropriate A_STATUS error
  1899. */
  1900. void htc_process_credit_rpt(HTC_TARGET *target, HTC_CREDIT_REPORT *pRpt,
  1901. int NumEntries, HTC_ENDPOINT_ID FromEndpoint)
  1902. {
  1903. int i;
  1904. HTC_ENDPOINT *pEndpoint;
  1905. int totalCredits = 0;
  1906. uint8_t rpt_credits, rpt_ep_id;
  1907. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  1908. ("+htc_process_credit_rpt, Credit Report Entries:%d\n",
  1909. NumEntries));
  1910. /* lock out TX while we update credits */
  1911. LOCK_HTC_TX(target);
  1912. for (i = 0; i < NumEntries; i++, pRpt++) {
  1913. rpt_ep_id = HTC_GET_FIELD(pRpt, HTC_CREDIT_REPORT, ENDPOINTID);
  1914. if (rpt_ep_id >= ENDPOINT_MAX) {
  1915. AR_DEBUG_ASSERT(false);
  1916. break;
  1917. }
  1918. rpt_credits = HTC_GET_FIELD(pRpt, HTC_CREDIT_REPORT, CREDITS);
  1919. pEndpoint = &target->endpoint[rpt_ep_id];
  1920. #if DEBUG_CREDIT
  1921. if (ep_debug_mask & (1 << pEndpoint->Id)) {
  1922. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  1923. (" <HTC> Increase EP%d %d + %d = %d credits\n",
  1924. rpt_ep_id, pEndpoint->TxCredits,
  1925. rpt_credits,
  1926. pEndpoint->TxCredits + rpt_credits));
  1927. }
  1928. #endif
  1929. #ifdef HTC_EP_STAT_PROFILING
  1930. INC_HTC_EP_STAT(pEndpoint, TxCreditRpts, 1);
  1931. INC_HTC_EP_STAT(pEndpoint, TxCreditsReturned, rpt_credits);
  1932. if (FromEndpoint == rpt_ep_id) {
  1933. /* this credit report arrived on the same endpoint
  1934. * indicating it arrived in an RX packet
  1935. */
  1936. INC_HTC_EP_STAT(pEndpoint, TxCreditsFromRx,
  1937. rpt_credits);
  1938. INC_HTC_EP_STAT(pEndpoint, TxCreditRptsFromRx, 1);
  1939. } else if (FromEndpoint == ENDPOINT_0) {
  1940. /* this credit arrived on endpoint 0 as a NULL msg */
  1941. INC_HTC_EP_STAT(pEndpoint, TxCreditsFromEp0,
  1942. rpt_credits);
  1943. INC_HTC_EP_STAT(pEndpoint, TxCreditRptsFromEp0, 1);
  1944. } else {
  1945. /* arrived on another endpoint */
  1946. INC_HTC_EP_STAT(pEndpoint, TxCreditsFromOther,
  1947. rpt_credits);
  1948. INC_HTC_EP_STAT(pEndpoint, TxCreditRptsFromOther, 1);
  1949. }
  1950. #endif
  1951. pEndpoint->TxCredits += rpt_credits;
  1952. if (pEndpoint->service_id == WMI_CONTROL_SVC) {
  1953. LOCK_HTC_CREDIT(target);
  1954. htc_credit_record(HTC_PROCESS_CREDIT_REPORT,
  1955. pEndpoint->TxCredits,
  1956. HTC_PACKET_QUEUE_DEPTH(&pEndpoint->
  1957. TxQueue));
  1958. UNLOCK_HTC_CREDIT(target);
  1959. }
  1960. if (pEndpoint->TxCredits
  1961. && HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue)) {
  1962. UNLOCK_HTC_TX(target);
  1963. #ifdef ATH_11AC_TXCOMPACT
  1964. htc_try_send(target, pEndpoint, NULL);
  1965. #else
  1966. if (pEndpoint->service_id == HTT_DATA_MSG_SVC)
  1967. htc_send_data_pkt(target, NULL, 0);
  1968. else
  1969. htc_try_send(target, pEndpoint, NULL);
  1970. #endif
  1971. LOCK_HTC_TX(target);
  1972. }
  1973. totalCredits += rpt_credits;
  1974. }
  1975. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  1976. (" Report indicated %d credits to distribute\n",
  1977. totalCredits));
  1978. UNLOCK_HTC_TX(target);
  1979. AR_DEBUG_PRINTF(ATH_DEBUG_SEND, ("-htc_process_credit_rpt\n"));
  1980. }
  1981. /* function to fetch stats from htc layer*/
  1982. struct ol_ath_htc_stats *ieee80211_ioctl_get_htc_stats(HTC_HANDLE HTCHandle)
  1983. {
  1984. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  1985. return &(target->htc_pkt_stats);
  1986. }