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