summaryrefslogtreecommitdiff
path: root/ecos/packages/devs/eth/powerpc/fec/current/src/fec.h
blob: dd5826a01e01cfb6ff149326eae90d94e00dfcd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//==========================================================================
//
//      fec.h
//
//      PowerPC MPC8xxT fast ethernet (FEC)
//
//==========================================================================
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
// -------------------------------------------                              
// This file is part of eCos, the Embedded Configurable Operating System.   
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under    
// the terms of the GNU General Public License as published by the Free     
// Software Foundation; either version 2 or (at your option) any later      
// version.                                                                 
//
// eCos is distributed in the hope that it will be useful, but WITHOUT      
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
// for more details.                                                        
//
// You should have received a copy of the GNU General Public License        
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
//
// As a special exception, if other files instantiate templates or use      
// macros or inline functions from this file, or you compile this file      
// and link it with other works to produce a work based on this file,       
// this file does not by itself cause the resulting work to be covered by   
// the GNU General Public License. However the source code for this file    
// must still be made available in accordance with section (3) of the GNU   
// General Public License v2.                                               
//
// This exception does not invalidate any other reasons why a work based    
// on this file might be covered by the GNU General Public License.         
// -------------------------------------------                              
// ####ECOSGPLCOPYRIGHTEND####                                              
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s):    gthomas
// Contributors: gthomas
// Date:         2001-01-21
// Purpose:      
// Description:  
//              
//
//####DESCRIPTIONEND####
//
//==========================================================================

// PowerPC FEC (MPC8xxT) Fast Ethernet

// Buffer descriptor
struct fec_bd {
    unsigned short  ctrl;
    unsigned short  length;
    unsigned char  *buffer;
};

// control flags differ for Rx and Tx buffers
#define FEC_BD_Rx_Empty  0x8000  // Buffer is empty [FEC can fill it]
#define FEC_BD_Rx_Wrap   0x2000  // Last buffer in ring [wrap]
#define FEC_BD_Rx_Last   0x0800  // Last buffer in frame
#define FEC_BD_Rx_Miss   0x0100  // 
#define FEC_BD_Rx_BC     0x0080
#define FEC_BD_Rx_MC     0x0040
#define FEC_BD_Rx_LG     0x0020
#define FEC_BD_Rx_NO     0x0010
#define FEC_BD_Rx_SH     0x0008  // Short frame
#define FEC_BD_Rx_CR     0x0004  // CRC error
#define FEC_BD_Rx_OV     0x0002  // Overrun
#define FEC_BD_Rx_TR     0x0001  // Frame truncated

#define FEC_BD_Tx_Ready  0x8000  // Frame ready
#define FEC_BD_Tx_Wrap   0x2000  // Last buffer in ring
#define FEC_BD_Tx_Intr   0x1000  // Generate interrupt
#define FEC_BD_Tx_Last   0x0800  // Last buffer in frame
#define FEC_BD_Tx_TC     0x0400  // Send CRC after data
#define FEC_BD_Tx_DEF    0x0200
#define FEC_BD_Tx_HB     0x0100
#define FEC_BD_Tx_LC     0x0080
#define FEC_BD_Tx_RL     0x0040
#define FEC_BD_Tx_RC     0x003C
#define FEC_BD_Tx_UN     0x0002  // Underrun
#define FEC_BD_Tx_CSL    0x0001  // Carrier sense lost

#define FEC_BD_Tx_STATS  0x03FF  // Status mask

struct fec_eth_info {
    volatile struct fec        *fec;
    volatile struct fec_bd     *txbd, *rxbd;     // Next Tx,Rx descriptor to use
    volatile struct fec_bd     *tbase, *rbase;   // First Tx,Rx descriptor
    volatile struct fec_bd     *tnext, *rnext;   // Next descriptor to check for interrupt
    int                         txsize, rxsize;  // Length of individual buffers
    int                         txactive;        // Count of active Tx buffers
    unsigned long               txkey[CYGNUM_DEVS_ETH_POWERPC_FEC_TxNUM];
};

// Fast Ethernet Controller [in PPC8xxT parameter RAM space]

struct fec {
    unsigned long  addr[2];    // ESA
    unsigned long  hash[2];    // Address hash mask
    volatile struct fec_bd *RxRing;
    volatile struct fec_bd *TxRing;
    unsigned long  RxBufSize;
    unsigned char  _fill0[0x40-0x1C];
    unsigned long  eControl;   // Master control register
    unsigned long  iEvent;     // Interrupt event
    unsigned long  iMask;      // Interrupt mask
    unsigned long  iVector;    // Interrupt vector
    unsigned long  RxUpdate;   // RxRing updated
    unsigned long  TxUpdate;   // TxRing updated
    unsigned char  _fill1[0x80-0x58];
    unsigned long  MiiData;
    unsigned long  MiiSpeed;
    unsigned char  _fill2[0xCC-0x88];
    unsigned long  RxBound;    // End of FIFO RAM
    unsigned long  RxStart;    // Start of FIFO RAM
    unsigned char  _fill3[0xE4-0xD4];
    unsigned long  TxWater;    // Transmit watermark
    unsigned char  _fill4[0xEC-0xE8];
    unsigned long  TxStart;    // Start of Tx FIFO
    unsigned char  _fill5[0x134-0xF0];
    unsigned long  FunCode;    // DMA function codes
    unsigned char  _fill6[0x144-0x138];
    unsigned long  RxControl;  // Receiver control
    unsigned long  RxHash;     // Receive hash
    unsigned char  _fill7[0x184-0x14C];
    unsigned long  TxControl;  // Transmitter control
};

#define FEC_OFFSET 0x0E00      // Offset in 8xx parameter RAM

// Master control register (eControl)
#define eControl_MUX    0x0004 // Select proper pin MUX functions
#define eControl_EN     0x0002 // Enable ethernet controller
#define eControl_RESET  0x0001 // Reset controller

// Receiver control register (RxControl)
#define RxControl_BC_REJ 0x0010 // Reject broadcast frames
#define RxControl_PROM   0x0008 // Promiscuous mode
#define RxControl_MII    0x0004 // MII (1) or 7 wire (0) mode 
#define RxControl_DRT    0x0002 // Disable receive on transmit
#define RxControl_LOOP   0x0001 // Internal loopback

// Interrupt events
#define iEvent_HBERR         0x80000000  // No heartbeat error
#define iEvent_BABR          0x40000000  // Babling receiver
#define iEvent_BABT          0x20000000  // Babling transmitter
#define iEvent_GRA           0x10000000  // Graceful shutdown
#define iEvent_TFINT         0x08000000  // Transmit frame interrupt
#define iEvent_TXB           0x04000000  // Transmit buffer
#define iEvent_RFINT         0x02000000  // Receive frame
#define iEvent_RXB           0x01000000  // Receive buffer
#define iEvent_MII           0x00800000  // MII complete
#define iEvent_EBERR         0x00400000  // Ethernet BUS error
#define iEvent_all           0xFFC00000  // Any interrupt

// MII interface
#define MII_Start            0x40000000
#define MII_Read             0x20000000
#define MII_Write            0x10000000
#define MII_Phy(phy)         (phy << 23)
#define MII_Reg(reg)         (reg << 18)
#define MII_TA               0x00020000

// Transceiver mode
#define PHY_BMCR             0x00    // Register number
#define PHY_BMCR_RESET       0x8000
#define PHY_BMCR_LOOPBACK    0x4000
#define PHY_BMCR_100MB       0x2000
#define PHY_BMCR_AUTO_NEG    0x1000
#define PHY_BMCR_POWER_DOWN  0x0800
#define PHY_BMCR_ISOLATE     0x0400
#define PHY_BMCR_RESTART     0x0200
#define PHY_BMCR_FULL_DUPLEX 0x0100
#define PHY_BMCR_COLL_TEST   0x0080

#define PHY_BMSR             0x01    // Status register
#define PHY_BMSR_AUTO_NEG    0x0020  
#define PHY_BMSR_LINK        0x0004

#define IEEE_8023_MAX_FRAME         1518    // Largest possible ethernet frame
#define IEEE_8023_MIN_FRAME           60    // Smallest possible ethernet frame