U8, U16, U32 data type changes
[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 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 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    uint16_t count;
125    uint16_t i;
126    ProcId procIdLst[SS_MAX_PROCS];
127 #endif /* SS_MULTIPLE_PROCS */
128
129 #endif
130
131
132 #if (ERRCLASS & ERRCLS_INT_PAR)
133
134 /* ss029.103: modification: multiple procId related changes */ 
135 #ifdef SS_MULTIPLE_PROCS
136    if (SGetProcIdLst(&count, procIdLst) != ROK)
137    {
138       SSLOGERROR(ERRCLS_INT_PAR, ESS001, ERRZERO, "Null procId list");
139       return RFAILED;
140    }
141
142    for (i = 0; i < count; i++)
143    {
144       if (procIdLst[i] >= low  &&  procIdLst[i] <= high)
145       {
146        SSLOGERROR(ERRCLS_INT_PAR, ESS002, ERRZERO, "Invalid procId range");
147        return RFAILED;
148       }
149    }
150 #else /* SS_MULTIPLE_PROCS */
151    thisProcId = SFndProcId();
152    if (thisProcId >= low  &&  thisProcId <= high)
153    {
154       SSLOGERROR(ERRCLS_INT_PAR, ESS003, ERRZERO, "Invalid procId range");
155       return RFAILED;
156    }
157 #endif /* SS_MULTIPLE_PROCS */
158
159    if (channel >= SS_MAX_DRVRTSKS)
160    {
161       SSLOGERROR(ERRCLS_INT_PAR, ESS004, channel, "Invalid channel");
162       return RFAILED;
163    }
164
165    /* check activation functions */
166    if (actvTsk == NULLP  ||  isTsk == NULLP)
167    {
168       SSLOGERROR(ERRCLS_INT_PAR, ESS005, ERRZERO, "Null pointer");
169       return RFAILED;
170    }
171
172    /* check if already registered */
173    if (osCp.drvrTskTbl[channel].used == TRUE)
174    {
175       SSLOGERROR(ERRCLS_INT_PAR, ESS006, ERRZERO,
176                   "Driver task already registered");
177       return RFAILED;
178    }
179 #endif
180
181
182 #if (ERRCLASS & ERRCLS_DEBUG)
183    /* check count of tasks */
184    if (osCp.numDrvrTsks == SS_MAX_DRVRTSKS)
185    {
186       SSLOGERROR(ERRCLS_DEBUG, ESS007, ERRZERO, "Too many tasks");
187       return (ROUTRES);
188    }
189 #endif
190
191
192    if (SInitLock(&osCp.drvrTskTbl[channel].lock, SS_DRVRENTRY_LOCK) != ROK)
193    {
194
195 #if (ERRCLASS & ERRCLS_DEBUG)
196       SSLOGERROR(ERRCLS_DEBUG, ESS008, ERRZERO, "Could not initialize lock");
197 #endif
198
199       return RFAILED;
200    }
201
202    osCp.drvrTskTbl[channel].channel = channel;
203    osCp.drvrTskTbl[channel].actvTsk = actvTsk;
204    osCp.drvrTskTbl[channel].isTsk = isTsk;
205    osCp.drvrTskTbl[channel].low = low;
206    osCp.drvrTskTbl[channel].high = high;
207
208    ret = ssdRegDrvrTsk(&osCp.drvrTskTbl[channel]);
209    if (ret != ROK)
210    {
211       osCp.drvrTskTbl[channel].channel = 0;
212       osCp.drvrTskTbl[channel].actvTsk = NULLP;
213       osCp.drvrTskTbl[channel].isTsk = NULLP;
214       osCp.drvrTskTbl[channel].low = 0;
215       osCp.drvrTskTbl[channel].high = 0;
216       SDestroyLock(&osCp.drvrTskTbl[channel].lock);
217    }
218    else
219    {
220       osCp.drvrTskTbl[channel].used = TRUE;
221       osCp.numDrvrTsks++;
222    }
223
224
225    return (ret);
226 }
227
228 /*  ss001.301: Additions */
229 /*
230 *
231 *       Fun:   SDeregDrvrTsk
232 *
233 *       Desc:  This function is used to de-register a driver task.
234 *
235 *       Ret:   ROK      - ok
236 *              RFAILED  - failed, general (optional)
237 *              ROUTRES  - failed, out of resources (optional)
238 *
239 *       Notes:
240 *
241 *       File:  ss_drvr.c 
242 *
243 */
244 #ifdef ANSI
245 S16 SDeregDrvrTsk
246 (
247 Inst channel                   /* channel instance */
248 )
249 #else
250 S16 SDeregDrvrTsk(channel)
251 Inst channel;
252 #endif
253 {
254         /* ss002.301 Modifications */
255
256 #if (ERRCLASS & ERRCLS_INT_PAR)
257    if (channel >= SS_MAX_DRVRTSKS)
258    {
259       SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, channel, "Invalid channel");
260       return RFAILED;
261    }
262
263    /* check if already registered */
264    if (osCp.drvrTskTbl[channel].used != TRUE)
265    {
266       SSLOGERROR(ERRCLS_INT_PAR, ESS477, ERRZERO,
267                   "Driver task is not registered");
268       return RFAILED;
269    }
270 #endif
271
272
273    if(SLock(&osCp.drvrTskTbl[channel].lock) != ROK)
274    {
275 #if (ERRCLASS & ERRCLS_DEBUG)
276          SSLOGERROR(ERRCLS_DEBUG, ESS477, ERRZERO,
277                      "Could not lock driver task lock");
278 #endif
279       return RFAILED;
280    }
281    ssdDeregDrvrTsk(&osCp.drvrTskTbl[channel]);
282
283    osCp.drvrTskTbl[channel].channel = 0;
284    osCp.drvrTskTbl[channel].actvTsk = NULLP;
285    osCp.drvrTskTbl[channel].isTsk = NULLP;
286    osCp.drvrTskTbl[channel].low = 0;
287    osCp.drvrTskTbl[channel].high = 0;
288
289    osCp.drvrTskTbl[channel].used = FALSE;
290    osCp.numDrvrTsks--;
291    if(SUnlock(&osCp.drvrTskTbl[channel].lock) != ROK)
292    {
293 #if (ERRCLASS & ERRCLS_DEBUG)
294          SSLOGERROR(ERRCLS_DEBUG, ESS477, ERRZERO,
295                      "Could not unlock driver task lock");
296 #endif
297       return RFAILED;
298    }
299    SDestroyLock(&osCp.drvrTskTbl[channel].lock);
300    /* ss002.301 Modifications */
301    return ROK;
302 }
303 #endif /* SS_DRVR_SUPPORT */
304 /**********************************************************************
305          End of file
306 **********************************************************************/