htc_send.c 63 KB

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