]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/devs/eth/ns/dp83902a/v2_0/include/dp83902a.h
Initial revision
[karo-tx-redboot.git] / packages / devs / eth / ns / dp83902a / v2_0 / include / dp83902a.h
1 //==========================================================================
2 //
3 //      dev/dp83902a.h
4 //
5 //      National Semiconductor DP83902a 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 //
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.
16 //
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
20 // for more details.
21 //
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.
25 //
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.
32 //
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.
35 //
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 //####BSDCOPYRIGHTBEGIN####
41 //
42 // -------------------------------------------
43 //
44 // Portions of this software may have been derived from OpenBSD or other sources,
45 // and are covered by the appropriate copyright disclaimers included herein.
46 //
47 // -------------------------------------------
48 //
49 //####BSDCOPYRIGHTEND####
50 //==========================================================================
51 //#####DESCRIPTIONBEGIN####
52 //
53 // Author(s):    gthomas
54 // Contributors: gthomas, jskov
55 // Date:         2001-06-13
56 // Purpose:      
57 // Description:  
58 //
59 //####DESCRIPTIONEND####
60 //
61 //==========================================================================
62
63 #include <cyg/hal/hal_io.h>
64 #include <pkgconf/devs_eth_ns_dp83902a.h>
65
66 #define __WANT_CONFIG
67 #include CYGDAT_DEVS_ETH_NS_DP83902A_INL
68 #undef __WANT_CONFIG
69
70 // ------------------------------------------------------------------------
71 // Debugging details
72
73 // Set to perms of:
74 // 0 disables all debug output
75 // 1 for process debug output
76 // 2 for added data IO output: get_reg, put_reg
77 // 4 for packet allocation/free output
78 // 8 for only startup status, so we can tell we're installed OK
79 #define DEBUG 0x0
80
81 #if DEBUG & 1
82 #define DEBUG_FUNCTION() do { diag_printf("%s\n", __FUNCTION__); } while (0)
83 #define DEBUG_LINE() do { diag_printf("%d\n", __LINE__); } while (0)
84 #else
85 #define DEBUG_FUNCTION() do {} while(0)
86 #define DEBUG_LINE() do {} while(0)
87 #endif
88
89 // ------------------------------------------------------------------------
90 // MAcros for keeping track of statistics
91 #if defined(ETH_DRV_GET_IF_STATS) || defined (ETH_DRV_GET_IF_STATS_UD)
92 #define KEEP_STATISTICS
93 #endif
94
95 #ifdef KEEP_STATISTICS
96 #define INCR_STAT( _x_ )        (dp->stats. _x_ ++)
97 #else
98 #define INCR_STAT( _x_ )        CYG_EMPTY_STATEMENT
99 #endif
100
101 // ------------------------------------------------------------------------
102 // Private driver structure
103 typedef struct dp83902a_priv_data {
104     cyg_uint8* base;
105     cyg_uint8* data;
106     cyg_uint8* reset;
107     int tx_next;           // First free Tx page
108     int tx_int;            // Expecting interrupt from this buffer
109     int rx_next;           // First free Rx page
110     int tx1, tx2;          // Page numbers for Tx buffers
111     unsigned long tx1_key, tx2_key;   // Used to ack when packet sent
112     int tx1_len, tx2_len;
113     bool tx_started, running, hardwired_esa;
114     struct cyg_netdevtab_entry *tab;
115     cyg_uint8 esa[6];
116     cyg_vector_t interrupt;             // Interrupt vector used by controller
117     cyg_handle_t  interrupt_handle;
118     cyg_interrupt interrupt_object;
119     void* plf_priv;
120
121     // For debugging
122     volatile int cr_lock;
123     volatile int cr_owner;
124
125     // Buffer allocation
126     int tx_buf1, tx_buf2;
127     int rx_buf_start, rx_buf_end;
128 } dp83902a_priv_data_t;
129
130 // ------------------------------------------------------------------------
131 // Macros for accessing structure elements
132
133 #define _SU8( _base_, _offset_) \
134         *((volatile cyg_uint8 *)((CYG_ADDRWORD)_base_+(_offset_)))
135 #define _SU16( _base_, _offset_) \
136         *((volatile cyg_uint16 *)((CYG_ADDRWORD)_base_+(_offset_)))
137 #define _SU32( _base_, _offset_) \
138         *((volatile cyg_uint32 *)((CYG_ADDRWORD)_base_+(_offset_)))
139
140 #define _SI8( _base_, _offset_) \
141         *((volatile cyg_int8 *)((CYG_ADDRWORD)_base_+(_offset_)))
142 #define _SI16( _base_, _offset_) \
143         *((volatile cyg_int16 *)((CYG_ADDRWORD)_base_+(_offset_)))
144 #define _SI32( _base_, _offset_) \
145         *((volatile cyg_int32 *)((CYG_ADDRWORD)_base_+(_offset_)))
146
147 // ------------------------------------------------------------------------
148 // Macros for accessing DP registers
149 // These can be overridden by the platform header
150
151 #ifndef DP_IN
152 # define DP_IN(_b_, _o_, _d_)  HAL_READ_UINT8 ((cyg_addrword_t)(_b_)+(_o_), (_d_))
153 # define DP_OUT(_b_, _o_, _d_) HAL_WRITE_UINT8((cyg_addrword_t)(_b_)+(_o_), (_d_))
154 #endif
155
156 #ifndef DP_IN_DATA
157 # ifdef CYGHWR_NS_DP83902A_PLF_16BIT_DATA
158 #  ifdef BIGEND
159 #   define DP_IN_DATA(_b_, _d_)                                 \
160     CYG_MACRO_START                                             \
161     cyg_uint16 _t;                                              \
162     HAL_READ_UINT16 ((cyg_addrword_t)(_b_), _t);                \
163     DELAY();                                                    \
164     (_d_) = ((_t >> 8) & 0xff) | ((_t & 0xff) << 8);            \
165     CYG_MACRO_END
166
167 #   define DP_OUT_DATA(_b_, _d_)                                \
168     CYG_MACRO_START                                             \
169     cyg_uint16 _t;                                              \
170     _t = (_d_);                                                 \
171     (_t) = (((_t) >> 8) & 0xff) | ((_t & 0xff) << 8);           \
172     HAL_WRITE_UINT16((cyg_addrword_t)(_b_), _t);                \
173     DELAY();                                                    \
174     CYG_MACRO_END
175 #  else
176 #   define DP_IN_DATA(_b_, _d_)  HAL_READ_UINT16  ((cyg_addrword_t)(_b_), (_d_))
177 #   define DP_OUT_DATA(_b_, _d_) HAL_WRITE_UINT16 ((cyg_addrword_t)(_b_), (_d_))
178 #  endif
179 # else
180 #  define DP_IN_DATA(_b_, _d_)  HAL_READ_UINT8  ((cyg_addrword_t)(_b_), (_d_))
181 #  define DP_OUT_DATA(_b_, _d_) HAL_WRITE_UINT8 ((cyg_addrword_t)(_b_), (_d_))
182 # endif
183 #endif
184
185 // ------------------------------------------------------------------------
186 // Macros allowing platform to customize some of the driver details
187
188 #ifndef CYGHWR_NS_DP83902A_PLF_RESET
189 # define CYGHWR_NS_DP83902A_PLF_RESET(_b_) do { } while (0)
190 #endif
191
192 #ifndef CYGHWR_NS_DP83902A_PLF_INT_CLEAR
193 # define CYGHWR_NS_DP83902A_PLF_INT_CLEAR(_dp_)
194 #endif
195
196 #ifndef CYGHWR_NS_DP83902A_PLF_INIT
197 #define CYGHWR_NS_DP83902A_PLF_INIT(dp) do { } while (0)
198 #endif
199
200 // ------------------------------------------------------------------------
201 // Hack that should go away, probably
202 #define CR_UP()                                                  \
203     CYG_MACRO_START                                              \
204         if (++dp->cr_lock > 1) {                                 \
205           diag_printf("*** Race on CR %s:%d owner %d\n",      \
206                       __FUNCTION__, __LINE__, dp->cr_owner);     \
207           for (;;);                                              \
208         }                                                        \
209         dp->cr_owner = __LINE__;                                 \
210     CYG_MACRO_END
211
212 #define CR_DOWN()                               \
213     dp->cr_lock--;
214
215 // ------------------------------------------------------------------------
216 // Some forward declarations
217 static void dp83902a_poll(struct eth_drv_sc *sc);
218
219 // ------------------------------------------------------------------------
220 // Register offsets
221
222 #define DP_CR          0x00
223 #define DP_CLDA0       0x01
224 #define DP_PSTART      0x01             // write
225 #define DP_CLDA1       0x02
226 #define DP_PSTOP       0x02             // write
227 #define DP_BNDRY       0x03
228 #define DP_TSR         0x04
229 #define DP_TPSR        0x04             // write
230 #define DP_NCR         0x05
231 #define DP_TBCL        0x05             // write
232 #define DP_FIFO        0x06
233 #define DP_TBCH        0x06             // write
234 #define DP_ISR         0x07
235 #define DP_CRDA0       0x08
236 #define DP_RSAL        0x08             // write
237 #define DP_CRDA1       0x09
238 #define DP_RSAH        0x09             // write
239 #define DP_RBCL        0x0a             // write
240 #define DP_RBCH        0x0b             // write
241 #define DP_RSR         0x0c
242 #define DP_RCR         0x0c             // write
243 #define DP_FER         0x0d
244 #define DP_TCR         0x0d             // write
245 #define DP_CER         0x0e
246 #define DP_DCR         0x0e             // write
247 #define DP_MISSED      0x0f
248 #define DP_IMR         0x0f             // write
249 #define DP_DATAPORT    0x10             // "eprom" data port
250
251 #define DP_P1_CR       0x00
252 #define DP_P1_PAR0     0x01
253 #define DP_P1_PAR1     0x02
254 #define DP_P1_PAR2     0x03
255 #define DP_P1_PAR3     0x04
256 #define DP_P1_PAR4     0x05
257 #define DP_P1_PAR5     0x06
258 #define DP_P1_CURP     0x07
259 #define DP_P1_MAR0     0x08
260 #define DP_P1_MAR1     0x09
261 #define DP_P1_MAR2     0x0a
262 #define DP_P1_MAR3     0x0b
263 #define DP_P1_MAR4     0x0c
264 #define DP_P1_MAR5     0x0d
265 #define DP_P1_MAR6     0x0e
266 #define DP_P1_MAR7     0x0f
267
268 #define DP_P2_CR       0x00
269 #define DP_P2_PSTART   0x01
270 #define DP_P2_CLDA0    0x01             // write
271 #define DP_P2_PSTOP    0x02
272 #define DP_P2_CLDA1    0x02             // write
273 #define DP_P2_RNPP     0x03
274 #define DP_P2_TPSR     0x04
275 #define DP_P2_LNPP     0x05
276 #define DP_P2_ACH      0x06
277 #define DP_P2_ACL      0x07
278 #define DP_P2_RCR      0x0c
279 #define DP_P2_TCR      0x0d
280 #define DP_P2_DCR      0x0e
281 #define DP_P2_IMR      0x0f
282
283 // Command register - common to all pages
284
285 #define DP_CR_STOP    0x01   // Stop: software reset
286 #define DP_CR_START   0x02   // Start: initialize device
287 #define DP_CR_TXPKT   0x04   // Transmit packet
288 #define DP_CR_RDMA    0x08   // Read DMA  (recv data from device)
289 #define DP_CR_WDMA    0x10   // Write DMA (send data to device)
290 #define DP_CR_SEND    0x18   // Send packet
291 #define DP_CR_NODMA   0x20   // Remote (or no) DMA
292 #define DP_CR_PAGE0   0x00   // Page select
293 #define DP_CR_PAGE1   0x40
294 #define DP_CR_PAGE2   0x80
295 #define DP_CR_PAGEMSK 0x3F   // Used to mask out page bits
296
297 // Data configuration register
298
299 #define DP_DCR_WTS    0x01   // 1=16 bit word transfers
300 #define DP_DCR_BOS    0x02   // 1=Little Endian
301 #define DP_DCR_LAS    0x04   // 1=Single 32 bit DMA mode
302 #define DP_DCR_LS     0x08   // 1=normal mode, 0=loopback
303 #define DP_DCR_ARM    0x10   // 0=no send command (program I/O)
304 #define DP_DCR_FIFO_1 0x00   // FIFO threshold
305 #define DP_DCR_FIFO_2 0x20
306 #define DP_DCR_FIFO_4 0x40
307 #define DP_DCR_FIFO_6 0x60
308
309 #ifdef CYGHWR_NS_DP83902A_PLF_16BIT_DATA
310 # ifdef BIGENDIAN
311 #  define DP_DCR_INIT   (DP_DCR_BOS|DP_DCR_WTS|DP_DCR_LS|DP_DCR_FIFO_4)
312 # else
313 #  define DP_DCR_INIT   (DP_DCR_WTS|DP_DCR_LS|DP_DCR_FIFO_4)
314 # endif
315 #else
316 # define DP_DCR_INIT   (DP_DCR_LS|DP_DCR_FIFO_4)
317 #endif
318
319 // Interrupt status register
320
321 #define DP_ISR_RxP    0x01   // Packet received
322 #define DP_ISR_TxP    0x02   // Packet transmitted
323 #define DP_ISR_RxE    0x04   // Receive error
324 #define DP_ISR_TxE    0x08   // Transmit error
325 #define DP_ISR_OFLW   0x10   // Receive overflow
326 #define DP_ISR_CNT    0x20   // Tally counters need emptying
327 #define DP_ISR_RDC    0x40   // Remote DMA complete
328 #define DP_ISR_RESET  0x80   // Device has reset (shutdown, error)
329
330 // Interrupt mask register
331
332 #define DP_IMR_RxP    0x01   // Packet received
333 #define DP_IMR_TxP    0x02   // Packet transmitted
334 #define DP_IMR_RxE    0x04   // Receive error
335 #define DP_IMR_TxE    0x08   // Transmit error
336 #define DP_IMR_OFLW   0x10   // Receive overflow
337 #define DP_IMR_CNT    0x20   // Tall counters need emptying
338 #define DP_IMR_RDC    0x40   // Remote DMA complete
339
340 #define DP_IMR_All    0x3F   // Everything but remote DMA
341
342 // Receiver control register
343
344 #define DP_RCR_SEP    0x01   // Save bad(error) packets
345 #define DP_RCR_AR     0x02   // Accept runt packets
346 #define DP_RCR_AB     0x04   // Accept broadcast packets
347 #define DP_RCR_AM     0x08   // Accept multicast packets
348 #define DP_RCR_PROM   0x10   // Promiscuous mode
349 #define DP_RCR_MON    0x20   // Monitor mode - 1=accept no packets
350
351 // Receiver status register
352
353 #define DP_RSR_RxP    0x01   // Packet received
354 #define DP_RSR_CRC    0x02   // CRC error
355 #define DP_RSR_FRAME  0x04   // Framing error
356 #define DP_RSR_FO     0x08   // FIFO overrun
357 #define DP_RSR_MISS   0x10   // Missed packet
358 #define DP_RSR_PHY    0x20   // 0=pad match, 1=mad match
359 #define DP_RSR_DIS    0x40   // Receiver disabled
360 #define DP_RSR_DFR    0x80   // Receiver processing deferred
361
362 // Transmitter control register
363
364 #define DP_TCR_NOCRC  0x01   // 1=inhibit CRC
365 #define DP_TCR_NORMAL 0x00   // Normal transmitter operation
366 #define DP_TCR_LOCAL  0x02   // Internal NIC loopback
367 #define DP_TCR_INLOOP 0x04   // Full internal loopback
368 #define DP_TCR_OUTLOOP 0x08  // External loopback
369 #define DP_TCR_ATD    0x10   // Auto transmit disable
370 #define DP_TCR_OFFSET 0x20   // Collision offset adjust
371
372 // Transmit status register
373
374 #define DP_TSR_TxP    0x01   // Packet transmitted
375 #define DP_TSR_COL    0x04   // Collision (at least one)
376 #define DP_TSR_ABT    0x08   // Aborted because of too many collisions
377 #define DP_TSR_CRS    0x10   // Lost carrier
378 #define DP_TSR_FU     0x20   // FIFO underrun
379 #define DP_TSR_CDH    0x40   // Collision Detect Heartbeat
380 #define DP_TSR_OWC    0x80   // Collision outside normal window
381
382 #define IEEE_8023_MAX_FRAME         1518    // Largest possible ethernet frame
383 #define IEEE_8023_MIN_FRAME           64    // Smallest possible ethernet frame
384