1 /*
2 * Copyright 2021-2023 NXP
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #ifndef FSL_NETC_HW_H_
8 #define FSL_NETC_HW_H_
9
10 #include "fsl_netc.h"
11
12 #if !(defined(__GNUC__) || defined(__ICCARM__))
13 #pragma region netc_hw
14 #endif
15 /*! @addtogroup netc_hw
16 * @{
17 */
18
19 /*! @brief MSIX table address offset. */
20 #define NETC_MSIX_TABLE_OFFSET (0x10000U)
21 /*! @brief MSIX PBA address offset. */
22 #define NETC_MSIX_TABLE_PBA_OFFSET (0x800U)
23
24 /*! @brief Nanosecond in one second. */
25 #define NETC_NANOSECOND_ONE_SECOND (1000000000UL)
26
27 /*!
28 * @brief Register groups for the PCIe function
29 *
30 */
31 typedef struct _netc_func
32 {
33 union
34 {
35 ENETC_PCI_TYPE0_Type *pf; /*!< PSI function */
36 ENETC_VF_PCI_TYPE0_Type *vf; /*!< VSI function */
37 };
38 } netc_func_t;
39
40 /*!
41 * @brief Register groups for the Port/Link hardware
42 *
43 */
44 typedef struct _netc_port_hw
45 {
46 NETC_PORT_Type *port; /*!< Port Address */
47 union
48 {
49 NETC_ETH_LINK_Type *eth; /*!< MAC Port Address */
50 #if !(defined(FSL_FEATURE_NETC_HAS_NO_SWITCH) && FSL_FEATURE_NETC_HAS_NO_SWITCH)
51 NETC_PSEUDO_LINK_Type *pseudo; /*!< Pseudo link port address */
52 #endif
53 };
54 } netc_port_hw_t;
55
56 /*!
57 * @brief Register group for the ENETC peripheral hardware
58 *
59 */
60 typedef struct _netc_enetc_hw
61 {
62 netc_func_t func; /*!< PCIE function register */
63 NETC_ENETC_Type *base; /*!< Base register of ENETC module */
64 NETC_SW_ENETC_Type *common; /*!< Common register of ENETC module */
65 netc_port_hw_t portGroup; /*!< Port register group */
66 ENETC_GLOBAL_Type *global; /*!< Global NETC address */
67 ENETC_SI_Type *si; /*!< Station Interfce for the P/V SI */
68 netc_msix_entry_t *msixTable; /*!< MSIX table address */
69 } netc_enetc_hw_t;
70
71 #if !(defined(FSL_FEATURE_NETC_HAS_NO_SWITCH) && FSL_FEATURE_NETC_HAS_NO_SWITCH)
72 /*!
73 * @brief Register group for the Switch peripheral hardware
74 *
75 */
76 typedef struct _netc_switch_hw
77 {
78 ENETC_PCI_TYPE0_Type *func; /*!< Base address for PCIE function */
79 NETC_SW_Type *base; /*!< Base address for Switch */
80 NETC_SW_ENETC_Type *common; /*!< Common address of ENETC Module */
81 netc_port_hw_t ports[FSL_FEATURE_NETC_SWITCH_MAX_PORT_NUMBER]; /*!< Port Register Group */
82 ENETC_GLOBAL_Type *global; /*!< GLobal NETC Register Base Address */
83 netc_msix_entry_t *msixTable; /*!< MSIX table address */
84 } netc_switch_hw_t;
85 #endif
86
87 /*!
88 * @brief Register group for the Timer peripheral hardware
89 *
90 */
91 typedef struct _netc_timer_hw
92 {
93 ENETC_PCI_TYPE0_Type *func; /*!< PCIE function register */
94 ENETC_PF_TMR_Type *base; /*!< Base register address for timer module */
95 ENETC_GLOBAL_Type *global; /*!< Global NETC register address */
96 netc_msix_entry_t *msixTable; /*!< MSIX table address */
97 } netc_timer_hw_t;
98
99 /*! @brief Register group for both EMDIO and port external MDIO. */
100 typedef struct _netc_mdio_hw
101 {
102 __IO uint32_t EMDIO_CFG; /*!< External MDIO configuration register, offset: 0x1C00 */
103 __IO uint32_t EMDIO_CTL; /*!< External MDIO interface control register, offset: 0x1C04 */
104 __IO uint32_t EMDIO_DATA; /*!< External MDIO interface data register, offset: 0x1C08 */
105 __IO uint32_t EMDIO_ADDR; /*!< External MDIO register address register, offset: 0x1C0C */
106 __I uint32_t EMDIO_STAT; /*!< External MDIO status register, offset: 0x1C10 */
107 uint8_t RESERVED_1[12];
108 __IO uint32_t PHY_STATUS_CFG; /*!< PHY status configuration register, offset: 0x1C20 */
109 __IO uint32_t PHY_STATUS_CTL; /*!< PHY status control register, offset: 0x1C24 */
110 __I uint32_t PHY_STATUS_DATA; /*!< PHY status data register, offset: 0x1C28 */
111 __IO uint32_t PHY_STATUS_ADDR; /*!< PHY status register address register, offset: 0x1C2C */
112 __IO uint32_t PHY_STATUS_EVENT; /*!< PHY status event register, offset: 0x1C30 */
113 __IO uint32_t PHY_STATUS_MASK; /*!< PHY status mask register, offset: 0x1C34 */
114 } netc_mdio_hw_t;
115
116 /*! @} */ // end of netc_hw
117 #if !(defined(__GNUC__) || defined(__ICCARM__))
118 #pragma endregion netc_hw
119 #endif
120
121 #if !(defined(__GNUC__) || defined(__ICCARM__))
122 #pragma region netc_hw_table
123 #endif
124 /*! @addtogroup netc_hw_table
125 * @{
126 */
127
128 /*! @brief Register group for SI/Switch command bd ring */
129 typedef struct _netc_cbdr_hw
130 {
131 __IO uint32_t CBDRMR; /*!< Command BDR mode register. */
132 __I uint32_t CBDRSR; /*!< Command BDR status register. */
133 uint8_t RESERVED_0[8];
134 __IO uint32_t CBDRBAR0; /*!< Command BDR base address register 0 */
135 __IO uint32_t CBDRBAR1; /*!< Command BDR base address register 1 */
136 __IO uint32_t CBDRPIR; /*!< Command BDR producer index register */
137 __IO uint32_t CBDRCIR; /*!< Command BDR consumer index register */
138 __IO uint32_t CBDRLENR; /*!< Command BDR length register */
139 } netc_cbdr_hw_t;
140
141 /*! @brief Handle for common part of EP/Switch NTMP */
142 typedef struct _netc_cbdr_handle
143 {
144 netc_cbdr_hw_t *base; /*!< Point to hardware command bd ring register group. */
145 netc_cmd_bdr_t *cmdr; /*!< Point to command BD ring handle. */
146 netc_tb_data_buffer_t *buffer; /*!< Point to table common data buffer. */
147 } netc_cbdr_handle_t;
148
149 /*! @} */ // end of netc_hw_table
150 #if !(defined(__GNUC__) || defined(__ICCARM__))
151 #pragma endregion netc_hw_table
152 #endif
153
154 /*******************************************************************************
155 * Definitions
156 ******************************************************************************/
157
158 #if defined(__cplusplus)
159 extern "C" {
160 #endif
161
162 /*******************************************************************************
163 * API
164 ******************************************************************************/
165
166 #if !(defined(__GNUC__) || defined(__ICCARM__))
167 #pragma region netc_hw_common
168 #endif
169 /*! @addtogroup netc_hw_common
170 * @{
171 */
172
EP_IncreaseIndex(uint16_t index,uint32_t max)173 static inline uint16_t EP_IncreaseIndex(uint16_t index, uint32_t max)
174 {
175 uint32_t i = (uint32_t)index;
176
177 if (++i >= max)
178 {
179 i = 0;
180 }
181 return (uint16_t)i;
182 }
183
184 /*!
185 * @brief Get the VSI index
186 *
187 * @param vsi The VSI number.
188 */
189 uint16_t NETC_SIGetVsiIndex(netc_vsi_number_t vsi);
190
191 /*!
192 * @brief Set layer2/3 Dos configuration
193 *
194 * @param base
195 * @param config
196 */
NETC_IPFInit(NETC_SW_ENETC_Type * base,const netc_ipf_config_t * config)197 static inline void NETC_IPFInit(NETC_SW_ENETC_Type *base, const netc_ipf_config_t *config)
198 {
199 base->DOSL2CR = NETC_SW_ENETC_DOSL2CR_SAMEADDR(config->l2DiscardSmacEquDmac) |
200 NETC_SW_ENETC_DOSL2CR_MSAMCC(config->l2DiscardMCSmac);
201 // base->DOSL3CR = NETC_SW_ENETC_DOSL3CR_SAMEADDR(config->l3DiscardSipEquDip);
202 }
203
204 /*!
205 * @brief Initialize the Ingress Stream Identification Key construction rule profiles
206 *
207 * @param base
208 * @param rule
209 * @param enKcPair1
210 * @return void
211 */
212 void NETC_PSFPKcProfileInit(NETC_SW_ENETC_Type *base, const netc_isi_kc_rule_t *rule, bool enKcPair1);
213
214 /*!
215 * @brief Initialize the customer vlan type
216 *
217 * @param base
218 * @param config
219 * @param enRtag
220 * @return void
221 */
222 void NETC_RxVlanCInit(NETC_SW_ENETC_Type *base, const netc_vlan_classify_config_t *config, bool enRtag);
223
224 /*!
225 * @brief Initialize the ingress QoS classification
226 *
227 * @param base
228 * @param profile
229 * @param enProfile1
230 */
231 void NETC_RxQosCInit(NETC_SW_ENETC_Type *base, const netc_qos_classify_profile_t *profile, bool enProfile1);
232
233 /*! @} */ // end of netc_hw_common
234 #if !(defined(__GNUC__) || defined(__ICCARM__))
235 #pragma endregion netc_hw_common
236 #endif
237
238 #if !(defined(__GNUC__) || defined(__ICCARM__))
239 #pragma region netc_hw_table
240 #endif
241 /*! @addtogroup netc_hw_table
242 * @{
243 */
244
245 /*!
246 * @brief Initialize the command BD ring
247 *
248 * @param base
249 * @param config
250 * @return kStatus_Success
251 * @return kStatus_Fail
252 */
253 status_t NETC_CmdBDRInit(netc_cbdr_hw_t *base, const netc_cmd_bdr_config_t *config);
254
255 /*!
256 * @brief Deinitialize the command BD ring
257 *
258 * @param base
259 * @return kStatus_Success
260 */
261 status_t NETC_CmdBDRDeinit(netc_cbdr_hw_t *base);
262
263 /*!
264 * @brief Send the Command Buffer Descriptor to operate on a NTMP table
265 *
266 * @param base
267 * @param cbdr
268 * @param cbd
269 * @param version
270 * @return status_t
271 * @return See @ref netc_cmd_error_t
272 */
273 status_t NETC_CmdBDSendCommand(netc_cbdr_hw_t *base,
274 netc_cmd_bdr_t *cbdr,
275 netc_cmd_bd_t *cbd,
276 netc_cbd_version_t version);
277
278 /*!
279 * @brief Add entry into the ingress Port Filter Table.
280 *
281 * @param handle
282 * @param config
283 * @param entryID
284 * @return status_t
285 * @return See @ref netc_cmd_error_t
286 */
287 status_t NETC_AddIPFTableEntry(netc_cbdr_handle_t *handle, netc_tb_ipf_config_t *config, uint32_t *entryID);
288
289 /*!
290 * @brief Update entry in the ingress Port Filter Table.
291 *
292 * @param handle
293 * @param entryID
294 * @param cfg
295 * @return status_t
296 * @return See @ref netc_cmd_error_t
297 */
298 status_t NETC_UpdateIPFTableEntry(netc_cbdr_handle_t *handle, uint32_t entryID, netc_tb_ipf_cfge_t *cfg);
299
300 /*!
301 * @brief Query entry in the ingress Port Filter Table.
302 *
303 * @param handle
304 * @param entryID
305 * @param config
306 * @return status_t
307 * @return See @ref netc_cmd_error_t
308 */
309 status_t NETC_QueryIPFTableEntry(netc_cbdr_handle_t *handle, uint32_t entryID, netc_tb_ipf_config_t *config);
310
311 /*!
312 * @brief Delete an entry in the ingress Port Filter Table.
313 *
314 * @param handle
315 * @param entryID
316 * @return status_t
317 * @return See @ref netc_cmd_error_t
318 */
319 status_t NETC_DelIPFTableEntry(netc_cbdr_handle_t *handle, uint32_t entryID);
320
321 /*!
322 * @brief Reset the counter of an ingress port filter Table entry
323 *
324 * @param handle
325 * @param entryID
326 * @return status_t
327 * @return See @ref netc_cmd_error_t
328 */
329 status_t NETC_ResetIPFMatchCounter(netc_cbdr_handle_t *handle, uint32_t entryID);
330
331 /*!
332 * @brief Get the matched count of an ingress port filter Table entry
333 *
334 * @param handle
335 * @param entryID
336 * @param count
337 * @return status_t
338 * @return See @ref netc_cmd_error_t
339 */
340 status_t NETC_GetIPFMatchedCount(netc_cbdr_handle_t *handle, uint32_t entryID, uint64_t *count);
341 /*!
342 * @brief Add entry into Ingress Stream Identification table
343 *
344 * @param handle
345 * @param config
346 * @param entryID
347 * @return status_t
348 * @return See @ref netc_cmd_error_t
349 */
350 status_t NETC_AddISITableEntry(netc_cbdr_handle_t *handle, netc_tb_isi_config_t *config, uint32_t *entryID);
351
352 /*!
353 * @brief Delete an entry in Ingress stream identification table
354 *
355 * @param handle
356 * @param entryID
357 * @return status_t
358 * @return See @ref netc_cmd_error_t
359 */
360 status_t NETC_DelISITableEntry(netc_cbdr_handle_t *handle, uint32_t entryID);
361
362 /*!
363 * @brief Query Ingress Stream Identification table
364 *
365 * @param handle
366 * @param entryID
367 * @param config
368 * @return status_t
369 * @return See @ref netc_cmd_error_t
370 */
371 status_t NETC_QueryISITableEntry(netc_cbdr_handle_t *handle, uint32_t entryID, netc_tb_isi_config_t *config);
372
373 /*!
374 * @brief Query Ingress Stream Identification table with key
375 *
376 * @param handle
377 * @param keye
378 * @param rsp
379 * @return status_t
380 * @return See @ref netc_cmd_error_t
381 */
382 status_t NETC_QueryISITableEntryWithKey(netc_cbdr_handle_t *handle, netc_tb_isi_keye_t *keye, netc_tb_isi_rsp_data_t *rsp);
383
384 /*!
385 * @brief Add or update entry in Ingress Stream table
386 *
387 * @param handle
388 * @param config
389 * @param isAdd
390 * @return status_t
391 * @return See @ref netc_cmd_error_t
392 */
393 status_t NETC_AddOrUpdateISTableEntry(netc_cbdr_handle_t *handle, netc_tb_is_config_t *config, bool isAdd);
394
395 /*!
396 * @brief Query Ingress Stream table
397 *
398 * @param handle
399 * @param entryID
400 * @param config
401 * @return status_t
402 * @return See @ref netc_cmd_error_t
403 */
404 status_t NETC_QueryISTableEntry(netc_cbdr_handle_t *handle, uint32_t entryID, netc_tb_is_config_t *config);
405
406 /*!
407 * @brief Delete an entry in Ingress stream table
408 *
409 * @param handle
410 * @param entryID
411 * @return status_t
412 * @return See @ref netc_cmd_error_t
413 */
414 status_t NETC_DelISTableEntry(netc_cbdr_handle_t *handle, uint32_t entryID);
415
416 /*!
417 * @brief Add entry into ingress stream filter table
418 *
419 * @param handle
420 * @param config
421 * @param entryID
422 * @return status_t
423 * @return See @ref netc_cmd_error_t
424 */
425 status_t NETC_AddISFTableEntry(netc_cbdr_handle_t *handle, netc_tb_isf_config_t *config, uint32_t *entryID);
426
427 /*!
428 * @brief Update entry into ingress stream filter table
429 *
430 * @param handle
431 * @param entryID
432 * @param cfg
433 * @return status_t
434 * @return See @ref netc_cmd_error_t
435 */
436 status_t NETC_UpdateISFTableEntry(netc_cbdr_handle_t *handle, uint32_t entryID, netc_tb_isf_cfge_t *cfg);
437
438 /*!
439 * @brief Delete an entry in Ingress stream filter table
440 *
441 * @param handle
442 * @param entryID
443 * @return status_t
444 * @return See @ref netc_cmd_error_t
445 */
446 status_t NETC_DelISFTableEntry(netc_cbdr_handle_t *handle, uint32_t entryID);
447
448 /*!
449 * @brief Query entry from the Ingress stream filter table
450 *
451 * @param handle
452 * @param keye
453 * @param rsp
454 * @return status_t
455 * @return See @ref netc_cmd_error_t
456 */
457 status_t NETC_QueryISFTableEntry(netc_cbdr_handle_t *handle, netc_tb_isf_keye_t *keye, netc_tb_isf_rsp_data_t *rsp);
458
459 /*!
460 * @brief Add entry in ingress stream count table
461 *
462 * @param handle
463 * @param entryID
464 * @return status_t
465 */
466 status_t NETC_AddISCTableEntry(netc_cbdr_handle_t *handle, uint32_t entryID);
467
468 /*!
469 * @brief Get ingress stream count statistic
470 *
471 * @param handle
472 * @param entryID
473 * @param statistic
474 * @return status_t
475 * @return See @ref netc_cmd_error_t
476 */
477 status_t NETC_GetISCStatistic(netc_cbdr_handle_t *handle, uint32_t entryID, netc_tb_isc_stse_t *statistic);
478
479 /*!
480 * @brief Reset the count of the ingress stream count
481 *
482 * @param handle
483 * @param entryID
484 * @return status_t
485 * @return See @ref netc_cmd_error_t
486 */
487 status_t NETC_ResetISCStatistic(netc_cbdr_handle_t *handle, uint32_t entryID);
488
489 /*!
490 * @brief Add or update entry in stream gate instance table
491 *
492 * @param handle
493 * @param config
494 * @param isAdd
495 * @return status_t
496 * @return See @ref netc_cmd_error_t
497 */
498 status_t NETC_AddOrUpdateSGITableEntry(netc_cbdr_handle_t *handle, netc_tb_sgi_config_t *config, bool isAdd);
499
500 /*!
501 * @brief Delete entry in the stream gate instance table
502 *
503 * @param handle
504 * @param entryID
505 * @return status_t
506 * @return See @ref netc_cmd_error_t
507 */
508 status_t NETC_DelSGITableEntry(netc_cbdr_handle_t *handle, uint32_t entryID);
509
510 /*!
511 * @brief Get statistic of specified stream gate instance table entry
512 *
513 * @param handle
514 * @param entryID
515 * @param statis
516 * @return status_t
517 * @return See @ref netc_cmd_error_t
518 */
519 status_t NETC_GetSGIState(netc_cbdr_handle_t *handle, uint32_t entryID, netc_tb_sgi_sgise_t *statis);
520
521 /*!
522 * @brief Query entry from the stream gate instance table
523 *
524 * @param handle
525 * @param entryID
526 * @param rsp
527 * @return status_t
528 * @return See @ref netc_cmd_error_t
529 */
530 status_t NETC_QuerySGITableEntry(netc_cbdr_handle_t *handle, uint32_t entryID, netc_tb_sgi_rsp_data_t *rsp);
531
532 /*!
533 * @brief Add entry into Stream Gate Control List Table
534 *
535 * @param handle
536 * @param config
537 * @return status_t
538 * @return See @ref netc_cmd_error_t
539 */
540 status_t NETC_AddSGCLTableEntry(netc_cbdr_handle_t *handle, netc_tb_sgcl_gcl_t *config);
541
542 /*!
543 * @brief Delete entry of Stream Gate Control List Table
544 *
545 * @param handle
546 * @param entryID
547 * @return status_t
548 * @return See @ref netc_cmd_error_t
549 */
550 status_t NETC_DelSGCLTableEntry(netc_cbdr_handle_t *handle, uint32_t entryID);
551
552 /*!
553 * @brief Get Stream Gate Control List Table entry gate control list
554 *
555 * @param handle
556 * @param gcl
557 * @param length
558 * @return status_t
559 * @return See @ref netc_cmd_error_t
560 */
561 status_t NETC_GetSGCLGateList(netc_cbdr_handle_t *handle, netc_tb_sgcl_gcl_t *gcl, uint32_t length);
562
563 /*!
564 * @brief Get state (ref count) for Stream Gate Control List table entry
565 *
566 * @param handle
567 * @param entryID
568 * @param state
569 * @return status_t
570 * @return See @ref netc_cmd_error_t
571 */
572 status_t NETC_GetSGCLState(netc_cbdr_handle_t *handle, uint32_t entryID, netc_tb_sgcl_sgclse_t *state);
573
574 /*!
575 * @brief Query entry from the Rate Policer table
576 *
577 * @param handle
578 * @param entryID
579 * @param rsp
580 * @return status_t
581 * @return See @ref netc_cmd_error_t
582 */
583 status_t NETC_QueryRPTableEntry(netc_cbdr_handle_t *handle, uint32_t entryID, netc_tb_rp_rsp_data_t *rsp);
584
585 /*!
586 * @brief Add or update entry in Rate Policer table
587 *
588 * @param handle
589 * @param config
590 * @param cmd
591 * @return status_t
592 * @return See @ref netc_cmd_error_t
593 */
594 status_t NETC_AddOrUpdateRPTableEntry(netc_cbdr_handle_t *handle, netc_tb_rp_config_t *config, netc_tb_cmd_t cmd);
595
596 /*!
597 * @brief Delete entry in the Rate Policer table
598 *
599 * @param handle
600 * @param entryID
601 * @return status_t
602 * @return See @ref netc_cmd_error_t
603 */
604 status_t NETC_DelRPTableEntry(netc_cbdr_handle_t *handle, uint32_t entryID);
605
606 /*!
607 * @brief Get statistic of specified Rate Policer table entry
608 *
609 * @param handle
610 * @param entryID
611 * @param statis
612 * @return status_t
613 * @return See @ref netc_cmd_error_t
614 */
615 status_t NETC_GetRPStatistic(netc_cbdr_handle_t *handle, uint32_t entryID, netc_tb_rp_stse_t *statis);
616
617 /*!
618 * @brief Config the QBV (Time Gate Scheduling)
619 *
620 * @param handle
621 * @param config
622 * @return status_t
623 * @return See @ref netc_cmd_error_t
624 */
625 status_t NETC_ConfigTGSAdminList(netc_cbdr_handle_t *handle, netc_tb_tgs_gcl_t *config);
626
627 /*!
628 * @brief Get time gate table operation list
629 *
630 * @param handle
631 * @param gcl
632 * @param length
633 * @return status_t
634 * @return See @ref netc_cmd_error_t
635 */
636 status_t NETC_GetTGSOperationList(netc_cbdr_handle_t *handle, netc_tb_tgs_gcl_t *gcl, uint32_t length);
637 /*! @} */ // end of netc_hw_table
638 #if !(defined(__GNUC__) || defined(__ICCARM__))
639 #pragma endregion netc_hw_table
640 #endif
641
642 #if defined(__cplusplus)
643 }
644 #endif
645 #endif /* FSL_NETC_HW_H_ */
646