1 /*
2 * Copyright 2021-2022 NXP
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #ifndef FSL_NETC_ENETC_H_
8 #define FSL_NETC_ENETC_H_
9
10 #include "fsl_netc.h"
11
12 /*******************************************************************************
13 * Definitions
14 ******************************************************************************/
15
16 #if defined(__cplusplus)
17 extern "C" {
18 #endif
19
20 /*******************************************************************************
21 * API
22 ******************************************************************************/
23
24 #if !(defined(__GNUC__) || defined(__ICCARM__))
25 #pragma region netc_hw_enetc
26 #endif
27 /*! @addtogroup netc_hw_enetc
28 * @{
29 */
30
31 /*!
32 * @brief ENETC capability.
33 *
34 */
35 typedef struct _netc_enetc_cap
36 {
37 bool funcSafety : 1; /*!< Support for safety capability. */
38 bool wol : 1; /*!< Support for Wake-on-LAN in low-power mode. */
39 bool rss : 1; /*!< Support for RSS. */
40 bool tsd : 1; /*!< Support for time specific departure. */
41 bool rfs : 1; /*!< Support for RFS. */
42 uint32_t ipvNum : 5; /*!< IPV number. */
43 uint32_t vsiNum : 4; /*!< VSI number. */
44 uint32_t msixNum : 11; /*!< MSIX table vector/entry number. */
45 uint32_t tcsNum : 4; /*!< Traffic class number. */
46 uint16_t uchNum; /*!< Unicast hash entry number. */
47 uint16_t mchNum; /*!< Multicast hash entry number. */
48 uint16_t rxBdrNum; /*!< Rx BD ring number. */
49 uint16_t txBdrNum; /*!< Tx BD ring number. */
50 } netc_enetc_cap_t;
51
52 /*!
53 * @brief Check whether ENETC has switch management capability
54 *
55 * @param base NETC peripheral base address.
56 * @return true or false
57 */
NETC_EnetcHasManagement(NETC_ENETC_Type * base)58 static inline bool NETC_EnetcHasManagement(NETC_ENETC_Type *base)
59 {
60 return ((base->SMCAPR & NETC_ENETC_SMCAPR_SM_MASK) != 0U);
61 }
62
63 /*!
64 * @brief Get ENETC capability
65 *
66 * @param base NETC peripheral base address.
67 * @param capability Pointer to capability structure.
68 */
69 void NETC_EnetcGetCapability(NETC_ENETC_Type *base, netc_enetc_cap_t *capability);
70
71 /*!
72 * @brief Set MAC address for specified VSI of ENETC
73 *
74 * @param base
75 * @param macAddr
76 */
77 void NETC_EnetcSetSIMacAddr(NETC_ENETC_Type *base, uint8_t si, uint8_t *macAddr);
78
79 /*!
80 * @brief Configure SI
81 *
82 * @param base ENETC peripheral base address.
83 * @param si The SI number
84 * @param psConfig The SI configuration
85 * @return status_t
86 */
87 status_t NETC_EnetcConfigureSI(NETC_ENETC_Type *base, uint8_t si, const netc_hw_enetc_si_config_t *psConfig);
88
89 /*!
90 * @brief Set SI MSIX table entry number
91 *
92 * @param base ENETC peripheral base address.
93 * @param si The SI number.
94 * @param msixNum The MSIX table entry number.
95 * @return status_t
96 */
97 status_t NETC_EnetcSetMsixEntryNum(NETC_ENETC_Type *base, uint8_t si, uint32_t msixNum);
98
99 /*!
100 * @brief Enable/Disable specified SI
101 *
102 * @param base ENETC peripheral base address.
103 * @param si SI index.
104 * @param enable Enable/Disable SI from ENETC layer.
105 */
NETC_EnetcEnableSI(NETC_ENETC_Type * base,uint8_t si,bool enable)106 static inline void NETC_EnetcEnableSI(NETC_ENETC_Type *base, uint8_t si, bool enable)
107 {
108 /* Enable SI from ENETC block, need to set SI block together to enable SI completely. */
109 if (enable)
110 {
111 base->PMR |= (NETC_ENETC_PMR_SI0EN_MASK << si);
112 }
113 else
114 {
115 base->PMR &= ~(NETC_ENETC_PMR_SI0EN_MASK << si);
116 }
117 }
118
119 /*!
120 * @brief Get ENETC discard statistic data
121 *
122 * @param base ENETC peripheral base address.
123 * @param statistic Statistic data.
124 */
125 void NETC_EnetcGetPortDiscardStatistic(NETC_ENETC_Type *base, netc_enetc_port_discard_statistic_t *statistic);
126
127 /*!
128 * @brief Enable MAC promiscuous mode
129 *
130 * @param base ENETC peripheral base address.
131 * @param si SI index.
132 * @param enableUCPromis Enable unicast frame promiscuous.
133 * @param enableMCPromis Enable multicast frame promiscuous.
134 */
135 void NETC_EnetcEnablePromiscuous(NETC_ENETC_Type *base, uint8_t si, bool enableUCPromis, bool enableMCPromis);
136
137 /*!
138 * @brief Configure VLAN filter
139 *
140 * @param base ENETC peripheral base address.
141 * @param si SI index.
142 * @param config Enable untagged VLAN frame promiscuous.
143 */
144 void NETC_EnetcConfigureVlanFilter(NETC_ENETC_Type *base, uint8_t si, netc_si_l2vf_config_t *config);
145
146 /*!
147 * @brief Add the hash filter for the MAC address
148 *
149 * Hardware layer will not maitain the counter of the hash filter. API layer shall cover this requirement.
150 *
151 * @param base ENETC peripheral base address.
152 * @param si SI index.
153 * @param type Unicast or multicast frame type.
154 * @param hashIndex The calculated hash index of MAC address.
155 */
156 void NETC_EnetcAddMacAddrHash(NETC_ENETC_Type *base, uint8_t si, netc_packet_type_t type, uint8_t hashIndex);
157
158 /*!
159 * @brief Remove the hash filter for the MAC address
160 *
161 * @param base ENETC peripheral base address.
162 * @param si SI index.
163 * @param type Unicast or multicast frame type.
164 * @param hashIndex The calculated hash index of MAC address.
165 */
166 void NETC_EnetcDelMacAddrHash(NETC_ENETC_Type *base, uint8_t si, netc_packet_type_t type, uint8_t hashIndex);
167
168 /*!
169 * @brief Add the hash filter for the VLAN
170 *
171 * @param base ENETC peripheral base address.
172 * @param si SI index.
173 * @param hashIndex The calculated hash index of MAC address.
174 */
175 void NETC_EnetcAddVlanHash(NETC_ENETC_Type *base, uint8_t si, uint8_t hashIndex);
176
177 /*!
178 * @brief Remove the hash filter for the VLAN
179 *
180 * @param base ENETC peripheral base address.
181 * @param si SI index.
182 * @param hashIndex The calculated hash index of MAC address.
183 */
184 void NETC_EnetcDelVlanHash(NETC_ENETC_Type *base, uint8_t si, uint8_t hashIndex);
185
186 /*!
187 * @brief Enable / Disable ENETC Port Time Specific Departure (TSD) feature
188 *
189 * It can't work with QBV CBS
190 *
191 * @param base
192 * @param tcIdx
193 * @param isEnable
194 * @return status_t
195 */
NETC_EnetcPortEnableTSD(NETC_ENETC_Type * base,netc_hw_tc_idx_t tcIdx,bool isEnable)196 static inline status_t NETC_EnetcPortEnableTSD(NETC_ENETC_Type *base, netc_hw_tc_idx_t tcIdx, bool isEnable)
197 {
198 base->PTCTSDR[tcIdx] = NETC_ENETC_PTCTSDR_TSDE(isEnable);
199 return kStatus_Success;
200 }
201
202 /*!
203 * @brief Set ENETC Rx native outer/inner VLAN
204 *
205 * It is used for classification when untagged frames are received by the port.
206 *
207 * @param base
208 * @param config
209 * @param isOunter
210 */
NETC_EnetcPortSetNativeVLAN(NETC_ENETC_Type * base,const netc_enetc_native_vlan_config_t * config,bool isOuter)211 static inline void NETC_EnetcPortSetNativeVLAN(NETC_ENETC_Type *base,
212 const netc_enetc_native_vlan_config_t *config,
213 bool isOuter)
214 {
215 if (isOuter)
216 {
217 base->PONVLANR = NETC_ENETC_PONVLANR_VZE(config->enUnderZeroVid) |
218 NETC_ENETC_PONVLANR_PNE(config->enUnderNoVlan) |
219 NETC_ENETC_PONVLANR_TPID(config->vlanTag.tpid) | NETC_ENETC_PONVLANR_PCP(config->vlanTag.pcp) |
220 NETC_ENETC_PONVLANR_DEI(config->vlanTag.dei) | NETC_ENETC_PONVLANR_VID(config->vlanTag.vid);
221 }
222 else
223 {
224 base->PINVLANR = NETC_ENETC_PINVLANR_VZE(config->enUnderZeroVid) |
225 NETC_ENETC_PINVLANR_PNE(config->enUnderNoVlan) |
226 NETC_ENETC_PINVLANR_TPID(config->vlanTag.tpid) | NETC_ENETC_PINVLANR_PCP(config->vlanTag.pcp) |
227 NETC_ENETC_PINVLANR_DEI(config->vlanTag.dei) | NETC_ENETC_PINVLANR_VID(config->vlanTag.vid);
228 }
229 }
230
231 /*!
232 * @brief Set ENETC Parser configuration
233 *
234 * PARCSCR and PARCE0CR - PARCE3CR.
235 *
236 * @param base
237 * @param config
238 */
NETC_EnetcSetParser(NETC_ENETC_Type * base,const netc_enetc_parser_config_t * config)239 static inline void NETC_EnetcSetParser(NETC_ENETC_Type *base, const netc_enetc_parser_config_t *config)
240 {
241 base->PARCSCR = NETC_ENETC_PARCSCR_L3CD(config->disL3Checksum) | NETC_ENETC_PARCSCR_L4CD(config->disL4Checksum);
242 for (uint8_t i = 0u; i < 4U; i++)
243 {
244 base->PARCECR[i] = NETC_ENETC_PARCECR_ETYPE(config->custEtype[i].etype) |
245 NETC_ENETC_PARCECR_EN(config->custEtype[i].en) |
246 NETC_ENETC_PARCECR_CP(config->custEtype[i].cp);
247 }
248 }
249
250 /*!
251 * @brief Enable / Disable ENETC Wake-on-LAN mode
252 *
253 * Only available on ENETC 0
254 *
255 * @param base
256 * @param isEnable
257 * @return status_t
258 */
NETC_EnetcEnableWakeOnLan(NETC_ENETC_Type * base,bool isEnable)259 static inline void NETC_EnetcEnableWakeOnLan(NETC_ENETC_Type *base, bool isEnable)
260 {
261 if (0U != (base->ECAPR0 & NETC_ENETC_ECAPR0_WO_MASK))
262 {
263 base->PLPMR = NETC_ENETC_PLPMR_WME(isEnable);
264 }
265 }
266 /*! @} */ // end of netc_hw_enetc
267 #if !(defined(__GNUC__) || defined(__ICCARM__))
268 #pragma endregion netc_hw_enetc
269 #endif
270
271 #if defined(__cplusplus)
272 }
273 #endif
274 #endif /* FSL_NETC_ENETC_H_ */
275