a89df34a6428a46f01f36ee75193f91db0aaa096
[open-ath9k-htc-firmware.git] / target_firmware / magpie_fw_dev / target / htc / htc_api.h
1 /*
2  * @File: htc_api.h
3  * 
4  * @Abstract: host-target communications API
5  * 
6  * @Notes: 
7  *  
8  * Copyright (c) 2008 Atheros Communications Inc.
9  * All rights reserved.
10  *
11  */
12
13 #ifndef __HTC_API_H__
14 #define __HTC_API_H__
15
16 #include <osapi.h>
17 #include <htc.h>
18 #include <adf_nbuf.h>
19 #include <buf_pool_api.h>
20
21 #define HTC_HDR_SZ          HTC_HDR_LENGTH
22 #define HTC_BUFSZ_MAX_SEND  2048
23
24 typedef void (* HTC_SERVICE_ProcessRecvMsg)(HTC_ENDPOINT_ID EndpointID, adf_nbuf_t, adf_nbuf_t, void *ServiceCtx);
25 typedef void (* HTC_SERVICE_ProcessSendBufferComplete)(HTC_ENDPOINT_ID EndpointID, adf_nbuf_t, void *ServiceCtx);
26  
27 /* HTC service structure :
28  * the caller is required to allocate storage for the service structure and register the
29  * structure using HTC_RegisterService()  The service must set the following fields:
30  *    ProcessRecvMsg
31  *    ProcessSendBufferComplete
32  *    ProcessConnect
33  *    ServiceID
34  *    MaxSvcMsgSize (for message validation)
35  * */
36 typedef struct _HTC_SERVICE {
37         struct _HTC_SERVICE *pNext;
38         /* Callback for processing receive messages.  HTC calls this callback whenever a 
39          * message arrives on the endpoint assigned to this service.
40          * HTC_BUFFER is a chain of buffers containing a full application message.
41          * HTC_BUFFER->buffer points to the start of the msg buffer (past the HTC header) */
42         void (* ProcessRecvMsg)(HTC_ENDPOINT_ID EndpointID, adf_nbuf_t, adf_nbuf_t, void *ServiceCtx); 
43         /* callback to process completed send buffers */
44         void (* ProcessSendBufferComplete)(HTC_ENDPOINT_ID EndpointID, adf_nbuf_t, void *ServiceCtx); 
45         /* optional callback when a connection request occurs.
46          * The EndpointID is the assigned endpoint, the callback returns a connect 
47          * response status code to allow or disallow the connection.
48          * pDataIn points to the optional meta data supplied in the connection request
49          * pDataOut points to a buffer to send back meta data 
50          * If no callback is supplied, HTC assumes the connect is allowed  */
51         A_UINT8 (* ProcessConnect)(struct _HTC_SERVICE *pService,
52                                    HTC_ENDPOINT_ID EndpointID, 
53                                    A_UINT8 *pDataIn, 
54                                    int LengthIn,
55                                    A_UINT8 *pDataOut,
56                                    int *pLengthOut); 
57
58         A_UINT16  ServiceID;        /* service ID to match connection requests */
59         A_UINT16  ServiceFlags;     /* service flags */
60         A_UINT16  MaxSvcMsgSize;    /* maximum length of service-specific messages exchanged on the endpoint */
61         A_UINT16  TrailerSpcCheckLimit;  /* amount of space in each send buffer that HTC can check for trailer
62                                             data. This should be set to the smallest HTC buffer that can be sent 
63                                             through the service. The service can disable trailer data insertion
64                                             by setting this value to 0. */
65         void      *ServiceCtx;
66 } HTC_SERVICE;
67
68 #define HTC_SERVICE_FLAGS_CONNECTED         (1 << 0)  /* service has at least 1 connection */
69
70 #define IS_SERVICE_CONNECTED(s) ((s)->ServiceFlags & HTC_SERVICE_FLAGS_CONNECTED)
71
72 /* configuration settings for the WMI service */
73 typedef struct _HTC_CONFIG {
74         int         CreditSize;    /*  */
75         int         CreditNumber;
76         adf_os_handle_t   OSHandle;
77         hif_handle_t      HIFHandle;
78         pool_handle_t     PoolHandle;
79 } HTC_CONFIG;
80
81 typedef struct _HTC_BUF_CONTEXT {
82         A_UINT8         end_point;
83         A_UINT8         htc_flags;      /* htc flags (used by HTC layer only) */     
84 } HTC_BUF_CONTEXT;
85
86 typedef void* htc_handle_t;
87
88 /*
89  * setup complete function, supplied by HTC caller at HTC_init time.
90  * HTC calls this function after the host has indicated that the service connection
91  * phase is complete.
92  * 
93  */
94 typedef void (* HTC_SETUP_COMPLETE_CB)(void);
95
96 struct htc_apis {
97         htc_handle_t (* _HTC_Init)(HTC_SETUP_COMPLETE_CB, HTC_CONFIG *pConfig);    
98         void (* _HTC_Shutdown)(htc_handle_t);
99         void (* _HTC_RegisterService)(htc_handle_t, HTC_SERVICE *);
100         void (* _HTC_Ready)(htc_handle_t);
101         void (* _HTC_ReturnBuffers)(htc_handle_t handle, HTC_ENDPOINT_ID EndpointID, adf_nbuf_t);
102         void (* _HTC_ReturnBuffersList)(htc_handle_t handle, HTC_ENDPOINT_ID EndpointID, adf_nbuf_queue_t);
103         void (* _HTC_SendMsg)(htc_handle_t handle, HTC_ENDPOINT_ID EndpointID, adf_nbuf_t);        
104         int  (* _HTC_GetReservedHeadroom)(htc_handle_t handle);
105     
106         /* These APIs below are for patch purpose only */
107         void (*_HTC_MsgRecvHandler)(adf_nbuf_t hdr_buf, adf_nbuf_t buf, void *context);
108         void (*_HTC_SendDoneHandler)(adf_nbuf_t buf, void *context);
109         void (*_HTC_ControlSvcProcessMsg)(HTC_ENDPOINT_ID EndpointID, adf_nbuf_t hdr_buf, adf_nbuf_t buf, void *arg);
110         void (*_HTC_ControlSvcProcessSendComplete)(HTC_ENDPOINT_ID EndpointID, adf_nbuf_t pBuffers, void *arg);
111
112         void *pReserved;  /* for expansion if need be */
113 };
114
115 extern void htc_module_install(struct htc_apis *pAPIs);
116
117 #endif /* _HTC_API_H__ */