36
36
(pP)->PktInfo.AsRx.ExpectedHdr, \
39
#ifdef HTC_EP_STAT_PROFILING
40
39
#define HTC_RX_STAT_PROFILE(t,ep,numLookAheads) \
42
41
INC_HTC_EP_STAT((ep), RxReceived, 1); \
46
45
INC_HTC_EP_STAT((ep), RxBundleLookAheads, 1); \
50
#define HTC_RX_STAT_PROFILE(t,ep,lookAhead)
53
static void DoRecvCompletion(HTC_ENDPOINT *pEndpoint,
54
HTC_PACKET_QUEUE *pQueueToIndicate)
49
static void DoRecvCompletion(struct htc_endpoint *pEndpoint,
50
struct htc_packet_queue *pQueueToIndicate)
79
75
} while (!HTC_QUEUE_EMPTY(pQueueToIndicate));
86
static INLINE A_STATUS HTCProcessTrailer(HTC_TARGET *target,
82
static INLINE int HTCProcessTrailer(struct htc_target *target,
89
A_UINT32 *pNextLookAheads,
90
86
int *pNumLookAheads,
91
87
HTC_ENDPOINT_ID FromEndpoint)
93
89
HTC_RECORD_HDR *pRecord;
95
91
HTC_LOOKAHEAD_REPORT *pLookAhead;
100
96
AR_DEBUG_PRINTF(ATH_DEBUG_RECV, ("+HTCProcessTrailer (length:%d) \n", Length));
149
145
pLookAhead->PostValid));
151
147
/* look ahead bytes are valid, copy them over */
152
((A_UINT8 *)(&pNextLookAheads[0]))[0] = pLookAhead->LookAhead[0];
153
((A_UINT8 *)(&pNextLookAheads[0]))[1] = pLookAhead->LookAhead[1];
154
((A_UINT8 *)(&pNextLookAheads[0]))[2] = pLookAhead->LookAhead[2];
155
((A_UINT8 *)(&pNextLookAheads[0]))[3] = pLookAhead->LookAhead[3];
148
((u8 *)(&pNextLookAheads[0]))[0] = pLookAhead->LookAhead[0];
149
((u8 *)(&pNextLookAheads[0]))[1] = pLookAhead->LookAhead[1];
150
((u8 *)(&pNextLookAheads[0]))[2] = pLookAhead->LookAhead[2];
151
((u8 *)(&pNextLookAheads[0]))[3] = pLookAhead->LookAhead[3];
157
153
#ifdef ATH_DEBUG_MODULE
158
154
if (AR_DEBUG_LVL_CHECK(ATH_DEBUG_RECV)) {
159
DebugDumpBytes((A_UINT8 *)pNextLookAheads,4,"Next Look Ahead");
155
DebugDumpBytes((u8 *)pNextLookAheads,4,"Next Look Ahead");
162
158
/* just one normal lookahead */
182
178
HTC_HOST_MAX_MSG_PER_BUNDLE) {
183
179
/* this should never happen, the target restricts the number
184
180
* of messages per bundle configured by the host */
186
182
status = A_EPROTO;
190
186
for (i = 0; i < (int)(pRecord->Length / (sizeof(HTC_BUNDLED_LOOKAHEAD_REPORT))); i++) {
191
((A_UINT8 *)(&pNextLookAheads[i]))[0] = pBundledLookAheadRpt->LookAhead[0];
192
((A_UINT8 *)(&pNextLookAheads[i]))[1] = pBundledLookAheadRpt->LookAhead[1];
193
((A_UINT8 *)(&pNextLookAheads[i]))[2] = pBundledLookAheadRpt->LookAhead[2];
194
((A_UINT8 *)(&pNextLookAheads[i]))[3] = pBundledLookAheadRpt->LookAhead[3];
187
((u8 *)(&pNextLookAheads[i]))[0] = pBundledLookAheadRpt->LookAhead[0];
188
((u8 *)(&pNextLookAheads[i]))[1] = pBundledLookAheadRpt->LookAhead[1];
189
((u8 *)(&pNextLookAheads[i]))[2] = pBundledLookAheadRpt->LookAhead[2];
190
((u8 *)(&pNextLookAheads[i]))[3] = pBundledLookAheadRpt->LookAhead[3];
195
191
pBundledLookAheadRpt++;
227
223
/* process a received message (i.e. strip off header, process any trailer data)
228
224
* note : locks must be released when this function is called */
229
static A_STATUS HTCProcessRecvHeader(HTC_TARGET *target,
231
A_UINT32 *pNextLookAheads,
225
static int HTCProcessRecvHeader(struct htc_target *target,
226
struct htc_packet *pPacket,
227
u32 *pNextLookAheads,
232
228
int *pNumLookAheads)
236
A_STATUS status = A_OK;
240
236
pBuf = pPacket->pBuffer;
253
249
/* note, we cannot assume the alignment of pBuffer, so we use the safe macros to
254
250
* retrieve 16 bit fields */
255
payloadLen = A_GET_UINT16_FIELD(pBuf, HTC_FRAME_HDR, PayloadLen);
251
payloadLen = A_GET_UINT16_FIELD(pBuf, struct htc_frame_hdr, PayloadLen);
257
((A_UINT8 *)&lookAhead)[0] = pBuf[0];
258
((A_UINT8 *)&lookAhead)[1] = pBuf[1];
259
((A_UINT8 *)&lookAhead)[2] = pBuf[2];
260
((A_UINT8 *)&lookAhead)[3] = pBuf[3];
253
((u8 *)&lookAhead)[0] = pBuf[0];
254
((u8 *)&lookAhead)[1] = pBuf[1];
255
((u8 *)&lookAhead)[2] = pBuf[2];
256
((u8 *)&lookAhead)[3] = pBuf[3];
262
258
if (pPacket->PktInfo.AsRx.HTCRxFlags & HTC_RX_PKT_REFRESH_HDR) {
263
259
/* refresh expected hdr, since this was unknown at the time we grabbed the packets
280
if (pPacket->Endpoint != A_GET_UINT8_FIELD(pBuf, HTC_FRAME_HDR, EndpointID)) {
276
if (pPacket->Endpoint != A_GET_UINT8_FIELD(pBuf, struct htc_frame_hdr, EndpointID)) {
281
277
AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
282
278
("Refreshed HDR endpoint (%d) does not match expected endpoint (%d) \n",
283
A_GET_UINT8_FIELD(pBuf, HTC_FRAME_HDR, EndpointID), pPacket->Endpoint));
279
A_GET_UINT8_FIELD(pBuf, struct htc_frame_hdr, EndpointID), pPacket->Endpoint));
284
280
status = A_EPROTO;
293
289
("HTCProcessRecvHeader, lookahead mismatch! (pPkt:0x%lX flags:0x%X) \n",
294
290
(unsigned long)pPacket, pPacket->PktInfo.AsRx.HTCRxFlags));
295
291
#ifdef ATH_DEBUG_MODULE
296
DebugDumpBytes((A_UINT8 *)&pPacket->PktInfo.AsRx.ExpectedHdr,4,"Expected Message LookAhead");
297
DebugDumpBytes(pBuf,sizeof(HTC_FRAME_HDR),"Current Frame Header");
292
DebugDumpBytes((u8 *)&pPacket->PktInfo.AsRx.ExpectedHdr,4,"Expected Message LookAhead");
293
DebugDumpBytes(pBuf,sizeof(struct htc_frame_hdr),"Current Frame Header");
298
294
#ifdef HTC_CAPTURE_LAST_FRAME
299
DebugDumpBytes((A_UINT8 *)&target->LastFrameHdr,sizeof(HTC_FRAME_HDR),"Last Frame Header");
295
DebugDumpBytes((u8 *)&target->LastFrameHdr,sizeof(struct htc_frame_hdr),"Last Frame Header");
300
296
if (target->LastTrailerLength != 0) {
301
297
DebugDumpBytes(target->LastTrailer,
302
298
target->LastTrailerLength,
312
temp = A_GET_UINT8_FIELD(pBuf, HTC_FRAME_HDR, Flags);
308
temp = A_GET_UINT8_FIELD(pBuf, struct htc_frame_hdr, Flags);
314
310
if (temp & HTC_FLAGS_RECV_TRAILER) {
315
311
/* this packet has a trailer */
317
313
/* extract the trailer length in control byte 0 */
318
temp = A_GET_UINT8_FIELD(pBuf, HTC_FRAME_HDR, ControlBytes[0]);
314
temp = A_GET_UINT8_FIELD(pBuf, struct htc_frame_hdr, ControlBytes[0]);
320
316
if ((temp < sizeof(HTC_RECORD_HDR)) || (temp > payloadLen)) {
321
317
AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
342
338
pPacket->Endpoint);
344
if (A_FAILED(status)) {
348
344
#ifdef HTC_CAPTURE_LAST_FRAME
349
A_MEMCPY(target->LastTrailer, (pBuf + HTC_HDR_LENGTH + payloadLen - temp), temp);
345
memcpy(target->LastTrailer, (pBuf + HTC_HDR_LENGTH + payloadLen - temp), temp);
350
346
target->LastTrailerLength = temp;
352
348
/* trim length by trailer bytes */
363
359
pPacket->pBuffer += HTC_HDR_LENGTH;
364
360
pPacket->ActualLength -= HTC_HDR_LENGTH;
368
if (A_FAILED(status)) {
369
365
/* dump the whole packet */
370
366
#ifdef ATH_DEBUG_MODULE
371
367
DebugDumpBytes(pBuf,pPacket->ActualLength < 256 ? pPacket->ActualLength : 256 ,"BAD HTC Recv PKT");
374
370
#ifdef HTC_CAPTURE_LAST_FRAME
375
A_MEMCPY(&target->LastFrameHdr,pBuf,sizeof(HTC_FRAME_HDR));
371
memcpy(&target->LastFrameHdr,pBuf,sizeof(struct htc_frame_hdr));
377
373
if (AR_DEBUG_LVL_CHECK(ATH_DEBUG_RECV)) {
378
374
if (pPacket->ActualLength > 0) {
388
static INLINE void HTCAsyncRecvCheckMorePackets(HTC_TARGET *target,
389
A_UINT32 NextLookAheads[],
384
static INLINE void HTCAsyncRecvCheckMorePackets(struct htc_target *target,
385
u32 NextLookAheads[],
390
386
int NumLookAheads,
391
A_BOOL CheckMoreMsgs)
393
389
/* was there a lookahead for the next packet? */
394
390
if (NumLookAheads > 0) {
397
393
AR_DEBUG_PRINTF(ATH_DEBUG_RECV,
398
394
("HTCAsyncRecvCheckMorePackets - num lookaheads were non-zero : %d \n",
405
401
AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
406
402
("Next look ahead from recv header was INVALID\n"));
407
403
#ifdef ATH_DEBUG_MODULE
408
DebugDumpBytes((A_UINT8 *)NextLookAheads,
409
NumLookAheads * (sizeof(A_UINT32)),
404
DebugDumpBytes((u8 *)NextLookAheads,
405
NumLookAheads * (sizeof(u32)),
410
406
"BAD lookaheads from lookahead report");
413
if (A_SUCCESS(nextStatus) && !fetched) {
409
if (!nextStatus && !fetched) {
414
410
/* we could not fetch any more packets due to resources */
415
411
DevAsyncIrqProcessComplete(&target->Device);
434
430
/* unload the recv completion queue */
435
static INLINE void DrainRecvIndicationQueue(HTC_TARGET *target, HTC_ENDPOINT *pEndpoint)
431
static INLINE void DrainRecvIndicationQueue(struct htc_target *target, struct htc_endpoint *pEndpoint)
437
HTC_PACKET_QUEUE recvCompletions;
433
struct htc_packet_queue recvCompletions;
439
435
AR_DEBUG_PRINTF(ATH_DEBUG_RECV, ("+DrainRecvIndicationQueue \n"));
496
492
(P)->PktInfo.AsRx.IndicationFlags |= HTC_RX_FLAGS_INDICATE_MORE_PKTS;
498
494
/* note: this function can be called with the RX lock held */
499
static INLINE void SetRxPacketIndicationFlags(A_UINT32 LookAhead,
500
HTC_ENDPOINT *pEndpoint,
495
static INLINE void SetRxPacketIndicationFlags(u32 LookAhead,
496
struct htc_endpoint *pEndpoint,
497
struct htc_packet *pPacket)
503
HTC_FRAME_HDR *pHdr = (HTC_FRAME_HDR *)&LookAhead;
499
struct htc_frame_hdr *pHdr = (struct htc_frame_hdr *)&LookAhead;
504
500
/* check to see if the "next" packet is from the same endpoint of the
505
501
completing packet */
506
502
if (pHdr->EndpointID == pPacket->Endpoint) {
516
512
/* asynchronous completion handler for recv packet fetching, when the device layer
517
513
* completes a read request, it will call this completion handler */
518
void HTCRecvCompleteHandler(void *Context, HTC_PACKET *pPacket)
514
void HTCRecvCompleteHandler(void *Context, struct htc_packet *pPacket)
520
HTC_TARGET *target = (HTC_TARGET *)Context;
521
HTC_ENDPOINT *pEndpoint;
522
A_UINT32 nextLookAheads[HTC_HOST_MAX_MSG_PER_BUNDLE];
516
struct htc_target *target = (struct htc_target *)Context;
517
struct htc_endpoint *pEndpoint;
518
u32 nextLookAheads[HTC_HOST_MAX_MSG_PER_BUNDLE];
523
519
int numLookAheads = 0;
525
A_BOOL checkMorePkts = TRUE;
521
bool checkMorePkts = true;
527
523
AR_DEBUG_PRINTF(ATH_DEBUG_RECV, ("+HTCRecvCompleteHandler (pkt:0x%lX, status:%d, ep:%d) \n",
528
524
(unsigned long)pPacket, pPacket->Status, pPacket->Endpoint));
568
564
/* check for more recv packets before indicating */
569
565
HTCAsyncRecvCheckMorePackets(target,nextLookAheads,numLookAheads,checkMorePkts);
573
if (A_FAILED(status)) {
574
570
AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
575
571
("HTCRecvCompleteHandler , message fetch failed (status = %d) \n",
587
583
/* synchronously wait for a control message from the target,
588
584
* This function is used at initialization time ONLY. At init messages
589
585
* on ENDPOINT 0 are expected. */
590
A_STATUS HTCWaitforControlMessage(HTC_TARGET *target, HTC_PACKET **ppControlPacket)
586
int HTCWaitforControlMessage(struct htc_target *target, struct htc_packet **ppControlPacket)
594
HTC_PACKET *pPacket = NULL;
590
struct htc_packet *pPacket = NULL;
591
struct htc_frame_hdr *pHdr;
597
593
AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("+HTCWaitforControlMessage \n"));
613
609
("HTCWaitforControlMessage : lookAhead : 0x%X \n", lookAhead));
615
611
/* check the lookahead */
616
pHdr = (HTC_FRAME_HDR *)&lookAhead;
612
pHdr = (struct htc_frame_hdr *)&lookAhead;
618
614
if (pHdr->EndpointID != ENDPOINT_0) {
619
615
/* unexpected endpoint number, should be zero */
620
AR_DEBUG_ASSERT(FALSE);
616
AR_DEBUG_ASSERT(false);
621
617
status = A_EPROTO;
625
if (A_FAILED(status)) {
626
622
/* bad message */
627
AR_DEBUG_ASSERT(FALSE);
623
AR_DEBUG_ASSERT(false);
628
624
status = A_EPROTO;
663
659
pPacket->Status = status;
665
if (A_FAILED(status)) {
666
662
AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
667
663
("HTCWaitforControlMessage, HTCProcessRecvHeader failed (status = %d) \n",
672
668
/* give the caller this control message packet, they are responsible to free */
673
669
*ppControlPacket = pPacket;
677
if (A_FAILED(status)) {
678
674
if (pPacket != NULL) {
679
675
/* cleanup buffer on error */
680
676
HTC_FREE_CONTROL_RX(target,pPacket);
689
static A_STATUS AllocAndPrepareRxPackets(HTC_TARGET *target,
690
A_UINT32 LookAheads[],
685
static int AllocAndPrepareRxPackets(struct htc_target *target,
692
HTC_ENDPOINT *pEndpoint,
693
HTC_PACKET_QUEUE *pQueue)
688
struct htc_endpoint *pEndpoint,
689
struct htc_packet_queue *pQueue)
695
A_STATUS status = A_OK;
692
struct htc_packet *pPacket;
693
struct htc_frame_hdr *pHdr;
703
699
/* lock RX while we assemble the packet buffers */
704
700
LOCK_HTC_RX(target);
706
702
for (i = 0; i < Messages; i++) {
708
pHdr = (HTC_FRAME_HDR *)&LookAheads[i];
704
pHdr = (struct htc_frame_hdr *)&LookAheads[i];
710
706
if (pHdr->EndpointID >= ENDPOINT_MAX) {
711
707
AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Invalid Endpoint in look-ahead: %d \n",pHdr->EndpointID));
725
721
if (pHdr->PayloadLen > HTC_MAX_PAYLOAD_LENGTH) {
726
722
AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Payload length %d exceeds max HTC : %d !\n",
727
pHdr->PayloadLen, (A_UINT32)HTC_MAX_PAYLOAD_LENGTH));
723
pHdr->PayloadLen, (u32)HTC_MAX_PAYLOAD_LENGTH));
728
724
status = A_EPROTO;
751
747
("HTC header indicates :%d messages can be fetched as a bundle \n",numMessages));
754
fullLength = DEV_CALC_RECV_PADDED_LEN(&target->Device,pHdr->PayloadLen + sizeof(HTC_FRAME_HDR));
750
fullLength = DEV_CALC_RECV_PADDED_LEN(&target->Device,pHdr->PayloadLen + sizeof(struct htc_frame_hdr));
756
752
/* get packet buffers for each message, if there was a bundle detected in the header,
757
753
* use pHdr as a template to fetch all packets in the bundle */
760
756
/* reset flag, any packets allocated using the RecvAlloc() API cannot be recycled on cleanup,
761
757
* they must be explicitly returned */
764
760
if (pEndpoint->EpCallBacks.EpRecvAlloc != NULL) {
765
761
UNLOCK_HTC_RX(target);
767
763
/* user is using a per-packet allocation callback */
768
764
pPacket = pEndpoint->EpCallBacks.EpRecvAlloc(pEndpoint->EpCallBacks.pContext,
776
772
INC_HTC_EP_STAT(pEndpoint,RxAllocThreshBytes,pHdr->PayloadLen);
777
773
/* threshold was hit, call the special recv allocation callback */
778
774
UNLOCK_HTC_RX(target);
780
776
/* user wants to allocate packets above a certain threshold */
781
777
pPacket = pEndpoint->EpCallBacks.EpRecvAllocThresh(pEndpoint->EpCallBacks.pContext,
834
830
/* make sure this message can fit in the endpoint buffer */
835
if ((A_UINT32)fullLength > pPacket->BufferLength) {
831
if ((u32)fullLength > pPacket->BufferLength) {
836
832
AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
837
833
("Payload Length Error : header reports payload of: %d (%d) endpoint buffer size: %d \n",
838
834
pHdr->PayloadLen, fullLength, pPacket->BufferLength));
882
static void HTCAsyncRecvScatterCompletion(HIF_SCATTER_REQ *pScatterReq)
878
static void HTCAsyncRecvScatterCompletion(struct hif_scatter_req *pScatterReq)
886
HTC_ENDPOINT *pEndpoint;
887
A_UINT32 lookAheads[HTC_HOST_MAX_MSG_PER_BUNDLE];
881
struct htc_packet *pPacket;
882
struct htc_endpoint *pEndpoint;
883
u32 lookAheads[HTC_HOST_MAX_MSG_PER_BUNDLE];
888
884
int numLookAheads = 0;
889
HTC_TARGET *target = (HTC_TARGET *)pScatterReq->Context;
891
A_BOOL partialBundle = FALSE;
892
HTC_PACKET_QUEUE localRecvQueue;
893
A_BOOL procError = FALSE;
885
struct htc_target *target = (struct htc_target *)pScatterReq->Context;
887
bool partialBundle = false;
888
struct htc_packet_queue localRecvQueue;
889
bool procError = false;
895
891
AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("+HTCAsyncRecvScatterCompletion TotLen: %d Entries: %d\n",
896
892
pScatterReq->TotalLength, pScatterReq->ValidScatterEntries));
898
894
A_ASSERT(!IS_DEV_IRQ_PROC_SYNC_MODE(&target->Device));
900
if (A_FAILED(pScatterReq->CompletionStatus)) {
896
if (pScatterReq->CompletionStatus) {
901
897
AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("** Recv Scatter Request Failed: %d \n",pScatterReq->CompletionStatus));
904
900
if (pScatterReq->CallerFlags & HTC_SCATTER_REQ_FLAGS_PARTIAL_BUNDLE) {
905
partialBundle = TRUE;
901
partialBundle = true;
908
904
DEV_FINISH_SCATTER_OPERATION(pScatterReq);
910
906
INIT_HTC_PACKET_QUEUE(&localRecvQueue);
912
pPacket = (HTC_PACKET *)pScatterReq->ScatterList[0].pCallerContexts[0];
908
pPacket = (struct htc_packet *)pScatterReq->ScatterList[0].pCallerContexts[0];
913
909
/* note: all packets in a scatter req are for the same endpoint ! */
914
910
pEndpoint = &target->EndPoint[pPacket->Endpoint];
917
913
/* **** NOTE: DO NOT HOLD ANY LOCKS here, HTCProcessRecvHeader can take the TX lock
918
914
* as it processes credit reports */
919
915
for (i = 0; i < pScatterReq->ValidScatterEntries; i++) {
920
pPacket = (HTC_PACKET *)pScatterReq->ScatterList[i].pCallerContexts[0];
916
pPacket = (struct htc_packet *)pScatterReq->ScatterList[i].pCallerContexts[0];
921
917
A_ASSERT(pPacket != NULL);
922
918
/* reset count, we are only interested in the look ahead in the last packet when we
923
919
* break out of this loop */
924
920
numLookAheads = 0;
926
if (A_SUCCESS(pScatterReq->CompletionStatus)) {
922
if (!pScatterReq->CompletionStatus) {
927
923
/* process header for each of the recv packets */
928
924
status = HTCProcessRecvHeader(target,pPacket,lookAheads,&numLookAheads);
930
926
status = A_ERROR;
933
if (A_SUCCESS(status)) {
934
#ifdef HTC_EP_STAT_PROFILING
935
930
LOCK_HTC_RX(target);
936
931
HTC_RX_STAT_PROFILE(target,pEndpoint,numLookAheads);
937
932
INC_HTC_EP_STAT(pEndpoint, RxPacketsBundled, 1);
938
933
UNLOCK_HTC_RX(target);
940
934
if (i == (pScatterReq->ValidScatterEntries - 1)) {
941
935
/* last packet's more packets flag is set based on the lookahead */
942
936
SET_MORE_RX_PACKET_INDICATION_FLAG(lookAheads,numLookAheads,pEndpoint,pPacket);
975
969
HTCAsyncRecvCheckMorePackets(target,
978
partialBundle ? FALSE : TRUE);
972
partialBundle ? false : true);
981
975
/* now drain the indication queue */
984
978
AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("-HTCAsyncRecvScatterCompletion \n"));
987
static A_STATUS HTCIssueRecvPacketBundle(HTC_TARGET *target,
988
HTC_PACKET_QUEUE *pRecvPktQueue,
989
HTC_PACKET_QUEUE *pSyncCompletionQueue,
981
static int HTCIssueRecvPacketBundle(struct htc_target *target,
982
struct htc_packet_queue *pRecvPktQueue,
983
struct htc_packet_queue *pSyncCompletionQueue,
990
984
int *pNumPacketsFetched,
991
A_BOOL PartialBundle)
993
A_STATUS status = A_OK;
994
HIF_SCATTER_REQ *pScatterReq;
988
struct hif_scatter_req *pScatterReq;
995
989
int i, totalLength;
996
990
int pktsToScatter;
998
A_BOOL asyncMode = (pSyncCompletionQueue == NULL) ? TRUE : FALSE;
991
struct htc_packet *pPacket;
992
bool asyncMode = (pSyncCompletionQueue == NULL) ? true : false;
999
993
int scatterSpaceRemaining = DEV_GET_MAX_BUNDLE_RECV_LENGTH(&target->Device);
1001
995
pktsToScatter = HTC_PACKET_QUEUE_DEPTH(pRecvPktQueue);
1004
998
if ((HTC_PACKET_QUEUE_DEPTH(pRecvPktQueue) - pktsToScatter) > 0) {
1005
999
/* we were forced to split this bundle receive operation
1006
1000
* all packets in this partial bundle must have their lookaheads ignored */
1007
PartialBundle = TRUE;
1001
PartialBundle = true;
1008
1002
/* this would only happen if the target ignored our max bundle limit */
1009
1003
AR_DEBUG_PRINTF(ATH_DEBUG_WARN,
1010
1004
("HTCIssueRecvPacketBundle : partial bundle detected num:%d , %d \n",
1094
1088
DEV_FREE_SCATTER_REQ(&target->Device, pScatterReq);
1099
1093
AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("-HTCIssueRecvPacketBundle (status:%d) (fetched:%d) \n",
1100
1094
status,*pNumPacketsFetched));
1105
static INLINE void CheckRecvWaterMark(HTC_ENDPOINT *pEndpoint)
1099
static INLINE void CheckRecvWaterMark(struct htc_endpoint *pEndpoint)
1107
1101
/* see if endpoint is using a refill watermark
1108
1102
* ** no need to use a lock here, since we are only inspecting...
1119
1113
/* callback when device layer or lookahead report parsing detects a pending message */
1120
A_STATUS HTCRecvMessagePendingHandler(void *Context, A_UINT32 MsgLookAheads[], int NumLookAheads, A_BOOL *pAsyncProc, int *pNumPktsFetched)
1114
int HTCRecvMessagePendingHandler(void *Context, u32 MsgLookAheads[], int NumLookAheads, bool *pAsyncProc, int *pNumPktsFetched)
1122
HTC_TARGET *target = (HTC_TARGET *)Context;
1123
A_STATUS status = A_OK;
1124
HTC_PACKET *pPacket;
1125
HTC_ENDPOINT *pEndpoint;
1126
A_BOOL asyncProc = FALSE;
1127
A_UINT32 lookAheads[HTC_HOST_MAX_MSG_PER_BUNDLE];
1116
struct htc_target *target = (struct htc_target *)Context;
1118
struct htc_packet *pPacket;
1119
struct htc_endpoint *pEndpoint;
1120
bool asyncProc = false;
1121
u32 lookAheads[HTC_HOST_MAX_MSG_PER_BUNDLE];
1128
1122
int pktsFetched;
1129
HTC_PACKET_QUEUE recvPktQueue, syncCompletedPktsQueue;
1130
A_BOOL partialBundle;
1123
struct htc_packet_queue recvPktQueue, syncCompletedPktsQueue;
1131
1125
HTC_ENDPOINT_ID id;
1132
1126
int totalFetched = 0;
1141
1135
/* We use async mode to get the packets if the device layer supports it.
1142
1136
* The device layer interfaces with HIF in which HIF may have restrictions on
1143
1137
* how interrupts are processed */
1147
1141
if (pAsyncProc != NULL) {
1152
1146
if (NumLookAheads > HTC_HOST_MAX_MSG_PER_BUNDLE) {
1154
1148
return A_EPROTO;
1157
1151
/* on first entry copy the lookaheads into our temp array for processing */
1158
A_MEMCPY(lookAheads, MsgLookAheads, (sizeof(A_UINT32)) * NumLookAheads);
1152
memcpy(lookAheads, MsgLookAheads, (sizeof(u32)) * NumLookAheads);
1162
1156
/* reset packets queues */
1163
1157
INIT_HTC_PACKET_QUEUE(&recvPktQueue);
1166
1160
if (NumLookAheads > HTC_HOST_MAX_MSG_PER_BUNDLE) {
1167
1161
status = A_EPROTO;
1172
1166
/* first lookahead sets the expected endpoint IDs for all packets in a bundle */
1173
id = ((HTC_FRAME_HDR *)&lookAheads[0])->EndpointID;
1167
id = ((struct htc_frame_hdr *)&lookAheads[0])->EndpointID;
1174
1168
pEndpoint = &target->EndPoint[id];
1176
1170
if (id >= ENDPOINT_MAX) {
1200
1194
/* we've got packet buffers for all we can currently fetch,
1201
1195
* this count is not valid anymore */
1202
1196
NumLookAheads = 0;
1203
partialBundle = FALSE;
1197
partialBundle = false;
1205
1199
/* now go fetch the list of HTC packets */
1206
1200
while (!HTC_QUEUE_EMPTY(&recvPktQueue)) {
1284
1278
/* unload sync completion queue */
1285
1279
while (!HTC_QUEUE_EMPTY(&syncCompletedPktsQueue)) {
1286
HTC_PACKET_QUEUE container;
1280
struct htc_packet_queue container;
1288
1282
pPacket = HTC_PACKET_DEQUEUE(&syncCompletedPktsQueue);
1289
1283
A_ASSERT(pPacket != NULL);
1295
1289
/* process header for each of the recv packets
1296
1290
* note: the lookahead of the last packet is useful for us to continue in this loop */
1297
1291
status = HTCProcessRecvHeader(target,pPacket,lookAheads,&NumLookAheads);
1298
if (A_FAILED(status)) {
1346
1340
REF_IRQ_STATUS_RECHECK(&target->Device);
1349
if (A_FAILED(status)) {
1350
1344
AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
1351
1345
("Failed to get pending recv messages (%d) \n",status));
1352
1346
/* cleanup any packets we allocated but didn't use to actually fetch any packets */
1388
A_STATUS HTCAddReceivePktMultiple(HTC_HANDLE HTCHandle, HTC_PACKET_QUEUE *pPktQueue)
1382
int HTCAddReceivePktMultiple(HTC_HANDLE HTCHandle, struct htc_packet_queue *pPktQueue)
1390
HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
1391
HTC_ENDPOINT *pEndpoint;
1392
A_BOOL unblockRecv = FALSE;
1393
A_STATUS status = A_OK;
1394
HTC_PACKET *pFirstPacket;
1384
struct htc_target *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
1385
struct htc_endpoint *pEndpoint;
1386
bool unblockRecv = false;
1388
struct htc_packet *pFirstPacket;
1396
1390
pFirstPacket = HTC_GET_PKT_AT_HEAD(pPktQueue);
1398
1392
if (NULL == pFirstPacket) {
1400
1394
return A_EINVAL;
1449
1443
DevEnableRecv(&target->Device,DEV_ENABLE_RECV_SYNC);
1457
1451
/* Makes a buffer available to the HTC module */
1458
A_STATUS HTCAddReceivePkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket)
1452
int HTCAddReceivePkt(HTC_HANDLE HTCHandle, struct htc_packet *pPacket)
1460
HTC_PACKET_QUEUE queue;
1454
struct htc_packet_queue queue;
1461
1455
INIT_HTC_PACKET_QUEUE_AND_ADD(&queue,pPacket);
1462
1456
return HTCAddReceivePktMultiple(HTCHandle, &queue);
1465
1459
void HTCUnblockRecv(HTC_HANDLE HTCHandle)
1467
HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
1468
A_BOOL unblockRecv = FALSE;
1461
struct htc_target *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
1462
bool unblockRecv = false;
1470
1464
LOCK_HTC_RX(target);
1489
static void HTCFlushRxQueue(HTC_TARGET *target, HTC_ENDPOINT *pEndpoint, HTC_PACKET_QUEUE *pQueue)
1483
static void HTCFlushRxQueue(struct htc_target *target, struct htc_endpoint *pEndpoint, struct htc_packet_queue *pQueue)
1491
HTC_PACKET *pPacket;
1492
HTC_PACKET_QUEUE container;
1485
struct htc_packet *pPacket;
1486
struct htc_packet_queue container;
1494
1488
LOCK_HTC_RX(target);
1512
1506
UNLOCK_HTC_RX(target);
1515
static void HTCFlushEndpointRX(HTC_TARGET *target, HTC_ENDPOINT *pEndpoint)
1509
static void HTCFlushEndpointRX(struct htc_target *target, struct htc_endpoint *pEndpoint)
1517
1511
/* flush any recv indications not already made */
1518
1512
HTCFlushRxQueue(target,pEndpoint,&pEndpoint->RecvIndicationQueue);
1520
1514
HTCFlushRxQueue(target,pEndpoint,&pEndpoint->RxBuffers);
1523
void HTCFlushRecvBuffers(HTC_TARGET *target)
1517
void HTCFlushRecvBuffers(struct htc_target *target)
1525
HTC_ENDPOINT *pEndpoint;
1519
struct htc_endpoint *pEndpoint;
1528
1522
for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) {
1559
1553
int HTCGetNumRecvBuffers(HTC_HANDLE HTCHandle,
1560
1554
HTC_ENDPOINT_ID Endpoint)
1562
HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
1556
struct htc_target *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
1563
1557
return HTC_PACKET_QUEUE_DEPTH(&(target->EndPoint[Endpoint].RxBuffers));
1566
A_STATUS HTCWaitForPendingRecv(HTC_HANDLE HTCHandle,
1567
A_UINT32 TimeoutInMs,
1568
A_BOOL *pbIsRecvPending)
1560
int HTCWaitForPendingRecv(HTC_HANDLE HTCHandle,
1562
bool *pbIsRecvPending)
1570
A_STATUS status = A_OK;
1571
HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
1565
struct htc_target *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
1573
1567
status = DevWaitForPendingRecv(&target->Device,