1 /*
2  * Copyright 2021-2024 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef FSL_NETC_ENDPOINT_H_
8 #define FSL_NETC_ENDPOINT_H_
9 
10 #include "fsl_netc.h"
11 #include "fsl_netc_soc.h"
12 #include "netc_hw/fsl_netc_hw.h"
13 #include "netc_hw/fsl_netc_hw_enetc.h"
14 #include "netc_hw/fsl_netc_hw_port.h"
15 #include "netc_hw/fsl_netc_hw_si.h"
16 
17 #if !(defined(__GNUC__) || defined(__ICCARM__))
18 #pragma region api_ep
19 #endif
20 //////////////////////////////////////
21 // Group for the End Point Driver
22 //////////////////////////////////////
23 /*!
24  * @defgroup netc_ep NETC Endpoint (EP) Driver
25  * @details API / Data structure for using NETC driver and endpoint.
26  * This group handles endpoint devices covering the features to Initialize/De-Initialize the endpoint, transfer
27  * packets, configure the port/links, and get the status and statistic. Note that it doesn't cover the phy configuration
28  * which shall be configured in MDIO module for both external real PHY and internal virtual PHY.
29  *
30  * The endpoint API mainly relates to the ENETC IP which interfaces the host to the MAC or Pseudo-MAC (Switch).
31  *
32  * APIs in this group take the ep_handle_t as first parameter to retrieve the current context.
33  * User shall not manipulate the members of the handle without invoking the provided APIs or help macros as it may
34  * break the driver state.
35  *
36  * All API in this groups start with `EP_` and data structure specific to endpoint start with `ep_`.
37  *
38  * @ingroup netc_api
39  */
40 
41 /*!
42  * @defgroup netc_ep_config Endpoint (EP) Generic Configuration
43  * @details Generic Ethernet endpoint configuration
44  * MAC, host interface and driver configuration.
45  * @ingroup netc_ep
46  */
47 /*!
48  * @defgroup netc_ep_ntmp Endpoint (EP) Table Management Module
49  * @details Generic Table Management related functionalities
50  * @ingroup netc_ep
51  */
52 /*!
53  * @defgroup netc_ep_stat Endpoint (EP) Statistic Module
54  * @details Statistics counters
55  * @ingroup netc_ep
56  */
57 /*!
58  * @defgroup netc_ep_interrupt Endpoint (EP) Interrupt Module
59  * @details Interrupt related functionalities
60  *
61  * @ingroup netc_ep
62  */
63 /*!
64  * @defgroup netc_ep_xfer Endpoint (EP) Transmit/Receive
65  * @details Data interface for transmit and receive
66  *
67  * @ingroup netc_ep
68  */
69 /*!
70  * @defgroup netc_ep_psi_vsi_msg Endpoint (EP) PSI/VSI
71  * @details PSI/VSI related functionalities
72  *
73  * @ingroup netc_ep
74  */
75 /*!
76  * @defgroup netc_ep_datapath Endpoint (EP) data path
77  * @details QoS, classification and filtering functionalities
78  * @ingroup netc_ep
79  */
80 /*!
81  * @defgroup netc_ep_tx Endpoint (EP) Egress data path configuration
82  * @details API/Data structure for configuration of the endpoint ingress datapath
83  * This module includes steps below in sequence and APIs are placed following this sequence for user to identify easily
84  * - Schedule: Credit Based Shaper also referred as IEEE 802.1 Qav
85  * - Schedule: Time Specific Departure
86  * - Schedule: Time Gate Scheduling referred as IEEE 802.1 Qbv
87  * - VLAN Insert
88  *
89  * API in this group starts with `EP_Tx`.
90  *
91  * @ingroup netc_ep_datapath
92  */
93 /*!
94  * @defgroup netc_ep_rx Endpoint (EP) Ingress data path configuration
95  * @details API/Data structure for configuration of the endpoint ingress datapath.
96  * This module includes steps below in sequence and APIs are placed following this sequence for user to identify easily
97  * - Parser
98  * - VLAN Classification
99  * - Ingress QoS Classification
100  * - Ingress Port Filtering
101  * - Stream Identification and Filtering
102  * - L2 Filtering: VLAN/MAC Address
103  * - Policying: Rate Policing and Stream Gating
104  * - Enqueue (Ingress Congestion Management ICM)
105  * - HTA (Host Transfer Agent Rx)
106  *
107  * API in this group starts with `EP_Rx`.
108  *
109  * @ingroup netc_ep_datapath
110  */
111 
112 #if !(defined(__GNUC__) || defined(__ICCARM__))
113 #pragma endregion api_ep
114 #endif
115 
116 /*******************************************************************************
117  * Definitions
118  ******************************************************************************/
119 
120 #if !(defined(__GNUC__) || defined(__ICCARM__))
121 #pragma region netc_ep_stat
122 #endif
123 /*! @addtogroup netc_ep_stat
124  * @{
125  */
126 
127 /*! @brief Status/interrupt detect flags merged to same set of enum. TODO SITMRIDR */
128 typedef enum _ep_flags
129 {
130     kNETC_EPTimerSyncedFlag     = 0x1,
131     kNETC_EPICMBlockedFlag      = 0x1 << 1,
132     kNETC_EPWakeOnLANActiveFlag = 0x1 << 2,
133 
134 } ep_flags_t;
135 
136 /*! @} */ // end of netc_ep_stat
137 #if !(defined(__GNUC__) || defined(__ICCARM__))
138 #pragma endregion netc_ep_stat
139 #endif
140 
141 #if !(defined(__GNUC__) || defined(__ICCARM__))
142 #pragma region netc_ep_interrupt
143 #endif
144 /*! @addtogroup netc_ep_interrupt
145  * @{
146  */
147 
148 /*!
149  * @brief Interrupt enable/disable flags.
150  *
151  * The value of the enumerator is not necessary match the bit in register. All interrupts in Endpoint are
152  * merged into this enum except the BDR specific interrupt.
153  * TODO SITMRIER
154  */
155 typedef enum _ep_interrupt_flag
156 {
157     kNETC_EPPSIResetInterruptEnable = 0x1,
158     kNETC_EPPSIMsgRxInterruptEnable = 0x1 << 1U,
159 } ep_interrupt_flag_t;
160 
161 /*! @} */ // end of netc_ep_interrupt
162 #if !(defined(__GNUC__) || defined(__ICCARM__))
163 #pragma endregion netc_ep_interrupt
164 #endif
165 
166 #if !(defined(__GNUC__) || defined(__ICCARM__))
167 #pragma region netc_ep_xfer
168 #endif
169 /*! @addtogroup netc_ep_xfer
170  * @{
171  */
172 
173 typedef enum _ep_rx_flags
174 {
175     kEP_RX_RSS_VALID       = 0x1,       /*!< Request timestamp. */
176     kEP_RX_VLAN_VALID      = 0x1 << 1U, /*!< Specifiy frame departure time. */
177     kEP_RX_TIMESTAMP_VALID = 0x1 << 2U, /*!< Enable port masquerading. */
178 } ep_rx_flags_t;
179 
180 typedef enum _ep_tx_opt_flags
181 {
182     kEP_TX_OPT_REQ_TS      = 0x1U, /*!< Request timestamp (IEEE 1588 PTP two-step timestamp). */
183     kEP_TX_OPT_VLAN_INSERT = 0x2U, /*!< Enable VLAN insert. */
184     kEP_TX_OPT_START_TIME  = 0x4U, /*!< Specifiy frame departure time. */
185 #if !(defined(FSL_FEATURE_NETC_HAS_ERRATA_051255) && FSL_FEATURE_NETC_HAS_ERRATA_051255)
186     kEP_TX_OPT_REQ_ONE_STEP_TS = 0x8U, /*!< Request IEEE 1588 PTP one-step timestamp offload. */
187 #endif
188 } ep_tx_opt_flags;
189 
190 typedef struct _ep_tx_opt
191 {
192     uint32_t flags;             /*!< A bitmask of ep_tx_opt_flags */
193     uint32_t timestamp;         /*!< Departure timestamp, used if kEP_TX_OPT_START_TIME is set */
194     netc_enetc_vlan_tag_t vlan; /*!< VLAN tag which will be inserted, used if kEP_TX_OPT_VLAN_INSERT is set */
195 } ep_tx_opt;
196 
197 /*! @} */ // end of netc_ep_xfer
198 #if !(defined(__GNUC__) || defined(__ICCARM__))
199 #pragma endregion netc_ep_xfer
200 #endif
201 
202 #if !(defined(__GNUC__) || defined(__ICCARM__))
203 #pragma region netc_ep_datapath
204 #endif
205 /*! @addtogroup netc_ep_datapath
206  * @{
207  */
208 /*! @brief Port Ingress Filter config */
209 typedef struct _netc_ep_ipf_config
210 {
211     netc_ipf_config_t dosCfg;          /*!< Configuration for L2/3 DOS. */
212     netc_port_ipf_config_t portConfig; /*!< Configuration for port connected to enetc peripheral. */
213 } netc_ep_ipf_config_t;
214 
215 /*! @brief PSFP config */
216 typedef struct _netc_ep_psfp_config
217 {
218     netc_isi_kc_rule_t kcRule[2];
219     netc_port_psfp_isi_config isiPortConfig;
220 } netc_ep_psfp_config_t;
221 
222 /*! @} */ // end of netc_ep_datapath
223 #if !(defined(__GNUC__) || defined(__ICCARM__))
224 #pragma endregion netc_ep_datapath
225 #endif
226 
227 #if !(defined(__GNUC__) || defined(__ICCARM__))
228 #pragma region netc_ep_config
229 #endif
230 /*! @addtogroup netc_ep_config
231  * @{
232  */
233 
234 /*! @brief Endpoint handle. */
235 typedef struct _ep_handle ep_handle_t;
236 
237 /*! @brief Callback for reclaimed tx frames. */
238 typedef status_t (*ep_reclaim_cb_t)(ep_handle_t *handle, uint8_t ring, netc_tx_frame_info_t *frameInfo, void *userData);
239 
240 /*! @brief Defines the EP Rx memory buffer alloc function pointer. */
241 typedef void *(*ep_rx_alloc_cb_t)(ep_handle_t *handle, uint8_t ring, uint32_t length, void *userData);
242 
243 /*! @brief Defines the EP Rx memory buffer free function pointer. */
244 typedef void (*ep_rx_free_cb_t)(ep_handle_t *handle, uint8_t ring, void *address, void *userData);
245 
246 /*! @brief Callback for getting link status */
247 typedef status_t (*ep_get_link_status_cb_t)(ep_handle_t *handle, uint8_t *link);
248 
249 /*! @brief Callback for getting link speed */
250 typedef status_t (*ep_get_link_speed_cb_t)(ep_handle_t *handle, netc_hw_mii_speed_t *speed, netc_hw_mii_duplex_t *duplex);
251 
252 /*! @brief Configuration for the endpoint handle. */
253 typedef struct _ep_config
254 {
255     netc_hw_si_idx_t si;                /*!< Station interface index. */
256     netc_hw_enetc_si_config_t siConfig; /*!< Station interface configuration. */
257     uint8_t txPrioToTC[8]; /*!< Tx BD ring priority to Tx traffic class queue index mapping, range in TC0 ~ TC7. */
258     netc_port_tx_tc_config_t txTcCfg[8]; /*!< Tx traffic class related configuration, vaild only on ENETC 0. */
259     netc_ep_psfp_config_t psfpCfg;       /*!< PSFP configuration,cover the ISI key construction profile and port ingress
260                                             stream identification configuration. */
261     bool enOuterAsInner;                 /*!< Enable use outer VLAN tag as the inner tag if only one tag is found. */
262     netc_enetc_native_vlan_config_t rxOuterVLANCfg; /*!< Port outer native VLAN config. */
263     netc_enetc_native_vlan_config_t rxInnerVLANCfg; /*!< Port inner native VLAN config. */
264     netc_enetc_parser_config_t parserCfg;           /*!< ENETC parser configuration. */
265     uint32_t pauseOnThr;  /*!< ENETC Port pause ON threshold value, value 0 means disables pause generation. */
266     uint32_t pauseOffThr; /*!< ENETC Port pause OFF threshold value, value 0 means disables pause generation. */
267     struct
268     {
269         netc_port_ethmac_t ethMac; /*!< Ethernet MAC configuration. */
270         netc_port_common_t common; /*!< Port common configuration. */
271         bool enableTg;             /*!< Enable port time gate scheduling. */
272         bool enPseudoMacTxPad; /*!< Enable pseudo MAC Port Transmit Padding, will pad the frame to a minimum of 60 bytes
273                                   and append 4 octets of FCS. */
274     } port;
275     netc_msix_entry_t *msixEntry;       /*!< MSIX table entry array. */
276     uint8_t entryNum;                   /*!< MSIX entry number. */
277     uint8_t cmdBdEntryIdx;              /*!< MSIX entry index of command BD ring interrupt. */
278     uint8_t siComEntryIdx;              /*!< MSIX entry index of PSI-VSI communication interrupt. */
279     uint8_t timerSyncEntryIdx;          /*!< MSIX entry index of timer synchronous state change interrupt. */
280     ep_reclaim_cb_t reclaimCallback;    /*!< Callback for reclaimed Tx frames. */
281     void *userData;                     /*!< User data, return in callback. */
282     bool rxCacheMaintain;               /*!< Enable/Disable Rx buffer cache maintain in driver. */
283     bool txCacheMaintain;               /*!< Enable/Disable Tx buffer cache maintain in driver. */
284     bool rxZeroCopy;                    /*!< Enable/Disable zero-copy receive mode. */
285     ep_rx_alloc_cb_t rxBuffAlloc;       /*!< Callback function to alloc memory, must be provided for zero-copy Rx. */
286     ep_rx_free_cb_t rxBuffFree;         /*!< Callback function to free memory, must be provided for zero-copy Rx. */
287     netc_cmd_bdr_config_t cmdBdrConfig; /*!< Command BD ring configuration. */
288 } ep_config_t;
289 
290 /*! @brief Configuration constant in handle. */
291 typedef struct _ep_config_const
292 {
293     netc_hw_si_idx_t si;    /*!< Station interface index. */
294     uint32_t rxRingUse : 7; /*!< Number of Rx Rings to be used, when enable Rx ring group, this equal to the sum of all
295                           Rx group rings. */
296     uint32_t txRingUse : 7; /*!< Number of Tx Rings to be used, note that when SI is Switch management ENETC SI, the
297                           number not include Tx ring 0. */
298     uint32_t rxBdrGroupNum : 2;      /*!< Rx BD ring group number, range in 0 ~ 2. */
299     uint32_t ringPerBdrGroup : 3;    /*!< The ring number in every Rx BD ring group, range in 1 ~ 8, active when
300                                        rxBdrGroupNum not equal zero. */
301     bool rxCacheMaintain : 1;        /*!< Enable/Disable Rx buffer cache maintain in driver. */
302     bool txCacheMaintain : 1;        /*!< Enable/Disable Tx buffer cache maintain in driver. */
303     bool rxZeroCopy : 1;             /*!< Enable/Disable zero-copy receive mode. */
304     uint8_t entryNum;                /*!< MSIX entry number. */
305     ep_reclaim_cb_t reclaimCallback; /*!< Callback for reclaimed Tx frames. */
306     void *userData;                  /*!< User data, return in callback. */
307     ep_rx_alloc_cb_t rxBuffAlloc;    /*!< Callback function to alloc memory, must be provided for zero-copy Rx. */
308     ep_rx_free_cb_t rxBuffFree;      /*!< Callback function to free memory, must be provided for zero-copy Rx. */
309 } ep_config_const_t;
310 
311 /*! @brief Handle for the endpoint
312  * Private internal data.
313  */
314 struct _ep_handle
315 {
316     netc_enetc_hw_t hw;                                       /*!< Hardware register map resource. */
317     netc_enetc_cap_t capability;                              /*!< ENETC capability. */
318     ep_config_const_t cfg;                                    /*!< Endpoint configuration constant. */
319     netc_rx_bdr_t rxBdRing[FSL_FEATURE_NETC_SI_RING_NUM_MAX]; /*!< Receive buffer descriptor ring. */
320     netc_tx_bdr_t txBdRing[FSL_FEATURE_NETC_SI_RING_NUM_MAX]; /*!< Transmit buffer descriptor ring. */
321     netc_cmd_bdr_t cmdBdRing;                                 /*!< Command BD ring handle for endpoint. */
322     uint8_t unicastHashCount[64];                             /*!< Unicast hash index collisions counter. */
323     uint8_t multicastHashCount[64];                           /*!< Multicast hash index collisions counter. */
324     uint8_t vlanHashCount[64];                                /*!< VLAN hash index collisions counter. */
325     uint8_t macFilterCount[64];                               /*!< mac address filter index collisions counter. */
326     uint8_t vlanFilterCount[64];                              /*!< vlan address filter index collisions counter. */
327     ep_get_link_status_cb_t getLinkStatus;                    /*!< Callback to get link status */
328     ep_get_link_speed_cb_t getLinkSpeed;                      /*!< Callback to get link speed */
329     uint16_t vsiBitMapNotifyLinkStatus;                       /*!< VSI bit map for link status notify */
330     uint16_t vsiBitMapNotifyLinkSpeed;                        /*!< VSI bit map for link speed notify */
331 };
332 
333 /*! @} */ // end of netc_ep_config
334 #if !(defined(__GNUC__) || defined(__ICCARM__))
335 #pragma endregion netc_ep_config
336 #endif
337 
338 #if defined(__cplusplus)
339 extern "C" {
340 #endif
341 
342 /*******************************************************************************
343  * API
344  ******************************************************************************/
345 
346 #if !(defined(__GNUC__) || defined(__ICCARM__))
347 #pragma region netc_ep_config
348 #endif
349 /*! @addtogroup netc_ep_config
350  * @{
351  */
352 
353 /*!
354  * @brief Initialize the endpoint with specified station interface
355  *
356  * Each station interface needs to call this API. In the case of a virtual station interface
357  * it's necessary that the physical station interface has been initialized beforehand.
358  *
359  * @param handle
360  * @param macAddr Primary MAC address
361  * @param config The user configuration
362  * @param bdrConfig Array of buffer configurations (for each queue/ring)
363  * @return status_t
364  */
365 status_t EP_Init(ep_handle_t *handle, uint8_t *macAddr, const ep_config_t *config, const netc_bdr_config_t *bdrConfig);
366 
367 /*!
368  * @brief De-initialize the endpoint.
369  *
370  * @param handle
371  * @return status_t
372  */
373 status_t EP_Deinit(ep_handle_t *handle);
374 
375 /*!
376  * @brief Get the default configuration.
377  *
378  * @param config
379  * @return status_t
380  */
381 status_t EP_GetDefaultConfig(ep_config_t *config);
382 
383 /*!
384  * @brief Enable MAC transmission/reception
385  * To be called when the PHY link is up.
386  *
387  * @param handle
388  * @param speed
389  * @param duplex
390  * @return status_t
391  */
392 status_t EP_Up(ep_handle_t *handle, netc_hw_mii_speed_t speed, netc_hw_mii_duplex_t duplex);
393 
394 /*!
395  * @brief Disable MAC transmission/reception
396  * To be called when the PHY link is down.
397  * @note Must ensure all active Tx rings finish current transmission before call this API.
398  *
399  * @param handle
400  * @return status_t
401  */
402 status_t EP_Down(ep_handle_t *handle);
403 
404 /*!
405  * @brief Set the Primary MAC address.
406  *
407  * @param handle
408  * @param macAddr
409  * @return status_t
410  */
411 status_t EP_SetPrimaryMacAddr(ep_handle_t *handle, uint8_t *macAddr);
412 
413 /*!
414  * @brief Set EP port speed
415  *
416  * @param handle
417  * @param pSpeed
418  */
EP_SetPortSpeed(ep_handle_t * handle,uint16_t pSpeed)419 static inline void EP_SetPortSpeed(ep_handle_t *handle, uint16_t pSpeed)
420 {
421     NETC_PortSetSpeed(handle->hw.portGroup.port, pSpeed);
422 }
423 
424 /*! @} */ // end of netc_ep_config
425 #if !(defined(__GNUC__) || defined(__ICCARM__))
426 #pragma endregion netc_ep_config
427 #endif
428 
429 #if !(defined(__GNUC__) || defined(__ICCARM__))
430 #pragma region netc_ep_ntmp
431 #endif
432 /*! @addtogroup netc_ep_ntmp
433  * @{
434  */
435 
436 /*!
437  * @brief Initialize endpoint command BD ring
438  *
439  * @param handle
440  * @param config The command BD ring configuration
441  * @return status_t
442  */
443 status_t EP_CmdBDRInit(ep_handle_t *handle, const netc_cmd_bdr_config_t *config);
444 
445 /*!
446  * @brief Deinit endpoint command BD ring
447  *
448  * @param handle
449  * @return status_t
450  */
451 status_t EP_CmdBDRDeinit(ep_handle_t *handle);
452 
453 /*! @} */ // end of netc_ep_ntmp
454 #if !(defined(__GNUC__) || defined(__ICCARM__))
455 #pragma endregion netc_ep_ntmp
456 #endif
457 
458 #if !(defined(__GNUC__) || defined(__ICCARM__))
459 #pragma region netc_ep_rx
460 #endif
461 /*! @addtogroup netc_ep_rx
462  * @{
463  */
464 
465 #if !(defined(__GNUC__) || defined(__ICCARM__))
466 #pragma region Rx Parser
467 #endif
468 /*!
469  * @brief Configure Parser in Receive Data Path
470  *
471  * @param handle
472  * @param config
473  * @return status_t
474  */
EP_RxParserConfig(ep_handle_t * handle,netc_port_parser_config_t * config)475 static inline status_t EP_RxParserConfig(ep_handle_t *handle, netc_port_parser_config_t *config)
476 {
477     NETC_PortSetParser(handle->hw.portGroup.port, config);
478     return kStatus_Success;
479 }
480 #if !(defined(__GNUC__) || defined(__ICCARM__))
481 #pragma endregion Rx Parser
482 #endif
483 
484 #if !(defined(__GNUC__) || defined(__ICCARM__))
485 #pragma region Vlan classification
486 #endif
487 /*!
488  * @brief Configure the customer vlan type
489  *
490  * @param handle
491  * @param config
492  * @return status_t
493  */
EP_RxVlanCInit(ep_handle_t * handle,const netc_vlan_classify_config_t * config)494 static inline status_t EP_RxVlanCInit(ep_handle_t *handle, const netc_vlan_classify_config_t *config)
495 {
496     NETC_RxVlanCInit(handle->hw.common, config, false);
497     return kStatus_Success;
498 }
499 
500 /*!
501  * @brief Configure the Accepted Vlan.
502  * @param handle
503  * @param config
504  * @return status_t
505  */
EP_RxVlanCConfigPort(ep_handle_t * handle,netc_port_vlan_classify_config_t * config)506 static inline status_t EP_RxVlanCConfigPort(ep_handle_t *handle, netc_port_vlan_classify_config_t *config)
507 {
508     NETC_PortSetVlanClassify(handle->hw.portGroup.port, config);
509     return kStatus_Success;
510 }
511 
512 #if !(defined(__GNUC__) || defined(__ICCARM__))
513 #pragma endregion Vlan classification
514 #endif
515 
516 #if !(defined(__GNUC__) || defined(__ICCARM__))
517 #pragma region PSFP
518 #endif
519 /*!
520  * @brief Enable / Disable Ingress Port Filtering
521  *
522  * Applied for both Switch and ENETC
523  *
524  * @param handle
525  * @param config IPF general features
526  * @return status_t
527  */
528 status_t EP_RxIPFInit(ep_handle_t *handle, netc_ep_ipf_config_t *config);
529 
530 /*!
531  * @brief Get remaining available word number (words size is 6 bytes) of the ingress Port Filter Table.
532  * @note  This is a ternary match table, and the entries can vary in size, from 2 to 14 words.
533  *
534  * @param handle
535  * @return uint32_t
536  */
EP_RxIPFGetTableRemainWordNum(ep_handle_t * handle)537 static inline uint32_t EP_RxIPFGetTableRemainWordNum(ep_handle_t *handle)
538 {
539     return (handle->hw.common->IPFTCAPR & NETC_SW_ENETC_IPFTCAPR_NUM_WORDS_MASK) -
540            (handle->hw.common->IPFTMOR & NETC_SW_ENETC_IPFTMOR_NUM_WORDS_MASK);
541 }
542 
543 /*!
544  * @brief Add an entry for the ingress Port Filter Table.
545  *
546  * This function do an add & query with return hardware id which can be used as future query / delete / update.
547  *
548  * @param handle
549  * @param config  IPF instance configuaration
550  * @param entryID  The table entry ID read out
551  * @return status_t
552  * @return See @ref netc_cmd_error_t
553  */
554 status_t EP_RxIPFAddTableEntry(ep_handle_t *handle, netc_tb_ipf_config_t *config, uint32_t *entryID);
555 
556 /*!
557  * @brief Update entry in the ingress Port Filter Table.
558  *
559  * @param handle
560  * @param entryID
561  * @param cfg
562  * @return status_t
563  * @return See @ref netc_cmd_error_t
564  */
565 status_t EP_RxIPFUpdateTableEntry(ep_handle_t *handle, uint32_t entryID, netc_tb_ipf_cfge_t *cfg);
566 
567 /*!
568  * @brief Delete an entry for the ingress Port Filter Table.
569  *
570  * @param handle
571  * @param entryID  The table entry ID
572  * @return status_t
573  */
574 status_t EP_RxIPFDelTableEntry(ep_handle_t *handle, uint32_t entryID);
575 
576 /*!
577  * @brief Reset the counter of an ingress port filter entry
578  *
579  * @param handle
580  * @param entryID  The table entry ID
581  * @return status_t
582  */
583 status_t EP_RxIPFResetMatchCounter(ep_handle_t *handle, uint32_t entryID);
584 
585 /*!
586  * @brief Get the matched count for entry in IPF
587  *
588  * @param handle
589  * @param entryID  The table entry ID
590  * @param count  A count of how many times this entry has been matched.
591  * @return status_t
592  */
593 status_t EP_RxIPFGetMatchedCount(ep_handle_t *handle, uint32_t entryID, uint64_t *count);
594 
595 /*!
596  * @brief Init the ENETC PSFP, inlcude
597  *
598  * @param handle
599  * @param config
600  * @return status_t
601  */
EP_RxPSFPInit(ep_handle_t * handle,const netc_ep_psfp_config_t * config)602 static inline status_t EP_RxPSFPInit(ep_handle_t *handle, const netc_ep_psfp_config_t *config)
603 {
604     NETC_PSFPKcProfileInit(handle->hw.common, &config->kcRule[0], false);
605     NETC_PortSetISI(handle->hw.portGroup.port, &config->isiPortConfig);
606     return kStatus_Success;
607 }
608 
609 /*!
610  * @brief Get remaining available entry number (entry size is 24 bytes) of stream identification table
611  * @note This is a Exact Match hash table, and it shares the remaining available entries with Ingress Stream Filter,
612  *       table.
613  *
614  * @param handle
615  * @return uint32_t
616  */
EP_RxPSFPGetISITableRemainEntryNum(ep_handle_t * handle)617 static inline uint32_t EP_RxPSFPGetISITableRemainEntryNum(ep_handle_t *handle)
618 {
619     return (handle->hw.common->HTMCAPR & NETC_SW_ENETC_HTMCAPR_NUM_WORDS_MASK) -
620            (handle->hw.common->HTMOR & NETC_SW_ENETC_HTMOR_AMOUNT_MASK);
621 }
622 
623 /*!
624  * @brief Add an entry into the stream identification table
625  *
626  * @param handle
627  * @param config
628  * @param entryID
629  * @return status_t
630  * @return See @ref netc_cmd_error_t
631  */
632 status_t EP_RxPSFPAddISITableEntry(ep_handle_t *handle, netc_tb_isi_config_t *config, uint32_t *entryID);
633 
634 /*!
635  * @brief Delete an entry in the stream identification table
636  *
637  * @param handle
638  * @param entryID
639  * @return status_t
640  * @return See @ref netc_cmd_error_t
641  */
642 status_t EP_RxPSFPDelISITableEntry(ep_handle_t *handle, uint32_t entryID);
643 
644 /*!
645  * @brief Get remaining available entry number of ingress stream table
646  * @note This is a dynamic bounded index table, the remaining entry can't be zero before add entry into it
647  *
648  * @param handle
649  * @return uint32_t
650  */
EP_RxPSFPGetISTableRemainEntryNum(ep_handle_t * handle)651 static inline uint32_t EP_RxPSFPGetISTableRemainEntryNum(ep_handle_t *handle)
652 {
653     return (handle->hw.common->ISITCAPR & NETC_SW_ENETC_ISITCAPR_NUM_ENTRIES_MASK) -
654            (handle->hw.common->ISITOR & NETC_SW_ENETC_ISITOR_NUM_ENTRIES_MASK);
655 }
656 
657 /*!
658  * @brief Add an entry into the ingress stream table
659  *
660  * @param handle
661  * @param config
662  * @return status_t
663  * @return See @ref netc_cmd_error_t
664  */
665 status_t EP_RxPSFPAddISTableEntry(ep_handle_t *handle, netc_tb_is_config_t *config);
666 
667 /*!
668  * @brief Update an entry in the ingress stream table
669  *
670  * @param handle
671  * @param config
672  * @return status_t
673  * @return See @ref netc_cmd_error_t
674  */
675 status_t EP_RxPSFPUpdateISTableEntry(ep_handle_t *handle, netc_tb_is_config_t *config);
676 
677 /*!
678  * @brief Delete an entry in the stream identification table
679  *
680  * @param handle
681  * @param entryID
682  * @return status_t
683  */
684 status_t EP_RxPSFPDelISTableEntry(ep_handle_t *handle, uint32_t entryID);
685 
686 /*!
687  * @brief Get remaining available entry number (entry size is 24 bytes) of ingress stream filter table
688  * @note This is a Exact Match hash table, and it shares the remaining available entries with Ingress Stream
689  *       Identification table.
690  *
691  * @param handle
692  * @return uint32_t
693  */
EP_RxPSFPGetISFTableRemainEntryNum(ep_handle_t * handle)694 static inline uint32_t EP_RxPSFPGetISFTableRemainEntryNum(ep_handle_t *handle)
695 {
696     return (handle->hw.common->HTMCAPR & NETC_SW_ENETC_HTMCAPR_NUM_WORDS_MASK) -
697            (handle->hw.common->HTMOR & NETC_SW_ENETC_HTMOR_AMOUNT_MASK);
698 }
699 
700 /*!
701  * @brief Add an entry into the ingress stream filter table
702  *
703  * @param handle
704  * @param config
705  * @param entryID
706  * @return status_t
707  * @return See @ref netc_cmd_error_t
708  */
709 status_t EP_RxPSFPAddISFTableEntry(ep_handle_t *handle, netc_tb_isf_config_t *config, uint32_t *entryID);
710 
711 /*!
712  * @brief Update an entry into the ingress stream filter table
713  *
714  * @param handle
715  * @param entryID
716  * @param cfg
717  * @return status_t
718  * @return See @ref netc_cmd_error_t
719  */
720 status_t EP_RxPSFPUpdateISFTableEntry(ep_handle_t *handle, uint32_t entryID, netc_tb_isf_cfge_t *cfg);
721 
722 /*!
723  * @brief Del an entry into the stream filter table
724  *
725  * @param handle
726  * @param entryID
727  * @return status_t
728  */
729 status_t EP_RxPSFPDelISFTableEntry(ep_handle_t *handle, uint32_t entryID);
730 
731 /*!
732  * @brief Get remaining available entry number of Rate Policer table
733  * @note This is a dynamic bounded index table, the remaining entry can't be zero before add entry into it
734  *
735  * @param handle
736  * @return uint32_t
737  */
EP_RxPSFPGetRPTableRemainEntryNum(ep_handle_t * handle)738 static inline uint32_t EP_RxPSFPGetRPTableRemainEntryNum(ep_handle_t *handle)
739 {
740     return (handle->hw.common->RPITCAPR & NETC_SW_ENETC_RPITCAPR_NUM_ENTRIES_MASK) -
741            (handle->hw.common->RPITOR & NETC_SW_ENETC_RPITOR_NUM_ENTRIES_MASK);
742 }
743 
744 /*!
745  * @brief Add entry to Rate Policer table
746  *
747  * @param handle
748  * @param config
749  * @return status_t
750  * @return See @ref netc_cmd_error_t
751  */
752 status_t EP_RxPSFPAddRPTableEntry(ep_handle_t *handle, netc_tb_rp_config_t *config);
753 
754 /*!
755  * @brief Update entry in Rate Policer table
756  *
757  * @param handle
758  * @param config
759  * @return status_t
760  * @return See @ref netc_cmd_error_t
761  */
762 status_t EP_RxPSFPUpdateRPTableEntry(ep_handle_t *handle, netc_tb_rp_config_t *config);
763 
764 /*!
765  * @brief Add or update entry in Rate Policer table
766  *
767  * @param handle
768  * @param config
769  * @return status_t
770  * @return See @ref netc_cmd_error_t
771  */
772 status_t EP_RxPSFPAddOrUpdateRPTableEntry(ep_handle_t *handle, netc_tb_rp_config_t *config);
773 
774 /*!
775  * @brief Delete entry in the Rate Policer table
776  *
777  * @param handle
778  * @param entryID
779  * @return status_t
780  */
781 status_t EP_RxPSFPDelRPTableEntry(ep_handle_t *handle, uint32_t entryID);
782 
783 /*!
784  * @brief Get statistic of specified Rate Policer entry
785  *
786  * @param handle
787  * @param entryID
788  * @param statis
789  * @return status_t
790  * @return See @ref netc_cmd_error_t
791  */
792 status_t EP_RxPSFPGetRPStatistic(ep_handle_t *handle, uint32_t entryID, netc_tb_rp_stse_t *statis);
793 
794 /*!
795  * @brief Get remaining available entry number of ingress stream count table
796  * @note This is a dynamic bounded index table, the remaining entry can't be zero before add entry into it
797  *
798  * @param handle
799  * @return uint32_t
800  */
EP_RxPSFPGetISCTableRemainEntryNum(ep_handle_t * handle)801 static inline uint32_t EP_RxPSFPGetISCTableRemainEntryNum(ep_handle_t *handle)
802 {
803     return (handle->hw.common->ISCITCAPR & NETC_SW_ENETC_ISCITCAPR_NUM_ENTRIES_MASK) -
804            (handle->hw.common->ISCITOR & NETC_SW_ENETC_ISCITOR_NUM_ENTRIES_MASK);
805 }
806 
807 /*!
808  * @brief Add entry in ingress stream count table
809  *
810  * @param handle
811  * @param entryID
812  * @return status_t
813  * @return See @ref netc_cmd_error_t
814  */
815 status_t EP_RxPSFPAddISCTableEntry(ep_handle_t *handle, uint32_t entryID);
816 
817 /*!
818  * @brief Get ingress stream count statistic
819  *
820  * @param handle
821  * @param entryID
822  * @param statistic
823  * @return status_t
824  * @return See @ref netc_cmd_error_t
825  */
826 status_t EP_RxPSFPGetISCStatistic(ep_handle_t *handle, uint32_t entryID, netc_tb_isc_stse_t *statistic);
827 
828 /*!
829  * @brief Reset the count of the ingress stream count
830  *
831  * @param handle
832  * @param entryID
833  * @return status_t
834  * @return See @ref netc_cmd_error_t
835  */
836 status_t EP_RxPSFPResetISCStatistic(ep_handle_t *handle, uint32_t entryID);
837 
838 /*!
839  * @brief Get remaining available entry number of stream gate instance table
840  * @note This is a dynamic bounded index table, the remaining entry can't be zero before add entry into it
841  *
842  * @param handle
843  * @return uint32_t
844  */
EP_RxPSFPGetSGITableRemainEntryNum(ep_handle_t * handle)845 static inline uint32_t EP_RxPSFPGetSGITableRemainEntryNum(ep_handle_t *handle)
846 {
847     return (handle->hw.common->SGIITCAPR & NETC_SW_ENETC_SGIITCAPR_NUM_ENTRIES_MASK) -
848            (handle->hw.common->SGIITOR & NETC_SW_ENETC_SGIITOR_NUM_ENTRIES_MASK);
849 }
850 
851 /*!
852  * @brief Add entry in stream gate instance table
853  *
854  * @param handle
855  * @param config
856  * @return status_t
857  * @return See @ref netc_cmd_error_t
858  */
859 status_t EP_RxPSFPAddSGITableEntry(ep_handle_t *handle, netc_tb_sgi_config_t *config);
860 
861 /*!
862  * @brief Update entry in stream gate instance table
863  *
864  * @param handle
865  * @param config
866  * @return status_t
867  * @return See @ref netc_cmd_error_t
868  */
869 status_t EP_RxPSFPUpdateSGITableEntry(ep_handle_t *handle, netc_tb_sgi_config_t *config);
870 
871 /*!
872  * @brief Delete entry in stream gate instance table
873  *
874  * @param handle
875  * @param entryID
876  * @return status_t
877  * @return See @ref netc_cmd_error_t
878  */
879 status_t EP_RxPSFPDelSGITableEntry(ep_handle_t *handle, uint32_t entryID);
880 
881 /*!
882  * @brief Get state of the stream gate instance for specified entry
883  *
884  * @param handle
885  * @param entryID
886  * @param state
887  * @return status_t
888  * @return See @ref netc_cmd_error_t
889  */
890 status_t EP_RxPSFPGetSGIState(ep_handle_t *handle, uint32_t entryID, netc_tb_sgi_sgise_t *state);
891 
892 /*!
893  * @brief Get remaining available words number of Stream Gate Control List table
894  * @note This is a dynamic bounded index table, and number of words required for a stream gate
895  *       control list is 1+N/2 where N is number of gate time slots in the stream gate control list.
896  *       The remaining word should be greater than the want added entry size
897  *
898  * @param handle
899  * @return uint32_t
900  */
EP_RxPSFPGetSGCLTableRemainWordNum(ep_handle_t * handle)901 static inline uint32_t EP_RxPSFPGetSGCLTableRemainWordNum(ep_handle_t *handle)
902 {
903     return (handle->hw.common->SGCLITCAPR & NETC_SW_ENETC_SGCLITCAPR_NUM_WORDS_MASK) -
904            (handle->hw.common->SGCLTMOR & NETC_SW_ENETC_SGCLTMOR_NUM_WORDS_MASK);
905 }
906 
907 /*!
908  * @brief Add entry into Stream Gate Control List Table
909  *
910  * @param handle
911  * @param config
912  * @return status_t
913  * @return See @ref netc_cmd_error_t
914  */
915 status_t EP_RxPSFPAddSGCLTableEntry(ep_handle_t *handle, netc_tb_sgcl_gcl_t *config);
916 
917 /*!
918  * @brief Delete entry of Stream Gate Control List Table
919  *
920  * @param handle
921  * @param entryID
922  * @return status_t
923  * @return See @ref netc_cmd_error_t
924  */
925 status_t EP_RxPSFPDelSGCLTableEntry(ep_handle_t *handle, uint32_t entryID);
926 
927 /*!
928  * @brief Get Stream Gate Control List Table entry gate control list
929  *
930  * @param handle
931  * @param gcl
932  * @param length
933  * @return status_t
934  * @return See @ref netc_cmd_error_t
935  */
936 status_t EP_RxPSFPGetSGCLGateList(ep_handle_t *handle, netc_tb_sgcl_gcl_t *gcl, uint32_t length);
937 
938 /*!
939  * @brief Get state (ref count) for Stream Gate Control List table entry
940  *
941  * @param handle
942  * @param entryID
943  * @param state
944  * @return status_t
945  * @return See @ref netc_cmd_error_t
946  */
947 status_t EP_RxPSFPGetSGCLState(ep_handle_t *handle, uint32_t entryID, netc_tb_sgcl_sgclse_t *state);
948 
949 #if !(defined(__GNUC__) || defined(__ICCARM__))
950 #pragma endregion PSFP
951 #endif
952 
953 #if !(defined(__GNUC__) || defined(__ICCARM__))
954 #pragma region L2 Filtering
955 #endif
956 
957 /*!
958  * @brief Init the L2 MAC Filter for a specified SI
959  *
960  * @param handle  EP handle
961  * @param config  The L2 MAC Filter configuration
962  * @return status_t
963  */
964 status_t EP_RxL2MFInit(ep_handle_t *handle, netc_si_l2mf_config_t *config);
965 
966 /*!
967  * @brief Add entry into the MAC address hash filter with given MAC address
968  * Hardware layer will not maitain the counter of the hash filter. API layer shall cover this requirement.
969  *
970  * @param handle  EP handle
971  * @param type  Unicast or multicast MAC address
972  * @param macAddr  MAC address to be added in filter table
973  * @return status_t
974  */
975 status_t EP_RxL2MFAddHashEntry(ep_handle_t *handle, netc_packet_type_t type, uint8_t *macAddr);
976 
977 /*!
978  * @brief Delete entry into the MAC address hash filter with given MAC address
979  * Hardware layer will not maitain the counter of the hash filter. API layer shall cover this requirement.
980  *
981  * @param handle  EP handle
982  * @param type  Unicast or multicast MAC address
983  * @param macAddr  MAC address to be deleted from filter table
984  * @return status_t
985  */
986 status_t EP_RxL2MFDelHashEntry(ep_handle_t *handle, netc_packet_type_t type, uint8_t *macAddr);
987 
988 /*!
989  * @brief Add entry into the MAC filter exact match table
990  *
991  * The entry is associated to the current Station Interface
992  *
993  * @param handle
994  * @param idx      Index in the entry table
995  * @param macAddr  MAC address for filter
996  * @return status_t
997  * @return See @ref netc_cmd_error_t
998  */
999 status_t EP_RxL2MFAddEMTableEntry(ep_handle_t *handle, uint32_t idx, uint8_t *macAddr);
1000 
1001 /*!
1002  * @brief Delete entry into the MAC filter exact match table
1003  *
1004  * @param handle  EP handle
1005  * @param idx  Index in the entry table
1006  * @return status_t
1007  * @return See @ref netc_cmd_error_t
1008  */
1009 status_t EP_RxL2MFDelEMTableEntry(ep_handle_t *handle, uint32_t idx);
1010 
1011 // L2 Vlan Filter Table
1012 /*!
1013  * @brief For VLAN filter, use inner vlan tag or outer vlan tag
1014  *
1015  * @param handle
1016  * @param config
1017  * @return status_t
1018  */
1019 status_t EP_RxL2VFInit(ep_handle_t *handle, netc_si_l2vf_config_t *config);
1020 
1021 /*!
1022  * @brief Add entry into the VLAN hash filter with given MAC address
1023  * Hardware layer will not maitain the counter of the hash filter. API layer shall cover this requirement.
1024  *
1025  * @param handle
1026  * @param vlanId  VLAN identifier for filter
1027  * @return status_t
1028  */
1029 status_t EP_RxL2VFAddHashEntry(ep_handle_t *handle, uint16_t vlanId);
1030 
1031 /*!
1032  * @brief Delete entry into the VLAN hash filter with given MAC address
1033  * Hardware layer will not maitain the counter of the hash filter. API layer shall cover this requirement.
1034  *
1035  * @param handle
1036  * @param vlanId  VLAN identifier for filter
1037  * @return status_t
1038  */
1039 status_t EP_RxL2VFDelHashEntry(ep_handle_t *handle, uint16_t vlanId);
1040 
1041 /*!
1042  * @brief Add entry into the MAC filter exact match table
1043  *
1044  * The entry is associated to the current Station Interface
1045  *
1046  * @param handle
1047  * @param idx     Index in the entry table
1048  * @param vlanId  VLAN identifier
1049  * @param tpid    VLAN TPID
1050  * @return status_t
1051  * @return See @ref netc_cmd_error_t
1052  */
1053 status_t EP_RxL2VFAddEMTableEntry(ep_handle_t *handle, uint32_t idx, uint16_t vlanId, netc_vlan_tpid_select_t tpid);
1054 
1055 /*!
1056  * @brief Delete entry into the VLAN filter exact match table
1057  *
1058  * @param handle
1059  * @param idx  Index in the entry table
1060  * @return status_t
1061  * @return See @ref netc_cmd_error_t
1062  */
1063 status_t EP_RxL2VFDelEMTableEntry(ep_handle_t *handle, uint32_t idx);
1064 
1065 #if !(defined(__GNUC__) || defined(__ICCARM__))
1066 #pragma endregion L2 Filtering
1067 #endif
1068 
1069 /*!
1070  * @brief Set the received Frame vlan to IPV mapping
1071  *
1072  * @param handle
1073  * @param vlan  Frame VLAN tag.
1074  * @param ipv  The IPV value to be mapped.
1075  * @return status_t
1076  */
EP_RxMapVlanToIpv(ep_handle_t * handle,netc_vlan_t vlan,uint8_t ipv)1077 static inline status_t EP_RxMapVlanToIpv(ep_handle_t *handle, netc_vlan_t vlan, uint8_t ipv)
1078 {
1079     status_t result = kStatus_Success;
1080 
1081     if (ipv > 7U)
1082     {
1083         result = kStatus_InvalidArgument;
1084     }
1085     else
1086     {
1087         NETC_SIMapVlanToIpv(handle->hw.si, (uint8_t)(vlan.pcp << 1U | vlan.dei), ipv);
1088     }
1089 
1090     return result;
1091 }
1092 
1093 /*!
1094  * @brief Set the IPV to Rx ring mapping
1095  *
1096  * @param handle
1097  * @param ipv  IPV value to be mapped.
1098  * @param ring  The Rx BD ring index to be mapped.
1099  * @return status_t
1100  */
EP_RxMapIpvToRing(ep_handle_t * handle,uint8_t ipv,uint8_t ring)1101 static inline status_t EP_RxMapIpvToRing(ep_handle_t *handle, uint8_t ipv, uint8_t ring)
1102 {
1103     if ((ipv > 7U) || (ring >= handle->cfg.ringPerBdrGroup))
1104     {
1105         return kStatus_InvalidArgument;
1106     }
1107     else
1108     {
1109         NETC_SIMapIpvToRing(handle->hw.si, ipv, ring);
1110         return kStatus_Success;
1111     }
1112 }
1113 
1114 /*!
1115  * @brief Set the default used receive Rx BD ring group.
1116  * @note The IPV mapped ring index is the relative index inside the default used group.
1117  *
1118  * @param handle
1119  * @param groupIdx  The default Rx group index.
1120  * @return status_t
1121  */
EP_RxSetDefaultBDRGroup(ep_handle_t * handle,netc_hw_enetc_si_rxr_group groupIdx)1122 static inline status_t EP_RxSetDefaultBDRGroup(ep_handle_t *handle, netc_hw_enetc_si_rxr_group groupIdx)
1123 {
1124     if (((uint8_t)groupIdx >= handle->cfg.rxBdrGroupNum) && (groupIdx != kNETC_SiBDRGroupOne))
1125     {
1126         /* Can't selected non existing group */
1127         return kStatus_InvalidArgument;
1128     }
1129     else
1130     {
1131         NETC_SISetDefaultRxBDRGroup(handle->hw.si, groupIdx);
1132         return kStatus_Success;
1133     }
1134 }
1135 
1136 /*! @} */ // end of netc_ep_rx
1137 #if !(defined(__GNUC__) || defined(__ICCARM__))
1138 #pragma endregion netc_ep_rx
1139 #endif
1140 
1141 #if !(defined(__GNUC__) || defined(__ICCARM__))
1142 #pragma region netc_ep_tx
1143 #endif
1144 /*! @addtogroup netc_ep_tx
1145  * @{
1146  */
1147 
1148 /*!
1149  * @brief Config the Time Gate Scheduling entry admin gate control list
1150  *
1151  * This function is used to program the Enhanced Scheduled Transmisson. (IEEE802.1Qbv)
1152  *
1153  * @param handle
1154  * @param config
1155  * @return status_t
1156  * @return See @ref netc_cmd_error_t
1157  */
1158 status_t EP_TxTGSConfigAdminGcl(ep_handle_t *handle, netc_tb_tgs_gcl_t *config);
1159 
1160 /*!
1161  * @brief Enable the EP port time gate scheduling
1162  *
1163  * @param handle
1164  * @param enable
1165  * @param gateState
1166  * @return status_t
1167  */
1168 #if (defined(FSL_FEATURE_NETC_HAS_ERRATA_051130) && FSL_FEATURE_NETC_HAS_ERRATA_051130)
1169 status_t EP_TxPortTGSEnable(ep_handle_t *handle, bool enable, uint8_t gateState);
1170 #else
1171 status_t EP_TxPortTGSEnable(ep_handle_t *handle, bool enable);
1172 #endif
1173 
1174 /*!
1175  * @brief Get Time Gate Scheduling entry operation gate control list
1176  *
1177  * This function is used to read the Enhanced Scheduled Transmisson. (IEEE802.1Qbv)
1178  *
1179  * @param handle
1180  * @param gcl
1181  * @param length
1182  * @return status_t
1183  * @return See @ref netc_cmd_error_t
1184  */
1185 status_t EP_TxtTGSGetOperGcl(ep_handle_t *handle, netc_tb_tgs_gcl_t *gcl, uint32_t length);
1186 
1187 /*!
1188  * @brief Config the TC (traffic class) property
1189  *
1190  * @param handle
1191  * @param tcIdx
1192  * @param config
1193  * @return status_t
1194  */
1195 status_t EP_TxTrafficClassConfig(ep_handle_t *handle, netc_hw_tc_idx_t tcIdx, const netc_port_tx_tc_config_t *config);
1196 
1197 /*! @} */ // end of netc_ep_tx
1198 #if !(defined(__GNUC__) || defined(__ICCARM__))
1199 #pragma endregion netc_ep_tx
1200 #endif
1201 
1202 #if !(defined(__GNUC__) || defined(__ICCARM__))
1203 #pragma region netc_ep_stat
1204 #endif
1205 /*! @addtogroup netc_ep_stat
1206  * @{
1207  */
1208 
1209 /*!
1210  * @brief Get the ENETC port discard statistic and reason
1211  *
1212  * Get the discarded count of frames and its reasons.
1213  *
1214  * @param handle
1215  * @param useTx true - Tx port.  false - Rx port.
1216  * @param statistic pointer to the statistic data
1217  * @return status_t
1218  */
EP_GetPortDiscardStatistic(ep_handle_t * handle,bool useTx,netc_port_discard_statistic_t * statistic)1219 static inline status_t EP_GetPortDiscardStatistic(ep_handle_t *handle,
1220                                                   bool useTx,
1221                                                   netc_port_discard_statistic_t *statistic)
1222 {
1223     NETC_PortGetDiscardStatistic(handle->hw.portGroup.port, (useTx) ? kNETC_TxDiscard : kNETC_RxDiscard, statistic);
1224     return kStatus_Success;
1225 }
1226 
1227 /*!
1228  * @brief Clean the EP Port Rx discard reason. Set the related bits to 1 to clear the specific reasons
1229  *
1230  * @param handle
1231  * @param useTx true - Tx port.  false - Rx port.
1232  * @param reason0
1233  * @param reason1
1234  * @return status_t
1235  */
EP_ClearPortDiscardReason(ep_handle_t * handle,bool useTx,uint32_t reason0,uint32_t reason1)1236 static inline status_t EP_ClearPortDiscardReason(ep_handle_t *handle, bool useTx, uint32_t reason0, uint32_t reason1)
1237 {
1238     NETC_PortClearDiscardReason(handle->hw.portGroup.port, (useTx) ? kNETC_TxDiscard : kNETC_RxDiscard, reason0,
1239                                 reason1);
1240     return kStatus_Success;
1241 }
1242 
1243 /*!
1244  * @brief Get EP port time gate scheduling gate list status
1245  *
1246  * @param handle
1247  * @return Port status flags which are ORed by the enumerators in the @ref netc_port_tgsl_status_t
1248  */
EP_GetPortTGSListStatus(ep_handle_t * handle)1249 static inline uint32_t EP_GetPortTGSListStatus(ep_handle_t *handle)
1250 {
1251     return NETC_PortGetTGSListStatus(handle->hw.portGroup.port);
1252 }
1253 
1254 /*! @} */ // end of netc_ep_stat
1255 #if !(defined(__GNUC__) || defined(__ICCARM__))
1256 #pragma endregion netc_ep_stat
1257 #endif
1258 
1259 #if !(defined(__GNUC__) || defined(__ICCARM__))
1260 #pragma region netc_ep_interrupt
1261 #endif
1262 /*! @addtogroup netc_ep_interrupt
1263  * @{
1264  */
1265 
1266 /*!
1267  * @brief Clean the SI transmit interrupt flags
1268  *
1269  * @param handle    The EP handle.
1270  * @param txFrameIntrMask  IPV value to be mapped, bit x represents ring x.
1271  * @param txThresIntrMask  The Rx BD ring index to be mapped, bit x represents ring x.
1272  */
EP_CleanTxIntrFlags(ep_handle_t * handle,uint16_t txFrameIntrMask,uint16_t txThresIntrMask)1273 static inline void EP_CleanTxIntrFlags(ep_handle_t *handle, uint16_t txFrameIntrMask, uint16_t txThresIntrMask)
1274 {
1275     NETC_SICleanTxIntrFlags(handle->hw.si, txFrameIntrMask, txThresIntrMask);
1276 }
1277 
1278 /*!
1279  * @brief Clean the SI receive interrupt flags
1280  *
1281  * @param handle    The EP handle.
1282  * @param rxIntrMask  Rx interrupt bit mask, bit x represents ring x.
1283  */
EP_CleanRxIntrFlags(ep_handle_t * handle,uint32_t rxIntrMask)1284 static inline void EP_CleanRxIntrFlags(ep_handle_t *handle, uint32_t rxIntrMask)
1285 {
1286     NETC_SICleanRxIntrFlags(handle->hw.si, rxIntrMask);
1287 }
1288 
1289 /*!
1290  * @brief Set the global MSIX mask status
1291  *
1292  * This function masks/unmasks global MSIX message.
1293  * Mask - All of the vectors are masked, regardless of their per-entry mask bit states.
1294  * Unmask - Each entry's mask status determines whether the vector is masked or not.
1295  *
1296  * @param handle    The EP handle
1297  * @param mask      The mask state. True: Mask, False: Unmask.
1298  * @return status_t
1299  */
1300 status_t EP_MsixSetGlobalMask(ep_handle_t *handle, bool mask);
1301 
1302 /*!
1303  * @brief Set the MSIX entry mask status for specified entry
1304  *
1305  * This function masks/unmasks MSIX message for specified entry.
1306  *
1307  * @param handle    The EP handle
1308  * @param entryIdx  The entry index in the table.
1309  * @param mask      The mask state. True: Mask, False: Unmask.
1310  * @return status_t
1311  */
1312 status_t EP_MsixSetEntryMask(ep_handle_t *handle, uint8_t entryIdx, bool mask);
1313 
1314 /*!
1315  * @brief Get the MSIX pending status in MSIX PBA table
1316  *
1317  * This function is to get the entry pending status from MSIX PBA table. If interrupt occurs but masked by vector
1318  * control of entry, pending bit in PBA will be set.
1319  *
1320  * @param handle  The EP handle
1321  * @param pbaIdx  The index of PBA array with 64-bit unit.
1322  * @param status  Pending status bit mask, bit n for entry n.
1323  * @return status_t
1324  */
1325 status_t EP_MsixGetPendingStatus(ep_handle_t *handle, uint8_t pbaIdx, uint64_t *status);
1326 
1327 /*! @} */ // end of netc_ep_interrupt
1328 #if !(defined(__GNUC__) || defined(__ICCARM__))
1329 #pragma endregion netc_ep_interrupt
1330 #endif
1331 
1332 #if !(defined(__GNUC__) || defined(__ICCARM__))
1333 #pragma region netc_ep_xfer
1334 #endif
1335 /*! @addtogroup netc_ep_xfer
1336  * @{
1337  */
1338 /*!
1339  * @brief Common part for transfer regular frame or Switch management frame.
1340  * @note This function is internal used. Please use EP_SendFrame() or SWT_SendFrame() API to send frames.
1341  *
1342  * @param handle
1343  * @param txBdRing The Transmit buffer descriptor ring handle
1344  * @param hwRing The hardware Tx ring index
1345  * @param frame The frame descriptor pointer
1346  * @param context Private context provided back by ep_reclaim_cb_t
1347  * @param txDesc Point to the Transmits BD Description array.
1348  * @param txCacheMaintain Enable/Disable Tx buffer Cache Maintain.
1349  * @retval status_t
1350  */
1351 status_t EP_SendFrameCommon(ep_handle_t *handle,
1352                             netc_tx_bdr_t *txBdRing,
1353                             uint8_t hwRing,
1354                             netc_frame_struct_t *frame,
1355                             void *context,
1356                             netc_tx_bd_t *txDesc,
1357                             bool txCacheMaintain);
1358 
1359 /*!
1360  * @brief Transmits a frame for specified ring.
1361  * This API is zero-copy and requires the ep_reclaim_cb_t to be called to free the transmitted frame.
1362  *
1363  * @param handle
1364  * @param ring The ring index
1365  * @param frame The frame descriptor pointer
1366  * @param context Private context provided back by ep_reclaim_cb_t
1367  * @param opt Additional tx options. If NULL, default is tx timestamping enabled, no start time and no masquerading.
1368  * @retval status_t
1369  */
1370 status_t EP_SendFrame(ep_handle_t *handle, uint8_t ring, netc_frame_struct_t *frame, void *context, ep_tx_opt *opt);
1371 
1372 /*!
1373  * @brief Wait until the EP Tx ring has completed the transfer.
1374  *
1375  * @note Only call after EP_SendFrame() to do a no-interrupt transfer
1376  *
1377  * @param handle
1378  * @param ring The ring index
1379  */
EP_WaitUnitilTxComplete(ep_handle_t * handle,uint8_t ring)1380 static inline void EP_WaitUnitilTxComplete(ep_handle_t *handle, uint8_t ring)
1381 {
1382     uint8_t hwRing = ring;
1383     if (NETC_EnetcHasManagement(handle->hw.base) && (getSiNum(handle->cfg.si) == 0U))
1384     {
1385         /* Switch management ENETC Tx BD hardware ring 0 can't be used to send regular frame, so the index need increase
1386          * 1 */
1387         hwRing++;
1388     }
1389     while (handle->hw.si->BDR[hwRing].TBCIR != handle->txBdRing[ring].producerIndex)
1390     {
1391     }
1392 }
1393 /*!
1394  * @brief Common part of Reclaim tx descriptors for regular frame or Switch management frame.
1395  * @note This function is internal used. Please use EP_ReclaimTxDescriptor() or SWT_ReclaimTxDescriptor() API to Reclaim
1396  * tx descriptors.
1397  *
1398  * @param handle
1399  * @param txBdRing The Transmit buffer descriptor ring handle
1400  * @param hwRing The hardware Tx ring index
1401  * @param enCallback Enable/Disable call the Tx Reclaim callback functions.
1402  */
1403 netc_tx_frame_info_t *EP_ReclaimTxDescCommon(ep_handle_t *handle,
1404                                              netc_tx_bdr_t *txBdRing,
1405                                              uint8_t hwRing,
1406                                              bool enCallback);
1407 
1408 /*!
1409  * @brief Reclaim tx descriptors.
1410  * This function is used to update the tx descriptor status and
1411  * get the tx timestamp. For each reclaimed transmit frame the
1412  * ep_reclaim_cb_t is called.
1413  *
1414  * This is called after being notified of a transmit completion from ISR.
1415  * It runs until there are no more frames to be reclaimed in the BD ring.
1416  *
1417  * @param handle
1418  * @param ring The ring index
1419  */
1420 void EP_ReclaimTxDescriptor(ep_handle_t *handle, uint8_t ring);
1421 
1422 /*!
1423  * @brief Common part of receives one frame with zero copy from specified ring
1424  *
1425  * @note This function is internal used. Please use EP_ReceiveFrame() or SWT_ReceiveFrame() API.
1426  *
1427  * @param handle
1428  * @param rxBdRing Rx BD ring handle
1429  * @param ring Ring index
1430  * @param frame Frame buffer point
1431  * @param attr Frame attribute pointer
1432  * @param rxCacheMaintain Enable/Disable Rx buffer Cache maintain
1433  * @return status_t
1434  */
1435 status_t EP_ReceiveFrameCommon(ep_handle_t *handle,
1436                                netc_rx_bdr_t *rxBdRing,
1437                                uint8_t ring,
1438                                netc_frame_struct_t *frame,
1439                                netc_frame_attr_t *attr,
1440                                bool rxCacheMaintain);
1441 
1442 /*!
1443  * @brief Receives one frame with zero copy from specified ring
1444  *
1445  * @note The sufficient rx frame data structure MUST be provided by appliction.
1446  *
1447  * @param handle
1448  * @param ring The ring index
1449  * @param frame The frame descriptor pointer
1450  * @param attr Frame attribute pointer
1451  * @return kStatus_Success                Successfully receive a regular frame
1452  * @return kStatus_NETC_RxHRNotZeroFrame  Frame in Rx BD ring is management frame, need call SWT_ReceiveFrame()
1453  * @return kStatus_NETC_RxTsrResp         Frame in Rx BD ring is Transmit Timestamp Reference Response messages, need
1454  *                                        call SWT_GetTimestampRefResp() to get Transmit Timestamp Reference Response
1455  * @return kStatus_NETC_RxFrameEmpty      Rx BD ring is empty
1456  * @return kStatus_NETC_RxFrameError      Frame in Rx BD ring has error, need be dropped
1457  * @return kStatus_InvalidArgument        Rx BD ring index is out of range
1458  * @return kStatus_NETC_LackOfResource    Appliction provided buffer is not enough
1459  */
1460 status_t EP_ReceiveFrame(ep_handle_t *handle, uint8_t ring, netc_frame_struct_t *frame, netc_frame_attr_t *attr);
1461 
1462 /*!
1463  * @brief Drop one frame
1464  *
1465  * @note This function is internal used.
1466  *
1467  * @param handle
1468  * @param rxBdRing Rx BD ring handle
1469  * @param ring Ring index
1470  */
1471 void EP_DropFrame(ep_handle_t *handle, netc_rx_bdr_t *rxBdRing, uint8_t ring);
1472 
1473 /*!
1474  * @brief Common part of receive regular frame or Switch management frame which will be copied in the provided buffer
1475  *
1476  * @note This function is internal used. Please use EP_ReceiveFrameCopy() or SWT_ReceiveFrameCopy() API.
1477  *
1478  * @param handle
1479  * @param rxBdRing Rx BD ring handle
1480  * @param ring Ring index
1481  * @param buffer Buffer address
1482  * @param length Buffer length
1483  * @param attr Frame attribute pointer
1484  * @param rxCacheMaintain Enable/Disable Rx buffer Cache maintain
1485  * @return status_t
1486  */
1487 status_t EP_ReceiveFrameCopyCommon(ep_handle_t *handle,
1488                                    netc_rx_bdr_t *rxBdRing,
1489                                    uint8_t ring,
1490                                    void *buffer,
1491                                    uint32_t length,
1492                                    netc_frame_attr_t *attr,
1493                                    bool rxCacheMaintain);
1494 
1495 /*!
1496  * @brief Receives one frame which will be copied in the provided buffer from specified ring
1497  *
1498  * @note The buffer size MUST be queried using EP_GetRxFrameSize() beforehand.
1499  *
1500  * @param handle
1501  * @param ring Ring index
1502  * @param buffer Buffer address
1503  * @param length Buffer length
1504  * @param attr Frame attribute pointer
1505  * @return kStatus_Success                Successfully receive a regular frame
1506  * @return kStatus_InvalidArgument        Rx BD ring index is out of range
1507  */
1508 status_t EP_ReceiveFrameCopy(ep_handle_t *handle, uint8_t ring, void *buffer, uint32_t length, netc_frame_attr_t *attr);
1509 
1510 /*!
1511  * @brief Common part of get pending frame size API for regular frame or Switch management frame.
1512  * @note This function is internal used. Please use EP_GetRxFrameSize() or SWT_GetRxFrameSize() API.
1513  *
1514  * @param handle
1515  * @param rxBdRing Rx BD ring handle
1516  * @param length The length of the valid frame received.
1517  * @return status_t
1518  */
1519 status_t EP_GetRxFrameSizeCommon(ep_handle_t *handle, netc_rx_bdr_t *rxBdRing, uint32_t *length);
1520 
1521 /*!
1522  * @brief Gets the size of the pending frame in the specified receive ring buffer.
1523  *
1524  * @note Frame size without FCS
1525  *
1526  * @param handle The ENET handler structure. This is the same handler pointer used in the ENET_Init.
1527  * @param ring The ring index
1528  * @param length The length of the valid frame received.
1529  * @return kStatus_Success                Successfully get the length of a regular frame
1530  * @return kStatus_NETC_RxHRNotZeroFrame  Frame in Rx BD ring is management frame, need call SWT_GetRxFrameSize() to get
1531  *                                        frame size
1532  * @return kStatus_NETC_RxTsrResp         Frame in Rx BD ring is Transmit Timestamp Reference Response messages, need
1533  *                                        call SWT_GetTimestampRefResp() to get Transmit Timestamp Reference Response
1534  * @return kStatus_NETC_RxFrameEmpty      Rx BD ring is empty
1535  * @return kStatus_NETC_RxFrameError      Frame in Rx BD ring has error, need be dropped
1536  * @return kStatus_InvalidArgument        Rx BD ring index is out of range
1537  */
1538 status_t EP_GetRxFrameSize(ep_handle_t *handle, uint8_t ring, uint32_t *length);
1539 
1540 /*! @} */ // end of netc_ep_xfer
1541 #if !(defined(__GNUC__) || defined(__ICCARM__))
1542 #pragma endregion netc_ep_xfer
1543 #endif
1544 
1545 #if !(defined(__GNUC__) || defined(__ICCARM__))
1546 #pragma region netc_ep_psi_vsi_msg
1547 #endif
1548 /*! @addtogroup netc_ep_psi_vsi_msg
1549  * @{
1550  */
1551 
1552 /*!
1553  * @brief PSI enables/disables specified interrupt
1554  *
1555  * @param handle  The EP handle.
1556  * @param mask  The interrupt mask, refer to #netc_psi_msg_flags_t which should be OR'd together.
1557  * @param enable  Enable/Disable the interrupt.
1558  */
1559 void EP_PsiEnableInterrupt(ep_handle_t *handle, uint32_t mask, bool enable);
1560 
1561 /*!
1562  * @brief PSI gets interrupt event flag status
1563  *
1564  * @param handle  The EP handle.
1565  * @return The interrupt mask, refer to #netc_psi_msg_flags_t which should be OR'd together.
1566  */
1567 uint32_t EP_PsiGetStatus(ep_handle_t *handle);
1568 
1569 /*!
1570  * @brief PSI clears interrupt event flag
1571  *
1572  * @param handle  The EP handle.
1573  * @param mask  The interrupt mask, refer to #netc_psi_msg_flags_t which should be OR'd together.
1574  */
1575 void EP_PsiClearStatus(ep_handle_t *handle, uint32_t mask);
1576 
1577 /*!
1578  * @brief PSI sends message to specified VSI(s)
1579  *
1580  * @param handle  The EP handle.
1581  * @param msg  The message to be sent.
1582  * @param vsi  The VSI number.
1583  * @return status_t
1584  */
1585 status_t EP_PsiSendMsg(ep_handle_t *handle, uint16_t msg, netc_vsi_number_t vsi);
1586 
1587 /*!
1588  * @brief PSI checks Tx busy flag which should be cleaned when VSI receive the message data
1589  *
1590  * @param handle  The EP handle.
1591  * @param vsi  The VSI number.
1592  * @return The busy status of specified VSI.
1593  */
1594 bool EP_PsiCheckTxBusy(ep_handle_t *handle, netc_vsi_number_t vsi);
1595 
1596 /*!
1597  * @brief PSI sets Rx buffer to receive message from specified VSI
1598  * @note The buffer memory size should be big enough for the message data from VSI
1599  *
1600  * @param handle  The EP handle.
1601  * @param vsi  The VSI number.
1602  * @param buffAddr  The buffer address to store message data from VSI.
1603  */
1604 status_t EP_PsiSetRxBuffer(ep_handle_t *handle, netc_vsi_number_t vsi, uint64_t buffAddr);
1605 
1606 /*!
1607  * @brief PSI gets Rx message from specified VSI
1608  *
1609  * @param handle  The EP handle.
1610  * @param vsi  The VSI number.
1611  * @param msgInfo  The Rx message information.
1612  */
1613 status_t EP_PsiGetRxMsg(ep_handle_t *handle, netc_vsi_number_t vsi, netc_psi_rx_msg_t *msgInfo);
1614 
1615 /*!
1616  * @brief Enable VSI interrupt
1617  *
1618  * @param handle  The EP handle.
1619  * @param mask  The interrupt mask, see #netc_vsi_msg_flags_t which should be OR'd together.
1620  * @param enable  Enable/Disable interrupt.
1621  */
1622 void EP_VsiEnableInterrupt(ep_handle_t *handle, uint32_t mask, bool enable);
1623 
1624 /*!
1625  * @brief Get VSI interrupt status
1626  *
1627  * @param handle  The EP handle.
1628  * @return A bitmask composed of #netc_vsi_msg_flags_t enumerators OR'd together.
1629  */
1630 uint32_t EP_VsiGetStatus(ep_handle_t *handle);
1631 
1632 /*!
1633  * @brief Clear VSI interrupt status
1634  *
1635  * @param handle  The EP handle.
1636  * @param mask  The interrupt mask, see #netc_vsi_msg_flags_t which should be OR'd together.
1637  */
1638 void EP_VsiClearStatus(ep_handle_t *handle, uint32_t mask);
1639 
1640 /*!
1641  * @brief VSI sends message to PSI
1642  *
1643  * @param handle  The EP handle.
1644  * @param msgAddr  Address to store message ready to be sent, must be 64 bytes aligned.
1645  * @param msgLen  The message length, must be 32 bytes aligned.
1646  * @return status_t
1647  */
1648 status_t EP_VsiSendMsg(ep_handle_t *handle, uint64_t msgAddr, uint32_t msgLen);
1649 
1650 /*!
1651  * @brief Check VSI Tx status
1652  *
1653  * @param handle  The EP handle.
1654  * @param status  The VSI Tx status structure.
1655  */
1656 void EP_VsiCheckTxStatus(ep_handle_t *handle, netc_vsi_msg_tx_status_t *status);
1657 
1658 /*!
1659  * @brief VSI receives message from PSI
1660  *
1661  * @param handle  The EP handle.
1662  * @param msg  The message from PSI.
1663  * @return status_t
1664  */
1665 status_t EP_VsiReceiveMsg(ep_handle_t *handle, uint16_t *msg);
1666 
1667 /*! @} */ // end of netc_ep_psi_vsi_msg
1668 #if !(defined(__GNUC__) || defined(__ICCARM__))
1669 #pragma endregion netc_ep_psi_vsi_msg
1670 #endif
1671 
1672 #if defined(__cplusplus)
1673 }
1674 #endif
1675 #endif /* FSL_NETC_ENDPOINT_H_ */
1676