]>
git.ipfire.org Git - people/ms/u-boot.git/blob - arch/powerpc/cpu/mpc8xx/scc.c
4 * Basic ET HW initialization and packet RX/TX routines
6 * NOTE <<<IMPORTANT: PLEASE READ>>>:
7 * Do not cache Rx/Tx buffers!
11 * MPC823 <-> MC68160 Connections:
13 * Setup MPC823 to work with MC68160 Enhanced Ethernet
14 * Serial Tranceiver as follows:
16 * MPC823 Signal MC68160 Comments
17 * ------ ------ ------- --------
18 * PA-12 ETHTX --------> TX Eth. Port Transmit Data
19 * PB-18 E_TENA --------> TENA Eth. Transmit Port Enable
20 * PA-5 ETHTCK <-------- TCLK Eth. Port Transmit Clock
21 * PA-13 ETHRX <-------- RX Eth. Port Receive Data
22 * PC-8 E_RENA <-------- RENA Eth. Receive Enable
23 * PA-6 ETHRCK <-------- RCLK Eth. Port Receive Clock
24 * PC-9 E_CLSN <-------- CLSN Eth. Port Collision Indication
26 * FADS Board Signal MC68160 Comments
27 * ----------------- ------- --------
28 * (BCSR1) ETHEN* --------> CS2 Eth. Port Enable
29 * (BSCR4) TPSQEL* --------> TPSQEL Twisted Pair Signal Quality Error Test Enable
30 * (BCSR4) TPFLDL* --------> TPFLDL Twisted Pair Full-Duplex
31 * (BCSR4) ETHLOOP --------> LOOP Eth. Port Diagnostic Loop-Back
41 #if defined(CONFIG_CMD_NET) && defined(SCC_ENET)
43 /* Ethernet Transmit and Receive Buffers */
44 #define DBUF_LENGTH 1520
48 #define TOUT_LOOP 10000 /* 10 ms to have a packet sent */
50 static char txbuf
[DBUF_LENGTH
];
52 static uint rxIdx
; /* index of the current RX buffer */
53 static uint txIdx
; /* index of the current TX buffer */
56 * SCC Ethernet Tx and Rx buffer descriptors allocated at the
57 * immr->udata_bd address on Dual-Port RAM
58 * Provide for Double Buffering
61 typedef volatile struct CommonBufferDescriptor
{
62 cbd_t rxbd
[PKTBUFSRX
]; /* Rx BD */
63 cbd_t txbd
[TX_BUF_CNT
]; /* Tx BD */
68 static int scc_send(struct eth_device
*dev
, void *packet
, int length
);
69 static int scc_recv(struct eth_device
* dev
);
70 static int scc_init (struct eth_device
* dev
, bd_t
* bd
);
71 static void scc_halt(struct eth_device
* dev
);
73 int scc_initialize(bd_t
*bis
)
75 struct eth_device
* dev
;
77 dev
= (struct eth_device
*) malloc(sizeof *dev
);
78 memset(dev
, 0, sizeof *dev
);
80 sprintf(dev
->name
, "SCC");
93 static int scc_send(struct eth_device
*dev
, void *packet
, int length
)
97 volatile char *in
, *out
;
104 while (rtx
->txbd
[txIdx
].cbd_sc
& BD_ENET_TX_READY
);
105 out
= (char *)(rtx
->txbd
[txIdx
].cbd_bufaddr
);
107 for(i
= 0; i
< length
; i
++) {
110 rtx
->txbd
[txIdx
].cbd_datlen
= length
;
111 rtx
->txbd
[txIdx
].cbd_sc
|= (BD_ENET_TX_READY
| BD_ENET_TX_LAST
);
112 while (rtx
->txbd
[txIdx
].cbd_sc
& BD_ENET_TX_READY
) j
++;
115 printf("cycles: %d status: %x\n", j
, rtx
->txbd
[txIdx
].cbd_sc
);
117 i
= (rtx
->txbd
[txIdx
++].cbd_sc
& BD_ENET_TX_STATS
) /* return only status bits */;
119 /* wrap around buffer index when necessary */
120 if (txIdx
>= TX_BUF_CNT
) txIdx
= 0;
123 while ((rtx
->txbd
[txIdx
].cbd_sc
& BD_ENET_TX_READY
) && (j
<TOUT_LOOP
)) {
124 udelay (1); /* will also trigger Wd if needed */
127 if (j
>=TOUT_LOOP
) printf("TX not ready\n");
128 rtx
->txbd
[txIdx
].cbd_bufaddr
= (uint
)packet
;
129 rtx
->txbd
[txIdx
].cbd_datlen
= length
;
130 rtx
->txbd
[txIdx
].cbd_sc
|= (BD_ENET_TX_READY
| BD_ENET_TX_LAST
|BD_ENET_TX_WRAP
);
131 while ((rtx
->txbd
[txIdx
].cbd_sc
& BD_ENET_TX_READY
) && (j
<TOUT_LOOP
)) {
132 udelay (1); /* will also trigger Wd if needed */
135 if (j
>=TOUT_LOOP
) printf("TX timeout\n");
137 printf("cycles: %d status: %x\n", j
, rtx
->txbd
[txIdx
].cbd_sc
);
139 i
= (rtx
->txbd
[txIdx
].cbd_sc
& BD_ENET_TX_STATS
) /* return only status bits */;
143 static int scc_recv (struct eth_device
*dev
)
148 /* section 16.9.23.2 */
149 if (rtx
->rxbd
[rxIdx
].cbd_sc
& BD_ENET_RX_EMPTY
) {
151 break; /* nothing received - leave for() loop */
154 length
= rtx
->rxbd
[rxIdx
].cbd_datlen
;
156 if (rtx
->rxbd
[rxIdx
].cbd_sc
& 0x003f) {
158 printf ("err: %x\n", rtx
->rxbd
[rxIdx
].cbd_sc
);
161 /* Pass the packet up to the protocol layers. */
162 NetReceive (NetRxPackets
[rxIdx
], length
- 4);
166 /* Give the buffer back to the SCC. */
167 rtx
->rxbd
[rxIdx
].cbd_datlen
= 0;
169 /* wrap around buffer index when necessary */
170 if ((rxIdx
+ 1) >= PKTBUFSRX
) {
171 rtx
->rxbd
[PKTBUFSRX
- 1].cbd_sc
=
172 (BD_ENET_RX_WRAP
| BD_ENET_RX_EMPTY
);
175 rtx
->rxbd
[rxIdx
].cbd_sc
= BD_ENET_RX_EMPTY
;
182 /**************************************************************
184 * SCC Ethernet Initialization Routine
186 *************************************************************/
188 static int scc_init (struct eth_device
*dev
, bd_t
* bis
)
192 scc_enet_t
*pram_ptr
;
194 volatile immap_t
*immr
= (immap_t
*) CONFIG_SYS_IMMR
;
196 #if defined(CONFIG_LWMON)
200 pram_ptr
= (scc_enet_t
*) & (immr
->im_cpm
.cp_dparam
[PROFF_ENET
]);
206 #ifdef CONFIG_SYS_ALLOC_DPRAM
207 rtx
= (RTXBD
*) (immr
->im_cpm
.cp_dpmem
+
208 dpram_alloc_align (sizeof (RTXBD
), 8));
210 rtx
= (RTXBD
*) (immr
->im_cpm
.cp_dpmem
+ CPM_SCC_BASE
);
214 #if (defined(PA_ENET_RXD) && defined(PA_ENET_TXD))
215 /* Configure port A pins for Txd and Rxd.
217 immr
->im_ioport
.iop_papar
|= (PA_ENET_RXD
| PA_ENET_TXD
);
218 immr
->im_ioport
.iop_padir
&= ~(PA_ENET_RXD
| PA_ENET_TXD
);
219 immr
->im_ioport
.iop_paodr
&= ~PA_ENET_TXD
;
220 #elif (defined(PB_ENET_RXD) && defined(PB_ENET_TXD))
221 /* Configure port B pins for Txd and Rxd.
223 immr
->im_cpm
.cp_pbpar
|= (PB_ENET_RXD
| PB_ENET_TXD
);
224 immr
->im_cpm
.cp_pbdir
&= ~(PB_ENET_RXD
| PB_ENET_TXD
);
225 immr
->im_cpm
.cp_pbodr
&= ~PB_ENET_TXD
;
227 #error Configuration Error: exactly ONE of PA_ENET_[RT]XD, PB_ENET_[RT]XD must be defined
230 #if defined(PC_ENET_LBK)
231 /* Configure port C pins to disable External Loopback
233 immr
->im_ioport
.iop_pcpar
&= ~PC_ENET_LBK
;
234 immr
->im_ioport
.iop_pcdir
|= PC_ENET_LBK
;
235 immr
->im_ioport
.iop_pcso
&= ~PC_ENET_LBK
;
236 immr
->im_ioport
.iop_pcdat
&= ~PC_ENET_LBK
; /* Disable Loopback */
237 #endif /* PC_ENET_LBK */
239 /* Configure port C pins to enable CLSN and RENA.
241 immr
->im_ioport
.iop_pcpar
&= ~(PC_ENET_CLSN
| PC_ENET_RENA
);
242 immr
->im_ioport
.iop_pcdir
&= ~(PC_ENET_CLSN
| PC_ENET_RENA
);
243 immr
->im_ioport
.iop_pcso
|= (PC_ENET_CLSN
| PC_ENET_RENA
);
245 /* Configure port A for TCLK and RCLK.
247 immr
->im_ioport
.iop_papar
|= (PA_ENET_TCLK
| PA_ENET_RCLK
);
248 immr
->im_ioport
.iop_padir
&= ~(PA_ENET_TCLK
| PA_ENET_RCLK
);
251 * Configure Serial Interface clock routing -- see section 16.7.5.3
252 * First, clear all SCC bits to zero, then set the ones we want.
255 immr
->im_cpm
.cp_sicr
&= ~SICR_ENET_MASK
;
256 immr
->im_cpm
.cp_sicr
|= SICR_ENET_CLKRT
;
260 * Initialize SDCR -- see section 16.9.23.7
261 * SDMA configuration register
263 immr
->im_siu_conf
.sc_sdcr
= 0x01;
267 * Setup SCC Ethernet Parameter RAM
270 pram_ptr
->sen_genscc
.scc_rfcr
= 0x18; /* Normal Operation and Mot byte ordering */
271 pram_ptr
->sen_genscc
.scc_tfcr
= 0x18; /* Mot byte ordering, Normal access */
273 pram_ptr
->sen_genscc
.scc_mrblr
= DBUF_LENGTH
; /* max. ET package len 1520 */
275 pram_ptr
->sen_genscc
.scc_rbase
= (unsigned int) (&rtx
->rxbd
[0]); /* Set RXBD tbl start at Dual Port */
276 pram_ptr
->sen_genscc
.scc_tbase
= (unsigned int) (&rtx
->txbd
[0]); /* Set TXBD tbl start at Dual Port */
279 * Setup Receiver Buffer Descriptors (13.14.24.18)
284 for (i
= 0; i
< PKTBUFSRX
; i
++) {
285 rtx
->rxbd
[i
].cbd_sc
= BD_ENET_RX_EMPTY
;
286 rtx
->rxbd
[i
].cbd_datlen
= 0; /* Reset */
287 rtx
->rxbd
[i
].cbd_bufaddr
= (uint
) NetRxPackets
[i
];
290 rtx
->rxbd
[PKTBUFSRX
- 1].cbd_sc
|= BD_ENET_RX_WRAP
;
293 * Setup Ethernet Transmitter Buffer Descriptors (13.14.24.19)
295 * Add PADs to Short FRAMES, Wrap, Last, Tx CRC
298 for (i
= 0; i
< TX_BUF_CNT
; i
++) {
299 rtx
->txbd
[i
].cbd_sc
=
300 (BD_ENET_TX_PAD
| BD_ENET_TX_LAST
| BD_ENET_TX_TC
);
301 rtx
->txbd
[i
].cbd_datlen
= 0; /* Reset */
302 rtx
->txbd
[i
].cbd_bufaddr
= (uint
) (&txbuf
[0]);
305 rtx
->txbd
[TX_BUF_CNT
- 1].cbd_sc
|= BD_ENET_TX_WRAP
;
308 * Enter Command: Initialize Rx Params for SCC
311 do { /* Spin until ready to issue command */
313 } while (immr
->im_cpm
.cp_cpcr
& CPM_CR_FLG
);
315 immr
->im_cpm
.cp_cpcr
=
316 ((CPM_CR_INIT_RX
<< 8) | (CPM_CR_ENET
<< 4) | CPM_CR_FLG
);
317 do { /* Spin until command processed */
319 } while (immr
->im_cpm
.cp_cpcr
& CPM_CR_FLG
);
322 * Ethernet Specific Parameter RAM
323 * see table 13-16, pg. 660,
324 * pg. 681 (example with suggested settings)
327 pram_ptr
->sen_cpres
= ~(0x0); /* Preset CRC */
328 pram_ptr
->sen_cmask
= 0xdebb20e3; /* Constant Mask for CRC */
329 pram_ptr
->sen_crcec
= 0x0; /* Error Counter CRC (unused) */
330 pram_ptr
->sen_alec
= 0x0; /* Alignment Error Counter (unused) */
331 pram_ptr
->sen_disfc
= 0x0; /* Discard Frame Counter (unused) */
332 pram_ptr
->sen_pads
= 0x8888; /* Short Frame PAD Characters */
334 pram_ptr
->sen_retlim
= 15; /* Retry Limit Threshold */
335 pram_ptr
->sen_maxflr
= 1518; /* MAX Frame Length Register */
336 pram_ptr
->sen_minflr
= 64; /* MIN Frame Length Register */
338 pram_ptr
->sen_maxd1
= DBUF_LENGTH
; /* MAX DMA1 Length Register */
339 pram_ptr
->sen_maxd2
= DBUF_LENGTH
; /* MAX DMA2 Length Register */
341 pram_ptr
->sen_gaddr1
= 0x0; /* Group Address Filter 1 (unused) */
342 pram_ptr
->sen_gaddr2
= 0x0; /* Group Address Filter 2 (unused) */
343 pram_ptr
->sen_gaddr3
= 0x0; /* Group Address Filter 3 (unused) */
344 pram_ptr
->sen_gaddr4
= 0x0; /* Group Address Filter 4 (unused) */
346 #define ea eth_get_dev()->enetaddr
347 pram_ptr
->sen_paddrh
= (ea
[5] << 8) + ea
[4];
348 pram_ptr
->sen_paddrm
= (ea
[3] << 8) + ea
[2];
349 pram_ptr
->sen_paddrl
= (ea
[1] << 8) + ea
[0];
352 pram_ptr
->sen_pper
= 0x0; /* Persistence (unused) */
353 pram_ptr
->sen_iaddr1
= 0x0; /* Individual Address Filter 1 (unused) */
354 pram_ptr
->sen_iaddr2
= 0x0; /* Individual Address Filter 2 (unused) */
355 pram_ptr
->sen_iaddr3
= 0x0; /* Individual Address Filter 3 (unused) */
356 pram_ptr
->sen_iaddr4
= 0x0; /* Individual Address Filter 4 (unused) */
357 pram_ptr
->sen_taddrh
= 0x0; /* Tmp Address (MSB) (unused) */
358 pram_ptr
->sen_taddrm
= 0x0; /* Tmp Address (unused) */
359 pram_ptr
->sen_taddrl
= 0x0; /* Tmp Address (LSB) (unused) */
362 * Enter Command: Initialize Tx Params for SCC
365 do { /* Spin until ready to issue command */
367 } while (immr
->im_cpm
.cp_cpcr
& CPM_CR_FLG
);
369 immr
->im_cpm
.cp_cpcr
=
370 ((CPM_CR_INIT_TX
<< 8) | (CPM_CR_ENET
<< 4) | CPM_CR_FLG
);
371 do { /* Spin until command processed */
373 } while (immr
->im_cpm
.cp_cpcr
& CPM_CR_FLG
);
376 * Mask all Events in SCCM - we use polling mode
378 immr
->im_cpm
.cp_scc
[SCC_ENET
].scc_sccm
= 0;
381 * Clear Events in SCCE -- Clear bits by writing 1's
384 immr
->im_cpm
.cp_scc
[SCC_ENET
].scc_scce
= ~(0x0);
388 * Initialize GSMR High 32-Bits
389 * Settings: Normal Mode
392 immr
->im_cpm
.cp_scc
[SCC_ENET
].scc_gsmrh
= 0;
395 * Initialize GSMR Low 32-Bits, but do not Enable Transmit/Receive
399 * TPP = Repeating 10's
403 immr
->im_cpm
.cp_scc
[SCC_ENET
].scc_gsmrl
= (SCC_GSMRL_TCI
|
406 SCC_GSMRL_MODE_ENET
);
409 * Initialize the DSR -- see section 13.14.4 (pg. 513) v0.4
412 immr
->im_cpm
.cp_scc
[SCC_ENET
].scc_dsr
= 0xd555;
415 * Initialize the PSMR
418 * NIB = Begin searching for SFD 22 bits after RENA
419 * FDE = Full Duplex Enable
420 * LPB = Loopback Enable (Needed when FDE is set)
421 * BRO = Reject broadcast packets
422 * PROMISCOUS = Catch all packets regardless of dest. MAC adress
424 immr
->im_cpm
.cp_scc
[SCC_ENET
].scc_psmr
= SCC_PSMR_ENCRC
|
426 #if defined(CONFIG_SCC_ENET_FULL_DUPLEX)
427 SCC_PSMR_FDE
| SCC_PSMR_LPB
|
429 #if defined(CONFIG_SCC_ENET_NO_BROADCAST)
432 #if defined(CONFIG_SCC_ENET_PROMISCOUS)
438 * Configure Ethernet TENA Signal
441 #if (defined(PC_ENET_TENA) && !defined(PB_ENET_TENA))
442 immr
->im_ioport
.iop_pcpar
|= PC_ENET_TENA
;
443 immr
->im_ioport
.iop_pcdir
&= ~PC_ENET_TENA
;
444 #elif (defined(PB_ENET_TENA) && !defined(PC_ENET_TENA))
445 immr
->im_cpm
.cp_pbpar
|= PB_ENET_TENA
;
446 immr
->im_cpm
.cp_pbdir
|= PB_ENET_TENA
;
448 #error Configuration Error: exactly ONE of PB_ENET_TENA, PC_ENET_TENA must be defined
451 #if defined(CONFIG_NETVIA)
452 #if defined(PA_ENET_PDN)
453 immr
->im_ioport
.iop_papar
&= ~PA_ENET_PDN
;
454 immr
->im_ioport
.iop_padir
|= PA_ENET_PDN
;
455 immr
->im_ioport
.iop_padat
|= PA_ENET_PDN
;
456 #elif defined(PB_ENET_PDN)
457 immr
->im_cpm
.cp_pbpar
&= ~PB_ENET_PDN
;
458 immr
->im_cpm
.cp_pbdir
|= PB_ENET_PDN
;
459 immr
->im_cpm
.cp_pbdat
|= PB_ENET_PDN
;
460 #elif defined(PC_ENET_PDN)
461 immr
->im_ioport
.iop_pcpar
&= ~PC_ENET_PDN
;
462 immr
->im_ioport
.iop_pcdir
|= PC_ENET_PDN
;
463 immr
->im_ioport
.iop_pcdat
|= PC_ENET_PDN
;
464 #elif defined(PD_ENET_PDN)
465 immr
->im_ioport
.iop_pdpar
&= ~PD_ENET_PDN
;
466 immr
->im_ioport
.iop_pddir
|= PD_ENET_PDN
;
467 immr
->im_ioport
.iop_pddat
|= PD_ENET_PDN
;
472 * Set the ENT/ENR bits in the GSMR Low -- Enable Transmit/Receive
475 immr
->im_cpm
.cp_scc
[SCC_ENET
].scc_gsmrl
|=
476 (SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);
482 static void scc_halt (struct eth_device
*dev
)
484 volatile immap_t
*immr
= (immap_t
*) CONFIG_SYS_IMMR
;
486 immr
->im_cpm
.cp_scc
[SCC_ENET
].scc_gsmrl
&=
487 ~(SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);
489 immr
->im_ioport
.iop_pcso
&= ~(PC_ENET_CLSN
| PC_ENET_RENA
);
495 volatile immap_t
*immr
= (immap_t
*) CONFIG_SYS_IMMR
;
497 immr
->im_cpm
.cp_scc
[SCC_ENET
].scc_gsmrl
|=
498 (SCC_GSMRL_ENR
| SCC_GSMRL_ENT
);