source: SVN/cambria/redboot/packages/devs/eth/intel/npe/ethDB/current/src/IxEthDBUtil.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: 5.6 KB
Line 
1/**
2 * @file ethUtil.c
3 *
4 * @brief Utility functions
5 *
6 * @par
7 * IXP400 SW Release version 2.3
8 *
9 * -- Copyright Notice --
10 *
11 * @par
12 * Copyright (c) 2001-2005, Intel Corporation.
13 * All rights reserved.
14 *
15 * @par
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 *    notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 *    notice, this list of conditions and the following disclaimer in the
23 *    documentation and/or other materials provided with the distribution.
24 * 3. Neither the name of the Intel Corporation nor the names of its contributors
25 *    may be used to endorse or promote products derived from this software
26 *    without specific prior written permission.
27 *
28 *
29 * @par
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
31 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * SUCH DAMAGE.
41 *
42 *
43 * @par
44 * -- End of Copyright Notice --
45 */
46
47
48#include "IxFeatureCtrl.h"
49#include "IxEthDB_p.h"
50#include "IxNpeDl.h"
51
52IX_ETH_DB_PUBLIC
53IxEthDBStatus ixEthDBSingleEthNpeCheck(IxEthDBPortId portID)
54{
55    UINT8 functionalityId;
56
57    IxEthNpeNodeId npeId = IX_ETHNPE_PHYSICAL_ID_TO_NODE(portID);
58   
59    if (IX_SUCCESS != ixNpeDlLoadedImageFunctionalityGet(npeId, &functionalityId))
60    {
61        return IX_ETH_DB_FAIL;
62    }
63    else
64    {
65
66        /* If not IXP42X A0 stepping, proceed to check for existence of NPEs and ethernet coprocessors */
67        if ((IX_FEATURE_CTRL_SILICON_TYPE_A0 !=
68            (ixFeatureCtrlProductIdRead() & IX_FEATURE_CTRL_SILICON_STEPPING_MASK))
69            || (IX_FEATURE_CTRL_DEVICE_TYPE_IXP42X != ixFeatureCtrlDeviceRead ()))
70        {
71            switch(npeId)
72            {
73              case IX_NPEDL_NPEID_NPEA:
74                if ((ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEA) ==
75                     IX_FEATURE_CTRL_COMPONENT_DISABLED) ||
76                     ((ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEA_ETH) ==
77#ifndef __ixp43X
78                     IX_FEATURE_CTRL_COMPONENT_DISABLED) ||
79                     (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_ETH0) ==
80#endif
81                     IX_FEATURE_CTRL_COMPONENT_DISABLED)))
82                {
83                    return IX_ETH_DB_FAIL;
84                }
85                break;
86
87              case IX_NPEDL_NPEID_NPEB:
88                if ( (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEB) ==
89                     IX_FEATURE_CTRL_COMPONENT_DISABLED) )
90                {
91                    return IX_ETH_DB_FAIL;
92                }
93                if (portID == 0)
94                {
95                    if( ixFeatureCtrlComponentCheck(IX_FEATURECTRL_ETH0) ==
96                        IX_FEATURE_CTRL_COMPONENT_DISABLED)
97                    {
98                        return IX_ETH_DB_FAIL;
99                    }
100                }
101                else /* ports 1-3 */
102                {
103                    if( ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEB_ETH) ==
104                        IX_FEATURE_CTRL_COMPONENT_DISABLED)
105                    {
106                        return IX_ETH_DB_FAIL;
107                    }
108
109                }
110                break;
111
112              case IX_NPEDL_NPEID_NPEC:
113                if ((ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEC) ==
114                     IX_FEATURE_CTRL_COMPONENT_DISABLED) ||
115                     ((ixFeatureCtrlComponentCheck(IX_FEATURECTRL_ETH1) ==
116#ifndef __ixp43X
117                     IX_FEATURE_CTRL_COMPONENT_DISABLED) ||
118                     (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_ETH0) ==
119#endif
120                     IX_FEATURE_CTRL_COMPONENT_DISABLED)))
121                {
122                    return IX_ETH_DB_FAIL;
123                }
124                break;
125
126              default: /* invalid NPE */
127                return IX_ETH_DB_FAIL;
128            }
129        }
130
131        return IX_ETH_DB_SUCCESS;
132    }
133}
134
135#ifdef _DIAB_TOOL
136__asm volatile void countLeadingZeros (UINT32 shift, UINT32 value)
137{
138%reg shift, value;
139    clz shift, value;
140}
141#endif /* #ifdef _DIAB_TOOL */
142
143
144IX_ETH_DB_PUBLIC
145BOOL ixEthDBCheckSingleBitValue(UINT32 value)
146{
147#if ((CPU!=SIMSPARCSOLARIS) && (CPU!=SIMLINUX) && !defined (__wince))
148    UINT32 shift;
149   
150    /* use the count-leading-zeros XScale instruction */
151#ifdef _DIAB_TOOL
152    countLeadingZeros(shift, value);
153#else
154    __asm__ ("clz %0, %1\n" : "=r" (shift) : "r" (value));
155#endif /* #ifdef _DIAB_TOOL */
156   
157    return ((value << shift) == 0x80000000UL);
158   
159#else
160       
161    while (value != 0)
162    {
163        if (value == 1) return TRUE;
164        else if ((value & 1) == 1) return FALSE;
165
166        value >>= 1;
167    }
168   
169    return FALSE;
170
171#endif
172}
173
174const char *mac2string(const unsigned char *mac)
175{
176  static char str[19];
177 
178  if (mac == NULL)
179  {
180    return NULL;
181  } 
182
183  sprintf(str, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
184
185  return str;
186}
Note: See TracBrowser for help on using the repository browser.