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

📄 xtemac_control.c

📁 xilinx trimode mac driver for linux
💻 C
📖 第 1 页 / 共 3 页
字号:
/* $Id: *//********************************************************************************       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 2005-2006 Xilinx Inc.*       All rights reserved.* This program is free software; you can redistribute it and/or modify it* under the terms of the GNU General Public License as published by the* Free Software Foundation; either version 2 of the License, or (at your* option) any later version.** You should have received a copy of the GNU General Public License* along with this program; if not, write to the Free Software* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA*******************************************************************************//*****************************************************************************//** * * @file xtemac_control.c * * Functions in this file implement general purpose command and control related * functionality. See xtemac.h for a detailed description of the driver. * * <pre> * MODIFICATION HISTORY: * * Ver   Who  Date     Changes * ----- ---- -------- ------------------------------------------------------- * 1.00a rmm  06/01/05 First release * 1.00b rmm  09/23/05 Implemented PhyRead/Write and multicast functions, *                     removed Set/Get IFG functions. Redesigned MII/RGMII/ *                     SGMII status functions. * 2.00a rmm  11/21/05 Added auto negotiate to options processing funcs, *                     fixed XTE_MGTDR_OFFSET and XTE_MGTCR_OFFSET to be *                     accessed with IPIF instead of host macros, removed *                     half duplex option processing *       rmm  06/22/06 Fixed c++ compiler warnings and errors * </pre> *****************************************************************************//***************************** Include Files *********************************/#include "xtemac.h"#include "xtemac_i.h"/************************** Constant Definitions *****************************//**************************** Type Definitions *******************************//***************** Macros (Inline Functions) Definitions *********************//************************** Function Prototypes ******************************//************************** Variable Definitions *****************************//*****************************************************************************//** * Set the MAC address for this driver/device.  The address is a 48-bit value. * The device must be stopped before calling this function. * * @param InstancePtr is a pointer to the instance to be worked on. * @param AddressPtr is a pointer to a 6-byte MAC address. * * @return * - XST_SUCCESS if the MAC address was set successfully * - XST_DEVICE_IS_STARTED if the device has not yet been stopped * ******************************************************************************/XStatus XTemac_SetMacAddress(XTemac *InstancePtr, void *AddressPtr){    u32 MacAddr;    u8* Aptr = (u8*)AddressPtr;    XASSERT_NONVOID(InstancePtr != NULL);    XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);    /* Be sure device has been stopped */    if (InstancePtr->IsStarted == XCOMPONENT_IS_STARTED)    {        return(XST_DEVICE_IS_STARTED);    }    /* Set the MAC bits [31:0] in EUAW0 */    MacAddr =  Aptr[0] & 0x000000FF;    MacAddr |= Aptr[1] << 8;    MacAddr |= Aptr[2] << 16;    MacAddr |= Aptr[3] << 24;    XTemac_mSetHostReg(XTE_UAW0_OFFSET, MacAddr);    /* There are reserved bits in EUAW1 so don't affect them */    MacAddr = XTemac_mGetHostReg(XTE_UAW1_OFFSET);    MacAddr &= ~XTE_UAW1_MASK;    /* Set MAC bits [47:32] in EUAW1 */    MacAddr |= Aptr[4] & 0x000000FF;    MacAddr |= Aptr[5] << 8;    XTemac_mSetHostReg(XTE_UAW1_OFFSET, MacAddr);    return(XST_SUCCESS);}/*****************************************************************************//** * Get the MAC address for this driver/device. * * @param InstancePtr is a pointer to the instance to be worked on. * @param AddressPtr is an output parameter, and is a pointer to a buffer into *        which the current MAC address will be copied. The buffer must be at *        least 6 bytes in length. * ******************************************************************************/void XTemac_GetMacAddress(XTemac *InstancePtr, void *AddressPtr){    u32 MacAddr;    u8* Aptr = (u8*)AddressPtr;    XASSERT_VOID(InstancePtr != NULL);    XASSERT_VOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);    /* Read MAC bits [31:0] in EUAW0 */    MacAddr = XTemac_mGetHostReg(XTE_UAW0_OFFSET);    Aptr[0] = (u8)MacAddr;    Aptr[1] = (u8)(MacAddr >> 8);    Aptr[2] = (u8)(MacAddr >> 16);    Aptr[3] = (u8)(MacAddr >> 24);    /* Read MAC bits [47:32] in EUAW1 */    MacAddr = XTemac_mGetHostReg(XTE_UAW1_OFFSET);    Aptr[4] = (u8)MacAddr;    Aptr[5] = (u8)(MacAddr >> 8);}/*****************************************************************************//** * Add an Ethernet address to the list that will be accepted by the receiver. * The address may be any unicast, multicast, or the broadcast address form. * Up to XTE_MULTI_CAM_ENTRIES addresses may be filtered in this way. The * device must be stopped to use this function. * * Once an address is programmed, it will be received by the device. There is * no control bit to disable multicast filtering. The only way to prevent a * CAM address from being received is to clear it with XTemac_MulticastClear(). * * @param InstancePtr is a pointer to the XTemac instance to be worked on. * @param AddressPtr is a pointer to a 6-byte Ethernet address. The previous *        address at this entry location (if any) is overwritten with the new *        one. * @param Entry is the storage location the HW uses to program this address. *        It must be between 0..XTE_MULTI_CAM_ENTRIES-1. * * @return * * - XST_SUCCESS if the address was added successfully * - XST_DEVICE_IS_STARTED if the device has not yet been stopped ******************************************************************************/XStatus XTemac_MulticastAdd(XTemac *InstancePtr, void *AddressPtr, int Entry){    u32 Emaw0Reg;    u32 Emaw1Reg;    u8  *Aptr = (u8*)AddressPtr;    XASSERT_NONVOID(InstancePtr != NULL);    XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);    XASSERT_NONVOID(Entry < XTE_MULTI_CAM_ENTRIES);    /* The device must be stopped before clearing the multicast hash table */    if (InstancePtr->IsStarted == XCOMPONENT_IS_STARTED)    {        return(XST_DEVICE_IS_STARTED);    }    /* Set MAC bits [31:0] */    Emaw0Reg =  Aptr[0] & 0x000000FF;    Emaw0Reg |= Aptr[1] << 8;    Emaw0Reg |= Aptr[2] << 16;    Emaw0Reg |= Aptr[3] << 24;    /* Set MAC bits [47:32] */    Emaw1Reg =  Aptr[4] & 0x000000FF;    Emaw1Reg |= Aptr[5] << 8;    /* Add in CAM address */    Emaw1Reg |= (Entry << XTE_MAW1_CAMMADDR_SHIFT_MASK);    /* Program HW */    XTemac_mSetHostReg(XTE_MAW0_OFFSET, Emaw0Reg);    XTemac_mSetHostReg(XTE_MAW1_OFFSET, Emaw1Reg);    return(XST_SUCCESS);}/*****************************************************************************//** * Retrieve an Ethernet address set by XTemac_MulticastAdd(). * * @param InstancePtr is a pointer to the XTemac instance to be worked on. * @param AddressPtr is an output parameter, and is a pointer to a buffer into *        which the current MAC address will be copied. The buffer must be at *        least 6 bytes in length. * @param Entry is the storage location in the HW. It must be between *        0..XTE_MULTI_CAM_ENTRIES-1. * * @return * * - XST_SUCCESS if the address was added successfully * - XST_DEVICE_IS_STARTED if the device has not yet been stopped ******************************************************************************/void XTemac_MulticastGet(XTemac *InstancePtr, void *AddressPtr, int Entry){    u32 Emaw0Reg;    u32 Emaw1Reg;    u8  *Aptr = (u8*)AddressPtr;    XASSERT_VOID(InstancePtr != NULL);    XASSERT_VOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);    XASSERT_VOID(Entry < XTE_MULTI_CAM_ENTRIES);    /* Tell HW to provide address stored in given entry */    XTemac_mSetHostReg(XTE_MAW1_OFFSET, XTE_MAW1_CAMRNW_MASK |                       (Entry << XTE_MAW1_CAMMADDR_SHIFT_MASK));    /* The HW should now have provided the CAM entry */    Emaw0Reg = XTemac_mGetHostReg(XTE_MAW0_OFFSET);    Emaw1Reg = XTemac_mGetHostReg(XTE_MAW1_OFFSET);    /* Copy the address to the user buffer */    Aptr[0] = (u8)Emaw0Reg;    Aptr[1] = (u8)(Emaw0Reg >> 8);    Aptr[2] = (u8)(Emaw0Reg >> 16);    Aptr[3] = (u8)(Emaw0Reg >> 24);    Aptr[4] = (u8)Emaw1Reg;    Aptr[5] = (u8)(Emaw1Reg >> 8);}/*****************************************************************************//*** Clear an address set by XTemac_MulticastAdd(). The device must be stopped* before calling this function.** @param InstancePtr is a pointer to the XTemac instance to be worked on.* @param Entry is the HW storage location used when this address was added.*        It must be between 0..XTE_MULTI_CAM_ENTRIES-1.** @return** - XST_SUCCESS if the address was cleared* - XST_DEVICE_IS_STARTED if the device has not yet been stopped*******************************************************************************/XStatus XTemac_MulticastClear(XTemac *InstancePtr, int Entry){    XASSERT_NONVOID(InstancePtr != NULL);    XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);    XASSERT_NONVOID(Entry < XTE_MULTI_CAM_ENTRIES);    /* The device must be stopped before clearing the multicast hash table */    if (InstancePtr->IsStarted == XCOMPONENT_IS_STARTED)    {        return(XST_DEVICE_IS_STARTED);    }    /* Clear the entry by writing 0:0:0:0:0:0 to it */    XTemac_mSetHostReg(XTE_MAW0_OFFSET, 0);    XTemac_mSetHostReg(XTE_MAW1_OFFSET,                       Entry << XTE_MAW1_CAMMADDR_SHIFT_MASK);    return(XST_SUCCESS);}/*****************************************************************************//** * Set the MAC address for pause frames. This is the address the device will * recognize as pause frames. Pause frames transmitted with * XTemac_SendPausePacket() will also use this address. * * @param InstancePtr is a pointer to the instance to be worked on. * @param AddressPtr is a pointer to a 6-byte MAC address. * * @return * - XST_SUCCESS if the MAC address was set successfully * - XST_DEVICE_IS_STARTED if the device has not yet been stopped * ******************************************************************************/XStatus XTemac_SetMacPauseAddress(XTemac *InstancePtr, void *AddressPtr){    u32 MacAddr;    u8* Aptr = (u8*)AddressPtr;    XASSERT_NONVOID(InstancePtr != NULL);    XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);    /* Be sure device has been stopped */    if (InstancePtr->IsStarted == XCOMPONENT_IS_STARTED)    {        return(XST_DEVICE_IS_STARTED);    }    /* Set the MAC bits [31:0] in ERXC0 */    MacAddr =  Aptr[0] & 0x000000FF;    MacAddr |= Aptr[1] << 8;    MacAddr |= Aptr[2] << 16;    MacAddr |= Aptr[3] << 24;    XTemac_mSetHostReg(XTE_RXC0_OFFSET, MacAddr);    /* ERXC1 contains other info that must be preserved */    MacAddr = XTemac_mGetHostReg(XTE_RXC1_OFFSET);    MacAddr &= ~XTE_RXC1_ERXC1_MASK;;    /* Set MAC bits [47:32] */    MacAddr |= Aptr[4] & 0x000000FF;    MacAddr |= Aptr[5] << 8;    XTemac_mSetHostReg(XTE_RXC1_OFFSET, MacAddr);    return(XST_SUCCESS);}/*****************************************************************************//** * Get the MAC address for pause frames for this driver/device. * * @param InstancePtr is a pointer to the instance to be worked on. * @param AddressPtr is an output parameter, and is a pointer to a buffer into *        which the current MAC address will be copied. The buffer must be at *        least 6 bytes in length. * ******************************************************************************/void XTemac_GetMacPauseAddress(XTemac *InstancePtr, void *AddressPtr){    u32 MacAddr;    u8* Aptr = (u8*)AddressPtr;    XASSERT_VOID(InstancePtr != NULL);    XASSERT_VOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);    /* Read MAC bits [31:0] in ERXC0 */    MacAddr = XTemac_mGetHostReg(XTE_RXC0_OFFSET);    Aptr[0] = (u8)MacAddr;    Aptr[1] = (u8)(MacAddr >> 8);    Aptr[2] = (u8)(MacAddr >> 16);    Aptr[3] = (u8)(MacAddr >> 24);    /* Read MAC bits [47:32] in RXC1 */    MacAddr = XTemac_mGetHostReg(XTE_RXC1_OFFSET);    Aptr[4] = (u8)MacAddr;    Aptr[5] = (u8)(MacAddr >> 8);}/*****************************************************************************//** * Set options for the driver/device. The driver should be stopped with * XTemac_Stop() before changing options. * * @param InstancePtr is a pointer to the instance to be worked on. * @param Options are the options to set. Multiple options can be set by OR'ing *        XTE_*_OPTIONS constants together. Options not specified are not *        affected. * * @return * - XST_SUCCESS if the options were set successfully * - XST_DEVICE_IS_STARTED if the device has not yet been stopped * - XST_NO_FEATURE if setting an option requires HW support not present * * @note * See xtemac.h for a description of the available options. * ******************************************************************************/XStatus XTemac_SetOptions(XTemac *InstancePtr, u32 Options){    u32 Reg;         /* Generic register contents */    u32 RegErxc1;    /* Reflects original contents of ERXC1 */    u32 RegEtxc;     /* Reflects original contents of ETXC  */    u32 RegNewErxc1; /* Reflects new contents of ERXC1 */    u32 RegNewEtxc;  /* Reflects new contents of ETXC  */    XASSERT_NONVOID(InstancePtr != NULL);    XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);

⌨️ 快捷键说明

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