]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/devs/eth/ns/dp83816/v2_0/src/dp83816.h
Initial revision
[karo-tx-redboot.git] / packages / devs / eth / ns / dp83816 / v2_0 / src / dp83816.h
1 //==========================================================================
2 //
3 //      dev/dp83816.h
4 //
5 //      National Semiconductor DP83816 ethernet chip
6 //
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.
12 // Copyright (C) 2003 Gary Thomas
13 //
14 // eCos is free software; you can redistribute it and/or modify it under
15 // the terms of the GNU General Public License as published by the Free
16 // Software Foundation; either version 2 or (at your option) any later version.
17 //
18 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
19 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
21 // for more details.
22 //
23 // You should have received a copy of the GNU General Public License along
24 // with eCos; if not, write to the Free Software Foundation, Inc.,
25 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 //
27 // As a special exception, if other files instantiate templates or use macros
28 // or inline functions from this file, or you compile this file and link it
29 // with other works to produce a work based on this file, this file does not
30 // by itself cause the resulting work to be covered by the GNU General Public
31 // License. However the source code for this file must still be made available
32 // in accordance with section (3) of the GNU General Public License.
33 //
34 // This exception does not invalidate any other reasons why a work based on
35 // this file might be covered by the GNU General Public License.
36 //
37 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
38 // at http://sources.redhat.com/ecos/ecos-license/
39 // -------------------------------------------
40 //####ECOSGPLCOPYRIGHTEND####
41 //==========================================================================
42 //#####DESCRIPTIONBEGIN####
43 //
44 // Author(s):    gthomas
45 // Contributors: 
46 // Date:         2003-09-29
47 // Purpose:      
48 // Description:  
49 //
50 //####DESCRIPTIONEND####
51 //
52 //==========================================================================
53
54 #include <cyg/hal/hal_io.h>
55 #include <pkgconf/devs_eth_ns_dp83816.h>
56
57 // ------------------------------------------------------------------------
58 // Debugging details
59
60 // Set to perms of:
61 // 0 disables all debug output
62 // 1 for process debug output
63 // 2 for added data IO output: get_reg, put_reg
64 // 4 for packet allocation/free output
65 // 8 for only startup status, so we can tell we're installed OK
66 #define DEBUG 0x0
67
68 #if DEBUG & 1
69 #define DEBUG_FUNCTION() do { diag_printf("%s\n", __FUNCTION__); } while (0)
70 #define DEBUG_LINE() do { diag_printf("%d\n", __LINE__); } while (0)
71 #else
72 #define DEBUG_FUNCTION() do {} while(0)
73 #define DEBUG_LINE() do {} while(0)
74 #endif
75
76 // ------------------------------------------------------------------------
77 // Buffer descriptors
78 typedef struct dp83816_bd {
79     struct dp83816_bd *next;  // Next descriptor
80     unsigned long      stat;  // Buffer status & flags
81     unsigned char     *buf;   // Buffer memory
82     unsigned long      key;   // Internal use only
83 } dp83816_bd_t;
84
85 // ------------------------------------------------------------------------
86 // Private driver structure
87 typedef struct dp83816_priv_data {
88     char                     *esa_key;        // RedBoot 'key' for device ESA
89     unsigned char            *enaddr;
90     int                       rxnum;          // Number of Rx buffers
91     unsigned char            *rxbuf;          // Rx buffer space
92     dp83816_bd_t             *rxd;            // Rx descriptor pool
93     int                       txnum;          // Number of Tx buffers
94     unsigned char            *txbuf;          // Tx buffer space
95     dp83816_bd_t             *txd;            // Tx descriptor pool
96     cyg_uint8                *base;
97     int                       interrupt;      // Interrupt vector
98 #ifdef CYGINT_IO_ETH_INT_SUPPORT_REQUIRED
99     cyg_handle_t  interrupt_handle;
100     cyg_interrupt interrupt_object;
101 #endif
102     dp83816_bd_t             *rxnext;         // Next Rx to interrupt
103     dp83816_bd_t             *txfill;         // Next Tx to fill
104     dp83816_bd_t             *txint;          // Next Tx to interrupt
105     int                       txbusy;         // Number of busy Tx buffers 
106 } dp83816_priv_data_t;
107
108 // ------------------------------------------------------------------------
109 // Macros for accessing DP registers
110 // These can be overridden by the platform header
111 // Note: the only accesses used must be 32 bit little endian.
112
113 #ifndef DP_IN
114 # define DP_IN(_b_, _o_, _d_)  HAL_READ_UINT32((cyg_addrword_t)(_b_)+(_o_), (_d_))
115 # define DP_OUT(_b_, _o_, _d_) HAL_WRITE_UINT32((cyg_addrword_t)(_b_)+(_o_), (_d_))
116 #endif
117
118 // ------------------------------------------------------------------------
119 // Macros allowing platform to customize some of the driver details
120
121 #ifndef CYGHWR_NS_DP83816_PLF_RESET
122 # define CYGHWR_NS_DP83816_PLF_RESET(_b_) do { } while (0)
123 #endif
124
125 #ifndef CYGHWR_NS_DP83816_PLF_INT_CLEAR
126 # define CYGHWR_NS_DP83816_PLF_INT_CLEAR(_dp_)
127 #endif
128
129 #ifndef CYGHWR_NS_DP83816_PLF_INIT
130 #define CYGHWR_NS_DP83816_PLF_INIT(dp) do { } while (0)
131 #endif
132
133
134 // ------------------------------------------------------------------------
135 // Some forward declarations
136 static void dp83816_poll(struct eth_drv_sc *sc);
137
138 // ------------------------------------------------------------------------
139 // Register offsets
140
141 #define DP_CR          0x00  // Command register
142 #define   _CR_RST         0x100  // Chip reset
143 #define   _CR_RXR         0x020  // Rx reset
144 #define   _CR_TXR         0x010  // Tx reset
145 #define   _CR_RXD         0x008  // Rx disable
146 #define   _CR_RXE         0x004  // Rx enable
147 #define   _CR_TXD         0x002  // Tx disable
148 #define   _CR_TXE         0x001  // Tx enable
149 #define DP_CFG         0x04  // Configuration register
150 #define   _CFG_LNKSTS  (1<<31) // Link status
151 #define   _CFG_SPD100  (1<<30) // 100Mb 
152 #define   _CFG_FDUP    (1<<29) // Full duplex
153 #define   _CFG_POL     (1<<28) // 10Mb polarity
154 #define   _CFG_ANDONE  (1<<27) // Auto-negotiation done
155 #define DP_MEAR        0x08  // EEPROM access
156 #define   _MEAR_EESEL  (1<<3) // EEPROM chip select
157 #define   _MEAR_EECLK  (1<<2) // EEPROM serial clock
158 #define   _MEAR_EEDO   (1<<1) // EEPROM data out
159 #define   _MEAR_EEDI   (1<<0) // EEPROM data in
160 #define DP_ISR         0x10  // Interrupt status
161 #define   _ISR_TXRCMP (1<<25) // Tx reset complete
162 #define   _ISR_RXRCMP (1<<24) // Rx reset complete
163 #define   _ISR_DPERR  (1<<23) // Detected parity error
164 #define   _ISR_SSERR  (1<<22) // Signalled system error
165 #define   _ISR_RMABT  (1<<21) // Received master abort
166 #define   _ISR_RTABT  (1<<20) // Received target abort
167 #define   _ISR_RXSOVR (1<<16) // Rx status FIFO overrun
168 #define   _ISR_HIBERR (1<<15) // High bits set (25-16)
169 #define   _ISR_PHY    (1<<14) // PHY interrupt
170 #define   _ISR_PME    (1<<13) // Power management event
171 #define   _ISR_SWI    (1<<12) // Software interrpt
172 #define   _ISR_MIB    (1<<11) // MII service 
173 #define   _ISR_TXURN  (1<<10) // Tx underrun
174 #define   _ISR_TXIDLE  (1<<9) // Tx idle (end of list)
175 #define   _ISR_TXERR   (1<<8) // Tx packet error
176 #define   _ISR_TXDESC  (1<<7) // Tx descriptor with INTS
177 #define   _ISR_TXOK    (1<<6) // Last Tx descriptor done
178 #define   _ISR_RXORN   (1<<5) // Rx overrun
179 #define   _ISR_RXIDLE  (1<<4) // Rx idle (end of list)
180 #define   _ISR_RXEARLY (1<<3) // Rx early threshold met
181 #define   _ISR_RXERR   (1<<2) // Rx packet error
182 #define   _ISR_RXDESC  (1<<1) // Rx descriptor with INTS
183 #define   _ISR_RXOK    (1<<0) // Last Rx descriptor done
184 #define DP_IMR         0x14  // Interrupt mask
185 #define DP_IER         0x18  // Interrupt enable
186 #define DP_IHR         0x1C  // Interrupt hold
187 #define DP_TXDP        0x20  // Tx descriptor pointer
188 #define DP_TXCFG       0x24  // Tx configuration
189 #define   _TXCFG_CSI    (1<<31) // Ignore carrier sense
190 #define   _TXCFG_HBI    (1<<30) // Ignore heartbeat
191 #define   _TXCFG_MLB    (1<<29) // Loopback
192 #define   _TXCFG_ATP    (1<<28) // Automatic padding
193 #define   _TXCFG_ECRTRY (1<<23) // Excessive collision enable
194 #define   _TXCFG_MXDMA_SHIFT 20
195 #define   _TXCFG_MXDMA_MASK 0x7
196 #define   _TXCFG_MXDMA_512  (0x0<<20)
197 #define   _TXCFG_MXDMA_4    (0x1<<20)
198 #define   _TXCFG_MXDMA_8    (0x2<<20)
199 #define   _TXCFG_MXDMA_16   (0x3<<20)
200 #define   _TXCFG_MXDMA_32   (0x4<<20)
201 #define   _TXCFG_MXDMA_64   (0x5<<20)
202 #define   _TXCFG_MXDMA_128  (0x6<<20)
203 #define   _TXCFG_MXDMA_256  (0x7<<20)
204 #define   _TXCFG_FLTH_SHIFT   8
205 #define   _TXCFG_FLTH_MASK 0x3F
206 #define   _TXCFG_DRTH_SHIFT   0
207 #define   _TXCFG_DRTH_MASK 0x3F
208 #define DP_RXDP        0x30  // Rx descriptor pointer
209 #define DP_RXCFG       0x34  // Rx configuration
210 #define   _RXCFG_AEP    (1<<31) // Accept error packets
211 #define   _RXCFG_ARP    (1<<30) // Accept runt packets
212 #define   _RXCFG_ATX    (1<<28) // Accept Tx packets (loopback)
213 #define   _RXCFG_ALP    (1<<27) // Accpet long packets (> 1518 bytes)
214 #define   _RXCFG_MXDMA_SHIFT 20
215 #define   _RXCFG_MXDMA_MASK 0x7
216 #define   _RXCFG_MXDMA_512  (0x0<<20)
217 #define   _RXCFG_MXDMA_4    (0x1<<20)
218 #define   _RXCFG_MXDMA_8    (0x2<<20)
219 #define   _RXCFG_MXDMA_16   (0x3<<20)
220 #define   _RXCFG_MXDMA_32   (0x4<<20)
221 #define   _RXCFG_MXDMA_64   (0x5<<20)
222 #define   _RXCFG_MXDMA_128  (0x6<<20)
223 #define   _RXCFG_MXDMA_256  (0x7<<20)
224 #define   _RXCFG_FLTH_SHIFT   8
225 #define   _RXCFG_FLTH_MASK 0x3F
226 #define   _RXCFG_DRTH_SHIFT   0
227 #define   _RXCFG_DRTH_MASK 0x3F
228 #define DP_RFCR        0x48  // Receive filter control
229 #define   _RFCR_RFEN  (1<<31) // Rx filter enable
230 #define   _RFCR_AAB   (1<<30) // Accept all broadcast
231 #define   _RFCR_AAM   (1<<29) // Accept all multicast
232 #define   _RFCR_AAU   (1<<28) // Accept all unicast
233 #define   _RFCR_APM   (1<<27) // Accept on perfect match
234 #define   _RFCR_APAT  (1<<26) // Accept on patern match
235 #define   _RFCR_AARP  (1<<22) // Accept ARP
236 #define   _RFCR_MHEN  (1<<21) // Multicast hash enable
237 #define   _RFCR_UHEN  (1<<20) // Unicast hash enable
238 #define   _RFCR_ULM   (1<<19) // U/L bit ignore
239 #define DP_RFDR        0x4C  // Receive filter data register
240
241 // Buffer descriptor status/flags
242 #define BD_OWN        (1<<31) // Owned by producer (Tx=driver, Rx=DP83816)
243 #define BD_MORE       (1<<30) // More descriptors in this frame
244 #define BD_INTR       (1<<29) // Interrupt when this descriptor processed
245 #define BD_CRC        (1<<28) // Include CRC
246 #define BD_OK         (1<<27) // Packet OK
247 // Tx buffer flags
248 #define BD_TXA        (1<<26) // Tx abort
249 #define BD_TFU        (1<<25) // Tx underrun
250 #define BD_CRS        (1<<24) // Carrier sense lost
251 #define BD_TD         (1<<23) // Transmission deferred
252 #define BD_ED         (1<<22) // Excessive Tx deferrals
253 #define BD_OWC        (1<<21) // Out of window collision
254 #define BD_EC         (1<<20) // Excessive collisions
255 #define BD_CCNT_MASK    0x0F
256 #define BD_CCNT_SHIFT     16  // Collision count
257 // Rx buffer flags
258 #define BD_RXA         (1<<26) // Rx abort
259 #define BD_RXO         (1<<25) // Rx overrun
260 #define BD_DEST_MASK   (3<<23)
261 #define BD_DEST_REJECT    (0<<23) // Packet rejected
262 #define BD_DEST_UNICAST   (1<<23) // Unicast packet
263 #define BD_DEST_MULTICAST (2<<23) // Multicast packet
264 #define BD_DEST_BROADCAST (3<<23) // Broadcast packet
265 #define BD_LONG        (1<<22) // Too long packet received
266 #define BD_RUNT        (1<<21) // Runt packet
267 #define BD_ISE         (1<<20) // Illegal symbol
268 #define BD_CRCE        (1<<19) // CRC error
269 #define BD_FAE         (1<<18) // Frame alignment error
270 #define BD_LBP         (1<<17) // Loopback frame
271 #define BD_COL         (1<<16) // Collision during frame
272 // Length field
273 #define BD_LENGTH_MASK 0x0FFF
274
275 #define IEEE_8023_MAX_FRAME         1518    // Largest possible ethernet frame
276 #define IEEE_8023_MIN_FRAME           64    // Smallest possible ethernet frame
277
278 #define _DP83816_BUFSIZE            1540    // Size of buffers