htc_recv.c 18 KB

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