⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xemac.c

📁 powerpc405开发板的linux网口驱动程序
💻 C
📖 第 1 页 / 共 3 页
字号:
/* $Id: xemac.c,v 1.5 2006/01/12 18:03:10 meinelte 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.c** The XEmac driver. Functions in this file are the minimum required functions* for this driver. See xemac.h for a detailed description of the driver.** <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  07/23/02 Removed the PHY reset from Initialize()* 1.00b rmm  09/23/02 Removed commented code in Initialize(). Recycled as*                     XEmac_mPhyReset macro in xemac_l.h.* 1.00c rpm  12/05/02 New version includes support for simple DMA* 1.00c rpm  12/12/02 Changed location of IsStarted assignment in XEmac_Start*                     to be sure the flag is set before the device and*                     interrupts are enabled.* 1.00c rpm  02/03/03 SelfTest was not clearing polled mode. Take driver out*                     of polled mode in XEmac_Reset() to fix this problem.* 1.00c rmm  05/13/03 Fixed diab compiler warnings relating to asserts.* 1.00d rpm  09/26/03 New version includes support PLB Ethernet and v2.00a of*                     the packet fifo driver.* 1.00e rmm  04/06/04 Changed XEmac_Initialize() to clear the instance data.*                     Added XEM_NO_SGEND_INT_OPTION processing to XEmac_Start().* 1.01a ecm  09/26/05 Changed XEmac_Initialize() to  create instance variable*                     which has the default DMA control words for the hardware.*                     Added the Chesksum offload initialization to control word.* </pre>******************************************************************************//***************************** Include Files *********************************/#include "xbasic_types.h"#include "xenv.h"#include "xemac_i.h"#include "xio.h"#include "xbuf_descriptor.h"#include "xdma_channel.h"#include "xipif_v1_23_b.h"      /* Uses v1.23b of the IPIF *//************************** Constant Definitions *****************************//**************************** Type Definitions *******************************//***************** Macros (Inline Functions) Definitions *********************//************************** Function Prototypes ******************************/XStatus Initialize(XEmac *InstancePtr, XEmac_Config *ConfigPtr);static XStatus ConfigureDma(XEmac *InstancePtr);static XStatus ConfigureFifo(XEmac *InstancePtr);static void StubFifoHandler(void *CallBackRef);static void StubErrorHandler(void *CallBackRef, XStatus ErrorCode);static void StubSgHandler(void *CallBackRef, XBufDescriptor *BdPtr,                          Xuint32 NumBds);/************************** Variable Definitions *****************************//*****************************************************************************//**** Initialize a specific XEmac instance/driver.** Retrieves the configuration table associated with the DeviceID provided.* Sets up the Instance data as determined bu the configuration table* Calls the unified local Initialize function contained in xemac,c** @param InstancePtr is a pointer to the XEmac instance to be worked on.* @param DeviceId is the unique id of the device controlled by this XEmac*        instance.  Passing in a device id associates the generic XEmac*        instance to a specific device, as chosen by the caller or application*        developer.* @param VirtualAddress is the address for the base address in the instance.*        This method is specific to Linux usage.** @return** - XST_SUCCESS if initialization was successful* - XST_DEVICE_NOT_FOUND if device configuration information was not found for*   a device with the supplied device ID.** @note** None.*******************************************************************************/XStatus XEmac_CfgInitialize(XEmac *InstancePtr, XEmac_Config *ConfigPtr,                            Xuint32 VirtualAddress){    XASSERT_NONVOID(InstancePtr != XNULL);    /* Clear instance memory */    XENV_MEM_FILL(InstancePtr, 0, sizeof(XEmac));    /*     * Assign the provided ConfigPtr to the instance.     */    InstancePtr->ConfigPtr = ConfigPtr;    /*     * Save the baseaddresses for faster access     */    InstancePtr->BaseAddress = VirtualAddress;    InstancePtr->PhysAddress = ConfigPtr->BaseAddress;    return (Initialize(InstancePtr, InstancePtr->ConfigPtr));}/*****************************************************************************//**** Start the Ethernet controller as follows:*   - If not in polled mode*       - Set the internal interrupt enable registers appropriately*       - Enable interrupts within the device itself. Note that connection of*         the driver's interrupt handler to the interrupt source (typically*         done using the interrupt controller component) is done by the higher*         layer software.*       - If the device is configured with scatter-gather DMA, start the DMA*         channels if the descriptor lists are not empty*   - Enable the transmitter*   - Enable the receiver** The PHY is enabled after driver initialization. We assume the upper layer* software has configured it and the EMAC appropriately before this function* is called.** @param InstancePtr is a pointer to the XEmac instance to be worked on.** @return** - XST_SUCCESS if the device was started successfully* - XST_NO_CALLBACK if a callback function has not yet been registered using*   the SetxxxHandler function. This is required if in interrupt mode.* - XST_DEVICE_IS_STARTED if the device is already started* - XST_DMA_SG_NO_LIST if configured for scatter-gather DMA and a descriptor*   list has not yet been created for the send or receive channel.** @note** The driver tries to match the hardware configuration. So if 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 config* 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.** This function makes use of internal resources that are shared between the* Start, Stop, and SetOptions functions. So if one task might be setting device* options while another is trying to start the device, the user is required to* provide protection of this shared data (typically using a semaphore).*******************************************************************************/XStatus XEmac_Start(XEmac *InstancePtr){    Xuint32 ControlReg;    XStatus Result;    XASSERT_NONVOID(InstancePtr != XNULL);    XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);    /*     * If it is already started, return a status indicating so     */    if (InstancePtr->IsStarted == XCOMPONENT_IS_STARTED)    {        return XST_DEVICE_IS_STARTED;    }    /*     * If not polled, enable interrupts     */    if (!InstancePtr->IsPolled)    {        /*         * Verify that the callbacks have been registered, then enable         * interrupts         */        if (XEmac_mIsSgDma(InstancePtr))        {            if ((InstancePtr->SgRecvHandler == StubSgHandler) ||                (InstancePtr->SgSendHandler == StubSgHandler))            {                return XST_NO_CALLBACK;            }            /* Enable IPIF interrupts */            XIIF_V123B_WRITE_DIER(InstancePtr->BaseAddress,                                XEM_IPIF_DMA_DFT_MASK | XIIF_V123B_ERROR_MASK);            XIIF_V123B_WRITE_IIER(InstancePtr->BaseAddress,                                XEM_EIR_DFT_SG_MASK);            /* Enable scatter-gather DMA interrupts */            ControlReg = XEM_DMA_SG_INTR_MASK;      /* Default mask */            if (InstancePtr->IsSgEndDisable)            {                ControlReg &= ~XDC_IXR_SG_END_MASK; /* Don't enable SGEND */            }            XDmaChannel_SetIntrEnable(&InstancePtr->RecvChannel, ControlReg);            XDmaChannel_SetIntrEnable(&InstancePtr->SendChannel, ControlReg);        }        else        {            if ((InstancePtr->FifoRecvHandler == StubFifoHandler) ||                (InstancePtr->FifoSendHandler == StubFifoHandler))            {                return XST_NO_CALLBACK;            }            /* Enable IPIF interrupts (used by simple DMA also) */            XIIF_V123B_WRITE_DIER(InstancePtr->BaseAddress,                                XEM_IPIF_FIFO_DFT_MASK | XIIF_V123B_ERROR_MASK);            XIIF_V123B_WRITE_IIER(InstancePtr->BaseAddress,                                XEM_EIR_DFT_FIFO_MASK);        }        /* Enable the global IPIF interrupt output */        XIIF_V123B_GINTR_ENABLE(InstancePtr->BaseAddress);    }    /*     * Indicate that the device is started before we enable the transmitter     * or receiver. This needs to be done before because as soon as the     * receiver is enabled we may get an interrupt, and there are functions     * in the interrupt handling path that rely on the IsStarted flag.     */    InstancePtr->IsStarted = XCOMPONENT_IS_STARTED;    /*     * Enable the transmitter, and receiver (do a read/modify/write to preserve     * current settings). There is no critical section here since this register     * is not modified during interrupt context.     */    ControlReg = XIo_In32(InstancePtr->BaseAddress + XEM_ECR_OFFSET);    ControlReg &= ~(XEM_ECR_XMIT_RESET_MASK | XEM_ECR_RECV_RESET_MASK);    ControlReg |= (XEM_ECR_XMIT_ENABLE_MASK | XEM_ECR_RECV_ENABLE_MASK);    XIo_Out32(InstancePtr->BaseAddress + XEM_ECR_OFFSET, ControlReg);    /*     * If configured with scatter-gather DMA and not polled, restart the     * DMA channels in case there are buffers ready to be sent or received into.     * The DMA SgStart function uses data that can be modified during interrupt     * context, so a critical section is required here.     */    if ((XEmac_mIsSgDma(InstancePtr)) && (!InstancePtr->IsPolled))    {        XIIF_V123B_GINTR_DISABLE(InstancePtr->BaseAddress);        /*         * The only error we care about is if the list has not yet been         * created, or on receive, if no buffer descriptors have been         * added yet (the list is empty). Other errors are benign at this point.         */        Result = XDmaChannel_SgStart(&InstancePtr->RecvChannel);        if ((Result == XST_DMA_SG_NO_LIST) || (Result == XST_DMA_SG_LIST_EMPTY))        {            XIIF_V123B_GINTR_ENABLE(InstancePtr->BaseAddress);            return Result;        }        Result = XDmaChannel_SgStart(&InstancePtr->SendChannel);        if (Result == XST_DMA_SG_NO_LIST)        {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -