Merge pull request #99 from olerem/pre_debian-2016.10.02
[open-ath9k-htc-firmware.git] / target_firmware / magpie_fw_dev / target / inc / magpie / htc_api.h
1 /*\r
2  * Copyright (c) 2013 Qualcomm Atheros, Inc.\r
3  *\r
4  * All rights reserved.\r
5  *\r
6  * Redistribution and use in source and binary forms, with or without\r
7  * modification, are permitted (subject to the limitations in the\r
8  * disclaimer below) provided that the following conditions are met:\r
9  *\r
10  *  * Redistributions of source code must retain the above copyright\r
11  *    notice, this list of conditions and the following disclaimer.\r
12  *\r
13  *  * Redistributions in binary form must reproduce the above copyright\r
14  *    notice, this list of conditions and the following disclaimer in the\r
15  *    documentation and/or other materials provided with the\r
16  *    distribution.\r
17  *\r
18  *  * Neither the name of Qualcomm Atheros nor the names of its\r
19  *    contributors may be used to endorse or promote products derived\r
20  *    from this software without specific prior written permission.\r
21  *\r
22  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE\r
23  * GRANTED BY THIS LICENSE.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT\r
24  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED\r
25  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
26  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
27  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE\r
28  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR\r
31  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
32  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\r
33  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN\r
34  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
35  */\r
36 \r
37 #ifndef __HTC_API_H__\r
38 #define __HTC_API_H__\r
39 \r
40 #include <osapi.h>\r
41 #include <htc.h>\r
42 //#include <htc_buf.h>\r
43 //#include <htc_services.h>\r
44 #include <adf_nbuf.h>\r
45 #include <buf_pool_api.h>\r
46 \r
47 #define HTC_HDR_SZ          HTC_HDR_LENGTH\r
48 #define HTC_BUFSZ_MAX_SEND  2048\r
49 \r
50 typedef void (* HTC_SERVICE_ProcessRecvMsg)(HTC_ENDPOINT_ID EndpointID, adf_nbuf_t, adf_nbuf_t, void *ServiceCtx);\r
51 typedef void (* HTC_SERVICE_ProcessSendBufferComplete)(HTC_ENDPOINT_ID EndpointID, adf_nbuf_t, void *ServiceCtx);\r
52  \r
53 /* HTC service structure :\r
54  * the caller is required to allocate storage for the service structure and register the\r
55  * structure using HTC_RegisterService()  The service must set the following fields:\r
56  *    ProcessRecvMsg\r
57  *    ProcessSendBufferComplete\r
58  *    ProcessConnect\r
59  *    ServiceID\r
60  *    MaxSvcMsgSize (for message validation)\r
61  * */\r
62 typedef struct _HTC_SERVICE {\r
63     struct _HTC_SERVICE *pNext;\r
64         /* Callback for processing receive messages.  HTC calls this callback whenever a \r
65          * message arrives on the endpoint assigned to this service.\r
66          * HTC_BUFFER is a chain of buffers containing a full application message.\r
67          * HTC_BUFFER->buffer points to the start of the msg buffer (past the HTC header) */\r
68     //void (* ProcessRecvMsg)(HTC_ENDPOINT_ID EndpointID, HTC_BUFFER *); \r
69     void (* ProcessRecvMsg)(HTC_ENDPOINT_ID EndpointID, adf_nbuf_t, adf_nbuf_t, void *ServiceCtx); \r
70         /* callback to process completed send buffers */\r
71     //void (* ProcessSendBufferComplete)(HTC_ENDPOINT_ID EndpointID, HTC_BUFFER *); \r
72     void (* ProcessSendBufferComplete)(HTC_ENDPOINT_ID EndpointID, adf_nbuf_t, void *ServiceCtx); \r
73         /* optional callback when a connection request occurs.\r
74          * The EndpointID is the assigned endpoint, the callback returns a connect \r
75          * response status code to allow or disallow the connection.\r
76          * pDataIn points to the optional meta data supplied in the connection request\r
77          * pDataOut points to a buffer to send back meta data \r
78          * If no callback is supplied, HTC assumes the connect is allowed  */\r
79     A_UINT8 (* ProcessConnect)(struct _HTC_SERVICE *pService,\r
80                                HTC_ENDPOINT_ID     EndpointID, \r
81                                A_UINT8 *pDataIn, \r
82                                int      LengthIn,\r
83                                A_UINT8 *pDataOut,\r
84                                int     *pLengthOut); \r
85     A_UINT16  ServiceID;        /* service ID to match connection requests */\r
86     A_UINT16  ServiceFlags;     /* service flags */\r
87     A_UINT16  MaxSvcMsgSize;    /* maximum length of service-specific messages exchanged on the endpoint */\r
88     A_UINT16  TrailerSpcCheckLimit;  /* amount of space in each send buffer that HTC can check for trailer\r
89                                         data. This should be set to the smallest HTC buffer that can be sent \r
90                                         through the service. The service can disable trailer data insertion\r
91                                         by setting this value to 0. */\r
92     void      *ServiceCtx;\r
93 } HTC_SERVICE;\r
94 \r
95 #define HTC_SERVICE_FLAGS_CONNECTED         (1 << 0)  /* service has at least 1 connection */\r
96 \r
97 #define IS_SERVICE_CONNECTED(s) ((s)->ServiceFlags & HTC_SERVICE_FLAGS_CONNECTED)\r
98 \r
99    /* configuration settings for the WMI service */\r
100 typedef struct _HTC_CONFIG {\r
101     int         CreditSize;    /*  */\r
102     int         CreditNumber;\r
103     //int         ControlDownLinkPipeID;\r
104     //int         ControlUpLinkPipeID;\r
105     adf_os_handle_t   OSHandle;\r
106     hif_handle_t      HIFHandle;\r
107     pool_handle_t     PoolHandle;\r
108 } HTC_CONFIG;\r
109 \r
110 typedef struct _HTC_BUF_CONTEXT {\r
111     A_UINT8         end_point;\r
112     A_UINT8         htc_flags;      /* htc flags (used by HTC layer only) */     \r
113 } HTC_BUF_CONTEXT;\r
114 \r
115 typedef void* htc_handle_t;\r
116 \r
117 /*\r
118  * setup complete function, supplied by HTC caller at HTC_init time.\r
119  * HTC calls this function after the host has indicated that the service connection\r
120  * phase is complete.\r
121  * \r
122  */\r
123 typedef void (* HTC_SETUP_COMPLETE_CB)(void);\r
124 \r
125 struct htc_apis {\r
126     htc_handle_t (* _HTC_Init)(HTC_SETUP_COMPLETE_CB, HTC_CONFIG *pConfig);    \r
127     void (* _HTC_Shutdown)(htc_handle_t);\r
128     void (* _HTC_RegisterService)(htc_handle_t, HTC_SERVICE *);\r
129     void (* _HTC_Ready)(htc_handle_t);\r
130     void (* _HTC_ReturnBuffers)(htc_handle_t handle, HTC_ENDPOINT_ID EndpointID, adf_nbuf_t);\r
131     void (* _HTC_ReturnBuffersList)(htc_handle_t handle, HTC_ENDPOINT_ID EndpointID, adf_nbuf_queue_t);\r
132     void (* _HTC_SendMsg)(htc_handle_t handle, HTC_ENDPOINT_ID EndpointID, adf_nbuf_t);        \r
133     int  (* _HTC_GetReservedHeadroom)(htc_handle_t handle);\r
134     \r
135     //void (* _HTC_PauseRecv)(HTC_ENDPOINT_ID EndpointID);\r
136     //void (* _HTC_ResumeRecv)(HTC_ENDPOINT_ID EndpointID);\r
137     //void (* _HTC_AddBufferResources)(int buffers);\r
138     \r
139     /* These APIs below are for patch purpose only */\r
140     void (*_HTC_MsgRecvHandler)(adf_nbuf_t hdr_buf, adf_nbuf_t buf, void *context);\r
141     void (*_HTC_SendDoneHandler)(adf_nbuf_t buf, void *context);\r
142     void (*_HTC_ControlSvcProcessMsg)(HTC_ENDPOINT_ID EndpointID, adf_nbuf_t hdr_buf, adf_nbuf_t buf, void *arg);\r
143     void (*_HTC_ControlSvcProcessSendComplete)(HTC_ENDPOINT_ID EndpointID, adf_nbuf_t pBuffers, void *arg);\r
144     \r
145     void *pReserved;  /* for expansion if need be */\r
146 };\r
147 \r
148 extern void htc_module_install(struct htc_apis *pAPIs);\r
149 \r
150 #endif /* _HTC_API_H__ */\r