2 * MPC8260 FCC Fast Ethernet
4 * Copyright (c) 2000 MontaVista Software, Inc. Dan Malek (dmalek@jlc.net)
6 * (C) Copyright 2000 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
7 * Marius Groeger <mgroeger@sysgo.de>
9 * SPDX-License-Identifier: GPL-2.0+
13 * MPC8260 FCC Fast Ethernet
14 * Basic ET HW initialization and packet RX/TX routines
16 * This code will not perform the IO port configuration. This should be
17 * done in the iop_conf_t structure specific for the board.
20 * add a PHY driver to do the negotiation
21 * reflect negotiation results in FPSMR
22 * look for ways to configure the board specific stuff elsewhere, eg.
23 * config_xxx.h or the board directory
29 #include <asm/cpm_8260.h>
35 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
39 DECLARE_GLOBAL_DATA_PTR;
41 #if defined(CONFIG_ETHER_ON_FCC) && defined(CONFIG_CMD_NET)
43 static struct ether_fcc_info_s
47 ulong cpm_cr_enet_sblock;
48 ulong cpm_cr_enet_page;
54 #ifdef CONFIG_ETHER_ON_FCC1
60 CONFIG_SYS_CMXFCR_MASK1,
61 CONFIG_SYS_CMXFCR_VALUE1
65 #ifdef CONFIG_ETHER_ON_FCC2
71 CONFIG_SYS_CMXFCR_MASK2,
72 CONFIG_SYS_CMXFCR_VALUE2
76 #ifdef CONFIG_ETHER_ON_FCC3
82 CONFIG_SYS_CMXFCR_MASK3,
83 CONFIG_SYS_CMXFCR_VALUE3
88 /*---------------------------------------------------------------------*/
90 /* Maximum input DMA size. Must be a should(?) be a multiple of 4. */
91 #define PKT_MAXDMA_SIZE 1520
93 /* The FCC stores dest/src/type, data, and checksum for receive packets. */
94 #define PKT_MAXBUF_SIZE 1518
95 #define PKT_MINBUF_SIZE 64
97 /* Maximum input buffer size. Must be a multiple of 32. */
98 #define PKT_MAXBLR_SIZE 1536
100 #define TOUT_LOOP 1000000
104 static char txbuf[TX_BUF_CNT][PKT_MAXBLR_SIZE] __attribute__ ((aligned(8)));
106 #error "txbuf must be 64-bit aligned"
109 static uint rxIdx; /* index of the current RX buffer */
110 static uint txIdx; /* index of the current TX buffer */
113 * FCC Ethernet Tx and Rx buffer descriptors.
114 * Provide for Double Buffering
115 * Note: PKTBUFSRX is defined in net.h
118 typedef volatile struct rtxbd {
119 cbd_t rxbd[PKTBUFSRX];
120 cbd_t txbd[TX_BUF_CNT];
123 /* Good news: the FCC supports external BDs! */
125 static RTXBD rtx __attribute__ ((aligned(8)));
127 #error "rtx must be 64-bit aligned"
130 static int fec_send(struct eth_device *dev, void *packet, int length)
136 printf("fec: bad packet size: %d\n", length);
140 for(i=0; rtx.txbd[txIdx].cbd_sc & BD_ENET_TX_READY; i++) {
141 if (i >= TOUT_LOOP) {
142 puts ("fec: tx buffer not ready\n");
147 rtx.txbd[txIdx].cbd_bufaddr = (uint)packet;
148 rtx.txbd[txIdx].cbd_datlen = length;
149 rtx.txbd[txIdx].cbd_sc |= (BD_ENET_TX_READY | BD_ENET_TX_LAST |
152 for(i=0; rtx.txbd[txIdx].cbd_sc & BD_ENET_TX_READY; i++) {
153 if (i >= TOUT_LOOP) {
154 puts ("fec: tx error\n");
160 printf("cycles: %d status: %04x\n", i, rtx.txbd[txIdx].cbd_sc);
163 /* return only status bits */
164 result = rtx.txbd[txIdx].cbd_sc & BD_ENET_TX_STATS;
170 static int fec_recv(struct eth_device* dev)
176 if (rtx.rxbd[rxIdx].cbd_sc & BD_ENET_RX_EMPTY) {
178 break; /* nothing received - leave for() loop */
180 length = rtx.rxbd[rxIdx].cbd_datlen;
182 if (rtx.rxbd[rxIdx].cbd_sc & 0x003f) {
183 printf("fec: rx error %04x\n", rtx.rxbd[rxIdx].cbd_sc);
186 /* Pass the packet up to the protocol layers. */
187 net_process_received_packet(net_rx_packets[rxIdx], length - 4);
191 /* Give the buffer back to the FCC. */
192 rtx.rxbd[rxIdx].cbd_datlen = 0;
194 /* wrap around buffer index when necessary */
195 if ((rxIdx + 1) >= PKTBUFSRX) {
196 rtx.rxbd[PKTBUFSRX - 1].cbd_sc = (BD_ENET_RX_WRAP | BD_ENET_RX_EMPTY);
200 rtx.rxbd[rxIdx].cbd_sc = BD_ENET_RX_EMPTY;
208 static int fec_init(struct eth_device* dev, bd_t *bis)
210 struct ether_fcc_info_s * info = dev->priv;
212 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
213 volatile cpm8260_t *cp = &(immr->im_cpm);
214 fcc_enet_t *pram_ptr;
215 unsigned long mem_addr;
221 /* 28.9 - (1-2): ioports have been set up already */
223 /* 28.9 - (3): connect FCC's tx and rx clocks */
224 immr->im_cpmux.cmx_uar = 0;
225 immr->im_cpmux.cmx_fcr = (immr->im_cpmux.cmx_fcr & ~info->cmxfcr_mask) |
228 /* 28.9 - (4): GFMR: disable tx/rx, CCITT CRC, Mode Ethernet */
229 immr->im_fcc[info->ether_index].fcc_gfmr =
230 FCC_GFMR_MODE_ENET | FCC_GFMR_TCRC_32;
232 /* 28.9 - (5): FPSMR: enable full duplex, select CCITT CRC for Ethernet */
233 immr->im_fcc[info->ether_index].fcc_fpsmr = CONFIG_SYS_FCC_PSMR | FCC_PSMR_ENCRC;
235 /* 28.9 - (6): FDSR: Ethernet Syn */
236 immr->im_fcc[info->ether_index].fcc_fdsr = 0xD555;
238 /* reset indeces to current rx/tx bd (see eth_send()/eth_rx()) */
242 /* Setup Receiver Buffer Descriptors */
243 for (i = 0; i < PKTBUFSRX; i++)
245 rtx.rxbd[i].cbd_sc = BD_ENET_RX_EMPTY;
246 rtx.rxbd[i].cbd_datlen = 0;
247 rtx.rxbd[i].cbd_bufaddr = (uint)net_rx_packets[i];
249 rtx.rxbd[PKTBUFSRX - 1].cbd_sc |= BD_ENET_RX_WRAP;
251 /* Setup Ethernet Transmitter Buffer Descriptors */
252 for (i = 0; i < TX_BUF_CNT; i++)
254 rtx.txbd[i].cbd_sc = (BD_ENET_TX_PAD | BD_ENET_TX_LAST | BD_ENET_TX_TC);
255 rtx.txbd[i].cbd_datlen = 0;
256 rtx.txbd[i].cbd_bufaddr = (uint)&txbuf[i][0];
258 rtx.txbd[TX_BUF_CNT - 1].cbd_sc |= BD_ENET_TX_WRAP;
260 /* 28.9 - (7): initialise parameter ram */
261 pram_ptr = (fcc_enet_t *)&(immr->im_dprambase[info->proff_enet]);
263 /* clear whole structure to make sure all reserved fields are zero */
264 memset((void*)pram_ptr, 0, sizeof(fcc_enet_t));
267 * common Parameter RAM area
269 * Allocate space in the reserved FCC area of DPRAM for the
270 * internal buffers. No one uses this space (yet), so we
271 * can do this. Later, we will add resource management for
274 mem_addr = CPM_FCC_SPECIAL_BASE + ((info->ether_index) * 64);
275 pram_ptr->fen_genfcc.fcc_riptr = mem_addr;
276 pram_ptr->fen_genfcc.fcc_tiptr = mem_addr+32;
278 * Set maximum bytes per receive buffer.
279 * It must be a multiple of 32.
281 pram_ptr->fen_genfcc.fcc_mrblr = PKT_MAXBLR_SIZE;
282 pram_ptr->fen_genfcc.fcc_rstate = (CPMFCR_GBL | CPMFCR_EB |
283 CONFIG_SYS_CPMFCR_RAMTYPE) << 24;
284 pram_ptr->fen_genfcc.fcc_rbase = (unsigned int)(&rtx.rxbd[rxIdx]);
285 pram_ptr->fen_genfcc.fcc_tstate = (CPMFCR_GBL | CPMFCR_EB |
286 CONFIG_SYS_CPMFCR_RAMTYPE) << 24;
287 pram_ptr->fen_genfcc.fcc_tbase = (unsigned int)(&rtx.txbd[txIdx]);
289 /* protocol-specific area */
290 pram_ptr->fen_cmask = 0xdebb20e3; /* CRC mask */
291 pram_ptr->fen_cpres = 0xffffffff; /* CRC preset */
292 pram_ptr->fen_retlim = 15; /* Retry limit threshold */
293 pram_ptr->fen_mflr = PKT_MAXBUF_SIZE; /* maximum frame length register */
295 * Set Ethernet station address.
297 * This is supplied in the board information structure, so we
298 * copy that into the controller.
299 * So, far we have only been given one Ethernet address. We make
300 * it unique by setting a few bits in the upper byte of the
301 * non-static part of the address.
303 #define ea eth_get_ethaddr()
304 pram_ptr->fen_paddrh = (ea[5] << 8) + ea[4];
305 pram_ptr->fen_paddrm = (ea[3] << 8) + ea[2];
306 pram_ptr->fen_paddrl = (ea[1] << 8) + ea[0];
308 pram_ptr->fen_minflr = PKT_MINBUF_SIZE; /* minimum frame length register */
309 /* pad pointer. use tiptr since we don't need a specific padding char */
310 pram_ptr->fen_padptr = pram_ptr->fen_genfcc.fcc_tiptr;
311 pram_ptr->fen_maxd1 = PKT_MAXDMA_SIZE; /* maximum DMA1 length */
312 pram_ptr->fen_maxd2 = PKT_MAXDMA_SIZE; /* maximum DMA2 length */
313 pram_ptr->fen_rfthr = 1;
314 pram_ptr->fen_rfcnt = 1;
316 printf("pram_ptr->fen_genfcc.fcc_rbase %08lx\n",
317 pram_ptr->fen_genfcc.fcc_rbase);
318 printf("pram_ptr->fen_genfcc.fcc_tbase %08lx\n",
319 pram_ptr->fen_genfcc.fcc_tbase);
322 /* 28.9 - (8): clear out events in FCCE */
323 immr->im_fcc[info->ether_index].fcc_fcce = ~0x0;
325 /* 28.9 - (9): FCCM: mask all events */
326 immr->im_fcc[info->ether_index].fcc_fccm = 0;
328 /* 28.9 - (10-12): we don't use ethernet interrupts */
332 * Let's re-initialize the channel now. We have to do it later
333 * than the manual describes because we have just now finished
334 * the BD initialization.
336 cp->cp_cpcr = mk_cr_cmd(info->cpm_cr_enet_page,
337 info->cpm_cr_enet_sblock,
339 CPM_CR_INIT_TRX) | CPM_CR_FLG;
341 __asm__ __volatile__ ("eieio");
342 } while (cp->cp_cpcr & CPM_CR_FLG);
344 /* 28.9 - (14): enable tx/rx in gfmr */
345 immr->im_fcc[info->ether_index].fcc_gfmr |= FCC_GFMR_ENT | FCC_GFMR_ENR;
350 static void fec_halt(struct eth_device* dev)
352 struct ether_fcc_info_s * info = dev->priv;
353 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
355 /* write GFMR: disable tx/rx */
356 immr->im_fcc[info->ether_index].fcc_gfmr &=
357 ~(FCC_GFMR_ENT | FCC_GFMR_ENR);
360 int fec_initialize(bd_t *bis)
362 struct eth_device* dev;
365 for (i = 0; i < ARRAY_SIZE(ether_fcc_info); i++)
367 dev = (struct eth_device*) malloc(sizeof *dev);
368 memset(dev, 0, sizeof *dev);
370 sprintf(dev->name, "FCC%d",
371 ether_fcc_info[i].ether_index + 1);
372 dev->priv = ðer_fcc_info[i];
373 dev->init = fec_init;
374 dev->halt = fec_halt;
375 dev->send = fec_send;
376 dev->recv = fec_recv;
380 #if (defined(CONFIG_MII) || defined(CONFIG_CMD_MII)) \
381 && defined(CONFIG_BITBANGMII)
383 struct mii_dev *mdiodev = mdio_alloc();
386 strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
387 mdiodev->read = bb_miiphy_read;
388 mdiodev->write = bb_miiphy_write;
390 retval = mdio_register(mdiodev);
399 #ifdef CONFIG_ETHER_LOOPBACK_TEST
401 #define ELBT_BUFSZ 1024 /* must be multiple of 32 */
405 #define ELBT_NRXBD 4 /* must be at least 2 */
408 #define ELBT_MAXRXERR 32
409 #define ELBT_MAXTXERR 32
411 #define ELBT_CLSWAIT 1000 /* msec to wait for further input frames */
422 uint _l, _f, m, bc, mc, lg, no, sh, cr, ov, cl;
423 uint badsrc, badtyp, badlen, badbit;
427 static elbt_prdesc rxeacc_descs[] = {
428 { offsetof(elbt_rxeacc, _l), "Not Last in Frame" },
429 { offsetof(elbt_rxeacc, _f), "Not First in Frame" },
430 { offsetof(elbt_rxeacc, m), "Address Miss" },
431 { offsetof(elbt_rxeacc, bc), "Broadcast Address" },
432 { offsetof(elbt_rxeacc, mc), "Multicast Address" },
433 { offsetof(elbt_rxeacc, lg), "Frame Length Violation"},
434 { offsetof(elbt_rxeacc, no), "Non-Octet Alignment" },
435 { offsetof(elbt_rxeacc, sh), "Short Frame" },
436 { offsetof(elbt_rxeacc, cr), "CRC Error" },
437 { offsetof(elbt_rxeacc, ov), "Overrun" },
438 { offsetof(elbt_rxeacc, cl), "Collision" },
439 { offsetof(elbt_rxeacc, badsrc), "Bad Src Address" },
440 { offsetof(elbt_rxeacc, badtyp), "Bad Frame Type" },
441 { offsetof(elbt_rxeacc, badlen), "Bad Frame Length" },
442 { offsetof(elbt_rxeacc, badbit), "Data Compare Errors" },
444 static int rxeacc_ndesc = ARRAY_SIZE(rxeacc_descs);
448 uint def, hb, lc, rl, rc, un, csl;
452 static elbt_prdesc txeacc_descs[] = {
453 { offsetof(elbt_txeacc, def), "Defer Indication" },
454 { offsetof(elbt_txeacc, hb), "Heartbeat" },
455 { offsetof(elbt_txeacc, lc), "Late Collision" },
456 { offsetof(elbt_txeacc, rl), "Retransmission Limit" },
457 { offsetof(elbt_txeacc, rc), "Retry Count" },
458 { offsetof(elbt_txeacc, un), "Underrun" },
459 { offsetof(elbt_txeacc, csl), "Carrier Sense Lost" },
461 static int txeacc_ndesc = ARRAY_SIZE(txeacc_descs);
465 uchar rxbufs[ELBT_NRXBD][ELBT_BUFSZ];
466 uchar txbufs[ELBT_NTXBD][ELBT_BUFSZ];
467 cbd_t rxbd[ELBT_NRXBD];
468 cbd_t txbd[ELBT_NTXBD];
469 enum { Idle, Running, Closing, Closed } state;
470 int proff, page, sblock;
471 uint clstime, nsent, ntxerr, nrcvd, nrxerr;
472 ushort rxerrs[ELBT_MAXRXERR], txerrs[ELBT_MAXTXERR];
475 } __attribute__ ((aligned(8)))
478 static uchar patbytes[ELBT_NTXBD] = {
479 0xff, 0xaa, 0x55, 0x00
481 static uint patwords[ELBT_NTXBD] = {
482 0xffffffff, 0xaaaaaaaa, 0x55555555, 0x00000000
486 static elbt_chan elbt_chans[3] __attribute__ ((aligned(8)));
488 #error "elbt_chans must be 64-bit aligned"
491 #define CPM_CR_GRACEFUL_STOP_TX ((ushort)0x0005)
493 static elbt_prdesc epram_descs[] = {
494 { offsetof(fcc_enet_t, fen_crcec), "CRC Errors" },
495 { offsetof(fcc_enet_t, fen_alec), "Alignment Errors" },
496 { offsetof(fcc_enet_t, fen_disfc), "Discarded Frames" },
497 { offsetof(fcc_enet_t, fen_octc), "Octets" },
498 { offsetof(fcc_enet_t, fen_colc), "Collisions" },
499 { offsetof(fcc_enet_t, fen_broc), "Broadcast Frames" },
500 { offsetof(fcc_enet_t, fen_mulc), "Multicast Frames" },
501 { offsetof(fcc_enet_t, fen_uspc), "Undersize Frames" },
502 { offsetof(fcc_enet_t, fen_frgc), "Fragments" },
503 { offsetof(fcc_enet_t, fen_ospc), "Oversize Frames" },
504 { offsetof(fcc_enet_t, fen_jbrc), "Jabbers" },
505 { offsetof(fcc_enet_t, fen_p64c), "64 Octet Frames" },
506 { offsetof(fcc_enet_t, fen_p65c), "65-127 Octet Frames" },
507 { offsetof(fcc_enet_t, fen_p128c), "128-255 Octet Frames" },
508 { offsetof(fcc_enet_t, fen_p256c), "256-511 Octet Frames" },
509 { offsetof(fcc_enet_t, fen_p512c), "512-1023 Octet Frames" },
510 { offsetof(fcc_enet_t, fen_p1024c), "1024-1518 Octet Frames"},
512 static int epram_ndesc = ARRAY_SIZE(epram_descs);
515 * given an elbt_prdesc array and an array of base addresses, print
516 * each prdesc down the screen with the values fetched from each
517 * base address across the screen
520 print_desc (elbt_prdesc descs[], int ndesc, uchar *bases[], int nbase)
522 elbt_prdesc *dp = descs, *edp = dp + ndesc;
527 for (i = 0; i < nbase; i++)
528 printf (" Channel %d", i);
534 printf ("%-32s", dp->lab);
536 for (i = 0; i < nbase; i++) {
537 uint val = *(uint *)(bases[i] + dp->off);
539 printf (" %10u", val);
549 * return number of bits that are set in a value; value contains
550 * nbits (right-justified) bits.
552 static uint __inline__
553 nbs (uint value, uint nbits)
557 uint pos = sizeof (uint) * 8;
559 __asm__ __volatile__ ("\
561 1: rlwnm. %2,%1,%4,31,31\n\
567 : "r"(value), "r"(nbits), "r"(cnt), "r"(pos)
583 badbits (uchar *bp, int n, ulong pat)
588 while (n > 0 && ((ulong)bp & (sizeof (ulong) - 1)) != 0) {
591 diff = *bp++ ^ (uchar)pat;
594 cnt += nbs ((ulong)diff, 8);
600 nl = n / sizeof (ulong);
601 n -= nl * sizeof (ulong);
609 cnt += nbs (diff, 32);
619 diff = *bp++ ^ (uchar)pat;
622 cnt += nbs ((ulong)diff, 8);
630 static inline unsigned short
631 swap16 (unsigned short x)
633 return (((x & 0xff) << 8) | ((x & 0xff00) >> 8));
636 /* broadcast is not an error - we send them like that */
637 #define BD_ENET_RX_ERRS (BD_ENET_RX_STATS & ~BD_ENET_RX_BC)
640 eth_loopback_test (void)
642 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
643 volatile cpm8260_t *cp = &(immr->im_cpm);
645 ulong runtime, nmsec;
648 puts ("FCC Ethernet External loopback test\n");
650 eth_getenv_enetaddr("ethaddr", net_ethaddr);
653 * global initialisations for all FCC channels
656 /* 28.9 - (1-2): ioports have been set up already */
658 #if defined(CONFIG_SACSng)
660 * Attention: this is board-specific
663 # define FCC_START_LOOP 1
664 # define FCC_END_LOOP 1
667 * Attention: this is board-specific
668 * - FCC2 Rx-CLK is CLK13
669 * - FCC2 Tx-CLK is CLK14
672 /* 28.9 - (3): connect FCC's tx and rx clocks */
673 immr->im_cpmux.cmx_uar = 0;
674 immr->im_cpmux.cmx_fcr = CMXFCR_RF2CS_CLK13|CMXFCR_TF2CS_CLK14;
676 #error "eth_loopback_test not supported on your board"
679 puts ("Initialise FCC channels:");
681 for (c = FCC_START_LOOP; c <= FCC_END_LOOP; c++) {
682 elbt_chan *ecp = &elbt_chans[c];
683 volatile fcc_t *fcp = &immr->im_fcc[c];
684 volatile fcc_enet_t *fpp;
689 * initialise channel data
694 memset ((void *)ecp, 0, sizeof (*ecp));
701 ecp->proff = PROFF_FCC1;
702 ecp->page = CPM_CR_FCC1_PAGE;
703 ecp->sblock = CPM_CR_FCC1_SBLOCK;
707 ecp->proff = PROFF_FCC2;
708 ecp->page = CPM_CR_FCC2_PAGE;
709 ecp->sblock = CPM_CR_FCC2_SBLOCK;
713 ecp->proff = PROFF_FCC3;
714 ecp->page = CPM_CR_FCC3_PAGE;
715 ecp->sblock = CPM_CR_FCC3_SBLOCK;
720 * set up tx buffers and bds
723 for (i = 0; i < ELBT_NTXBD; i++) {
724 cbd_t *bdp = &ecp->txbd[i];
725 uchar *bp = &ecp->txbufs[i][0];
727 bdp->cbd_bufaddr = (uint)bp;
729 bdp->cbd_datlen = ELBT_BUFSZ - ELBT_CRCSZ;
730 bdp->cbd_sc = BD_ENET_TX_READY | BD_ENET_TX_PAD | \
731 BD_ENET_TX_LAST | BD_ENET_TX_TC;
733 memset((void *)bp, patbytes[i], ELBT_BUFSZ);
734 net_set_ether(bp, net_bcast_ethaddr, 0x8000);
736 ecp->txbd[ELBT_NTXBD - 1].cbd_sc |= BD_ENET_TX_WRAP;
739 * set up rx buffers and bds
742 for (i = 0; i < ELBT_NRXBD; i++) {
743 cbd_t *bdp = &ecp->rxbd[i];
744 uchar *bp = &ecp->rxbufs[i][0];
746 bdp->cbd_bufaddr = (uint)bp;
748 bdp->cbd_sc = BD_ENET_RX_EMPTY;
750 memset ((void *)bp, 0, ELBT_BUFSZ);
752 ecp->rxbd[ELBT_NRXBD - 1].cbd_sc |= BD_ENET_RX_WRAP;
755 * set up the FCC channel hardware
758 /* 28.9 - (4): GFMR: disable tx/rx, CCITT CRC, Mode Ethernet */
759 fcp->fcc_gfmr = FCC_GFMR_MODE_ENET | FCC_GFMR_TCRC_32;
761 /* 28.9 - (5): FPSMR: fd, enet CRC, Promis, RMON, Rx SHort */
762 fcp->fcc_fpsmr = FCC_PSMR_FDE | FCC_PSMR_LPB | \
763 FCC_PSMR_ENCRC | FCC_PSMR_PRO | \
764 FCC_PSMR_MON | FCC_PSMR_RSH;
766 /* 28.9 - (6): FDSR: Ethernet Syn */
767 fcp->fcc_fdsr = 0xD555;
769 /* 29.9 - (7): initialise parameter ram */
770 fpp = (fcc_enet_t *)&(immr->im_dprambase[ecp->proff]);
772 /* clear whole struct to make sure all resv fields are zero */
773 memset ((void *)fpp, 0, sizeof (fcc_enet_t));
776 * common Parameter RAM area
778 * Allocate space in the reserved FCC area of DPRAM for the
779 * internal buffers. No one uses this space (yet), so we
780 * can do this. Later, we will add resource management for
783 addr = CPM_FCC_SPECIAL_BASE + (c * 64);
784 fpp->fen_genfcc.fcc_riptr = addr;
785 fpp->fen_genfcc.fcc_tiptr = addr + 32;
788 * Set maximum bytes per receive buffer.
789 * It must be a multiple of 32.
790 * buffers are in 60x bus memory.
792 fpp->fen_genfcc.fcc_mrblr = PKT_MAXBLR_SIZE;
793 fpp->fen_genfcc.fcc_rstate = (CPMFCR_GBL | CPMFCR_EB) << 24;
794 fpp->fen_genfcc.fcc_rbase = (unsigned int)(&ecp->rxbd[0]);
795 fpp->fen_genfcc.fcc_tstate = (CPMFCR_GBL | CPMFCR_EB) << 24;
796 fpp->fen_genfcc.fcc_tbase = (unsigned int)(&ecp->txbd[0]);
798 /* protocol-specific area */
799 fpp->fen_cmask = 0xdebb20e3; /* CRC mask */
800 fpp->fen_cpres = 0xffffffff; /* CRC preset */
801 fpp->fen_retlim = 15; /* Retry limit threshold */
802 fpp->fen_mflr = PKT_MAXBUF_SIZE;/* max frame length register */
805 * Set Ethernet station address.
807 * This is supplied in the board information structure, so we
808 * copy that into the controller.
809 * So, far we have only been given one Ethernet address. We use
810 * the same address for all channels
812 fpp->fen_paddrh = (net_ethaddr[5] << 8) + net_ethaddr[4];
813 fpp->fen_paddrm = (net_ethaddr[3] << 8) + net_ethaddr[2];
814 fpp->fen_paddrl = (net_ethaddr[1] << 8) + net_ethaddr[0];
816 fpp->fen_minflr = PKT_MINBUF_SIZE; /* min frame len register */
818 * pad pointer. use tiptr since we don't need
819 * a specific padding char
821 fpp->fen_padptr = fpp->fen_genfcc.fcc_tiptr;
822 fpp->fen_maxd1 = PKT_MAXDMA_SIZE; /* max DMA1 length */
823 fpp->fen_maxd2 = PKT_MAXDMA_SIZE; /* max DMA2 length */
827 /* 28.9 - (8): clear out events in FCCE */
828 fcp->fcc_fcce = ~0x0;
830 /* 28.9 - (9): FCCM: mask all events */
833 /* 28.9 - (10-12): we don't use ethernet interrupts */
837 * Let's re-initialize the channel now. We have to do it later
838 * than the manual describes because we have just now finished
839 * the BD initialization.
841 cp->cp_cpcr = mk_cr_cmd (ecp->page, ecp->sblock, \
842 0x0c, CPM_CR_INIT_TRX) | CPM_CR_FLG;
844 __asm__ __volatile__ ("eieio");
845 } while (cp->cp_cpcr & CPM_CR_FLG);
848 puts (" done\nStarting test... (Ctrl-C to Finish)\n");
851 * Note: don't want serial output from here until the end of the
852 * test - the delays would probably stuff things up.
856 runtime = get_timer (0);
861 for (c = FCC_START_LOOP; c <= FCC_END_LOOP; c++) {
862 volatile fcc_t *fcp = &immr->im_fcc[c];
863 elbt_chan *ecp = &elbt_chans[c];
866 switch (ecp->state) {
870 * set the channel Running ...
873 /* 28.9 - (14): enable tx/rx in gfmr */
874 fcp->fcc_gfmr |= FCC_GFMR_ENT | FCC_GFMR_ENR;
876 ecp->state = Running;
881 * (while Running only) check for
882 * termination of the test
889 * initiate a "graceful stop transmit"
892 cp->cp_cpcr = mk_cr_cmd (ecp->page, \
894 CPM_CR_GRACEFUL_STOP_TX) | \
897 __asm__ __volatile__ ("eieio");
898 } while (cp->cp_cpcr & CPM_CR_FLG);
900 ecp->clstime = get_timer (0);
901 ecp->state = Closing;
903 /* fall through ... */
907 * (while Running or Closing) poll the channel:
908 * - check for any non-READY tx buffers and
910 * - check for any non-EMPTY rx buffers and
911 * check that they were received correctly,
912 * adjust counters etc, then make empty
915 for (i = 0; i < ELBT_NTXBD; i++) {
916 cbd_t *bdp = &ecp->txbd[i];
917 ushort sc = bdp->cbd_sc;
919 if ((sc & BD_ENET_TX_READY) != 0)
923 * this frame has finished
928 if (sc & BD_ENET_TX_STATS) {
936 if (n < ELBT_MAXTXERR)
939 if (sc & BD_ENET_TX_DEF)
941 if (sc & BD_ENET_TX_HB)
943 if (sc & BD_ENET_TX_LC)
945 if (sc & BD_ENET_TX_RL)
947 if (sc & BD_ENET_TX_RCMASK)
949 if (sc & BD_ENET_TX_UN)
951 if (sc & BD_ENET_TX_CSL)
958 if (ecp->state == Closing)
959 ecp->clstime = get_timer (0);
961 /* make it ready again */
962 bdp->cbd_sc |= BD_ENET_TX_READY;
965 for (i = 0; i < ELBT_NRXBD; i++) {
966 cbd_t *bdp = &ecp->rxbd[i];
967 ushort sc = bdp->cbd_sc, mask;
969 if ((sc & BD_ENET_RX_EMPTY) != 0)
972 /* we have a new frame in this buffer */
975 mask = BD_ENET_RX_LAST|BD_ENET_RX_FIRST;
976 if ((sc & mask) != mask) {
977 /* somethings wrong here ... */
978 if (!(sc & BD_ENET_RX_LAST))
980 if (!(sc & BD_ENET_RX_FIRST))
984 if (sc & BD_ENET_RX_ERRS) {
988 * we had some sort of error
992 if (n < ELBT_MAXRXERR)
995 if (sc & BD_ENET_RX_MISS)
997 if (sc & BD_ENET_RX_BC)
999 if (sc & BD_ENET_RX_MC)
1001 if (sc & BD_ENET_RX_LG)
1003 if (sc & BD_ENET_RX_NO)
1005 if (sc & BD_ENET_RX_SH)
1007 if (sc & BD_ENET_RX_CR)
1009 if (sc & BD_ENET_RX_OV)
1011 if (sc & BD_ENET_RX_CL)
1018 ushort datlen = bdp->cbd_datlen;
1019 struct ethernet_hdr *ehp;
1021 int ours, tb, n, nbytes;
1023 ehp = (struct ethernet_hdr *) \
1026 ours = memcmp (ehp->et_src, \
1029 prot = swap16 (ehp->et_protlen);
1033 nbytes = ELBT_BUFSZ -
1037 /* check the frame is correct */
1038 if (datlen != ELBT_BUFSZ)
1039 ecp->rxeacc.badlen++;
1041 ecp->rxeacc.badsrc++;
1042 else if (!tb || n >= ELBT_NTXBD)
1043 ecp->rxeacc.badtyp++;
1054 ecp->rxeacc.badbit += \
1059 if (ecp->state == Closing)
1060 ecp->clstime = get_timer (0);
1062 /* make it empty again */
1063 bdp->cbd_sc |= BD_ENET_RX_EMPTY;
1066 if (ecp->state != Closing)
1070 * (while Closing) check to see if
1071 * waited long enough
1074 if (get_timer (ecp->clstime) >= ELBT_CLSWAIT) {
1075 /* write GFMR: disable tx/rx */
1077 ~(FCC_GFMR_ENT | FCC_GFMR_ENR);
1078 ecp->state = Closed;
1089 } while (nclosed < (FCC_END_LOOP - FCC_START_LOOP + 1));
1091 runtime = get_timer (runtime);
1092 if (runtime <= ELBT_CLSWAIT) {
1093 printf ("Whoops! somehow elapsed time (%ld) is wrong (<= %d)\n",
1094 runtime, ELBT_CLSWAIT);
1097 nmsec = runtime - ELBT_CLSWAIT;
1099 printf ("Test Finished in %ldms (plus %dms close wait period)!\n\n",
1100 nmsec, ELBT_CLSWAIT);
1106 for (c = FCC_START_LOOP; c <= FCC_END_LOOP; c++) {
1107 elbt_chan *ecp = &elbt_chans[c];
1108 uint rxpps, txpps, nerr;
1110 rxpps = (ecp->nrcvd * 1000) / nmsec;
1111 txpps = (ecp->nsent * 1000) / nmsec;
1113 printf ("Channel %d: %d rcvd (%d pps, %d rxerrs), "
1114 "%d sent (%d pps, %d txerrs)\n\n", c,
1115 ecp->nrcvd, rxpps, ecp->nrxerr,
1116 ecp->nsent, txpps, ecp->ntxerr);
1118 if ((nerr = ecp->nrxerr) > 0) {
1121 printf ("\tFirst %d rx errs:", nerr);
1122 for (i = 0; i < nerr; i++)
1123 printf (" %04x", ecp->rxerrs[i]);
1127 if ((nerr = ecp->ntxerr) > 0) {
1130 printf ("\tFirst %d tx errs:", nerr);
1131 for (i = 0; i < nerr; i++)
1132 printf (" %04x", ecp->txerrs[i]);
1137 puts ("Receive Error Counts:\n");
1138 for (c = FCC_START_LOOP; c <= FCC_END_LOOP; c++)
1139 bases[c] = (uchar *)&elbt_chans[c].rxeacc;
1140 print_desc (rxeacc_descs, rxeacc_ndesc, bases, 3);
1142 puts ("\nTransmit Error Counts:\n");
1143 for (c = FCC_START_LOOP; c <= FCC_END_LOOP; c++)
1144 bases[c] = (uchar *)&elbt_chans[c].txeacc;
1145 print_desc (txeacc_descs, txeacc_ndesc, bases, 3);
1147 puts ("\nRMON(-like) Counters:\n");
1148 for (c = FCC_START_LOOP; c <= FCC_END_LOOP; c++)
1149 bases[c] = (uchar *)&immr->im_dprambase[elbt_chans[c].proff];
1150 print_desc (epram_descs, epram_ndesc, bases, 3);
1153 #endif /* CONFIG_ETHER_LOOPBACK_TEST */