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

« back to all changes in this revision

Viewing changes to drivers/staging/ath6kl/htc2/AR6000/ar6k_gmbox_hciuart.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:
24
24
//==============================================================================
25
25
#include "a_config.h"
26
26
#include "athdefs.h"
27
 
#include "a_types.h"
28
27
#include "a_osapi.h"
29
28
#include "../htc_debug.h"
30
29
#include "hif.h"
56
55
#define BAUD_TIMEOUT_MS           1
57
56
#define BTPWRSAV_TIMEOUT_MS       1  
58
57
 
59
 
typedef struct {
60
 
    HCI_TRANSPORT_CONFIG_INFO   HCIConfig;
61
 
    A_BOOL                      HCIAttached;
62
 
    A_BOOL                      HCIStopped;
63
 
    A_UINT32                    RecvStateFlags;
64
 
    A_UINT32                    SendStateFlags;
 
58
struct gmbox_proto_hci_uart {
 
59
    struct hci_transport_config_info   HCIConfig;
 
60
    bool                      HCIAttached;
 
61
    bool                      HCIStopped;
 
62
    u32 RecvStateFlags;
 
63
    u32 SendStateFlags;
65
64
    HCI_TRANSPORT_PACKET_TYPE   WaitBufferType;
66
 
    HTC_PACKET_QUEUE            SendQueue;         /* write queue holding HCI Command and ACL packets */
67
 
    HTC_PACKET_QUEUE            HCIACLRecvBuffers;  /* recv queue holding buffers for incomming ACL packets */
68
 
    HTC_PACKET_QUEUE            HCIEventBuffers;    /* recv queue holding buffers for incomming event packets */
69
 
    AR6K_DEVICE                 *pDev;
 
65
    struct htc_packet_queue            SendQueue;         /* write queue holding HCI Command and ACL packets */
 
66
    struct htc_packet_queue            HCIACLRecvBuffers;  /* recv queue holding buffers for incomming ACL packets */
 
67
    struct htc_packet_queue            HCIEventBuffers;    /* recv queue holding buffers for incomming event packets */
 
68
    struct ar6k_device                 *pDev;
70
69
    A_MUTEX_T                   HCIRxLock;
71
70
    A_MUTEX_T                   HCITxLock;
72
71
    int                         CreditsMax;
75
74
    int                         CreditSize;
76
75
    int                         CreditsCurrentSeek;
77
76
    int                         SendProcessCount;
78
 
} GMBOX_PROTO_HCI_UART;
 
77
};
79
78
 
80
79
#define LOCK_HCI_RX(t)   A_MUTEX_LOCK(&(t)->HCIRxLock);
81
80
#define UNLOCK_HCI_RX(t) A_MUTEX_UNLOCK(&(t)->HCIRxLock);
82
81
#define LOCK_HCI_TX(t)   A_MUTEX_LOCK(&(t)->HCITxLock);
83
82
#define UNLOCK_HCI_TX(t) A_MUTEX_UNLOCK(&(t)->HCITxLock);
84
83
 
85
 
#define DO_HCI_RECV_INDICATION(p,pt) \
86
 
{   AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("HCI: Indicate Recv on packet:0x%lX status:%d len:%d type:%d \n",  \
87
 
      (unsigned long)(pt),(pt)->Status, A_SUCCESS((pt)->Status) ? (pt)->ActualLength : 0, HCI_GET_PACKET_TYPE(pt))); \
88
 
    (p)->HCIConfig.pHCIPktRecv((p)->HCIConfig.pContext, (pt));                                 \
89
 
}
 
84
#define DO_HCI_RECV_INDICATION(p, pt)                           \
 
85
do {                                                            \
 
86
        AR_DEBUG_PRINTF(ATH_DEBUG_RECV,                                 \
 
87
                        ("HCI: Indicate Recv on packet:0x%lX status:%d len:%d type:%d \n", \
 
88
                         (unsigned long)(pt),                           \
 
89
                         (pt)->Status,                                  \
 
90
                         !(pt)->Status ? (pt)->ActualLength : 0,        \
 
91
                         HCI_GET_PACKET_TYPE(pt)));                     \
 
92
        (p)->HCIConfig.pHCIPktRecv((p)->HCIConfig.pContext, (pt));      \
 
93
} while (0)
90
94
 
91
95
#define DO_HCI_SEND_INDICATION(p,pt) \
92
96
{   AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("HCI: Indicate Send on packet:0x%lX status:%d type:%d \n",  \
94
98
    (p)->HCIConfig.pHCISendComplete((p)->HCIConfig.pContext, (pt));                            \
95
99
}
96
100
    
97
 
static A_STATUS HCITrySend(GMBOX_PROTO_HCI_UART *pProt, HTC_PACKET *pPacket, A_BOOL Synchronous);
 
101
static int HCITrySend(struct gmbox_proto_hci_uart *pProt, struct htc_packet *pPacket, bool Synchronous);
98
102
 
99
 
static void HCIUartCleanup(GMBOX_PROTO_HCI_UART *pProtocol)
 
103
static void HCIUartCleanup(struct gmbox_proto_hci_uart *pProtocol)
100
104
{
101
105
    A_ASSERT(pProtocol != NULL);
102
106
    
103
107
    A_MUTEX_DELETE(&pProtocol->HCIRxLock);
104
108
    A_MUTEX_DELETE(&pProtocol->HCITxLock);
105
109
        
106
 
    A_FREE(pProtocol);    
 
110
    kfree(pProtocol);    
107
111
}
108
112
 
109
 
static A_STATUS InitTxCreditState(GMBOX_PROTO_HCI_UART *pProt)
 
113
static int InitTxCreditState(struct gmbox_proto_hci_uart *pProt)
110
114
{
111
 
    A_STATUS    status;
 
115
    int    status;
112
116
    int         credits;
113
117
    int         creditPollCount = CREDIT_POLL_COUNT;
114
 
    A_BOOL      gotCredits = FALSE;
 
118
    bool      gotCredits = false;
115
119
 
116
120
    pProt->CreditsConsumed = 0;
117
121
    
120
124
        if (pProt->CreditsMax != 0) {
121
125
            /* we can only call this only once per target reset */
122
126
            AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("HCI: InitTxCreditState - already called!  \n"));
123
 
            A_ASSERT(FALSE);
 
127
            A_ASSERT(false);
124
128
            status = A_EINVAL;
125
129
            break; 
126
130
        }
135
139
 
136
140
            status = DevGMboxReadCreditCounter(pProt->pDev, PROC_IO_SYNC, &credits);
137
141
    
138
 
            if (A_FAILED(status)) {
 
142
            if (status) {
139
143
                break;    
140
144
            }
141
145
            
145
149
                A_MDELAY(HCI_DELAY_PER_INTERVAL_MS);
146
150
                continue;  
147
151
            } else {
148
 
                gotCredits = TRUE;    
 
152
                gotCredits = true;
149
153
            }
150
154
            
151
155
            if (0 == credits) {
155
159
            pProt->CreditsMax += credits;
156
160
        }
157
161
        
158
 
        if (A_FAILED(status)) {
 
162
        if (status) {
159
163
            break;    
160
164
        }
161
165
        
169
173
            /* now get the size */
170
174
        status = DevGMboxReadCreditSize(pProt->pDev, &pProt->CreditSize);
171
175
        
172
 
        if (A_FAILED(status)) {
 
176
        if (status) {
173
177
            break;    
174
178
        }
175
179
               
176
 
    } while (FALSE);
 
180
    } while (false);
177
181
    
178
 
    if (A_SUCCESS(status)) {
 
182
    if (!status) {
179
183
        pProt->CreditsAvailable = pProt->CreditsMax;
180
184
        AR_DEBUG_PRINTF(ATH_DEBUG_ANY,("HCI : InitTxCreditState - credits avail: %d, size: %d \n",
181
185
            pProt->CreditsAvailable, pProt->CreditSize));    
184
188
    return status;
185
189
}
186
190
 
187
 
static A_STATUS CreditsAvailableCallback(void *pContext, int Credits, A_BOOL CreditIRQEnabled)
 
191
static int CreditsAvailableCallback(void *pContext, int Credits, bool CreditIRQEnabled)
188
192
{
189
 
    GMBOX_PROTO_HCI_UART *pProt = (GMBOX_PROTO_HCI_UART *)pContext;    
190
 
    A_BOOL               enableCreditIrq = FALSE;   
191
 
    A_BOOL               disableCreditIrq = FALSE;
192
 
    A_BOOL               doPendingSends = FALSE;
193
 
    A_STATUS             status = A_OK;
 
193
    struct gmbox_proto_hci_uart *pProt = (struct gmbox_proto_hci_uart *)pContext;    
 
194
    bool               enableCreditIrq = false;
 
195
    bool               disableCreditIrq = false;
 
196
    bool               doPendingSends = false;
 
197
    int             status = 0;
194
198
    
195
199
    /** this callback is called under 2 conditions:
196
200
     *   1. The credit IRQ interrupt was enabled and signaled.
209
213
        if (0 == Credits) {
210
214
            if (!CreditIRQEnabled) {
211
215
                    /* enable credit IRQ */
212
 
                enableCreditIrq = TRUE;    
 
216
                enableCreditIrq = true;
213
217
            }
214
218
            break;
215
219
        }
232
236
                         pProt->CreditsCurrentSeek));
233
237
        
234
238
        if (pProt->CreditsAvailable >= pProt->CreditsCurrentSeek) {
235
 
                /* we have enough credits to fullfill at least 1 packet waiting in the queue */
 
239
                /* we have enough credits to fulfill at least 1 packet waiting in the queue */
236
240
            pProt->CreditsCurrentSeek = 0;
237
241
            pProt->SendStateFlags &= ~HCI_SEND_WAIT_CREDITS;  
238
 
            doPendingSends = TRUE;  
 
242
            doPendingSends = true;
239
243
            if (CreditIRQEnabled) {
240
244
                    /* credit IRQ was enabled, we shouldn't need it anymore */
241
 
                disableCreditIrq = TRUE;    
 
245
                disableCreditIrq = true;
242
246
            }      
243
247
        } else {
244
248
                /* not enough credits yet, enable credit IRQ if we haven't already */
245
249
            if (!CreditIRQEnabled) {               
246
 
                enableCreditIrq = TRUE;    
 
250
                enableCreditIrq = true;
247
251
            }    
248
252
        }
249
253
                      
250
 
    } while (FALSE);
 
254
    } while (false);
251
255
    
252
256
    UNLOCK_HCI_TX(pProt);
253
257
 
262
266
    }
263
267
       
264
268
    if (doPendingSends) {
265
 
        HCITrySend(pProt, NULL, FALSE);
 
269
        HCITrySend(pProt, NULL, false);
266
270
    }
267
271
 
268
272
    AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("+CreditsAvailableCallback \n"));
269
273
    return status;
270
274
}
271
275
 
272
 
static INLINE void NotifyTransportFailure(GMBOX_PROTO_HCI_UART  *pProt, A_STATUS status)
 
276
static INLINE void NotifyTransportFailure(struct gmbox_proto_hci_uart  *pProt, int status)
273
277
{
274
278
    if (pProt->HCIConfig.TransportFailure != NULL) {
275
279
        pProt->HCIConfig.TransportFailure(pProt->HCIConfig.pContext, status);
276
280
    }
277
281
}
278
282
 
279
 
static void FailureCallback(void *pContext, A_STATUS Status)
 
283
static void FailureCallback(void *pContext, int Status)
280
284
{
281
 
    GMBOX_PROTO_HCI_UART  *pProt = (GMBOX_PROTO_HCI_UART *)pContext; 
 
285
    struct gmbox_proto_hci_uart  *pProt = (struct gmbox_proto_hci_uart *)pContext; 
282
286
    
283
 
        /* target assertion occured */           
 
287
        /* target assertion occurred */           
284
288
    NotifyTransportFailure(pProt, Status);  
285
289
}
286
290
 
287
291
static void StateDumpCallback(void *pContext)
288
292
{
289
 
    GMBOX_PROTO_HCI_UART  *pProt = (GMBOX_PROTO_HCI_UART *)pContext;
 
293
    struct gmbox_proto_hci_uart  *pProt = (struct gmbox_proto_hci_uart *)pContext;
290
294
   
291
295
    AR_DEBUG_PRINTF(ATH_DEBUG_ANY,("============ HCIUart State ======================\n"));    
292
296
    AR_DEBUG_PRINTF(ATH_DEBUG_ANY,("RecvStateFlags   :  0x%X \n",pProt->RecvStateFlags));
299
303
    AR_DEBUG_PRINTF(ATH_DEBUG_ANY,("==================================================\n"));
300
304
}
301
305
 
302
 
static A_STATUS HCIUartMessagePending(void *pContext, A_UINT8 LookAheadBytes[], int ValidBytes)
 
306
static int HCIUartMessagePending(void *pContext, u8 LookAheadBytes[], int ValidBytes)
303
307
{
304
 
    GMBOX_PROTO_HCI_UART        *pProt = (GMBOX_PROTO_HCI_UART *)pContext;
305
 
    A_STATUS                    status = A_OK;
 
308
    struct gmbox_proto_hci_uart        *pProt = (struct gmbox_proto_hci_uart *)pContext;
 
309
    int                    status = 0;
306
310
    int                         totalRecvLength = 0;
307
311
    HCI_TRANSPORT_PACKET_TYPE   pktType = HCI_PACKET_INVALID;
308
 
    A_BOOL                      recvRefillCalled = FALSE;
309
 
    A_BOOL                      blockRecv = FALSE;
310
 
    HTC_PACKET                  *pPacket = NULL;
 
312
    bool                      recvRefillCalled = false;
 
313
    bool                      blockRecv = false;
 
314
    struct htc_packet                  *pPacket = NULL;
311
315
    
312
316
    /** caller guarantees that this is a fully block-able context (synch I/O is allowed) */
313
317
    
348
352
                break;
349
353
        }
350
354
        
351
 
        if (A_FAILED(status)) {
 
355
        if (status) {
352
356
            break;    
353
357
        }
354
358
                
361
365
            LOCK_HCI_RX(pProt);
362
366
    
363
367
        } else {
364
 
            HTC_PACKET_QUEUE *pQueue;
 
368
            struct htc_packet_queue *pQueue;
365
369
                /* user is using a refill handler that can refill multiple HTC buffers */
366
370
            
367
371
                /* select buffer queue */
377
381
                    pktType));
378
382
                    /* check for refill handler */
379
383
                if (pProt->HCIConfig.pHCIPktRecvRefill != NULL) {
380
 
                    recvRefillCalled = TRUE;
 
384
                    recvRefillCalled = true;
381
385
                    UNLOCK_HCI_RX(pProt);
382
386
                        /* call the re-fill handler */
383
387
                    pProt->HCIConfig.pHCIPktRecvRefill(pProt->HCIConfig.pContext,
402
406
                /* this is not an error, we simply need to mark that we are waiting for buffers.*/
403
407
            pProt->RecvStateFlags |= HCI_RECV_WAIT_BUFFERS;
404
408
            pProt->WaitBufferType = pktType;
405
 
            blockRecv = TRUE;
 
409
            blockRecv = true;
406
410
            break;
407
411
        }
408
412
        
413
417
            break;
414
418
        }
415
419
        
416
 
    } while (FALSE);
 
420
    } while (false);
417
421
    
418
422
    UNLOCK_HCI_RX(pProt);
419
423
    
421
425
        
422
426
    do {
423
427
        
424
 
        if (A_FAILED(status) || (NULL == pPacket)) {
 
428
        if (status || (NULL == pPacket)) {
425
429
            break;    
426
430
        } 
427
431
        
433
437
                
434
438
        status = DevGMboxRead(pProt->pDev, pPacket, totalRecvLength);     
435
439
        
436
 
        if (A_FAILED(status)) {
 
440
        if (status) {
437
441
            break;    
438
442
        }
439
443
        
471
475
            /* adjust buffer to move past packet ID */
472
476
        pPacket->pBuffer++;
473
477
        pPacket->ActualLength = totalRecvLength - 1;
474
 
        pPacket->Status = A_OK;
 
478
        pPacket->Status = 0;
475
479
            /* indicate packet */
476
480
        DO_HCI_RECV_INDICATION(pProt,pPacket);
477
481
        pPacket = NULL;
478
482
        
479
483
            /* check if we need to refill recv buffers */        
480
484
        if ((pProt->HCIConfig.pHCIPktRecvRefill != NULL) && !recvRefillCalled) {           
481
 
            HTC_PACKET_QUEUE *pQueue;
 
485
            struct htc_packet_queue *pQueue;
482
486
            int              watermark;
483
487
 
484
488
            if (pktType == HCI_ACL_TYPE) {
500
504
            }
501
505
        }   
502
506
        
503
 
    } while (FALSE);
 
507
    } while (false);
504
508
        
505
 
        /* check if we need to disable the reciever */
506
 
    if (A_FAILED(status) || blockRecv) {
 
509
        /* check if we need to disable the receiver */
 
510
    if (status || blockRecv) {
507
511
        DevGMboxIRQAction(pProt->pDev, GMBOX_RECV_IRQ_DISABLE, PROC_IO_SYNC); 
508
512
    }
509
513
    
510
514
        /* see if we need to recycle the recv buffer */    
511
 
    if (A_FAILED(status) && (pPacket != NULL)) {
512
 
        HTC_PACKET_QUEUE queue;
 
515
    if (status && (pPacket != NULL)) {
 
516
        struct htc_packet_queue queue;
513
517
        
514
518
        if (A_EPROTO == status) {
515
519
            DebugDumpBytes(pPacket->pBuffer, totalRecvLength, "Bad HCI-UART Recv packet");    
527
531
    return status;
528
532
}
529
533
 
530
 
static void HCISendPacketCompletion(void *Context, HTC_PACKET *pPacket)
 
534
static void HCISendPacketCompletion(void *Context, struct htc_packet *pPacket)
531
535
{
532
 
    GMBOX_PROTO_HCI_UART *pProt = (GMBOX_PROTO_HCI_UART *)Context;
 
536
    struct gmbox_proto_hci_uart *pProt = (struct gmbox_proto_hci_uart *)Context;
533
537
    AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("+HCISendPacketCompletion (pPacket:0x%lX) \n",(unsigned long)pPacket));
534
538
    
535
 
    if (A_FAILED(pPacket->Status)) {
 
539
    if (pPacket->Status) {
536
540
        AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" Send Packet (0x%lX) failed: %d , len:%d \n",
537
541
            (unsigned long)pPacket, pPacket->Status, pPacket->ActualLength));        
538
542
    }
542
546
    AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("+HCISendPacketCompletion \n"));
543
547
}
544
548
 
545
 
static A_STATUS SeekCreditsSynch(GMBOX_PROTO_HCI_UART *pProt)
 
549
static int SeekCreditsSynch(struct gmbox_proto_hci_uart *pProt)
546
550
{
547
 
    A_STATUS status = A_OK;
 
551
    int status = 0;
548
552
    int      credits;
549
553
    int      retry = 100;
550
554
    
551
 
    while (TRUE) {                
 
555
    while (true) {
552
556
        credits = 0;
553
557
        status =  DevGMboxReadCreditCounter(pProt->pDev, PROC_IO_SYNC, &credits);   
554
 
        if (A_FAILED(status)) {
 
558
        if (status) {
555
559
            break;    
556
560
        }
557
561
        LOCK_HCI_TX(pProt);
574
578
    return status;
575
579
}
576
580
 
577
 
static A_STATUS HCITrySend(GMBOX_PROTO_HCI_UART *pProt, HTC_PACKET *pPacket, A_BOOL Synchronous)
 
581
static int HCITrySend(struct gmbox_proto_hci_uart *pProt, struct htc_packet *pPacket, bool Synchronous)
578
582
{   
579
 
    A_STATUS    status = A_OK;
 
583
    int    status = 0;
580
584
    int         transferLength;
581
585
    int         creditsRequired, remainder;
582
 
    A_UINT8     hciUartType;
583
 
    A_BOOL      synchSendComplete = FALSE;
 
586
    u8 hciUartType;
 
587
    bool      synchSendComplete = false;
584
588
    
585
589
    AR_DEBUG_PRINTF(ATH_DEBUG_SEND,("+HCITrySend (pPacket:0x%lX) %s \n",(unsigned long)pPacket,
586
590
            Synchronous ? "SYNC" :"ASYNC"));
603
607
                    /* in synchronous mode, the send queue can only hold 1 packet */
604
608
                if (!HTC_QUEUE_EMPTY(&pProt->SendQueue)) {
605
609
                    status = A_EBUSY;
606
 
                    A_ASSERT(FALSE);
 
610
                    A_ASSERT(false);
607
611
                    break;    
608
612
                }             
609
613
                
610
614
                if (pProt->SendProcessCount > 1) {
611
615
                        /* another thread or task is draining the TX queues  */
612
616
                    status = A_EBUSY;
613
 
                    A_ASSERT(FALSE);
 
617
                    A_ASSERT(false);
614
618
                    break;
615
619
                } 
616
620
                  
667
671
                    break;
668
672
                default:
669
673
                    status = A_EINVAL;
670
 
                    A_ASSERT(FALSE);
 
674
                    A_ASSERT(false);
671
675
                    break;
672
676
            }
673
677
                       
674
 
            if (A_FAILED(status)) {
 
678
            if (status) {
675
679
                break;   
676
680
            }
677
681
            
701
705
                    UNLOCK_HCI_TX(pProt);
702
706
                    status = SeekCreditsSynch(pProt);
703
707
                    LOCK_HCI_TX(pProt);
704
 
                    if (A_FAILED(status)) {
 
708
                    if (status) {
705
709
                        break;    
706
710
                    }                    
707
711
                    /* fall through and continue processing this send op */                    
751
755
            
752
756
            status = DevGMboxWrite(pProt->pDev,pPacket,transferLength);            
753
757
            if (Synchronous) {            
754
 
                synchSendComplete = TRUE;
 
758
                synchSendComplete = true;
755
759
            } else {
756
760
                pPacket = NULL;    
757
761
            }
760
764
              
761
765
        }
762
766
        
763
 
    } while (FALSE);
 
767
    } while (false);
764
768
        
765
769
    pProt->SendProcessCount--;
766
770
    A_ASSERT(pProt->SendProcessCount >= 0);
768
772
    
769
773
    if (Synchronous) {
770
774
        A_ASSERT(pPacket != NULL);
771
 
        if (A_SUCCESS(status) && (!synchSendComplete)) {
 
775
        if (!status && (!synchSendComplete)) {
772
776
            status = A_EBUSY;
773
 
            A_ASSERT(FALSE);
 
777
            A_ASSERT(false);
774
778
            LOCK_HCI_TX(pProt);
775
779
            if (pPacket->ListLink.pNext != NULL) {
776
780
                    /* remove from the queue */
779
783
            UNLOCK_HCI_TX(pProt);
780
784
        }
781
785
    } else {   
782
 
        if (A_FAILED(status) && (pPacket != NULL)) {
 
786
        if (status && (pPacket != NULL)) {
783
787
            pPacket->Status = status;
784
788
            DO_HCI_SEND_INDICATION(pProt,pPacket); 
785
789
        }
789
793
    return status;    
790
794
}
791
795
 
792
 
static void FlushSendQueue(GMBOX_PROTO_HCI_UART *pProt)
 
796
static void FlushSendQueue(struct gmbox_proto_hci_uart *pProt)
793
797
{
794
 
    HTC_PACKET          *pPacket;
795
 
    HTC_PACKET_QUEUE    discardQueue;
 
798
    struct htc_packet          *pPacket;
 
799
    struct htc_packet_queue    discardQueue;
796
800
    
797
801
    INIT_HTC_PACKET_QUEUE(&discardQueue);
798
802
    
813
817
    
814
818
}
815
819
 
816
 
static void FlushRecvBuffers(GMBOX_PROTO_HCI_UART *pProt)
 
820
static void FlushRecvBuffers(struct gmbox_proto_hci_uart *pProt)
817
821
{
818
 
    HTC_PACKET_QUEUE discardQueue;
819
 
    HTC_PACKET *pPacket;
 
822
    struct htc_packet_queue discardQueue;
 
823
    struct htc_packet *pPacket;
820
824
    
821
825
    INIT_HTC_PACKET_QUEUE(&discardQueue);
822
826
    
841
845
 
842
846
/*** protocol module install entry point ***/
843
847
 
844
 
A_STATUS GMboxProtocolInstall(AR6K_DEVICE *pDev)
 
848
int GMboxProtocolInstall(struct ar6k_device *pDev)
845
849
{
846
 
    A_STATUS                status = A_OK;
847
 
    GMBOX_PROTO_HCI_UART    *pProtocol = NULL;
 
850
    int                status = 0;
 
851
    struct gmbox_proto_hci_uart    *pProtocol = NULL;
848
852
        
849
853
    do {
850
854
        
851
 
        pProtocol = A_MALLOC(sizeof(GMBOX_PROTO_HCI_UART));
 
855
        pProtocol = A_MALLOC(sizeof(struct gmbox_proto_hci_uart));
852
856
        
853
857
        if (NULL == pProtocol) {
854
858
            status = A_NO_MEMORY;
863
867
        A_MUTEX_INIT(&pProtocol->HCIRxLock);
864
868
        A_MUTEX_INIT(&pProtocol->HCITxLock);
865
869
     
866
 
    } while (FALSE);
 
870
    } while (false);
867
871
    
868
 
    if (A_SUCCESS(status)) {
 
872
    if (!status) {
869
873
        LOCK_AR6K(pDev);
870
874
        DEV_GMBOX_SET_PROTOCOL(pDev,
871
875
                               HCIUartMessagePending,
884
888
}
885
889
 
886
890
/*** protocol module uninstall entry point ***/
887
 
void GMboxProtocolUninstall(AR6K_DEVICE *pDev)
 
891
void GMboxProtocolUninstall(struct ar6k_device *pDev)
888
892
{
889
 
    GMBOX_PROTO_HCI_UART *pProtocol = (GMBOX_PROTO_HCI_UART *)DEV_GMBOX_GET_PROTOCOL(pDev);
 
893
    struct gmbox_proto_hci_uart *pProtocol = (struct gmbox_proto_hci_uart *)DEV_GMBOX_GET_PROTOCOL(pDev);
890
894
    
891
895
    if (pProtocol != NULL) {
892
896
        
894
898
        if (pProtocol->HCIAttached) {
895
899
            A_ASSERT(pProtocol->HCIConfig.TransportRemoved != NULL);
896
900
            pProtocol->HCIConfig.TransportRemoved(pProtocol->HCIConfig.pContext);
897
 
            pProtocol->HCIAttached = FALSE;    
 
901
            pProtocol->HCIAttached = false;
898
902
        }
899
903
        
900
904
        HCIUartCleanup(pProtocol);
903
907
    
904
908
}
905
909
 
906
 
static A_STATUS NotifyTransportReady(GMBOX_PROTO_HCI_UART  *pProt)
 
910
static int NotifyTransportReady(struct gmbox_proto_hci_uart  *pProt)
907
911
{
908
 
    HCI_TRANSPORT_PROPERTIES props;
909
 
    A_STATUS                 status = A_OK;
 
912
    struct hci_transport_properties props;
 
913
    int                 status = 0;
910
914
    
911
915
    do {
912
916
        
924
928
                                                    pProt->HCIConfig.pContext);
925
929
        }
926
930
        
927
 
    } while (FALSE);
 
931
    } while (false);
928
932
    
929
933
    return status;
930
934
}
931
935
 
932
936
/***********  HCI UART protocol implementation ************************************************/
933
937
 
934
 
HCI_TRANSPORT_HANDLE HCI_TransportAttach(void *HTCHandle, HCI_TRANSPORT_CONFIG_INFO *pInfo)
 
938
HCI_TRANSPORT_HANDLE HCI_TransportAttach(void *HTCHandle, struct hci_transport_config_info *pInfo)
935
939
{
936
 
    GMBOX_PROTO_HCI_UART  *pProtocol = NULL; 
937
 
    AR6K_DEVICE           *pDev;
 
940
    struct gmbox_proto_hci_uart  *pProtocol = NULL; 
 
941
    struct ar6k_device           *pDev;
938
942
    
939
943
    AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("+HCI_TransportAttach \n"));
940
944
    
944
948
    
945
949
    do {
946
950
        
947
 
        pProtocol = (GMBOX_PROTO_HCI_UART *)DEV_GMBOX_GET_PROTOCOL(pDev);
 
951
        pProtocol = (struct gmbox_proto_hci_uart *)DEV_GMBOX_GET_PROTOCOL(pDev);
948
952
        
949
953
        if (NULL == pProtocol) {
950
954
            AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("GMBOX protocol not installed! \n"));
956
960
            break;    
957
961
        }
958
962
        
959
 
        A_MEMCPY(&pProtocol->HCIConfig, pInfo, sizeof(HCI_TRANSPORT_CONFIG_INFO));
 
963
        memcpy(&pProtocol->HCIConfig, pInfo, sizeof(struct hci_transport_config_info));
960
964
        
961
965
        A_ASSERT(pProtocol->HCIConfig.pHCIPktRecv != NULL);
962
966
        A_ASSERT(pProtocol->HCIConfig.pHCISendComplete != NULL);
963
967
        
964
 
        pProtocol->HCIAttached = TRUE;
 
968
        pProtocol->HCIAttached = true;
965
969
        
966
 
    } while (FALSE);
 
970
    } while (false);
967
971
    
968
972
    UNLOCK_AR6K(pDev);
969
973
    
978
982
 
979
983
void HCI_TransportDetach(HCI_TRANSPORT_HANDLE HciTrans)
980
984
{
981
 
    GMBOX_PROTO_HCI_UART  *pProtocol = (GMBOX_PROTO_HCI_UART *)HciTrans; 
982
 
    AR6K_DEVICE           *pDev = pProtocol->pDev;
 
985
    struct gmbox_proto_hci_uart  *pProtocol = (struct gmbox_proto_hci_uart *)HciTrans; 
 
986
    struct ar6k_device           *pDev = pProtocol->pDev;
983
987
    
984
988
    AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("+HCI_TransportDetach \n"));
985
989
    
989
993
        UNLOCK_AR6K(pDev);
990
994
        return;
991
995
    }
992
 
    pProtocol->HCIAttached = FALSE;
 
996
    pProtocol->HCIAttached = false;
993
997
    UNLOCK_AR6K(pDev);
994
998
    
995
999
    HCI_TransportStop(HciTrans);
996
1000
    AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("-HCI_TransportAttach \n"));
997
1001
}
998
1002
 
999
 
A_STATUS HCI_TransportAddReceivePkts(HCI_TRANSPORT_HANDLE HciTrans, HTC_PACKET_QUEUE *pQueue)
 
1003
int HCI_TransportAddReceivePkts(HCI_TRANSPORT_HANDLE HciTrans, struct htc_packet_queue *pQueue)
1000
1004
{
1001
 
    GMBOX_PROTO_HCI_UART  *pProt = (GMBOX_PROTO_HCI_UART *)HciTrans; 
1002
 
    A_STATUS              status = A_OK;
1003
 
    A_BOOL                unblockRecv = FALSE;
1004
 
    HTC_PACKET            *pPacket;
 
1005
    struct gmbox_proto_hci_uart  *pProt = (struct gmbox_proto_hci_uart *)HciTrans; 
 
1006
    int              status = 0;
 
1007
    bool                unblockRecv = false;
 
1008
    struct htc_packet            *pPacket;
1005
1009
    
1006
1010
    AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("+HCI_TransportAddReceivePkt \n"));
1007
1011
    
1039
1043
                        pProt->WaitBufferType));
1040
1044
                pProt->RecvStateFlags &= ~HCI_RECV_WAIT_BUFFERS;
1041
1045
                pProt->WaitBufferType = HCI_PACKET_INVALID;
1042
 
                unblockRecv = TRUE;
 
1046
                unblockRecv = true;
1043
1047
            }
1044
1048
        }
1045
1049
        
1046
 
    } while (FALSE);
 
1050
    } while (false);
1047
1051
    
1048
1052
    UNLOCK_HCI_RX(pProt);
1049
1053
    
1050
 
    if (A_FAILED(status)) {
 
1054
    if (status) {
1051
1055
        while (!HTC_QUEUE_EMPTY(pQueue)) {
1052
1056
            pPacket = HTC_PACKET_DEQUEUE(pQueue);      
1053
1057
            pPacket->Status = A_ECANCELED;
1061
1065
    
1062
1066
    AR_DEBUG_PRINTF(ATH_DEBUG_RECV,("-HCI_TransportAddReceivePkt \n"));
1063
1067
    
1064
 
    return A_OK;    
 
1068
    return 0;
1065
1069
}
1066
1070
 
1067
 
A_STATUS HCI_TransportSendPkt(HCI_TRANSPORT_HANDLE HciTrans, HTC_PACKET *pPacket, A_BOOL Synchronous)
 
1071
int HCI_TransportSendPkt(HCI_TRANSPORT_HANDLE HciTrans, struct htc_packet *pPacket, bool Synchronous)
1068
1072
{
1069
 
    GMBOX_PROTO_HCI_UART  *pProt = (GMBOX_PROTO_HCI_UART *)HciTrans;  
 
1073
    struct gmbox_proto_hci_uart  *pProt = (struct gmbox_proto_hci_uart *)HciTrans;  
1070
1074
    
1071
1075
    return HCITrySend(pProt,pPacket,Synchronous);
1072
1076
}
1073
1077
 
1074
1078
void HCI_TransportStop(HCI_TRANSPORT_HANDLE HciTrans)
1075
1079
{
1076
 
    GMBOX_PROTO_HCI_UART  *pProt = (GMBOX_PROTO_HCI_UART *)HciTrans; 
 
1080
    struct gmbox_proto_hci_uart  *pProt = (struct gmbox_proto_hci_uart *)HciTrans; 
1077
1081
    
1078
1082
    AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("+HCI_TransportStop \n"));
1079
1083
     
1083
1087
        AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("-HCI_TransportStop \n"));
1084
1088
        return;    
1085
1089
    }
1086
 
    pProt->HCIStopped = TRUE;
 
1090
    pProt->HCIStopped = true;
1087
1091
    UNLOCK_AR6K(pProt->pDev);
1088
1092
     
1089
1093
        /* disable interrupts */
1097
1101
    AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("-HCI_TransportStop \n"));
1098
1102
}
1099
1103
 
1100
 
A_STATUS HCI_TransportStart(HCI_TRANSPORT_HANDLE HciTrans)
 
1104
int HCI_TransportStart(HCI_TRANSPORT_HANDLE HciTrans)
1101
1105
{
1102
 
    A_STATUS              status;
1103
 
    GMBOX_PROTO_HCI_UART  *pProt = (GMBOX_PROTO_HCI_UART *)HciTrans;
 
1106
    int              status;
 
1107
    struct gmbox_proto_hci_uart  *pProt = (struct gmbox_proto_hci_uart *)HciTrans;
1104
1108
    
1105
1109
    AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("+HCI_TransportStart \n"));
1106
1110
    
1107
1111
        /* set stopped in case we have a problem in starting */
1108
 
    pProt->HCIStopped = TRUE;
 
1112
    pProt->HCIStopped = true;
1109
1113
    
1110
1114
    do {
1111
1115
        
1112
1116
        status = InitTxCreditState(pProt);   
1113
1117
        
1114
 
        if (A_FAILED(status)) {
 
1118
        if (status) {
1115
1119
            break;    
1116
1120
        }     
1117
1121
        
1118
1122
        status = DevGMboxIRQAction(pProt->pDev, GMBOX_ERRORS_IRQ_ENABLE, PROC_IO_SYNC);   
1119
1123
        
1120
 
        if (A_FAILED(status)) {
 
1124
        if (status) {
1121
1125
            break;   
1122
1126
        } 
1123
1127
            /* enable recv */   
1124
1128
        status = DevGMboxIRQAction(pProt->pDev, GMBOX_RECV_IRQ_ENABLE, PROC_IO_SYNC);
1125
1129
        
1126
 
        if (A_FAILED(status)) {
 
1130
        if (status) {
1127
1131
            break;   
1128
1132
        } 
1129
1133
            /* signal bridge side to power up BT */
1130
1134
        status = DevGMboxSetTargetInterrupt(pProt->pDev, MBOX_SIG_HCI_BRIDGE_BT_ON, BTON_TIMEOUT_MS);
1131
1135
        
1132
 
        if (A_FAILED(status)) {
 
1136
        if (status) {
1133
1137
            AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("HCI_TransportStart : Failed to trigger BT ON \n"));
1134
1138
            break;   
1135
1139
        } 
1136
1140
        
1137
1141
            /* we made it */
1138
 
        pProt->HCIStopped = FALSE;
 
1142
        pProt->HCIStopped = false;
1139
1143
        
1140
 
    } while (FALSE);
 
1144
    } while (false);
1141
1145
    
1142
1146
    AR_DEBUG_PRINTF(ATH_DEBUG_TRC,("-HCI_TransportStart \n"));
1143
1147
    
1144
1148
    return status;
1145
1149
}
1146
1150
 
1147
 
A_STATUS HCI_TransportEnableDisableAsyncRecv(HCI_TRANSPORT_HANDLE HciTrans, A_BOOL Enable)
 
1151
int HCI_TransportEnableDisableAsyncRecv(HCI_TRANSPORT_HANDLE HciTrans, bool Enable)
1148
1152
{
1149
 
    GMBOX_PROTO_HCI_UART  *pProt = (GMBOX_PROTO_HCI_UART *)HciTrans;
 
1153
    struct gmbox_proto_hci_uart  *pProt = (struct gmbox_proto_hci_uart *)HciTrans;
1150
1154
    return DevGMboxIRQAction(pProt->pDev, 
1151
1155
                             Enable ? GMBOX_RECV_IRQ_ENABLE : GMBOX_RECV_IRQ_DISABLE, 
1152
1156
                             PROC_IO_SYNC);
1153
1157
                             
1154
1158
}
1155
1159
 
1156
 
A_STATUS HCI_TransportRecvHCIEventSync(HCI_TRANSPORT_HANDLE HciTrans,
1157
 
                                       HTC_PACKET           *pPacket,
 
1160
int HCI_TransportRecvHCIEventSync(HCI_TRANSPORT_HANDLE HciTrans,
 
1161
                                       struct htc_packet           *pPacket,
1158
1162
                                       int                  MaxPollMS)
1159
1163
{
1160
 
    GMBOX_PROTO_HCI_UART  *pProt = (GMBOX_PROTO_HCI_UART *)HciTrans;
1161
 
    A_STATUS              status = A_OK;
1162
 
    A_UINT8               lookAhead[8];
 
1164
    struct gmbox_proto_hci_uart  *pProt = (struct gmbox_proto_hci_uart *)HciTrans;
 
1165
    int              status = 0;
 
1166
    u8 lookAhead[8];
1163
1167
    int                   bytes;
1164
1168
    int                   totalRecvLength;
1165
1169
    
1173
1177
        
1174
1178
        bytes = sizeof(lookAhead);
1175
1179
        status = DevGMboxRecvLookAheadPeek(pProt->pDev,lookAhead,&bytes);
1176
 
        if (A_FAILED(status)) {
 
1180
        if (status) {
1177
1181
            break;    
1178
1182
        }        
1179
1183
                
1199
1203
                break;
1200
1204
        }
1201
1205
        
1202
 
        if (A_FAILED(status)) {
 
1206
        if (status) {
1203
1207
            break;    
1204
1208
        }
1205
1209
        
1206
1210
        pPacket->Completion = NULL;
1207
1211
        status = DevGMboxRead(pProt->pDev,pPacket,totalRecvLength); 
1208
 
        if (A_FAILED(status)) {
 
1212
        if (status) {
1209
1213
            break;    
1210
1214
        }
1211
1215
        
1212
1216
        pPacket->pBuffer++;
1213
1217
        pPacket->ActualLength = totalRecvLength - 1;
1214
 
        pPacket->Status = A_OK;        
 
1218
        pPacket->Status = 0;
1215
1219
        break; 
1216
1220
    }
1217
1221
    
1225
1229
 
1226
1230
#define LSB_SCRATCH_IDX     4
1227
1231
#define MSB_SCRATCH_IDX     5
1228
 
A_STATUS HCI_TransportSetBaudRate(HCI_TRANSPORT_HANDLE HciTrans, A_UINT32 Baud)
 
1232
int HCI_TransportSetBaudRate(HCI_TRANSPORT_HANDLE HciTrans, u32 Baud)
1229
1233
{
1230
 
    GMBOX_PROTO_HCI_UART  *pProt = (GMBOX_PROTO_HCI_UART *)HciTrans;
1231
 
    HIF_DEVICE *pHIFDevice = (HIF_DEVICE *)(pProt->pDev->HIFDevice);
1232
 
    A_UINT32 scaledBaud, scratchAddr;
1233
 
    A_STATUS status = A_OK;
 
1234
    struct gmbox_proto_hci_uart  *pProt = (struct gmbox_proto_hci_uart *)HciTrans;
 
1235
    struct hif_device *pHIFDevice = (struct hif_device *)(pProt->pDev->HIFDevice);
 
1236
    u32 scaledBaud, scratchAddr;
 
1237
    int status = 0;
1234
1238
 
1235
1239
    /* Divide the desired baud rate by 100
1236
1240
     * Store the LSB in the local scratch register 4 and the MSB in the local
1242
1246
    scratchAddr = MBOX_BASE_ADDRESS | (LOCAL_SCRATCH_ADDRESS + 4 * MSB_SCRATCH_IDX);
1243
1247
    scaledBaud = ((Baud / 100) >> (LOCAL_SCRATCH_VALUE_MSB+1)) & LOCAL_SCRATCH_VALUE_MASK;
1244
1248
    status |= ar6000_WriteRegDiag(pHIFDevice, &scratchAddr, &scaledBaud);                     
1245
 
    if (A_OK != status) {
 
1249
    if (0 != status) {
1246
1250
        AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to set up baud rate in scratch register!"));            
1247
1251
        return status;
1248
1252
    }
1249
1253
 
1250
1254
    /* Now interrupt the target to tell it about the baud rate */
1251
1255
    status = DevGMboxSetTargetInterrupt(pProt->pDev, MBOX_SIG_HCI_BRIDGE_BAUD_SET, BAUD_TIMEOUT_MS);
1252
 
    if (A_OK != status) {
 
1256
    if (0 != status) {
1253
1257
        AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to tell target to change baud rate!"));            
1254
1258
    }
1255
1259
    
1256
1260
    return status;
1257
1261
}
1258
1262
 
1259
 
A_STATUS HCI_TransportEnablePowerMgmt(HCI_TRANSPORT_HANDLE HciTrans, A_BOOL Enable)
 
1263
int HCI_TransportEnablePowerMgmt(HCI_TRANSPORT_HANDLE HciTrans, bool Enable)
1260
1264
{
1261
 
    A_STATUS status;
1262
 
    GMBOX_PROTO_HCI_UART  *pProt = (GMBOX_PROTO_HCI_UART *)HciTrans;
 
1265
    int status;
 
1266
    struct gmbox_proto_hci_uart  *pProt = (struct gmbox_proto_hci_uart *)HciTrans;
1263
1267
                             
1264
1268
    if (Enable) {
1265
1269
        status = DevGMboxSetTargetInterrupt(pProt->pDev, MBOX_SIG_HCI_BRIDGE_PWR_SAV_ON, BTPWRSAV_TIMEOUT_MS);
1267
1271
        status = DevGMboxSetTargetInterrupt(pProt->pDev, MBOX_SIG_HCI_BRIDGE_PWR_SAV_OFF, BTPWRSAV_TIMEOUT_MS);
1268
1272
    }
1269
1273
 
1270
 
    if (A_FAILED(status)) {
 
1274
    if (status) {
1271
1275
        AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Failed to enable/disable HCI power management!\n"));
1272
1276
    } else {
1273
1277
        AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("HCI power management enabled/disabled!\n"));