Setting up repository
[linux-libre-firmware.git] / ath9k_htc / sboot / magpie_1_1 / sboot / htc / src / htc_internal.h
1 /*
2  * Copyright (c) 2013 Qualcomm Atheros, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted (subject to the limitations in the
7  * disclaimer below) provided that the following conditions are met:
8  *
9  *  * Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  *  * Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the
15  *    distribution.
16  *
17  *  * Neither the name of Qualcomm Atheros nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific prior written permission.
20  *
21  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
22  * GRANTED BY THIS LICENSE.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
23  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
24  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 /*
36  * @File: 
37  * 
38  * @Abstract: internal data and structure definitions for HTC
39  * 
40  * @Notes: 
41  */
42
43 #ifndef HTC_INTERNAL_H_
44 #define HTC_INTERNAL_H_
45
46 /* minimum buffer size to hold up to 8 endpoint reports, lookahead and the HTC header */
47 #define MIN_BUF_SIZE_FOR_RPTS (A_ROUND_UP((sizeof(HTC_LOOKAHEAD_REPORT) +              \
48                                           (sizeof(HTC_CREDIT_REPORT)) * 8 +            \
49                                           (sizeof(HTC_RECORD_HDR)) * 2  ) +            \
50                                           HTC_HDR_LENGTH,                              \
51                                           sizeof(A_UINT32)))
52 /* minimum allocation for a credit message */                                   
53 //#define MIN_CREDIT_BUFFER_ALLOC_SIZE     (A_ROUND_UP(MIN_BUF_SIZE_FOR_RPTS, A_CACHE_LINE_SIZE))
54 #define MIN_CREDIT_BUFFER_ALLOC_SIZE     (MIN_BUF_SIZE_FOR_RPTS)
55 /* max ctrl buffers size for a setup message */
56 //#define MAX_HTC_SETUP_MSG_SIZE           (128 + 64)  /* meta data + 64 byte response message */
57 #define MAX_HTC_SETUP_MSG_SIZE           64            /* The max size of USB command/event pipe is 64 bytes */
58
59 /* check size for trailer space */
60 #define HTC_CTRL_BUFFER_CHECK_SIZE       (MIN_BUF_SIZE_FOR_RPTS - HTC_HDR_LENGTH)
61
62 #define HTC_DEFAULT_NUM_CTRL_BUFFERS              6
63
64 #define HTC_DEFAULT_MAX_EP_PENDING_CREDIT_REPORTS 3  /* an EP should not have more than this many outstanding reports */
65
66 #define HTC_FLAGS_CRPT_EP_MASK      0x1F     /* if the message is a credit report this is the endpoint 
67                                                 that issued it */
68
69 #define HTC_FLAGS_CREDIT_RPT       (1 << 5)  /* the buffer was a credit report */
70 #define HTC_FLAGS_BUF_HDR          (1 << 6)  /* the buffer was manipulated and a header added */
71 #define HTC_FLAGS_RECV_END_MSG     (1 << 7)  /* this buffer is the last buffer for the recev
72                                                 message (used for recv pause logic) */     
73                                                                                                                               
74 #define HTC_MAILBOX                 0        /* we use mailbox 0 for all communications */
75 #define HTC_ANY_ENDPOINT_MASK       0xFFFFFFFF
76 #define HTC_LOOKAHEAD_POST_VALID    0x55
77 #define HTC_LOOKAHEAD_PRE_VALID     0xAA
78 #define MAX_HTC_CREDITS             255
79
80 typedef struct _HTC_ENDPOINT {
81     A_INT16       CreditsToReturn;       /* credits that are ready to be returned to the host */
82     HTC_SERVICE   *pService;             /* service that is bound to this endpoint */
83     //VBUF          *pRcvPausedQueueHead;  /* paused queue head and tail */
84     //VBUF          *pRcvPausedQueueTail;
85 #ifdef HTC_PAUSE_RESUME_REF_COUNTING 
86     int           PauseRefCount;         /* reference count */
87 #endif
88     A_INT16       CreditReturnThreshhold;   /* threshold before credits are returned via NULL pkts,
89                                                this reduces dribbling effect */    
90     A_INT16       CreditsConsumed;          /* number of credits consumed (outstanding) on the endpoint */  
91     A_UINT16      ConnectionFlags;          /* HTC connection flags */          
92     int           PendingCreditReports;     /* no. of pending credit reports issued by this endpoint */    
93     A_UINT8       DownLinkPipeID;           /* The pipe ID to be use for the direction: target -> host */
94     A_UINT8       UpLinkPipeID;             /* The pipe ID to be use for the direction: host   -> target */
95 } HTC_ENDPOINT;
96
97 typedef struct _HTC_CONTEXT {
98     adf_os_handle_t OSHandle;
99     HTC_ENDPOINT    Endpoints[ENDPOINT_MAX];  /* endpoint state structs */
100     A_UINT32        EpHostNeedsCreditMap;     /* credit update bit map for all EPs */
101     A_UINT32        EpCreditPendingMap;       /* credits pending bit map for all EPs */
102     A_UINT32        EpRecvPausedMap;          /* recv pause state bit map for all EPs */
103     HTC_ENDPOINT_ID CurrentEpIndex;           /* current unused endpoint index */
104     HTC_SERVICE     HTCControlService;        /* the pseudo service that handles EP0 traffic */
105     HTC_SERVICE     *pServiceList;            /* the service list */
106     int             RecvBufferSize;           /* the length of each recv buffer that HTC is given */
107     A_UINT32        StateFlags;               /* state flags */
108     HTC_SETUP_COMPLETE_CB SetupCompleteCb;    /* caller supplied setup completion routine */
109     int             TotalCredits;             /* total credits in system */
110     int             TotalCreditsAssigned;
111     int             NumBuffersForCreditRpts;      /* number of control buffers for credit reports */
112     int             CtrlBufferAllocSize;          /* length of allocation */
113     A_UINT8         *pCtrlBuffer;                 /* control buffer to be carved up for messages */
114     int             MaxEpPendingCreditRpts;       /* maximum number of pending credit reports that any 1 EP can have */
115     hif_handle_t    hifHandle;
116     pool_handle_t   PoolHandle;
117
118     // Left a door for extension the structure
119     void *pReserved;      
120 } HTC_CONTEXT;
121
122 #define HTC_STATE_SETUP_COMPLETE    (1 << 0)  /* HTC host-target setup is complete */
123 #define HTC_SEND_CREDIT_UPDATE_SOON (1 << 1)  /* Credit update message needs to be sent */
124 #define HTC_STATE_BUFF_REALLOC      (1 << 2)  /* buffers have been reallocated for credit messages */
125
126 #endif /*HTC_INTERNAL_H_*/