source: SVN/rincon/u-boot/cpu/ixp/npe/IxEthDBUtil.c @ 55

Last change on this file since 55 was 55, checked in by Tim Harvey, 22 months ago

rincon: added latest u-boot source

restored form server backup

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

File size: 3.5 KB
Line 
1/**
2 * @file ethUtil.c
3 *
4 * @brief Utility functions
5 *
6 * @par
7 * IXP400 SW Release version 2.0
8 *
9 * -- Copyright Notice --
10 *
11 * @par
12 * Copyright 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 * @par
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
30 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * SUCH DAMAGE.
40 *
41 * @par
42 * -- End of Copyright Notice --
43 */
44
45
46#include "IxFeatureCtrl.h"
47#include "IxEthDB_p.h"
48
49IX_ETH_DB_PUBLIC
50IxEthDBStatus ixEthDBSingleEthNpeCheck(IxEthDBPortId portID)
51{
52    /* If not IXP42X A0 stepping, proceed to check for existence of coprocessors */ 
53    if ((IX_FEATURE_CTRL_SILICON_TYPE_A0 != 
54        (ixFeatureCtrlProductIdRead() & IX_FEATURE_CTRL_SILICON_STEPPING_MASK))
55        || (IX_FEATURE_CTRL_DEVICE_TYPE_IXP42X != ixFeatureCtrlDeviceRead ()))
56    { 
57        if ((portID == 0) && 
58            (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_ETH0) ==
59             IX_FEATURE_CTRL_COMPONENT_DISABLED))
60        {
61            return IX_ETH_DB_FAIL;
62        }
63
64        if ((portID == 1) &&
65            (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_ETH1) ==
66             IX_FEATURE_CTRL_COMPONENT_DISABLED))
67        {
68            return IX_ETH_DB_FAIL;         
69        }
70
71        if ((portID == 2) &&
72            (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEA_ETH) ==
73             IX_FEATURE_CTRL_COMPONENT_DISABLED))
74        {
75            return IX_ETH_DB_FAIL;         
76        }
77    }
78   
79    return IX_ETH_DB_SUCCESS;
80}
81
82IX_ETH_DB_PUBLIC
83BOOL ixEthDBCheckSingleBitValue(UINT32 value)
84{
85#if (CPU != SIMSPARCSOLARIS) && !defined (__wince)
86    UINT32 shift;
87   
88    /* use the count-leading-zeros XScale instruction */
89    __asm__ ("clz %0, %1\n" : "=r" (shift) : "r" (value));
90   
91    return ((value << shift) == 0x80000000UL);
92   
93#else
94       
95    while (value != 0)
96    {
97        if (value == 1) return TRUE;
98        else if ((value & 1) == 1) return FALSE;
99
100        value >>= 1;
101    }
102   
103    return FALSE;
104
105#endif
106}
107
108const char *mac2string(const unsigned char *mac)
109{
110  static char str[19];
111 
112  if (mac == NULL)
113  {
114    return NULL;
115  } 
116
117  sprintf(str, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
118
119  return str;
120}
Note: See TracBrowser for help on using the repository browser.