1 /*
2  * Copyright 2020-2023 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef GMAC_IP_H
8 #define GMAC_IP_H
9 
10 /**
11 *   @file
12 *
13 *   @addtogroup GMAC_DRIVER GMAC Driver
14 *   @{
15 */
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 /*==================================================================================================
22 *                                        INCLUDE FILES
23 * 1) system and project includes
24 * 2) needed interfaces from external units
25 * 3) internal and external interfaces from this unit
26 ==================================================================================================*/
27 #include "Gmac_Ip_Types.h"
28 #include "Gmac_Ip_Cfg.h"
29 
30 /*==================================================================================================
31 *                              SOURCE FILE VERSION INFORMATION
32 ==================================================================================================*/
33 #define GMAC_IP_VENDOR_ID                      43
34 #define GMAC_IP_AR_RELEASE_MAJOR_VERSION       4
35 #define GMAC_IP_AR_RELEASE_MINOR_VERSION       7
36 #define GMAC_IP_AR_RELEASE_REVISION_VERSION    0
37 #define GMAC_IP_SW_MAJOR_VERSION               3
38 #define GMAC_IP_SW_MINOR_VERSION               0
39 #define GMAC_IP_SW_PATCH_VERSION               0
40 
41 /*==================================================================================================
42 *                                     FILE VERSION CHECKS
43 ==================================================================================================*/
44 /* Checks against Gmac_Ip_Types.h */
45 #if (GMAC_IP_VENDOR_ID != GMAC_IP_TYPES_VENDOR_ID)
46     #error "Gmac_Ip.h and Gmac_Ip_Types.h have different vendor ids"
47 #endif
48 #if (( GMAC_IP_AR_RELEASE_MAJOR_VERSION    != GMAC_IP_TYPES_AR_RELEASE_MAJOR_VERSION) || \
49      ( GMAC_IP_AR_RELEASE_MINOR_VERSION    != GMAC_IP_TYPES_AR_RELEASE_MINOR_VERSION) || \
50      ( GMAC_IP_AR_RELEASE_REVISION_VERSION != GMAC_IP_TYPES_AR_RELEASE_REVISION_VERSION))
51      #error "AUTOSAR Version Numbers of Gmac_Ip.h and Gmac_Ip_Types.h are different"
52 #endif
53 #if (( GMAC_IP_SW_MAJOR_VERSION != GMAC_IP_TYPES_SW_MAJOR_VERSION) || \
54      ( GMAC_IP_SW_MINOR_VERSION != GMAC_IP_TYPES_SW_MINOR_VERSION) || \
55      ( GMAC_IP_SW_PATCH_VERSION != GMAC_IP_TYPES_SW_PATCH_VERSION))
56     #error "Software Version Numbers of Gmac_Ip.h and Gmac_Ip_Types.h are different"
57 #endif
58 
59 /* Checks against Gmac_Ip_Cfg.h */
60 #if (GMAC_IP_VENDOR_ID != GMAC_IP_CFG_VENDOR_ID)
61     #error "Gmac_Ip.h and Gmac_Ip_Cfg.h have different vendor ids"
62 #endif
63 #if (( GMAC_IP_AR_RELEASE_MAJOR_VERSION    != GMAC_IP_CFG_AR_RELEASE_MAJOR_VERSION) || \
64      ( GMAC_IP_AR_RELEASE_MINOR_VERSION    != GMAC_IP_CFG_AR_RELEASE_MINOR_VERSION) || \
65      ( GMAC_IP_AR_RELEASE_REVISION_VERSION != GMAC_IP_CFG_AR_RELEASE_REVISION_VERSION))
66      #error "AUTOSAR Version Numbers of Gmac_Ip.h and Gmac_Ip_Cfg.h are different"
67 #endif
68 #if (( GMAC_IP_SW_MAJOR_VERSION != GMAC_IP_CFG_SW_MAJOR_VERSION) || \
69      ( GMAC_IP_SW_MINOR_VERSION != GMAC_IP_CFG_SW_MINOR_VERSION) || \
70      ( GMAC_IP_SW_PATCH_VERSION != GMAC_IP_CFG_SW_PATCH_VERSION))
71     #error "Software Version Numbers of Gmac_Ip.h and Gmac_Ip_Cfg.h are different"
72 #endif
73 
74 
75 /*******************************************************************************
76  * GLOBAL VARIABLE DECLARATIONS
77  ******************************************************************************/
78 #define ETH_43_GMAC_START_SEC_CONFIG_DATA_UNSPECIFIED
79 #include "Eth_43_GMAC_MemMap.h"
80 
81 GMAC_CONFIG_EXT
82 
83 #define ETH_43_GMAC_STOP_SEC_CONFIG_DATA_UNSPECIFIED
84 #include "Eth_43_GMAC_MemMap.h"
85 
86 /*******************************************************************************
87  * API
88  ******************************************************************************/
89 #define ETH_43_GMAC_START_SEC_CODE
90 #include "Eth_43_GMAC_MemMap.h"
91 
92 /*!
93  * @name Initialization and De-initialization
94  * @{
95  */
96 
97 /*!
98  * @brief Initializes the GMAC module
99  *
100  * This function initializes and enables the GMAC module, configuring receive and transmit control
101  * settings, the receive and transmit descriptors rings, and the MAC physical address.
102  *
103  * Note: All untagged packets will be received by ring 0 (zero). VLAN tagged
104  * packets are routed depending on the VLAN Tag Priority field according to
105  * the provided configuration.
106  *
107  * @param[in] instance Instance number
108  * @param[in] config Pointer to the module configuration structure
109  *
110  * @retval GMAC_STATUS_SUCCESS The initialization was successful.
111  * @retval GMAC_STATUS_TIMEOUT The DMA subsystem reset could not complete.
112  */
113 Gmac_Ip_StatusType Gmac_Ip_Init(uint8 Instance,
114                                 const Gmac_CtrlConfigType *Config);
115 
116 /*!
117  * @brief Deinitializes the GMAC module
118  *
119  * This function disables the interrupts and then disables the GMAC module.
120  *
121  * @param[in] instance Instance number
122  */
123 void Gmac_Ip_Deinit(uint8 Instance);
124 
125 /*!
126  * @brief Gets the current power state of the GMAC module
127  *
128  * @param[in] instance Instance number
129  * @return Gmac_Ip_PowerStateType The power state of the controller
130  */
131 Gmac_Ip_PowerStateType Gmac_Ip_GetPowerState(uint8 Instance);
132 
133 /*!
134  * @brief Sets the power state of the GMAC module
135  *
136  * @param[in] instance   Instance number
137  * @param[in] powerState Power state to transition into
138  */
139 void Gmac_Ip_SetPowerState(uint8 Instance, Gmac_Ip_PowerStateType PowerState);
140 
141 /*!
142  * @brief Enables all configured transmit and receive buffers and then enables the controller
143  *
144  * @param[in] instance   Instance number
145  */
146 void Gmac_Ip_EnableController(uint8 Instance);
147 
148 /*!
149  * @brief Disables the controller and resets all the configured transmit and receive buffers
150  *
151  * Warning: This function ignores all pending transmission and reception requests
152  *
153  * @param[in] instance   Instance number
154  *
155  * @retval GMAC_STATUS_SUCCESS Tthe controller was successfully disabled.
156  * @retval GMAC_STATUS_TIMEOUT Tthe underlying MTL queues could not be flushed.
157  */
158 Gmac_Ip_StatusType Gmac_Ip_DisableController(uint8 Instance);
159 
160 /*!
161  * @brief Sets the speed of the MII interface
162  *
163  * @param[in] instance Instance number
164  * @param[in] speed MII speed
165  */
166 void Gmac_Ip_SetSpeed(uint8 Instance, Gmac_Ip_SpeedType Speed);
167 
168 /*!
169  * @brief Provides a transmit buffer to be used by the application for transmission.
170  *
171  * This function provides an internal buffer which can further be used by the application
172  * to store the transmit data.
173  *
174  * Note: The buffer will be marked as locked and won't be released until after a call to
175  * Gmac_Ip_GetTransmitStatus for the same buffer returns GMAC_STATUS_SUCCESS.
176  *
177  * Important: The driver does not ensure synchronization between different threads trying
178  * to get a buffer at the same time. This synchronization shall be implemented by the
179  * application.
180  *
181  * @param[in]     instance Instance number
182  * @param[in]     ring   Ring number
183  * @param[in,out] buff   In:  Buffer containing the desired length
184  *                       Out: Buffer containing the granted length or available length in case of overflow.
185  * @param[out]    buffId Index of the buffer (descriptor) within the ring.
186  *                       If this information is not needed, this parameter should be NULL_PTR.
187  * @retval GMAC_STATUS_SUCCESS The buffer has been successfully locked.
188  * @retval GMAC_STATUS_TX_BUFF_BUSY All buffers are currently in use.
189  * @retval GMAC_STATUS_TX_BUFF_OVERFLOW The requested buffer length cannot be granted.
190  */
191 Gmac_Ip_StatusType Gmac_Ip_GetTxBuff(uint8 Instance,
192                                      uint8 Ring,
193                                      Gmac_Ip_BufferType * Buff,
194                                      uint16 * BuffId);
195 
196 /*!
197  * @brief Sends an Ethernet frame
198  *
199  * This function sends an Ethernet frame, contained in the buffer received as parameter.
200  *
201  * Note: Since the transmission of the frame is not complete when this function returns,
202  * the application must not change/alter/re-use the provided buffer until after a call
203  * to Gmac_Ip_GetTransmitStatus for the same buffer returns GMAC_STATUS_SUCCESS.
204  *
205  * Important: The driver does not ensure synchronization between different threads trying
206  * to send a frame at the same time. This synchronization shall be implemented by the
207  * application.
208  *
209  * @param[in] instance Instance number
210  * @param[in] ring The ring number
211  * @param[in] buff The buffer containing the frame
212  * @param[in] options Configuration options applicable to this buffer's transmission only.
213  * Can be NULL_PTR, if no special option is required.
214  * @retval GMAC_STATUS_SUCCESS       The frame was successfully enqueued for transmission.
215  * @retval GMAC_STATUS_TX_QUEUE_FULL There is no available space for the frame in the queue.
216  */
217 Gmac_Ip_StatusType Gmac_Ip_SendFrame(uint8 Instance,
218                                      uint8 Ring,
219                                      const Gmac_Ip_BufferType * Buff,
220                                      const Gmac_Ip_TxOptionsType * Options);
221 
222 /*!
223  * @brief Sends an Ethernet frame composed out of multiple buffers (not necessarily contiguous)
224  *
225  * This function sends an Ethernet frame contained in the buffers received as parameter.
226  *
227  * Note: Since the transmission of the frame is not complete when this function returns,
228  * the application must not change/alter/re-use the provided buffers until after a call
229  * to Gmac_Ip_GetTransmitStatus for the same buffer returns GMAC_STATUS_SUCCESS.
230  *
231  * Important: The driver does not ensure synchronization between different threads trying
232  * to send a frame at the same time. This synchronization shall be implemented by the
233  * application.
234  *
235  * @param[in] Instance   Instance number
236  * @param[in] Ring       The ring number
237  * @param[in] Buffers    The contiguous buffer array composing the frame
238  * @param[in] Options    Configuration options applied to the transmitted frame.
239  *                       Must be different from NULL_PTR.
240  * @param[in] NumBuffers The size of the Buffers array
241  * @retval GMAC_STATUS_SUCCESS       The frame was successfully enqueued for transmission.
242  * @retval GMAC_STATUS_TX_QUEUE_FULL There is no available space for the frame in the queue.
243  */
244 Gmac_Ip_StatusType Gmac_Ip_SendMultiBufferFrame(uint8 Instance,
245                                                 uint8 Ring,
246                                                 const Gmac_Ip_BufferType Buffers[],
247                                                 const Gmac_Ip_TxOptionsType *Options,
248                                                 uint32 NumBuffers);
249 
250 /*!
251  * @brief Provides a transmit buffer to be used by the application for transmission.
252  *
253  * This function will verify if there are enough descriptors free and that each of
254  * the descriptors can hold the parts of the frame to be send using Gmac_Ip_SendMultiBufferFrame.
255  *
256  * Note: This function will only return the first buffer descriptor index starting with which the
257  * multi buffer frame can be sent.
258  *
259  * Important: This function is meant for internal use only and will be called from an upper layer to get
260  * the first buffer descriptor index from a sequence of buffers that will be used for sending a
261  * multi buffer frame.
262  *
263  * @param[in]     Instance     Instance number
264  * @param[in]     ring          Ring number
265  * @param[in]     NumBuffers    Number of buffers
266  * @param[in]     BufferLength  List with the length of each chunk of the frame
267  * @param[out]    buffId        Index of the buffer (descriptor) within the ring.
268  * @retval GMAC_STATUS_SUCCESS The buffer has been successfully locked.
269  * @retval GMAC_STATUS_TX_BUFF_BUSY All buffers are currently in use for the current ring.
270  * @retval GMAC_STATUS_TX_BUFF_OVERFLOW The requested buffer length cannot be granted.
271  * @retval GMAC_STATUS_INVALID_FRAME_LENGTH The buffer length is smaller than minium of frame length.
272  */
273 Gmac_Ip_StatusType Gmac_Ip_GetTxMultiBuff(uint8 Instance,
274                                                   uint8 ring,
275                                                   uint16 NumBuffers,
276                                                   const uint16 BufferLength[],
277                                                   uint16 *buffId);
278 
279 /*!
280  * @brief Reads a received Ethernet frame
281  *
282  * This function reads the first received Ethernet frame in the Rx queue. The buffer received
283  * as parameter will be updated by the driver and the .data field will point to a memory area
284  * containing the frame data.
285  *
286  * Note: Once the application finished processing the buffer, it could be reused by the
287  * driver for further receptions by invoking Gmac_Ip_ProvideRxBuff.
288  *
289  * Important: The driver does not ensure synchronization between different threads trying
290  * to read a frame at the same time. This synchronization shall be implemented by the
291  * application.
292  *
293  * @param[in]  instance Instance number
294  * @param[in]  ring The ring number
295  * @param[out] buff The buffer containing the frame
296  * @param[out] info Enhanced information related to the data contained by this receive buffer.
297  * If this information is not needed, this parameter should be NULL_PTR.
298  * @retval GMAC_STATUS_SUCCESS        A frame was successfully read.
299  * @retval GMAC_STATUS_RX_QUEUE_EMPTY There is no available frame in the queue.
300  */
301 Gmac_Ip_StatusType Gmac_Ip_ReadFrame(uint8 Instance,
302                                      uint8 Ring,
303                                      Gmac_Ip_BufferType * Buff,
304                                      Gmac_Ip_RxInfoType * Info);
305 
306 /*!
307  * @brief Provides a receive buffer to be used by the driver for reception.
308  *
309  * This function provides a buffer which can further be used by the reception mechanism
310  * in order to store the received data.
311  *
312  * Note: The application can either provide a buffer previously obtained in a Gmac_Ip_ReadFrame
313  * call (when it is no longer needed after being fully processed), or allocate a new buffer.
314  * The former approach is recommended as it has a simpler usage model and re-uses the same initial
315  * memory range for the entire driver lifetime operation. The later approach could provide more
316  * flexibility, but since it involves constant memory free/alloc operations it is only recommended
317  * with an efficient pool-based memory allocator.
318  *
319  * Important: The driver does not ensure synchronization between different threads trying
320  * to provide a buffer at the same time. This synchronization shall be implemented by the
321  * application.
322  *
323  * Important: The application is responsible for providing one Rx buffer for every frame it
324  * receives, otherwise the reception ring can fill-up, affecting further reception.
325  *
326  * Usage example:
327  *
328  * stat = Gmac_Ip_ReadFrame(INST_GMAC1, 0U, &rxBuff);
329  *
330  * if (stat == GMAC_STATUS_SUCCESS)
331  * {
332  *     process_buffer(&rxBuff);
333  *     Gmac_Ip_ProvideRxBuff(INST_GMAC1, 0U, &rxBuff);
334  * }
335  *
336  * @param[in] instance Instance number
337  * @param[in] ring The ring number
338  * @param[in] buff The buffer to be added to the reception ring
339  */
340 void Gmac_Ip_ProvideRxBuff(uint8 Instance,
341                            uint8 Ring,
342                            const Gmac_Ip_BufferType * Buff);
343 
344 /*!
345  * @brief Checks if there are more frames available in the given queue
346  *
347  * This function takes a peek at the given Rx queue to check if there are more Ethernet
348  * frames to be received. Its intended usage is to provide this information without
349  * also extracting the frame as "Gmac_Ip_ReadFrame".
350  *
351  * @param[in]  instance Instance number
352  * @param[in]  ring The ring number
353  * @retval TRUE  There is an available frame in the queue.
354  * @retval FALSE There is no available frame in the queue.
355  */
356 boolean Gmac_Ip_IsFrameAvailable(uint8 Instance,
357                                  uint8 Ring);
358 
359 /*!
360  * @brief Checks if the transmission of a buffer is complete.
361  *
362  * This function checks if the transmission of the given buffer is complete.
363  *
364  * Note: If the buffer is not found in the Tx ring, the function will return GMAC_STATUS_BUFF_NOT_FOUND.
365  *
366  * @param[in]  instance Instance number
367  * @param[in]  ring The ring number
368  * @param[in]  buff The transmit buffer for which the status shall be checked
369  * @param[out] info Extended information related to the buffer. If this information is not needed,
370  * this parameter should be NULL_PTR.
371  * @retval GMAC_STATUS_BUSY            The frame is still enqueued for transmission.
372  * @retval GMAC_STATUS_BUFF_NOT_FOUND  The buffer was not found in the Tx queue.
373  * @retval GMAC_STATUS_SUCCESS         Otherwise.
374  */
375 Gmac_Ip_StatusType Gmac_Ip_GetTransmitStatus(uint8 Instance,
376                                              uint8 Ring,
377                                              const Gmac_Ip_BufferType * Buff,
378                                              Gmac_Ip_TxInfoType * Info);
379 void Gmac_Ip_SetRxExternalBuffer(uint8 Instance,
380                            uint8 Ring,
381                            const Gmac_Ip_BufferType * Buff);
382 /*!
383  * @brief Gets statistics from the specified counter
384  *
385  * @param[in] instance Instance number
386  * @param[in] counter The counter to be read
387  * @return The value of the requested counter
388  */
389 uint32 Gmac_Ip_GetCounter(uint8 Instance,
390                           Gmac_Ip_CounterType Counter);
391 
392 /*!
393  * @brief Enables the MDIO interface
394  *
395  * @param[in] instance Instance number
396  * @param[in] miiPreambleDisabled Enables/disables prepending a preamble to the MII management frame.
397  * @param[in] clock provide module
398  */
399 void Gmac_Ip_EnableMDIO(uint8 Instance,
400                         boolean MiiPreambleDisabled,
401                         uint32 ModuleClk);
402 
403 /*!
404  * @brief Reads the selected register of the PHY
405  *
406  * @param[in]  instance Instance number
407  * @param[in]  phyAddr PHY device address
408  * @param[in]  phyReg PHY register address
409  * @param[out] data Data read from the PHY
410  * @param[in] timeoutMs Timeout for the read operation (in milliseconds)
411  * @retval GMAC_STATUS_SUCCESS The operation completed successfully.
412  * @retval GMAC_STATUS_TIMEOUT The specified timeout expired before completing the operation.
413  */
414 Gmac_Ip_StatusType Gmac_Ip_MDIORead(uint8 Instance,
415                                     uint8 PhyAddr,
416                                     uint8 PhyReg,
417                                     uint16 *Data,
418                                     uint32 TimeoutMs);
419 
420 /*!
421  * @brief Writes the selected register of the PHY
422  *
423  * @param[in] instance Instance number
424  * @param[in] phyAddr PHY device address
425  * @param[in] phyReg PHY register address
426  * @param[in] data Data to be written in the specified register of the PHY
427  * @param[in] timeoutMs Timeout for the write operation (in milliseconds)
428  * @retval GMAC_STATUS_SUCCESS The operation completed successfully.
429  * @retval GMAC_STATUS_TIMEOUT The specified timeout expired before completing the operation.
430  */
431 Gmac_Ip_StatusType Gmac_Ip_MDIOWrite(uint8 Instance,
432                                      uint8 PhyAddr,
433                                      uint8 PhyReg,
434                                      uint16 Data,
435                                      uint32 TimeoutMs);
436 
437 /*!
438  * @brief Reads a register of the specified MMD in a PHY device
439  *
440  * @param[in]  instance Instance number
441  * @param[in]  phyAddr PHY device address
442  * @param[in]  mmd The MMD index of the target register
443  * @param[in]  phyReg PHY register address
444  * @param[out] data Data read from the PHY
445  * @param[in] timeoutMs Timeout for the read operation (in milliseconds)
446  * @retval GMAC_STATUS_SUCCESS The operation completed successfully.
447  * @retval GMAC_STATUS_TIMEOUT The specified timeout expired before completing the operation.
448  */
449 Gmac_Ip_StatusType Gmac_Ip_MDIOReadMMD(uint8 Instance,
450                                        uint8 PhyAddr,
451                                        uint8 Mmd,
452                                        uint16 PhyReg,
453                                        uint16 *Data,
454                                        uint32 TimeoutMs);
455 
456 /*!
457  * @brief Writes a register of the specified MMD in a PHY device
458  *
459  * @param[in] instance Instance number
460  * @param[in] phyAddr PHY device address
461  * @param[in] mmd The MMD index of the target register
462  * @param[in] phyReg PHY register address
463  * @param[in] data Data to be written in the specified register of the PHY
464  * @param[in] timeoutMs Timeout for the write operation (in milliseconds)
465  * @retval GMAC_STATUS_SUCCESS The operation completed successfully.
466  * @retval GMAC_STATUS_TIMEOUT The specified timeout expired before completing the operation.
467  */
468 Gmac_Ip_StatusType Gmac_Ip_MDIOWriteMMD(uint8 Instance,
469                                         uint8 PhyAddr,
470                                         uint8 Mmd,
471                                         uint16 PhyReg,
472                                         uint16 Data,
473                                         uint32 TimeoutMs);
474 
475 /*!
476  * @brief Configures the physical address of the MAC
477  *
478  * @param[in] instance Instance number
479  * @param[in] macAddr The MAC address to be configured
480  */
481 void Gmac_Ip_SetMacAddr(uint8 Instance,
482                         const uint8 *MacAddr);
483 
484 /*!
485  * @brief Gets the physical address of the MAC
486  *
487  * @param[in]  instance Instance number
488  * @param[out] macAddr The physical address of the MAC
489  */
490 void Gmac_Ip_GetMacAddr(uint8 Instance,
491                         uint8 *MacAddr);
492 /*!
493  * @brief Initialize time aware shaper
494  *
495  * @param[in]  instance Instance number
496  * @param[in]  Parameters of controller will be used.
497  * return GMAC_STATUS_SUCCESS write/read to Gate control registers successfully
498  * return GMAC_STATUS_TIMEOUT write/read to Gate control registers failed
499  */
500 Gmac_Ip_StatusType Gmac_Ip_TxTimeAwareShaperInit(uint8 Instance,
501                                                 const Gmac_CtrlConfigType *Config);
502 
503 /*!
504  * @brief Gets a mask of the common interrupt events which occurred.
505  *
506  * @param[in] instance Instance number
507  * @return A logical OR of "Gmac_Ip_InterruptType"
508  */
509 uint32 Gmac_Ip_GetInterruptFlags(uint8 Instance);
510 
511 
512 /*!
513  * @brief Gets a mask of the interrupt events associated to a channel which occurred.
514  *
515  * @param[in] instance Instance number
516  * @param[in] channel Channel number
517  * @return A logical OR of "Gmac_Ip_ChInterruptType"
518  */
519 uint32 Gmac_Ip_GetChInterruptFlags(uint8 Instance,
520                                    uint8 Channel);
521 
522 /*!
523  * @brief Enables/Disables forwarding of the broadcast traffic.
524  *
525  * @param[in]  instance Instance number
526  * @param[in]  enable   If true, the application will receive all the broadcast
527  * traffic; if false, it stops forwarding this kind of traffic.
528  */
529 void Gmac_Ip_SetBroadcastForwardAll(uint8 Instance,
530                                     boolean Enable);
531 
532 /*!
533  * @brief Enables/Disables forwarding of the multicast traffic, irrespective of
534  * the destination MAC address.
535  *
536  * @param[in]  instance Instance number
537  * @param[in]  enable If true, the application will receive all the multicast
538  * traffic; if false, stops forwarding this kind of traffic.
539  */
540 void Gmac_Ip_SetMulticastForwardAll(uint8 Instance,
541                                     boolean Enable);
542 
543 /*!
544  * @brief Enables/Disables hash filtering for unicast traffic.
545  *
546  * Note: When the hash filter is disabled, the addresses are passed through the
547  * perfect filter. By default, the perfect filter contains the hardware address
548  * configured when the MAC module is initialized. This address is always used
549  * for destination address filtering. Optionally, a second filter can be enabled
550  * by the means of Gmac_Ip_SetAddrPerfectFilter() function.
551  *
552  * @param[in]  instance Instance number
553  * @param[in]  enable   If true, the hash filtering for unicast destination
554  * addresses is enabled; if false, the hash filtering for such traffic is
555  * disabled.
556  */
557 void Gmac_Ip_SetUnicastHashFilter(uint8 Instance,
558                                   boolean Enable);
559 
560 /*!
561  * @brief Enables/Disables hash filtering for multicast traffic.
562  *
563  * Note: When the hash filter is disabled, the addresses are passed through the
564  * perfect filter. By default, the perfect filter contains the hardware address
565  * configured when the MAC module is initialized. This address is always used
566  * for destination address filtering. Optionally, a second filter can be enabled
567  * by the means of Gmac_Ip_SetAddrPerfectFilter() function.
568  *
569  * @param[in]  instance Instance number
570  * @param[in]  enable   If true, the hash filtering for multicast destination
571  * addresses is enabled; if false, the hash filtering for such traffic is
572  * disabled.
573  */
574 void Gmac_Ip_SetMulticastHashFilter(uint8 Instance,
575                                     boolean Enable);
576 
577 /*!
578  * @brief Enables/Disables either hash or perfect filters. If the destination
579  * address of an incoming packet passes either the perfect filter or the hash
580  * filter, the packet is forwarded to the application.
581  *
582  * Note: When the hash filter is disabled, the addresses are passed through the
583  * perfect filter. By default, the perfect filter contains the hardware address
584  * configured when the MAC module is initialized. This address is always used
585  * for destination address filtering. Optionally, a second filter can be enabled
586  * by the means of Gmac_Ip_SetAddrPerfectFilter() function.
587  *
588  * @param[in]  instance Instance number
589  * @param[in]  enable   If true, the hash filtering and perfect filtering for
590  * destination addresses are enabled; if false, only one filtering option is
591  * enabled, depending on unicast/multicast hash filter settings.
592  */
593 void Gmac_Ip_SetHashOrPerfectFilter(uint8 Instance,
594                                     boolean Enable);
595 
596 /*!
597  * @brief Adds a hardware address to the hash filter. The destination address of
598  * an incoming packet is passed through CRC logic and then compared to the
599  * entries in the hash table.
600  *
601  * @param[in]  instance Instance number
602  * @param[in]  macAddr  The physical address
603  */
604 void Gmac_Ip_AddDstAddrToHashFilter(uint8 Instance,
605                                     const uint8 *MacAddr);
606 
607 /*!
608  * @brief Removes a hardware address from the hash filter. The destination
609  * address of an incoming packet is passed through CRC logic and then compared
610  * to the entries in the hash table.
611  *
612  * @param[in]  instance Instance number
613  * @param[in]  macAddr  The physical address
614  */
615 void Gmac_Ip_RemoveDstAddrFromHashFilter(uint8 Instance,
616                                          const uint8 *MacAddr);
617 
618 /*!
619  * @brief Sets the second destination/source address perfect filter.
620  *
621  * Note: By default, the perfect filter contains the hardware address
622  * configured when the MAC module is initialized. This address is always used
623  * for destination address filtering. Optionally, a second filter
624  * can be enabled by the means of this function. This filter allows the
625  * selection of destination or source address checking and group filtering.
626  * Only one address can be configured and it's respective mask for group
627  * filtering. The mask is 6 bits long and is used for comparing each of the MAC
628  * Address bytes. When set high, the MAC does not compare the corresponding byte
629  * of received destination address or source address with the configured MAC
630  * address. You can filter a group of addresses by masking one or more bytes of
631  * the address. When configuring the source address inverse filter, all the traffic
632  * that matches the configured source address will be rejected and the traffic that
633  * does not match the configured source address is accepted. The source address filter
634  * (either normal or inverse) result and the destination address filter result are
635  * AND'ed to decide whether the packet to be accepted. This means that the packet is
636  * dropped if either filter fails. The packet is accepted only if the packet passes
637  * both filters.
638  *
639  * @param[in]  instance  Instance number
640  * @param[in]  macAddr   The physical address
641  * @param[in]  mask      Group filter mask
642  * @param[in]  addrType  Selects between destination address filter, source
643  * address filter or source address inverse filter
644  * @param[in]  enable    If true, the application will receive all the traffic
645  * matching the selected filter; if false, it stops forwarding this kind of traffic.
646  */
647 void Gmac_Ip_SetAddrPerfectFilter(uint8 Instance,
648                                   const uint8 *MacAddr,
649                                   const uint8 Mask,
650                                   const Gmac_Ip_MacAddrFilterType AddrType,
651                                   boolean Enable);
652 
653 #if FEATURE_GMAC_ARP_EN
654 /*!
655  * @brief Enables/Disables ARP offloading.
656  *
657  * @param[in]  instance Instance number
658  * @param[in]  dstAddr The IPv4 destination address used for ARP offloading
659  * @param[in]  enable If true, the MAC can recognize an incoming ARP request and
660  * schedules the ARP response for transmission. It also forwards the ARP packet
661  * to the application; if false, the MAC receiver does not recognize any ARP
662  * packet and indicates them as Type frame.
663  */
664 void Gmac_Ip_SetArpOffloading(uint8 Instance,
665                               const uint8 *DstAddr,
666                               boolean Enable);
667 #endif /* FEATURE_GMAC_ARP_EN */
668 
669 /*!
670  * @brief Enable and set VLAN control for transmitted and received packets.
671  *
672  * @param[in]  instance      Instance number
673  * @param[in]  vlanConfig    VLAN configuration structure
674  */
675 void Gmac_Ip_EnableVlan(uint8 Instance,
676                         const Gmac_Ip_VlanConfigType * VlanConfig);
677 
678 /*!
679  * @brief Sets outer VLAN type and tag to be inserted by a particular
680  * transmission ring.
681  *
682  * @param[in]  instance            Instance number
683  * @param[in]  ring                Ring number
684  * @param[in]  vlanType            VLAN type (S-VLAN or C-VLAN) to be used
685  * @param[in]  vlanTag             Value for the VLAN tag to be used
686  * @retval GMAC_STATUS_SUCCESS     The ring was successfully configured.
687  * @retval GMAC_STATUS_BUSY        The resource is busy and the ring could not be
688  *                                 configured.
689  * @retval GMAC_STATUS_TIMEOUT     The ring configuration could not complete before
690  *                                 expiration of timeout.
691  * @retval GMAC_STATUS_UNSUPPORTED The function was called when VLAN replacement
692  *                                 option was configured.
693  */
694 Gmac_Ip_StatusType Gmac_Ip_SetTxOuterVlanTagForInsertion(uint8 Instance,
695                                                          uint8 Ring,
696                                                          Gmac_Ip_VlanType VlanType,
697                                                          uint16 VlanTag);
698 
699 /*!
700  * @brief Sets outer VLAN tag to be replaced for all transmission rings.
701  *
702  * @param[in]  instance            Instance number
703  * @param[in]  vlanType            VLAN type (S-VLAN or C-VLAN) to be used
704  * @param[in]  vlanTag             Value for the VLAN tag to be used
705  * @retval GMAC_STATUS_SUCCESS     The rings were successfully configured.
706  * @retval GMAC_STATUS_UNSUPPORTED The function was called when VLAN insertion
707  *                                 option was configured.
708  */
709 Gmac_Ip_StatusType Gmac_Ip_SetTxOuterVlanTagForReplacement(uint8 Instance,
710                                                            Gmac_Ip_VlanType VlanType,
711                                                            uint16 VlanTag);
712 
713 /*!
714  * @brief Sets inner VLAN type and tag to be inserted/replaced on transmission.
715  *
716  * @param[in]  instance      Instance number
717  * @param[in]  vlanType      VLAN type (S-VLAN or C-VLAN) to be used
718  * @param[in]  vlanTag       Value for the VLAN tag to be used
719  */
720 void Gmac_Ip_SetTxInnerVlanTag(uint8 Instance,
721                                Gmac_Ip_VlanType VlanType,
722                                uint16 VlanTag);
723 
724 #if (FEATURE_GMAC_VLAN_RX_FILTERS_NUM > 0U)
725 /*!
726  * @brief Enables/disables and configures the Rx filters for VLAN tag.
727  *
728  * @param[in]  instance      Instance number
729  * @param[in]  enable        Enables/Disables the Rx filter for VLAN tag
730  * @param[in]  rxFilter      Rx filter options for VLAN tag comparison
731  */
732 void Gmac_Ip_SetVlanTagRxFilter(uint8 Instance,
733                                 boolean Enable,
734                                 const Gmac_Ip_VlanRxFilterType * RxFilter);
735 
736 /*!
737  * @brief Adds a VLAN Tag to the Rx filter.
738  *
739  * @param[in]  instance           Instance number
740  * @param[in]  filterIdx          Index of the VLAN filter
741  * @param[in]  vlanTag            Vlan Tag to be added to the Rx filter
742  * @retval GMAC_STATUS_SUCCESS    The filter was successfully configured.
743  * @retval GMAC_STATUS_TIMEOUT    The filter configuration could not complete
744  *                                before expiration of timeout.
745  */
746 Gmac_Ip_StatusType Gmac_Ip_AddVlanTagToRxFilter(uint8 Instance,
747                                                 uint8 FilterIdx,
748                                                 uint16 VlanTag);
749 
750 /*!
751  * @brief Read a VLAN Tag Rx filter.
752  *
753  * @param[in]  instance           Instance number
754  * @param[in]  filterIdx          Index of the VLAN filter
755  * @param[out] vlanTag            Vlan Tag configured for the selcted Rx filter
756  * @retval GMAC_STATUS_SUCCESS    The filter was successfully read.
757  * @retval GMAC_STATUS_TIMEOUT    The filter could not be read before expiration
758  *                                of timeout.
759  */
760 Gmac_Ip_StatusType Gmac_Ip_ReadVlanTagRxFilter(uint8 Instance,
761                                                uint8 FilterIdx,
762                                                uint16 * VlanTag);
763 
764 /*!
765  * @brief Clear a VLAN Tag Rx filter.
766  *
767  * @param[in]  instance           Instance number
768  * @param[in]  filterIdx          Index of the VLAN filter
769  * @retval GMAC_STATUS_SUCCESS    The filter was successfully cleared.
770  * @retval GMAC_STATUS_TIMEOUT    The filter could not be cleared before
771  *                                expiration of timeout.
772  */
773 Gmac_Ip_StatusType Gmac_Ip_ClearVlanTagRxFilter(uint8 Instance,
774                                                 uint8 FilterIdx);
775 #endif
776 
777 /*!
778  * @brief Adds a VLAN Tag to the Hash Table filter.
779  *
780  * @param[in]  instance      Instance number
781  * @param[in]  vlanTag       Vlan Tag to be added to the hash table
782  */
783 void Gmac_Ip_AddVlanTagToHashTable(uint8 Instance,
784                                    uint16 VlanTag);
785 
786 /*!
787  * @brief Removes a VLAN Tag from the hash table filter.
788  *
789  * @param[in]  instance      Instance number
790  * @param[in]  vlanTag       Vlan Tag to be removed from the hash table
791  */
792 void Gmac_Ip_RemoveVlanTagFromHashTable(uint8 Instance,
793                                         uint16 VlanTag);
794 
795 /*!
796  * @brief Initialize system time.
797  *
798  * @param[in]  instance       Instance number
799  * @param[in]  sysTimeConfig  Pointer to a structure representing the configuration
800  *                            of the system time
801  */
802 void Gmac_Ip_InitSysTime(uint8 Instance,
803                          const Gmac_Ip_SysTimeConfigType * SysTimeConfig);
804 
805 /*!
806  * @brief Set system time correction.
807  *
808  * @param[in]  instance           Instance number
809  * @param[in]  offset             Chooses between negative and positive correction
810  * @param[in]  secondsUpdate      The seconds part of the update
811  * @param[in]  nanosecondsUpdate  The nanoseconds part of the update
812  * @retval GMAC_STATUS_SUCCESS    The correction was set with no error.
813  * @retval GMAC_STATUS_TIMEOUT    The correction could not be set before
814  *                                expiration of timeout.
815  */
816 Gmac_Ip_StatusType Gmac_Ip_SetSysTimeCorr(uint8 Instance,
817                                           Gmac_Ip_SysTimeCorrOffsetType Offset,
818                                           uint32 SecondsUpdate,
819                                           uint32 NanoSecondsUpdate);
820 
821 /*!
822  * @brief Set system time correction.
823  *
824  * @param[in]  instance           Instance number
825  * @param[in]  rateRatio          Rate ratio is used to sync
826  * @retval GMAC_STATUS_SUCCESS    The correction was set with no error.
827  * @retval GMAC_STATUS_TIMEOUT    The correction could not be set before
828  *                                expiration of timeout.
829  */
830 Gmac_Ip_StatusType Gmac_Ip_SetRateRatioCorr(uint8 Instance,
831                                             float64 RateRatio
832                                            );
833 
834 /*!
835  * @brief Gets the current system time.
836  *
837  * @param[in]  instance      Instance number
838  * @param[out] timestamp     Pointer to a structure representing the current
839  *                           system time
840  */
841 void Gmac_Ip_GetSysTime(uint8 Instance, Gmac_Ip_TimestampType * Timestamp);
842 
843 /*!
844  * @brief Sets the transmitter scheduling algorithm.
845  *
846  * @param[in] instance Instance number
847  * @param[in] scheme   Transmitter scheduling algorithm.
848  */
849 void Gmac_Ip_SetTxSchedAlgo(uint8 Instance, Gmac_Ip_TxSchedAlgoType SchedAlgo);
850 
851 /*!
852  * @brief Sets the weight (in WRR scheduling algorithm) for a particular Tx ring.
853  *
854  * Note: If multiple rings are configured and the WWR scheduling algorithm is
855  * selected, the weight must be programmed with a non-zero value. The maximum
856  * value for the weight is 0x64.
857  *
858  * @param[in] instance Instance number
859  * @param[in] ring     Tx ring
860  * @param[in] weight   Tx ring weight
861  */
862 void Gmac_Ip_SetTxRingWeight(uint8 Instance, uint8 Ring, uint32 Weight);
863 
864 /*!
865  * @brief Enables the store and forward feature on the transmit path.
866  *
867  * When the store and forward feature is enabled, the MAC starts to transmit
868  * data only when a complete packet is stored in the Transmit Queue.
869  *
870  * @param[in] instance Instance number
871  * @param[in] ring     Tx ring
872  */
873 void Gmac_Ip_EnableTxStoreAndForward(uint8 Instance, uint8 Ring);
874 
875 /*!
876  * @brief Sets transmit threshold levels.
877  *
878  * @param[in] instance       Instance number
879  * @param[in] ring           Tx ring
880  * @param[in] thresholdValue The threshold value
881  */
882 void Gmac_Ip_SetTxThreshold(uint8 Instance,
883                             uint8 Ring,
884                             Gmac_Ip_TxThresholdType ThresholdValue);
885 
886 #define ETH_43_GMAC_STOP_SEC_CODE
887 #include "Eth_43_GMAC_MemMap.h"
888 
889 
890 #ifdef __cplusplus
891 }
892 #endif
893 
894 /** @} */
895 
896 #endif /* GMAC_IP_H */
897 
898