c5e8467f17ed3427abf95149b94876274fd68154
[keystone-rtos/netapi.git] / ti / runtime / netapi / src / pdkv3 / 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"
57 /********************************************************************
58  * FUNCTION PURPOSE:  Internal NETAPI macro to convert to IP Register
59  *                    Virtual Address from a mapped base Virtual
60  *                    Address.
61  ********************************************************************
62  * DESCRIPTION:  Arguments:
63  *      virtBaseAddr: Virtual base address mapped using mmap for IP
64  *       phyBaseAddr: Physical base address for the IP
65  *       phyRegAddr:  Physical register address
66  ********************************************************************/
67 static inline void* NETAPI_GET_REG_VADDR (void *    virtBaseAddr,
68                                           uint32_t  phyBaseAddr,
69                                           uint32_t  phyRegAddr)
70 {
71     return((void *)((uint8_t *)virtBaseAddr + (phyRegAddr - phyBaseAddr)));
72 }
75 /*****************************************************************************
76  * FUNCTION PURPOSE: Global Initialization of CPPI. Once Per System
77  *****************************************************************************
78  * DESCRIPTION: The function will initialize the CPPI
79  *****************************************************************************/
80 int netapip_initCppi(void)
81 {
83     int32_t                         result;
84     Cppi_GlobalConfigParams         netapi_cppiGblCfgParams;
86     netapi_cppiGblCfgParams = cppiGblCfgParams;
87     /* Convert Physical address to Virtual address for LLD access */
88     /* SRIO CPDMA regs */
89     netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_SRIO_CPDMA].gblCfgRegs =
90         NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->srioCfgVaddr,
91                              CSL_SRIO_CFG_REGS,
92                              (uint32_t)netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_SRIO_CPDMA].gblCfgRegs);
94     netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_SRIO_CPDMA].txChRegs =
95         NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->srioCfgVaddr,
96                              CSL_SRIO_CFG_REGS,
97                              (uint32_t)netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_SRIO_CPDMA].txChRegs);
99     netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_SRIO_CPDMA].rxChRegs =
100         NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->srioCfgVaddr,
101                              CSL_SRIO_CFG_REGS,
102                              (uint32_t)netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_SRIO_CPDMA].rxChRegs);
104     netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_SRIO_CPDMA].txSchedRegs =
105         NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->srioCfgVaddr,
106                              CSL_SRIO_CFG_REGS,
107                              (uint32_t)netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_SRIO_CPDMA].txSchedRegs);
109     netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_SRIO_CPDMA].rxFlowRegs =
110         NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->srioCfgVaddr,
111                              CSL_SRIO_CFG_REGS,
112                              (uint32_t)netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_SRIO_CPDMA].rxFlowRegs);
114     /* PASS CPDMA regs */
115     netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_PASS_CPDMA].gblCfgRegs =
116         NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->passCfgVaddr,
117                              CSL_NETCP_CFG_REGS,
118                              (uint32_t)netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_PASS_CPDMA].gblCfgRegs);
120     netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_PASS_CPDMA].txChRegs =
121         NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->passCfgVaddr,
122                              CSL_NETCP_CFG_REGS,
123                              (uint32_t)netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_PASS_CPDMA].txChRegs);
125     netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_PASS_CPDMA].rxChRegs =
126         NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->passCfgVaddr,
127                              CSL_NETCP_CFG_REGS,
128                              (uint32_t)netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_PASS_CPDMA].rxChRegs);
130     netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_PASS_CPDMA].txSchedRegs =
131         NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->passCfgVaddr,
132                              CSL_NETCP_CFG_REGS,
133                              (uint32_t)netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_PASS_CPDMA].txSchedRegs);
135     netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_PASS_CPDMA].rxFlowRegs =
136         NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->passCfgVaddr,
137                              CSL_NETCP_CFG_REGS,
138                              (uint32_t)netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_PASS_CPDMA].rxFlowRegs);
140     /* QMSS CPDMA regs */
141     netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_QMSS_CPDMA].gblCfgRegs =
142         NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
143                              QMSS_CFG_BASE_ADDR,
144                              (uint32_t)netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_QMSS_CPDMA].gblCfgRegs);
146     netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_QMSS_CPDMA].txChRegs =
147         NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
148                              QMSS_CFG_BASE_ADDR,
149                              (uint32_t)netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_QMSS_CPDMA].txChRegs);
151     netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_QMSS_CPDMA].rxChRegs =
152         NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
153                              QMSS_CFG_BASE_ADDR,
154                              (uint32_t)netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_QMSS_CPDMA].rxChRegs);
156     netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_QMSS_CPDMA].txSchedRegs =
157         NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
158                              QMSS_CFG_BASE_ADDR,
159                              (uint32_t)netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_QMSS_CPDMA].txSchedRegs);
161     netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_QMSS_CPDMA].rxFlowRegs =
162         NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
163                              QMSS_CFG_BASE_ADDR,
164                              (uint32_t)netapi_cppiGblCfgParams.cpDmaCfgs[Cppi_CpDma_QMSS_CPDMA].rxFlowRegs);
165     result = Cppi_init (&netapi_cppiGblCfgParams);
166     if (result != CPPI_SOK)  {
167         netapi_Log ("function testNwGlobCppiInit: Cppi_init failed with error code %d\n", result);
168         return (-1);
169     }
170     return (1);
173 /*****************************************************************************
174  * FUNCTION PURPOSE: Global Initialization of Queue Manager. Once Per System
175  *****************************************************************************
176  * DESCRIPTION: The function will initialize the Queue Manager
177  *****************************************************************************/
178 int netapip_initQm(int max_descriptors)
180     Qmss_InitCfg              qmssInitConfig;
181     int32_t                   result;
182     Qmss_GlobalConfigParams   netapi_qmssGblCfgParams;
183     uint32_t                  count;
185     memset (&qmssInitConfig, 0, sizeof (Qmss_InitCfg));
187     /* Use Internal Linking RAM for optimal performance */
188     qmssInitConfig.linkingRAM0Base = 0;
189     qmssInitConfig.linkingRAM0Size = 0;
190     qmssInitConfig.linkingRAM1Base = 0;
191     qmssInitConfig.maxDescNum      = max_descriptors;
192     qmssInitConfig.qmssHwStatus = QMSS_HW_INIT_COMPLETE;
194     netapi_qmssGblCfgParams = qmssGblCfgParams;
196     /* Convert address to Virtual address */
197     for(count=0;count < netapi_qmssGblCfgParams.maxQueMgrGroups;count++)
198     {
199         netapi_qmssGblCfgParams.groupRegs[count].qmConfigReg =
200             NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
201                                  QMSS_CFG_BASE_ADDR,
202                                  (uint32_t)netapi_qmssGblCfgParams.groupRegs[count].qmConfigReg);
204         netapi_qmssGblCfgParams.groupRegs[count].qmDescReg =
205             NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
206                                  QMSS_CFG_BASE_ADDR,
207                                  (uint32_t)netapi_qmssGblCfgParams.groupRegs[count].qmDescReg);
209         netapi_qmssGblCfgParams.groupRegs[count].qmQueMgmtReg =
210             NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
211                                  QMSS_CFG_BASE_ADDR,
212                                  (uint32_t)netapi_qmssGblCfgParams.groupRegs[count].qmQueMgmtReg);
214         netapi_qmssGblCfgParams.groupRegs[count].qmQueMgmtProxyReg =
215             NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
216                                  QMSS_CFG_BASE_ADDR,
217                                  (uint32_t)netapi_qmssGblCfgParams.groupRegs[count].qmQueMgmtProxyReg);
219         netapi_qmssGblCfgParams.groupRegs[count].qmQueStatReg =
220             NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
221                                  QMSS_CFG_BASE_ADDR,
222                                  (uint32_t)netapi_qmssGblCfgParams.groupRegs[count].qmQueStatReg);
224         netapi_qmssGblCfgParams.groupRegs[count].qmStatusRAM =
225             NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
226                                  QMSS_CFG_BASE_ADDR,
227                                  (uint32_t)netapi_qmssGblCfgParams.groupRegs[count].qmStatusRAM);
229         netapi_qmssGblCfgParams.groupRegs[count].qmQueMgmtDataReg =
230             NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssDataVaddr,
231                                  QMSS_DATA_BASE_ADDR,
232                                  (uint32_t)netapi_qmssGblCfgParams.groupRegs[count].qmQueMgmtDataReg);
234         netapi_qmssGblCfgParams.groupRegs[count].qmQueMgmtProxyDataReg =
235             NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssDataVaddr,
236                                  QMSS_DATA_BASE_ADDR,
237                                  (uint32_t)netapi_qmssGblCfgParams.groupRegs[count].qmQueMgmtProxyDataReg);
238     }
240     for(count=0;count < QMSS_MAX_INTD;count++)
241     {
242         netapi_qmssGblCfgParams.regs.qmQueIntdReg[count] =
243             NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
244                                  QMSS_CFG_BASE_ADDR,
245                                  (uint32_t)netapi_qmssGblCfgParams.regs.qmQueIntdReg[count]);
246     }
248     for(count=0;count < QMSS_MAX_PDSP;count++)
249     {
250         netapi_qmssGblCfgParams.regs.qmPdspCmdReg[count] =
251             NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
252                                  QMSS_CFG_BASE_ADDR,
253                                  (uint32_t)netapi_qmssGblCfgParams.regs.qmPdspCmdReg[count]);
255         netapi_qmssGblCfgParams.regs.qmPdspCtrlReg[count] =
256             NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
257                                  QMSS_CFG_BASE_ADDR,
258                                  (uint32_t)netapi_qmssGblCfgParams.regs.qmPdspCtrlReg[count]);
260         netapi_qmssGblCfgParams.regs.qmPdspIRamReg[count] =
261             NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
262                                  QMSS_CFG_BASE_ADDR,
263                                  (uint32_t)netapi_qmssGblCfgParams.regs.qmPdspIRamReg[count]);
264     }
266     netapi_qmssGblCfgParams.regs.qmLinkingRAMReg =
267         NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
268                              QMSS_CFG_BASE_ADDR,
269                              (uint32_t)netapi_qmssGblCfgParams.regs.qmLinkingRAMReg);
271     netapi_qmssGblCfgParams.regs.qmBaseAddr =
272         NETAPI_GET_REG_VADDR(netapi_VM_VirtAddr->qmssCfgVaddr,
273                              QMSS_CFG_BASE_ADDR,
274                              (uint32_t)netapi_qmssGblCfgParams.regs.qmBaseAddr);
276     result = Qmss_init (&qmssInitConfig, &netapi_qmssGblCfgParams);
277     if (result != QMSS_SOK)
278     {
279         netapi_Log ("function testNwGlobQmInit: qmss_Init failed with error code %d\n", result);
280         return (nwal_FALSE);
281     }
282     return 1;