1 /*
2  * Copyright 2023 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef FSL_NETC_IERB_H_
8 #define FSL_NETC_IERB_H_
9 
10 #include "fsl_netc.h"
11 
12 /*!
13  * @brief Software reset NETC module
14  * Software should follow these steps when initiating a soft reset to avoid hanging any outstanding transactions in the system.
15  * - Software disables MAC receive function(s).
16  * - Software sets the soft reset bit NETCRR[SR]=1.
17  *   + NETC stops further prefetching of BDs
18  *   + NETC stops scheduling transmit frames
19  * - Software waits for NETC to complete any in-flight transmit frames processing.
20  *   + If there is use of time gating or credit based shaping, worst case wait time is SaTGSLR/EaTGSLR[MIN_LOOKAHEAD] +
21  *     PTGSATOR[ADV_TIME_OFFSET] + Transmit(MAX_SDU) + Writeback BD.
22  *   + If there is no use of time gating or credit based shaping, worst case wait time is Transmit(MAX_SDU) + Writeback BD.
23  * - Software waits for either:
24  *   + 100 ms (as per PCIe specification).
25  *   + Shortest possible reset time as defined by IERB register NETCFLRCR.
26  *   + NETCSR[SR] bit to clear by polling.
27  * - Software reconfigures NETC.
28  */
29 void NETC_SoftReset(void);
30 
31 /*!
32  * @brief Check NETC software reset over status
33  *
34  * @return bool  True: Software reset is over, False: Software reset is not over.
35  */
NETC_SoftResetIsOver(void)36 static inline bool NETC_SoftResetIsOver(void)
37 {
38     return ((NETC_PRIV->NETCRR & NETC_PRIV_NETCRR_SR_MASK) == 0U);
39 }
40 
41 /*!
42  * @brief Lock NETC IERB access
43  * @note Can't access IERB register after locking.
44  *
45  * @return status_t
46  */
47 status_t NETC_IERBLock(void);
48 
49 /*!
50  * @brief Check NETC IERB lock complete status.
51  *
52  * @return bool  True: IERB lock is over, False: IERB lock is not over.
53  */
NETC_IERBIsLockOver(void)54 static inline bool NETC_IERBIsLockOver(void)
55 {
56     return ((NETC_PRIV->NETCSR & NETC_PRIV_NETCSR_STATE_MASK) == 0U);
57 }
58 
59 /*!
60  * @brief Check NETC IERB lock error status
61  *
62  * @return bool  True: IERB lock is over, False: IERB lock is not over.
63  */
NETC_IERBIsLockErr(void)64 static inline bool NETC_IERBIsLockErr(void)
65 {
66     return ((NETC_PRIV->NETCSR & NETC_PRIV_NETCSR_ERROR_MASK) != 0U);
67 }
68 
69 /*!
70  * @brief Unlock NETC IERB
71  *
72  * @return status_t
73  */
74 status_t NETC_IERBUnlock(void);
75 
76 /*!
77  * @brief Check NETC IERB unlock complete status.
78  *
79  * @return bool  True: IERB lock is over, False: IERB lock is not over.
80  */
NETC_IERBIsUnlockOver(void)81 static inline bool NETC_IERBIsUnlockOver(void)
82 {
83     return ((NETC_PRIV->NETCRR & NETC_PRIV_NETCRR_LOCK_MASK) == 0U);
84 }
85 
86 #endif /* FSL_NETC_IERB_H_ */
87