carl9170: Update to latest upstream
[linux-libre-firmware.git] / ath9k_htc / target_firmware / magpie_fw_dev / target / inc / magpie / Magpie_api.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: Magpie_api.h
37  *
38  * @Abstract: Magpie FW api
39  *
40  * @Notes:
41  */
42
43 #ifndef _MAGPIE_API_H
44 #define _MAGPIE_API_H
45
46 #define MAGPIE_FW_BUILD
47
48 #include "cmnos_api.h"
49 #ifdef MAGPIE_FW_BUILD
50 #include "vbuf_api.h"
51 #include "vdesc_api.h"
52 #include "usbfifo_api.h"
53 //#include "allocram_api.h"
54 #endif
55
56 #include "hif_api.h"
57 #include "htc_api.h"
58 #include "wmi_svc_api.h"
59 #include "buf_pool_api.h"
60 #include "dma_engine_api.h"
61 #include "dma_lib.h"
62
63 #if (SYSTEM_MODULE_SFLASH != 0)
64 #include "sflash_api.h"
65 #endif
66
67 #define A_INDIR(sym)   _A_MAGPIE_INDIRECTION_TABLE->sym
68
69 #if SYSTEM_MODULE_DBG
70 /* debug Support */
71 #define DBG_MODULE_INSTALL()            cmnos_dbg_module_install(&_A_MAGPIE_INDIRECTION_TABLE->dbg)
72 #define A_DBG_INIT()                    A_INDIR(dbg._dbg_init())
73 #define A_DBG_TASK()                    A_INDIR(dbg._dbg_task())
74 #else
75 #define A_DBG_INIT()
76 #define A_DBG_TASK()
77 #endif
78
79 /* Serial Flash support */
80 #if (SYSTEM_MODULE_SFLASH != 0)
81 #define SFLASH_MODULE_INSTALL()                 cmnos_sflash_module_install(&_A_MAGPIE_INDIRECTION_TABLE->sflash)
82 #define A_SFLASH_INIT()                         A_INDIR(sflash._sflash_init())
83 #define A_SFLASH_ERASE(erase_type, addr)        A_INDIR(sflash._sflash_erase(erase_type, addr))
84 #define A_SFLASH_PROG(addr, len, buf)           A_INDIR(sflash._sflash_program(addr, len, buf))
85 #define A_SFLASH_READ(fast, addr, len, buf)     A_INDIR(sflash._sflash_read(fast, addr, len, buf))
86 #define A_SFLASH_RDSR()                         A_INDIR(sflash._sflash_rdsr())
87 #else
88 #define A_SFLASH_INIT()
89 #define A_SFLASH_ERASE(erase_type, addr)
90 #define A_SFLASH_PROG(addr, len, buf)
91 #define A_SFLASH_READ(fast, addr, len, buf)
92 #define A_SFLASH_RDSR()
93 #endif
94
95 /* DMA Engine Interface */
96 #define DMA_ENGINE_MODULE_INSTALL()                 dma_engine_module_install(&_A_MAGPIE_INDIRECTION_TABLE->dma_engine);
97 #define DMA_Engine_init()                           A_INDIR(dma_engine._init())
98 #define DMA_Engine_config_rx_queue(q, nDesc, size)  A_INDIR(dma_engine._config_rx_queue(q, nDesc, size))
99 #define DMA_Engine_xmit_buf(q, buf)                 A_INDIR(dma_engine._xmit_buf(q, buf))
100 #define DMA_Engine_flush_xmit(q)                    A_INDIR(dma_engine._flush_xmit(q))
101 #define DMA_Engine_reap_recv_buf(q)                 A_INDIR(dma_engine._reap_recv_buf(q))
102 #define DMA_Engine_return_recv_buf(q,buf)           A_INDIR(dma_engine._return_recv_buf(q, buf))
103 #define DMA_Engine_reap_xmited_buf(q)               A_INDIR(dma_engine._reap_xmited_buf(q))
104 #define DMA_Engine_swap_data(desc)                  A_INDIR(dma_engine._swap_data(desc))
105 #define DMA_Engine_init_rx_queue(q)                 A_INDIR(dma_engine._init_rx_queue(q))
106 #define DMA_Engine_init_tx_queue(q)                 A_INDIR(dma_engine._init_tx_queue(q))
107 #define DMA_Engine_has_compl_packets(q)             A_INDIR(dma_engine._has_compl_packets(q))
108 #define DMA_Engine_desc_dump(q)                     A_INDIR(dma_engine._desc_dump(q))
109 #define DMA_Engine_get_packet(q)                    A_INDIR(dma_engine._get_packet(q))
110 #define DMA_Engine_reclaim_packet(q,desc)           A_INDIR(dma_engine._reclaim_packet(q,desc))
111 #define DMA_Engine_put_packet(q,desc)               A_INDIR(dma_engine._put_packet(q,desc))
112
113 /*DMA Library support for GMAC & PCI(E)*/
114 #define DMA_LIB_MODULE_INSTALL()                    dma_lib_module_install(&_A_MAGPIE_INDIRECTION_TABLE->dma_lib)
115 #define dma_lib_tx_init(eng_no, if_type)            A_INDIR(dma_lib.tx_init(eng_no, if_type))
116 #define dma_lib_rx_init(eng_no, if_type)            A_INDIR(dma_lib.rx_init(eng_no, if_type))
117 #define dma_lib_rx_config(eng_no, desc, gran)       A_INDIR(dma_lib.rx_config(eng_no, desc, gran))
118 #define dma_lib_tx_start(eng_no)                    A_INDIR(dma_lib.tx_start(eng_no))
119 #define dma_lib_rx_start(eng_no)                    A_INDIR(dma_lib.rx_start(eng_no))
120 #define dma_lib_intr_status(if_type)                A_INDIR(dma_lib.intr_status(if_type))
121 #define dma_lib_hard_xmit(eng_no, buf)              A_INDIR(dma_lib.hard_xmit(eng_no, buf))
122 #define dma_lib_flush_xmit(eng_no)                  A_INDIR(dma_lib.flush_xmit(eng_no))
123 #define dma_lib_xmit_done(eng_no)                   A_INDIR(dma_lib.xmit_done(eng_no))
124 #define dma_lib_reap_xmitted(eng_no)                A_INDIR(dma_lib.reap_xmitted(eng_no))
125 #define dma_lib_reap_recv(eng_no)                   A_INDIR(dma_lib.reap_recv(eng_no))
126 #define dma_lib_return_recv(eng_no, buf)            A_INDIR(dma_lib.return_recv(eng_no, buf))
127 #define dma_lib_recv_pkt(eng_no)                    A_INDIR(dma_lib.recv_pkt(eng_no))
128
129 /* HIF PCI Api's */
130 #define hif_pci_boot_init()                 A_INDIR(hif_pci.pci_boot_init())
131 #define hif_pci_init(pConfig)               A_INDIR(hif_pci.pci_init(pConfig))
132 #define hif_pci_reset()                     A_INDIR(hif_pci.pci_reset())
133 #define hif_pci_enable()                    A_INDIR(hif_pci.pci_enable())
134 #define hif_pci_get_pipe(eng)               A_INDIR(hif_pci.pci_get_pipe(eng))
135 #define hif_pci_get_tx_eng(pipe)            A_INDIR(hif_pci.pci_get_tx_eng(pipe))
136 #define hif_pci_get_rx_eng(pipe)            A_INDIR(hif_pci.pci_get_rx_eng(pipe))
137 #define hif_pci_reap_recv(sc, eng_no)       A_INDIR(hif_pci.pci_reap_recv(sc, eng_no))
138 #define hif_pci_reap_xmitted(sc, eng_no)    A_INDIR(hif_pci.pci_reap_xmitted(sc, eng_no))
139
140 /* HIF support */
141 #define HIF_MODULE_INSTALL()                        generic_hif_module_install(&_A_MAGPIE_INDIRECTION_TABLE->hif)
142 #define HIF_init(pConfig)                           A_INDIR(hif._init(pConfig))
143 #define HIF_shutdown(h)                             A_INDIR(hif._shutdown(h))
144 #define HIF_register_callback(h, pConfig)           A_INDIR(hif._register_callback(h, pConfig))
145 #define HIF_start(h)                                A_INDIR(hif._start(h))
146 #define HIF_config_pipe(h, pipe, desc_list)         A_INDIR(hif._config_pipe(h, pipe, desc_list))
147 #define HIF_send_buffer(h, pipe, buf)               A_INDIR(hif._send_buffer(h, pipe, buf))
148 #define HIF_return_recv_buf(h, pipe, buf)           A_INDIR(hif._return_recv_buf(h, pipe, buf))
149 #define HIF_isr_handler(h)                          A_INDIR(hif._isr_handler(h))
150 #define HIF_is_pipe_supported(h, pipe)              A_INDIR(hif._is_pipe_supported(h, pipe))
151 #define HIF_get_max_msg_len(h, pipe)                A_INDIR(hif._get_max_msg_len(h, pipe))
152 #define HIF_get_reserved_headroom(h)                A_INDIR(hif._get_reserved_headroom(h))
153 #define HIF_get_default_pipe(h,u,d)                 A_INDIR(hif._get_default_pipe(h,u,d))
154 typedef void (*HIF_INSTALL_FUNC_T)(struct hif_api *apis);
155
156 /* VBUF APIs */
157 #ifdef MAGPIE_FW_BUILD
158 #define VBUF_MODULE_INSTALL()                       vbuf_module_install(&_A_MAGPIE_INDIRECTION_TABLE->vbuf)
159 #define VBUF_init(nBuf)                             A_INDIR(vbuf._init(nBuf))
160 #define VBUF_alloc_vbuf()                           A_INDIR(vbuf._alloc_vbuf())
161 #define VBUF_free_vbuf(buf)                         A_INDIR(vbuf._free_vbuf(buf))
162 #endif
163
164 /* VDESC APIs */
165 #ifdef MAGPIE_FW_BUILD
166 #define VDESC_MODULE_INSTALL()                      vdesc_module_install(&_A_MAGPIE_INDIRECTION_TABLE->vdesc)
167 #define VDESC_init(nDesc)                           A_INDIR(vdesc._init(nDesc))
168 #define VDESC_alloc_vdesc()                         A_INDIR(vdesc._alloc_vdesc())
169 #define VDESC_get_hw_desc(desc)                     A_INDIR(vdesc._get_hw_desc(desc))
170 #define VDESC_swap_vdesc(dst, src)                  A_INDIR(vdesc._swap_vdesc(dst, src))
171 #endif
172
173 #define HTC_MODULE_INSTALL()                        htc_module_install(&_A_MAGPIE_INDIRECTION_TABLE->htc)
174 #define HTC_init(SetupComplete, pConfig)            A_INDIR(htc._HTC_Init(SetupComplete, pConfig))
175 #define HTC_Shutdown(h)                             A_INDIR(htc._HTC_Shutdown(h))
176 #define HTC_RegisterService(h, s)                   A_INDIR(htc._HTC_RegisterService(h, s))
177 #define HTC_Ready(h)                                A_INDIR(htc._HTC_Ready(h))
178 #define HTC_SendMsg(h, endpt, buf)                  A_INDIR(htc._HTC_SendMsg(h, endpt, buf))
179 #define HTC_ReturnBuffers(h, endpt, buf)            A_INDIR(htc._HTC_ReturnBuffers(h, endpt, buf))
180 #define HTC_ReturnBuffersList(h, endpt, hd)         A_INDIR(htc._HTC_ReturnBuffersList(h, endpt, hd))
181 #define HTC_GetReservedHeadroom(h)                  A_INDIR(htc._HTC_GetReservedHeadroom(h))
182
183 #define HTC_NotifyTargetInserted(h)
184 #define HTC_NotifyTargetDetached(h)
185
186 /* WMI SVC module */
187 #define WMI_SERVICE_MODULE_INSTALL()                WMI_service_module_install(&_A_MAGPIE_INDIRECTION_TABLE->wmi_svc_api)
188 #define WMI_Init(pCfg)                              A_INDIR(wmi_svc_api._WMI_Init(pCfg))
189 #define WMI_RegisterDispatchTable(h,pT)             A_INDIR(wmi_svc_api._WMI_RegisterDispatchTable(h, pT))
190 #define WMI_AllocEvent(h,ec,len)                    A_INDIR(wmi_svc_api._WMI_AllocEvent(h, ec, len))
191 #define WMI_SendEvent(h,ev,id,seq,len)              A_INDIR(wmi_svc_api._WMI_SendEvent(h, ev, id, seq, len))
192 #define WMI_GetPendingEventsCount()                 A_INDIR(wmi_svc_api._WMI_GetPendingEventsCount())
193 #define WMI_GetControlEp()                          A_INDIR(wmi_svc_api._WMI_GetControlEp())
194 #define WMI_SendCompleteHandler(ep, buf)            A_INDIR(wmi_svc_api._WMI_SendCompleteHandler(ep, buf))
195 #define WMI_Shutdown(h)                             A_INDIR(wmi_svc_api._WMI_Shutdown(h))
196
197 /* USB FIFO module */
198 #define USBFIFO_MODULE_INSTALL()                    usbfifo_module_install(&_A_MAGPIE_INDIRECTION_TABLE->usbfifo_api)
199 #define USBFIFO_init(pConfig)                       A_INDIR(usbfifo_api._init(pConfig))
200 #define USBFIFO_enable_event_isr()                  A_INDIR(usbfifo_api._enable_event_isr())
201
202 /* BUF pool module */
203 #define BUF_POOL_MODULE_INSTALL()                       buf_pool_module_install(&_A_MAGPIE_INDIRECTION_TABLE->buf_pool)
204 #define BUF_Pool_init(h)                                A_INDIR(buf_pool._init(h))
205 #define BUF_Pool_shutdown(h)                            A_INDIR(buf_pool._shutdown(h))
206 #define BUF_Pool_create_pool(h, id, nItems, nSize)      A_INDIR(buf_pool._create_pool(h, id, nItems, nSize))
207 #define BUF_Pool_alloc_buf(h, id, reserve)              A_INDIR(buf_pool._alloc_buf(h, id, reserve))
208 #define BUF_Pool_alloc_buf_align(h, id, reserve,align)  A_INDIR(buf_pool._alloc_buf_align(h, id, reserve,align))
209 #define BUF_Pool_free_buf(h, id, buf)                   A_INDIR(buf_pool._free_buf(h, id, buf))
210
211 /*
212  * This defines the layout of the indirection table, which
213  * is used to access exported APIs of various modules.  The
214  * layout is shared across ROM and RAM code.  RAM code may
215  * call into ROM and ROM code may call into RAM.  Because
216  * of the latter, existing offsets must not change for the
217  * lifetime of a revision of ROM; but new members may be
218  * added at the end.
219  */
220 typedef struct _A_magpie_indirection_table {
221     _A_cmnos_indirection_table_t        cmnos;
222
223 //#if SYSTEM_MODULE_DBG
224     struct dbg_api                      dbg;        // move to firmware not in cmnos
225 //#endif
226     struct hif_api                      hif;
227     struct htc_apis                     htc;
228     WMI_SVC_APIS                        wmi_svc_api;
229     struct usbfifo_api                  usbfifo_api;
230     struct buf_pool_api                 buf_pool;
231 #ifdef MAGPIE_FW_BUILD
232     struct vbuf_api                     vbuf;
233     struct vdesc_api                    vdesc;
234     struct allocram_api                 allocram;
235 #endif
236     struct dma_engine_api               dma_engine;
237     struct dma_lib_api                  dma_lib;
238
239 #if SYSTEM_MODULE_PCI
240     struct hif_pci_api                  hif_pci;
241 #endif
242     // structure to be added after this....
243 #if (SYSTEM_MODULE_SFLASH != 0)
244     struct sflash_api           sflash;
245 #endif
246 } _A_magpie_indirection_table_t;
247
248 extern _A_magpie_indirection_table_t _indir_tbl;
249 #define _A_MAGPIE_INDIRECTION_TABLE_SIZE sizeof(_A_magpie_indirection_table_t)
250 #if defined(__mips__)
251 #define _A_MAGPIE_INDIRECTION_TABLE ((_A_magpie_indirection_table_t *)0x700)
252 #else
253 #define _A_MAGPIE_INDIRECTION_TABLE (&_indir_tbl)
254 #endif
255
256 #endif