~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/staging/ath6kl/htc2/htc_recv.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
                        (pP)->PktInfo.AsRx.ExpectedHdr,        \
37
37
                        (pP)->Endpoint))                         
38
38
                        
39
 
#ifdef HTC_EP_STAT_PROFILING
40
39
#define HTC_RX_STAT_PROFILE(t,ep,numLookAheads)        \
41
40
{                                                      \
42
41
    INC_HTC_EP_STAT((ep), RxReceived, 1);              \
46
45
        INC_HTC_EP_STAT((ep), RxBundleLookAheads, 1);  \
47
46
    }                                                  \
48
47
}
49
 
#else
50
 
#define HTC_RX_STAT_PROFILE(t,ep,lookAhead)
51
 
#endif
52
48
 
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)
55
51
{           
56
52
    
57
53
    do {
69
65
                                                     pQueueToIndicate);
70
66
            INIT_HTC_PACKET_QUEUE(pQueueToIndicate);        
71
67
        } else {
72
 
            HTC_PACKET *pPacket;  
 
68
            struct htc_packet *pPacket;  
73
69
            /* using legacy EpRecv */         
74
70
            do {
75
71
                pPacket = HTC_PACKET_DEQUEUE(pQueueToIndicate);
79
75
            } while (!HTC_QUEUE_EMPTY(pQueueToIndicate));                                              
80
76
        }
81
77
        
82
 
    } while (FALSE);
 
78
    } while (false);
83
79
 
84
80
}
85
81
 
86
 
static INLINE A_STATUS HTCProcessTrailer(HTC_TARGET *target,
87
 
                                         A_UINT8    *pBuffer,
 
82
static INLINE int HTCProcessTrailer(struct htc_target *target,
 
83
                                         u8 *pBuffer,
88
84
                                         int         Length,
89
 
                                         A_UINT32   *pNextLookAheads,
 
85
                                         u32 *pNextLookAheads,
90
86
                                         int        *pNumLookAheads,
91
87
                                         HTC_ENDPOINT_ID FromEndpoint)
92
88
{
93
89
    HTC_RECORD_HDR          *pRecord;
94
 
    A_UINT8                 *pRecordBuf;
 
90
    u8 *pRecordBuf;
95
91
    HTC_LOOKAHEAD_REPORT    *pLookAhead;
96
 
    A_UINT8                 *pOrigBuffer;
 
92
    u8 *pOrigBuffer;
97
93
    int                     origLength;
98
 
    A_STATUS                status;
 
94
    int                status;
99
95
 
100
96
    AR_DEBUG_PRINTF(ATH_DEBUG_RECV, ("+HTCProcessTrailer (length:%d) \n", Length));
101
97
 
105
101
 
106
102
    pOrigBuffer = pBuffer;
107
103
    origLength = Length;
108
 
    status = A_OK;
 
104
    status = 0;
109
105
    
110
106
    while (Length > 0) {
111
107
 
149
145
                                pLookAhead->PostValid));
150
146
 
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];
156
152
 
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");
160
156
                    }
161
157
#endif
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 */        
185
 
                        A_ASSERT(FALSE);
 
181
                        A_ASSERT(false);
186
182
                        status = A_EPROTO;
187
183
                        break;        
188
184
                    }
189
185
                                         
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++;
196
192
                    }
197
193
                    
204
200
                break;
205
201
        }
206
202
 
207
 
        if (A_FAILED(status)) {
 
203
        if (status) {
208
204
            break;
209
205
        }
210
206
 
214
210
    }
215
211
 
216
212
#ifdef ATH_DEBUG_MODULE
217
 
    if (A_FAILED(status)) {
 
213
    if (status) {
218
214
        DebugDumpBytes(pOrigBuffer,origLength,"BAD Recv Trailer");
219
215
    }
220
216
#endif
226
222
 
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, 
230
 
                                     HTC_PACKET *pPacket, 
231
 
                                     A_UINT32   *pNextLookAheads, 
 
225
static int HTCProcessRecvHeader(struct htc_target *target,
 
226
                                     struct htc_packet *pPacket, 
 
227
                                     u32 *pNextLookAheads,
232
228
                                     int        *pNumLookAheads)
233
229
{
234
 
    A_UINT8   temp;
235
 
    A_UINT8   *pBuf;
236
 
    A_STATUS  status = A_OK;
237
 
    A_UINT16  payloadLen;
238
 
    A_UINT32  lookAhead;
 
230
    u8 temp;
 
231
    u8 *pBuf;
 
232
    int  status = 0;
 
233
    u16 payloadLen;
 
234
    u32 lookAhead;
239
235
 
240
236
    pBuf = pPacket->pBuffer;
241
237
    
252
248
    do {
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);
256
252
        
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];
261
257
 
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
277
273
                break;    
278
274
            }
279
275
            
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;
285
281
                break;      
286
282
            }   
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,
309
305
        }
310
306
 
311
307
            /* get flags */
312
 
        temp = A_GET_UINT8_FIELD(pBuf, HTC_FRAME_HDR, Flags);
 
308
        temp = A_GET_UINT8_FIELD(pBuf, struct htc_frame_hdr, Flags);
313
309
 
314
310
        if (temp & HTC_FLAGS_RECV_TRAILER) {
315
311
            /* this packet has a trailer */
316
312
 
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]);
319
315
 
320
316
            if ((temp < sizeof(HTC_RECORD_HDR)) || (temp > payloadLen)) {
321
317
                AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
341
337
                                       pNumLookAheads,
342
338
                                       pPacket->Endpoint);
343
339
 
344
 
            if (A_FAILED(status)) {
 
340
            if (status) {
345
341
                break;
346
342
            }
347
343
 
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;
351
347
#endif
352
348
                /* trim length by trailer bytes */
363
359
        pPacket->pBuffer += HTC_HDR_LENGTH;
364
360
        pPacket->ActualLength -= HTC_HDR_LENGTH;
365
361
 
366
 
    } while (FALSE);
 
362
    } while (false);
367
363
 
368
 
    if (A_FAILED(status)) {
 
364
    if (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");
372
368
#endif
373
369
    } else {
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));
376
372
#endif
377
373
        if (AR_DEBUG_LVL_CHECK(ATH_DEBUG_RECV)) {
378
374
            if (pPacket->ActualLength > 0) {
385
381
    return status;
386
382
}
387
383
 
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)
 
387
                                                bool      CheckMoreMsgs)
392
388
{
393
389
        /* was there a lookahead for the next packet? */
394
390
    if (NumLookAheads > 0) {
395
 
        A_STATUS nextStatus;
 
391
        int nextStatus;
396
392
        int      fetched = 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");
411
407
#endif
412
408
        }
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);        
416
412
        }
432
428
}      
433
429
 
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)
436
432
{
437
 
    HTC_PACKET_QUEUE     recvCompletions;
 
433
    struct htc_packet_queue     recvCompletions;
438
434
    
439
435
    AR_DEBUG_PRINTF(ATH_DEBUG_RECV, ("+DrainRecvIndicationQueue \n"));
440
436
                
454
450
    
455
451
    /******* at this point only 1 thread may enter ******/
456
452
     
457
 
    while (TRUE) { 
 
453
    while (true) {
458
454
                
459
455
            /* transfer items from main recv queue to the local one so we can release the lock */ 
460
456
        HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(&recvCompletions, &pEndpoint->RecvIndicationQueue);
496
492
    (P)->PktInfo.AsRx.IndicationFlags |= HTC_RX_FLAGS_INDICATE_MORE_PKTS; 
497
493
   
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, 
501
 
                                              HTC_PACKET    *pPacket)
 
495
static INLINE void SetRxPacketIndicationFlags(u32 LookAhead,
 
496
                                              struct htc_endpoint  *pEndpoint, 
 
497
                                              struct htc_packet    *pPacket)
502
498
{
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) {
515
511
     
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)
519
515
{
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;
524
 
    A_STATUS        status;
525
 
    A_BOOL          checkMorePkts = TRUE;
 
520
    int        status;
 
521
    bool          checkMorePkts = true;
526
522
 
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));
537
533
 
538
534
    do {
539
535
        
540
 
        if (A_FAILED(status)) {
 
536
        if (status) {
541
537
            AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("HTCRecvCompleteHandler: request failed (status:%d, ep:%d) \n",
542
538
                pPacket->Status, pPacket->Endpoint));
543
539
            break;
545
541
            /* process the header for any trailer data */
546
542
        status = HTCProcessRecvHeader(target,pPacket,nextLookAheads,&numLookAheads);
547
543
 
548
 
        if (A_FAILED(status)) {
 
544
        if (status) {
549
545
            break;
550
546
        }
551
547
        
554
550
                 * It was fetched one message at a time.  There may be other asynchronous reads queued behind this one.
555
551
                 * Do no issue another check for more packets since the last one in the series of requests
556
552
                 * will handle it */
557
 
            checkMorePkts = FALSE;    
 
553
            checkMorePkts = false;
558
554
        }
559
555
          
560
556
        DUMP_RECV_PKT_INFO(pPacket);    
568
564
            /* check for more recv packets before indicating */
569
565
        HTCAsyncRecvCheckMorePackets(target,nextLookAheads,numLookAheads,checkMorePkts);
570
566
 
571
 
    } while (FALSE);
 
567
    } while (false);
572
568
 
573
 
    if (A_FAILED(status)) {
 
569
    if (status) {
574
570
         AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
575
571
                         ("HTCRecvCompleteHandler , message fetch failed (status = %d) \n",
576
572
                         status));
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)
591
587
{
592
 
    A_STATUS        status;
593
 
    A_UINT32        lookAhead;
594
 
    HTC_PACKET      *pPacket = NULL;
595
 
    HTC_FRAME_HDR   *pHdr;
 
588
    int        status;
 
589
    u32 lookAhead;
 
590
    struct htc_packet      *pPacket = NULL;
 
591
    struct htc_frame_hdr   *pHdr;
596
592
 
597
593
    AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("+HTCWaitforControlMessage \n"));
598
594
 
605
601
                                    &lookAhead,
606
602
                                    HTC_TARGET_RESPONSE_TIMEOUT);
607
603
 
608
 
        if (A_FAILED(status)) {
 
604
        if (status) {
609
605
            break;
610
606
        }
611
607
 
613
609
                ("HTCWaitforControlMessage : lookAhead : 0x%X \n", lookAhead));
614
610
 
615
611
            /* check the lookahead */
616
 
        pHdr = (HTC_FRAME_HDR *)&lookAhead;
 
612
        pHdr = (struct htc_frame_hdr *)&lookAhead;
617
613
 
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;
622
618
            break;
623
619
        }
624
620
 
625
 
        if (A_FAILED(status)) {
 
621
        if (status) {
626
622
                /* bad message */
627
 
            AR_DEBUG_ASSERT(FALSE);
 
623
            AR_DEBUG_ASSERT(false);
628
624
            status = A_EPROTO;
629
625
            break;
630
626
        }
632
628
        pPacket = HTC_ALLOC_CONTROL_RX(target);
633
629
 
634
630
        if (pPacket == NULL) {
635
 
            AR_DEBUG_ASSERT(FALSE);
 
631
            AR_DEBUG_ASSERT(false);
636
632
            status = A_NO_MEMORY;
637
633
            break;
638
634
        }
642
638
        pPacket->ActualLength = pHdr->PayloadLen + HTC_HDR_LENGTH;
643
639
 
644
640
        if (pPacket->ActualLength > pPacket->BufferLength) {
645
 
            AR_DEBUG_ASSERT(FALSE);
 
641
            AR_DEBUG_ASSERT(false);
646
642
            status = A_EPROTO;
647
643
            break;
648
644
        }
653
649
            /* get the message from the device, this will block */
654
650
        status = HTCIssueRecv(target, pPacket);
655
651
 
656
 
        if (A_FAILED(status)) {
 
652
        if (status) {
657
653
            break;
658
654
        }
659
655
 
662
658
 
663
659
        pPacket->Status = status;
664
660
 
665
 
        if (A_FAILED(status)) {
 
661
        if (status) {
666
662
            AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
667
663
                    ("HTCWaitforControlMessage, HTCProcessRecvHeader failed (status = %d) \n",
668
664
                     status));
672
668
            /* give the caller this control message packet, they are responsible to free */
673
669
        *ppControlPacket = pPacket;
674
670
 
675
 
    } while (FALSE);
 
671
    } while (false);
676
672
 
677
 
    if (A_FAILED(status)) {
 
673
    if (status) {
678
674
        if (pPacket != NULL) {
679
675
                /* cleanup buffer on error */
680
676
            HTC_FREE_CONTROL_RX(target,pPacket);
686
682
    return status;
687
683
}
688
684
 
689
 
static A_STATUS AllocAndPrepareRxPackets(HTC_TARGET       *target, 
690
 
                                         A_UINT32         LookAheads[], 
 
685
static int AllocAndPrepareRxPackets(struct htc_target       *target,
 
686
                                         u32 LookAheads[],
691
687
                                         int              Messages,                                        
692
 
                                         HTC_ENDPOINT     *pEndpoint, 
693
 
                                         HTC_PACKET_QUEUE *pQueue)
 
688
                                         struct htc_endpoint     *pEndpoint, 
 
689
                                         struct htc_packet_queue *pQueue)
694
690
{
695
 
    A_STATUS         status = A_OK;
696
 
    HTC_PACKET      *pPacket;
697
 
    HTC_FRAME_HDR   *pHdr;
 
691
    int         status = 0;
 
692
    struct htc_packet      *pPacket;
 
693
    struct htc_frame_hdr   *pHdr;
698
694
    int              i,j;
699
695
    int              numMessages;
700
696
    int              fullLength;
701
 
    A_BOOL           noRecycle;
 
697
    bool           noRecycle;
702
698
            
703
699
        /* lock RX while we assemble the packet buffers */
704
700
    LOCK_HTC_RX(target);
705
701
                        
706
702
    for (i = 0; i < Messages; i++) {   
707
703
         
708
 
        pHdr = (HTC_FRAME_HDR *)&LookAheads[i];
 
704
        pHdr = (struct htc_frame_hdr *)&LookAheads[i];
709
705
 
710
706
        if (pHdr->EndpointID >= ENDPOINT_MAX) {
711
707
            AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Invalid Endpoint in look-ahead: %d \n",pHdr->EndpointID));
724
720
       
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;
729
725
            break;
730
726
        }
751
747
                ("HTC header indicates :%d messages can be fetched as a bundle \n",numMessages));           
752
748
        }
753
749
     
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));
755
751
            
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 */        
759
755
            
760
756
                /* reset flag, any packets allocated using the RecvAlloc() API cannot be recycled on cleanup,
761
757
                 * they must be explicitly returned */
762
 
            noRecycle = FALSE;
 
758
            noRecycle = false;
763
759
                                                                                   
764
760
            if (pEndpoint->EpCallBacks.EpRecvAlloc != NULL) {
765
761
                UNLOCK_HTC_RX(target);
766
 
                noRecycle = TRUE;
 
762
                noRecycle = true;
767
763
                    /* user is using a per-packet allocation callback */
768
764
                pPacket = pEndpoint->EpCallBacks.EpRecvAlloc(pEndpoint->EpCallBacks.pContext,
769
765
                                                             pEndpoint->Id,
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);
779
 
                noRecycle = TRUE;
 
775
                noRecycle = true;
780
776
                    /* user wants to allocate packets above a certain threshold */
781
777
                pPacket = pEndpoint->EpCallBacks.EpRecvAllocThresh(pEndpoint->EpCallBacks.pContext,
782
778
                                                                   pEndpoint->Id,
816
812
                /* clear flags */
817
813
            pPacket->PktInfo.AsRx.HTCRxFlags = 0;
818
814
            pPacket->PktInfo.AsRx.IndicationFlags = 0;
819
 
            pPacket->Status = A_OK;
 
815
            pPacket->Status = 0;
820
816
            
821
817
            if (noRecycle) {
822
818
                    /* flag that these packets cannot be recycled, they have to be returned to the 
832
828
            }
833
829
    
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));
856
852
            pPacket->ActualLength = pHdr->PayloadLen + HTC_HDR_LENGTH;
857
853
        }
858
854
        
859
 
        if (A_FAILED(status)) {
 
855
        if (status) {
860
856
            if (A_NO_RESOURCE == status) {
861
857
                    /* this is actually okay */
862
 
                status = A_OK;    
 
858
                status = 0;
863
859
            }
864
860
            break;    
865
861
        }
868
864
    
869
865
    UNLOCK_HTC_RX(target);
870
866
    
871
 
    if (A_FAILED(status)) {
 
867
    if (status) {
872
868
        while (!HTC_QUEUE_EMPTY(pQueue)) {
873
869
            pPacket = HTC_PACKET_DEQUEUE(pQueue);
874
870
                /* recycle all allocated packets */
879
875
    return status; 
880
876
}
881
877
 
882
 
static void HTCAsyncRecvScatterCompletion(HIF_SCATTER_REQ *pScatterReq)
 
878
static void HTCAsyncRecvScatterCompletion(struct hif_scatter_req *pScatterReq)
883
879
{
884
880
    int                 i;    
885
 
    HTC_PACKET          *pPacket;
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;
890
 
    A_STATUS            status;
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;
 
886
    int            status;
 
887
    bool              partialBundle = false;
 
888
    struct htc_packet_queue    localRecvQueue;
 
889
    bool              procError = false;
894
890
           
895
891
    AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("+HTCAsyncRecvScatterCompletion  TotLen: %d  Entries: %d\n",
896
892
        pScatterReq->TotalLength, pScatterReq->ValidScatterEntries));
897
893
    
898
894
    A_ASSERT(!IS_DEV_IRQ_PROC_SYNC_MODE(&target->Device));
899
895
           
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));            
902
898
    }
903
899
    
904
900
    if (pScatterReq->CallerFlags & HTC_SCATTER_REQ_FLAGS_PARTIAL_BUNDLE) {
905
 
        partialBundle = TRUE;    
 
901
        partialBundle = true;
906
902
    }
907
903
    
908
904
    DEV_FINISH_SCATTER_OPERATION(pScatterReq);
909
905
    
910
906
    INIT_HTC_PACKET_QUEUE(&localRecvQueue);
911
907
        
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];
915
911
         
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;
925
921
        
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);
929
925
        } else {
930
926
            status = A_ERROR;    
931
927
        }
932
928
        
933
 
        if (A_SUCCESS(status)) {    
934
 
#ifdef HTC_EP_STAT_PROFILING
 
929
        if (!status) {
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);
939
 
#endif      
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);
956
950
                /* recycle failed recv */
957
951
            HTC_RECYCLE_RX_PKT(target, pPacket, pEndpoint);
958
952
                /* set flag and continue processing the remaining scatter entries */
959
 
            procError = TRUE;
 
953
            procError = true;
960
954
        }   
961
955
    
962
956
    }
975
969
        HTCAsyncRecvCheckMorePackets(target,
976
970
                                     lookAheads,
977
971
                                     numLookAheads,
978
 
                                     partialBundle ? FALSE : TRUE);
 
972
                                     partialBundle ? false : true);
979
973
    }
980
974
    
981
975
        /* now drain the indication queue */
984
978
    AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("-HTCAsyncRecvScatterCompletion \n"));
985
979
}
986
980
 
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)
 
985
                                         bool             PartialBundle)
992
986
{
993
 
    A_STATUS        status = A_OK;
994
 
    HIF_SCATTER_REQ *pScatterReq;
 
987
    int        status = 0;
 
988
    struct hif_scatter_req *pScatterReq;
995
989
    int             i, totalLength;
996
990
    int             pktsToScatter;
997
 
    HTC_PACKET      *pPacket;
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);
1000
994
        
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",
1085
1079
        
1086
1080
        status = DevSubmitScatterRequest(&target->Device, pScatterReq, DEV_SCATTER_READ, asyncMode);
1087
1081
        
1088
 
        if (A_SUCCESS(status)) {
 
1082
        if (!status) {
1089
1083
            *pNumPacketsFetched = i;    
1090
1084
        }
1091
1085
        
1094
1088
            DEV_FREE_SCATTER_REQ(&target->Device, pScatterReq);   
1095
1089
        }
1096
1090
        
1097
 
    } while (FALSE);
 
1091
    } while (false);
1098
1092
   
1099
1093
    AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("-HTCIssueRecvPacketBundle (status:%d) (fetched:%d) \n",
1100
1094
            status,*pNumPacketsFetched));
1102
1096
    return status;
1103
1097
}
1104
1098
 
1105
 
static INLINE void CheckRecvWaterMark(HTC_ENDPOINT    *pEndpoint)
 
1099
static INLINE void CheckRecvWaterMark(struct htc_endpoint    *pEndpoint)
1106
1100
{  
1107
1101
        /* see if endpoint is using a refill watermark 
1108
1102
         * ** no need to use a lock here, since we are only inspecting...
1117
1111
}
1118
1112
 
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)
1121
1115
{
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;
 
1117
    int         status = 0;
 
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;
 
1124
    bool          partialBundle;
1131
1125
    HTC_ENDPOINT_ID id;
1132
1126
    int             totalFetched = 0;
1133
1127
    
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 */
1144
 
        asyncProc = TRUE;
 
1138
        asyncProc = true;
1145
1139
    }
1146
1140
 
1147
1141
    if (pAsyncProc != NULL) {
1150
1144
    }
1151
1145
    
1152
1146
    if (NumLookAheads > HTC_HOST_MAX_MSG_PER_BUNDLE) {
1153
 
        A_ASSERT(FALSE);
 
1147
        A_ASSERT(false);
1154
1148
        return A_EPROTO; 
1155
1149
    }
1156
1150
        
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);
1159
1153
            
1160
 
    while (TRUE) {
 
1154
    while (true) {
1161
1155
        
1162
1156
            /* reset packets queues */
1163
1157
        INIT_HTC_PACKET_QUEUE(&recvPktQueue);
1165
1159
        
1166
1160
        if (NumLookAheads > HTC_HOST_MAX_MSG_PER_BUNDLE) {
1167
1161
            status = A_EPROTO;
1168
 
            A_ASSERT(FALSE);
 
1162
            A_ASSERT(false);
1169
1163
            break;    
1170
1164
        }
1171
1165
   
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];
1175
1169
        
1176
1170
        if (id >= ENDPOINT_MAX) {
1186
1180
                                          NumLookAheads,
1187
1181
                                          pEndpoint, 
1188
1182
                                          &recvPktQueue);        
1189
 
        if (A_FAILED(status)) {
 
1183
        if (status) {
1190
1184
            break;    
1191
1185
        }
1192
1186
 
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;
1204
1198
       
1205
1199
            /* now go fetch the list of HTC packets */
1206
1200
        while (!HTC_QUEUE_EMPTY(&recvPktQueue)) {   
1214
1208
                                                  asyncProc ? NULL : &syncCompletedPktsQueue,
1215
1209
                                                  &pktsFetched,
1216
1210
                                                  partialBundle);                                                   
1217
 
                if (A_FAILED(status)) {
 
1211
                if (status) {
1218
1212
                    break;
1219
1213
                }
1220
1214
                
1221
1215
                if (HTC_PACKET_QUEUE_DEPTH(&recvPktQueue) != 0) {
1222
1216
                        /* we couldn't fetch all packets at one time, this creates a broken
1223
1217
                         * bundle  */
1224
 
                    partialBundle = TRUE;    
 
1218
                    partialBundle = true;
1225
1219
                }                                                                     
1226
1220
            }
1227
1221
            
1248
1242
                                    
1249
1243
                    /* go fetch the packet */
1250
1244
                status = HTCIssueRecv(target, pPacket);              
1251
 
                if (A_FAILED(status)) {
 
1245
                if (status) {
1252
1246
                    break;
1253
1247
                }  
1254
1248
                               
1261
1255
            
1262
1256
        }
1263
1257
 
1264
 
        if (A_SUCCESS(status)) {  
 
1258
        if (!status) {
1265
1259
            CheckRecvWaterMark(pEndpoint);
1266
1260
        }
1267
1261
            
1283
1277
             
1284
1278
             /* unload sync completion queue */      
1285
1279
        while (!HTC_QUEUE_EMPTY(&syncCompletedPktsQueue)) {
1286
 
            HTC_PACKET_QUEUE    container;
 
1280
            struct htc_packet_queue    container;
1287
1281
           
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)) {
 
1292
            if (status) {
1299
1293
                break;
1300
1294
            }
1301
1295
            
1317
1311
            DO_RCV_COMPLETION(pEndpoint,&container);
1318
1312
        }
1319
1313
 
1320
 
        if (A_FAILED(status)) {
 
1314
        if (status) {
1321
1315
            break;
1322
1316
        }
1323
1317
            
1346
1340
        REF_IRQ_STATUS_RECHECK(&target->Device);
1347
1341
    }
1348
1342
    
1349
 
    if (A_FAILED(status)) {
 
1343
    if (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 */                        
1385
1379
    return status;
1386
1380
}
1387
1381
 
1388
 
A_STATUS HTCAddReceivePktMultiple(HTC_HANDLE HTCHandle, HTC_PACKET_QUEUE *pPktQueue)
 
1382
int HTCAddReceivePktMultiple(HTC_HANDLE HTCHandle, struct htc_packet_queue *pPktQueue)
1389
1383
{
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;
 
1387
    int        status = 0;
 
1388
    struct htc_packet      *pFirstPacket;
1395
1389
 
1396
1390
    pFirstPacket = HTC_GET_PKT_AT_HEAD(pPktQueue);
1397
1391
    
1398
1392
    if (NULL == pFirstPacket) {
1399
 
        A_ASSERT(FALSE);
 
1393
        A_ASSERT(false);
1400
1394
        return A_EINVAL;    
1401
1395
    }
1402
1396
    
1415
1409
        LOCK_HTC_RX(target);
1416
1410
 
1417
1411
        if (HTC_STOPPING(target)) {
1418
 
            HTC_PACKET *pPacket;
 
1412
            struct htc_packet *pPacket;
1419
1413
            
1420
1414
            UNLOCK_HTC_RX(target);
1421
1415
            
1438
1432
                    target->EpWaitingForBuffers));
1439
1433
                target->RecvStateFlags &= ~HTC_RECV_WAIT_BUFFERS;
1440
1434
                target->EpWaitingForBuffers = ENDPOINT_MAX;
1441
 
                unblockRecv = TRUE;
 
1435
                unblockRecv = true;
1442
1436
            }
1443
1437
        }
1444
1438
 
1449
1443
            DevEnableRecv(&target->Device,DEV_ENABLE_RECV_SYNC);
1450
1444
        }
1451
1445
 
1452
 
    } while (FALSE);
 
1446
    } while (false);
1453
1447
 
1454
1448
    return status;
1455
1449
}
1456
1450
 
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)
1459
1453
{
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);       
1463
1457
}
1464
1458
 
1465
1459
void HTCUnblockRecv(HTC_HANDLE HTCHandle)
1466
1460
{
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;
1469
1463
 
1470
1464
    LOCK_HTC_RX(target);
1471
1465
 
1475
1469
            target->EpWaitingForBuffers));
1476
1470
        target->RecvStateFlags &= ~HTC_RECV_WAIT_BUFFERS;
1477
1471
        target->EpWaitingForBuffers = ENDPOINT_MAX;
1478
 
        unblockRecv = TRUE;
 
1472
        unblockRecv = true;
1479
1473
    }
1480
1474
 
1481
1475
    UNLOCK_HTC_RX(target);
1486
1480
    }
1487
1481
}
1488
1482
 
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)
1490
1484
{
1491
 
    HTC_PACKET  *pPacket;
1492
 
    HTC_PACKET_QUEUE container;
 
1485
    struct htc_packet  *pPacket;
 
1486
    struct htc_packet_queue container;
1493
1487
    
1494
1488
    LOCK_HTC_RX(target);
1495
1489
 
1512
1506
    UNLOCK_HTC_RX(target);
1513
1507
}
1514
1508
 
1515
 
static void HTCFlushEndpointRX(HTC_TARGET *target, HTC_ENDPOINT *pEndpoint)
 
1509
static void HTCFlushEndpointRX(struct htc_target *target, struct htc_endpoint *pEndpoint)
1516
1510
{
1517
1511
        /* flush any recv indications not already made */
1518
1512
    HTCFlushRxQueue(target,pEndpoint,&pEndpoint->RecvIndicationQueue);
1520
1514
    HTCFlushRxQueue(target,pEndpoint,&pEndpoint->RxBuffers);
1521
1515
}
1522
1516
 
1523
 
void HTCFlushRecvBuffers(HTC_TARGET *target)
 
1517
void HTCFlushRecvBuffers(struct htc_target *target)
1524
1518
{
1525
 
    HTC_ENDPOINT    *pEndpoint;
 
1519
    struct htc_endpoint    *pEndpoint;
1526
1520
    int             i;
1527
1521
 
1528
1522
    for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) {
1538
1532
 
1539
1533
void HTCEnableRecv(HTC_HANDLE HTCHandle)
1540
1534
{
1541
 
    HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
 
1535
    struct htc_target *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
1542
1536
 
1543
1537
    if (!HTC_STOPPING(target)) {
1544
1538
            /* re-enable */
1548
1542
 
1549
1543
void HTCDisableRecv(HTC_HANDLE HTCHandle)
1550
1544
{
1551
 
    HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
 
1545
    struct htc_target *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
1552
1546
 
1553
1547
    if (!HTC_STOPPING(target)) {
1554
1548
            /* disable */
1559
1553
int HTCGetNumRecvBuffers(HTC_HANDLE      HTCHandle,
1560
1554
                         HTC_ENDPOINT_ID Endpoint)
1561
1555
{
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));
1564
1558
}
1565
1559
 
1566
 
A_STATUS HTCWaitForPendingRecv(HTC_HANDLE   HTCHandle,
1567
 
                               A_UINT32     TimeoutInMs,
1568
 
                               A_BOOL      *pbIsRecvPending)
 
1560
int HTCWaitForPendingRecv(HTC_HANDLE   HTCHandle,
 
1561
                               u32 TimeoutInMs,
 
1562
                               bool      *pbIsRecvPending)
1569
1563
{
1570
 
    A_STATUS    status  = A_OK;
1571
 
    HTC_TARGET *target  = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
 
1564
    int    status  = 0;
 
1565
    struct htc_target *target  = GET_HTC_TARGET_FROM_HANDLE(HTCHandle);
1572
1566
 
1573
1567
    status = DevWaitForPendingRecv(&target->Device,
1574
1568
                                    TimeoutInMs,