blob: 660620e8f6282f7d04f4f6ac649ad61aa8d6a25d [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25
26/*
27 * Ethernet test
28 *
29 * The Serial Communication Controllers (SCC) listed in ctlr_list array below
30 * are tested in the loopback ethernet mode.
31 * The controllers are configured accordingly and several packets
32 * are transmitted. The configurable test parameters are:
33 * MIN_PACKET_LENGTH - minimum size of packet to transmit
34 * MAX_PACKET_LENGTH - maximum size of packet to transmit
35 * TEST_NUM - number of tests
36 */
37
38#ifdef CONFIG_POST
39
40#include <post.h>
wdenk2c9b05d2003-09-10 22:30:53 +000041#if CONFIG_POST & CFG_POST_ETHER
wdenkc6097192002-11-03 00:24:07 +000042#if defined(CONFIG_8xx)
43#include <commproc.h>
44#elif defined(CONFIG_MPC8260)
45#include <asm/cpm_8260.h>
46#else
47#error "Apparently a bad configuration, please fix."
48#endif
49
50#include <command.h>
51#include <net.h>
wdenk7ac16102004-08-01 22:48:16 +000052#include <serial.h>
wdenkc6097192002-11-03 00:24:07 +000053
wdenkc6097192002-11-03 00:24:07 +000054#define MIN_PACKET_LENGTH 64
55#define MAX_PACKET_LENGTH 256
56#define TEST_NUM 1
57
58#define CTLR_SCC 0
59
60extern void spi_init_f (void);
61extern void spi_init_r (void);
62
63/* The list of controllers to test */
64#if defined(CONFIG_MPC823)
65static int ctlr_list[][2] = { {CTLR_SCC, 1} };
66#else
67static int ctlr_list[][2] = { };
68#endif
69
70#define CTRL_LIST_SIZE (sizeof(ctlr_list) / sizeof(ctlr_list[0]))
71
72static struct {
73 void (*init) (int index);
wdenkda55c6e2004-01-20 23:12:12 +000074 void (*halt) (int index);
wdenkc6097192002-11-03 00:24:07 +000075 int (*send) (int index, volatile void *packet, int length);
76 int (*recv) (int index, void *packet, int length);
77} ctlr_proc[1];
78
79static char *ctlr_name[1] = { "SCC" };
80
wdenkc6097192002-11-03 00:24:07 +000081/* Ethernet Transmit and Receive Buffers */
82#define DBUF_LENGTH 1520
83
84#define TX_BUF_CNT 2
85
86#define TOUT_LOOP 100
87
88static char txbuf[DBUF_LENGTH];
89
90static uint rxIdx; /* index of the current RX buffer */
91static uint txIdx; /* index of the current TX buffer */
92
93/*
94 * SCC Ethernet Tx and Rx buffer descriptors allocated at the
95 * immr->udata_bd address on Dual-Port RAM
96 * Provide for Double Buffering
97 */
98
99typedef volatile struct CommonBufferDescriptor {
100 cbd_t rxbd[PKTBUFSRX]; /* Rx BD */
101 cbd_t txbd[TX_BUF_CNT]; /* Tx BD */
102} RTXBD;
103
104static RTXBD *rtx;
105
106 /*
107 * SCC callbacks
108 */
109
110static void scc_init (int scc_index)
111{
112 DECLARE_GLOBAL_DATA_PTR;
113 bd_t *bd = gd->bd;
114
115 static int proff[] =
116 { PROFF_SCC1, PROFF_SCC2, PROFF_SCC3, PROFF_SCC4 };
117 static unsigned int cpm_cr[] =
118 { CPM_CR_CH_SCC1, CPM_CR_CH_SCC2, CPM_CR_CH_SCC3,
119CPM_CR_CH_SCC4 };
120
121 int i;
122 scc_enet_t *pram_ptr;
123
124 volatile immap_t *immr = (immap_t *) CFG_IMMR;
125
126 immr->im_cpm.cp_scc[scc_index].scc_gsmrl &=
127 ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
128
129#if defined(CONFIG_FADS)
wdenk2bb11052003-07-17 23:16:40 +0000130#if defined(CONFIG_MPC860T) || defined(CONFIG_MPC86xADS)
131 /* The FADS860T and MPC86xADS don't use the MODEM_EN or DATA_VOICE signals. */
wdenkc6097192002-11-03 00:24:07 +0000132 *((uint *) BCSR4) &= ~BCSR4_ETHLOOP;
133 *((uint *) BCSR4) |= BCSR4_TFPLDL | BCSR4_TPSQEL;
134 *((uint *) BCSR1) &= ~BCSR1_ETHEN;
135#else
136 *((uint *) BCSR4) &= ~(BCSR4_ETHLOOP | BCSR4_MODEM_EN);
137 *((uint *) BCSR4) |= BCSR4_TFPLDL | BCSR4_TPSQEL | BCSR4_DATA_VOICE;
138 *((uint *) BCSR1) &= ~BCSR1_ETHEN;
139#endif
140#endif
141
142 pram_ptr = (scc_enet_t *) & (immr->im_cpm.cp_dparam[proff[scc_index]]);
143
144 rxIdx = 0;
145 txIdx = 0;
146
147#ifdef CFG_ALLOC_DPRAM
148 rtx = (RTXBD *) (immr->im_cpm.cp_dpmem +
149 dpram_alloc_align (sizeof (RTXBD), 8));
150#else
151 rtx = (RTXBD *) (immr->im_cpm.cp_dpmem + CPM_SCC_BASE);
152#endif
153
154#if 0
155
156#if (defined(PA_ENET_RXD) && defined(PA_ENET_TXD))
157 /* Configure port A pins for Txd and Rxd.
158 */
159 immr->im_ioport.iop_papar |= (PA_ENET_RXD | PA_ENET_TXD);
160 immr->im_ioport.iop_padir &= ~(PA_ENET_RXD | PA_ENET_TXD);
161 immr->im_ioport.iop_paodr &= ~PA_ENET_TXD;
162#elif (defined(PB_ENET_RXD) && defined(PB_ENET_TXD))
163 /* Configure port B pins for Txd and Rxd.
164 */
165 immr->im_cpm.cp_pbpar |= (PB_ENET_RXD | PB_ENET_TXD);
166 immr->im_cpm.cp_pbdir &= ~(PB_ENET_RXD | PB_ENET_TXD);
167 immr->im_cpm.cp_pbodr &= ~PB_ENET_TXD;
168#else
169#error Configuration Error: exactly ONE of PA_ENET_[RT]XD, PB_ENET_[RT]XD must be defined
170#endif
171
172#if defined(PC_ENET_LBK)
173 /* Configure port C pins to disable External Loopback
174 */
175 immr->im_ioport.iop_pcpar &= ~PC_ENET_LBK;
176 immr->im_ioport.iop_pcdir |= PC_ENET_LBK;
177 immr->im_ioport.iop_pcso &= ~PC_ENET_LBK;
178 immr->im_ioport.iop_pcdat &= ~PC_ENET_LBK; /* Disable Loopback */
179#endif /* PC_ENET_LBK */
180
181 /* Configure port C pins to enable CLSN and RENA.
182 */
183 immr->im_ioport.iop_pcpar &= ~(PC_ENET_CLSN | PC_ENET_RENA);
184 immr->im_ioport.iop_pcdir &= ~(PC_ENET_CLSN | PC_ENET_RENA);
185 immr->im_ioport.iop_pcso |= (PC_ENET_CLSN | PC_ENET_RENA);
186
187 /* Configure port A for TCLK and RCLK.
188 */
189 immr->im_ioport.iop_papar |= (PA_ENET_TCLK | PA_ENET_RCLK);
190 immr->im_ioport.iop_padir &= ~(PA_ENET_TCLK | PA_ENET_RCLK);
191
192 /*
193 * Configure Serial Interface clock routing -- see section 16.7.5.3
194 * First, clear all SCC bits to zero, then set the ones we want.
195 */
196
197 immr->im_cpm.cp_sicr &= ~SICR_ENET_MASK;
198 immr->im_cpm.cp_sicr |= SICR_ENET_CLKRT;
199#else
200 /*
201 * SCC2 receive clock is BRG2
202 * SCC2 transmit clock is BRG3
203 */
204 immr->im_cpm.cp_brgc2 = 0x0001000C;
205 immr->im_cpm.cp_brgc3 = 0x0001000C;
206
207 immr->im_cpm.cp_sicr &= ~0x00003F00;
208 immr->im_cpm.cp_sicr |= 0x00000a00;
209#endif /* 0 */
210
211
212 /*
213 * Initialize SDCR -- see section 16.9.23.7
214 * SDMA configuration register
215 */
216 immr->im_siu_conf.sc_sdcr = 0x01;
217
218
219 /*
220 * Setup SCC Ethernet Parameter RAM
221 */
222
223 pram_ptr->sen_genscc.scc_rfcr = 0x18; /* Normal Operation and Mot byte ordering */
224 pram_ptr->sen_genscc.scc_tfcr = 0x18; /* Mot byte ordering, Normal access */
225
226 pram_ptr->sen_genscc.scc_mrblr = DBUF_LENGTH; /* max. ET package len 1520 */
227
228 pram_ptr->sen_genscc.scc_rbase = (unsigned int) (&rtx->rxbd[0]); /* Set RXBD tbl start at Dual Port */
229 pram_ptr->sen_genscc.scc_tbase = (unsigned int) (&rtx->txbd[0]); /* Set TXBD tbl start at Dual Port */
230
231 /*
232 * Setup Receiver Buffer Descriptors (13.14.24.18)
233 * Settings:
234 * Empty, Wrap
235 */
236
237 for (i = 0; i < PKTBUFSRX; i++) {
238 rtx->rxbd[i].cbd_sc = BD_ENET_RX_EMPTY;
239 rtx->rxbd[i].cbd_datlen = 0; /* Reset */
240 rtx->rxbd[i].cbd_bufaddr = (uint) NetRxPackets[i];
241 }
242
243 rtx->rxbd[PKTBUFSRX - 1].cbd_sc |= BD_ENET_RX_WRAP;
244
245 /*
246 * Setup Ethernet Transmitter Buffer Descriptors (13.14.24.19)
247 * Settings:
248 * Add PADs to Short FRAMES, Wrap, Last, Tx CRC
249 */
250
251 for (i = 0; i < TX_BUF_CNT; i++) {
252 rtx->txbd[i].cbd_sc =
253 (BD_ENET_TX_PAD | BD_ENET_TX_LAST | BD_ENET_TX_TC);
254 rtx->txbd[i].cbd_datlen = 0; /* Reset */
255 rtx->txbd[i].cbd_bufaddr = (uint) (&txbuf[0]);
256 }
257
258 rtx->txbd[TX_BUF_CNT - 1].cbd_sc |= BD_ENET_TX_WRAP;
259
260 /*
261 * Enter Command: Initialize Rx Params for SCC
262 */
263
264 do { /* Spin until ready to issue command */
265 __asm__ ("eieio");
266 } while (immr->im_cpm.cp_cpcr & CPM_CR_FLG);
267 /* Issue command */
268 immr->im_cpm.cp_cpcr =
269 ((CPM_CR_INIT_RX << 8) | (cpm_cr[scc_index] << 4) |
270 CPM_CR_FLG);
271 do { /* Spin until command processed */
272 __asm__ ("eieio");
273 } while (immr->im_cpm.cp_cpcr & CPM_CR_FLG);
274
275 /*
276 * Ethernet Specific Parameter RAM
277 * see table 13-16, pg. 660,
278 * pg. 681 (example with suggested settings)
279 */
280
281 pram_ptr->sen_cpres = ~(0x0); /* Preset CRC */
282 pram_ptr->sen_cmask = 0xdebb20e3; /* Constant Mask for CRC */
283 pram_ptr->sen_crcec = 0x0; /* Error Counter CRC (unused) */
284 pram_ptr->sen_alec = 0x0; /* Alignment Error Counter (unused) */
285 pram_ptr->sen_disfc = 0x0; /* Discard Frame Counter (unused) */
286 pram_ptr->sen_pads = 0x8888; /* Short Frame PAD Characters */
287
288 pram_ptr->sen_retlim = 15; /* Retry Limit Threshold */
289 pram_ptr->sen_maxflr = 1518; /* MAX Frame Length Register */
290 pram_ptr->sen_minflr = 64; /* MIN Frame Length Register */
291
292 pram_ptr->sen_maxd1 = DBUF_LENGTH; /* MAX DMA1 Length Register */
293 pram_ptr->sen_maxd2 = DBUF_LENGTH; /* MAX DMA2 Length Register */
294
295 pram_ptr->sen_gaddr1 = 0x0; /* Group Address Filter 1 (unused) */
296 pram_ptr->sen_gaddr2 = 0x0; /* Group Address Filter 2 (unused) */
297 pram_ptr->sen_gaddr3 = 0x0; /* Group Address Filter 3 (unused) */
298 pram_ptr->sen_gaddr4 = 0x0; /* Group Address Filter 4 (unused) */
299
300#define ea bd->bi_enetaddr
301 pram_ptr->sen_paddrh = (ea[5] << 8) + ea[4];
302 pram_ptr->sen_paddrm = (ea[3] << 8) + ea[2];
303 pram_ptr->sen_paddrl = (ea[1] << 8) + ea[0];
304#undef ea
305
306 pram_ptr->sen_pper = 0x0; /* Persistence (unused) */
307 pram_ptr->sen_iaddr1 = 0x0; /* Individual Address Filter 1 (unused) */
308 pram_ptr->sen_iaddr2 = 0x0; /* Individual Address Filter 2 (unused) */
309 pram_ptr->sen_iaddr3 = 0x0; /* Individual Address Filter 3 (unused) */
310 pram_ptr->sen_iaddr4 = 0x0; /* Individual Address Filter 4 (unused) */
311 pram_ptr->sen_taddrh = 0x0; /* Tmp Address (MSB) (unused) */
312 pram_ptr->sen_taddrm = 0x0; /* Tmp Address (unused) */
313 pram_ptr->sen_taddrl = 0x0; /* Tmp Address (LSB) (unused) */
314
315 /*
316 * Enter Command: Initialize Tx Params for SCC
317 */
318
319 do { /* Spin until ready to issue command */
320 __asm__ ("eieio");
321 } while (immr->im_cpm.cp_cpcr & CPM_CR_FLG);
322 /* Issue command */
323 immr->im_cpm.cp_cpcr =
324 ((CPM_CR_INIT_TX << 8) | (cpm_cr[scc_index] << 4) |
325 CPM_CR_FLG);
326 do { /* Spin until command processed */
327 __asm__ ("eieio");
328 } while (immr->im_cpm.cp_cpcr & CPM_CR_FLG);
329
330 /*
331 * Mask all Events in SCCM - we use polling mode
332 */
333 immr->im_cpm.cp_scc[scc_index].scc_sccm = 0;
334
335 /*
336 * Clear Events in SCCE -- Clear bits by writing 1's
337 */
338
339 immr->im_cpm.cp_scc[scc_index].scc_scce = ~(0x0);
340
341
342 /*
343 * Initialize GSMR High 32-Bits
344 * Settings: Normal Mode
345 */
346
347 immr->im_cpm.cp_scc[scc_index].scc_gsmrh = 0;
348
349 /*
350 * Initialize GSMR Low 32-Bits, but do not Enable Transmit/Receive
351 * Settings:
352 * TCI = Invert
353 * TPL = 48 bits
354 * TPP = Repeating 10's
355 * LOOP = Loopback
356 * MODE = Ethernet
357 */
358
359 immr->im_cpm.cp_scc[scc_index].scc_gsmrl = (SCC_GSMRL_TCI |
wdenk4dd56e52004-02-20 22:02:48 +0000360 SCC_GSMRL_TPL_48 |
361 SCC_GSMRL_TPP_10 |
362 SCC_GSMRL_DIAG_LOOP |
363 SCC_GSMRL_MODE_ENET);
wdenkc6097192002-11-03 00:24:07 +0000364
365 /*
366 * Initialize the DSR -- see section 13.14.4 (pg. 513) v0.4
367 */
368
369 immr->im_cpm.cp_scc[scc_index].scc_dsr = 0xd555;
370
371 /*
372 * Initialize the PSMR
373 * Settings:
374 * CRC = 32-Bit CCITT
375 * NIB = Begin searching for SFD 22 bits after RENA
376 * LPB = Loopback Enable (Needed when FDE is set)
377 */
378 immr->im_cpm.cp_scc[scc_index].scc_psmr = SCC_PSMR_ENCRC |
379 SCC_PSMR_NIB22 | SCC_PSMR_LPB;
380
381#if 0
382 /*
383 * Configure Ethernet TENA Signal
384 */
385
386#if (defined(PC_ENET_TENA) && !defined(PB_ENET_TENA))
387 immr->im_ioport.iop_pcpar |= PC_ENET_TENA;
388 immr->im_ioport.iop_pcdir &= ~PC_ENET_TENA;
389#elif (defined(PB_ENET_TENA) && !defined(PC_ENET_TENA))
390 immr->im_cpm.cp_pbpar |= PB_ENET_TENA;
391 immr->im_cpm.cp_pbdir |= PB_ENET_TENA;
392#else
393#error Configuration Error: exactly ONE of PB_ENET_TENA, PC_ENET_TENA must be defined
394#endif
395
396#if defined(CONFIG_ADS) && defined(CONFIG_MPC860)
397 /*
398 * Port C is used to control the PHY,MC68160.
399 */
400 immr->im_ioport.iop_pcdir |=
401 (PC_ENET_ETHLOOP | PC_ENET_TPFLDL | PC_ENET_TPSQEL);
402
403 immr->im_ioport.iop_pcdat |= PC_ENET_TPFLDL;
404 immr->im_ioport.iop_pcdat &= ~(PC_ENET_ETHLOOP | PC_ENET_TPSQEL);
405 *((uint *) BCSR1) &= ~BCSR1_ETHEN;
406#endif /* MPC860ADS */
407
408#if defined(CONFIG_AMX860)
409 /*
410 * Port B is used to control the PHY,MC68160.
411 */
412 immr->im_cpm.cp_pbdir |=
413 (PB_ENET_ETHLOOP | PB_ENET_TPFLDL | PB_ENET_TPSQEL);
414
415 immr->im_cpm.cp_pbdat |= PB_ENET_TPFLDL;
416 immr->im_cpm.cp_pbdat &= ~(PB_ENET_ETHLOOP | PB_ENET_TPSQEL);
417
418 immr->im_ioport.iop_pddir |= PD_ENET_ETH_EN;
419 immr->im_ioport.iop_pddat &= ~PD_ENET_ETH_EN;
420#endif /* AMX860 */
421
422#endif /* 0 */
423
424#ifdef CONFIG_RPXCLASSIC
425 *((uchar *) BCSR0) &= ~BCSR0_ETHLPBK;
426 *((uchar *) BCSR0) |= (BCSR0_ETHEN | BCSR0_COLTEST | BCSR0_FULLDPLX);
427#endif
428
429#ifdef CONFIG_RPXLITE
430 *((uchar *) BCSR0) |= BCSR0_ETHEN;
431#endif
432
433#ifdef CONFIG_MBX
434 board_ether_init ();
435#endif
436
437 /*
438 * Set the ENT/ENR bits in the GSMR Low -- Enable Transmit/Receive
439 */
440
441 immr->im_cpm.cp_scc[scc_index].scc_gsmrl |=
442 (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
443
444 /*
445 * Work around transmit problem with first eth packet
446 */
447#if defined (CONFIG_FADS)
448 udelay (10000); /* wait 10 ms */
449#elif defined (CONFIG_AMX860) || defined(CONFIG_RPXCLASSIC)
450 udelay (100000); /* wait 100 ms */
451#endif
452}
453
wdenkda55c6e2004-01-20 23:12:12 +0000454static void scc_halt (int scc_index)
455{
456 volatile immap_t *immr = (immap_t *) CFG_IMMR;
457
458 immr->im_cpm.cp_scc[scc_index].scc_gsmrl &=
459 ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
wdenk7ac16102004-08-01 22:48:16 +0000460 immr->im_ioport.iop_pcso &= ~(PC_ENET_CLSN | PC_ENET_RENA);
wdenkda55c6e2004-01-20 23:12:12 +0000461}
462
wdenkc6097192002-11-03 00:24:07 +0000463static int scc_send (int index, volatile void *packet, int length)
464{
465 int i, j = 0;
466
467 while ((rtx->txbd[txIdx].cbd_sc & BD_ENET_TX_READY) && (j < TOUT_LOOP)) {
468 udelay (1); /* will also trigger Wd if needed */
469 j++;
470 }
471 if (j >= TOUT_LOOP)
472 printf ("TX not ready\n");
473 rtx->txbd[txIdx].cbd_bufaddr = (uint) packet;
474 rtx->txbd[txIdx].cbd_datlen = length;
475 rtx->txbd[txIdx].cbd_sc |=
476 (BD_ENET_TX_READY | BD_ENET_TX_LAST | BD_ENET_TX_WRAP);
477 while ((rtx->txbd[txIdx].cbd_sc & BD_ENET_TX_READY) && (j < TOUT_LOOP)) {
478 udelay (1); /* will also trigger Wd if needed */
479 j++;
480 }
481 if (j >= TOUT_LOOP)
482 printf ("TX timeout\n");
483 i = (rtx->txbd[txIdx].
484 cbd_sc & BD_ENET_TX_STATS) /* return only status bits */ ;
485 return i;
486}
487
488static int scc_recv (int index, void *packet, int max_length)
489{
490 int length = -1;
491
492 if (rtx->rxbd[rxIdx].cbd_sc & BD_ENET_RX_EMPTY) {
493 goto Done; /* nothing received */
494 }
495
496 if (!(rtx->rxbd[rxIdx].cbd_sc & 0x003f)) {
497 length = rtx->rxbd[rxIdx].cbd_datlen - 4;
498 memcpy (packet,
499 (void *) (NetRxPackets[rxIdx]),
500 length < max_length ? length : max_length);
501 }
502
503 /* Give the buffer back to the SCC. */
504 rtx->rxbd[rxIdx].cbd_datlen = 0;
505
506 /* wrap around buffer index when necessary */
507 if ((rxIdx + 1) >= PKTBUFSRX) {
508 rtx->rxbd[PKTBUFSRX - 1].cbd_sc =
509 (BD_ENET_RX_WRAP | BD_ENET_RX_EMPTY);
510 rxIdx = 0;
511 } else {
512 rtx->rxbd[rxIdx].cbd_sc = BD_ENET_RX_EMPTY;
513 rxIdx++;
514 }
515
wdenk7ac16102004-08-01 22:48:16 +0000516Done:
wdenkc6097192002-11-03 00:24:07 +0000517 return length;
518}
519
520 /*
521 * Test routines
522 */
523
524static void packet_fill (char *packet, int length)
525{
526 char c = (char) length;
527 int i;
528
529 packet[0] = 0xFF;
530 packet[1] = 0xFF;
531 packet[2] = 0xFF;
532 packet[3] = 0xFF;
533 packet[4] = 0xFF;
534 packet[5] = 0xFF;
535
536 for (i = 6; i < length; i++) {
537 packet[i] = c++;
538 }
539}
540
541static int packet_check (char *packet, int length)
542{
543 char c = (char) length;
544 int i;
545
546 for (i = 6; i < length; i++) {
547 if (packet[i] != c++)
548 return -1;
549 }
550
551 return 0;
552}
553
554static int test_ctlr (int ctlr, int index)
555{
556 int res = -1;
557 char packet_send[MAX_PACKET_LENGTH];
558 char packet_recv[MAX_PACKET_LENGTH];
559 int length;
560 int i;
561 int l;
562
563 ctlr_proc[ctlr].init (index);
564
565 for (i = 0; i < TEST_NUM; i++) {
566 for (l = MIN_PACKET_LENGTH; l <= MAX_PACKET_LENGTH; l++) {
567 packet_fill (packet_send, l);
568
569 ctlr_proc[ctlr].send (index, packet_send, l);
570
571 length = ctlr_proc[ctlr].recv (index, packet_recv,
572 MAX_PACKET_LENGTH);
573
574 if (length != l || packet_check (packet_recv, length) < 0) {
575 goto Done;
576 }
577 }
578 }
579
580 res = 0;
581
wdenk7ac16102004-08-01 22:48:16 +0000582Done:
wdenkc6097192002-11-03 00:24:07 +0000583
wdenkda55c6e2004-01-20 23:12:12 +0000584 ctlr_proc[ctlr].halt (index);
585
wdenkc6097192002-11-03 00:24:07 +0000586 /*
587 * SCC2 Ethernet parameter RAM space overlaps
588 * the SPI parameter RAM space. So we need to restore
589 * the SPI configuration after SCC2 ethernet test.
590 */
591#if defined(CONFIG_SPI)
592 if (ctlr == CTLR_SCC && index == 1) {
593 spi_init_f ();
594 spi_init_r ();
595 }
596#endif
597
598 if (res != 0) {
599 post_log ("ethernet %s%d test failed\n", ctlr_name[ctlr],
600 index + 1);
601 }
602
603 return res;
604}
605
606int ether_post_test (int flags)
607{
608 int res = 0;
609 int i;
610
wdenkc6097192002-11-03 00:24:07 +0000611 ctlr_proc[CTLR_SCC].init = scc_init;
wdenkda55c6e2004-01-20 23:12:12 +0000612 ctlr_proc[CTLR_SCC].halt = scc_halt;
wdenkc6097192002-11-03 00:24:07 +0000613 ctlr_proc[CTLR_SCC].send = scc_send;
614 ctlr_proc[CTLR_SCC].recv = scc_recv;
615
616 for (i = 0; i < CTRL_LIST_SIZE; i++) {
617 if (test_ctlr (ctlr_list[i][0], ctlr_list[i][1]) != 0) {
618 res = -1;
619 }
620 }
621
wdenk7ac16102004-08-01 22:48:16 +0000622#if !defined(CONFIG_8xx_CONS_NONE)
623 serial_reinit_all ();
624#endif
wdenkc6097192002-11-03 00:24:07 +0000625 return res;
626}
627
628#endif /* CONFIG_POST & CFG_POST_ETHER */
629
630#endif /* CONFIG_POST */