htc_recv.c 18 KB

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