parent
6f5a40d81a
commit
7837210e23
|
@ -1,3 +1,4 @@
|
|||
obj-y += cpu.o interrupts.o
|
||||
obj-y += start.o
|
||||
obj-y += imx/
|
||||
head-y += start.o
|
||||
#obj-y += imx/
|
||||
obj-y += at91rm9200/
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
obj-y += bcm5221.o
|
||||
obj-y += dm9161.o
|
||||
obj-$(CONFIG_DRIVER_NET_AT91_ETHER += ether.o
|
||||
obj-$(CONFIG_DRIVER_NET_AT91_ETHER) += ether.o
|
||||
obj-y += i2c.o
|
||||
obj-y += interrupts.o
|
||||
obj-y += lowlevel_init.o
|
||||
|
|
|
@ -1,299 +0,0 @@
|
|||
/*
|
||||
* (C) Copyright 2003
|
||||
* Author : Hamid Ikdoumi (Atmel)
|
||||
*
|
||||
* See file CREDITS for list of people who contributed to this
|
||||
* project.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* 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., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <at91rm9200_net.h>
|
||||
#include <net.h>
|
||||
#include <miiphy.h>
|
||||
|
||||
/* ----- Ethernet Buffer definitions ----- */
|
||||
|
||||
typedef struct {
|
||||
unsigned long addr, size;
|
||||
} rbf_t;
|
||||
|
||||
#define RBF_ADDR 0xfffffffc
|
||||
#define RBF_OWNER (1<<0)
|
||||
#define RBF_WRAP (1<<1)
|
||||
#define RBF_BROADCAST (1<<31)
|
||||
#define RBF_MULTICAST (1<<30)
|
||||
#define RBF_UNICAST (1<<29)
|
||||
#define RBF_EXTERNAL (1<<28)
|
||||
#define RBF_UNKOWN (1<<27)
|
||||
#define RBF_SIZE 0x07ff
|
||||
#define RBF_LOCAL4 (1<<26)
|
||||
#define RBF_LOCAL3 (1<<25)
|
||||
#define RBF_LOCAL2 (1<<24)
|
||||
#define RBF_LOCAL1 (1<<23)
|
||||
|
||||
#define RBF_FRAMEMAX 64
|
||||
#define RBF_FRAMELEN 0x600
|
||||
|
||||
#ifdef CONFIG_DRIVER_ETHER
|
||||
|
||||
#if (CONFIG_COMMANDS & CFG_CMD_NET)
|
||||
|
||||
/* alignment as per Errata #11 (64 bytes) is insufficient! */
|
||||
rbf_t rbfdt[RBF_FRAMEMAX] __attribute((aligned(512)));
|
||||
rbf_t *rbfp;
|
||||
|
||||
unsigned char rbf_framebuf[RBF_FRAMEMAX][RBF_FRAMELEN] __attribute((aligned(4)));
|
||||
|
||||
/* structure to interface the PHY */
|
||||
AT91S_PhyOps PhyOps;
|
||||
|
||||
AT91PS_EMAC p_mac;
|
||||
|
||||
/*********** EMAC Phy layer Management functions *************************/
|
||||
/*
|
||||
* Name:
|
||||
* at91rm9200_EmacEnableMDIO
|
||||
* Description:
|
||||
* Enables the MDIO bit in MAC control register
|
||||
* Arguments:
|
||||
* p_mac - pointer to struct AT91S_EMAC
|
||||
* Return value:
|
||||
* none
|
||||
*/
|
||||
void at91rm9200_EmacEnableMDIO (AT91PS_EMAC p_mac)
|
||||
{
|
||||
/* Mac CTRL reg set for MDIO enable */
|
||||
p_mac->EMAC_CTL |= AT91C_EMAC_MPE; /* Management port enable */
|
||||
}
|
||||
|
||||
/*
|
||||
* Name:
|
||||
* at91rm9200_EmacDisableMDIO
|
||||
* Description:
|
||||
* Disables the MDIO bit in MAC control register
|
||||
* Arguments:
|
||||
* p_mac - pointer to struct AT91S_EMAC
|
||||
* Return value:
|
||||
* none
|
||||
*/
|
||||
void at91rm9200_EmacDisableMDIO (AT91PS_EMAC p_mac)
|
||||
{
|
||||
/* Mac CTRL reg set for MDIO disable */
|
||||
p_mac->EMAC_CTL &= ~AT91C_EMAC_MPE; /* Management port disable */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Name:
|
||||
* at91rm9200_EmacReadPhy
|
||||
* Description:
|
||||
* Reads data from the PHY register
|
||||
* Arguments:
|
||||
* dev - pointer to struct net_device
|
||||
* RegisterAddress - unsigned char
|
||||
* pInput - pointer to value read from register
|
||||
* Return value:
|
||||
* TRUE - if data read successfully
|
||||
*/
|
||||
UCHAR at91rm9200_EmacReadPhy (AT91PS_EMAC p_mac,
|
||||
unsigned char RegisterAddress,
|
||||
unsigned short *pInput)
|
||||
{
|
||||
p_mac->EMAC_MAN = (AT91C_EMAC_HIGH & ~AT91C_EMAC_LOW) |
|
||||
(AT91C_EMAC_RW_R) |
|
||||
(RegisterAddress << 18) |
|
||||
(AT91C_EMAC_CODE_802_3);
|
||||
|
||||
udelay (10000);
|
||||
|
||||
*pInput = (unsigned short) p_mac->EMAC_MAN;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Name:
|
||||
* at91rm9200_EmacWritePhy
|
||||
* Description:
|
||||
* Writes data to the PHY register
|
||||
* Arguments:
|
||||
* dev - pointer to struct net_device
|
||||
* RegisterAddress - unsigned char
|
||||
* pOutput - pointer to value to be written in the register
|
||||
* Return value:
|
||||
* TRUE - if data read successfully
|
||||
*/
|
||||
UCHAR at91rm9200_EmacWritePhy (AT91PS_EMAC p_mac,
|
||||
unsigned char RegisterAddress,
|
||||
unsigned short *pOutput)
|
||||
{
|
||||
p_mac->EMAC_MAN = (AT91C_EMAC_HIGH & ~AT91C_EMAC_LOW) |
|
||||
AT91C_EMAC_CODE_802_3 | AT91C_EMAC_RW_W |
|
||||
(RegisterAddress << 18) | *pOutput;
|
||||
|
||||
udelay (10000);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int eth_init (bd_t * bd)
|
||||
{
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
p_mac = AT91C_BASE_EMAC;
|
||||
|
||||
/* PIO Disable Register */
|
||||
*AT91C_PIOA_PDR = AT91C_PA16_EMDIO | AT91C_PA15_EMDC | AT91C_PA14_ERXER |
|
||||
AT91C_PA13_ERX1 | AT91C_PA12_ERX0 | AT91C_PA11_ECRS_ECRSDV |
|
||||
AT91C_PA10_ETX1 | AT91C_PA9_ETX0 | AT91C_PA8_ETXEN |
|
||||
AT91C_PA7_ETXCK_EREFCK;
|
||||
|
||||
#ifdef CONFIG_AT91C_USE_RMII
|
||||
*AT91C_PIOB_PDR = AT91C_PB19_ERXCK;
|
||||
*AT91C_PIOB_BSR = AT91C_PB19_ERXCK;
|
||||
#else
|
||||
*AT91C_PIOB_PDR = AT91C_PB19_ERXCK | AT91C_PB18_ECOL | AT91C_PB17_ERXDV |
|
||||
AT91C_PB16_ERX3 | AT91C_PB15_ERX2 | AT91C_PB14_ETXER |
|
||||
AT91C_PB13_ETX3 | AT91C_PB12_ETX2;
|
||||
|
||||
/* Select B Register */
|
||||
*AT91C_PIOB_BSR = AT91C_PB19_ERXCK | AT91C_PB18_ECOL |
|
||||
AT91C_PB17_ERXDV | AT91C_PB16_ERX3 | AT91C_PB15_ERX2 |
|
||||
AT91C_PB14_ETXER | AT91C_PB13_ETX3 | AT91C_PB12_ETX2;
|
||||
#endif
|
||||
|
||||
*AT91C_PMC_PCER = 1 << AT91C_ID_EMAC; /* Peripheral Clock Enable Register */
|
||||
|
||||
p_mac->EMAC_CFG |= AT91C_EMAC_CSR; /* Clear statistics */
|
||||
|
||||
/* Init Ehternet buffers */
|
||||
for (i = 0; i < RBF_FRAMEMAX; i++) {
|
||||
rbfdt[i].addr = (unsigned long)rbf_framebuf[i];
|
||||
rbfdt[i].size = 0;
|
||||
}
|
||||
rbfdt[RBF_FRAMEMAX - 1].addr |= RBF_WRAP;
|
||||
rbfp = &rbfdt[0];
|
||||
|
||||
p_mac->EMAC_SA2L = (bd->bi_enetaddr[3] << 24) | (bd->bi_enetaddr[2] << 16)
|
||||
| (bd->bi_enetaddr[1] << 8) | (bd->bi_enetaddr[0]);
|
||||
p_mac->EMAC_SA2H = (bd->bi_enetaddr[5] << 8) | (bd->bi_enetaddr[4]);
|
||||
|
||||
p_mac->EMAC_RBQP = (long) (&rbfdt[0]);
|
||||
p_mac->EMAC_RSR &= ~(AT91C_EMAC_RSR_OVR | AT91C_EMAC_REC | AT91C_EMAC_BNA);
|
||||
|
||||
p_mac->EMAC_CFG = (p_mac->EMAC_CFG | AT91C_EMAC_CAF | AT91C_EMAC_NBC)
|
||||
& ~AT91C_EMAC_CLK;
|
||||
|
||||
#ifdef CONFIG_AT91C_USE_RMII
|
||||
p_mac->EMAC_CFG |= AT91C_EMAC_RMII;
|
||||
#endif
|
||||
|
||||
#if (AT91C_MASTER_CLOCK > 40000000)
|
||||
/* MDIO clock must not exceed 2.5 MHz, so enable MCK divider */
|
||||
p_mac->EMAC_CFG |= AT91C_EMAC_CLK_HCLK_64;
|
||||
#endif
|
||||
|
||||
p_mac->EMAC_CTL |= AT91C_EMAC_TE | AT91C_EMAC_RE;
|
||||
|
||||
at91rm9200_GetPhyInterface (& PhyOps);
|
||||
|
||||
if (!PhyOps.IsPhyConnected (p_mac))
|
||||
printf ("PHY not connected!!\n\r");
|
||||
|
||||
/* MII management start from here */
|
||||
if (!(p_mac->EMAC_SR & AT91C_EMAC_LINK)) {
|
||||
if (!(ret = PhyOps.Init (p_mac))) {
|
||||
printf ("MAC: error during MII initialization\n");
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
printf ("No link\n\r");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int eth_send (volatile void *packet, int length)
|
||||
{
|
||||
while (!(p_mac->EMAC_TSR & AT91C_EMAC_BNQ));
|
||||
p_mac->EMAC_TAR = (long) packet;
|
||||
p_mac->EMAC_TCR = length;
|
||||
while (p_mac->EMAC_TCR & 0x7ff);
|
||||
p_mac->EMAC_TSR |= AT91C_EMAC_COMP;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int eth_rx (void)
|
||||
{
|
||||
int size;
|
||||
|
||||
if (!(rbfp->addr & RBF_OWNER))
|
||||
return 0;
|
||||
|
||||
size = rbfp->size & RBF_SIZE;
|
||||
NetReceive ((volatile uchar *) (rbfp->addr & RBF_ADDR), size);
|
||||
|
||||
rbfp->addr &= ~RBF_OWNER;
|
||||
if (rbfp->addr & RBF_WRAP)
|
||||
rbfp = &rbfdt[0];
|
||||
else
|
||||
rbfp++;
|
||||
|
||||
p_mac->EMAC_RSR |= AT91C_EMAC_REC;
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
void eth_halt (void)
|
||||
{
|
||||
};
|
||||
|
||||
#if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)
|
||||
int at91rm9200_miiphy_read(char *devname, unsigned char addr,
|
||||
unsigned char reg, unsigned short * value)
|
||||
{
|
||||
at91rm9200_EmacEnableMDIO (p_mac);
|
||||
at91rm9200_EmacReadPhy (p_mac, reg, value);
|
||||
at91rm9200_EmacDisableMDIO (p_mac);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int at91rm9200_miiphy_write(char *devname, unsigned char addr,
|
||||
unsigned char reg, unsigned short value)
|
||||
{
|
||||
at91rm9200_EmacEnableMDIO (p_mac);
|
||||
at91rm9200_EmacWritePhy (p_mac, reg, &value);
|
||||
at91rm9200_EmacDisableMDIO (p_mac);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII) */
|
||||
|
||||
int at91rm9200_miiphy_initialize(bd_t *bis)
|
||||
{
|
||||
#if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)
|
||||
miiphy_register("at91rm9200phy", at91rm9200_miiphy_read, at91rm9200_miiphy_write);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_COMMANDS & CFG_CMD_NET */
|
||||
|
||||
#endif /* CONFIG_DRIVER_ETHER */
|
|
@ -1,600 +0,0 @@
|
|||
/*
|
||||
* (C) Copyright 2000-2004
|
||||
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
||||
*
|
||||
* See file CREDITS for list of people who contributed to this
|
||||
* project.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* 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., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <malloc.h>
|
||||
#include <asm/fec.h>
|
||||
|
||||
#ifdef CONFIG_M5271
|
||||
#include <asm/m5271.h>
|
||||
#include <asm/immap_5271.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_M5272
|
||||
#include <asm/m5272.h>
|
||||
#include <asm/immap_5272.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_M5282
|
||||
#include <asm/m5282.h>
|
||||
#include <asm/immap_5282.h>
|
||||
#endif
|
||||
|
||||
#include <net.h>
|
||||
#include <command.h>
|
||||
|
||||
#ifdef CONFIG_M5272
|
||||
#define FEC_ADDR (CFG_MBAR + 0x840)
|
||||
#endif
|
||||
#if defined(CONFIG_M5282) || defined(CONFIG_M5271)
|
||||
#define FEC_ADDR (CFG_MBAR + 0x1000)
|
||||
#endif
|
||||
|
||||
#undef ET_DEBUG
|
||||
#undef MII_DEBUG
|
||||
|
||||
#if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(FEC_ENET)
|
||||
|
||||
#ifdef CFG_DISCOVER_PHY
|
||||
#include <miiphy.h>
|
||||
static void mii_discover_phy (void);
|
||||
#endif
|
||||
|
||||
/* Ethernet Transmit and Receive Buffers */
|
||||
#define DBUF_LENGTH 1520
|
||||
|
||||
#define TX_BUF_CNT 2
|
||||
|
||||
#define TOUT_LOOP 100
|
||||
|
||||
#define PKT_MAXBUF_SIZE 1518
|
||||
#define PKT_MINBUF_SIZE 64
|
||||
#define PKT_MAXBLR_SIZE 1520
|
||||
|
||||
|
||||
static char txbuf[DBUF_LENGTH];
|
||||
|
||||
static uint rxIdx; /* index of the current RX buffer */
|
||||
static uint txIdx; /* index of the current TX buffer */
|
||||
|
||||
/*
|
||||
* FEC Ethernet Tx and Rx buffer descriptors allocated at the
|
||||
* immr->udata_bd address on Dual-Port RAM
|
||||
* Provide for Double Buffering
|
||||
*/
|
||||
|
||||
typedef volatile struct CommonBufferDescriptor {
|
||||
cbd_t rxbd[PKTBUFSRX]; /* Rx BD */
|
||||
cbd_t txbd[TX_BUF_CNT]; /* Tx BD */
|
||||
} RTXBD;
|
||||
|
||||
static RTXBD *rtx = NULL;
|
||||
|
||||
int eth_send (volatile void *packet, int length)
|
||||
{
|
||||
int j, rc;
|
||||
volatile fec_t *fecp = (fec_t *) (FEC_ADDR);
|
||||
|
||||
/* section 16.9.23.3
|
||||
* Wait for ready
|
||||
*/
|
||||
j = 0;
|
||||
while ((rtx->txbd[txIdx].cbd_sc & BD_ENET_TX_READY)
|
||||
&& (j < TOUT_LOOP)) {
|
||||
udelay (1);
|
||||
j++;
|
||||
}
|
||||
if (j >= TOUT_LOOP) {
|
||||
printf ("TX not ready\n");
|
||||
}
|
||||
|
||||
rtx->txbd[txIdx].cbd_bufaddr = (uint) packet;
|
||||
rtx->txbd[txIdx].cbd_datlen = length;
|
||||
rtx->txbd[txIdx].cbd_sc |= BD_ENET_TX_READY | BD_ENET_TX_LAST;
|
||||
|
||||
/* Activate transmit Buffer Descriptor polling */
|
||||
fecp->fec_x_des_active = 0x01000000; /* Descriptor polling active */
|
||||
|
||||
j = 0;
|
||||
while ((rtx->txbd[txIdx].cbd_sc & BD_ENET_TX_READY)
|
||||
&& (j < TOUT_LOOP)) {
|
||||
udelay (1);
|
||||
j++;
|
||||
}
|
||||
if (j >= TOUT_LOOP) {
|
||||
printf ("TX timeout\n");
|
||||
}
|
||||
#ifdef ET_DEBUG
|
||||
printf ("%s[%d] %s: cycles: %d status: %x retry cnt: %d\n",
|
||||
__FILE__, __LINE__, __FUNCTION__, j, rtx->txbd[txIdx].cbd_sc,
|
||||
(rtx->txbd[txIdx].cbd_sc & 0x003C) >> 2);
|
||||
#endif
|
||||
|
||||
/* return only status bits */ ;
|
||||
rc = (rtx->txbd[txIdx].cbd_sc & BD_ENET_TX_STATS);
|
||||
|
||||
txIdx = (txIdx + 1) % TX_BUF_CNT;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int eth_rx (void)
|
||||
{
|
||||
int length;
|
||||
volatile fec_t *fecp = (fec_t *) FEC_ADDR;
|
||||
|
||||
for (;;) {
|
||||
/* section 16.9.23.2 */
|
||||
if (rtx->rxbd[rxIdx].cbd_sc & BD_ENET_RX_EMPTY) {
|
||||
length = -1;
|
||||
break; /* nothing received - leave for() loop */
|
||||
}
|
||||
|
||||
length = rtx->rxbd[rxIdx].cbd_datlen;
|
||||
|
||||
if (rtx->rxbd[rxIdx].cbd_sc & 0x003f) {
|
||||
#ifdef ET_DEBUG
|
||||
printf ("%s[%d] err: %x\n",
|
||||
__FUNCTION__, __LINE__,
|
||||
rtx->rxbd[rxIdx].cbd_sc);
|
||||
#endif
|
||||
} else {
|
||||
/* Pass the packet up to the protocol layers. */
|
||||
NetReceive (NetRxPackets[rxIdx], length - 4);
|
||||
}
|
||||
|
||||
/* Give the buffer back to the FEC. */
|
||||
rtx->rxbd[rxIdx].cbd_datlen = 0;
|
||||
|
||||
/* wrap around buffer index when necessary */
|
||||
if ((rxIdx + 1) >= PKTBUFSRX) {
|
||||
rtx->rxbd[PKTBUFSRX - 1].cbd_sc =
|
||||
(BD_ENET_RX_WRAP | BD_ENET_RX_EMPTY);
|
||||
rxIdx = 0;
|
||||
} else {
|
||||
rtx->rxbd[rxIdx].cbd_sc = BD_ENET_RX_EMPTY;
|
||||
rxIdx++;
|
||||
}
|
||||
|
||||
/* Try to fill Buffer Descriptors */
|
||||
fecp->fec_r_des_active = 0x01000000; /* Descriptor polling active */
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
/**************************************************************
|
||||
*
|
||||
* FEC Ethernet Initialization Routine
|
||||
*
|
||||
*************************************************************/
|
||||
#define FEC_ECNTRL_ETHER_EN 0x00000002
|
||||
#define FEC_ECNTRL_RESET 0x00000001
|
||||
|
||||
#define FEC_RCNTRL_BC_REJ 0x00000010
|
||||
#define FEC_RCNTRL_PROM 0x00000008
|
||||
#define FEC_RCNTRL_MII_MODE 0x00000004
|
||||
#define FEC_RCNTRL_DRT 0x00000002
|
||||
#define FEC_RCNTRL_LOOP 0x00000001
|
||||
|
||||
#define FEC_TCNTRL_FDEN 0x00000004
|
||||
#define FEC_TCNTRL_HBC 0x00000002
|
||||
#define FEC_TCNTRL_GTS 0x00000001
|
||||
|
||||
#define FEC_RESET_DELAY 50000
|
||||
|
||||
int eth_init (bd_t * bd)
|
||||
{
|
||||
#ifndef CFG_ENET_BD_BASE
|
||||
DECLARE_GLOBAL_DATA_PTR;
|
||||
#endif
|
||||
int i;
|
||||
volatile fec_t *fecp = (fec_t *) (FEC_ADDR);
|
||||
|
||||
/* Whack a reset.
|
||||
* A delay is required between a reset of the FEC block and
|
||||
* initialization of other FEC registers because the reset takes
|
||||
* some time to complete. If you don't delay, subsequent writes
|
||||
* to FEC registers might get killed by the reset routine which is
|
||||
* still in progress.
|
||||
*/
|
||||
fecp->fec_ecntrl = FEC_ECNTRL_RESET;
|
||||
for (i = 0;
|
||||
(fecp->fec_ecntrl & FEC_ECNTRL_RESET) && (i < FEC_RESET_DELAY);
|
||||
++i) {
|
||||
udelay (1);
|
||||
}
|
||||
if (i == FEC_RESET_DELAY) {
|
||||
printf ("FEC_RESET_DELAY timeout\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* We use strictly polling mode only
|
||||
*/
|
||||
fecp->fec_imask = 0;
|
||||
|
||||
/* Clear any pending interrupt */
|
||||
fecp->fec_ievent = 0xffffffff;
|
||||
|
||||
/* Set station address */
|
||||
#define ea bd->bi_enetaddr
|
||||
fecp->fec_addr_low = (ea[0] << 24) | (ea[1] << 16) |
|
||||
(ea[2] << 8) | (ea[3]);
|
||||
fecp->fec_addr_high = (ea[4] << 24) | (ea[5] << 16);
|
||||
#ifdef ET_DEBUG
|
||||
printf ("Eth Addrs: %02x:%02x:%02x:%02x:%02x:%02x\n",
|
||||
ea[0], ea[1], ea[2], ea[3], ea[4], ea[5]);
|
||||
#endif
|
||||
#undef ea
|
||||
|
||||
#ifdef CONFIG_M5271
|
||||
/* Clear multicast address hash table
|
||||
*/
|
||||
fecp->fec_ghash_table_high = 0;
|
||||
fecp->fec_ghash_table_low = 0;
|
||||
|
||||
/* Clear individual address hash table
|
||||
*/
|
||||
fecp->fec_ihash_table_high = 0;
|
||||
fecp->fec_ihash_table_low = 0;
|
||||
#else
|
||||
/* Clear multicast address hash table
|
||||
*/
|
||||
#ifdef CONFIG_M5282
|
||||
fecp->fec_ihash_table_high = 0;
|
||||
fecp->fec_ihash_table_low = 0;
|
||||
#else
|
||||
fecp->fec_hash_table_high = 0;
|
||||
fecp->fec_hash_table_low = 0;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Set maximum receive buffer size.
|
||||
*/
|
||||
fecp->fec_r_buff_size = PKT_MAXBLR_SIZE;
|
||||
|
||||
/*
|
||||
* Setup Buffers and Buffer Desriptors
|
||||
*/
|
||||
rxIdx = 0;
|
||||
txIdx = 0;
|
||||
|
||||
if (!rtx) {
|
||||
#ifdef CFG_ENET_BD_BASE
|
||||
rtx = (RTXBD *) CFG_ENET_BD_BASE;
|
||||
#else
|
||||
rtx = (RTXBD *) (CFG_MONITOR_BASE+gd->reloc_off -
|
||||
(((PKTBUFSRX+TX_BUF_CNT)*+sizeof(cbd_t)
|
||||
+0xFF)
|
||||
& ~0xFF)
|
||||
);
|
||||
debug("set ENET_DB_BASE to %lX\n",(long) rtx);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Setup Receiver Buffer Descriptors (13.14.24.18)
|
||||
* Settings:
|
||||
* Empty, Wrap
|
||||
*/
|
||||
for (i = 0; i < PKTBUFSRX; i++) {
|
||||
rtx->rxbd[i].cbd_sc = BD_ENET_RX_EMPTY;
|
||||
rtx->rxbd[i].cbd_datlen = 0; /* Reset */
|
||||
rtx->rxbd[i].cbd_bufaddr = (uint) NetRxPackets[i];
|
||||
}
|
||||
rtx->rxbd[PKTBUFSRX - 1].cbd_sc |= BD_ENET_RX_WRAP;
|
||||
|
||||
/*
|
||||
* Setup Ethernet Transmitter Buffer Descriptors (13.14.24.19)
|
||||
* Settings:
|
||||
* Last, Tx CRC
|
||||
*/
|
||||
for (i = 0; i < TX_BUF_CNT; i++) {
|
||||
rtx->txbd[i].cbd_sc = BD_ENET_TX_LAST | BD_ENET_TX_TC;
|
||||
rtx->txbd[i].cbd_datlen = 0; /* Reset */
|
||||
rtx->txbd[i].cbd_bufaddr = (uint) (&txbuf[0]);
|
||||
}
|
||||
rtx->txbd[TX_BUF_CNT - 1].cbd_sc |= BD_ENET_TX_WRAP;
|
||||
|
||||
/* Set receive and transmit descriptor base
|
||||
*/
|
||||
fecp->fec_r_des_start = (unsigned int) (&rtx->rxbd[0]);
|
||||
fecp->fec_x_des_start = (unsigned int) (&rtx->txbd[0]);
|
||||
|
||||
/* Enable MII mode
|
||||
*/
|
||||
|
||||
fecp->fec_r_cntrl = (PKT_MAXBUF_SIZE << 16); /* set max frame length */
|
||||
fecp->fec_r_cntrl |= FEC_RCNTRL_MII_MODE | FEC_RCNTRL_DRT;
|
||||
fecp->fec_x_cntrl = 0;
|
||||
/* Set MII speed */
|
||||
fecp->fec_mii_speed = (((CFG_CLK / 2) / (2500000 / 10)) + 5) / 10;
|
||||
fecp->fec_mii_speed *= 2;
|
||||
|
||||
/* Configure port B for MII.
|
||||
*/
|
||||
/* port initialization was already made in cpu_init_f() */
|
||||
|
||||
/* Now enable the transmit and receive processing
|
||||
*/
|
||||
fecp->fec_ecntrl = FEC_ECNTRL_ETHER_EN;
|
||||
|
||||
#ifdef CFG_DISCOVER_PHY
|
||||
/* wait for the PHY to wake up after reset */
|
||||
mii_discover_phy ();
|
||||
#endif
|
||||
|
||||
/* And last, try to fill Rx Buffer Descriptors */
|
||||
fecp->fec_r_des_active = 0x01000000; /* Descriptor polling active */
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void eth_halt (void)
|
||||
{
|
||||
volatile fec_t *fecp = (fec_t *) FEC_ADDR;
|
||||
|
||||
fecp->fec_ecntrl = 0;
|
||||
}
|
||||
|
||||
|
||||
#if defined(CFG_DISCOVER_PHY) || (CONFIG_COMMANDS & CFG_CMD_MII)
|
||||
|
||||
static int phyaddr = -1; /* didn't find a PHY yet */
|
||||
static uint phytype;
|
||||
|
||||
/* Make MII read/write commands for the FEC.
|
||||
*/
|
||||
|
||||
#define mk_mii_read(ADDR, REG) (0x60020000 | ((ADDR << 23) | \
|
||||
(REG & 0x1f) << 18))
|
||||
|
||||
#define mk_mii_write(ADDR, REG, VAL) (0x50020000 | ((ADDR << 23) | \
|
||||
(REG & 0x1f) << 18) | \
|
||||
(VAL & 0xffff))
|
||||
|
||||
/* Interrupt events/masks.
|
||||
*/
|
||||
#define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */
|
||||
#define FEC_ENET_BABR ((uint)0x40000000) /* Babbling receiver */
|
||||
#define FEC_ENET_BABT ((uint)0x20000000) /* Babbling transmitter */
|
||||
#define FEC_ENET_GRA ((uint)0x10000000) /* Graceful stop complete */
|
||||
#define FEC_ENET_TXF ((uint)0x08000000) /* Full frame transmitted */
|
||||
#define FEC_ENET_TXB ((uint)0x04000000) /* A buffer was transmitted */
|
||||
#define FEC_ENET_RXF ((uint)0x02000000) /* Full frame received */
|
||||
#define FEC_ENET_RXB ((uint)0x01000000) /* A buffer was received */
|
||||
#define FEC_ENET_MII ((uint)0x00800000) /* MII interrupt */
|
||||
#define FEC_ENET_EBERR ((uint)0x00400000) /* SDMA bus error */
|
||||
|
||||
/* PHY identification
|
||||
*/
|
||||
#define PHY_ID_LXT970 0x78100000 /* LXT970 */
|
||||
#define PHY_ID_LXT971 0x001378e0 /* LXT971 and 972 */
|
||||
#define PHY_ID_82555 0x02a80150 /* Intel 82555 */
|
||||
#define PHY_ID_QS6612 0x01814400 /* QS6612 */
|
||||
#define PHY_ID_AMD79C784 0x00225610 /* AMD 79C784 */
|
||||
#define PHY_ID_LSI80225 0x0016f870 /* LSI 80225 */
|
||||
#define PHY_ID_LSI80225B 0x0016f880 /* LSI 80225/B */
|
||||
|
||||
/* send command to phy using mii, wait for result */
|
||||
static uint mii_send (uint mii_cmd)
|
||||
{
|
||||
uint mii_reply;
|
||||
volatile fec_t *ep = (fec_t *) (FEC_ADDR);
|
||||
|
||||
ep->fec_mii_data = mii_cmd; /* command to phy */
|
||||
|
||||
/* wait for mii complete */
|
||||
while (!(ep->fec_ievent & FEC_ENET_MII)); /* spin until done */
|
||||
mii_reply = ep->fec_mii_data; /* result from phy */
|
||||
ep->fec_ievent = FEC_ENET_MII; /* clear MII complete */
|
||||
#ifdef ET_DEBUG
|
||||
printf ("%s[%d] %s: sent=0x%8.8x, reply=0x%8.8x\n",
|
||||
__FILE__, __LINE__, __FUNCTION__, mii_cmd, mii_reply);
|
||||
#endif
|
||||
return (mii_reply & 0xffff); /* data read from phy */
|
||||
}
|
||||
#endif /* CFG_DISCOVER_PHY || (CONFIG_COMMANDS & CFG_CMD_MII) */
|
||||
|
||||
#if defined(CFG_DISCOVER_PHY)
|
||||
static void mii_discover_phy (void)
|
||||
{
|
||||
#define MAX_PHY_PASSES 11
|
||||
uint phyno;
|
||||
int pass;
|
||||
|
||||
phyaddr = -1; /* didn't find a PHY yet */
|
||||
for (pass = 1; pass <= MAX_PHY_PASSES && phyaddr < 0; ++pass) {
|
||||
if (pass > 1) {
|
||||
/* PHY may need more time to recover from reset.
|
||||
* The LXT970 needs 50ms typical, no maximum is
|
||||
* specified, so wait 10ms before try again.
|
||||
* With 11 passes this gives it 100ms to wake up.
|
||||
*/
|
||||
udelay (10000); /* wait 10ms */
|
||||
}
|
||||
for (phyno = 1; phyno < 32 && phyaddr < 0; ++phyno) {
|
||||
phytype = mii_send (mk_mii_read (phyno, PHY_PHYIDR1));
|
||||
#ifdef ET_DEBUG
|
||||
printf ("PHY type 0x%x pass %d type ", phytype, pass);
|
||||
#endif
|
||||
if (phytype != 0xffff) {
|
||||
phyaddr = phyno;
|
||||
phytype <<= 16;
|
||||
phytype |= mii_send (mk_mii_read (phyno,
|
||||
PHY_PHYIDR2));
|
||||
|
||||
#ifdef ET_DEBUG
|
||||
printf ("PHY @ 0x%x pass %d type ", phyno,
|
||||
pass);
|
||||
switch (phytype & 0xfffffff0) {
|
||||
case PHY_ID_LXT970:
|
||||
printf ("LXT970\n");
|
||||
break;
|
||||
case PHY_ID_LXT971:
|
||||
printf ("LXT971\n");
|
||||
break;
|
||||
case PHY_ID_82555:
|
||||
printf ("82555\n");
|
||||
break;
|
||||
case PHY_ID_QS6612:
|
||||
printf ("QS6612\n");
|
||||
break;
|
||||
case PHY_ID_AMD79C784:
|
||||
printf ("AMD79C784\n");
|
||||
break;
|
||||
case PHY_ID_LSI80225B:
|
||||
printf ("LSI L80225/B\n");
|
||||
break;
|
||||
default:
|
||||
printf ("0x%08x\n", phytype);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
if (phyaddr < 0) {
|
||||
printf ("No PHY device found.\n");
|
||||
}
|
||||
}
|
||||
#endif /* CFG_DISCOVER_PHY */
|
||||
|
||||
#if (CONFIG_COMMANDS & CFG_CMD_MII) && !defined(CONFIG_BITBANGMII)
|
||||
|
||||
static int mii_init_done = 0;
|
||||
|
||||
/****************************************************************************
|
||||
* mii_init -- Initialize the MII for MII command without ethernet
|
||||
* This function is a subset of eth_init
|
||||
****************************************************************************
|
||||
*/
|
||||
void mii_init (void)
|
||||
{
|
||||
volatile fec_t *fecp = (fec_t *) (FEC_ADDR);
|
||||
|
||||
int i;
|
||||
|
||||
if (mii_init_done != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Whack a reset.
|
||||
* A delay is required between a reset of the FEC block and
|
||||
* initialization of other FEC registers because the reset takes
|
||||
* some time to complete. If you don't delay, subsequent writes
|
||||
* to FEC registers might get killed by the reset routine which is
|
||||
* still in progress.
|
||||
*/
|
||||
|
||||
fecp->fec_ecntrl = FEC_ECNTRL_RESET;
|
||||
for (i = 0;
|
||||
(fecp->fec_ecntrl & FEC_ECNTRL_RESET) && (i < FEC_RESET_DELAY);
|
||||
++i) {
|
||||
udelay (1);
|
||||
}
|
||||
if (i == FEC_RESET_DELAY) {
|
||||
printf ("FEC_RESET_DELAY timeout\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* We use strictly polling mode only
|
||||
*/
|
||||
fecp->fec_imask = 0;
|
||||
|
||||
/* Clear any pending interrupt
|
||||
*/
|
||||
fecp->fec_ievent = 0xffffffff;
|
||||
|
||||
/* Set MII speed */
|
||||
fecp->fec_mii_speed = 0x0e;
|
||||
|
||||
/* Configure port B for MII.
|
||||
*/
|
||||
/* port initialization was already made in cpu_init_f() */
|
||||
|
||||
/* Now enable the transmit and receive processing */
|
||||
fecp->fec_ecntrl = FEC_ECNTRL_ETHER_EN;
|
||||
|
||||
mii_init_done = 1;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* Read and write a MII PHY register, routines used by MII Utilities
|
||||
*
|
||||
* FIXME: These routines are expected to return 0 on success, but mii_send
|
||||
* does _not_ return an error code. Maybe 0xFFFF means error, i.e.
|
||||
* no PHY connected...
|
||||
* For now always return 0.
|
||||
* FIXME: These routines only work after calling eth_init() at least once!
|
||||
* Otherwise they hang in mii_send() !!! Sorry!
|
||||
*****************************************************************************/
|
||||
|
||||
int mcf52x2_miiphy_read (char *devname, unsigned char addr,
|
||||
unsigned char reg, unsigned short *value)
|
||||
{
|
||||
short rdreg; /* register working value */
|
||||
|
||||
#ifdef MII_DEBUG
|
||||
printf ("miiphy_read(0x%x) @ 0x%x = ", reg, addr);
|
||||
#endif
|
||||
rdreg = mii_send (mk_mii_read (addr, reg));
|
||||
|
||||
*value = rdreg;
|
||||
|
||||
#ifdef MII_DEBUG
|
||||
printf ("0x%04x\n", *value);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mcf52x2_miiphy_write (char *devname, unsigned char addr,
|
||||
unsigned char reg, unsigned short value)
|
||||
{
|
||||
short rdreg; /* register working value */
|
||||
|
||||
#ifdef MII_DEBUG
|
||||
printf ("miiphy_write(0x%x) @ 0x%x = ", reg, addr);
|
||||
#endif
|
||||
|
||||
rdreg = mii_send (mk_mii_write (addr, reg, value));
|
||||
|
||||
#ifdef MII_DEBUG
|
||||
printf ("0x%04x\n", value);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* (CONFIG_COMMANDS & CFG_CMD_MII) && !defined(CONFIG_BITBANGMII) */
|
||||
#endif /* CFG_CMD_NET, FEC_ENET */
|
||||
|
||||
int mcf52x2_miiphy_initialize(bd_t *bis)
|
||||
{
|
||||
#if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(FEC_ENET)
|
||||
#if (CONFIG_COMMANDS & CFG_CMD_MII) && !defined(CONFIG_BITBANGMII)
|
||||
miiphy_register("mcf52x2phy", mcf52x2_miiphy_read, mcf52x2_miiphy_write);
|
||||
#endif
|
||||
#endif
|
||||
return 0;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,348 +0,0 @@
|
|||
/*
|
||||
* MPC8260 SCC Ethernet
|
||||
*
|
||||
* Copyright (c) 2000 MontaVista Software, Inc. Dan Malek (dmalek@jlc.net)
|
||||
*
|
||||
* (C) Copyright 2000 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
|
||||
* Marius Groeger <mgroeger@sysgo.de>
|
||||
*
|
||||
* (C) Copyright (c) 2001
|
||||
* Advent Networks, Inc. <http://www.adventnetworks.com>
|
||||
* Jay Monkman <jtm@smoothsmoothie.com>
|
||||
*
|
||||
* See file CREDITS for list of people who contributed to this
|
||||
* project.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* 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., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <asm/cpm_8260.h>
|
||||
#include <mpc8260.h>
|
||||
#include <net.h>
|
||||
#include <command.h>
|
||||
#include <config.h>
|
||||
|
||||
#if defined(CONFIG_ETHER_ON_SCC) && (CONFIG_COMMANDS & CFG_CMD_NET)
|
||||
|
||||
#if (CONFIG_ETHER_INDEX == 1)
|
||||
# define PROFF_ENET PROFF_SCC1
|
||||
# define CPM_CR_ENET_PAGE CPM_CR_SCC1_PAGE
|
||||
# define CPM_CR_ENET_SBLOCK CPM_CR_SCC1_SBLOCK
|
||||
# define CMXSCR_MASK (CMXSCR_SC1 |\
|
||||
CMXSCR_RS1CS_MSK |\
|
||||
CMXSCR_TS1CS_MSK)
|
||||
|
||||
#elif (CONFIG_ETHER_INDEX == 2)
|
||||
# define PROFF_ENET PROFF_SCC2
|
||||
# define CPM_CR_ENET_PAGE CPM_CR_SCC2_PAGE
|
||||
# define CPM_CR_ENET_SBLOCK CPM_CR_SCC2_SBLOCK
|
||||
# define CMXSCR_MASK (CMXSCR_SC2 |\
|
||||
CMXSCR_RS2CS_MSK |\
|
||||
CMXSCR_TS2CS_MSK)
|
||||
|
||||
#elif (CONFIG_ETHER_INDEX == 3)
|
||||
# define PROFF_ENET PROFF_SCC3
|
||||
# define CPM_CR_ENET_PAGE CPM_CR_SCC3_PAGE
|
||||
# define CPM_CR_ENET_SBLOCK CPM_CR_SCC3_SBLOCK
|
||||
# define CMXSCR_MASK (CMXSCR_SC3 |\
|
||||
CMXSCR_RS3CS_MSK |\
|
||||
CMXSCR_TS3CS_MSK)
|
||||
#elif (CONFIG_ETHER_INDEX == 4)
|
||||
# define PROFF_ENET PROFF_SCC4
|
||||
# define CPM_CR_ENET_PAGE CPM_CR_SCC4_PAGE
|
||||
# define CPM_CR_ENET_SBLOCK CPM_CR_SCC4_SBLOCK
|
||||
# define CMXSCR_MASK (CMXSCR_SC4 |\
|
||||
CMXSCR_RS4CS_MSK |\
|
||||
CMXSCR_TS4CS_MSK)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* Ethernet Transmit and Receive Buffers */
|
||||
#define DBUF_LENGTH 1520
|
||||
|
||||
#define TX_BUF_CNT 2
|
||||
|
||||
#define TOUT_LOOP 1000000
|
||||
|
||||
static char txbuf[TX_BUF_CNT][ DBUF_LENGTH ];
|
||||
|
||||
static uint rxIdx; /* index of the current RX buffer */
|
||||
static uint txIdx; /* index of the current TX buffer */
|
||||
|
||||
/*
|
||||
* SCC Ethernet Tx and Rx buffer descriptors allocated at the
|
||||
* immr->udata_bd address on Dual-Port RAM
|
||||
* Provide for Double Buffering
|
||||
*/
|
||||
|
||||
typedef volatile struct CommonBufferDescriptor {
|
||||
cbd_t rxbd[PKTBUFSRX]; /* Rx BD */
|
||||
cbd_t txbd[TX_BUF_CNT]; /* Tx BD */
|
||||
} RTXBD;
|
||||
|
||||
static RTXBD *rtx;
|
||||
|
||||
|
||||
int eth_send(volatile void *packet, int length)
|
||||
{
|
||||
int i;
|
||||
int result = 0;
|
||||
|
||||
if (length <= 0) {
|
||||
printf("scc: bad packet size: %d\n", length);
|
||||
goto out;
|
||||
}
|
||||
|
||||
for(i=0; rtx->txbd[txIdx].cbd_sc & BD_ENET_TX_READY; i++) {
|
||||
if (i >= TOUT_LOOP) {
|
||||
puts ("scc: tx buffer not ready\n");
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
rtx->txbd[txIdx].cbd_bufaddr = (uint)packet;
|
||||
rtx->txbd[txIdx].cbd_datlen = length;
|
||||
rtx->txbd[txIdx].cbd_sc |= (BD_ENET_TX_READY | BD_ENET_TX_LAST |
|
||||
BD_ENET_TX_WRAP);
|
||||
|
||||
for(i=0; rtx->txbd[txIdx].cbd_sc & BD_ENET_TX_READY; i++) {
|
||||
if (i >= TOUT_LOOP) {
|
||||
puts ("scc: tx error\n");
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
/* return only status bits */
|
||||
result = rtx->txbd[txIdx].cbd_sc & BD_ENET_TX_STATS;
|
||||
|
||||
out:
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int eth_rx(void)
|
||||
{
|
||||
int length;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (rtx->rxbd[rxIdx].cbd_sc & BD_ENET_RX_EMPTY) {
|
||||
length = -1;
|
||||
break; /* nothing received - leave for() loop */
|
||||
}
|
||||
|
||||
length = rtx->rxbd[rxIdx].cbd_datlen;
|
||||
|
||||
if (rtx->rxbd[rxIdx].cbd_sc & 0x003f)
|
||||
{
|
||||
printf("err: %x\n", rtx->rxbd[rxIdx].cbd_sc);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Pass the packet up to the protocol layers. */
|
||||
NetReceive(NetRxPackets[rxIdx], length - 4);
|
||||
}
|
||||
|
||||
|
||||
/* Give the buffer back to the SCC. */
|
||||
rtx->rxbd[rxIdx].cbd_datlen = 0;
|
||||
|
||||
/* wrap around buffer index when necessary */
|
||||
if ((rxIdx + 1) >= PKTBUFSRX) {
|
||||
rtx->rxbd[PKTBUFSRX - 1].cbd_sc = (BD_ENET_RX_WRAP |
|
||||
BD_ENET_RX_EMPTY);
|
||||
rxIdx = 0;
|
||||
}
|
||||
else {
|
||||
rtx->rxbd[rxIdx].cbd_sc = BD_ENET_RX_EMPTY;
|
||||
rxIdx++;
|
||||
}
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
/**************************************************************
|
||||
*
|
||||
* SCC Ethernet Initialization Routine
|
||||
*
|
||||
*************************************************************/
|
||||
|
||||
int eth_init(bd_t *bis)
|
||||
{
|
||||
int i;
|
||||
volatile immap_t *immr = (immap_t *)CFG_IMMR;
|
||||
scc_enet_t *pram_ptr;
|
||||
uint dpaddr;
|
||||
|
||||
rxIdx = 0;
|
||||
txIdx = 0;
|
||||
|
||||
/* assign static pointer to BD area */
|
||||
dpaddr = m8260_cpm_dpalloc(sizeof(RTXBD) + 2, 16);
|
||||
rtx = (RTXBD *)&immr->im_dprambase[dpaddr];
|
||||
|
||||
/* 24.21 - (1-3): ioports have been set up already */
|
||||
|
||||
/* 24.21 - (4,5): connect SCC's tx and rx clocks, use NMSI for SCC */
|
||||
immr->im_cpmux.cmx_uar = 0;
|
||||
immr->im_cpmux.cmx_scr = ( (immr->im_cpmux.cmx_scr & ~CMXSCR_MASK) |
|
||||
CFG_CMXSCR_VALUE);
|
||||
|
||||
|
||||
/* 24.21 (6) write RBASE and TBASE to parameter RAM */
|
||||
pram_ptr = (scc_enet_t *)&(immr->im_dprambase[PROFF_ENET]);
|
||||
pram_ptr->sen_genscc.scc_rbase = (unsigned int)(&rtx->rxbd[0]);
|
||||
pram_ptr->sen_genscc.scc_tbase = (unsigned int)(&rtx->txbd[0]);
|
||||
|
||||
pram_ptr->sen_genscc.scc_rfcr = 0x18; /* Nrml Ops and Mot byte ordering */
|
||||
pram_ptr->sen_genscc.scc_tfcr = 0x18; /* Mot byte ordering, Nrml access */
|
||||
|
||||
pram_ptr->sen_genscc.scc_mrblr = DBUF_LENGTH; /* max. package len 1520 */
|
||||
|
||||
pram_ptr->sen_cpres = ~(0x0); /* Preset CRC */
|
||||
pram_ptr->sen_cmask = 0xdebb20e3; /* Constant Mask for CRC */
|
||||
|
||||
|
||||
/* 24.21 - (7): Write INIT RX AND TX PARAMETERS to CPCR */
|
||||
while(immr->im_cpm.cp_cpcr & CPM_CR_FLG);
|
||||
immr->im_cpm.cp_cpcr = mk_cr_cmd(CPM_CR_ENET_PAGE,
|
||||
CPM_CR_ENET_SBLOCK,
|
||||
0x0c,
|
||||
CPM_CR_INIT_TRX) | CPM_CR_FLG;
|
||||
|
||||
/* 24.21 - (8-18): Set up parameter RAM */
|
||||
pram_ptr->sen_crcec = 0x0; /* Error Counter CRC (unused) */
|
||||
pram_ptr->sen_alec = 0x0; /* Align Error Counter (unused) */
|
||||
pram_ptr->sen_disfc = 0x0; /* Discard Frame Counter (unused) */
|
||||
|
||||
pram_ptr->sen_pads = 0x8888; /* Short Frame PAD Characters */
|
||||
|
||||
pram_ptr->sen_retlim = 15; /* Retry Limit Threshold */
|
||||
|
||||
pram_ptr->sen_maxflr = 1518; /* MAX Frame Length Register */
|
||||
pram_ptr->sen_minflr = 64; /* MIN Frame Length Register */
|
||||
|
||||
pram_ptr->sen_maxd1 = DBUF_LENGTH; /* MAX DMA1 Length Register */
|
||||
pram_ptr->sen_maxd2 = DBUF_LENGTH; /* MAX DMA2 Length Register */
|
||||
|
||||
pram_ptr->sen_gaddr1 = 0x0; /* Group Address Filter 1 (unused) */
|
||||
pram_ptr->sen_gaddr2 = 0x0; /* Group Address Filter 2 (unused) */
|
||||
pram_ptr->sen_gaddr3 = 0x0; /* Group Address Filter 3 (unused) */
|
||||
pram_ptr->sen_gaddr4 = 0x0; /* Group Address Filter 4 (unused) */
|
||||
|
||||
# define ea bis->bi_enetaddr
|
||||
pram_ptr->sen_paddrh = (ea[5] << 8) + ea[4];
|
||||
pram_ptr->sen_paddrm = (ea[3] << 8) + ea[2];
|
||||
pram_ptr->sen_paddrl = (ea[1] << 8) + ea[0];
|
||||
# undef ea
|
||||
|
||||
pram_ptr->sen_pper = 0x0; /* Persistence (unused) */
|
||||
|
||||
pram_ptr->sen_iaddr1 = 0x0; /* Individual Address Filter 1 (unused) */
|
||||
pram_ptr->sen_iaddr2 = 0x0; /* Individual Address Filter 2 (unused) */
|
||||
pram_ptr->sen_iaddr3 = 0x0; /* Individual Address Filter 3 (unused) */
|
||||
pram_ptr->sen_iaddr4 = 0x0; /* Individual Address Filter 4 (unused) */
|
||||
|
||||
pram_ptr->sen_taddrh = 0x0; /* Tmp Address (MSB) (unused) */
|
||||
pram_ptr->sen_taddrm = 0x0; /* Tmp Address (unused) */
|
||||
pram_ptr->sen_taddrl = 0x0; /* Tmp Address (LSB) (unused) */
|
||||
|
||||
|
||||
/* 24.21 - (19): Initialize RxBD */
|
||||
for (i = 0; i < PKTBUFSRX; i++)
|
||||
{
|
||||
rtx->rxbd[i].cbd_sc = BD_ENET_RX_EMPTY;
|
||||
rtx->rxbd[i].cbd_datlen = 0; /* Reset */
|
||||
rtx->rxbd[i].cbd_bufaddr = (uint)NetRxPackets[i];
|
||||
}
|
||||
|
||||
rtx->rxbd[PKTBUFSRX - 1].cbd_sc |= BD_ENET_RX_WRAP;
|
||||
|
||||
/* 24.21 - (20): Initialize TxBD */
|
||||
for (i = 0; i < TX_BUF_CNT; i++)
|
||||
{
|
||||
rtx->txbd[i].cbd_sc = (BD_ENET_TX_PAD |
|
||||
BD_ENET_TX_LAST |
|
||||
BD_ENET_TX_TC);
|
||||
rtx->txbd[i].cbd_datlen = 0; /* Reset */
|
||||
rtx->txbd[i].cbd_bufaddr = (uint)&txbuf[i][0];
|
||||
}
|
||||
|
||||
rtx->txbd[TX_BUF_CNT - 1].cbd_sc |= BD_ENET_TX_WRAP;
|
||||
|
||||
/* 24.21 - (21): Write 0xffff to SCCE */
|
||||
immr->im_scc[CONFIG_ETHER_INDEX-1].scc_scce = ~(0x0);
|
||||
|
||||
/* 24.21 - (22): Write to SCCM to enable TXE, RXF, TXB events */
|
||||
immr->im_scc[CONFIG_ETHER_INDEX-1].scc_sccm = (SCCE_ENET_TXE |
|
||||
SCCE_ENET_RXF |
|
||||
SCCE_ENET_TXB);
|
||||
|
||||
/* 24.21 - (23): we don't use ethernet interrupts */
|
||||
|
||||
/* 24.21 - (24): Clear GSMR_H to enable normal operations */
|
||||
immr->im_scc[CONFIG_ETHER_INDEX-1].scc_gsmrh = 0;
|
||||
|
||||
/* 24.21 - (25): Clear GSMR_L to enable normal operations */
|
||||
immr->im_scc[CONFIG_ETHER_INDEX-1].scc_gsmrl = (SCC_GSMRL_TCI |
|
||||
SCC_GSMRL_TPL_48 |
|
||||
SCC_GSMRL_TPP_10 |
|
||||
SCC_GSMRL_MODE_ENET);
|
||||
|
||||
/* 24.21 - (26): Initialize DSR */
|
||||
immr->im_scc[CONFIG_ETHER_INDEX-1].scc_dsr = 0xd555;
|
||||
|
||||
/* 24.21 - (27): Initialize PSMR2
|
||||
*
|
||||
* Settings:
|
||||
* CRC = 32-Bit CCITT
|
||||
* NIB = Begin searching for SFD 22 bits after RENA
|
||||
* FDE = Full Duplex Enable
|
||||
* BRO = Reject broadcast packets
|
||||
* PROMISCOUS = Catch all packets regardless of dest. MAC adress
|
||||
*/
|
||||
immr->im_scc[CONFIG_ETHER_INDEX-1].scc_psmr = SCC_PSMR_ENCRC |
|
||||
SCC_PSMR_NIB22 |
|
||||
#if defined(CONFIG_SCC_ENET_FULL_DUPLEX)
|
||||
SCC_PSMR_FDE |
|
||||
#endif
|
||||
#if defined(CONFIG_SCC_ENET_NO_BROADCAST)
|
||||
SCC_PSMR_BRO |
|
||||
#endif
|
||||
#if defined(CONFIG_SCC_ENET_PROMISCOUS)
|
||||
SCC_PSMR_PRO |
|
||||
#endif
|
||||
0;
|
||||
|
||||
/* 24.21 - (28): Write to GSMR_L to enable SCC */
|
||||
immr->im_scc[CONFIG_ETHER_INDEX-1].scc_gsmrl |= (SCC_GSMRL_ENR |
|
||||
SCC_GSMRL_ENT);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void eth_halt(void)
|
||||
{
|
||||
volatile immap_t *immr = (immap_t *)CFG_IMMR;
|
||||
immr->im_scc[CONFIG_ETHER_INDEX-1].scc_gsmrl &= ~(SCC_GSMRL_ENR |
|
||||
SCC_GSMRL_ENT);
|
||||
}
|
||||
|
||||
|
||||
#endif /* CONFIG_ETHER_ON_SCC && CFG_CMD_NET */
|
|
@ -1,470 +0,0 @@
|
|||
/*
|
||||
* MPC8560 FCC Fast Ethernet
|
||||
* Copyright (c) 2003 Motorola,Inc.
|
||||
* Xianghua Xiao, (X.Xiao@motorola.com)
|
||||
*
|
||||
* Copyright (c) 2000 MontaVista Software, Inc. Dan Malek (dmalek@jlc.net)
|
||||
*
|
||||
* (C) Copyright 2000 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
|
||||
* Marius Groeger <mgroeger@sysgo.de>
|
||||
*
|
||||
* See file CREDITS for list of people who contributed to this
|
||||
* project.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* 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., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
* MPC8560 FCC Fast Ethernet
|
||||
* Basic ET HW initialization and packet RX/TX routines
|
||||
*
|
||||
* This code will not perform the IO port configuration. This should be
|
||||
* done in the iop_conf_t structure specific for the board.
|
||||
*
|
||||
* TODO:
|
||||
* add a PHY driver to do the negotiation
|
||||
* reflect negotiation results in FPSMR
|
||||
* look for ways to configure the board specific stuff elsewhere, eg.
|
||||
* config_xxx.h or the board directory
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <malloc.h>
|
||||
#include <asm/cpm_85xx.h>
|
||||
#include <command.h>
|
||||
#include <config.h>
|
||||
#include <net.h>
|
||||
|
||||
#if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)
|
||||
#include <miiphy.h>
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_CPM2)
|
||||
|
||||
#if defined(CONFIG_ETHER_ON_FCC) && (CONFIG_COMMANDS & CFG_CMD_NET) && \
|
||||
defined(CONFIG_NET_MULTI)
|
||||
|
||||
static struct ether_fcc_info_s
|
||||
{
|
||||
int ether_index;
|
||||
int proff_enet;
|
||||
ulong cpm_cr_enet_sblock;
|
||||
ulong cpm_cr_enet_page;
|
||||
ulong cmxfcr_mask;
|
||||
ulong cmxfcr_value;
|
||||
}
|
||||
ether_fcc_info[] =
|
||||
{
|
||||
#ifdef CONFIG_ETHER_ON_FCC1
|
||||
{
|
||||
0,
|
||||
PROFF_FCC1,
|
||||
CPM_CR_FCC1_SBLOCK,
|
||||
CPM_CR_FCC1_PAGE,
|
||||
CFG_CMXFCR_MASK1,
|
||||
CFG_CMXFCR_VALUE1
|
||||
},
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ETHER_ON_FCC2
|
||||
{
|
||||
1,
|
||||
PROFF_FCC2,
|
||||
CPM_CR_FCC2_SBLOCK,
|
||||
CPM_CR_FCC2_PAGE,
|
||||
CFG_CMXFCR_MASK2,
|
||||
CFG_CMXFCR_VALUE2
|
||||
},
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ETHER_ON_FCC3
|
||||
{
|
||||
2,
|
||||
PROFF_FCC3,
|
||||
CPM_CR_FCC3_SBLOCK,
|
||||
CPM_CR_FCC3_PAGE,
|
||||
CFG_CMXFCR_MASK3,
|
||||
CFG_CMXFCR_VALUE3
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
/*---------------------------------------------------------------------*/
|
||||
|
||||
/* Maximum input DMA size. Must be a should(?) be a multiple of 4. */
|
||||
#define PKT_MAXDMA_SIZE 1520
|
||||
|
||||
/* The FCC stores dest/src/type, data, and checksum for receive packets. */
|
||||
#define PKT_MAXBUF_SIZE 1518
|
||||
#define PKT_MINBUF_SIZE 64
|
||||
|
||||
/* Maximum input buffer size. Must be a multiple of 32. */
|
||||
#define PKT_MAXBLR_SIZE 1536
|
||||
|
||||
#define TOUT_LOOP 1000000
|
||||
|
||||
#define TX_BUF_CNT 2
|
||||
|
||||
static uint rxIdx; /* index of the current RX buffer */
|
||||
static uint txIdx; /* index of the current TX buffer */
|
||||
|
||||
/*
|
||||
* FCC Ethernet Tx and Rx buffer descriptors.
|
||||
* Provide for Double Buffering
|
||||
* Note: PKTBUFSRX is defined in net.h
|
||||
*/
|
||||
|
||||
typedef volatile struct rtxbd {
|
||||
cbd_t rxbd[PKTBUFSRX];
|
||||
cbd_t txbd[TX_BUF_CNT];
|
||||
} RTXBD;
|
||||
|
||||
/* Good news: the FCC supports external BDs! */
|
||||
#ifdef __GNUC__
|
||||
static RTXBD rtx __attribute__ ((aligned(8)));
|
||||
#else
|
||||
#error "rtx must be 64-bit aligned"
|
||||
#endif
|
||||
|
||||
#undef ET_DEBUG
|
||||
|
||||
static int fec_send(struct eth_device* dev, volatile void *packet, int length)
|
||||
{
|
||||
int i = 0;
|
||||
int result = 0;
|
||||
|
||||
if (length <= 0) {
|
||||
printf("fec: bad packet size: %d\n", length);
|
||||
goto out;
|
||||
}
|
||||
|
||||
for(i=0; rtx.txbd[txIdx].cbd_sc & BD_ENET_TX_READY; i++) {
|
||||
if (i >= TOUT_LOOP) {
|
||||
printf("fec: tx buffer not ready\n");
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
rtx.txbd[txIdx].cbd_bufaddr = (uint)packet;
|
||||
rtx.txbd[txIdx].cbd_datlen = length;
|
||||
rtx.txbd[txIdx].cbd_sc |= (BD_ENET_TX_READY | BD_ENET_TX_LAST | \
|
||||
BD_ENET_TX_TC | BD_ENET_TX_PAD);
|
||||
|
||||
for(i=0; rtx.txbd[txIdx].cbd_sc & BD_ENET_TX_READY; i++) {
|
||||
if (i >= TOUT_LOOP) {
|
||||
printf("fec: tx error\n");
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ET_DEBUG
|
||||
printf("cycles: 0x%x txIdx=0x%04x status: 0x%04x\n", i, txIdx,rtx.txbd[txIdx].cbd_sc);
|
||||
printf("packets at 0x%08x, length_in_bytes=0x%x\n",(uint)packet,length);
|
||||
for(i=0;i<(length/16 + 1);i++) {
|
||||
printf("%08x %08x %08x %08x\n",*((uint *)rtx.txbd[txIdx].cbd_bufaddr+i*4),\
|
||||
*((uint *)rtx.txbd[txIdx].cbd_bufaddr + i*4 + 1),*((uint *)rtx.txbd[txIdx].cbd_bufaddr + i*4 + 2), \
|
||||
*((uint *)rtx.txbd[txIdx].cbd_bufaddr + i*4 + 3));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* return only status bits */
|
||||
result = rtx.txbd[txIdx].cbd_sc & BD_ENET_TX_STATS;
|
||||
txIdx = (txIdx + 1) % TX_BUF_CNT;
|
||||
|
||||
out:
|
||||
return result;
|
||||
}
|
||||
|
||||
static int fec_recv(struct eth_device* dev)
|
||||
{
|
||||
int length;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (rtx.rxbd[rxIdx].cbd_sc & BD_ENET_RX_EMPTY) {
|
||||
length = -1;
|
||||
break; /* nothing received - leave for() loop */
|
||||
}
|
||||
length = rtx.rxbd[rxIdx].cbd_datlen;
|
||||
|
||||
if (rtx.rxbd[rxIdx].cbd_sc & 0x003f) {
|
||||
printf("fec: rx error %04x\n", rtx.rxbd[rxIdx].cbd_sc);
|
||||
}
|
||||
else {
|
||||
/* Pass the packet up to the protocol layers. */
|
||||
NetReceive(NetRxPackets[rxIdx], length - 4);
|
||||
}
|
||||
|
||||
|
||||
/* Give the buffer back to the FCC. */
|
||||
rtx.rxbd[rxIdx].cbd_datlen = 0;
|
||||
|
||||
/* wrap around buffer index when necessary */
|
||||
if ((rxIdx + 1) >= PKTBUFSRX) {
|
||||
rtx.rxbd[PKTBUFSRX - 1].cbd_sc = (BD_ENET_RX_WRAP | BD_ENET_RX_EMPTY);
|
||||
rxIdx = 0;
|
||||
}
|
||||
else {
|
||||
rtx.rxbd[rxIdx].cbd_sc = BD_ENET_RX_EMPTY;
|
||||
rxIdx++;
|
||||
}
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
static int fec_init(struct eth_device* dev, bd_t *bis)
|
||||
{
|
||||
struct ether_fcc_info_s * info = dev->priv;
|
||||
int i;
|
||||
volatile immap_t *immr = (immap_t *)CFG_IMMR;
|
||||
volatile ccsr_cpm_cp_t *cp = &(immr->im_cpm.im_cpm_cp);
|
||||
fcc_enet_t *pram_ptr;
|
||||
unsigned long mem_addr;
|
||||
|
||||
|
||||
/* 28.9 - (1-2): ioports have been set up already */
|
||||
|
||||
/* 28.9 - (3): connect FCC's tx and rx clocks */
|
||||
immr->im_cpm.im_cpm_mux.cmxuar = 0; /* ATM */
|
||||
immr->im_cpm.im_cpm_mux.cmxfcr = (immr->im_cpm.im_cpm_mux.cmxfcr & ~info->cmxfcr_mask) |
|
||||
info->cmxfcr_value;
|
||||
|
||||
/* 28.9 - (4): GFMR: disable tx/rx, CCITT CRC, set Mode Ethernet */
|
||||
if(info->ether_index == 0) {
|
||||
immr->im_cpm.im_cpm_fcc1.gfmr = FCC_GFMR_MODE_ENET | FCC_GFMR_TCRC_32;
|
||||
} else if (info->ether_index == 1) {
|
||||
immr->im_cpm.im_cpm_fcc2.gfmr = FCC_GFMR_MODE_ENET | FCC_GFMR_TCRC_32;
|
||||
} else if (info->ether_index == 2) {
|
||||
immr->im_cpm.im_cpm_fcc3.gfmr = FCC_GFMR_MODE_ENET | FCC_GFMR_TCRC_32;
|
||||
}
|
||||
|
||||
/* 28.9 - (5): FPSMR: enable full duplex, select CCITT CRC for Ethernet,MII */
|
||||
if(info->ether_index == 0) {
|
||||
immr->im_cpm.im_cpm_fcc1.fpsmr = CFG_FCC_PSMR | FCC_PSMR_ENCRC;
|
||||
} else if (info->ether_index == 1){
|
||||
immr->im_cpm.im_cpm_fcc2.fpsmr = CFG_FCC_PSMR | FCC_PSMR_ENCRC;
|
||||
} else if (info->ether_index == 2){
|
||||
immr->im_cpm.im_cpm_fcc3.fpsmr = CFG_FCC_PSMR | FCC_PSMR_ENCRC;
|
||||
}
|
||||
|
||||
/* 28.9 - (6): FDSR: Ethernet Syn */
|
||||
if(info->ether_index == 0) {
|
||||
immr->im_cpm.im_cpm_fcc1.fdsr = 0xD555;
|
||||
} else if (info->ether_index == 1) {
|
||||
immr->im_cpm.im_cpm_fcc2.fdsr = 0xD555;
|
||||
} else if (info->ether_index == 2) {
|
||||
immr->im_cpm.im_cpm_fcc3.fdsr = 0xD555;
|
||||
}
|
||||
|
||||
/* reset indeces to current rx/tx bd (see eth_send()/eth_rx()) */
|
||||
rxIdx = 0;
|
||||
txIdx = 0;
|
||||
|
||||
/* Setup Receiver Buffer Descriptors */
|
||||
for (i = 0; i < PKTBUFSRX; i++)
|
||||
{
|
||||
rtx.rxbd[i].cbd_sc = BD_ENET_RX_EMPTY;
|
||||
rtx.rxbd[i].cbd_datlen = 0;
|
||||
rtx.rxbd[i].cbd_bufaddr = (uint)NetRxPackets[i];
|
||||
}
|
||||
rtx.rxbd[PKTBUFSRX - 1].cbd_sc |= BD_ENET_RX_WRAP;
|
||||
|
||||
/* Setup Ethernet Transmitter Buffer Descriptors */
|
||||
for (i = 0; i < TX_BUF_CNT; i++)
|
||||
{
|
||||
rtx.txbd[i].cbd_sc = 0;
|
||||
rtx.txbd[i].cbd_datlen = 0;
|
||||
rtx.txbd[i].cbd_bufaddr = 0;
|
||||
}
|
||||
rtx.txbd[TX_BUF_CNT - 1].cbd_sc |= BD_ENET_TX_WRAP;
|
||||
|
||||
/* 28.9 - (7): initialize parameter ram */
|
||||
pram_ptr = (fcc_enet_t *)&(immr->im_cpm.im_dprambase[info->proff_enet]);
|
||||
|
||||
/* clear whole structure to make sure all reserved fields are zero */
|
||||
memset((void*)pram_ptr, 0, sizeof(fcc_enet_t));
|
||||
|
||||
/*
|
||||
* common Parameter RAM area
|
||||
*
|
||||
* Allocate space in the reserved FCC area of DPRAM for the
|
||||
* internal buffers. No one uses this space (yet), so we
|
||||
* can do this. Later, we will add resource management for
|
||||
* this area.
|
||||
* CPM_FCC_SPECIAL_BASE: 0xB000 for MPC8540, MPC8560
|
||||
* 0x9000 for MPC8541, MPC8555
|
||||
*/
|
||||
mem_addr = CPM_FCC_SPECIAL_BASE + ((info->ether_index) * 64);
|
||||
pram_ptr->fen_genfcc.fcc_riptr = mem_addr;
|
||||
pram_ptr->fen_genfcc.fcc_tiptr = mem_addr+32;
|
||||
/*
|
||||
* Set maximum bytes per receive buffer.
|
||||
* It must be a multiple of 32.
|
||||
*/
|
||||
pram_ptr->fen_genfcc.fcc_mrblr = PKT_MAXBLR_SIZE; /* 1536 */
|
||||
/* localbus SDRAM should be preferred */
|
||||
pram_ptr->fen_genfcc.fcc_rstate = (CPMFCR_GBL | CPMFCR_EB |
|
||||
CFG_CPMFCR_RAMTYPE) << 24;
|
||||
pram_ptr->fen_genfcc.fcc_rbase = (unsigned int)(&rtx.rxbd[rxIdx]);
|
||||
pram_ptr->fen_genfcc.fcc_rbdstat = 0;
|
||||
pram_ptr->fen_genfcc.fcc_rbdlen = 0;
|
||||
pram_ptr->fen_genfcc.fcc_rdptr = 0;
|
||||
/* localbus SDRAM should be preferred */
|
||||
pram_ptr->fen_genfcc.fcc_tstate = (CPMFCR_GBL | CPMFCR_EB |
|
||||
CFG_CPMFCR_RAMTYPE) << 24;
|
||||
pram_ptr->fen_genfcc.fcc_tbase = (unsigned int)(&rtx.txbd[txIdx]);
|
||||
pram_ptr->fen_genfcc.fcc_tbdstat = 0;
|
||||
pram_ptr->fen_genfcc.fcc_tbdlen = 0;
|
||||
pram_ptr->fen_genfcc.fcc_tdptr = 0;
|
||||
|
||||
/* protocol-specific area */
|
||||
pram_ptr->fen_statbuf = 0x0;
|
||||
pram_ptr->fen_cmask = 0xdebb20e3; /* CRC mask */
|
||||
pram_ptr->fen_cpres = 0xffffffff; /* CRC preset */
|
||||
pram_ptr->fen_crcec = 0;
|
||||
pram_ptr->fen_alec = 0;
|
||||
pram_ptr->fen_disfc = 0;
|
||||
pram_ptr->fen_retlim = 15; /* Retry limit threshold */
|
||||
pram_ptr->fen_retcnt = 0;
|
||||
pram_ptr->fen_pper = 0;
|
||||
pram_ptr->fen_boffcnt = 0;
|
||||
pram_ptr->fen_gaddrh = 0;
|
||||
pram_ptr->fen_gaddrl = 0;
|
||||
pram_ptr->fen_mflr = PKT_MAXBUF_SIZE; /* maximum frame length register */
|
||||
/*
|
||||
* Set Ethernet station address.
|
||||
*
|
||||
* This is supplied in the board information structure, so we
|
||||
* copy that into the controller.
|
||||
* So far we have only been given one Ethernet address. We make
|
||||
* it unique by setting a few bits in the upper byte of the
|
||||
* non-static part of the address.
|
||||
*/
|
||||
#define ea eth_get_dev()->enetaddr
|
||||
pram_ptr->fen_paddrh = (ea[5] << 8) + ea[4];
|
||||
pram_ptr->fen_paddrm = (ea[3] << 8) + ea[2];
|
||||
pram_ptr->fen_paddrl = (ea[1] << 8) + ea[0];
|
||||
#undef ea
|
||||
pram_ptr->fen_ibdcount = 0;
|
||||
pram_ptr->fen_ibdstart = 0;
|
||||
pram_ptr->fen_ibdend = 0;
|
||||
pram_ptr->fen_txlen = 0;
|
||||
pram_ptr->fen_iaddrh = 0; /* disable hash */
|
||||
pram_ptr->fen_iaddrl = 0;
|
||||
pram_ptr->fen_minflr = PKT_MINBUF_SIZE; /* minimum frame length register: 64 */
|
||||
/* pad pointer. use tiptr since we don't need a specific padding char */
|
||||
pram_ptr->fen_padptr = pram_ptr->fen_genfcc.fcc_tiptr;
|
||||
pram_ptr->fen_maxd1 = PKT_MAXDMA_SIZE; /* maximum DMA1 length:1520 */
|
||||
pram_ptr->fen_maxd2 = PKT_MAXDMA_SIZE; /* maximum DMA2 length:1520 */
|
||||
|
||||
#if defined(ET_DEBUG)
|
||||
printf("parm_ptr(0xff788500) = %p\n",pram_ptr);
|
||||
printf("pram_ptr->fen_genfcc.fcc_rbase %08x\n",
|
||||
pram_ptr->fen_genfcc.fcc_rbase);
|
||||
printf("pram_ptr->fen_genfcc.fcc_tbase %08x\n",
|
||||
pram_ptr->fen_genfcc.fcc_tbase);
|
||||
#endif
|
||||
|
||||
/* 28.9 - (8)(9): clear out events in FCCE */
|
||||
/* 28.9 - (9): FCCM: mask all events */
|
||||
if(info->ether_index == 0) {
|
||||
immr->im_cpm.im_cpm_fcc1.fcce = ~0x0;
|
||||
immr->im_cpm.im_cpm_fcc1.fccm = 0;
|
||||
} else if (info->ether_index == 1) {
|
||||
immr->im_cpm.im_cpm_fcc2.fcce = ~0x0;
|
||||
immr->im_cpm.im_cpm_fcc2.fccm = 0;
|
||||
} else if (info->ether_index == 2) {
|
||||
immr->im_cpm.im_cpm_fcc3.fcce = ~0x0;
|
||||
immr->im_cpm.im_cpm_fcc3.fccm = 0;
|
||||
}
|
||||
|
||||
/* 28.9 - (10-12): we don't use ethernet interrupts */
|
||||
|
||||
/* 28.9 - (13)
|
||||
*
|
||||
* Let's re-initialize the channel now. We have to do it later
|
||||
* than the manual describes because we have just now finished
|
||||
* the BD initialization.
|
||||
*/
|
||||
cp->cpcr = mk_cr_cmd(info->cpm_cr_enet_page,
|
||||
info->cpm_cr_enet_sblock,
|
||||
0x0c,
|
||||
CPM_CR_INIT_TRX) | CPM_CR_FLG;
|
||||
do {
|
||||
__asm__ __volatile__ ("eieio");
|
||||
} while (cp->cpcr & CPM_CR_FLG);
|
||||
|
||||
/* 28.9 - (14): enable tx/rx in gfmr */
|
||||
if(info->ether_index == 0) {
|
||||
immr->im_cpm.im_cpm_fcc1.gfmr |= FCC_GFMR_ENT | FCC_GFMR_ENR;
|
||||
} else if (info->ether_index == 1) {
|
||||
immr->im_cpm.im_cpm_fcc2.gfmr |= FCC_GFMR_ENT | FCC_GFMR_ENR;
|
||||
} else if (info->ether_index == 2) {
|
||||
immr->im_cpm.im_cpm_fcc3.gfmr |= FCC_GFMR_ENT | FCC_GFMR_ENR;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void fec_halt(struct eth_device* dev)
|
||||
{
|
||||
struct ether_fcc_info_s * info = dev->priv;
|
||||
volatile immap_t *immr = (immap_t *)CFG_IMMR;
|
||||
|
||||
/* write GFMR: disable tx/rx */
|
||||
if(info->ether_index == 0) {
|
||||
immr->im_cpm.im_cpm_fcc1.gfmr &= ~(FCC_GFMR_ENT | FCC_GFMR_ENR);
|
||||
} else if(info->ether_index == 1) {
|
||||
immr->im_cpm.im_cpm_fcc2.gfmr &= ~(FCC_GFMR_ENT | FCC_GFMR_ENR);
|
||||
} else if(info->ether_index == 2) {
|
||||
immr->im_cpm.im_cpm_fcc3.gfmr &= ~(FCC_GFMR_ENT | FCC_GFMR_ENR);
|
||||
}
|
||||
}
|
||||
|
||||
int fec_initialize(bd_t *bis)
|
||||
{
|
||||
struct eth_device* dev;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sizeof(ether_fcc_info) / sizeof(ether_fcc_info[0]); i++)
|
||||
{
|
||||
dev = (struct eth_device*) malloc(sizeof *dev);
|
||||
memset(dev, 0, sizeof *dev);
|
||||
|
||||
sprintf(dev->name, "FCC%d ETHERNET",
|
||||
ether_fcc_info[i].ether_index + 1);
|
||||
dev->priv = ðer_fcc_info[i];
|
||||
dev->init = fec_init;
|
||||
dev->halt = fec_halt;
|
||||
dev->send = fec_send;
|
||||
dev->recv = fec_recv;
|
||||
|
||||
eth_register(dev);
|
||||
|
||||
#if (defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)) \
|
||||
&& defined(CONFIG_BITBANGMII)
|
||||
miiphy_register(dev->name,
|
||||
bb_miiphy_read, bb_miiphy_write);
|
||||
#endif
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_ETHER_ON_FCC && CFG_CMD_NET && CONFIG_NET_MULTI */
|
||||
|
||||
#endif /* CONFIG_CPM2 */
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue