📄 xemac.h
字号:
/* $Id: xemac.h,v 1.8 2006/03/27 17:41:42 xduan Exp $ *//******************************************************************************** XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS"* AS A COURTESY TO YOU, SOLELY FOR USE IN DEVELOPING PROGRAMS AND* SOLUTIONS FOR XILINX DEVICES. BY PROVIDING THIS DESIGN, CODE,* OR INFORMATION AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE,* APPLICATION OR STANDARD, XILINX IS MAKING NO REPRESENTATION* THAT THIS IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT,* AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE* FOR YOUR IMPLEMENTATION. XILINX EXPRESSLY DISCLAIMS ANY* WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE* IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR* REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF* INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS* FOR A PARTICULAR PURPOSE.** (c) Copyright 2003 Xilinx Inc.* All rights reserved.*******************************************************************************//*****************************************************************************//**** @file xemac.h** The Xilinx Ethernet driver component. This component supports the Xilinx* Ethernet 10/100 MAC (EMAC).** The Xilinx Ethernet 10/100 MAC supports the following features:* - Simple and scatter-gather DMA operations, as well as simple memory* mapped direct I/O interface (FIFOs)* - Media Independent Interface (MII) for connection to external* 10/100 Mbps PHY transceivers* - MII management control reads and writes with MII PHYs* - Independent internal transmit and receive FIFOs* - CSMA/CD compliant operations for half-duplex modes* - Programmable PHY reset signal* - Unicast, broadcast, multicast, and promiscuous address filtering* - Reception of any address that matches a CAM entry.* - Internal loopback* - Automatic source address insertion or overwrite (programmable)* - Automatic FCS insertion and stripping (programmable)* - Automatic pad insertion and stripping (programmable)* - Pause frame (flow control) detection in full-duplex mode* - Programmable interframe gap* - VLAN frame support* - Pause frame support* - Jumbo frame support* - Dynamic Re-alignment Engine (DRE) support handled automatically* - Transmit and Receive checksum offloading support** The device driver supports all the features listed above.** <b>Driver Description</b>** The device driver enables higher layer software (e.g., an application) to* communicate to the EMAC. The driver handles transmission and reception of* Ethernet frames, as well as configuration of the controller. It does not* handle protocol stack functionality such as Link Layer Control (LLC) or the* Address Resolution Protocol (ARP). The protocol stack that makes use of the* driver handles this functionality. This implies that the driver is simply a* pass-through mechanism between a protocol stack and the EMAC. A single device* driver can support multiple EMACs.** The driver is designed for a zero-copy buffer scheme. That is, the driver will* not copy buffers. This avoids potential throughput bottlenecks within the* driver.** Since the driver is a simple pass-through mechanism between a protocol stack* and the EMAC, no assembly or disassembly of Ethernet frames is done at the* driver-level. This assumes that the protocol stack passes a correctly* formatted Ethernet frame to the driver for transmission, and that the driver* does not validate the contents of an incoming frame** <b>Buffer Alignment</b>** It is important to note that when using direct FIFO communication (either* polled or interrupt-driven), packet buffers must be 32-bit aligned. When* using DMA without DRE and the OPB 10/100 Ethernet core, packet buffers* must be 32-bit aligned. When using DMA without DRE and the PLB 10/100* Ethernet core, packet buffers must be 64-bit aligned.** When using scatter-gather DMA, the buffer descriptors must be 32-bit* aligned (for either the OPB or the PLB core). The driver may not enforce* this alignment so it is up to the user to guarantee the proper alignment.** When DRE is available in the DMA engine, only the buffer descriptors must* be aligned, the actual buffers do not need to be aligned to any particular* addressing convention, the DRE takes care of that in hardware.** <b>Receive Address Filtering</b>** The device can be set to accept frames whose destination MAC address:** - Match the station MAC address (see XEmac_SetMacAddress())* - Match the broadcast MAC address (see XEM_BROADCAST_OPTION)* - Match any multicast MAC address (see XEM_MULTICAST_OPTION)* - Match any one of the 64 possible CAM addresses (see XEmac_MulticastAdd()* and XEM_MULTICAST_CAM_OPTION). The CAM is optional.* - Match any MAC address (see XEM_PROMISC_OPTION)** <b>PHY Communication</b>** The driver provides rudimentary read and write functions to allow the higher* layer software to access the PHY. The EMAC provides MII registers for the* driver to access. This management interface can be parameterized away in the* FPGA implementation process. If this is the case, the PHY read and write* functions of the driver return XST_NO_FEATURE.** External loopback is usually supported at the PHY. It is up to the user to* turn external loopback on or off at the PHY. The driver simply provides pass-* through functions for configuring the PHY. The driver does not read, write,* or reset the PHY on its own. All control of the PHY must be done by the user.** <b>Asynchronous Callbacks</b>** The driver services interrupts and passes Ethernet frames to the higher layer* software through asynchronous callback functions. When using the driver* directly (i.e., not with the RTOS protocol stack), the higher layer* software must register its callback functions during initialization. The* driver requires callback functions for received frames, for confirmation of* transmitted frames, and for asynchronous errors.** <b>Interrupts</b>** The driver has no dependencies on the interrupt controller. The driver* provides two interrupt handlers. XEmac_IntrHandlerDma() handles interrupts* when the EMAC is configured with scatter-gather DMA. XEmac_IntrHandlerFifo()* handles interrupts when the EMAC is configured for direct FIFO I/O or simple* DMA. Either of these routines can be connected to the system interrupt* controller by the user.** <b>Interrupt Frequency</b>** When the EMAC is configured with scatter-gather DMA, the frequency of* interrupts can be controlled with the interrupt coalescing features of the* scatter-gather DMA engine. The frequency of interrupts can be adjusted using* the driver API functions for setting the packet count threshold and the packet* wait bound values.** The scatter-gather DMA engine only interrupts when the packet count threshold* is reached, instead of interrupting for each packet. A packet is a generic* term used by the scatter-gather DMA engine, and is equivalent to an Ethernet* frame in our case.** The packet wait bound is a timer value used during interrupt coalescing to* trigger an interrupt when not enough packets have been received to reach the* packet count threshold.** These values can be tuned by the user to meet their needs. If there appear to* be interrupt latency problems or delays in packet arrival that are longer than* might be expected, the user should verify that the packet count threshold is* set low enough to receive interrupts before the wait bound timer goes off.** <b>Device Reset</b>** Some errors that can occur in the device require a device reset. These errors* are listed in the XEmac_SetErrorHandler() function header. The user's error* handler is responsible for resetting the device and re-configuring it based on* its needs (the driver does not save the current configuration). When* integrating into an RTOS, these reset and re-configure obligations are* taken care of by the Xilinx adapter software if it exists for that RTOS.** <b>Device Configuration</b>** The device can be configured in various ways during the FPGA implementation* process. Configuration parameters are stored in the xemac_g.c files.* A table is defined where each entry contains configuration information* for an EMAC device. This information includes such things as the base address* of the memory-mapped device, the base addresses of IPIF, DMA, and FIFO modules* within the device, and whether the device has DMA, counter registers,* multicast support, MII support, and flow control.** The driver tries to use the features built into the device. So if, for* example, the hardware is configured with scatter-gather DMA, the driver* expects to start the scatter-gather channels and expects that the user has set* up the buffer descriptor lists already. If the user expects to use the driver* in a mode different than how the hardware is configured, the user should* modify the configuration table to reflect the mode to be used. Modifying the* configuration table is a workaround for now until we get some experience with* how users are intending to use the hardware in its different configurations.* For example, if the hardware is built with scatter-gather DMA but the user is* intending to use only simple DMA, the user either needs to modify the config* table as a workaround or rebuild the hardware with only simple DMA. The* recommendation at this point is to build the hardware with the features you* intend to use. If you're inclined to modify the table, do so before the call* to XEmac_Initialize(). Here is a snippet of code that changes a device to* simple DMA (the hardware needs to have DMA for this to work of course):* <pre>* XEmac_Config *ConfigPtr;** ConfigPtr = XEmac_LookupConfig(DeviceId);* ConfigPtr->IpIfDmaConfig = XEM_CFG_SIMPLE_DMA;* </pre>** <b>Simple DMA</b>** Simple DMA is supported through the FIFO functions, FifoSend and FifoRecv, of* the driver (i.e., there is no separate interface for it). The driver makes use* of the DMA engine for a simple DMA transfer if the device is configured with* DMA, otherwise it uses the FIFOs directly. While the simple DMA interface is* therefore transparent to the user, the caching of network buffers is not.* If the device is configured with DMA and the FIFO interface is used, the user* must ensure that the network buffers are not cached or are cache coherent,* since DMA will be used to transfer to and from the Emac device. If the device* is configured with DMA and the user really wants to use the FIFOs directly,* the user should rebuild the hardware without DMA. If unable to do this, there* is a workaround (described above in Device Configuration) to modify the* configuration table of the driver to fake the driver into thinking the device* has no DMA. A code snippet follows:* <pre>* XEmac_Config *ConfigPtr;** ConfigPtr = XEmac_LookupConfig(DeviceId);* ConfigPtr->IpIfDmaConfig = XEM_CFG_NO_DMA;* </pre>** <b>Asserts</b>** Asserts are used within all Xilinx drivers to enforce constraints on argument* values. Asserts can be turned off on a system-wide basis by defining, at* compile time, the NDEBUG identifier. By default, asserts are turned on and it* is recommended that users leave asserts on during development.** <b>Building the driver</b>** The XEmac driver is composed of several source files. Why so many? This* allows the user to build and link only those parts of the driver that are* necessary. Since the EMAC hardware can be configured in various ways (e.g.,* with or without DMA), the driver too can be built with varying features.* For the most part, this means that besides always linking in xemac.c, you* link in only the driver functionality you want. Some of the choices you have* are polled vs. interrupt, interrupt with FIFOs only vs. interrupt with DMA,* self-test diagnostics, and driver statistics. Note that currently the DMA code* must be linked in, even if you don't have DMA in the device.** @note** Xilinx drivers are typically composed of two components, one is the driver* and the other is the adapter. The driver is independent of OS and processor* and is intended to be highly portable. The adapter is OS-specific and* facilitates communication between the driver and an OS.* <br><br>* This driver is intended to be RTOS and processor independent. It works* with physical addresses only. Any needs for dynamic memory management,* threads or thread mutual exclusion, virtual memory, or cache control must* be satisfied by the layer above this driver.* <br><br>* If the EMAC device has checksum offloading feature turned on, direct FIFO* and polled mode functions in this driver do NOT work. This should not be* any problem because checksum offloading feature depends on scatter-gather* DMA and scatter-gather DMA mode functions will be chosen automatically* by this driver if scatter-gather DMA is included in hardware.** <pre>* MODIFICATION HISTORY:** Ver Who Date Changes* ----- ---- -------- -------------------------------------------------------* 1.00a rpm 07/31/01 First release* 1.00b rpm 02/20/02 Repartitioned files and functions* 1.00b rpm 10/08/02 Replaced HasSgDma boolean with IpifDmaConfig enumerated* configuration parameter* 1.00c rpm 12/05/02 New version includes support for simple DMA and the delay* argument to SgSend* 1.00c rpm 02/03/03 The XST_DMA_SG_COUNT_EXCEEDED return code was removed* from SetPktThreshold in the internal DMA driver. Also* avoided compiler warnings by initializing Result in the* DMA interrupt service routines.* 1.00d rpm 09/26/03 New version includes support PLB Ethernet and v2.00a of* the packet fifo driver. Also supports multicast option.* 1.00e rmm 04/06/04 SGEND option added, Zero instance memory on init. Changed* SG DMA callback invokation from once per packet to once* for all packets received for an interrupt event. Added* XEmac_GetSgRecvFreeDesc() and GetSgSendFreeDesc()* functions. Moved some IFG and PHY constants to xemac_l.h.* 1.00f rmm 10/19/04 Added programmable CAM address filtering. Added jumbo* frame support. Added XEmac_PhyReset() function.* 1.01a ecm 09/01/05 Added DRE and Checksum Offload support through Control* words in instance which are set at initialization.* Added the config structure items to support separate* Tx and Rx capabilities.* </pre>*******************************************************************************/#ifndef XEMAC_H /* prevent circular inclusions */#define XEMAC_H /* by using protection macros */#ifdef __cplusplusextern "C" {#endif/***************************** Include Files *********************************/#include "xbasic_types.h"#include "xstatus.h"#include "xparameters.h"#include "xpacket_fifo_v2_00_a.h" /* Uses v2.00a of Packet Fifo */#include "xdma_channel.h"/************************** Constant Definitions *****************************//* * Device information */#define XEM_DEVICE_NAME "xemac"#define XEM_DEVICE_DESC "Xilinx Ethernet 10/100 MAC"/** @name Configuration options * * Device configuration options (see the XEmac_SetOptions() and * XEmac_GetOptions() for information on how to use these options) * @{ */#define XEM_UNICAST_OPTION 0x00000001UL /**< Unicast addressing (defaults on) */#define XEM_BROADCAST_OPTION 0x00000002UL /**< Broadcast addressing (defaults on) */#define XEM_PROMISC_OPTION 0x00000004UL /**< Promiscuous addressing (defaults off) */#define XEM_FDUPLEX_OPTION 0x00000008UL /**< Full duplex mode (defaults off) */#define XEM_POLLED_OPTION 0x00000010UL /**< Polled mode (defaults off) */#define XEM_LOOPBACK_OPTION 0x00000020UL /**< Internal loopback mode (defaults off) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -