Initial cut of the open ath9k htc firmware.
[open-ath9k-htc-firmware.git] / target_firmware / magpie_fw_dev / build / magpie_1_1 / sboot / htc / src / htc_internal.h
1 /*
2  * @File: 
3  * 
4  * @Abstract: internal data and structure definitions for HTC
5  * 
6  * @Notes: 
7  * 
8  * 
9  * Copyright (c) 2007 Atheros Communications Inc.
10  * All rights reserved.
11  *
12  */
13
14 #ifndef HTC_INTERNAL_H_
15 #define HTC_INTERNAL_H_
16
17 /* minimum buffer size to hold up to 8 endpoint reports, lookahead and the HTC header */
18 #define MIN_BUF_SIZE_FOR_RPTS (A_ROUND_UP((sizeof(HTC_LOOKAHEAD_REPORT) +              \
19                                           (sizeof(HTC_CREDIT_REPORT)) * 8 +            \
20                                           (sizeof(HTC_RECORD_HDR)) * 2  ) +            \
21                                           HTC_HDR_LENGTH,                              \
22                                           sizeof(A_UINT32)))
23 /* minimum allocation for a credit message */                                   
24 //#define MIN_CREDIT_BUFFER_ALLOC_SIZE     (A_ROUND_UP(MIN_BUF_SIZE_FOR_RPTS, A_CACHE_LINE_SIZE))
25 #define MIN_CREDIT_BUFFER_ALLOC_SIZE     (MIN_BUF_SIZE_FOR_RPTS)
26 /* max ctrl buffers size for a setup message */
27 //#define MAX_HTC_SETUP_MSG_SIZE           (128 + 64)  /* meta data + 64 byte response message */
28 #define MAX_HTC_SETUP_MSG_SIZE           64            /* The max size of USB command/event pipe is 64 bytes */
29
30 /* check size for trailer space */
31 #define HTC_CTRL_BUFFER_CHECK_SIZE       (MIN_BUF_SIZE_FOR_RPTS - HTC_HDR_LENGTH)
32
33 #define HTC_DEFAULT_NUM_CTRL_BUFFERS              6
34
35 #define HTC_DEFAULT_MAX_EP_PENDING_CREDIT_REPORTS 3  /* an EP should not have more than this many outstanding reports */
36
37 #define HTC_FLAGS_CRPT_EP_MASK      0x1F     /* if the message is a credit report this is the endpoint 
38                                                 that issued it */
39
40 #define HTC_FLAGS_CREDIT_RPT       (1 << 5)  /* the buffer was a credit report */
41 #define HTC_FLAGS_BUF_HDR          (1 << 6)  /* the buffer was manipulated and a header added */
42 #define HTC_FLAGS_RECV_END_MSG     (1 << 7)  /* this buffer is the last buffer for the recev
43                                                 message (used for recv pause logic) */     
44                                                                                                                               
45 #define HTC_MAILBOX                 0        /* we use mailbox 0 for all communications */
46 #define HTC_ANY_ENDPOINT_MASK       0xFFFFFFFF
47 #define HTC_LOOKAHEAD_POST_VALID    0x55
48 #define HTC_LOOKAHEAD_PRE_VALID     0xAA
49 #define MAX_HTC_CREDITS             255
50
51 typedef struct _HTC_ENDPOINT {
52     A_INT16       CreditsToReturn;       /* credits that are ready to be returned to the host */
53     HTC_SERVICE   *pService;             /* service that is bound to this endpoint */
54     //VBUF          *pRcvPausedQueueHead;  /* paused queue head and tail */
55     //VBUF          *pRcvPausedQueueTail;
56 #ifdef HTC_PAUSE_RESUME_REF_COUNTING 
57     int           PauseRefCount;         /* reference count */
58 #endif
59     A_INT16       CreditReturnThreshhold;   /* threshold before credits are returned via NULL pkts,
60                                                this reduces dribbling effect */    
61     A_INT16       CreditsConsumed;          /* number of credits consumed (outstanding) on the endpoint */  
62     A_UINT16      ConnectionFlags;          /* HTC connection flags */          
63     int           PendingCreditReports;     /* no. of pending credit reports issued by this endpoint */    
64     A_UINT8       DownLinkPipeID;           /* The pipe ID to be use for the direction: target -> host */
65     A_UINT8       UpLinkPipeID;             /* The pipe ID to be use for the direction: host   -> target */
66 } HTC_ENDPOINT;
67
68 typedef struct _HTC_CONTEXT {
69     adf_os_handle_t OSHandle;
70     HTC_ENDPOINT    Endpoints[ENDPOINT_MAX];  /* endpoint state structs */
71     A_UINT32        EpHostNeedsCreditMap;     /* credit update bit map for all EPs */
72     A_UINT32        EpCreditPendingMap;       /* credits pending bit map for all EPs */
73     A_UINT32        EpRecvPausedMap;          /* recv pause state bit map for all EPs */
74     HTC_ENDPOINT_ID CurrentEpIndex;           /* current unused endpoint index */
75     HTC_SERVICE     HTCControlService;        /* the pseudo service that handles EP0 traffic */
76     HTC_SERVICE     *pServiceList;            /* the service list */
77     int             RecvBufferSize;           /* the length of each recv buffer that HTC is given */
78     A_UINT32        StateFlags;               /* state flags */
79     HTC_SETUP_COMPLETE_CB SetupCompleteCb;    /* caller supplied setup completion routine */
80     int             TotalCredits;             /* total credits in system */
81     int             TotalCreditsAssigned;
82     int             NumBuffersForCreditRpts;      /* number of control buffers for credit reports */
83     int             CtrlBufferAllocSize;          /* length of allocation */
84     A_UINT8         *pCtrlBuffer;                 /* control buffer to be carved up for messages */
85     int             MaxEpPendingCreditRpts;       /* maximum number of pending credit reports that any 1 EP can have */
86     hif_handle_t    hifHandle;
87     pool_handle_t   PoolHandle;
88
89     // Left a door for extension the structure
90     void *pReserved;      
91 } HTC_CONTEXT;
92
93 #define HTC_STATE_SETUP_COMPLETE    (1 << 0)  /* HTC host-target setup is complete */
94 #define HTC_SEND_CREDIT_UPDATE_SOON (1 << 1)  /* Credit update message needs to be sent */
95 #define HTC_STATE_BUFF_REALLOC      (1 << 2)  /* buffers have been reallocated for credit messages */
96
97 #endif /*HTC_INTERNAL_H_*/