IxEthDBUtil.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. #include "IxFeatureCtrl.h"
  45. #include "IxEthDB_p.h"
  46. IX_ETH_DB_PUBLIC
  47. IxEthDBStatus ixEthDBSingleEthNpeCheck(IxEthDBPortId portID)
  48. {
  49. /* If not IXP42X A0 stepping, proceed to check for existence of coprocessors */
  50. if ((IX_FEATURE_CTRL_SILICON_TYPE_A0 !=
  51. (ixFeatureCtrlProductIdRead() & IX_FEATURE_CTRL_SILICON_STEPPING_MASK))
  52. || (IX_FEATURE_CTRL_DEVICE_TYPE_IXP42X != ixFeatureCtrlDeviceRead ()))
  53. {
  54. if ((portID == 0) &&
  55. (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_ETH0) ==
  56. IX_FEATURE_CTRL_COMPONENT_DISABLED))
  57. {
  58. return IX_ETH_DB_FAIL;
  59. }
  60. if ((portID == 1) &&
  61. (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_ETH1) ==
  62. IX_FEATURE_CTRL_COMPONENT_DISABLED))
  63. {
  64. return IX_ETH_DB_FAIL;
  65. }
  66. if ((portID == 2) &&
  67. (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEA_ETH) ==
  68. IX_FEATURE_CTRL_COMPONENT_DISABLED))
  69. {
  70. return IX_ETH_DB_FAIL;
  71. }
  72. }
  73. return IX_ETH_DB_SUCCESS;
  74. }
  75. IX_ETH_DB_PUBLIC
  76. BOOL ixEthDBCheckSingleBitValue(UINT32 value)
  77. {
  78. #if (CPU != SIMSPARCSOLARIS) && !defined (__wince)
  79. UINT32 shift;
  80. /* use the count-leading-zeros XScale instruction */
  81. __asm__ ("clz %0, %1\n" : "=r" (shift) : "r" (value));
  82. return ((value << shift) == 0x80000000UL);
  83. #else
  84. while (value != 0)
  85. {
  86. if (value == 1) return TRUE;
  87. else if ((value & 1) == 1) return FALSE;
  88. value >>= 1;
  89. }
  90. return FALSE;
  91. #endif
  92. }
  93. const char *mac2string(const unsigned char *mac)
  94. {
  95. static char str[19];
  96. if (mac == NULL)
  97. {
  98. return NULL;
  99. }
  100. sprintf(str, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  101. return str;
  102. }