OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [devs/] [eth/] [ns/] [dp83902a/] [current/] [include/] [dp83902a.h] - Blame information for rev 786

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.