Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 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 |
Wolfgang Denk | cb3761e | 2013-07-28 22:12:47 +0200 | [diff] [blame^] | 16 | * SPDX-License-Identifier: BSD-3-Clause |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 17 | * @par |
| 18 | * -- End of Copyright Notice -- |
| 19 | */ |
| 20 | |
| 21 | |
| 22 | #include "IxFeatureCtrl.h" |
| 23 | #include "IxEthDB_p.h" |
| 24 | |
| 25 | IX_ETH_DB_PUBLIC |
| 26 | IxEthDBStatus ixEthDBSingleEthNpeCheck(IxEthDBPortId portID) |
| 27 | { |
| 28 | /* If not IXP42X A0 stepping, proceed to check for existence of coprocessors */ |
| 29 | if ((IX_FEATURE_CTRL_SILICON_TYPE_A0 != |
| 30 | (ixFeatureCtrlProductIdRead() & IX_FEATURE_CTRL_SILICON_STEPPING_MASK)) |
| 31 | || (IX_FEATURE_CTRL_DEVICE_TYPE_IXP42X != ixFeatureCtrlDeviceRead ())) |
| 32 | { |
| 33 | if ((portID == 0) && |
| 34 | (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_ETH0) == |
| 35 | IX_FEATURE_CTRL_COMPONENT_DISABLED)) |
| 36 | { |
| 37 | return IX_ETH_DB_FAIL; |
| 38 | } |
| 39 | |
| 40 | if ((portID == 1) && |
| 41 | (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_ETH1) == |
| 42 | IX_FEATURE_CTRL_COMPONENT_DISABLED)) |
| 43 | { |
| 44 | return IX_ETH_DB_FAIL; |
| 45 | } |
| 46 | |
| 47 | if ((portID == 2) && |
| 48 | (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEA_ETH) == |
| 49 | IX_FEATURE_CTRL_COMPONENT_DISABLED)) |
| 50 | { |
| 51 | return IX_ETH_DB_FAIL; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | return IX_ETH_DB_SUCCESS; |
| 56 | } |
| 57 | |
| 58 | IX_ETH_DB_PUBLIC |
| 59 | BOOL ixEthDBCheckSingleBitValue(UINT32 value) |
| 60 | { |
| 61 | #if (CPU != SIMSPARCSOLARIS) && !defined (__wince) |
| 62 | UINT32 shift; |
| 63 | |
| 64 | /* use the count-leading-zeros XScale instruction */ |
| 65 | __asm__ ("clz %0, %1\n" : "=r" (shift) : "r" (value)); |
| 66 | |
| 67 | return ((value << shift) == 0x80000000UL); |
| 68 | |
| 69 | #else |
| 70 | |
| 71 | while (value != 0) |
| 72 | { |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 73 | if (value == 1) return true; |
| 74 | else if ((value & 1) == 1) return false; |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 75 | |
| 76 | value >>= 1; |
| 77 | } |
| 78 | |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 79 | return false; |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 80 | |
| 81 | #endif |
| 82 | } |
| 83 | |
| 84 | const char *mac2string(const unsigned char *mac) |
| 85 | { |
| 86 | static char str[19]; |
| 87 | |
| 88 | if (mac == NULL) |
| 89 | { |
| 90 | return NULL; |
| 91 | } |
| 92 | |
| 93 | sprintf(str, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); |
| 94 | |
| 95 | return str; |
| 96 | } |