📄 sysnet.c
字号:
/* sysNet.c - IBM 405EP eval board system network initialization *//******************************************************************************* This source and object code has been made available to you by IBM on an AS-IS basis. IT IS PROVIDED WITHOUT WARRANTY OF ANY KIND, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE OR OF NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL IBM OR ITS LICENSORS BE LIABLE FOR INCIDENTAL, CONSEQUENTIAL OR PUNITIVE DAMAGES. IBM'S OR ITS LICENSOR'S DAMAGES FOR ANY CAUSE OF ACTION, WHETHER IN CONTRACT OR IN TORT, AT LAW OR AT EQUITY, SHALL BE LIMITED TO A MAXIMUM OF $1,000 PER LICENSE. No license under IBM patents or patent applications is to be implied by the copyright license. Any user of this software should understand that neither IBM nor its licensors will be responsible for any consequences resulting from the use of this software. Any person who transfers this source code or any derivative work must include the IBM copyright notice, this paragraph, and the preceding two paragraphs in the transferred software. Any person who transfers this object code or any derivative work must include the IBM copyright notice in the transferred software. COPYRIGHT I B M CORPORATION 2000 LICENSED MATERIAL - PROGRAM PROPERTY OF I B M"*******************************************************************************//* Copyright 1984-2002 Wind River Systems, Inc. *//*modification history--------------------01b,06sep02,mcg enable EMAC noise filters if not a 405EP rev 1.001a,18jul02,mcg create from walnut version 01f*//*DESCRIPTIONThis library contains board-specific routines for network subsystems.This library will support either the 405GP integrated Ethernet core calledEMAC, or an Allied Telesyn AT-2700TX PCI adapter which contains the AMDPCnet-FAST+ (AM79C972) controller.*//* This file contributes nothing if INCLUDE_NETWORK is not defined */#ifdef INCLUDE_NETWORK/* includes */#include "vxLib.h"#include "stdio.h"#include "ctype.h"#ifdef INCLUDE_LN97XEND# include "drv/pci/pciConfigLib.h"# include "drv/end/ln97xEnd.h"#endif /* INCLUDE_LN97XEND */#ifdef INCLUDE_EMAC_NETWORK# include "ibmEmacEnd.h"#endif /* INCLUDE_EMAC_NETWORK *//***** GLOBALS *****/#ifdef INCLUDE_LN97XENDunsigned char sysEnetAddr [6]; /* MAC address for the Am79C97x */ char sys97xLoadString[100]; /* load string for sys97xLoad */#endif /* INCLUDE_LN97XEND */#ifdef INCLUDE_EMAC_NETWORK char sysEmacLoadString0[100]; /* load string for ibmEmacLoad */ char sysEmacLoadString1[100]; /* load string for ibmEmacLoad */ MAL_DATA * pMalData;#endif /* INCLUDE_EMAC_NETWORK *//* Forward declarations */#ifdef INCLUDE_LN97XENDSTATUS sysln97xEndBldLoadStr(void);#endif /* INCLUDE_LN97XEND */#ifdef INCLUDE_EMAC_NETWORKSTATUS sysIbmEmacEndBldLoadStr(void);#endif /* INCLUDE_EMAC_NETWORK *//* Macros *//* The EMAC_REG_WRITE and EMAC_REG_READ macros below are needed because * on the 405EP, only EMAC0 has its MDIO interface pinned out. Both EMACs * must use the EMAC0 STACR register to access registers in its PHY. * The macros are used so ibmEmacEnd.c did not have to change. */#define EMAC_REG_WRITE(pDrvCtrl,addr,value) \ { \ sysEmacRegWrite405EP((pDrvCtrl), (addr), (value)); \ }#define EMAC_REG_READ(pDrvCtrl,addr,value) \ { \ ((value) = (sysEmacRegRead405EP((pDrvCtrl), (addr)))); \ }/* Local definitions *//* * define to use PCI memory, undef for PCI I/O * * It should work either way. If not, perhaps the * host <=> PCI bridge is not set up properly. * * This has no effect unless INCLUDE_LN97XEND */#define PCI_NETWORK_USE_MEM/******************************************************************************** sysNetHwInit - initialize the network interface** This routine initializes the network hardware to a quiescent state. It* does not connect interrupts.** Only polled mode operation is possible after calling this routine.* Interrupt mode operation is possible after the memory system has been* initialized and sysNetHwInit2() has been called.** RETURNS: N/A** SEE ALSO: sysNetHwInit2()*/void sysNetHwInit ( void ) { /* * Build the load string for the ln97x PCI Ethernet END driver. * Some of the parameters cannot be determined until runtime when the * PCI slot the card is plugged in is known. */#ifdef INCLUDE_LN97XEND sysln97xEndBldLoadStr();#endif /* INCLUDE_LN97XEND */ /* * Moved call to sysIbmEmacEndBldLoadStr() to sysNetHwInit2 because MAL * init has to be run first and requires malloc. */ return; }/******************************************************************************** sysNetHwInit2 - initialize additional features of the network interface** This routine completes initialization needed for interrupt mode operation* of the network device drivers. Interrupt handlers can be connected.* Interrupt or DMA operations can begin.** RETURNS: N/A**/void sysNetHwInit2 ( void ) {#ifdef INCLUDE_EMAC_NETWORK MAL_INIT malInitData; UINT32 dcr;#endif /* INCLUDE_EMAC_NETWORK */#ifdef INCLUDE_EMAC_NETWORK /* * If this is not a 405EP rev 1.0, enable the TX and RX noise filters for * EMAC0 and EMAC1. CPC0_JTAGID[VERS] is used to determine if this is * a 405EP rev 1.0 or not. */ dcr = sysDcrInLong(CPC0_JTAGID) & JTAG_VERS_MASK; if (dcr != 0x10000000) { dcr = sysDcrInLong(CPC0_EPRCSR); sysDcrOutLong(CPC0_EPRCSR, dcr | EPRCSR_NOISE_FILTER_BOTH); } /* * If the native EMAC Ethernet controller is being used, the Memory Access * Layer must be initialized. */ malInitData.dcrBaseReg = MAL0_DCR_BASE; malInitData.validChannels[MAL_TX_TYPE] = MAL_CHN_TX_405EP; malInitData.validChannels[MAL_RX_TYPE] = MAL_CHN_RX_405EP; malInitData.intLvlTxeob = INT_VEC_MAL_TXEOB; malInitData.intVecTxeob = INT_LVL_MAL_TXEOB; malInitData.intLvlRxeob = INT_VEC_MAL_RXEOB; malInitData.intVecRxeob = INT_LVL_MAL_RXEOB; malInitData.intLvlTxde = INT_VEC_MAL_TXDE; malInitData.intVecTxde = INT_LVL_MAL_TXDE; malInitData.intLvlRxde = INT_VEC_MAL_RXDE; malInitData.intVecRxde = INT_LVL_MAL_RXDE; malInitData.intLvlSerr = INT_VEC_MAL_SERR; malInitData.intVecSerr = INT_LVL_MAL_SERR; /* * Initialize MAL and get pointer to MAL driver control structure */ pMalData = malInit(&malInitData); /* * Build the load string for each IBM EMAC Ethernet core. */ sysIbmEmacEndBldLoadStr();#endif /* INCLUDE_EMAC_NETWORK */ return; }#ifdef INCLUDE_LN97XEND/******************************************************************************** sysln97xEndBldLoadStr - determines arguments for and builds the ln97xEndLoad* parameter string** Searches for the PCI Ethernet card, gets the base memory address of the card* that was assigned during PCI configuration, selects the correct interrupt* vector based on the PCI slot, reads the MAC address of the card, and calls* ln97xEndLoad with all of these parameters.* This function also enables the Ethernet card for PCI memory cycles and* and bus mastership.** RETURNS: ERROR if the PCI card is not found**/STATUS sysln97xEndBldLoadStr ( void ) { int i; UCHAR intvec; UCHAR intlvl; void * pciMemAddr; void * pciIOAddr; int bus; int device; int function; /* Initially set the PCI memory and I/O addresses to NONE */ pciMemAddr = (void *)NONE; pciIOAddr = (void *)NONE; /* * Find and configure the first AMD Am79C97x device on the PCI bus. */ if (pciFindDevice(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_79C97X, 0, &bus, &device, &function)) { return(ERROR); }#ifdef PCI_NETWORK_USE_MEM /* * Base Address 1 of the 97x contains the PCI Memory space base address. * Translate the PCI address into a processor address. The 97x does not * support prefetching. */ ibmPciConfigRead(bus, device, function, PCI_CFG_BASE_ADDRESS_1, 4, &pciMemAddr); pciMemAddr = (void *)((UINT)pciMemAddr & 0xFFFFFFF0); pciMemAddr = PCI_MEMIO2LOCAL(pciMemAddr);#else /* PCI_NETWORK_USE_MEM */ /* * Base Address 0 of the 97x contains the PCI I/O space base address. * Translate the PCI address into a processor address. */ ibmPciConfigRead(bus, device, function, PCI_CFG_BASE_ADDRESS_0, 4, &pciIOAddr); pciIOAddr = (void *)((UINT)pciIOAddr & 0xFFFFFFFC); pciIOAddr = PCI_IO2LOCAL(pciIOAddr);#endif /* PCI_NETWORK_USE_MEM */ /* * Each PCI slot on the board is connected to a different pin on * the chip's integrated Universal Interrupt Controller. The UIC pin was * was written to the Interrupt Line config register in each device by the * PCI auto-configuration code. */ ibmPciConfigRead(bus, device, function, PCI_CFG_DEV_INT_LINE, 1, &intvec); intlvl = intvec; /* * Copy the hardware address from the APROM area to the board_cfg structure * and elsewhere. The PCI Ethernet adapter has a serial EEPROM on-board * that contains the MAC address of the card. When the card first powers up, * the address is copied into the APROM registers. The value in the APROM * regs will be read from the card and placed into the global variable * sysEnetAddr so the driver can find it. */ for (i=0; i<6; i++) {#ifdef PCI_NETWORK_USE_MEM sysEnetAddr[i] = sysInByte((UINT)pciMemAddr + APROM01 + i);#else /* PCI_NETWORK_USE_MEM */ sysEnetAddr[i] = sysInByte((UINT)pciIOAddr + APROM01 + i);#endif /* PCI_NETWORK_USE_MEM */ } /* * Build the initialization string. It looks like this: * * <devMemAddr>:<devIoAddr>:<pciMemBase>:<vecNum>:<intLvl>:<memAdrs>: * <memSize>:<memWidth>:<csr3b>:<offset>:<flags> * * The unit number will be tacked onto the beginning by muxEndLoad */ sprintf(sys97xLoadString, "0x%x:0x%x:0x%x:%d:%d:0x%x:0:0x%x:0:0:0", (UINT)pciMemAddr, (UINT)pciIOAddr, (UINT)PCI_SLV_MEM_BUS, intvec, intlvl, NONE, NONE); return(OK); }/******************************************************************************** sysLan97xIntEnable - enable the LAN interrupt** Enables the interrupt in the UIC corresponding to the PCI slot where* the Ethernet card was found** RETURNS: N/A**/STATUS sysLan97xIntEnable ( UINT intlvl
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -