📄 xemac_multicast.c
字号:
/* $Id: xemac_multicast.c,v 1.1 2005/10/26 15:44:52 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_multicast.c** Contains functions to configure multicast addressing in the Ethernet MAC.** <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.00c rpm 12/05/02 New version includes support for simple DMA* 1.00d rpm 09/26/03 New version includes support PLB Ethernet and v2.00a of* the packet fifo driver.* 1.00f rmm 10/19/04 Changed multicast function implementation for CAM based* filtering.* </pre>*******************************************************************************//***************************** Include Files *********************************/#include "xbasic_types.h"#include "xemac_i.h"#include "xio.h"/************************** Constant Definitions *****************************//**************************** Type Definitions *******************************//***************** Macros (Inline Functions) Definitions *********************//************************** Function Prototypes ******************************//************************** Variable Definitions *****************************//*****************************************************************************//**** Add an Ethernet address to the list that will be accepted by the receiver.* The address may be in unicast or multicast form. Up to XEM_MULTI_CAM_ENTRIES* addresses may be filtered in this way. The device must be stopped to use* this function.** To enable receive address filtering based on the addresses stored by this* function, the user must enable the XEM_MULTICAST_CAM_OPTION.** This driver does not remember which entry was used to store a specific* address, nor does the HW provide a way to read back stored addresses. * Therefore, it is entirely up to the application to manage the addresses.* * @param InstancePtr is a pointer to the XEmac instance to be worked on.* @param AddressPtr is a pointer to a 6-byte unicast or multicast 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..XEM_MULTI_CAM_ENTRIES-1. When deleting this* address (see XEmac_MulticastClear()), use the same Entry.** @return** - XST_SUCCESS if the address was added successfully* - XST_NO_FEATURE if the device is not configured with CAM support* - XST_DEVICE_IS_STARTED if the device has not yet been stopped*******************************************************************************/XStatus XEmac_MulticastAdd(XEmac *InstancePtr, Xuint8 *AddressPtr, int Entry){ Xuint32 Addr; Xuint32 ControlReg; XASSERT_NONVOID(InstancePtr != XNULL); XASSERT_NONVOID(AddressPtr != XNULL); XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY); XASSERT_NONVOID(Entry < XEM_MULTI_CAM_ENTRIES); /* Make sure the device has multicast hash table support */ if (!XEmac_mHasCam(InstancePtr)) { return XST_NO_FEATURE; } /* The device must be stopped before adding a multicast address */ if (InstancePtr->IsStarted == XCOMPONENT_IS_STARTED) { return XST_DEVICE_IS_STARTED; } /* Set the low part of the address bits 31:0 */ Addr = (AddressPtr[2] << 24) | (AddressPtr[3] << 16) | (AddressPtr[4] << 8) | AddressPtr[5]; XIo_Out32(InstancePtr->BaseAddress + XEM_CAML_OFFSET, Addr); /* Set the high part of the address bits 47:32 and its HW storage address */ Addr = (AddressPtr[0] << 8) | AddressPtr[1] | ((Entry << XEM_CAMH_SLOT_SHIFT) & XEM_CAMH_SLOT_MASK); XIo_Out32(InstancePtr->BaseAddress + XEM_CAMH_OFFSET, Addr); /* Trigger the HW to program the address by setting one of the ECR control * bits. The bit will automatically reset back to 0. */ ControlReg = XIo_In32(InstancePtr->BaseAddress + XEM_ECR_OFFSET); XIo_Out32(InstancePtr->BaseAddress + XEM_ECR_OFFSET, ControlReg | XEM_ECR_WRITE_CAM_MASK); return XST_SUCCESS;}/*****************************************************************************//**** Clear an address set by XEmac_MulticastAdd(). The device must be stopped* before calling this function.** @param InstancePtr is a pointer to the XEmac instance to be worked on.* @param Entry is the HW storage location used when this address was added.* It must be between 0..XEM_MULTI_CAM_ENTRIES-1. ** @return** - XST_SUCCESS if the address was cleared* - XST_NO_FEATURE if the device is not configured with CAM support* - XST_DEVICE_IS_STARTED if the device has not yet been stopped*******************************************************************************/XStatus XEmac_MulticastClear(XEmac *InstancePtr, int Entry){ Xuint32 ControlReg; XASSERT_NONVOID(InstancePtr != XNULL); XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY); XASSERT_NONVOID(Entry < XEM_MULTI_CAM_ENTRIES); /* Make sure the device has multicast hash table support */ if (!XEmac_mHasCam(InstancePtr)) { return XST_NO_FEATURE; } /* 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 */ XIo_Out32(InstancePtr->BaseAddress + XEM_CAML_OFFSET, 0); XIo_Out32(InstancePtr->BaseAddress + XEM_CAMH_OFFSET, ((Entry << XEM_CAMH_SLOT_SHIFT) & XEM_CAMH_SLOT_MASK)); /* Trigger the HW to clear the address by setting one of the ECR control * bits. The bit will automatically reset back to 0. */ ControlReg = XIo_In32(InstancePtr->BaseAddress + XEM_ECR_OFFSET); XIo_Out32(InstancePtr->BaseAddress + XEM_ECR_OFFSET, ControlReg | XEM_ECR_WRITE_CAM_MASK); return XST_SUCCESS;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -