htc.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  1. /*
  2. * Copyright (c) 2013-2016 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 "ol_if_athvar.h"
  27. #include "htc_debug.h"
  28. #include "htc_internal.h"
  29. #include <cdf_nbuf.h> /* cdf_nbuf_t */
  30. #include <qdf_types.h> /* qdf_print */
  31. #include <hif.h>
  32. #include "epping_main.h"
  33. #include "hif_io32.h"
  34. #include "cds_concurrency.h"
  35. #include <cds_api.h>
  36. #ifdef DEBUG
  37. static ATH_DEBUG_MASK_DESCRIPTION g_htc_debug_description[] = {
  38. {ATH_DEBUG_SEND, "Send"},
  39. {ATH_DEBUG_RECV, "Recv"},
  40. {ATH_DEBUG_SYNC, "Sync"},
  41. {ATH_DEBUG_DUMP, "Dump Data (RX or TX)"},
  42. {ATH_DEBUG_SETUP, "Setup"},
  43. };
  44. ATH_DEBUG_INSTANTIATE_MODULE_VAR(htc,
  45. "htc",
  46. "Host Target Communications",
  47. ATH_DEBUG_MASK_DEFAULTS | ATH_DEBUG_INFO |
  48. ATH_DEBUG_SETUP,
  49. ATH_DEBUG_DESCRIPTION_COUNT
  50. (g_htc_debug_description),
  51. g_htc_debug_description);
  52. #endif
  53. extern unsigned int htc_credit_flow;
  54. static void reset_endpoint_states(HTC_TARGET *target);
  55. static void destroy_htc_tx_ctrl_packet(HTC_PACKET *pPacket)
  56. {
  57. cdf_nbuf_t netbuf;
  58. netbuf = (cdf_nbuf_t) GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  59. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("free ctrl netbuf :0x%p \n", netbuf));
  60. if (netbuf != NULL) {
  61. cdf_nbuf_free(netbuf);
  62. }
  63. qdf_mem_free(pPacket);
  64. }
  65. static HTC_PACKET *build_htc_tx_ctrl_packet(qdf_device_t osdev)
  66. {
  67. HTC_PACKET *pPacket = NULL;
  68. cdf_nbuf_t netbuf;
  69. do {
  70. pPacket = (HTC_PACKET *) qdf_mem_malloc(sizeof(HTC_PACKET));
  71. if (NULL == pPacket) {
  72. break;
  73. }
  74. A_MEMZERO(pPacket, sizeof(HTC_PACKET));
  75. netbuf =
  76. cdf_nbuf_alloc(osdev, HTC_CONTROL_BUFFER_SIZE, 20, 4, true);
  77. if (NULL == netbuf) {
  78. qdf_mem_free(pPacket);
  79. pPacket = NULL;
  80. qdf_print("%s: nbuf alloc failed\n", __func__);
  81. break;
  82. }
  83. AR_DEBUG_PRINTF(ATH_DEBUG_TRC,
  84. ("alloc ctrl netbuf :0x%p \n", netbuf));
  85. SET_HTC_PACKET_NET_BUF_CONTEXT(pPacket, netbuf);
  86. } while (false);
  87. return pPacket;
  88. }
  89. void htc_free_control_tx_packet(HTC_TARGET *target, HTC_PACKET *pPacket)
  90. {
  91. #ifdef TODO_FIXME
  92. LOCK_HTC(target);
  93. HTC_PACKET_ENQUEUE(&target->ControlBufferTXFreeList, pPacket);
  94. UNLOCK_HTC(target);
  95. /* TODO_FIXME netbufs cannot be RESET! */
  96. #else
  97. destroy_htc_tx_ctrl_packet(pPacket);
  98. #endif
  99. }
  100. HTC_PACKET *htc_alloc_control_tx_packet(HTC_TARGET *target)
  101. {
  102. #ifdef TODO_FIXME
  103. HTC_PACKET *pPacket;
  104. LOCK_HTC(target);
  105. pPacket = htc_packet_dequeue(&target->ControlBufferTXFreeList);
  106. UNLOCK_HTC(target);
  107. return pPacket;
  108. #else
  109. return build_htc_tx_ctrl_packet(target->osdev);
  110. #endif
  111. }
  112. /* Set the target failure handling callback */
  113. void htc_set_target_failure_callback(HTC_HANDLE HTCHandle,
  114. HTC_TARGET_FAILURE Callback)
  115. {
  116. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  117. target->HTCInitInfo.TargetFailure = Callback;
  118. }
  119. void htc_dump(HTC_HANDLE HTCHandle, uint8_t CmdId, bool start)
  120. {
  121. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  122. hif_dump(target->hif_dev, CmdId, start);
  123. }
  124. /* cleanup the HTC instance */
  125. static void htc_cleanup(HTC_TARGET *target)
  126. {
  127. HTC_PACKET *pPacket;
  128. /* cdf_nbuf_t netbuf; */
  129. if (target->hif_dev != NULL) {
  130. hif_detach_htc(target->hif_dev);
  131. target->hif_dev = NULL;
  132. }
  133. while (true) {
  134. pPacket = allocate_htc_packet_container(target);
  135. if (NULL == pPacket) {
  136. break;
  137. }
  138. qdf_mem_free(pPacket);
  139. }
  140. pPacket = target->pBundleFreeList;
  141. while (pPacket) {
  142. HTC_PACKET *pPacketTmp = (HTC_PACKET *) pPacket->ListLink.pNext;
  143. qdf_mem_free(pPacket);
  144. pPacket = pPacketTmp;
  145. }
  146. #ifdef TODO_FIXME
  147. while (true) {
  148. pPacket = htc_alloc_control_tx_packet(target);
  149. if (NULL == pPacket) {
  150. break;
  151. }
  152. netbuf = (cdf_nbuf_t) GET_HTC_PACKET_NET_BUF_CONTEXT(pPacket);
  153. if (netbuf != NULL) {
  154. cdf_nbuf_free(netbuf);
  155. }
  156. qdf_mem_free(pPacket);
  157. }
  158. #endif
  159. qdf_spinlock_destroy(&target->HTCLock);
  160. qdf_spinlock_destroy(&target->HTCRxLock);
  161. qdf_spinlock_destroy(&target->HTCTxLock);
  162. qdf_spinlock_destroy(&target->HTCCreditLock);
  163. /* free our instance */
  164. qdf_mem_free(target);
  165. }
  166. /* registered target arrival callback from the HIF layer */
  167. HTC_HANDLE htc_create(void *ol_sc, HTC_INIT_INFO *pInfo, qdf_device_t osdev)
  168. {
  169. struct hif_msg_callbacks htcCallbacks;
  170. HTC_ENDPOINT *pEndpoint = NULL;
  171. HTC_TARGET *target = NULL;
  172. int i;
  173. if (ol_sc == NULL) {
  174. HTC_ERROR("%s: ol_sc = NULL", __func__);
  175. return NULL;
  176. }
  177. HTC_TRACE("+htc_create .. HIF :%p", ol_sc);
  178. A_REGISTER_MODULE_DEBUG_INFO(htc);
  179. target = (HTC_TARGET *) qdf_mem_malloc(sizeof(HTC_TARGET));
  180. if (target == NULL) {
  181. HTC_ERROR("%s: Unable to allocate memory", __func__);
  182. return NULL;
  183. }
  184. A_MEMZERO(target, sizeof(HTC_TARGET));
  185. htc_runtime_pm_init(target);
  186. qdf_spinlock_create(&target->HTCLock);
  187. qdf_spinlock_create(&target->HTCRxLock);
  188. qdf_spinlock_create(&target->HTCTxLock);
  189. qdf_spinlock_create(&target->HTCCreditLock);
  190. do {
  191. A_MEMCPY(&target->HTCInitInfo, pInfo, sizeof(HTC_INIT_INFO));
  192. target->host_handle = pInfo->pContext;
  193. target->osdev = osdev;
  194. reset_endpoint_states(target);
  195. INIT_HTC_PACKET_QUEUE(&target->ControlBufferTXFreeList);
  196. for (i = 0; i < HTC_PACKET_CONTAINER_ALLOCATION; i++) {
  197. HTC_PACKET *pPacket =
  198. (HTC_PACKET *) qdf_mem_malloc(sizeof(HTC_PACKET));
  199. if (pPacket != NULL) {
  200. A_MEMZERO(pPacket, sizeof(HTC_PACKET));
  201. free_htc_packet_container(target, pPacket);
  202. }
  203. }
  204. #ifdef TODO_FIXME
  205. for (i = 0; i < NUM_CONTROL_TX_BUFFERS; i++) {
  206. pPacket = build_htc_tx_ctrl_packet();
  207. if (NULL == pPacket) {
  208. break;
  209. }
  210. htc_free_control_tx_packet(target, pPacket);
  211. }
  212. #endif
  213. /* setup HIF layer callbacks */
  214. qdf_mem_zero(&htcCallbacks, sizeof(struct hif_msg_callbacks));
  215. htcCallbacks.Context = target;
  216. htcCallbacks.rxCompletionHandler = htc_rx_completion_handler;
  217. htcCallbacks.txCompletionHandler = htc_tx_completion_handler;
  218. htcCallbacks.txResourceAvailHandler = htc_tx_resource_avail_handler;
  219. htcCallbacks.fwEventHandler = htc_fw_event_handler;
  220. target->hif_dev = ol_sc;
  221. /* Get HIF default pipe for HTC message exchange */
  222. pEndpoint = &target->endpoint[ENDPOINT_0];
  223. hif_post_init(target->hif_dev, target, &htcCallbacks);
  224. hif_get_default_pipe(target->hif_dev, &pEndpoint->UL_PipeID,
  225. &pEndpoint->DL_PipeID);
  226. } while (false);
  227. htc_recv_init(target);
  228. HTC_TRACE("-htc_create: (0x%p)", target);
  229. return (HTC_HANDLE) target;
  230. }
  231. void htc_destroy(HTC_HANDLE HTCHandle)
  232. {
  233. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  234. AR_DEBUG_PRINTF(ATH_DEBUG_TRC,
  235. ("+htc_destroy .. Destroying :0x%p\n", target));
  236. hif_stop(htc_get_hif_device(HTCHandle));
  237. if (target)
  238. htc_cleanup(target);
  239. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("-htc_destroy\n"));
  240. }
  241. /* get the low level HIF device for the caller , the caller may wish to do low level
  242. * HIF requests */
  243. void *htc_get_hif_device(HTC_HANDLE HTCHandle)
  244. {
  245. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  246. return target->hif_dev;
  247. }
  248. void htc_control_tx_complete(void *Context, HTC_PACKET *pPacket)
  249. {
  250. HTC_TARGET *target = (HTC_TARGET *) Context;
  251. AR_DEBUG_PRINTF(ATH_DEBUG_TRC,
  252. ("+-htc_control_tx_complete 0x%p (l:%d) \n", pPacket,
  253. pPacket->ActualLength));
  254. htc_free_control_tx_packet(target, pPacket);
  255. }
  256. /* TODO, this is just a temporary max packet size */
  257. #define MAX_MESSAGE_SIZE 1536
  258. /**
  259. * htc_setup_target_buffer_assignments() - setup target buffer assignments
  260. * @target: HTC Target Pointer
  261. *
  262. * Return: A_STATUS
  263. */
  264. A_STATUS htc_setup_target_buffer_assignments(HTC_TARGET *target)
  265. {
  266. HTC_SERVICE_TX_CREDIT_ALLOCATION *pEntry;
  267. A_STATUS status;
  268. int credits;
  269. int creditsPerMaxMsg;
  270. creditsPerMaxMsg = MAX_MESSAGE_SIZE / target->TargetCreditSize;
  271. if (MAX_MESSAGE_SIZE % target->TargetCreditSize) {
  272. creditsPerMaxMsg++;
  273. }
  274. /* TODO, this should be configured by the caller! */
  275. credits = target->TotalTransmitCredits;
  276. pEntry = &target->ServiceTxAllocTable[0];
  277. /*
  278. * Allocate all credists/HTC buffers to WMI.
  279. * no buffers are used/required for data. data always
  280. * remains on host.
  281. */
  282. status = A_OK;
  283. pEntry++;
  284. pEntry->service_id = WMI_CONTROL_SVC;
  285. pEntry->CreditAllocation = credits;
  286. if (WLAN_IS_EPPING_ENABLED(cds_get_conparam())) {
  287. /* endpoint ping is a testing tool directly on top of HTC in
  288. * both target and host sides.
  289. * In target side, the endppint ping fw has no wlan stack and the
  290. * FW mboxping app directly sits on HTC and it simply drops
  291. * or loops back TX packets. For rx perf, FW mboxping app
  292. * generates packets and passes packets to HTC to send to host.
  293. * There is no WMI mesage exchanges between host and target
  294. * in endpoint ping case.
  295. * In host side, the endpoint ping driver is a Ethernet driver
  296. * and it directly sits on HTC. Only HIF, HTC, QDF, ADF are
  297. * used by the endpoint ping driver. There is no wifi stack
  298. * at all in host side also. For tx perf use case,
  299. * the user space mboxping app sends the raw packets to endpoint
  300. * ping driver and it directly forwards to HTC for transmission
  301. * to stress the bus. For the rx perf, HTC passes the received
  302. * packets to endpoint ping driver and it is passed to the user
  303. * space through the Ethernet interface.
  304. * For credit allocation, in SDIO bus case, only BE service is
  305. * used for tx/rx perf testing so that all credits are given
  306. * to BE service. In PCIe and USB bus case, endpoint ping uses both
  307. * BE and BK services to stress the bus so that the total credits
  308. * are equally distributed to BE and BK services.
  309. */
  310. pEntry->service_id = WMI_DATA_BE_SVC;
  311. pEntry->CreditAllocation = (credits >> 1);
  312. pEntry++;
  313. pEntry->service_id = WMI_DATA_BK_SVC;
  314. pEntry->CreditAllocation = (credits >> 1);
  315. }
  316. if (A_SUCCESS(status)) {
  317. int i;
  318. for (i = 0; i < HTC_MAX_SERVICE_ALLOC_ENTRIES; i++) {
  319. if (target->ServiceTxAllocTable[i].service_id != 0) {
  320. AR_DEBUG_PRINTF(ATH_DEBUG_INIT,
  321. ("HTC Service Index : %d TX : 0x%2.2X : alloc:%d\n",
  322. i,
  323. target->ServiceTxAllocTable[i].
  324. service_id,
  325. target->ServiceTxAllocTable[i].
  326. CreditAllocation));
  327. }
  328. }
  329. }
  330. return status;
  331. }
  332. A_UINT8 htc_get_credit_allocation(HTC_TARGET *target, A_UINT16 service_id)
  333. {
  334. A_UINT8 allocation = 0;
  335. int i;
  336. for (i = 0; i < HTC_MAX_SERVICE_ALLOC_ENTRIES; i++) {
  337. if (target->ServiceTxAllocTable[i].service_id == service_id) {
  338. allocation =
  339. target->ServiceTxAllocTable[i].CreditAllocation;
  340. }
  341. }
  342. if (0 == allocation) {
  343. AR_DEBUG_PRINTF(ATH_DEBUG_INIT,
  344. ("HTC Service TX : 0x%2.2X : allocation is zero!\n",
  345. service_id));
  346. }
  347. return allocation;
  348. }
  349. A_STATUS htc_wait_target(HTC_HANDLE HTCHandle)
  350. {
  351. A_STATUS status = A_OK;
  352. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  353. HTC_READY_EX_MSG *pReadyMsg;
  354. HTC_SERVICE_CONNECT_REQ connect;
  355. HTC_SERVICE_CONNECT_RESP resp;
  356. HTC_READY_MSG *rdy_msg;
  357. A_UINT16 htc_rdy_msg_id;
  358. AR_DEBUG_PRINTF(ATH_DEBUG_TRC,
  359. ("htc_wait_target - Enter (target:0x%p) \n", HTCHandle));
  360. AR_DEBUG_PRINTF(ATH_DEBUG_ANY, ("+HWT\n"));
  361. do {
  362. status = hif_start(target->hif_dev);
  363. if (A_FAILED(status)) {
  364. AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, ("hif_start failed\n"));
  365. break;
  366. }
  367. status = htc_wait_recv_ctrl_message(target);
  368. if (A_FAILED(status)) {
  369. break;
  370. }
  371. if (target->CtrlResponseLength < (sizeof(HTC_READY_EX_MSG))) {
  372. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  373. ("Invalid HTC Ready Msg Len:%d! \n",
  374. target->CtrlResponseLength));
  375. status = A_ECOMM;
  376. break;
  377. }
  378. pReadyMsg = (HTC_READY_EX_MSG *) target->CtrlResponseBuffer;
  379. rdy_msg = &pReadyMsg->Version2_0_Info;
  380. htc_rdy_msg_id =
  381. HTC_GET_FIELD(rdy_msg, HTC_READY_MSG, MESSAGEID);
  382. if (htc_rdy_msg_id != HTC_MSG_READY_ID) {
  383. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  384. ("Invalid HTC Ready Msg : 0x%X ! \n",
  385. htc_rdy_msg_id));
  386. status = A_ECOMM;
  387. break;
  388. }
  389. target->TotalTransmitCredits =
  390. HTC_GET_FIELD(rdy_msg, HTC_READY_MSG, CREDITCOUNT);
  391. target->TargetCreditSize =
  392. (int)HTC_GET_FIELD(rdy_msg, HTC_READY_MSG, CREDITSIZE);
  393. target->MaxMsgsPerHTCBundle =
  394. (A_UINT8) pReadyMsg->MaxMsgsPerHTCBundle;
  395. /* for old fw this value is set to 0. But the minimum value should be 1,
  396. * i.e., no bundling */
  397. if (target->MaxMsgsPerHTCBundle < 1)
  398. target->MaxMsgsPerHTCBundle = 1;
  399. AR_DEBUG_PRINTF(ATH_DEBUG_INIT,
  400. ("Target Ready! : transmit resources : %d size:%d, MaxMsgsPerHTCBundle = %d\n",
  401. target->TotalTransmitCredits,
  402. target->TargetCreditSize,
  403. target->MaxMsgsPerHTCBundle));
  404. if ((0 == target->TotalTransmitCredits)
  405. || (0 == target->TargetCreditSize)) {
  406. status = A_ECOMM;
  407. break;
  408. }
  409. /* done processing */
  410. target->CtrlResponseProcessing = false;
  411. htc_setup_target_buffer_assignments(target);
  412. /* setup our pseudo HTC control endpoint connection */
  413. A_MEMZERO(&connect, sizeof(connect));
  414. A_MEMZERO(&resp, sizeof(resp));
  415. connect.EpCallbacks.pContext = target;
  416. connect.EpCallbacks.EpTxComplete = htc_control_tx_complete;
  417. connect.EpCallbacks.EpRecv = htc_control_rx_complete;
  418. connect.MaxSendQueueDepth = NUM_CONTROL_TX_BUFFERS;
  419. connect.service_id = HTC_CTRL_RSVD_SVC;
  420. /* connect fake service */
  421. status = htc_connect_service((HTC_HANDLE) target,
  422. &connect, &resp);
  423. } while (false);
  424. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("htc_wait_target - Exit (%d)\n", status));
  425. AR_DEBUG_PRINTF(ATH_DEBUG_ANY, ("-HWT\n"));
  426. return status;
  427. }
  428. /* start HTC, this is called after all services are connected */
  429. static A_STATUS htc_config_target_hif_pipe(HTC_TARGET *target)
  430. {
  431. return A_OK;
  432. }
  433. static void reset_endpoint_states(HTC_TARGET *target)
  434. {
  435. HTC_ENDPOINT *pEndpoint;
  436. int i;
  437. for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) {
  438. pEndpoint = &target->endpoint[i];
  439. pEndpoint->service_id = 0;
  440. pEndpoint->MaxMsgLength = 0;
  441. pEndpoint->MaxTxQueueDepth = 0;
  442. pEndpoint->Id = i;
  443. INIT_HTC_PACKET_QUEUE(&pEndpoint->TxQueue);
  444. INIT_HTC_PACKET_QUEUE(&pEndpoint->TxLookupQueue);
  445. INIT_HTC_PACKET_QUEUE(&pEndpoint->RxBufferHoldQueue);
  446. pEndpoint->target = target;
  447. /* pEndpoint->TxCreditFlowEnabled = (A_BOOL)htc_credit_flow; */
  448. pEndpoint->TxCreditFlowEnabled = (A_BOOL) 1;
  449. qdf_atomic_init(&pEndpoint->TxProcessCount);
  450. }
  451. }
  452. A_STATUS htc_start(HTC_HANDLE HTCHandle)
  453. {
  454. cdf_nbuf_t netbuf;
  455. A_STATUS status = A_OK;
  456. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  457. HTC_SETUP_COMPLETE_EX_MSG *pSetupComp;
  458. HTC_PACKET *pSendPacket;
  459. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("htc_start Enter\n"));
  460. do {
  461. htc_config_target_hif_pipe(target);
  462. /* allocate a buffer to send */
  463. pSendPacket = htc_alloc_control_tx_packet(target);
  464. if (NULL == pSendPacket) {
  465. AR_DEBUG_ASSERT(false);
  466. qdf_print("%s: allocControlTxPacket failed\n",
  467. __func__);
  468. status = A_NO_MEMORY;
  469. break;
  470. }
  471. netbuf =
  472. (cdf_nbuf_t) GET_HTC_PACKET_NET_BUF_CONTEXT(pSendPacket);
  473. /* assemble setup complete message */
  474. cdf_nbuf_put_tail(netbuf, sizeof(HTC_SETUP_COMPLETE_EX_MSG));
  475. pSetupComp =
  476. (HTC_SETUP_COMPLETE_EX_MSG *) cdf_nbuf_data(netbuf);
  477. A_MEMZERO(pSetupComp, sizeof(HTC_SETUP_COMPLETE_EX_MSG));
  478. HTC_SET_FIELD(pSetupComp, HTC_SETUP_COMPLETE_EX_MSG,
  479. MESSAGEID, HTC_MSG_SETUP_COMPLETE_EX_ID);
  480. if (!htc_credit_flow) {
  481. AR_DEBUG_PRINTF(ATH_DEBUG_INIT,
  482. ("HTC will not use TX credit flow control\n"));
  483. pSetupComp->SetupFlags |=
  484. HTC_SETUP_COMPLETE_FLAGS_DISABLE_TX_CREDIT_FLOW;
  485. } else {
  486. AR_DEBUG_PRINTF(ATH_DEBUG_INIT,
  487. ("HTC using TX credit flow control\n"));
  488. }
  489. #ifdef HIF_SDIO
  490. #if ENABLE_BUNDLE_RX
  491. if (HTC_ENABLE_BUNDLE(target))
  492. pSetupComp->SetupFlags |=
  493. HTC_SETUP_COMPLETE_FLAGS_ENABLE_BUNDLE_RECV;
  494. #endif /* ENABLE_BUNDLE_RX */
  495. #endif /* HIF_SDIO */
  496. SET_HTC_PACKET_INFO_TX(pSendPacket,
  497. NULL,
  498. (A_UINT8 *) pSetupComp,
  499. sizeof(HTC_SETUP_COMPLETE_EX_MSG),
  500. ENDPOINT_0, HTC_SERVICE_TX_PACKET_TAG);
  501. status = htc_send_pkt((HTC_HANDLE) target, pSendPacket);
  502. if (A_FAILED(status)) {
  503. break;
  504. }
  505. } while (false);
  506. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("htc_start Exit\n"));
  507. return status;
  508. }
  509. /*flush all queued buffers for surpriseremove case*/
  510. void htc_flush_surprise_remove(HTC_HANDLE HTCHandle)
  511. {
  512. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  513. int i;
  514. HTC_ENDPOINT *pEndpoint;
  515. #ifdef RX_SG_SUPPORT
  516. cdf_nbuf_t netbuf;
  517. cdf_nbuf_queue_t *rx_sg_queue = &target->RxSgQueue;
  518. #endif
  519. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("+htc_flush_surprise_remove \n"));
  520. /* cleanup endpoints */
  521. for (i = 0; i < ENDPOINT_MAX; i++) {
  522. pEndpoint = &target->endpoint[i];
  523. htc_flush_rx_hold_queue(target, pEndpoint);
  524. htc_flush_endpoint_tx(target, pEndpoint, HTC_TX_PACKET_TAG_ALL);
  525. }
  526. hif_flush_surprise_remove(target->hif_dev);
  527. #ifdef RX_SG_SUPPORT
  528. LOCK_HTC_RX(target);
  529. while ((netbuf = cdf_nbuf_queue_remove(rx_sg_queue)) != NULL) {
  530. cdf_nbuf_free(netbuf);
  531. }
  532. RESET_RX_SG_CONFIG(target);
  533. UNLOCK_HTC_RX(target);
  534. #endif
  535. reset_endpoint_states(target);
  536. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("-htc_flush_surprise_remove \n"));
  537. }
  538. /* stop HTC communications, i.e. stop interrupt reception, and flush all queued buffers */
  539. void htc_stop(HTC_HANDLE HTCHandle)
  540. {
  541. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  542. int i;
  543. HTC_ENDPOINT *pEndpoint;
  544. #ifdef RX_SG_SUPPORT
  545. cdf_nbuf_t netbuf;
  546. cdf_nbuf_queue_t *rx_sg_queue = &target->RxSgQueue;
  547. #endif
  548. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("+htc_stop \n"));
  549. /* cleanup endpoints */
  550. for (i = 0; i < ENDPOINT_MAX; i++) {
  551. pEndpoint = &target->endpoint[i];
  552. htc_flush_rx_hold_queue(target, pEndpoint);
  553. htc_flush_endpoint_tx(target, pEndpoint, HTC_TX_PACKET_TAG_ALL);
  554. if (pEndpoint->ul_is_polled) {
  555. qdf_timer_stop(&pEndpoint->ul_poll_timer);
  556. qdf_timer_free(&pEndpoint->ul_poll_timer);
  557. }
  558. }
  559. /* Note: htc_flush_endpoint_tx for all endpoints should be called before
  560. * hif_stop - otherwise htc_tx_completion_handler called from
  561. * hif_send_buffer_cleanup_on_pipe for residual tx frames in HIF layer,
  562. * might queue the packet again to HIF Layer - which could cause tx
  563. * buffer leak
  564. */
  565. hif_stop(target->hif_dev);
  566. #ifdef RX_SG_SUPPORT
  567. LOCK_HTC_RX(target);
  568. while ((netbuf = cdf_nbuf_queue_remove(rx_sg_queue)) != NULL) {
  569. cdf_nbuf_free(netbuf);
  570. }
  571. RESET_RX_SG_CONFIG(target);
  572. UNLOCK_HTC_RX(target);
  573. #endif
  574. reset_endpoint_states(target);
  575. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("-htc_stop\n"));
  576. }
  577. /**
  578. * htc_runtime_pm_init(): runtime pm related intialization
  579. *
  580. * need to initialize a work item.
  581. */
  582. void htc_runtime_pm_init(HTC_TARGET *target)
  583. {
  584. qdf_create_work(0, &target->queue_kicker, htc_kick_queues, target);
  585. }
  586. /**
  587. * htc_runtime_suspend(): ensure htc is ready to suspend
  588. *
  589. * htc is ready to suspend if there are no pending pactets
  590. * in the txrx queues.
  591. *
  592. * Return: 0 on success or -EBUSY if there are queued packets.
  593. */
  594. int htc_runtime_suspend(void)
  595. {
  596. ol_txrx_pdev_handle txrx_pdev = cds_get_context(QDF_MODULE_ID_TXRX);
  597. if (txrx_pdev == NULL) {
  598. HTC_ERROR("%s: txrx context null", __func__);
  599. return QDF_STATUS_E_FAULT;
  600. }
  601. if (ol_txrx_get_tx_pending(txrx_pdev))
  602. return -EBUSY;
  603. else
  604. return 0;
  605. }
  606. /**
  607. * htc_runtime_resume(): resume htc
  608. *
  609. * The htc message queue needs to be kicked off after
  610. * a runtime resume. Otherwise messages would get stuck.
  611. *
  612. * Return: 0 for success;
  613. */
  614. int htc_runtime_resume(void)
  615. {
  616. HTC_HANDLE htc_ctx = cds_get_context(QDF_MODULE_ID_HTC);
  617. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_ctx);
  618. if (target == NULL)
  619. return 0;
  620. qdf_sched_work(0, &target->queue_kicker);
  621. return 0;
  622. }
  623. void htc_dump_credit_states(HTC_HANDLE HTCHandle)
  624. {
  625. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  626. HTC_ENDPOINT *pEndpoint;
  627. int i;
  628. for (i = 0; i < ENDPOINT_MAX; i++) {
  629. pEndpoint = &target->endpoint[i];
  630. if (0 == pEndpoint->service_id)
  631. continue;
  632. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  633. ("--- EP : %d service_id: 0x%X --------------\n",
  634. pEndpoint->Id, pEndpoint->service_id));
  635. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  636. (" TxCredits : %d\n",
  637. pEndpoint->TxCredits));
  638. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  639. (" TxCreditSize : %d\n",
  640. pEndpoint->TxCreditSize));
  641. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  642. (" TxCreditsPerMaxMsg : %d\n",
  643. pEndpoint->TxCreditsPerMaxMsg));
  644. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  645. (" TxQueueDepth : %d\n",
  646. HTC_PACKET_QUEUE_DEPTH(&pEndpoint->TxQueue)));
  647. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  648. ("----------------------------------------------------\n"));
  649. }
  650. }
  651. A_BOOL htc_get_endpoint_statistics(HTC_HANDLE HTCHandle,
  652. HTC_ENDPOINT_ID Endpoint,
  653. HTC_ENDPOINT_STAT_ACTION Action,
  654. HTC_ENDPOINT_STATS *pStats)
  655. {
  656. #ifdef HTC_EP_STAT_PROFILING
  657. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  658. A_BOOL clearStats = false;
  659. A_BOOL sample = false;
  660. switch (Action) {
  661. case HTC_EP_STAT_SAMPLE:
  662. sample = true;
  663. break;
  664. case HTC_EP_STAT_SAMPLE_AND_CLEAR:
  665. sample = true;
  666. clearStats = true;
  667. break;
  668. case HTC_EP_STAT_CLEAR:
  669. clearStats = true;
  670. break;
  671. default:
  672. break;
  673. }
  674. A_ASSERT(Endpoint < ENDPOINT_MAX);
  675. /* lock out TX and RX while we sample and/or clear */
  676. LOCK_HTC_TX(target);
  677. LOCK_HTC_RX(target);
  678. if (sample) {
  679. A_ASSERT(pStats != NULL);
  680. /* return the stats to the caller */
  681. A_MEMCPY(pStats, &target->endpoint[Endpoint].endpoint_stats,
  682. sizeof(HTC_ENDPOINT_STATS));
  683. }
  684. if (clearStats) {
  685. /* reset stats */
  686. A_MEMZERO(&target->endpoint[Endpoint].endpoint_stats,
  687. sizeof(HTC_ENDPOINT_STATS));
  688. }
  689. UNLOCK_HTC_RX(target);
  690. UNLOCK_HTC_TX(target);
  691. return true;
  692. #else
  693. return false;
  694. #endif
  695. }
  696. void *htc_get_targetdef(HTC_HANDLE htc_handle)
  697. {
  698. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
  699. return hif_get_targetdef(target->hif_dev);
  700. }
  701. /**
  702. * htc_set_target_to_sleep() - set target to sleep
  703. * @context: hif_opaque_softc context
  704. *
  705. * Return: none
  706. */
  707. void htc_set_target_to_sleep(void *context)
  708. {
  709. struct hif_opaque_softc *scn = (struct hif_opaque_softc *)context;
  710. hif_set_target_sleep(scn, true, false);
  711. }
  712. /**
  713. * htc_cancel_deferred_target_sleep() - cancel deferred target sleep
  714. * @context: hif_opaque_softc context
  715. *
  716. * Return: none
  717. */
  718. void htc_cancel_deferred_target_sleep(void *context)
  719. {
  720. struct hif_opaque_softc *scn = (struct hif_opaque_softc *)context;
  721. hif_cancel_deferred_target_sleep(scn);
  722. }
  723. #ifdef IPA_OFFLOAD
  724. /**
  725. * htc_ipa_get_ce_resource() - get uc resource on lower layer
  726. * @htc_handle: htc context
  727. * @ce_sr_base_paddr: copyengine source ring base physical address
  728. * @ce_sr_ring_size: copyengine source ring size
  729. * @ce_reg_paddr: copyengine register physical address
  730. *
  731. * Return: None
  732. */
  733. void htc_ipa_get_ce_resource(HTC_HANDLE htc_handle,
  734. qdf_dma_addr_t *ce_sr_base_paddr,
  735. uint32_t *ce_sr_ring_size,
  736. qdf_dma_addr_t *ce_reg_paddr)
  737. {
  738. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
  739. if (target->hif_dev != NULL) {
  740. hif_ipa_get_ce_resource(target->hif_dev,
  741. ce_sr_base_paddr,
  742. ce_sr_ring_size, ce_reg_paddr);
  743. }
  744. }
  745. #endif /* IPA_OFFLOAD */
  746. /**
  747. * htc_vote_link_down - API to vote for link down
  748. * @htc_handle: HTC handle
  749. *
  750. * API for upper layers to call HIF to vote for link down
  751. *
  752. * Return: void
  753. */
  754. void htc_vote_link_down(HTC_HANDLE htc_handle)
  755. {
  756. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
  757. if (!target->hif_dev)
  758. return;
  759. hif_vote_link_down(target->hif_dev);
  760. }
  761. /**
  762. * htc_vote_link_up - API to vote for link up
  763. * @htc_handle: HTC Handle
  764. *
  765. * API for upper layers to call HIF to vote for link up
  766. *
  767. * Return: void
  768. */
  769. void htc_vote_link_up(HTC_HANDLE htc_handle)
  770. {
  771. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
  772. if (!target->hif_dev)
  773. return;
  774. hif_vote_link_up(target->hif_dev);
  775. }
  776. /**
  777. * htc_can_suspend_link - API to query HIF for link status
  778. * @htc_handle: HTC Handle
  779. *
  780. * API for upper layers to call HIF to query if the link can suspend
  781. *
  782. * Return: void
  783. */
  784. bool htc_can_suspend_link(HTC_HANDLE htc_handle)
  785. {
  786. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(htc_handle);
  787. if (!target->hif_dev)
  788. return false;
  789. return hif_can_suspend_link(target->hif_dev);
  790. }