IxEthAcc.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /**
  2. * @file IxEthAcc.c
  3. *
  4. * @author Intel Corporation
  5. * @date 20-Feb-2001
  6. *
  7. * @brief This file contains the implementation of the IXP425 Ethernet Access Component
  8. *
  9. * Design Notes:
  10. *
  11. * @par
  12. * IXP400 SW Release version 2.0
  13. *
  14. * -- Copyright Notice --
  15. *
  16. * @par
  17. * Copyright 2001-2005, Intel Corporation.
  18. * All rights reserved.
  19. *
  20. * @par
  21. * Redistribution and use in source and binary forms, with or without
  22. * modification, are permitted provided that the following conditions
  23. * are met:
  24. * 1. Redistributions of source code must retain the above copyright
  25. * notice, this list of conditions and the following disclaimer.
  26. * 2. Redistributions in binary form must reproduce the above copyright
  27. * notice, this list of conditions and the following disclaimer in the
  28. * documentation and/or other materials provided with the distribution.
  29. * 3. Neither the name of the Intel Corporation nor the names of its contributors
  30. * may be used to endorse or promote products derived from this software
  31. * without specific prior written permission.
  32. *
  33. * @par
  34. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
  35. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  36. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  37. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  38. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  39. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  40. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  41. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  42. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  43. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  44. * SUCH DAMAGE.
  45. *
  46. * @par
  47. * -- End of Copyright Notice --
  48. */
  49. #include "IxEthAcc.h"
  50. #ifdef CONFIG_IXP425_COMPONENT_ETHDB
  51. #include "IxEthDB.h"
  52. #endif
  53. #include "IxFeatureCtrl.h"
  54. #include "IxEthAcc_p.h"
  55. #include "IxEthAccMac_p.h"
  56. #include "IxEthAccMii_p.h"
  57. /**
  58. * @addtogroup IxEthAcc
  59. *@{
  60. */
  61. /**
  62. * @brief System-wide information data strucure.
  63. *
  64. * @ingroup IxEthAccPri
  65. *
  66. */
  67. IxEthAccInfo ixEthAccDataInfo;
  68. extern PUBLIC IxEthAccMacState ixEthAccMacState[];
  69. extern PUBLIC IxOsalMutex ixEthAccControlInterfaceMutex;
  70. /**
  71. * @brief System-wide information
  72. *
  73. * @ingroup IxEthAccPri
  74. *
  75. */
  76. BOOL ixEthAccServiceInit = false;
  77. /* global filtering bit mask */
  78. PUBLIC UINT32 ixEthAccNewSrcMask;
  79. /**
  80. * @brief Per port information data strucure.
  81. *
  82. * @ingroup IxEthAccPri
  83. *
  84. */
  85. IxEthAccPortDataInfo ixEthAccPortData[IX_ETH_ACC_NUMBER_OF_PORTS];
  86. PUBLIC IxEthAccStatus ixEthAccInit()
  87. {
  88. #ifdef CONFIG_IXP425_COMPONENT_ETHDB
  89. /*
  90. * Initialize Control plane
  91. */
  92. if (ixEthDBInit() != IX_ETH_DB_SUCCESS)
  93. {
  94. IX_ETH_ACC_WARNING_LOG("ixEthAccInit: EthDB init failed\n", 0, 0, 0, 0, 0, 0);
  95. return IX_ETH_ACC_FAIL;
  96. }
  97. #endif
  98. if (IX_FEATURE_CTRL_SWCONFIG_ENABLED == ixFeatureCtrlSwConfigurationCheck (IX_FEATURECTRL_ETH_LEARNING))
  99. {
  100. ixEthAccNewSrcMask = (~0); /* want all the bits */
  101. }
  102. else
  103. {
  104. ixEthAccNewSrcMask = (~IX_ETHACC_NE_NEWSRCMASK); /* want all but the NewSrc bit */
  105. }
  106. /*
  107. * Initialize Data plane
  108. */
  109. if ( ixEthAccInitDataPlane() != IX_ETH_ACC_SUCCESS )
  110. {
  111. IX_ETH_ACC_WARNING_LOG("ixEthAccInit: data plane init failed\n", 0, 0, 0, 0, 0, 0);
  112. return IX_ETH_ACC_FAIL;
  113. }
  114. if ( ixEthAccQMgrQueuesConfig() != IX_ETH_ACC_SUCCESS )
  115. {
  116. IX_ETH_ACC_WARNING_LOG("ixEthAccInit: queue config failed\n", 0, 0, 0, 0, 0, 0);
  117. return IX_ETH_ACC_FAIL;
  118. }
  119. /*
  120. * Initialize MII
  121. */
  122. if ( ixEthAccMiiInit() != IX_ETH_ACC_SUCCESS )
  123. {
  124. IX_ETH_ACC_WARNING_LOG("ixEthAccInit: Mii init failed\n", 0, 0, 0, 0, 0, 0);
  125. return IX_ETH_ACC_FAIL;
  126. }
  127. /*
  128. * Initialize MAC I/O memory
  129. */
  130. if (ixEthAccMacMemInit() != IX_ETH_ACC_SUCCESS)
  131. {
  132. IX_ETH_ACC_WARNING_LOG("ixEthAccInit: Mac init failed\n", 0, 0, 0, 0, 0, 0);
  133. return IX_ETH_ACC_FAIL;
  134. }
  135. /*
  136. * Initialize control plane interface lock
  137. */
  138. if (ixOsalMutexInit(&ixEthAccControlInterfaceMutex) != IX_SUCCESS)
  139. {
  140. IX_ETH_ACC_WARNING_LOG("ixEthAccInit: Control plane interface lock initialization failed\n", 0, 0, 0, 0, 0, 0);
  141. return IX_ETH_ACC_FAIL;
  142. }
  143. /* initialiasation is complete */
  144. ixEthAccServiceInit = true;
  145. return IX_ETH_ACC_SUCCESS;
  146. }
  147. PUBLIC void ixEthAccUnload(void)
  148. {
  149. IxEthAccPortId portId;
  150. if ( IX_ETH_ACC_IS_SERVICE_INITIALIZED() )
  151. {
  152. /* check none of the port is still active */
  153. for (portId = 0; portId < IX_ETH_ACC_NUMBER_OF_PORTS; portId++)
  154. {
  155. if ( IX_ETH_IS_PORT_INITIALIZED(portId) )
  156. {
  157. if (ixEthAccMacState[portId].portDisableState == ACTIVE)
  158. {
  159. IX_ETH_ACC_WARNING_LOG("ixEthAccUnload: port %u still active, bail out\n", portId, 0, 0, 0, 0, 0);
  160. return;
  161. }
  162. }
  163. }
  164. /* unmap the memory areas */
  165. ixEthAccMiiUnload();
  166. ixEthAccMacUnload();
  167. /* set all ports as uninitialized */
  168. for (portId = 0; portId < IX_ETH_ACC_NUMBER_OF_PORTS; portId++)
  169. {
  170. ixEthAccPortData[portId].portInitialized = false;
  171. }
  172. /* uninitialize the service */
  173. ixEthAccServiceInit = false;
  174. }
  175. }
  176. PUBLIC IxEthAccStatus ixEthAccPortInit( IxEthAccPortId portId)
  177. {
  178. IxEthAccStatus ret=IX_ETH_ACC_SUCCESS;
  179. if ( ! IX_ETH_ACC_IS_SERVICE_INITIALIZED() )
  180. {
  181. return(IX_ETH_ACC_FAIL);
  182. }
  183. /*
  184. * Check for valid port
  185. */
  186. if ( ! IX_ETH_ACC_IS_PORT_VALID(portId) )
  187. {
  188. return (IX_ETH_ACC_INVALID_PORT);
  189. }
  190. if (IX_ETH_ACC_SUCCESS != ixEthAccSingleEthNpeCheck(portId))
  191. {
  192. IX_ETH_ACC_WARNING_LOG("EthAcc: Unavailable Eth %d: Cannot initialize Eth port.\n",(INT32) portId,0,0,0,0,0);
  193. return IX_ETH_ACC_SUCCESS ;
  194. }
  195. if ( IX_ETH_IS_PORT_INITIALIZED(portId) )
  196. {
  197. /* Already initialized */
  198. return(IX_ETH_ACC_FAIL);
  199. }
  200. if(ixEthAccMacInit(portId)!=IX_ETH_ACC_SUCCESS)
  201. {
  202. return IX_ETH_ACC_FAIL;
  203. }
  204. /*
  205. * Set the port init flag.
  206. */
  207. ixEthAccPortData[portId].portInitialized = true;
  208. #ifdef CONFIG_IXP425_COMPONENT_ETHDB
  209. /* init learning/filtering database structures for this port */
  210. ixEthDBPortInit(portId);
  211. #endif
  212. return(ret);
  213. }