1 /*
2  * Copyright 2020-2023 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef GMAC_IP_HW_ACCESS_H
8 #define GMAC_IP_HW_ACCESS_H
9 
10 /**
11 *   @file
12 *
13 *   @internal
14 *   @addtogroup GMAC_DRIVER GMAC Driver
15 *   @{
16 */
17 
18 #ifdef __cplusplus
19 extern "C"{
20 #endif
21 
22 /*==================================================================================================
23 *                                        INCLUDE FILES
24 * 1) system and project includes
25 * 2) needed interfaces from external units
26 * 3) internal and external interfaces from this unit
27 ==================================================================================================*/
28 #include "Gmac_Ip.h"
29 #include "Gmac_Ip_Device_Registers.h"
30 
31 /*==================================================================================================
32 *                              SOURCE FILE VERSION INFORMATION
33 ==================================================================================================*/
34 #define GMAC_IP_HW_ACCESS_VENDOR_ID                    43
35 #define GMAC_IP_HW_ACCESS_AR_RELEASE_MAJOR_VERSION     4
36 #define GMAC_IP_HW_ACCESS_AR_RELEASE_MINOR_VERSION     7
37 #define GMAC_IP_HW_ACCESS_AR_RELEASE_REVISION_VERSION  0
38 #define GMAC_IP_HW_ACCESS_SW_MAJOR_VERSION             3
39 #define GMAC_IP_HW_ACCESS_SW_MINOR_VERSION             0
40 #define GMAC_IP_HW_ACCESS_SW_PATCH_VERSION             0
41 
42 /*==================================================================================================
43 *                                     FILE VERSION CHECKS
44 ==================================================================================================*/
45 /* Checks against Gmac_Ip.h */
46 #if (GMAC_IP_HW_ACCESS_VENDOR_ID != GMAC_IP_VENDOR_ID)
47     #error "Gmac_Ip_Hw_Access.h and Gmac_Ip.h have different vendor ids"
48 #endif
49 #if (( GMAC_IP_HW_ACCESS_AR_RELEASE_MAJOR_VERSION    != GMAC_IP_AR_RELEASE_MAJOR_VERSION) || \
50      ( GMAC_IP_HW_ACCESS_AR_RELEASE_MINOR_VERSION    != GMAC_IP_AR_RELEASE_MINOR_VERSION) || \
51      ( GMAC_IP_HW_ACCESS_AR_RELEASE_REVISION_VERSION != GMAC_IP_AR_RELEASE_REVISION_VERSION))
52      #error "AUTOSAR Version Numbers of Gmac_Ip_Hw_Access.h and Gmac_Ip.h are different"
53 #endif
54 #if (( GMAC_IP_HW_ACCESS_SW_MAJOR_VERSION != GMAC_IP_SW_MAJOR_VERSION) || \
55      ( GMAC_IP_HW_ACCESS_SW_MINOR_VERSION != GMAC_IP_SW_MINOR_VERSION) || \
56      ( GMAC_IP_HW_ACCESS_SW_PATCH_VERSION != GMAC_IP_SW_PATCH_VERSION))
57     #error "Software Version Numbers of Gmac_Ip_Hw_Access.h and Gmac_Ip.h are different"
58 #endif
59 
60 /* Checks against Gmac_Ip_Device_Registers.h */
61 #if (GMAC_IP_HW_ACCESS_VENDOR_ID != GMAC_IP_DEVICE_REGISTERS_VENDOR_ID)
62     #error "Gmac_Ip_Hw_Access.h and Gmac_Ip_Device_Registers.h have different vendor ids"
63 #endif
64 #if (( GMAC_IP_HW_ACCESS_AR_RELEASE_MAJOR_VERSION    != GMAC_IP_DEVICE_REGISTERS_AR_RELEASE_MAJOR_VERSION) || \
65      ( GMAC_IP_HW_ACCESS_AR_RELEASE_MINOR_VERSION    != GMAC_IP_DEVICE_REGISTERS_AR_RELEASE_MINOR_VERSION) || \
66      ( GMAC_IP_HW_ACCESS_AR_RELEASE_REVISION_VERSION != GMAC_IP_DEVICE_REGISTERS_AR_RELEASE_REVISION_VERSION))
67      #error "AUTOSAR Version Numbers of Gmac_Ip_Hw_Access.h and Gmac_Ip_Device_Registers.h are different"
68 #endif
69 #if (( GMAC_IP_HW_ACCESS_SW_MAJOR_VERSION != GMAC_IP_DEVICE_REGISTERS_SW_MAJOR_VERSION) || \
70      ( GMAC_IP_HW_ACCESS_SW_MINOR_VERSION != GMAC_IP_DEVICE_REGISTERS_SW_MINOR_VERSION) || \
71      ( GMAC_IP_HW_ACCESS_SW_PATCH_VERSION != GMAC_IP_DEVICE_REGISTERS_SW_PATCH_VERSION))
72     #error "Software Version Numbers of Gmac_Ip_Hw_Access.h and Gmac_Ip_Device_Registers.h are different"
73 #endif
74 
75 /*******************************************************************************
76  * Definitions
77  ******************************************************************************/
78 
79 /*!
80  * @brief Management Frame operation type
81  */
82 typedef enum
83 {
84     GMAC_MMFR_OP_WRITE = 0U,
85     GMAC_MMFR_OP_READ
86 } Gmac_Ip_MmfrOpType;
87 
88 /*!
89  * @brief Management Frame information
90  */
91 typedef struct
92 {
93     uint8 PhysAddr;
94     uint16 PhysReg;
95     uint16 MmdAddr;
96     Gmac_Ip_MmfrOpType OpFrameType;
97     uint16 FrameData;
98     boolean SupportedClause45;
99 } Gmac_Ip_ManagementInfo;
100 
101 /*******************************************************************************
102  * Variables
103  ******************************************************************************/
104 #define ETH_43_GMAC_START_SEC_CONST_UNSPECIFIED
105 #include "Eth_43_GMAC_MemMap.h"
106 
107 extern GMAC_Type * const Gmac_apxBases[FEATURE_GMAC_NUM_INSTANCES];
108 
109 extern Gmac_Ip_ChannelType * const Gmac_apxChBases[FEATURE_GMAC_NUM_INSTANCES][FEATURE_GMAC_NUM_CHANNELS];
110 
111 extern Gmac_Ip_QueueType * const Gmac_apxQueueBases[FEATURE_GMAC_NUM_INSTANCES][FEATURE_GMAC_NUM_QUEUES];
112 
113 #define ETH_43_GMAC_STOP_SEC_CONST_UNSPECIFIED
114 #include "Eth_43_GMAC_MemMap.h"
115 
116 #define ETH_43_GMAC_START_SEC_VAR_CLEARED_UNSPECIFIED
117 #include "Eth_43_GMAC_MemMap.h"
118 
119 extern Gmac_Ip_StateType *Gmac_apxState[FEATURE_GMAC_NUM_INSTANCES];
120 
121 #define ETH_43_GMAC_STOP_SEC_VAR_CLEARED_UNSPECIFIED
122 #include "Eth_43_GMAC_MemMap.h"
123 
124 /*******************************************************************************
125  * API
126  ******************************************************************************/
127 #define ETH_43_GMAC_START_SEC_CODE
128 #include "Eth_43_GMAC_MemMap.h"
129 
130 /*!
131  * @brief Initializes a starting reference point for timeout
132  *
133  * @param[out] StartTimeOut    The starting time from which elapsed time is measured
134  * @param[out] ElapsedTimeOut  The elapsed time to be passed to GMAC_TimeoutExpired
135  * @param[out] TimeoutTicksOut The timeout value (in ticks) to be passed to GMAC_TimeoutExpired
136  * @param[in]  TimeoutUs       The timeout value (in microseconds)
137  */
138 void GMAC_StartTimeOut(uint32 *StartTimeOut,
139                        uint32 *ElapsedTimeOut,
140                        uint32 *TimeoutTicksOut,
141                        uint32 TimeoutUs);
142 
143 /*!
144  * @brief Checks for timeout condition.
145  *
146  * @param[in,out] StartTimeInOut    The starting time from which elapsed time is measured
147  * @param[in,out] ElapsedTimeInOut  The accumulated elapsed time from the starting time reference
148  * @param[in]     TimeoutTicks      The timeout limit (in ticks)
149  */
150 boolean GMAC_TimeoutExpired(uint32 *StartTimeInOut,
151                             uint32 *ElapsedTimeInOut,
152                             uint32 TimeoutTicks);
153 
154 /*!
155  * @brief Adds an entry to the hash table filter.
156  *
157  * @param[in] Base The base address of the module
158  * @param[in] Crc The CRC of a hardware address
159  */
160 void GMAC_AddToHashTable(const GMAC_Type * Base,
161                          uint32 Crc);
162 
163 /*!
164  * @brief Removes an entry from the hash table filter.
165  *
166  * @param[in] Base The base address of the module
167  * @param[in] Crc The CRC of a hardware address
168  */
169 void GMAC_RemoveFromHashTable(const GMAC_Type * Base,
170                               uint32 Crc);
171 
172 /*!
173  * @brief Adds a VLAN tag to the VLAN hash table filter.
174  *
175  * @param[in] Base The base address of the module
176  * @param[in] Crc  The CRC of a VLAN tag
177  */
178 void GMAC_AddVlanToHashTable(GMAC_Type * Base,
179                              uint32 Crc);
180 
181 /*!
182  * @brief Removes VLAN tag from the VLAN hash table filter.
183  *
184  * @param[in] Base The base address of the module
185  * @param[in] Crc  The CRC of a VLAN tag
186  */
187 void GMAC_RemoveVlanFromHashTable(GMAC_Type * Base,
188                                   uint32 Crc);
189 
190 /*!
191  * @brief Writes an MII management frame.
192  *
193  * @param[in] Base The base address of the module
194  * @param[in] ManageInfo contains some information:
195  *  physAddr The address of the PHY
196  *  physReg The address of the register to be accessed
197  *  MmdAddr For clause 45, selects the device (MMD)
198  *  OpFrameType The operation type (read/write)
199  *  FrameData Data to be written, ignored if the operation is a read one
200  *  SupportedClause45 True if the management frame is a clause 45 one, false for clause 22
201  * @param[in] TimeoutUs Timeout for the management operation (in microseconds)
202  * @retval GMAC_STATUS_SUCCESS The operation completed successfully.
203  * @retval GMAC_STATUS_TIMEOUT The specified timeout expired before completing the operation.
204  */
205 Gmac_Ip_StatusType GMAC_WriteManagementFrame(GMAC_Type * Base,
206                                              const Gmac_Ip_ManagementInfo *ManageInfo,
207                                              uint32 TimeoutUs);
208 
209 /*!
210  * @brief Reads the data field of a MII management frame.
211  *
212  * @param[in] base The base address of the module
213  * @return The read data
214  */
GMAC_ReadManagementFrameData(const GMAC_Type * Base)215 static inline uint16 GMAC_ReadManagementFrameData(const GMAC_Type * Base)
216 {
217     return (uint16)(Base->MAC_MDIO_DATA & GMAC_MAC_MDIO_DATA_GD_MASK);
218 }
219 
220 #if (FEATURE_GMAC_ASP_ALL || FEATURE_GMAC_ASP_ECC)
221 /*!
222  * @brief Handler for GMAC safety interrupts.
223  *
224  * This handler invokes the installed callback, if available, and clears the
225  * interrupt flags.
226  *
227  * @param[in] Instance Instance number
228  */
229 void GMAC_SafetyIRQHandler(uint8 Instance);
230 #endif
231 
232 /*!
233  * @brief Handler for GMAC common interrupts.
234  *
235  * This handler invokes the installed callback, if available, and clears the
236  * interrupt flags.
237  *
238  * @param[in] Instance Instance number
239  */
240 void GMAC_CommonIRQHandler(uint8 Instance);
241 
242 /*!
243  * @brief Handler for GMAC receive interrupts.
244  *
245  * This handler invokes the installed callback, if available, and clears the
246  * interrupt flags.
247  *
248  * @param[in] Instance Instance number
249  * @param[in] Channel  Channel number
250  */
251 void GMAC_RxIRQHandler(uint8 Instance,
252                        uint8 Channel);
253 
254 /*!
255  * @brief Handler for GMAC transmit interrupts.
256  *
257  * This handler invokes the installed callback, if available, and clears the
258  * interrupt flags.
259  *
260  * @param[in] Instance Instance number
261  * @param[in] Channel Channel number
262  */
263 void GMAC_TxIRQHandler(uint8 Instance,
264                        uint8 Channel);
265 
266 /*!
267  * @brief Gets the power state
268  *
269  * @param[in] Base   The base address of the module
270  * @return  The power state of the controller
271  */
272 Gmac_Ip_PowerStateType GMAC_GetPowerState(const GMAC_Type * Base);
273 
274 /*!
275  * @brief Sets the power state
276  *
277  * @param[in] base       The base address of the module
278  * @param[in] powerState The power state to transition into
279  */
280 void GMAC_SetPowerState(GMAC_Type * Base, Gmac_Ip_PowerStateType PowerState);
281 
282 /*!
283  * @brief Sets the speed of the MII interface.
284  *
285  * @param[in] base  The base address of the module
286  * @param[in] speed The MII speed
287  */
288 void GMAC_SetSpeed(GMAC_Type * Base, Gmac_Ip_SpeedType Speed);
289 
290 /*!
291  * @brief Sets the Tx scheduling algorithm.
292  *
293  * @param[in] base    The base address of the module
294  * @param[in] channel Channel number
295  */
296 void GMAC_SetSchedAlg(GMAC_Type * Base, Gmac_Ip_TxSchedAlgoType SchedAlgo);
297 
298 /*!
299  * @brief Sets the weight or idle slope credit for a specific Tx Queue.
300  *
301  * @param[in] queueBase  The base address of the Tx Queue
302  * @param[in] weight     Queue weight or idle slope credit
303  */
304 void GMAC_SetTxQueueQuantumWeight(Gmac_Ip_QueueType * QueueBase,
305                                   uint32 Weight);
306 
307 /*!
308  * @brief Sets the send slope, high credit and low credit for a specific Tx Queue
309  *
310  * @param[in] queueBase         The base address of the Tx Queue
311  * @param[in] sendSlopeCredit   Queue send slope credit
312  * @param[in] highCredit        Queue high credit limit
313  * @param[in] lowCredit         Queue low credit limit
314  */
315 void GMAC_SetTxQueueCreditBasedShaper(Gmac_Ip_QueueType * QueueBase,
316                                       uint32 SendSlopeCredit,
317                                       uint32 HighCredit,
318                                       sint32 LowCredit);
319 
320 /*!
321  * @brief Sets the operation mode for a Tx Queue.
322  *
323  * @param[in] queueBase  The base address of the Tx Queue
324  * @param[in] queueMode  The operation mode of the Tx Queue
325  * @param[in] queueSize  Queue size in blocks of 256 bytes
326  */
327 void GMAC_SetTxQueueOperationMode(Gmac_Ip_QueueType * QueueBase,
328                                   Gmac_Ip_OperationModeType QueueMode,
329                                   uint32 QueueSize);
330 
331 /*!
332  * @brief Enable store and forward for a specific Tx Queue.
333  * @param[in] queueBase  The base address of the Tx Queue
334  */
335 void GMAC_SetTxStoreAndForward(Gmac_Ip_QueueType * QueueBase);
336 
337 /*!
338  * @brief Sets the Tx threshold value.
339  *
340  * @param[in] queueBase       The base address of the Tx Queue
341  * @param[in] thresholdValue  Threshold value
342  */
343 void GMAC_SetTxThreshold(Gmac_Ip_QueueType * QueueBase,
344                          Gmac_Ip_TxThresholdType ThresholdValue);
345 
346 /*!
347  * @brief Enables the given Rx Queue for generic traffic with the given VLAN priorities.
348  *
349  * @param[in] base         The base address of the module
350  * @param[in] priorityMask VLAN priorities
351  * @param[in] queueNum     Number of the queue
352  */
353 void GMAC_EnableRxQueue(GMAC_Type * Base,
354                         uint8 PriorityMask,
355                         uint8 QueueNum);
356 
357 /*!
358  * @brief Sets the operation mode for an Rx Queue
359  *
360  * @param[in] queueBase  The base address of the Rx Queue
361  * @param[in] queueSize  Queue size in blocks of 256 bytes
362  */
363 void GMAC_SetRxQueueOperationMode(Gmac_Ip_QueueType * QueueBase,
364                                   uint32 QueueSize);
365 
366 /*!
367  * @brief Sets the DMA channel mapping for Rx queues.
368  *
369  * @param[in] base       The base address of the module
370  * @param[in] queuesNum  Number of queues
371  */
372 void GMAC_SetRxQueuesDmaChMap(GMAC_Type * Base,
373                               uint8 QueuesNum);
374 
375 /*!
376  * @brief Sets VLAN Tag inverse match.
377  *
378  * @param[in] base The base address of the module
379  * @param[in] enable   Enables/Disables VLAN Tag inverse filtering
380  */
381 void GMAC_SetVlanTagInvMatch(GMAC_Type * Base, boolean Enable);
382 
383 /*!
384  * @brief Sets MAC_VLAN_Tag_Data register with Rx matching relevant data.
385  *
386  * @param[in] base     The base address of the module
387  * @param[in] enable   Enables/Disables VLAN Tag inverse filtering
388  */
389 void GMAC_SetVlanTagDataRxMatch(GMAC_Type * Base,
390                                 boolean EnInnerVlanMatch,
391                                 boolean EnSvlanMatch,
392                                 boolean DisVlanTypeMatch,
393                                 boolean En12bitMatch);
394 
395 #if (FEATURE_GMAC_VLAN_RX_FILTERS_NUM > 0U)
396 /*!
397  * @brief Read a VLAN Tag Rx filter.
398  *
399  * @param[in]  base               The base address of the module
400  * @param[in]  filterIdx          Index of the VLAN filter
401  * @param[in]  timeoutUs          Timeout value (in microseconds)
402  * @param[out] vlanTag            Vlan Tag configured for the selcted Rx filter
403  * @retval GMAC_STATUS_SUCCESS    The filter was successfully read.
404  * @retval GMAC_STATUS_TIMEOUT    The filter could not be read before expiration
405  *                                of timeout.
406  */
407 Gmac_Ip_StatusType GMAC_ReadVlanTagRxFilter(GMAC_Type * Base,
408                                            uint8 FilterIdx,
409                                            uint16 * VlanTag);
410 #endif
411 
412 #define ETH_43_GMAC_STOP_SEC_CODE
413 #include "Eth_43_GMAC_MemMap.h"
414 
415 
416 #ifdef __cplusplus
417 }
418 #endif
419 
420 /** @} */
421 
422 #endif /* GMAC_IP_HW_ACCESS_H */
423