htc_recv.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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. QDF_STATUS htc_rx_completion_handler(void *Context, qdf_nbuf_t netbuf,
  192. uint8_t pipeID)
  193. {
  194. QDF_STATUS status = QDF_STATUS_SUCCESS;
  195. HTC_FRAME_HDR *HtcHdr;
  196. HTC_TARGET *target = (HTC_TARGET *) Context;
  197. uint8_t *netdata;
  198. uint32_t netlen;
  199. HTC_ENDPOINT *pEndpoint, *currendpoint;
  200. HTC_PACKET *pPacket;
  201. uint16_t payloadLen;
  202. uint32_t trailerlen = 0;
  203. uint8_t htc_ep_id;
  204. int i;
  205. #ifdef HTC_MSG_WAKEUP_FROM_SUSPEND_ID
  206. struct htc_init_info *info;
  207. #endif
  208. #ifdef RX_SG_SUPPORT
  209. LOCK_HTC_RX(target);
  210. if (target->IsRxSgInprogress) {
  211. target->CurRxSgTotalLen += qdf_nbuf_len(netbuf);
  212. qdf_nbuf_queue_add(&target->RxSgQueue, netbuf);
  213. if (target->CurRxSgTotalLen == target->ExpRxSgTotalLen) {
  214. netbuf = rx_sg_to_single_netbuf(target);
  215. if (!netbuf) {
  216. UNLOCK_HTC_RX(target);
  217. goto _out;
  218. }
  219. } else {
  220. netbuf = NULL;
  221. UNLOCK_HTC_RX(target);
  222. goto _out;
  223. }
  224. }
  225. UNLOCK_HTC_RX(target);
  226. #endif
  227. netdata = qdf_nbuf_data(netbuf);
  228. netlen = qdf_nbuf_len(netbuf);
  229. HtcHdr = (HTC_FRAME_HDR *) netdata;
  230. do {
  231. htc_ep_id = HTC_GET_FIELD(HtcHdr, HTC_FRAME_HDR, ENDPOINTID);
  232. if (htc_ep_id >= ENDPOINT_MAX) {
  233. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  234. ("HTC Rx: invalid EndpointID=%d\n",
  235. htc_ep_id));
  236. debug_dump_bytes((uint8_t *) HtcHdr,
  237. sizeof(HTC_FRAME_HDR),
  238. "BAD HTC Header");
  239. status = QDF_STATUS_E_FAILURE;
  240. DPTRACE(qdf_dp_trace(
  241. netbuf,
  242. QDF_DP_TRACE_HTC_PACKET_PTR_RECORD,
  243. QDF_TRACE_DEFAULT_PDEV_ID,
  244. qdf_nbuf_data_addr(netbuf),
  245. sizeof(qdf_nbuf_data(netbuf)),
  246. QDF_RX));
  247. break;
  248. }
  249. pEndpoint = &target->endpoint[htc_ep_id];
  250. /*
  251. * If this endpoint that received a message from the target has
  252. * a to-target HIF pipe whose send completions are polled rather
  253. * than interrupt driven, this is a good point to ask HIF to
  254. * check whether it has any completed sends to handle.
  255. */
  256. if (pEndpoint->ul_is_polled) {
  257. for (i = 0; i < ENDPOINT_MAX; i++) {
  258. currendpoint = &target->endpoint[i];
  259. if ((currendpoint->DL_PipeID ==
  260. pEndpoint->DL_PipeID) &&
  261. currendpoint->ul_is_polled) {
  262. htc_send_complete_check(currendpoint,
  263. 1);
  264. }
  265. }
  266. }
  267. payloadLen = HTC_GET_FIELD(HtcHdr, HTC_FRAME_HDR, PAYLOADLEN);
  268. if (netlen < (payloadLen + HTC_HDR_LENGTH)) {
  269. #ifdef RX_SG_SUPPORT
  270. LOCK_HTC_RX(target);
  271. target->IsRxSgInprogress = true;
  272. qdf_nbuf_queue_init(&target->RxSgQueue);
  273. qdf_nbuf_queue_add(&target->RxSgQueue, netbuf);
  274. target->ExpRxSgTotalLen = (payloadLen + HTC_HDR_LENGTH);
  275. target->CurRxSgTotalLen += netlen;
  276. UNLOCK_HTC_RX(target);
  277. netbuf = NULL;
  278. break;
  279. #else
  280. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  281. ("HTC Rx: insufficient length, got:%d expected =%zu\n",
  282. netlen, payloadLen + HTC_HDR_LENGTH));
  283. debug_dump_bytes((uint8_t *) HtcHdr,
  284. sizeof(HTC_FRAME_HDR),
  285. "BAD RX packet length");
  286. status = QDF_STATUS_E_FAILURE;
  287. DPTRACE(qdf_dp_trace(
  288. netbuf,
  289. QDF_DP_TRACE_HTC_PACKET_PTR_RECORD,
  290. QDF_TRACE_DEFAULT_PDEV_ID,
  291. qdf_nbuf_data_addr(netbuf),
  292. sizeof(qdf_nbuf_data(netbuf)),
  293. QDF_RX));
  294. break;
  295. #endif
  296. }
  297. #ifdef HTC_EP_STAT_PROFILING
  298. LOCK_HTC_RX(target);
  299. INC_HTC_EP_STAT(pEndpoint, RxReceived, 1);
  300. UNLOCK_HTC_RX(target);
  301. #endif
  302. /* if (IS_TX_CREDIT_FLOW_ENABLED(pEndpoint)) { */
  303. {
  304. uint8_t temp;
  305. A_STATUS temp_status;
  306. /* get flags to check for trailer */
  307. temp = HTC_GET_FIELD(HtcHdr, HTC_FRAME_HDR, FLAGS);
  308. if (temp & HTC_FLAGS_RECV_TRAILER) {
  309. /* extract the trailer length */
  310. temp =
  311. HTC_GET_FIELD(HtcHdr, HTC_FRAME_HDR,
  312. CONTROLBYTES0);
  313. if ((temp < sizeof(HTC_RECORD_HDR))
  314. || (temp > payloadLen)) {
  315. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  316. ("htc_rx_completion_handler, invalid header (payloadlength should be :%d, CB[0] is:%d)\n",
  317. payloadLen, temp));
  318. status = QDF_STATUS_E_INVAL;
  319. break;
  320. }
  321. trailerlen = temp;
  322. /* process trailer data that follows HDR +
  323. * application payload
  324. */
  325. temp_status = htc_process_trailer(target,
  326. ((uint8_t *) HtcHdr +
  327. HTC_HDR_LENGTH +
  328. payloadLen - temp),
  329. temp, htc_ep_id);
  330. if (A_FAILED(temp_status)) {
  331. status = QDF_STATUS_E_FAILURE;
  332. break;
  333. }
  334. }
  335. }
  336. if (((int)payloadLen - (int)trailerlen) <= 0) {
  337. /* 0 length packet with trailer data, just drop these */
  338. break;
  339. }
  340. if (htc_ep_id == ENDPOINT_0) {
  341. uint16_t message_id;
  342. HTC_UNKNOWN_MSG *htc_msg;
  343. bool wow_nack;
  344. /* remove HTC header */
  345. qdf_nbuf_pull_head(netbuf, HTC_HDR_LENGTH);
  346. netdata = qdf_nbuf_data(netbuf);
  347. netlen = qdf_nbuf_len(netbuf);
  348. htc_msg = (HTC_UNKNOWN_MSG *) netdata;
  349. message_id = HTC_GET_FIELD(htc_msg, HTC_UNKNOWN_MSG,
  350. MESSAGEID);
  351. switch (message_id) {
  352. default:
  353. /* handle HTC control message */
  354. if (target->CtrlResponseProcessing) {
  355. /* this is a fatal error, target should
  356. * not be sending unsolicited messages
  357. * on the endpoint 0
  358. */
  359. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  360. ("HTC Rx Ctrl still processing\n"));
  361. status = QDF_STATUS_E_FAILURE;
  362. QDF_BUG(false);
  363. break;
  364. }
  365. LOCK_HTC_RX(target);
  366. target->CtrlResponseLength =
  367. min((int)netlen,
  368. HTC_MAX_CONTROL_MESSAGE_LENGTH);
  369. qdf_mem_copy(target->CtrlResponseBuffer,
  370. netdata,
  371. target->CtrlResponseLength);
  372. /* Requester will clear this flag */
  373. target->CtrlResponseProcessing = true;
  374. UNLOCK_HTC_RX(target);
  375. qdf_event_set(&target->ctrl_response_valid);
  376. break;
  377. #ifdef HTC_MSG_WAKEUP_FROM_SUSPEND_ID
  378. case HTC_MSG_WAKEUP_FROM_SUSPEND_ID:
  379. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  380. ("Received initial wake up"));
  381. htc_credit_record(HTC_INITIAL_WAKE_UP,
  382. pEndpoint->TxCredits,
  383. HTC_PACKET_QUEUE_DEPTH(
  384. &pEndpoint->TxQueue));
  385. info = &target->HTCInitInfo;
  386. if (info && info->target_initial_wakeup_cb)
  387. info->target_initial_wakeup_cb(
  388. info->target_psoc);
  389. else
  390. AR_DEBUG_PRINTF(ATH_DEBUG_ANY,
  391. ("No initial wake up cb"));
  392. break;
  393. #endif
  394. case HTC_MSG_SEND_SUSPEND_COMPLETE:
  395. wow_nack = false;
  396. htc_credit_record(HTC_SUSPEND_ACK,
  397. pEndpoint->TxCredits,
  398. HTC_PACKET_QUEUE_DEPTH(
  399. &pEndpoint->TxQueue));
  400. target->HTCInitInfo.TargetSendSuspendComplete(
  401. target->HTCInitInfo.target_psoc,
  402. wow_nack);
  403. break;
  404. case HTC_MSG_NACK_SUSPEND:
  405. wow_nack = true;
  406. htc_credit_record(HTC_SUSPEND_ACK,
  407. pEndpoint->TxCredits,
  408. HTC_PACKET_QUEUE_DEPTH(
  409. &pEndpoint->TxQueue));
  410. target->HTCInitInfo.TargetSendSuspendComplete(
  411. target->HTCInitInfo.target_psoc,
  412. wow_nack);
  413. break;
  414. }
  415. qdf_nbuf_free(netbuf);
  416. netbuf = NULL;
  417. break;
  418. }
  419. /* the current message based HIF architecture allocates net bufs
  420. * for recv packets since this layer bridges that HIF to upper
  421. * layers , which expects HTC packets, we form the packets here
  422. * TODO_FIXME
  423. */
  424. pPacket = allocate_htc_packet_container(target);
  425. if (!pPacket) {
  426. status = QDF_STATUS_E_RESOURCES;
  427. break;
  428. }
  429. pPacket->Status = QDF_STATUS_SUCCESS;
  430. pPacket->Endpoint = htc_ep_id;
  431. pPacket->pPktContext = netbuf;
  432. pPacket->pBuffer = qdf_nbuf_data(netbuf) + HTC_HDR_LENGTH;
  433. pPacket->ActualLength = netlen - HTC_HEADER_LEN - trailerlen;
  434. qdf_nbuf_pull_head(netbuf, HTC_HEADER_LEN);
  435. qdf_nbuf_set_pktlen(netbuf, pPacket->ActualLength);
  436. do_recv_completion_pkt(pEndpoint, pPacket);
  437. /* recover the packet container */
  438. free_htc_packet_container(target, pPacket);
  439. netbuf = NULL;
  440. } while (false);
  441. #ifdef RX_SG_SUPPORT
  442. _out:
  443. #endif
  444. if (netbuf)
  445. qdf_nbuf_free(netbuf);
  446. return status;
  447. }
  448. A_STATUS htc_add_receive_pkt_multiple(HTC_HANDLE HTCHandle,
  449. HTC_PACKET_QUEUE *pPktQueue)
  450. {
  451. HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
  452. HTC_ENDPOINT *pEndpoint;
  453. HTC_PACKET *pFirstPacket;
  454. A_STATUS status = A_OK;
  455. HTC_PACKET *pPacket;
  456. pFirstPacket = htc_get_pkt_at_head(pPktQueue);
  457. if (!pFirstPacket) {
  458. A_ASSERT(false);
  459. return A_EINVAL;
  460. }
  461. if (pFirstPacket->Endpoint >= ENDPOINT_MAX) {
  462. A_ASSERT(false);
  463. return A_EINVAL;
  464. }
  465. AR_DEBUG_PRINTF(ATH_DEBUG_RECV,
  466. ("+- htc_add_receive_pkt_multiple : endPointId: %d, cnt:%d, length: %d\n",
  467. pFirstPacket->Endpoint,
  468. HTC_PACKET_QUEUE_DEPTH(pPktQueue),
  469. pFirstPacket->BufferLength));
  470. pEndpoint = &target->endpoint[pFirstPacket->Endpoint];
  471. LOCK_HTC_RX(target);
  472. do {
  473. if (HTC_STOPPING(target)) {
  474. status = A_ERROR;
  475. break;
  476. }
  477. /* store receive packets */
  478. HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&pEndpoint->RxBufferHoldQueue,
  479. pPktQueue);
  480. } while (false);
  481. UNLOCK_HTC_RX(target);
  482. if (A_FAILED(status)) {
  483. /* walk through queue and mark each one canceled */
  484. HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pPktQueue, pPacket) {
  485. pPacket->Status = QDF_STATUS_E_CANCELED;
  486. }
  487. HTC_PACKET_QUEUE_ITERATE_END;
  488. do_recv_completion(pEndpoint, pPktQueue);
  489. }
  490. return status;
  491. }
  492. void htc_flush_rx_hold_queue(HTC_TARGET *target, HTC_ENDPOINT *pEndpoint)
  493. {
  494. HTC_PACKET *pPacket;
  495. LOCK_HTC_RX(target);
  496. while (1) {
  497. pPacket = htc_packet_dequeue(&pEndpoint->RxBufferHoldQueue);
  498. if (!pPacket)
  499. break;
  500. UNLOCK_HTC_RX(target);
  501. pPacket->Status = QDF_STATUS_E_CANCELED;
  502. pPacket->ActualLength = 0;
  503. AR_DEBUG_PRINTF(ATH_DEBUG_RECV,
  504. ("Flushing RX packet:%pK, length:%d, ep:%d\n",
  505. pPacket, pPacket->BufferLength,
  506. pPacket->Endpoint));
  507. /* give the packet back */
  508. do_recv_completion_pkt(pEndpoint, pPacket);
  509. LOCK_HTC_RX(target);
  510. }
  511. UNLOCK_HTC_RX(target);
  512. }
  513. void htc_recv_init(HTC_TARGET *target)
  514. {
  515. /* Initialize ctrl_response_valid to block */
  516. qdf_event_create(&target->ctrl_response_valid);
  517. }
  518. /* polling routine to wait for a control packet to be received */
  519. QDF_STATUS htc_wait_recv_ctrl_message(HTC_TARGET *target)
  520. {
  521. /* int count = HTC_TARGET_MAX_RESPONSE_POLL; */
  522. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("+HTCWaitCtrlMessageRecv\n"));
  523. /* Wait for BMI request/response transaction to complete */
  524. if (qdf_wait_single_event(&target->ctrl_response_valid,
  525. HTC_CONTROL_RX_TIMEOUT)) {
  526. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  527. ("Failed to receive control message\n"));
  528. return QDF_STATUS_E_FAILURE;
  529. }
  530. LOCK_HTC_RX(target);
  531. /* caller will clear this flag */
  532. target->CtrlResponseProcessing = true;
  533. UNLOCK_HTC_RX(target);
  534. AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("-HTCWaitCtrlMessageRecv success\n"));
  535. return QDF_STATUS_SUCCESS;
  536. }
  537. static A_STATUS htc_process_trailer(HTC_TARGET *target,
  538. uint8_t *pBuffer,
  539. int Length, HTC_ENDPOINT_ID FromEndpoint)
  540. {
  541. HTC_RECORD_HDR *pRecord;
  542. uint8_t htc_rec_id;
  543. uint8_t htc_rec_len;
  544. uint8_t *pRecordBuf;
  545. uint8_t *pOrigBuffer;
  546. int origLength;
  547. A_STATUS status;
  548. AR_DEBUG_PRINTF(ATH_DEBUG_RECV,
  549. ("+htc_process_trailer (length:%d)\n", Length));
  550. if (AR_DEBUG_LVL_CHECK(ATH_DEBUG_RECV))
  551. AR_DEBUG_PRINTBUF(pBuffer, Length, "Recv Trailer");
  552. pOrigBuffer = pBuffer;
  553. origLength = Length;
  554. status = A_OK;
  555. while (Length > 0) {
  556. if (Length < sizeof(HTC_RECORD_HDR)) {
  557. status = A_EPROTO;
  558. break;
  559. }
  560. /* these are byte aligned structs */
  561. pRecord = (HTC_RECORD_HDR *) pBuffer;
  562. Length -= sizeof(HTC_RECORD_HDR);
  563. pBuffer += sizeof(HTC_RECORD_HDR);
  564. htc_rec_len = HTC_GET_FIELD(pRecord, HTC_RECORD_HDR, LENGTH);
  565. htc_rec_id = HTC_GET_FIELD(pRecord, HTC_RECORD_HDR, RECORDID);
  566. if (htc_rec_len > Length) {
  567. /* no room left in buffer for record */
  568. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  569. ("invalid record length: %d (id:%d) buffer has: %d bytes left\n",
  570. htc_rec_len, htc_rec_id, Length));
  571. status = A_EPROTO;
  572. break;
  573. }
  574. /* start of record follows the header */
  575. pRecordBuf = pBuffer;
  576. switch (htc_rec_id) {
  577. case HTC_RECORD_CREDITS:
  578. AR_DEBUG_ASSERT(htc_rec_len >=
  579. sizeof(HTC_CREDIT_REPORT));
  580. htc_process_credit_rpt(target,
  581. (HTC_CREDIT_REPORT *) pRecordBuf,
  582. htc_rec_len /
  583. (sizeof(HTC_CREDIT_REPORT)),
  584. FromEndpoint);
  585. break;
  586. #ifdef HIF_SDIO
  587. case HTC_RECORD_LOOKAHEAD:
  588. /* Process in HIF layer */
  589. break;
  590. case HTC_RECORD_LOOKAHEAD_BUNDLE:
  591. /* Process in HIF layer */
  592. break;
  593. #endif /* HIF_SDIO */
  594. default:
  595. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  596. ("HTC unhandled record: id:%d length:%d\n",
  597. htc_rec_id, htc_rec_len));
  598. break;
  599. }
  600. if (A_FAILED(status)) {
  601. break;
  602. }
  603. /* advance buffer past this record for next time around */
  604. pBuffer += htc_rec_len;
  605. Length -= htc_rec_len;
  606. }
  607. if (A_FAILED(status))
  608. debug_dump_bytes(pOrigBuffer, origLength, "BAD Recv Trailer");
  609. AR_DEBUG_PRINTF(ATH_DEBUG_RECV, ("-htc_process_trailer\n"));
  610. return status;
  611. }