1 //==========================================================================
5 // PowerPC PPC405GP Ethernet
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //==========================================================================
41 //#####DESCRIPTIONBEGIN####
44 // Contributors: gthomas
50 //####DESCRIPTIONEND####
52 //==========================================================================
54 // PowerPC PPC405 Ethernet
57 // Ethernet MAC controller registers
59 #define EMAC0_MR0 *(volatile unsigned long *)0xEF600800
60 #define EMAC0_MR1 *(volatile unsigned long *)0xEF600804
61 #define EMAC0_TMR0 *(volatile unsigned long *)0xEF600808
62 #define EMAC0_TMR1 *(volatile unsigned long *)0xEF60080C
63 #define EMAC0_RMR *(volatile unsigned long *)0xEF600810
64 #define EMAC0_ISR *(volatile unsigned long *)0xEF600814
65 #define EMAC0_ISER *(volatile unsigned long *)0xEF600818
66 #define EMAC0_IAHR *(volatile unsigned long *)0xEF60081C
67 #define EMAC0_IALR *(volatile unsigned long *)0xEF600820
68 #define EMAC0_VTPID *(volatile unsigned long *)0xEF600824
69 #define EMAC0_VTCI *(volatile unsigned long *)0xEF600828
70 #define EMAC0_PRT *(volatile unsigned long *)0xEF60082C
71 #define EMAC0_IAHT1 *(volatile unsigned long *)0xEF600830
72 #define EMAC0_IAHT2 *(volatile unsigned long *)0xEF600834
73 #define EMAC0_IAHT3 *(volatile unsigned long *)0xEF600838
74 #define EMAC0_IAHT4 *(volatile unsigned long *)0xEF60083C
75 #define EMAC0_GAHT1 *(volatile unsigned long *)0xEF600840
76 #define EMAC0_GAHT2 *(volatile unsigned long *)0xEF600844
77 #define EMAC0_GAHT3 *(volatile unsigned long *)0xEF600848
78 #define EMAC0_GAHT4 *(volatile unsigned long *)0xEF60084C
79 #define EMAC0_LSAH *(volatile unsigned long *)0xEF600850
80 #define EMAC0_LSAL *(volatile unsigned long *)0xEF600854
81 #define EMAC0_IPGVR *(volatile unsigned long *)0xEF600858
82 #define EMAC0_STACR *(volatile unsigned long *)0xEF60085C
83 #define EMAC0_TRTR *(volatile unsigned long *)0xEF600860
84 #define EMAC0_RWMR *(volatile unsigned long *)0xEF600864
85 #define EMAC0_OCTX *(volatile unsigned long *)0xEF600868
86 #define EMAC0_OCRX *(volatile unsigned long *)0xEF60086C
91 #define EMAC0_MR0_RXI 0x80000000 // RX MAC Idle (1 = RX is idle)
92 #define EMAC0_MR0_TXI 0x40000000 // TX MAC Idle (1 = TX is idle)
93 #define EMAC0_MR0_SRST 0x20000000
94 #define EMAC0_MR0_TXE 0x10000000
95 #define EMAC0_MR0_RXE 0x08000000
96 #define EMAC0_MR0_WKE 0x04000000
101 #define EMAC0_MR1_FDE 0x80000000
102 #define EMAC0_MR1_ILE 0x40000000
103 #define EMAC0_MR1_VLE 0x20000000
104 #define EMAC0_MR1_EIFC 0x10000000
105 #define EMAC0_MR1_APP 0x08000000
106 #define EMAC0_MR1_IST 0x01000000
107 #define EMAC0_MR1_MF 0x00C00000
108 #define EMAC0_MR1_MF_10MB 0x00000000
109 #define EMAC0_MR1_MF_100MB 0x00400000
110 #define EMAC0_MR1_RFS 0x00300000
111 #define EMAC0_MR1_RFS_512 0x00000000
112 #define EMAC0_MR1_RFS_1024 0x00100000
113 #define EMAC0_MR1_RFS_2048 0x00200000
114 #define EMAC0_MR1_RFS_4096 0x00300000
115 #define EMAC0_MR1_TFS 0x000C0000
116 #define EMAC0_MR1_TFS_1024 0x00040000
117 #define EMAC0_MR1_TFS_2048 0x00080000
118 #define EMAC0_MR1_TR0 0x00018000
119 #define EMAC0_MR1_TR0_SINGLE 0x00000000
120 #define EMAC0_MR1_TR0_MULTI 0x00008000
121 #define EMAC0_MR1_TR0_DEP 0x00010000
122 #define EMAC0_MR1_TR1 0x00006000
123 #define EMAC0_MR1_TR1_SINGLE 0x00000000
124 #define EMAC0_MR1_TR1_MULTI 0x00002000
125 #define EMAC0_MR1_TR1_DEP 0x00004000
128 // Transmit mode register 0
130 #define EMAC0_TMR0_GNP0 0x80000000
131 #define EMAC0_TMR0_GNP1 0x40000000
132 #define EMAC0_TMR0_GNPD 0x20000000
133 #define EMAC0_TMR0_FC 0x10000000
136 // Transmit mode register 1
138 #define EMAC0_TMR1_TLR 0xF8000000
139 #define EMAC0_TMR1_TLR_SHIFT (32-5)
140 #define EMAC0_TMR1_TUR 0x00FF0000
141 #define EMAC0_TMR1_TUR_SHIFT (32-16)
144 // Receive mode register
146 #define EMAC0_RMR_SP 0x80000000
147 #define EMAC0_RMR_SFCS 0x40000000
148 #define EMAC0_RMR_RRP 0x20000000
149 #define EMAC0_RMR_RFP 0x10000000
150 #define EMAC0_RMR_ROP 0x08000000
151 #define EMAC0_RMR_RPIR 0x04000000
152 #define EMAC0_RMR_PPP 0x02000000
153 #define EMAC0_RMR_PME 0x01000000
154 #define EMAC0_RMR_PMME 0x00800000
155 #define EMAC0_RMR_IAE 0x00400000
156 #define EMAC0_RMR_MIAE 0x00200000
157 #define EMAC0_RMR_BAE 0x00100000
158 #define EMAC0_RMR_MAE 0x00080000
163 #define EMAC0_ISR_OVR 0x02000000 // Rx overrun
164 #define EMAC0_ISR_PP 0x01000000 // Pause packet received
165 #define EMAC0_ISR_BP 0x00800000 // Rx bad packet
166 #define EMAC0_ISR_RP 0x00400000 // Rx runt packet
167 #define EMAC0_ISR_SE 0x00200000 // Rx short event
168 #define EMAC0_ISR_ALE 0x00100000 // Rx alignment error
169 #define EMAC0_ISR_BFCS 0x00080000 // Rx bad FCS
170 #define EMAC0_ISR_PTLE 0x00040000 // Rx packet too long
171 #define EMAC0_ISR_ORE 0x00020000 // Rx packet out of range
172 #define EMAC0_ISR_IRE 0x00010000 // Rx packet in range error
173 #define EMAC0_ISR_DBDM 0x00000200
174 #define EMAC0_ISR_DB0 0x00000100
175 #define EMAC0_ISR_SE0 0x00000080
176 #define EMAC0_ISR_TE0 0x00000040
177 #define EMAC0_ISR_DB1 0x00000020
178 #define EMAC0_ISR_SE1 0x00000010
179 #define EMAC0_ISR_TE1 0x00000008
180 #define EMAC0_ISR_MOS 0x00000002
181 #define EMAC0_ISR_MOF 0x00000001
184 // Interrupt status enable - same as interrupt status
188 // STA control register - MII interface
190 #define EMAC0_STACR_PHYD 0xFFFF0000
191 #define EMAC0_STACR_PHYD_SHIFT (32-16)
192 #define EMAC0_STACR_OC 0x00008000
193 #define EMAC0_STACR_PHYE 0x00004000
194 #define EMAC0_STACR_STAC 0x00003000
195 #define EMAC0_STACR_STAC_READ 0x00001000
196 #define EMAC0_STACR_STAC_WRITE 0x00002000
197 #define EMAC0_STACR_OPBC 0x00000C00
198 #define EMAC0_STACR_OPBC_50 0x00000000
199 #define EMAC0_STACR_OPBC_66 0x00000400
200 #define EMAC0_STACR_OPBC_83 0x00000800
201 #define EMAC0_STACR_OPBC_100 0x00000C00
202 #define EMAC0_STACR_PCDA 0x000003E0
203 #define EMAC0_STACR_PCDA_SHIFT (32-27)
204 #define EMAC0_STACR_PRA 0x0000001F
207 // Transmit request threshold
209 #define EMAC0_TRTR_TRT 0xF8000000 // 0=64, 1=128, 2=192, etc
210 #define EMAC0_TRTR_TRT_SHIFT (32-5)
211 #define EMAC0_TRTR_TRT_SCALE 64
214 // Receive high/low water marks
216 #define EMAC0_RWMR_RLWM 0xFF800000
217 #define EMAC0_RWMR_RLWM_SHIFT (32-9)
218 #define EMAC0_RWMR_RHWM 0x0000FF80
219 #define EMAC0_RWMR_RHWM_SHIFT (32-25)
222 // Memory Access Layer (MAL) - in DCR space
224 #define MAL0_CFG 0x180
225 #define MAL0_ESR 0x181
226 #define MAL0_IER 0x182
227 #define MAL0_TXCASR 0x184
228 #define MAL0_TXCARR 0x185
229 #define MAL0_TXEOBISR 0x186
230 #define MAL0_TXDEIR 0x187
231 #define MAL0_RXCASR 0x190
232 #define MAL0_RXCARR 0x191
233 #define MAL0_RXEOBISR 0x192
234 #define MAL0_RXDEIR 0x193
235 #define MAL0_TXCTP0R 0x1A0
236 #define MAL0_TXCTP1R 0x1A1
237 #define MAL0_RXCTP0R 0x1C0
238 #define MAL0_RXBS0 0x1E0
243 #define MAL_CFG_SR 0x80000000
244 #define MAL_CFG_PLBP 0x00C00000
245 #define MAL_CFG_PLBP_0 0x00000000
246 #define MAL_CFG_PLBP_1 0x00400000
247 #define MAL_CFG_PLBP_2 0x00800000
248 #define MAL_CFG_PLBP_3 0x00C00000
249 #define MAL_CFG_GA 0x00200000
250 #define MAL_CFG_OA 0x00100000
251 #define MAL_CFG_PLBLE 0x00080000
252 #define MAL_CFG_PLBLT 0x00078000
253 #define MAL_CFG_PLBLT_SHIFT (32-17)
254 #define MAL_CFG_PLBT_DEFAULT (0x07<<MAL_CFG_PLBLT_SHIFT)
255 #define MAL_CFG_PLBB 0x00004000
256 #define MAL_CFG_OPBBL 0x00000080
257 #define MAL_CFG_EOPIE 0x00000004
258 #define MAL_CFG_LEA 0x00000002
259 #define MAL_CFG_SD 0x00000001
262 // Channel active set/reset
264 #define MAL_CASR_C0 0x80000000
265 #define MAL_CASR_C1 0x40000000
268 // Error and interrupt status
270 #define MAL_ESR_EVB 0x80000000
271 #define MAL_ESR_CID 0x7E000000
272 #define MAL_ESR_CID_SHIFT (32-7)
273 #define MAL_ESR_DE 0x00100000
274 #define MAL_ESR_ONE 0x00080000
275 #define MAL_ESR_OTE 0x00040000
276 #define MAL_ESR_OSE 0x00020000
277 #define MAL_ESR_PEIN 0x00010000
278 #define MAL_ESR_DEI 0x00000010
279 #define MAL_ESR_ONEI 0x00000008
280 #define MAL_ESR_OTEI 0x00000004
281 #define MAL_ESR_OSEI 0x00000002
282 #define MAL_ESR_PBEI 0x00000001
283 #define MAL_ESR_INT_MASK 0x0000001F
287 // MAL Buffer Descriptor
289 typedef struct mal_bd {
290 unsigned short status;
291 unsigned short length;
292 unsigned long buffer;
298 #define MAL_BD_R 0x8000
299 #define MAL_BD_W 0x4000
300 #define MAL_BD_CM 0x2000
301 #define MAL_BD_L 0x1000
302 #define MAL_BD_F 0x0800
303 #define MAL_BD_I 0x0400
304 // EMAC TX bits (command - set before activating buffer)
305 #define MAL_BD_TX_GFCS 0x0200
306 #define MAL_BD_TX_GPAD 0x0100
307 #define MAL_BD_TX_ISA 0x0080
308 #define MAL_BD_TX_RSA 0x0040
309 #define MAL_BD_TX_IVLA 0x0020
310 #define MAL_BD_TX_RVLA 0x0010
311 // EMAC TX bits (status - valid after buffer completes)
312 #define MAL_BD_TX_BFCS 0x0200
313 #define MAL_BD_TX_BPP 0x0100
314 #define MAL_BD_TX_LOC 0x0080
315 #define MAL_BD_TX_EDEF 0x0040
316 #define MAL_BD_TX_ECOL 0x0020
317 #define MAL_BD_TX_LATE 0x0010
318 #define MAL_BD_TX_MULT 0x0008
319 #define MAL_BD_TX_SNGL 0x0004
320 #define MAL_BD_TX_URUN 0x0002
321 #define MAL_BD_TX_SQE 0x0001
322 // EMAC RX bits (only after buffer completes)
323 #define MAL_BD_RX_ORUN 0x0200
324 #define MAL_BD_RX_PP 0x0100
325 #define MAL_BD_RX_BP 0x0080
326 #define MAL_BD_RX_RP 0x0040
327 #define MAL_BD_RX_SE 0x0020
328 #define MAL_BD_RX_ALE 0x0010
329 #define MAL_BD_RX_BFCS 0x0008
330 #define MAL_BD_RX_PTL 0x0004
331 #define MAL_BD_RX_ORNG 0x0002
332 #define MAL_BD_RX_IRNG 0x0001
335 // Private information kept about interface
337 struct ppc405_eth_info {
338 // These fields should be defined by the implementation
340 char *esa_key; // RedBoot 'key' for device ESA
341 unsigned char *enaddr;
342 int rxnum; // Number of Rx buffers
343 unsigned char *rxbuf; // Rx buffer space
344 mal_bd_t *rxbd_table; // Rx buffer headers
345 int txnum; // Number of Tx buffers
346 unsigned char *txbuf; // Tx buffer space
347 mal_bd_t *txbd_table; // Tx buffer headers
348 eth_phy_access_t *phy; // Routines to access PHY
349 // The following fields are maintained by the driver
350 volatile mal_bd_t *txbd, *rxbd; // Next Tx,Rx descriptor to use
351 volatile mal_bd_t *tbase, *rbase; // First Tx,Rx descriptor
352 volatile mal_bd_t *tnext, *rnext; // Next descriptor to check for interrupt
353 int txsize, rxsize; // Length of individual buffers
354 int txactive; // Count of active Tx buffers
355 unsigned long txkey[CYGNUM_DEVS_ETH_POWERPC_PPC405_TxNUM];
356 #ifdef CYGINT_IO_ETH_INT_SUPPORT_REQUIRED
357 unsigned long ints; // Mask of interrupts in progress
359 unsigned char cfg_enaddr[6]; // Last configured ESA