1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59#include "IxOsal.h"
60#include "IxQMgr.h"
61#include "IxQMgrAqmIf_p.h"
62#include "IxQMgrQCfg_p.h"
63#include "IxQMgrDefines_p.h"
64
65
66
67
68
69#define IX_QMGR_MIN_ENTRY_SIZE_IN_WORDS 16
70
71
72#define IX_QMGR_AQM_SRAM_SIZE_IN_BYTES 0x4000
73
74
75
76
77
78#define IX_QMGR_QID_IS_VALID(qId) \
79(((qId) >= (IX_QMGR_MIN_QID)) && ((qId) <= (IX_QMGR_MAX_QID)))
80
81
82
83
84
85
86
87
88
89
90
91
92typedef struct
93{
94 char qName[IX_QMGR_MAX_QNAME_LEN+1];
95 IxQMgrQSizeInWords qSizeInWords;
96 IxQMgrQEntrySizeInWords qEntrySizeInWords;
97 BOOL isConfigured;
98
99
100} IxQMgrCfgQ;
101
102
103
104
105
106
107extern UINT32 * ixQMgrAqmIfQueAccRegAddr[];
108
109
110
111IxQMgrQInlinedReadWriteInfo ixQMgrQInlinedReadWriteInfo[IX_QMGR_MAX_NUM_QUEUES];
112
113static IxQMgrCfgQ cfgQueueInfo[IX_QMGR_MAX_NUM_QUEUES];
114
115
116
117
118static UINT32 freeSramAddress=0;
119
120
121static UINT32 zeroedPlaceHolder[4] = { 0, 0, 0, 0 };
122
123static BOOL cfgInitialized = FALSE;
124
125static IxOsalMutex ixQMgrQCfgMutex;
126
127
128
129
130static IxQMgrQCfgStats stats;
131
132
133
134
135PRIVATE BOOL
136watermarkLevelIsOk (IxQMgrQId qId, IxQMgrWMLevel level);
137
138PRIVATE BOOL
139qSizeInWordsIsOk (IxQMgrQSizeInWords qSize);
140
141PRIVATE BOOL
142qEntrySizeInWordsIsOk (IxQMgrQEntrySizeInWords entrySize);
143
144
145
146
147void
148ixQMgrQCfgInit (void)
149{
150 int loopIndex;
151
152 for (loopIndex=0; loopIndex < IX_QMGR_MAX_NUM_QUEUES;loopIndex++)
153 {
154
155 ixQMgrAqmIfQueAccRegAddr[loopIndex] = zeroedPlaceHolder;
156
157
158 ixQMgrQInlinedReadWriteInfo[loopIndex].qReadCount = 0;
159 ixQMgrQInlinedReadWriteInfo[loopIndex].qWriteCount = 0;
160 ixQMgrQInlinedReadWriteInfo[loopIndex].qAccRegAddr = zeroedPlaceHolder;
161 ixQMgrQInlinedReadWriteInfo[loopIndex].qUOStatRegAddr = zeroedPlaceHolder;
162 ixQMgrQInlinedReadWriteInfo[loopIndex].qUflowStatBitMask = 0;
163 ixQMgrQInlinedReadWriteInfo[loopIndex].qOflowStatBitMask = 0;
164 ixQMgrQInlinedReadWriteInfo[loopIndex].qEntrySizeInWords = 0;
165 ixQMgrQInlinedReadWriteInfo[loopIndex].qSizeInEntries = 0;
166 ixQMgrQInlinedReadWriteInfo[loopIndex].qConfigRegAddr = zeroedPlaceHolder;
167 }
168
169
170 ixQMgrAqmIfInit ();
171
172
173
174
175 for (loopIndex=0; loopIndex < IX_QMGR_MAX_NUM_QUEUES;loopIndex++)
176 {
177 strcpy (cfgQueueInfo[loopIndex].qName, "");
178 cfgQueueInfo[loopIndex].qSizeInWords = 0;
179 cfgQueueInfo[loopIndex].qEntrySizeInWords = 0;
180 cfgQueueInfo[loopIndex].isConfigured = FALSE;
181
182
183 stats.qStats[loopIndex].isConfigured = FALSE;
184 stats.qStats[loopIndex].qName = cfgQueueInfo[loopIndex].qName;
185 }
186
187
188 stats.wmSetCnt = 0;
189
190 ixQMgrAqmIfSramBaseAddressGet (&freeSramAddress);
191
192 ixOsalMutexInit(&ixQMgrQCfgMutex);
193
194 cfgInitialized = TRUE;
195}
196
197void
198ixQMgrQCfgUninit (void)
199{
200 cfgInitialized = FALSE;
201
202
203 ixQMgrAqmIfUninit ();
204}
205
206IX_STATUS
207ixQMgrQConfig (char *qName,
208 IxQMgrQId qId,
209 IxQMgrQSizeInWords qSizeInWords,
210 IxQMgrQEntrySizeInWords qEntrySizeInWords)
211{
212 UINT32 aqmLocalBaseAddress;
213
214 if (!cfgInitialized)
215 {
216 return IX_FAIL;
217 }
218
219 if (!IX_QMGR_QID_IS_VALID(qId))
220 {
221 return IX_QMGR_INVALID_Q_ID;
222 }
223
224 else if (NULL == qName)
225 {
226 return IX_QMGR_PARAMETER_ERROR;
227 }
228
229 else if (strlen (qName) > IX_QMGR_MAX_QNAME_LEN)
230 {
231 return IX_QMGR_PARAMETER_ERROR;
232 }
233
234 else if (!qSizeInWordsIsOk (qSizeInWords))
235 {
236 return IX_QMGR_INVALID_QSIZE;
237 }
238
239 else if (!qEntrySizeInWordsIsOk (qEntrySizeInWords))
240 {
241 return IX_QMGR_INVALID_Q_ENTRY_SIZE;
242 }
243
244 else if (cfgQueueInfo[qId].isConfigured)
245 {
246 return IX_QMGR_Q_ALREADY_CONFIGURED;
247 }
248
249 ixOsalMutexLock(&ixQMgrQCfgMutex, IX_OSAL_WAIT_FOREVER);
250
251
252 ixQMgrAqmIfQueCfgWrite (qId,
253 qSizeInWords,
254 qEntrySizeInWords,
255 freeSramAddress);
256
257
258 strcpy (cfgQueueInfo[qId].qName, qName);
259 cfgQueueInfo[qId].qSizeInWords = qSizeInWords;
260 cfgQueueInfo[qId].qEntrySizeInWords = qEntrySizeInWords;
261
262
263
264
265
266 ixQMgrQInlinedReadWriteInfo[qId].qReadCount = 0;
267 ixQMgrQInlinedReadWriteInfo[qId].qWriteCount = 0;
268 ixQMgrQInlinedReadWriteInfo[qId].qEntrySizeInWords = qEntrySizeInWords;
269 ixQMgrQInlinedReadWriteInfo[qId].qSizeInEntries =
270 (UINT32)qSizeInWords / (UINT32)qEntrySizeInWords;
271
272
273
274
275 freeSramAddress += (qSizeInWords * IX_QMGR_NUM_BYTES_PER_WORD);
276
277
278 ixQMgrAqmIfBaseAddressGet (&aqmLocalBaseAddress);
279
280 IX_OSAL_ASSERT((freeSramAddress - (aqmLocalBaseAddress + (IX_QMGR_QUEBUFFER_SPACE_OFFSET))) <=
281 IX_QMGR_QUE_BUFFER_SPACE_SIZE);
282
283
284 cfgQueueInfo[qId].isConfigured = TRUE;
285
286 ixOsalMutexUnlock(&ixQMgrQCfgMutex);
287
288#ifndef NDEBUG
289
290 stats.qStats[qId].isConfigured = TRUE;
291 stats.qStats[qId].qName = cfgQueueInfo[qId].qName;
292#endif
293 return IX_SUCCESS;
294}
295
296IxQMgrQSizeInWords
297ixQMgrQSizeInWordsGet (IxQMgrQId qId)
298{
299
300 return (cfgQueueInfo[qId].qSizeInWords);
301}
302
303IX_STATUS
304ixQMgrQSizeInEntriesGet (IxQMgrQId qId,
305 unsigned *qSizeInEntries)
306{
307 if (!ixQMgrQIsConfigured(qId))
308 {
309 return IX_QMGR_Q_NOT_CONFIGURED;
310 }
311
312 if(NULL == qSizeInEntries)
313 {
314 return IX_QMGR_PARAMETER_ERROR;
315 }
316
317 *qSizeInEntries = (UINT32)(cfgQueueInfo[qId].qSizeInWords) /
318 (UINT32)cfgQueueInfo[qId].qEntrySizeInWords;
319
320 return IX_SUCCESS;
321}
322
323IxQMgrQEntrySizeInWords
324ixQMgrQEntrySizeInWordsGet (IxQMgrQId qId)
325{
326
327 return (cfgQueueInfo[qId].qEntrySizeInWords);
328}
329
330IX_STATUS
331ixQMgrWatermarkSet (IxQMgrQId qId,
332 IxQMgrWMLevel ne,
333 IxQMgrWMLevel nf)
334{
335 IxQMgrQStatus qStatusOnEntry;
336 IxQMgrQStatus qStatusOnExit;
337
338 if (!ixQMgrQIsConfigured(qId))
339 {
340 return IX_QMGR_Q_NOT_CONFIGURED;
341 }
342
343 if (!watermarkLevelIsOk (qId, ne))
344 {
345 return IX_QMGR_INVALID_Q_WM;
346 }
347
348 if (!watermarkLevelIsOk (qId, nf))
349 {
350 return IX_QMGR_INVALID_Q_WM;
351 }
352
353
354 ixQMgrAqmIfQueStatRead (qId, &qStatusOnEntry);
355
356#ifndef NDEBUG
357
358 stats.wmSetCnt++;
359#endif
360
361 ixQMgrAqmIfWatermarkSet (qId,
362 ne,
363 nf);
364
365
366 ixQMgrAqmIfQueStatRead (qId, &qStatusOnExit);
367
368
369 if (qStatusOnEntry != qStatusOnExit)
370 {
371 return IX_QMGR_WARNING;
372 }
373
374 return IX_SUCCESS;
375}
376
377IX_STATUS
378ixQMgrAvailableSramAddressGet (UINT32 *address,
379 unsigned *sizeOfFreeRam)
380{
381 UINT32 aqmLocalBaseAddress;
382
383 if ((NULL == address)||(NULL == sizeOfFreeRam))
384 {
385 return IX_QMGR_PARAMETER_ERROR;
386 }
387 if (!cfgInitialized)
388 {
389 return IX_FAIL;
390 }
391
392 *address = freeSramAddress;
393
394
395 ixQMgrAqmIfBaseAddressGet (&aqmLocalBaseAddress);
396
397
398
399
400
401
402 *sizeOfFreeRam =
403 (aqmLocalBaseAddress +
404 IX_QMGR_AQM_SRAM_SIZE_IN_BYTES) -
405 freeSramAddress;
406
407 if (0 == *sizeOfFreeRam)
408 {
409 return IX_QMGR_NO_AVAILABLE_SRAM;
410 }
411
412 return IX_SUCCESS;
413}
414
415BOOL
416ixQMgrQIsConfigured (IxQMgrQId qId)
417{
418 if (!IX_QMGR_QID_IS_VALID(qId))
419 {
420 return FALSE;
421 }
422
423 return cfgQueueInfo[qId].isConfigured;
424}
425
426IxQMgrQCfgStats*
427ixQMgrQCfgStatsGet (void)
428{
429 return &stats;
430}
431
432IxQMgrQCfgStats*
433ixQMgrQCfgQStatsGet (IxQMgrQId qId)
434{
435 unsigned int ne;
436 unsigned int nf;
437 UINT32 baseAddress;
438 UINT32 readPtr;
439 UINT32 writePtr;
440
441 stats.qStats[qId].qSizeInWords = cfgQueueInfo[qId].qSizeInWords;
442 stats.qStats[qId].qEntrySizeInWords = cfgQueueInfo[qId].qEntrySizeInWords;
443
444 if (IX_SUCCESS != ixQMgrQNumEntriesGet (qId, &stats.qStats[qId].numEntries))
445 {
446 if (IX_QMGR_WARNING != ixQMgrQNumEntriesGet (qId, &stats.qStats[qId].numEntries))
447 {
448 IX_QMGR_LOG_WARNING1("Failed to get the number of entries in queue.... %d\n", qId);
449 }
450 }
451
452 ixQMgrAqmIfQueCfgRead (qId,
453 stats.qStats[qId].numEntries,
454 &baseAddress,
455 &ne,
456 &nf,
457 &readPtr,
458 &writePtr);
459
460 stats.qStats[qId].baseAddress = baseAddress;
461 stats.qStats[qId].ne = ne;
462 stats.qStats[qId].nf = nf;
463 stats.qStats[qId].readPtr = readPtr;
464 stats.qStats[qId].writePtr = writePtr;
465
466 return &stats;
467}
468
469
470
471
472
473PRIVATE BOOL
474watermarkLevelIsOk (IxQMgrQId qId, IxQMgrWMLevel level)
475{
476 unsigned qSizeInEntries;
477
478 switch (level)
479 {
480 case IX_QMGR_Q_WM_LEVEL0:
481 case IX_QMGR_Q_WM_LEVEL1:
482 case IX_QMGR_Q_WM_LEVEL2:
483 case IX_QMGR_Q_WM_LEVEL4:
484 case IX_QMGR_Q_WM_LEVEL8:
485 case IX_QMGR_Q_WM_LEVEL16:
486 case IX_QMGR_Q_WM_LEVEL32:
487 case IX_QMGR_Q_WM_LEVEL64:
488 break;
489 default:
490 return FALSE;
491 }
492
493
494 ixQMgrQSizeInEntriesGet(qId, &qSizeInEntries);
495
496 if ((unsigned)level > qSizeInEntries)
497 {
498 return FALSE;
499 }
500
501 return TRUE;
502}
503
504PRIVATE BOOL
505qSizeInWordsIsOk (IxQMgrQSizeInWords qSize)
506{
507 BOOL status;
508
509 switch (qSize)
510 {
511 case IX_QMGR_Q_SIZE16:
512 case IX_QMGR_Q_SIZE32:
513 case IX_QMGR_Q_SIZE64:
514 case IX_QMGR_Q_SIZE128:
515 status = TRUE;
516 break;
517 default:
518 status = FALSE;
519 break;
520 }
521
522 return status;
523}
524
525PRIVATE BOOL
526qEntrySizeInWordsIsOk (IxQMgrQEntrySizeInWords entrySize)
527{
528 BOOL status;
529
530 switch (entrySize)
531 {
532 case IX_QMGR_Q_ENTRY_SIZE1:
533 case IX_QMGR_Q_ENTRY_SIZE2:
534 case IX_QMGR_Q_ENTRY_SIZE4:
535 status = TRUE;
536 break;
537 default:
538 status = FALSE;
539 break;
540 }
541
542 return status;
543}
544