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