xref: /rk3399_rockchip-uboot/arch/powerpc/cpu/mpc85xx/ether_fcc.c (revision 48690d8024eeeaee3120db702e54fcb238e6d9c7)
1a47a12beSStefan Roese /*
2a47a12beSStefan Roese  * MPC8560 FCC Fast Ethernet
3a47a12beSStefan Roese  * Copyright (c) 2003 Motorola,Inc.
4a47a12beSStefan Roese  * Xianghua Xiao, (X.Xiao@motorola.com)
5a47a12beSStefan Roese  *
6a47a12beSStefan Roese  * Copyright (c) 2000 MontaVista Software, Inc.   Dan Malek (dmalek@jlc.net)
7a47a12beSStefan Roese  *
8a47a12beSStefan Roese  * (C) Copyright 2000 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
9a47a12beSStefan Roese  * Marius Groeger <mgroeger@sysgo.de>
10a47a12beSStefan Roese  *
11a47a12beSStefan Roese  * See file CREDITS for list of people who contributed to this
12a47a12beSStefan Roese  * project.
13a47a12beSStefan Roese  *
14a47a12beSStefan Roese  * This program is free software; you can redistribute it and/or
15a47a12beSStefan Roese  * modify it under the terms of the GNU General Public License as
16a47a12beSStefan Roese  * published by the Free Software Foundation; either version 2 of
17a47a12beSStefan Roese  * the License, or (at your option) any later version.
18a47a12beSStefan Roese  *
19a47a12beSStefan Roese  * This program is distributed in the hope that it will be useful,
20a47a12beSStefan Roese  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21a47a12beSStefan Roese  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22a47a12beSStefan Roese  * GNU General Public License for more details.
23a47a12beSStefan Roese  *
24a47a12beSStefan Roese  * You should have received a copy of the GNU General Public License
25a47a12beSStefan Roese  * along with this program; if not, write to the Free Software
26a47a12beSStefan Roese  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27a47a12beSStefan Roese  * MA 02111-1307 USA
28a47a12beSStefan Roese  */
29a47a12beSStefan Roese 
30a47a12beSStefan Roese /*
31a47a12beSStefan Roese  * MPC8560 FCC Fast Ethernet
32a47a12beSStefan Roese  * Basic ET HW initialization and packet RX/TX routines
33a47a12beSStefan Roese  *
34a47a12beSStefan Roese  * This code will not perform the IO port configuration. This should be
35a47a12beSStefan Roese  * done in the iop_conf_t structure specific for the board.
36a47a12beSStefan Roese  *
37a47a12beSStefan Roese  * TODO:
38a47a12beSStefan Roese  * add a PHY driver to do the negotiation
39a47a12beSStefan Roese  * reflect negotiation results in FPSMR
40a47a12beSStefan Roese  * look for ways to configure the board specific stuff elsewhere, eg.
41a47a12beSStefan Roese  *    config_xxx.h or the board directory
42a47a12beSStefan Roese  */
43a47a12beSStefan Roese 
44a47a12beSStefan Roese #include <common.h>
45a47a12beSStefan Roese #include <malloc.h>
46a47a12beSStefan Roese #include <asm/cpm_85xx.h>
47a47a12beSStefan Roese #include <command.h>
48a47a12beSStefan Roese #include <config.h>
49a47a12beSStefan Roese #include <net.h>
50a47a12beSStefan Roese 
51a47a12beSStefan Roese #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
52a47a12beSStefan Roese #include <miiphy.h>
53a47a12beSStefan Roese #endif
54a47a12beSStefan Roese 
55a47a12beSStefan Roese #if defined(CONFIG_ETHER_ON_FCC) && defined(CONFIG_CMD_NET) && \
56a47a12beSStefan Roese 	defined(CONFIG_NET_MULTI)
57a47a12beSStefan Roese 
58a47a12beSStefan Roese static struct ether_fcc_info_s
59a47a12beSStefan Roese {
60a47a12beSStefan Roese 	int ether_index;
61a47a12beSStefan Roese 	int proff_enet;
62a47a12beSStefan Roese 	ulong cpm_cr_enet_sblock;
63a47a12beSStefan Roese 	ulong cpm_cr_enet_page;
64a47a12beSStefan Roese 	ulong cmxfcr_mask;
65a47a12beSStefan Roese 	ulong cmxfcr_value;
66a47a12beSStefan Roese }
67a47a12beSStefan Roese 	ether_fcc_info[] =
68a47a12beSStefan Roese {
69a47a12beSStefan Roese #ifdef CONFIG_ETHER_ON_FCC1
70a47a12beSStefan Roese {
71a47a12beSStefan Roese 	0,
72a47a12beSStefan Roese 	PROFF_FCC1,
73a47a12beSStefan Roese 	CPM_CR_FCC1_SBLOCK,
74a47a12beSStefan Roese 	CPM_CR_FCC1_PAGE,
75a47a12beSStefan Roese 	CONFIG_SYS_CMXFCR_MASK1,
76a47a12beSStefan Roese 	CONFIG_SYS_CMXFCR_VALUE1
77a47a12beSStefan Roese },
78a47a12beSStefan Roese #endif
79a47a12beSStefan Roese 
80a47a12beSStefan Roese #ifdef CONFIG_ETHER_ON_FCC2
81a47a12beSStefan Roese {
82a47a12beSStefan Roese 	1,
83a47a12beSStefan Roese 	PROFF_FCC2,
84a47a12beSStefan Roese 	CPM_CR_FCC2_SBLOCK,
85a47a12beSStefan Roese 	CPM_CR_FCC2_PAGE,
86a47a12beSStefan Roese 	CONFIG_SYS_CMXFCR_MASK2,
87a47a12beSStefan Roese 	CONFIG_SYS_CMXFCR_VALUE2
88a47a12beSStefan Roese },
89a47a12beSStefan Roese #endif
90a47a12beSStefan Roese 
91a47a12beSStefan Roese #ifdef CONFIG_ETHER_ON_FCC3
92a47a12beSStefan Roese {
93a47a12beSStefan Roese 	2,
94a47a12beSStefan Roese 	PROFF_FCC3,
95a47a12beSStefan Roese 	CPM_CR_FCC3_SBLOCK,
96a47a12beSStefan Roese 	CPM_CR_FCC3_PAGE,
97a47a12beSStefan Roese 	CONFIG_SYS_CMXFCR_MASK3,
98a47a12beSStefan Roese 	CONFIG_SYS_CMXFCR_VALUE3
99a47a12beSStefan Roese },
100a47a12beSStefan Roese #endif
101a47a12beSStefan Roese };
102a47a12beSStefan Roese 
103a47a12beSStefan Roese /*---------------------------------------------------------------------*/
104a47a12beSStefan Roese 
105a47a12beSStefan Roese /* Maximum input DMA size.  Must be a should(?) be a multiple of 4. */
106a47a12beSStefan Roese #define PKT_MAXDMA_SIZE         1520
107a47a12beSStefan Roese 
108a47a12beSStefan Roese /* The FCC stores dest/src/type, data, and checksum for receive packets. */
109a47a12beSStefan Roese #define PKT_MAXBUF_SIZE         1518
110a47a12beSStefan Roese #define PKT_MINBUF_SIZE         64
111a47a12beSStefan Roese 
112a47a12beSStefan Roese /* Maximum input buffer size.  Must be a multiple of 32. */
113a47a12beSStefan Roese #define PKT_MAXBLR_SIZE         1536
114a47a12beSStefan Roese 
115a47a12beSStefan Roese #define TOUT_LOOP 1000000
116a47a12beSStefan Roese 
117a47a12beSStefan Roese #define TX_BUF_CNT 2
118a47a12beSStefan Roese 
119a47a12beSStefan Roese static uint rxIdx;	/* index of the current RX buffer */
120a47a12beSStefan Roese static uint txIdx;	/* index of the current TX buffer */
121a47a12beSStefan Roese 
122a47a12beSStefan Roese /*
123a47a12beSStefan Roese  * FCC Ethernet Tx and Rx buffer descriptors.
124a47a12beSStefan Roese  * Provide for Double Buffering
125a47a12beSStefan Roese  * Note: PKTBUFSRX is defined in net.h
126a47a12beSStefan Roese  */
127a47a12beSStefan Roese 
128a47a12beSStefan Roese typedef volatile struct rtxbd {
129a47a12beSStefan Roese     cbd_t rxbd[PKTBUFSRX];
130a47a12beSStefan Roese     cbd_t txbd[TX_BUF_CNT];
131a47a12beSStefan Roese } RTXBD;
132a47a12beSStefan Roese 
133a47a12beSStefan Roese /*  Good news: the FCC supports external BDs! */
134a47a12beSStefan Roese #ifdef __GNUC__
135a47a12beSStefan Roese static RTXBD rtx __attribute__ ((aligned(8)));
136a47a12beSStefan Roese #else
137a47a12beSStefan Roese #error "rtx must be 64-bit aligned"
138a47a12beSStefan Roese #endif
139a47a12beSStefan Roese 
140a47a12beSStefan Roese #undef ET_DEBUG
141a47a12beSStefan Roese 
142a47a12beSStefan Roese static int fec_send(struct eth_device* dev, volatile void *packet, int length)
143a47a12beSStefan Roese {
144a47a12beSStefan Roese     int i = 0;
145a47a12beSStefan Roese     int result = 0;
146a47a12beSStefan Roese 
147a47a12beSStefan Roese     if (length <= 0) {
148a47a12beSStefan Roese 	printf("fec: bad packet size: %d\n", length);
149a47a12beSStefan Roese 	goto out;
150a47a12beSStefan Roese     }
151a47a12beSStefan Roese 
152a47a12beSStefan Roese     for(i=0; rtx.txbd[txIdx].cbd_sc & BD_ENET_TX_READY; i++) {
153a47a12beSStefan Roese 	if (i >= TOUT_LOOP) {
154a47a12beSStefan Roese 	    printf("fec: tx buffer not ready\n");
155a47a12beSStefan Roese 	    goto out;
156a47a12beSStefan Roese 	}
157a47a12beSStefan Roese     }
158a47a12beSStefan Roese 
159a47a12beSStefan Roese     rtx.txbd[txIdx].cbd_bufaddr = (uint)packet;
160a47a12beSStefan Roese     rtx.txbd[txIdx].cbd_datlen = length;
161a47a12beSStefan Roese     rtx.txbd[txIdx].cbd_sc |= (BD_ENET_TX_READY | BD_ENET_TX_LAST | \
162a47a12beSStefan Roese 			       BD_ENET_TX_TC | BD_ENET_TX_PAD);
163a47a12beSStefan Roese 
164a47a12beSStefan Roese     for(i=0; rtx.txbd[txIdx].cbd_sc & BD_ENET_TX_READY; i++) {
165a47a12beSStefan Roese 	if (i >= TOUT_LOOP) {
166a47a12beSStefan Roese 	    printf("fec: tx error\n");
167a47a12beSStefan Roese 	    goto out;
168a47a12beSStefan Roese 	}
169a47a12beSStefan Roese     }
170a47a12beSStefan Roese 
171a47a12beSStefan Roese #ifdef ET_DEBUG
172a47a12beSStefan Roese     printf("cycles: 0x%x txIdx=0x%04x status: 0x%04x\n", i, txIdx,rtx.txbd[txIdx].cbd_sc);
173a47a12beSStefan Roese     printf("packets at 0x%08x, length_in_bytes=0x%x\n",(uint)packet,length);
174a47a12beSStefan Roese     for(i=0;i<(length/16 + 1);i++) {
175a47a12beSStefan Roese 	 printf("%08x %08x %08x %08x\n",*((uint *)rtx.txbd[txIdx].cbd_bufaddr+i*4),\
176a47a12beSStefan Roese     *((uint *)rtx.txbd[txIdx].cbd_bufaddr + i*4 + 1),*((uint *)rtx.txbd[txIdx].cbd_bufaddr + i*4 + 2), \
177a47a12beSStefan Roese     *((uint *)rtx.txbd[txIdx].cbd_bufaddr + i*4 + 3));
178a47a12beSStefan Roese     }
179a47a12beSStefan Roese #endif
180a47a12beSStefan Roese 
181a47a12beSStefan Roese     /* return only status bits */
182a47a12beSStefan Roese     result = rtx.txbd[txIdx].cbd_sc & BD_ENET_TX_STATS;
183a47a12beSStefan Roese     txIdx = (txIdx + 1) % TX_BUF_CNT;
184a47a12beSStefan Roese 
185a47a12beSStefan Roese out:
186a47a12beSStefan Roese     return result;
187a47a12beSStefan Roese }
188a47a12beSStefan Roese 
189a47a12beSStefan Roese static int fec_recv(struct eth_device* dev)
190a47a12beSStefan Roese {
191a47a12beSStefan Roese     int length;
192a47a12beSStefan Roese 
193a47a12beSStefan Roese     for (;;)
194a47a12beSStefan Roese     {
195a47a12beSStefan Roese 	if (rtx.rxbd[rxIdx].cbd_sc & BD_ENET_RX_EMPTY) {
196a47a12beSStefan Roese 	    length = -1;
197a47a12beSStefan Roese 	    break;     /* nothing received - leave for() loop */
198a47a12beSStefan Roese 	}
199a47a12beSStefan Roese 	length = rtx.rxbd[rxIdx].cbd_datlen;
200a47a12beSStefan Roese 
201a47a12beSStefan Roese 	if (rtx.rxbd[rxIdx].cbd_sc & 0x003f) {
202a47a12beSStefan Roese 	    printf("fec: rx error %04x\n", rtx.rxbd[rxIdx].cbd_sc);
203a47a12beSStefan Roese 	}
204a47a12beSStefan Roese 	else {
205a47a12beSStefan Roese 	    /* Pass the packet up to the protocol layers. */
206a47a12beSStefan Roese 	    NetReceive(NetRxPackets[rxIdx], length - 4);
207a47a12beSStefan Roese 	}
208a47a12beSStefan Roese 
209a47a12beSStefan Roese 
210a47a12beSStefan Roese 	/* Give the buffer back to the FCC. */
211a47a12beSStefan Roese 	rtx.rxbd[rxIdx].cbd_datlen = 0;
212a47a12beSStefan Roese 
213a47a12beSStefan Roese 	/* wrap around buffer index when necessary */
214a47a12beSStefan Roese 	if ((rxIdx + 1) >= PKTBUFSRX) {
215a47a12beSStefan Roese 	    rtx.rxbd[PKTBUFSRX - 1].cbd_sc = (BD_ENET_RX_WRAP | BD_ENET_RX_EMPTY);
216a47a12beSStefan Roese 	    rxIdx = 0;
217a47a12beSStefan Roese 	}
218a47a12beSStefan Roese 	else {
219a47a12beSStefan Roese 	    rtx.rxbd[rxIdx].cbd_sc = BD_ENET_RX_EMPTY;
220a47a12beSStefan Roese 	    rxIdx++;
221a47a12beSStefan Roese 	}
222a47a12beSStefan Roese     }
223a47a12beSStefan Roese     return length;
224a47a12beSStefan Roese }
225a47a12beSStefan Roese 
226a47a12beSStefan Roese 
227a47a12beSStefan Roese static int fec_init(struct eth_device* dev, bd_t *bis)
228a47a12beSStefan Roese {
229a47a12beSStefan Roese     struct ether_fcc_info_s * info = dev->priv;
230a47a12beSStefan Roese     int i;
231a47a12beSStefan Roese     volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
232a47a12beSStefan Roese     volatile ccsr_cpm_cp_t *cp = &(cpm->im_cpm_cp);
233a47a12beSStefan Roese     fcc_enet_t *pram_ptr;
234a47a12beSStefan Roese     unsigned long mem_addr;
235a47a12beSStefan Roese 
236a47a12beSStefan Roese #if 0
237a47a12beSStefan Roese     mii_discover_phy();
238a47a12beSStefan Roese #endif
239a47a12beSStefan Roese 
240a47a12beSStefan Roese     /* 28.9 - (1-2): ioports have been set up already */
241a47a12beSStefan Roese 
242a47a12beSStefan Roese     /* 28.9 - (3): connect FCC's tx and rx clocks */
243a47a12beSStefan Roese     cpm->im_cpm_mux.cmxuar = 0; /* ATM */
244a47a12beSStefan Roese     cpm->im_cpm_mux.cmxfcr = (cpm->im_cpm_mux.cmxfcr & ~info->cmxfcr_mask) |
245a47a12beSStefan Roese 							info->cmxfcr_value;
246a47a12beSStefan Roese 
247a47a12beSStefan Roese     /* 28.9 - (4): GFMR: disable tx/rx, CCITT CRC, set Mode Ethernet */
248a47a12beSStefan Roese     if(info->ether_index == 0) {
249a47a12beSStefan Roese 	cpm->im_cpm_fcc1.gfmr = FCC_GFMR_MODE_ENET | FCC_GFMR_TCRC_32;
250a47a12beSStefan Roese     } else if (info->ether_index == 1) {
251a47a12beSStefan Roese 	cpm->im_cpm_fcc2.gfmr = FCC_GFMR_MODE_ENET | FCC_GFMR_TCRC_32;
252a47a12beSStefan Roese     } else if (info->ether_index == 2) {
253a47a12beSStefan Roese 	cpm->im_cpm_fcc3.gfmr = FCC_GFMR_MODE_ENET | FCC_GFMR_TCRC_32;
254a47a12beSStefan Roese     }
255a47a12beSStefan Roese 
256a47a12beSStefan Roese     /* 28.9 - (5): FPSMR: enable full duplex, select CCITT CRC for Ethernet,MII */
257a47a12beSStefan Roese     if(info->ether_index == 0) {
258a47a12beSStefan Roese 	cpm->im_cpm_fcc1.fpsmr = CONFIG_SYS_FCC_PSMR | FCC_PSMR_ENCRC;
259a47a12beSStefan Roese     } else if (info->ether_index == 1){
260a47a12beSStefan Roese 	cpm->im_cpm_fcc2.fpsmr = CONFIG_SYS_FCC_PSMR | FCC_PSMR_ENCRC;
261a47a12beSStefan Roese     } else if (info->ether_index == 2){
262a47a12beSStefan Roese 	cpm->im_cpm_fcc3.fpsmr = CONFIG_SYS_FCC_PSMR | FCC_PSMR_ENCRC;
263a47a12beSStefan Roese     }
264a47a12beSStefan Roese 
265a47a12beSStefan Roese     /* 28.9 - (6): FDSR: Ethernet Syn */
266a47a12beSStefan Roese     if(info->ether_index == 0) {
267a47a12beSStefan Roese 	cpm->im_cpm_fcc1.fdsr = 0xD555;
268a47a12beSStefan Roese     } else if (info->ether_index == 1) {
269a47a12beSStefan Roese 	cpm->im_cpm_fcc2.fdsr = 0xD555;
270a47a12beSStefan Roese     } else if (info->ether_index == 2) {
271a47a12beSStefan Roese 	cpm->im_cpm_fcc3.fdsr = 0xD555;
272a47a12beSStefan Roese     }
273a47a12beSStefan Roese 
274a47a12beSStefan Roese     /* reset indeces to current rx/tx bd (see eth_send()/eth_rx()) */
275a47a12beSStefan Roese     rxIdx = 0;
276a47a12beSStefan Roese     txIdx = 0;
277a47a12beSStefan Roese 
278a47a12beSStefan Roese     /* Setup Receiver Buffer Descriptors */
279a47a12beSStefan Roese     for (i = 0; i < PKTBUFSRX; i++)
280a47a12beSStefan Roese     {
281a47a12beSStefan Roese       rtx.rxbd[i].cbd_sc = BD_ENET_RX_EMPTY;
282a47a12beSStefan Roese       rtx.rxbd[i].cbd_datlen = 0;
283a47a12beSStefan Roese       rtx.rxbd[i].cbd_bufaddr = (uint)NetRxPackets[i];
284a47a12beSStefan Roese     }
285a47a12beSStefan Roese     rtx.rxbd[PKTBUFSRX - 1].cbd_sc |= BD_ENET_RX_WRAP;
286a47a12beSStefan Roese 
287a47a12beSStefan Roese     /* Setup Ethernet Transmitter Buffer Descriptors */
288a47a12beSStefan Roese     for (i = 0; i < TX_BUF_CNT; i++)
289a47a12beSStefan Roese     {
290a47a12beSStefan Roese       rtx.txbd[i].cbd_sc = 0;
291a47a12beSStefan Roese       rtx.txbd[i].cbd_datlen = 0;
292a47a12beSStefan Roese       rtx.txbd[i].cbd_bufaddr = 0;
293a47a12beSStefan Roese     }
294a47a12beSStefan Roese     rtx.txbd[TX_BUF_CNT - 1].cbd_sc |= BD_ENET_TX_WRAP;
295a47a12beSStefan Roese 
296a47a12beSStefan Roese     /* 28.9 - (7): initialize parameter ram */
297a47a12beSStefan Roese     pram_ptr = (fcc_enet_t *)&(cpm->im_dprambase[info->proff_enet]);
298a47a12beSStefan Roese 
299a47a12beSStefan Roese     /* clear whole structure to make sure all reserved fields are zero */
300a47a12beSStefan Roese     memset((void*)pram_ptr, 0, sizeof(fcc_enet_t));
301a47a12beSStefan Roese 
302a47a12beSStefan Roese     /*
303a47a12beSStefan Roese      * common Parameter RAM area
304a47a12beSStefan Roese      *
305a47a12beSStefan Roese      * Allocate space in the reserved FCC area of DPRAM for the
306a47a12beSStefan Roese      * internal buffers.  No one uses this space (yet), so we
307a47a12beSStefan Roese      * can do this.  Later, we will add resource management for
308a47a12beSStefan Roese      * this area.
309a47a12beSStefan Roese      * CPM_FCC_SPECIAL_BASE:	0xB000 for MPC8540, MPC8560
310a47a12beSStefan Roese      *				0x9000 for MPC8541, MPC8555
311a47a12beSStefan Roese      */
312a47a12beSStefan Roese     mem_addr = CPM_FCC_SPECIAL_BASE + ((info->ether_index) * 64);
313a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_riptr = mem_addr;
314a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_tiptr = mem_addr+32;
315a47a12beSStefan Roese     /*
316a47a12beSStefan Roese      * Set maximum bytes per receive buffer.
317a47a12beSStefan Roese      * It must be a multiple of 32.
318a47a12beSStefan Roese      */
319a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_mrblr = PKT_MAXBLR_SIZE; /* 1536 */
320a47a12beSStefan Roese     /* localbus SDRAM should be preferred */
321a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_rstate = (CPMFCR_GBL | CPMFCR_EB |
322a47a12beSStefan Roese 				       CONFIG_SYS_CPMFCR_RAMTYPE) << 24;
323a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_rbase = (unsigned int)(&rtx.rxbd[rxIdx]);
324a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_rbdstat = 0;
325a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_rbdlen = 0;
326a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_rdptr = 0;
327a47a12beSStefan Roese     /* localbus SDRAM should be preferred */
328a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_tstate = (CPMFCR_GBL | CPMFCR_EB |
329a47a12beSStefan Roese 				       CONFIG_SYS_CPMFCR_RAMTYPE) << 24;
330a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_tbase = (unsigned int)(&rtx.txbd[txIdx]);
331a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_tbdstat = 0;
332a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_tbdlen = 0;
333a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_tdptr = 0;
334a47a12beSStefan Roese 
335a47a12beSStefan Roese     /* protocol-specific area */
336a47a12beSStefan Roese     pram_ptr->fen_statbuf = 0x0;
337a47a12beSStefan Roese     pram_ptr->fen_cmask = 0xdebb20e3;	/* CRC mask */
338a47a12beSStefan Roese     pram_ptr->fen_cpres = 0xffffffff;	/* CRC preset */
339a47a12beSStefan Roese     pram_ptr->fen_crcec = 0;
340a47a12beSStefan Roese     pram_ptr->fen_alec = 0;
341a47a12beSStefan Roese     pram_ptr->fen_disfc = 0;
342a47a12beSStefan Roese     pram_ptr->fen_retlim = 15;		/* Retry limit threshold */
343a47a12beSStefan Roese     pram_ptr->fen_retcnt = 0;
344a47a12beSStefan Roese     pram_ptr->fen_pper = 0;
345a47a12beSStefan Roese     pram_ptr->fen_boffcnt = 0;
346a47a12beSStefan Roese     pram_ptr->fen_gaddrh = 0;
347a47a12beSStefan Roese     pram_ptr->fen_gaddrl = 0;
348a47a12beSStefan Roese     pram_ptr->fen_mflr = PKT_MAXBUF_SIZE;   /* maximum frame length register */
349a47a12beSStefan Roese     /*
350a47a12beSStefan Roese      * Set Ethernet station address.
351a47a12beSStefan Roese      *
352a47a12beSStefan Roese      * This is supplied in the board information structure, so we
353a47a12beSStefan Roese      * copy that into the controller.
354a47a12beSStefan Roese      * So far we have only been given one Ethernet address. We make
355a47a12beSStefan Roese      * it unique by setting a few bits in the upper byte of the
356a47a12beSStefan Roese      * non-static part of the address.
357a47a12beSStefan Roese      */
358a47a12beSStefan Roese #define ea eth_get_dev()->enetaddr
359a47a12beSStefan Roese     pram_ptr->fen_paddrh = (ea[5] << 8) + ea[4];
360a47a12beSStefan Roese     pram_ptr->fen_paddrm = (ea[3] << 8) + ea[2];
361a47a12beSStefan Roese     pram_ptr->fen_paddrl = (ea[1] << 8) + ea[0];
362a47a12beSStefan Roese #undef ea
363a47a12beSStefan Roese     pram_ptr->fen_ibdcount = 0;
364a47a12beSStefan Roese     pram_ptr->fen_ibdstart = 0;
365a47a12beSStefan Roese     pram_ptr->fen_ibdend = 0;
366a47a12beSStefan Roese     pram_ptr->fen_txlen = 0;
367a47a12beSStefan Roese     pram_ptr->fen_iaddrh = 0;  /* disable hash */
368a47a12beSStefan Roese     pram_ptr->fen_iaddrl = 0;
369a47a12beSStefan Roese     pram_ptr->fen_minflr = PKT_MINBUF_SIZE; /* minimum frame length register: 64 */
370a47a12beSStefan Roese     /* pad pointer. use tiptr since we don't need a specific padding char */
371a47a12beSStefan Roese     pram_ptr->fen_padptr = pram_ptr->fen_genfcc.fcc_tiptr;
372a47a12beSStefan Roese     pram_ptr->fen_maxd1 = PKT_MAXDMA_SIZE;	/* maximum DMA1 length:1520 */
373a47a12beSStefan Roese     pram_ptr->fen_maxd2 = PKT_MAXDMA_SIZE;	/* maximum DMA2 length:1520 */
374a47a12beSStefan Roese 
375a47a12beSStefan Roese #if defined(ET_DEBUG)
376a47a12beSStefan Roese     printf("parm_ptr(0xff788500) = %p\n",pram_ptr);
377a47a12beSStefan Roese     printf("pram_ptr->fen_genfcc.fcc_rbase %08x\n",
378a47a12beSStefan Roese 	pram_ptr->fen_genfcc.fcc_rbase);
379a47a12beSStefan Roese     printf("pram_ptr->fen_genfcc.fcc_tbase %08x\n",
380a47a12beSStefan Roese 	pram_ptr->fen_genfcc.fcc_tbase);
381a47a12beSStefan Roese #endif
382a47a12beSStefan Roese 
383a47a12beSStefan Roese     /* 28.9 - (8)(9): clear out events in FCCE */
384a47a12beSStefan Roese     /* 28.9 - (9): FCCM: mask all events */
385a47a12beSStefan Roese     if(info->ether_index == 0) {
386a47a12beSStefan Roese 	cpm->im_cpm_fcc1.fcce = ~0x0;
387a47a12beSStefan Roese 	cpm->im_cpm_fcc1.fccm = 0;
388a47a12beSStefan Roese     } else if (info->ether_index == 1) {
389a47a12beSStefan Roese 	cpm->im_cpm_fcc2.fcce = ~0x0;
390a47a12beSStefan Roese 	cpm->im_cpm_fcc2.fccm = 0;
391a47a12beSStefan Roese     } else if (info->ether_index == 2) {
392a47a12beSStefan Roese 	cpm->im_cpm_fcc3.fcce = ~0x0;
393a47a12beSStefan Roese 	cpm->im_cpm_fcc3.fccm = 0;
394a47a12beSStefan Roese     }
395a47a12beSStefan Roese 
396a47a12beSStefan Roese     /* 28.9 - (10-12): we don't use ethernet interrupts */
397a47a12beSStefan Roese 
398a47a12beSStefan Roese     /* 28.9 - (13)
399a47a12beSStefan Roese      *
400a47a12beSStefan Roese      * Let's re-initialize the channel now.  We have to do it later
401a47a12beSStefan Roese      * than the manual describes because we have just now finished
402a47a12beSStefan Roese      * the BD initialization.
403a47a12beSStefan Roese      */
404a47a12beSStefan Roese     cp->cpcr = mk_cr_cmd(info->cpm_cr_enet_page,
405a47a12beSStefan Roese 			    info->cpm_cr_enet_sblock,
406a47a12beSStefan Roese 			    0x0c,
407a47a12beSStefan Roese 			    CPM_CR_INIT_TRX) | CPM_CR_FLG;
408a47a12beSStefan Roese     do {
409a47a12beSStefan Roese 	__asm__ __volatile__ ("eieio");
410a47a12beSStefan Roese     } while (cp->cpcr & CPM_CR_FLG);
411a47a12beSStefan Roese 
412a47a12beSStefan Roese     /* 28.9 - (14): enable tx/rx in gfmr */
413a47a12beSStefan Roese     if(info->ether_index == 0) {
414a47a12beSStefan Roese 	cpm->im_cpm_fcc1.gfmr |= FCC_GFMR_ENT | FCC_GFMR_ENR;
415a47a12beSStefan Roese     } else if (info->ether_index == 1) {
416a47a12beSStefan Roese 	cpm->im_cpm_fcc2.gfmr |= FCC_GFMR_ENT | FCC_GFMR_ENR;
417a47a12beSStefan Roese     } else if (info->ether_index == 2) {
418a47a12beSStefan Roese 	cpm->im_cpm_fcc3.gfmr |= FCC_GFMR_ENT | FCC_GFMR_ENR;
419a47a12beSStefan Roese     }
420a47a12beSStefan Roese 
421a47a12beSStefan Roese     return 1;
422a47a12beSStefan Roese }
423a47a12beSStefan Roese 
424a47a12beSStefan Roese static void fec_halt(struct eth_device* dev)
425a47a12beSStefan Roese {
426a47a12beSStefan Roese     struct ether_fcc_info_s * info = dev->priv;
427a47a12beSStefan Roese     volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
428a47a12beSStefan Roese 
429a47a12beSStefan Roese     /* write GFMR: disable tx/rx */
430a47a12beSStefan Roese     if(info->ether_index == 0) {
431a47a12beSStefan Roese 	cpm->im_cpm_fcc1.gfmr &= ~(FCC_GFMR_ENT | FCC_GFMR_ENR);
432a47a12beSStefan Roese     } else if(info->ether_index == 1) {
433a47a12beSStefan Roese 	cpm->im_cpm_fcc2.gfmr &= ~(FCC_GFMR_ENT | FCC_GFMR_ENR);
434a47a12beSStefan Roese     } else if(info->ether_index == 2) {
435a47a12beSStefan Roese 	cpm->im_cpm_fcc3.gfmr &= ~(FCC_GFMR_ENT | FCC_GFMR_ENR);
436a47a12beSStefan Roese     }
437a47a12beSStefan Roese }
438a47a12beSStefan Roese 
439a47a12beSStefan Roese int fec_initialize(bd_t *bis)
440a47a12beSStefan Roese {
441a47a12beSStefan Roese 	struct eth_device* dev;
442a47a12beSStefan Roese 	int i;
443a47a12beSStefan Roese 
444a47a12beSStefan Roese 	for (i = 0; i < sizeof(ether_fcc_info) / sizeof(ether_fcc_info[0]); i++)
445a47a12beSStefan Roese 	{
446a47a12beSStefan Roese 		dev = (struct eth_device*) malloc(sizeof *dev);
447a47a12beSStefan Roese 		memset(dev, 0, sizeof *dev);
448a47a12beSStefan Roese 
449*48690d80SHeiko Schocher 		sprintf(dev->name, "FCC%d",
450a47a12beSStefan Roese 			ether_fcc_info[i].ether_index + 1);
451a47a12beSStefan Roese 		dev->priv   = &ether_fcc_info[i];
452a47a12beSStefan Roese 		dev->init   = fec_init;
453a47a12beSStefan Roese 		dev->halt   = fec_halt;
454a47a12beSStefan Roese 		dev->send   = fec_send;
455a47a12beSStefan Roese 		dev->recv   = fec_recv;
456a47a12beSStefan Roese 
457a47a12beSStefan Roese 		eth_register(dev);
458a47a12beSStefan Roese 
459a47a12beSStefan Roese #if (defined(CONFIG_MII) || defined(CONFIG_CMD_MII)) \
460a47a12beSStefan Roese 		&& defined(CONFIG_BITBANGMII)
461a47a12beSStefan Roese 		miiphy_register(dev->name,
462a47a12beSStefan Roese 				bb_miiphy_read,	bb_miiphy_write);
463a47a12beSStefan Roese #endif
464a47a12beSStefan Roese 	}
465a47a12beSStefan Roese 
466a47a12beSStefan Roese 	return 1;
467a47a12beSStefan Roese }
468a47a12beSStefan Roese 
469a47a12beSStefan Roese #endif
470