xref: /rk3399_rockchip-uboot/drivers/net/mcffec.c (revision ec6bc928bbe852a5dae242d24cfd28f868f6286c)
18e585f02STsiChung Liew /*
28e585f02STsiChung Liew  * (C) Copyright 2000-2004
38e585f02STsiChung Liew  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
48e585f02STsiChung Liew  *
5f2208fbcSTsiChungLiew  * (C) Copyright 2007 Freescale Semiconductor, Inc.
68e585f02STsiChung Liew  * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
78e585f02STsiChung Liew  *
81a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
98e585f02STsiChung Liew  */
108e585f02STsiChung Liew 
118e585f02STsiChung Liew #include <common.h>
128e585f02STsiChung Liew #include <malloc.h>
138e585f02STsiChung Liew 
148e585f02STsiChung Liew #include <command.h>
158e585f02STsiChung Liew #include <net.h>
1689973f8aSBen Warren #include <netdev.h>
178e585f02STsiChung Liew #include <miiphy.h>
188e585f02STsiChung Liew 
1954bdcc9fSTsiChung Liew #include <asm/fec.h>
2054bdcc9fSTsiChung Liew #include <asm/immap.h>
2154bdcc9fSTsiChung Liew 
228e585f02STsiChung Liew #undef	ET_DEBUG
238e585f02STsiChung Liew #undef	MII_DEBUG
248e585f02STsiChung Liew 
258e585f02STsiChung Liew /* Ethernet Transmit and Receive Buffers */
268e585f02STsiChung Liew #define DBUF_LENGTH		1520
278e585f02STsiChung Liew #define TX_BUF_CNT		2
288e585f02STsiChung Liew #define PKT_MAXBUF_SIZE		1518
298e585f02STsiChung Liew #define PKT_MINBUF_SIZE		64
308e585f02STsiChung Liew #define PKT_MAXBLR_SIZE		1520
318e585f02STsiChung Liew #define LAST_PKTBUFSRX		PKTBUFSRX - 1
328e585f02STsiChung Liew #define BD_ENET_RX_W_E		(BD_ENET_RX_WRAP | BD_ENET_RX_EMPTY)
338e585f02STsiChung Liew #define BD_ENET_TX_RDY_LST	(BD_ENET_TX_READY | BD_ENET_TX_LAST)
348e585f02STsiChung Liew 
358e585f02STsiChung Liew DECLARE_GLOBAL_DATA_PTR;
368e585f02STsiChung Liew 
378e585f02STsiChung Liew struct fec_info_s fec_info[] = {
386d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_SYS_FEC0_IOBASE
398e585f02STsiChung Liew 	{
408e585f02STsiChung Liew 	 0,			/* index */
416d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	 CONFIG_SYS_FEC0_IOBASE,	/* io base */
426d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	 CONFIG_SYS_FEC0_PINMUX,	/* gpio pin muxing */
436d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	 CONFIG_SYS_FEC0_MIIBASE,	/* mii base */
448e585f02STsiChung Liew 	 -1,			/* phy_addr */
458e585f02STsiChung Liew 	 0,			/* duplex and speed */
468e585f02STsiChung Liew 	 0,			/* phy name */
478e585f02STsiChung Liew 	 0,			/* phyname init */
488e585f02STsiChung Liew 	 0,			/* RX BD */
498e585f02STsiChung Liew 	 0,			/* TX BD */
508e585f02STsiChung Liew 	 0,			/* rx Index */
518e585f02STsiChung Liew 	 0,			/* tx Index */
528e585f02STsiChung Liew 	 0,			/* tx buffer */
538e585f02STsiChung Liew 	 0,			/* initialized flag */
541803f7f9STsiChung Liew 	 (struct fec_info_s *)-1,
558e585f02STsiChung Liew 	 },
568e585f02STsiChung Liew #endif
576d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_SYS_FEC1_IOBASE
588e585f02STsiChung Liew 	{
598e585f02STsiChung Liew 	 1,			/* index */
606d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	 CONFIG_SYS_FEC1_IOBASE,	/* io base */
616d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	 CONFIG_SYS_FEC1_PINMUX,	/* gpio pin muxing */
626d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	 CONFIG_SYS_FEC1_MIIBASE,	/* mii base */
638e585f02STsiChung Liew 	 -1,			/* phy_addr */
648e585f02STsiChung Liew 	 0,			/* duplex and speed */
658e585f02STsiChung Liew 	 0,			/* phy name */
668e585f02STsiChung Liew 	 0,			/* phy name init */
676d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_SYS_FEC_BUF_USE_SRAM
681803f7f9STsiChung Liew 	 (cbd_t *)DBUF_LENGTH,	/* RX BD */
691803f7f9STsiChung Liew #else
708e585f02STsiChung Liew 	 0,			/* RX BD */
711803f7f9STsiChung Liew #endif
728e585f02STsiChung Liew 	 0,			/* TX BD */
738e585f02STsiChung Liew 	 0,			/* rx Index */
748e585f02STsiChung Liew 	 0,			/* tx Index */
758e585f02STsiChung Liew 	 0,			/* tx buffer */
768e585f02STsiChung Liew 	 0,			/* initialized flag */
771803f7f9STsiChung Liew 	 (struct fec_info_s *)-1,
788e585f02STsiChung Liew 	 }
798e585f02STsiChung Liew #endif
808e585f02STsiChung Liew };
818e585f02STsiChung Liew 
828e585f02STsiChung Liew int fec_recv(struct eth_device *dev);
838e585f02STsiChung Liew int fec_init(struct eth_device *dev, bd_t * bd);
848e585f02STsiChung Liew void fec_halt(struct eth_device *dev);
858e585f02STsiChung Liew void fec_reset(struct eth_device *dev);
868e585f02STsiChung Liew 
setFecDuplexSpeed(volatile fec_t * fecp,bd_t * bd,int dup_spd)878e585f02STsiChung Liew void setFecDuplexSpeed(volatile fec_t * fecp, bd_t * bd, int dup_spd)
888e585f02STsiChung Liew {
898e585f02STsiChung Liew 	if ((dup_spd >> 16) == FULL) {
908e585f02STsiChung Liew 		/* Set maximum frame length */
918e585f02STsiChung Liew 		fecp->rcr = FEC_RCR_MAX_FL(PKT_MAXBUF_SIZE) | FEC_RCR_MII_MODE |
928e585f02STsiChung Liew 		    FEC_RCR_PROM | 0x100;
938e585f02STsiChung Liew 		fecp->tcr = FEC_TCR_FDEN;
948e585f02STsiChung Liew 	} else {
958e585f02STsiChung Liew 		/* Half duplex mode */
968e585f02STsiChung Liew 		fecp->rcr = FEC_RCR_MAX_FL(PKT_MAXBUF_SIZE) |
978e585f02STsiChung Liew 		    FEC_RCR_MII_MODE | FEC_RCR_DRT;
988e585f02STsiChung Liew 		fecp->tcr &= ~FEC_TCR_FDEN;
998e585f02STsiChung Liew 	}
1008e585f02STsiChung Liew 
1018e585f02STsiChung Liew 	if ((dup_spd & 0xFFFF) == _100BASET) {
102ff36fbb2STsiChung Liew #ifdef CONFIG_MCF5445x
103ff36fbb2STsiChung Liew 		fecp->rcr &= ~0x200;	/* disabled 10T base */
104ff36fbb2STsiChung Liew #endif
1058e585f02STsiChung Liew #ifdef MII_DEBUG
1068e585f02STsiChung Liew 		printf("100Mbps\n");
1078e585f02STsiChung Liew #endif
1088e585f02STsiChung Liew 		bd->bi_ethspeed = 100;
1098e585f02STsiChung Liew 	} else {
110ff36fbb2STsiChung Liew #ifdef CONFIG_MCF5445x
111ff36fbb2STsiChung Liew 		fecp->rcr |= 0x200;	/* enabled 10T base */
112ff36fbb2STsiChung Liew #endif
1138e585f02STsiChung Liew #ifdef MII_DEBUG
1148e585f02STsiChung Liew 		printf("10Mbps\n");
1158e585f02STsiChung Liew #endif
1168e585f02STsiChung Liew 		bd->bi_ethspeed = 10;
1178e585f02STsiChung Liew 	}
1188e585f02STsiChung Liew }
1198e585f02STsiChung Liew 
fec_send(struct eth_device * dev,void * packet,int length)12010cbe3b6SJoe Hershberger static int fec_send(struct eth_device *dev, void *packet, int length)
1218e585f02STsiChung Liew {
1228e585f02STsiChung Liew 	struct fec_info_s *info = dev->priv;
1238e585f02STsiChung Liew 	volatile fec_t *fecp = (fec_t *) (info->iobase);
1248e585f02STsiChung Liew 	int j, rc;
1258e585f02STsiChung Liew 	u16 phyStatus;
1268e585f02STsiChung Liew 
1278ef583a0SMike Frysinger 	miiphy_read(dev->name, info->phy_addr, MII_BMSR, &phyStatus);
1288e585f02STsiChung Liew 
1298e585f02STsiChung Liew 	/* section 16.9.23.3
1308e585f02STsiChung Liew 	 * Wait for ready
1318e585f02STsiChung Liew 	 */
1328e585f02STsiChung Liew 	j = 0;
1338e585f02STsiChung Liew 	while ((info->txbd[info->txIdx].cbd_sc & BD_ENET_TX_READY) &&
1348e585f02STsiChung Liew 	       (j < MCFFEC_TOUT_LOOP)) {
1358e585f02STsiChung Liew 		udelay(1);
1368e585f02STsiChung Liew 		j++;
1378e585f02STsiChung Liew 	}
1388e585f02STsiChung Liew 	if (j >= MCFFEC_TOUT_LOOP) {
1398e585f02STsiChung Liew 		printf("TX not ready\n");
1408e585f02STsiChung Liew 	}
1410dca874dSTsiChung 
1428e585f02STsiChung Liew 	info->txbd[info->txIdx].cbd_bufaddr = (uint) packet;
1438e585f02STsiChung Liew 	info->txbd[info->txIdx].cbd_datlen = length;
1448e585f02STsiChung Liew 	info->txbd[info->txIdx].cbd_sc |= BD_ENET_TX_RDY_LST;
1458e585f02STsiChung Liew 
1468e585f02STsiChung Liew 	/* Activate transmit Buffer Descriptor polling */
1478e585f02STsiChung Liew 	fecp->tdar = 0x01000000;	/* Descriptor polling active    */
1488e585f02STsiChung Liew 
1496d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifndef CONFIG_SYS_FEC_BUF_USE_SRAM
1501803f7f9STsiChung Liew 	/*
1511803f7f9STsiChung Liew 	 * FEC unable to initial transmit data packet.
152f605479dSTsi-Chung Liew 	 * A nop will ensure the descriptor polling active completed.
1531803f7f9STsiChung Liew 	 * CF Internal RAM has shorter cycle access than DRAM. If use
1541803f7f9STsiChung Liew 	 * DRAM as Buffer descriptor and data, a nop is a must.
1551803f7f9STsiChung Liew 	 * Affect only V2 and V3.
156f605479dSTsi-Chung Liew 	 */
157f605479dSTsi-Chung Liew 	__asm__ ("nop");
1581803f7f9STsiChung Liew 
159f605479dSTsi-Chung Liew #endif
160f605479dSTsi-Chung Liew 
1616d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_SYS_UNIFY_CACHE
162f2208fbcSTsiChungLiew 	icache_invalid();
163f2208fbcSTsiChungLiew #endif
1641803f7f9STsiChung Liew 
1650dca874dSTsiChung 	j = 0;
1668e585f02STsiChung Liew 	while ((info->txbd[info->txIdx].cbd_sc & BD_ENET_TX_READY) &&
1678e585f02STsiChung Liew 	       (j < MCFFEC_TOUT_LOOP)) {
1688e585f02STsiChung Liew 		udelay(1);
1698e585f02STsiChung Liew 		j++;
1708e585f02STsiChung Liew 	}
1718e585f02STsiChung Liew 	if (j >= MCFFEC_TOUT_LOOP) {
1728e585f02STsiChung Liew 		printf("TX timeout\n");
1738e585f02STsiChung Liew 	}
1740dca874dSTsiChung 
1758e585f02STsiChung Liew #ifdef ET_DEBUG
1768e585f02STsiChung Liew 	printf("%s[%d] %s: cycles: %d    status: %x  retry cnt: %d\n",
1778e585f02STsiChung Liew 	       __FILE__, __LINE__, __FUNCTION__, j,
1788e585f02STsiChung Liew 	       info->txbd[info->txIdx].cbd_sc,
1798e585f02STsiChung Liew 	       (info->txbd[info->txIdx].cbd_sc & 0x003C) >> 2);
1808e585f02STsiChung Liew #endif
1818e585f02STsiChung Liew 
1820dca874dSTsiChung 	/* return only status bits */
1838e585f02STsiChung Liew 	rc = (info->txbd[info->txIdx].cbd_sc & BD_ENET_TX_STATS);
1848e585f02STsiChung Liew 	info->txIdx = (info->txIdx + 1) % TX_BUF_CNT;
1858e585f02STsiChung Liew 
1868e585f02STsiChung Liew 	return rc;
1878e585f02STsiChung Liew }
1888e585f02STsiChung Liew 
fec_recv(struct eth_device * dev)1898e585f02STsiChung Liew int fec_recv(struct eth_device *dev)
1908e585f02STsiChung Liew {
1918e585f02STsiChung Liew 	struct fec_info_s *info = dev->priv;
1928e585f02STsiChung Liew 	volatile fec_t *fecp = (fec_t *) (info->iobase);
1938e585f02STsiChung Liew 	int length;
1948e585f02STsiChung Liew 
1958e585f02STsiChung Liew 	for (;;) {
1966d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifndef CONFIG_SYS_FEC_BUF_USE_SRAM
1971803f7f9STsiChung Liew #endif
1986d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_SYS_UNIFY_CACHE
1990dca874dSTsiChung 		icache_invalid();
2000dca874dSTsiChung #endif
2018e585f02STsiChung Liew 		/* section 16.9.23.2 */
2028e585f02STsiChung Liew 		if (info->rxbd[info->rxIdx].cbd_sc & BD_ENET_RX_EMPTY) {
2038e585f02STsiChung Liew 			length = -1;
2048e585f02STsiChung Liew 			break;	/* nothing received - leave for() loop */
2058e585f02STsiChung Liew 		}
2068e585f02STsiChung Liew 
2078e585f02STsiChung Liew 		length = info->rxbd[info->rxIdx].cbd_datlen;
2088e585f02STsiChung Liew 
2098e585f02STsiChung Liew 		if (info->rxbd[info->rxIdx].cbd_sc & 0x003f) {
2108e585f02STsiChung Liew 			printf("%s[%d] err: %x\n",
2118e585f02STsiChung Liew 			       __FUNCTION__, __LINE__,
2128e585f02STsiChung Liew 			       info->rxbd[info->rxIdx].cbd_sc);
2138e585f02STsiChung Liew #ifdef ET_DEBUG
2148e585f02STsiChung Liew 			printf("%s[%d] err: %x\n",
2158e585f02STsiChung Liew 			       __FUNCTION__, __LINE__,
2168e585f02STsiChung Liew 			       info->rxbd[info->rxIdx].cbd_sc);
2178e585f02STsiChung Liew #endif
2188e585f02STsiChung Liew 		} else {
2198e585f02STsiChung Liew 
2208e585f02STsiChung Liew 			length -= 4;
2218e585f02STsiChung Liew 			/* Pass the packet up to the protocol layers. */
2221fd92db8SJoe Hershberger 			net_process_received_packet(net_rx_packets[info->rxIdx],
2231fd92db8SJoe Hershberger 						    length);
2248e585f02STsiChung Liew 
2258e585f02STsiChung Liew 			fecp->eir |= FEC_EIR_RXF;
2268e585f02STsiChung Liew 		}
2278e585f02STsiChung Liew 
2288e585f02STsiChung Liew 		/* Give the buffer back to the FEC. */
2298e585f02STsiChung Liew 		info->rxbd[info->rxIdx].cbd_datlen = 0;
2308e585f02STsiChung Liew 
2318e585f02STsiChung Liew 		/* wrap around buffer index when necessary */
2328e585f02STsiChung Liew 		if (info->rxIdx == LAST_PKTBUFSRX) {
2338e585f02STsiChung Liew 			info->rxbd[PKTBUFSRX - 1].cbd_sc = BD_ENET_RX_W_E;
2348e585f02STsiChung Liew 			info->rxIdx = 0;
2358e585f02STsiChung Liew 		} else {
2368e585f02STsiChung Liew 			info->rxbd[info->rxIdx].cbd_sc = BD_ENET_RX_EMPTY;
2378e585f02STsiChung Liew 			info->rxIdx++;
2388e585f02STsiChung Liew 		}
2398e585f02STsiChung Liew 
2408e585f02STsiChung Liew 		/* Try to fill Buffer Descriptors */
2418e585f02STsiChung Liew 		fecp->rdar = 0x01000000;	/* Descriptor polling active    */
2428e585f02STsiChung Liew 	}
2438e585f02STsiChung Liew 
2448e585f02STsiChung Liew 	return length;
2458e585f02STsiChung Liew }
2468e585f02STsiChung Liew 
2478e585f02STsiChung Liew #ifdef ET_DEBUG
dbgFecRegs(struct eth_device * dev)2488e585f02STsiChung Liew void dbgFecRegs(struct eth_device *dev)
2498e585f02STsiChung Liew {
2508e585f02STsiChung Liew 	struct fec_info_s *info = dev->priv;
2518e585f02STsiChung Liew 	volatile fec_t *fecp = (fec_t *) (info->iobase);
2528e585f02STsiChung Liew 
2538e585f02STsiChung Liew 	printf("=====\n");
2548e585f02STsiChung Liew 	printf("ievent       %x - %x\n", (int)&fecp->eir, fecp->eir);
2558e585f02STsiChung Liew 	printf("imask        %x - %x\n", (int)&fecp->eimr, fecp->eimr);
2568e585f02STsiChung Liew 	printf("r_des_active %x - %x\n", (int)&fecp->rdar, fecp->rdar);
2578e585f02STsiChung Liew 	printf("x_des_active %x - %x\n", (int)&fecp->tdar, fecp->tdar);
2588e585f02STsiChung Liew 	printf("ecntrl       %x - %x\n", (int)&fecp->ecr, fecp->ecr);
2598e585f02STsiChung Liew 	printf("mii_mframe   %x - %x\n", (int)&fecp->mmfr, fecp->mmfr);
2608e585f02STsiChung Liew 	printf("mii_speed    %x - %x\n", (int)&fecp->mscr, fecp->mscr);
2618e585f02STsiChung Liew 	printf("mii_ctrlstat %x - %x\n", (int)&fecp->mibc, fecp->mibc);
2628e585f02STsiChung Liew 	printf("r_cntrl      %x - %x\n", (int)&fecp->rcr, fecp->rcr);
2638e585f02STsiChung Liew 	printf("x_cntrl      %x - %x\n", (int)&fecp->tcr, fecp->tcr);
2648e585f02STsiChung Liew 	printf("padr_l       %x - %x\n", (int)&fecp->palr, fecp->palr);
2658e585f02STsiChung Liew 	printf("padr_u       %x - %x\n", (int)&fecp->paur, fecp->paur);
2668e585f02STsiChung Liew 	printf("op_pause     %x - %x\n", (int)&fecp->opd, fecp->opd);
2678e585f02STsiChung Liew 	printf("iadr_u       %x - %x\n", (int)&fecp->iaur, fecp->iaur);
2688e585f02STsiChung Liew 	printf("iadr_l       %x - %x\n", (int)&fecp->ialr, fecp->ialr);
2698e585f02STsiChung Liew 	printf("gadr_u       %x - %x\n", (int)&fecp->gaur, fecp->gaur);
2708e585f02STsiChung Liew 	printf("gadr_l       %x - %x\n", (int)&fecp->galr, fecp->galr);
2718e585f02STsiChung Liew 	printf("x_wmrk       %x - %x\n", (int)&fecp->tfwr, fecp->tfwr);
2728e585f02STsiChung Liew 	printf("r_bound      %x - %x\n", (int)&fecp->frbr, fecp->frbr);
2738e585f02STsiChung Liew 	printf("r_fstart     %x - %x\n", (int)&fecp->frsr, fecp->frsr);
2748e585f02STsiChung Liew 	printf("r_drng       %x - %x\n", (int)&fecp->erdsr, fecp->erdsr);
2758e585f02STsiChung Liew 	printf("x_drng       %x - %x\n", (int)&fecp->etdsr, fecp->etdsr);
2768e585f02STsiChung Liew 	printf("r_bufsz      %x - %x\n", (int)&fecp->emrbr, fecp->emrbr);
2778e585f02STsiChung Liew 
2788e585f02STsiChung Liew 	printf("\n");
2798e585f02STsiChung Liew 	printf("rmon_t_drop        %x - %x\n", (int)&fecp->rmon_t_drop,
2808e585f02STsiChung Liew 	       fecp->rmon_t_drop);
2818e585f02STsiChung Liew 	printf("rmon_t_packets     %x - %x\n", (int)&fecp->rmon_t_packets,
2828e585f02STsiChung Liew 	       fecp->rmon_t_packets);
2838e585f02STsiChung Liew 	printf("rmon_t_bc_pkt      %x - %x\n", (int)&fecp->rmon_t_bc_pkt,
2848e585f02STsiChung Liew 	       fecp->rmon_t_bc_pkt);
2858e585f02STsiChung Liew 	printf("rmon_t_mc_pkt      %x - %x\n", (int)&fecp->rmon_t_mc_pkt,
2868e585f02STsiChung Liew 	       fecp->rmon_t_mc_pkt);
2878e585f02STsiChung Liew 	printf("rmon_t_crc_align   %x - %x\n", (int)&fecp->rmon_t_crc_align,
2888e585f02STsiChung Liew 	       fecp->rmon_t_crc_align);
2898e585f02STsiChung Liew 	printf("rmon_t_undersize   %x - %x\n", (int)&fecp->rmon_t_undersize,
2908e585f02STsiChung Liew 	       fecp->rmon_t_undersize);
2918e585f02STsiChung Liew 	printf("rmon_t_oversize    %x - %x\n", (int)&fecp->rmon_t_oversize,
2928e585f02STsiChung Liew 	       fecp->rmon_t_oversize);
2938e585f02STsiChung Liew 	printf("rmon_t_frag        %x - %x\n", (int)&fecp->rmon_t_frag,
2948e585f02STsiChung Liew 	       fecp->rmon_t_frag);
2958e585f02STsiChung Liew 	printf("rmon_t_jab         %x - %x\n", (int)&fecp->rmon_t_jab,
2968e585f02STsiChung Liew 	       fecp->rmon_t_jab);
2978e585f02STsiChung Liew 	printf("rmon_t_col         %x - %x\n", (int)&fecp->rmon_t_col,
2988e585f02STsiChung Liew 	       fecp->rmon_t_col);
2998e585f02STsiChung Liew 	printf("rmon_t_p64         %x - %x\n", (int)&fecp->rmon_t_p64,
3008e585f02STsiChung Liew 	       fecp->rmon_t_p64);
3018e585f02STsiChung Liew 	printf("rmon_t_p65to127    %x - %x\n", (int)&fecp->rmon_t_p65to127,
3028e585f02STsiChung Liew 	       fecp->rmon_t_p65to127);
3038e585f02STsiChung Liew 	printf("rmon_t_p128to255   %x - %x\n", (int)&fecp->rmon_t_p128to255,
3048e585f02STsiChung Liew 	       fecp->rmon_t_p128to255);
3058e585f02STsiChung Liew 	printf("rmon_t_p256to511   %x - %x\n", (int)&fecp->rmon_t_p256to511,
3068e585f02STsiChung Liew 	       fecp->rmon_t_p256to511);
3078e585f02STsiChung Liew 	printf("rmon_t_p512to1023  %x - %x\n", (int)&fecp->rmon_t_p512to1023,
3088e585f02STsiChung Liew 	       fecp->rmon_t_p512to1023);
3098e585f02STsiChung Liew 	printf("rmon_t_p1024to2047 %x - %x\n", (int)&fecp->rmon_t_p1024to2047,
3108e585f02STsiChung Liew 	       fecp->rmon_t_p1024to2047);
3118e585f02STsiChung Liew 	printf("rmon_t_p_gte2048   %x - %x\n", (int)&fecp->rmon_t_p_gte2048,
3128e585f02STsiChung Liew 	       fecp->rmon_t_p_gte2048);
3138e585f02STsiChung Liew 	printf("rmon_t_octets      %x - %x\n", (int)&fecp->rmon_t_octets,
3148e585f02STsiChung Liew 	       fecp->rmon_t_octets);
3158e585f02STsiChung Liew 
3168e585f02STsiChung Liew 	printf("\n");
3178e585f02STsiChung Liew 	printf("ieee_t_drop      %x - %x\n", (int)&fecp->ieee_t_drop,
3188e585f02STsiChung Liew 	       fecp->ieee_t_drop);
3198e585f02STsiChung Liew 	printf("ieee_t_frame_ok  %x - %x\n", (int)&fecp->ieee_t_frame_ok,
3208e585f02STsiChung Liew 	       fecp->ieee_t_frame_ok);
3218e585f02STsiChung Liew 	printf("ieee_t_1col      %x - %x\n", (int)&fecp->ieee_t_1col,
3228e585f02STsiChung Liew 	       fecp->ieee_t_1col);
3238e585f02STsiChung Liew 	printf("ieee_t_mcol      %x - %x\n", (int)&fecp->ieee_t_mcol,
3248e585f02STsiChung Liew 	       fecp->ieee_t_mcol);
3258e585f02STsiChung Liew 	printf("ieee_t_def       %x - %x\n", (int)&fecp->ieee_t_def,
3268e585f02STsiChung Liew 	       fecp->ieee_t_def);
3278e585f02STsiChung Liew 	printf("ieee_t_lcol      %x - %x\n", (int)&fecp->ieee_t_lcol,
3288e585f02STsiChung Liew 	       fecp->ieee_t_lcol);
3298e585f02STsiChung Liew 	printf("ieee_t_excol     %x - %x\n", (int)&fecp->ieee_t_excol,
3308e585f02STsiChung Liew 	       fecp->ieee_t_excol);
3318e585f02STsiChung Liew 	printf("ieee_t_macerr    %x - %x\n", (int)&fecp->ieee_t_macerr,
3328e585f02STsiChung Liew 	       fecp->ieee_t_macerr);
3338e585f02STsiChung Liew 	printf("ieee_t_cserr     %x - %x\n", (int)&fecp->ieee_t_cserr,
3348e585f02STsiChung Liew 	       fecp->ieee_t_cserr);
3358e585f02STsiChung Liew 	printf("ieee_t_sqe       %x - %x\n", (int)&fecp->ieee_t_sqe,
3368e585f02STsiChung Liew 	       fecp->ieee_t_sqe);
3378e585f02STsiChung Liew 	printf("ieee_t_fdxfc     %x - %x\n", (int)&fecp->ieee_t_fdxfc,
3388e585f02STsiChung Liew 	       fecp->ieee_t_fdxfc);
3398e585f02STsiChung Liew 	printf("ieee_t_octets_ok %x - %x\n", (int)&fecp->ieee_t_octets_ok,
3408e585f02STsiChung Liew 	       fecp->ieee_t_octets_ok);
3418e585f02STsiChung Liew 
3428e585f02STsiChung Liew 	printf("\n");
3438e585f02STsiChung Liew 	printf("rmon_r_drop        %x - %x\n", (int)&fecp->rmon_r_drop,
3448e585f02STsiChung Liew 	       fecp->rmon_r_drop);
3458e585f02STsiChung Liew 	printf("rmon_r_packets     %x - %x\n", (int)&fecp->rmon_r_packets,
3468e585f02STsiChung Liew 	       fecp->rmon_r_packets);
3478e585f02STsiChung Liew 	printf("rmon_r_bc_pkt      %x - %x\n", (int)&fecp->rmon_r_bc_pkt,
3488e585f02STsiChung Liew 	       fecp->rmon_r_bc_pkt);
3498e585f02STsiChung Liew 	printf("rmon_r_mc_pkt      %x - %x\n", (int)&fecp->rmon_r_mc_pkt,
3508e585f02STsiChung Liew 	       fecp->rmon_r_mc_pkt);
3518e585f02STsiChung Liew 	printf("rmon_r_crc_align   %x - %x\n", (int)&fecp->rmon_r_crc_align,
3528e585f02STsiChung Liew 	       fecp->rmon_r_crc_align);
3538e585f02STsiChung Liew 	printf("rmon_r_undersize   %x - %x\n", (int)&fecp->rmon_r_undersize,
3548e585f02STsiChung Liew 	       fecp->rmon_r_undersize);
3558e585f02STsiChung Liew 	printf("rmon_r_oversize    %x - %x\n", (int)&fecp->rmon_r_oversize,
3568e585f02STsiChung Liew 	       fecp->rmon_r_oversize);
3578e585f02STsiChung Liew 	printf("rmon_r_frag        %x - %x\n", (int)&fecp->rmon_r_frag,
3588e585f02STsiChung Liew 	       fecp->rmon_r_frag);
3598e585f02STsiChung Liew 	printf("rmon_r_jab         %x - %x\n", (int)&fecp->rmon_r_jab,
3608e585f02STsiChung Liew 	       fecp->rmon_r_jab);
3618e585f02STsiChung Liew 	printf("rmon_r_p64         %x - %x\n", (int)&fecp->rmon_r_p64,
3628e585f02STsiChung Liew 	       fecp->rmon_r_p64);
3638e585f02STsiChung Liew 	printf("rmon_r_p65to127    %x - %x\n", (int)&fecp->rmon_r_p65to127,
3648e585f02STsiChung Liew 	       fecp->rmon_r_p65to127);
3658e585f02STsiChung Liew 	printf("rmon_r_p128to255   %x - %x\n", (int)&fecp->rmon_r_p128to255,
3668e585f02STsiChung Liew 	       fecp->rmon_r_p128to255);
3678e585f02STsiChung Liew 	printf("rmon_r_p256to511   %x - %x\n", (int)&fecp->rmon_r_p256to511,
3688e585f02STsiChung Liew 	       fecp->rmon_r_p256to511);
3698e585f02STsiChung Liew 	printf("rmon_r_p512to1023  %x - %x\n", (int)&fecp->rmon_r_p512to1023,
3708e585f02STsiChung Liew 	       fecp->rmon_r_p512to1023);
3718e585f02STsiChung Liew 	printf("rmon_r_p1024to2047 %x - %x\n", (int)&fecp->rmon_r_p1024to2047,
3728e585f02STsiChung Liew 	       fecp->rmon_r_p1024to2047);
3738e585f02STsiChung Liew 	printf("rmon_r_p_gte2048   %x - %x\n", (int)&fecp->rmon_r_p_gte2048,
3748e585f02STsiChung Liew 	       fecp->rmon_r_p_gte2048);
3758e585f02STsiChung Liew 	printf("rmon_r_octets      %x - %x\n", (int)&fecp->rmon_r_octets,
3768e585f02STsiChung Liew 	       fecp->rmon_r_octets);
3778e585f02STsiChung Liew 
3788e585f02STsiChung Liew 	printf("\n");
3798e585f02STsiChung Liew 	printf("ieee_r_drop      %x - %x\n", (int)&fecp->ieee_r_drop,
3808e585f02STsiChung Liew 	       fecp->ieee_r_drop);
3818e585f02STsiChung Liew 	printf("ieee_r_frame_ok  %x - %x\n", (int)&fecp->ieee_r_frame_ok,
3828e585f02STsiChung Liew 	       fecp->ieee_r_frame_ok);
3838e585f02STsiChung Liew 	printf("ieee_r_crc       %x - %x\n", (int)&fecp->ieee_r_crc,
3848e585f02STsiChung Liew 	       fecp->ieee_r_crc);
3858e585f02STsiChung Liew 	printf("ieee_r_align     %x - %x\n", (int)&fecp->ieee_r_align,
3868e585f02STsiChung Liew 	       fecp->ieee_r_align);
3878e585f02STsiChung Liew 	printf("ieee_r_macerr    %x - %x\n", (int)&fecp->ieee_r_macerr,
3888e585f02STsiChung Liew 	       fecp->ieee_r_macerr);
3898e585f02STsiChung Liew 	printf("ieee_r_fdxfc     %x - %x\n", (int)&fecp->ieee_r_fdxfc,
3908e585f02STsiChung Liew 	       fecp->ieee_r_fdxfc);
3918e585f02STsiChung Liew 	printf("ieee_r_octets_ok %x - %x\n", (int)&fecp->ieee_r_octets_ok,
3928e585f02STsiChung Liew 	       fecp->ieee_r_octets_ok);
3938e585f02STsiChung Liew 
3948e585f02STsiChung Liew 	printf("\n\n\n");
3958e585f02STsiChung Liew }
3968e585f02STsiChung Liew #endif
3978e585f02STsiChung Liew 
fec_init(struct eth_device * dev,bd_t * bd)3988e585f02STsiChung Liew int fec_init(struct eth_device *dev, bd_t * bd)
3998e585f02STsiChung Liew {
4008e585f02STsiChung Liew 	struct fec_info_s *info = dev->priv;
4018e585f02STsiChung Liew 	volatile fec_t *fecp = (fec_t *) (info->iobase);
4028e585f02STsiChung Liew 	int i;
403d3f87148SMike Frysinger 	uchar ea[6];
4048e585f02STsiChung Liew 
4058e585f02STsiChung Liew 	fecpin_setclear(dev, 1);
4068e585f02STsiChung Liew 
4078e585f02STsiChung Liew 	fec_reset(dev);
4088e585f02STsiChung Liew 
409ab77bc54STsiChungLiew #if defined(CONFIG_CMD_MII) || defined (CONFIG_MII) || \
4106d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	defined (CONFIG_SYS_DISCOVER_PHY)
4118e585f02STsiChung Liew 
4128e585f02STsiChung Liew 	mii_init();
4138e585f02STsiChung Liew 
4148e585f02STsiChung Liew 	setFecDuplexSpeed(fecp, bd, info->dup_spd);
4158e585f02STsiChung Liew #else
4166d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifndef CONFIG_SYS_DISCOVER_PHY
4178e585f02STsiChung Liew 	setFecDuplexSpeed(fecp, bd, (FECDUPLEX << 16) | FECSPEED);
4186d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #endif				/* ifndef CONFIG_SYS_DISCOVER_PHY */
419ab77bc54STsiChungLiew #endif				/* CONFIG_CMD_MII || CONFIG_MII */
4208e585f02STsiChung Liew 
4218e585f02STsiChung Liew 	/* We use strictly polling mode only */
4228e585f02STsiChung Liew 	fecp->eimr = 0;
4238e585f02STsiChung Liew 
4248e585f02STsiChung Liew 	/* Clear any pending interrupt */
4258e585f02STsiChung Liew 	fecp->eir = 0xffffffff;
4268e585f02STsiChung Liew 
4278e585f02STsiChung Liew 	/* Set station address   */
4286d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	if ((u32) fecp == CONFIG_SYS_FEC0_IOBASE) {
4296d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_SYS_FEC1_IOBASE
4306d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		volatile fec_t *fecp1 = (fec_t *) (CONFIG_SYS_FEC1_IOBASE);
43135affd7aSSimon Glass 		eth_env_get_enetaddr("eth1addr", ea);
4328ae158cdSTsiChungLiew 		fecp1->palr =
4338ae158cdSTsiChungLiew 		    (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]);
4348ae158cdSTsiChungLiew 		fecp1->paur = (ea[4] << 24) | (ea[5] << 16);
4358ae158cdSTsiChungLiew #endif
43635affd7aSSimon Glass 		eth_env_get_enetaddr("ethaddr", ea);
4378ae158cdSTsiChungLiew 		fecp->palr =
4388ae158cdSTsiChungLiew 		    (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]);
4398ae158cdSTsiChungLiew 		fecp->paur = (ea[4] << 24) | (ea[5] << 16);
4408e585f02STsiChung Liew 	} else {
4416d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_SYS_FEC0_IOBASE
4426d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		volatile fec_t *fecp0 = (fec_t *) (CONFIG_SYS_FEC0_IOBASE);
44335affd7aSSimon Glass 		eth_env_get_enetaddr("ethaddr", ea);
4448ae158cdSTsiChungLiew 		fecp0->palr =
4458ae158cdSTsiChungLiew 		    (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]);
4468ae158cdSTsiChungLiew 		fecp0->paur = (ea[4] << 24) | (ea[5] << 16);
4478ae158cdSTsiChungLiew #endif
4486d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_SYS_FEC1_IOBASE
44935affd7aSSimon Glass 		eth_env_get_enetaddr("eth1addr", ea);
4508ae158cdSTsiChungLiew 		fecp->palr =
4518ae158cdSTsiChungLiew 		    (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]);
4528ae158cdSTsiChungLiew 		fecp->paur = (ea[4] << 24) | (ea[5] << 16);
4538e585f02STsiChung Liew #endif
4548e585f02STsiChung Liew 	}
4558e585f02STsiChung Liew 
4568e585f02STsiChung Liew 	/* Clear unicast address hash table */
4578e585f02STsiChung Liew 	fecp->iaur = 0;
4588e585f02STsiChung Liew 	fecp->ialr = 0;
4598e585f02STsiChung Liew 
4608e585f02STsiChung Liew 	/* Clear multicast address hash table */
4618e585f02STsiChung Liew 	fecp->gaur = 0;
4628e585f02STsiChung Liew 	fecp->galr = 0;
4638e585f02STsiChung Liew 
4648e585f02STsiChung Liew 	/* Set maximum receive buffer size. */
4658e585f02STsiChung Liew 	fecp->emrbr = PKT_MAXBLR_SIZE;
4668e585f02STsiChung Liew 
4678e585f02STsiChung Liew 	/*
468*e4691564SHeinrich Schuchardt 	 * Setup Buffers and Buffer Descriptors
4698e585f02STsiChung Liew 	 */
4708e585f02STsiChung Liew 	info->rxIdx = 0;
4718e585f02STsiChung Liew 	info->txIdx = 0;
4728e585f02STsiChung Liew 
4738e585f02STsiChung Liew 	/*
4748e585f02STsiChung Liew 	 * Setup Receiver Buffer Descriptors (13.14.24.18)
4758e585f02STsiChung Liew 	 * Settings:
4768e585f02STsiChung Liew 	 *     Empty, Wrap
4778e585f02STsiChung Liew 	 */
4788e585f02STsiChung Liew 	for (i = 0; i < PKTBUFSRX; i++) {
4798e585f02STsiChung Liew 		info->rxbd[i].cbd_sc = BD_ENET_RX_EMPTY;
4808e585f02STsiChung Liew 		info->rxbd[i].cbd_datlen = 0;	/* Reset */
4811fd92db8SJoe Hershberger 		info->rxbd[i].cbd_bufaddr = (uint) net_rx_packets[i];
4828e585f02STsiChung Liew 	}
4838e585f02STsiChung Liew 	info->rxbd[PKTBUFSRX - 1].cbd_sc |= BD_ENET_RX_WRAP;
4848e585f02STsiChung Liew 
4858e585f02STsiChung Liew 	/*
4868e585f02STsiChung Liew 	 * Setup Ethernet Transmitter Buffer Descriptors (13.14.24.19)
4878e585f02STsiChung Liew 	 * Settings:
4888e585f02STsiChung Liew 	 *    Last, Tx CRC
4898e585f02STsiChung Liew 	 */
4908e585f02STsiChung Liew 	for (i = 0; i < TX_BUF_CNT; i++) {
4918e585f02STsiChung Liew 		info->txbd[i].cbd_sc = BD_ENET_TX_LAST | BD_ENET_TX_TC;
4928e585f02STsiChung Liew 		info->txbd[i].cbd_datlen = 0;	/* Reset */
4938e585f02STsiChung Liew 		info->txbd[i].cbd_bufaddr = (uint) (&info->txbuf[0]);
4948e585f02STsiChung Liew 	}
4958e585f02STsiChung Liew 	info->txbd[TX_BUF_CNT - 1].cbd_sc |= BD_ENET_TX_WRAP;
4968e585f02STsiChung Liew 
4978e585f02STsiChung Liew 	/* Set receive and transmit descriptor base */
4988e585f02STsiChung Liew 	fecp->erdsr = (unsigned int)(&info->rxbd[0]);
4998e585f02STsiChung Liew 	fecp->etdsr = (unsigned int)(&info->txbd[0]);
5008e585f02STsiChung Liew 
5018e585f02STsiChung Liew 	/* Now enable the transmit and receive processing */
5028e585f02STsiChung Liew 	fecp->ecr |= FEC_ECR_ETHER_EN;
5038e585f02STsiChung Liew 
5048e585f02STsiChung Liew 	/* And last, try to fill Rx Buffer Descriptors */
5058e585f02STsiChung Liew 	fecp->rdar = 0x01000000;	/* Descriptor polling active    */
5068e585f02STsiChung Liew 
5078e585f02STsiChung Liew 	return 1;
5088e585f02STsiChung Liew }
5098e585f02STsiChung Liew 
fec_reset(struct eth_device * dev)5108e585f02STsiChung Liew void fec_reset(struct eth_device *dev)
5118e585f02STsiChung Liew {
5128e585f02STsiChung Liew 	struct fec_info_s *info = dev->priv;
5138e585f02STsiChung Liew 	volatile fec_t *fecp = (fec_t *) (info->iobase);
5148e585f02STsiChung Liew 	int i;
5158e585f02STsiChung Liew 
5168e585f02STsiChung Liew 	fecp->ecr = FEC_ECR_RESET;
5178e585f02STsiChung Liew 	for (i = 0; (fecp->ecr & FEC_ECR_RESET) && (i < FEC_RESET_DELAY); ++i) {
5188e585f02STsiChung Liew 		udelay(1);
5198e585f02STsiChung Liew 	}
5208e585f02STsiChung Liew 	if (i == FEC_RESET_DELAY) {
5218e585f02STsiChung Liew 		printf("FEC_RESET_DELAY timeout\n");
5228e585f02STsiChung Liew 	}
5238e585f02STsiChung Liew }
5248e585f02STsiChung Liew 
fec_halt(struct eth_device * dev)5258e585f02STsiChung Liew void fec_halt(struct eth_device *dev)
5268e585f02STsiChung Liew {
5278e585f02STsiChung Liew 	struct fec_info_s *info = dev->priv;
5288e585f02STsiChung Liew 
5298e585f02STsiChung Liew 	fec_reset(dev);
5308e585f02STsiChung Liew 
5318e585f02STsiChung Liew 	fecpin_setclear(dev, 0);
5328e585f02STsiChung Liew 
5338e585f02STsiChung Liew 	info->rxIdx = info->txIdx = 0;
5348e585f02STsiChung Liew 	memset(info->rxbd, 0, PKTBUFSRX * sizeof(cbd_t));
5358e585f02STsiChung Liew 	memset(info->txbd, 0, TX_BUF_CNT * sizeof(cbd_t));
5368e585f02STsiChung Liew 	memset(info->txbuf, 0, DBUF_LENGTH);
5378e585f02STsiChung Liew }
5388e585f02STsiChung Liew 
mcffec_initialize(bd_t * bis)5398e585f02STsiChung Liew int mcffec_initialize(bd_t * bis)
5408e585f02STsiChung Liew {
5418e585f02STsiChung Liew 	struct eth_device *dev;
5428e585f02STsiChung Liew 	int i;
5436d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_SYS_FEC_BUF_USE_SRAM
5446d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	u32 tmp = CONFIG_SYS_INIT_RAM_ADDR + 0x1000;
5451803f7f9STsiChung Liew #endif
5468e585f02STsiChung Liew 
547a62cd29cSAxel Lin 	for (i = 0; i < ARRAY_SIZE(fec_info); i++) {
5488e585f02STsiChung Liew 
549f2208fbcSTsiChungLiew 		dev =
5506d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		    (struct eth_device *)memalign(CONFIG_SYS_CACHELINE_SIZE,
551f2208fbcSTsiChungLiew 						  sizeof *dev);
5528e585f02STsiChung Liew 		if (dev == NULL)
5538e585f02STsiChung Liew 			hang();
5548e585f02STsiChung Liew 
5558e585f02STsiChung Liew 		memset(dev, 0, sizeof(*dev));
5568e585f02STsiChung Liew 
5578e585f02STsiChung Liew 		sprintf(dev->name, "FEC%d", fec_info[i].index);
5588e585f02STsiChung Liew 
5598e585f02STsiChung Liew 		dev->priv = &fec_info[i];
5608e585f02STsiChung Liew 		dev->init = fec_init;
5618e585f02STsiChung Liew 		dev->halt = fec_halt;
5628e585f02STsiChung Liew 		dev->send = fec_send;
5638e585f02STsiChung Liew 		dev->recv = fec_recv;
5648e585f02STsiChung Liew 
5658e585f02STsiChung Liew 		/* setup Receive and Transmit buffer descriptor */
5666d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_SYS_FEC_BUF_USE_SRAM
5671803f7f9STsiChung Liew 		fec_info[i].rxbd = (cbd_t *)((u32)fec_info[i].rxbd + tmp);
5681803f7f9STsiChung Liew 		tmp = (u32)fec_info[i].rxbd;
5691803f7f9STsiChung Liew 		fec_info[i].txbd =
5701803f7f9STsiChung Liew 		    (cbd_t *)((u32)fec_info[i].txbd + tmp +
5711803f7f9STsiChung Liew 		    (PKTBUFSRX * sizeof(cbd_t)));
5721803f7f9STsiChung Liew 		tmp = (u32)fec_info[i].txbd;
5731803f7f9STsiChung Liew 		fec_info[i].txbuf =
5741803f7f9STsiChung Liew 		    (char *)((u32)fec_info[i].txbuf + tmp +
5756d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		    (CONFIG_SYS_TX_ETH_BUFFER * sizeof(cbd_t)));
5761803f7f9STsiChung Liew 		tmp = (u32)fec_info[i].txbuf;
5771803f7f9STsiChung Liew #else
5788e585f02STsiChung Liew 		fec_info[i].rxbd =
5796d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		    (cbd_t *) memalign(CONFIG_SYS_CACHELINE_SIZE,
580f2208fbcSTsiChungLiew 				       (PKTBUFSRX * sizeof(cbd_t)));
5818e585f02STsiChung Liew 		fec_info[i].txbd =
5826d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		    (cbd_t *) memalign(CONFIG_SYS_CACHELINE_SIZE,
583f2208fbcSTsiChungLiew 				       (TX_BUF_CNT * sizeof(cbd_t)));
584f2208fbcSTsiChungLiew 		fec_info[i].txbuf =
5856d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		    (char *)memalign(CONFIG_SYS_CACHELINE_SIZE, DBUF_LENGTH);
5861803f7f9STsiChung Liew #endif
5871803f7f9STsiChung Liew 
5888e585f02STsiChung Liew #ifdef ET_DEBUG
5898e585f02STsiChung Liew 		printf("rxbd %x txbd %x\n",
5908e585f02STsiChung Liew 		       (int)fec_info[i].rxbd, (int)fec_info[i].txbd);
5918e585f02STsiChung Liew #endif
5928e585f02STsiChung Liew 
5936d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		fec_info[i].phy_name = (char *)memalign(CONFIG_SYS_CACHELINE_SIZE, 32);
5948e585f02STsiChung Liew 
5958e585f02STsiChung Liew 		eth_register(dev);
5968e585f02STsiChung Liew 
597ab77bc54STsiChungLiew #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
5985a49f174SJoe Hershberger 		int retval;
5995a49f174SJoe Hershberger 		struct mii_dev *mdiodev = mdio_alloc();
6005a49f174SJoe Hershberger 		if (!mdiodev)
6015a49f174SJoe Hershberger 			return -ENOMEM;
6025a49f174SJoe Hershberger 		strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
6035a49f174SJoe Hershberger 		mdiodev->read = mcffec_miiphy_read;
6045a49f174SJoe Hershberger 		mdiodev->write = mcffec_miiphy_write;
6055a49f174SJoe Hershberger 
6065a49f174SJoe Hershberger 		retval = mdio_register(mdiodev);
6075a49f174SJoe Hershberger 		if (retval < 0)
6085a49f174SJoe Hershberger 			return retval;
6098e585f02STsiChung Liew #endif
6101803f7f9STsiChung Liew 		if (i > 0)
6111803f7f9STsiChung Liew 			fec_info[i - 1].next = &fec_info[i];
6128e585f02STsiChung Liew 	}
6131803f7f9STsiChung Liew 	fec_info[i - 1].next = &fec_info[0];
6148e585f02STsiChung Liew 
6158e585f02STsiChung Liew 	/* default speed */
6168e585f02STsiChung Liew 	bis->bi_ethspeed = 10;
6178e585f02STsiChung Liew 
61886882b80SBen Warren 	return 0;
6198e585f02STsiChung Liew }
620