Set qmQueMgmtProxyDataReg to NULL for k1, k2h
[keystone-rtos/netapi.git] / ti / runtime / netapi / src / pdkv2 / netapi_navig.c
1 /************************************************
2 *  FILE:  netapi_device.c
3  *  Device specific initialization for NETAPI
4  *
5  * DESCRIPTION: Functions to initialize multicore navigator related global
6  *              resources
7  *
8  * REVISION HISTORY:
9  *
10  *  Copyright (c) Texas Instruments Incorporated 2013
11  *
12  *  Redistribution and use in source and binary forms, with or without
13  *  modification, are permitted provided that the following conditions
14  *  are met:
15  *
16  *    Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  *
19  *    Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the
21  *    documentation and/or other materials provided with the
22  *    distribution.
23  *
24  *    Neither the name of Texas Instruments Incorporated nor the names of
25  *    its contributors may be used to endorse or promote products derived
26  *    from this software without specific prior written permission.
27  *
28  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  *
40  ***********************************************/
42 #include "netapi.h"
43 #include <sys/types.h>
44 #include <sys/stat.h>
45 #include <fcntl.h>
46 #include <sys/mman.h>
47 #include <errno.h>
48 #include <unistd.h>
50 #include <ti/csl/cslr_device.h>
51 #include <ti/drv/qmss/qmss_qm.h>
53 //pull in device config for qmss, cppi
54 #include "qmss_device.c"
55 #include "cppi_device.c"
58 /********************************************************************
59  * FUNCTION PURPOSE:  Internal NETAPI macro to convert to IP Register
60  *                    Virtual Address from a mapped base Virtual
61  *                    Address.
62  ********************************************************************
63  * DESCRIPTION:  Arguments:
64  *      virtBaseAddr: Virtual base address mapped using mmap for IP
65  *       phyBaseAddr: Physical base address for the IP
66  *       phyRegAddr:  Physical register address
67  ********************************************************************/
70 static inline void* NETAPI_GET_REG_VADDR (void *    virtBaseAddr,
71                                           uint32_t  phyBaseAddr,
72                                           uint32_t  phyRegAddr)
73 {
74     return((void *)((uint8_t *)virtBaseAddr + (phyRegAddr - phyBaseAddr)));
75 }
78 /********************************************************************
79  * FUNCTION PURPOSE:  Internal NETAI function ti initialize CPPI. 
80  ********************************************************************
81  * DESCRIPTION:  Internal NETAI function ti initialize CPPI
82  ********************************************************************/
83 int netapip_initCppi(void)
84 {
85     int32_t result, i;
86     Cppi_GlobalConfigParams     netapi_cppiGblCfgParams[CPPI_MAX_CPDMA];
88     for (i=0; i<CPPI_MAX_CPDMA; i++)
89         netapi_cppiGblCfgParams[i] = cppiGblCfgParams[i];
91     /* SRIO CPDMA regs */
92     netapi_cppiGblCfgParams[Cppi_CpDma_SRIO_CPDMA].gblCfgRegs =
93      NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->srioCfgVaddr,
94                         CSL_SRIO_CONFIG_REGS,
95                         (uint32_t)netapi_cppiGblCfgParams[Cppi_CpDma_SRIO_CPDMA].gblCfgRegs);
97     netapi_cppiGblCfgParams[Cppi_CpDma_SRIO_CPDMA].txChRegs =
98      NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->srioCfgVaddr,
99                           CSL_SRIO_CONFIG_REGS,
100                           (uint32_t)netapi_cppiGblCfgParams[Cppi_CpDma_SRIO_CPDMA].txChRegs);
102     netapi_cppiGblCfgParams[Cppi_CpDma_SRIO_CPDMA].rxChRegs =
103      NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->srioCfgVaddr,
104                           CSL_SRIO_CONFIG_REGS,
105                           (uint32_t)netapi_cppiGblCfgParams[Cppi_CpDma_SRIO_CPDMA].rxChRegs);
107     netapi_cppiGblCfgParams[Cppi_CpDma_SRIO_CPDMA].txSchedRegs =
108      NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->srioCfgVaddr,
109                           CSL_SRIO_CONFIG_REGS,
110                           (uint32_t)netapi_cppiGblCfgParams[Cppi_CpDma_SRIO_CPDMA].txSchedRegs);
112    netapi_cppiGblCfgParams[Cppi_CpDma_SRIO_CPDMA].rxFlowRegs =
113      NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->srioCfgVaddr,
114                           CSL_SRIO_CONFIG_REGS,
115                           (uint32_t)netapi_cppiGblCfgParams[Cppi_CpDma_SRIO_CPDMA].rxFlowRegs);
117     /* PASS CPDMA regs */
118     netapi_cppiGblCfgParams[Cppi_CpDma_PASS_CPDMA].gblCfgRegs =
119       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->passCfgVaddr,
120                            CSL_PA_SS_CFG_REGS,
121                            (uint32_t)netapi_cppiGblCfgParams[Cppi_CpDma_PASS_CPDMA].gblCfgRegs);
123     netapi_cppiGblCfgParams[Cppi_CpDma_PASS_CPDMA].txChRegs =
124       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->passCfgVaddr,
125                            CSL_PA_SS_CFG_REGS,
126                            (uint32_t)netapi_cppiGblCfgParams[Cppi_CpDma_PASS_CPDMA].txChRegs);
128     netapi_cppiGblCfgParams[Cppi_CpDma_PASS_CPDMA].rxChRegs =
129       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->passCfgVaddr,
130                            CSL_PA_SS_CFG_REGS,
131                            (uint32_t)netapi_cppiGblCfgParams[Cppi_CpDma_PASS_CPDMA].rxChRegs);
133     netapi_cppiGblCfgParams[Cppi_CpDma_PASS_CPDMA].txSchedRegs =
134       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->passCfgVaddr,
135                            CSL_PA_SS_CFG_REGS,
136                            (uint32_t)netapi_cppiGblCfgParams[Cppi_CpDma_PASS_CPDMA].txSchedRegs);
138     netapi_cppiGblCfgParams[Cppi_CpDma_PASS_CPDMA].rxFlowRegs =
139       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->passCfgVaddr,
140                            CSL_PA_SS_CFG_REGS,
141                            (uint32_t)netapi_cppiGblCfgParams[Cppi_CpDma_PASS_CPDMA].rxFlowRegs);
143    /* QMSS CPDMA regs */
144     netapi_cppiGblCfgParams[Cppi_CpDma_QMSS_CPDMA].gblCfgRegs =
145       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
146                            QMSS_CFG_BASE_ADDR,
147                            (uint32_t)netapi_cppiGblCfgParams[Cppi_CpDma_QMSS_CPDMA].gblCfgRegs);
149     netapi_cppiGblCfgParams[Cppi_CpDma_QMSS_CPDMA].txChRegs =
150       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
151                            QMSS_CFG_BASE_ADDR,
152                            (uint32_t)netapi_cppiGblCfgParams[Cppi_CpDma_QMSS_CPDMA].txChRegs);
154     netapi_cppiGblCfgParams[Cppi_CpDma_QMSS_CPDMA].rxChRegs =
155       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
156                            QMSS_CFG_BASE_ADDR,
157                            (uint32_t)netapi_cppiGblCfgParams[Cppi_CpDma_QMSS_CPDMA].rxChRegs);
159     netapi_cppiGblCfgParams[Cppi_CpDma_QMSS_CPDMA].txSchedRegs =
160       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
161                            QMSS_CFG_BASE_ADDR,
162                            (uint32_t)netapi_cppiGblCfgParams[Cppi_CpDma_QMSS_CPDMA].txSchedRegs);
164     netapi_cppiGblCfgParams[Cppi_CpDma_QMSS_CPDMA].rxFlowRegs =
165       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
166                            QMSS_CFG_BASE_ADDR,
167                            (uint32_t)netapi_cppiGblCfgParams[Cppi_CpDma_QMSS_CPDMA].rxFlowRegs);
169     result = Cppi_init (netapi_cppiGblCfgParams);
170     if (result != CPPI_SOK)
171     {
172       netapi_Log (">function cppi_init: Cppi_init failed with error code %d\n", result);
173       return (-1);
174     }
175      return 1;
178 /********************************************************************
179  * FUNCTION PURPOSE:  Internal NETAI function ti initialize QM. 
180  ********************************************************************
181  * DESCRIPTION:  Internal NETAI function ti initialize QM (once per SOC)
182  ********************************************************************/
183 int netapip_initQm(int max_descriptors)
185     Qmss_InitCfg     qmssInitConfig;
186     int32_t          result;
187     Qmss_GlobalConfigParams netapi_qmssGblCfgParams;
189     memset (&qmssInitConfig, 0, sizeof (Qmss_InitCfg));
191     /* Use Internal Linking RAM for optimal performance */
192     qmssInitConfig.linkingRAM0Base = 0;
193     qmssInitConfig.linkingRAM0Size = 0;
194     qmssInitConfig.linkingRAM1Base = 0;
195     qmssInitConfig.maxDescNum      = max_descriptors;
196     qmssInitConfig.qmssHwStatus =QMSS_HW_INIT_COMPLETE; //bypass some of the hw init
197     netapi_qmssGblCfgParams = qmssGblCfgParams[0];
199     netapi_qmssGblCfgParams.qmConfigReg =
200       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
201                            QMSS_CFG_BASE_ADDR,
202                            (uint32_t)netapi_qmssGblCfgParams.qmConfigReg);
204     netapi_qmssGblCfgParams.qmDescReg =
205       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
206                            QMSS_CFG_BASE_ADDR,
207                            (uint32_t)netapi_qmssGblCfgParams.qmDescReg);
209     netapi_qmssGblCfgParams.qmQueMgmtReg =
210       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
211                            QMSS_CFG_BASE_ADDR,
212                            (uint32_t)netapi_qmssGblCfgParams.qmQueMgmtReg);
214     netapi_qmssGblCfgParams.qmQueMgmtProxyReg =
215       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
216                            QMSS_CFG_BASE_ADDR,
217                            (uint32_t)netapi_qmssGblCfgParams.qmQueMgmtProxyReg);
219     netapi_qmssGblCfgParams.qmQueStatReg =
220       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
221                            QMSS_CFG_BASE_ADDR,
222                            (uint32_t)netapi_qmssGblCfgParams.qmQueStatReg);
224     netapi_qmssGblCfgParams.qmQueIntdReg =
225       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
226                            QMSS_CFG_BASE_ADDR,
227                            (uint32_t)netapi_qmssGblCfgParams.qmQueIntdReg);
229     netapi_qmssGblCfgParams.qmPdspCmdReg[0] =
230       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
231                            QMSS_CFG_BASE_ADDR,
232                            (uint32_t)netapi_qmssGblCfgParams.qmPdspCmdReg[0]);
234     netapi_qmssGblCfgParams.qmPdspCmdReg[1] =
235       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
236                            QMSS_CFG_BASE_ADDR,
237                            (uint32_t)netapi_qmssGblCfgParams.qmPdspCmdReg[1]);
239     netapi_qmssGblCfgParams.qmPdspCtrlReg[0] =
240       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
241                            QMSS_CFG_BASE_ADDR,
242                            (uint32_t)netapi_qmssGblCfgParams.qmPdspCtrlReg[0]);
244     netapi_qmssGblCfgParams.qmPdspCtrlReg[1] =
245       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
246                            QMSS_CFG_BASE_ADDR,
247                            (uint32_t)netapi_qmssGblCfgParams.qmPdspCtrlReg[1]);
249     netapi_qmssGblCfgParams.qmPdspIRamReg[0] =
250       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
251                            QMSS_CFG_BASE_ADDR,
252                            (uint32_t)netapi_qmssGblCfgParams.qmPdspIRamReg[0]);
254     netapi_qmssGblCfgParams.qmPdspIRamReg[1] =
255       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
256                            QMSS_CFG_BASE_ADDR,
257                            (uint32_t)netapi_qmssGblCfgParams.qmPdspIRamReg[1]);
259     netapi_qmssGblCfgParams.qmStatusRAM =
260       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
261                            QMSS_CFG_BASE_ADDR,
262                            (uint32_t)netapi_qmssGblCfgParams.qmStatusRAM);
264     netapi_qmssGblCfgParams.qmLinkingRAMReg =
265       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
266                            QMSS_CFG_BASE_ADDR,
267                            (uint32_t)netapi_qmssGblCfgParams.qmLinkingRAMReg);
269     netapi_qmssGblCfgParams.qmMcDMAReg =
270       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
271                            QMSS_CFG_BASE_ADDR,
272                            (uint32_t)netapi_qmssGblCfgParams.qmMcDMAReg);
274     netapi_qmssGblCfgParams.qmTimer16Reg[0] =
275       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
276                            QMSS_CFG_BASE_ADDR,
277                            (uint32_t)netapi_qmssGblCfgParams.qmTimer16Reg[0]);
279     netapi_qmssGblCfgParams.qmTimer16Reg[1] =
280       NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
281                            QMSS_CFG_BASE_ADDR,
282                            (uint32_t)netapi_qmssGblCfgParams.qmTimer16Reg[1]);
284     netapi_qmssGblCfgParams.qmQueMgmtDataReg = 
285                                                       (void *)((uint32_t)netapi_VM_VirtAddr->qmssDataVaddr);
288     netapi_qmssGblCfgParams.qmQueMgmtProxyDataReg = NULL;
289     result = Qmss_init (&qmssInitConfig, &netapi_qmssGblCfgParams);
290     if (result != QMSS_SOK)  {
291         netapi_Log (">function init_qm: qmss_Init failed with error code %d\n", result);
292         return (nwal_FALSE);
293     }
294     return 1;