1 /******************************************************************************
3 * Copyright (C) 2004 - 2014 Xilinx, Inc. All rights reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
31 ******************************************************************************/
32 /*****************************************************************************/
36 * @addtogroup emaclite_v4_1
40 * The Xilinx Ethernet Lite (EmacLite) driver. This driver supports the Xilinx
41 * Ethernet Lite 10/100 MAC (EmacLite).
43 * The Xilinx Ethernet Lite 10/100 MAC supports the following features:
44 * - Media Independent Interface (MII) for connection to external
45 * 10/100 Mbps PHY transceivers
46 * - Independent internal transmit and receive buffers
47 * - CSMA/CD compliant operations for half-duplex modes
48 * - Unicast and broadcast
49 * - Automatic FCS insertion
50 * - Automatic pad insertion on transmit
51 * - Configurable ping/pong buffers for either/both transmit and receive
53 * - Interrupt driven mode
54 * - Internal loop back
55 * - MDIO Support to access PHY Registers
57 * The Xilinx Ethernet Lite 10/100 MAC does not support the following features:
58 * - multi-frame buffering
59 * only 1 transmit frame is allowed into each transmit buffer,
60 * only 1 receive frame is allowed into each receive buffer.
61 * the hardware blocks reception until buffer is emptied
62 * - Pause frame (flow control) detection in full-duplex mode
63 * - Programmable inter frame gap
64 * - Multicast and promiscuous address filtering
65 * - Automatic source address insertion or overwrite
67 * <b>Driver Description</b>
69 * The device driver enables higher layer software (e.g., an application) to
70 * communicate to the EmacLite. The driver handles transmission and reception
71 * of Ethernet frames, as well as configuration of the controller. It does not
72 * handle protocol stack functionality such as Link Layer Control (LLC) or the
73 * Address Resolution Protocol (ARP). The protocol stack that makes use of the
74 * driver handles this functionality. This implies that the driver is simply a
75 * pass-through mechanism between a protocol stack and the EmacLite.
77 * Since the driver is a simple pass-through mechanism between a protocol stack
78 * and the EmacLite, no assembly or disassembly of Ethernet frames is done at
79 * the driver-level. This assumes that the protocol stack passes a correctly
80 * formatted Ethernet frame to the driver for transmission, and that the driver
81 * does not validate the contents of an incoming frame. A single device driver
82 * can support multiple EmacLite devices.
84 * The driver supports interrupt driven mode and the default mode of operation
85 * is polled mode. If interrupts are desired, XEmacLite_InterruptEnable() must
88 * <b>Device Configuration</b>
90 * The device can be configured in various ways during the FPGA implementation
91 * process. Configuration parameters are stored in the xemaclite_g.c file.
92 * A table is defined where each entry contains configuration information for an
93 * EmacLite device. This information includes such things as the base address
94 * of the memory-mapped device and the number of buffers.
96 * <b>Interrupt Processing</b>
98 * After _Initialize is called, _InterruptEnable can be called to enable the
99 * interrupt driven functionality. If polled operation is desired, just call
100 * _Send and check the return code. If XST_FAILURE is returned, call _Send with
101 * the same data until XST_SUCCESS is returned. The same idea applies to _Recv.
102 * Call _Recv until the returned length is non-zero at which point the received
103 * data is in the buffer provided in the function call.
105 * The Transmit and Receive interrupts are enabled within the _InterruptEnable
106 * function and disabled in the _InterruptDisable function. The _Send and _Recv
107 * functions acknowledge the EmacLite generated interrupts associated with each
109 * It is the application's responsibility to acknowledge any associated Interrupt
110 * Controller interrupts if it is used in the system.
112 * <b>Memory Buffer Alignment</b>
114 * The alignment of the input/output buffers for the _Send and _Recv routine is
115 * not required to be 32 bits. If the buffer is not aligned on a 32-bit boundary
116 * there will be a performance impact while the driver aligns the data for
117 * transmission or upon reception.
119 * For optimum performance, the user should provide a 32-bit aligned buffer
120 * to the _Send and _Recv routines.
124 * Asserts are used within all Xilinx drivers to enforce constraints on argument
125 * values. Asserts can be turned off on a system-wide basis by defining, at
126 * compile time, the NDEBUG identifier. By default, asserts are turned on and it
127 * is recommended that application developers leave asserts on during
132 * This driver requires EmacLite hardware version 1.01a and higher. It is not
133 * compatible with earlier versions of the EmacLite hardware. Use version 1.00a
134 * software driver for hardware version 1.00a/b.
136 * The RX hardware is enabled from powerup and there is no disable. It is
137 * possible that frames have been received prior to the initialization
138 * of the driver. If this situation is possible, call XEmacLite_FlushReceive()
139 * to empty the receive buffers after initialization.
141 * This driver is intended to be RTOS and processor independent. It works
142 * with physical addresses only. Any needs for dynamic memory management,
143 * threads or thread mutual exclusion, virtual memory, or cache control must
144 * be satisfied by the layer above this driver.
147 * MODIFICATION HISTORY:
149 * Ver Who Date Changes
150 * ----- ---- -------- -----------------------------------------------
151 * 1.01a ecm 01/30/04 First release
152 * 1.11a mta 03/21/07 Updated to new coding style
153 * 1.12a mta 11/28/07 Added the function XEmacLite_CfgInitialize,
154 * moved the functions XEmacLite_LookupConfig and
155 * XEmacLite_Initialize to xemaclite_sinit.c for removing
156 * the dependency on the static config table and
157 * xparameters.h from the driver initialization
158 * 1.13a sv 02/1/08 Updated the TxBufferAvailable routine to return
159 * busy status properly and added macros for Tx/Rx status
160 * 1.14a sdm 08/22/08 Removed support for static interrupt handlers from the MDD
162 * 2.00a ktn 02/16/09 Added support for MDIO and internal loop back
163 * 2.01a ktn 07/20/09 Updated the XEmacLite_AlignedWrite and
164 * XEmacLite_AlignedRead functions to use volatile
165 * variables so that they are not optimized.
166 * Modified the XEmacLite_EnableInterrupts and
167 * XEmacLite_DisableInterrupts functions to enable/disable
168 * the interrupt in the Ping buffer as this is used to enable
169 * the interrupts for both Ping and Pong Buffers.
170 * The interrupt enable bit in the Pong buffer is not used by
172 * Modified XEmacLite_Send function to use Ping buffers
173 * Interrupt enable bit since this alone is used to enable
174 * the interrupts for both Ping and Pong Buffers.
175 * 3.00a ktn 10/22/09 Updated driver to use the HAL Processor APIs/macros.
176 * The macros have been renamed to remove _m from the name in
177 * all the driver files.
178 * The macros changed in this file are
179 * XEmacLite_mNextTransmitAddr is XEmacLite_NextTransmitAddr,
180 * XEmacLite_mNextReceiveAddr is XEmacLite_NextReceiveAddr,
181 * XEmacLite_mIsMdioConfigured is XEmacLite_IsMdioConfigured,
182 * XEmacLite_mIsLoopbackConfigured is
183 * XEmacLite_IsLoopbackConfigured.
184 * See xemaclite_i.h for the macros which have changed.
185 * 3.01a ktn 07/08/10 The macro XEmacLite_GetReceiveDataLength in the
186 * xemaclite.c file is changed to a static function.
187 * XEmacLite_GetReceiveDataLength and XEmacLite_Recv
188 * functions are updated to support little endian
190 * 3.02a sdm 07/22/11 Removed redundant code in XEmacLite_Recv functions for
192 * 3.03a asa 04/05/12 Defined the flag __LITTLE_ENDIAN__ for cases where the
193 * driver is compiled with ARM toolchain.
194 * 3.04a srt 04/13/13 Removed warnings (CR 705000).
195 * 4.0 adk 19/12/13 Updated as per the New Tcl API's
196 * 4.1 nsk 07/13/15 Added Length check in XEmacLite_AlignedWrite function
197 * in xemaclite_l.c file to avoid extra write operation
199 * 4.2 sk 11/10/15 Used UINTPTR instead of u32 for Baseaddress CR# 867425.
200 * Changed the prototype of XEmacLite_CfgInitialize API.
201 * 4.2 adk 11/18/15 Fix compilation errors due to conflicting data types
203 * 4.2 adk 29/02/16 Updated interrupt example to support Zynq and ZynqMP
209 ******************************************************************************/
210 #ifndef XEMACLITE_H /* prevent circular inclusions */
211 #define XEMACLITE_H /* by using protection macros */
217 /***************************** Include Files *********************************/
220 #include "xil_types.h"
221 #include "xil_assert.h"
223 #include "xemaclite_l.h"
226 #ifndef __LITTLE_ENDIAN__
227 #define __LITTLE_ENDIAN__
230 /************************** Constant Definitions *****************************/
234 #define XEL_DEVICE_NAME "xemaclite"
235 #define XEL_DEVICE_DESC "Xilinx Ethernet Lite 10/100 MAC"
237 /**************************** Type Definitions *******************************/
240 * This typedef contains configuration information for a device.
243 u16 DeviceId; /**< Unique ID of device */
244 UINTPTR BaseAddress; /**< Device base address */
245 u8 TxPingPong; /**< 1 if TX Pong buffer configured, 0 otherwise */
246 u8 RxPingPong; /**< 1 if RX Pong buffer configured, 0 otherwise */
247 u8 MdioInclude; /**< 1 if MDIO is enabled, 0 otherwise */
248 u8 Loopback; /**< 1 if internal loopback is enabled, 0 otherwise */
253 * Callback when data is sent or received .
254 * @param CallBackRef is a callback reference passed in by the upper layer
255 * when setting the callback functions, and passed back to the
256 * upper layer when the callback is invoked.
258 typedef void (*XEmacLite_Handler) (void *CallBackRef);
261 * The XEmacLite driver instance data. The user is required to allocate a
262 * variable of this type for every EmacLite device in the system. A pointer
263 * to a variable of this type is then passed to the driver API functions.
266 XEmacLite_Config EmacLiteConfig; /* Device configuration */
267 u32 IsReady; /* Device is initialized and ready */
269 u32 NextTxBufferToUse; /* Next TX buffer to write to */
270 u32 NextRxBufferToUse; /* Next RX buffer to read from */
275 XEmacLite_Handler RecvHandler;
277 XEmacLite_Handler SendHandler;
282 /***************** Macros (Inline Functions) Definitions *********************/
284 /****************************************************************************/
287 * Return the next expected Transmit Buffer's address.
289 * @param InstancePtr is the pointer to the instance of the driver to
292 * @note C-Style signature:
293 * u32 XEmacLite_NextTransmitAddr(XEmacLite *InstancePtr);
295 * This macro returns the address of the next transmit buffer to put data into.
296 * This is used to determine the destination of the next transmit data frame.
298 *****************************************************************************/
299 #define XEmacLite_NextTransmitAddr(InstancePtr) \
300 ((InstancePtr)->EmacLiteConfig.BaseAddress + \
301 (InstancePtr)->NextTxBufferToUse) + XEL_TXBUFF_OFFSET
303 /****************************************************************************/
306 * Return the next expected Receive Buffer's address.
308 * @param InstancePtr is the pointer to the instance of the driver to
311 * @note C-Style signature:
312 * u32 XEmacLite_NextReceiveAddr(XEmacLite *InstancePtr);
314 * This macro returns the address of the next receive buffer to read data from.
315 * This is the expected receive buffer address if the driver is in sync.
317 *****************************************************************************/
318 #define XEmacLite_NextReceiveAddr(InstancePtr) \
319 ((InstancePtr)->EmacLiteConfig.BaseAddress + \
320 (InstancePtr)->NextRxBufferToUse)
322 /*****************************************************************************/
325 * This macro determines if the device is currently configured for MDIO.
327 * @param InstancePtr is the pointer to the instance of the
331 * - TRUE if the device is configured for MDIO.
332 * - FALSE if the device is NOT configured for MDIO.
334 * @note C-Style signature:
335 * int XEmacLite_IsMdioConfigured(XEmacLite *InstancePtr)
337 ******************************************************************************/
338 #define XEmacLite_IsMdioConfigured(InstancePtr) \
339 ((InstancePtr)->EmacLiteConfig.MdioInclude == 1)
341 /*****************************************************************************/
344 * This macro determines if the device is currently configured for internal
347 * @param InstancePtr is the pointer to the instance of the
351 * - TRUE if the device is configured for internal loopback.
352 * - FALSE if the device is NOT configured for internal loopback.
354 * @note C-Style signature:
355 * int XEmacLite_IsLoopbackConfigured(XEmacLite *InstancePtr)
357 ******************************************************************************/
358 #define XEmacLite_IsLoopbackConfigured(InstancePtr) \
359 ((InstancePtr)->EmacLiteConfig.Loopback == 1)
361 /************************** Variable Definitions *****************************/
363 /************************** Function Prototypes ******************************/
366 * Functions in xemaclite.c
368 int XEmacLite_CfgInitialize(XEmacLite *InstancePtr,
369 XEmacLite_Config *EmacLiteConfigPtr,
370 UINTPTR EffectiveAddr);
371 void XEmacLite_SetMacAddress(XEmacLite *InstancePtr, u8 *AddressPtr);
372 int XEmacLite_TxBufferAvailable(XEmacLite *InstancePtr);
373 void XEmacLite_FlushReceive(XEmacLite *InstancePtr);
375 int XEmacLite_Send(XEmacLite *InstancePtr, u8 *FramePtr, unsigned ByteCount);
376 u16 XEmacLite_Recv(XEmacLite *InstancePtr, u8 *FramePtr);
378 int XEmacLite_PhyRead(XEmacLite *InstancePtr, u32 PhyAddress, u32 RegNum,
380 int XEmacLite_PhyWrite(XEmacLite *InstancePtr, u32 PhyAddress, u32 RegNum,
383 void XEmacLite_EnableLoopBack(XEmacLite *InstancePtr);
384 void XEmacLite_DisableLoopBack(XEmacLite *InstancePtr);
387 * Initialization functions in xemaclite_sinit.c
389 XEmacLite_Config *XEmacLite_LookupConfig(u16 DeviceId);
390 int XEmacLite_Initialize(XEmacLite *InstancePtr, u16 DeviceId);
393 * Interrupt driven functions in xemaclite_intr.c
395 int XEmacLite_EnableInterrupts(XEmacLite *InstancePtr);
396 void XEmacLite_DisableInterrupts(XEmacLite *InstancePtr);
398 void XEmacLite_InterruptHandler(void *InstancePtr);
400 void XEmacLite_SetRecvHandler(XEmacLite *InstancePtr, void *CallBackRef,
401 XEmacLite_Handler FuncPtr);
402 void XEmacLite_SetSendHandler(XEmacLite *InstancePtr, void *CallBackRef,
403 XEmacLite_Handler FuncPtr);
406 * Selftest function in xemaclite_selftest.c
408 int XEmacLite_SelfTest(XEmacLite *InstancePtr);
414 #endif /* end of protection macro */