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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [devs/] [eth/] [via/] [rhine/] [current/] [src/] [via_rhine.h] - Blame information for rev 868

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
#ifndef CYGONCE_DEVS_ETH_VIA_RHINE_H
2
#define CYGONCE_DEVS_ETH_VIA_RHINE_H
3
//==========================================================================
4
//
5
//      via_rhine.h
6
//
7
//      VIA Rhine Ethernet chip
8
//
9
//==========================================================================
10
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
11
// -------------------------------------------                              
12
// This file is part of eCos, the Embedded Configurable Operating System.   
13
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
14
//
15
// eCos is free software; you can redistribute it and/or modify it under    
16
// the terms of the GNU General Public License as published by the Free     
17
// Software Foundation; either version 2 or (at your option) any later      
18
// version.                                                                 
19
//
20
// eCos is distributed in the hope that it will be useful, but WITHOUT      
21
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
22
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
23
// for more details.                                                        
24
//
25
// You should have received a copy of the GNU General Public License        
26
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
27
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
28
//
29
// As a special exception, if other files instantiate templates or use      
30
// macros or inline functions from this file, or you compile this file      
31
// and link it with other works to produce a work based on this file,       
32
// this file does not by itself cause the resulting work to be covered by   
33
// the GNU General Public License. However the source code for this file    
34
// must still be made available in accordance with section (3) of the GNU   
35
// General Public License v2.                                               
36
//
37
// This exception does not invalidate any other reasons why a work based    
38
// on this file might be covered by the GNU General Public License.         
39
// -------------------------------------------                              
40
// ####ECOSGPLCOPYRIGHTEND####                                              
41
//==========================================================================
42
//#####DESCRIPTIONBEGIN####
43
//
44
// Author(s):    jskov
45
// Contributors: jskov
46
// Date:         2001-05-30
47
// Purpose:      Hardware description of VIA Rhine series.
48
// Description:  
49
//
50
//####DESCRIPTIONEND####
51
//
52
//==========================================================================
53
 
54
#include <cyg/hal/hal_io.h>
55
#include <cyg/io/pci_hw.h>             // HAL_PCI_ macros
56
 
57
//------------------------------------------------------------------------
58
// Get macros from platform header
59
#define __WANT_CONFIG
60
#include CYGDAT_DEVS_ETH_VIA_RHINE_INL
61
#undef  __WANT_CONFIG
62
 
63
//------------------------------------------------------------------------
64
// Set to perms of:
65
// 0 disables all debug output
66
// 1 for process debug output
67
// 2 for added data IO output: get_reg, put_reg
68
// 4 for packet allocation/free output
69
// 8 for only startup status, so we can tell we're installed OK
70
#define DEBUG 0x00
71
 
72
#if DEBUG & 1
73
# define DEBUG_FUNCTION() do { diag_printf("%s\n", __FUNCTION__); } while (0)
74
#else
75
# define DEBUG_FUNCTION() 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_ )        (cpd->stats. _x_ ++)
86
#else
87
#define INCR_STAT( _x_ )        CYG_EMPTY_STATEMENT
88
#endif
89
 
90
//------------------------------------------------------------------------
91
// Cache translation
92
#ifndef CYGARC_UNCACHED_ADDRESS
93
# define CYGARC_UNCACHED_ADDRESS(x) (x)
94
#endif
95
 
96
//------------------------------------------------------------------------
97
// Address translation
98
#ifndef HAL_PCI_CPU_TO_BUS
99
# error "HAL PCI support must define translation macros"
100
#endif
101
 
102
//------------------------------------------------------------------------
103
// Macros for accessing structure elements
104
 
105
#define _SU8( _base_, _offset_) \
106
        *((volatile cyg_uint8 *)((CYG_ADDRWORD)_base_+(_offset_)))
107
#define _SU16( _base_, _offset_) \
108
        *((volatile cyg_uint16 *)((CYG_ADDRWORD)_base_+(_offset_)))
109
#define _SU32( _base_, _offset_) \
110
        *((volatile cyg_uint32 *)((CYG_ADDRWORD)_base_+(_offset_)))
111
 
112
#define _SI8( _base_, _offset_) \
113
        *((volatile cyg_int8 *)((CYG_ADDRWORD)_base_+(_offset_)))
114
#define _SI16( _base_, _offset_) \
115
        *((volatile cyg_int16 *)((CYG_ADDRWORD)_base_+(_offset_)))
116
#define _SI32( _base_, _offset_) \
117
        *((volatile cyg_int32 *)((CYG_ADDRWORD)_base_+(_offset_)))
118
 
119
// ------------------------------------------------------------------------
120
// Macros for accessing controller registers
121
#ifndef HAL_PCI_IO_READ_UINT8
122
# define HAL_PCI_IO_READ_UINT8(addr, datum)   HAL_READ_UINT8(addr, datum)
123
# define HAL_PCI_IO_WRITE_UINT8(addr, datum)  HAL_WRITE_UINT8(addr, datum)
124
# define HAL_PCI_IO_READ_UINT16(addr, datum)  HAL_READ_UINT16(addr, datum)
125
# define HAL_PCI_IO_WRITE_UINT16(addr, datum) HAL_WRITE_UINT16(addr, datum)
126
# define HAL_PCI_IO_READ_UINT32(addr, datum)  HAL_READ_UINT32(addr, datum)
127
# define HAL_PCI_IO_WRITE_UINT32(addr, datum) HAL_WRITE_UINT32(addr, datum)
128
#endif
129
 
130
// ------------------------------------------------------------------------
131
// Control registers
132
#define RHINE_PAR0         0x00
133
#define RHINE_PAR1         0x01
134
#define RHINE_PAR2         0x02
135
#define RHINE_PAR3         0x03
136
#define RHINE_PAR4         0x04
137
#define RHINE_PAR5         0x05
138
 
139
#define RHINE_RCR          0x06
140
#define RHINE_TCR          0x07
141
#define RHINE_CR0          0x08
142
#define RHINE_CR1          0x09
143
 
144
#define RHINE_ISR          0x0c         // 16 bit
145
#define RHINE_IMR          0x0e         // 16 bit
146
 
147
#define RHINE_CUR_RX       0x18
148
#define RHINE_CUR_TX       0x1c
149
 
150
 
151
#define RHINE_PHYADR       0x6c
152
#define RHINE_MIISR        0x6d
153
#define RHINE_BCR0         0x6e
154
#define RHINE_BCR1         0x6f
155
#define RHINE_MIICR        0x70
156
#define RHINE_MIIAD        0x71
157
#define RHINE_MIIDATA      0x72         // 16 bit
158
 
159
 
160
#define RHINE_EECSR        0x74
161
 
162
#define RHINE_CFGA         0x78
163
#define RHINE_CFGB         0x79
164
#define RHINE_CFGC         0x7a
165
#define RHINE_CFGD         0x7b
166
 
167
#define RHINE_STICKYHW     0x83
168
#define RHINE_WOL_CR_CLR   0xa4
169
#define RHINE_WOL_CG_CLR   0xa7
170
#define RHINE_PWR_CSR_CLR  0xac
171
 
172
#define RHINE_RCR_RRSF     0x80
173
#define RHINE_RCR_RFT_64   0x00
174
#define RHINE_RCR_RFT_SF   0x60
175
#define RHINE_RCR_PRO      0x10
176
#define RHINE_RCR_AB       0x08
177
#define RHINE_RCR_AM       0x04
178
#define RHINE_RCR_AR       0x02
179
#define RHINE_RCR_SEP      0x01
180
 
181
#define RHINE_TCR_RTSF     0x80
182
#define RHINE_TCR_TFT_64   0x00
183
#define RHINE_TCR_TFT_SF   0x60
184
#define RHINE_TCR_OFFSET   0x08
185
#define RHINE_TCR_LB1      0x04
186
#define RHINE_TCR_LB0      0x02
187
 
188
#define RHINE_CR0_RDMD       0x40
189
#define RHINE_CR0_TDMD       0x20
190
#define RHINE_CR0_TXON       0x10
191
#define RHINE_CR0_RXON       0x08
192
#define RHINE_CR0_STOP       0x04
193
#define RHINE_CR0_STRT       0x02
194
#define RHINE_CR0_INIT       0x01
195
 
196
#define RHINE_CR1_SRST       0x80
197
#define RHINE_CR1_DPOLL      0x08
198
#define RHINE_CR1_FDX        0x04
199
#define RHINE_CR1_ETEN       0x02
200
#define RHINE_CR1_EREN       0x01
201
 
202
#define RHINE_ISR_KEYI       0x8000
203
#define RHINE_ISR_SRCI       0x4000
204
#define RHINE_ISR_ABTI       0x2000
205
#define RHINE_ISR_NORBF      0x1000
206
#define RHINE_ISR_PKRACE     0x0800
207
#define RHINE_ISR_OVFI       0x0400
208
#define RHINE_ISR_ETI        0x0200
209
#define RHINE_ISR_ERI        0x0100
210
#define RHINE_ISR_CNT        0x0080
211
#define RHINE_ISR_BE         0x0040
212
#define RHINE_ISR_RU         0x0020
213
#define RHINE_ISR_TU         0x0010
214
#define RHINE_ISR_TXE        0x0008
215
#define RHINE_ISR_RXE        0x0004
216
#define RHINE_ISR_PTX        0x0002
217
#define RHINE_ISR_PRX        0x0001
218
 
219
#define RHINE_IMR_KEYI       0x8000
220
#define RHINE_IMR_SRCI       0x4000
221
#define RHINE_IMR_ABTI       0x2000
222
#define RHINE_IMR_NORBF      0x1000
223
#define RHINE_IMR_PKRACE     0x0800
224
#define RHINE_IMR_OVFI       0x0400
225
#define RHINE_IMR_ETI        0x0200
226
#define RHINE_IMR_ERI        0x0100
227
#define RHINE_IMR_CNT        0x0080
228
#define RHINE_IMR_BE         0x0040
229
#define RHINE_IMR_RU         0x0020
230
#define RHINE_IMR_TU         0x0010
231
#define RHINE_IMR_TXE        0x0008
232
#define RHINE_IMR_RXE        0x0004
233
#define RHINE_IMR_PTX        0x0002
234
#define RHINE_IMR_PRX        0x0001
235
 
236
#define RHINE_IMR_INIT (RHINE_IMR_PTX | RHINE_IMR_PRX | RHINE_IMR_RU)
237
 
238
#define RHINE_BCR0_MAGIC_INIT 0x00
239
 
240
#define RHINE_BCR1_POT2      0x04
241
#define RHINE_BCR1_POT1      0x02
242
#define RHINE_BCR1_MAGIC_INIT (RHINE_BCR1_POT1|RHINE_BCR1_POT2)
243
 
244
 
245
#define RHINE_MIICR_MAUTO    0x80
246
#define RHINE_MIICR_RCMD     0x40
247
#define RHINE_MIICR_WCMD     0x20
248
#define RHINE_MIICR_MDPM     0x10
249
#define RHINE_MIICR_MOUT     0x08
250
#define RHINE_MIICR_MDO      0x04
251
#define RHINE_MIICR_MDI      0x02
252
#define RHINE_MIICR_MDC      0x01
253
 
254
#define RHINE_MIISR_GPIO1POL 0x80
255
#define RHINE_MIISR_MFDC     0x20
256
#define RHINE_MIISR_PHYOPT   0x10
257
#define RHINE_MIISR_MIIERR   0x08
258
#define RHINE_MIISR_MRERR    0x04
259
#define RHINE_MIISR_LNKFL    0x02
260
#define RHINE_MIISR_SPEED    0x01
261
 
262
#define RHINE_EECSR_EEPR     0x80
263
#define RHINE_EECSR_EMBP     0x40
264
#define RHINE_EECSR_LOAD     0x20
265
#define RHINE_EECSR_DPM      0x10
266
#define RHINE_EECSR_ECS      0x08
267
#define RHINE_EECSR_ECK      0x04
268
#define RHINE_EECSR_EDI      0x02
269
#define RHINE_EECSR_EDO      0x01
270
 
271
 
272
 
273
#define RHINE_CFGA_EELOAD    0x80
274
#define RHINE_CFGA_JUMPER    0x40
275
#define RHINE_CFGA_MMIEN     0x20
276
#define RHINE_CFGA_MIIOPT    0x10
277
#define RHINE_CFGA_AUTOOPT   0x08
278
#define RHINE_CFGA_GPIO2I    0x04
279
#define RHINE_CFGA_GPIO2O    0x02
280
#define RHINE_CFGA_GPIO2OE   0x01
281
 
282
#define RHINE_CFGB_QPKTDIS   0x80
283
#define RHINE_CFGB_TRACEN    0x40
284
#define RHINE_CFGB_MRDM      0x20
285
#define RHINE_CFGB_TXARBIT   0x10
286
#define RHINE_CFGB_RXARBIT   0x08
287
#define RHINE_CFGB_MWWAIT    0x04
288
#define RHINE_CFGB_MRWAIT    0x02
289
#define RHINE_CFGB_LATMEN    0x01
290
 
291
#define RHINE_CFGC_BROPT     0x40
292
#define RHINE_CFGC_DLYEN     0x20
293
#define RHINE_CFGC_BTSEL     0x08
294
#define RHINE_CFGC_BPS2      0x04
295
#define RHINE_CFGC_BPS1      0x02
296
#define RHINE_CFGC_BPS0      0x01
297
 
298
#define RHINE_CFGD_GPIOEN    0x80
299
#define RHINE_CFGD_DIAG      0x40
300
#define RHINE_CFGD_MRDLEN    0x20
301
#define RHINE_CFGD_MAGIC     0x10
302
#define RHINE_CFGD_CRANDOM   0x08
303
#define RHINE_CFGD_CAP       0x04
304
#define RHINE_CFGD_MBA       0x02
305
#define RHINE_CFGD_BAKOPT    0x01
306
 
307
 
308
 
309
 
310
//----------------------------------------------------------------------------
311
// Receive buffer Descriptor
312
#define RHINE_RDES0              0x00   // frame length, status registers
313
#define RHINE_RDES1              0x04   // receive length
314
#define RHINE_RDES2              0x08   // rx data buffer
315
#define RHINE_RDES3              0x0c   // next
316
#define RHINE_RD_SIZE            0x10
317
 
318
#define RHINE_RDES0_OWN          0x80000000
319
#define RHINE_RDES0_FLNG_mask    0x07ff0000
320
#define RHINE_RDES0_FLNG_shift   16
321
#define RHINE_RDES0_RXOK         0x00008000
322
#define RHINE_RDES0_RES1         0x00004000
323
#define RHINE_RDES0_MAR          0x00002000
324
#define RHINE_RDES0_BAR          0x00001000
325
#define RHINE_RDES0_PHY          0x00000800
326
#define RHINE_RDES0_CHN          0x00000400
327
#define RHINE_RDES0_STP          0x00000200
328
#define RHINE_RDES0_EDP          0x00000100
329
#define RHINE_RDES0_BUFF         0x00000080
330
#define RHINE_RDES0_SERR         0x00000040
331
#define RHINE_RDES0_RUNT         0x00000020
332
#define RHINE_RDES0_LONG         0x00000010
333
#define RHINE_RDES0_FOV          0x00000008
334
#define RHINE_RDES0_FAE          0x00000004
335
#define RHINE_RDES0_CRC          0x00000002
336
#define RHINE_RDES0_RERR         0x00000001
337
 
338
#define RHINE_RD_RLEN_IC         0x00800000
339
#define RHINE_RD_RLEN_C          0x00008000
340
#define RHINE_RD_RLEN_RLEN_mask  0x000007ff
341
 
342
 
343
//----------------------------------------------------------------------------
344
// Transmit buffer Descriptor
345
#define RHINE_TDES0        0x00        // status & own
346
#define RHINE_TDES1        0x04        // tx config & length
347
#define RHINE_TDES2        0x08        // tx data buffer
348
#define RHINE_TDES3        0x0c        // next
349
#define RHINE_TD_SIZE      0x10
350
 
351
#define RHINE_TDES0_OWN        0x80000000
352
#define RHINE_TDES0_TXOK       0x00008000
353
#define RHINE_TDES0_JAB        0x00004000
354
#define RHINE_TDES0_SERR       0x00002000
355
#define RHINE_TDES0_RES1       0x00001000
356
#define RHINE_TDES0_RES2       0x00000800
357
#define RHINE_TDES0_CRS        0x00000400
358
#define RHINE_TDES0_OWC        0x00000200
359
#define RHINE_TDES0_ABT        0x00000100
360
#define RHINE_TDES0_CDH        0x00000080
361
#define RHINE_TDES0_NCR_mask   0x00000038
362
#define RHINE_TDES0_NCR_shift  3
363
#define RHINE_TDES0_RES3       0x00000004
364
#define RHINE_TDES0_UDF        0x00000002
365
#define RHINE_TDES0_DFR        0x00000001
366
 
367
#define RHINE_TDES1_TCR_mask   0x00ff0000
368
#define RHINE_TDES1_TCR_shift  16
369
#define RHINE_TDES1_IC         0x00800000
370
#define RHINE_TDES1_EDP        0x00400000
371
#define RHINE_TDES1_STP        0x00200000
372
#define RHINE_TDES1_CRC        0x00010000
373
#define RHINE_TDES1_C          0x00008000
374
#define RHINE_TDES1_TLNG_mask  0x000007ff
375
 
376
// ------------------------------------------------------------------------
377
 
378
#define MII_BMCR               0
379
#define MII_BMSR               1
380
 
381
#define MII_BMCR_RENEGOTIATE   0x3300
382
 
383
#define MII_BMSR_AN_COMPLETE   0x0020
384
#define MII_BMSR_LINK          0x0004
385
 
386
// ------------------------------------------------------------------------
387
 
388
#ifdef KEEP_STATISTICS
389
struct via_rhine_stats {
390
    unsigned int tx_good             ;
391
    unsigned int tx_max_collisions   ;
392
    unsigned int tx_late_collisions  ;
393
    unsigned int tx_underrun         ;
394
    unsigned int tx_carrier_loss     ;
395
    unsigned int tx_deferred         ;
396
    unsigned int tx_sqetesterrors    ;
397
    unsigned int tx_single_collisions;
398
    unsigned int tx_mult_collisions  ;
399
    unsigned int tx_total_collisions ;
400
    unsigned int rx_good             ;
401
    unsigned int rx_crc_errors       ;
402
    unsigned int rx_align_errors     ;
403
    unsigned int rx_resource_errors  ;
404
    unsigned int rx_overrun_errors   ;
405
    unsigned int rx_collisions       ;
406
    unsigned int rx_short_frames     ;
407
    unsigned int rx_too_long_frames  ;
408
    unsigned int rx_symbol_errors    ;
409
    unsigned int interrupts          ;
410
    unsigned int rx_count            ;
411
    unsigned int rx_deliver          ;
412
    unsigned int rx_resource         ;
413
    unsigned int rx_restart          ;
414
    unsigned int tx_count            ;
415
    unsigned int tx_complete         ;
416
    unsigned int tx_dropped          ;
417
};
418
#endif
419
 
420
typedef struct rhine_priv_data {
421
    int index;
422
    cyg_uint8                           // (split up for atomic byte access)
423
        found:1,                        // was hardware discovered?
424
        mac_addr_ok:1,                  // can we bring up?
425
        active:1,                       // has this if been brung up?
426
        hardwired_esa:1,                // set if ESA is hardwired via CDL
427
        spare1:4;
428
 
429
    int txbusy;                         // A packet has been sent
430
    unsigned long txkey;                // Used to ack when packet sent
431
    unsigned char* base;                // Base address of controller IO region
432
    cyg_vector_t interrupt;             // Interrupt vector used by controller
433
    unsigned char esa[6];               // Controller ESA
434
    // Function to configure the ESA - may fetch ESA from EPROM or 
435
    // RedBoot config option.
436
    void (*config_esa)(struct rhine_priv_data* cpd);
437
    void *ndp;                          // Network Device Pointer
438
 
439
    cyg_handle_t  interrupt_handle;
440
    cyg_interrupt interrupt_object;
441
 
442
    int devid;
443
 
444
    int phys_id;                        // ID of physical MII controller
445
 
446
    cyg_uint8* rx_buffers;              // ptr to base of buffer mem
447
    cyg_uint8* rx_ring;                 // ptr to base of rx ring memory
448
    int rx_ring_cnt;                    // number of entries in ring
449
    int rx_ring_log_cnt;                // log of above
450
    int rx_ring_next;                   // index of next full ring entry
451
 
452
    cyg_uint8* tx_buffers;
453
    cyg_uint8* tx_ring;
454
    int tx_ring_cnt;
455
    int tx_ring_log_cnt;
456
    int tx_ring_free;                   // index of next free ring entry
457
    int tx_ring_alloc;                  // index of first controller owned ring
458
    int tx_ring_owned;                  // number of controller owned ring entries
459
 
460
    int rxpacket;
461
#ifdef KEEP_STATISTICS
462
    struct via_rhine_stats stats;
463
#endif
464
} rhine_priv_data;
465
 
466
// ------------------------------------------------------------------------
467
#endif // CYGONCE_DEVS_ETH_VIA_RHINE_H
468
// EOF via_rhine.h

powered by: WebSVN 2.1.0

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