1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44#include <common.h>
45#include <malloc.h>
46#include <asm/cpm_85xx.h>
47#include <command.h>
48#include <config.h>
49#include <net.h>
50
51#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
52#include <miiphy.h>
53#endif
54
55#if defined(CONFIG_ETHER_ON_FCC) && defined(CONFIG_CMD_NET)
56
57static struct ether_fcc_info_s
58{
59 int ether_index;
60 int proff_enet;
61 ulong cpm_cr_enet_sblock;
62 ulong cpm_cr_enet_page;
63 ulong cmxfcr_mask;
64 ulong cmxfcr_value;
65}
66 ether_fcc_info[] =
67{
68#ifdef CONFIG_ETHER_ON_FCC1
69{
70 0,
71 PROFF_FCC1,
72 CPM_CR_FCC1_SBLOCK,
73 CPM_CR_FCC1_PAGE,
74 CONFIG_SYS_CMXFCR_MASK1,
75 CONFIG_SYS_CMXFCR_VALUE1
76},
77#endif
78
79#ifdef CONFIG_ETHER_ON_FCC2
80{
81 1,
82 PROFF_FCC2,
83 CPM_CR_FCC2_SBLOCK,
84 CPM_CR_FCC2_PAGE,
85 CONFIG_SYS_CMXFCR_MASK2,
86 CONFIG_SYS_CMXFCR_VALUE2
87},
88#endif
89
90#ifdef CONFIG_ETHER_ON_FCC3
91{
92 2,
93 PROFF_FCC3,
94 CPM_CR_FCC3_SBLOCK,
95 CPM_CR_FCC3_PAGE,
96 CONFIG_SYS_CMXFCR_MASK3,
97 CONFIG_SYS_CMXFCR_VALUE3
98},
99#endif
100};
101
102
103
104
105#define PKT_MAXDMA_SIZE 1520
106
107
108#define PKT_MAXBUF_SIZE 1518
109#define PKT_MINBUF_SIZE 64
110
111
112#define PKT_MAXBLR_SIZE 1536
113
114#define TOUT_LOOP 1000000
115
116#define TX_BUF_CNT 2
117
118static uint rxIdx;
119static uint txIdx;
120
121
122
123
124
125
126
127typedef volatile struct rtxbd {
128 cbd_t rxbd[PKTBUFSRX];
129 cbd_t txbd[TX_BUF_CNT];
130} RTXBD;
131
132
133#ifdef __GNUC__
134static RTXBD rtx __attribute__ ((aligned(8)));
135#else
136#error "rtx must be 64-bit aligned"
137#endif
138
139#undef ET_DEBUG
140
141static int fec_send(struct eth_device *dev, void *packet, int length)
142{
143 int i = 0;
144 int result = 0;
145
146 if (length <= 0) {
147 printf("fec: bad packet size: %d\n", length);
148 goto out;
149 }
150
151 for(i=0; rtx.txbd[txIdx].cbd_sc & BD_ENET_TX_READY; i++) {
152 if (i >= TOUT_LOOP) {
153 printf("fec: tx buffer not ready\n");
154 goto out;
155 }
156 }
157
158 rtx.txbd[txIdx].cbd_bufaddr = (uint)packet;
159 rtx.txbd[txIdx].cbd_datlen = length;
160 rtx.txbd[txIdx].cbd_sc |= (BD_ENET_TX_READY | BD_ENET_TX_LAST | \
161 BD_ENET_TX_TC | BD_ENET_TX_PAD);
162
163 for(i=0; rtx.txbd[txIdx].cbd_sc & BD_ENET_TX_READY; i++) {
164 if (i >= TOUT_LOOP) {
165 printf("fec: tx error\n");
166 goto out;
167 }
168 }
169
170#ifdef ET_DEBUG
171 printf("cycles: 0x%x txIdx=0x%04x status: 0x%04x\n", i, txIdx,rtx.txbd[txIdx].cbd_sc);
172 printf("packets at 0x%08x, length_in_bytes=0x%x\n",(uint)packet,length);
173 for(i=0;i<(length/16 + 1);i++) {
174 printf("%08x %08x %08x %08x\n",*((uint *)rtx.txbd[txIdx].cbd_bufaddr+i*4),\
175 *((uint *)rtx.txbd[txIdx].cbd_bufaddr + i*4 + 1),*((uint *)rtx.txbd[txIdx].cbd_bufaddr + i*4 + 2), \
176 *((uint *)rtx.txbd[txIdx].cbd_bufaddr + i*4 + 3));
177 }
178#endif
179
180
181 result = rtx.txbd[txIdx].cbd_sc & BD_ENET_TX_STATS;
182 txIdx = (txIdx + 1) % TX_BUF_CNT;
183
184out:
185 return result;
186}
187
188static int fec_recv(struct eth_device* dev)
189{
190 int length;
191
192 for (;;)
193 {
194 if (rtx.rxbd[rxIdx].cbd_sc & BD_ENET_RX_EMPTY) {
195 length = -1;
196 break;
197 }
198 length = rtx.rxbd[rxIdx].cbd_datlen;
199
200 if (rtx.rxbd[rxIdx].cbd_sc & 0x003f) {
201 printf("fec: rx error %04x\n", rtx.rxbd[rxIdx].cbd_sc);
202 }
203 else {
204
205 NetReceive(NetRxPackets[rxIdx], length - 4);
206 }
207
208
209
210 rtx.rxbd[rxIdx].cbd_datlen = 0;
211
212
213 if ((rxIdx + 1) >= PKTBUFSRX) {
214 rtx.rxbd[PKTBUFSRX - 1].cbd_sc = (BD_ENET_RX_WRAP | BD_ENET_RX_EMPTY);
215 rxIdx = 0;
216 }
217 else {
218 rtx.rxbd[rxIdx].cbd_sc = BD_ENET_RX_EMPTY;
219 rxIdx++;
220 }
221 }
222 return length;
223}
224
225
226static int fec_init(struct eth_device* dev, bd_t *bis)
227{
228 struct ether_fcc_info_s * info = dev->priv;
229 int i;
230 volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
231 volatile ccsr_cpm_cp_t *cp = &(cpm->im_cpm_cp);
232 fcc_enet_t *pram_ptr;
233 unsigned long mem_addr;
234
235#if 0
236 mii_discover_phy();
237#endif
238
239
240
241
242 cpm->im_cpm_mux.cmxuar = 0;
243 cpm->im_cpm_mux.cmxfcr = (cpm->im_cpm_mux.cmxfcr & ~info->cmxfcr_mask) |
244 info->cmxfcr_value;
245
246
247 if(info->ether_index == 0) {
248 cpm->im_cpm_fcc1.gfmr = FCC_GFMR_MODE_ENET | FCC_GFMR_TCRC_32;
249 } else if (info->ether_index == 1) {
250 cpm->im_cpm_fcc2.gfmr = FCC_GFMR_MODE_ENET | FCC_GFMR_TCRC_32;
251 } else if (info->ether_index == 2) {
252 cpm->im_cpm_fcc3.gfmr = FCC_GFMR_MODE_ENET | FCC_GFMR_TCRC_32;
253 }
254
255
256 if(info->ether_index == 0) {
257 cpm->im_cpm_fcc1.fpsmr = CONFIG_SYS_FCC_PSMR | FCC_PSMR_ENCRC;
258 } else if (info->ether_index == 1){
259 cpm->im_cpm_fcc2.fpsmr = CONFIG_SYS_FCC_PSMR | FCC_PSMR_ENCRC;
260 } else if (info->ether_index == 2){
261 cpm->im_cpm_fcc3.fpsmr = CONFIG_SYS_FCC_PSMR | FCC_PSMR_ENCRC;
262 }
263
264
265 if(info->ether_index == 0) {
266 cpm->im_cpm_fcc1.fdsr = 0xD555;
267 } else if (info->ether_index == 1) {
268 cpm->im_cpm_fcc2.fdsr = 0xD555;
269 } else if (info->ether_index == 2) {
270 cpm->im_cpm_fcc3.fdsr = 0xD555;
271 }
272
273
274 rxIdx = 0;
275 txIdx = 0;
276
277
278 for (i = 0; i < PKTBUFSRX; i++)
279 {
280 rtx.rxbd[i].cbd_sc = BD_ENET_RX_EMPTY;
281 rtx.rxbd[i].cbd_datlen = 0;
282 rtx.rxbd[i].cbd_bufaddr = (uint)NetRxPackets[i];
283 }
284 rtx.rxbd[PKTBUFSRX - 1].cbd_sc |= BD_ENET_RX_WRAP;
285
286
287 for (i = 0; i < TX_BUF_CNT; i++)
288 {
289 rtx.txbd[i].cbd_sc = 0;
290 rtx.txbd[i].cbd_datlen = 0;
291 rtx.txbd[i].cbd_bufaddr = 0;
292 }
293 rtx.txbd[TX_BUF_CNT - 1].cbd_sc |= BD_ENET_TX_WRAP;
294
295
296 pram_ptr = (fcc_enet_t *)&(cpm->im_dprambase[info->proff_enet]);
297
298
299 memset((void*)pram_ptr, 0, sizeof(fcc_enet_t));
300
301
302
303
304
305
306
307
308
309
310
311 mem_addr = CPM_FCC_SPECIAL_BASE + ((info->ether_index) * 64);
312 pram_ptr->fen_genfcc.fcc_riptr = mem_addr;
313 pram_ptr->fen_genfcc.fcc_tiptr = mem_addr+32;
314
315
316
317
318 pram_ptr->fen_genfcc.fcc_mrblr = PKT_MAXBLR_SIZE;
319
320 pram_ptr->fen_genfcc.fcc_rstate = (CPMFCR_GBL | CPMFCR_EB |
321 CONFIG_SYS_CPMFCR_RAMTYPE) << 24;
322 pram_ptr->fen_genfcc.fcc_rbase = (unsigned int)(&rtx.rxbd[rxIdx]);
323 pram_ptr->fen_genfcc.fcc_rbdstat = 0;
324 pram_ptr->fen_genfcc.fcc_rbdlen = 0;
325 pram_ptr->fen_genfcc.fcc_rdptr = 0;
326
327 pram_ptr->fen_genfcc.fcc_tstate = (CPMFCR_GBL | CPMFCR_EB |
328 CONFIG_SYS_CPMFCR_RAMTYPE) << 24;
329 pram_ptr->fen_genfcc.fcc_tbase = (unsigned int)(&rtx.txbd[txIdx]);
330 pram_ptr->fen_genfcc.fcc_tbdstat = 0;
331 pram_ptr->fen_genfcc.fcc_tbdlen = 0;
332 pram_ptr->fen_genfcc.fcc_tdptr = 0;
333
334
335 pram_ptr->fen_statbuf = 0x0;
336 pram_ptr->fen_cmask = 0xdebb20e3;
337 pram_ptr->fen_cpres = 0xffffffff;
338 pram_ptr->fen_crcec = 0;
339 pram_ptr->fen_alec = 0;
340 pram_ptr->fen_disfc = 0;
341 pram_ptr->fen_retlim = 15;
342 pram_ptr->fen_retcnt = 0;
343 pram_ptr->fen_pper = 0;
344 pram_ptr->fen_boffcnt = 0;
345 pram_ptr->fen_gaddrh = 0;
346 pram_ptr->fen_gaddrl = 0;
347 pram_ptr->fen_mflr = PKT_MAXBUF_SIZE;
348
349
350
351
352
353
354
355
356
357#define ea eth_get_dev()->enetaddr
358 pram_ptr->fen_paddrh = (ea[5] << 8) + ea[4];
359 pram_ptr->fen_paddrm = (ea[3] << 8) + ea[2];
360 pram_ptr->fen_paddrl = (ea[1] << 8) + ea[0];
361#undef ea
362 pram_ptr->fen_ibdcount = 0;
363 pram_ptr->fen_ibdstart = 0;
364 pram_ptr->fen_ibdend = 0;
365 pram_ptr->fen_txlen = 0;
366 pram_ptr->fen_iaddrh = 0;
367 pram_ptr->fen_iaddrl = 0;
368 pram_ptr->fen_minflr = PKT_MINBUF_SIZE;
369
370 pram_ptr->fen_padptr = pram_ptr->fen_genfcc.fcc_tiptr;
371 pram_ptr->fen_maxd1 = PKT_MAXDMA_SIZE;
372 pram_ptr->fen_maxd2 = PKT_MAXDMA_SIZE;
373
374#if defined(ET_DEBUG)
375 printf("parm_ptr(0xff788500) = %p\n",pram_ptr);
376 printf("pram_ptr->fen_genfcc.fcc_rbase %08x\n",
377 pram_ptr->fen_genfcc.fcc_rbase);
378 printf("pram_ptr->fen_genfcc.fcc_tbase %08x\n",
379 pram_ptr->fen_genfcc.fcc_tbase);
380#endif
381
382
383
384 if(info->ether_index == 0) {
385 cpm->im_cpm_fcc1.fcce = ~0x0;
386 cpm->im_cpm_fcc1.fccm = 0;
387 } else if (info->ether_index == 1) {
388 cpm->im_cpm_fcc2.fcce = ~0x0;
389 cpm->im_cpm_fcc2.fccm = 0;
390 } else if (info->ether_index == 2) {
391 cpm->im_cpm_fcc3.fcce = ~0x0;
392 cpm->im_cpm_fcc3.fccm = 0;
393 }
394
395
396
397
398
399
400
401
402
403 cp->cpcr = mk_cr_cmd(info->cpm_cr_enet_page,
404 info->cpm_cr_enet_sblock,
405 0x0c,
406 CPM_CR_INIT_TRX) | CPM_CR_FLG;
407 do {
408 __asm__ __volatile__ ("eieio");
409 } while (cp->cpcr & CPM_CR_FLG);
410
411
412 if(info->ether_index == 0) {
413 cpm->im_cpm_fcc1.gfmr |= FCC_GFMR_ENT | FCC_GFMR_ENR;
414 } else if (info->ether_index == 1) {
415 cpm->im_cpm_fcc2.gfmr |= FCC_GFMR_ENT | FCC_GFMR_ENR;
416 } else if (info->ether_index == 2) {
417 cpm->im_cpm_fcc3.gfmr |= FCC_GFMR_ENT | FCC_GFMR_ENR;
418 }
419
420 return 1;
421}
422
423static void fec_halt(struct eth_device* dev)
424{
425 struct ether_fcc_info_s * info = dev->priv;
426 volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
427
428
429 if(info->ether_index == 0) {
430 cpm->im_cpm_fcc1.gfmr &= ~(FCC_GFMR_ENT | FCC_GFMR_ENR);
431 } else if(info->ether_index == 1) {
432 cpm->im_cpm_fcc2.gfmr &= ~(FCC_GFMR_ENT | FCC_GFMR_ENR);
433 } else if(info->ether_index == 2) {
434 cpm->im_cpm_fcc3.gfmr &= ~(FCC_GFMR_ENT | FCC_GFMR_ENR);
435 }
436}
437
438int fec_initialize(bd_t *bis)
439{
440 struct eth_device* dev;
441 int i;
442
443 for (i = 0; i < sizeof(ether_fcc_info) / sizeof(ether_fcc_info[0]); i++)
444 {
445 dev = (struct eth_device*) malloc(sizeof *dev);
446 memset(dev, 0, sizeof *dev);
447
448 sprintf(dev->name, "FCC%d",
449 ether_fcc_info[i].ether_index + 1);
450 dev->priv = ðer_fcc_info[i];
451 dev->init = fec_init;
452 dev->halt = fec_halt;
453 dev->send = fec_send;
454 dev->recv = fec_recv;
455
456 eth_register(dev);
457
458#if (defined(CONFIG_MII) || defined(CONFIG_CMD_MII)) \
459 && defined(CONFIG_BITBANGMII)
460 miiphy_register(dev->name,
461 bb_miiphy_read, bb_miiphy_write);
462#endif
463 }
464
465 return 1;
466}
467
468#endif
469