5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
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
42 #if defined(CONFIG_8xx)
44 #elif defined(CONFIG_MPC8260)
45 #include <asm/cpm_8260.h>
47 #error "Apparently a bad configuration, please fix."
53 #if CONFIG_POST & CFG_POST_ETHER
55 #define MIN_PACKET_LENGTH 64
56 #define MAX_PACKET_LENGTH 256
61 extern void spi_init_f (void);
62 extern void spi_init_r (void);
64 /* The list of controllers to test */
65 #if defined(CONFIG_MPC823)
66 static int ctlr_list[][2] = { {CTLR_SCC, 1} };
68 static int ctlr_list[][2] = { };
71 #define CTRL_LIST_SIZE (sizeof(ctlr_list) / sizeof(ctlr_list[0]))
74 void (*init) (int index);
75 int (*send) (int index, volatile void *packet, int length);
76 int (*recv) (int index, void *packet, int length);
79 static char *ctlr_name[1] = { "SCC" };
81 static int used_by_uart[1] = { -1 };
82 static int used_by_ether[1] = { -1 };
84 /* Ethernet Transmit and Receive Buffers */
85 #define DBUF_LENGTH 1520
91 static char txbuf[DBUF_LENGTH];
93 static uint rxIdx; /* index of the current RX buffer */
94 static uint txIdx; /* index of the current TX buffer */
97 * SCC Ethernet Tx and Rx buffer descriptors allocated at the
98 * immr->udata_bd address on Dual-Port RAM
99 * Provide for Double Buffering
102 typedef volatile struct CommonBufferDescriptor {
103 cbd_t rxbd[PKTBUFSRX]; /* Rx BD */
104 cbd_t txbd[TX_BUF_CNT]; /* Tx BD */
113 static void scc_init (int scc_index)
115 DECLARE_GLOBAL_DATA_PTR;
119 { PROFF_SCC1, PROFF_SCC2, PROFF_SCC3, PROFF_SCC4 };
120 static unsigned int cpm_cr[] =
121 { CPM_CR_CH_SCC1, CPM_CR_CH_SCC2, CPM_CR_CH_SCC3,
125 scc_enet_t *pram_ptr;
127 volatile immap_t *immr = (immap_t *) CFG_IMMR;
129 immr->im_cpm.cp_scc[scc_index].scc_gsmrl &=
130 ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
132 #if defined(CONFIG_FADS)
133 #if defined(CONFIG_MPC860T) || defined(CONFIG_MPC86xADS)
134 /* The FADS860T and MPC86xADS don't use the MODEM_EN or DATA_VOICE signals. */
135 *((uint *) BCSR4) &= ~BCSR4_ETHLOOP;
136 *((uint *) BCSR4) |= BCSR4_TFPLDL | BCSR4_TPSQEL;
137 *((uint *) BCSR1) &= ~BCSR1_ETHEN;
139 *((uint *) BCSR4) &= ~(BCSR4_ETHLOOP | BCSR4_MODEM_EN);
140 *((uint *) BCSR4) |= BCSR4_TFPLDL | BCSR4_TPSQEL | BCSR4_DATA_VOICE;
141 *((uint *) BCSR1) &= ~BCSR1_ETHEN;
145 pram_ptr = (scc_enet_t *) & (immr->im_cpm.cp_dparam[proff[scc_index]]);
150 #ifdef CFG_ALLOC_DPRAM
151 rtx = (RTXBD *) (immr->im_cpm.cp_dpmem +
152 dpram_alloc_align (sizeof (RTXBD), 8));
154 rtx = (RTXBD *) (immr->im_cpm.cp_dpmem + CPM_SCC_BASE);
159 #if (defined(PA_ENET_RXD) && defined(PA_ENET_TXD))
160 /* Configure port A pins for Txd and Rxd.
162 immr->im_ioport.iop_papar |= (PA_ENET_RXD | PA_ENET_TXD);
163 immr->im_ioport.iop_padir &= ~(PA_ENET_RXD | PA_ENET_TXD);
164 immr->im_ioport.iop_paodr &= ~PA_ENET_TXD;
165 #elif (defined(PB_ENET_RXD) && defined(PB_ENET_TXD))
166 /* Configure port B pins for Txd and Rxd.
168 immr->im_cpm.cp_pbpar |= (PB_ENET_RXD | PB_ENET_TXD);
169 immr->im_cpm.cp_pbdir &= ~(PB_ENET_RXD | PB_ENET_TXD);
170 immr->im_cpm.cp_pbodr &= ~PB_ENET_TXD;
172 #error Configuration Error: exactly ONE of PA_ENET_[RT]XD, PB_ENET_[RT]XD must be defined
175 #if defined(PC_ENET_LBK)
176 /* Configure port C pins to disable External Loopback
178 immr->im_ioport.iop_pcpar &= ~PC_ENET_LBK;
179 immr->im_ioport.iop_pcdir |= PC_ENET_LBK;
180 immr->im_ioport.iop_pcso &= ~PC_ENET_LBK;
181 immr->im_ioport.iop_pcdat &= ~PC_ENET_LBK; /* Disable Loopback */
182 #endif /* PC_ENET_LBK */
184 /* Configure port C pins to enable CLSN and RENA.
186 immr->im_ioport.iop_pcpar &= ~(PC_ENET_CLSN | PC_ENET_RENA);
187 immr->im_ioport.iop_pcdir &= ~(PC_ENET_CLSN | PC_ENET_RENA);
188 immr->im_ioport.iop_pcso |= (PC_ENET_CLSN | PC_ENET_RENA);
190 /* Configure port A for TCLK and RCLK.
192 immr->im_ioport.iop_papar |= (PA_ENET_TCLK | PA_ENET_RCLK);
193 immr->im_ioport.iop_padir &= ~(PA_ENET_TCLK | PA_ENET_RCLK);
196 * Configure Serial Interface clock routing -- see section 16.7.5.3
197 * First, clear all SCC bits to zero, then set the ones we want.
200 immr->im_cpm.cp_sicr &= ~SICR_ENET_MASK;
201 immr->im_cpm.cp_sicr |= SICR_ENET_CLKRT;
204 * SCC2 receive clock is BRG2
205 * SCC2 transmit clock is BRG3
207 immr->im_cpm.cp_brgc2 = 0x0001000C;
208 immr->im_cpm.cp_brgc3 = 0x0001000C;
210 immr->im_cpm.cp_sicr &= ~0x00003F00;
211 immr->im_cpm.cp_sicr |= 0x00000a00;
216 * Initialize SDCR -- see section 16.9.23.7
217 * SDMA configuration register
219 immr->im_siu_conf.sc_sdcr = 0x01;
223 * Setup SCC Ethernet Parameter RAM
226 pram_ptr->sen_genscc.scc_rfcr = 0x18; /* Normal Operation and Mot byte ordering */
227 pram_ptr->sen_genscc.scc_tfcr = 0x18; /* Mot byte ordering, Normal access */
229 pram_ptr->sen_genscc.scc_mrblr = DBUF_LENGTH; /* max. ET package len 1520 */
231 pram_ptr->sen_genscc.scc_rbase = (unsigned int) (&rtx->rxbd[0]); /* Set RXBD tbl start at Dual Port */
232 pram_ptr->sen_genscc.scc_tbase = (unsigned int) (&rtx->txbd[0]); /* Set TXBD tbl start at Dual Port */
235 * Setup Receiver Buffer Descriptors (13.14.24.18)
240 for (i = 0; i < PKTBUFSRX; i++) {
241 rtx->rxbd[i].cbd_sc = BD_ENET_RX_EMPTY;
242 rtx->rxbd[i].cbd_datlen = 0; /* Reset */
243 rtx->rxbd[i].cbd_bufaddr = (uint) NetRxPackets[i];
246 rtx->rxbd[PKTBUFSRX - 1].cbd_sc |= BD_ENET_RX_WRAP;
249 * Setup Ethernet Transmitter Buffer Descriptors (13.14.24.19)
251 * Add PADs to Short FRAMES, Wrap, Last, Tx CRC
254 for (i = 0; i < TX_BUF_CNT; i++) {
255 rtx->txbd[i].cbd_sc =
256 (BD_ENET_TX_PAD | BD_ENET_TX_LAST | BD_ENET_TX_TC);
257 rtx->txbd[i].cbd_datlen = 0; /* Reset */
258 rtx->txbd[i].cbd_bufaddr = (uint) (&txbuf[0]);
261 rtx->txbd[TX_BUF_CNT - 1].cbd_sc |= BD_ENET_TX_WRAP;
264 * Enter Command: Initialize Rx Params for SCC
267 do { /* Spin until ready to issue command */
269 } while (immr->im_cpm.cp_cpcr & CPM_CR_FLG);
271 immr->im_cpm.cp_cpcr =
272 ((CPM_CR_INIT_RX << 8) | (cpm_cr[scc_index] << 4) |
274 do { /* Spin until command processed */
276 } while (immr->im_cpm.cp_cpcr & CPM_CR_FLG);
279 * Ethernet Specific Parameter RAM
280 * see table 13-16, pg. 660,
281 * pg. 681 (example with suggested settings)
284 pram_ptr->sen_cpres = ~(0x0); /* Preset CRC */
285 pram_ptr->sen_cmask = 0xdebb20e3; /* Constant Mask for CRC */
286 pram_ptr->sen_crcec = 0x0; /* Error Counter CRC (unused) */
287 pram_ptr->sen_alec = 0x0; /* Alignment Error Counter (unused) */
288 pram_ptr->sen_disfc = 0x0; /* Discard Frame Counter (unused) */
289 pram_ptr->sen_pads = 0x8888; /* Short Frame PAD Characters */
291 pram_ptr->sen_retlim = 15; /* Retry Limit Threshold */
292 pram_ptr->sen_maxflr = 1518; /* MAX Frame Length Register */
293 pram_ptr->sen_minflr = 64; /* MIN Frame Length Register */
295 pram_ptr->sen_maxd1 = DBUF_LENGTH; /* MAX DMA1 Length Register */
296 pram_ptr->sen_maxd2 = DBUF_LENGTH; /* MAX DMA2 Length Register */
298 pram_ptr->sen_gaddr1 = 0x0; /* Group Address Filter 1 (unused) */
299 pram_ptr->sen_gaddr2 = 0x0; /* Group Address Filter 2 (unused) */
300 pram_ptr->sen_gaddr3 = 0x0; /* Group Address Filter 3 (unused) */
301 pram_ptr->sen_gaddr4 = 0x0; /* Group Address Filter 4 (unused) */
303 #define ea bd->bi_enetaddr
304 pram_ptr->sen_paddrh = (ea[5] << 8) + ea[4];
305 pram_ptr->sen_paddrm = (ea[3] << 8) + ea[2];
306 pram_ptr->sen_paddrl = (ea[1] << 8) + ea[0];
309 pram_ptr->sen_pper = 0x0; /* Persistence (unused) */
310 pram_ptr->sen_iaddr1 = 0x0; /* Individual Address Filter 1 (unused) */
311 pram_ptr->sen_iaddr2 = 0x0; /* Individual Address Filter 2 (unused) */
312 pram_ptr->sen_iaddr3 = 0x0; /* Individual Address Filter 3 (unused) */
313 pram_ptr->sen_iaddr4 = 0x0; /* Individual Address Filter 4 (unused) */
314 pram_ptr->sen_taddrh = 0x0; /* Tmp Address (MSB) (unused) */
315 pram_ptr->sen_taddrm = 0x0; /* Tmp Address (unused) */
316 pram_ptr->sen_taddrl = 0x0; /* Tmp Address (LSB) (unused) */
319 * Enter Command: Initialize Tx Params for SCC
322 do { /* Spin until ready to issue command */
324 } while (immr->im_cpm.cp_cpcr & CPM_CR_FLG);
326 immr->im_cpm.cp_cpcr =
327 ((CPM_CR_INIT_TX << 8) | (cpm_cr[scc_index] << 4) |
329 do { /* Spin until command processed */
331 } while (immr->im_cpm.cp_cpcr & CPM_CR_FLG);
334 * Mask all Events in SCCM - we use polling mode
336 immr->im_cpm.cp_scc[scc_index].scc_sccm = 0;
339 * Clear Events in SCCE -- Clear bits by writing 1's
342 immr->im_cpm.cp_scc[scc_index].scc_scce = ~(0x0);
346 * Initialize GSMR High 32-Bits
347 * Settings: Normal Mode
350 immr->im_cpm.cp_scc[scc_index].scc_gsmrh = 0;
353 * Initialize GSMR Low 32-Bits, but do not Enable Transmit/Receive
357 * TPP = Repeating 10's
362 immr->im_cpm.cp_scc[scc_index].scc_gsmrl = (SCC_GSMRL_TCI |
365 SCC_GSMRL_DIAG_LOOP |
366 SCC_GSMRL_MODE_ENET);
369 * Initialize the DSR -- see section 13.14.4 (pg. 513) v0.4
372 immr->im_cpm.cp_scc[scc_index].scc_dsr = 0xd555;
375 * Initialize the PSMR
378 * NIB = Begin searching for SFD 22 bits after RENA
379 * LPB = Loopback Enable (Needed when FDE is set)
381 immr->im_cpm.cp_scc[scc_index].scc_psmr = SCC_PSMR_ENCRC |
382 SCC_PSMR_NIB22 | SCC_PSMR_LPB;
386 * Configure Ethernet TENA Signal
389 #if (defined(PC_ENET_TENA) && !defined(PB_ENET_TENA))
390 immr->im_ioport.iop_pcpar |= PC_ENET_TENA;
391 immr->im_ioport.iop_pcdir &= ~PC_ENET_TENA;
392 #elif (defined(PB_ENET_TENA) && !defined(PC_ENET_TENA))
393 immr->im_cpm.cp_pbpar |= PB_ENET_TENA;
394 immr->im_cpm.cp_pbdir |= PB_ENET_TENA;
396 #error Configuration Error: exactly ONE of PB_ENET_TENA, PC_ENET_TENA must be defined
399 #if defined(CONFIG_ADS) && defined(CONFIG_MPC860)
401 * Port C is used to control the PHY,MC68160.
403 immr->im_ioport.iop_pcdir |=
404 (PC_ENET_ETHLOOP | PC_ENET_TPFLDL | PC_ENET_TPSQEL);
406 immr->im_ioport.iop_pcdat |= PC_ENET_TPFLDL;
407 immr->im_ioport.iop_pcdat &= ~(PC_ENET_ETHLOOP | PC_ENET_TPSQEL);
408 *((uint *) BCSR1) &= ~BCSR1_ETHEN;
409 #endif /* MPC860ADS */
411 #if defined(CONFIG_AMX860)
413 * Port B is used to control the PHY,MC68160.
415 immr->im_cpm.cp_pbdir |=
416 (PB_ENET_ETHLOOP | PB_ENET_TPFLDL | PB_ENET_TPSQEL);
418 immr->im_cpm.cp_pbdat |= PB_ENET_TPFLDL;
419 immr->im_cpm.cp_pbdat &= ~(PB_ENET_ETHLOOP | PB_ENET_TPSQEL);
421 immr->im_ioport.iop_pddir |= PD_ENET_ETH_EN;
422 immr->im_ioport.iop_pddat &= ~PD_ENET_ETH_EN;
427 #ifdef CONFIG_RPXCLASSIC
428 *((uchar *) BCSR0) &= ~BCSR0_ETHLPBK;
429 *((uchar *) BCSR0) |= (BCSR0_ETHEN | BCSR0_COLTEST | BCSR0_FULLDPLX);
432 #ifdef CONFIG_RPXLITE
433 *((uchar *) BCSR0) |= BCSR0_ETHEN;
441 * Set the ENT/ENR bits in the GSMR Low -- Enable Transmit/Receive
444 immr->im_cpm.cp_scc[scc_index].scc_gsmrl |=
445 (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
448 * Work around transmit problem with first eth packet
450 #if defined (CONFIG_FADS)
451 udelay (10000); /* wait 10 ms */
452 #elif defined (CONFIG_AMX860) || defined(CONFIG_RPXCLASSIC)
453 udelay (100000); /* wait 100 ms */
457 static int scc_send (int index, volatile void *packet, int length)
461 while ((rtx->txbd[txIdx].cbd_sc & BD_ENET_TX_READY) && (j < TOUT_LOOP)) {
462 udelay (1); /* will also trigger Wd if needed */
466 printf ("TX not ready\n");
467 rtx->txbd[txIdx].cbd_bufaddr = (uint) packet;
468 rtx->txbd[txIdx].cbd_datlen = length;
469 rtx->txbd[txIdx].cbd_sc |=
470 (BD_ENET_TX_READY | BD_ENET_TX_LAST | BD_ENET_TX_WRAP);
471 while ((rtx->txbd[txIdx].cbd_sc & BD_ENET_TX_READY) && (j < TOUT_LOOP)) {
472 udelay (1); /* will also trigger Wd if needed */
476 printf ("TX timeout\n");
477 i = (rtx->txbd[txIdx].
478 cbd_sc & BD_ENET_TX_STATS) /* return only status bits */ ;
482 static int scc_recv (int index, void *packet, int max_length)
486 if (rtx->rxbd[rxIdx].cbd_sc & BD_ENET_RX_EMPTY) {
487 goto Done; /* nothing received */
490 if (!(rtx->rxbd[rxIdx].cbd_sc & 0x003f)) {
491 length = rtx->rxbd[rxIdx].cbd_datlen - 4;
493 (void *) (NetRxPackets[rxIdx]),
494 length < max_length ? length : max_length);
497 /* Give the buffer back to the SCC. */
498 rtx->rxbd[rxIdx].cbd_datlen = 0;
500 /* wrap around buffer index when necessary */
501 if ((rxIdx + 1) >= PKTBUFSRX) {
502 rtx->rxbd[PKTBUFSRX - 1].cbd_sc =
503 (BD_ENET_RX_WRAP | BD_ENET_RX_EMPTY);
506 rtx->rxbd[rxIdx].cbd_sc = BD_ENET_RX_EMPTY;
518 static void packet_fill (char *packet, int length)
520 char c = (char) length;
530 for (i = 6; i < length; i++) {
535 static int packet_check (char *packet, int length)
537 char c = (char) length;
540 for (i = 6; i < length; i++) {
541 if (packet[i] != c++)
548 static int test_ctlr (int ctlr, int index)
551 char packet_send[MAX_PACKET_LENGTH];
552 char packet_recv[MAX_PACKET_LENGTH];
557 ctlr_proc[ctlr].init (index);
559 for (i = 0; i < TEST_NUM; i++) {
560 for (l = MIN_PACKET_LENGTH; l <= MAX_PACKET_LENGTH; l++) {
561 packet_fill (packet_send, l);
563 ctlr_proc[ctlr].send (index, packet_send, l);
565 length = ctlr_proc[ctlr].recv (index, packet_recv,
568 if (length != l || packet_check (packet_recv, length) < 0) {
578 #if !defined(CONFIG_8xx_CONS_NONE)
579 if (used_by_uart[ctlr] == index) {
584 #if defined(SCC_ENET)
585 if (used_by_ether[ctlr] == index) {
586 DECLARE_GLOBAL_DATA_PTR;
593 * SCC2 Ethernet parameter RAM space overlaps
594 * the SPI parameter RAM space. So we need to restore
595 * the SPI configuration after SCC2 ethernet test.
597 #if defined(CONFIG_SPI)
598 if (ctlr == CTLR_SCC && index == 1) {
605 post_log ("ethernet %s%d test failed\n", ctlr_name[ctlr],
612 int ether_post_test (int flags)
617 #if defined(CONFIG_8xx_CONS_SCC1)
618 used_by_uart[CTLR_SCC] = 0;
619 #elif defined(CONFIG_8xx_CONS_SCC2)
620 used_by_uart[CTLR_SCC] = 1;
621 #elif defined(CONFIG_8xx_CONS_SCC3)
622 used_by_uart[CTLR_SCC] = 2;
623 #elif defined(CONFIG_8xx_CONS_SCC4)
624 used_by_uart[CTLR_SCC] = 3;
627 #if defined(SCC_ENET)
628 used_by_ether[CTLR_SCC] = SCC_ENET;
631 ctlr_proc[CTLR_SCC].init = scc_init;
632 ctlr_proc[CTLR_SCC].send = scc_send;
633 ctlr_proc[CTLR_SCC].recv = scc_recv;
635 for (i = 0; i < CTRL_LIST_SIZE; i++) {
636 if (test_ctlr (ctlr_list[i][0], ctlr_list[i][1]) != 0) {
644 #endif /* CONFIG_POST & CFG_POST_ETHER */
646 #endif /* CONFIG_POST */