]>
git.ipfire.org Git - people/ms/u-boot.git/blob - post/cpu/mpc8xx/ether.c
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
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
41 #if CONFIG_POST & CFG_POST_ETHER
42 #if defined(CONFIG_8xx)
44 #elif defined(CONFIG_MPC8260)
45 #include <asm/cpm_8260.h>
47 #error "Apparently a bad configuration, please fix."
54 DECLARE_GLOBAL_DATA_PTR
;
56 #define MIN_PACKET_LENGTH 64
57 #define MAX_PACKET_LENGTH 256
62 extern void spi_init_f (void);
63 extern void spi_init_r (void);
65 /* The list of controllers to test */
66 #if defined(CONFIG_MPC823)
67 static int ctlr_list
[][2] = { {CTLR_SCC
, 1} };
69 static int ctlr_list
[][2] = { };
72 #define CTRL_LIST_SIZE (sizeof(ctlr_list) / sizeof(ctlr_list[0]))
75 void (*init
) (int index
);
76 void (*halt
) (int index
);
77 int (*send
) (int index
, volatile void *packet
, int length
);
78 int (*recv
) (int index
, void *packet
, int length
);
81 static char *ctlr_name
[1] = { "SCC" };
83 /* Ethernet Transmit and Receive Buffers */
84 #define DBUF_LENGTH 1520
90 static char txbuf
[DBUF_LENGTH
];
92 static uint rxIdx
; /* index of the current RX buffer */
93 static uint txIdx
; /* index of the current TX buffer */
96 * SCC Ethernet Tx and Rx buffer descriptors allocated at the
97 * immr->udata_bd address on Dual-Port RAM
98 * Provide for Double Buffering
101 typedef volatile struct CommonBufferDescriptor
{
102 cbd_t rxbd
[PKTBUFSRX
]; /* Rx BD */
103 cbd_t txbd
[TX_BUF_CNT
]; /* Tx BD */
112 static void scc_init (int scc_index
)
117 { PROFF_SCC1
, PROFF_SCC2
, PROFF_SCC3
, PROFF_SCC4
};
118 static unsigned int cpm_cr
[] =
119 { CPM_CR_CH_SCC1
, CPM_CR_CH_SCC2
, CPM_CR_CH_SCC3
,
123 scc_enet_t
*pram_ptr
;
125 volatile immap_t
*immr
= (immap_t
*) CFG_IMMR
;
127 immr
->im_cpm
.cp_scc
[scc_index
].scc_gsmrl
&=
128 ~(SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);
130 #if defined(CONFIG_FADS)
131 #if defined(CONFIG_MPC860T) || defined(CONFIG_MPC86xADS)
132 /* The FADS860T and MPC86xADS don't use the MODEM_EN or DATA_VOICE signals. */
133 *((uint
*) BCSR4
) &= ~BCSR4_ETHLOOP
;
134 *((uint
*) BCSR4
) |= BCSR4_TFPLDL
| BCSR4_TPSQEL
;
135 *((uint
*) BCSR1
) &= ~BCSR1_ETHEN
;
137 *((uint
*) BCSR4
) &= ~(BCSR4_ETHLOOP
| BCSR4_MODEM_EN
);
138 *((uint
*) BCSR4
) |= BCSR4_TFPLDL
| BCSR4_TPSQEL
| BCSR4_DATA_VOICE
;
139 *((uint
*) BCSR1
) &= ~BCSR1_ETHEN
;
143 pram_ptr
= (scc_enet_t
*) & (immr
->im_cpm
.cp_dparam
[proff
[scc_index
]]);
148 #ifdef CFG_ALLOC_DPRAM
149 rtx
= (RTXBD
*) (immr
->im_cpm
.cp_dpmem
+
150 dpram_alloc_align (sizeof (RTXBD
), 8));
152 rtx
= (RTXBD
*) (immr
->im_cpm
.cp_dpmem
+ CPM_SCC_BASE
);
157 #if (defined(PA_ENET_RXD) && defined(PA_ENET_TXD))
158 /* Configure port A pins for Txd and Rxd.
160 immr
->im_ioport
.iop_papar
|= (PA_ENET_RXD
| PA_ENET_TXD
);
161 immr
->im_ioport
.iop_padir
&= ~(PA_ENET_RXD
| PA_ENET_TXD
);
162 immr
->im_ioport
.iop_paodr
&= ~PA_ENET_TXD
;
163 #elif (defined(PB_ENET_RXD) && defined(PB_ENET_TXD))
164 /* Configure port B pins for Txd and Rxd.
166 immr
->im_cpm
.cp_pbpar
|= (PB_ENET_RXD
| PB_ENET_TXD
);
167 immr
->im_cpm
.cp_pbdir
&= ~(PB_ENET_RXD
| PB_ENET_TXD
);
168 immr
->im_cpm
.cp_pbodr
&= ~PB_ENET_TXD
;
170 #error Configuration Error: exactly ONE of PA_ENET_[RT]XD, PB_ENET_[RT]XD must be defined
173 #if defined(PC_ENET_LBK)
174 /* Configure port C pins to disable External Loopback
176 immr
->im_ioport
.iop_pcpar
&= ~PC_ENET_LBK
;
177 immr
->im_ioport
.iop_pcdir
|= PC_ENET_LBK
;
178 immr
->im_ioport
.iop_pcso
&= ~PC_ENET_LBK
;
179 immr
->im_ioport
.iop_pcdat
&= ~PC_ENET_LBK
; /* Disable Loopback */
180 #endif /* PC_ENET_LBK */
182 /* Configure port C pins to enable CLSN and RENA.
184 immr
->im_ioport
.iop_pcpar
&= ~(PC_ENET_CLSN
| PC_ENET_RENA
);
185 immr
->im_ioport
.iop_pcdir
&= ~(PC_ENET_CLSN
| PC_ENET_RENA
);
186 immr
->im_ioport
.iop_pcso
|= (PC_ENET_CLSN
| PC_ENET_RENA
);
188 /* Configure port A for TCLK and RCLK.
190 immr
->im_ioport
.iop_papar
|= (PA_ENET_TCLK
| PA_ENET_RCLK
);
191 immr
->im_ioport
.iop_padir
&= ~(PA_ENET_TCLK
| PA_ENET_RCLK
);
194 * Configure Serial Interface clock routing -- see section 16.7.5.3
195 * First, clear all SCC bits to zero, then set the ones we want.
198 immr
->im_cpm
.cp_sicr
&= ~SICR_ENET_MASK
;
199 immr
->im_cpm
.cp_sicr
|= SICR_ENET_CLKRT
;
202 * SCC2 receive clock is BRG2
203 * SCC2 transmit clock is BRG3
205 immr
->im_cpm
.cp_brgc2
= 0x0001000C;
206 immr
->im_cpm
.cp_brgc3
= 0x0001000C;
208 immr
->im_cpm
.cp_sicr
&= ~0x00003F00;
209 immr
->im_cpm
.cp_sicr
|= 0x00000a00;
214 * Initialize SDCR -- see section 16.9.23.7
215 * SDMA configuration register
217 immr
->im_siu_conf
.sc_sdcr
= 0x01;
221 * Setup SCC Ethernet Parameter RAM
224 pram_ptr
->sen_genscc
.scc_rfcr
= 0x18; /* Normal Operation and Mot byte ordering */
225 pram_ptr
->sen_genscc
.scc_tfcr
= 0x18; /* Mot byte ordering, Normal access */
227 pram_ptr
->sen_genscc
.scc_mrblr
= DBUF_LENGTH
; /* max. ET package len 1520 */
229 pram_ptr
->sen_genscc
.scc_rbase
= (unsigned int) (&rtx
->rxbd
[0]); /* Set RXBD tbl start at Dual Port */
230 pram_ptr
->sen_genscc
.scc_tbase
= (unsigned int) (&rtx
->txbd
[0]); /* Set TXBD tbl start at Dual Port */
233 * Setup Receiver Buffer Descriptors (13.14.24.18)
238 for (i
= 0; i
< PKTBUFSRX
; i
++) {
239 rtx
->rxbd
[i
].cbd_sc
= BD_ENET_RX_EMPTY
;
240 rtx
->rxbd
[i
].cbd_datlen
= 0; /* Reset */
241 rtx
->rxbd
[i
].cbd_bufaddr
= (uint
) NetRxPackets
[i
];
244 rtx
->rxbd
[PKTBUFSRX
- 1].cbd_sc
|= BD_ENET_RX_WRAP
;
247 * Setup Ethernet Transmitter Buffer Descriptors (13.14.24.19)
249 * Add PADs to Short FRAMES, Wrap, Last, Tx CRC
252 for (i
= 0; i
< TX_BUF_CNT
; i
++) {
253 rtx
->txbd
[i
].cbd_sc
=
254 (BD_ENET_TX_PAD
| BD_ENET_TX_LAST
| BD_ENET_TX_TC
);
255 rtx
->txbd
[i
].cbd_datlen
= 0; /* Reset */
256 rtx
->txbd
[i
].cbd_bufaddr
= (uint
) (&txbuf
[0]);
259 rtx
->txbd
[TX_BUF_CNT
- 1].cbd_sc
|= BD_ENET_TX_WRAP
;
262 * Enter Command: Initialize Rx Params for SCC
265 do { /* Spin until ready to issue command */
267 } while (immr
->im_cpm
.cp_cpcr
& CPM_CR_FLG
);
269 immr
->im_cpm
.cp_cpcr
=
270 ((CPM_CR_INIT_RX
<< 8) | (cpm_cr
[scc_index
] << 4) |
272 do { /* Spin until command processed */
274 } while (immr
->im_cpm
.cp_cpcr
& CPM_CR_FLG
);
277 * Ethernet Specific Parameter RAM
278 * see table 13-16, pg. 660,
279 * pg. 681 (example with suggested settings)
282 pram_ptr
->sen_cpres
= ~(0x0); /* Preset CRC */
283 pram_ptr
->sen_cmask
= 0xdebb20e3; /* Constant Mask for CRC */
284 pram_ptr
->sen_crcec
= 0x0; /* Error Counter CRC (unused) */
285 pram_ptr
->sen_alec
= 0x0; /* Alignment Error Counter (unused) */
286 pram_ptr
->sen_disfc
= 0x0; /* Discard Frame Counter (unused) */
287 pram_ptr
->sen_pads
= 0x8888; /* Short Frame PAD Characters */
289 pram_ptr
->sen_retlim
= 15; /* Retry Limit Threshold */
290 pram_ptr
->sen_maxflr
= 1518; /* MAX Frame Length Register */
291 pram_ptr
->sen_minflr
= 64; /* MIN Frame Length Register */
293 pram_ptr
->sen_maxd1
= DBUF_LENGTH
; /* MAX DMA1 Length Register */
294 pram_ptr
->sen_maxd2
= DBUF_LENGTH
; /* MAX DMA2 Length Register */
296 pram_ptr
->sen_gaddr1
= 0x0; /* Group Address Filter 1 (unused) */
297 pram_ptr
->sen_gaddr2
= 0x0; /* Group Address Filter 2 (unused) */
298 pram_ptr
->sen_gaddr3
= 0x0; /* Group Address Filter 3 (unused) */
299 pram_ptr
->sen_gaddr4
= 0x0; /* Group Address Filter 4 (unused) */
301 #define ea bd->bi_enetaddr
302 pram_ptr
->sen_paddrh
= (ea
[5] << 8) + ea
[4];
303 pram_ptr
->sen_paddrm
= (ea
[3] << 8) + ea
[2];
304 pram_ptr
->sen_paddrl
= (ea
[1] << 8) + ea
[0];
307 pram_ptr
->sen_pper
= 0x0; /* Persistence (unused) */
308 pram_ptr
->sen_iaddr1
= 0x0; /* Individual Address Filter 1 (unused) */
309 pram_ptr
->sen_iaddr2
= 0x0; /* Individual Address Filter 2 (unused) */
310 pram_ptr
->sen_iaddr3
= 0x0; /* Individual Address Filter 3 (unused) */
311 pram_ptr
->sen_iaddr4
= 0x0; /* Individual Address Filter 4 (unused) */
312 pram_ptr
->sen_taddrh
= 0x0; /* Tmp Address (MSB) (unused) */
313 pram_ptr
->sen_taddrm
= 0x0; /* Tmp Address (unused) */
314 pram_ptr
->sen_taddrl
= 0x0; /* Tmp Address (LSB) (unused) */
317 * Enter Command: Initialize Tx Params for SCC
320 do { /* Spin until ready to issue command */
322 } while (immr
->im_cpm
.cp_cpcr
& CPM_CR_FLG
);
324 immr
->im_cpm
.cp_cpcr
=
325 ((CPM_CR_INIT_TX
<< 8) | (cpm_cr
[scc_index
] << 4) |
327 do { /* Spin until command processed */
329 } while (immr
->im_cpm
.cp_cpcr
& CPM_CR_FLG
);
332 * Mask all Events in SCCM - we use polling mode
334 immr
->im_cpm
.cp_scc
[scc_index
].scc_sccm
= 0;
337 * Clear Events in SCCE -- Clear bits by writing 1's
340 immr
->im_cpm
.cp_scc
[scc_index
].scc_scce
= ~(0x0);
344 * Initialize GSMR High 32-Bits
345 * Settings: Normal Mode
348 immr
->im_cpm
.cp_scc
[scc_index
].scc_gsmrh
= 0;
351 * Initialize GSMR Low 32-Bits, but do not Enable Transmit/Receive
355 * TPP = Repeating 10's
360 immr
->im_cpm
.cp_scc
[scc_index
].scc_gsmrl
= (SCC_GSMRL_TCI
|
363 SCC_GSMRL_DIAG_LOOP
|
364 SCC_GSMRL_MODE_ENET
);
367 * Initialize the DSR -- see section 13.14.4 (pg. 513) v0.4
370 immr
->im_cpm
.cp_scc
[scc_index
].scc_dsr
= 0xd555;
373 * Initialize the PSMR
376 * NIB = Begin searching for SFD 22 bits after RENA
377 * LPB = Loopback Enable (Needed when FDE is set)
379 immr
->im_cpm
.cp_scc
[scc_index
].scc_psmr
= SCC_PSMR_ENCRC
|
380 SCC_PSMR_NIB22
| SCC_PSMR_LPB
;
384 * Configure Ethernet TENA Signal
387 #if (defined(PC_ENET_TENA) && !defined(PB_ENET_TENA))
388 immr
->im_ioport
.iop_pcpar
|= PC_ENET_TENA
;
389 immr
->im_ioport
.iop_pcdir
&= ~PC_ENET_TENA
;
390 #elif (defined(PB_ENET_TENA) && !defined(PC_ENET_TENA))
391 immr
->im_cpm
.cp_pbpar
|= PB_ENET_TENA
;
392 immr
->im_cpm
.cp_pbdir
|= PB_ENET_TENA
;
394 #error Configuration Error: exactly ONE of PB_ENET_TENA, PC_ENET_TENA must be defined
397 #if defined(CONFIG_ADS) && defined(CONFIG_MPC860)
399 * Port C is used to control the PHY,MC68160.
401 immr
->im_ioport
.iop_pcdir
|=
402 (PC_ENET_ETHLOOP
| PC_ENET_TPFLDL
| PC_ENET_TPSQEL
);
404 immr
->im_ioport
.iop_pcdat
|= PC_ENET_TPFLDL
;
405 immr
->im_ioport
.iop_pcdat
&= ~(PC_ENET_ETHLOOP
| PC_ENET_TPSQEL
);
406 *((uint
*) BCSR1
) &= ~BCSR1_ETHEN
;
407 #endif /* MPC860ADS */
409 #if defined(CONFIG_AMX860)
411 * Port B is used to control the PHY,MC68160.
413 immr
->im_cpm
.cp_pbdir
|=
414 (PB_ENET_ETHLOOP
| PB_ENET_TPFLDL
| PB_ENET_TPSQEL
);
416 immr
->im_cpm
.cp_pbdat
|= PB_ENET_TPFLDL
;
417 immr
->im_cpm
.cp_pbdat
&= ~(PB_ENET_ETHLOOP
| PB_ENET_TPSQEL
);
419 immr
->im_ioport
.iop_pddir
|= PD_ENET_ETH_EN
;
420 immr
->im_ioport
.iop_pddat
&= ~PD_ENET_ETH_EN
;
425 #ifdef CONFIG_RPXCLASSIC
426 *((uchar
*) BCSR0
) &= ~BCSR0_ETHLPBK
;
427 *((uchar
*) BCSR0
) |= (BCSR0_ETHEN
| BCSR0_COLTEST
| BCSR0_FULLDPLX
);
430 #ifdef CONFIG_RPXLITE
431 *((uchar
*) BCSR0
) |= BCSR0_ETHEN
;
439 * Set the ENT/ENR bits in the GSMR Low -- Enable Transmit/Receive
442 immr
->im_cpm
.cp_scc
[scc_index
].scc_gsmrl
|=
443 (SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);
446 * Work around transmit problem with first eth packet
448 #if defined (CONFIG_FADS)
449 udelay (10000); /* wait 10 ms */
450 #elif defined (CONFIG_AMX860) || defined(CONFIG_RPXCLASSIC)
451 udelay (100000); /* wait 100 ms */
455 static void scc_halt (int scc_index
)
457 volatile immap_t
*immr
= (immap_t
*) CFG_IMMR
;
459 immr
->im_cpm
.cp_scc
[scc_index
].scc_gsmrl
&=
460 ~(SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);
461 immr
->im_ioport
.iop_pcso
&= ~(PC_ENET_CLSN
| PC_ENET_RENA
);
464 static int scc_send (int index
, volatile void *packet
, int length
)
468 while ((rtx
->txbd
[txIdx
].cbd_sc
& BD_ENET_TX_READY
) && (j
< TOUT_LOOP
)) {
469 udelay (1); /* will also trigger Wd if needed */
473 printf ("TX not ready\n");
474 rtx
->txbd
[txIdx
].cbd_bufaddr
= (uint
) packet
;
475 rtx
->txbd
[txIdx
].cbd_datlen
= length
;
476 rtx
->txbd
[txIdx
].cbd_sc
|=
477 (BD_ENET_TX_READY
| BD_ENET_TX_LAST
| BD_ENET_TX_WRAP
);
478 while ((rtx
->txbd
[txIdx
].cbd_sc
& BD_ENET_TX_READY
) && (j
< TOUT_LOOP
)) {
479 udelay (1); /* will also trigger Wd if needed */
483 printf ("TX timeout\n");
484 i
= (rtx
->txbd
[txIdx
].
485 cbd_sc
& BD_ENET_TX_STATS
) /* return only status bits */ ;
489 static int scc_recv (int index
, void *packet
, int max_length
)
493 if (rtx
->rxbd
[rxIdx
].cbd_sc
& BD_ENET_RX_EMPTY
) {
494 goto Done
; /* nothing received */
497 if (!(rtx
->rxbd
[rxIdx
].cbd_sc
& 0x003f)) {
498 length
= rtx
->rxbd
[rxIdx
].cbd_datlen
- 4;
500 (void *) (NetRxPackets
[rxIdx
]),
501 length
< max_length
? length
: max_length
);
504 /* Give the buffer back to the SCC. */
505 rtx
->rxbd
[rxIdx
].cbd_datlen
= 0;
507 /* wrap around buffer index when necessary */
508 if ((rxIdx
+ 1) >= PKTBUFSRX
) {
509 rtx
->rxbd
[PKTBUFSRX
- 1].cbd_sc
=
510 (BD_ENET_RX_WRAP
| BD_ENET_RX_EMPTY
);
513 rtx
->rxbd
[rxIdx
].cbd_sc
= BD_ENET_RX_EMPTY
;
525 static void packet_fill (char *packet
, int length
)
527 char c
= (char) length
;
537 for (i
= 6; i
< length
; i
++) {
542 static int packet_check (char *packet
, int length
)
544 char c
= (char) length
;
547 for (i
= 6; i
< length
; i
++) {
548 if (packet
[i
] != c
++)
555 static int test_ctlr (int ctlr
, int index
)
558 char packet_send
[MAX_PACKET_LENGTH
];
559 char packet_recv
[MAX_PACKET_LENGTH
];
564 ctlr_proc
[ctlr
].init (index
);
566 for (i
= 0; i
< TEST_NUM
; i
++) {
567 for (l
= MIN_PACKET_LENGTH
; l
<= MAX_PACKET_LENGTH
; l
++) {
568 packet_fill (packet_send
, l
);
570 ctlr_proc
[ctlr
].send (index
, packet_send
, l
);
572 length
= ctlr_proc
[ctlr
].recv (index
, packet_recv
,
575 if (length
!= l
|| packet_check (packet_recv
, length
) < 0) {
585 ctlr_proc
[ctlr
].halt (index
);
588 * SCC2 Ethernet parameter RAM space overlaps
589 * the SPI parameter RAM space. So we need to restore
590 * the SPI configuration after SCC2 ethernet test.
592 #if defined(CONFIG_SPI)
593 if (ctlr
== CTLR_SCC
&& index
== 1) {
600 post_log ("ethernet %s%d test failed\n", ctlr_name
[ctlr
],
607 int ether_post_test (int flags
)
612 ctlr_proc
[CTLR_SCC
].init
= scc_init
;
613 ctlr_proc
[CTLR_SCC
].halt
= scc_halt
;
614 ctlr_proc
[CTLR_SCC
].send
= scc_send
;
615 ctlr_proc
[CTLR_SCC
].recv
= scc_recv
;
617 for (i
= 0; i
< CTRL_LIST_SIZE
; i
++) {
618 if (test_ctlr (ctlr_list
[i
][0], ctlr_list
[i
][1]) != 0) {
623 #if !defined(CONFIG_8xx_CONS_NONE)
624 serial_reinit_all ();
629 #endif /* CONFIG_POST & CFG_POST_ETHER */
631 #endif /* CONFIG_POST */