htc_services.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. /*
  2. * Copyright (c) 2013-2018 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #include "htc_debug.h"
  19. #include "htc_internal.h"
  20. #include <hif.h>
  21. #include <qdf_nbuf.h> /* qdf_nbuf_t */
  22. #include "qdf_module.h"
  23. /* use credit flow control over HTC */
  24. unsigned int htc_credit_flow = 1;
  25. #ifndef DEBUG_CREDIT
  26. #define DEBUG_CREDIT 0
  27. #endif
  28. /* HTC credit flow global disable */
  29. void htc_global_credit_flow_disable(void)
  30. {
  31. htc_credit_flow = 0;
  32. }
  33. /* HTC credit flow global enable */
  34. void htc_global_credit_flow_enable(void)
  35. {
  36. htc_credit_flow = 1;
  37. }
  38. #ifdef HIF_SDIO
  39. /**
  40. * htc_alt_data_credit_size_update() - update tx credit size info
  41. * on max bundle size
  42. * @target: hif context
  43. * @ul_pipe: endpoint ul pipe id
  44. * @dl_pipe: endpoint dl pipe id
  45. * @txCreditSize: endpoint tx credit size
  46. *
  47. *
  48. * When AltDataCreditSize is non zero, it indicates the credit size for
  49. * HTT and all other services on Mbox0. Mbox1 has WMI_CONTROL_SVC which
  50. * uses the default credit size. Use AltDataCreditSize only when
  51. * mailbox is swapped. Mailbox swap bit is set by bmi_target_ready at
  52. * the end of BMI phase.
  53. *
  54. * The Credit Size is a parameter associated with the mbox rather than
  55. * a service. Multiple services can run on this mbox.
  56. *
  57. * If AltDataCreditSize is 0, that means the firmware doesn't support
  58. * this feature. Default to the TargetCreditSize
  59. *
  60. * Return: None
  61. */
  62. static inline void
  63. htc_alt_data_credit_size_update(HTC_TARGET *target,
  64. uint8_t *ul_pipe,
  65. uint8_t *dl_pipe,
  66. int *txCreditSize)
  67. {
  68. if ((target->AltDataCreditSize) &&
  69. (*ul_pipe == 1) && (*dl_pipe == 0))
  70. *txCreditSize = target->AltDataCreditSize;
  71. }
  72. #else
  73. static inline void
  74. htc_alt_data_credit_size_update(HTC_TARGET *target,
  75. uint8_t *ul_pipe,
  76. uint8_t *dl_pipe,
  77. int *txCreditSize)
  78. {
  79. }
  80. #endif
  81. QDF_STATUS htc_connect_service(HTC_HANDLE HTCHandle,
  82. struct htc_service_connect_req *pConnectReq,
  83. struct htc_service_connect_resp *pConnectResp)
  84. {
  85. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  86. QDF_STATUS status = QDF_STATUS_SUCCESS;
  87. HTC_PACKET *pSendPacket = NULL;
  88. HTC_CONNECT_SERVICE_RESPONSE_MSG *pResponseMsg;
  89. HTC_CONNECT_SERVICE_MSG *pConnectMsg;
  90. HTC_ENDPOINT_ID assignedEndpoint = ENDPOINT_MAX;
  91. HTC_ENDPOINT *pEndpoint;
  92. unsigned int maxMsgSize = 0;
  93. qdf_nbuf_t netbuf;
  94. uint8_t txAlloc;
  95. int length;
  96. bool disableCreditFlowCtrl = false;
  97. uint16_t conn_flags;
  98. uint16_t rsp_msg_id, rsp_msg_serv_id, rsp_msg_max_msg_size;
  99. uint8_t rsp_msg_status, rsp_msg_end_id, rsp_msg_serv_meta_len;
  100. AR_DEBUG_PRINTF(ATH_DEBUG_TRC,
  101. ("+htc_connect_service, target:%pK SvcID:0x%X\n", target,
  102. pConnectReq->service_id));
  103. do {
  104. AR_DEBUG_ASSERT(pConnectReq->service_id != 0);
  105. if (HTC_CTRL_RSVD_SVC == pConnectReq->service_id) {
  106. /* special case for pseudo control service */
  107. assignedEndpoint = ENDPOINT_0;
  108. maxMsgSize = HTC_MAX_CONTROL_MESSAGE_LENGTH;
  109. txAlloc = 0;
  110. } else {
  111. txAlloc = htc_get_credit_allocation(target,
  112. pConnectReq->service_id);
  113. if (!txAlloc) {
  114. AR_DEBUG_PRINTF(ATH_DEBUG_TRC,
  115. ("Service %d does not allocate target credits!\n",
  116. pConnectReq->service_id));
  117. }
  118. /* allocate a packet to send to the target */
  119. pSendPacket = htc_alloc_control_tx_packet(target);
  120. if (NULL == pSendPacket) {
  121. AR_DEBUG_ASSERT(false);
  122. status = QDF_STATUS_E_NOMEM;
  123. break;
  124. }
  125. netbuf =
  126. (qdf_nbuf_t)
  127. GET_HTC_PACKET_NET_BUF_CONTEXT(pSendPacket);
  128. length =
  129. sizeof(HTC_CONNECT_SERVICE_MSG) +
  130. pConnectReq->MetaDataLength;
  131. /* assemble connect service message */
  132. qdf_nbuf_put_tail(netbuf, length);
  133. pConnectMsg =
  134. (HTC_CONNECT_SERVICE_MSG *) qdf_nbuf_data(netbuf);
  135. if (NULL == pConnectMsg) {
  136. AR_DEBUG_ASSERT(0);
  137. status = QDF_STATUS_E_FAULT;
  138. break;
  139. }
  140. qdf_mem_zero(pConnectMsg,
  141. sizeof(HTC_CONNECT_SERVICE_MSG));
  142. conn_flags =
  143. (pConnectReq->
  144. ConnectionFlags & ~HTC_SET_RECV_ALLOC_MASK) |
  145. HTC_CONNECT_FLAGS_SET_RECV_ALLOCATION(txAlloc);
  146. HTC_SET_FIELD(pConnectMsg, HTC_CONNECT_SERVICE_MSG,
  147. MESSAGEID, HTC_MSG_CONNECT_SERVICE_ID);
  148. HTC_SET_FIELD(pConnectMsg, HTC_CONNECT_SERVICE_MSG,
  149. SERVICE_ID, pConnectReq->service_id);
  150. HTC_SET_FIELD(pConnectMsg, HTC_CONNECT_SERVICE_MSG,
  151. CONNECTIONFLAGS, conn_flags);
  152. if (pConnectReq->
  153. ConnectionFlags &
  154. HTC_CONNECT_FLAGS_DISABLE_CREDIT_FLOW_CTRL) {
  155. disableCreditFlowCtrl = true;
  156. }
  157. if (!htc_credit_flow)
  158. disableCreditFlowCtrl = true;
  159. /* check caller if it wants to transfer meta data */
  160. if ((pConnectReq->pMetaData != NULL) &&
  161. (pConnectReq->MetaDataLength <=
  162. HTC_SERVICE_META_DATA_MAX_LENGTH)) {
  163. /* copy meta data into msg buffer (after hdr) */
  164. qdf_mem_copy((uint8_t *) pConnectMsg +
  165. sizeof(HTC_CONNECT_SERVICE_MSG),
  166. pConnectReq->pMetaData,
  167. pConnectReq->MetaDataLength);
  168. HTC_SET_FIELD(pConnectMsg,
  169. HTC_CONNECT_SERVICE_MSG,
  170. SERVICEMETALENGTH,
  171. pConnectReq->MetaDataLength);
  172. }
  173. SET_HTC_PACKET_INFO_TX(pSendPacket,
  174. NULL,
  175. (uint8_t *) pConnectMsg,
  176. length,
  177. ENDPOINT_0,
  178. HTC_SERVICE_TX_PACKET_TAG);
  179. status = htc_send_pkt((HTC_HANDLE) target, pSendPacket);
  180. /* we don't own it anymore */
  181. pSendPacket = NULL;
  182. if (QDF_IS_STATUS_ERROR(status))
  183. break;
  184. /* wait for response */
  185. status = htc_wait_recv_ctrl_message(target);
  186. if (QDF_IS_STATUS_ERROR(status))
  187. break;
  188. /* we controlled the buffer creation so it has to be
  189. * properly aligned
  190. */
  191. pResponseMsg =
  192. (HTC_CONNECT_SERVICE_RESPONSE_MSG *) target->
  193. CtrlResponseBuffer;
  194. rsp_msg_id = HTC_GET_FIELD(pResponseMsg,
  195. HTC_CONNECT_SERVICE_RESPONSE_MSG,
  196. MESSAGEID);
  197. rsp_msg_serv_id =
  198. HTC_GET_FIELD(pResponseMsg,
  199. HTC_CONNECT_SERVICE_RESPONSE_MSG,
  200. SERVICEID);
  201. rsp_msg_status =
  202. HTC_GET_FIELD(pResponseMsg,
  203. HTC_CONNECT_SERVICE_RESPONSE_MSG,
  204. STATUS);
  205. rsp_msg_end_id =
  206. HTC_GET_FIELD(pResponseMsg,
  207. HTC_CONNECT_SERVICE_RESPONSE_MSG,
  208. ENDPOINTID);
  209. rsp_msg_max_msg_size =
  210. HTC_GET_FIELD(pResponseMsg,
  211. HTC_CONNECT_SERVICE_RESPONSE_MSG,
  212. MAXMSGSIZE);
  213. rsp_msg_serv_meta_len =
  214. HTC_GET_FIELD(pResponseMsg,
  215. HTC_CONNECT_SERVICE_RESPONSE_MSG,
  216. SERVICEMETALENGTH);
  217. if ((rsp_msg_id != HTC_MSG_CONNECT_SERVICE_RESPONSE_ID)
  218. || (target->CtrlResponseLength <
  219. sizeof(HTC_CONNECT_SERVICE_RESPONSE_MSG))) {
  220. /* this message is not valid */
  221. AR_DEBUG_ASSERT(false);
  222. status = QDF_STATUS_E_PROTO;
  223. break;
  224. }
  225. AR_DEBUG_PRINTF(ATH_DEBUG_TRC,
  226. ("htc_connect_service, service 0x%X connect response from target status:%d, assigned ep: %d\n",
  227. rsp_msg_serv_id, rsp_msg_status,
  228. rsp_msg_end_id));
  229. pConnectResp->ConnectRespCode = rsp_msg_status;
  230. /* check response status */
  231. if (rsp_msg_status != HTC_SERVICE_SUCCESS) {
  232. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  233. (" Target failed service 0x%X connect request (status:%d)\n",
  234. rsp_msg_serv_id,
  235. rsp_msg_status));
  236. status = QDF_STATUS_E_PROTO;
  237. /* TODO: restore the ifdef when FW supports services 301 and 302
  238. * (HTT_MSG_DATA[23]_MSG_SVC)
  239. */
  240. /* #ifdef QCA_TX_HTT2_SUPPORT */
  241. /* Keep work and not to block the control msg */
  242. target->CtrlResponseProcessing = false;
  243. /* #endif */ /* QCA_TX_HTT2_SUPPORT */
  244. break;
  245. }
  246. assignedEndpoint = (HTC_ENDPOINT_ID) rsp_msg_end_id;
  247. maxMsgSize = rsp_msg_max_msg_size;
  248. if ((pConnectResp->pMetaData != NULL) &&
  249. (rsp_msg_serv_meta_len > 0) &&
  250. (rsp_msg_serv_meta_len <=
  251. HTC_SERVICE_META_DATA_MAX_LENGTH)) {
  252. /* caller supplied a buffer and the target
  253. * responded with data
  254. */
  255. int copyLength =
  256. min((int)pConnectResp->BufferLength,
  257. (int)rsp_msg_serv_meta_len);
  258. /* copy the meta data */
  259. qdf_mem_copy(pConnectResp->pMetaData,
  260. ((uint8_t *) pResponseMsg) +
  261. sizeof
  262. (HTC_CONNECT_SERVICE_RESPONSE_MSG),
  263. copyLength);
  264. pConnectResp->ActualLength = copyLength;
  265. }
  266. /* done processing response buffer */
  267. target->CtrlResponseProcessing = false;
  268. }
  269. /* rest of these are parameter checks so set the error status */
  270. status = QDF_STATUS_E_PROTO;
  271. if (assignedEndpoint >= ENDPOINT_MAX) {
  272. AR_DEBUG_ASSERT(false);
  273. break;
  274. }
  275. if (0 == maxMsgSize) {
  276. AR_DEBUG_ASSERT(false);
  277. break;
  278. }
  279. pEndpoint = &target->endpoint[assignedEndpoint];
  280. pEndpoint->Id = assignedEndpoint;
  281. if (pEndpoint->service_id != 0) {
  282. /* endpoint already in use! */
  283. AR_DEBUG_ASSERT(false);
  284. break;
  285. }
  286. /* return assigned endpoint to caller */
  287. pConnectResp->Endpoint = assignedEndpoint;
  288. pConnectResp->MaxMsgLength = maxMsgSize;
  289. /* setup the endpoint */
  290. /* service_id marks the endpoint in use */
  291. pEndpoint->service_id = pConnectReq->service_id;
  292. pEndpoint->MaxTxQueueDepth = pConnectReq->MaxSendQueueDepth;
  293. pEndpoint->MaxMsgLength = maxMsgSize;
  294. pEndpoint->TxCredits = txAlloc;
  295. pEndpoint->TxCreditSize = target->TargetCreditSize;
  296. pEndpoint->TxCreditsPerMaxMsg =
  297. maxMsgSize / target->TargetCreditSize;
  298. if (maxMsgSize % target->TargetCreditSize)
  299. pEndpoint->TxCreditsPerMaxMsg++;
  300. #if DEBUG_CREDIT
  301. qdf_print(" Endpoint%d initial credit:%d, size:%d.\n",
  302. pEndpoint->Id, pEndpoint->TxCredits,
  303. pEndpoint->TxCreditSize);
  304. #endif
  305. /* copy all the callbacks */
  306. pEndpoint->EpCallBacks = pConnectReq->EpCallbacks;
  307. pEndpoint->async_update = 0;
  308. status = hif_map_service_to_pipe(target->hif_dev,
  309. pEndpoint->service_id,
  310. &pEndpoint->UL_PipeID,
  311. &pEndpoint->DL_PipeID,
  312. &pEndpoint->ul_is_polled,
  313. &pEndpoint->dl_is_polled);
  314. if (QDF_IS_STATUS_ERROR(status))
  315. break;
  316. htc_alt_data_credit_size_update(target,
  317. &pEndpoint->UL_PipeID,
  318. &pEndpoint->DL_PipeID,
  319. &pEndpoint->TxCreditSize);
  320. /* not currently supported */
  321. qdf_assert(!pEndpoint->dl_is_polled);
  322. if (pEndpoint->ul_is_polled) {
  323. qdf_timer_init(target->osdev,
  324. &pEndpoint->ul_poll_timer,
  325. htc_send_complete_check_cleanup,
  326. pEndpoint,
  327. QDF_TIMER_TYPE_SW);
  328. }
  329. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,
  330. ("SVC:0x%4.4X, ULpipe:%d DLpipe:%d id:%d Ready",
  331. pEndpoint->service_id, pEndpoint->UL_PipeID,
  332. pEndpoint->DL_PipeID, pEndpoint->Id));
  333. if (disableCreditFlowCtrl && pEndpoint->TxCreditFlowEnabled) {
  334. pEndpoint->TxCreditFlowEnabled = false;
  335. AR_DEBUG_PRINTF(ATH_DEBUG_INFO,
  336. ("SVC:0x%4.4X ep:%d TX flow control disabled",
  337. pEndpoint->service_id,
  338. assignedEndpoint));
  339. }
  340. } while (false);
  341. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("-htc_connect_service\n"));
  342. return status;
  343. }
  344. qdf_export_symbol(htc_connect_service);
  345. void htc_set_credit_distribution(HTC_HANDLE HTCHandle,
  346. void *pCreditDistContext,
  347. HTC_CREDIT_DIST_CALLBACK CreditDistFunc,
  348. HTC_CREDIT_INIT_CALLBACK CreditInitFunc,
  349. HTC_SERVICE_ID ServicePriorityOrder[],
  350. int ListLength)
  351. {
  352. /* NOT Supported, this transport does not use a credit based flow
  353. * control mechanism
  354. */
  355. }
  356. void htc_fw_event_handler(void *context, QDF_STATUS status)
  357. {
  358. HTC_TARGET *target = (HTC_TARGET *) context;
  359. struct htc_init_info *initInfo = &target->HTCInitInfo;
  360. /* check if target failure handler exists and pass error code to it. */
  361. if (target->HTCInitInfo.TargetFailure != NULL)
  362. initInfo->TargetFailure(initInfo->pContext, status);
  363. }
  364. void htc_set_async_ep(HTC_HANDLE HTCHandle,
  365. HTC_ENDPOINT_ID htc_ep_id, bool value)
  366. {
  367. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  368. HTC_ENDPOINT *pEndpoint = &target->endpoint[htc_ep_id];
  369. pEndpoint->async_update = value;
  370. qdf_print("%s: htc_handle %pK, ep %d, value %d\n", __func__,
  371. HTCHandle, htc_ep_id, value);
  372. }