📄 xemacps.h
字号:
/******************************************************************************* (c) Copyright 2010-11 Xilinx, Inc. All rights reserved.** This file contains confidential and proprietary information of Xilinx, Inc.* and is protected under U.S. and international copyright and other* intellectual property laws.** DISCLAIMER* This disclaimer is not a license and does not grant any rights to the* materials distributed herewith. Except as otherwise provided in a valid* license issued to you by Xilinx, and to the maximum extent permitted by* applicable law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND WITH ALL* FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS,* IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF* MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE;* and (2) Xilinx shall not be liable (whether in contract or tort, including* negligence, or under any other theory of liability) for any loss or damage* of any kind or nature related to, arising under or in connection with these* materials, including for any direct, or any indirect, special, incidental,* or consequential loss or damage (including loss of data, profits, goodwill,* or any type of loss or damage suffered as a result of any action brought by* a third party) even if such damage or loss was reasonably foreseeable or* Xilinx had been advised of the possibility of the same.** CRITICAL APPLICATIONS* Xilinx products are not designed or intended to be fail-safe, or for use in* any application requiring fail-safe performance, such as life-support or* safety devices or systems, Class III medical devices, nuclear facilities,* applications related to the deployment of airbags, or any other applications* that could lead to death, personal injury, or severe property or* environmental damage (individually and collectively, "Critical* Applications"). Customer assumes the sole risk and liability of any use of* Xilinx products in Critical Applications, subject only to applicable laws* and regulations governing limitations on product liability.** THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE* AT ALL TIMES.******************************************************************************//****************************************************************************//** * * @file xemacps.h * * The Xilinx Embedded Processor Block Ethernet driver. * * For a full description of XEMACPS features, please see the hardware spec. * This driver supports the following features: * - Memory mapped access to host interface registers * - Statistics counter registers for RMON/MIB * - API for interrupt driven frame transfers for hardware configured DMA * - Virtual memory support * - Unicast, broadcast, and multicast receive address filtering * - Full and half duplex operation * - Automatic PAD & FCS insertion and stripping * - Flow control * - Support up to four 48bit addresses * - Address checking for four specific 48bit addresses * - VLAN frame support * - Pause frame support * - Large frame support up to 1536 bytes * - Checksum offload * * <b>Driver Description</b> * * The device driver enables higher layer software (e.g., an application) to * communicate to the XEmacPs. The driver handles transmission and reception * of Ethernet frames, as well as configuration and control. No pre or post * processing of frame data is performed. The driver does not validate the * contents of an incoming frame in addition to what has already occurred in * hardware. * A single device driver can support multiple devices even when those devices * have significantly different configurations. * * <b>Initialization & Configuration</b> * * The XEmacPs_Config structure is used by the driver to configure itself. * This configuration structure is typically created by the tool-chain based * on hardware build properties. * * The driver instance can be initialized in * * - XEmacPs_CfgInitialize(InstancePtr, CfgPtr, EffectiveAddress): Uses a * configuration structure provided by the caller. If running in a system * with address translation, the provided virtual memory base address * replaces the physical address present in the configuration structure. * * The device supports DMA only as current development plan. No FIFO mode is * supported. The driver expects to start the DMA channels and expects that * the user has set up the buffer descriptor lists. * * <b>Interrupts and Asynchronous Callbacks</b> * * The driver has no dependencies on the interrupt controller. When an * interrupt occurs, the handler will perform a small amount of * housekeeping work, determine the source of the interrupt, and call the * appropriate callback function. All callbacks are registered by the user * level application. * * <b>Virtual Memory</b> * * All virtual to physical memory mappings must occur prior to accessing the * driver API. * * For DMA transactions, user buffers supplied to the driver must be in terms * of their physical address. * * <b>DMA</b> * * The DMA engine uses buffer descriptors (BDs) to describe Ethernet frames. * These BDs are typically chained together into a list the hardware follows * when transferring data in and out of the packet buffers. Each BD describes * a memory region containing either a full or partial Ethernet packet. * * Interrupt coalescing is not suppoted from this built-in DMA engine. * * This API requires the user to understand how the DMA operates. The * following paragraphs provide some explanation, but the user is encouraged * to read documentation in xemacps_bdring.h as well as study example code * that accompanies this driver. * * The API is designed to get BDs to and from the DMA engine in the most * efficient means possible. The first step is to establish a memory region * to contain all BDs for a specific channel. This is done with * XEmacPs_BdRingCreate(). This function sets up a BD ring that hardware will * follow as BDs are processed. The ring will consist of a user defined number * of BDs which will all be partially initialized. For example on the transmit * channel, the driver will initialize all BDs' so that they are configured * for transmit. The more fields that can be permanently setup at * initialization, then the fewer accesses will be needed to each BD while * the DMA engine is in operation resulting in better throughput and CPU * utilization. The best case initialization would require the user to set * only a frame buffer address and length prior to submitting the BD to the * engine. * * BDs move through the engine with the help of functions * XEmacPs_BdRingAlloc(), XEmacPs_BdRingToHw(), XEmacPs_BdRingFromHw(), * and XEmacPs_BdRingFree(). * All these functions handle BDs that are in place. That is, there are no * copies of BDs kept anywhere and any BD the user interacts with is an actual * BD from the same ring hardware accesses. * * BDs in the ring go through a series of states as follows: * 1. Idle. The driver controls BDs in this state. * 2. The user has data to transfer. XEmacPs_BdRingAlloc() is called to * reserve BD(s). Once allocated, the user may setup the BD(s) with * frame buffer address, length, and other attributes. The user controls * BDs in this state. * 3. The user submits BDs to the DMA engine with XEmacPs_BdRingToHw. BDs * in this state are either waiting to be processed by hardware, are in * process, or have been processed. The DMA engine controls BDs in this * state. * 4. Processed BDs are retrieved with XEmacEpv_BdRingFromHw() by the * user. Once retrieved, the user can examine each BD for the outcome of * the DMA transfer. The user controls BDs in this state. After examining * the BDs the user calls XEmacPs_BdRingFree() which places the BDs back * into state 1. * * Each of the four BD accessor functions operate on a set of BDs. A set is * defined as a segment of the BD ring consisting of one or more BDs. The user * views the set as a pointer to the first BD along with the number of BDs for * that set. The set can be navigated by using macros XEmacPs_BdNext(). The * user must exercise extreme caution when changing BDs in a set as there is * nothing to prevent doing a mBdNext past the end of the set and modifying a * BD out of bounds. * * XEmacPs_BdRingAlloc() + XEmacPs_BdRingToHw(), as well as * XEmacPs_BdRingFromHw() + XEmacPs_BdRingFree() are designed to be used in * tandem. The same BD set retrieved with BdRingAlloc should be the same one * provided to hardware with BdRingToHw. Same goes with BdRingFromHw and * BdRIngFree. * * <b>Alignment & Data Cache Restrictions</b> * * Due to the design of the hardware, all RX buffers, BDs need to be 4-byte * aligned. Please reference xemacps_bd.h for cache related macros. * * DMA Tx: * * - If frame buffers exist in cached memory, then they must be flushed * prior to committing them to hardware. * * DMA Rx: * * - If frame buffers exist in cached memory, then the cache must be * invalidated for the memory region containing the frame prior to data * access * * Both cache invalidate/flush are taken care of in driver code. * * <b>Buffer Copying</b> * * 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. If byte copying is required, then the transfer will take longer * to complete. * * <b>Checksum Offloading</b> * * The Embedded Processor Block Ethernet can be configured to perform IP, TCP * and UDP checksum offloading in both receive and transmit directions. * * IP packets contain a 16-bit checksum field, which is the 16-bit 1s * complement of the 1s complement sum of all 16-bit words in the header. * TCP and UDP packets contain a 16-bit checksum field, which is the 16-bit * 1s complement of the 1s complement sum of all 16-bit words in the header, * the data and a conceptual pseudo header. * * To calculate these checksums in software requires each byte of the packet * to be read. For TCP and UDP this can use a large amount of processing power. * Offloading the checksum calculation to hardware can result in significant * performance improvements. * * The transmit checksum offload is only available to use DMA in packet buffer * mode. This is because the complete frame to be transmitted must be read * into the packet buffer memory before the checksum can be calculated and * written to the header at the beginning of the frame. * * For IP, TCP or UDP receive checksum offload to be useful, the operating * system containing the protocol stack must be aware that this offload is * available so that it can make use of the fact that the hardware has verified * the checksum. * * When receive checksum offloading is enabled in the hardware, the IP header * checksum is checked, where the packet meets the following criteria: * * 1. If present, the VLAN header must be four octets long and the CFI bit * must not be set. * 2. Encapsulation must be RFC 894 Ethernet Type Encoding or RFC 1042 SNAP * encoding. * 3. IP v4 packet. * 4. IP header is of a valid length. * 5. Good IP header checksum. * 6. No IP fragmentation. * 7. TCP or UDP packet. * * When an IP, TCP or UDP frame is received, the receive buffer descriptor * gives an indication if the hardware was able to verify the checksums. * There is also an indication if the frame had SNAP encapsulation. These * indication bits will replace the type ID match indication bits when the * receive checksum offload is enabled. * * If any of the checksums are verified incorrect by the hardware, the packet * is discarded and the appropriate statistics counter incremented. * * <b>PHY Interfaces</b> * * RGMII 1.3 is the only interface supported. * * <b>Asserts</b> * * Asserts are used within all Xilinx drivers to enforce constraints on * parameters. 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. For * deployment use -DNDEBUG compiler switch to remove assert code. * * @note * * Xilinx drivers are typically composed of two parts, 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. * This driver is intended to be RTOS and processor independent. Any needs for * dynamic memory management, threads or thread mutual exclusion, or cache * control must be satisfied bythe layer above this driver. * * <pre> * MODIFICATION HISTORY: * * Ver Who Date Changes * ----- ---- -------- ------------------------------------------------------- * 1.00a wsy 01/10/10 First release * 1.00a asa 11/21/11 The function XEmacPs_BdRingFromHwTx in file * xemacps_bdring.c is modified. Earlier it was checking for * "BdLimit"(passed argument) number of BDs for finding out * which BDs are successfully processed. Now one more check * is added. It looks for BDs till the current BD pointer * reaches HwTail. By doing this processing time is saved. * 1.00a asa 01/24/12 The function XEmacPs_BdRingFromHwTx in file * xemacps_bdring.c is modified. Now start of packet is * searched for returning the number of BDs processed. * </pre> * ****************************************************************************/#ifndef XEMACPS_H /* prevent circular inclusions */#define XEMACPS_H /* by using protection macros */#ifdef __cplusplusextern "C" {#endif/***************************** Include Files ********************************/#include "xil_types.h"#include "xil_assert.h"#include "xstatus.h"#include "xemacps_hw.h"#include "xemacps_bd.h"#include "xemacps_bdring.h"/************************** Constant Definitions ****************************//* * Device information */#define XEMACPS_DEVICE_NAME "xemacps"#define XEMACPS_DEVICE_DESC "Xilinx PS 10/100/1000 MAC"/** @name Configuration options * * Device configuration options. See the XEmacPs_SetOptions(), * XEmacPs_ClearOptions() and XEmacPs_GetOptions() for information on how to * use options. * * The default state of the options are noted and are what the device and * driver will be set to after calling XEmacPs_Reset() or * XEmacPs_Initialize(). * * @{ */#define XEMACPS_PROMISC_OPTION 0x00000001/**< Accept all incoming packets. * This option defaults to disabled (cleared) */#define XEMACPS_FRAME1536_OPTION 0x00000002/**< Frame larger than 1516 support for Tx & Rx. * This option defaults to disabled (cleared) */#define XEMACPS_VLAN_OPTION 0x00000004/**< VLAN Rx & Tx frame support. * This option defaults to disabled (cleared) */#define XEMACPS_FLOW_CONTROL_OPTION 0x00000010/**< Enable recognition of flow control frames on Rx * This option defaults to enabled (set) */#define XEMACPS_FCS_STRIP_OPTION 0x00000020/**< Strip FCS and PAD from incoming frames. Note: PAD from VLAN frames is not * stripped. * This option defaults to enabled (set) */#define XEMACPS_FCS_INSERT_OPTION 0x00000040
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -