fix compile warnings for gcc 6.2.0
[open-ath9k-htc-firmware.git] / target_firmware / magpie_fw_dev / target / init / magpie.c
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 #include "sys_cfg.h"
36 #include "app_start.h"
37
38 #if defined(_RAM_)
39
40 #include "dt_defs.h"
41 #include "athos_api.h"
42
43 #include "adf_os_mem.h"
44
45 #define MAGPIE 1
46
47 #if MAGPIE==1
48
49 void htc_setup_comp(void)
50 {
51 }
52
53 /* target WMI command related globals */
54 static void dispatch_magpie_sys_cmds(void *pContext, A_UINT16 Command,
55                                      A_UINT16 SeqNo, A_UINT8 *buffer, int Length);
56
57 #if MAGPIE_ENABLE_WLAN == 0
58 static WMI_DISPATCH_ENTRY Magpie_Sys_DispatchEntries[] =
59 {
60         {dispatch_magpie_sys_cmds,  WMI_ECHO_CMDID, 0},
61         {dispatch_magpie_sys_cmds,  WMI_ACCESS_MEMORY_CMDID, 0}
62 };
63
64 static WMI_DECLARE_DISPATCH_TABLE(Magpie_Sys_Commands_Tbl, Magpie_Sys_DispatchEntries);
65 #endif
66
67 htc_handle_t htc_handle;
68
69 extern void HTC_Loopback_Init(htc_handle_t handle);
70 extern void _wmi_cmd_rsp(void *pContext, WMI_COMMAND_ID cmd_id,
71                          A_UINT16 SeqNo, A_UINT8 *buffer, int Length);
72
73 static void handle_echo_command(void *pContext, A_UINT16 SeqNo,
74                                 A_UINT8 *buffer, int Length)
75 {
76         _wmi_cmd_rsp(pContext, WMI_ECHO_CMDID, SeqNo, buffer, Length);
77 }
78
79 static void dispatch_magpie_sys_cmds(void *pContext, A_UINT16 Command,
80                                      A_UINT16 SeqNo, A_UINT8 *buffer, int Length)
81 {
82         switch(Command)
83         {
84         case WMI_ECHO_CMDID:
85                 handle_echo_command(pContext, SeqNo, buffer, Length);
86                 break;
87
88         case WMI_ACCESS_MEMORY_CMDID:
89                 break;
90         }
91 }
92
93 void _wmi_cmd_rsp(void *pContext, WMI_COMMAND_ID cmd_id, A_UINT16 SeqNo,
94                   A_UINT8 *buffer, int Length)
95 {
96         adf_nbuf_t netbuf = ADF_NBUF_NULL;
97         A_UINT8 *pData;
98
99         netbuf = WMI_AllocEvent(pContext, WMI_EVT_CLASS_CMD_REPLY, sizeof(WMI_CMD_HDR) + Length);
100     
101         if (netbuf == ADF_NBUF_NULL) {
102                 adf_os_print("%s: buffer allocation for event_id %x failed!\n", __FUNCTION__, cmd_id);
103                 adf_os_assert(0);
104                 return;
105         }
106
107         if (Length != 0 && buffer != NULL) {
108                 pData = (A_UINT8 *)adf_nbuf_put_tail(netbuf, Length);
109                 adf_os_mem_copy(pData, buffer, Length);
110         }
111
112         WMI_SendEvent(pContext, netbuf, cmd_id, SeqNo, Length);
113 }
114
115
116 void Magpie_init(void)
117 {
118         A_PRINTF("[+++Magpie_init]\n\r");
119  
120         A_PRINTF("[+++VBUF_init(%d)]\n\r", MAX_BUF_NUM);
121         VBUF_init(MAX_BUF_NUM);
122     
123         A_PRINTF("[+++VBUF_init(%d)]\n\r", MAX_DESC_NUM);
124         VDESC_init(MAX_DESC_NUM);
125
126 #if MAGPIE_ENABLE_WLAN == 0
127         aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
128                 hif_handle = HIF_init(0);
129
130 #if ZM_FM_LOOPBACK == 1
131         HIF_config_pipe(hif_handle, HIF_USB_PIPE_TX, 5);
132         HIF_config_pipe(hif_handle, HIF_USB_PIPE_COMMAND, 2);
133
134 #if SYSTEM_MODULE_HP_EP5
135         HIF_config_pipe(hif_handle, HIF_USB_PIPE_HP_TX, 3);
136 #endif
137 #if SYSTEM_MODULE_HP_EP6
138         HIF_config_pipe(hif_handle, HIF_USB_PIPE_MP_TX, 3);
139 #endif
140     
141         A_PRINTF("[+++HIF_init(0)]\n\r");
142
143         HIF_start(hif_handle);
144
145 #else /* ZM_FM_LOOPBACK == 0 */
146         // initialize HTC
147         htcConf.CreditSize = 320;
148         htcConf.CreditNumber = 10;
149 #if 1
150         htcConf.ControlDownLinkPipeID = HIF_USB_PIPE_INTERRUPT;         // Target -> Host
151         htcConf.ControlUpLinkPipeID = HIF_USB_PIPE_COMMAND;             // Host   -> Target
152 #else
153         htcConf.ControlDownLinkPipeID = HIF_USB_PIPE_RX;
154         htcConf.ControlUpLinkPipeID = HIF_USB_PIPE_TX;
155 #endif
156         htcConf.HIFHandle = hif_handle;
157         htcConf.OSHandle = 0;             // not used
158         htcConf.PoolHandle = pool_handle;
159
160         htc_handle = HTC_init(htc_setup_comp, &htcConf);
161         // Initialize HTC services
162         HTC_Loopback_Init(htc_handle);
163
164         adf_os_mem_zero(&wmiConfig, sizeof(WMI_SVC_CONFIG));
165         wmiConfig.HtcHandle = htc_handle;
166         wmiConfig.PoolHandle = pool_handle;
167         wmiConfig.MaxCmdReplyEvts = 1;
168         wmiConfig.MaxEventEvts = 1;
169
170         wmi_handle = WMI_Init(&wmiConfig);
171         Magpie_Sys_Commands_Tbl.pContext = wmi_handle;
172         WMI_RegisterDispatchTable(Magpie_Sys_Commands_Tbl.pContext, &Magpie_Sys_Commands_Tbl);
173
174 #endif/* ZM_FM_LOOPBACK == 0 */
175 #endif /* MAGPIE_ENABLE_WLAN */                 
176 }
177
178 #endif /* #if MAGPIE==1 */
179
180 #endif /* #if defined(_RAM_) */