htc_recv.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. /*
  2. * Copyright (c) 2013-2019 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 "htc_credit_history.h"
  21. #include <qdf_nbuf.h> /* qdf_nbuf_t */
  22. /* HTC Control message receive timeout msec */
  23. #define HTC_CONTROL_RX_TIMEOUT 6000
  24. #if defined(WLAN_DEBUG) || defined(DEBUG)
  25. void debug_dump_bytes(uint8_t *buffer, uint16_t length, char *pDescription)
  26. {
  27. int8_t stream[60];
  28. int8_t byteOffsetStr[10];
  29. uint32_t i;
  30. uint16_t offset, count, byteOffset;
  31. A_PRINTF("<---------Dumping %d Bytes : %s ------>\n", length,
  32. pDescription);
  33. count = 0;
  34. offset = 0;
  35. byteOffset = 0;
  36. for (i = 0; i < length; i++) {
  37. A_SNPRINTF(stream + offset, (sizeof(stream) - offset),
  38. "%02X ", buffer[i]);
  39. count++;
  40. offset += 3;
  41. if (count == 16) {
  42. count = 0;
  43. offset = 0;
  44. A_SNPRINTF(byteOffsetStr, sizeof(byteOffset), "%4.4X",
  45. byteOffset);
  46. A_PRINTF("[%s]: %s\n", byteOffsetStr, stream);
  47. qdf_mem_zero(stream, 60);
  48. byteOffset += 16;
  49. }
  50. }
  51. if (offset != 0) {
  52. A_SNPRINTF(byteOffsetStr, sizeof(byteOffset), "%4.4X",
  53. byteOffset);
  54. A_PRINTF("[%s]: %s\n", byteOffsetStr, stream);
  55. }
  56. A_PRINTF("<------------------------------------------------->\n");
  57. }
  58. #else
  59. void debug_dump_bytes(uint8_t *buffer, uint16_t length, char *pDescription)
  60. {
  61. }
  62. #endif
  63. static A_STATUS htc_process_trailer(HTC_TARGET *target,
  64. uint8_t *pBuffer,
  65. int Length, HTC_ENDPOINT_ID FromEndpoint);
  66. static void do_recv_completion_pkt(HTC_ENDPOINT *pEndpoint,
  67. HTC_PACKET *pPacket)
  68. {
  69. if (!pEndpoint->EpCallBacks.EpRecv) {
  70. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  71. ("HTC ep %d has NULL recv callback on packet %pK\n",
  72. pEndpoint->Id,
  73. pPacket));
  74. if (pPacket)
  75. qdf_nbuf_free(pPacket->pPktContext);
  76. } else {
  77. AR_DEBUG_PRINTF(ATH_DEBUG_RECV,
  78. ("HTC calling ep %d recv callback on packet %pK\n",
  79. pEndpoint->Id, pPacket));
  80. pEndpoint->EpCallBacks.EpRecv(pEndpoint->EpCallBacks.pContext,
  81. pPacket);
  82. }
  83. }
  84. static void do_recv_completion(HTC_ENDPOINT *pEndpoint,
  85. HTC_PACKET_QUEUE *pQueueToIndicate)
  86. {
  87. HTC_PACKET *pPacket;
  88. if (HTC_QUEUE_EMPTY(pQueueToIndicate)) {
  89. /* nothing to indicate */
  90. return;
  91. }
  92. while (!HTC_QUEUE_EMPTY(pQueueToIndicate)) {
  93. pPacket = htc_packet_dequeue(pQueueToIndicate);
  94. do_recv_completion_pkt(pEndpoint, pPacket);
  95. }
  96. }
  97. void htc_control_rx_complete(void *Context, HTC_PACKET *pPacket)
  98. {
  99. /* TODO, can't really receive HTC control messages yet.... */
  100. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  101. ("Invalid call to htc_control_rx_complete\n"));
  102. }
  103. void htc_unblock_recv(HTC_HANDLE HTCHandle)
  104. {
  105. /* TODO find the Need in new model */
  106. }
  107. void htc_enable_recv(HTC_HANDLE HTCHandle)
  108. {
  109. /* TODO find the Need in new model */
  110. }
  111. void htc_disable_recv(HTC_HANDLE HTCHandle)
  112. {
  113. /* TODO find the Need in new model */
  114. }
  115. int htc_get_num_recv_buffers(HTC_HANDLE HTCHandle, HTC_ENDPOINT_ID Endpoint)
  116. {
  117. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  118. HTC_ENDPOINT *pEndpoint = &target->endpoint[Endpoint];
  119. return HTC_PACKET_QUEUE_DEPTH(&pEndpoint->RxBufferHoldQueue);
  120. }
  121. HTC_PACKET *allocate_htc_packet_container(HTC_TARGET *target)
  122. {
  123. HTC_PACKET *pPacket;
  124. LOCK_HTC_RX(target);
  125. if (!target->pHTCPacketStructPool) {
  126. UNLOCK_HTC_RX(target);
  127. return NULL;
  128. }
  129. pPacket = target->pHTCPacketStructPool;
  130. target->pHTCPacketStructPool = (HTC_PACKET *) pPacket->ListLink.pNext;
  131. UNLOCK_HTC_RX(target);
  132. pPacket->ListLink.pNext = NULL;
  133. return pPacket;
  134. }
  135. void free_htc_packet_container(HTC_TARGET *target, HTC_PACKET *pPacket)
  136. {
  137. pPacket->ListLink.pPrev = NULL;
  138. LOCK_HTC_RX(target);
  139. if (!target->pHTCPacketStructPool) {
  140. target->pHTCPacketStructPool = pPacket;
  141. pPacket->ListLink.pNext = NULL;
  142. } else {
  143. pPacket->ListLink.pNext =
  144. (DL_LIST *) target->pHTCPacketStructPool;
  145. target->pHTCPacketStructPool = pPacket;
  146. }
  147. UNLOCK_HTC_RX(target);
  148. }
  149. #ifdef RX_SG_SUPPORT
  150. qdf_nbuf_t rx_sg_to_single_netbuf(HTC_TARGET *target)
  151. {
  152. qdf_nbuf_t skb;
  153. uint8_t *anbdata;
  154. uint8_t *anbdata_new;
  155. uint32_t anblen;
  156. qdf_nbuf_t new_skb = NULL;
  157. uint32_t sg_queue_len;
  158. qdf_nbuf_queue_t *rx_sg_queue = &target->RxSgQueue;
  159. sg_queue_len = qdf_nbuf_queue_len(rx_sg_queue);
  160. if (sg_queue_len <= 1) {
  161. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  162. ("rx_sg_to_single_netbuf: invalid sg queue len %u\n"));
  163. goto _failed;
  164. }
  165. new_skb = qdf_nbuf_alloc(target->ExpRxSgTotalLen, 0, 4, false);
  166. if (!new_skb) {
  167. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  168. ("rx_sg_to_single_netbuf: can't allocate %u size netbuf\n",
  169. target->ExpRxSgTotalLen));
  170. goto _failed;
  171. }
  172. qdf_nbuf_peek_header(new_skb, &anbdata_new, &anblen);
  173. skb = qdf_nbuf_queue_remove(rx_sg_queue);
  174. do {
  175. qdf_nbuf_peek_header(skb, &anbdata, &anblen);
  176. qdf_mem_copy(anbdata_new, anbdata, qdf_nbuf_len(skb));
  177. qdf_nbuf_put_tail(new_skb, qdf_nbuf_len(skb));
  178. anbdata_new += qdf_nbuf_len(skb);
  179. qdf_nbuf_free(skb);
  180. skb = qdf_nbuf_queue_remove(rx_sg_queue);
  181. } while (skb);
  182. RESET_RX_SG_CONFIG(target);
  183. return new_skb;
  184. _failed:
  185. while ((skb = qdf_nbuf_queue_remove(rx_sg_queue)) != NULL)
  186. qdf_nbuf_free(skb);
  187. RESET_RX_SG_CONFIG(target);
  188. return NULL;
  189. }
  190. #endif
  191. #ifdef CONFIG_WIN
  192. #define HTC_MSG_NACK_SUSPEND 7
  193. #endif
  194. QDF_STATUS htc_rx_completion_handler(void *Context, qdf_nbuf_t netbuf,
  195. uint8_t pipeID)
  196. {
  197. QDF_STATUS status = QDF_STATUS_SUCCESS;
  198. HTC_FRAME_HDR *HtcHdr;
  199. HTC_TARGET *target = (HTC_TARGET *) Context;
  200. uint8_t *netdata;
  201. uint32_t netlen;
  202. HTC_ENDPOINT *pEndpoint;
  203. HTC_PACKET *pPacket;
  204. uint16_t payloadLen;
  205. uint32_t trailerlen = 0;
  206. uint8_t htc_ep_id;
  207. #ifdef HTC_MSG_WAKEUP_FROM_SUSPEND_ID
  208. struct htc_init_info *info;
  209. #endif
  210. #ifdef RX_SG_SUPPORT
  211. LOCK_HTC_RX(target);
  212. if (target->IsRxSgInprogress) {
  213. target->CurRxSgTotalLen += qdf_nbuf_len(netbuf);
  214. qdf_nbuf_queue_add(&target->RxSgQueue, netbuf);
  215. if (target->CurRxSgTotalLen == target->ExpRxSgTotalLen) {
  216. netbuf = rx_sg_to_single_netbuf(target);
  217. if (!netbuf) {
  218. UNLOCK_HTC_RX(target);
  219. goto _out;
  220. }
  221. } else {
  222. netbuf = NULL;
  223. UNLOCK_HTC_RX(target);
  224. goto _out;
  225. }
  226. }
  227. UNLOCK_HTC_RX(target);
  228. #endif
  229. netdata = qdf_nbuf_data(netbuf);
  230. netlen = qdf_nbuf_len(netbuf);
  231. HtcHdr = (HTC_FRAME_HDR *) netdata;
  232. do {
  233. htc_ep_id = HTC_GET_FIELD(HtcHdr, HTC_FRAME_HDR, ENDPOINTID);
  234. if (htc_ep_id >= ENDPOINT_MAX) {
  235. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  236. ("HTC Rx: invalid EndpointID=%d\n",
  237. htc_ep_id));
  238. debug_dump_bytes((uint8_t *) HtcHdr,
  239. sizeof(HTC_FRAME_HDR),
  240. "BAD HTC Header");
  241. status = QDF_STATUS_E_FAILURE;
  242. DPTRACE(qdf_dp_trace(
  243. netbuf,
  244. QDF_DP_TRACE_HTC_PACKET_PTR_RECORD,
  245. QDF_TRACE_DEFAULT_PDEV_ID,
  246. qdf_nbuf_data_addr(netbuf),
  247. sizeof(qdf_nbuf_data(netbuf)),
  248. QDF_RX));
  249. break;
  250. }
  251. pEndpoint = &target->endpoint[htc_ep_id];
  252. /*
  253. * If this endpoint that received a message from the target has
  254. * a to-target HIF pipe whose send completions are polled rather
  255. * than interrupt driven, this is a good point to ask HIF to
  256. * check whether it has any completed sends to handle.
  257. */
  258. if (pEndpoint->ul_is_polled)
  259. htc_send_complete_check(pEndpoint, 1);
  260. payloadLen = HTC_GET_FIELD(HtcHdr, HTC_FRAME_HDR, PAYLOADLEN);
  261. if (netlen < (payloadLen + HTC_HDR_LENGTH)) {
  262. #ifdef RX_SG_SUPPORT
  263. LOCK_HTC_RX(target);
  264. target->IsRxSgInprogress = true;
  265. qdf_nbuf_queue_init(&target->RxSgQueue);
  266. qdf_nbuf_queue_add(&target->RxSgQueue, netbuf);
  267. target->ExpRxSgTotalLen = (payloadLen + HTC_HDR_LENGTH);
  268. target->CurRxSgTotalLen += netlen;
  269. UNLOCK_HTC_RX(target);
  270. netbuf = NULL;
  271. break;
  272. #else
  273. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  274. ("HTC Rx: insufficient length, got:%d expected =%zu\n",
  275. netlen, payloadLen + HTC_HDR_LENGTH));
  276. debug_dump_bytes((uint8_t *) HtcHdr,
  277. sizeof(HTC_FRAME_HDR),
  278. "BAD RX packet length");
  279. status = QDF_STATUS_E_FAILURE;
  280. DPTRACE(qdf_dp_trace(
  281. netbuf,
  282. QDF_DP_TRACE_HTC_PACKET_PTR_RECORD,
  283. QDF_TRACE_DEFAULT_PDEV_ID,
  284. qdf_nbuf_data_addr(netbuf),
  285. sizeof(qdf_nbuf_data(netbuf)),
  286. QDF_RX));
  287. break;
  288. #endif
  289. }
  290. #ifdef HTC_EP_STAT_PROFILING
  291. LOCK_HTC_RX(target);
  292. INC_HTC_EP_STAT(pEndpoint, RxReceived, 1);
  293. UNLOCK_HTC_RX(target);
  294. #endif
  295. /* if (IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) { */
  296. {
  297. uint8_t temp;
  298. A_STATUS temp_status;
  299. /* get flags to check for trailer */
  300. temp = HTC_GET_FIELD(HtcHdr, HTC_FRAME_HDR, FLAGS);
  301. if (temp & HTC_FLAGS_RECV_TRAILER) {
  302. /* extract the trailer length */
  303. temp =
  304. HTC_GET_FIELD(HtcHdr, HTC_FRAME_HDR,
  305. CONTROLBYTES0);
  306. if ((temp < sizeof(HTC_RECORD_HDR))
  307. || (temp > payloadLen)) {
  308. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  309. ("htc_rx_completion_handler, invalid header (payloadlength should be :%d, CB[0] is:%d)\n",
  310. payloadLen, temp));
  311. status = QDF_STATUS_E_INVAL;
  312. break;
  313. }
  314. trailerlen = temp;
  315. /* process trailer data that follows HDR +
  316. * application payload
  317. */
  318. temp_status = htc_process_trailer(target,
  319. ((uint8_t *) HtcHdr +
  320. HTC_HDR_LENGTH +
  321. payloadLen - temp),
  322. temp, htc_ep_id);
  323. if (A_FAILED(temp_status)) {
  324. status = QDF_STATUS_E_FAILURE;
  325. break;
  326. }
  327. }
  328. }
  329. if (((int)payloadLen - (int)trailerlen) <= 0) {
  330. /* 0 length packet with trailer data, just drop these */
  331. break;
  332. }
  333. if (htc_ep_id == ENDPOINT_0) {
  334. uint16_t message_id;
  335. HTC_UNKNOWN_MSG *htc_msg;
  336. bool wow_nack;
  337. /* remove HTC header */
  338. qdf_nbuf_pull_head(netbuf, HTC_HDR_LENGTH);
  339. netdata = qdf_nbuf_data(netbuf);
  340. netlen = qdf_nbuf_len(netbuf);
  341. htc_msg = (HTC_UNKNOWN_MSG *) netdata;
  342. message_id = HTC_GET_FIELD(htc_msg, HTC_UNKNOWN_MSG,
  343. MESSAGEID);
  344. switch (message_id) {
  345. default:
  346. /* handle HTC control message */
  347. if (target->CtrlResponseProcessing) {
  348. /* this is a fatal error, target should
  349. * not be sending unsolicited messages
  350. * on the endpoint 0
  351. */
  352. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  353. ("HTC Rx Ctrl still processing\n"));
  354. status = QDF_STATUS_E_FAILURE;
  355. QDF_BUG(false);
  356. break;
  357. }
  358. LOCK_HTC_RX(target);
  359. target->CtrlResponseLength =
  360. min((int)netlen,
  361. HTC_MAX_CONTROL_MESSAGE_LENGTH);
  362. qdf_mem_copy(target->CtrlResponseBuffer,
  363. netdata,
  364. target->CtrlResponseLength);
  365. /* Requester will clear this flag */
  366. target->CtrlResponseProcessing = true;
  367. UNLOCK_HTC_RX(target);
  368. qdf_event_set(&target->ctrl_response_valid);
  369. break;
  370. #ifdef HTC_MSG_WAKEUP_FROM_SUSPEND_ID
  371. case HTC_MSG_WAKEUP_FROM_SUSPEND_ID:
  372. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  373. ("Received initial wake up"));
  374. htc_credit_record(HTC_INITIAL_WAKE_UP,
  375. pEndpoint->TxCredits,
  376. HTC_PACKET_QUEUE_DEPTH(
  377. &pEndpoint->TxQueue));
  378. info = &target->HTCInitInfo;
  379. if (info && info->target_initial_wakeup_cb)
  380. info->target_initial_wakeup_cb(
  381. info->target_psoc);
  382. else
  383. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  384. ("No initial wake up cb"));
  385. break;
  386. #endif
  387. case HTC_MSG_SEND_SUSPEND_COMPLETE:
  388. wow_nack = false;
  389. htc_credit_record(HTC_SUSPEND_ACK,
  390. pEndpoint->TxCredits,
  391. HTC_PACKET_QUEUE_DEPTH(
  392. &pEndpoint->TxQueue));
  393. target->HTCInitInfo.TargetSendSuspendComplete(
  394. target->HTCInitInfo.target_psoc,
  395. wow_nack);
  396. break;
  397. case HTC_MSG_NACK_SUSPEND:
  398. wow_nack = true;
  399. htc_credit_record(HTC_SUSPEND_ACK,
  400. pEndpoint->TxCredits,
  401. HTC_PACKET_QUEUE_DEPTH(
  402. &pEndpoint->TxQueue));
  403. target->HTCInitInfo.TargetSendSuspendComplete(
  404. target->HTCInitInfo.target_psoc,
  405. wow_nack);
  406. break;
  407. }
  408. qdf_nbuf_free(netbuf);
  409. netbuf = NULL;
  410. break;
  411. }
  412. /* the current message based HIF architecture allocates net bufs
  413. * for recv packets since this layer bridges that HIF to upper
  414. * layers , which expects HTC packets, we form the packets here
  415. * TODO_FIXME
  416. */
  417. pPacket = allocate_htc_packet_container(target);
  418. if (!pPacket) {
  419. status = QDF_STATUS_E_RESOURCES;
  420. break;
  421. }
  422. pPacket->Status = QDF_STATUS_SUCCESS;
  423. pPacket->Endpoint = htc_ep_id;
  424. pPacket->pPktContext = netbuf;
  425. pPacket->pBuffer = qdf_nbuf_data(netbuf) + HTC_HDR_LENGTH;
  426. pPacket->ActualLength = netlen - HTC_HEADER_LEN - trailerlen;
  427. qdf_nbuf_pull_head(netbuf, HTC_HEADER_LEN);
  428. qdf_nbuf_set_pktlen(netbuf, pPacket->ActualLength);
  429. do_recv_completion_pkt(pEndpoint, pPacket);
  430. /* recover the packet container */
  431. free_htc_packet_container(target, pPacket);
  432. netbuf = NULL;
  433. } while (false);
  434. #ifdef RX_SG_SUPPORT
  435. _out:
  436. #endif
  437. if (netbuf)
  438. qdf_nbuf_free(netbuf);
  439. return status;
  440. }
  441. A_STATUS htc_add_receive_pkt_multiple(HTC_HANDLE HTCHandle,
  442. HTC_PACKET_QUEUE *pPktQueue)
  443. {
  444. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  445. HTC_ENDPOINT *pEndpoint;
  446. HTC_PACKET *pFirstPacket;
  447. A_STATUS status = A_OK;
  448. HTC_PACKET *pPacket;
  449. pFirstPacket = htc_get_pkt_at_head(pPktQueue);
  450. if (!pFirstPacket) {
  451. A_ASSERT(false);
  452. return A_EINVAL;
  453. }
  454. if (pFirstPacket->Endpoint >= ENDPOINT_MAX) {
  455. A_ASSERT(false);
  456. return A_EINVAL;
  457. }
  458. AR_DEBUG_PRINTF(ATH_DEBUG_RECV,
  459. ("+- htc_add_receive_pkt_multiple : endPointId: %d, cnt:%d, length: %d\n",
  460. pFirstPacket->Endpoint,
  461. HTC_PACKET_QUEUE_DEPTH(pPktQueue),
  462. pFirstPacket->BufferLength));
  463. pEndpoint = &target->endpoint[pFirstPacket->Endpoint];
  464. LOCK_HTC_RX(target);
  465. do {
  466. if (HTC_STOPPING(target)) {
  467. status = A_ERROR;
  468. break;
  469. }
  470. /* store receive packets */
  471. HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&pEndpoint->RxBufferHoldQueue,
  472. pPktQueue);
  473. } while (false);
  474. UNLOCK_HTC_RX(target);
  475. if (A_FAILED(status)) {
  476. /* walk through queue and mark each one canceled */
  477. HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pPktQueue, pPacket) {
  478. pPacket->Status = QDF_STATUS_E_CANCELED;
  479. }
  480. HTC_PACKET_QUEUE_ITERATE_END;
  481. do_recv_completion(pEndpoint, pPktQueue);
  482. }
  483. return status;
  484. }
  485. void htc_flush_rx_hold_queue(HTC_TARGET *target, HTC_ENDPOINT *pEndpoint)
  486. {
  487. HTC_PACKET *pPacket;
  488. LOCK_HTC_RX(target);
  489. while (1) {
  490. pPacket = htc_packet_dequeue(&pEndpoint->RxBufferHoldQueue);
  491. if (!pPacket)
  492. break;
  493. UNLOCK_HTC_RX(target);
  494. pPacket->Status = QDF_STATUS_E_CANCELED;
  495. pPacket->ActualLength = 0;
  496. AR_DEBUG_PRINTF(ATH_DEBUG_RECV,
  497. ("Flushing RX packet:%pK, length:%d, ep:%d\n",
  498. pPacket, pPacket->BufferLength,
  499. pPacket->Endpoint));
  500. /* give the packet back */
  501. do_recv_completion_pkt(pEndpoint, pPacket);
  502. LOCK_HTC_RX(target);
  503. }
  504. UNLOCK_HTC_RX(target);
  505. }
  506. void htc_recv_init(HTC_TARGET *target)
  507. {
  508. /* Initialize ctrl_response_valid to block */
  509. qdf_event_create(&target->ctrl_response_valid);
  510. }
  511. /* polling routine to wait for a control packet to be received */
  512. QDF_STATUS htc_wait_recv_ctrl_message(HTC_TARGET *target)
  513. {
  514. /* int count = HTC_TARGET_MAX_RESPONSE_POLL; */
  515. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("+HTCWaitCtrlMessageRecv\n"));
  516. /* Wait for BMI request/response transaction to complete */
  517. if (qdf_wait_single_event(&target->ctrl_response_valid,
  518. HTC_CONTROL_RX_TIMEOUT)) {
  519. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  520. ("Failed to receive control message\n"));
  521. return QDF_STATUS_E_FAILURE;
  522. }
  523. LOCK_HTC_RX(target);
  524. /* caller will clear this flag */
  525. target->CtrlResponseProcessing = true;
  526. UNLOCK_HTC_RX(target);
  527. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("-HTCWaitCtrlMessageRecv success\n"));
  528. return QDF_STATUS_SUCCESS;
  529. }
  530. static A_STATUS htc_process_trailer(HTC_TARGET *target,
  531. uint8_t *pBuffer,
  532. int Length, HTC_ENDPOINT_ID FromEndpoint)
  533. {
  534. HTC_RECORD_HDR *pRecord;
  535. uint8_t htc_rec_id;
  536. uint8_t htc_rec_len;
  537. uint8_t *pRecordBuf;
  538. uint8_t *pOrigBuffer;
  539. int origLength;
  540. A_STATUS status;
  541. AR_DEBUG_PRINTF(ATH_DEBUG_RECV,
  542. ("+htc_process_trailer (length:%d)\n", Length));
  543. if (AR_DEBUG_LVL_CHECK(ATH_DEBUG_RECV))
  544. AR_DEBUG_PRINTBUF(pBuffer, Length, "Recv Trailer");
  545. pOrigBuffer = pBuffer;
  546. origLength = Length;
  547. status = A_OK;
  548. while (Length > 0) {
  549. if (Length < sizeof(HTC_RECORD_HDR)) {
  550. status = A_EPROTO;
  551. break;
  552. }
  553. /* these are byte aligned structs */
  554. pRecord = (HTC_RECORD_HDR *) pBuffer;
  555. Length -= sizeof(HTC_RECORD_HDR);
  556. pBuffer += sizeof(HTC_RECORD_HDR);
  557. htc_rec_len = HTC_GET_FIELD(pRecord, HTC_RECORD_HDR, LENGTH);
  558. htc_rec_id = HTC_GET_FIELD(pRecord, HTC_RECORD_HDR, RECORDID);
  559. if (htc_rec_len > Length) {
  560. /* no room left in buffer for record */
  561. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  562. ("invalid record length: %d (id:%d) buffer has: %d bytes left\n",
  563. htc_rec_len, htc_rec_id, Length));
  564. status = A_EPROTO;
  565. break;
  566. }
  567. /* start of record follows the header */
  568. pRecordBuf = pBuffer;
  569. switch (htc_rec_id) {
  570. case HTC_RECORD_CREDITS:
  571. AR_DEBUG_ASSERT(htc_rec_len >=
  572. sizeof(HTC_CREDIT_REPORT));
  573. htc_process_credit_rpt(target,
  574. (HTC_CREDIT_REPORT *) pRecordBuf,
  575. htc_rec_len /
  576. (sizeof(HTC_CREDIT_REPORT)),
  577. FromEndpoint);
  578. break;
  579. #ifdef HIF_SDIO
  580. case HTC_RECORD_LOOKAHEAD:
  581. /* Process in HIF layer */
  582. break;
  583. case HTC_RECORD_LOOKAHEAD_BUNDLE:
  584. /* Process in HIF layer */
  585. break;
  586. #endif /* HIF_SDIO */
  587. default:
  588. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  589. ("HTC unhandled record: id:%d length:%d\n",
  590. htc_rec_id, htc_rec_len));
  591. break;
  592. }
  593. if (A_FAILED(status)) {
  594. break;
  595. }
  596. /* advance buffer past this record for next time around */
  597. pBuffer += htc_rec_len;
  598. Length -= htc_rec_len;
  599. }
  600. if (A_FAILED(status))
  601. debug_dump_bytes(pOrigBuffer, origLength, "BAD Recv Trailer");
  602. AR_DEBUG_PRINTF(ATH_DEBUG_RECV, ("-htc_process_trailer\n"));
  603. return status;
  604. }