1 /*
2  * Copyright 2024 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef FSL_NETC_MSG_H_
8 #define FSL_NETC_MSG_H_
9 
10 #include "fsl_netc.h"
11 #include "fsl_netc_endpoint.h"
12 
13 #define NETC_MSG_RETURN_CODE(class, code, cookie) (((uint16_t)(class) << 8U) | ((uint16_t)(code) << 4U) | (uint16_t)(cookie))
14 
15 /*!
16  * @brief VSI-PSI message class id
17  */
18 typedef enum _netc_msg_class
19 {
20     /* PSI to VSI only */
21     kNETC_MsgClassDone         = 0x01U,
22     kNETC_MsgClassDenied       = 0x02U,
23     kNETC_MsgClassNotSupport   = 0x03U,
24     kNETC_MsgClassBusy         = 0x04U,
25     kNETC_MsgClassCsumError    = 0x05U,
26     kNETC_MsgClassVersionError = 0x06U,
27     kNETC_MsgClassLenError     = 0x07U,
28     kNETC_MsgClassTimeout      = 0x08U,
29     kNETC_MsgClassDefer        = 0x0fU,
30     /* Others */
31     kNETC_MsgClassMacFilter       = 0x20U,
32     kNETC_MsgClassVlanFilter      = 0x21U,
33     kNETC_MsgClassLinkStatus      = 0x80U,
34     kNETC_MsgClassLinkSpeed       = 0x81U,
35     kNETC_MsgClassTimerSyncStatus = 0xe0U,
36     kNETC_MsgClassIpVersion       = 0xf0U,
37 } netc_msg_class_t;
38 
39 /*!
40  * @brief MAC address filtering class cmd id
41  */
42 typedef enum _netc_msg_mac_filter_cmd
43 {
44     kNETC_MsgMacFilterSetMacAddr    = 0x00U,
45     kNETC_MsgMacFilterAdd           = 0x01U,
46     kNETC_MsgMacFilterDelete        = 0x02U,
47     kNETC_MsgMacFilterSet           = 0x03U,
48     kNETC_MsgMacFilterFlush         = 0x04U,
49     kNETC_MsgMacFilterSetMacPromisc = 0x05U,
50 } netc_msg_mac_filter_cmd_t;
51 
52 /*!
53  * @brief MAC address filtering class specific code
54  */
55 typedef enum _netc_msg_mac_filter_code
56 {
57     kNETC_MsgMacFilterInvalidAddr   = 0x0U, /* Invalid MAC address                                    */
58     kNETC_MsgMacFilterDuplicateAddr = 0x1U, /* Duplicate MAC addr (‘set primary’, ‘add entry’)        */
59     kNETC_MsgMacFilterAddrNotFound  = 0x2U, /* MAC addr not found (‘del entry’)                       */
60     kNETC_MsgMacFilterNoResource    = 0x3U, /* No resource (not enough exact-match entries available) */
61     kNETC_MsgMacFilterNotSupported  = 0x4U, /* Not supported: HT size mismatch                        */
62 } netc_msg_mac_filter_code_t;
63 
64 /*!
65  * @brief VLAN filtering class cmd id
66  */
67 typedef enum _netc_msg_vlan_filter_cmd
68 {
69     kNETC_MsgVlanFilterAdd            = 0x00U,
70     kNETC_MsgVlanFilterDelete         = 0x01U,
71     kNETC_MsgVlanFilterSet            = 0x02U,
72     kNETC_MsgVlanFilterFlush          = 0x03U,
73     kNETC_MsgVlanFilterSetVlanPromisc = 0x04U,
74 } netc_msg_vlan_filter_cmd_t;
75 
76 /*!
77  * @brief VLAN filtering class specific code
78  */
79 typedef enum _netc_msg_vlan_filter_code
80 {
81     kNETC_MsgVlanFilterInvalidVlan   = 0x0U, /* Invalid VLAN                                    */
82     kNETC_MsgVlanFilterDuplicateVlan = 0x1U, /* Duplicate VLAN (‘add entry’)        */
83     kNETC_MsgVlanFilterAddrNotFound  = 0x2U, /* VLAN not found (‘del entry’)                       */
84     kNETC_MsgVlanFilterNoResource    = 0x3U, /* No resource (not enough exact-match entries available) */
85     kNETC_MsgVlanFilterNotSupported  = 0x4U, /* Not supported: HT size mismatch                        */
86 } netc_msg_vlan_filter_code_t;
87 
88 /*!
89  * @brief Get link status class cmd id
90  */
91 typedef enum _netc_msg_link_status_cmd
92 {
93     kNETC_MsgLinkStatusGet          = 0x00U,
94     kNETC_MsgLinkStatusEnableNotify = 0x01U,
95     kNETC_MsgLinkStatusCancelNotify = 0x02U,
96 } netc_msg_link_status_cmd_t;
97 
98 /*!
99  * @brief Get link status class specific code
100  */
101 typedef enum _netc_msg_link_status_code
102 {
103     kNETC_MsgLinkStatusUp   = 0x00U,
104     kNETC_MsgLinkStatusDown = 0x01U,
105 } netc_msg_link_status_code_t;
106 
107 /*!
108  * @brief Get link speed class cmd id
109  */
110 typedef enum _netc_msg_link_speed_cmd
111 {
112     kNETC_MsgLinkSpeedGet          = 0x00U,
113     kNETC_MsgLinkSpeedEnableNotify = 0x01U,
114     kNETC_MsgLinkSpeedCancelNotify = 0x02U,
115 } netc_msg_link_speed_cmd_t;
116 
117 /*!
118  * @brief Get link speed class specific code
119  */
120 typedef enum _netc_msg_link_speed_code
121 {
122     kNETC_MsgLinkSpeedUnKnown    = 0x00U,
123     kNETC_MsgLinkSpeed10HD       = 0x01U,
124     kNETC_MsgLinkSpeed10FD       = 0x02U,
125     kNETC_MsgLinkSpeed100HD      = 0x03U,
126     kNETC_MsgLinkSpeed100FD      = 0x04U,
127     kNETC_MsgLinkSpeed1000       = 0x05U,
128     kNETC_MsgLinkSpeed2500       = 0x06U,
129     kNETC_MsgLinkSpeed5000       = 0x07U,
130     kNETC_MsgLinkSpeed10G        = 0x08U,
131     kNETC_MsgLinkSpeed25G        = 0x09U,
132     kNETC_MsgLinkSpeed50G        = 0x0aU,
133     kNETC_MsgLinkSpeed100G       = 0x0bU,
134     kNETC_MsgLinkSpeedNotSupport = 0x0fU,
135 } netc_msg_link_speed_code_t;
136 
137 /*!
138  * @brief Get timer sync status class cmd id
139  */
140 typedef enum _netc_msg_timer_sync_status_cmd
141 {
142     kNETC_MsgTimerSyncStatusGet = 0x00U,
143 } netc_msg_timer_sync_status_cmd_t;
144 
145 /*!
146  * @brief Get IP version class cmd id
147  */
148 typedef enum _netc_msg_ip_version_cmd
149 {
150     kNETC_MsgIpVersionMJ  = 0x00U,
151     kNETC_MsgIpVersionMN  = 0x01U,
152     kNETC_MsgIpVersionINT = 0x02U,
153     kNETC_MsgIpVersionMNT = 0x03U,
154     kNETC_MsgIpVersionCFG = 0x04U,
155 } netc_msg_ip_version_cmd_t;
156 
157 /*!
158  * @brief VSI-PSI message header format
159  */
160 typedef struct _netc_msg_header
161 {
162     uint16_t crc16;
163     uint8_t classId;
164     uint8_t cmdId;
165     uint8_t protoVer;
166     uint8_t len;
167     uint8_t reserved1;
168     uint8_t cookie;
169     uint8_t reserved2[8];
170 } netc_msg_header_t;
171 
172 /*!
173  * @brief Exact Match table query result
174  */
175 typedef struct _emtable_query_result
176 {
177     uint8_t valid;     /* Valid result or not */
178     uint8_t match;     /* If address matches to one entry */
179     uint16_t siBitMap; /* The siBitMap of mac matched entry */
180     uint16_t index;    /* Index of mac matched entry */
181 } emtable_query_result_t;
182 
183 /*!
184  * @brief NETC PSI receives message from VSI
185  *
186  * @param handle
187  * @param vsi      vsi number.
188  * @param msgInfo  PSI received message from VSI
189  * @return status_t
190  */
191 status_t EP_PsiRxMsg(ep_handle_t *handle, netc_vsi_number_t vsi, netc_psi_rx_msg_t *msgInfo);
192 
193 /*!
194  * @brief NETC processes PSI received message from VSI
195  *
196  * @param handle
197  * @param vsi      vsi number.
198  * @param msgInfo  PSI received message from VSI
199  */
200 void EP_PsiHandleRxMsg(ep_handle_t *handle, uint8_t vsi, netc_psi_rx_msg_t *msgInfo);
201 
202 /*!
203  * @brief NETC notify VSI for link status and speed
204  *
205  * @param handle
206  */
207 void EP_PsiNotifyLink(ep_handle_t *handle);
208 #endif /* FSL_NETC_MSG_H_ */
209