1 /*
2  * Copyright 2021-2022 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 /**
8  *   @file Netc_EthSwt_Ip.c
9  *   @internal
10  *   @addtogroup NETC_ETHSWT_IP NETC_ETHSWT Driver
11  *   @{
12  */
13 
14 #ifdef __cplusplus
15 extern "C"{
16 #endif
17 
18 /*==================================================================================================
19 *                                          INCLUDE FILES
20 * 1) system and project includes
21 * 2) needed interfaces from external units
22 * 3) internal and external interfaces from this unit
23 ==================================================================================================*/
24 #include "Netc_EthSwt_Ip.h"
25 #include "Netc_EthSwt_Ip_Types.h"
26 #include "Netc_EthSwt_Ip_Cfg_Defines.h"
27 #include "OsIf.h"        /* Used for timeouts. */
28 
29 #if(NETC_ETHSWT_IP_DEV_ERROR_DETECT == STD_ON)
30     #include "Devassert.h"
31 #endif
32 
33 /*==================================================================================================
34 *                                 SOURCE FILE VERSION INFORMATION
35 ==================================================================================================*/
36 #define NETC_ETHSWT_IP_VENDOR_ID_C                      43
37 #define NETC_ETHSWT_IP_AR_RELEASE_MAJOR_VERSION_C       4
38 #define NETC_ETHSWT_IP_AR_RELEASE_MINOR_VERSION_C       7
39 #define NETC_ETHSWT_IP_AR_RELEASE_REVISION_VERSION_C    0
40 #define NETC_ETHSWT_IP_SW_MAJOR_VERSION_C               0
41 #define NETC_ETHSWT_IP_SW_MINOR_VERSION_C               9
42 #define NETC_ETHSWT_IP_SW_PATCH_VERSION_C               0
43 
44 /*==================================================================================================
45 *                                       FILE VERSION CHECKS
46 ==================================================================================================*/
47 /* Checks against Netc_EthSwt_Ip.h */
48 #if (NETC_ETHSWT_IP_VENDOR_ID_C !=  NETC_ETHSWT_IP_VENDOR_ID)
49     #error "Netc_EthSwt_Ip.c and Netc_EthSwt_Ip.h have different vendor ids"
50 #endif
51 #if (( NETC_ETHSWT_IP_AR_RELEASE_MAJOR_VERSION_C    !=  NETC_ETHSWT_IP_AR_RELEASE_MAJOR_VERSION) || \
52      ( NETC_ETHSWT_IP_AR_RELEASE_MINOR_VERSION_C    !=  NETC_ETHSWT_IP_AR_RELEASE_MINOR_VERSION) || \
53      ( NETC_ETHSWT_IP_AR_RELEASE_REVISION_VERSION_C !=  NETC_ETHSWT_IP_AR_RELEASE_REVISION_VERSION))
54      #error "AUTOSAR Version Numbers of Netc_EthSwt_Ip.c and Netc_EthSwt_Ip.h are different"
55 #endif
56 #if (( NETC_ETHSWT_IP_SW_MAJOR_VERSION_C !=  NETC_ETHSWT_IP_SW_MAJOR_VERSION) || \
57      ( NETC_ETHSWT_IP_SW_MINOR_VERSION_C !=  NETC_ETHSWT_IP_SW_MINOR_VERSION) || \
58      ( NETC_ETHSWT_IP_SW_PATCH_VERSION_C !=  NETC_ETHSWT_IP_SW_PATCH_VERSION))
59     #error "Software Version Numbers of Netc_EthSwt_Ip.c and Netc_EthSwt_Ip.h are different"
60 #endif
61 
62 /* Checks against Netc_EthSwt_Ip_Types.h */
63 #if (NETC_ETHSWT_IP_VENDOR_ID_C !=  NETC_ETHSWT_IP_TYPES_VENDOR_ID)
64     #error "Netc_EthSwt_Ip.c and Netc_EthSwt_Ip_Types.h have different vendor ids"
65 #endif
66 #if (( NETC_ETHSWT_IP_AR_RELEASE_MAJOR_VERSION_C    !=  NETC_ETHSWT_IP_TYPES_AR_RELEASE_MAJOR_VERSION) || \
67      ( NETC_ETHSWT_IP_AR_RELEASE_MINOR_VERSION_C    !=  NETC_ETHSWT_IP_TYPES_AR_RELEASE_MINOR_VERSION) || \
68      ( NETC_ETHSWT_IP_AR_RELEASE_REVISION_VERSION_C !=  NETC_ETHSWT_IP_TYPES_AR_RELEASE_REVISION_VERSION))
69      #error "AUTOSAR Version Numbers of Netc_EthSwt_Ip.c and Netc_EthSwt_Ip_Types.h are different"
70 #endif
71 #if (( NETC_ETHSWT_IP_SW_MAJOR_VERSION_C !=  NETC_ETHSWT_IP_TYPES_SW_MAJOR_VERSION) || \
72      ( NETC_ETHSWT_IP_SW_MINOR_VERSION_C !=  NETC_ETHSWT_IP_TYPES_SW_MINOR_VERSION) || \
73      ( NETC_ETHSWT_IP_SW_PATCH_VERSION_C !=  NETC_ETHSWT_IP_TYPES_SW_PATCH_VERSION))
74     #error "Software Version Numbers of Netc_EthSwt_Ip.c and Netc_EthSwt_Ip_Types.h are different"
75 #endif
76 
77 /* Checks against Netc_EthSwt_Ip_Cfg_Defines.h */
78 #if (NETC_ETHSWT_IP_VENDOR_ID_C !=  NETC_ETHSWT_IP_CFG_DEFINES_VENDOR_ID)
79     #error "Netc_EthSwt_Ip.c and Netc_EthSwt_Ip_Cfg_Defines.h have different vendor ids"
80 #endif
81 #if (( NETC_ETHSWT_IP_AR_RELEASE_MAJOR_VERSION_C    !=  NETC_ETHSWT_IP_CFG_DEFINES_AR_RELEASE_MAJOR_VERSION) || \
82      ( NETC_ETHSWT_IP_AR_RELEASE_MINOR_VERSION_C    !=  NETC_ETHSWT_IP_CFG_DEFINES_AR_RELEASE_MINOR_VERSION) || \
83      ( NETC_ETHSWT_IP_AR_RELEASE_REVISION_VERSION_C !=  NETC_ETHSWT_IP_CFG_DEFINES_AR_RELEASE_REVISION_VERSION))
84      #error "AUTOSAR Version Numbers of Netc_EthSwt_Ip.c and Netc_EthSwt_Ip_Cfg_Defines.h are different"
85 #endif
86 #if (( NETC_ETHSWT_IP_SW_MAJOR_VERSION_C !=  NETC_ETHSWT_IP_CFG_DEFINES_SW_MAJOR_VERSION) || \
87      ( NETC_ETHSWT_IP_SW_MINOR_VERSION_C !=  NETC_ETHSWT_IP_CFG_DEFINES_SW_MINOR_VERSION) || \
88      ( NETC_ETHSWT_IP_SW_PATCH_VERSION_C !=  NETC_ETHSWT_IP_CFG_DEFINES_SW_PATCH_VERSION))
89     #error "Software Version Numbers of Netc_EthSwt_Ip.c and Netc_EthSwt_Ip_Cfg_Defines.h are different"
90 #endif
91 /*==================================================================================================
92 *                           LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
93 ==================================================================================================*/
94 
95 /*==================================================================================================
96 *                                          LOCAL MACROS
97 ==================================================================================================*/
98 #define SW_ETH_MAC_PORT_PM0_IF_MODE_IFMODE_MII_MODE (1U)
99 #define SW_ETH_MAC_PORT_PM0_IF_MODE_IFMODE_RMII_MODE (3U)
100 #define SW_ETH_MAC_PORT_PM0_IF_MODE_IFMODE_RGMII_MODE (4U)
101 #define SW_ETH_MAC_PORT_PM0_IF_MODE_SSP_BAUD_RATE_100MBIT (0U)
102 #define SW_ETH_MAC_PORT_PM0_IF_MODE_SSP_BAUD_RATE_10MBIT (1U)
103 #define SW_ETH_MAC_PORT_PM0_IF_MODE_SSP_BAUD_RATE_1000MBIT (2U)
104 
105 /*==================================================================================================
106 *                                         LOCAL CONSTANTS
107 ==================================================================================================*/
108 #define NETC_ETHSWT_IP_FIELD_REP_IN_4BITS (4U)
109 #define NETC_ETHSWT_IP_FIELD_REP_IN_TOP_OF_32BITS (16U)
110 
111 #define NETC_ETHSWT_IP_RXTAGA_ACCEPT_UNTAGGED (1U)
112 #define NETC_ETHSWT_IP_RXTAGA_ACCEPT_PRIO_TAGGED (2U)
113 #define NETC_ETHSWT_IP_RXTAGA_ACCEPT_SINGLE_TAGGED (4U)
114 #define NETC_ETHSWT_IP_RXTAGA_ACCEPT_DOUBLE_TAGGED (8U)
115 
116 /* Formula for speed: 10Mbps * (PSPEED+1) */
117 #define NETC_ETHSWT_IP_SHAPING_PSPEED_10MBITS (0U)
118 #define NETC_ETHSWT_IP_SHAPING_PSPEED_100MBITS (9U)
119 #define NETC_ETHSWT_IP_SHAPING_PSPEED_1000MBITS (99U)
120 #define NETC_ETHSWT_IP_SHAPING_PSPEED_2000MBITS (199U)
121 
122 #define NETC_ETHSWT_IP_NUM_SHAPING_CLASS (8U)
123 
124 /*==================================================================================================
125 *                                         LOCAL VARIABLES
126 ==================================================================================================*/
127 
128 
129 /*==================================================================================================
130 *                                        GLOBAL CONSTANTS
131 ==================================================================================================*/
132 
133 /*==================================================================================================
134 *                                        GLOBAL VARIABLES
135 ==================================================================================================*/
136 #define ETHSWT_43_NETC_START_SEC_VAR_INIT_BOOLEAN
137 #include "EthSwt_43_NETC_MemMap.h"
138 
139 /* Enabled status for Time Aware Shaper of each port */
140 static boolean PortTimeAwareShaperEnabled[NETC_ETHSWT_NUMBER_OF_PORTS] = {(boolean)FALSE, (boolean)FALSE, (boolean)FALSE};
141 
142 /* Flag to determine if mirroring is active or not */
143 static boolean MirrorConfigurationDone = FALSE;
144 
145 #define ETHSWT_43_NETC_STOP_SEC_VAR_INIT_BOOLEAN
146 #include "EthSwt_43_NETC_MemMap.h"
147 
148 #define ETHSWT_43_NETC_START_SEC_VAR_INIT_UNSPECIFIED
149 #include "EthSwt_43_NETC_MemMap.h"
150 
151 /* Base address of the registers for the MAC Ports */
152 Netc_EthSwt_Ip_PortBaseType* Netc_EthSwt_Ip_PortBaseTable[] = { (Netc_EthSwt_Ip_PortBaseType*)IP_NETC__SW0_ETH_MAC_PORT0_BASE, (Netc_EthSwt_Ip_PortBaseType*)IP_NETC__SW0_ETH_MAC_PORT1_BASE };
153 
154 /* Base address of the registers for the pseudo Port */
155 Netc_EthSwt_Ip_PseudoPortBaseType* Netc_EthSwt_Ip_PseudoPortBaseTable[] = { (Netc_EthSwt_Ip_PseudoPortBaseType*)IP_NETC__SW0_PSEUDO_MAC_PORT2_BASE };
156 SW_PORT0_Type *Netc_EthSwt_Ip_SW0_PortxBaseAddr[NETC_ETHSWT_NUMBER_OF_PORTS] = {(SW_PORT0_Type*)IP_NETC__SW0_PORT0_BASE, (SW_PORT0_Type*)IP_NETC__SW0_PORT1_BASE, (SW_PORT0_Type*)IP_NETC__SW0_PORT2_BASE};
157 #define ETHSWT_43_NETC_STOP_SEC_VAR_INIT_UNSPECIFIED
158 #include "EthSwt_43_NETC_MemMap.h"
159 
160 #define ETHSWT_43_NETC_START_SEC_VAR_CLEARED_UNSPECIFIED
161 #include "EthSwt_43_NETC_MemMap.h"
162 
163 /* Table entries for Time Aware Shaping configuration of each Port */
164 static Netc_EthSwt_Ip_TimeGateSchedulingEntryDataType TimeGateSchedulingEntryData[NETC_ETHSWT_NUMBER_OF_PORTS] = {0U};
165 
166 #define ETHSWT_43_NETC_STOP_SEC_VAR_CLEARED_UNSPECIFIED
167 #include "EthSwt_43_NETC_MemMap.h"
168 
169 #define ETHSWT_43_NETC_START_SEC_VAR_INIT_32
170 #include "EthSwt_43_NETC_MemMap.h"
171 
172 /* Ingress Port Filter Entry ID for mirroing */
173 uint32 MirroringIngressPortFilterEntryId = 0xFFFFFFFFUL;
174 
175 #define ETHSWT_43_NETC_STOP_SEC_VAR_INIT_32
176 #include "EthSwt_43_NETC_MemMap.h"
177 
178 #define ETHSWT_43_NETC_START_SEC_VAR_CLEARED_32
179 #include "EthSwt_43_NETC_MemMap.h"
180 
181 /* The frequency of the NETC module for computing CBS parameters */
182 static uint32 Netc_EthSwt_Ip_NetcClockFrequency;
183 
184 #define ETHSWT_43_NETC_STOP_SEC_VAR_CLEARED_32
185 #include "EthSwt_43_NETC_MemMap.h"
186 
187 #define ETHSWT_43_NETC_START_SEC_VAR_CLEARED_16
188 #include "EthSwt_43_NETC_MemMap.h"
189 
190 /* The timeout set for FDB aging */
191 static uint16 Netc_EthSwt_Ip_FdbTableEntryTimeout;
192 
193 #define ETHSWT_43_NETC_STOP_SEC_VAR_CLEARED_16
194 #include "EthSwt_43_NETC_MemMap.h"
195 
196 #define ETHSWT_43_NETC_START_SEC_VAR_CLEARED_UNSPECIFIED_NO_CACHEABLE
197 #include "EthSwt_43_NETC_MemMap.h"
198 
199 /* A shadow buffer for the mirroring configuration to be used when the application is reading the active configuration */
200 static Netc_EthSwt_Ip_SwitchMirrorCfgType MirrorCfgBackup;
201 
202 /* Structure used for filling in the actual command buffer descriptor used in table operations */
203 volatile Netc_EthSwt_Ip_CmdBDType CmdBDRConfig[NETC_ETHSWT_IP_CBDR_NUM];
204 
205  /* Key element data for ingress port filter table */
206 static volatile uint32 IPFKeyeData[NETC_ETHSWT_IP_INGRESSPORTFILTERTABLE_KEYE_DATA_LEN];
207 
208 /* a 128 bytes aligned command ring descriptor buffer */
209 VAR_ALIGN(Netc_EthSwt_Ip_NTMPMessageHeaderFormatType SwtcommandRingDescriptor0[NETC_ETHSWT_IP_ACTUAL_CBDR0_LENGTH], NETC_ETHSWT_IP_CBD_ALIGNED_SIZE)
210 VAR_ALIGN(Netc_EthSwt_Ip_NTMPMessageHeaderFormatType SwtcommandRingDescriptor1[NETC_ETHSWT_IP_ACTUAL_CBDR1_LENGTH], NETC_ETHSWT_IP_CBD_ALIGNED_SIZE)
211 
212 /* a 16 bytes aligned FDB table request data buffer */
213 VAR_ALIGN(volatile Netc_EthSwt_Ip_SwitchTableDataType TableDataBuffer, NETC_ETHSWT_IP_TABLE_ALIGNED_SIZE)
214 
215 #define ETHSWT_43_NETC_STOP_SEC_VAR_CLEARED_UNSPECIFIED_NO_CACHEABLE
216 #include "EthSwt_43_NETC_MemMap.h"
217 
218 /*==================================================================================================
219 *                                    LOCAL FUNCTION PROTOTYPES
220 ==================================================================================================*/
221 #define ETHSWT_43_NETC_START_SEC_CODE
222 #include "EthSwt_43_NETC_MemMap.h"
223 
224 /**
225  * @brief            Command BD Rings initialization function
226  * @details          Initialize command ring for switch
227  *
228  * @param[in]        cbdrIndex: Index of switch command BD rings. There are only two switch command BD rings.
229  *
230  * @return           Result of the operation
231  * @retval           0 : NETC_ETHSWT_CBDRSTATUS_SUCCES, success
232  * @retval           1 : NETC_ETHSWT_CBDRSTATUS_INDEX_ERROR, fail
233  */
234 static Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_InitCommandBDR(uint8 SwitchIdx, uint8 cbdrIndex);
235 
236 /**
237  * @brief            Command request function
238  * @details          Add one entry with different commands to command ring
239  *
240  * @param[in]        cbdrIndex:        Index of switch command BD rings
241  *                   OperationData:    a pointer points to a structure with elements table id, access method, and cmd
242  *
243  * @return           Result of the operation
244  * @retval           0 : NETC_ETHSWT_CBDRSTATUS_SUCCES, success
245  * @retval           2 : NETC_ETHSWT_CBDRSTATUS_RINGFULL, fail
246  */
247 static Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_SendCommand(uint8 SwitchIdx, uint8 cbdrIndex, const NetcEthSwt_Ip_ReqHeaderTableOperationDataType *OperationData);
248 
249 /**
250  * @brief            Get Matched table entries function
251  * @details          Check how many table entry exist
252  *
253  * @param[in]        cbdrIndex:     Index of switch command BD rings
254  *
255   * @param[out]      NumOfEntry:    Number of matched entry found
256  *
257  * @return           Result of the operation
258  * @retval           0 : NETC_ETHSWT_CBDRSTATUS_SUCCES, success
259  * @retval           others: fail
260  */
261 static void Netc_EthSwt_Ip_GetMatchedEntries(uint8 cbdrIndex, uint32 *NumOfEntry);
262 
263 /**
264  * @brief            FDB table initialization function
265  * @details          Fill in the FDB table request data buffer
266  *
267  * @param[in]        ActionsData: The data of Action Field of FDB table request data buffer
268  *                   pAccessKey:  A pointer points the data of Access Key field of FDB table request data buffer
269  *                   pCfgeData:   A pointer points the data of Cfge field of FDB table request data buffer
270  *                   accessMethod: The value of ACCESS_METHOD. it determins the content of the Access Key field
271  *
272  * @return           Result of the operation
273  * @retval           0 : NETC_ETHSWT_CBDRSTATUS_SUCCES, success
274  * @retval           6 : NETC_ETHSWT_CBDRSTATUS_ACCESSMETHOD_ERROR, fail
275  */
276 static Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_FillInFdbTableReqDataBuff(uint32 ActionsData, const uint32 *pAccessKey, const Netc_EthSwt_Ip_FDBTableCFGEDataType *pCfgeData, Netc_EthSwt_Ip_AccessMethodType accessMethod);
277 
278 /**
279  * @brief            Vlan Filter table initialization function
280  * @details          Fill in the Vlan Filter table request data buffer
281  *
282  * @param[in]        ActionsData: The data of Action Field of Vlan Filter table request data buffer
283  *                   AccessKeyData:  The data of Access Key field in Vlan Filter table request data buffer, it could be Entry_Id, VID, Resume_Entry_Id according to different Access Method.
284  *                   pCfgeData:   A pointer points the data of Cfge field of Vlan Filter table request data buffer
285  *                   accessMethod: The value of ACCESS_METHOD. it determins the content of the Access Key field
286  *
287  * @return           Result of the operation
288  * @retval           0 : NETC_ETHSWT_CBDRSTATUS_SUCCES, success
289  * @retval           6 : NETC_ETHSWT_CBDRSTATUS_ACCESSMETHOD_ERROR, fail
290  */
291 static Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_FillInVlanFilterTableReqDataBuff(uint32 ActionsData, uint32 AccessKeyData, const Netc_EthSwt_Ip_VlanFilterTableCFGEDataType *pCfgeData, Netc_EthSwt_Ip_AccessMethodType accessMethod);
292 
293 static Std_ReturnType Netc_EthSwt_Ip_MacPortConfig( uint8 SwitchIdx, uint8 SwitchPortIdx,
294                                                     Netc_EthSwt_Ip_XmiiModeType EthSwtPortPhysicalLayerType,
295                                                     EthTrcv_BaudRateType EthSwtPortMacLayerSpeed,
296                                                     Netc_EthSwt_Ip_PortDuplexType EthSwtPortMacLayerDuplexMode
297                                                   );
298 /**
299  * @brief Prepare to use a timeout.
300  *
301  * @param StartTimeOut Current value of selected counter.
302  * @param ElapsedTimeOut Reset elapsed time to 0.
303  * @param TimeoutTicksOut TimeoutUs converted from microsecond units to ticks units.
304  * @param TimeoutUs Timeout value in microsecond.
305  */
306 static inline void Netc_EthSwt_Ip_StartTimeOut( uint32 *StartTimeOut,
307                                                 uint32 *ElapsedTimeOut,
308                                                 uint32 *TimeoutTicksOut,
309                                                 uint32 TimeoutUs
310                                               );
311 
312 /**
313  * @brief Checks for timeout expiration condition.
314  *
315  * @param StartTimeInOut Initial value of the counter.
316  * @param ElapsedTimeInOut Current ticks passed.
317  * @param TimeoutTicks Number of ticks after timout will be activated.
318  *
319  * @return boolean TRUE  - timout activated.
320  *                 FALSE - timeout is not yet reached.
321  */
322 static inline boolean Netc_EthSwt_Ip_TimeoutExpired( uint32 *StartTimeInOut,
323                                                      uint32 *ElapsedTimeInOut,
324                                                      uint32 TimeoutTicks
325                                                    );
326 
327 static inline Std_ReturnType Netc_EthSwt_Ip_PortRateEnumToRate(EthTrcv_BaudRateType baudRate, uint64 *portTxRate);
328 
329 static Std_ReturnType Netc_EthSwt_Ip_IerbReady(void);
330 /*==================================================================================================
331 *                                         LOCAL FUNCTIONS
332 ==================================================================================================*/
Netc_EthSwt_Ip_StartTimeOut(uint32 * StartTimeOut,uint32 * ElapsedTimeOut,uint32 * TimeoutTicksOut,uint32 TimeoutUs)333 static inline void Netc_EthSwt_Ip_StartTimeOut( uint32 *StartTimeOut,
334                                                 uint32 *ElapsedTimeOut,
335                                                 uint32 *TimeoutTicksOut,
336                                                 uint32 TimeoutUs
337                                               )
338 {
339     *StartTimeOut    = OsIf_GetCounter(NETC_ETHSWT_IP_TIMEOUT_TYPE);
340     *ElapsedTimeOut  = 0U;
341     *TimeoutTicksOut = OsIf_MicrosToTicks(TimeoutUs, NETC_ETHSWT_IP_TIMEOUT_TYPE);
342 }
343 
Netc_EthSwt_Ip_TimeoutExpired(uint32 * StartTimeInOut,uint32 * ElapsedTimeInOut,uint32 TimeoutTicks)344 static inline boolean Netc_EthSwt_Ip_TimeoutExpired( uint32 *StartTimeInOut,
345                                                      uint32 *ElapsedTimeInOut,
346                                                      uint32 TimeoutTicks
347                                                    )
348 {
349     /* get elapsed ticks */
350     *ElapsedTimeInOut += OsIf_GetElapsed(StartTimeInOut, NETC_ETHSWT_IP_TIMEOUT_TYPE);
351 
352     return ((*ElapsedTimeInOut >= TimeoutTicks) ? TRUE : FALSE);
353 }
354 
Netc_EthSwt_Ip_IerbReady(void)355 static Std_ReturnType Netc_EthSwt_Ip_IerbReady(void)
356 {
357     Std_ReturnType status = E_OK;
358     uint32 StartTime;
359     uint32 ElapsedTime;
360     uint32 TimeoutTicks;
361 
362     /* Verify ready and IERB is valid */
363     /* Setup timeout timer */
364     Netc_EthSwt_Ip_StartTimeOut(&StartTime, &ElapsedTime, &TimeoutTicks, NETC_ETHSWT_IP_TIMEOUT_VALUE_US);
365     do
366     {
367         if (
368              (0UL == (IP_NETC__SW0_COMMON->OSR & NETC_F2_COMMON_OSR_STATE_MASK)) &&
369              (0UL == (IP_NETC__SW0_COMMON->OSR & NETC_F2_COMMON_OSR_ITM_STATE_MASK))
370            )
371         {
372             status = E_OK;
373             break;
374         }
375         else
376         {
377             status = E_NOT_OK;
378         }
379     }while(!Netc_EthSwt_Ip_TimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks));
380 
381     return status;
382 }
383 
Netc_EthSwt_Ip_PortRateEnumToRate(EthTrcv_BaudRateType baudRate,uint64 * portTxRate)384 static inline Std_ReturnType Netc_EthSwt_Ip_PortRateEnumToRate(EthTrcv_BaudRateType baudRate, uint64 *portTxRate)
385 {
386     Std_ReturnType status = E_OK;
387     /* Translate enum in uint32 for calculations and PSPEED config */
388     switch(baudRate) {
389     case ETHTRCV_BAUD_RATE_10MBIT:
390         *portTxRate = 10000000UL;
391         break;
392     case ETHTRCV_BAUD_RATE_100MBIT:
393         *portTxRate = 100000000UL;
394         break;
395     case ETHTRCV_BAUD_RATE_1000MBIT:
396         *portTxRate = 1000000000UL;
397         break;
398     default:
399         *portTxRate = 1000000000UL;
400         status = E_NOT_OK;
401         break;
402     };
403     return status;
404 }
405 
406 /*FUNCTION**********************************************************************
407  *
408  * Function Name : Netc_EthSwt_Ip_EMDIOConfiguration
409  * Description   : function for configuring the EMDIO
410  *
411  *END**************************************************************************/
412 static Std_ReturnType Netc_EthSwt_Ip_EMDIOConfiguration( uint8 SwitchIdx );
413 
414 /*==================================================================================================
415 *                                        GLOBAL FUNCTIONS
416 ==================================================================================================*/
417 
418 /*FUNCTION**********************************************************************
419  *
420  * Function Name : Netc_EthSwt_Ip_SetPortMode
421  * Description   : function for setting the port mode
422  * implements Netc_EthSwt_Ip_SetPortMode_Activity
423  *END**************************************************************************/
Netc_EthSwt_Ip_SetPortMode(uint8 SwitchIdx,uint8 SwitchPortIdx,boolean PortEnable)424 Std_ReturnType Netc_EthSwt_Ip_SetPortMode(uint8 SwitchIdx,
425                                           uint8 SwitchPortIdx,
426                                           boolean PortEnable)
427 {
428 #if(NETC_ETHSWT_IP_DEV_ERROR_DETECT == STD_ON)
429     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
430     DevAssert(SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_PORTS);
431 #endif
432 
433     (void) SwitchIdx;
434 
435     if(TRUE == PortEnable)
436     {
437         Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->POR &= ~(SW_PORT0_POR_TXDIS_MASK | SW_PORT0_POR_RXDIS_MASK);
438 
439         /* Write the PM0_COMMAND_CONFIG only for the MAC ports */
440         if (SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_MAC_PORTS)
441         {
442             Netc_EthSwt_Ip_PortBaseTable[SwitchPortIdx]->PM0_COMMAND_CONFIG |= (SW_ETH_MAC_PORT0_PM0_COMMAND_CONFIG_RX_EN_MASK | \
443                                                                                 SW_ETH_MAC_PORT0_PM0_COMMAND_CONFIG_TX_EN_MASK);
444         }
445     }
446     else
447     {
448         Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->POR |= (SW_PORT0_POR_TXDIS_MASK | SW_PORT0_POR_RXDIS_MASK);
449 
450         /* Write the PM0_COMMAND_CONFIG only for the MAC ports */
451         if (SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_MAC_PORTS)
452         {
453             Netc_EthSwt_Ip_PortBaseTable[SwitchPortIdx]->PM0_COMMAND_CONFIG &= ~(SW_ETH_MAC_PORT0_PM0_COMMAND_CONFIG_RX_EN_MASK | \
454                                                                                  SW_ETH_MAC_PORT0_PM0_COMMAND_CONFIG_TX_EN_MASK);
455         }
456     }
457 
458     return E_OK;
459 }
460 
461 
462 /*FUNCTION**********************************************************************
463  *
464  * Function Name : Netc_EthSwt_Ip_GetPortMode
465  * Description   : function for getting the port mode
466  * implements Netc_EthSwt_Ip_GetPortMode_Activity
467  *END**************************************************************************/
Netc_EthSwt_Ip_GetPortMode(uint8 SwitchIdx,uint8 SwitchPortIdx,boolean * PortEnable)468 Std_ReturnType Netc_EthSwt_Ip_GetPortMode(uint8 SwitchIdx,
469                                           uint8 SwitchPortIdx,
470                                           boolean *PortEnable)
471 {
472     uint32 macPortConfig;
473     Std_ReturnType status = E_OK;
474 
475     (void) SwitchIdx;
476 #if(NETC_ETHSWT_IP_DEV_ERROR_DETECT == STD_ON)
477     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
478     DevAssert(SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_PORTS);
479 #endif
480 
481     if (SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_MAC_PORTS)
482     {
483         macPortConfig = Netc_EthSwt_Ip_PortBaseTable[SwitchPortIdx]->PM0_COMMAND_CONFIG;
484 
485         if ( (((SW_ETH_MAC_PORT1_PM0_COMMAND_CONFIG_TX_EN_MASK & macPortConfig) >> SW_ETH_MAC_PORT1_PM0_COMMAND_CONFIG_TX_EN_SHIFT) ^ \
486               ((SW_ETH_MAC_PORT1_PM0_COMMAND_CONFIG_RX_EN_MASK & macPortConfig) >> SW_ETH_MAC_PORT1_PM0_COMMAND_CONFIG_RX_EN_SHIFT)) == 1UL
487            ) /* Test for different mode for RX and TX with XOR */
488         {
489             *PortEnable = FALSE;
490             status = E_NOT_OK;
491         }
492         else
493         {
494             if((macPortConfig & SW_ETH_MAC_PORT1_PM0_COMMAND_CONFIG_TX_EN_MASK) == SW_ETH_MAC_PORT1_PM0_COMMAND_CONFIG_TX_EN_MASK)
495             {
496                 *PortEnable = TRUE;
497             }
498             else
499             {
500                 *PortEnable = FALSE;
501             }
502         }
503     }
504     else
505     {
506         if (0UL == (Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->POR & (SW_PORT0_POR_TXDIS_MASK | SW_PORT0_POR_RXDIS_MASK)))
507         {
508             *PortEnable = TRUE;
509         }
510         else
511         {
512             *PortEnable = FALSE;
513         }
514     }
515 
516     return status;
517 }
518 
519 /*FUNCTION**********************************************************************
520  *
521  * Function Name : Netc_EthSwt_Ip_GetPortSpeed
522  * Description   : Ethernet Switch get baud rate function.
523  * implements Netc_EthSwt_Ip_GetPortSpeed_Activity
524  *END**************************************************************************/
Netc_EthSwt_Ip_GetPortSpeed(uint8 SwitchIdx,uint8 SwitchPortIdx,EthTrcv_BaudRateType * BaudRate)525 Std_ReturnType Netc_EthSwt_Ip_GetPortSpeed( uint8 SwitchIdx,
526                                             uint8 SwitchPortIdx,
527                                             EthTrcv_BaudRateType * BaudRate
528                                           )
529 {
530     Std_ReturnType status = E_OK;
531     uint32 interfaceModeConfig;
532 
533 #if(NETC_ETHSWT_IP_DEV_ERROR_DETECT == STD_ON)
534     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
535     DevAssert(SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_PORTS);
536 #endif
537 
538     (void) SwitchIdx;
539     if(SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_MAC_PORTS)
540     {
541         interfaceModeConfig = (Netc_EthSwt_Ip_PortBaseTable[SwitchPortIdx]->PM0_IF_MODE);
542 
543         switch((interfaceModeConfig & SW_ETH_MAC_PORT1_PM0_IF_MODE_IFMODE_MASK) >> SW_ETH_MAC_PORT1_PM0_IF_MODE_IFMODE_SHIFT)
544         {
545             case SW_ETH_MAC_PORT_PM0_IF_MODE_IFMODE_MII_MODE: /* MII mode */
546             case SW_ETH_MAC_PORT_PM0_IF_MODE_IFMODE_RMII_MODE: /* RMII mode */
547                 if((interfaceModeConfig & SW_ETH_MAC_PORT1_PM0_IF_MODE_M10_MASK) == SW_ETH_MAC_PORT1_PM0_IF_MODE_M10_MASK)
548                 {
549                     *BaudRate = ETHTRCV_BAUD_RATE_10MBIT;
550                 }
551                 else
552                 {
553                     *BaudRate = ETHTRCV_BAUD_RATE_100MBIT;
554                 }
555                 break;
556             case SW_ETH_MAC_PORT_PM0_IF_MODE_IFMODE_RGMII_MODE: /* RGMII mode */
557                 switch((interfaceModeConfig & SW_ETH_MAC_PORT1_PM0_IF_MODE_SSP_MASK) >> SW_ETH_MAC_PORT1_PM0_IF_MODE_SSP_SHIFT)
558                 {
559                     case SW_ETH_MAC_PORT_PM0_IF_MODE_SSP_BAUD_RATE_1000MBIT: /* 1000Mbps */
560                         *BaudRate = ETHTRCV_BAUD_RATE_1000MBIT;
561                         break;
562                     case SW_ETH_MAC_PORT_PM0_IF_MODE_SSP_BAUD_RATE_100MBIT: /* 100Mbps */
563                         *BaudRate = ETHTRCV_BAUD_RATE_100MBIT;
564                         break;
565                     case SW_ETH_MAC_PORT_PM0_IF_MODE_SSP_BAUD_RATE_10MBIT: /* 10Mbps */
566                         *BaudRate = ETHTRCV_BAUD_RATE_10MBIT;
567                         break;
568                     default:
569                         status = E_NOT_OK;
570                         break;
571                 }
572                 break;
573             default:
574                 status = E_NOT_OK;
575                 break;
576         }
577     }
578     else
579     {
580         *BaudRate = ETHTRCV_BAUD_RATE_1000MBIT;
581     }
582 
583     return status;
584 }
585 
586 /*FUNCTION**********************************************************************
587  *
588  * Function Name : Netc_EthSwt_Ip_SetPortSpeed
589  * Description   : Ethernet Switch set baud rate function.
590  * implements Netc_EthSwt_Ip_SetPortSpeed_Activity
591  *END**************************************************************************/
Netc_EthSwt_Ip_SetPortSpeed(uint8 SwitchIdx,uint8 SwitchPortIdx,EthTrcv_BaudRateType BaudRate)592 Std_ReturnType Netc_EthSwt_Ip_SetPortSpeed( uint8 SwitchIdx,
593                                             uint8 SwitchPortIdx,
594                                             EthTrcv_BaudRateType BaudRate
595                                           )
596 {
597     Std_ReturnType status = E_OK;
598     uint32 interfaceType;
599     uint32 interfaceModeConfig = 0UL;
600     uint32 shapingPSpeedConfig = 0UL; /* used for shaping of the port */
601 
602     (void) SwitchIdx;
603 #if(NETC_ETHSWT_IP_DEV_ERROR_DETECT == STD_ON)
604     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
605     DevAssert(SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_PORTS);
606 #endif
607 
608     if(SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_MAC_PORTS)
609     {
610         interfaceModeConfig = Netc_EthSwt_Ip_PortBaseTable[SwitchPortIdx]->PM0_IF_MODE;
611 
612         interfaceType = ((interfaceModeConfig & SW_ETH_MAC_PORT1_PM0_IF_MODE_IFMODE_MASK) >> SW_ETH_MAC_PORT1_PM0_IF_MODE_IFMODE_SHIFT) ;
613         switch(interfaceType)
614         {
615             case SW_ETH_MAC_PORT_PM0_IF_MODE_IFMODE_MII_MODE: /* MII mode */
616             case SW_ETH_MAC_PORT_PM0_IF_MODE_IFMODE_RMII_MODE: /* RMII mode */
617             {
618                 if(BaudRate == ETHTRCV_BAUD_RATE_10MBIT)
619                 {
620                     interfaceModeConfig |= SW_ETH_MAC_PORT1_PM0_IF_MODE_M10_MASK;
621 		    shapingPSpeedConfig = NETC_ETHSWT_IP_SHAPING_PSPEED_10MBITS;
622                 }
623                 else if(BaudRate == ETHTRCV_BAUD_RATE_100MBIT)
624                 {
625                     interfaceModeConfig &= ~(SW_ETH_MAC_PORT1_PM0_IF_MODE_M10_MASK);
626 		    shapingPSpeedConfig = NETC_ETHSWT_IP_SHAPING_PSPEED_100MBITS;
627                 }
628                 else
629                 {
630                     status = E_NOT_OK;
631                 }
632                 break;
633             }
634             case SW_ETH_MAC_PORT_PM0_IF_MODE_IFMODE_RGMII_MODE: /* RGMII mode */
635             {
636                 switch(BaudRate)
637                 {
638                     case ETHTRCV_BAUD_RATE_10MBIT: /* 10Mbps */
639                     {
640                         interfaceModeConfig &= ~(SW_ETH_MAC_PORT1_PM0_IF_MODE_SSP_MASK);
641                         interfaceModeConfig |= (SW_ETH_MAC_PORT1_PM0_IF_MODE_SSP(SW_ETH_MAC_PORT_PM0_IF_MODE_SSP_BAUD_RATE_10MBIT));
642 		    	shapingPSpeedConfig = NETC_ETHSWT_IP_SHAPING_PSPEED_10MBITS;
643                         break;
644                     }
645                     case ETHTRCV_BAUD_RATE_100MBIT: /* 100Mbps */
646                     {
647                         interfaceModeConfig &= ~(SW_ETH_MAC_PORT1_PM0_IF_MODE_SSP_MASK);
648                         interfaceModeConfig |= (SW_ETH_MAC_PORT1_PM0_IF_MODE_SSP(SW_ETH_MAC_PORT_PM0_IF_MODE_SSP_BAUD_RATE_100MBIT));
649 		    	shapingPSpeedConfig = NETC_ETHSWT_IP_SHAPING_PSPEED_100MBITS;
650                         break;
651                     }
652                     case ETHTRCV_BAUD_RATE_1000MBIT: /* 1000Mbps */
653                     {
654                         interfaceModeConfig &= ~(SW_ETH_MAC_PORT1_PM0_IF_MODE_SSP_MASK);
655                         interfaceModeConfig |= (SW_ETH_MAC_PORT1_PM0_IF_MODE_SSP(SW_ETH_MAC_PORT_PM0_IF_MODE_SSP_BAUD_RATE_1000MBIT));
656 		    	shapingPSpeedConfig = NETC_ETHSWT_IP_SHAPING_PSPEED_1000MBITS;
657                         break;
658                     }
659                     default:
660                     {
661                         status = E_NOT_OK;
662                         break;
663                     }
664                 }
665                 break;
666             }
667             default:
668             {
669                 status = E_NOT_OK;
670                 break;
671             }
672         }
673         Netc_EthSwt_Ip_PortBaseTable[SwitchPortIdx]->PM0_IF_MODE = interfaceModeConfig;
674         Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->PCR &= ~SW_PORT0_PCR_PSPEED_MASK;
675         Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->PCR |= SW_PORT0_PCR_PSPEED(shapingPSpeedConfig);
676     }
677     else
678     {
679 	/* pseudo port */
680         Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->PCR &= ~SW_PORT0_PCR_PSPEED_MASK;
681         Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->PCR |= SW_PORT0_PCR_PSPEED(NETC_ETHSWT_IP_SHAPING_PSPEED_2000MBITS);
682     }
683 
684     return status;
685 }
686 
687 /*FUNCTION**********************************************************************
688  *
689  * Function Name : Netc_EthSwt_Ip_GetDuplexMode
690  * Description   : Ethernet Switch get duplex mode function.
691  * implements Netc_EthSwt_Ip_GetDuplexMode_Activity
692  *END**************************************************************************/
Netc_EthSwt_Ip_GetDuplexMode(uint8 SwitchIdx,uint8 SwitchPortIdx,EthTrcv_DuplexModeType * DuplexMode)693 Std_ReturnType Netc_EthSwt_Ip_GetDuplexMode( uint8 SwitchIdx,
694                                              uint8 SwitchPortIdx,
695                                              EthTrcv_DuplexModeType * DuplexMode
696                                            )
697 {
698     Std_ReturnType status = E_OK;
699     uint32 interfaceModeConfig;
700 
701 #if(NETC_ETHSWT_IP_DEV_ERROR_DETECT == STD_ON)
702     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
703     DevAssert(SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_PORTS);
704 #endif
705 
706     (void) SwitchIdx;
707     if(SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_MAC_PORTS)
708     {
709         interfaceModeConfig = Netc_EthSwt_Ip_PortBaseTable[SwitchPortIdx]->PM0_IF_MODE;
710 
711         /* Is this RGMII mode == 4U */
712         if ( SW_ETH_MAC_PORT_PM0_IF_MODE_IFMODE_RGMII_MODE ==
713              ((interfaceModeConfig & SW_ETH_MAC_PORT1_PM0_IF_MODE_IFMODE_MASK) >> SW_ETH_MAC_PORT1_PM0_IF_MODE_IFMODE_SHIFT)
714             )
715         {
716         /* Full duplex is 1 in SFD field */
717             if(SW_ETH_MAC_PORT1_PM0_IF_MODE_SFD_MASK == (interfaceModeConfig & SW_ETH_MAC_PORT1_PM0_IF_MODE_SFD_MASK))
718             {
719                 *DuplexMode = ETHTRCV_DUPLEX_MODE_FULL;
720             }
721             else /* ETHTRCV_DUPLEX_MODE_HALF */
722             {
723                 *DuplexMode = ETHTRCV_DUPLEX_MODE_HALF;
724             }
725         }
726         else
727         {
728         /* Full duplex is 0 in HD field */
729             if (SW_ETH_MAC_PORT1_PM0_IF_MODE_HD_MASK == (interfaceModeConfig & SW_ETH_MAC_PORT1_PM0_IF_MODE_HD_MASK))
730             {
731                 *DuplexMode = ETHTRCV_DUPLEX_MODE_HALF;
732             }
733             else /* ETHTRCV_DUPLEX_MODE_HALF */
734             {
735                 *DuplexMode = ETHTRCV_DUPLEX_MODE_FULL;
736             }
737         }
738     }
739     else
740     {
741     }
742         *DuplexMode = ETHTRCV_DUPLEX_MODE_FULL;
743 
744     return status;
745 }
746 
747 /*FUNCTION**********************************************************************
748  *
749  * Function Name : Netc_EthSwt_Ip_SetMacAddr
750  * Description   : This function sets the MAC address of a certain port of switch
751  *
752  *END**************************************************************************/
Netc_EthSwt_Ip_SetMacAddr(uint8 SwitchIdx,uint8 portIndex,const uint8 * macAddr)753 Std_ReturnType Netc_EthSwt_Ip_SetMacAddr(uint8 SwitchIdx, uint8 portIndex, const uint8 *macAddr)
754 {
755     Std_ReturnType status = E_OK;
756 
757 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
758     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
759     DevAssert(portIndex < NETC_ETHSWT_NUMBER_OF_PORTS);
760     DevAssert(macAddr != NULL_PTR);
761 #endif
762 
763     Netc_EthSwt_Ip_SW0_PortxBaseAddr[portIndex]->PMAR0 = (uint32)(macAddr[0U]) | ((uint32)(macAddr[1U]) << 8U) | ((uint32)(macAddr[2U]) << 16U) | ((uint32)(macAddr[3U]) << 24U);
764     Netc_EthSwt_Ip_SW0_PortxBaseAddr[portIndex]->PMAR1 = (uint32)(macAddr[4U]) | ((uint32)(macAddr[5U]) << 8U);
765 
766     return status;
767 }
768 
769 /*FUNCTION**********************************************************************
770  *
771  * Function Name : Netc_EthSwt_Ip_GetMacAddr
772  * Description   : This function reads the MAC address of a certain port
773  *
774  *END**************************************************************************/
Netc_EthSwt_Ip_GetMacAddr(uint8 SwitchIdx,uint8 portIndex,uint8 * macAddr)775 void Netc_EthSwt_Ip_GetMacAddr(uint8 SwitchIdx, uint8 portIndex, uint8 *macAddr)
776 {
777     uint32 msbMacAddr;
778     uint32 lsbMacAddr;
779     uint8 macAddrIdx;
780 
781 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
782     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
783     DevAssert(portIndex < NETC_ETHSWT_NUMBER_OF_PORTS);
784     DevAssert(macAddr != NULL_PTR);
785 #endif
786 
787     /* read data from registers */
788     msbMacAddr = Netc_EthSwt_Ip_SW0_PortxBaseAddr[portIndex]->PMAR0;
789     lsbMacAddr = Netc_EthSwt_Ip_SW0_PortxBaseAddr[portIndex]->PMAR1;
790 
791     /* copy mac address in the correct order */
792     for (macAddrIdx = 0U; macAddrIdx < 4U; macAddrIdx++)
793     {
794         macAddr[macAddrIdx] = (uint8)(msbMacAddr & NETC_ETHSWT_IP_0XFF_MASK);
795         msbMacAddr >>= 8U;
796     }
797 
798     macAddr[4U] = (uint8)(lsbMacAddr & NETC_ETHSWT_IP_0XFF_MASK);
799     lsbMacAddr >>= 8U;
800     macAddr[5U] = (uint8)(lsbMacAddr & NETC_ETHSWT_IP_0XFF_MASK);
801 
802 }
803 
804 /*FUNCTION**********************************************************************
805  *
806  * Function Name : Netc_EthSwt_Ip_GetPortMacAddr
807  * Description   : Ethernet Switch get port MAC address function.
808  * implements Netc_EthSwt_Ip_GetPortMacAddr_Activity
809  *END**************************************************************************/
Netc_EthSwt_Ip_GetPortMacAddr(uint8 SwitchIdx,uint16 Fid,const uint8 * MacAddr,uint8 * PortIdx)810 Std_ReturnType Netc_EthSwt_Ip_GetPortMacAddr( uint8 SwitchIdx, uint16 Fid, const uint8 * MacAddr, uint8 * PortIdx )
811 {
812     Std_ReturnType status = E_OK;
813     Netc_EthSwt_Ip_CBDRStatusType QueryStatus;
814     uint8 PortIndex;
815     uint8 NumOfMatchedPorts = 0U;
816     uint8 MacByteIdx;
817     uint32 NumOfMatchedElement = 0;
818     Netc_EthSwt_Ip_FdbEntryDataType FdbTableEntry;
819     uint32 PortBitMap;
820 
821 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
822     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
823     DevAssert(MacAddr != NULL_PTR);
824     DevAssert(PortIdx != NULL_PTR);
825 #endif
826 
827     for (MacByteIdx = 0U; MacByteIdx < NETC_ETHSWT_IP_MACADDRLEN; MacByteIdx++)
828     {
829         FdbTableEntry.MacAddr[MacByteIdx] = MacAddr[MacByteIdx];
830     }
831     FdbTableEntry.FID = Fid;
832 
833     QueryStatus = Netc_EthSwt_Ip_QueryFdbTableEntry(SwitchIdx, &NumOfMatchedElement, &FdbTableEntry);
834     if (QueryStatus == NETC_ETHSWT_CBDRSTATUS_SUCCES)
835     {
836         /* find a matched entry */
837         if (1U == NumOfMatchedElement)
838         {
839             /* get the port bitmap value from Fdb table response data buffer */
840             PortBitMap = TableDataBuffer.TableDataField[NETC_ETHSWT_FDBTABLE_RSPDATA_PORTBITMAP];
841 
842             /* check matched port number */
843             for (PortIndex = 0U; PortIndex < NETC_ETHSWT_IP_BITMAPLEN; PortIndex++)
844             {
845                 if (1U == (PortBitMap & (0x1U)))
846                 {
847                     NumOfMatchedPorts += 1U;
848                     *PortIdx = PortIndex;
849                 }
850                 PortBitMap >>= 1U;
851             }
852 
853             /* no matched ports found */
854             if (0U == NumOfMatchedPorts)
855             {
856                 *PortIdx = NETC_ETHSWT_IP_NOMATCHEDPORTMACADDR;
857             }
858 
859             /* multiple matched ports found */
860             if (NumOfMatchedPorts > 1U)
861             {
862                 status = E_NOT_OK;
863                 *PortIdx = NETC_ETHSWT_IP_NOMATCHEDPORTMACADDR;
864             }
865         }
866         else
867         {
868             /* no entry found */
869             *PortIdx = NETC_ETHSWT_IP_NOMATCHEDPORTMACADDR;
870         }
871     }
872     else
873     {
874         status = E_NOT_OK;
875     }
876 
877     return status;
878 }
879 
880 /*FUNCTION**********************************************************************
881  *
882  * Function Name : Netc_EthSwt_Ip_QueryFdbTableEntry
883  * Description   : Ethernet Switch query FDB table entry function.
884  * implements Netc_EthSwt_Ip_QueryFdbTableEntry_Activity
885  *END**************************************************************************/
Netc_EthSwt_Ip_QueryFdbTableEntry(uint8 SwitchIdx,uint32 * MatchedEntries,Netc_EthSwt_Ip_FdbEntryDataType * FdbTableEntry)886 Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_QueryFdbTableEntry( uint8 SwitchIdx,
887                                                                  uint32 *MatchedEntries,
888                                                                  Netc_EthSwt_Ip_FdbEntryDataType * FdbTableEntry
889                                                                )
890 {
891     Netc_EthSwt_Ip_CBDRStatusType status;
892     uint32 KeyeData[3U];
893     uint32 ActionsData;
894     uint32 MacAddrL;
895     uint32 MacAddrH;
896     uint32 CfgeData;
897     uint8 MacByteIdx;
898     NetcEthSwt_Ip_ReqHeaderTableOperationDataType OperationData;
899 
900 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
901     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
902     DevAssert(MatchedEntries != NULL_PTR);
903     DevAssert(FdbTableEntry != NULL_PTR);
904 #endif
905 
906     /* always do the full query. 0x0 = Full query. */
907     ActionsData = NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD_QUERY_ACTIONS(NETC_ETHSWT_TABLES_FULL_QUERY);
908 
909     KeyeData[0U] = ((uint32)(FdbTableEntry->MacAddr[0U]) | ((uint32)(FdbTableEntry->MacAddr[1U]) << 8U) | ((uint32)(FdbTableEntry->MacAddr[2U]) << 16U) | ((uint32)(FdbTableEntry->MacAddr[3U]) << 24U));
910     KeyeData[1U] = ((uint32)(FdbTableEntry->MacAddr[4U]) | ((uint32)(FdbTableEntry->MacAddr[5U]) << 8U));
911     KeyeData[2U] = FdbTableEntry->FID;
912 
913     /* no need CFGE_DATA and only use "NETC_ETHSWT_EXACT_MATCH_KEY_ELEMENT_MATCH" as the access method */
914     status = Netc_EthSwt_Ip_FillInFdbTableReqDataBuff(ActionsData, &KeyeData[0U], NULL_PTR, NETC_ETHSWT_EXACT_MATCH_KEY_ELEMENT_MATCH);
915     if (NETC_ETHSWT_CBDRSTATUS_SUCCES == status)
916     {
917         /* fill in operation data for config field of Request Header*/
918         OperationData.CmdCompletionInt = 0x0U;                                        /* command completion interrupt disabled */
919         OperationData.Version = NETC_ETHSWT_IP_CMDBD_REQFMT_PROTOCOL_VERSION;         /* protocol version = 2 */
920         OperationData.TableId = NETC_ETHSWT_IP_FDB_TABLE_ID;
921         OperationData.AccessMethod = NETC_ETHSWT_EXACT_MATCH_KEY_ELEMENT_MATCH;       /* for query command, always uses NETC_ETHSWT_EXACT_MATCH_KEY_ELEMENT_MATCH method */
922         OperationData.Cmd = NETC_ETHSWT_QUERY_CMD;
923         OperationData.ReqBuffLength = (NETC_ETHSWT_IP_TABLE_REQBUFFER_LEN);           /* set request data buffer length */
924         OperationData.RspBuffLength = (NETC_ETHSWT_IP_TABLE_RESBUFFER_LEN);           /* set response data buffer with normal length */
925 
926         /* send command */
927         status = Netc_EthSwt_Ip_SendCommand(SwitchIdx, NETC_ETHSWT_IP_CBDR_0, &OperationData);
928         /* Erroe code 0x8A is not a real error. check it on Errata. */
929         if ((status == 0x8AU) || (status == NETC_ETHSWT_CBDRSTATUS_SUCCES))
930         {
931             Netc_EthSwt_Ip_GetMatchedEntries(NETC_ETHSWT_IP_CBDR_0, MatchedEntries);
932 
933             /* found a matched entry */
934             if (1U == *MatchedEntries)
935             {
936                 /* fill in "Netc_EthSwt_Ip_FdbEntryDataType" structure with data in response data buffer */
937                 MacAddrL = TableDataBuffer.TableDataField[NETC_ETHSWT_FDBTABLE_RSPDATA_MACADDRESS_L];
938                 MacAddrH = TableDataBuffer.TableDataField[NETC_ETHSWT_FDBTABLE_RSPDATA_MACADDRESS_H];
939                 for (MacByteIdx = 0U; MacByteIdx < 4U; MacByteIdx++ )
940                 {
941                     FdbTableEntry->MacAddr[MacByteIdx] = (uint8)(MacAddrL & NETC_ETHSWT_IP_0XFF_MASK);
942                     MacAddrL >>= 8U;
943                 }
944                 FdbTableEntry->MacAddr[4U] = (uint8)(MacAddrH & NETC_ETHSWT_IP_0XFF_MASK);
945                 FdbTableEntry->MacAddr[5U] = (uint8)((MacAddrH >> 8U) & NETC_ETHSWT_IP_0XFF_MASK);
946 
947                 FdbTableEntry->FID = (uint16)(TableDataBuffer.TableDataField[NETC_ETHSWT_FDBTABLE_RSPDATA_FID] & NETC_ETHSWT_IP_FDBTABLE_KEYE_DATA_FID_MASK);
948                 FdbTableEntry->SwitchPortEgressBitMask = (TableDataBuffer.TableDataField[NETC_ETHSWT_FDBTABLE_RSPDATA_PORTBITMAP] & NETC_ETHSWT_IP_FDBTABLE_CFGE_PORT_BITMAP_MASK);
949 
950                 CfgeData = TableDataBuffer.TableDataField[NETC_ETHSWT_FDBTABLE_RSPDATA_CFGECONFIG];
951                 FdbTableEntry->TimeStampCapture = (((CfgeData & NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_TIMECAPE_MASK) >> NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_TIMECAPE_SHIFT) != 0x0UL) ? TRUE : FALSE;
952                 FdbTableEntry->DynamicEntry = (((CfgeData & NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_DYNAMIC_MASK) >> NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_DYNAMIC_SHIFT) != 0x0UL) ? TRUE : FALSE;
953                 FdbTableEntry->CutThroughDisable = (uint8)((CfgeData & NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_CTD_MASK) >> NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_CTD_SHIFT);
954                 FdbTableEntry->IngressMirroringEnable = (((CfgeData & NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_IMIRE_MASK) >> NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_IMIRE_SHIFT) != 0x0UL) ? TRUE : FALSE;
955                 FdbTableEntry->EgressPort = (uint8)((CfgeData & NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_EPORT_MASK) >> NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_EPORT_SHIFT);
956                 FdbTableEntry->OverridETEID = (uint8)(CfgeData & NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_OETEID_MASK);
957 
958                 FdbTableEntry->ET_EID = TableDataBuffer.TableDataField[NETC_ETHSWT_FDBTABLE_RSPDATA_ETEID];
959             }
960         }
961     }
962     else
963     {
964         status = NETC_ETHSWT_CBDRSTATUS_ACCESSMETHOD_ERROR;
965     }
966 
967 
968     return status;
969 }
970 
971 /*FUNCTION**********************************************************************
972  *
973  * Function Name : Netc_EthSwt_Ip_DeleteFdbTableEntry
974  * Description   : Ethernet Switch delete FDB table entry function.
975  * implements Netc_EthSwt_Ip_DeleteFdbTableEntry_Activity
976  *END**************************************************************************/
Netc_EthSwt_Ip_DeleteFdbTableEntry(uint8 SwitchIdx,uint32 * MatchedEntries,const Netc_EthSwt_Ip_FdbEntryDataType * FdbTableEntry)977 Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_DeleteFdbTableEntry( uint8 SwitchIdx,
978                                                                   uint32 *MatchedEntries,
979                                                                   const Netc_EthSwt_Ip_FdbEntryDataType * FdbTableEntry
980                                                                 )
981 {
982     Netc_EthSwt_Ip_CBDRStatusType status;
983     uint32 KeyeData[3U];
984     uint32 ActionsData = 0U;
985     NetcEthSwt_Ip_ReqHeaderTableOperationDataType OperationData;
986 
987 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
988     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
989     DevAssert(MatchedEntries != NULL_PTR);
990     DevAssert(FdbTableEntry != NULL_PTR);
991 #endif
992 
993     /* Delete command will ignore ActionsData data field */
994     KeyeData[0U] = ((uint32)(FdbTableEntry->MacAddr[0U]) | ((uint32)(FdbTableEntry->MacAddr[1U]) << 8U) | ((uint32)(FdbTableEntry->MacAddr[2U]) << 16U) | ((uint32)(FdbTableEntry->MacAddr[3U]) << 24U));
995     KeyeData[1U] = ((uint32)(FdbTableEntry->MacAddr[4U]) | ((uint32)(FdbTableEntry->MacAddr[5U]) << 8U));
996     KeyeData[2U] = FdbTableEntry->FID;
997 
998     /* no need CFGE_DATA and only use "NETC_ETHSWT_EXACT_MATCH_KEY_ELEMENT_MATCH" as the access method */
999     status = Netc_EthSwt_Ip_FillInFdbTableReqDataBuff(ActionsData, &KeyeData[0U], NULL_PTR, NETC_ETHSWT_EXACT_MATCH_KEY_ELEMENT_MATCH);
1000     if (NETC_ETHSWT_CBDRSTATUS_SUCCES == status)
1001     {
1002         /* fill in operation data for config field of Request Header*/
1003         OperationData.CmdCompletionInt = 0x0U;                                        /* command completion interrupt disabled */
1004         OperationData.Version = NETC_ETHSWT_IP_CMDBD_REQFMT_PROTOCOL_VERSION;         /* protocol version = 2 */
1005         OperationData.TableId = NETC_ETHSWT_IP_FDB_TABLE_ID;
1006         OperationData.AccessMethod = NETC_ETHSWT_EXACT_MATCH_KEY_ELEMENT_MATCH;       /* for delete command, always uses NETC_ETHSWT_EXACT_MATCH_KEY_ELEMENT_MATCH method */
1007         OperationData.Cmd = NETC_ETHSWT_DELETE_CMD;
1008         OperationData.ReqBuffLength = (NETC_ETHSWT_IP_TABLE_REQBUFFER_LEN);           /* set request data buffer length */
1009         OperationData.RspBuffLength = (NETC_ETHSWT_IP_TABLE_RESBUFFER_LEN);           /* set response data buffer with normal length */
1010 
1011         /* send the "Delete" command */
1012         status = Netc_EthSwt_Ip_SendCommand(SwitchIdx, NETC_ETHSWT_IP_CBDR_0, &OperationData);
1013         /* Erroe code 0x8A is not a real error. check it on Errata. */
1014         if ((status == 0x8AU) || (status == NETC_ETHSWT_CBDRSTATUS_SUCCES))
1015         {
1016             Netc_EthSwt_Ip_GetMatchedEntries(NETC_ETHSWT_IP_CBDR_0, MatchedEntries);
1017         }
1018     }
1019     else
1020     {
1021         status = NETC_ETHSWT_CBDRSTATUS_ACCESSMETHOD_ERROR;
1022     }
1023 
1024 
1025     return status;
1026 }
1027 
1028 /*FUNCTION**********************************************************************
1029  *
1030  * Function Name : Netc_EthSwt_Ip_AddOrUpdateFdbTableEntry
1031  * Description   : Ethernet Switch Add or Update FDB table entry function.
1032  * implements Netc_EthSwt_Ip_AddOrUpdateFdbTableEntry_Activity
1033  *END**************************************************************************/
Netc_EthSwt_Ip_AddOrUpdateFdbTableEntry(uint8 SwitchIdx,Netc_EthSwt_Ip_CommandsType Cmd,uint32 * MatchedEntries,const Netc_EthSwt_Ip_FdbEntryDataType * FdbTableEntry)1034 Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_AddOrUpdateFdbTableEntry( uint8 SwitchIdx,
1035                                                                        Netc_EthSwt_Ip_CommandsType Cmd,
1036                                                                        uint32 *MatchedEntries,
1037                                                                        const Netc_EthSwt_Ip_FdbEntryDataType * FdbTableEntry
1038                                                                      )
1039 {
1040     Netc_EthSwt_Ip_CBDRStatusType status;
1041     uint32 KeyeData[3U];
1042     uint32 ActionsData;
1043     Netc_EthSwt_Ip_FDBTableCFGEDataType CfgeData;
1044     NetcEthSwt_Ip_ReqHeaderTableOperationDataType OperationData;
1045 
1046 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
1047     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
1048     DevAssert(FdbTableEntry != NULL_PTR);
1049     DevAssert(MatchedEntries != NULL_PTR);
1050     DevAssert(FdbTableEntry->DynamicEntry == FALSE);    /* users should not be allowed to add dynamic entries */
1051 #endif
1052 
1053     /* only support Add, Update and AddOrUpdate commands */
1054     if ((NETC_ETHSWT_ADD_CMD != Cmd) && (NETC_ETHSWT_UPDATE_CMD != Cmd) && (NETC_ETHSWT_ADD_OR_UPDATE_CMD != Cmd))
1055     {
1056         status = NETC_ETHSWT_CBDRSTATUS_INVALID_CMD;    /* not supported command */
1057     }
1058     else
1059     {
1060         /* set ACTEU and CFGEU flag */
1061         ActionsData = (NETC_ETHSWT_IP_FDBTABLE_REQFMT_ACTIONS_FIELD_ACTEU(1U) \
1062                     | NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD_CFGEU(1U));
1063 
1064         KeyeData[0U] = ((uint32)(FdbTableEntry->MacAddr[0U]) | ((uint32)(FdbTableEntry->MacAddr[1U]) << 8U) | ((uint32)(FdbTableEntry->MacAddr[2U]) << 16U) | ((uint32)(FdbTableEntry->MacAddr[3U]) << 24U));
1065         KeyeData[1U] = ((uint32)(FdbTableEntry->MacAddr[4U]) | ((uint32)(FdbTableEntry->MacAddr[5U]) << 8U));
1066         KeyeData[2U] = FdbTableEntry->FID;
1067 
1068         CfgeData.Cfge_PortBitmap = NETC_ETHSWT_IP_FDBTABLE_CFGE_PORT_BITMAP(FdbTableEntry->SwitchPortEgressBitMask);
1069         CfgeData.Cfge_ConfigField = (NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_TIMECAPE(FdbTableEntry->TimeStampCapture ? 1U : 0U) \
1070                                 | NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_DYNAMIC(FdbTableEntry->DynamicEntry ? 1U : 0U) \
1071                                 | NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_CTD(FdbTableEntry->CutThroughDisable) \
1072                                 | NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_IMIRE(FdbTableEntry->IngressMirroringEnable ? 1U : 0U) \
1073                                 | NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_EPORT(FdbTableEntry->EgressPort) \
1074                                 | NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_OETEID(FdbTableEntry->OverridETEID));
1075 
1076         CfgeData.Cfge_EtEid = FdbTableEntry->ET_EID;
1077 
1078         /* only supports "NETC_ETHSWT_EXACT_MATCH_KEY_ELEMENT_MATCH" access method */
1079         status = Netc_EthSwt_Ip_FillInFdbTableReqDataBuff(ActionsData, &KeyeData[0U], &CfgeData, NETC_ETHSWT_EXACT_MATCH_KEY_ELEMENT_MATCH);
1080         if (NETC_ETHSWT_CBDRSTATUS_SUCCES == status)
1081         {
1082             /* fill in operation data for config field of Request Header*/
1083             OperationData.CmdCompletionInt = 0x0U;                                        /* command completion interrupt disabled */
1084             OperationData.Version = NETC_ETHSWT_IP_CMDBD_REQFMT_PROTOCOL_VERSION;         /* protocol version = 2 */
1085             OperationData.TableId = NETC_ETHSWT_IP_FDB_TABLE_ID;
1086             OperationData.AccessMethod = NETC_ETHSWT_EXACT_MATCH_KEY_ELEMENT_MATCH;       /* for Add, Update, or AddorUpdate command, the Access Method should only be NETC_ETHSWT_EXACT_MATCH_KEY_ELEMENT_MATCH */
1087             OperationData.Cmd = Cmd;
1088             OperationData.ReqBuffLength = (NETC_ETHSWT_IP_TABLE_REQBUFFER_LEN);
1089             OperationData.RspBuffLength = (NETC_ETHSWT_IP_TABLE_RESBUFFER_LEN);
1090 
1091             /* send command */
1092             status = Netc_EthSwt_Ip_SendCommand(SwitchIdx, NETC_ETHSWT_IP_CBDR_0, &OperationData);
1093             /* Erroe code 0x8A is not a real error. check it on Errata. */
1094             if ((status == 0x8AU) || (status == NETC_ETHSWT_CBDRSTATUS_SUCCES))
1095             {
1096                 Netc_EthSwt_Ip_GetMatchedEntries(NETC_ETHSWT_IP_CBDR_0, MatchedEntries);
1097             }
1098         }
1099         else
1100         {
1101             status = NETC_ETHSWT_CBDRSTATUS_ACCESSMETHOD_ERROR;
1102         }
1103     }
1104 
1105     return status;
1106 }
1107 
1108 /* inline function for verifying conditions in function FillInFdbTableListData() */
VerifyFillInFdbTableListDataFuncCond(const uint32 * ResumeId,boolean * StatciEntryQuerying,boolean * QueryDone)1109 static inline void VerifyFillInFdbTableListDataFuncCond(const uint32 *ResumeId, boolean *StatciEntryQuerying, boolean *QueryDone)
1110 {
1111     if (NETC_ETHSWT_IP_BD_NULL_ENTRY_ID == *ResumeId)
1112     {
1113         if (TRUE == *StatciEntryQuerying)
1114         {
1115             *StatciEntryQuerying = FALSE;
1116         }
1117         else
1118         {
1119             *QueryDone = TRUE;
1120         }
1121     }
1122 }
1123 
1124 /*FUNCTION**********************************************************************
1125  *
1126  * Function Name : SearchAndFillInFdbTableList
1127  * Description   : inline function for searching and filling in FdbTableList data in function Netc_EthSwt_Ip_GetFdbTable().
1128  *
1129  *END**************************************************************************/
SearchAndFillInFdbTableList(uint32 * ResumeId,uint16 * NumOfExistingEntry,Netc_EthSwt_Ip_FdbEntryDataType * FdbTableList,boolean * StatciEntryQuerying,boolean * QueryDone)1130 static inline Std_ReturnType SearchAndFillInFdbTableList(uint32 *ResumeId, uint16 *NumOfExistingEntry, Netc_EthSwt_Ip_FdbEntryDataType *FdbTableList,
1131                                                          boolean *StatciEntryQuerying, boolean *QueryDone)
1132 {
1133     Std_ReturnType status = E_OK;
1134     Netc_EthSwt_Ip_CBDRStatusType CBDRStatus;
1135     NetcEthSwt_Ip_ReqHeaderTableOperationDataType OperationData = {0U};
1136     uint32 NumOfElement = 0U;
1137     uint32 MacAddrL;
1138     uint32 MacAddrH;
1139     uint32 CfgeData;
1140     uint8 MacAddrByteIdx;
1141     uint32 ActionsData;
1142 
1143     /* set the querry options with full querry */
1144     ActionsData = NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD_QUERY_ACTIONS(NETC_ETHSWT_TABLES_FULL_QUERY) \
1145                 | NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD_DEBUG_OPTIONS(0U) \
1146                 | NETC_ETHSWT_IP_FDBTABLE_REQFMT_ACTIONS_FIELD_ACTEU(0U) \
1147                 | NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD_CFGEU(0U);
1148 
1149     /* fill in FdbTabeDataBuffer for request */
1150     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD] = ActionsData;
1151     /* fill in Access Key data with search criteria data format */
1152     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_RESUMEENTRYID] = *ResumeId;    /* resume entry id */
1153     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_MACADDRESS_L] = 0U;
1154     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_MACADDRESS_H] = 0U;
1155     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_FID] = 0U;
1156     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_PORTBITMAP] = 0U;
1157     /* search static entries first then dynamic entries. set CFGE_DATA[DYNAMIC] to 0x0 meaning it will match static entries, set CFGE_DATA[DYNAMIC] to 0x1 meaning it will match dynamic entries */
1158     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_CFGECONFIG] = (TRUE == *StatciEntryQuerying) ? NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_DYNAMIC(0U) : NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_DYNAMIC(1U);
1159 
1160     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_ETEID] = 0U;
1161     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_MATCHCRITERIA] = NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_CFGEMC(1U);    /* 0x1: Match CFGE_DATA[DYNAMIC] field */
1162 
1163     /* do the full querry with Search Method */
1164     /* fill in operation data for config field of Request Header*/
1165     OperationData.CmdCompletionInt = 0x0U;                                          /* command completion interrupt disabled */
1166     OperationData.Version = NETC_ETHSWT_IP_CMDBD_REQFMT_PROTOCOL_VERSION;           /* protocol version = 2 */
1167     OperationData.TableId = NETC_ETHSWT_IP_FDB_TABLE_ID;
1168     OperationData.AccessMethod = NETC_ETHSWT_SEARCH_METHOD;
1169     OperationData.Cmd = NETC_ETHSWT_QUERY_CMD;
1170     OperationData.ReqBuffLength = (NETC_ETHSWT_IP_TABLE_REQBUFFER_LEN);
1171     OperationData.RspBuffLength = (NETC_ETHSWT_IP_TABLE_RESBUFFER_LEN);             /* full query needs more space for response data */
1172 
1173     /* send the "Query" command */
1174     /* [notes]: there is an error "0x8A" in NTMP response header during this query operation but it is not a real error. there should be another errata for "0x8A" later. */
1175     CBDRStatus = Netc_EthSwt_Ip_SendCommand(0U, NETC_ETHSWT_IP_CBDR_0, &OperationData);
1176 
1177     /* check the status of querry command */
1178     if ((CBDRStatus == 0x8AU) || (CBDRStatus == NETC_ETHSWT_CBDRSTATUS_SUCCES))
1179     {
1180         Netc_EthSwt_Ip_GetMatchedEntries(NETC_ETHSWT_IP_CBDR_0, &NumOfElement);
1181 
1182         /* get the resume_entry_id and be ready for the next query operation */
1183         *ResumeId = TableDataBuffer.TableDataField[NETC_ETHSWT_FDBTABLE_RSPDATA_STATUS];
1184 
1185         /* found a matched entry */
1186         if ((1U == NumOfElement) && (*ResumeId != NETC_ETHSWT_IP_BD_NULL_ENTRY_ID))
1187         {
1188             /* fill in "Netc_EthSwt_Ip_FdbEntryDataType" structure with data in response data buffer */
1189             MacAddrL = TableDataBuffer.TableDataField[NETC_ETHSWT_FDBTABLE_RSPDATA_MACADDRESS_L];
1190             MacAddrH = TableDataBuffer.TableDataField[NETC_ETHSWT_FDBTABLE_RSPDATA_MACADDRESS_H];
1191             for (MacAddrByteIdx = 0U; MacAddrByteIdx < 4U; MacAddrByteIdx++ )
1192             {
1193                 FdbTableList[(*NumOfExistingEntry)].MacAddr[MacAddrByteIdx] = (uint8)(MacAddrL & NETC_ETHSWT_IP_0XFF_MASK);
1194                 MacAddrL >>= 8U;
1195             }
1196             FdbTableList[(*NumOfExistingEntry)].MacAddr[4U] = (uint8)(MacAddrH & NETC_ETHSWT_IP_0XFF_MASK);
1197             FdbTableList[(*NumOfExistingEntry)].MacAddr[5U] = (uint8)((MacAddrH >> 8U) & NETC_ETHSWT_IP_0XFF_MASK);
1198 
1199             FdbTableList[(*NumOfExistingEntry)].FID = (uint16)(TableDataBuffer.TableDataField[NETC_ETHSWT_FDBTABLE_RSPDATA_FID] & NETC_ETHSWT_IP_FDBTABLE_KEYE_DATA_FID_MASK);
1200             FdbTableList[(*NumOfExistingEntry)].SwitchPortEgressBitMask = (TableDataBuffer.TableDataField[NETC_ETHSWT_FDBTABLE_RSPDATA_PORTBITMAP] & NETC_ETHSWT_IP_FDBTABLE_CFGE_PORT_BITMAP_MASK);
1201 
1202             CfgeData = TableDataBuffer.TableDataField[NETC_ETHSWT_FDBTABLE_RSPDATA_CFGECONFIG];
1203             FdbTableList[(*NumOfExistingEntry)].TimeStampCapture = (((CfgeData & NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_TIMECAPE_MASK) >> NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_TIMECAPE_SHIFT) != 0x0UL) ? TRUE : FALSE;
1204             FdbTableList[(*NumOfExistingEntry)].DynamicEntry = (((CfgeData & NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_DYNAMIC_MASK) >> NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_DYNAMIC_SHIFT) != 0x0UL) ? TRUE : FALSE;
1205             FdbTableList[(*NumOfExistingEntry)].CutThroughDisable = (uint8)((CfgeData & NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_CTD_MASK) >> NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_CTD_SHIFT);
1206             FdbTableList[(*NumOfExistingEntry)].IngressMirroringEnable = (((CfgeData & NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_IMIRE_MASK) >> NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_IMIRE_SHIFT) != 0x0UL) ? TRUE : FALSE;
1207             FdbTableList[(*NumOfExistingEntry)].EgressPort = (uint8)((CfgeData & NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_EPORT_MASK) >> NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_EPORT_SHIFT);
1208             FdbTableList[(*NumOfExistingEntry)].OverridETEID = (uint8)(CfgeData & NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_OETEID_MASK);
1209 
1210             FdbTableList[(*NumOfExistingEntry)].ET_EID = TableDataBuffer.TableDataField[NETC_ETHSWT_FDBTABLE_RSPDATA_ETEID];
1211 
1212             /* increase the NumOfExistingEntry */
1213             (*NumOfExistingEntry) += 1U;
1214         }
1215 
1216         VerifyFillInFdbTableListDataFuncCond(ResumeId, StatciEntryQuerying, QueryDone);
1217     }
1218     else
1219     {
1220         status = E_NOT_OK;
1221     }
1222 
1223     return status;
1224 }
1225 
1226 /*FUNCTION**********************************************************************
1227  *
1228  * Function Name : Netc_EthSwt_Ip_GetFdbTable
1229  * Description   : Ethernet Switch get FDB table function.
1230  * implements Netc_EthSwt_Ip_GetFdbTable_Activity
1231  *END**************************************************************************/
Netc_EthSwt_Ip_GetFdbTable(uint8 SwitchIdx,uint16 * NumberOfElements,Netc_EthSwt_Ip_FdbEntryDataType * FdbTableList)1232 Std_ReturnType Netc_EthSwt_Ip_GetFdbTable( uint8 SwitchIdx,
1233                                            uint16 * NumberOfElements,
1234                                            Netc_EthSwt_Ip_FdbEntryDataType * FdbTableList
1235                                          )
1236 {
1237     Std_ReturnType status = E_OK;
1238     uint16 NumOfExistingEntry = 0U;
1239     uint16 NumOfInUseEntry;
1240     uint32 ResumeId = NETC_ETHSWT_IP_BD_NULL_ENTRY_ID;
1241     boolean StatciEntryQuerying = TRUE;
1242     boolean QueryDone = FALSE;
1243 
1244     /* [notes]: we will have to read entries one by one because of the errata ERR051048.
1245      - ERR051048: NETC: Management command with search action responds with incorrect NUM_MATCHED
1246      - Description: The NUM_MATCHED field in the command NTMP response header may be incorrect when
1247        the search access method is used for the following tables: FDB table 15, L2 IPv4 Multicast
1248        Filter table 16, VLAN Filter table 18, Ingress Stream Identification table 30, or Ingress Stream
1249        Filter table 32.
1250      - Workaround: For the query command, limit the message response buffer size (RESPONSE_LENGTH field in the request header)
1251        so that NETC returns no more than one entry at a time. Under this condition, the NUM_MATCHED field value is correct
1252     */
1253 
1254 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
1255     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
1256     DevAssert(NumberOfElements != NULL_PTR);
1257     if (*NumberOfElements > 0U)
1258     {
1259         DevAssert(FdbTableList != NULL_PTR);
1260     }
1261 #endif
1262 
1263     /*
1264     * Number of static FDB entries in-use (hash-based and CAM-based entries) is indicated in FDBHTOR0[STATIC_ENTRIES].
1265     * Number of dynamic FDB entries in-use (hash-based and CAMbased entries) is indicated in FDBHTOR1[DYN_ENTRIES].
1266     */
1267     NumOfInUseEntry = (uint16)(IP_NETC__SW0_BASE->FDBHTOR0 & NETC_ETHSWT_IP_0XFFFF_MASK) + (uint16)(IP_NETC__SW0_BASE->FDBHTOR1 & NETC_ETHSWT_IP_0XFFFF_MASK);    /* get how many entries exist in module */
1268 
1269     /* if *NumberOfElements == 0U or NumOfInUseEntry == 0U, return the NumOfInUseEntry directly and will not do the query and fill in the structure */
1270     if ((*NumberOfElements == 0U) || (NumOfInUseEntry == 0U))
1271     {
1272         NumOfExistingEntry = NumOfInUseEntry;
1273     }
1274     else    /* if *NumberOfElements > 0, do the query and fill in the structure */
1275     {
1276         do {
1277             /* check if the FdbTableList is full or we get all existing entries */
1278             if ((NumOfExistingEntry >= *NumberOfElements) || (NumOfExistingEntry >= NumOfInUseEntry) || (status == (uint8)(E_NOT_OK)) || (QueryDone == TRUE))
1279             {
1280                 break;
1281             }
1282 
1283             status = SearchAndFillInFdbTableList(&ResumeId, &NumOfExistingEntry, FdbTableList, &StatciEntryQuerying, &QueryDone);
1284 
1285         } while ((TableDataBuffer.TableDataField[NETC_ETHSWT_FDBTABLE_RSPDATA_STATUS] != NETC_ETHSWT_IP_BD_NULL_ENTRY_ID) || (FALSE == StatciEntryQuerying));      /* Status == 0xFFFFFFFF means the query operation is completed */
1286     }
1287 
1288     /* return the Number of elements which are currently available in the EthSwitch module or number of elements copied to FdbTableList*/
1289     *NumberOfElements = NumOfExistingEntry;
1290 
1291     return status;
1292 }
1293 
1294 /* inline function for filling in TableDataBuff in Netc_EthSwt_Ip_SearchFdbTable() function. */
FillInTableDataBuffForSearchingFDBTable(const uint32 * ResumeEntryId,const Netc_EthSwt_Ip_FDBTableSearchCriteriaDataType * SearchCriteriaData)1295 static inline void FillInTableDataBuffForSearchingFDBTable(const uint32 * ResumeEntryId, const Netc_EthSwt_Ip_FDBTableSearchCriteriaDataType * SearchCriteriaData)
1296 {
1297     uint32 ActionsData;
1298     uint8 MatchCriteriaData;
1299 
1300     /* set the querry options with full querry */
1301     ActionsData = NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD_QUERY_ACTIONS(NETC_ETHSWT_TABLES_FULL_QUERY) \
1302                 | NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD_DEBUG_OPTIONS(0U) \
1303                 | NETC_ETHSWT_IP_FDBTABLE_REQFMT_ACTIONS_FIELD_ACTEU(0U) \
1304                 | NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD_CFGEU(0U);
1305 
1306     /* +++ fill in FdbTabeDataBuffer for request +++ */
1307     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD] = ActionsData;
1308 
1309     /* fill in Access Key data with search criteria data format */
1310     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_RESUMEENTRYID] = *ResumeEntryId;    /* ResumeEntryId should start from 0xFFFFFFFF */
1311     /* no need to fill in ETEID data for searching purpose */
1312     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_ETEID] = 0U;
1313 
1314     /* remap and fill in Match Criteria flag */
1315     if (SearchCriteriaData->SearchMatchCriteria >= NETC_ETHSWT_IP_FDBTABLE_MATCH_KEYE_FID_FIELD)
1316     {
1317         MatchCriteriaData = ((uint8)(SearchCriteriaData->SearchMatchCriteria) - NETC_ETHSWT_IP_FDBTABLE_KEYE_MATCH_CRITERIA_ADJUSTING_FACTOR);
1318         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_MATCHCRITERIA] = NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_KEYEMC(MatchCriteriaData);
1319 
1320         /* fill in Key Element Match Criteria data */
1321         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_MACADDRESS_L] = NETC_ETHSWT_IP_MULTICASTBIT_OF_MAC_ADDRESS(SearchCriteriaData->SearchKeyeData.SearchMulticastMacAddr ? 1U : 0U);
1322         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_FID] = SearchCriteriaData->SearchKeyeData.SearchFid;
1323     }
1324     else if (SearchCriteriaData->SearchMatchCriteria >= NETC_ETHSWT_IP_FDBTABLE_MATCH_CFGE_DYNAMIC_FIELD)
1325     {
1326         MatchCriteriaData = ((uint8)(SearchCriteriaData->SearchMatchCriteria) - NETC_ETHSWT_IP_FDBTABLE_CFGE_MATCH_CRITERIA_ADJUSTING_FACTOR);
1327         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_MATCHCRITERIA] = NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_CFGEMC(MatchCriteriaData);
1328 
1329         /* fill in CFGE Match Criteria data*/
1330         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_PORTBITMAP] = SearchCriteriaData->SearchCfgeData.SearchPortBitMap;
1331         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_CFGECONFIG] = NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_DYNAMIC(SearchCriteriaData->SearchCfgeData.SearchDynamicEntry ? 1U : 0U);
1332     }
1333     else if (SearchCriteriaData->SearchMatchCriteria == NETC_ETHSWT_IP_FDBTABLE_MATCH_ACTE_DATA_FIELD)
1334     {
1335         MatchCriteriaData = (uint8)(SearchCriteriaData->SearchMatchCriteria);
1336         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_MATCHCRITERIA] = NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_ACTEMC(MatchCriteriaData);
1337 
1338         /* fill in ACTE Match Criteria data*/
1339         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_MATCHCRITERIA] |= (NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_ACTCNT(SearchCriteriaData->SearchActeData.ActivityCounter) \
1340                                                                                                 | NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_ACTFLAG(SearchCriteriaData->SearchActeData.ActivityFlag ? 1U : 0U));
1341     }
1342     else
1343     {
1344         /* MATCH_ANY_CRITERIA */
1345         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_MATCHCRITERIA] = 0x0UL;
1346     }
1347 
1348     /* --- fill in FdbTabeDataBuffer for request --- */
1349 }
1350 /*FUNCTION**********************************************************************
1351  *
1352  * Function Name : Netc_EthSwt_Ip_SearchFdbTable
1353  * Description   : Ethernet Switch search FDB table one by one.
1354  * implements Netc_EthSwt_Ip_SearchFdbTable_Activity
1355  *END**************************************************************************/
Netc_EthSwt_Ip_SearchFdbTable(uint8 SwitchIdx,uint32 * ResumeEntryId,const Netc_EthSwt_Ip_FDBTableSearchCriteriaDataType * SearchCriteriaData,Netc_EthSwt_Ip_FdbEntryDataType * FdbTableEntry)1356 Std_ReturnType Netc_EthSwt_Ip_SearchFdbTable( uint8 SwitchIdx,
1357                                               uint32 * ResumeEntryId,
1358                                               const Netc_EthSwt_Ip_FDBTableSearchCriteriaDataType * SearchCriteriaData,
1359                                               Netc_EthSwt_Ip_FdbEntryDataType * FdbTableEntry
1360                                             )
1361 {
1362     Std_ReturnType status = E_OK;
1363     Netc_EthSwt_Ip_CBDRStatusType CBDRStatus;
1364     uint8 MacBeyteIdx;
1365     uint32 MacAddrL;
1366     uint32 MacAddrH;
1367     uint32 CfgeData;
1368     NetcEthSwt_Ip_ReqHeaderTableOperationDataType OperationData;
1369     uint32 NumOfElement = 0U;
1370     uint32 TableEntryId;
1371 
1372 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
1373     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
1374     DevAssert(SearchCriteriaData != NULL_PTR);
1375     DevAssert(SearchCriteriaData->SearchMatchCriteria <= (NETC_ETHSWT_IP_FDBTABLE_MATCH_KEYE_FID_AND_MULTICAST_BIT_OF_MACADDR));
1376     DevAssert(FdbTableEntry != NULL_PTR);
1377 #endif
1378 
1379     /* +++ fill in FdbTabeDataBuffer for request +++ */
1380     FillInTableDataBuffForSearchingFDBTable(ResumeEntryId, SearchCriteriaData);
1381     /* --- fill in FdbTabeDataBuffer for request --- */
1382 
1383     /* do the full querry with Search Method */
1384     /* fill in operation data for config field of Request Header*/
1385     OperationData.CmdCompletionInt = 0x0U;                                        /* command completion interrupt disabled */
1386     OperationData.Version = NETC_ETHSWT_IP_CMDBD_REQFMT_PROTOCOL_VERSION;         /* protocol version = 2 */
1387     OperationData.TableId = NETC_ETHSWT_IP_FDB_TABLE_ID;
1388     OperationData.AccessMethod = NETC_ETHSWT_SEARCH_METHOD;
1389     OperationData.Cmd = NETC_ETHSWT_QUERY_CMD;
1390     OperationData.ReqBuffLength = (NETC_ETHSWT_IP_TABLE_REQBUFFER_LEN);
1391     OperationData.RspBuffLength = (NETC_ETHSWT_IP_TABLE_RESBUFFER_LEN);           /* full query needs more space for response data */
1392 
1393     /* send the "Query" command */
1394     /* [notes]: there is an error "0x8A" in NTMP response header during this query operation but it is not a real error. there should be another errata for "0x8A" later. */
1395     CBDRStatus = Netc_EthSwt_Ip_SendCommand(SwitchIdx, NETC_ETHSWT_IP_CBDR_0, &OperationData);
1396 
1397     if ((CBDRStatus == 0x8AU) || (CBDRStatus == NETC_ETHSWT_CBDRSTATUS_SUCCES))
1398     {
1399         /* check if found a matched entry */
1400         Netc_EthSwt_Ip_GetMatchedEntries(NETC_ETHSWT_IP_CBDR_0, &NumOfElement);
1401 
1402         /* found a matched entry */
1403         TableEntryId = TableDataBuffer.TableDataField[NETC_ETHSWT_FDBTABLE_RSPDATA_STATUS];
1404         if ((1U == NumOfElement) && (TableEntryId != NETC_ETHSWT_IP_BD_NULL_ENTRY_ID))
1405         {
1406             /* fill in "Netc_EthSwt_Ip_FdbEntryDataType" structure with data in response data buffer */
1407             MacAddrL = TableDataBuffer.TableDataField[NETC_ETHSWT_FDBTABLE_RSPDATA_MACADDRESS_L];
1408             MacAddrH = TableDataBuffer.TableDataField[NETC_ETHSWT_FDBTABLE_RSPDATA_MACADDRESS_H];
1409             for (MacBeyteIdx = 0U; MacBeyteIdx < 4U; MacBeyteIdx++ )
1410             {
1411                 FdbTableEntry->MacAddr[MacBeyteIdx] = (uint8)(MacAddrL & NETC_ETHSWT_IP_0XFF_MASK);
1412                 MacAddrL >>= 8U;
1413             }
1414             FdbTableEntry->MacAddr[4U] = (uint8)(MacAddrH & NETC_ETHSWT_IP_0XFF_MASK);
1415             FdbTableEntry->MacAddr[5U] = (uint8)((MacAddrH >> 8U) & NETC_ETHSWT_IP_0XFF_MASK);
1416 
1417             FdbTableEntry->FID = (uint16)(TableDataBuffer.TableDataField[NETC_ETHSWT_FDBTABLE_RSPDATA_FID] & NETC_ETHSWT_IP_FDBTABLE_KEYE_DATA_FID_MASK);
1418             FdbTableEntry->SwitchPortEgressBitMask = TableDataBuffer.TableDataField[NETC_ETHSWT_FDBTABLE_RSPDATA_PORTBITMAP] & NETC_ETHSWT_IP_FDBTABLE_CFGE_PORT_BITMAP_MASK;
1419 
1420             CfgeData = TableDataBuffer.TableDataField[NETC_ETHSWT_FDBTABLE_RSPDATA_CFGECONFIG];
1421             FdbTableEntry->TimeStampCapture = (((CfgeData & NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_TIMECAPE_MASK) >> NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_TIMECAPE_SHIFT) == 0x0UL) ? FALSE : TRUE;
1422             FdbTableEntry->DynamicEntry = (((CfgeData & NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_DYNAMIC_MASK) >> NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_DYNAMIC_SHIFT) == 0x0UL) ? FALSE : TRUE;
1423             FdbTableEntry->CutThroughDisable = (uint8)((CfgeData & NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_CTD_MASK) >> NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_CTD_SHIFT);
1424             FdbTableEntry->IngressMirroringEnable = (((CfgeData & NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_IMIRE_MASK) >> NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_IMIRE_SHIFT) == 0x0UL) ? FALSE : TRUE;
1425             FdbTableEntry->EgressPort = (uint8)((CfgeData & NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_EPORT_MASK) >> NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_EPORT_SHIFT);
1426             FdbTableEntry->OverridETEID = (uint8)(CfgeData & NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_OETEID_MASK);
1427 
1428             FdbTableEntry->ET_EID = TableDataBuffer.TableDataField[NETC_ETHSWT_FDBTABLE_RSPDATA_ETEID];
1429         }
1430 
1431         /* get the resume_entry_id and be ready for the next query operation */
1432         /* [notes]: if the searching is completed, or there is no matched entry found, then TableDataBuffer.TableDataField[0U] will be writen with 0xFFFFFFFF by hardware */
1433         *ResumeEntryId = TableDataBuffer.TableDataField[NETC_ETHSWT_FDBTABLE_RSPDATA_STATUS];
1434     }
1435     else
1436     {
1437         status = E_NOT_OK;
1438     }
1439 
1440     return status;
1441 }
1442 
1443 /* inline function for searching and filling in VlanFilterTableList in function Netc_EthSwt_Ip_GetVlanFilterTable() */
SearchAndFIllInVlanFilterTableList(uint32 * ResumeId,uint16 * NumOfExistingEntry,Netc_EthSwt_Ip_VlanFilterEntryDataType * VlanFilterTableList)1444 static inline Std_ReturnType SearchAndFIllInVlanFilterTableList(uint32 *ResumeId, uint16 *NumOfExistingEntry, Netc_EthSwt_Ip_VlanFilterEntryDataType * VlanFilterTableList)
1445 {
1446     Std_ReturnType status = E_OK;
1447     uint32 ActionsData;
1448     Netc_EthSwt_Ip_CBDRStatusType CBDRStatus;
1449     NetcEthSwt_Ip_ReqHeaderTableOperationDataType OperationData = {0U};
1450     uint32 NumOfElement = 0U;
1451     uint32 CfgeData;
1452 
1453     /* set the querry options with full querry */
1454     ActionsData = (NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD_QUERY_ACTIONS(NETC_ETHSWT_TABLES_FULL_QUERY) \
1455                 | NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD_DEBUG_OPTIONS(0U));
1456 
1457     /* fill in TabeDataBuffer for request */
1458     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD] = ActionsData;
1459     /* fill in Access Key data with search criteria data format */
1460     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_VLANFILTERTABLE_REQFMT_RESUMEENTRYID_FIELD] = *ResumeId;    /* resume entry id */
1461 
1462     /* do the full querry with Search Method */
1463     /* fill in operation data for config field of Request Header*/
1464     OperationData.CmdCompletionInt = 0x0U;                                        /* command completion interrupt disabled */
1465     OperationData.Version = NETC_ETHSWT_IP_CMDBD_REQFMT_PROTOCOL_VERSION;         /* protocol version = 2 */
1466     OperationData.TableId = NETC_ETHSWT_IP_VLAN_FILTER_TABLE_ID;
1467     OperationData.AccessMethod = NETC_ETHSWT_SEARCH_METHOD;
1468     OperationData.Cmd = NETC_ETHSWT_QUERY_CMD;
1469     OperationData.ReqBuffLength = (NETC_ETHSWT_IP_TABLE_REQBUFFER_LEN);
1470     OperationData.RspBuffLength = (NETC_ETHSWT_IP_TABLE_RESBUFFER_LEN);           /* full query needs more space for response data */
1471 
1472     /* send the "Query" command */
1473     /* [notes]: there is an error "0x8A" in NTMP response header during this query operation but it is not a real error. there should be another errata for "0x8A" later. */
1474     CBDRStatus = Netc_EthSwt_Ip_SendCommand(0U, NETC_ETHSWT_IP_CBDR_0, &OperationData);
1475 
1476     /* check the status of querry command */
1477     if ((CBDRStatus == 0x8AU) || (CBDRStatus == NETC_ETHSWT_CBDRSTATUS_SUCCES))
1478     {
1479         Netc_EthSwt_Ip_GetMatchedEntries(NETC_ETHSWT_IP_CBDR_0, &NumOfElement);
1480 
1481         /* get the resume_entry_id and be ready for the next query operation */
1482         *ResumeId = TableDataBuffer.TableDataField[NETC_ETHSWT_VLANFILTERTABLE_RSPDATA_STATUS];
1483 
1484         /* found a matched entry */
1485         if ((1U == NumOfElement) && (*ResumeId != NETC_ETHSWT_IP_BD_NULL_ENTRY_ID))
1486         {
1487             /* fill in "Netc_EthSwt_Ip_VlanFilterEntryDataType" structure with data in response data buffer */
1488             VlanFilterTableList[(*NumOfExistingEntry)].VlanID = TableDataBuffer.TableDataField[NETC_ETHSWT_VLANFILTERTABL_RSPDATA_VID] & NETC_ETHSWT_VLANFILTERTABLE_KEYEDATA_VID_MASK;
1489 
1490             CfgeData = TableDataBuffer.TableDataField[NETC_ETHSWT_VLANFILTERTABL_RSPDATA_CFGEDATA0];
1491             VlanFilterTableList[(*NumOfExistingEntry)].SpanningTreeGroupMemberId = (uint8)((CfgeData & NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_STG_ID_MASK) >> NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_STG_ID_SHIFT);
1492             VlanFilterTableList[(*NumOfExistingEntry)].PortMembershipBitmap = (CfgeData & NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_PORT_MEMBERSHIP_MASK);
1493 
1494             CfgeData = TableDataBuffer.TableDataField[NETC_ETHSWT_VLANFILTERTABL_RSPDATA_CFGEDATA1];
1495             VlanFilterTableList[(*NumOfExistingEntry)].FID = (uint16)(CfgeData & NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_FID_MASK);
1496             VlanFilterTableList[(*NumOfExistingEntry)].MacLearningOptions = (uint8)((CfgeData & NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_MLO_MASK) >> NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_MLO_SHIFT);
1497             VlanFilterTableList[(*NumOfExistingEntry)].MacForwardingOptions = (uint8)((CfgeData & NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_MFO_MASK) >> NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_MFO_SHIFT);
1498             VlanFilterTableList[(*NumOfExistingEntry)].IpMulticastFilteringEnable = (((CfgeData & NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_IPMFE_MASK) >> NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_IPMFE_SHIFT) == 0x0UL) ? FALSE : TRUE;
1499             VlanFilterTableList[(*NumOfExistingEntry)].IpMulticastFloodingEnable = (((CfgeData & NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_IPMFLE_MASK) >> NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_IPMFLE_SHIFT) == 0x0UL) ? FALSE : TRUE;
1500 
1501             VlanFilterTableList[(*NumOfExistingEntry)].EgressTreatmentApplicabilityPortBitmap = TableDataBuffer.TableDataField[NETC_ETHSWT_VLANFILTERTABL_RSPDATA_CFGEDATA2] & NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_ETA_PORT_BITMAP_MASK;
1502             VlanFilterTableList[(*NumOfExistingEntry)].BaseEgressTreatmentEntryID = TableDataBuffer.TableDataField[NETC_ETHSWT_VLANFILTERTABL_RSPDATA_CFGEDATA3];
1503 
1504             /* increase the NumOfExistingEntry */
1505             (*NumOfExistingEntry) += 1U;
1506         }
1507     }
1508     else
1509     {
1510         status = E_NOT_OK;
1511     }
1512 
1513     return status;
1514 }
1515 
1516 /*FUNCTION**********************************************************************
1517  *
1518  * Function Name : Netc_EthSwt_Ip_GetVlanFilterTable
1519  * Description   : Ethernet Switch get Vlan Filter table function.
1520  * implements Netc_EthSwt_Ip_GetVlanFilterTable_Activity
1521  *END**************************************************************************/
Netc_EthSwt_Ip_GetVlanFilterTable(uint8 SwitchIdx,uint16 * NumberOfElements,Netc_EthSwt_Ip_VlanFilterEntryDataType * VlanFilterTableList)1522 Std_ReturnType Netc_EthSwt_Ip_GetVlanFilterTable( uint8 SwitchIdx,
1523                                                   uint16 * NumberOfElements,
1524                                                   Netc_EthSwt_Ip_VlanFilterEntryDataType * VlanFilterTableList
1525                                                 )
1526 {
1527     Std_ReturnType status = E_OK;
1528     uint16 NumOfExistingEntry = 0U;
1529     uint16 NumOfInUseEntry;
1530     uint32 ResumeId = NETC_ETHSWT_IP_BD_NULL_ENTRY_ID;
1531 
1532     /* [notes]: we will have to read entries one by one because of the errata ERR051048.
1533      - ERR051048: NETC: Management command with search action responds with incorrect NUM_MATCHED
1534      - Description: The NUM_MATCHED field in the command NTMP response header may be incorrect when
1535        the search access method is used for the following tables: FDB table 15, L2 IPv4 Multicast
1536        Filter table 16, VLAN Filter table 18, Ingress Stream Identification table 30, or Ingress Stream
1537        Filter table 32.
1538      - Workaround: For the query command, limit the message response buffer size (RESPONSE_LENGTH field in the request header)
1539        so that NETC returns no more than one entry at a time. Under this condition, the NUM_MATCHED field value is correct
1540     */
1541 
1542 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
1543     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
1544     DevAssert(NumberOfElements != NULL_PTR);
1545     if (*NumberOfElements > 0U)
1546     {
1547         DevAssert(VlanFilterTableList != NULL_PTR);
1548     }
1549 #endif
1550 
1551     /* Number of entries in-use by the VLAN Filter table is indicated in VFHTOR[NUM_ENTRIES]. */
1552     NumOfInUseEntry = (uint16)(IP_NETC__SW0_BASE->VFHTOR & NETC_ETHSWT_IP_0XFFFF_MASK);    /* get how many entries exist in module */
1553 
1554     /* if *NumberOfElements == 0U or NumOfInUseEntry == 0U, return the NumOfInUseEntry directly and will not do the query and fill in the structure */
1555     if ((*NumberOfElements == 0U) || (NumOfInUseEntry == 0U))
1556     {
1557         NumOfExistingEntry = NumOfInUseEntry;
1558     }
1559     else    /* if *NumberOfElements > 0, do the query and fill in the structure */
1560     {
1561         do {
1562             /* check if the VlanFilterTableList is full or we get all existing entries */
1563             if ((NumOfExistingEntry >= *NumberOfElements) || (NumOfExistingEntry >= NumOfInUseEntry) || (status == (uint8)(E_NOT_OK)))
1564             {
1565                 break;
1566             }
1567 
1568             status = SearchAndFIllInVlanFilterTableList(&ResumeId, &NumOfExistingEntry, VlanFilterTableList);
1569         } while (TableDataBuffer.TableDataField[NETC_ETHSWT_VLANFILTERTABLE_RSPDATA_STATUS] != NETC_ETHSWT_IP_BD_NULL_ENTRY_ID);      /* Status == 0xFFFFFFFF means the query operation is completed */
1570     }
1571 
1572     /* return the Number of elements which are currently available in the EthSwitch module or number of elements copied to VlanFilterTableList*/
1573     *NumberOfElements = NumOfExistingEntry;
1574 
1575     return status;
1576 }
1577 
1578 /*FUNCTION**********************************************************************
1579  *
1580  * Function Name : Netc_EthSwt_Ip_AddOrUpdateVlanFilterTableEntry
1581  * Description   : Ethernet Switch add, update or addorupdate Vlan Filter table entry function.
1582  * implements Netc_EthSwt_Ip_AddOrUpdateVlanFilterTableEntry_Activity
1583  *END**************************************************************************/
Netc_EthSwt_Ip_AddOrUpdateVlanFilterTableEntry(uint8 SwitchIdx,Netc_EthSwt_Ip_CommandsType Cmd,uint32 * MatchedEntries,const Netc_EthSwt_Ip_VlanFilterEntryDataType * VlanFilterTableEntry)1584 Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_AddOrUpdateVlanFilterTableEntry( uint8 SwitchIdx,
1585                                                                               Netc_EthSwt_Ip_CommandsType Cmd,
1586                                                                               uint32 *MatchedEntries,
1587                                                                               const Netc_EthSwt_Ip_VlanFilterEntryDataType * VlanFilterTableEntry
1588                                                                             )
1589 {
1590     Netc_EthSwt_Ip_CBDRStatusType status;
1591     uint32 AccessKeyData;
1592     uint32 ActionsData;
1593     Netc_EthSwt_Ip_VlanFilterTableCFGEDataType VlanFilterCfgeData;
1594     NetcEthSwt_Ip_ReqHeaderTableOperationDataType OperationData;
1595 
1596 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
1597     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
1598     DevAssert(MatchedEntries != NULL_PTR);
1599     DevAssert(VlanFilterTableEntry != NULL_PTR);
1600 #endif
1601 
1602     /* only support Add, Update and AddOrUpdate commands */
1603     if ((NETC_ETHSWT_ADD_CMD != Cmd) && (NETC_ETHSWT_UPDATE_CMD != Cmd) && (NETC_ETHSWT_ADD_OR_UPDATE_CMD != Cmd))
1604     {
1605         status = NETC_ETHSWT_CBDRSTATUS_INVALID_CMD;    /* not supported command */
1606     }
1607     else
1608     {
1609         /* fill in Vlan Filter Table Request Data Buffer */
1610         ActionsData = NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD_CFGEU(1U);
1611 
1612         AccessKeyData = VlanFilterTableEntry->VlanID;
1613 
1614         VlanFilterCfgeData.Cfge_Data[0U] = (NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_STG_ID(VlanFilterTableEntry->SpanningTreeGroupMemberId) \
1615                                         | NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_PORT_MEMBERSHIP(VlanFilterTableEntry->PortMembershipBitmap));
1616         VlanFilterCfgeData.Cfge_Data[1U] = (NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_IPMFLE(VlanFilterTableEntry->IpMulticastFloodingEnable ? 1U :0U) \
1617                                         | NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_IPMFE(VlanFilterTableEntry->IpMulticastFilteringEnable ? 1U : 0U) \
1618                                         | NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_MFO(VlanFilterTableEntry->MacForwardingOptions) \
1619                                         | NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_MLO(VlanFilterTableEntry->MacLearningOptions) \
1620                                         | NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_FID(VlanFilterTableEntry->FID));
1621         VlanFilterCfgeData.Cfge_Data[2U] = NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_ETA_PORT_BITMAP(VlanFilterTableEntry->EgressTreatmentApplicabilityPortBitmap);
1622         VlanFilterCfgeData.Cfge_Data[3U] = NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_BASE_ET_EID(VlanFilterTableEntry->BaseEgressTreatmentEntryID);
1623 
1624         /* For Add, Update and AddOrUpdate commands, we only provide NETC_ETHSWT_EXACT_MATCH_KEY_ELEMENT_MATCH method for users */
1625         status = Netc_EthSwt_Ip_FillInVlanFilterTableReqDataBuff(ActionsData, AccessKeyData, &VlanFilterCfgeData, NETC_ETHSWT_EXACT_MATCH_KEY_ELEMENT_MATCH);
1626         if (NETC_ETHSWT_CBDRSTATUS_SUCCES == status)
1627         {
1628             /* fill in operation data for config field of Request Header*/
1629             OperationData.CmdCompletionInt = 0x0U;                                        /* command completion interrupt disabled */
1630             OperationData.Version = NETC_ETHSWT_IP_CMDBD_REQFMT_PROTOCOL_VERSION;         /* protocol version = 2 */
1631             OperationData.TableId = NETC_ETHSWT_IP_VLAN_FILTER_TABLE_ID;
1632             OperationData.AccessMethod = NETC_ETHSWT_EXACT_MATCH_KEY_ELEMENT_MATCH;        /* for Add command, the Access Method should only be NETC_ETHSWT_EXACT_MATCH_KEY_ELEMENT_MATCH */
1633             OperationData.Cmd = Cmd;
1634             OperationData.ReqBuffLength = (NETC_ETHSWT_IP_TABLE_REQBUFFER_LEN);
1635             OperationData.RspBuffLength = (NETC_ETHSWT_IP_TABLE_RESBUFFER_LEN);
1636 
1637             /* send the command */
1638             status = Netc_EthSwt_Ip_SendCommand(SwitchIdx, NETC_ETHSWT_IP_CBDR_0, &OperationData);
1639             /* Erroe code 0x8A is not a real error. check it on Errata. */
1640             if ((status == 0x8AU) || (status == NETC_ETHSWT_CBDRSTATUS_SUCCES))
1641             {
1642                 Netc_EthSwt_Ip_GetMatchedEntries(NETC_ETHSWT_IP_CBDR_0, MatchedEntries);
1643             }
1644         }
1645         else
1646         {
1647             status = NETC_ETHSWT_CBDRSTATUS_ACCESSMETHOD_ERROR;
1648         }
1649     }
1650 
1651     return status;
1652 }
1653 
1654 /*FUNCTION**********************************************************************
1655  *
1656  * Function Name : Netc_EthSwt_Ip_QueryVlanFilterTableEntry
1657  * Description   : Ethernet Switch query Vlan Filter table entry function.
1658  * implements Netc_EthSwt_Ip_QueryVlanFilterTableEntry_Activity
1659  *END**************************************************************************/
Netc_EthSwt_Ip_QueryVlanFilterTableEntry(uint8 SwitchIdx,uint32 * MatchedEntries,Netc_EthSwt_Ip_VlanFilterEntryDataType * VlanFilterTableEntry)1660 Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_QueryVlanFilterTableEntry( uint8 SwitchIdx,
1661                                                                         uint32 *MatchedEntries,
1662                                                                         Netc_EthSwt_Ip_VlanFilterEntryDataType * VlanFilterTableEntry
1663                                                                       )
1664 {
1665     Netc_EthSwt_Ip_CBDRStatusType status;
1666     uint32 AccessKeyData;
1667     uint32 ActionsData;
1668     uint32 CfgeData;
1669     NetcEthSwt_Ip_ReqHeaderTableOperationDataType OperationData;
1670 
1671 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
1672     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
1673     DevAssert(MatchedEntries != NULL_PTR);
1674 #endif
1675 
1676     /* fill in Vlan Filter Table Request Data Buffer */
1677     ActionsData = NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD_QUERY_ACTIONS(NETC_ETHSWT_TABLES_FULL_QUERY);        /* for "query" command we only provide "full query" for users */
1678 
1679     AccessKeyData = VlanFilterTableEntry->VlanID;
1680 
1681     /* for query command, we don't need the CFGE_DATA field */
1682     status = Netc_EthSwt_Ip_FillInVlanFilterTableReqDataBuff(ActionsData, AccessKeyData, NULL_PTR, NETC_ETHSWT_EXACT_MATCH_KEY_ELEMENT_MATCH);
1683     if (NETC_ETHSWT_CBDRSTATUS_SUCCES == status)
1684     {
1685         /* fill in operation data for config field of NTMP Request Header*/
1686         OperationData.CmdCompletionInt = 0x0U;                                        /* command completion interrupt disabled */
1687         OperationData.Version = NETC_ETHSWT_IP_CMDBD_REQFMT_PROTOCOL_VERSION;         /* protocol version = 2 */
1688         OperationData.TableId = NETC_ETHSWT_IP_VLAN_FILTER_TABLE_ID;
1689         OperationData.AccessMethod = NETC_ETHSWT_EXACT_MATCH_KEY_ELEMENT_MATCH;
1690         OperationData.Cmd = NETC_ETHSWT_QUERY_CMD;
1691         OperationData.ReqBuffLength = (NETC_ETHSWT_IP_TABLE_REQBUFFER_LEN);            /* set request data buffer length */
1692         OperationData.RspBuffLength = (NETC_ETHSWT_IP_TABLE_RESBUFFER_LEN);            /* set response data buffer length */
1693 
1694         /* send the "Query" command */
1695         status = Netc_EthSwt_Ip_SendCommand(SwitchIdx, NETC_ETHSWT_IP_CBDR_0, &OperationData);
1696         /* Erroe code 0x8A is not a real error. check it on Errata. */
1697         if ((status == 0x8AU) || (status == NETC_ETHSWT_CBDRSTATUS_SUCCES))
1698         {
1699             Netc_EthSwt_Ip_GetMatchedEntries(NETC_ETHSWT_IP_CBDR_0, MatchedEntries);
1700 
1701             /* found a matched entry */
1702             if (1U == *MatchedEntries)
1703             {
1704                 /* fill in "Netc_EthSwt_Ip_VlanFilterEntryDataType" structure with data in response data buffer */
1705                 VlanFilterTableEntry->VlanID = TableDataBuffer.TableDataField[NETC_ETHSWT_VLANFILTERTABL_RSPDATA_VID] & NETC_ETHSWT_VLANFILTERTABLE_KEYEDATA_VID_MASK;
1706 
1707                 CfgeData = TableDataBuffer.TableDataField[NETC_ETHSWT_VLANFILTERTABL_RSPDATA_CFGEDATA0];
1708                 VlanFilterTableEntry->SpanningTreeGroupMemberId = (uint8)((CfgeData & NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_STG_ID_MASK) >> NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_STG_ID_SHIFT);
1709                 VlanFilterTableEntry->PortMembershipBitmap = (CfgeData & NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_PORT_MEMBERSHIP_MASK);
1710 
1711                 CfgeData = TableDataBuffer.TableDataField[NETC_ETHSWT_VLANFILTERTABL_RSPDATA_CFGEDATA1];
1712                 VlanFilterTableEntry->FID = (uint16)(CfgeData & NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_FID_MASK);
1713                 VlanFilterTableEntry->MacLearningOptions = (uint8)((CfgeData & NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_MLO_MASK) >> NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_MLO_SHIFT);
1714                 VlanFilterTableEntry->MacForwardingOptions = (uint8)((CfgeData & NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_MFO_MASK) >> NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_MFO_SHIFT);
1715                 VlanFilterTableEntry->IpMulticastFilteringEnable = (((CfgeData & NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_IPMFE_MASK) >> NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_IPMFE_SHIFT) != 0x0UL) ? TRUE : FALSE;
1716                 VlanFilterTableEntry->IpMulticastFloodingEnable = (((CfgeData & NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_IPMFLE_MASK) >> NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_IPMFLE_SHIFT) != 0x0UL) ? TRUE : FALSE;
1717 
1718                 VlanFilterTableEntry->EgressTreatmentApplicabilityPortBitmap = TableDataBuffer.TableDataField[NETC_ETHSWT_VLANFILTERTABL_RSPDATA_CFGEDATA2] & NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_ETA_PORT_BITMAP_MASK;
1719                 VlanFilterTableEntry->BaseEgressTreatmentEntryID = TableDataBuffer.TableDataField[NETC_ETHSWT_VLANFILTERTABL_RSPDATA_CFGEDATA3];
1720             }
1721         }
1722     }
1723     else
1724     {
1725         status = NETC_ETHSWT_CBDRSTATUS_ACCESSMETHOD_ERROR;
1726     }
1727 
1728     return status;
1729 }
1730 
1731 /*FUNCTION**********************************************************************
1732  *
1733  * Function Name : Netc_EthSwt_Ip_DeleteVlanFilterTableEntry
1734  * Description   : Ethernet Switch delete Vlan Filter table entry function.
1735  * implements Netc_EthSwt_Ip_DeleteVlanFilterTableEntry_Activity
1736  *END**************************************************************************/
Netc_EthSwt_Ip_DeleteVlanFilterTableEntry(uint8 SwitchIdx,uint32 * MatchedEntries,uint32 VlanFilterTableEntryId)1737 Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_DeleteVlanFilterTableEntry( uint8 SwitchIdx,
1738                                                                          uint32 *MatchedEntries,
1739                                                                          uint32 VlanFilterTableEntryId
1740                                                                        )
1741 {
1742     Netc_EthSwt_Ip_CBDRStatusType status;
1743     uint32 AccessKeyData;
1744     uint32 ActionsData = 0U;
1745     NetcEthSwt_Ip_ReqHeaderTableOperationDataType OperationData;
1746 
1747 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
1748     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
1749     DevAssert(MatchedEntries != NULL_PTR);
1750 #endif
1751 
1752     /* fill in Vlan Filter Table Request Data Buffer */
1753     AccessKeyData = VlanFilterTableEntryId;
1754 
1755     /* for delete command, we don't need the CFGE_DATA field */
1756     status = Netc_EthSwt_Ip_FillInVlanFilterTableReqDataBuff(ActionsData, AccessKeyData, NULL_PTR, NETC_ETHSWT_EXACT_MATCH_KEY_ELEMENT_MATCH);
1757     if (NETC_ETHSWT_CBDRSTATUS_SUCCES == status)
1758     {
1759         /* fill in operation data for config field of NTMP Request Header*/
1760         OperationData.CmdCompletionInt = 0x0U;                                        /* command completion interrupt disabled */
1761         OperationData.Version = NETC_ETHSWT_IP_CMDBD_REQFMT_PROTOCOL_VERSION;        /* protocol version = 2 */
1762         OperationData.TableId = NETC_ETHSWT_IP_VLAN_FILTER_TABLE_ID;
1763         OperationData.AccessMethod = NETC_ETHSWT_EXACT_MATCH_KEY_ELEMENT_MATCH;
1764         OperationData.Cmd = NETC_ETHSWT_DELETE_CMD;
1765         OperationData.ReqBuffLength = (NETC_ETHSWT_IP_TABLE_REQBUFFER_LEN);
1766         OperationData.RspBuffLength = (NETC_ETHSWT_IP_TABLE_RESBUFFER_LEN);
1767 
1768         /* send the "Delete" command */
1769         status = Netc_EthSwt_Ip_SendCommand(SwitchIdx, NETC_ETHSWT_IP_CBDR_0, &OperationData);
1770         /* Erroe code 0x8A is not a real error. check it on Errata. */
1771         if ((status == 0x8AU) || (status == NETC_ETHSWT_CBDRSTATUS_SUCCES))
1772         {
1773             Netc_EthSwt_Ip_GetMatchedEntries(NETC_ETHSWT_IP_CBDR_0, MatchedEntries);
1774         }
1775     }
1776     else
1777     {
1778         status = NETC_ETHSWT_CBDRSTATUS_ACCESSMETHOD_ERROR;
1779     }
1780 
1781     return status;
1782 }
1783 
1784 /*FUNCTION**********************************************************************
1785  *
1786  * Function Name : Netc_EthSwt_Ip_QueryEgressCountTableEntry
1787  * Description   : Ethernet Switch query Egress count table entry function.
1788  * implements Netc_EthSwt_Ip_QueryEgressCountTableEntry_Activity
1789  *END**************************************************************************/
Netc_EthSwt_Ip_QueryEgressCountTableEntry(uint8 SwitchIdx,uint32 EntryId,uint32 * MatchedEntries,Netc_EthSwt_Ip_ECTableStatisticsDataType * StatisticsData)1790 Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_QueryEgressCountTableEntry( uint8 SwitchIdx,
1791                                                                         uint32 EntryId,
1792                                                                         uint32 *MatchedEntries,
1793                                                                         Netc_EthSwt_Ip_ECTableStatisticsDataType *StatisticsData
1794                                                                        )
1795 {
1796     Netc_EthSwt_Ip_CBDRStatusType status;
1797     NetcEthSwt_Ip_ReqHeaderTableOperationDataType OperationData;
1798 
1799 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
1800     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
1801     DevAssert(StatisticsData != NULL_PTR);
1802     DevAssert(MatchedEntries != NULL_PTR);
1803     DevAssert((EntryId > 0U) && (EntryId <= (IP_NETC__SW0_COMMON->ECTCAPR & NETC_F2_COMMON_ECTCAPR_NUM_ENTRIES_MASK)));
1804 #endif
1805 
1806     /* fill in Egress Count Table Request Data Buffer */
1807     /* fill in Actions field. only support "full query" action and no need to update Statistics Element */
1808     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD] = (NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD_QUERY_ACTIONS(NETC_ETHSWT_TABLES_FULL_QUERY) \
1809                                                                                     | NETC_ETHSWT_IP_EGRESSCOUNTTABLE_REQFMT_ACTIONS_FIELD_STSEU(NETC_ETHSWT_EGRESSCOUNTTABLE_NO_UPDATE_STATISTICS_ELEMENT));
1810     /* fill in Access Key field, only support Entry ID Match method */
1811     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ENTRYID_FIELD] = EntryId;
1812 
1813     /* fill in operation data for config field of NTMP Request Header*/
1814     OperationData.CmdCompletionInt = 0x0U;                                          /* command completion interrupt disabled */
1815     OperationData.Version = NETC_ETHSWT_IP_CMDBD_REQFMT_PROTOCOL_VERSION;           /* protocol version = 2 */
1816     OperationData.TableId = NETC_ETHSWT_IP_EGRESS_COUNT_TABLE_ID;
1817     OperationData.AccessMethod = NETC_ETHSWT_ENTRY_ID_MATCH;                        /* only support Entry ID Match method */
1818     OperationData.Cmd = NETC_ETHSWT_QUERY_CMD;
1819     OperationData.ReqBuffLength = (NETC_ETHSWT_IP_EGRESSCOUNTTABLE_REQBUFFER_LEN);  /* set request data buffer length */
1820     OperationData.RspBuffLength = (NETC_ETHSWT_IP_EGRESSCOUNTTABLE_RSPBUFFER_LEN);  /* set response data buffer length */
1821 
1822     /* send the "Query" command */
1823     status = Netc_EthSwt_Ip_SendCommand(SwitchIdx, NETC_ETHSWT_IP_CBDR_0, &OperationData);
1824     /* Erroe code 0x8A is not a real error. check it on Errata. */
1825     if ((status == 0x8AU) || (status == NETC_ETHSWT_CBDRSTATUS_SUCCES))
1826     {
1827         Netc_EthSwt_Ip_GetMatchedEntries(NETC_ETHSWT_IP_CBDR_0, MatchedEntries);
1828         /* found a matched entry */
1829         if (*MatchedEntries == 1U)
1830         {
1831             /* get the Enqueued Frame Count data */
1832             StatisticsData->EnqueuedFrmCnt = ((uint64)(TableDataBuffer.TableDataField[NETC_ETHSWT_ECTABLE_RSPDATA_ENQFRMCNT_H]) << NETC_ETHSWT_IP_32BIT_SHIFT);
1833             StatisticsData->EnqueuedFrmCnt |= (uint64)(TableDataBuffer.TableDataField[NETC_ETHSWT_ECTABLE_RSPDATA_ENQFRMCNT_L]);
1834 
1835             /* get the Rejected Frame Count */
1836             StatisticsData->RejectedFrmCnt = ((uint64)(TableDataBuffer.TableDataField[NETC_ETHSWT_ECTABLE_RSPDATA_REJFRMCNT_H]) << NETC_ETHSWT_IP_32BIT_SHIFT);
1837             StatisticsData->RejectedFrmCnt |= (uint64)(TableDataBuffer.TableDataField[NETC_ETHSWT_ECTABLE_RSPDATA_REJFRMCNT_L]);
1838         }
1839     }
1840 
1841     return status;
1842 }
1843 
1844 /*FUNCTION**********************************************************************
1845  *
1846  * Function Name : Netc_EthSwt_Ip_ResetEgressCountTableEntry
1847  * Description   : Ethernet Switch reset Egress count table entry function.
1848  * implements Netc_EthSwt_Ip_ResetEgressCountTableEntry_Activity
1849  *END**************************************************************************/
Netc_EthSwt_Ip_ResetEgressCountTableEntry(uint8 SwitchIdx,uint32 EntryId,uint32 * MatchedEntries)1850 Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_ResetEgressCountTableEntry( uint8 SwitchIdx,
1851                                                                          uint32 EntryId,
1852                                                                          uint32 *MatchedEntries
1853                                                                        )
1854 {
1855     Netc_EthSwt_Ip_CBDRStatusType status;
1856     NetcEthSwt_Ip_ReqHeaderTableOperationDataType OperationData;
1857 
1858 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
1859     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
1860     DevAssert(MatchedEntries != NULL_PTR);
1861     DevAssert((EntryId > 0U) && (EntryId <= (IP_NETC__SW0_COMMON->ECTCAPR & NETC_F2_COMMON_ECTCAPR_NUM_ENTRIES_MASK)));
1862 #endif
1863 
1864     /* fill in Egress Count Table Request Data Buffer */
1865     /* fill in Actions field. only support "full query" action and set STSEU to reset Statistics Element */
1866     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_EGRESSCOUNTTABLE_REQFMT_ACTIONS_FIELD] = (NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD_QUERY_ACTIONS(NETC_ETHSWT_TABLES_FULL_QUERY) \
1867                                                                                          | NETC_ETHSWT_IP_EGRESSCOUNTTABLE_REQFMT_ACTIONS_FIELD_STSEU(NETC_ETHSWT_EGRESSCOUNTTABLE_RESET_STATISTICS_ELEMENT));
1868     /* fill in Access Key field, only support Entry ID Match method */
1869     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_EGRESSCOUNTTABLE_REQFMT_ACCESSKEY_FIELD] = EntryId;
1870 
1871     /* fill in operation data for config field of NTMP Request Header*/
1872     OperationData.CmdCompletionInt = 0x0U;                                          /* command completion interrupt disabled */
1873     OperationData.Version = NETC_ETHSWT_IP_CMDBD_REQFMT_PROTOCOL_VERSION;           /* protocol version = 2 */
1874     OperationData.TableId = NETC_ETHSWT_IP_EGRESS_COUNT_TABLE_ID;
1875     OperationData.AccessMethod = NETC_ETHSWT_ENTRY_ID_MATCH;                        /* only support Entry ID Match method */
1876     OperationData.Cmd = NETC_ETHSWT_UPDATE_CMD;
1877     OperationData.ReqBuffLength = (NETC_ETHSWT_IP_EGRESSCOUNTTABLE_REQBUFFER_LEN);  /* set request data buffer length */
1878     OperationData.RspBuffLength = (NETC_ETHSWT_IP_EGRESSCOUNTTABLE_RSPBUFFER_LEN);  /* set response data buffer length */
1879 
1880     /* send the "Update" command */
1881     status = Netc_EthSwt_Ip_SendCommand(SwitchIdx, NETC_ETHSWT_IP_CBDR_0, &OperationData);
1882     /* Erroe code 0x8A is not a real error. check it on Errata. */
1883     if ((status == 0x8AU) || (status == NETC_ETHSWT_CBDRSTATUS_SUCCES))
1884     {
1885         Netc_EthSwt_Ip_GetMatchedEntries(NETC_ETHSWT_IP_CBDR_0, MatchedEntries);
1886     }
1887 
1888     return status;
1889 }
1890 
1891 /*FUNCTION**********************************************************************
1892  *
1893  * Function Name : Netc_EthSwt_Ip_AddOrUpdateEgressTreatmentTableEntry
1894  * Description   : Ethernet Switch add, update or addorupdate Egress Treatment table entry function.
1895  * implements Netc_EthSwt_Ip_AddOrUpdateEgressTreatmentTableEntry_Activity
1896  *END**************************************************************************/
Netc_EthSwt_Ip_AddOrUpdateEgressTreatmentTableEntry(uint8 SwitchIdx,Netc_EthSwt_Ip_CommandsType Cmd,uint32 * MatchedEntries,const Netc_EthSwt_Ip_EgressTreatmentEntryDataType * EgressTreatmentTableEntry)1897 Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_AddOrUpdateEgressTreatmentTableEntry( uint8 SwitchIdx,
1898                                                                                    Netc_EthSwt_Ip_CommandsType Cmd,
1899                                                                                    uint32 *MatchedEntries,
1900                                                                                    const Netc_EthSwt_Ip_EgressTreatmentEntryDataType * EgressTreatmentTableEntry
1901                                                                                  )
1902 {
1903     Netc_EthSwt_Ip_CBDRStatusType status;
1904     NetcEthSwt_Ip_ReqHeaderTableOperationDataType OperationData;
1905 
1906 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
1907     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
1908     DevAssert(MatchedEntries != NULL_PTR);
1909     DevAssert(EgressTreatmentTableEntry != NULL_PTR);
1910 #endif
1911 
1912     /* only support Add, Update and AddOrUpdate commands */
1913     if ((NETC_ETHSWT_ADD_CMD != Cmd) && (NETC_ETHSWT_UPDATE_CMD != Cmd) && (NETC_ETHSWT_ADD_OR_UPDATE_CMD != Cmd))
1914     {
1915         status = NETC_ETHSWT_CBDRSTATUS_INVALID_CMD;    /* not supported command */
1916     }
1917     else
1918     {
1919         /* fill in Egress Treatment Table Request Data Buffer */
1920         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD] = NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD_CFGEU(1U);
1921         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ENTRYID_FIELD] = EgressTreatmentTableEntry->EgressTreatmentEntryID;
1922 
1923         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_CFGEDATA0] = (NETC_ETHSWT_IP_ETTABLE_CFGE_FRM_MODIFICATION_DATA_LEN(EgressTreatmentTableEntry->EgressFrmModificationDataLength) \
1924                                                                                     | NETC_ETHSWT_IP_ETTABLE_CFGE_FRM_MODIFICATION_LEN_CHANGE(EgressTreatmentTableEntry->EgressFrmModificationLengthChange) \
1925                                                                                     | NETC_ETHSWT_IP_ETTABLE_CFGE_EGRESS_COUNTER_ACTION(EgressTreatmentTableEntry->EgressCounterAction) \
1926                                                                                     | NETC_ETHSWT_IP_ETTABLE_CFGE_EGRESS_SEQUENCE_ACTION(EgressTreatmentTableEntry->EgressSequenceAction) \
1927                                                                                     | NETC_ETHSWT_IP_ETTABLE_CFGE_FRM_MODIFICATION_MODE(EgressTreatmentTableEntry->EgressFrmModificationMode));
1928         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_CFGEDATA1] = EgressTreatmentTableEntry->EgressFrmModificationEID;
1929         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_CFGEDATA2] = EgressTreatmentTableEntry->EgressCountTableEID;
1930         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_CFGEDATA3] = EgressTreatmentTableEntry->EgressSeqActionsTargetEID;
1931 
1932         /* fill in operation data for config field of Request Header*/
1933         OperationData.CmdCompletionInt = 0x0U;                                        /* command completion interrupt disabled */
1934         OperationData.Version = NETC_ETHSWT_IP_CMDBD_REQFMT_PROTOCOL_VERSION;         /* protocol version = 2 */
1935         OperationData.TableId = NETC_ETHSWT_IP_EGRESS_TREATMENT_TABLE_ID;
1936         OperationData.AccessMethod = NETC_ETHSWT_ENTRY_ID_MATCH;
1937         OperationData.Cmd = Cmd;
1938         OperationData.ReqBuffLength = (NETC_ETHSWT_IP_TABLE_REQBUFFER_LEN);
1939         OperationData.RspBuffLength = (NETC_ETHSWT_IP_TABLE_RESBUFFER_LEN);
1940 
1941         /* send the command */
1942         status = Netc_EthSwt_Ip_SendCommand(SwitchIdx, NETC_ETHSWT_IP_CBDR_0, &OperationData);
1943         /* Erroe code 0x8A is not a real error. check it on Errata. */
1944         if ((status == 0x8AU) || (status == NETC_ETHSWT_CBDRSTATUS_SUCCES))
1945         {
1946             Netc_EthSwt_Ip_GetMatchedEntries(NETC_ETHSWT_IP_CBDR_0, MatchedEntries);
1947         }
1948 
1949     }
1950 
1951     return status;
1952 }
1953 
1954 /*FUNCTION**********************************************************************
1955  *
1956  * Function Name : Netc_EthSwt_Ip_QueryEgressTreatmentTableEntry
1957  * Description   : Ethernet Switch query Egress Treatment table entry function.
1958  * implements Netc_EthSwt_Ip_QueryEgressTreatmentTableEntry_Activity
1959  *END**************************************************************************/
Netc_EthSwt_Ip_QueryEgressTreatmentTableEntry(uint8 SwitchIdx,uint32 * MatchedEntries,Netc_EthSwt_Ip_EgressTreatmentEntryDataType * EgressTreatmentTableEntry)1960 Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_QueryEgressTreatmentTableEntry( uint8 SwitchIdx,
1961                                                                              uint32 *MatchedEntries,
1962                                                                              Netc_EthSwt_Ip_EgressTreatmentEntryDataType * EgressTreatmentTableEntry
1963                                                                            )
1964 {
1965     Netc_EthSwt_Ip_CBDRStatusType status;
1966     NetcEthSwt_Ip_ReqHeaderTableOperationDataType OperationData;
1967     uint32 CfgeData;
1968 
1969 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
1970     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
1971     DevAssert(MatchedEntries != NULL_PTR);
1972 #endif
1973 
1974     /* fill in Egress Treatment Table Request Data Buffer */
1975     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD] = NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD_QUERY_ACTIONS(NETC_ETHSWT_TABLES_FULL_QUERY);     /* only supports Full Query */
1976     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ENTRYID_FIELD] = EgressTreatmentTableEntry->EgressTreatmentEntryID;
1977 
1978     /* fill in operation data for config field of Request Header*/
1979     OperationData.CmdCompletionInt = 0x0U;                                        /* command completion interrupt disabled */
1980     OperationData.Version = NETC_ETHSWT_IP_CMDBD_REQFMT_PROTOCOL_VERSION;         /* protocol version = 2 */
1981     OperationData.TableId = NETC_ETHSWT_IP_EGRESS_TREATMENT_TABLE_ID;
1982     OperationData.AccessMethod = NETC_ETHSWT_ENTRY_ID_MATCH;
1983     OperationData.Cmd = NETC_ETHSWT_QUERY_CMD;
1984     OperationData.ReqBuffLength = (NETC_ETHSWT_IP_TABLE_REQBUFFER_LEN);
1985     OperationData.RspBuffLength = (NETC_ETHSWT_IP_TABLE_RESBUFFER_LEN);
1986 
1987     /* send the command */
1988     status = Netc_EthSwt_Ip_SendCommand(SwitchIdx, NETC_ETHSWT_IP_CBDR_0, &OperationData);
1989     /* Erroe code 0x8A is not a real error. check it on Errata. */
1990     if ((status == 0x8AU) || (status == NETC_ETHSWT_CBDRSTATUS_SUCCES))
1991     {
1992         Netc_EthSwt_Ip_GetMatchedEntries(NETC_ETHSWT_IP_CBDR_0, MatchedEntries);
1993 
1994         /* found a matched entry */
1995         if (1U == *MatchedEntries)
1996         {
1997             /* fill in "Netc_EthSwt_Ip_EgressTreatmentEntryDataType" structure with data in response data buffer */
1998             EgressTreatmentTableEntry->EgressTreatmentEntryID = TableDataBuffer.TableDataField[NETC_ETHSWT_IP_EGRESSTREATMENTTABLE_RSPFMT_ENTRYID_FIELD];
1999 
2000             CfgeData = TableDataBuffer.TableDataField[NETC_ETHSWT_IP_EGRESSTREATMENTTABLE_RSPFMT_CFGEDATA0];
2001             EgressTreatmentTableEntry->EgressFrmModificationDataLength = (uint16)((CfgeData & NETC_ETHSWT_IP_ETTABLE_CFGE_FRM_MODIFICATION_DATA_LEN_MASK) >> NETC_ETHSWT_IP_ETTABLE_CFGE_FRM_MODIFICATION_DATA_LEN_SHIFT);
2002             EgressTreatmentTableEntry->EgressFrmModificationLengthChange = (uint8)((CfgeData & NETC_ETHSWT_IP_ETTABLE_CFGE_FRM_MODIFICATION_LEN_CHANGE_MASK) >> NETC_ETHSWT_IP_ETTABLE_CFGE_FRM_MODIFICATION_LEN_CHANGE_SHIFT);
2003             EgressTreatmentTableEntry->EgressCounterAction = ((CfgeData & NETC_ETHSWT_IP_ETTABLE_CFGE_EGRESS_COUNTER_ACTION_MASK) >> NETC_ETHSWT_IP_ETTABLE_CFGE_EGRESS_COUNTER_ACTION_SHIFT);
2004             EgressTreatmentTableEntry->EgressSequenceAction = ((CfgeData & NETC_ETHSWT_IP_ETTABLE_CFGE_EGRESS_SEQUENCE_ACTION_MASK) >> NETC_ETHSWT_IP_ETTABLE_CFGE_EGRESS_SEQUENCE_ACTION_SHIFT);
2005             EgressTreatmentTableEntry->EgressFrmModificationMode = (CfgeData & NETC_ETHSWT_IP_ETTABLE_CFGE_FRM_MODIFICATION_MODE_MASK);
2006 
2007             EgressTreatmentTableEntry->EgressFrmModificationEID = TableDataBuffer.TableDataField[NETC_ETHSWT_IP_EGRESSTREATMENTTABLE_RSPFMT_CFGEDATA1];         /* fill in EFM_EID field */
2008             EgressTreatmentTableEntry->EgressCountTableEID = TableDataBuffer.TableDataField[NETC_ETHSWT_IP_EGRESSTREATMENTTABLE_RSPFMT_CFGEDATA2];              /* fill in EC_EID field */
2009             EgressTreatmentTableEntry->EgressSeqActionsTargetEID = TableDataBuffer.TableDataField[NETC_ETHSWT_IP_EGRESSTREATMENTTABLE_RSPFMT_CFGEDATA3];        /* fill in ESQA_TGT_EID field */
2010         }
2011     }
2012 
2013     return status;
2014 }
2015 
2016 /*FUNCTION**********************************************************************
2017  *
2018  * Function Name : Netc_EthSwt_Ip_DeleteEgressTreatmentTableEntry
2019  * Description   : Ethernet Switch delete Egress Treatment table entry function.
2020  * implements Netc_EthSwt_Ip_DeleteEgressTreatmentTableEntry_Activity
2021  *END**************************************************************************/
Netc_EthSwt_Ip_DeleteEgressTreatmentTableEntry(uint8 SwitchIdx,uint32 EgressTreatmentTableEntryId,uint32 * MatchedEntries)2022 Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_DeleteEgressTreatmentTableEntry( uint8 SwitchIdx,
2023                                                                               uint32 EgressTreatmentTableEntryId,
2024                                                                               uint32 *MatchedEntries
2025                                                                             )
2026 {
2027     Netc_EthSwt_Ip_CBDRStatusType status;
2028     NetcEthSwt_Ip_ReqHeaderTableOperationDataType OperationData;
2029 
2030 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
2031     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
2032     DevAssert(MatchedEntries != NULL_PTR);
2033 #endif
2034 
2035     /* fill in Egress Treatment Table Request Data Buffer */
2036     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD] = 0U;     /* no need to fill in Actions field */
2037     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ENTRYID_FIELD] = EgressTreatmentTableEntryId;
2038 
2039     /* fill in operation data for config field of Request Header*/
2040     OperationData.CmdCompletionInt = 0x0U;                                        /* command completion interrupt disabled */
2041     OperationData.Version = NETC_ETHSWT_IP_CMDBD_REQFMT_PROTOCOL_VERSION;         /* protocol version = 2 */
2042     OperationData.TableId = NETC_ETHSWT_IP_EGRESS_TREATMENT_TABLE_ID;
2043     OperationData.AccessMethod = NETC_ETHSWT_ENTRY_ID_MATCH;
2044     OperationData.Cmd = NETC_ETHSWT_DELETE_CMD;
2045     OperationData.ReqBuffLength = (NETC_ETHSWT_IP_TABLE_REQBUFFER_LEN);
2046     OperationData.RspBuffLength = (NETC_ETHSWT_IP_TABLE_RESBUFFER_LEN);
2047 
2048     /* send the command */
2049     status = Netc_EthSwt_Ip_SendCommand(SwitchIdx, NETC_ETHSWT_IP_CBDR_0, &OperationData);
2050     /* Erroe code 0x8A is not a real error. check it on Errata. */
2051     if ((status == 0x8AU) || (status == NETC_ETHSWT_CBDRSTATUS_SUCCES))
2052     {
2053         Netc_EthSwt_Ip_GetMatchedEntries(NETC_ETHSWT_IP_CBDR_0, MatchedEntries);
2054     }
2055 
2056     return status;
2057 }
2058 
2059 /*FUNCTION**********************************************************************
2060  *
2061  * Function Name : Netc_EthSwt_Ip_AddOrUpdateFrmModificationTableEntry
2062  * Description   : Ethernet Switch add, update or addorupdate Frame Modification table entry function.
2063  * implements Netc_EthSwt_Ip_AddOrUpdateFrmModificationTableEntry_Activity
2064  *END**************************************************************************/
Netc_EthSwt_Ip_AddOrUpdateFrmModificationTableEntry(uint8 SwitchIdx,Netc_EthSwt_Ip_CommandsType Cmd,uint32 * MatchedEntries,const Netc_EthSwt_Ip_FrmModificationEntryDataType * FrmModificationTableEntry)2065 Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_AddOrUpdateFrmModificationTableEntry( uint8 SwitchIdx,
2066                                                                                    Netc_EthSwt_Ip_CommandsType Cmd,
2067                                                                                    uint32 *MatchedEntries,
2068                                                                                    const Netc_EthSwt_Ip_FrmModificationEntryDataType * FrmModificationTableEntry
2069                                                                                  )
2070 {
2071     Netc_EthSwt_Ip_CBDRStatusType status;
2072     NetcEthSwt_Ip_ReqHeaderTableOperationDataType OperationData;
2073     uint16 MacAddrH;
2074     uint32 MacAddrL = 0x0UL;
2075     uint8 MacByteIdx;
2076 
2077 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
2078     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
2079     DevAssert(MatchedEntries != NULL_PTR);
2080     DevAssert(FrmModificationTableEntry != NULL_PTR);
2081 #endif
2082 
2083     /* only support Add, Update and AddOrUpdate commands */
2084     if ((NETC_ETHSWT_ADD_CMD != Cmd) && (NETC_ETHSWT_UPDATE_CMD != Cmd) && (NETC_ETHSWT_ADD_OR_UPDATE_CMD != Cmd))
2085     {
2086         status = NETC_ETHSWT_CBDRSTATUS_INVALID_CMD;    /* not supported command */
2087     }
2088     else
2089     {
2090         /* fill in Frame Modification Table Request Data Buffer */
2091         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD] = NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD_CFGEU(1U);        /* Configuration Element Update */
2092         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ENTRYID_FIELD] = FrmModificationTableEntry->FrmModificationEntryID;                /* Entry ID */
2093 
2094         /* be careful to the order of dest mac address, it is in big endian */
2095         for (MacByteIdx = 5U; MacByteIdx > 2U; MacByteIdx-- )       /* Get the Dest Mac Address */
2096         {
2097             MacAddrL |= FrmModificationTableEntry->DestMacAddr[MacByteIdx];
2098             MacAddrL <<= 8U;
2099         }
2100         MacAddrL |= FrmModificationTableEntry->DestMacAddr[2U];
2101         MacAddrH = ((uint16)(FrmModificationTableEntry->DestMacAddr[1U]) << 8U) | FrmModificationTableEntry->DestMacAddr[0U];
2102 
2103         /* fill in CFGE Data */
2104         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_CFGEDATA0] = (NENETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_DEST_MAC_ADDR_H(MacAddrH) \
2105                                                                                     | NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_SRC_MAC_ADDR_PORT(FrmModificationTableEntry->SrcMacAddrRegisterPort) \
2106                                                                                     | NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_SEQUENCE_TAG_ACTION(FrmModificationTableEntry->SequenceTagAction) \
2107                                                                                     | NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_OUTER_VID_ACTION(FrmModificationTableEntry->OuterVidActions) \
2108                                                                                     | NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_VLAN_HEADER_ACTION(FrmModificationTableEntry->L2HeaderVlanActions) \
2109                                                                                     | NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_MAC_HEADER_ACTION(FrmModificationTableEntry->L2HeaderMacActions) \
2110                                                                                     | NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_LAYER2_ACTION(FrmModificationTableEntry->L2Actions));
2111         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_CFGEDATA1] = MacAddrL;
2112         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_CFGEDATA2] = (NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_PAYLOAD_ACTION(FrmModificationTableEntry->PayloadActions) \
2113                                                                                     | NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_OUTER_DEI_ACTION(FrmModificationTableEntry->OuterDeiAction) \
2114                                                                                     | NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_OUTER_PCP_ACTION(FrmModificationTableEntry->OuterPcpAction) \
2115                                                                                     | NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_OUTER_TPID_ACTION(FrmModificationTableEntry->OuterTpidAction) \
2116                                                                                     | NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_OUTER_VLAN_DEI(FrmModificationTableEntry->OuterVlanDei) \
2117                                                                                     | NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_OUTER_VLAN_PCP(FrmModificationTableEntry->OuterVlanPcp) \
2118                                                                                     | NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_OUTER_VLAN_VID(FrmModificationTableEntry->OuterVlanVID));
2119         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_CFGEDATA3] = NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_PAYLOAD_OFFSET(FrmModificationTableEntry->PayloadOffset);
2120         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_CFGEDATA4] = NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_FRM_MODI_BYTES(FrmModificationTableEntry->FrmModificationDataBytes);
2121         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_CFGEDATA5] = FrmModificationTableEntry->FrmModificationDataEntryID;        /* Frame Modification Data Tabel Entry ID */
2122 
2123         /* fill in operation data for config field of Request Header*/
2124         OperationData.CmdCompletionInt = 0x0U;                                        /* command completion interrupt disabled */
2125         OperationData.Version = NETC_ETHSWT_IP_CMDBD_REQFMT_PROTOCOL_VERSION;         /* protocol version = 2 */
2126         OperationData.TableId = NETC_ETHSWT_IP_FRM_MODIFICATION_TABLE_ID;
2127         OperationData.AccessMethod = NETC_ETHSWT_ENTRY_ID_MATCH;                      /* only support "Entry ID" match method */
2128         OperationData.Cmd = Cmd;
2129         OperationData.ReqBuffLength = (NETC_ETHSWT_IP_TABLE_REQBUFFER_LEN);
2130         OperationData.RspBuffLength = (NETC_ETHSWT_IP_TABLE_RESBUFFER_LEN);
2131 
2132         /* send the command */
2133         status = Netc_EthSwt_Ip_SendCommand(SwitchIdx, NETC_ETHSWT_IP_CBDR_0, &OperationData);
2134         /* Erroe code 0x8A is not a real error. check it on Errata. */
2135         if ((status == 0x8AU) || (status == NETC_ETHSWT_CBDRSTATUS_SUCCES))
2136         {
2137             Netc_EthSwt_Ip_GetMatchedEntries(NETC_ETHSWT_IP_CBDR_0, MatchedEntries);
2138         }
2139     }
2140 
2141     return status;
2142 }
2143 
2144 /*FUNCTION**********************************************************************
2145  *
2146  * Function Name : Netc_EthSwt_Ip_QueryFrmModificationTableEntry
2147  * Description   : Ethernet Switch query Frame Modification table entry function.
2148  * implements Netc_EthSwt_Ip_QueryFrmModificationTableEntry_Activity
2149  *END**************************************************************************/
Netc_EthSwt_Ip_QueryFrmModificationTableEntry(uint8 SwitchIdx,uint32 * MatchedEntries,Netc_EthSwt_Ip_FrmModificationEntryDataType * FrmModificationTableEntry)2150 Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_QueryFrmModificationTableEntry( uint8 SwitchIdx,
2151                                                                              uint32 *MatchedEntries,
2152                                                                              Netc_EthSwt_Ip_FrmModificationEntryDataType * FrmModificationTableEntry
2153                                                                             )
2154 {
2155     Netc_EthSwt_Ip_CBDRStatusType status;
2156     NetcEthSwt_Ip_ReqHeaderTableOperationDataType OperationData;
2157     uint16 MacAddrH;
2158     uint32 MacAddrL;
2159     uint8 MacByteIdx;
2160     uint32 CfgeData;
2161 
2162 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
2163     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
2164     DevAssert(MatchedEntries != NULL_PTR);
2165     DevAssert(FrmModificationTableEntry != NULL_PTR);
2166 #endif
2167 
2168     /* fill in Frame Modification Table Request Data Buffer */
2169     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD] = NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD_QUERY_ACTIONS(NETC_ETHSWT_TABLES_FULL_QUERY);        /* only support "Full Query" */
2170     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ENTRYID_FIELD] = FrmModificationTableEntry->FrmModificationEntryID;                /* Entry ID */
2171 
2172     /* fill in operation data for config field of Request Header*/
2173     OperationData.CmdCompletionInt = 0x0U;                                        /* command completion interrupt disabled */
2174     OperationData.Version = NETC_ETHSWT_IP_CMDBD_REQFMT_PROTOCOL_VERSION;         /* protocol version = 2 */
2175     OperationData.TableId = NETC_ETHSWT_IP_FRM_MODIFICATION_TABLE_ID;
2176     OperationData.AccessMethod = NETC_ETHSWT_ENTRY_ID_MATCH;                      /* only support "Entry ID" match method */
2177     OperationData.Cmd = NETC_ETHSWT_QUERY_CMD;
2178     OperationData.ReqBuffLength = (NETC_ETHSWT_IP_TABLE_REQBUFFER_LEN);
2179     OperationData.RspBuffLength = (NETC_ETHSWT_IP_TABLE_RESBUFFER_LEN);
2180 
2181     /* send the command */
2182     status = Netc_EthSwt_Ip_SendCommand(SwitchIdx, NETC_ETHSWT_IP_CBDR_0, &OperationData);
2183     /* Erroe code 0x8A is not a real error. check it on Errata. */
2184     if ((status == 0x8AU) || (status == NETC_ETHSWT_CBDRSTATUS_SUCCES))
2185     {
2186         Netc_EthSwt_Ip_GetMatchedEntries(NETC_ETHSWT_IP_CBDR_0, MatchedEntries);
2187         /* found a matched entry */
2188         if (1U == *MatchedEntries)
2189         {
2190             /* fill in structure Netc_EthSwt_Ip_FrmModificationEntryDataType with data in response data buffer */
2191             CfgeData = TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_RSPFMT_CFGEDATA0];
2192             MacAddrH = (uint16)((CfgeData & NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_DEST_MAC_ADDR_H_MASK) >> NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_DEST_MAC_ADDR_H_SHIFT);
2193             MacAddrL = TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_RSPFMT_CFGEDATA1];
2194             for (MacByteIdx = 0U; MacByteIdx < 4U; MacByteIdx++)
2195             {
2196                 FrmModificationTableEntry->DestMacAddr[MacByteIdx] = (uint8)(MacAddrL & NETC_ETHSWT_IP_0XFF_MASK);
2197                 MacAddrL >>= 8U;
2198             }
2199             FrmModificationTableEntry->DestMacAddr[4U] = (uint8)(MacAddrH & NETC_ETHSWT_IP_0XFF_MASK);
2200             FrmModificationTableEntry->DestMacAddr[5U] = (uint8)(MacAddrH >> 8U);
2201 
2202             FrmModificationTableEntry->SrcMacAddrRegisterPort = (uint8)((CfgeData & NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_SRC_MAC_ADDR_PORT_MASK) >> NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_SRC_MAC_ADDR_PORT_SHIFT);
2203             FrmModificationTableEntry->SequenceTagAction = (uint8)((CfgeData & NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_SEQUENCE_TAG_ACTION_MASK) >> NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_SEQUENCE_TAG_ACTION_SHIFT);
2204             FrmModificationTableEntry->OuterVidActions = (uint8)((CfgeData & NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_OUTER_VID_ACTION_MASK) >> NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_OUTER_VID_ACTION_SHIFT);
2205             FrmModificationTableEntry->L2HeaderVlanActions = (uint8)((CfgeData & NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_VLAN_HEADER_ACTION_MASK) >> NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_VLAN_HEADER_ACTION_SHIFT);
2206             FrmModificationTableEntry->L2HeaderMacActions = (uint8)((CfgeData & NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_MAC_HEADER_ACTION_MASK) >> NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_MAC_HEADER_ACTION_SHIFT);
2207             FrmModificationTableEntry->L2Actions = (uint8)((CfgeData & NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_LAYER2_ACTION_MASK) >> NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_LAYER2_ACTION_SHIFT);
2208 
2209             CfgeData = TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_RSPFMT_CFGEDATA2];
2210             FrmModificationTableEntry->PayloadActions = (uint8)((CfgeData & NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_PAYLOAD_ACTION_MASK) >> NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_PAYLOAD_ACTION_SHIFT);
2211             FrmModificationTableEntry->OuterDeiAction = (uint8)((CfgeData & NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_OUTER_DEI_ACTION_MASK) >> NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_OUTER_DEI_ACTION_SHIFT);
2212             FrmModificationTableEntry->OuterPcpAction = (uint8)((CfgeData & NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_OUTER_PCP_ACTION_MASK) >> NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_OUTER_PCP_ACTION_SHIFT);
2213             FrmModificationTableEntry->OuterTpidAction = (uint8)((CfgeData & NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_OUTER_TPID_ACTION_MASK) >> NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_OUTER_TPID_ACTION_SHIFT);
2214             FrmModificationTableEntry->OuterVlanDei = (uint8)((CfgeData & NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_OUTER_VLAN_DEI_MASK) >> NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_OUTER_VLAN_DEI_SHIFT);
2215             FrmModificationTableEntry->OuterVlanPcp = (uint8)((CfgeData & NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_OUTER_VLAN_PCP_MASK) >> NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_OUTER_VLAN_PCP_SHIFT);
2216             FrmModificationTableEntry->OuterVlanVID = (uint16)((CfgeData & NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_OUTER_VLAN_VID_MASK) >> NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_OUTER_VLAN_VID_SHIFT);
2217 
2218             FrmModificationTableEntry->PayloadOffset = (uint8)(TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_RSPFMT_CFGEDATA3] & NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_PAYLOAD_OFFSET_MASK);
2219             FrmModificationTableEntry->FrmModificationDataBytes = (uint16)(TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_RSPFMT_CFGEDATA4] & NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_CFGE_FRM_MODI_BYTES_MASK);
2220             FrmModificationTableEntry->FrmModificationDataEntryID = TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FRMMODIFICATIONTABLE_RSPFMT_CFGEDATA5];
2221         }
2222     }
2223 
2224 
2225     return status;
2226 }
2227 
2228 /*FUNCTION**********************************************************************
2229  *
2230  * Function Name : Netc_EthSwt_Ip_DeleteFrmModificationTableEntry
2231  * Description   : Ethernet Switch delete Frame Modification table entry function.
2232  * implements Netc_EthSwt_Ip_DeleteFrmModificationTableEntry_Activity
2233  *END**************************************************************************/
Netc_EthSwt_Ip_DeleteFrmModificationTableEntry(uint8 SwitchIdx,uint32 FrmModificationEntryID,uint32 * MatchedEntries)2234 Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_DeleteFrmModificationTableEntry( uint8 SwitchIdx,
2235                                                                               uint32 FrmModificationEntryID,
2236                                                                               uint32 *MatchedEntries
2237                                                                             )
2238 {
2239     Netc_EthSwt_Ip_CBDRStatusType status;
2240     NetcEthSwt_Ip_ReqHeaderTableOperationDataType OperationData;
2241 
2242 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
2243     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
2244     DevAssert(MatchedEntries != NULL_PTR);
2245 #endif
2246 
2247     /* fill in Frame Modification Table Request Data Buffer */
2248     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD] = 0U;                               /* no need to fill in Actions field */
2249     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ENTRYID_FIELD] = FrmModificationEntryID;           /* Entry ID */
2250 
2251     /* fill in operation data for config field of Request Header*/
2252     OperationData.CmdCompletionInt = 0x0U;                                        /* command completion interrupt disabled */
2253     OperationData.Version = NETC_ETHSWT_IP_CMDBD_REQFMT_PROTOCOL_VERSION;         /* protocol version = 2 */
2254     OperationData.TableId = NETC_ETHSWT_IP_FRM_MODIFICATION_TABLE_ID;
2255     OperationData.AccessMethod = NETC_ETHSWT_ENTRY_ID_MATCH;                      /* only support "Entry ID" match method */
2256     OperationData.Cmd = NETC_ETHSWT_DELETE_CMD;
2257     OperationData.ReqBuffLength = (NETC_ETHSWT_IP_TABLE_REQBUFFER_LEN);
2258     OperationData.RspBuffLength = (NETC_ETHSWT_IP_TABLE_RESBUFFER_LEN);
2259 
2260     /* send the command */
2261     status = Netc_EthSwt_Ip_SendCommand(SwitchIdx, NETC_ETHSWT_IP_CBDR_0, &OperationData);
2262     /* Erroe code 0x8A is not a real error. check it on Errata. */
2263     if ((status == 0x8AU) || (status == NETC_ETHSWT_CBDRSTATUS_SUCCES))
2264     {
2265         Netc_EthSwt_Ip_GetMatchedEntries(NETC_ETHSWT_IP_CBDR_0, MatchedEntries);
2266     }
2267 
2268     return status;
2269 }
2270 
2271 /*FUNCTION**********************************************************************
2272  *
2273  * Function Name : Netc_EthSwt_Ip_EnableIngressPortFiltering
2274  * Description   : Ethernet switch enables the ingress port filtering lookup function.
2275  * implements Netc_EthSwt_Ip_EnableIngressPortFiltering_Activity
2276  *END**************************************************************************/
Netc_EthSwt_Ip_EnableIngressPortFiltering(uint8 SwitchIdx,uint8 SwitchPortIdx,boolean Enable)2277 Std_ReturnType Netc_EthSwt_Ip_EnableIngressPortFiltering( uint8 SwitchIdx, uint8 SwitchPortIdx, boolean Enable )
2278 {
2279     Std_ReturnType Status = E_OK;
2280     uint32 RegVal;
2281 
2282 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
2283     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
2284     DevAssert(SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_PORTS);
2285 #endif
2286 
2287     /* Convert the value */
2288     RegVal = (Enable) ? (0x1UL) : (0x0UL);
2289 
2290     /* write the PIPFCR[EN] bit */
2291     Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->PIPFCR = RegVal;
2292 
2293     return Status;
2294 }
2295 
2296 /* inline function for filling in Access Keye data in function Netc_EthSwt_Ip_FillInIngressPortFilterTableReqDataBuff() */
FillInAccessKeyeData(const Netc_EthSwt_Ip_AccessMethodType accessMethod,const volatile uint32 * pAccessKey)2297 static inline Netc_EthSwt_Ip_CBDRStatusType FillInAccessKeyeData(const Netc_EthSwt_Ip_AccessMethodType accessMethod, const volatile uint32 *pAccessKey)
2298 {
2299     uint8 ItemIdx;
2300     Netc_EthSwt_Ip_CBDRStatusType status = NETC_ETHSWT_CBDRSTATUS_SUCCES;
2301 
2302     switch (accessMethod)
2303     {
2304         case NETC_ETHSWT_ENTRY_ID_MATCH:
2305             /* fill in Entry_ID field */
2306             TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ENTRYID_FIELD] = pAccessKey[0U];
2307             break;
2308         case NETC_ETHSWT_EXACT_MATCH_KEY_ELEMENT_MATCH:
2309             /* Not Applicable for Ingress Port Filter table*/
2310             status = NETC_ETHSWT_CBDRSTATUS_ACCESSMETHOD_ERROR;
2311             break;
2312         case NETC_ETHSWT_SEARCH_METHOD:
2313             /* fill in Resume_Entry_ID field */
2314             TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ENTRYID_FIELD] = pAccessKey[0U];
2315             break;
2316         case NETC_ETHSWT_TERNARY_MATCH_KEY_ELEMENT_MATCH:
2317             /* fill in keye_data field */
2318             for (ItemIdx = 1U; ItemIdx <= NETC_ETHSWT_IP_INGRESSPORTFILTERTABLE_KEYE_DATA_LEN; ItemIdx++)
2319             {
2320                 TableDataBuffer.TableDataField[ItemIdx] = pAccessKey[ItemIdx - 1U];
2321             }
2322             break;
2323         default:
2324             /* Not Applicable for Ingress Port Filter table*/
2325             status = NETC_ETHSWT_CBDRSTATUS_ACCESSMETHOD_ERROR;
2326             break;
2327     }
2328 
2329     return status;
2330 }
2331 
2332 /*FUNCTION**********************************************************************
2333  *
2334  * Function Name : Netc_EthSwt_Ip_FillInIngressPortFilterTableReqDataBuff
2335  * Description   : Internal function for initializing the Ingress Port Filter Table Request Data Buffer.
2336  *
2337  *END**************************************************************************/
Netc_EthSwt_Ip_FillInIngressPortFilterTableReqDataBuff(uint32 ActionsData,const volatile uint32 * pAccessKey,const Netc_EthSwt_Ip_IngressPortFilterCfgeDataType * pCfgeData,Netc_EthSwt_Ip_AccessMethodType accessMethod)2338 static Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_FillInIngressPortFilterTableReqDataBuff( uint32 ActionsData,
2339                                                                                              const volatile uint32 *pAccessKey,
2340                                                                                              const Netc_EthSwt_Ip_IngressPortFilterCfgeDataType *pCfgeData,
2341                                                                                              Netc_EthSwt_Ip_AccessMethodType accessMethod
2342                                                                                            )
2343 {
2344     Netc_EthSwt_Ip_CBDRStatusType status = NETC_ETHSWT_CBDRSTATUS_SUCCES;
2345 
2346     /* ------initialize the table request data buffer------ */
2347     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD] = ActionsData;  /* fill in Actions field */
2348 
2349     /* initialize ACCESS_KEY */
2350     status = FillInAccessKeyeData(accessMethod, pAccessKey);
2351 
2352     /* initialize CFGE_DATA. This portion is present only for commands which perform an update or add. */
2353     if (pCfgeData != NULL_PTR)
2354     {
2355         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_INGRESSPORTFILTER_CFGE_CONFIG_FIELD] = (NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_IPV(pCfgeData->CfgeIpv) \
2356                                                                                             | NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_OIPV(pCfgeData->CfgeOverrideIpv ? 1U : 0U) \
2357                                                                                             | NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_DR(pCfgeData->CfgeDr) \
2358                                                                                             | NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_ODR(pCfgeData->CfgeOverrideDr ? 1U : 0U) \
2359                                                                                             | NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_FLTFA(pCfgeData->CfgeFilterForwardingAction) \
2360                                                                                             | NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_IMIRE(pCfgeData->CfgeIngressMirroringEnable ? 1U : 0U) \
2361                                                                                             | NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_WOLTE(pCfgeData->CfgeWakeOnLanTriggerEnable ? 1U : 0U) \
2362                                                                                             | NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_FLTA(pCfgeData->CfgeFilterAction) \
2363                                                                                             | NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_RPR(pCfgeData->CfgeRelativePrecedentResolution) \
2364                                                                                             | NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_CTD(pCfgeData->CfgeCutThroughDisable? 1U : 0U) \
2365                                                                                             | NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_HR(pCfgeData->CfgeHostReason) \
2366                                                                                             | NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_TIMECAP(pCfgeData->CfgeTimestampCaptureEable ? 1U : 0U));
2367         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_INGRESSPORTFILTER_CFGE_FLTATGT_FIELD] = pCfgeData->CfgeTargetForSelectedFilterAction;
2368     }
2369 
2370     return status;
2371 }
2372 
2373 /*FUNCTION**********************************************************************
2374  *
2375  * Function Name : Netc_EthSwt_Ip_AddIngressPortFilterTableEntry
2376  * Description   : Ethernet Switch adds Ingress Port Filter table entry function.
2377  * implements Netc_EthSwt_Ip_AddIngressPortFilterTableEntry_Activity
2378  *END**************************************************************************/
Netc_EthSwt_Ip_AddIngressPortFilterTableEntry(uint8 SwitchIdx,uint32 * MatchedEntries,Netc_EthSwt_Ip_IngressPortFilterEntryDataType * IngressPortFilterTableEntry)2379 Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_AddIngressPortFilterTableEntry( uint8 SwitchIdx,
2380                                                                              uint32 *MatchedEntries,
2381                                                                              Netc_EthSwt_Ip_IngressPortFilterEntryDataType * IngressPortFilterTableEntry
2382                                                                            )
2383 {
2384     Netc_EthSwt_Ip_CBDRStatusType status;
2385     NetcEthSwt_Ip_ReqHeaderTableOperationDataType OperationData;
2386     uint32 ActionsData;
2387     uint8 ByteIdx;
2388     uint8 CfgeDataIdx;
2389     uint8 PayloadIdx;
2390 
2391 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
2392     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
2393     DevAssert(MatchedEntries != NULL_PTR);
2394     DevAssert(IngressPortFilterTableEntry != NULL_PTR);
2395 #endif
2396 
2397     /* set STSEU and CFGEU flag */
2398     ActionsData = (NETC_ETHSWT_IP_IPFTABLE_REQFMT_ACTIONS_FIELD_STSEU(1U) | NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD_CFGEU(1U));
2399 
2400     /* inialize KEYE_DATA */
2401     IPFKeyeData[0U] = IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyePrecedence;
2402     IPFKeyeData[2U] = ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeFrmAttributeFlagsMask) << NETC_ETHSWT_IP_16BIT_SHIFT) \
2403                  | IngressPortFilterTableEntry->IngressPortFilterkeyeData.keyeFrmAttributeFlags;
2404     IPFKeyeData[3U] = NETC_ETHSWT_IP_IPFTABLE_KEYE_DATA_SRCPORTMASK(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSourcePortIDMask) \
2405                  | NETC_ETHSWT_IP_IPFTABLE_KEYE_DATA_SRCPRTID(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSourcePortID) \
2406                  | NETC_ETHSWT_IP_IPFTABLE_KEYE_DATA_DSCPMASK(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDifferentiatedServicesCodePointMask) \
2407                  | NETC_ETHSWT_IP_IPFTABLE_KEYE_DATA_DIFFSCP(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDifferentiatedServicesCodePoint);
2408     IPFKeyeData[4U] = ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeOuterVLANTagControlInformationMask) << NETC_ETHSWT_IP_16BIT_SHIFT) \
2409                  | (IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeOuterVLANTagControlInformation << NETC_ETHSWT_IP_8BIT_SHIFT);        /* big endian for TCI */
2410     IPFKeyeData[5U] = (uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDstMacAddr[0U]) | ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDstMacAddr[1U]) << NETC_ETHSWT_IP_8BIT_SHIFT) \
2411                  | ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDstMacAddr[2U]) << NETC_ETHSWT_IP_16BIT_SHIFT) \
2412                  | ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDstMacAddr[3U]) << NETC_ETHSWT_IP_24BIT_SHIFT);
2413     IPFKeyeData[6U] = (uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDstMacAddr[4U]) | ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDstMacAddr[5U]) << NETC_ETHSWT_IP_8BIT_SHIFT) \
2414                  | (((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDstMacAddrMask[0U]) | ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDstMacAddrMask[1U]) << NETC_ETHSWT_IP_8BIT_SHIFT)) << NETC_ETHSWT_IP_16BIT_SHIFT);
2415     IPFKeyeData[7U] = (uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDstMacAddrMask[2U]) | ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDstMacAddrMask[3U]) << NETC_ETHSWT_IP_8BIT_SHIFT) \
2416                  | ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDstMacAddrMask[4U]) << NETC_ETHSWT_IP_16BIT_SHIFT) \
2417                  | ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDstMacAddrMask[5U]) << NETC_ETHSWT_IP_24BIT_SHIFT);
2418     IPFKeyeData[8U] = (uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSrcMacAddr[0U]) | ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSrcMacAddr[1U]) << NETC_ETHSWT_IP_8BIT_SHIFT) \
2419                  | ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSrcMacAddr[2U]) << NETC_ETHSWT_IP_16BIT_SHIFT) \
2420                  | ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSrcMacAddr[3U]) << NETC_ETHSWT_IP_24BIT_SHIFT);
2421     IPFKeyeData[9U] = (uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSrcMacAddr[4U]) | ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSrcMacAddr[5U]) << NETC_ETHSWT_IP_8BIT_SHIFT) \
2422                  | (((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSrcMacAddrMask[0U]) | ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSrcMacAddrMask[1U]) << NETC_ETHSWT_IP_8BIT_SHIFT)) << NETC_ETHSWT_IP_16BIT_SHIFT);
2423     IPFKeyeData[10U] = (uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSrcMacAddrMask[2U]) | ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSrcMacAddrMask[3U]) << NETC_ETHSWT_IP_8BIT_SHIFT) \
2424                  | ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSrcMacAddrMask[4U]) << NETC_ETHSWT_IP_16BIT_SHIFT) \
2425                  | ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSrcMacAddrMask[5U]) << NETC_ETHSWT_IP_24BIT_SHIFT);
2426     IPFKeyeData[11U] = ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeInnerVLANTagControlInformationMask) << NETC_ETHSWT_IP_16BIT_SHIFT) \
2427                  | IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeInnerVLANTagControlInformation;
2428     IPFKeyeData[12U] = ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeEtherTypeMask) << NETC_ETHSWT_IP_16BIT_SHIFT) \
2429                  | IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeEtherTypeMask;
2430     IPFKeyeData[13U] = ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeIPProtocolMask) << NETC_ETHSWT_IP_8BIT_SHIFT) | (uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeIPProtocol);
2431     for (ByteIdx = 0U; ByteIdx < 4U; ByteIdx++)
2432     {
2433         IPFKeyeData[ByteIdx + 17U] = IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeIPSourceAddress[ByteIdx];
2434     }
2435     for (ByteIdx = 0U; ByteIdx < 4U; ByteIdx++)
2436     {
2437         IPFKeyeData[ByteIdx + 23U] = IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeIPSourceAddressMask[ByteIdx];
2438     }
2439     IPFKeyeData[27U] = ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeL4SourcePortMask) << NETC_ETHSWT_IP_16BIT_SHIFT) | IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeL4SourcePort;
2440     for (ByteIdx = 0U; ByteIdx < 4U; ByteIdx++)
2441     {
2442         IPFKeyeData[ByteIdx + 29U] = IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeIPDestinationAddress[ByteIdx];
2443     }
2444     for (ByteIdx = 0U; ByteIdx < 4U; ByteIdx++)
2445     {
2446         IPFKeyeData[ByteIdx + 35U] = IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeIPDestinationAddressMask[ByteIdx];
2447     }
2448     IPFKeyeData[39U] = ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeL4DestinationPortMask) << NETC_ETHSWT_IP_16BIT_SHIFT) | IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeL4DestinationPort;
2449 
2450     CfgeDataIdx = 0U;
2451     PayloadIdx = 0U;
2452     for (ByteIdx = 0U; ByteIdx < 12U; ByteIdx++)
2453     {
2454         IPFKeyeData[CfgeDataIdx + 41U] = (uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyePayloadBytes[ByteIdx + PayloadIdx]) \
2455                                    | ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyePayloadBytesMask[ByteIdx + PayloadIdx]) << NETC_ETHSWT_IP_8BIT_SHIFT) \
2456                                    | ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyePayloadBytes[ByteIdx + PayloadIdx + 1U]) << NETC_ETHSWT_IP_16BIT_SHIFT) \
2457                                    | ((uint32)(IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyePayloadBytesMask[ByteIdx + PayloadIdx + 1U]) << NETC_ETHSWT_IP_24BIT_SHIFT);
2458         PayloadIdx++;
2459         CfgeDataIdx++;
2460     }
2461 
2462     /* only supports "NETC_ETHSWT_TERNARY_MATCH_KEY_ELEMENT_MATCH" access method */
2463     status = Netc_EthSwt_Ip_FillInIngressPortFilterTableReqDataBuff(ActionsData, &IPFKeyeData[0U], &(IngressPortFilterTableEntry->IngressPortFilterCfgeData), NETC_ETHSWT_TERNARY_MATCH_KEY_ELEMENT_MATCH);
2464     if (NETC_ETHSWT_CBDRSTATUS_SUCCES == status)
2465     {
2466         /* fill in operation data for config field of Request Header*/
2467         OperationData.CmdCompletionInt = 0x0U;                                        /* command completion interrupt disabled */
2468         OperationData.Version = NETC_ETHSWT_IP_CMDBD_REQFMT_PROTOCOL_VERSION;         /* protocol version = 2 */
2469         OperationData.TableId = NETC_ETHSWT_IP_INGRESS_PORT_FILTER_TABLE_ID;
2470         OperationData.AccessMethod = NETC_ETHSWT_TERNARY_MATCH_KEY_ELEMENT_MATCH;       /* for Adding an ingress port filter entry, the Access Method should only be NETC_ETHSWT_TERNARY_MATCH_KEY_ELEMENT_MATCH */
2471         OperationData.Cmd = NETC_ETHSWT_ADD_FOLLOWEDBY_QUERY_CMD;                       /* can only use "Add followed by a Query" command to add an ingress port filter table entry */
2472         OperationData.ReqBuffLength = (NETC_ETHSWT_IP_INGRESSPORTFILTERTABLE_REQBUFFER_LEN);
2473         OperationData.RspBuffLength = (NETC_ETHSWT_IP_INGRESSPORTFILTERTABLE_RSPBUFFER_LEN);
2474 
2475         /* send command */
2476         status = Netc_EthSwt_Ip_SendCommand(SwitchIdx, NETC_ETHSWT_IP_CBDR_0, &OperationData);
2477         /* Erroe code 0x8A is not a real error. check it on Errata. */
2478         if ((status == 0x8AU) || (status == NETC_ETHSWT_CBDRSTATUS_SUCCES))
2479         {
2480             Netc_EthSwt_Ip_GetMatchedEntries(NETC_ETHSWT_IP_CBDR_0, MatchedEntries);
2481             /* It's an "Add followed by a Query", but even if this entry is added successfully, the MatchedEntry is still 0. So here we can not check the MatchedEntries parameter. */
2482             IngressPortFilterTableEntry->IngressPortFilterEntryID = TableDataBuffer.TableDataField[1U];     /* Get the Entry_ID from response data buffer */
2483         }
2484     }
2485     else
2486     {
2487         status = NETC_ETHSWT_CBDRSTATUS_ACCESSMETHOD_ERROR;
2488     }
2489 
2490     return status;
2491 }
2492 
2493 /* inline function for filling in part of keye data in function FillInIPFTableEntryData() */
FillInKeyeDataForIPF(Netc_EthSwt_Ip_IngressPortFilterEntryDataType * IngressPortFilterTableEntry)2494 static inline void FillInKeyeDataForIPF(Netc_EthSwt_Ip_IngressPortFilterEntryDataType * IngressPortFilterTableEntry)
2495 {
2496     uint8 ByteIdx;
2497     uint8 PayloadIdx;
2498     uint8 CfgeDataIdx;
2499 
2500     for (ByteIdx = 2U; ByteIdx < 6U; ByteIdx++)
2501     {
2502         IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSrcMacAddrMask[ByteIdx] = (uint8)(TableDataBuffer.TableDataField[12U] & NETC_ETHSWT_IP_0XFF_MASK);
2503         TableDataBuffer.TableDataField[12U] >>= NETC_ETHSWT_IP_8BIT_SHIFT;
2504     }
2505     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeInnerVLANTagControlInformation = (uint16)(TableDataBuffer.TableDataField[13U] & NETC_ETHSWT_IP_0XFFFF_MASK);
2506     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeInnerVLANTagControlInformationMask = (uint16)((TableDataBuffer.TableDataField[13U] >> NETC_ETHSWT_IP_16BIT_SHIFT) & NETC_ETHSWT_IP_0XFFFF_MASK);
2507     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeEtherType = (uint16)(TableDataBuffer.TableDataField[14U] & NETC_ETHSWT_IP_0XFFFF_MASK);
2508     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeEtherTypeMask = (uint16)((TableDataBuffer.TableDataField[14U] >> NETC_ETHSWT_IP_16BIT_SHIFT) & NETC_ETHSWT_IP_0XFFFF_MASK);
2509     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeIPProtocol = (uint8)(TableDataBuffer.TableDataField[15U] & NETC_ETHSWT_IP_0XFF_MASK);
2510     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeIPProtocolMask = (uint8)((TableDataBuffer.TableDataField[15U] >> NETC_ETHSWT_IP_8BIT_SHIFT) & NETC_ETHSWT_IP_0XFF_MASK);
2511     for (ByteIdx = 0U; ByteIdx < 4U; ByteIdx++)
2512     {
2513         IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeIPSourceAddress[ByteIdx] = TableDataBuffer.TableDataField[ByteIdx + 19U];
2514     }
2515     for (ByteIdx = 0U; ByteIdx < 4U; ByteIdx++)
2516     {
2517         IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeIPSourceAddressMask[ByteIdx] = TableDataBuffer.TableDataField[ByteIdx + 25U];
2518     }
2519     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeL4SourcePort = (uint16)(TableDataBuffer.TableDataField[29U] & NETC_ETHSWT_IP_0XFFFF_MASK);
2520     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeL4SourcePortMask = (uint16)((TableDataBuffer.TableDataField[29U] >> NETC_ETHSWT_IP_16BIT_SHIFT) & NETC_ETHSWT_IP_0XFFFF_MASK);
2521     for (ByteIdx = 0U; ByteIdx < 4U; ByteIdx++)
2522     {
2523         IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeIPDestinationAddress[ByteIdx] = TableDataBuffer.TableDataField[ByteIdx + 31U];
2524     }
2525     for (ByteIdx = 0U; ByteIdx < 4U; ByteIdx++)
2526     {
2527         IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeIPDestinationAddressMask[ByteIdx] = TableDataBuffer.TableDataField[ByteIdx + 37U];
2528     }
2529     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeL4DestinationPort = (uint16)(TableDataBuffer.TableDataField[41U] & NETC_ETHSWT_IP_0XFFFF_MASK);
2530     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeL4DestinationPortMask = (uint16)((TableDataBuffer.TableDataField[41U] >> NETC_ETHSWT_IP_16BIT_SHIFT) & NETC_ETHSWT_IP_0XFFFF_MASK);
2531 
2532     CfgeDataIdx = 0U;
2533     PayloadIdx = 0U;
2534     for (ByteIdx = 0U; ByteIdx < 12U; ByteIdx++)
2535     {
2536         IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyePayloadBytes[ByteIdx + PayloadIdx] = (uint8)(TableDataBuffer.TableDataField[CfgeDataIdx + 43U] & NETC_ETHSWT_IP_0XFF_MASK);
2537         IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyePayloadBytes[ByteIdx + PayloadIdx + 1U] = (uint8)((TableDataBuffer.TableDataField[CfgeDataIdx + 43U] >> NETC_ETHSWT_IP_16BIT_SHIFT) & NETC_ETHSWT_IP_0XFF_MASK);
2538         IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyePayloadBytesMask[ByteIdx + PayloadIdx] = (uint8)((TableDataBuffer.TableDataField[CfgeDataIdx + 43U] >> NETC_ETHSWT_IP_8BIT_SHIFT) & NETC_ETHSWT_IP_0XFF_MASK);
2539         IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyePayloadBytesMask[ByteIdx + PayloadIdx + 1U] = (uint8)((TableDataBuffer.TableDataField[CfgeDataIdx + 43U] >> NETC_ETHSWT_IP_24BIT_SHIFT) & NETC_ETHSWT_IP_0XFF_MASK);
2540         PayloadIdx++;
2541         CfgeDataIdx++;
2542     }
2543 }
2544 
2545 /* inline function for filling in IngressPortFilterTableEntry data in function Netc_EthSwt_Ip_QueryIngressPortFilterTableEntry() */
FillInIPFTableEntryData(Netc_EthSwt_Ip_IngressPortFilterEntryDataType * IngressPortFilterTableEntry)2546 static inline void FillInIPFTableEntryData(Netc_EthSwt_Ip_IngressPortFilterEntryDataType * IngressPortFilterTableEntry)
2547 {
2548     uint8 ByteIdx;
2549     uint32 CfgeData;
2550 
2551     /* fill in structure Netc_EthSwt_Ip_IngressPortFilterEntryDataType with data from response data buffer */
2552     IngressPortFilterTableEntry->IngressPortFilterEntryID = TableDataBuffer.TableDataField[1U];         /* Entry_ID */
2553 
2554     /* KEYE_DATA */
2555     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyePrecedence = (uint16)(TableDataBuffer.TableDataField[2U] & NETC_ETHSWT_IP_0XFFFF_MASK);
2556     IngressPortFilterTableEntry->IngressPortFilterkeyeData.keyeFrmAttributeFlags = (uint16)(TableDataBuffer.TableDataField[4U] & NETC_ETHSWT_IP_0XFFFF_MASK);
2557     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeFrmAttributeFlagsMask = (uint16)((TableDataBuffer.TableDataField[4U] & NETC_ETHSWT_IP_0XFFFF0000_MASK) >> NETC_ETHSWT_IP_16BIT_SHIFT);
2558     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDifferentiatedServicesCodePoint = (uint8)(TableDataBuffer.TableDataField[5U] & NETC_ETHSWT_IP_IPFTABLE_KEYE_DATA_DIFFSCP_MASK);
2559     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDifferentiatedServicesCodePointMask = (uint8)((TableDataBuffer.TableDataField[5U] & NETC_ETHSWT_IP_IPFTABLE_KEYE_DATA_DSCPMASK_MASK) \
2560                                                                                                     >> NETC_ETHSWT_IP_IPFTABLE_KEYE_DATA_DSCPMASK_SHIFT);
2561     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSourcePortID = (uint8)((TableDataBuffer.TableDataField[5U] & NETC_ETHSWT_IP_IPFTABLE_KEYE_DATA_SRCPRTID_MASK) \
2562                                                                                     >> NETC_ETHSWT_IP_IPFTABLE_KEYE_DATA_SRCPRTID_SHIFT);
2563     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSourcePortIDMask = (uint8)((TableDataBuffer.TableDataField[5U] & NETC_ETHSWT_IP_IPFTABLE_KEYE_DATA_SRCPORTMASK_MASK) \
2564                                                                                     >> NETC_ETHSWT_IP_IPFTABLE_KEYE_DATA_SRCPORTMASK_SHIFT);
2565     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeOuterVLANTagControlInformation = (uint16)(TableDataBuffer.TableDataField[6U] & NETC_ETHSWT_IP_0XFFFF_MASK);
2566     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeOuterVLANTagControlInformationMask = (uint16)((TableDataBuffer.TableDataField[6U] & NETC_ETHSWT_IP_0XFFFF0000_MASK) >> NETC_ETHSWT_IP_16BIT_SHIFT);
2567     for (ByteIdx = 0U; ByteIdx < 4U; ByteIdx++)
2568     {
2569         IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDstMacAddr[ByteIdx] = (uint8)(TableDataBuffer.TableDataField[7U] & NETC_ETHSWT_IP_0XFF_MASK);
2570         TableDataBuffer.TableDataField[7U] >>= NETC_ETHSWT_IP_8BIT_SHIFT;
2571     }
2572     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDstMacAddr[4U] = (uint8)(TableDataBuffer.TableDataField[8U] & NETC_ETHSWT_IP_0XFF_MASK);
2573     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDstMacAddr[5U] = (uint8)((TableDataBuffer.TableDataField[8U] >> NETC_ETHSWT_IP_8BIT_SHIFT) & NETC_ETHSWT_IP_0XFF_MASK);
2574     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDstMacAddrMask[0U] = (uint8)((TableDataBuffer.TableDataField[8U] >> NETC_ETHSWT_IP_16BIT_SHIFT) & NETC_ETHSWT_IP_0XFF_MASK);
2575     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDstMacAddrMask[1U] = (uint8)((TableDataBuffer.TableDataField[8U] >> NETC_ETHSWT_IP_24BIT_SHIFT) & NETC_ETHSWT_IP_0XFF_MASK);
2576     for (ByteIdx = 2U; ByteIdx < 6U; ByteIdx++)
2577     {
2578         IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDstMacAddrMask[ByteIdx] = (uint8)(TableDataBuffer.TableDataField[9U] & NETC_ETHSWT_IP_0XFF_MASK);
2579         TableDataBuffer.TableDataField[9U] >>= NETC_ETHSWT_IP_8BIT_SHIFT;
2580     }
2581     for (ByteIdx = 0U; ByteIdx < 4U; ByteIdx++)
2582     {
2583         IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSrcMacAddr[ByteIdx] = (uint8)(TableDataBuffer.TableDataField[10U] & NETC_ETHSWT_IP_0XFF_MASK);
2584         TableDataBuffer.TableDataField[10U] >>= NETC_ETHSWT_IP_8BIT_SHIFT;
2585     }
2586     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSrcMacAddr[4U] = (uint8)(TableDataBuffer.TableDataField[11U] & NETC_ETHSWT_IP_0XFF_MASK);
2587     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSrcMacAddr[5U] = (uint8)((TableDataBuffer.TableDataField[11U] >> NETC_ETHSWT_IP_8BIT_SHIFT) & NETC_ETHSWT_IP_0XFF_MASK);
2588     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSrcMacAddrMask[0U] = (uint8)((TableDataBuffer.TableDataField[11U] >> NETC_ETHSWT_IP_16BIT_SHIFT) & NETC_ETHSWT_IP_0XFF_MASK);
2589     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSrcMacAddrMask[1U] = ((uint8)(TableDataBuffer.TableDataField[11U] >> NETC_ETHSWT_IP_24BIT_SHIFT) & NETC_ETHSWT_IP_0XFF_MASK);
2590 
2591     FillInKeyeDataForIPF(IngressPortFilterTableEntry);  /* fill in the rest part of the KEYE_DATA */
2592 
2593     /* Match Count data */
2594     IngressPortFilterTableEntry->IngressPortFilterMatchCount = (uint64)(TableDataBuffer.TableDataField[55U]);
2595     IngressPortFilterTableEntry->IngressPortFilterMatchCount |= ((uint64)(TableDataBuffer.TableDataField[56U]) << NETC_ETHSWT_IP_32BIT_SHIFT);
2596 
2597     /* CFGE_DATA */
2598     CfgeData = TableDataBuffer.TableDataField[57U];             /* config field in CFGE_DATA */
2599     IngressPortFilterTableEntry->IngressPortFilterCfgeData.CfgeIpv = (uint8)(CfgeData & NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_IPV_MASK);
2600     IngressPortFilterTableEntry->IngressPortFilterCfgeData.CfgeOverrideIpv = (((CfgeData & NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_OIPV_MASK) >> NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_OIPV_SHIFT) != 0x0UL) ? TRUE : FALSE;
2601     IngressPortFilterTableEntry->IngressPortFilterCfgeData.CfgeDr = (uint8)((CfgeData & NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_DR_MASK) >> NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_DR_SHIFT);
2602     IngressPortFilterTableEntry->IngressPortFilterCfgeData.CfgeOverrideDr = (((CfgeData & NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_ODR_MASK) >> NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_ODR_SHIFT) != 0x0UL) ? TRUE : FALSE;
2603     IngressPortFilterTableEntry->IngressPortFilterCfgeData.CfgeFilterForwardingAction = ((CfgeData & NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_FLTFA_MASK) >> NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_FLTFA_SHIFT);
2604     IngressPortFilterTableEntry->IngressPortFilterCfgeData.CfgeIngressMirroringEnable = (((CfgeData & NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_IMIRE_MASK) >> NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_IMIRE_SHIFT) != 0x0UL) ? TRUE : FALSE;
2605     IngressPortFilterTableEntry->IngressPortFilterCfgeData.CfgeWakeOnLanTriggerEnable = (((CfgeData & NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_WOLTE_MASK) >> NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_WOLTE_SHIFT) != 0x0UL) ? TRUE : FALSE;
2606     IngressPortFilterTableEntry->IngressPortFilterCfgeData.CfgeFilterAction = ((CfgeData & NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_FLTA_MASK) >> NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_FLTA_SHIFT);
2607     IngressPortFilterTableEntry->IngressPortFilterCfgeData.CfgeRelativePrecedentResolution = (uint8)((CfgeData & NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_RPR_MASK) >> NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_RPR_SHIFT);
2608     IngressPortFilterTableEntry->IngressPortFilterCfgeData.CfgeCutThroughDisable = (((CfgeData & NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_CTD_MASK) >> NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_CTD_SHIFT) != 0x0UL) ? TRUE : FALSE;
2609     IngressPortFilterTableEntry->IngressPortFilterCfgeData.CfgeHostReason = (uint8)((CfgeData & NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_HR_MASK) >> NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_HR_SHIFT);
2610     IngressPortFilterTableEntry->IngressPortFilterCfgeData.CfgeTimestampCaptureEable = (((CfgeData & NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_TIMECAP_MASK) >> NETC_ETHSWT_IP_IPFTABLE_CFGE_CONFIG_TIMECAP_SHIFT) != 0x0UL) ? TRUE : FALSE;
2611 }
2612 
2613 /*FUNCTION**********************************************************************
2614  *
2615  * Function Name : Netc_EthSwt_Ip_QueryIngressPortFilterTableEntry
2616  * Description   : Ethernet Switch querys Ingress Port Filter table entry function.
2617  * implements Netc_EthSwt_Ip_QueryIngressPortFilterTableEntry_Activity
2618  *END**************************************************************************/
Netc_EthSwt_Ip_QueryIngressPortFilterTableEntry(uint8 SwitchIdx,uint32 * MatchedEntries,Netc_EthSwt_Ip_IngressPortFilterEntryDataType * IngressPortFilterTableEntry)2619 Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_QueryIngressPortFilterTableEntry( uint8 SwitchIdx,
2620                                                                                uint32 *MatchedEntries,
2621                                                                                Netc_EthSwt_Ip_IngressPortFilterEntryDataType * IngressPortFilterTableEntry
2622                                                                              )
2623 {
2624     Netc_EthSwt_Ip_CBDRStatusType status;
2625     NetcEthSwt_Ip_ReqHeaderTableOperationDataType OperationData;
2626     uint32 KeyeData[NETC_ETHSWT_IP_INGRESSPORTFILTERTABLE_KEYE_DATA_LEN];
2627     uint32 ActionsData;
2628 
2629 
2630 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
2631     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
2632     DevAssert(MatchedEntries != NULL_PTR);
2633     DevAssert(IngressPortFilterTableEntry != NULL_PTR);
2634 #endif
2635 
2636     /* only support "full query" */
2637     ActionsData = NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD_QUERY_ACTIONS(NETC_ETHSWT_TABLES_FULL_QUERY);
2638 
2639     /* inialize KEYE_DATA with Entry_ID */
2640     KeyeData[0U] = IngressPortFilterTableEntry->IngressPortFilterEntryID;
2641 
2642     status = Netc_EthSwt_Ip_FillInIngressPortFilterTableReqDataBuff(ActionsData, &KeyeData[0U], NULL_PTR, NETC_ETHSWT_ENTRY_ID_MATCH);
2643     if (NETC_ETHSWT_CBDRSTATUS_SUCCES == status)
2644     {
2645         /* fill in operation data for config field of Request Header*/
2646         OperationData.CmdCompletionInt = 0x0U;                                        /* command completion interrupt disabled */
2647         OperationData.Version = NETC_ETHSWT_IP_CMDBD_REQFMT_PROTOCOL_VERSION;         /* protocol version = 2 */
2648         OperationData.TableId = NETC_ETHSWT_IP_INGRESS_PORT_FILTER_TABLE_ID;
2649         OperationData.AccessMethod = NETC_ETHSWT_ENTRY_ID_MATCH;
2650         OperationData.Cmd = NETC_ETHSWT_QUERY_CMD;
2651         OperationData.ReqBuffLength = (NETC_ETHSWT_IP_INGRESSPORTFILTERTABLE_REQBUFFER_LEN);
2652         OperationData.RspBuffLength = (NETC_ETHSWT_IP_INGRESSPORTFILTERTABLE_RSPBUFFER_LEN);
2653 
2654         /* send command */
2655         status = Netc_EthSwt_Ip_SendCommand(SwitchIdx, NETC_ETHSWT_IP_CBDR_0, &OperationData);
2656         /* Error code 0x8A is not a real error. check it on Errata. */
2657         if ((status == 0x8AU) || (status == NETC_ETHSWT_CBDRSTATUS_SUCCES))
2658         {
2659             Netc_EthSwt_Ip_GetMatchedEntries(NETC_ETHSWT_IP_CBDR_0, MatchedEntries);
2660             /* if found a matched entry, then fill in the structure */
2661             if (1U == *MatchedEntries)
2662             {
2663                 FillInIPFTableEntryData(IngressPortFilterTableEntry);
2664             }
2665         }
2666     }
2667     else
2668     {
2669         status = NETC_ETHSWT_CBDRSTATUS_ACCESSMETHOD_ERROR;
2670     }
2671 
2672     return status;
2673 }
2674 
2675 /*FUNCTION**********************************************************************
2676  *
2677  * Function Name : Netc_EthSwt_Ip_DeleteIngressPortFilterTableEntry
2678  * Description   : Ethernet Switch deletes Ingress Port Filter table entry function.
2679  * implements Netc_EthSwt_Ip_DeleteIngressPortFilterTableEntry_Activity
2680  *END**************************************************************************/
Netc_EthSwt_Ip_DeleteIngressPortFilterTableEntry(uint8 SwitchIdx,uint32 * MatchedEntries,uint32 IngressPortFilterEntry)2681 Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_DeleteIngressPortFilterTableEntry( uint8 SwitchIdx,
2682                                                                                 uint32 *MatchedEntries,
2683                                                                                 uint32 IngressPortFilterEntry
2684                                                                               )
2685 {
2686     Netc_EthSwt_Ip_CBDRStatusType status;
2687     NetcEthSwt_Ip_ReqHeaderTableOperationDataType OperationData;
2688     uint32 KeyeData[1U];
2689     uint32 ActionsData = 0x0UL;
2690 
2691 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
2692     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
2693     DevAssert(MatchedEntries != NULL_PTR);
2694 #endif
2695 
2696     /* inialize KEYE_DATA with Entry_ID */
2697     KeyeData[0U] = IngressPortFilterEntry;
2698 
2699     status = Netc_EthSwt_Ip_FillInIngressPortFilterTableReqDataBuff(ActionsData, &KeyeData[0U], NULL_PTR, NETC_ETHSWT_ENTRY_ID_MATCH);
2700     if (NETC_ETHSWT_CBDRSTATUS_SUCCES == status)
2701     {
2702         /* fill in operation data for config field of Request Header*/
2703         OperationData.CmdCompletionInt = 0x0U;                                        /* command completion interrupt disabled */
2704         OperationData.Version = NETC_ETHSWT_IP_CMDBD_REQFMT_PROTOCOL_VERSION;         /* protocol version = 2 */
2705         OperationData.TableId = NETC_ETHSWT_IP_INGRESS_PORT_FILTER_TABLE_ID;
2706         OperationData.AccessMethod = NETC_ETHSWT_ENTRY_ID_MATCH;
2707         OperationData.Cmd = NETC_ETHSWT_DELETE_CMD;
2708         OperationData.ReqBuffLength = (NETC_ETHSWT_IP_INGRESSPORTFILTERTABLE_REQBUFFER_LEN);
2709         OperationData.RspBuffLength = (NETC_ETHSWT_IP_INGRESSPORTFILTERTABLE_RSPBUFFER_LEN);
2710 
2711         /* send command */
2712         status = Netc_EthSwt_Ip_SendCommand(SwitchIdx, NETC_ETHSWT_IP_CBDR_0, &OperationData);
2713         /* Erroe code 0x8A is not a real error. check it on Errata. */
2714         if ((status == 0x8AU) || (status == NETC_ETHSWT_CBDRSTATUS_SUCCES))
2715         {
2716             Netc_EthSwt_Ip_GetMatchedEntries(NETC_ETHSWT_IP_CBDR_0, MatchedEntries);
2717         }
2718     }
2719     else
2720     {
2721         status = NETC_ETHSWT_CBDRSTATUS_ACCESSMETHOD_ERROR;
2722     }
2723 
2724     return status;
2725 }
2726 
2727 /*FUNCTION**********************************************************************
2728  *
2729  * Function Name : Netc_EthSwt_Ip_ConfigPortTimeGateScheduling
2730  * Description   : Ethernet Switch enables or disables Time Gate Scheduling function on a port.
2731  *
2732  *END**************************************************************************/
Netc_EthSwt_Ip_ConfigPortTimeGateScheduling(uint8 SwitchIdx,uint8 SwitchPortIdx,boolean Enable)2733 Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_ConfigPortTimeGateScheduling( uint8 SwitchIdx,
2734                                                                            uint8 SwitchPortIdx,
2735                                                                            boolean Enable
2736                                                                          )
2737 {
2738     Netc_EthSwt_Ip_CBDRStatusType status = NETC_ETHSWT_CBDRSTATUS_SUCCES;
2739     uint32 RegValue;
2740     uint32 GateControlListState;
2741     uint32 StartTime;
2742     uint32 ElapsedTime;
2743     uint32 TimeoutTicks;
2744     boolean TimeExpired;
2745 
2746 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
2747     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
2748     DevAssert(SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_PORTS);
2749 #endif
2750 
2751     /* Software must also wait until PTGAGLSR[TG] is deasserted before re-enabling. */
2752     Netc_EthSwt_Ip_StartTimeOut(&StartTime, &ElapsedTime, &TimeoutTicks, NETC_ETHSWT_IP_TIMEOUT_VALUE_US);
2753     do {
2754         /* get the state of gate control list */
2755         GateControlListState = (Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->PTGAGLSR & SW_PORT0_PTGAGLSR_TG_MASK);
2756         TimeExpired = Netc_EthSwt_Ip_TimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
2757     } while ((GateControlListState != 0x0U) && (FALSE == TimeExpired));
2758 
2759     if (GateControlListState == 0x0U)
2760     {
2761         /* read the reg value first */
2762         RegValue = Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->PTGSCR;
2763 
2764         if (TRUE == Enable)
2765         {
2766             RegValue |= SW_PORT0_PTGSCR_TGE(1U);    /* Enable time gating */
2767         }
2768         else
2769         {
2770             RegValue &= ~SW_PORT0_PTGSCR_TGE(1U);    /* Disable time gating */
2771         }
2772 
2773         /* write it back. */
2774         Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->PTGSCR = RegValue;
2775 
2776         /* if time gate scheduling is enabled, and entry data is configured, then adds the entry */
2777         if ((TRUE == Enable) && (TRUE == PortTimeAwareShaperEnabled[SwitchPortIdx]))
2778         {
2779             status = Netc_EthSwt_Ip_AddOrUpdateTimeGateSchedulingTableEntry(0U, &TimeGateSchedulingEntryData[SwitchPortIdx]);
2780             /* fail to add or update the time gate schedulling table entry */
2781             if (status != NETC_ETHSWT_CBDRSTATUS_SUCCES)
2782             {
2783                 status = E_NOT_OK;
2784             }
2785         }
2786     }
2787     else
2788     {
2789         status = E_NOT_OK;
2790     }
2791 
2792     return status;
2793 }
2794 
FillInGateControlListData(const uint8 * OperationTimeIdx,const Netc_EthSwt_Ip_TimeGateSchedulingEntryDataType * TimeGateSchedulingTableEntry)2795 static inline void FillInGateControlListData(const uint8 *OperationTimeIdx, const Netc_EthSwt_Ip_TimeGateSchedulingEntryDataType *TimeGateSchedulingTableEntry)
2796 {
2797     uint8 CFGEDataIdx;
2798     uint16 GateEntryIdx;
2799     uint8 HostRequest;
2800 
2801     if (*OperationTimeIdx == 1U)
2802     {
2803         CFGEDataIdx = 0U;
2804         for (GateEntryIdx = 0U; GateEntryIdx < TimeGateSchedulingTableEntry->AdminControlListLength; GateEntryIdx++)
2805         {
2806             TableDataBuffer.TableDataField[(uint8)(NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_CFGEDATA5) + CFGEDataIdx] = TimeGateSchedulingTableEntry->GateEntryAdminControlListData[GateEntryIdx].AdminTimeInterval;
2807             /* convert gate operation type */
2808             switch (TimeGateSchedulingTableEntry->GateEntryAdminControlListData[GateEntryIdx].AdminGateOperationType)
2809             {
2810                 case ETHSWT_HOST_REQUEST_UNCHANGED:
2811                     HostRequest = 0U;
2812                     break;
2813                 case ETHSWT_HOST_REQUEST_HOLD:
2814                     HostRequest = 1U;
2815                     break;
2816                 case ETHSWT_HOST_REQUEST_RELEASE:
2817                     HostRequest = 2U;
2818                     break;
2819                 default:
2820                     HostRequest = 0U;
2821                     break;
2822             }
2823             TableDataBuffer.TableDataField[(uint8)(NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_CFGEDATA6) + CFGEDataIdx] = NETC_ETHSWT_IP_TGSTABLE_CFGE_ADMIN_TC_STATES(TimeGateSchedulingTableEntry->GateEntryAdminControlListData[GateEntryIdx].AdminTrafficClassGateStates) \
2824                                                                                                         | NETC_ETHSWT_IP_TGSTABLE_CFGE_ADMIN_HR_CB(HostRequest);
2825 
2826             CFGEDataIdx += 2U;      /* CFGE data field index increased by 2 */
2827         }
2828     }
2829 }
2830 
2831 /*FUNCTION**********************************************************************
2832  *
2833  * Function Name : Netc_EthSwt_Ip_AddOrUpdateTimeGateSchedulingTableEntry
2834  * Description   : Ethernet Switch adds or updates Time Gate Scheduling table entry function.
2835  *
2836  *END**************************************************************************/
Netc_EthSwt_Ip_AddOrUpdateTimeGateSchedulingTableEntry(uint8 SwitchIdx,const Netc_EthSwt_Ip_TimeGateSchedulingEntryDataType * TimeGateSchedulingTableEntry)2837 Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_AddOrUpdateTimeGateSchedulingTableEntry( uint8 SwitchIdx,
2838                                                                                       const Netc_EthSwt_Ip_TimeGateSchedulingEntryDataType *TimeGateSchedulingTableEntry
2839                                                                                     )
2840 {
2841     Netc_EthSwt_Ip_CBDRStatusType status = NETC_ETHSWT_CBDRSTATUS_SUCCES;
2842     NetcEthSwt_Ip_ReqHeaderTableOperationDataType OperationData;
2843     uint8 OperationTimes;
2844     uint8 OperationTimeIdx;
2845     volatile uint64 CurrentTime = 0;
2846     uint32 CycleFactor;
2847     uint64 NewBaseTime;
2848     uint32 LookaheadTime;
2849 
2850 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
2851     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
2852     DevAssert(TimeGateSchedulingTableEntry != NULL_PTR);
2853 #endif
2854 
2855     /* AdminControlListLength = 0U means to reset the gate control list or add the time gate scheduling entry without gate control list */
2856     OperationTimes = (TimeGateSchedulingTableEntry->AdminControlListLength > 0U) ? 2U : 1U;
2857 
2858     /* for adding or updating gate control list, we'll have to remove the gate control list firstly */
2859     for (OperationTimeIdx = 0U; OperationTimeIdx < OperationTimes; OperationTimeIdx++)
2860     {
2861         /* ++++++ initialize the table request data buffer ++++++ */
2862         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD] = NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD_CFGEU(1U);    /* fill in Actions field */
2863         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ENTRYID_FIELD] = TimeGateSchedulingTableEntry->TimeGateSchedulingTable_EID;    /* fill in Entry ID */
2864         /* fill in CFGE_DATA */
2865         /* get the current time from 1588 timer */
2866         CurrentTime = IP_NETC__TMR0_BASE->TMR_CUR_TIME_L;      /* should read the Lower register first */
2867         CurrentTime |= ((uint64)(IP_NETC__TMR0_BASE->TMR_CUR_TIME_H)) << NETC_ETHSWT_IP_32BIT_SHIFT;
2868         /* get lookaheadtime */
2869         LookaheadTime = IP_NETC__NETC_IERB->CFG_SW_INST[0U].STGSLR; /* [Ricky]TODO: this register is not available for now + Netc_EthSwt_Ip_SW0_PortxBaseAddr[portIndex]->RESERVED_7; */
2870 
2871         /* calculate the NewBaseTime */
2872         if (TimeGateSchedulingTableEntry->AdminBaseTime >= (CurrentTime + LookaheadTime))
2873         {
2874             NewBaseTime = TimeGateSchedulingTableEntry->AdminBaseTime;
2875         }
2876         else
2877         {
2878             CycleFactor = (uint32)(CurrentTime + LookaheadTime - TimeGateSchedulingTableEntry->AdminBaseTime) / (TimeGateSchedulingTableEntry->AdminCycleTime);
2879             NewBaseTime = TimeGateSchedulingTableEntry->AdminBaseTime + (((uint64)CycleFactor + 1UL) * (uint64)(TimeGateSchedulingTableEntry->AdminCycleTime));
2880         }
2881         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_CFGEDATA0] = (uint32)(NewBaseTime & (0xFFFFFFFFUL));
2882         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_CFGEDATA1] = (uint32)(NewBaseTime >> NETC_ETHSWT_IP_32BIT_SHIFT);
2883         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_CFGEDATA2] = TimeGateSchedulingTableEntry->AdminCycleTime;
2884         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_CFGEDATA3] = TimeGateSchedulingTableEntry->AdminCycleTimeExt;
2885         /* set Administrative Control List Length to 0 for removing the admin gate control list or adding an entry with no administrative gate control list */
2886         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_CFGEDATA4] = (OperationTimeIdx == 0U) ? 0x0UL : (uint32)(TimeGateSchedulingTableEntry->AdminControlListLength);
2887 
2888         FillInGateControlListData(&OperationTimeIdx, TimeGateSchedulingTableEntry);
2889         /* ------ initialize the table request data buffer ------ */
2890 
2891         /* fill in operation data for config field of Request Header*/
2892         OperationData.CmdCompletionInt = 0x0U;                                        /* command completion interrupt disabled */
2893         OperationData.Version = NETC_ETHSWT_IP_CMDBD_REQFMT_PROTOCOL_VERSION;         /* protocol version = 2 */
2894         OperationData.TableId = NETC_ETHSWT_IP_TIME_GATE_SCHEDULING_TABLE_ID;
2895         OperationData.AccessMethod = NETC_ETHSWT_ENTRY_ID_MATCH;                      /* only support NETC_ETHSWT_ENTRY_ID_MATCH method */
2896         OperationData.Cmd = NETC_ETHSWT_UPDATE_CMD;                                   /* can only use "update" command to add or update an time gate scheduling table entry */
2897         OperationData.ReqBuffLength = (NETC_ETHSWT_IP_INGRESSPORTFILTERTABLE_REQBUFFER_LEN);    /* [Ricky]TODO: follow-up work needs to do. */
2898         OperationData.RspBuffLength = (NETC_ETHSWT_IP_INGRESSPORTFILTERTABLE_RSPBUFFER_LEN);
2899 
2900         /* send "update" command to add/remove gate control list */
2901         status = Netc_EthSwt_Ip_SendCommand(SwitchIdx, NETC_ETHSWT_IP_CBDR_0, &OperationData);
2902         /* Erroe code 0x8A is not a real error. check it on Errata. */
2903         if ((status == 0x8AU) || (status == NETC_ETHSWT_CBDRSTATUS_SUCCES))
2904         {
2905             status = NETC_ETHSWT_CBDRSTATUS_SUCCES;
2906         }
2907     }
2908 
2909     return status;
2910 }
2911 
2912 /*!
2913  * @brief Ethernet Switch get port index counter values function.
2914  *
2915  * @param[in]
2916  * @param[out]
2917  * @return
2918  */
Netc_EthSwt_Ip_GetSwtPortCounters(uint8 SwitchIdx,uint8 portIndex,Netc_EthSwt_Ip_CounterType * Counter)2919 static Std_ReturnType Netc_EthSwt_Ip_GetSwtPortCounters( uint8 SwitchIdx, uint8 portIndex, Netc_EthSwt_Ip_CounterType *Counter )
2920 {
2921     volatile uint32 *xCR0Value;
2922     volatile uint32 *xCR1Value;
2923 
2924     (void)SwitchIdx;
2925 
2926     /* Receive */
2927     /* Port MAC index Receive Ethernet Octets Counter(etherStatsOctetsn) */
2928     xCR0Value = (volatile uint32 *)(&(Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_REOCTN));
2929     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_REOCTN) + 1U;
2930     Counter->rxEtherOctetCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
2931 
2932 
2933     /* Port MAC index Receive Octets Counter(iflnOctetsn)  */
2934     xCR0Value = (volatile uint32 *)(&(Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_ROCTN));
2935     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_ROCTN) + 1U;
2936     Counter->rxOctetCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
2937 
2938     /* Port MAC index Receive Alignment Error Counter Register(aAlignmentErrorsn) */
2939     /* Reserved */
2940 
2941     /* Port MAC index Receive Valid Pause Frame Counter Register(aPAUSEMACCtrlFramesReceivedn) */
2942     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RXPFN);
2943     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RXPFN) + 1U;
2944     Counter->rxValidPauseFrmCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
2945 
2946     /* Port MAC index Receive Frame Counter */
2947     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RFRMN);
2948     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RFRMN) + 1U;
2949     Counter->rxFrmCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
2950 
2951     /* Port MAC index Receive Frame Check Sequence Error Counter */
2952     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RFCSN);
2953     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RFCSN) + 1U;
2954     Counter->rxFrameCheckSequenceErrorCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
2955 
2956     /* Port MAC index Receive VLAN Frame Counter */
2957     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RVLANN);
2958     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RVLANN) + 1U;
2959     Counter->rxVlanFrmCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
2960 
2961     /* Port MAC index Receive Frame Error Counter Register(ifInErrorsn) */
2962     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RERRN);
2963     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RERRN) + 1U;
2964     Counter->rxFrameErrorCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
2965 
2966     /* Port MAC index Receive Unicast Frame Counter */
2967     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RUCAN);
2968     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RUCAN) + 1U;
2969     Counter->rxUnicastFrmCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
2970 
2971     /* Port MAC index Receive Multicast Frame Counter */
2972     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RMCAN);
2973     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RMCAN) + 1U;
2974     Counter->rxMulticastFrmCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
2975 
2976     /* Port MAC index Receive Broadcast Frame Counter */
2977     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RBCAN);
2978     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RBCAN) + 1U;
2979     Counter->rxBroadcastFrmCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
2980 
2981     /* Port MAC index Receive Dropped Packets Counter Register(etherStatsDropEventsn) */
2982     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RDRPN);
2983     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RDRPN) + 1U;
2984     Counter->rxDroppedPktCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
2985 
2986     /* Port MAC index Receive Packets Counter Register(etherStatsPktsn) */
2987     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RPKTN);
2988     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RPKTN) + 1U;
2989     Counter->rxPktCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
2990 
2991     /* Port MAC index Receive Undersized Packet Counter */
2992     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RUNDN);
2993     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RUNDN) + 1U;
2994     Counter->rxUndersizePacketCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
2995 
2996     /* Port MAC index Receive 64-Octet Packet Counter Register(etherStatsPkts64OctetsN) */
2997     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_R64N);
2998     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_R64N) + 1U;
2999     Counter->rx64OctetPktCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3000 
3001     /* Port MAC index Receive 65 to 127-Octet Packet Counter Register(etherStatsPkts65to127OctetsN) */
3002     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_R127N);
3003     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_R127N) + 1U;
3004     Counter->rx65to127OctetPktCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3005 
3006     /* Port MAC index Receive 128 to 255-Octet Packet Counter Register(etherStatsPkts128to255OctetsN) */
3007     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_R255N);
3008     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_R255N) + 1U;
3009     Counter->rx128to255OctetPktCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3010 
3011     /* Port MAC index Receive 256 to 511-Octet Packet Counter Register(etherStatsPkts256to511OctetsN) */
3012     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_R511N);
3013     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_R511N) + 1U;
3014     Counter->rx256to511OctetPktCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3015 
3016     /* Port MAC index Receive 512 to 1023-Octet Packet Counter Register(etherStatsPkts512to1023OctetsN) */
3017     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_R1023N);
3018     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_R1023N) + 1U;
3019     Counter->rx512to1023OctetPktCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3020 
3021     /* Port MAC index Receive 1024 to 1522-Octet Packet Counter Register(etherStatsPkts1024to1522OctetsN) */
3022     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_R1522N);
3023     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_R1522N) + 1U;
3024     Counter->rx1024to1522OctetPktCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3025 
3026     /* Port MAC index Receive 1523 to Max-Octet Packet Counter Register(etherStatsPkts1523toMaxOctetsN) */
3027     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_R1523XN);
3028     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_R1523XN) + 1U;
3029     Counter->rx1523toMaxOctetPktCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3030 
3031     /* Port MAC index Receive Oversized Packet Counter */
3032     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_ROVRN);
3033     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_ROVRN) + 1U;
3034     Counter->rxOversizedPacketsCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3035 
3036     /* Port MAC index Receive Jabber Packet Counter Register(etherStatsJabbersn) */
3037     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RJBRN);
3038     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RJBRN) + 1U;
3039     Counter->rxJabberPktCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3040 
3041     /* Port MAC index Receive Fragment Packet Counter Register(etherStatsFragmentsn) */
3042     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RFRGN);
3043     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RFRGN) + 1U;
3044     Counter->rxFragmentPktCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3045 
3046     /* Port MAC index Receive Control Packet Counter Register */
3047     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RCNPN);
3048     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RCNPN) + 1U;
3049     Counter->rxControlPktCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3050 
3051     /* Port MAC index Receive Dropped Not Truncated Packets Counter Register(etherStatsDropEventsn) */
3052     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RDRNTPN);
3053     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_RDRNTPN) + 1U;
3054     Counter->rxDroppedNTruncatedPktCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3055 
3056     /* Port Rx discard count register */
3057     Counter->rxDiscardCounter = Netc_EthSwt_Ip_SW0_PortxBaseAddr[portIndex]->PRXDCR;
3058 
3059     /* Transmit */
3060     /* Port MAC index Transmit Ethernet Octets Counter(etherStatsOctetsn) */
3061     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TEOCTN);
3062     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TEOCTN) + 1U;
3063     Counter->txEtherOctetCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3064 
3065     /* Port MAC index Transmit Octets Counter Register(ifOutOctetsn) */
3066     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TOCTN);
3067     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TOCTN) + 1U;
3068     Counter->txOctetCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3069 
3070     /* Port MAC index Transmit Valid Pause Frame Counter Register(aPAUSEMACCtrlFramesReceivedn) */
3071     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TXPFN);
3072     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TXPFN) + 1U;
3073     Counter->txValidPauseFrmCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3074 
3075     /* Port MAC index Transmit Frame Counter */
3076     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TFRMN);
3077     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TFRMN) + 1U;
3078     Counter->txFrmCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3079 
3080     /* Port MAC index Transmit Frame Check Sequence Error Counter */
3081     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TFCSN);
3082     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TFCSN) + 1U;
3083     Counter->txFrameCheckSequenceErrorCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3084 
3085     /* Port MAC index Transmit VLAN Frame Counter */
3086     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TVLANN);
3087     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TVLANN) + 1U;
3088     Counter->txVlanFrmCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3089 
3090     /* Port MAC index Transmit Frame Error Counter Register(ifOutErrorsn) */
3091     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TERRN);
3092     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TERRN) + 1U;
3093     Counter->txFrameErrorCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3094 
3095     /* Port MAC index Transmit Unicast Frame Counter */
3096     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TUCAN);
3097     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TUCAN) + 1U;
3098     Counter->txUnicastFrmCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3099 
3100     /* Port MAC index Transmit Multicast Frame Counter */
3101     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TMCAN);
3102     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TMCAN) + 1U;
3103     Counter->txMulticastFrmCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3104 
3105     /* Port MAC index Transmit Broadcast Frame Counter */
3106     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TBCAN);
3107     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TBCAN) + 1U;
3108     Counter->txBroadcastFrmCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3109 
3110     /* Port MAC index Transmit Packets Counter Register(etherStatsPktsN; */
3111     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TPKTN);
3112     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TPKTN) + 1U;
3113     Counter->txPktCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3114 
3115     /* Port MAC index Transmit Undersized Packet Counter */
3116     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TUNDN);
3117     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TUNDN) + 1U;
3118     Counter->txUndersizePacketCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3119 
3120     /* Port MAC index Transmit 64-Octet Packet Counter Register (etherStatsPkts64OctetsN) */
3121     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_T64N);
3122     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_T64N) + 1U;
3123     Counter->tx64OctetPktCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3124 
3125     /* Port MAC index Transmit 65 to 127-Octet Packet Counter Register (etherStatsPkts65to127OctetsN) */
3126     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_T127N);
3127     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_T127N) + 1U;
3128     Counter->tx65to127OctetPktCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3129 
3130     /* Port MAC index Transmit 128 to 255-Octet Packet Counter Register (etherStatsPkts128to255OctetsN) */
3131     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_T255N);
3132     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_T255N) + 1U;
3133     Counter->tx128to255OctetPktCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3134 
3135     /* Port MAC index Transmit 256 to 511-Octet Packet Counter Register (etherStatsPkts256to511OctetsN) */
3136     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_T511N);
3137     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_T511N) + 1U;
3138     Counter->tx256to511OctetPktCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3139 
3140     /* Port MAC index Transmit 512 to 1023-Octet Packet Counter Register (etherStatsPkts512to1023OctetsN) */
3141     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_T1023N);
3142     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_T1023N) + 1U;
3143     Counter->tx512to1023OctetPktCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3144 
3145     /* Port MAC index Transmit 1024 to 1522-Octet Packet Counter Register (etherStatsPkts1024to1522OctetsN) */
3146     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_T1522N);
3147     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_T1522N) + 1U;
3148     Counter->tx1024to1522OctetPktCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3149 
3150     /* Port MAC index Transmit 1523 to TX_MTU-Octet Packet Counter Register (etherStatsPkts1523toMaxOctetsN) */
3151     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_T1523XN);
3152     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_T1523XN) + 1U;
3153     Counter->tx1523toMaxOctetPktCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3154 
3155     /* Port MAC index Transmit Control Packet Counter Register */
3156     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TCNPN);
3157     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TCNPN) + 1U;
3158     Counter->txControlPktCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3159 
3160     /* Port MAC index Transmit Deferred Packet Counter Register(aFramesWithDeferredXmissions) */
3161     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TDFRN);
3162     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TDFRN) + 1U;
3163     Counter->txDeferredPktCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3164 
3165     /* Port MAC index Transmit Multiple Collisions Counter Register */
3166     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TMCOLN);
3167     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TMCOLN) + 1U;
3168     Counter->txMultiCollisionCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3169 
3170     /* Port MAC index Transmit Single Collision Counter Register */
3171     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TSCOLN);
3172     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TSCOLN) + 1U;
3173     Counter->txSingleCollisionCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3174 
3175     /* Port MAC index Transmit Late Collision Counter(aLateCollisions) Register */
3176     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TLCOLN);
3177     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TLCOLN) + 1U;
3178     Counter->txLateCollisionCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3179 
3180     /* Port MAC index Transmit Excessive Collisions Counter Register */
3181     xCR0Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TECOLN);
3182     xCR1Value = (volatile uint32 *)(&Netc_EthSwt_Ip_PortBaseTable[portIndex]->PM0_TECOLN) + 1U;
3183     Counter->txExcessiveCollisionCounter = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3184 
3185     /* ERR051023: NETC: Excessive collisions are counted as late collisions */
3186     Counter->txLateCollisionCounter -= Counter->txExcessiveCollisionCounter;
3187 
3188     /* Port Tx discard count register */
3189     Counter->txDiscardCounter = Netc_EthSwt_Ip_SW0_PortxBaseAddr[portIndex]->PTXDCR;
3190 
3191     /* Errata ERR051129: Uncorrectable non-fatal integrity error count register */
3192     Counter->unIntegrityErrorCounter = IP_NETC__SW0_COMMON->UNIECTR & NETC_F2_COMMON_UNIECTR_COUNT_MASK;
3193 
3194     return E_OK;
3195 }
3196 
3197 /*!
3198  * @brief Ethernet Switch get pseudo port counter values function.
3199  *
3200  * @param[in]
3201  * @param[out]
3202  * @return
3203  */
Netc_EthSwt_Ip_GetSwtPseudoPortCounters(uint8 SwitchIdx,uint8 SwitchPortIdx,Netc_EthSwt_Ip_CounterType * Counter)3204 static Std_ReturnType Netc_EthSwt_Ip_GetSwtPseudoPortCounters( uint8 SwitchIdx, uint8 SwitchPortIdx, Netc_EthSwt_Ip_CounterType *Counter )
3205 {
3206     uint32 xCR0Value;
3207     uint8 PseudoPortIdx;
3208 
3209     (void)SwitchIdx;
3210 
3211     /* pseudo port indexes are starting after the mac ports. */
3212     PseudoPortIdx = SwitchPortIdx - NETC_ETHSWT_NUMBER_OF_MAC_PORTS;
3213 
3214     /* Receive */
3215     /* Port pseudo MAC receive octets counter  */
3216     xCR0Value = Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx]->PPMROCR[0];
3217     Counter->rxOctetCounter = xCR0Value | ((uint64)((uint32)(Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx]->PPMROCR[1])) << NETC_ETHSWT_IP_32BIT_SHIFT);
3218     /* Port pseudo MAC receive unicast frame counter register */
3219     xCR0Value = Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx]->PPMRUFCR[0];
3220     Counter->rxUnicastFrmCounter = xCR0Value | ((uint64)((uint32)(Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx]->PPMRUFCR[1])) << NETC_ETHSWT_IP_32BIT_SHIFT);
3221     /* Port pseudo MAC receive multicast frame counter register */
3222     xCR0Value = Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx]->PPMRMFCR[0];
3223     Counter->rxMulticastFrmCounter = xCR0Value | ((uint64)((uint32)(Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx]->PPMRMFCR[1])) << NETC_ETHSWT_IP_32BIT_SHIFT);
3224     /*  Port pseudo MAC receive broadcast frame counter register */
3225     xCR0Value = Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx]->PPMRBFCR[0];
3226     Counter->rxBroadcastFrmCounter = xCR0Value | ((uint64)((uint32)(Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx]->PPMRBFCR[1])) << NETC_ETHSWT_IP_32BIT_SHIFT);
3227 
3228     /* unsupported rx counters */
3229     Counter->rxPktCounter = 0xFFFFFFFFFFFFFFFFU;
3230     Counter->rxFrmCounter = 0xFFFFFFFFFFFFFFFFU;
3231     Counter->rxVlanFrmCounter = 0xFFFFFFFFFFFFFFFFU;
3232     Counter->rxFrameErrorCounter = 0xFFFFFFFFFFFFFFFFU;
3233     Counter->rxUndersizePacketCounter = 0xFFFFFFFFFFFFFFFFU;
3234     Counter->rxOversizedPacketsCounter = 0xFFFFFFFFFFFFFFFFU;
3235     Counter->rxFrameCheckSequenceErrorCounter = 0xFFFFFFFFFFFFFFFFU;
3236     Counter->rxEtherOctetCounter = 0xFFFFFFFFFFFFFFFFU;
3237     Counter->rxValidPauseFrmCounter = 0xFFFFFFFFFFFFFFFFU;
3238     Counter->rxDroppedPktCounter = 0xFFFFFFFFFFFFFFFFU;
3239     Counter->rx64OctetPktCounter = 0xFFFFFFFFFFFFFFFFU;
3240     Counter->rx65to127OctetPktCounter = 0xFFFFFFFFFFFFFFFFU;
3241     Counter->rx128to255OctetPktCounter = 0xFFFFFFFFFFFFFFFFU;
3242     Counter->rx256to511OctetPktCounter = 0xFFFFFFFFFFFFFFFFU;
3243     Counter->rx512to1023OctetPktCounter = 0xFFFFFFFFFFFFFFFFU;
3244     Counter->rx1024to1522OctetPktCounter = 0xFFFFFFFFFFFFFFFFU;
3245     Counter->rx1523toMaxOctetPktCounter = 0xFFFFFFFFFFFFFFFFU;
3246     Counter->rxJabberPktCounter = 0xFFFFFFFFFFFFFFFFU;
3247     Counter->rxFragmentPktCounter = 0xFFFFFFFFFFFFFFFFU;
3248     Counter->rxControlPktCounter = 0xFFFFFFFFFFFFFFFFU;
3249     Counter->rxDroppedNTruncatedPktCounter = 0xFFFFFFFFFFFFFFFFU;
3250 
3251     /* Port Rx discard count register */
3252     Counter->rxDiscardCounter = Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->PRXDCR;
3253 
3254     /*  Transmit */
3255     /*  Port pseudo MAC transmit octets counter  */
3256     xCR0Value = Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx]->PPMTOCR[0];
3257     Counter->txOctetCounter = xCR0Value | ((uint64)((uint32)(Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx]->PPMTOCR[1])) << NETC_ETHSWT_IP_32BIT_SHIFT);
3258     /*  Port pseudo MAC transmit unicast frame counter register */
3259     xCR0Value = Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx]->PPMTUFCR[0];
3260     Counter->txUnicastFrmCounter = xCR0Value | ((uint64)((uint32)(Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx]->PPMTUFCR[1])) << NETC_ETHSWT_IP_32BIT_SHIFT);
3261     /*  Port pseudo MAC transmit multicast frame counter register */
3262     xCR0Value = Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx]->PPMTMFCR[0];
3263     Counter->txMulticastFrmCounter = xCR0Value | ((uint64)((uint32)(Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx]->PPMTMFCR[1])) << NETC_ETHSWT_IP_32BIT_SHIFT);
3264     /*  Port pseudo MAC transmit broadcast frame counter register */
3265     xCR0Value = IP_NETC__SW0_PSEUDO_MAC_PORT2->PPMTBFCR[0];
3266     Counter->txBroadcastFrmCounter = xCR0Value | ((uint64)((uint32)(Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx]->PPMTBFCR[1])) << NETC_ETHSWT_IP_32BIT_SHIFT);
3267 
3268     /* Port Tx discard count register */
3269     Counter->txDiscardCounter = Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->PTXDCR;
3270 
3271     /* unsupported tx counters */
3272     Counter->txPktCounter = 0xFFFFFFFFFFFFFFFFU;
3273     Counter->txFrmCounter = 0xFFFFFFFFFFFFFFFFU;
3274     Counter->txVlanFrmCounter = 0xFFFFFFFFFFFFFFFFU;
3275     Counter->txFrameErrorCounter = 0xFFFFFFFFFFFFFFFFU;
3276     Counter->txUndersizePacketCounter = 0xFFFFFFFFFFFFFFFFU;
3277     Counter->txSingleCollisionCounter = 0xFFFFFFFFFFFFFFFFU;
3278     Counter->txMultiCollisionCounter = 0xFFFFFFFFFFFFFFFFU;
3279     Counter->txFrameCheckSequenceErrorCounter = 0xFFFFFFFFFFFFFFFFU;
3280 
3281     Counter->txEtherOctetCounter = 0xFFFFFFFFFFFFFFFFU;
3282     Counter->txValidPauseFrmCounter = 0xFFFFFFFFFFFFFFFFU;
3283     Counter->tx64OctetPktCounter = 0xFFFFFFFFFFFFFFFFU;
3284     Counter->tx65to127OctetPktCounter = 0xFFFFFFFFFFFFFFFFU;
3285     Counter->tx128to255OctetPktCounter = 0xFFFFFFFFFFFFFFFFU;
3286     Counter->tx256to511OctetPktCounter = 0xFFFFFFFFFFFFFFFFU;
3287     Counter->tx512to1023OctetPktCounter = 0xFFFFFFFFFFFFFFFFU;
3288     Counter->tx1024to1522OctetPktCounter = 0xFFFFFFFFFFFFFFFFU;
3289     Counter->tx1523toMaxOctetPktCounter = 0xFFFFFFFFFFFFFFFFU;
3290     Counter->txControlPktCounter = 0xFFFFFFFFFFFFFFFFU;
3291     Counter->txDeferredPktCounter = 0xFFFFFFFFFFFFFFFFU;
3292     Counter->txLateCollisionCounter = 0xFFFFFFFFFFFFFFFFU;
3293     Counter->txExcessiveCollisionCounter = 0xFFFFFFFFFFFFFFFFU;
3294 
3295     /* Errata ERR051129: Uncorrectable non-fatal integrity error count register */
3296     Counter->unIntegrityErrorCounter = IP_NETC__SW0_COMMON->UNIECTR & NETC_F2_COMMON_UNIECTR_COUNT_MASK;
3297 
3298     return E_OK;
3299 }
3300 
3301 /*FUNCTION**********************************************************************
3302  *
3303  * Function Name : Netc_EthSwt_Ip_EnableVlan
3304  * Description   : Ethernet switch enable VLAN function.
3305  * implements Netc_EthSwt_Ip_EnableVlan_Activity
3306  *END**************************************************************************/
Netc_EthSwt_Ip_EnableVlan(uint8 SwitchIdx,uint8 SwitchPortIdx,uint16 VlanId,boolean Enable)3307 Std_ReturnType Netc_EthSwt_Ip_EnableVlan( uint8 SwitchIdx, uint8 SwitchPortIdx, uint16 VlanId, boolean Enable )
3308 {
3309     Std_ReturnType Status = E_OK;
3310     Netc_EthSwt_Ip_CBDRStatusType CBDRStatus = NETC_ETHSWT_CBDRSTATUS_SUCCES;
3311     Netc_EthSwt_Ip_VlanFilterEntryDataType VlanFilterTableEntry;
3312     uint32 MatchedEntries = 0U;
3313 
3314 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
3315     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
3316     DevAssert(SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_PORTS);
3317 #endif
3318 
3319     /* Query the entry with VlanId */
3320     VlanFilterTableEntry.VlanID = VlanId;
3321     CBDRStatus = Netc_EthSwt_Ip_QueryVlanFilterTableEntry(SwitchIdx, &MatchedEntries, &VlanFilterTableEntry);
3322     if ((CBDRStatus != NETC_ETHSWT_CBDRSTATUS_SUCCES) || (MatchedEntries == 0U))
3323     {
3324         Status = E_NOT_OK;        /* Query command error or no mached Vlan ID entry found */
3325     }
3326     else
3327     {
3328         /* Get the CFGE data of a mached entry */
3329         VlanFilterTableEntry.SpanningTreeGroupMemberId = (uint8)((TableDataBuffer.TableDataField[NETC_ETHSWT_VLANFILTERTABL_RSPDATA_CFGEDATA0] & NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_STG_ID_MASK) >> NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_STG_ID_SHIFT);
3330         VlanFilterTableEntry.PortMembershipBitmap = TableDataBuffer.TableDataField[NETC_ETHSWT_VLANFILTERTABL_RSPDATA_CFGEDATA0] & NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_PORT_MEMBERSHIP_MASK;
3331         VlanFilterTableEntry.IpMulticastFloodingEnable = (((TableDataBuffer.TableDataField[NETC_ETHSWT_VLANFILTERTABL_RSPDATA_CFGEDATA1] & NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_IPMFLE_MASK) >> NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_IPMFLE_SHIFT) != 0x0UL) ? TRUE : FALSE;
3332         VlanFilterTableEntry.IpMulticastFilteringEnable = (((TableDataBuffer.TableDataField[NETC_ETHSWT_VLANFILTERTABL_RSPDATA_CFGEDATA1] & NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_IPMFE_MASK) >> NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_IPMFE_SHIFT) != 0x0UL) ? TRUE : FALSE;
3333         VlanFilterTableEntry.MacForwardingOptions = (uint8)((TableDataBuffer.TableDataField[NETC_ETHSWT_VLANFILTERTABL_RSPDATA_CFGEDATA1] & NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_MFO_MASK) >> NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_MFO_SHIFT);
3334         VlanFilterTableEntry.MacLearningOptions = (uint8)((TableDataBuffer.TableDataField[NETC_ETHSWT_VLANFILTERTABL_RSPDATA_CFGEDATA1] & NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_MLO_MASK) >> NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_MLO_SHIFT);
3335         VlanFilterTableEntry.FID = (uint16)(TableDataBuffer.TableDataField[NETC_ETHSWT_VLANFILTERTABL_RSPDATA_CFGEDATA1] & NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_FID_MASK);
3336         VlanFilterTableEntry.EgressTreatmentApplicabilityPortBitmap = TableDataBuffer.TableDataField[NETC_ETHSWT_VLANFILTERTABL_RSPDATA_CFGEDATA2] & NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_ETA_PORT_BITMAP_MASK;
3337         VlanFilterTableEntry.BaseEgressTreatmentEntryID = TableDataBuffer.TableDataField[NETC_ETHSWT_VLANFILTERTABL_RSPDATA_CFGEDATA3] & NETC_ETHSWT_VLANFILTERTABLE_CFGEDATA_BASE_ET_EID_MASK;
3338 
3339         /* Modify port membership bitmap data */
3340         if (TRUE == Enable)
3341         {
3342             VlanFilterTableEntry.PortMembershipBitmap |= (uint32)(0x1UL << SwitchPortIdx);            /* add the port to the portmembershipbitmap */
3343         }
3344         else
3345         {
3346             VlanFilterTableEntry.PortMembershipBitmap &= ~((uint32)(0x1UL << SwitchPortIdx));        /* remove the port from the portmembershipbitmap */
3347         }
3348 
3349         /* Update the entry */
3350         VlanFilterTableEntry.VlanID = VlanId;
3351         CBDRStatus = Netc_EthSwt_Ip_AddOrUpdateVlanFilterTableEntry(SwitchIdx, NETC_ETHSWT_UPDATE_CMD, &MatchedEntries, &VlanFilterTableEntry);
3352         if (CBDRStatus != NETC_ETHSWT_CBDRSTATUS_SUCCES)
3353         {
3354             Status = E_NOT_OK;        /* Update command error */
3355         }
3356 
3357     }
3358 
3359     return Status;
3360 }
3361 /*FUNCTION**********************************************************************
3362  *
3363  * Function Name : Netc_EthSwt_Ip_ResetConfiguration
3364  * Description   : Ethernet switch reset configuration function.
3365  * implements Netc_EthSwt_Ip_ResetConfiguration_Activity
3366  *END**************************************************************************/
Netc_EthSwt_Ip_ResetConfiguration(uint8 SwitchIdx)3367 Std_ReturnType Netc_EthSwt_Ip_ResetConfiguration(uint8 SwitchIdx)
3368 {
3369     /*
3370      * [notes]: implemented this function with singel delete command and Search Method.
3371     */
3372     Std_ReturnType status = E_OK;
3373     Netc_EthSwt_Ip_CBDRStatusType CBDRStatus;
3374     uint32 ActionsData;
3375     NetcEthSwt_Ip_ReqHeaderTableOperationDataType OperationData;
3376 
3377 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
3378     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
3379 #endif
3380 
3381     /* set the querry options with ENTRY_ID only querry */
3382     ActionsData = NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD_QUERY_ACTIONS(1U) \
3383                 | NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD_DEBUG_OPTIONS(0U) \
3384                 | NETC_ETHSWT_IP_FDBTABLE_REQFMT_ACTIONS_FIELD_ACTEU(0U) \
3385                 | NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD_CFGEU(1U);
3386 
3387     /*+++ fill in FdbTabeDataBuffer for Request Data Buffer +++ */
3388     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD] = ActionsData;    /* fill in the Actions field */
3389     /* fill in Access Key data field with search criteria data format */
3390     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_RESUMEENTRYID] = NETC_ETHSWT_IP_BD_NULL_ENTRY_ID;  /* resume entry id */
3391     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_MACADDRESS_L] = 0U;            /* clear other unuse data field */
3392     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_MACADDRESS_H] = 0U;            /* clear other unuse data field */
3393     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_FID] = 0U;            /* clear other unuse data field */
3394     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_PORTBITMAP] = 0U;            /* clear other unuse data field */
3395     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_CFGECONFIG] = NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD_DYNAMIC(1U);   /* set CFGE_DATA[DYNAMIC] to 0x1 meaning it will match dynamic entries */
3396     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_ETEID] = 0U;            /* clear other unuse data field */
3397     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_MATCHCRITERIA] = NETC_ETHSWT_IP_FDBTABLE_SEARCH_CRITERIA_CFGEMC(1U);      /* 0x1: Match CFGE_DATA[DYNAMIC] field */
3398     /*--- fill in FdbTabeDataBuffer for Request Data Buffer --- */
3399 
3400     /* fill in operation data for config field of Request Header*/
3401     OperationData.CmdCompletionInt = 0x0U;                                        /* command completion interrupt disabled */
3402     OperationData.Version = NETC_ETHSWT_IP_CMDBD_REQFMT_PROTOCOL_VERSION;        /* protocol version = 2 */
3403     OperationData.TableId = NETC_ETHSWT_IP_FDB_TABLE_ID;
3404     OperationData.AccessMethod = NETC_ETHSWT_SEARCH_METHOD;                        /* delete all matched entries with Search Method */
3405     OperationData.Cmd = NETC_ETHSWT_DELETE_CMD;
3406     OperationData.ReqBuffLength = (NETC_ETHSWT_IP_TABLE_REQBUFFER_LEN);
3407     OperationData.RspBuffLength = (NETC_ETHSWT_IP_TABLE_RESBUFFER_LEN);
3408 
3409     /* send the "Delete" command */
3410     CBDRStatus = Netc_EthSwt_Ip_SendCommand(SwitchIdx, NETC_ETHSWT_IP_CBDR_0, &OperationData);
3411     if (CBDRStatus != NETC_ETHSWT_CBDRSTATUS_SUCCES)
3412     {
3413         status = E_NOT_OK;
3414     }
3415 
3416     return status;
3417 }
3418 
3419 /*FUNCTION**********************************************************************
3420  *
3421  * Function Name : Netc_EthSwt_Ip_SetMacLearningMode
3422  * Description   : Ethernet switch set MAC learning mode function.
3423  * implements Netc_EthSwt_Ip_SetMacLearningMode_Activity
3424  *END**************************************************************************/
Netc_EthSwt_Ip_SetMacLearningMode(uint8 SwitchIdx,Netc_EthSwt_Ip_MacLearningOptionType MacLearningMode)3425 Std_ReturnType Netc_EthSwt_Ip_SetMacLearningMode( uint8 SwitchIdx,
3426                                                   Netc_EthSwt_Ip_MacLearningOptionType MacLearningMode
3427                                                 )
3428 {
3429     Std_ReturnType status = E_OK;
3430     uint32 MacLearningOption;
3431 
3432 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
3433     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
3434 #endif
3435 
3436     MacLearningOption = IP_NETC__SW0_BASE->VFHTDECR2;
3437     MacLearningOption &= ~NETC_F2_VFHTDECR2_MLO_MASK;
3438     switch (MacLearningMode)
3439     {
3440         case ETHSWT_MACLEARNINGOPTION_HWDISABLED:
3441             MacLearningOption |= NETC_F2_VFHTDECR2_MLO(ETHSWT_MACLEARNINGOPTION_HWDISABLED);
3442             break;
3443         case ETHSWT_MACLEARNINGOPTION_HWENABLED:
3444             MacLearningOption |= NETC_F2_VFHTDECR2_MLO(ETHSWT_MACLEARNINGOPTION_HWENABLED);
3445             break;
3446         case ETHSWT_MACLEARNINGOPTION_SWSECUREENABLED:
3447             MacLearningOption |= NETC_F2_VFHTDECR2_MLO(ETHSWT_MACLEARNINGOPTION_SWSECUREENABLED);
3448             break;
3449         case ETHSWT_MACLEARNINGOPTION_SWUNSECUREENABLED:
3450             MacLearningOption |= NETC_F2_VFHTDECR2_MLO(ETHSWT_MACLEARNINGOPTION_SWUNSECUREENABLED);
3451             break;
3452         case ETHSWT_MACLEARNINGOPTION_DISABLEDWITHSWVALIDATION:
3453             MacLearningOption |= NETC_F2_VFHTDECR2_MLO(ETHSWT_MACLEARNINGOPTION_DISABLEDWITHSWVALIDATION);
3454             break;
3455         default:
3456             /* log error */
3457             status = E_NOT_OK;
3458             break;
3459     }
3460 
3461     IP_NETC__SW0_BASE->VFHTDECR2 = MacLearningOption;
3462 
3463     return status;
3464 }
3465 
3466 /*FUNCTION**********************************************************************
3467  *
3468  * Function Name : Netc_EthSwt_Ip_GetMacLearningMode
3469  * Description   : Ethernet switch get MAC learning mode function.
3470  * implements Netc_EthSwt_Ip_GetMacLearningMode_Activity
3471  *END**************************************************************************/
Netc_EthSwt_Ip_GetMacLearningMode(uint8 SwitchIdx,Netc_EthSwt_Ip_MacLearningOptionType * MacLearningMode)3472 Std_ReturnType Netc_EthSwt_Ip_GetMacLearningMode( uint8 SwitchIdx,
3473                                                   Netc_EthSwt_Ip_MacLearningOptionType * MacLearningMode
3474                                                 )
3475 {
3476     Std_ReturnType status = E_OK;
3477     uint32 MacLearningOption;
3478 
3479 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
3480     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
3481     DevAssert(MacLearningMode != NULL_PTR);
3482 #endif
3483 
3484     MacLearningOption = IP_NETC__SW0_BASE->VFHTDECR2;
3485     MacLearningOption = ((MacLearningOption & NETC_F2_VFHTDECR2_MLO_MASK) >> NETC_F2_VFHTDECR2_MLO_SHIFT);
3486     switch (MacLearningOption)
3487     {
3488         case 0x1UL:
3489             *MacLearningMode = ETHSWT_MACLEARNINGOPTION_HWDISABLED;
3490             break;
3491         case 0x2UL:
3492             *MacLearningMode = ETHSWT_MACLEARNINGOPTION_HWENABLED;
3493             break;
3494         case 0x3UL:
3495             *MacLearningMode = ETHSWT_MACLEARNINGOPTION_SWSECUREENABLED;
3496             break;
3497         case 0x4UL:
3498             *MacLearningMode = ETHSWT_MACLEARNINGOPTION_SWUNSECUREENABLED;
3499             break;
3500         case 0x5UL:
3501             *MacLearningMode = ETHSWT_MACLEARNINGOPTION_DISABLEDWITHSWVALIDATION;
3502             break;
3503         default:
3504             /* log error */
3505             status = E_NOT_OK;
3506             break;
3507     }
3508 
3509     return status;
3510 }
3511 
3512 /*FUNCTION**********************************************************************
3513  *
3514  * Function Name : Netc_EthSwt_Ip_GetSwitchIdentifier
3515  * Description   : Ethernet switch hardware version function.
3516  * implements Netc_EthSwt_Ip_GetSwitchIdentifier_Activity
3517  *END**************************************************************************/
Netc_EthSwt_Ip_GetSwitchIdentifier(uint8 SwitchIdx,uint32 * HwVersion)3518 Std_ReturnType Netc_EthSwt_Ip_GetSwitchIdentifier(uint8 SwitchIdx, uint32 *HwVersion)
3519 {
3520     /* This dummy cast is done to support scalability in futures platforms. */
3521     (void)SwitchIdx;
3522     /* Hardware revision. */
3523     *HwVersion = IP_NETC__SW0_GLOBAL->IPBRR0;
3524 
3525     return E_OK;
3526 }
3527 
3528 /*FUNCTION**********************************************************************
3529  *
3530  * Function Name : Netc_EthSwt_Ip_InitCommandBDR
3531  * Description   : Internal function for initializing the command ring.
3532  *
3533  *END**************************************************************************/
Netc_EthSwt_Ip_InitCommandBDR(uint8 SwitchIdx,uint8 cbdrIndex)3534 static Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_InitCommandBDR(uint8 SwitchIdx, uint8 cbdrIndex)
3535 {
3536     Netc_EthSwt_Ip_CBDRStatusType status = NETC_ETHSWT_CBDRSTATUS_SUCCES;
3537 
3538     (void)SwitchIdx;
3539 
3540     /* check the index of command ring */
3541     if (cbdrIndex >= NETC_ETHSWT_IP_CBDR_NUM)
3542     {
3543         status = NETC_ETHSWT_CBDRSTATUS_INDEX_ERROR;
3544     }
3545     else
3546     {
3547         /* configure the CBDR base address register where the address of a switch table is stored*/
3548         IP_NETC__SW0_BASE->NUM_CBDR[cbdrIndex].CBDRBAR0 = (uint32)(CmdBDRConfig[cbdrIndex].CmdBDAddr);
3549 
3550         /* set the index of producer and consumer register to 0. The ring is empty now. */
3551         IP_NETC__SW0_BASE->NUM_CBDR[cbdrIndex].CBDRPIR = NETC_F2_CBDRPIR_BDR_INDEX(0U);
3552         IP_NETC__SW0_BASE->NUM_CBDR[cbdrIndex].CBDRCIR = NETC_F2_CBDRCIR_BDR_INDEX(0U);
3553 
3554         /* set the size of command ring. Size of ring in sets of 8 BDs. Maximum ring size is 1K. */
3555         IP_NETC__SW0_BASE->NUM_CBDR[cbdrIndex].CBDRLENR = NETC_F2_CBDRLENR_LENGTH(CmdBDRConfig[cbdrIndex].lengthCBDR);
3556 
3557         /* enable CBDR. When the ring is non-empty, command buffer descriptors will be processed */
3558         IP_NETC__SW0_BASE->NUM_CBDR[cbdrIndex].CBDRMR = NETC_F2_CBDRMR_EN(1U);
3559     }
3560 
3561     return status;
3562 }
3563 
3564 /*FUNCTION**********************************************************************
3565  *
3566  * Function Name : Netc_EthSwt_Ip_FillInFdbTableReqDataBuff
3567  * Description   : Internal function for initializing the FDB Table Request Data Buffer.
3568  *
3569  *END**************************************************************************/
Netc_EthSwt_Ip_FillInFdbTableReqDataBuff(uint32 ActionsData,const uint32 * pAccessKey,const Netc_EthSwt_Ip_FDBTableCFGEDataType * pCfgeData,Netc_EthSwt_Ip_AccessMethodType accessMethod)3570 static Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_FillInFdbTableReqDataBuff(uint32 ActionsData, const uint32 *pAccessKey, const Netc_EthSwt_Ip_FDBTableCFGEDataType *pCfgeData, Netc_EthSwt_Ip_AccessMethodType accessMethod)
3571 {
3572     uint8 ItemIdx;
3573     Netc_EthSwt_Ip_CBDRStatusType status = NETC_ETHSWT_CBDRSTATUS_SUCCES;
3574 
3575     /* ------initialize the table request data buffer------ */
3576     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD] = ActionsData;  /* fill in Actions field */
3577 
3578     /* initialize ACCESS_KEY */
3579     switch (accessMethod)
3580     {
3581         case NETC_ETHSWT_ENTRY_ID_MATCH:
3582             TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ENTRYID_FIELD] = pAccessKey[0U];        /* fill in Entry_ID field */
3583             break;
3584         case NETC_ETHSWT_EXACT_MATCH_KEY_ELEMENT_MATCH:
3585             for (ItemIdx = 1U; ItemIdx <= NETC_ETHSWT_IP_FDB_KEYE_DATA_ITEMS; ItemIdx++)
3586             {
3587                 TableDataBuffer.TableDataField[ItemIdx] = pAccessKey[ItemIdx - 1U];  /* fill in keye data field */
3588             }
3589             break;
3590         case NETC_ETHSWT_SEARCH_METHOD:
3591             for (ItemIdx = 1U; ItemIdx <= NETC_ETHSWT_IP_FDB_SEARCH_CRITERIA_DATA_ITEMS; ItemIdx++)
3592             {
3593                 TableDataBuffer.TableDataField[ItemIdx] = pAccessKey[ItemIdx - 1U];  /* fill in search criteria data field */
3594             }
3595             break;
3596         default:
3597             /* Not Applicable for FDB table*/
3598             status = NETC_ETHSWT_CBDRSTATUS_ACCESSMETHOD_ERROR;
3599             break;
3600     }
3601 
3602     /* initialize CFGE_DATA. This portion is present only for commands which perform an update or add. */
3603     if (pCfgeData != NULL_PTR)
3604     {
3605         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_CFGE_PORT_BITMAP_FIELD] = pCfgeData->Cfge_PortBitmap;
3606         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_CFGE_CONFIG_FIELD] = pCfgeData->Cfge_ConfigField;
3607         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_FDBTABLE_CFGE_ETEID_FIELD] = pCfgeData->Cfge_EtEid;
3608     }
3609 
3610     return status;
3611 }
3612 
3613 /*FUNCTION**********************************************************************
3614  *
3615  * Function Name : Netc_EthSwt_Ip_FillInVlanFilterTableReqDataBuff
3616  * Description   : Internal function for initializing the Vlan Filter Table Request Data Buffer.
3617  *
3618  *END**************************************************************************/
Netc_EthSwt_Ip_FillInVlanFilterTableReqDataBuff(uint32 ActionsData,uint32 AccessKeyData,const Netc_EthSwt_Ip_VlanFilterTableCFGEDataType * pCfgeData,Netc_EthSwt_Ip_AccessMethodType accessMethod)3619 static Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_FillInVlanFilterTableReqDataBuff(uint32 ActionsData, uint32 AccessKeyData, const Netc_EthSwt_Ip_VlanFilterTableCFGEDataType *pCfgeData, Netc_EthSwt_Ip_AccessMethodType accessMethod)
3620 {
3621     Netc_EthSwt_Ip_CBDRStatusType status = NETC_ETHSWT_CBDRSTATUS_SUCCES;
3622 
3623     /* ------initialize the table request data buffer------ */
3624     TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ACTIONS_FIELD] = ActionsData;  /* fill in Actions field */
3625 
3626     /* initialize ACCESS_KEY Data */
3627     switch (accessMethod)
3628     {
3629         case NETC_ETHSWT_ENTRY_ID_MATCH:
3630             TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_ENTRYID_FIELD] = AccessKeyData;        /* fill in Entry_ID field */
3631             break;
3632         case NETC_ETHSWT_EXACT_MATCH_KEY_ELEMENT_MATCH:
3633             TableDataBuffer.TableDataField[NETC_ETHSWT_IP_VLANFILTERTABLE_REQFMT_VID_FIELD] = AccessKeyData;              /* fill in VID field of KEYE Data */
3634             break;
3635         case NETC_ETHSWT_SEARCH_METHOD:
3636             TableDataBuffer.TableDataField[NETC_ETHSWT_IP_VLANFILTERTABLE_REQFMT_RESUMEENTRYID_FIELD] = AccessKeyData;  /* fill in RESUME_ENTRY_ID of search criteria data */
3637             break;
3638         default:
3639             /* Not Applicable for Vlan Filter table*/
3640             status = NETC_ETHSWT_CBDRSTATUS_ACCESSMETHOD_ERROR;
3641             break;
3642     }
3643 
3644     /* initialize CFGE_DATA. This portion is present only for commands which perform an update or add. */
3645     if (pCfgeData != NULL_PTR)
3646     {
3647         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_CFGEDATA0] = pCfgeData->Cfge_Data[0U];
3648         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_CFGEDATA1] = pCfgeData->Cfge_Data[1U];
3649         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_CFGEDATA2] = pCfgeData->Cfge_Data[2U];
3650         TableDataBuffer.TableDataField[NETC_ETHSWT_IP_SWITCHTABLE_REQFMT_CFGEDATA3] = pCfgeData->Cfge_Data[3U];
3651     }
3652 
3653     return status;
3654 }
3655 
3656 /*FUNCTION**********************************************************************
3657  *
3658  * Function Name : Netc_EthSwt_Ip_SendCommand
3659  * Description   : Internal function for adding an entry with different commands to command ring.
3660  *
3661  *END**************************************************************************/
Netc_EthSwt_Ip_SendCommand(uint8 SwitchIdx,uint8 cbdrIndex,const NetcEthSwt_Ip_ReqHeaderTableOperationDataType * OperationData)3662 static Netc_EthSwt_Ip_CBDRStatusType Netc_EthSwt_Ip_SendCommand(uint8 SwitchIdx, uint8 cbdrIndex, const NetcEthSwt_Ip_ReqHeaderTableOperationDataType *OperationData)
3663 {
3664     uint32 producerIdx;
3665     uint32 consumerIdx;
3666     Netc_EthSwt_Ip_CBDRStatusType status = NETC_ETHSWT_CBDRSTATUS_SUCCES;
3667     uint32 PreviousProducerIdx;
3668     uint32 statusField;
3669     uint32 rrBit;
3670     uint32 errorField;
3671     uint32 StartTime;
3672     uint32 ElapsedTime;
3673     uint32 TimeoutTicks;
3674     boolean TimeExpired;
3675 
3676     (void)SwitchIdx;
3677 
3678     /* read the producer and consumer index register */
3679     producerIdx = IP_NETC__SW0_BASE->NUM_CBDR[cbdrIndex].CBDRPIR;
3680     consumerIdx = IP_NETC__SW0_BASE->NUM_CBDR[cbdrIndex].CBDRCIR;
3681 
3682     /* check if the ring is full */
3683     if (((producerIdx + 0x1UL) % ((uint32)(CmdBDRConfig[cbdrIndex].lengthCBDR) * NETC_ETHSWT_IP_SET_OF_BD)) == consumerIdx)
3684     {
3685         status = NETC_ETHSWT_CBDRSTATUS_RINGFULL;  /* the ring is full */
3686     }
3687     else
3688     {
3689         /* +++ fill in the NTMP request message header +++ */
3690         /* set the table address */
3691         CmdBDRConfig[cbdrIndex].CmdBDAddr[producerIdx].MessageHeaderDataField[NETC_ETHSWT_IP_REQHEADER_ADDR_L] = (uint32)(&TableDataBuffer);
3692 
3693         /* set the length of request and response data buffer */
3694         CmdBDRConfig[cbdrIndex].CmdBDAddr[producerIdx].MessageHeaderDataField[NETC_ETHSWT_IP_REQHEADER_LENGTHFIELD] = (NETC_ETHSWT_IP_CMDBD_REQFMT_REQUEST_LENGTH(OperationData->ReqBuffLength) | NETC_ETHSWT_IP_CMDBD_REQFMT_RESPONSE_LENGTH(OperationData->RspBuffLength));
3695 
3696         /* set RR = 0, CCI = 0, protocol version = 2, table id, access method and cmd */
3697         CmdBDRConfig[cbdrIndex].CmdBDAddr[producerIdx].MessageHeaderDataField[NETC_ETHSWT_IP_REQHEADER_CONFIGFIELD] = 0x0; /* clear this field first */
3698         CmdBDRConfig[cbdrIndex].CmdBDAddr[producerIdx].MessageHeaderDataField[NETC_ETHSWT_IP_REQHEADER_CONFIGFIELD] |= NETC_ETHSWT_IP_CMDBD_REQFMT_CONFIG_FIELD_CMD(OperationData->Cmd);
3699         CmdBDRConfig[cbdrIndex].CmdBDAddr[producerIdx].MessageHeaderDataField[NETC_ETHSWT_IP_REQHEADER_CONFIGFIELD] |= NETC_ETHSWT_IP_CMDBD_REQFMT_CONFIG_FIELD_ACCESS_METHOD(OperationData->AccessMethod);
3700         CmdBDRConfig[cbdrIndex].CmdBDAddr[producerIdx].MessageHeaderDataField[NETC_ETHSWT_IP_REQHEADER_CONFIGFIELD] |= NETC_ETHSWT_IP_CMDBD_REQFMT_CONFIG_FIELD_TABLE_ID(OperationData->TableId);
3701         CmdBDRConfig[cbdrIndex].CmdBDAddr[producerIdx].MessageHeaderDataField[NETC_ETHSWT_IP_REQHEADER_CONFIGFIELD] |= NETC_ETHSWT_IP_CMDBD_REQFMT_CONFIG_FIELD_VERSION(OperationData->Version);
3702         CmdBDRConfig[cbdrIndex].CmdBDAddr[producerIdx].MessageHeaderDataField[NETC_ETHSWT_IP_REQHEADER_CONFIGFIELD] |= NETC_ETHSWT_IP_CMDBD_REQFMT_CONFIG_FIELD_CCI(OperationData->CmdCompletionInt);
3703         CmdBDRConfig[cbdrIndex].CmdBDAddr[producerIdx].MessageHeaderDataField[NETC_ETHSWT_IP_REQHEADER_CONFIGFIELD] |= NETC_ETHSWT_IP_CMDBD_REQFMT_CONFIG_FIELD_RR(0U);        /* RR bit has to be set to 0 */
3704 
3705         /* set NTMP version to 2.0*/
3706         CmdBDRConfig[cbdrIndex].CmdBDAddr[producerIdx].MessageHeaderDataField[NETC_ETHSWT_IP_REQHEADER_NPFFIELD] = NETC_ETHSWT_IP_CMDBD_REQFMT_NPF_FIELD(NETC_ETHSWT_IP_CMDBD_REQFMT_NTMP_PROTOCOL_VERSION);
3707         /* --- fill in the NTMP request message header --- */
3708 
3709         /* +++ write the produce index register and enable hardware to consume the command +++ */
3710         PreviousProducerIdx = producerIdx;        /* save the produce index before incrementing it manually */
3711         if ((producerIdx + 0x1UL) == ((uint32)(CmdBDRConfig[cbdrIndex].lengthCBDR) * NETC_ETHSWT_IP_SET_OF_BD))        /* adjust producer index */
3712         {
3713             producerIdx = 0x0UL;    /* when producerIdx equals ACTUAL_CBDR_LENGTH minus 1, then it would start from 0 again */
3714         }
3715         else
3716         {
3717             producerIdx += 0x1UL;   /* increase the producer index manually */
3718         }
3719 
3720         /* This is needed to make sure the descriptor gets updated with the latest values, before
3721            incrementing the producer index to start the actual operation */
3722         MCAL_DATA_SYNC_BARRIER();
3723 
3724         IP_NETC__SW0_BASE->NUM_CBDR[cbdrIndex].CBDRPIR = NETC_F2_CBDRPIR_BDR_INDEX(producerIdx);
3725         /* --- write the produce index register and enable hardware to consume the command --- */
3726 
3727         /* +++ to make sure the hardware consumes and processes the command completely +++ */
3728         /* Setup timeout timer */
3729         Netc_EthSwt_Ip_StartTimeOut(&StartTime, &ElapsedTime, &TimeoutTicks, NETC_ETHSWT_IP_TIMEOUT_VALUE_US);
3730         do {
3731             statusField = CmdBDRConfig[cbdrIndex].CmdBDAddr[PreviousProducerIdx].MessageHeaderDataField[NETC_ETHSWT_IP_RSPHEADER_STATUS_FIELD_INDEX];    /* get status field in the response data buffer */
3732             rrBit = ((statusField & (NETC_ETHSWT_IP_CMDBD_RSPFMT_STATUS_FIELD_RR_MASK)) >> (NETC_ETHSWT_IP_CMDBD_RSPFMT_STATUS_FIELD_RR_SHIFT));        /* get the value of RR bit in the response data buffer */
3733             TimeExpired = Netc_EthSwt_Ip_TimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
3734         } while ((rrBit != 0x1U) && (FALSE == TimeExpired));        /* wait the hardware consume the command and check RR bit to see if the processing is completed (rrBit = 1). */
3735         /* --- to make sure the hardware consumes and processes the command completely --- */
3736 
3737         /* return the value of ERROR field in response data buffer indicating if there is an error for processing the command */
3738         errorField = ((statusField & (NETC_ETHSWT_IP_CMDBD_RSPFMT_STATUS_FIELD_ERROR_MASK)) >> (NETC_ETHSWT_IP_CMDBD_RSPFMT_STATUS_FIELD_ERROR_SHIFT));
3739         if (errorField != 0U)
3740         {
3741             status = errorField;     /* ERROR field should be 0. */
3742         }
3743     }
3744     return status;
3745 }
3746 
3747 /*FUNCTION**********************************************************************
3748  *
3749  * Function Name : Netc_EthSwt_Ip_GetMatchedEntries
3750  * Description   : Function for getting matched table entries. Num_Matched field indicates if it matches an entry.
3751  *
3752  *END**************************************************************************/
Netc_EthSwt_Ip_GetMatchedEntries(uint8 cbdrIndex,uint32 * NumOfEntry)3753 static void Netc_EthSwt_Ip_GetMatchedEntries(uint8 cbdrIndex, uint32 *NumOfEntry)
3754 {
3755     uint32 producerIdx;
3756     uint32 statusField;
3757 
3758     producerIdx = IP_NETC__SW0_BASE->NUM_CBDR[cbdrIndex].CBDRPIR;
3759 
3760     /* the value stored in producer index register indicates the index of next entry */
3761     if (producerIdx > 0U)
3762     {
3763         producerIdx -= 1U;
3764     }
3765     else /* producerIdx increased from 15 to 0, will set it to 15, or length minus 1 */
3766     {
3767         producerIdx = ((uint32)(CmdBDRConfig[cbdrIndex].lengthCBDR) * NETC_ETHSWT_IP_SET_OF_BD) - 0x1UL;
3768     }
3769 
3770     /* get status field in the response data buffer for the matched fdb entry */
3771     statusField = CmdBDRConfig[cbdrIndex].CmdBDAddr[producerIdx].MessageHeaderDataField[NETC_ETHSWT_IP_RSPHEADER_STATUS_FIELD_INDEX];
3772 
3773     /* NUM_MATCHED should equal or greater than 1 if the entry exists for any commands. */
3774     *NumOfEntry = (statusField & (NETC_ETHSWT_IP_CMDBD_RSPFMT_STATUS_FIELD_NUMMATCHED_MASK));
3775 
3776 }
3777 
3778 /*FUNCTION**********************************************************************
3779  *
3780  * Function Name : Netc_EthSwt_Ip_GetCounters
3781  * Description   : Function for getting the counters of a port
3782  * implements Netc_EthSwt_Ip_GetCounters_Activity
3783  *END**************************************************************************/
Netc_EthSwt_Ip_GetCounters(uint8 SwitchIdx,uint8 SwitchPortIdx,Netc_EthSwt_Ip_CounterType * Counter)3784 Std_ReturnType Netc_EthSwt_Ip_GetCounters( uint8 SwitchIdx,
3785                                            uint8 SwitchPortIdx,
3786                                            Netc_EthSwt_Ip_CounterType *Counter
3787                                          )
3788 {
3789     Std_ReturnType status = E_OK;
3790 
3791 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
3792     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
3793     DevAssert(SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_PORTS);
3794     DevAssert(Counter != NULL_PTR);
3795 #endif
3796 
3797     if(SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_MAC_PORTS)
3798     {
3799         status = Netc_EthSwt_Ip_GetSwtPortCounters(SwitchIdx, SwitchPortIdx, Counter);
3800     }
3801     else
3802     {
3803         status = Netc_EthSwt_Ip_GetSwtPseudoPortCounters(SwitchIdx, SwitchPortIdx, Counter);
3804     }
3805 
3806     return status;
3807 }
3808 
3809 /*FUNCTION**********************************************************************
3810  *
3811  * Function Name : Netc_EthSwt_Ip_GetCounters
3812  * Description   : Function for getting the counters of a port
3813  * implements Netc_EthSwt_Ip_GetCounter_Activity
3814  *END**************************************************************************/
Netc_EthSwt_Ip_GetCounter(uint8 SwitchIdx,uint8 SwitchPortIdx,Netc_EthSwt_Ip_SingleCounterType Counter)3815 Netc_EthSwt_Ip_CounterValueType Netc_EthSwt_Ip_GetCounter(uint8 SwitchIdx, uint8 SwitchPortIdx, Netc_EthSwt_Ip_SingleCounterType Counter)
3816 {
3817     volatile uint32 *xCR0Value;
3818     volatile uint32 *xCR1Value;
3819     uint8 PseudoPortIdx;
3820     uint64 CounterValue = 0UL;
3821 
3822 #if (STD_ON == NETC_ETHSWT_IP_DEV_ERROR_DETECT)
3823     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
3824     DevAssert(SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_PORTS);
3825 #endif
3826 
3827     if(SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_MAC_PORTS)
3828     {
3829         /* Compute addres of the counter. for port 0 and port 1*/
3830         xCR0Value = (volatile uint32 *)((uint32)Netc_EthSwt_Ip_PortBaseTable[SwitchPortIdx] + (uint32)Counter);
3831         xCR1Value = (volatile uint32 *)((uint32)Netc_EthSwt_Ip_PortBaseTable[SwitchPortIdx] + (uint32)Counter) + 1U;
3832         CounterValue = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3833     }
3834     else
3835     {
3836         /* pseudo port indexes are starting after the mac ports. */
3837         PseudoPortIdx = SwitchPortIdx - NETC_ETHSWT_NUMBER_OF_MAC_PORTS;
3838         switch (Counter)
3839         {
3840             case NETC_ETHSWT_IP_RX_OCTETS_COUNT:
3841                 /* Compute addres of the counter. */
3842                 xCR0Value = (volatile uint32 *)((uint32)Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx] + (uint32)(NETC_ETHSWT_IP_PPMROCR0));
3843                 xCR1Value = (volatile uint32 *)((uint32)Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx] + (uint32)(NETC_ETHSWT_IP_PPMROCR1));
3844                 CounterValue = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3845                 break;
3846             case NETC_ETHSWT_IP_RX_UNICAST_FRM_COUNT:
3847                 /* Compute addres of the counter. */
3848                 xCR0Value = (volatile uint32 *)((uint32)Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx] + (uint32)(NETC_ETHSWT_IP_PPMRUFCR0));
3849                 xCR1Value = (volatile uint32 *)((uint32)Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx] + (uint32)(NETC_ETHSWT_IP_PPMROCR1));
3850                 CounterValue = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3851                 break;
3852             case NETC_ETHSWT_IP_RX_MULTICAST_FRM_COUNT:
3853                 /* Compute addres of the counter. */
3854                 xCR0Value = (volatile uint32 *)((uint32)Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx] + (uint32)(NETC_ETHSWT_IP_PPMRMFCR0));
3855                 xCR1Value = (volatile uint32 *)((uint32)Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx] + (uint32)(NETC_ETHSWT_IP_PPMRMFCR1));
3856                 CounterValue = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3857                 break;
3858             case NETC_ETHSWT_IP_RX_BROADCAST_FRM_COUNT:
3859                 /* Compute addres of the counter. */
3860                 xCR0Value = (volatile uint32 *)((uint32)Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx] + (uint32)(NETC_ETHSWT_IP_PPMRBFCR0));
3861                 xCR1Value = (volatile uint32 *)((uint32)Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx] + (uint32)(NETC_ETHSWT_IP_PPMRBFCR1));
3862                 CounterValue = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3863                 break;
3864             case NETC_ETHSWT_IP_TX_OCTETS_COUNT:
3865                 /* Compute addres of the counter. */
3866                 xCR0Value = (volatile uint32 *)((uint32)Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx] + (uint32)(NETC_ETHSWT_IP_PPMTOCR0));
3867                 xCR1Value = (volatile uint32 *)((uint32)Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx] + (uint32)(NETC_ETHSWT_IP_PPMTOCR1));
3868                 CounterValue = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3869                 break;
3870             case NETC_ETHSWT_IP_TX_UNICAST_FRM_COUNT:
3871                 /* Compute addres of the counter. */
3872                 xCR0Value = (volatile uint32 *)((uint32)Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx] + (uint32)(NETC_ETHSWT_IP_PPMTUFCR0));
3873                 xCR1Value = (volatile uint32 *)((uint32)Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx] + (uint32)(NETC_ETHSWT_IP_PPMTUFCR1));
3874                 CounterValue = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3875                 break;
3876             case NETC_ETHSWT_IP_TX_MULTICAST_FRM_COUNT:
3877                 /* Compute addres of the counter. */
3878                 xCR0Value = (volatile uint32 *)((uint32)Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx] + (uint32)(NETC_ETHSWT_IP_PPMTMFCR0));
3879                 xCR1Value = (volatile uint32 *)((uint32)Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx] + (uint32)(NETC_ETHSWT_IP_PPMTMFCR1));
3880                 CounterValue = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3881                 break;
3882             case NETC_ETHSWT_IP_TX_BROADCAST_FRM_COUNT:
3883                 /* Compute addres of the counter. */
3884                 xCR0Value = (volatile uint32 *)((uint32)Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx] + (uint32)(NETC_ETHSWT_IP_PPMTBFCR0));
3885                 xCR1Value = (volatile uint32 *)((uint32)Netc_EthSwt_Ip_PseudoPortBaseTable[PseudoPortIdx] + (uint32)(NETC_ETHSWT_IP_PPMTBFCR1));
3886                 CounterValue = (*xCR0Value) | ((uint64)(*xCR1Value) << NETC_ETHSWT_IP_32BIT_SHIFT);
3887                 break;
3888             default:
3889                 CounterValue = 0xFFFFFFFFFFFFFFFFU;
3890                 break;
3891         }
3892 
3893     }
3894 
3895     return CounterValue;
3896 }
3897 
3898 /*FUNCTION**********************************************************************
3899  *
3900  * Function Name : Netc_EthSwt_Ip_PortGetLoopbackMode
3901  * Description   : Function for getting the loopback mode of a port
3902  * implements Netc_EthSwt_Ip_PortGetLoopbackMode_Activity
3903  *END**************************************************************************/
Netc_EthSwt_Ip_PortGetLoopbackMode(uint8 SwitchIdx,uint8 SwitchPortIdx,boolean * LoopbackEnable)3904 Std_ReturnType Netc_EthSwt_Ip_PortGetLoopbackMode( uint8 SwitchIdx,
3905                                                    uint8 SwitchPortIdx,
3906                                                    boolean *LoopbackEnable
3907                                                  )
3908 {
3909     Std_ReturnType status = E_OK;
3910     uint32 portCommandConfig = 0UL;
3911 
3912     (void)SwitchIdx;
3913 
3914     /* Read the register */
3915     portCommandConfig = Netc_EthSwt_Ip_PortBaseTable[SwitchPortIdx]->PM0_COMMAND_CONFIG;
3916 
3917     /* Get the loop back mode value */
3918     if (SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_MAC_PORTS)
3919     {
3920         *LoopbackEnable = ((SW_ETH_MAC_PORT0_PM0_COMMAND_CONFIG_LOOP_ENA_MASK & portCommandConfig) == 0U) ? FALSE : TRUE;
3921     }
3922     else
3923     {
3924         *LoopbackEnable = FALSE;    /* pseudo port does not have loop back mode */
3925     }
3926     return status;
3927 }
3928 
3929 /*FUNCTION**********************************************************************
3930  *
3931  * Function Name : Netc_EthSwt_Ip_PortSetLoopbackMode
3932  * Description   : Function for setting the loopback mode of a port
3933  * implements Netc_EthSwt_Ip_PortSetLoopbackMode_Activity
3934  *END**************************************************************************/
Netc_EthSwt_Ip_PortSetLoopbackMode(uint8 SwitchIdx,uint8 SwitchPortIdx,boolean LoopbackEnable)3935 Std_ReturnType Netc_EthSwt_Ip_PortSetLoopbackMode( uint8 SwitchIdx,
3936                                                    uint8 SwitchPortIdx,
3937                                                    boolean LoopbackEnable
3938                                                   )
3939 {
3940     Std_ReturnType status = E_OK;
3941     uint32 portCommandConfig = 0UL;
3942 
3943 #if(NETC_ETHSWT_IP_DEV_ERROR_DETECT == STD_ON)
3944     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
3945     DevAssert(SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_MAC_PORTS);
3946 #endif
3947 
3948     portCommandConfig = Netc_EthSwt_Ip_PortBaseTable[SwitchPortIdx]->PM0_COMMAND_CONFIG
3949                         & ~SW_ETH_MAC_PORT0_PM0_COMMAND_CONFIG_LOOP_ENA_MASK;
3950 
3951     /* Configure the loopback mode in the PM0_COMMAND_CONFIG */
3952     if (TRUE == LoopbackEnable)
3953     {
3954         portCommandConfig |= SW_ETH_MAC_PORT0_PM0_COMMAND_CONFIG_LOOP_ENA_MASK;
3955     }
3956 
3957     /* Write the PM0_COMMAND_CONFIG with the computed value */
3958     Netc_EthSwt_Ip_PortBaseTable[SwitchPortIdx]->PM0_COMMAND_CONFIG = portCommandConfig;
3959     return status;
3960 }
3961 
Netc_EthSwt_Ip_SetPortMacLayerDuplexMode(uint8 SwitchIdx,uint8 SwitchPortIdx,Netc_EthSwt_Ip_PortDuplexType EthSwtPortMacLayerDuplexMode)3962 Std_ReturnType Netc_EthSwt_Ip_SetPortMacLayerDuplexMode( uint8 SwitchIdx, uint8 SwitchPortIdx,
3963                                                          Netc_EthSwt_Ip_PortDuplexType EthSwtPortMacLayerDuplexMode
3964                                                         )
3965 {
3966     Std_ReturnType status = E_OK;
3967     uint32 interfaceModeConfig = 0UL;
3968 
3969     (void) SwitchIdx;
3970 #if(NETC_ETHSWT_IP_DEV_ERROR_DETECT == STD_ON)
3971     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
3972     DevAssert(SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_PORTS);
3973 #endif
3974 
3975     if(SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_MAC_PORTS)
3976     {
3977         interfaceModeConfig = Netc_EthSwt_Ip_PortBaseTable[SwitchPortIdx]->PM0_IF_MODE;
3978 
3979         /* Is this RGMII mode == 4U */
3980         if ( SW_ETH_MAC_PORT_PM0_IF_MODE_IFMODE_RGMII_MODE == \
3981              ((interfaceModeConfig & SW_ETH_MAC_PORT0_PM0_IF_MODE_IFMODE_MASK) >> SW_ETH_MAC_PORT0_PM0_IF_MODE_IFMODE_SHIFT)
3982            )
3983         {
3984             /* Full duplex is 1 in SFD field */
3985             if(EthSwtPortMacLayerDuplexMode == NETC_ETHSWT_PORT_FULL_DUPLEX)
3986             {
3987                 interfaceModeConfig |= SW_ETH_MAC_PORT0_PM0_IF_MODE_SFD_MASK;
3988             }
3989             else /* ETHTRCV_DUPLEX_MODE_HALF */
3990             {
3991                 interfaceModeConfig &= ~SW_ETH_MAC_PORT0_PM0_IF_MODE_SFD_MASK;
3992             }
3993         }
3994         else
3995         {
3996             /* Full duplex is 0 in HD field */
3997             if(EthSwtPortMacLayerDuplexMode == NETC_ETHSWT_PORT_FULL_DUPLEX)
3998             {
3999                 interfaceModeConfig &= ~SW_ETH_MAC_PORT0_PM0_IF_MODE_HD_MASK;
4000             }
4001             else /* ETHTRCV_DUPLEX_MODE_HALF */
4002             {
4003                 interfaceModeConfig |= SW_ETH_MAC_PORT0_PM0_IF_MODE_HD_MASK;
4004             }
4005         }
4006 
4007         Netc_EthSwt_Ip_PortBaseTable[SwitchPortIdx]->PM0_IF_MODE = interfaceModeConfig;
4008     }
4009 
4010     return status;
4011 }
4012 
RGMIIModeConfig(uint32 * interfaceModeConfig,uint32 * shapingPSpeedConfig,EthTrcv_BaudRateType EthSwtPortMacLayerSpeed,Netc_EthSwt_Ip_PortDuplexType EthSwtPortMacLayerDuplexMode)4013 static inline Std_ReturnType RGMIIModeConfig(uint32 *interfaceModeConfig, uint32 *shapingPSpeedConfig, EthTrcv_BaudRateType EthSwtPortMacLayerSpeed, Netc_EthSwt_Ip_PortDuplexType EthSwtPortMacLayerDuplexMode)
4014 {
4015     Std_ReturnType status = E_OK;
4016 
4017     /* Full duplex is 1 in SFD field */
4018     if (EthSwtPortMacLayerDuplexMode == NETC_ETHSWT_PORT_FULL_DUPLEX)
4019     {
4020         (*interfaceModeConfig) |= SW_ETH_MAC_PORT1_PM0_IF_MODE_SFD_MASK;
4021     }
4022 
4023     switch(EthSwtPortMacLayerSpeed)
4024     {
4025         case ETHTRCV_BAUD_RATE_10MBIT: /* 10Mbps */
4026         {
4027             (*interfaceModeConfig) |= (SW_ETH_MAC_PORT1_PM0_IF_MODE_SSP(SW_ETH_MAC_PORT_PM0_IF_MODE_SSP_BAUD_RATE_10MBIT));
4028             (*shapingPSpeedConfig) = NETC_ETHSWT_IP_SHAPING_PSPEED_10MBITS;
4029             break;
4030         }
4031         case ETHTRCV_BAUD_RATE_100MBIT: /* 100Mbps */
4032         {
4033             (*interfaceModeConfig) |= (SW_ETH_MAC_PORT1_PM0_IF_MODE_SSP(SW_ETH_MAC_PORT_PM0_IF_MODE_SSP_BAUD_RATE_100MBIT));
4034             (*shapingPSpeedConfig) = NETC_ETHSWT_IP_SHAPING_PSPEED_100MBITS;
4035             break;
4036         }
4037         case ETHTRCV_BAUD_RATE_1000MBIT: /* 1000Mbps */
4038         {
4039             (*interfaceModeConfig) |= (SW_ETH_MAC_PORT1_PM0_IF_MODE_SSP(SW_ETH_MAC_PORT_PM0_IF_MODE_SSP_BAUD_RATE_1000MBIT));
4040             (*shapingPSpeedConfig) = NETC_ETHSWT_IP_SHAPING_PSPEED_1000MBITS;
4041             break;
4042         }
4043         default:
4044         {
4045             status = E_NOT_OK;
4046             break;
4047         }
4048     }
4049 
4050     return status;
4051 }
4052 
Netc_EthSwt_Ip_MacPortConfig(uint8 SwitchIdx,uint8 SwitchPortIdx,Netc_EthSwt_Ip_XmiiModeType EthSwtPortPhysicalLayerType,EthTrcv_BaudRateType EthSwtPortMacLayerSpeed,Netc_EthSwt_Ip_PortDuplexType EthSwtPortMacLayerDuplexMode)4053 static Std_ReturnType Netc_EthSwt_Ip_MacPortConfig( uint8 SwitchIdx, uint8 SwitchPortIdx,
4054                                                     Netc_EthSwt_Ip_XmiiModeType EthSwtPortPhysicalLayerType,
4055                                                     EthTrcv_BaudRateType EthSwtPortMacLayerSpeed,
4056                                                     Netc_EthSwt_Ip_PortDuplexType EthSwtPortMacLayerDuplexMode
4057                                                   )
4058 {
4059     Std_ReturnType status = E_OK;
4060     uint32 interfaceModeConfig = 0UL;
4061     uint32 shapingPSpeedConfig = 0UL; /* used for shaping of the port */
4062 
4063     (void) SwitchIdx;
4064 
4065     if(SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_MAC_PORTS)
4066     {
4067         /* Set the interface type */
4068         if (NETC_ETHSWT_RGMII_MODE == EthSwtPortPhysicalLayerType)
4069         {
4070             interfaceModeConfig |= (SW_ETH_MAC_PORT1_PM0_IF_MODE_IFMODE(4U));
4071             status = RGMIIModeConfig(&interfaceModeConfig, &shapingPSpeedConfig, EthSwtPortMacLayerSpeed, EthSwtPortMacLayerDuplexMode);
4072         }
4073         else if (NETC_ETHSWT_RMII_MODE == EthSwtPortPhysicalLayerType)
4074         {
4075             interfaceModeConfig = (SW_ETH_MAC_PORT1_PM0_IF_MODE_IFMODE(3U));
4076             /* Full duplex is 0 in HD field */
4077             if (EthSwtPortMacLayerDuplexMode == NETC_ETHSWT_PORT_FULL_DUPLEX)
4078             {
4079                 interfaceModeConfig |= SW_ETH_MAC_PORT1_PM0_IF_MODE_HD_MASK;
4080             }
4081             if(ETHTRCV_BAUD_RATE_10MBIT == EthSwtPortMacLayerSpeed)
4082             {
4083                 interfaceModeConfig |= SW_ETH_MAC_PORT1_PM0_IF_MODE_M10_MASK;
4084                 shapingPSpeedConfig = NETC_ETHSWT_IP_SHAPING_PSPEED_10MBITS;
4085             }
4086         }
4087         else if (NETC_ETHSWT_MII_MODE == EthSwtPortPhysicalLayerType)
4088         {
4089             interfaceModeConfig = (SW_ETH_MAC_PORT1_PM0_IF_MODE_IFMODE(1U));
4090             shapingPSpeedConfig = NETC_ETHSWT_IP_SHAPING_PSPEED_100MBITS;
4091         }
4092         else
4093         {
4094             /* type error */
4095             status = E_NOT_OK;
4096         }
4097 
4098         /* Write the interface mode configuration in the register */
4099         Netc_EthSwt_Ip_PortBaseTable[SwitchPortIdx]->PM0_IF_MODE = interfaceModeConfig;
4100         Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->PCR &= ~SW_PORT0_PCR_PSPEED_MASK;
4101         Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->PCR |= SW_PORT0_PCR_PSPEED(shapingPSpeedConfig);
4102     }
4103     else
4104     {
4105 	/* pseudo port */
4106         Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->PCR &= ~SW_PORT0_PCR_PSPEED_MASK;
4107         Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->PCR |= SW_PORT0_PCR_PSPEED(NETC_ETHSWT_IP_SHAPING_PSPEED_2000MBITS);
4108     }
4109 
4110     return status;
4111 }
4112 
4113 /* inline function for configuring BPDVR */
ConfigBridgePortDefaultVlanReg(uint8 SwitchPortIdx,const Netc_EthSwt_Ip_PortType * port)4114 static inline void ConfigBridgePortDefaultVlanReg(uint8 SwitchPortIdx, const Netc_EthSwt_Ip_PortType *port)
4115 {
4116     uint32 bridgePortDefaultVlan = 0UL;
4117 
4118     /* Bridge VLAN port defaults, bits in this section use reverse logic, TRUE==0 */
4119     if(TRUE != port->iPort->EthSwtDropDoubleTagged)
4120     {
4121         bridgePortDefaultVlan  |= SW_PORT0_BPDVR_RXTAGA(NETC_ETHSWT_IP_RXTAGA_ACCEPT_DOUBLE_TAGGED);
4122     }
4123     if(TRUE != port->iPort->EthSwtPortIngressDropUntagged)
4124     {
4125         bridgePortDefaultVlan  |= SW_PORT0_BPDVR_RXTAGA(NETC_ETHSWT_IP_RXTAGA_ACCEPT_UNTAGGED);
4126     }
4127     if(TRUE != port->iPort->EthSwtPortIngressDropSingleTagged)
4128     {
4129         bridgePortDefaultVlan  |= SW_PORT0_BPDVR_RXTAGA(NETC_ETHSWT_IP_RXTAGA_ACCEPT_SINGLE_TAGGED);
4130     }
4131     if(TRUE != port->iPort->EthSwtPortIngressDropPriorityTagged)
4132     {
4133         bridgePortDefaultVlan  |= SW_PORT0_BPDVR_RXTAGA(NETC_ETHSWT_IP_RXTAGA_ACCEPT_PRIO_TAGGED);
4134     }
4135     if(TRUE != port->iPort->vlanEnable)
4136     {
4137         bridgePortDefaultVlan  |= SW_PORT0_BPDVR_RXVAM(1);
4138     }
4139 
4140     if(TRUE == port->iPort->SentUntaggedFrames)
4141     {
4142         bridgePortDefaultVlan  |= SW_PORT0_BPDVR_TXTAGA(1);    /* Delete outer VLAN tag */
4143     }
4144     /* default vlan id */
4145     bridgePortDefaultVlan |= SW_PORT0_BPDVR_VID(port->iPort->EthSwtPortIngressDefaultVlan);
4146     /* default priority */
4147     bridgePortDefaultVlan |= SW_PORT0_BPDVR_PCP(port->iPort->EthSwtPortIngressDefaultPriority);
4148     Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->BPDVR = bridgePortDefaultVlan;
4149 }
4150 
4151 /* inline function for configuring credit base shaper registers */
ConfigCreditBaseShaperReg(uint8 SwitchPortIdx,const Netc_EthSwt_Ip_PortType * port)4152 static inline void ConfigCreditBaseShaperReg(uint8 SwitchPortIdx, const Netc_EthSwt_Ip_PortType *port)
4153 {
4154     uint8 shapingClass;
4155     uint32 localPtcTmSDUR;
4156 
4157     if(port->ePort->portShaper != NULL)
4158     {
4159         for(shapingClass = 0U; shapingClass < NETC_ETHSWT_IP_NUM_SHAPING_CLASS; shapingClass++)
4160         {
4161             /* Coonfigure the maximum frame size per shaping class, Max 2000 */
4162             localPtcTmSDUR = Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->TCT_NUM[shapingClass].PTCTMSDUR;
4163             localPtcTmSDUR &= ~SW_PORT0_PTCTMSDUR_MAXSDU_MASK;
4164             localPtcTmSDUR |= SW_PORT0_PTCTMSDUR_MAXSDU(port->ePort->portShaper[shapingClass]->EthSwtPortMaxSizedFrame);
4165             Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->TCT_NUM[shapingClass].PTCTMSDUR = localPtcTmSDUR;
4166 
4167             Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->TCT_NUM[shapingClass].PTCCBSR0 = SW_PORT0_PTCCBSR0_CBSE(port->ePort->portShaper[shapingClass]->EthSwtPortEgressCBShaperEnable ? 1U : 0U)
4168 	                                                                                        | SW_PORT0_PTCCBSR0_BW(port->ePort->portShaper[shapingClass]->EthSwtPortEgressCBShaperBandwidth);
4169             Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->TCT_NUM[shapingClass].PTCCBSR1 = SW_PORT0_PTCCBSR1_HI_CREDIT(port->ePort->portShaper[shapingClass]->EthSwtPortEgressHiCredit);
4170         }
4171     }
4172 }
4173 
4174 /* inline function for configuring PM0_COMMAND register */
ConfigPM0CommandReg(uint8 SwitchIdx,uint8 SwitchPortIdx,const Netc_EthSwt_Ip_PortType * port)4175 static inline Std_ReturnType ConfigPM0CommandReg(uint8 SwitchIdx, uint8 SwitchPortIdx, const Netc_EthSwt_Ip_PortType *port)
4176 {
4177     Std_ReturnType status = E_OK;
4178     uint32 portCommandConfig = 0UL;
4179 
4180     /* Start the PM0_COMMAND_CONFIG value with the TX padding option */
4181     portCommandConfig = SW_ETH_MAC_PORT0_PM0_COMMAND_CONFIG_TXP_MASK;
4182 
4183     /* Construct several values to be used later based on whether the port is enabled or not */
4184     if (TRUE == port->EthSwtPortMacLayerPortEnable)
4185     {
4186         /* The pseudoport does not have the PM0_COMMAND_CONFIG register */
4187         if (SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_MAC_PORTS)
4188         {
4189             portCommandConfig |= SW_ETH_MAC_PORT0_PM0_COMMAND_CONFIG_TX_EN_MASK | SW_ETH_MAC_PORT0_PM0_COMMAND_CONFIG_RX_EN_MASK;
4190         }
4191     }
4192     else
4193     {
4194         /* Disable the port in POR register */
4195         Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->POR |= SW_PORT0_POR_TXDIS_MASK | SW_PORT0_POR_RXDIS_MASK;
4196     }
4197 
4198     /* The pseudoport does not have the following options */
4199     if (SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_MAC_PORTS)
4200     {
4201         if(TRUE == port->EthSwtPortEnableMagicPacketDetection)
4202         {
4203             portCommandConfig |= SW_ETH_MAC_PORT0_PM0_COMMAND_CONFIG_MG(1U);
4204         }
4205 
4206         /* Configure the loopback mode in the PM0_COMMAND_CONFIG */
4207         if (TRUE == port->EthSwtPortLoopbackEnable)
4208         {
4209             portCommandConfig |= SW_ETH_MAC_PORT0_PM0_COMMAND_CONFIG_LOOP_ENA_MASK;
4210         }
4211 
4212         /* Write the PM0_COMMAND_CONFIG with the computed value */
4213         Netc_EthSwt_Ip_PortBaseTable[SwitchPortIdx]->PM0_COMMAND_CONFIG = portCommandConfig;
4214 
4215         /* Configure the interface mode, the speed and the duplex mode */
4216         status |= Netc_EthSwt_Ip_MacPortConfig( SwitchIdx, SwitchPortIdx, port->EthSwtPortPhysicalLayerType,
4217                                                 port->EthSwtPortMacLayerSpeed, port->EthSwtPortMacLayerDuplexMode
4218                                                 );
4219     }
4220 
4221     return status;
4222 }
4223 
Netc_EthSwt_Ip_InitPort(uint8 SwitchIdx,uint8 SwitchPortIdx,const Netc_EthSwt_Ip_PortType * port)4224 static Std_ReturnType Netc_EthSwt_Ip_InitPort(uint8 SwitchIdx, uint8 SwitchPortIdx, const Netc_EthSwt_Ip_PortType *port)
4225 {
4226     Std_ReturnType status = E_OK;
4227     uint32 bridgePortConfig = 0UL;
4228 
4229 
4230     (void) SwitchIdx;
4231 #if(NETC_ETHSWT_IP_DEV_ERROR_DETECT == STD_ON)
4232     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
4233     DevAssert(SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_PORTS);
4234 #endif
4235 
4236     /* Port QOS mode */
4237     Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->PQOSMR = SW_PORT0_PQOSMR_VS(1U)
4238         | SW_PORT0_PQOSMR_VE(port->iPort->vlanEnable?1U:0U)
4239         | SW_PORT0_PQOSMR_DIPV(port->iPort->vlanDefaultIpv)
4240         | SW_PORT0_PQOSMR_DDR(port->iPort->vlanDefaultDr)
4241         | SW_PORT0_PQOSMR_VQMP(port->iPort->vlanMappingProfile)
4242         | SW_PORT0_PQOSMR_QVMP(port->ePort->vlanMappingProfile);
4243 
4244     Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->PPCPDEIMR = SW_PORT0_PPCPDEIMR_IPCPMPV(port->iPort->vlanEnableIngressPcpToPcpMapping?1U:0U)
4245         | SW_PORT0_PPCPDEIMR_IPCPMP(port->iPort->vlanIngressPcpToPcpProfile)
4246         | SW_PORT0_PPCPDEIMR_EPCPMPV(port->ePort->vlanEnableEgressPcpToPcpMapping?1U:0U)
4247         | SW_PORT0_PPCPDEIMR_EPCPMP(port->ePort->vlanEgressPcpToPcpProfile)
4248         | SW_PORT0_PPCPDEIMR_DRME(port->ePort->updateEgressDr?1U:0U)
4249         | SW_PORT0_PPCPDEIMR_DR0DEI(port->ePort->vlanDrToDei[0U])
4250         | SW_PORT0_PPCPDEIMR_DR1DEI(port->ePort->vlanDrToDei[1U])
4251         | SW_PORT0_PPCPDEIMR_DR2DEI(port->ePort->vlanDrToDei[2U])
4252         | SW_PORT0_PPCPDEIMR_DR3DEI(port->ePort->vlanDrToDei[3U]);
4253 
4254     /* Bridge Port Default Vlan register configuration */
4255     ConfigBridgePortDefaultVlanReg(SwitchPortIdx, port);
4256 
4257     /* PM0_COMMAND_CONFIG configuration */
4258     status = ConfigPM0CommandReg(SwitchIdx, SwitchPortIdx, port);
4259 
4260     /* Bridge port configuration */
4261     if(port->EthSwtPortDisallowMacStationMove)
4262     {
4263         bridgePortConfig = SW_PORT1_BPCR_STAMVD(1U);
4264     }
4265 
4266     bridgePortConfig |= SW_PORT0_BPCR_DYN_LIMIT(port->EthSwtPortMaxDynamicEntries);
4267 
4268     /* Configure the pruning setting for each port */
4269     if (FALSE == port->EthSwtPortPruningEnable)
4270     {
4271         bridgePortConfig |= SW_PORT0_BPCR_SRCPRND_MASK;
4272     }
4273 
4274     Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->BPCR = bridgePortConfig;
4275 
4276     /* configure the credit base shaper */
4277     ConfigCreditBaseShaperReg(SwitchPortIdx, port);
4278 
4279     return status;
4280 }
4281 
4282 /*FUNCTION**********************************************************************
4283  *
4284  * Function Name : Netc_EthSwt_Ip_ConfigureCreditBasedShaper
4285  * Description   : function for configuring the CBS
4286  * implements Netc_EthSwt_Ip_ConfigureCreditBasedShaper_Activity
4287  *END**************************************************************************/
Netc_EthSwt_Ip_ConfigureCreditBasedShaper(uint8 SwitchIdx,const uint8 SwitchPortIdx,const uint8 TrafficClass,const uint64 idleSlope)4288 Std_ReturnType Netc_EthSwt_Ip_ConfigureCreditBasedShaper(uint8 SwitchIdx, const uint8 SwitchPortIdx, const uint8 TrafficClass, const uint64 idleSlope)
4289 {
4290     Std_ReturnType status = E_OK;
4291     uint64 portTxRate;
4292     EthTrcv_BaudRateType baudRate = ETHTRCV_BAUD_RATE_10MBIT;
4293     uint64 largeBandwidth;
4294     uint32 bandwidth;
4295     uint64 largeEgressHiCredit;
4296     uint32 egressHiCredit;
4297     uint32 Netc_EthSwt_Ip_MaxFrameSize;
4298 
4299 #if(NETC_ETHSWT_IP_DEV_ERROR_DETECT == STD_ON)
4300     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
4301     /* A Slope of zero would cause a bandwidth of zero and this would cause a buffer leak */
4302     DevAssert(idleSlope > 0U);
4303     DevAssert(TrafficClass < NETC_ETHSWT_IP_NUM_SHAPING_CLASS);
4304 #endif
4305 
4306     if(SwitchPortIdx < NETC_ETHSWT_NUMBER_OF_MAC_PORTS)
4307     {
4308         status = Netc_EthSwt_Ip_GetPortSpeed( SwitchIdx, SwitchPortIdx, &baudRate);
4309         status |= Netc_EthSwt_Ip_PortRateEnumToRate(baudRate, &portTxRate);
4310     }
4311     else
4312     {
4313         portTxRate = 2000000UL;
4314     };
4315 
4316     largeBandwidth = idleSlope / (portTxRate / 10000UL); /* bandwidth is in % and 100th precision, so need to divide by 10000 */
4317     if( largeBandwidth < 100UL )
4318     {
4319         largeBandwidth = 100UL; /* Min of 1% bandwidth, otherwise frames would get stuck in the switch */
4320     }
4321     /* Round and convert to uint32 */
4322     bandwidth = (uint32)(largeBandwidth/100UL);
4323     bandwidth = ((uint64)((((uint64)bandwidth)*100UL)+50UL)>largeBandwidth)?bandwidth:(bandwidth+1UL);
4324 
4325     /* High Credit in credits
4326            hiCredit (bits) = maxSizedFrame * (idleSlope/portTxRate)
4327            bandwidth = idleSlope / portTxRate
4328            Then:
4329                hiCredit (bits) = maxSizedFrame * bandwidth
4330 
4331            hiCredit (credits) = hiCredit (bits) * (ClockFrequency/portRate)
4332            Then:
4333                hiCredit (credits) = maxSizedFrame * bandwidth * (ClockFrequency / portRate)
4334     */
4335     Netc_EthSwt_Ip_MaxFrameSize = Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->TCT_NUM[TrafficClass].PTCTMSDUR;
4336     largeEgressHiCredit = largeBandwidth * Netc_EthSwt_Ip_MaxFrameSize * (Netc_EthSwt_Ip_NetcClockFrequency / (portTxRate)) / 100UL; /* Bandwidth is in %, need to div by 100 */
4337     /* Round and convert to uint32 */
4338     egressHiCredit = (uint32)(largeEgressHiCredit/100UL);
4339     egressHiCredit = (((egressHiCredit*100UL)+50UL)>egressHiCredit)?egressHiCredit:(egressHiCredit+1UL);
4340 
4341     Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->TCT_NUM[TrafficClass].PTCCBSR0 &= ~SW_PORT0_PTCCBSR0_BW_MASK;
4342     Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->TCT_NUM[TrafficClass].PTCCBSR0 |= SW_PORT0_PTCCBSR0_BW(bandwidth);
4343     Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->TCT_NUM[TrafficClass].PTCCBSR1 = SW_PORT0_PTCCBSR1_HI_CREDIT(egressHiCredit);
4344 
4345     return status;
4346 }
4347 
4348 /*FUNCTION**********************************************************************
4349  *
4350  * Function Name : Netc_EthSwt_Ip_EnableCreditBasedShaper
4351  * Description   : function for enabling a CBS
4352  * implements Netc_EthSwt_Ip_EnableCreditBasedShaper_Activity
4353  *END**************************************************************************/
Netc_EthSwt_Ip_EnableCreditBasedShaper(uint8 SwitchIdx,const uint8 SwitchPortIdx,const uint8 TrafficClass,const boolean Enable)4354 Std_ReturnType Netc_EthSwt_Ip_EnableCreditBasedShaper(uint8 SwitchIdx, const uint8 SwitchPortIdx, const uint8 TrafficClass, const boolean Enable)
4355 {
4356     Std_ReturnType status = E_OK;
4357 
4358 #if(NETC_ETHSWT_IP_DEV_ERROR_DETECT == STD_ON)
4359     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
4360     DevAssert(TrafficClass < NETC_ETHSWT_IP_NUM_SHAPING_CLASS);
4361 #endif
4362 
4363     /* clear the bit first */
4364     Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->TCT_NUM[TrafficClass].PTCCBSR0 &= ~SW_PORT0_PTCCBSR0_CBSE_MASK;
4365     /* write the bit */
4366     Netc_EthSwt_Ip_SW0_PortxBaseAddr[SwitchPortIdx]->TCT_NUM[TrafficClass].PTCCBSR0 |= SW_PORT0_PTCCBSR0_CBSE((TRUE==Enable)?1U:0U);
4367 
4368     return status;
4369 }
4370 
4371 /* inline function for configuring VlanIpvDr2PcpProfile */
ConfigVlanIpvDr2PcpProfile(const uint8 * IndexProfile,const Netc_EthSwt_Ip_ConfigType * Config)4372 static inline void ConfigVlanIpvDr2PcpProfile(const uint8 *IndexProfile, const Netc_EthSwt_Ip_ConfigType * Config)
4373 {
4374     uint8 IndexIpv;
4375     uint8 IndexDr;
4376 
4377     if(NULL_PTR != Config->vlanIpvDr2PcpProfile)
4378     {
4379         for (IndexDr=0U; IndexDr<NETC_ETHSWT_NUMBER_OF_DR; IndexDr++)
4380         { /* Shifted by NETC_ETHSWT_IP_FIELD_REP_IN_4BITS for each DR index */
4381             for (IndexIpv=0; IndexIpv<NETC_ETHSWT_NUMBER_OF_IPV; IndexIpv++)
4382             {
4383                 /* Settings are divied in 4 registers by groups of 2 */
4384                 if((IndexIpv % 2U) == 0U)
4385                 { /* even IPV in lower bits */
4386                     IP_NETC__SW0_BASE->MAP_PCP[(*IndexProfile)].QOSVLANMPR[IndexIpv/2U] |= (uint32)((uint32)((*(Config->vlanIpvDr2PcpProfile))[(*IndexProfile)][IndexIpv][IndexDr])
4387                     & NETC_F2_QOSVLANMPR_IPV0_DR0_MASK)<<(IndexDr*NETC_ETHSWT_IP_FIELD_REP_IN_4BITS);
4388                 }
4389                 else
4390                 {
4391                     IP_NETC__SW0_BASE->MAP_PCP[(*IndexProfile)].QOSVLANMPR[IndexIpv/2U] |= (uint32)((uint32)((*(Config->vlanIpvDr2PcpProfile))[(*IndexProfile)][IndexIpv][IndexDr])
4392                     & NETC_F2_QOSVLANMPR_IPV0_DR0_MASK)<<((IndexDr*NETC_ETHSWT_IP_FIELD_REP_IN_4BITS)+NETC_ETHSWT_IP_FIELD_REP_IN_TOP_OF_32BITS);
4393                 }
4394             }
4395         }
4396     }
4397 }
4398 
4399 /* inline function for initializing Mapping profile */
InitMappingProfile(const Netc_EthSwt_Ip_ConfigType * Config)4400 static inline void InitMappingProfile(const Netc_EthSwt_Ip_ConfigType * Config)
4401 {
4402     uint8 IndexProfile;
4403     uint8 IndexPcpDei;
4404     uint8 IndexPcp;
4405 
4406     /* Initialize the clasification mapping */
4407     for (IndexProfile=0U; IndexProfile<NETC_ETHSWT_NUMBER_OF_PROFILES; IndexProfile++)
4408     {
4409         /* Initializing the different arrays */
4410         IP_NETC__SW0_COMMON->NUM_PROFILE[IndexProfile].VLANIPVMPR0 = 0U;
4411         IP_NETC__SW0_COMMON->NUM_PROFILE[IndexProfile].VLANIPVMPR1 = 0U;
4412         IP_NETC__SW0_COMMON->NUM_PROFILE[IndexProfile].VLANDRMPR = 0U;
4413         IP_NETC__SW0_BASE->PCP2PCPMPR[IndexProfile] = 0U;
4414         IP_NETC__SW0_BASE->MAP_PCP[IndexProfile].QOSVLANMPR[0] = 0U;
4415         IP_NETC__SW0_BASE->MAP_PCP[IndexProfile].QOSVLANMPR[1] = 0U;
4416         IP_NETC__SW0_BASE->MAP_PCP[IndexProfile].QOSVLANMPR[2] = 0U;
4417         IP_NETC__SW0_BASE->MAP_PCP[IndexProfile].QOSVLANMPR[3] = 0U;
4418 
4419         if(NULL_PTR != Config->vlanPcpDei2IpvProfile )
4420         {
4421             for (IndexPcpDei=0U; IndexPcpDei<NETC_ETHSWT_NUMBER_OF_PCP_DEI; IndexPcpDei++)
4422             {
4423                 if(IndexPcpDei < (NETC_ETHSWT_NUMBER_OF_PCP_DEI/2U)) /* Setting are divided in 2 registers */
4424                 {
4425                     IP_NETC__SW0_COMMON->NUM_PROFILE[IndexProfile].VLANIPVMPR0 |= (((uint32)((*(Config->vlanPcpDei2IpvProfile))[IndexProfile][IndexPcpDei]) & NETC_F2_COMMON_VLANIPVMPR0_PCP_DEI_0_MASK)<<(IndexPcpDei*NETC_ETHSWT_IP_FIELD_REP_IN_4BITS));
4426                 }
4427                 else
4428                 {
4429                     IP_NETC__SW0_COMMON->NUM_PROFILE[IndexProfile].VLANIPVMPR1 |= (((uint32)((*(Config->vlanPcpDei2IpvProfile))[IndexProfile][IndexPcpDei]) & NETC_F2_COMMON_VLANIPVMPR0_PCP_DEI_0_MASK)<<(IndexPcpDei/2U*NETC_ETHSWT_IP_FIELD_REP_IN_4BITS));
4430                 }
4431             }
4432         }
4433         if(Config->vlanPcpDei2DrProfile != NULL_PTR)
4434         {
4435             for (IndexPcpDei=0U; IndexPcpDei<NETC_ETHSWT_NUMBER_OF_PCP_DEI; IndexPcpDei++)
4436             {
4437                 IP_NETC__SW0_COMMON->NUM_PROFILE[IndexProfile].VLANDRMPR |= (((uint32)((*(Config->vlanPcpDei2DrProfile))[IndexProfile][IndexPcpDei]) & NETC_F2_COMMON_VLANDRMPR_PCP_DEI_0_MASK)<<(IndexPcpDei*NETC_F2_COMMON_VLANDRMPR_PCP_DEI_0_WIDTH));
4438             }
4439         }
4440         if(NULL_PTR != Config->vlanPcp2PcpProfile)
4441         {
4442             for (IndexPcp=0U; IndexPcp<NETC_ETHSWT_NUMBER_OF_PCP; IndexPcp++)
4443             {
4444                     IP_NETC__SW0_BASE->PCP2PCPMPR[IndexProfile] |= (((uint32)((*(Config->vlanPcp2PcpProfile))[IndexProfile][IndexPcp]) & NETC_F2_PCP2PCPMPR_PCP0_MASK)<<(IndexPcp*NETC_ETHSWT_IP_FIELD_REP_IN_4BITS));
4445             }
4446         }
4447 
4448         ConfigVlanIpvDr2PcpProfile(&IndexProfile, Config);
4449     }
4450 }
4451 
4452 /* inline function for initializing 1588 timer */
InitTimer1588(const Netc_EthSwt_Ip_ConfigType * Config)4453 static inline void InitTimer1588(const Netc_EthSwt_Ip_ConfigType * Config)
4454 {
4455     uint32 TimerRefClk;
4456     uint16 TimerClkPeriod;
4457     uint32 ClkAddendData;
4458     uint32 TimerClkAddend;
4459 
4460     if (Config->Timer1588ClkSrc == ETHSWT_EXTERNAL_REFERENCE_CLOCK)
4461     {
4462         TimerRefClk = Config->netcExternalClockFrequency;
4463         IP_NETC__TMR0_BASE->TMR_CTRL &= ~TMR0_BASE_TMR_CTRL_CK_SEL(1U);         /* select the external 200MHz clock for 1588 timer */
4464     }
4465     else
4466     {
4467         TimerRefClk = Config->netcClockFrequency;
4468         IP_NETC__TMR0_BASE->TMR_CTRL |= TMR0_BASE_TMR_CTRL_CK_SEL(1U);          /* select NETC system clock (default setting) for 1588 timer */
4469     }
4470 
4471     TimerClkPeriod = (uint16)(1000U/(TimerRefClk/1000000U));                              /* clock period = 1/200000000 = 5ns */
4472     ClkAddendData = (1000000U/(TimerRefClk/1000000U)) - (1000U * TimerClkPeriod);
4473     TimerClkAddend = (uint32)((((uint64)0x1U << NETC_ETHSWT_IP_32BIT_SHIFT) * ClkAddendData) / 1000U);
4474 
4475     /* FunctionTimer addend register holds the fractional part of the timer clock period */
4476     IP_NETC__TMR0_BASE->TMR_ADD = TMR0_BASE_TMR_ADD_ADDEND(TimerClkAddend);
4477     /* clear CLK_PERIOD data field first */
4478     IP_NETC__TMR0_BASE->TMR_CTRL &= ~TMR0_BASE_TMR_CTRL_TCLK_PERIOD(0x3FFF);
4479     IP_NETC__TMR0_BASE->TMR_CTRL |= TMR0_BASE_TMR_CTRL_TCLK_PERIOD(TimerClkPeriod);
4480     /* Enable timer */
4481     IP_NETC__TMR0_BASE->TMR_CTRL |= TMR0_BASE_TMR_CTRL_TE(1U);        /* FunctionTimer addend register holds the fractional part of the timer clock period */
4482     IP_NETC__TMR0_BASE->TMR_ADD = TMR0_BASE_TMR_ADD_ADDEND(TimerClkAddend);
4483     /* clear CLK_PERIOD data field first */
4484     IP_NETC__TMR0_BASE->TMR_CTRL &= ~TMR0_BASE_TMR_CTRL_TCLK_PERIOD(0x3FFF);
4485     IP_NETC__TMR0_BASE->TMR_CTRL |= TMR0_BASE_TMR_CTRL_TCLK_PERIOD(TimerClkPeriod);
4486     /* Enable timer */
4487     IP_NETC__TMR0_BASE->TMR_CTRL |= TMR0_BASE_TMR_CTRL_TE(1U);
4488 }
4489 
4490 /* inline function for initializing time gate scheduling table entries data during switch init */
InitTimeGateSchedulingTableEntryData(const Netc_EthSwt_Ip_ConfigType * Config)4491 static inline void InitTimeGateSchedulingTableEntryData(const Netc_EthSwt_Ip_ConfigType * Config)
4492 {
4493     uint8 portIndex;
4494     uint8 GateControlListIdx;
4495 
4496     for (portIndex = 0U; portIndex < NETC_ETHSWT_NUMBER_OF_PORTS; portIndex++)
4497     {
4498         if ((*((*(Config)).port))[portIndex].ePort->portTimeAwareShaperEnable == TRUE)
4499         {
4500             /* set the flag for ports */
4501             PortTimeAwareShaperEnabled[portIndex] = TRUE;
4502 
4503             /* write register PTGSATOR. [Ricky}: not supported for now. follow up ticket needed. */
4504             /* TODO: Netc_EthSwt_Ip_SW0_PortxBaseAddr[portIndex]->RESERVED_7 should be equal to (*((*(Config)).port))[portIndex].ePort->portTimeGateSchedulingAdvanceTimeOffsetReg; */
4505 
4506             /* Fill in the data structure for time gate scheduling */
4507             TimeGateSchedulingEntryData[portIndex].TimeGateSchedulingTable_EID = portIndex;
4508             TimeGateSchedulingEntryData[portIndex].AdminBaseTime = (*((*(Config)).port))[portIndex].ePort->portEgressAdminBaseTime;
4509             TimeGateSchedulingEntryData[portIndex].AdminCycleTime = (*((*(Config)).port))[portIndex].ePort->portEgressAdminCycleTime;
4510             TimeGateSchedulingEntryData[portIndex].AdminCycleTimeExt = (*((*(Config)).port))[portIndex].ePort->portEgressAdminCycleTimeExt;
4511             TimeGateSchedulingEntryData[portIndex].AdminControlListLength = (*((*(Config)).port))[portIndex].ePort->numberOfGateControlListEntries;
4512             for (GateControlListIdx = 0U; GateControlListIdx < TimeGateSchedulingEntryData[portIndex].AdminControlListLength; GateControlListIdx++)
4513             {
4514                 TimeGateSchedulingEntryData[portIndex].GateEntryAdminControlListData[GateControlListIdx].AdminTimeInterval = (*((*((*(Config)).port))[portIndex].ePort->TimeGateControlListEntries))[GateControlListIdx].AdminTimeInterval;
4515                 TimeGateSchedulingEntryData[portIndex].GateEntryAdminControlListData[GateControlListIdx].AdminTrafficClassGateStates = (*((*((*(Config)).port))[portIndex].ePort->TimeGateControlListEntries))[GateControlListIdx].AdminTrafficClassGateStates;
4516                 TimeGateSchedulingEntryData[portIndex].GateEntryAdminControlListData[GateControlListIdx].AdminGateOperationType = (*((*((*(Config)).port))[portIndex].ePort->TimeGateControlListEntries))[GateControlListIdx].AdminGateOperationType;
4517             }
4518         }
4519     }
4520 }
4521 
4522 /*  Workaround for ERR051130:
4523     Egress time gate scheduling can get corrupted when functional level reset is applied or when time gating is disabled
4524 */
4525 /* Added 2 fake time gate control list entries for clearing the internal context for time gate scheduling feature */
InitTimeGateSchedulingFeature(uint8 SwitchIdx,uint8 SwitchPortIdx)4526 static Netc_EthSwt_Ip_CBDRStatusType InitTimeGateSchedulingFeature(uint8 SwitchIdx, uint8 SwitchPortIdx)
4527 {
4528     Netc_EthSwt_Ip_CBDRStatusType CBDRStatus = NETC_ETHSWT_CBDRSTATUS_SUCCES;
4529     volatile uint64 CurrentTime = 0;
4530     uint8 EntryIdx;
4531 
4532     /* fill in struct Netc_EthSwt_Ip_TimeGateSchedulingEntryDataType */
4533     TimeGateSchedulingEntryData[0U].TimeGateSchedulingTable_EID = SwitchPortIdx;
4534     TimeGateSchedulingEntryData[0U].AdminCycleTime = 4000000U;           /* it should be greater than the sum of time interval */
4535     TimeGateSchedulingEntryData[0U].AdminCycleTimeExt = 100000U;
4536     TimeGateSchedulingEntryData[0U].AdminControlListLength = 2U;         /* 2 entries */
4537 
4538     /* get the current time from 1588 timer */
4539     CurrentTime = IP_NETC__TMR0_BASE->TMR_CUR_TIME_L;      /* should read the Lower register first */
4540     CurrentTime |= ((uint64)(IP_NETC__TMR0_BASE->TMR_CUR_TIME_H)) << NETC_ETHSWT_IP_32BIT_SHIFT;
4541     TimeGateSchedulingEntryData[0U].AdminBaseTime = CurrentTime;        /* set base time to current time */
4542 
4543     /* fill in gate control list entries data */
4544     for (EntryIdx = 0U; EntryIdx < TimeGateSchedulingEntryData[0U].AdminControlListLength; EntryIdx++)
4545     {
4546         TimeGateSchedulingEntryData[0U].GateEntryAdminControlListData[EntryIdx].AdminTimeInterval = 2000000U;        /* the value is equal to transmit 128bytes + 20 bytes (header) frame with port speed 10M */
4547         TimeGateSchedulingEntryData[0U].GateEntryAdminControlListData[EntryIdx].AdminTrafficClassGateStates = 0xFFU;      /* all open */
4548         TimeGateSchedulingEntryData[0U].GateEntryAdminControlListData[EntryIdx].AdminGateOperationType = ETHSWT_HOST_REQUEST_UNCHANGED;
4549     }
4550 
4551     /* add these 2 gate control list entries */
4552     CBDRStatus = Netc_EthSwt_Ip_ConfigPortTimeGateScheduling(SwitchIdx, SwitchPortIdx, TRUE);
4553 
4554     return CBDRStatus;
4555 }
4556 
4557 /*FUNCTION**********************************************************************
4558  *
4559  * Function Name : Netc_EthSwt_Ip_Init
4560  * Description   : function for initializing a switch
4561  * implements Netc_EthSwt_Ip_Init_Activity
4562  *END**************************************************************************/
Netc_EthSwt_Ip_Init(uint8 SwitchIdx,const Netc_EthSwt_Ip_ConfigType * Config)4563 Std_ReturnType Netc_EthSwt_Ip_Init(uint8 SwitchIdx, const Netc_EthSwt_Ip_ConfigType * Config)
4564 {
4565     Std_ReturnType status = E_OK;
4566     Netc_EthSwt_Ip_CBDRStatusType CBDRStatus;
4567     uint8 portIndex;
4568     uint8 enabledPortMask = 0U;
4569 
4570 #if (NETC_ETHSWT_NUMBER_OF_FDB_ENTRIES > 0U)
4571     uint32 MatchedEntries = 0U;
4572     uint8 MacAddrByteIdx;
4573     uint8 FdbEntryIdx;
4574     Netc_EthSwt_Ip_FdbEntryDataType FdbTableEntry = {0};
4575 #endif
4576 #if (NETC_ETHSWT_NUMBER_OF_VLANFILTER_ENTRIES > 0U)
4577     uint32 VlanMatchedEntries = 0U;
4578     uint8 VlanEntryIdx;
4579     Netc_EthSwt_Ip_VlanFilterEntryDataType VlanFilterEntryData = {0};
4580 #endif
4581 
4582 #if(NETC_ETHSWT_IP_DEV_ERROR_DETECT == STD_ON)
4583     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
4584     DevAssert(Config != NULL_PTR);
4585 #endif
4586 
4587     /* Enable PCIE for the TIMER */
4588     IP_NETC__NETC_F0_PCI_HDR_TYPE0->PCI_CFH_CMD = NETC_F0_PCI_HDR_TYPE0_PCI_CFH_CMD_BUS_MASTER_EN(1U) | NETC_F0_PCI_HDR_TYPE0_PCI_CFH_CMD_MEM_ACCESS(1U);
4589     /* Enable PCIE for the MDIO */
4590     IP_NETC__NETC_F1_PCI_HDR_TYPE0->PCI_CFH_CMD = NETC_F1_PCI_HDR_TYPE0_PCI_CFH_CMD_BUS_MASTER_EN(1U) | NETC_F1_PCI_HDR_TYPE0_PCI_CFH_CMD_MEM_ACCESS(1U);
4591     /* Enable PCIE for the Switch */
4592     IP_NETC__NETC_F2_PCI_HDR_TYPE0->PCI_CFH_CMD = NETC_F2_PCI_HDR_TYPE0_PCI_CFH_CMD_BUS_MASTER_EN(1U) | NETC_F2_PCI_HDR_TYPE0_PCI_CFH_CMD_MEM_ACCESS(1U);
4593     /* Enable PCIE for the ENETC */
4594     IP_NETC__NETC_F3_PCI_HDR_TYPE0->PCI_CFH_CMD = NETC_F3_PCI_HDR_TYPE0_PCI_CFH_CMD_BUS_MASTER_EN(1U) | NETC_F3_PCI_HDR_TYPE0_PCI_CFH_CMD_MEM_ACCESS(1U);
4595 
4596     status = Netc_EthSwt_Ip_IerbReady();
4597 
4598     if(status == (uint8)(E_OK))
4599     {
4600         Netc_EthSwt_Ip_NetcClockFrequency = Config->netcClockFrequency;
4601 
4602         if(Config->EthSwtEnableSharedLearning)
4603         {
4604             IP_NETC__SW0_BASE->VFHTDECR1 = NETC_F2_VFHTDECR1_VL_MODE(1U) | NETC_F2_VFHTDECR1_FID(0U);
4605         }
4606         else
4607         {
4608             IP_NETC__SW0_BASE->VFHTDECR1 = NETC_F2_VFHTDECR1_VL_MODE(0U);
4609         }
4610 
4611         IP_NETC__SW0_BASE->FDBHTMCR = NETC_F2_FDBHTMCR_DYN_LIMIT(Config->EthSwtMaxDynamicEntries);
4612         IP_NETC__SW0_COMMON->CVLANR1 = NETC_F2_COMMON_CVLANR1_V(Config->EthSwtCustomVlanEtherType1);
4613         IP_NETC__SW0_COMMON->CVLANR2 = NETC_F2_COMMON_CVLANR2_ETYPE(Config->EthSwtCustomVlanEtherType2);
4614 
4615         /* Mapping profile initialization */
4616         InitMappingProfile(Config);
4617 
4618         /* Initialize the ports of the switch */
4619         for (portIndex = 0U; portIndex < NETC_ETHSWT_NUMBER_OF_PORTS; portIndex++)
4620         {
4621             status = Netc_EthSwt_Ip_InitPort(SwitchIdx, portIndex, &(*((*(Config)).port))[portIndex]);
4622 
4623             if (TRUE == (*((*(Config)).port))[portIndex].EthSwtPortMacLayerPortEnable)
4624             {
4625                 enabledPortMask |= (1U << portIndex);
4626             }
4627         }
4628 
4629         status |= Netc_EthSwt_Ip_EMDIOConfiguration(0U);  /* init EMDIO configuration register */
4630 
4631         /* Configure the VLAN filter hash default settings */
4632         IP_NETC__SW0_BASE->VFHTDECR0 = enabledPortMask; /* Add enabled ports to the default VLAN */
4633         /* To add Shared learning setting in EBT */
4634         /* set configured learning and forwarding options */
4635         IP_NETC__SW0_BASE->VFHTDECR2 = NETC_F2_VFHTDECR2_MLO(Config->MacLearningOption) | NETC_F2_VFHTDECR2_MFO(Config->MacForwardingOption);
4636 
4637         /* used for port aging, value in sec */
4638         Netc_EthSwt_Ip_FdbTableEntryTimeout = Config->EthSwtArlTableEntryTimeout;
4639 
4640         /* +++ initialize 1588 timer for time gate scheduling +++ */
4641         InitTimer1588(Config);
4642         /* --- initialize 1588 timer for time gate scheduling --- */
4643 
4644         /* initialize memory and length for command ring 0 and 1 */
4645         CmdBDRConfig[NETC_ETHSWT_IP_CBDR_0].CmdBDAddr = &SwtcommandRingDescriptor0[0U];
4646         CmdBDRConfig[NETC_ETHSWT_IP_CBDR_0].lengthCBDR = (NETC_ETHSWT_IP_CBDR0_LENGTH);
4647         CmdBDRConfig[NETC_ETHSWT_IP_CBDR_1].CmdBDAddr = &SwtcommandRingDescriptor1[0U];
4648         CmdBDRConfig[NETC_ETHSWT_IP_CBDR_1].lengthCBDR = (NETC_ETHSWT_IP_CBDR1_LENGTH);
4649 
4650         /* intialize command ring 0 */
4651         CBDRStatus = Netc_EthSwt_Ip_InitCommandBDR(0U, NETC_ETHSWT_IP_CBDR_0);
4652         if (NETC_ETHSWT_CBDRSTATUS_SUCCES == CBDRStatus)
4653         {
4654 #if (NETC_ETHSWT_NUMBER_OF_FDB_ENTRIES > 0U)
4655             /* Add static FDB entries */
4656             for (FdbEntryIdx = 0U; FdbEntryIdx < Config->NumberOfFdbEntries; FdbEntryIdx++)
4657             {
4658                 /* fill in data of Mac Address */
4659                 for (MacAddrByteIdx = 0U; MacAddrByteIdx < NETC_ETHSWT_IP_MACADDRLEN; MacAddrByteIdx++)
4660                 {
4661                     FdbTableEntry.MacAddr[MacAddrByteIdx] = (*(Config->FdbEntries))[FdbEntryIdx].macAddr[MacAddrByteIdx];
4662                 }
4663 
4664                 FdbTableEntry.FID = 0U; /* fill in data of FID */
4665                 FdbTableEntry.SwitchPortEgressBitMask = (*(Config->FdbEntries))[FdbEntryIdx].ePortMask; /* fill in data of port bitmask */
4666                 FdbTableEntry.DynamicEntry = FALSE; /* static entry */
4667 
4668                 CBDRStatus = Netc_EthSwt_Ip_AddOrUpdateFdbTableEntry(0U, NETC_ETHSWT_ADD_CMD, &MatchedEntries, &FdbTableEntry);
4669                 /* fail to add the static FDB entry */
4670                 if ((CBDRStatus != NETC_ETHSWT_CBDRSTATUS_SUCCES) || (MatchedEntries != 0U))
4671                 {
4672                     status = E_NOT_OK;
4673                     break;
4674                 }
4675 
4676             }
4677 #endif
4678 
4679 #if (NETC_ETHSWT_NUMBER_OF_VLANFILTER_ENTRIES > 0U)
4680             /* Add Vlan Filter entries */
4681             for (VlanEntryIdx = 0U; VlanEntryIdx < Config->NumberOfVlanFilterEntries; VlanEntryIdx++)
4682             {
4683                 /* fill in VlanFilterEntryData structure  */
4684                 VlanFilterEntryData.VlanID = (*(Config->VlanFilterEntries))[VlanEntryIdx].vlanId;
4685                 VlanFilterEntryData.PortMembershipBitmap = (*(Config->VlanFilterEntries))[VlanEntryIdx].iPortMask;
4686 
4687                 VlanFilterEntryData.FID = (0U);
4688                 VlanFilterEntryData.MacLearningOptions = (2U);                  /* enable mac learning */
4689                 VlanFilterEntryData.MacForwardingOptions = (2U);                /* FDB lookup, if there is no match, then frame is flooded */
4690                 VlanFilterEntryData.IpMulticastFloodingEnable = FALSE;          /* IP multicast flooding disable */
4691                 VlanFilterEntryData.IpMulticastFilteringEnable = FALSE;         /* IP multicast filtering disable */
4692                 VlanFilterEntryData.BaseEgressTreatmentEntryID = 0xFFFFFFFFUL;    /* egress treatment processing is by-passed */
4693 
4694                 CBDRStatus = Netc_EthSwt_Ip_AddOrUpdateVlanFilterTableEntry(0U, NETC_ETHSWT_ADD_CMD, &VlanMatchedEntries, &VlanFilterEntryData);
4695                 /* fail to add the Vlan Filter entry */
4696                 if ((CBDRStatus != NETC_ETHSWT_CBDRSTATUS_SUCCES) || (VlanMatchedEntries != 0U))
4697                 {
4698                     status = E_NOT_OK;
4699                     break;
4700                 }
4701             }
4702 #endif
4703 
4704             /* check if TAS is enabled or not */
4705             PortTimeAwareShaperEnabled[0U] = ((*((*(Config)).port))[0U].ePort->portTimeAwareShaperEnable ||
4706                                               (*((*(Config)).port))[1U].ePort->portTimeAwareShaperEnable ||
4707                                               (*((*(Config)).port))[2U].ePort->portTimeAwareShaperEnable) ? TRUE : FALSE;
4708 
4709             if (TRUE ==  PortTimeAwareShaperEnabled[0U])
4710             {
4711                 /* Default time gate scheduling conditions on the port 0 */
4712                 CBDRStatus = InitTimeGateSchedulingFeature(SwitchIdx, 0U);
4713                 if (CBDRStatus != NETC_ETHSWT_CBDRSTATUS_SUCCES)
4714                 {
4715                     status = E_NOT_OK;
4716                 }
4717                 else
4718                 {
4719                     /* Add time gate scheduling table entries data */
4720                     InitTimeGateSchedulingTableEntryData(Config);
4721                 }
4722             }
4723         }
4724         else
4725         {
4726             status = E_NOT_OK;
4727         }
4728     }
4729 
4730     return status;
4731 }
4732 
4733 /*FUNCTION**********************************************************************
4734  *
4735  * Function Name : Netc_EthSwt_Ip_EMDIOConfiguration
4736  * Description   : function for configuring the EMDIO
4737  *
4738  *END**************************************************************************/
Netc_EthSwt_Ip_EMDIOConfiguration(uint8 SwitchIdx)4739 static Std_ReturnType Netc_EthSwt_Ip_EMDIOConfiguration( uint8 SwitchIdx )
4740 {
4741     Std_ReturnType Status = E_OK;
4742     uint32 CfgData;
4743 
4744     (void)SwitchIdx;
4745 #if(NETC_ETHSWT_IP_DEV_ERROR_DETECT == STD_ON)
4746     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
4747 #endif
4748 
4749     CfgData = NETC_F1_EMDIO_CFG_CMP(0U) | NETC_F1_EMDIO_CFG_CIM(0U) | NETC_F1_EMDIO_CFG_NEG(1U) \
4750             | NETC_F1_EMDIO_CFG_EHOLD(0U) | NETC_F1_EMDIO_CFG_MDIO_CLK_DIV(NETC_ETHSWT_IP_MDIO_CLK_DIV) \
4751             | NETC_F1_EMDIO_CFG_ENC45(0U) | NETC_F1_EMDIO_CFG_PRE_DIS(0U) | NETC_F1_EMDIO_CFG_MDIO_HOLD(4U);
4752 
4753     /* config EMDIO_CFG register */
4754     IP_NETC__EMDIO_BASE->EMDIO_CFG = CfgData;
4755 
4756     return Status;
4757 }
4758 
4759 /*FUNCTION**********************************************************************
4760  *
4761  * Function Name : Netc_EthSwt_Ip_ReadTrcvRegister
4762  * Description   : External function for reading the content of a transceiver register
4763  * implements Netc_EthSwt_Ip_ReadTrcvRegister_Activity
4764  *END**************************************************************************/
Netc_EthSwt_Ip_ReadTrcvRegister(uint8 SwitchIdx,uint8 TrcvIdx,uint8 RegIdx,uint16 * RegVal)4765 Std_ReturnType Netc_EthSwt_Ip_ReadTrcvRegister( uint8 SwitchIdx, uint8 TrcvIdx, uint8 RegIdx, uint16 * RegVal )
4766 {
4767     Std_ReturnType Status = E_NOT_OK;
4768     uint32 CtrlData;
4769     uint32 StartTime;
4770     uint32 ElapsedTime;
4771     uint32 TimeoutTicks;
4772 
4773 #if(NETC_ETHSWT_IP_DEV_ERROR_DETECT == STD_ON)
4774     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
4775 #endif
4776 
4777     CtrlData = NETC_F1_EMDIO_CTL_PORT_ADDR(TrcvIdx) | NETC_F1_EMDIO_CTL_DEV_ADDR(RegIdx) \
4778              | NETC_F1_EMDIO_CTL_READ(1U);
4779 
4780     /* config EMDIO_CTL register */
4781     IP_NETC__EMDIO_BASE->EMDIO_CTL = CtrlData;
4782 
4783     /* Wait till MDIO transaction is occuring and no read error is detected */
4784     Netc_EthSwt_Ip_StartTimeOut(&StartTime, &ElapsedTime, &TimeoutTicks, NETC_ETHSWT_IP_TIMEOUT_VALUE_US);
4785     do
4786     {
4787         if ((IP_NETC__EMDIO_BASE->EMDIO_CFG & NETC_ETHSWT_IP_MDIO_REG_READ_FLAG) == 0x0U)
4788         {
4789             Status = E_OK;
4790             break;
4791         }
4792     } while (!Netc_EthSwt_Ip_TimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks));
4793 
4794     /* Read the Data */
4795     if ((uint8)(E_OK) == Status)
4796     {
4797         *RegVal = (uint16)(IP_NETC__EMDIO_BASE->EMDIO_DATA & NETC_F1_EMDIO_DATA_MDIO_DATA_MASK);
4798     }
4799 
4800     return Status;
4801 }
4802 
4803 /*FUNCTION**********************************************************************
4804  *
4805  * Function Name : Netc_EthSwt_Ip_ReadTrcvRegister
4806  * Description   : External function for writing the content of a transceiver register
4807  * implements Netc_EthSwt_Ip_WriteTrcvRegister_Activity
4808  *END**************************************************************************/
Netc_EthSwt_Ip_WriteTrcvRegister(uint8 SwitchIdx,uint8 TrcvIdx,uint8 RegIdx,uint16 RegVal)4809 Std_ReturnType Netc_EthSwt_Ip_WriteTrcvRegister( uint8 SwitchIdx, uint8 TrcvIdx, uint8 RegIdx, uint16 RegVal )
4810 {
4811     Std_ReturnType Status = E_NOT_OK;
4812     uint32 CtrlData;
4813     uint32 StartTime;
4814     uint32 ElapsedTime;
4815     uint32 TimeoutTicks;
4816 
4817 #if(NETC_ETHSWT_IP_DEV_ERROR_DETECT == STD_ON)
4818     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
4819 #endif
4820 
4821     CtrlData = NETC_F1_EMDIO_CTL_PORT_ADDR(TrcvIdx) | NETC_F1_EMDIO_CTL_DEV_ADDR(RegIdx);
4822 
4823     /* config EMDIO_CTL register */
4824     IP_NETC__EMDIO_BASE->EMDIO_CTL = CtrlData;
4825 
4826     /* Write MDIO_DATA for initiating write transaction to PHY */
4827     IP_NETC__EMDIO_BASE->EMDIO_DATA = RegVal;
4828 
4829     /* Wait till MDIO transaction is occuring */
4830     Netc_EthSwt_Ip_StartTimeOut(&StartTime, &ElapsedTime, &TimeoutTicks, NETC_ETHSWT_IP_TIMEOUT_VALUE_US);
4831     do
4832     {
4833         if ((IP_NETC__EMDIO_BASE->EMDIO_CFG & NETC_ETHSWT_IP_MDIO_REG_WRITE_FLAG) == 0x0U)
4834         {
4835             Status = E_OK;
4836             break;
4837         }
4838     } while (!Netc_EthSwt_Ip_TimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks));
4839 
4840     return Status;
4841 }
4842 
4843 /*FUNCTION**********************************************************************
4844  *
4845  * Function Name : Netc_EthSwt_Ip_GetPortMirrorState
4846  * Description   : External function for obtaining the current status of mirroring for the indexed Ethernet switch
4847  * implements Netc_EthSwt_Ip_GetMirrorState_Activity
4848  *END**************************************************************************/
Netc_EthSwt_Ip_GetMirrorState(uint8 SwitchIdx,Netc_EthSwt_Ip_SwitchMirrorStateType * MirrorStatePtr)4849 Std_ReturnType Netc_EthSwt_Ip_GetMirrorState( uint8 SwitchIdx, Netc_EthSwt_Ip_SwitchMirrorStateType *MirrorStatePtr )
4850 {
4851     Std_ReturnType Status = E_OK;
4852     uint32 MirrorState;
4853 
4854 #if(NETC_ETHSWT_IP_DEV_ERROR_DETECT == STD_ON)
4855     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
4856     DevAssert(MirrorStatePtr != NULL_PTR);
4857 #endif
4858 
4859     MirrorState = (IP_NETC__SW0_BASE->IMDCR0) & NETC_F2_IMDCR0_MIREN_MASK;
4860     *MirrorStatePtr = (MirrorState == 0U) ? (NETC_ETHSWT_MIRROR_DISABLED) : (NETC_ETHSWT_MIRROR_ENABLED);
4861 
4862     return Status;
4863 }
4864 
4865 /*FUNCTION**********************************************************************
4866  *
4867  * Function Name : Netc_EthSwt_Ip_SetMirrorState
4868  * Description   : External function for requesting to set the mirroring state of the given Ethernet switch.
4869  * implements Netc_EthSwt_Ip_SetMirrorState_Activity
4870  *END**************************************************************************/
Netc_EthSwt_Ip_SetMirrorState(uint8 SwitchIdx,Netc_EthSwt_Ip_SwitchMirrorStateType MirrorState)4871 Std_ReturnType Netc_EthSwt_Ip_SetMirrorState( uint8 SwitchIdx, Netc_EthSwt_Ip_SwitchMirrorStateType MirrorState )
4872 {
4873     Std_ReturnType Status = E_OK;
4874     uint32 RegIMDCR0 = 0x0UL;
4875 
4876 #if(NETC_ETHSWT_IP_DEV_ERROR_DETECT == STD_ON)
4877     DevAssert(SwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
4878 #endif
4879 
4880     RegIMDCR0 = IP_NETC__SW0_BASE->IMDCR0;
4881     if (NETC_ETHSWT_MIRROR_ENABLED == MirrorState)
4882     {
4883         RegIMDCR0 |= NETC_F2_IMDCR0_MIREN(NETC_ETHSWT_MIRROR_ENABLED);
4884     }
4885     else
4886     {
4887         RegIMDCR0 &= ~NETC_F2_IMDCR0_MIREN(NETC_ETHSWT_MIRROR_ENABLED);
4888     }
4889 
4890     IP_NETC__SW0_BASE->IMDCR0 = RegIMDCR0;
4891 
4892     return Status;
4893 }
4894 
4895 /*FUNCTION**********************************************************************
4896  *
4897  * Function Name : Netc_EthSwt_Ip_DeleteMirrorConfiguration
4898  * Description   : External function for deleting the mirror configuration of the given Ethernet switch..
4899  * implements Netc_EthSwt_Ip_DeleteMirrorConfiguration_Activity
4900  *END**************************************************************************/
Netc_EthSwt_Ip_DeleteMirrorConfiguration(uint8 MirroredSwitchIdx)4901 Std_ReturnType Netc_EthSwt_Ip_DeleteMirrorConfiguration( uint8 MirroredSwitchIdx )
4902 {
4903     Std_ReturnType Status = E_OK;
4904     Netc_EthSwt_Ip_CBDRStatusType CBDRStatus;
4905     uint16 EFMEntryId;
4906     uint8 MIRDestBit;
4907     uint32 MatchedEntries = 0U;
4908 
4909 #if(NETC_ETHSWT_IP_DEV_ERROR_DETECT == STD_ON)
4910     DevAssert(MirroredSwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
4911 #endif
4912 
4913     if (TRUE == MirrorConfigurationDone)
4914     {
4915         if (MirroringIngressPortFilterEntryId != NETC_ETHSWT_IP_BD_NULL_ENTRY_ID)
4916         {
4917             /* Delete ingress port filter entry */
4918             CBDRStatus = Netc_EthSwt_Ip_DeleteIngressPortFilterTableEntry(MirroredSwitchIdx, &MatchedEntries, MirroringIngressPortFilterEntryId);
4919             if ((NETC_ETHSWT_CBDRSTATUS_SUCCES != CBDRStatus) || (0U == MatchedEntries))
4920             {
4921                 Status = E_NOT_OK;
4922             }
4923             else
4924             {
4925                 /* Set ingress port filter entry to NULL again */
4926                 MirroringIngressPortFilterEntryId = NETC_ETHSWT_IP_BD_NULL_ENTRY_ID;
4927             }
4928         }
4929 
4930         /* Delete Frame modificatin entry */
4931         MIRDestBit = (uint8)((IP_NETC__SW0_BASE->IMDCR0 & NETC_F2_IMDCR0_MIRDEST_MASK) >> NETC_F2_IMDCR0_MIRDEST_SHIFT);
4932         EFMEntryId = (uint16)(IP_NETC__SW0_BASE->IMDCR1 & NETC_F2_IMDCR1_EFMEID_MASK);
4933         if ((EFMEntryId != 0xFFFFU) && (MIRDestBit == 0U))
4934         {
4935             CBDRStatus = Netc_EthSwt_Ip_DeleteFrmModificationTableEntry(MirroredSwitchIdx, EFMEntryId, &MatchedEntries);
4936             if ((NETC_ETHSWT_CBDRSTATUS_SUCCES != CBDRStatus) || (0U == MatchedEntries))
4937             {
4938                 Status = E_NOT_OK;
4939             }
4940             else
4941             {
4942                 EFMEntryId = (uint16)(NETC_F2_IMDCR1_EFMEID(0xFFFFU));        /* set frame modification table entry ID to NULL */
4943                 IP_NETC__SW0_BASE->IMDCR1 |= EFMEntryId;
4944             }
4945         }
4946 
4947         if ((uint8)(E_OK) == Status)
4948         {
4949             Status = Netc_EthSwt_Ip_SetMirrorState(MirroredSwitchIdx, NETC_ETHSWT_MIRROR_DISABLED);
4950 
4951             /* Disable ingress mirroring on all ports */
4952             Netc_EthSwt_Ip_SW0_PortxBaseAddr[0U]->PMCR = 0x0U;
4953             Netc_EthSwt_Ip_SW0_PortxBaseAddr[1U]->PMCR = 0x0U;
4954             Netc_EthSwt_Ip_SW0_PortxBaseAddr[2U]->PMCR = 0x0U;
4955 
4956             MirrorConfigurationDone = FALSE;
4957         }
4958     }
4959 
4960     return Status;
4961 }
4962 
4963 /* inline function for checking if mac address filter enabled or not */
CheckMacAddressFilterEnableFlag(boolean * SrcMacAddrFilterEnabled,boolean * DstMacAddrFilterEnabled,const Netc_EthSwt_Ip_SwitchMirrorCfgType * MirrorConfigurationPtr)4964 static inline void CheckMacAddressFilterEnableFlag(boolean *SrcMacAddrFilterEnabled, boolean *DstMacAddrFilterEnabled, const Netc_EthSwt_Ip_SwitchMirrorCfgType* MirrorConfigurationPtr)
4965 {
4966     uint8 MacByteIdx;
4967 
4968     for (MacByteIdx = 0U; MacByteIdx < NETC_ETHSWT_IP_MACADDRLEN; MacByteIdx++)
4969     {
4970         if (MirrorConfigurationPtr->SrcMacAddrFilter[MacByteIdx] != 0x0U)
4971         {
4972             *SrcMacAddrFilterEnabled = TRUE;
4973             break;
4974         }
4975     }
4976     for (MacByteIdx = 0U; MacByteIdx < NETC_ETHSWT_IP_MACADDRLEN; MacByteIdx++)
4977     {
4978         if (MirrorConfigurationPtr->DstMacAddrFilter[MacByteIdx] != 0x0U)
4979         {
4980             *DstMacAddrFilterEnabled = TRUE;
4981             break;
4982         }
4983     }
4984 }
4985 
4986 /* inline function for enabling mac address filtering */
ConfigAndEnableIngressPortFiltering(uint8 MirroredSwitchIdx,const boolean * SrcMacAddrFilterEnabled,const boolean * DstMacAddrFilterEnabled,const Netc_EthSwt_Ip_SwitchMirrorCfgType * MirrorConfigurationPtr,Netc_EthSwt_Ip_IngressPortFilterEntryDataType * IngressPortFilterTableEntry)4987 static inline Std_ReturnType ConfigAndEnableIngressPortFiltering(uint8 MirroredSwitchIdx, const boolean *SrcMacAddrFilterEnabled,
4988                                                                  const boolean *DstMacAddrFilterEnabled,
4989                                                                  const Netc_EthSwt_Ip_SwitchMirrorCfgType* MirrorConfigurationPtr,
4990                                                                  Netc_EthSwt_Ip_IngressPortFilterEntryDataType *IngressPortFilterTableEntry
4991                                                                 )
4992 {
4993     Std_ReturnType Status = E_OK;
4994     Netc_EthSwt_Ip_CBDRStatusType CBDRStatus;
4995     uint8 MacByteIdx;
4996     uint8 PayloadByteIdx;
4997     uint32 MatchedEntries;
4998 
4999     /* config and add one ingress port filter table entry */
5000     IngressPortFilterTableEntry->IngressPortFilterCfgeData.CfgeOverrideIpv = FALSE;
5001     IngressPortFilterTableEntry->IngressPortFilterCfgeData.CfgeOverrideDr = FALSE;
5002     IngressPortFilterTableEntry->IngressPortFilterCfgeData.CfgeIngressMirroringEnable = TRUE;    /* enable mirroring */
5003     IngressPortFilterTableEntry->IngressPortFilterCfgeData.CfgeWakeOnLanTriggerEnable = FALSE;
5004     IngressPortFilterTableEntry->IngressPortFilterCfgeData.CfgeCutThroughDisable = TRUE;         /* shoudl disable CTD */
5005     IngressPortFilterTableEntry->IngressPortFilterCfgeData.CfgeTimestampCaptureEable = FALSE;
5006     /* permit frames */
5007     IngressPortFilterTableEntry->IngressPortFilterCfgeData.CfgeFilterForwardingAction = NETC_ETHSWT_IP_INGRESSPORTFILTERTABLE_PERMITFRAMES;
5008     IngressPortFilterTableEntry->IngressPortFilterCfgeData.CfgeFilterAction = NETC_ETHSWT_IP_INGRESSPORTFILTERTABLE_NOACTION;
5009 
5010     /* enable mac address filtering */
5011     for (MacByteIdx = 0U; MacByteIdx < NETC_ETHSWT_IP_MACADDRLEN; MacByteIdx++)
5012     {
5013         if (*DstMacAddrFilterEnabled == TRUE)
5014         {
5015             IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDstMacAddrMask[MacByteIdx] = 0xFFU;
5016             IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDstMacAddr[MacByteIdx] = MirrorConfigurationPtr->DstMacAddrFilter[MacByteIdx];
5017             MirrorCfgBackup.DstMacAddrFilter[MacByteIdx] = MirrorConfigurationPtr->DstMacAddrFilter[MacByteIdx];
5018         }
5019         else
5020         {
5021             IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDstMacAddrMask[MacByteIdx] = 0x0U;
5022             MirrorCfgBackup.DstMacAddrFilter[MacByteIdx] = 0x0U;
5023         }
5024 
5025         if (*SrcMacAddrFilterEnabled == TRUE)
5026         {
5027             IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSrcMacAddrMask[MacByteIdx] = 0xFFU;
5028             IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSrcMacAddr[MacByteIdx] = MirrorConfigurationPtr->SrcMacAddrFilter[MacByteIdx];
5029             MirrorCfgBackup.SrcMacAddrFilter[MacByteIdx] = MirrorConfigurationPtr->SrcMacAddrFilter[MacByteIdx];
5030         }
5031         else
5032         {
5033             IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSrcMacAddrMask[MacByteIdx] = 0x0U;
5034             MirrorCfgBackup.SrcMacAddrFilter[MacByteIdx] = 0x0U;
5035         }
5036     }
5037 
5038     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeFrmAttributeFlagsMask = 0U;
5039     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeSourcePortIDMask = 0U;
5040     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeDifferentiatedServicesCodePointMask = 0U;
5041     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeInnerVLANTagControlInformationMask = 0U;
5042     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeEtherTypeMask = 0U;
5043     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeIPProtocolMask = 0U;
5044     for (MacByteIdx = 0U; MacByteIdx < 4U; MacByteIdx++)
5045     {
5046         IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeIPSourceAddressMask[MacByteIdx] = 0x0U;
5047         IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeIPDestinationAddressMask[MacByteIdx] = 0x0U;
5048     }
5049     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeL4SourcePortMask = 0U;
5050     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeL4DestinationPortMask = 0U;
5051     for (PayloadByteIdx = 0U; PayloadByteIdx < 24U; PayloadByteIdx++)
5052     {
5053         IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyePayloadBytesMask[PayloadByteIdx] = 0x0U;
5054     }
5055     IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyePrecedence = 0xFFFFU;      /* precedence, maximum priority */
5056 
5057     if (MirrorConfigurationPtr->VlanIdFilter != 0xFFFFU)
5058     {
5059         MirrorCfgBackup.VlanIdFilter = MirrorConfigurationPtr->VlanIdFilter;
5060 
5061         /* vlan id filter */
5062         IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeOuterVLANTagControlInformationMask = 0xFFF0U;
5063         IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeOuterVLANTagControlInformation = (MirrorConfigurationPtr->VlanIdFilter);
5064     }
5065     else
5066     {
5067         MirrorCfgBackup.VlanIdFilter = 0xFFFFU;
5068         IngressPortFilterTableEntry->IngressPortFilterkeyeData.KeyeOuterVLANTagControlInformationMask = 0x0U;
5069     }
5070 
5071     CBDRStatus = Netc_EthSwt_Ip_AddIngressPortFilterTableEntry(MirroredSwitchIdx, &MatchedEntries, IngressPortFilterTableEntry);
5072     if ((NETC_ETHSWT_CBDRSTATUS_SUCCES != CBDRStatus) || (1U == MatchedEntries))
5073     {
5074         Status = E_NOT_OK;
5075     }
5076     else
5077     {
5078         /* Store the ingress port filter entry id */
5079         MirroringIngressPortFilterEntryId = IngressPortFilterTableEntry->IngressPortFilterEntryID;
5080     }
5081 
5082     return Status;
5083 }
5084 
5085 /* inline function for retagging /double tagging egress frames with frame modification table entry */
ConfigAndEnableEgressFramesModification(uint8 MirroredSwitchIdx,const Netc_EthSwt_Ip_SwitchMirrorCfgType * MirrorConfigurationPtr)5086 static inline Std_ReturnType ConfigAndEnableEgressFramesModification(uint8 MirroredSwitchIdx, const Netc_EthSwt_Ip_SwitchMirrorCfgType* MirrorConfigurationPtr)
5087 {
5088     Std_ReturnType Status = E_OK;
5089     Netc_EthSwt_Ip_CBDRStatusType CBDRStatus;
5090     uint32 RegIMDCR1 = 0x0UL;
5091     uint32 MatchedEntries = 0x0UL;
5092     Netc_EthSwt_Ip_FrmModificationEntryDataType FrmModificationEntry = {0};
5093 
5094     if (MirrorConfigurationPtr->MirroringMode != NETC_ETHSWT_NO_VLAN_RETAGGING)
5095     {
5096         /* config and add one frame modification table entry for modifying the dest mac address */
5097         FrmModificationEntry.FrmModificationEntryID = NETC_ETHSWT_EFMEID_FOR_MIRRORING;                   /* default frame modification table entry ID for mirroring */
5098         FrmModificationEntry.L2Actions = 0U;
5099         FrmModificationEntry.L2HeaderMacActions = 0U;                       /*  no actions for Header Mac */
5100         FrmModificationEntry.L2HeaderVlanActions = (MirrorConfigurationPtr->MirroringMode > NETC_ETHSWT_VLAN_RETAGGING) ? (2U) : (3U);
5101         FrmModificationEntry.OuterVidActions = 1U;                          /*  Use the VID specified in the OUTER_VLAN_VID field of this entry */
5102         FrmModificationEntry.OuterVlanVID = MirrorConfigurationPtr->VlanId;
5103         FrmModificationEntry.OuterTpidAction = 0U;                          /* Use TPID, PCP and DEI from outer VLAN header */
5104         FrmModificationEntry.OuterDeiAction = 0U;                           /* Use TPID, PCP and DEI from outer VLAN header */
5105         FrmModificationEntry.OuterPcpAction = 0U;                           /* Use TPID, PCP and DEI from outer VLAN header */
5106         FrmModificationEntry.SequenceTagAction = 0U;
5107         FrmModificationEntry.PayloadActions = 0U;
5108         FrmModificationEntry.FrmModificationDataEntryID = 0xFFFFFFFFUL;     /* frame modification data table entry id */
5109 
5110         CBDRStatus = Netc_EthSwt_Ip_AddOrUpdateFrmModificationTableEntry(MirroredSwitchIdx, NETC_ETHSWT_ADD_CMD, &MatchedEntries, &FrmModificationEntry);
5111         if (NETC_ETHSWT_CBDRSTATUS_SUCCES == CBDRStatus)
5112         {
5113             /* [IMDCR0]: keep IPV and DR default in IMDCR0 register */
5114             /* [IMDCR1] */
5115             RegIMDCR1 = NETC_F2_IMDCR1_EFM_LEN_CHANGE(NETC_ETHSWT_EFM_LEN_CHANGE_FOR_MIRRORING);
5116             RegIMDCR1 |= NETC_F2_IMDCR1_EFMEID(NETC_ETHSWT_EFMEID_FOR_MIRRORING);        /* default frame modification table entry ID for mirroring */
5117             IP_NETC__SW0_BASE->IMDCR1 = RegIMDCR1;
5118         }
5119         else
5120         {
5121             Status = E_NOT_OK;
5122         }
5123     }
5124 
5125     return Status;
5126 }
5127 
5128 /*FUNCTION**********************************************************************
5129  *
5130  * Function Name : Netc_EthSwt_Ip_WriteMirrorConfiguration
5131  * Description   : Function used for writing a mirroring configuration
5132  * implements Netc_EthSwt_Ip_WriteMirrorConfiguration_Activity
5133  *END**************************************************************************/
Netc_EthSwt_Ip_WriteMirrorConfiguration(uint8 MirroredSwitchIdx,const Netc_EthSwt_Ip_SwitchMirrorCfgType * MirrorConfigurationPtr)5134 Std_ReturnType Netc_EthSwt_Ip_WriteMirrorConfiguration( uint8 MirroredSwitchIdx, const Netc_EthSwt_Ip_SwitchMirrorCfgType* MirrorConfigurationPtr )
5135 {
5136     Std_ReturnType Status = E_OK;
5137     uint32 RegIMDCR0 = 0x0UL;
5138     uint32 RegIMDCR1 = 0x0UL;
5139     uint8 PortIdx;
5140     uint32 IngressBitMask;
5141     boolean DstMacAddrFilterEnabled = FALSE;
5142     boolean SrcMacAddrFilterEnabled = FALSE;
5143     Netc_EthSwt_Ip_IngressPortFilterEntryDataType IngressPortFilterTableEntry = {0};
5144 
5145 
5146 #if(NETC_ETHSWT_IP_DEV_ERROR_DETECT == STD_ON)
5147     DevAssert(MirroredSwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
5148     DevAssert(MirrorConfigurationPtr != NULL_PTR);
5149     DevAssert(MirrorConfigurationPtr->CapturePortIdx < NETC_ETHSWT_NUMBER_OF_PORTS);
5150     DevAssert(MirrorConfigurationPtr->MirroringMode <= NETC_ETHSWT_VLAN_DOUBLE_TAGGING);
5151 #endif
5152 
5153     /* If a mirroring configuration is already in place, delete it */
5154     Status = Netc_EthSwt_Ip_DeleteMirrorConfiguration(MirroredSwitchIdx);
5155     if ((uint8)(E_OK) == Status)
5156     {
5157         /* Indicates the mirror destination */
5158         RegIMDCR0 = IP_NETC__SW0_BASE->IMDCR0;
5159         RegIMDCR0 &= ~(NETC_F2_IMDCR0_MIRDEST_MASK);
5160         RegIMDCR0 |= NETC_F2_IMDCR0_MIRDEST(0U);         /* 0: Port as specified by PORT field; 1: Switch management port */
5161         RegIMDCR0 &= ~(NETC_F2_IMDCR0_PORT_MASK);
5162         RegIMDCR0 |= NETC_F2_IMDCR0_PORT(MirrorConfigurationPtr->CapturePortIdx);
5163         /* Write IMDCR0 register */
5164         IP_NETC__SW0_BASE->IMDCR0 = RegIMDCR0;
5165 
5166         RegIMDCR1 = NETC_F2_IMDCR1_EFMEID(0xFFFFU);        /* set frame modification table entry ID to NULL */
5167         IP_NETC__SW0_BASE->IMDCR1 |= RegIMDCR1;
5168 
5169         /* check if Mac Address Filter enabled */
5170         CheckMacAddressFilterEnableFlag(&SrcMacAddrFilterEnabled, &DstMacAddrFilterEnabled, MirrorConfigurationPtr);
5171 
5172         /* Start writing mirroring configuration */
5173         /* #1 */
5174         if ((MirrorConfigurationPtr->VlanIdFilter == 0xFFFFU) && (DstMacAddrFilterEnabled == FALSE) && (SrcMacAddrFilterEnabled == FALSE))
5175         {
5176             /* Enable port mirroring according to TrafficDirectionIngressBitMask */
5177             IngressBitMask = MirrorConfigurationPtr->TrafficDirectionIngressBitMask;
5178             for(PortIdx = 0U; PortIdx < NETC_ETHSWT_NUMBER_OF_PORTS; PortIdx++)
5179             {
5180                 if((IngressBitMask & 0x1U) == 0x1U)
5181                 {
5182                     Netc_EthSwt_Ip_SW0_PortxBaseAddr[PortIdx]->PMCR = (uint32)0x1U;
5183                 }
5184                 IngressBitMask >>= 1U;
5185             }
5186         }
5187         else    /* #2 ingress port filtering */
5188         {
5189             /* using bitmask to enable port filtering */
5190             IngressBitMask = MirrorConfigurationPtr->TrafficDirectionIngressBitMask;
5191             for(PortIdx = 0U; PortIdx < NETC_ETHSWT_NUMBER_OF_PORTS; PortIdx++)
5192             {
5193                 if((IngressBitMask & 0x1U) == 0x1U)
5194                 {
5195                     /* Enable ingress port filter table lookup function for ports */
5196                     Status = Netc_EthSwt_Ip_EnableIngressPortFiltering(MirroredSwitchIdx, PortIdx, TRUE);
5197                 }
5198                 IngressBitMask >>= 1U;
5199             }
5200 
5201             /* Config and add the ingress port filter table entry for ingress frames filtering */
5202             Status |= ConfigAndEnableIngressPortFiltering(MirroredSwitchIdx, &SrcMacAddrFilterEnabled, &DstMacAddrFilterEnabled, MirrorConfigurationPtr, &IngressPortFilterTableEntry);
5203         }
5204 
5205         /* #3 egress frame modification */
5206         Status |= ConfigAndEnableEgressFramesModification(MirroredSwitchIdx, MirrorConfigurationPtr);
5207 
5208         if ((uint8)(E_OK) == Status)
5209         {
5210             /* Set the mirror configuration done flag */
5211             MirrorConfigurationDone = TRUE;
5212 
5213             /* store the mirror configuration data */
5214             MirrorCfgBackup.MirroringMode = MirrorConfigurationPtr->MirroringMode;
5215             MirrorCfgBackup.VlanId = MirrorConfigurationPtr->VlanId;
5216             MirrorCfgBackup.CapturePortIdx = MirrorConfigurationPtr->CapturePortIdx;
5217             MirrorCfgBackup.TrafficDirectionIngressBitMask = MirrorConfigurationPtr->TrafficDirectionIngressBitMask;
5218         }
5219     }
5220 
5221     return Status;
5222 }
5223 
5224 /*FUNCTION**********************************************************************
5225  *
5226  * Function Name : Netc_EthSwt_Ip_ReadMirrorConfiguration
5227  * Description   : External function for obtaining the mirror configuration of the given Ethernet switch..
5228  * implements Netc_EthSwt_Ip_ReadMirrorConfiguration_Activity
5229  *END**************************************************************************/
Netc_EthSwt_Ip_ReadMirrorConfiguration(uint8 MirroredSwitchIdx,Netc_EthSwt_Ip_SwitchMirrorCfgType * MirrorConfigurationPtr)5230 Std_ReturnType Netc_EthSwt_Ip_ReadMirrorConfiguration( uint8 MirroredSwitchIdx, Netc_EthSwt_Ip_SwitchMirrorCfgType* MirrorConfigurationPtr )
5231 {
5232     Std_ReturnType Status = E_OK;
5233     uint8 MacByteIdx;
5234 
5235 #if(NETC_ETHSWT_IP_DEV_ERROR_DETECT == STD_ON)
5236     DevAssert(MirroredSwitchIdx < FEATURE_NETC_ETHSWT_IP_NUMBER_OF_SWTS);
5237     DevAssert(MirrorConfigurationPtr != NULL_PTR);
5238 #endif
5239 
5240     if (TRUE == MirrorConfigurationDone)    /* The mirror configuration is in place */
5241     {
5242         for (MacByteIdx = 0U; MacByteIdx < NETC_ETHSWT_IP_MACADDRLEN; MacByteIdx++)
5243         {
5244             MirrorConfigurationPtr->SrcMacAddrFilter[MacByteIdx] = MirrorCfgBackup.SrcMacAddrFilter[MacByteIdx];
5245             MirrorConfigurationPtr->DstMacAddrFilter[MacByteIdx] = MirrorCfgBackup.DstMacAddrFilter[MacByteIdx];
5246         }
5247         MirrorConfigurationPtr->VlanIdFilter = MirrorCfgBackup.VlanIdFilter;
5248         MirrorConfigurationPtr->MirroringMode = MirrorCfgBackup.MirroringMode;
5249         MirrorConfigurationPtr->VlanId = MirrorCfgBackup.VlanId;
5250         MirrorConfigurationPtr->CapturePortIdx = MirrorCfgBackup.CapturePortIdx;
5251         MirrorConfigurationPtr->TrafficDirectionIngressBitMask = MirrorCfgBackup.TrafficDirectionIngressBitMask;
5252     }
5253     else        /* no mirror configuration exists */
5254     {
5255         for (MacByteIdx = 0U; MacByteIdx < NETC_ETHSWT_IP_MACADDRLEN; MacByteIdx++)
5256         {
5257             MirrorConfigurationPtr->SrcMacAddrFilter[MacByteIdx] = 0x0U;
5258             MirrorConfigurationPtr->DstMacAddrFilter[MacByteIdx] = 0x0U;
5259         }
5260         MirrorConfigurationPtr->VlanIdFilter = 0xFFFFU;
5261         MirrorConfigurationPtr->MirroringMode = NETC_ETHSWT_NO_VLAN_RETAGGING;
5262         MirrorConfigurationPtr->VlanId = 0xFFFFU;
5263         MirrorConfigurationPtr->CapturePortIdx = 0U;
5264         MirrorConfigurationPtr->TrafficDirectionIngressBitMask = 0x0UL;
5265     }
5266 
5267     return Status;
5268 }
5269 
5270 #define ETHSWT_43_NETC_STOP_SEC_CODE
5271 #include "EthSwt_43_NETC_MemMap.h"
5272 
5273 #ifdef __cplusplus
5274 }
5275 #endif
5276 
5277 /** @} */
5278