Added code for MAC-PHY interface, DU_APP, F1AP, SCTP and CU stub
[o-du/l2.git] / src / mt / ss_drvr.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18 \f
19 /********************************************************************20**
20  
21      Name:     System Services -- Driver
22  
23      Type:     C source file
24  
25      Desc:     Source code for those functions in System Services
26                that exist for driver support.
27  
28      File:     ss_drvr.c
29  
30 *********************************************************************21*/
31
32
33 \f
34 /* header include files (.h) */
35
36 #include "envopt.h"        /* environment options */
37 #include "envdep.h"        /* environment dependent */
38 #include "envind.h"        /* environment independent */
39   
40 #include "gen.h"           /* general layer */
41 #include "ssi.h"           /* system services */
42
43 #include "ss_err.h"        /* errors */
44 #include "ss_dep.h"        /* implementation-specific */
45 #include "ss_queue.h"      /* queues */
46 #include "ss_msg.h"        /* messaging */
47 #include "ss_mem.h"        /* memory management interface */
48 #include "ss_gen.h"        /* general */
49 #include "cm_mem.h"        /* memory management */
50
51
52
53 /* header/extern include files (.x) */
54
55 #include "gen.x"           /* general layer */
56 #include "ssi.x"           /* system services */
57
58
59 #include "ss_dep.x"        /* implementation-specific */
60 #include "ss_queue.x"      /* queues */
61 #include "ss_task.x"       /* tasking */
62 #include "ss_timer.x"      /* timers */
63 #include "ss_strm.x"       /* STREAMS */
64 #include "ss_msg.x"        /* messaging */
65 #include "ss_mem.x"        /* memory management interface */
66 #include "ss_drvr.x"       /* driver tasks */
67 #ifdef SS_LOCKLESS_MEMORY
68 #include "cm_llist.x"
69 #include "cm_hash.x"
70 #include "cm_mem_wl.x"        /* common memory manager */
71 #else
72 #include "cm_mem.x"        /* common memory manager */
73 #endif /* SS_LOCKLESS_MEMORY */
74 #include "ss_gen.x"        /* general */
75
76
77 #ifdef SS_DRVR_SUPPORT
78
79
80 \f
81 /*
82 *
83 *       Fun:   SRegDrvrTsk
84 *
85 *       Desc:  This function is used to register a driver task.
86 *
87 *       Ret:   ROK      - ok
88 *              RFAILED  - failed, general (optional)
89 *              ROUTRES  - failed, out of resources (optional)
90 *
91 *       Notes:
92 *
93 *       File:  ss_drvr.c
94 *
95 */
96 #ifdef ANSI
97 PUBLIC S16 SRegDrvrTsk
98 (
99 Inst channel,                   /* channel instance */
100 ProcId low,                     /* processor ID -- low */
101 ProcId high,                    /* processor ID -- high */
102 ActvTsk actvTsk,                /* activation function */
103 ISTsk isTsk                     /* interrupt service function */
104 )
105 #else
106 PUBLIC S16 SRegDrvrTsk(channel, low, high, actvTsk, isTsk)
107 Inst channel;                   /* channel instance */
108 ProcId low;                     /* processor ID -- low */
109 ProcId high;                    /* processor ID -- high */
110 ActvTsk actvTsk;                /* activation function */
111 ISTsk isTsk;                    /* interrupt service function */
112 #endif
113 {
114    S16 ret;
115 #if (ERRCLASS & ERRCLS_INT_PAR)
116
117 /* ss029.103: modification: multiple procId related changes */ 
118 #ifndef SS_MULTIPLE_PROCS
119    ProcId thisProcId;
120 #endif
121
122 /* ss029.103: modification: multiple procId related changes */ 
123 #ifdef SS_MULTIPLE_PROCS
124    U16 count;
125    U16 i;
126    ProcId procIdLst[SS_MAX_PROCS];
127 #endif /* SS_MULTIPLE_PROCS */
128
129 #endif
130
131    TRC1(SRegDrvrTsk);
132
133 #if (ERRCLASS & ERRCLS_INT_PAR)
134
135 /* ss029.103: modification: multiple procId related changes */ 
136 #ifdef SS_MULTIPLE_PROCS
137    if (SGetProcIdLst(&count, procIdLst) != ROK)
138    {
139       SSLOGERROR(ERRCLS_INT_PAR, ESS001, ERRZERO, "Null procId list");
140       RETVALUE(RFAILED);
141    }
142
143    for (i = 0; i < count; i++)
144    {
145       if (procIdLst[i] >= low  &&  procIdLst[i] <= high)
146       {
147        SSLOGERROR(ERRCLS_INT_PAR, ESS002, ERRZERO, "Invalid procId range");
148        RETVALUE(RFAILED);
149       }
150    }
151 #else /* SS_MULTIPLE_PROCS */
152    thisProcId = SFndProcId();
153    if (thisProcId >= low  &&  thisProcId <= high)
154    {
155       SSLOGERROR(ERRCLS_INT_PAR, ESS003, ERRZERO, "Invalid procId range");
156       RETVALUE(RFAILED);
157    }
158 #endif /* SS_MULTIPLE_PROCS */
159
160    if (channel >= SS_MAX_DRVRTSKS)
161    {
162       SSLOGERROR(ERRCLS_INT_PAR, ESS004, channel, "Invalid channel");
163       RETVALUE(RFAILED);
164    }
165
166    /* check activation functions */
167    if (actvTsk == NULLP  ||  isTsk == NULLP)
168    {
169       SSLOGERROR(ERRCLS_INT_PAR, ESS005, ERRZERO, "Null pointer");
170       RETVALUE(RFAILED);
171    }
172
173    /* check if already registered */
174    if (osCp.drvrTskTbl[channel].used == TRUE)
175    {
176       SSLOGERROR(ERRCLS_INT_PAR, ESS006, ERRZERO,
177                   "Driver task already registered");
178       RETVALUE(RFAILED);
179    }
180 #endif
181
182
183 #if (ERRCLASS & ERRCLS_DEBUG)
184    /* check count of tasks */
185    if (osCp.numDrvrTsks == SS_MAX_DRVRTSKS)
186    {
187       SSLOGERROR(ERRCLS_DEBUG, ESS007, ERRZERO, "Too many tasks");
188       RETVALUE(ROUTRES);
189    }
190 #endif
191
192
193    if (SInitLock(&osCp.drvrTskTbl[channel].lock, SS_DRVRENTRY_LOCK) != ROK)
194    {
195
196 #if (ERRCLASS & ERRCLS_DEBUG)
197       SSLOGERROR(ERRCLS_DEBUG, ESS008, ERRZERO, "Could not initialize lock");
198 #endif
199
200       RETVALUE(RFAILED);
201    }
202
203    osCp.drvrTskTbl[channel].channel = channel;
204    osCp.drvrTskTbl[channel].actvTsk = actvTsk;
205    osCp.drvrTskTbl[channel].isTsk = isTsk;
206    osCp.drvrTskTbl[channel].low = low;
207    osCp.drvrTskTbl[channel].high = high;
208
209    ret = ssdRegDrvrTsk(&osCp.drvrTskTbl[channel]);
210    if (ret != ROK)
211    {
212       osCp.drvrTskTbl[channel].channel = 0;
213       osCp.drvrTskTbl[channel].actvTsk = NULLP;
214       osCp.drvrTskTbl[channel].isTsk = NULLP;
215       osCp.drvrTskTbl[channel].low = 0;
216       osCp.drvrTskTbl[channel].high = 0;
217       SDestroyLock(&osCp.drvrTskTbl[channel].lock);
218    }
219    else
220    {
221       osCp.drvrTskTbl[channel].used = TRUE;
222       osCp.numDrvrTsks++;
223    }
224
225
226    RETVALUE(ret);
227 }
228
229 /*  ss001.301: Additions */
230 /*
231 *
232 *       Fun:   SDeregDrvrTsk
233 *
234 *       Desc:  This function is used to de-register a driver task.
235 *
236 *       Ret:   ROK      - ok
237 *              RFAILED  - failed, general (optional)
238 *              ROUTRES  - failed, out of resources (optional)
239 *
240 *       Notes:
241 *
242 *       File:  ss_drvr.c 
243 *
244 */
245 #ifdef ANSI
246 PUBLIC S16 SDeregDrvrTsk
247 (
248 Inst channel                   /* channel instance */
249 )
250 #else
251 PUBLIC S16 SDeregDrvrTsk(channel)
252 Inst channel;
253 #endif
254 {
255         /* ss002.301 Modifications */
256    TRC1(SRegDrvrTsk);
257
258 #if (ERRCLASS & ERRCLS_INT_PAR)
259    if (channel >= SS_MAX_DRVRTSKS)
260    {
261       SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, channel, "Invalid channel");
262       RETVALUE(RFAILED);
263    }
264
265    /* check if already registered */
266    if (osCp.drvrTskTbl[channel].used != TRUE)
267    {
268       SSLOGERROR(ERRCLS_INT_PAR, ESS477, ERRZERO,
269                   "Driver task is not registered");
270       RETVALUE(RFAILED);
271    }
272 #endif
273
274
275    if(SLock(&osCp.drvrTskTbl[channel].lock) != ROK)
276    {
277 #if (ERRCLASS & ERRCLS_DEBUG)
278          SSLOGERROR(ERRCLS_DEBUG, ESS477, ERRZERO,
279                      "Could not lock driver task lock");
280 #endif
281       RETVALUE(RFAILED);
282    }
283    ssdDeregDrvrTsk(&osCp.drvrTskTbl[channel]);
284
285    osCp.drvrTskTbl[channel].channel = 0;
286    osCp.drvrTskTbl[channel].actvTsk = NULLP;
287    osCp.drvrTskTbl[channel].isTsk = NULLP;
288    osCp.drvrTskTbl[channel].low = 0;
289    osCp.drvrTskTbl[channel].high = 0;
290
291    osCp.drvrTskTbl[channel].used = FALSE;
292    osCp.numDrvrTsks--;
293    if(SUnlock(&osCp.drvrTskTbl[channel].lock) != ROK)
294    {
295 #if (ERRCLASS & ERRCLS_DEBUG)
296          SSLOGERROR(ERRCLS_DEBUG, ESS477, ERRZERO,
297                      "Could not unlock driver task lock");
298 #endif
299       RETVALUE(RFAILED);
300    }
301    SDestroyLock(&osCp.drvrTskTbl[channel].lock);
302    /* ss002.301 Modifications */
303    RETVALUE(ROK);
304 }
305 #endif /* SS_DRVR_SUPPORT */
306 /**********************************************************************
307          End of file
308 **********************************************************************/