blob: a11ad1e9d06be650266fc48ee1d1402c853f15e8 [file] [log] [blame]
wdenkaffae2b2002-08-17 09:36:01 +00001/*
2 * MPC8260 FCC Fast Ethernet
3 *
4 * Copyright (c) 2000 MontaVista Software, Inc. Dan Malek (dmalek@jlc.net)
5 *
6 * (C) Copyright 2000 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
7 * Marius Groeger <mgroeger@sysgo.de>
8 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02009 * SPDX-License-Identifier: GPL-2.0+
wdenkaffae2b2002-08-17 09:36:01 +000010 */
11
12/*
13 * MPC8260 FCC Fast Ethernet
14 * Basic ET HW initialization and packet RX/TX routines
15 *
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.
18 *
19 * TODO:
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
24 */
25
26#include <common.h>
Simon Glassa73bda42015-11-08 23:47:45 -070027#include <console.h>
wdenkeda42082003-01-17 16:27:01 +000028#include <malloc.h>
wdenkaffae2b2002-08-17 09:36:01 +000029#include <asm/cpm_8260.h>
30#include <mpc8260.h>
wdenkaffae2b2002-08-17 09:36:01 +000031#include <command.h>
32#include <config.h>
wdenkeda42082003-01-17 16:27:01 +000033#include <net.h>
wdenkaffae2b2002-08-17 09:36:01 +000034
Jon Loeliger526e5ce2007-07-09 19:06:00 -050035#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
Marian Balakowiczaab8c492005-10-28 22:30:33 +020036#include <miiphy.h>
37#endif
38
Wolfgang Denk6405a152006-03-31 18:32:53 +020039DECLARE_GLOBAL_DATA_PTR;
40
Mike Frysingera23230c2011-10-02 10:01:27 +000041#if defined(CONFIG_ETHER_ON_FCC) && defined(CONFIG_CMD_NET)
wdenkaffae2b2002-08-17 09:36:01 +000042
wdenkeda42082003-01-17 16:27:01 +000043static struct ether_fcc_info_s
44{
45 int ether_index;
46 int proff_enet;
47 ulong cpm_cr_enet_sblock;
48 ulong cpm_cr_enet_page;
49 ulong cmxfcr_mask;
50 ulong cmxfcr_value;
51}
52 ether_fcc_info[] =
53{
54#ifdef CONFIG_ETHER_ON_FCC1
55{
56 0,
57 PROFF_FCC1,
58 CPM_CR_FCC1_SBLOCK,
59 CPM_CR_FCC1_PAGE,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020060 CONFIG_SYS_CMXFCR_MASK1,
61 CONFIG_SYS_CMXFCR_VALUE1
wdenkeda42082003-01-17 16:27:01 +000062},
63#endif
wdenkaffae2b2002-08-17 09:36:01 +000064
wdenkeda42082003-01-17 16:27:01 +000065#ifdef CONFIG_ETHER_ON_FCC2
66{
67 1,
68 PROFF_FCC2,
69 CPM_CR_FCC2_SBLOCK,
70 CPM_CR_FCC2_PAGE,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020071 CONFIG_SYS_CMXFCR_MASK2,
72 CONFIG_SYS_CMXFCR_VALUE2
wdenkeda42082003-01-17 16:27:01 +000073},
74#endif
wdenkaffae2b2002-08-17 09:36:01 +000075
wdenkeda42082003-01-17 16:27:01 +000076#ifdef CONFIG_ETHER_ON_FCC3
77{
78 2,
79 PROFF_FCC3,
80 CPM_CR_FCC3_SBLOCK,
81 CPM_CR_FCC3_PAGE,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020082 CONFIG_SYS_CMXFCR_MASK3,
83 CONFIG_SYS_CMXFCR_VALUE3
wdenkeda42082003-01-17 16:27:01 +000084},
wdenkaffae2b2002-08-17 09:36:01 +000085#endif
wdenkeda42082003-01-17 16:27:01 +000086};
87
wdenkaffae2b2002-08-17 09:36:01 +000088/*---------------------------------------------------------------------*/
89
90/* Maximum input DMA size. Must be a should(?) be a multiple of 4. */
91#define PKT_MAXDMA_SIZE 1520
92
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
96
97/* Maximum input buffer size. Must be a multiple of 32. */
98#define PKT_MAXBLR_SIZE 1536
99
100#define TOUT_LOOP 1000000
101
102#define TX_BUF_CNT 2
103#ifdef __GNUC__
104static char txbuf[TX_BUF_CNT][PKT_MAXBLR_SIZE] __attribute__ ((aligned(8)));
105#else
106#error "txbuf must be 64-bit aligned"
107#endif
108
109static uint rxIdx; /* index of the current RX buffer */
110static uint txIdx; /* index of the current TX buffer */
111
112/*
113 * FCC Ethernet Tx and Rx buffer descriptors.
114 * Provide for Double Buffering
115 * Note: PKTBUFSRX is defined in net.h
116 */
117
118typedef volatile struct rtxbd {
119 cbd_t rxbd[PKTBUFSRX];
120 cbd_t txbd[TX_BUF_CNT];
121} RTXBD;
122
123/* Good news: the FCC supports external BDs! */
124#ifdef __GNUC__
125static RTXBD rtx __attribute__ ((aligned(8)));
126#else
127#error "rtx must be 64-bit aligned"
128#endif
129
Joe Hershberger8cb3af82012-05-22 07:56:11 +0000130static int fec_send(struct eth_device *dev, void *packet, int length)
wdenkaffae2b2002-08-17 09:36:01 +0000131{
132 int i;
133 int result = 0;
134
135 if (length <= 0) {
136 printf("fec: bad packet size: %d\n", length);
137 goto out;
138 }
139
140 for(i=0; rtx.txbd[txIdx].cbd_sc & BD_ENET_TX_READY; i++) {
141 if (i >= TOUT_LOOP) {
wdenk42c05472004-03-23 22:14:11 +0000142 puts ("fec: tx buffer not ready\n");
wdenkaffae2b2002-08-17 09:36:01 +0000143 goto out;
144 }
145 }
146
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 |
150 BD_ENET_TX_WRAP);
151
152 for(i=0; rtx.txbd[txIdx].cbd_sc & BD_ENET_TX_READY; i++) {
153 if (i >= TOUT_LOOP) {
wdenk42c05472004-03-23 22:14:11 +0000154 puts ("fec: tx error\n");
wdenkaffae2b2002-08-17 09:36:01 +0000155 goto out;
156 }
157 }
158
159#ifdef ET_DEBUG
160 printf("cycles: %d status: %04x\n", i, rtx.txbd[txIdx].cbd_sc);
161#endif
162
163 /* return only status bits */
164 result = rtx.txbd[txIdx].cbd_sc & BD_ENET_TX_STATS;
165
166out:
167 return result;
168}
169
wdenkeda42082003-01-17 16:27:01 +0000170static int fec_recv(struct eth_device* dev)
wdenkaffae2b2002-08-17 09:36:01 +0000171{
172 int length;
173
174 for (;;)
175 {
176 if (rtx.rxbd[rxIdx].cbd_sc & BD_ENET_RX_EMPTY) {
177 length = -1;
178 break; /* nothing received - leave for() loop */
179 }
180 length = rtx.rxbd[rxIdx].cbd_datlen;
181
182 if (rtx.rxbd[rxIdx].cbd_sc & 0x003f) {
183 printf("fec: rx error %04x\n", rtx.rxbd[rxIdx].cbd_sc);
184 }
185 else {
186 /* Pass the packet up to the protocol layers. */
Joe Hershberger9f09a362015-04-08 01:41:06 -0500187 net_process_received_packet(net_rx_packets[rxIdx], length - 4);
wdenkaffae2b2002-08-17 09:36:01 +0000188 }
189
190
191 /* Give the buffer back to the FCC. */
192 rtx.rxbd[rxIdx].cbd_datlen = 0;
193
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);
197 rxIdx = 0;
198 }
199 else {
200 rtx.rxbd[rxIdx].cbd_sc = BD_ENET_RX_EMPTY;
201 rxIdx++;
202 }
203 }
204 return length;
205}
206
207
wdenkeda42082003-01-17 16:27:01 +0000208static int fec_init(struct eth_device* dev, bd_t *bis)
wdenkaffae2b2002-08-17 09:36:01 +0000209{
wdenkeda42082003-01-17 16:27:01 +0000210 struct ether_fcc_info_s * info = dev->priv;
wdenkaffae2b2002-08-17 09:36:01 +0000211 int i;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200212 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
wdenkaffae2b2002-08-17 09:36:01 +0000213 volatile cpm8260_t *cp = &(immr->im_cpm);
214 fcc_enet_t *pram_ptr;
215 unsigned long mem_addr;
216
217#if 0
218 mii_discover_phy();
219#endif
220
221 /* 28.9 - (1-2): ioports have been set up already */
222
223 /* 28.9 - (3): connect FCC's tx and rx clocks */
224 immr->im_cpmux.cmx_uar = 0;
wdenkeda42082003-01-17 16:27:01 +0000225 immr->im_cpmux.cmx_fcr = (immr->im_cpmux.cmx_fcr & ~info->cmxfcr_mask) |
wdenk9c53f402003-10-15 23:53:47 +0000226 info->cmxfcr_value;
wdenkaffae2b2002-08-17 09:36:01 +0000227
228 /* 28.9 - (4): GFMR: disable tx/rx, CCITT CRC, Mode Ethernet */
wdenkeda42082003-01-17 16:27:01 +0000229 immr->im_fcc[info->ether_index].fcc_gfmr =
wdenkaffae2b2002-08-17 09:36:01 +0000230 FCC_GFMR_MODE_ENET | FCC_GFMR_TCRC_32;
231
232 /* 28.9 - (5): FPSMR: enable full duplex, select CCITT CRC for Ethernet */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200233 immr->im_fcc[info->ether_index].fcc_fpsmr = CONFIG_SYS_FCC_PSMR | FCC_PSMR_ENCRC;
wdenkaffae2b2002-08-17 09:36:01 +0000234
235 /* 28.9 - (6): FDSR: Ethernet Syn */
wdenkeda42082003-01-17 16:27:01 +0000236 immr->im_fcc[info->ether_index].fcc_fdsr = 0xD555;
wdenkaffae2b2002-08-17 09:36:01 +0000237
238 /* reset indeces to current rx/tx bd (see eth_send()/eth_rx()) */
239 rxIdx = 0;
240 txIdx = 0;
241
242 /* Setup Receiver Buffer Descriptors */
243 for (i = 0; i < PKTBUFSRX; i++)
244 {
245 rtx.rxbd[i].cbd_sc = BD_ENET_RX_EMPTY;
246 rtx.rxbd[i].cbd_datlen = 0;
Joe Hershberger9f09a362015-04-08 01:41:06 -0500247 rtx.rxbd[i].cbd_bufaddr = (uint)net_rx_packets[i];
wdenkaffae2b2002-08-17 09:36:01 +0000248 }
249 rtx.rxbd[PKTBUFSRX - 1].cbd_sc |= BD_ENET_RX_WRAP;
250
251 /* Setup Ethernet Transmitter Buffer Descriptors */
252 for (i = 0; i < TX_BUF_CNT; i++)
253 {
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];
257 }
258 rtx.txbd[TX_BUF_CNT - 1].cbd_sc |= BD_ENET_TX_WRAP;
259
260 /* 28.9 - (7): initialise parameter ram */
wdenkeda42082003-01-17 16:27:01 +0000261 pram_ptr = (fcc_enet_t *)&(immr->im_dprambase[info->proff_enet]);
wdenkaffae2b2002-08-17 09:36:01 +0000262
263 /* clear whole structure to make sure all reserved fields are zero */
264 memset((void*)pram_ptr, 0, sizeof(fcc_enet_t));
265
266 /*
267 * common Parameter RAM area
268 *
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
272 * this area.
273 */
wdenkeda42082003-01-17 16:27:01 +0000274 mem_addr = CPM_FCC_SPECIAL_BASE + ((info->ether_index) * 64);
wdenkaffae2b2002-08-17 09:36:01 +0000275 pram_ptr->fen_genfcc.fcc_riptr = mem_addr;
276 pram_ptr->fen_genfcc.fcc_tiptr = mem_addr+32;
277 /*
278 * Set maximum bytes per receive buffer.
279 * It must be a multiple of 32.
280 */
281 pram_ptr->fen_genfcc.fcc_mrblr = PKT_MAXBLR_SIZE;
282 pram_ptr->fen_genfcc.fcc_rstate = (CPMFCR_GBL | CPMFCR_EB |
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200283 CONFIG_SYS_CPMFCR_RAMTYPE) << 24;
wdenkaffae2b2002-08-17 09:36:01 +0000284 pram_ptr->fen_genfcc.fcc_rbase = (unsigned int)(&rtx.rxbd[rxIdx]);
285 pram_ptr->fen_genfcc.fcc_tstate = (CPMFCR_GBL | CPMFCR_EB |
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200286 CONFIG_SYS_CPMFCR_RAMTYPE) << 24;
wdenkaffae2b2002-08-17 09:36:01 +0000287 pram_ptr->fen_genfcc.fcc_tbase = (unsigned int)(&rtx.txbd[txIdx]);
288
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 */
294 /*
295 * Set Ethernet station address.
296 *
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.
302 */
Joe Hershberger11cd5a02015-03-22 17:09:00 -0500303#define ea eth_get_ethaddr()
wdenkaffae2b2002-08-17 09:36:01 +0000304 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];
307#undef ea
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;
315#if 0
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);
320#endif
321
322 /* 28.9 - (8): clear out events in FCCE */
wdenkeda42082003-01-17 16:27:01 +0000323 immr->im_fcc[info->ether_index].fcc_fcce = ~0x0;
wdenkaffae2b2002-08-17 09:36:01 +0000324
325 /* 28.9 - (9): FCCM: mask all events */
wdenkeda42082003-01-17 16:27:01 +0000326 immr->im_fcc[info->ether_index].fcc_fccm = 0;
wdenkaffae2b2002-08-17 09:36:01 +0000327
328 /* 28.9 - (10-12): we don't use ethernet interrupts */
329
330 /* 28.9 - (13)
331 *
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.
335 */
wdenkeda42082003-01-17 16:27:01 +0000336 cp->cp_cpcr = mk_cr_cmd(info->cpm_cr_enet_page,
337 info->cpm_cr_enet_sblock,
wdenkaffae2b2002-08-17 09:36:01 +0000338 0x0c,
339 CPM_CR_INIT_TRX) | CPM_CR_FLG;
340 do {
341 __asm__ __volatile__ ("eieio");
342 } while (cp->cp_cpcr & CPM_CR_FLG);
343
344 /* 28.9 - (14): enable tx/rx in gfmr */
wdenkeda42082003-01-17 16:27:01 +0000345 immr->im_fcc[info->ether_index].fcc_gfmr |= FCC_GFMR_ENT | FCC_GFMR_ENR;
wdenkaffae2b2002-08-17 09:36:01 +0000346
347 return 1;
348}
349
wdenkeda42082003-01-17 16:27:01 +0000350static void fec_halt(struct eth_device* dev)
wdenkaffae2b2002-08-17 09:36:01 +0000351{
wdenkeda42082003-01-17 16:27:01 +0000352 struct ether_fcc_info_s * info = dev->priv;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200353 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
wdenkaffae2b2002-08-17 09:36:01 +0000354
355 /* write GFMR: disable tx/rx */
wdenkeda42082003-01-17 16:27:01 +0000356 immr->im_fcc[info->ether_index].fcc_gfmr &=
wdenkaffae2b2002-08-17 09:36:01 +0000357 ~(FCC_GFMR_ENT | FCC_GFMR_ENR);
358}
359
wdenkeda42082003-01-17 16:27:01 +0000360int fec_initialize(bd_t *bis)
361{
362 struct eth_device* dev;
363 int i;
364
Robert P. J. Day0c911592016-05-23 06:49:21 -0400365 for (i = 0; i < ARRAY_SIZE(ether_fcc_info); i++)
wdenkeda42082003-01-17 16:27:01 +0000366 {
367 dev = (struct eth_device*) malloc(sizeof *dev);
368 memset(dev, 0, sizeof *dev);
369
Heiko Schocherc5e84052010-07-20 17:45:02 +0200370 sprintf(dev->name, "FCC%d",
wdenk9c53f402003-10-15 23:53:47 +0000371 ether_fcc_info[i].ether_index + 1);
wdenkeda42082003-01-17 16:27:01 +0000372 dev->priv = &ether_fcc_info[i];
373 dev->init = fec_init;
374 dev->halt = fec_halt;
375 dev->send = fec_send;
376 dev->recv = fec_recv;
377
378 eth_register(dev);
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200379
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500380#if (defined(CONFIG_MII) || defined(CONFIG_CMD_MII)) \
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200381 && defined(CONFIG_BITBANGMII)
382 miiphy_register(dev->name,
383 bb_miiphy_read, bb_miiphy_write);
384#endif
wdenkeda42082003-01-17 16:27:01 +0000385 }
386
387 return 1;
388}
389
wdenkb00ec162003-06-19 23:40:20 +0000390#ifdef CONFIG_ETHER_LOOPBACK_TEST
391
392#define ELBT_BUFSZ 1024 /* must be multiple of 32 */
393
394#define ELBT_CRCSZ 4
395
396#define ELBT_NRXBD 4 /* must be at least 2 */
397#define ELBT_NTXBD 4
398
399#define ELBT_MAXRXERR 32
400#define ELBT_MAXTXERR 32
401
402#define ELBT_CLSWAIT 1000 /* msec to wait for further input frames */
403
404typedef
405 struct {
406 uint off;
407 char *lab;
408 }
409elbt_prdesc;
410
411typedef
412 struct {
413 uint _l, _f, m, bc, mc, lg, no, sh, cr, ov, cl;
414 uint badsrc, badtyp, badlen, badbit;
415 }
416elbt_rxeacc;
417
418static elbt_prdesc rxeacc_descs[] = {
419 { offsetof(elbt_rxeacc, _l), "Not Last in Frame" },
420 { offsetof(elbt_rxeacc, _f), "Not First in Frame" },
421 { offsetof(elbt_rxeacc, m), "Address Miss" },
422 { offsetof(elbt_rxeacc, bc), "Broadcast Address" },
423 { offsetof(elbt_rxeacc, mc), "Multicast Address" },
424 { offsetof(elbt_rxeacc, lg), "Frame Length Violation"},
425 { offsetof(elbt_rxeacc, no), "Non-Octet Alignment" },
426 { offsetof(elbt_rxeacc, sh), "Short Frame" },
427 { offsetof(elbt_rxeacc, cr), "CRC Error" },
428 { offsetof(elbt_rxeacc, ov), "Overrun" },
429 { offsetof(elbt_rxeacc, cl), "Collision" },
430 { offsetof(elbt_rxeacc, badsrc), "Bad Src Address" },
431 { offsetof(elbt_rxeacc, badtyp), "Bad Frame Type" },
432 { offsetof(elbt_rxeacc, badlen), "Bad Frame Length" },
433 { offsetof(elbt_rxeacc, badbit), "Data Compare Errors" },
434};
Robert P. J. Day0c911592016-05-23 06:49:21 -0400435static int rxeacc_ndesc = ARRAY_SIZE(rxeacc_descs);
wdenkb00ec162003-06-19 23:40:20 +0000436
437typedef
438 struct {
439 uint def, hb, lc, rl, rc, un, csl;
440 }
441elbt_txeacc;
442
443static elbt_prdesc txeacc_descs[] = {
444 { offsetof(elbt_txeacc, def), "Defer Indication" },
445 { offsetof(elbt_txeacc, hb), "Heartbeat" },
446 { offsetof(elbt_txeacc, lc), "Late Collision" },
447 { offsetof(elbt_txeacc, rl), "Retransmission Limit" },
448 { offsetof(elbt_txeacc, rc), "Retry Count" },
449 { offsetof(elbt_txeacc, un), "Underrun" },
450 { offsetof(elbt_txeacc, csl), "Carrier Sense Lost" },
451};
Robert P. J. Day0c911592016-05-23 06:49:21 -0400452static int txeacc_ndesc = ARRAY_SIZE(txeacc_descs);
wdenkb00ec162003-06-19 23:40:20 +0000453
454typedef
455 struct {
456 uchar rxbufs[ELBT_NRXBD][ELBT_BUFSZ];
457 uchar txbufs[ELBT_NTXBD][ELBT_BUFSZ];
458 cbd_t rxbd[ELBT_NRXBD];
459 cbd_t txbd[ELBT_NTXBD];
460 enum { Idle, Running, Closing, Closed } state;
461 int proff, page, sblock;
462 uint clstime, nsent, ntxerr, nrcvd, nrxerr;
463 ushort rxerrs[ELBT_MAXRXERR], txerrs[ELBT_MAXTXERR];
464 elbt_rxeacc rxeacc;
465 elbt_txeacc txeacc;
466 } __attribute__ ((aligned(8)))
467elbt_chan;
468
469static uchar patbytes[ELBT_NTXBD] = {
470 0xff, 0xaa, 0x55, 0x00
471};
472static uint patwords[ELBT_NTXBD] = {
473 0xffffffff, 0xaaaaaaaa, 0x55555555, 0x00000000
474};
475
476#ifdef __GNUC__
477static elbt_chan elbt_chans[3] __attribute__ ((aligned(8)));
478#else
479#error "elbt_chans must be 64-bit aligned"
480#endif
481
482#define CPM_CR_GRACEFUL_STOP_TX ((ushort)0x0005)
483
484static elbt_prdesc epram_descs[] = {
485 { offsetof(fcc_enet_t, fen_crcec), "CRC Errors" },
486 { offsetof(fcc_enet_t, fen_alec), "Alignment Errors" },
487 { offsetof(fcc_enet_t, fen_disfc), "Discarded Frames" },
488 { offsetof(fcc_enet_t, fen_octc), "Octets" },
489 { offsetof(fcc_enet_t, fen_colc), "Collisions" },
490 { offsetof(fcc_enet_t, fen_broc), "Broadcast Frames" },
491 { offsetof(fcc_enet_t, fen_mulc), "Multicast Frames" },
492 { offsetof(fcc_enet_t, fen_uspc), "Undersize Frames" },
493 { offsetof(fcc_enet_t, fen_frgc), "Fragments" },
494 { offsetof(fcc_enet_t, fen_ospc), "Oversize Frames" },
495 { offsetof(fcc_enet_t, fen_jbrc), "Jabbers" },
496 { offsetof(fcc_enet_t, fen_p64c), "64 Octet Frames" },
497 { offsetof(fcc_enet_t, fen_p65c), "65-127 Octet Frames" },
498 { offsetof(fcc_enet_t, fen_p128c), "128-255 Octet Frames" },
499 { offsetof(fcc_enet_t, fen_p256c), "256-511 Octet Frames" },
500 { offsetof(fcc_enet_t, fen_p512c), "512-1023 Octet Frames" },
501 { offsetof(fcc_enet_t, fen_p1024c), "1024-1518 Octet Frames"},
502};
Robert P. J. Day0c911592016-05-23 06:49:21 -0400503static int epram_ndesc = ARRAY_SIZE(epram_descs);
wdenkb00ec162003-06-19 23:40:20 +0000504
505/*
506 * given an elbt_prdesc array and an array of base addresses, print
507 * each prdesc down the screen with the values fetched from each
508 * base address across the screen
509 */
510static void
511print_desc (elbt_prdesc descs[], int ndesc, uchar *bases[], int nbase)
512{
513 elbt_prdesc *dp = descs, *edp = dp + ndesc;
514 int i;
515
516 printf ("%32s", "");
517
518 for (i = 0; i < nbase; i++)
519 printf (" Channel %d", i);
520
wdenk42c05472004-03-23 22:14:11 +0000521 putc ('\n');
wdenkb00ec162003-06-19 23:40:20 +0000522
523 while (dp < edp) {
524
525 printf ("%-32s", dp->lab);
526
527 for (i = 0; i < nbase; i++) {
528 uint val = *(uint *)(bases[i] + dp->off);
529
530 printf (" %10u", val);
531 }
532
wdenk42c05472004-03-23 22:14:11 +0000533 putc ('\n');
wdenkb00ec162003-06-19 23:40:20 +0000534
535 dp++;
536 }
537}
538
539/*
540 * return number of bits that are set in a value; value contains
541 * nbits (right-justified) bits.
542 */
543static uint __inline__
544nbs (uint value, uint nbits)
545{
546 uint cnt = 0;
547#if 1
548 uint pos = sizeof (uint) * 8;
549
550 __asm__ __volatile__ ("\
551 mtctr %2\n\
5521: rlwnm. %2,%1,%4,31,31\n\
553 beq 2f\n\
554 addi %0,%0,1\n\
5552: subi %4,%4,1\n\
556 bdnz 1b"
557 : "=r"(cnt)
558 : "r"(value), "r"(nbits), "r"(cnt), "r"(pos)
559 : "ctr", "cc" );
560#else
561 uint mask = 1;
562
563 do {
564 if (value & mask)
565 cnt++;
566 mask <<= 1;
567 } while (--nbits);
568#endif
569
570 return (cnt);
571}
572
573static ulong
574badbits (uchar *bp, int n, ulong pat)
575{
576 ulong *lp, cnt = 0;
577 int nl;
578
579 while (n > 0 && ((ulong)bp & (sizeof (ulong) - 1)) != 0) {
580 uchar diff;
581
582 diff = *bp++ ^ (uchar)pat;
583
584 if (diff)
585 cnt += nbs ((ulong)diff, 8);
586
587 n--;
588 }
589
590 lp = (ulong *)bp;
591 nl = n / sizeof (ulong);
592 n -= nl * sizeof (ulong);
593
594 while (nl > 0) {
595 ulong diff;
596
597 diff = *lp++ ^ pat;
598
599 if (diff)
600 cnt += nbs (diff, 32);
601
602 nl--;
603 }
604
605 bp = (uchar *)lp;
606
607 while (n > 0) {
608 uchar diff;
609
610 diff = *bp++ ^ (uchar)pat;
611
612 if (diff)
613 cnt += nbs ((ulong)diff, 8);
614
615 n--;
616 }
617
618 return (cnt);
619}
620
621static inline unsigned short
622swap16 (unsigned short x)
623{
624 return (((x & 0xff) << 8) | ((x & 0xff00) >> 8));
625}
626
Wolfgang Denk116edc92005-08-03 23:03:54 +0200627/* broadcast is not an error - we send them like that */
628#define BD_ENET_RX_ERRS (BD_ENET_RX_STATS & ~BD_ENET_RX_BC)
629
wdenkb00ec162003-06-19 23:40:20 +0000630void
631eth_loopback_test (void)
632{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200633 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
wdenkb00ec162003-06-19 23:40:20 +0000634 volatile cpm8260_t *cp = &(immr->im_cpm);
635 int c, nclosed;
636 ulong runtime, nmsec;
637 uchar *bases[3];
638
639 puts ("FCC Ethernet External loopback test\n");
640
Joe Hershberger8ecdbed2015-04-08 01:41:04 -0500641 eth_getenv_enetaddr("ethaddr", net_ethaddr);
wdenkb00ec162003-06-19 23:40:20 +0000642
643 /*
644 * global initialisations for all FCC channels
645 */
646
647 /* 28.9 - (1-2): ioports have been set up already */
648
Marek Vasut4cdede62014-10-22 21:34:48 +0200649#if defined(CONFIG_SACSng)
wdenk5256def2003-09-18 10:45:21 +0000650 /*
651 * Attention: this is board-specific
wdenk9c53f402003-10-15 23:53:47 +0000652 * 1, FCC2
653 */
wdenk5256def2003-09-18 10:45:21 +0000654# define FCC_START_LOOP 1
655# define FCC_END_LOOP 1
656
657 /*
658 * Attention: this is board-specific
659 * - FCC2 Rx-CLK is CLK13
660 * - FCC2 Tx-CLK is CLK14
661 */
662
663 /* 28.9 - (3): connect FCC's tx and rx clocks */
664 immr->im_cpmux.cmx_uar = 0;
665 immr->im_cpmux.cmx_fcr = CMXFCR_RF2CS_CLK13|CMXFCR_TF2CS_CLK14;
wdenkb00ec162003-06-19 23:40:20 +0000666#else
667#error "eth_loopback_test not supported on your board"
668#endif
669
670 puts ("Initialise FCC channels:");
671
wdenk5256def2003-09-18 10:45:21 +0000672 for (c = FCC_START_LOOP; c <= FCC_END_LOOP; c++) {
wdenkb00ec162003-06-19 23:40:20 +0000673 elbt_chan *ecp = &elbt_chans[c];
674 volatile fcc_t *fcp = &immr->im_fcc[c];
675 volatile fcc_enet_t *fpp;
676 int i;
677 ulong addr;
678
679 /*
680 * initialise channel data
681 */
682
683 printf (" %d", c);
684
685 memset ((void *)ecp, 0, sizeof (*ecp));
686
687 ecp->state = Idle;
688
689 switch (c) {
690
691 case 0: /* FCC1 */
692 ecp->proff = PROFF_FCC1;
693 ecp->page = CPM_CR_FCC1_PAGE;
694 ecp->sblock = CPM_CR_FCC1_SBLOCK;
695 break;
696
697 case 1: /* FCC2 */
698 ecp->proff = PROFF_FCC2;
699 ecp->page = CPM_CR_FCC2_PAGE;
700 ecp->sblock = CPM_CR_FCC2_SBLOCK;
701 break;
702
703 case 2: /* FCC3 */
704 ecp->proff = PROFF_FCC3;
705 ecp->page = CPM_CR_FCC3_PAGE;
706 ecp->sblock = CPM_CR_FCC3_SBLOCK;
707 break;
708 }
709
710 /*
711 * set up tx buffers and bds
712 */
713
714 for (i = 0; i < ELBT_NTXBD; i++) {
715 cbd_t *bdp = &ecp->txbd[i];
716 uchar *bp = &ecp->txbufs[i][0];
717
718 bdp->cbd_bufaddr = (uint)bp;
719 /* room for crc */
720 bdp->cbd_datlen = ELBT_BUFSZ - ELBT_CRCSZ;
721 bdp->cbd_sc = BD_ENET_TX_READY | BD_ENET_TX_PAD | \
722 BD_ENET_TX_LAST | BD_ENET_TX_TC;
723
Joe Hershbergera8ca4f62015-04-08 01:41:05 -0500724 memset((void *)bp, patbytes[i], ELBT_BUFSZ);
725 net_set_ether(bp, net_bcast_ethaddr, 0x8000);
wdenkb00ec162003-06-19 23:40:20 +0000726 }
727 ecp->txbd[ELBT_NTXBD - 1].cbd_sc |= BD_ENET_TX_WRAP;
728
729 /*
730 * set up rx buffers and bds
731 */
732
733 for (i = 0; i < ELBT_NRXBD; i++) {
734 cbd_t *bdp = &ecp->rxbd[i];
735 uchar *bp = &ecp->rxbufs[i][0];
736
737 bdp->cbd_bufaddr = (uint)bp;
738 bdp->cbd_datlen = 0;
739 bdp->cbd_sc = BD_ENET_RX_EMPTY;
740
741 memset ((void *)bp, 0, ELBT_BUFSZ);
742 }
743 ecp->rxbd[ELBT_NRXBD - 1].cbd_sc |= BD_ENET_RX_WRAP;
744
745 /*
746 * set up the FCC channel hardware
747 */
748
749 /* 28.9 - (4): GFMR: disable tx/rx, CCITT CRC, Mode Ethernet */
750 fcp->fcc_gfmr = FCC_GFMR_MODE_ENET | FCC_GFMR_TCRC_32;
751
752 /* 28.9 - (5): FPSMR: fd, enet CRC, Promis, RMON, Rx SHort */
753 fcp->fcc_fpsmr = FCC_PSMR_FDE | FCC_PSMR_LPB | \
754 FCC_PSMR_ENCRC | FCC_PSMR_PRO | \
755 FCC_PSMR_MON | FCC_PSMR_RSH;
756
757 /* 28.9 - (6): FDSR: Ethernet Syn */
758 fcp->fcc_fdsr = 0xD555;
759
760 /* 29.9 - (7): initialise parameter ram */
761 fpp = (fcc_enet_t *)&(immr->im_dprambase[ecp->proff]);
762
763 /* clear whole struct to make sure all resv fields are zero */
764 memset ((void *)fpp, 0, sizeof (fcc_enet_t));
765
766 /*
767 * common Parameter RAM area
768 *
769 * Allocate space in the reserved FCC area of DPRAM for the
770 * internal buffers. No one uses this space (yet), so we
771 * can do this. Later, we will add resource management for
772 * this area.
773 */
774 addr = CPM_FCC_SPECIAL_BASE + (c * 64);
775 fpp->fen_genfcc.fcc_riptr = addr;
776 fpp->fen_genfcc.fcc_tiptr = addr + 32;
777
778 /*
779 * Set maximum bytes per receive buffer.
780 * It must be a multiple of 32.
781 * buffers are in 60x bus memory.
782 */
783 fpp->fen_genfcc.fcc_mrblr = PKT_MAXBLR_SIZE;
784 fpp->fen_genfcc.fcc_rstate = (CPMFCR_GBL | CPMFCR_EB) << 24;
785 fpp->fen_genfcc.fcc_rbase = (unsigned int)(&ecp->rxbd[0]);
786 fpp->fen_genfcc.fcc_tstate = (CPMFCR_GBL | CPMFCR_EB) << 24;
787 fpp->fen_genfcc.fcc_tbase = (unsigned int)(&ecp->txbd[0]);
788
789 /* protocol-specific area */
790 fpp->fen_cmask = 0xdebb20e3; /* CRC mask */
791 fpp->fen_cpres = 0xffffffff; /* CRC preset */
792 fpp->fen_retlim = 15; /* Retry limit threshold */
793 fpp->fen_mflr = PKT_MAXBUF_SIZE;/* max frame length register */
794
795 /*
796 * Set Ethernet station address.
797 *
798 * This is supplied in the board information structure, so we
799 * copy that into the controller.
800 * So, far we have only been given one Ethernet address. We use
801 * the same address for all channels
802 */
Joe Hershberger8ecdbed2015-04-08 01:41:04 -0500803 fpp->fen_paddrh = (net_ethaddr[5] << 8) + net_ethaddr[4];
804 fpp->fen_paddrm = (net_ethaddr[3] << 8) + net_ethaddr[2];
805 fpp->fen_paddrl = (net_ethaddr[1] << 8) + net_ethaddr[0];
wdenkb00ec162003-06-19 23:40:20 +0000806
807 fpp->fen_minflr = PKT_MINBUF_SIZE; /* min frame len register */
808 /*
809 * pad pointer. use tiptr since we don't need
810 * a specific padding char
811 */
812 fpp->fen_padptr = fpp->fen_genfcc.fcc_tiptr;
813 fpp->fen_maxd1 = PKT_MAXDMA_SIZE; /* max DMA1 length */
814 fpp->fen_maxd2 = PKT_MAXDMA_SIZE; /* max DMA2 length */
815 fpp->fen_rfthr = 1;
816 fpp->fen_rfcnt = 1;
817
818 /* 28.9 - (8): clear out events in FCCE */
819 fcp->fcc_fcce = ~0x0;
820
821 /* 28.9 - (9): FCCM: mask all events */
822 fcp->fcc_fccm = 0;
823
824 /* 28.9 - (10-12): we don't use ethernet interrupts */
825
826 /* 28.9 - (13)
827 *
828 * Let's re-initialize the channel now. We have to do it later
829 * than the manual describes because we have just now finished
830 * the BD initialization.
831 */
832 cp->cp_cpcr = mk_cr_cmd (ecp->page, ecp->sblock, \
833 0x0c, CPM_CR_INIT_TRX) | CPM_CR_FLG;
834 do {
835 __asm__ __volatile__ ("eieio");
836 } while (cp->cp_cpcr & CPM_CR_FLG);
837 }
838
839 puts (" done\nStarting test... (Ctrl-C to Finish)\n");
840
841 /*
842 * Note: don't want serial output from here until the end of the
843 * test - the delays would probably stuff things up.
844 */
845
846 clear_ctrlc ();
847 runtime = get_timer (0);
848
849 do {
850 nclosed = 0;
851
wdenk5256def2003-09-18 10:45:21 +0000852 for (c = FCC_START_LOOP; c <= FCC_END_LOOP; c++) {
wdenkb00ec162003-06-19 23:40:20 +0000853 volatile fcc_t *fcp = &immr->im_fcc[c];
854 elbt_chan *ecp = &elbt_chans[c];
855 int i;
856
857 switch (ecp->state) {
858
859 case Idle:
860 /*
861 * set the channel Running ...
862 */
863
864 /* 28.9 - (14): enable tx/rx in gfmr */
865 fcp->fcc_gfmr |= FCC_GFMR_ENT | FCC_GFMR_ENR;
866
867 ecp->state = Running;
868 break;
869
870 case Running:
871 /*
872 * (while Running only) check for
873 * termination of the test
874 */
875
876 (void)ctrlc ();
877
878 if (had_ctrlc ()) {
879 /*
880 * initiate a "graceful stop transmit"
881 * on the channel
882 */
883 cp->cp_cpcr = mk_cr_cmd (ecp->page, \
884 ecp->sblock, 0x0c, \
885 CPM_CR_GRACEFUL_STOP_TX) | \
886 CPM_CR_FLG;
887 do {
888 __asm__ __volatile__ ("eieio");
889 } while (cp->cp_cpcr & CPM_CR_FLG);
890
891 ecp->clstime = get_timer (0);
892 ecp->state = Closing;
893 }
894 /* fall through ... */
895
896 case Closing:
897 /*
898 * (while Running or Closing) poll the channel:
899 * - check for any non-READY tx buffers and
900 * make them ready
901 * - check for any non-EMPTY rx buffers and
902 * check that they were received correctly,
903 * adjust counters etc, then make empty
904 */
905
906 for (i = 0; i < ELBT_NTXBD; i++) {
907 cbd_t *bdp = &ecp->txbd[i];
908 ushort sc = bdp->cbd_sc;
909
910 if ((sc & BD_ENET_TX_READY) != 0)
911 continue;
912
913 /*
914 * this frame has finished
915 * transmitting
916 */
917 ecp->nsent++;
918
919 if (sc & BD_ENET_TX_STATS) {
920 ulong n;
921
922 /*
923 * we had an error on
924 * the transmission
925 */
926 n = ecp->ntxerr++;
927 if (n < ELBT_MAXTXERR)
928 ecp->txerrs[n] = sc;
929
930 if (sc & BD_ENET_TX_DEF)
931 ecp->txeacc.def++;
932 if (sc & BD_ENET_TX_HB)
933 ecp->txeacc.hb++;
934 if (sc & BD_ENET_TX_LC)
935 ecp->txeacc.lc++;
936 if (sc & BD_ENET_TX_RL)
937 ecp->txeacc.rl++;
938 if (sc & BD_ENET_TX_RCMASK)
939 ecp->txeacc.rc++;
940 if (sc & BD_ENET_TX_UN)
941 ecp->txeacc.un++;
942 if (sc & BD_ENET_TX_CSL)
943 ecp->txeacc.csl++;
944
945 bdp->cbd_sc &= \
946 ~BD_ENET_TX_STATS;
947 }
948
949 if (ecp->state == Closing)
950 ecp->clstime = get_timer (0);
951
952 /* make it ready again */
953 bdp->cbd_sc |= BD_ENET_TX_READY;
954 }
955
956 for (i = 0; i < ELBT_NRXBD; i++) {
957 cbd_t *bdp = &ecp->rxbd[i];
958 ushort sc = bdp->cbd_sc, mask;
959
960 if ((sc & BD_ENET_RX_EMPTY) != 0)
961 continue;
962
963 /* we have a new frame in this buffer */
964 ecp->nrcvd++;
965
966 mask = BD_ENET_RX_LAST|BD_ENET_RX_FIRST;
967 if ((sc & mask) != mask) {
968 /* somethings wrong here ... */
969 if (!(sc & BD_ENET_RX_LAST))
970 ecp->rxeacc._l++;
971 if (!(sc & BD_ENET_RX_FIRST))
972 ecp->rxeacc._f++;
973 }
974
Wolfgang Denk116edc92005-08-03 23:03:54 +0200975 if (sc & BD_ENET_RX_ERRS) {
wdenkb00ec162003-06-19 23:40:20 +0000976 ulong n;
977
978 /*
979 * we had some sort of error
980 * on the frame
981 */
982 n = ecp->nrxerr++;
983 if (n < ELBT_MAXRXERR)
984 ecp->rxerrs[n] = sc;
985
986 if (sc & BD_ENET_RX_MISS)
987 ecp->rxeacc.m++;
988 if (sc & BD_ENET_RX_BC)
989 ecp->rxeacc.bc++;
990 if (sc & BD_ENET_RX_MC)
991 ecp->rxeacc.mc++;
992 if (sc & BD_ENET_RX_LG)
993 ecp->rxeacc.lg++;
994 if (sc & BD_ENET_RX_NO)
995 ecp->rxeacc.no++;
996 if (sc & BD_ENET_RX_SH)
997 ecp->rxeacc.sh++;
998 if (sc & BD_ENET_RX_CR)
999 ecp->rxeacc.cr++;
1000 if (sc & BD_ENET_RX_OV)
1001 ecp->rxeacc.ov++;
1002 if (sc & BD_ENET_RX_CL)
1003 ecp->rxeacc.cl++;
1004
1005 bdp->cbd_sc &= \
Wolfgang Denk116edc92005-08-03 23:03:54 +02001006 ~BD_ENET_RX_ERRS;
wdenkb00ec162003-06-19 23:40:20 +00001007 }
1008 else {
1009 ushort datlen = bdp->cbd_datlen;
Joe Hershberger1178f412012-05-23 07:58:06 +00001010 struct ethernet_hdr *ehp;
wdenkb00ec162003-06-19 23:40:20 +00001011 ushort prot;
1012 int ours, tb, n, nbytes;
1013
Joe Hershberger1178f412012-05-23 07:58:06 +00001014 ehp = (struct ethernet_hdr *) \
wdenkb00ec162003-06-19 23:40:20 +00001015 &ecp->rxbufs[i][0];
1016
1017 ours = memcmp (ehp->et_src, \
Joe Hershberger8ecdbed2015-04-08 01:41:04 -05001018 net_ethaddr, 6);
wdenkb00ec162003-06-19 23:40:20 +00001019
1020 prot = swap16 (ehp->et_protlen);
1021 tb = prot & 0x8000;
1022 n = prot & 0x7fff;
1023
Joe Hershberger1178f412012-05-23 07:58:06 +00001024 nbytes = ELBT_BUFSZ -
1025 ETHER_HDR_SIZE -
wdenkb00ec162003-06-19 23:40:20 +00001026 ELBT_CRCSZ;
1027
1028 /* check the frame is correct */
1029 if (datlen != ELBT_BUFSZ)
1030 ecp->rxeacc.badlen++;
1031 else if (!ours)
1032 ecp->rxeacc.badsrc++;
1033 else if (!tb || n >= ELBT_NTXBD)
1034 ecp->rxeacc.badtyp++;
1035 else {
1036 ulong patword = \
1037 patwords[n];
1038 uint nbb;
1039
Joe Hershberger1178f412012-05-23 07:58:06 +00001040 nbb = badbits(
1041 ((uchar *)&ehp) +
1042 ETHER_HDR_SIZE,
1043 nbytes, patword);
wdenkb00ec162003-06-19 23:40:20 +00001044
1045 ecp->rxeacc.badbit += \
1046 nbb;
1047 }
1048 }
1049
1050 if (ecp->state == Closing)
1051 ecp->clstime = get_timer (0);
1052
1053 /* make it empty again */
1054 bdp->cbd_sc |= BD_ENET_RX_EMPTY;
1055 }
1056
1057 if (ecp->state != Closing)
1058 break;
1059
1060 /*
1061 * (while Closing) check to see if
1062 * waited long enough
1063 */
1064
1065 if (get_timer (ecp->clstime) >= ELBT_CLSWAIT) {
1066 /* write GFMR: disable tx/rx */
1067 fcp->fcc_gfmr &= \
1068 ~(FCC_GFMR_ENT | FCC_GFMR_ENR);
1069 ecp->state = Closed;
1070 }
1071
1072 break;
1073
1074 case Closed:
1075 nclosed++;
1076 break;
1077 }
1078 }
1079
wdenk5256def2003-09-18 10:45:21 +00001080 } while (nclosed < (FCC_END_LOOP - FCC_START_LOOP + 1));
wdenkb00ec162003-06-19 23:40:20 +00001081
1082 runtime = get_timer (runtime);
1083 if (runtime <= ELBT_CLSWAIT) {
1084 printf ("Whoops! somehow elapsed time (%ld) is wrong (<= %d)\n",
1085 runtime, ELBT_CLSWAIT);
1086 return;
1087 }
1088 nmsec = runtime - ELBT_CLSWAIT;
1089
1090 printf ("Test Finished in %ldms (plus %dms close wait period)!\n\n",
1091 nmsec, ELBT_CLSWAIT);
1092
1093 /*
1094 * now print stats
1095 */
1096
wdenk5256def2003-09-18 10:45:21 +00001097 for (c = FCC_START_LOOP; c <= FCC_END_LOOP; c++) {
wdenkb00ec162003-06-19 23:40:20 +00001098 elbt_chan *ecp = &elbt_chans[c];
1099 uint rxpps, txpps, nerr;
1100
1101 rxpps = (ecp->nrcvd * 1000) / nmsec;
1102 txpps = (ecp->nsent * 1000) / nmsec;
1103
1104 printf ("Channel %d: %d rcvd (%d pps, %d rxerrs), "
1105 "%d sent (%d pps, %d txerrs)\n\n", c,
1106 ecp->nrcvd, rxpps, ecp->nrxerr,
1107 ecp->nsent, txpps, ecp->ntxerr);
1108
1109 if ((nerr = ecp->nrxerr) > 0) {
1110 ulong i;
1111
1112 printf ("\tFirst %d rx errs:", nerr);
1113 for (i = 0; i < nerr; i++)
1114 printf (" %04x", ecp->rxerrs[i]);
wdenk42c05472004-03-23 22:14:11 +00001115 putc ('\n');
wdenkb00ec162003-06-19 23:40:20 +00001116 }
1117
1118 if ((nerr = ecp->ntxerr) > 0) {
1119 ulong i;
1120
1121 printf ("\tFirst %d tx errs:", nerr);
1122 for (i = 0; i < nerr; i++)
1123 printf (" %04x", ecp->txerrs[i]);
wdenk42c05472004-03-23 22:14:11 +00001124 putc ('\n');
wdenkb00ec162003-06-19 23:40:20 +00001125 }
1126 }
1127
1128 puts ("Receive Error Counts:\n");
wdenk5256def2003-09-18 10:45:21 +00001129 for (c = FCC_START_LOOP; c <= FCC_END_LOOP; c++)
wdenkb00ec162003-06-19 23:40:20 +00001130 bases[c] = (uchar *)&elbt_chans[c].rxeacc;
1131 print_desc (rxeacc_descs, rxeacc_ndesc, bases, 3);
1132
1133 puts ("\nTransmit Error Counts:\n");
wdenk5256def2003-09-18 10:45:21 +00001134 for (c = FCC_START_LOOP; c <= FCC_END_LOOP; c++)
wdenkb00ec162003-06-19 23:40:20 +00001135 bases[c] = (uchar *)&elbt_chans[c].txeacc;
1136 print_desc (txeacc_descs, txeacc_ndesc, bases, 3);
1137
1138 puts ("\nRMON(-like) Counters:\n");
wdenk5256def2003-09-18 10:45:21 +00001139 for (c = FCC_START_LOOP; c <= FCC_END_LOOP; c++)
wdenkb00ec162003-06-19 23:40:20 +00001140 bases[c] = (uchar *)&immr->im_dprambase[elbt_chans[c].proff];
1141 print_desc (epram_descs, epram_ndesc, bases, 3);
1142}
1143
1144#endif /* CONFIG_ETHER_LOOPBACK_TEST */
1145
Jon Loeliger07efe2a2007-07-10 10:27:39 -05001146#endif