source: SVN/cambria/redboot/packages/devs/eth/intel/npe/common/current/src/IxOsalOsServices.c @ 1

Last change on this file since 1 was 1, checked in by Tim Harvey, 2 years ago

restored latest version of files from server backup

Signed-off-by: Tim Harvey <tharvey@…>

File size: 7.7 KB
Line 
1/**
2 * @file IxOsalOsServices.c (linux)
3 *
4 * @brief Implementation for Irq, Mem, sleep.
5 *
6 *
7 * @par
8 * IXP400 SW Release version 1.5
9 *
10 * -- Intel Copyright Notice --
11 *
12 * @par
13 * Copyright 2002-2004 Intel Corporation All Rights Reserved.
14 *
15 * @par
16 * The source code contained or described herein and all documents
17 * related to the source code ("Material") are owned by Intel Corporation
18 * or its suppliers or licensors.  Title to the Material remains with
19 * Intel Corporation or its suppliers and licensors.
20 *
21 * @par
22 * The Material is protected by worldwide copyright and trade secret laws
23 * and treaty provisions. No part of the Material may be used, copied,
24 * reproduced, modified, published, uploaded, posted, transmitted,
25 * distributed, or disclosed in any way except in accordance with the
26 * applicable license agreement .
27 *
28 * @par
29 * No license under any patent, copyright, trade secret or other
30 * intellectual property right is granted to or conferred upon you by
31 * disclosure or delivery of the Materials, either expressly, by
32 * implication, inducement, estoppel, except in accordance with the
33 * applicable license agreement.
34 *
35 * @par
36 * Unless otherwise agreed by Intel in writing, you may not remove or
37 * alter this notice or any other notice embedded in Materials by Intel
38 * or Intel's suppliers or licensors in any way.
39 *
40 * @par
41 * For further details, please see the file README.TXT distributed with
42 * this software.
43 *
44 * @par
45 * -- End Intel Copyright Notice --
46 */
47
48#include <redboot.h>
49#include "IxOsal.h"
50#include <IxEthAcc.h>
51#include <IxEthDB.h>
52#include <IxNpeDl.h>
53#include <IxQMgr.h>
54#include <IxNpeMh.h>
55
56static char *traceHeaders[] = {
57    "",
58    "[fatal] ",
59    "[error] ",
60    "[warning] ",
61    "[message] ",
62    "[debug1] ",
63    "[debug2] ",
64    "[debug3] ",
65    "[all]"
66};
67
68/* by default trace all but debug message */
69PRIVATE int ixOsalCurrLogLevel = IX_OSAL_LOG_LVL_MESSAGE;
70
71/**************************************
72 * Irq services
73 *************************************/
74
75PUBLIC IX_STATUS
76ixOsalIrqBind (UINT32 vector, IxOsalVoidFnVoidPtr routine, void *parameter)
77{
78    return IX_FAIL;
79}
80
81PUBLIC IX_STATUS
82ixOsalIrqUnbind (UINT32 vector)
83{
84    return IX_FAIL;
85}
86
87PUBLIC UINT32
88ixOsalIrqLock ()
89{
90    int old;
91    HAL_DISABLE_INTERRUPTS(old);
92    return old;
93}
94
95/* Enable interrupts and task scheduling,
96 * input parameter: irqEnable status returned
97 * by ixOsalIrqLock().
98 */
99PUBLIC void
100ixOsalIrqUnlock (UINT32 lockKey)
101{
102    HAL_RESTORE_INTERRUPTS(lockKey)
103}
104
105PUBLIC UINT32
106ixOsalIrqLevelSet (UINT32 level)
107{
108    return IX_FAIL;   
109}
110
111PUBLIC void
112ixOsalIrqEnable (UINT32 irqLevel)
113{
114}
115
116PUBLIC void
117ixOsalIrqDisable (UINT32 irqLevel)
118{
119}
120
121/*********************
122 * Log function
123 *********************/
124
125INT32
126ixOsalLog (IxOsalLogLevel level,
127    IxOsalLogDevice device,
128    char *format, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6)
129{
130    /*
131     * Return -1 for custom display devices
132     */
133    if ((device != IX_OSAL_LOG_DEV_STDOUT)
134        && (device != IX_OSAL_LOG_DEV_STDERR))
135    {
136        diag_printf
137            ("ixOsalLog: only IX_OSAL_LOG_DEV_STDOUT and IX_OSAL_LOG_DEV_STDERR are supported \n");
138        return (IX_OSAL_LOG_ERROR);
139    }
140
141    if (level <= ixOsalCurrLogLevel && level != IX_OSAL_LOG_LVL_NONE)
142    {
143        int headerByteCount =
144            (level ==
145            IX_OSAL_LOG_LVL_USER) ? 0 : diag_printf(traceHeaders[level - 1]);
146
147        return headerByteCount + diag_printf (format, arg1, arg2, arg3, arg4, arg5,
148            arg6);
149    }
150    else
151    {
152        /*
153         * Return error
154         */
155        return (IX_OSAL_LOG_ERROR);
156    }
157}
158
159PUBLIC UINT32
160ixOsalLogLevelSet (UINT32 level)
161{
162    UINT32 oldLevel;
163
164    /*
165     * Check value first
166     */
167    if ((level < IX_OSAL_LOG_LVL_NONE) || (level > IX_OSAL_LOG_LVL_ALL))
168    {
169        ixOsalLog (IX_OSAL_LOG_LVL_MESSAGE,
170            IX_OSAL_LOG_DEV_STDOUT,
171            "ixOsalLogLevelSet: Log Level is between %d and%d \n",
172            IX_OSAL_LOG_LVL_NONE, IX_OSAL_LOG_LVL_ALL, 0, 0, 0, 0);
173        return IX_OSAL_LOG_LVL_NONE;
174    }
175    oldLevel = ixOsalCurrLogLevel;
176
177    ixOsalCurrLogLevel = level;
178
179    return oldLevel;
180}
181
182/**************************************
183 * Task services
184 *************************************/
185
186PUBLIC void
187ixOsalBusySleep (UINT32 microseconds)
188{
189    CYGACC_CALL_IF_DELAY_US(microseconds);
190}
191
192PUBLIC void
193ixOsalSleep (UINT32 milliseconds)
194{
195    if (milliseconds != 0) {
196#ifdef CYGPKG_REDBOOT
197        // We poll while we wait because interrupts are off in RedBoot
198        // and CSR expects messages, etc to be dispatched while sleeping.
199        int i;
200        IxQMgrDispatcherFuncPtr qDispatcherFunc;
201        extern void ixEthAccMacRecoveryPoll(void);
202
203        ixQMgrDispatcherLoopGet(&qDispatcherFunc);
204
205        while (milliseconds--) {
206            for (i = 0; i < IX_ETH_ACC_NUMBER_OF_PORTS; i++)
207                ixNpeMhMessagesReceive(i);
208            (*qDispatcherFunc)(IX_QMGR_QUELOW_GROUP);
209            ixEthAccMacRecoveryPoll();
210            CYGACC_CALL_IF_DELAY_US(1000);
211        }
212#else
213        CYGACC_CALL_IF_DELAY_US(milliseconds * 1000);
214#endif
215    }
216}
217
218/**************************************
219 * Memory functions
220 *************************************/
221
222void *
223ixOsalMemAlloc (UINT32 size)
224{
225    return (void *)0;
226}
227
228void
229ixOsalMemFree (void *ptr)
230{
231}
232
233/*
234 * Copy count bytes from src to dest ,
235 * returns pointer to the dest mem zone.
236 */
237void *
238ixOsalMemCopy (void *dest, void *src, UINT32 count)
239{
240    IX_OSAL_ASSERT (dest != NULL);
241    IX_OSAL_ASSERT (src != NULL);
242    return (memcpy (dest, src, count));
243}
244
245/*
246 * Fills a memory zone with a given constant byte,
247 * returns pointer to the memory zone.
248 */
249void *
250ixOsalMemSet (void *ptr, UINT8 filler, UINT32 count)
251{
252    IX_OSAL_ASSERT (ptr != NULL);
253    return (memset (ptr, filler, count));
254}
255
256/*****************************
257 *
258 *  Time
259 *
260 *****************************/
261
262/* Retrieve current system time */
263void
264ixOsalTimeGet (IxOsalTimeval * ptime)
265{
266    /*
267     * linux struct timeval has subfields:
268     * -- time_t   (type long, second)
269     * -- suseconds_t ( type long, usecond)
270     */
271    do_gettimeofday ((struct timeval *) ptime);
272
273    /*
274     * Translate microsecond to nanosecond,
275     * second field is identical so no translation
276     * there.
277     */
278    ptime->nsecs *= 1000;
279
280}
281
282/* Timestamp is implemented in OEM */
283PUBLIC UINT32
284ixOsalTimestampGet (void)
285{
286    return IX_OSAL_OEM_TIMESTAMP_GET ();
287}
288
289/* OEM-specific implementation */
290PUBLIC UINT32
291ixOsalTimestampResolutionGet (void)
292{
293    return IX_OSAL_OEM_TIMESTAMP_RESOLUTION_GET ();
294}
295
296PUBLIC UINT32
297ixOsalSysClockRateGet (void)
298{
299    diag_printf("%s called\n", __FUNCTION__);
300    return 0;
301}
302
303PUBLIC void
304ixOsalYield (void)
305{
306}
307
308PUBLIC IX_STATUS
309ixOsalOsNameGet (INT8* osName, INT32 maxSize)
310{
311    IX_STATUS status = IX_FAIL;
312
313    /* Ensure that the input parameters are valid */
314    if (osName == NULL || maxSize <= 0)
315    {
316        ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
317                   IX_OSAL_LOG_DEV_STDOUT,
318                   "ixOsalOsNameGet: invalid input parameters\n",
319                   0, 0, 0, 0, 0, 0);
320        return status;
321    }
322
323    status = IX_OSAL_OEM_OS_NAME_GET(osName, maxSize);
324
325    return status;
326}
327
328PUBLIC IX_STATUS
329ixOsalOsVersionGet(INT8* osVersion, INT32 maxSize)
330{
331    IX_STATUS status = IX_FAIL;
332
333    /* Ensure that the input parameters are valid */
334    if (osVersion == NULL || maxSize <= 0)
335    {
336        ixOsalLog (IX_OSAL_LOG_LVL_ERROR,
337                   IX_OSAL_LOG_DEV_STDOUT,
338                   "ixOsalOsVersionGet: invalid input parameters\n",
339                   0, 0, 0, 0, 0, 0);
340        return status;
341    }
342
343    status = IX_OSAL_OEM_OS_VERSION_GET(osVersion, maxSize);
344
345    return status;
346}
347
348unsigned int
349ixQMgrCountLeadingZeros(UINT32 word)
350{
351    unsigned int leadingZerosCount = 0;
352
353    if (word == 0)
354        return 32;
355
356    /* search the first bit set by testing the MSB and shifting the input word */
357    while ((word & 0x80000000) == 0)
358    {
359        word <<= 1;
360        leadingZerosCount++;
361    }
362    return leadingZerosCount;
363}
Note: See TracBrowser for help on using the repository browser.