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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [devs/] [eth/] [amd/] [pcnet/] [current/] [src/] [amd_pcnet.h] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
#ifndef CYGONCE_DEVS_ETH_AMD_PCNET_H
2
#define CYGONCE_DEVS_ETH_AMD_PCNET_H
3
//==========================================================================
4
//
5
//      amd_pcnet.h
6
//
7
//      AMD PCNet 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, hmt
46
// Date:         2001-04-02
47
// Purpose:      Hardware description of AMD PCnet series.
48
// Description:  
49
//
50
//####DESCRIPTIONEND####
51
//
52
//==========================================================================
53
 
54
#include <cyg/hal/hal_io.h>
55
 
56
//------------------------------------------------------------------------
57
// Get macros from platform header
58
#define __WANT_CONFIG
59
#include CYGDAT_DEVS_ETH_AMD_PCNET_INL
60
#undef  __WANT_CONFIG
61
 
62
//------------------------------------------------------------------------
63
// Set to perms of:
64
// 0 disables all debug output
65
// 1 for process debug output
66
// 2 for added data IO output: get_reg, put_reg
67
// 4 for packet allocation/free output
68
// 8 for only startup status, so we can tell we're installed OK
69
#define DEBUG 0x0
70
 
71
#if DEBUG & 1
72
#define DEBUG_FUNCTION() do { os_printf("%s\n", __FUNCTION__); } while (0)
73
#else
74
#define DEBUG_FUNCTION() do {} while(0)
75
#endif
76
 
77
// ------------------------------------------------------------------------
78
// Macros for keeping track of statistics
79
#if defined(ETH_DRV_GET_IF_STATS) || defined (ETH_DRV_GET_IF_STATS_UD)
80
# define KEEP_STATISTICS
81
#endif
82
 
83
#ifdef KEEP_STATISTICS
84
# define INCR_STAT( _x_ )        (cpd->stats. _x_ ++)
85
#else
86
# define INCR_STAT( _x_ )        CYG_EMPTY_STATEMENT
87
#endif
88
 
89
//------------------------------------------------------------------------
90
// Cache translation
91
#ifndef CYGARC_UNCACHED_ADDRESS
92
# define CYGARC_UNCACHED_ADDRESS(x) (x)
93
#endif
94
 
95
//------------------------------------------------------------------------
96
// Address translation
97
#ifndef HAL_PCI_CPU_TO_BUS
98
# error "HAL PCI support must define translation macros"
99
#endif
100
 
101
// ------------------------------------------------------------------------
102
// Macros for accessing structure elements
103
 
104
#define _SU8( _base_, _offset_) \
105
        *((cyg_uint8 *)((CYG_ADDRWORD)_base_+(_offset_)))
106
#define _SU16( _base_, _offset_) \
107
        *((cyg_uint16 *)((CYG_ADDRWORD)_base_+(_offset_)))
108
#define _SU32( _base_, _offset_) \
109
        *((cyg_uint32 *)((CYG_ADDRWORD)_base_+(_offset_)))
110
 
111
#define _SI8( _base_, _offset_) \
112
        *((cyg_int8 *)((CYG_ADDRWORD)_base_+(_offset_)))
113
#define _SI16( _base_, _offset_) \
114
        *((cyg_int16 *)((CYG_ADDRWORD)_base_+(_offset_)))
115
#define _SI32( _base_, _offset_) \
116
        *((cyg_int32 *)((CYG_ADDRWORD)_base_+(_offset_)))
117
 
118
// ------------------------------------------------------------------------
119
// Macros for accessing controller registers
120
#ifndef HAL_PCI_IO_READ_UINT8
121
# define HAL_PCI_IO_READ_UINT8(addr, datum)   HAL_READ_UINT8(addr, datum)
122
# define HAL_PCI_IO_WRITE_UINT8(addr, datum)  HAL_WRITE_UINT8(addr, datum)
123
# define HAL_PCI_IO_READ_UINT16(addr, datum)  HAL_READ_UINT16(addr, datum)
124
# define HAL_PCI_IO_WRITE_UINT16(addr, datum) HAL_WRITE_UINT16(addr, datum)
125
# define HAL_PCI_IO_READ_UINT32(addr, datum)  HAL_READ_UINT32(addr, datum)
126
# define HAL_PCI_IO_WRITE_UINT32(addr, datum) HAL_WRITE_UINT32(addr, datum)
127
#endif
128
 
129
// ------------------------------------------------------------------------
130
// IO map registers
131
#define PCNET_IO_EEPROM   0x00
132
#define PCNET_IO_ID       0x0e
133
#define PCNET_IO_RDP      0x10
134
#define PCNET_IO_RAP      0x12
135
#define PCNET_IO_RESET    0x14
136
#define PCNET_IO_BDP      0x16
137
 
138
// The ID of the 79C790 is 0x5757 - that may be different in other
139
// (older) cards.
140
#define PCNET_IO_ID_KEY   0x5757
141
 
142
// ------------------------------------------------------------------------
143
// Controller registers come in three sets: CSR, BCR and ANR. Use
144
// high-bits do differentiate, make the put/get functions do the right
145
// thing depending the state of these bits.
146
#define PCNET_RAP_MASK    0x007f
147
//#define PCNET_CSR_FLAG  0x0000        // implied
148
#define PCNET_BCR_FLAG    0x0080
149
#define PCNET_ANR_FLAG    0x0100
150
 
151
 
152
// CSR registers
153
#define PCNET_CSR_CSCR    0
154
#define PCNET_CSR_IBA0    1
155
#define PCNET_CSR_IBA1    2
156
#define PCNET_CSR_IM      3
157
#define PCNET_CSR_TFC     4
158
#define PCNET_CSR_ECI     5
159
#define PCNET_CSR_LAR0    8
160
#define PCNET_CSR_LAR1    9
161
#define PCNET_CSR_LAR2    10
162
#define PCNET_CSR_LAR3    11
163
#define PCNET_CSR_PAR0    12
164
#define PCNET_CSR_PAR1    13
165
#define PCNET_CSR_PAR2    14
166
#define PCNET_CSR_MODE    15
167
#define PCNET_CSR_BARRL   24
168
#define PCNET_CSR_BARRU   25
169
#define PCNET_CSR_BATRL   30
170
#define PCNET_CSR_BATRU   31
171
#define PCNET_CSR_RRC     72
172
#define PCNET_CSR_TRC     74
173
#define PCNET_CSR_RRLEN   76
174
#define PCNET_CSR_TRLEN   78
175
#define PCNET_CSR_ID_LO   88
176
#define PCNET_CSR_ID_HI   89
177
 
178
 
179
#define PCNET_CSR_CSCR_ERR       0x8000
180
#define PCNET_CSR_CSCR_RES       0x4000
181
#define PCNET_CSR_CSCR_CERR      0x2000
182
#define PCNET_CSR_CSCR_MISS      0x1000
183
#define PCNET_CSR_CSCR_MERR      0x0800
184
#define PCNET_CSR_CSCR_RINT      0x0400
185
#define PCNET_CSR_CSCR_TINT      0x0200
186
#define PCNET_CSR_CSCR_IDON      0x0100
187
#define PCNET_CSR_CSCR_INTR      0x0080
188
#define PCNET_CSR_CSCR_IENA      0x0040
189
#define PCNET_CSR_CSCR_RXON      0x0020
190
#define PCNET_CSR_CSCR_TXON      0x0010
191
#define PCNET_CSR_CSCR_TDMD      0x0008
192
#define PCNET_CSR_CSCR_STOP      0x0004
193
#define PCNET_CSR_CSCR_STRT      0x0002
194
#define PCNET_CSR_CSCR_INIT      0x0001
195
 
196
#define PCNET_CSR_CSCR_EV_MASK   0x007f
197
 
198
#define PCNET_CSR_IM_MISSM       0x1000
199
#define PCNET_CSR_IM_MERRM       0x0800
200
#define PCNET_CSR_IM_RINTM       0x0400
201
#define PCNET_CSR_IM_TINTM       0x0200
202
#define PCNET_CSR_IM_IDONM       0x0100
203
#define PCNET_CSR_IM_DXSUFLO     0x0040
204
#define PCNET_CSR_IM_LAPPEN      0x0020
205
#define PCNET_CSR_IM_DXMT2PD     0x0010
206
#define PCNET_CSR_IM_EMBA        0x0008
207
#define PCNET_CSR_IM_BSWP        0x0004
208
 
209
#define PCNET_CSR_TFC_TXDPOLL    0x1000
210
#define PCNET_CSR_TFC_APAD_XMT   0x0800
211
#define PCNET_CSR_TFC_ASTRP_RCV  0x0400
212
#define PCNET_CSR_TFC_MFCO       0x0200
213
#define PCNET_CSR_TFC_MFCOM      0x0100
214
#define PCNET_CSR_TFC_UINTCMD    0x0080
215
#define PCNET_CSR_TFC_UINT       0x0040
216
#define PCNET_CSR_TFC_RCVCCO     0x0020
217
#define PCNET_CSR_TFC_RCVCCOM    0x0010
218
#define PCNET_CSR_TFC_TXSTRT     0x0008
219
#define PCNET_CSR_TFC_TXSTRTM    0x0004
220
 
221
#define PCNET_CSR_ECI_TOKINTD      0x8000
222
#define PCNET_CSR_ECI_LTINTEN      0x4000
223
#define PCNET_CSR_ECI_SINT         0x0800
224
#define PCNET_CSR_ECI_SINTE        0x0400
225
#define PCNET_CSR_ECI_EXDINT       0x0080
226
#define PCNET_CSR_ECI_EXDINTE      0x0040
227
#define PCNET_CSR_ECI_MPPLBA       0x0020
228
#define PCNET_CSR_ECI_MPINT        0x0010
229
#define PCNET_CSR_ECI_MPINTE       0x0008
230
#define PCNET_CSR_ECI_MPEN         0x0004
231
#define PCNET_CSR_ECI_MPMODE       0x0002
232
#define PCNET_CSR_ECI_SPND         0x0001
233
 
234
#define PCNET_CSR_MODE_PROM        0x8000
235
#define PCNET_CSR_MODE_DRCVBC      0x4000
236
#define PCNET_CSR_MODE_DRCVPA      0x2000
237
#define PCNET_CSR_MODE_PORTSEL     0x0180
238
#define PCNET_CSR_MODE_INTL        0x0040
239
#define PCNET_CSR_MODE_DRTY        0x0020
240
#define PCNET_CSR_MODE_FCOLL       0x0010
241
#define PCNET_CSR_MODE_DXMTFCS     0x0008
242
#define PCNET_CSR_MODE_LOOP        0x0004
243
#define PCNET_CSR_MODE_DTX         0x0002
244
#define PCNET_CSR_MODE_DRX         0x0001
245
 
246
// BCR registers
247
#define PCNET_BCR_SWSTYLE (20 |PCNET_BCR_FLAG)
248
#define PCNET_BCR_MIIADDR (33 |PCNET_BCR_FLAG)
249
#define PCNET_BCR_MIIDATA (34 |PCNET_BCR_FLAG)
250
 
251
#define PCNET_BCR_MIIADDR_PHYAD    0x03e0
252
 
253
 
254
// ANR registers
255
#define PCNET_ANR_PHYCTRL ( 0 |PCNET_ANR_FLAG)
256
#define PCNET_ANR_PHYSTAT ( 1 |PCNET_ANR_FLAG)
257
#define PCNET_ANR_AAR     ( 4 |PCNET_ANR_FLAG)
258
 
259
#define PCNET_ANR_PHYCTRL_100MBPS     0x2000
260
#define PCNET_ANR_PHYCTRL_RENEGOTIATE 0x0200
261
#define PCNET_ANR_PHYCTRL_DUPLEX      0x0100
262
 
263
#define PCNET_ANR_PHYSTAT_AUTONEG_COMP    0x0020
264
#define PCNET_ANR_PHYSTAT_LINK            0x0004
265
 
266
#define PCNET_ANR_AAR_100_FD      0x0100
267
#define PCNET_ANR_AAR_100_HD      0x0080
268
#define PCNET_ANR_AAR_100         0x0180
269
#define PCNET_ANR_AAR_10_FD       0x0040
270
#define PCNET_ANR_AAR_10_HD       0x0020
271
#define PCNET_ANR_AAR_10          0x0060
272
 
273
//----------------------------------------------------------------------------
274
// Receive buffer Descriptor
275
#if 1
276
#define PCNET_RD_PTR       0x00        // 32 bit
277
#define PCNET_RD_BLEN      0x04        // 16 bit (2's complement, negative)
278
#define PCNET_RD_MLEN      0x06        // 16 bit
279
#define PCNET_RD_SIZE      0x08
280
 
281
#define PCNET_RD_PTR_OWN       0x80000000
282
#define PCNET_RD_PTR_ERR       0x40000000
283
#define PCNET_RD_PTR_FRAM      0x20000000
284
#define PCNET_RD_PTR_OFLO      0x10000000
285
#define PCNET_RD_PTR_CRC       0x08000000
286
#define PCNET_RD_PTR_BUFF      0x04000000
287
#define PCNET_RD_PTR_STP       0x02000000
288
#define PCNET_RD_PTR_ENP       0x01000000
289
#define PCNET_RD_PTR_MASK      0x00ffffff
290
#else
291
 
292
#define PCNET_RD_PTR       0x00
293
#define PCNET_RD_BLEN      0x04
294
#define PCNET_RD_MLEN      0x08
295
#define PCNET_RD_USER      0x0c
296
#define PCNET_RD_SIZE      0x10
297
 
298
#define PCNET_RD_BLEN_OWN       0x80000000
299
#define PCNET_RD_BLEN_ERR       0x40000000
300
#define PCNET_RD_BLEN_FRAM      0x20000000
301
#define PCNET_RD_BLEN_OFLO      0x10000000
302
#define PCNET_RD_BLEN_CRC       0x08000000
303
#define PCNET_RD_BLEN_BUFF      0x04000000
304
#define PCNET_RD_BLEN_STP       0x02000000
305
#define PCNET_RD_BLEN_ENP       0x01000000
306
#define PCNET_RD_BLEN_BPE       0x00800000
307
#define PCNET_RD_BLEN_PAM       0x00400000
308
#define PCNET_RD_BLEN_LAFM      0x00200000
309
#define PCNET_RD_BLEN_BAM       0x00100000
310
#define PCNET_RD_BLEN_MASK      0x0000ffff
311
#endif
312
 
313
// Transmit buffer Descriptor
314
#if 1
315
#define PCNET_TD_PTR       0x00        // 32 bit
316
#define PCNET_TD_LEN       0x04        // 16 bit (2's complement, negative)
317
#define PCNET_TD_MISC      0x06        // 16 bit
318
#define PCNET_TD_SIZE      0x08
319
 
320
#define PCNET_TD_PTR_OWN       0x80000000
321
#define PCNET_TD_PTR_ERR       0x40000000
322
#define PCNET_TD_PTR_ADD_FCS   0x20000000
323
#define PCNET_TD_PTR_MORE      0x10000000
324
#define PCNET_TD_PTR_ONE       0x08000000
325
#define PCNET_TD_PTR_DEF       0x04000000
326
#define PCNET_TD_PTR_STP       0x02000000
327
#define PCNET_TD_PTR_ENP       0x01000000
328
#define PCNET_TD_PTR_MASK      0x00ffffff
329
#else
330
#define PCNET_TD_PTR       0x00
331
#define PCNET_TD_LEN       0x04
332
#define PCNET_TD_MISC      0x08
333
#define PCNET_TD_USER      0x0c
334
#define PCNET_TD_SIZE      0x10
335
 
336
#define PCNET_TD_LEN_OWN       0x80000000
337
#define PCNET_TD_LEN_ERR       0x40000000
338
#define PCNET_TD_LEN_ADD_FCS   0x20000000
339
#define PCNET_TD_LEN_MORE      0x10000000
340
#define PCNET_TD_LEN_ONE       0x08000000
341
#define PCNET_TD_LEN_DEF       0x04000000
342
#define PCNET_TD_LEN_STP       0x02000000
343
#define PCNET_TD_LEN_ENP       0x01000000
344
#define PCNET_TD_LEN_BPE       0x00800000
345
#define PCNET_TD_LEN_MASK      0x0000ffff
346
 
347
#define PCNET_TD_FLAGS_BUFF     0x80000000
348
#define PCNET_TD_FLAGS_UFLO     0x40000000
349
#define PCNET_TD_FLAGS_EX_DEF   0x20000000
350
#define PCNET_TD_FLAGS_LCOL     0x10000000
351
#define PCNET_TD_FLAGS_LCAR     0x08000000
352
#define PCNET_TD_FLAGS_RTRY     0x04000000
353
#define PCNET_TD_FLAGS_TRC_MASK 0x0000000f
354
#endif
355
 
356
 
357
#define PCNET_TD_MISC_BUFF     0x8000
358
#define PCNET_TD_MISC_UFLO     0x4000
359
#define PCNET_TD_MISC_EXDEF    0x2000
360
#define PCNET_TD_MISC_LCOL     0x1000
361
#define PCNET_TD_MISC_LCAR     0x0800
362
#define PCNET_TD_MISC_RTRY     0x0400
363
#define PCNET_TD_MISC_TDR      0x03ff
364
 
365
// Initialization Buffer
366
#define PCNET_IB_MODE            0
367
#define PCNET_IB_PADR0           2
368
#define PCNET_IB_PADR1           4
369
#define PCNET_IB_PADR2           6
370
#define PCNET_IB_LADRF0          8
371
#define PCNET_IB_LADRF1          10
372
#define PCNET_IB_LADRF2          12
373
#define PCNET_IB_LADRF3          14
374
#define PCNET_IB_RDRA            16
375
#define PCNET_IB_TDRA            20
376
#define PCNET_IB_SIZE            24
377
 
378
#define PCNET_IB_TDRA_CNT_shift  29
379
#define PCNET_IB_TDRA_PTR_mask   0x00ffffff
380
#define PCNET_IB_RDRA_CNT_shift  29
381
#define PCNET_IB_RDRA_PTR_mask   0x00ffffff
382
 
383
// ------------------------------------------------------------------------
384
 
385
#ifdef KEEP_STATISTICS
386
struct amd_pcnet_stats {
387
    unsigned int tx_good             ;
388
    unsigned int tx_max_collisions   ;
389
    unsigned int tx_late_collisions  ;
390
    unsigned int tx_underrun         ;
391
    unsigned int tx_carrier_loss     ;
392
    unsigned int tx_deferred         ;
393
    unsigned int tx_sqetesterrors    ;
394
    unsigned int tx_single_collisions;
395
    unsigned int tx_mult_collisions  ;
396
    unsigned int tx_total_collisions ;
397
    unsigned int rx_good             ;
398
    unsigned int rx_crc_errors       ;
399
    unsigned int rx_align_errors     ;
400
    unsigned int rx_resource_errors  ;
401
    unsigned int rx_overrun_errors   ;
402
    unsigned int rx_collisions       ;
403
    unsigned int rx_short_frames     ;
404
    unsigned int rx_too_long_frames  ;
405
    unsigned int rx_symbol_errors    ;
406
    unsigned int interrupts          ;
407
    unsigned int rx_count            ;
408
    unsigned int rx_deliver          ;
409
    unsigned int rx_resource         ;
410
    unsigned int rx_restart          ;
411
    unsigned int tx_count            ;
412
    unsigned int tx_complete         ;
413
    unsigned int tx_dropped          ;
414
};
415
#endif
416
 
417
typedef struct pcnet_priv_data {
418
    int index;
419
    cyg_uint8                           // (split up for atomic byte access)
420
        found:1,                        // was hardware discovered?
421
        mac_addr_ok:1,                  // can we bring up?
422
        active:1,                       // has this if been brung up?
423
        hardwired_esa:1,                // set if ESA is hardwired via CDL
424
        txbusy:1,                       // A packet has been sent
425
        spare1:3;
426
 
427
    unsigned long txkey;                // Used to ack when packet sent
428
    unsigned char* base;                // Base address of controller EPROM region
429
    int interrupt;                      // Interrupt vector used by controller
430
    unsigned char esa[6];            // Controller ESA
431
    // Function to configure the ESA - may fetch ESA from EPROM or 
432
    // RedBoot config option.
433
    void (*config_esa)(struct pcnet_priv_data* cpd);
434
    void *ndp;                          // Network Device Pointer
435
 
436
    cyg_handle_t  interrupt_handle;
437
    cyg_interrupt interrupt_object;
438
    int devid;
439
 
440
    cyg_uint8* rx_buffers;              // ptr to base of buffer mem
441
    cyg_uint8* rx_ring;                 // ptr to base of rx ring memory
442
    int rx_ring_cnt;                    // number of entries in ring
443
    int rx_ring_log_cnt;                // log of above
444
    int rx_ring_next;                   // index of next full ring entry
445
 
446
    cyg_uint8* tx_buffers;
447
    cyg_uint8* tx_ring;
448
    int tx_ring_cnt;
449
    int tx_ring_log_cnt;
450
    int tx_ring_free;                   // index of next free ring entry
451
    int tx_ring_alloc;                  // index of first controller owned ring
452
    int tx_ring_owned;                  // number of controller owned ring entries
453
 
454
    int rxpacket;
455
#ifdef KEEP_STATISTICS
456
    struct amd_pcnet_stats stats;
457
#endif
458
#if DEBUG & 1
459
    cyg_uint32 txd;
460
#endif
461
} pcnet_priv_data;
462
 
463
// ------------------------------------------------------------------------
464
 
465
static __inline__ cyg_uint16
466
get_reg(struct eth_drv_sc *sc, int regno)
467
{
468
    struct pcnet_priv_data *cpd =
469
        (struct pcnet_priv_data *)sc->driver_private;
470
    cyg_uint16 val, addr;
471
 
472
    if (regno & PCNET_ANR_FLAG) {
473
        // We could do this with recursive calls to get/put reg
474
        // functions, but might as well just do it directly.
475
        // First set ANR address
476
        HAL_PCI_IO_WRITE_UINT16(cpd->base+PCNET_IO_RAP, PCNET_BCR_MIIADDR & PCNET_RAP_MASK);
477
        HAL_PCI_IO_READ_UINT16(cpd->base+PCNET_IO_BDP, addr);
478
        addr &= PCNET_BCR_MIIADDR_PHYAD;
479
        addr |= (regno & PCNET_RAP_MASK);
480
        HAL_PCI_IO_WRITE_UINT16(cpd->base+PCNET_IO_BDP, addr);
481
        // Then read ANR register data
482
        HAL_PCI_IO_WRITE_UINT16(cpd->base+PCNET_IO_RAP, PCNET_BCR_MIIDATA & PCNET_RAP_MASK);
483
        HAL_PCI_IO_READ_UINT16(cpd->base+PCNET_IO_BDP, val);
484
    } else {
485
        HAL_PCI_IO_WRITE_UINT16(cpd->base+PCNET_IO_RAP, regno & PCNET_RAP_MASK);
486
        if (regno & PCNET_BCR_FLAG)
487
            HAL_PCI_IO_READ_UINT16(cpd->base+PCNET_IO_BDP, val);
488
        else
489
            HAL_PCI_IO_READ_UINT16(cpd->base+PCNET_IO_RDP, val);
490
    }
491
#if DEBUG & 2
492
    os_printf("read %s reg %d val 0x%04x\n",
493
                (regno & PCNET_ANR_FLAG) ? "anr" : (regno & PCNET_BCR_FLAG) ? "bcr" : "csr",
494
                regno & PCNET_RAP_MASK, val);
495
#endif
496
    return val;
497
}
498
 
499
static __inline__ void
500
put_reg(struct eth_drv_sc *sc, int regno, cyg_uint16 val)
501
{
502
    struct pcnet_priv_data *cpd =
503
        (struct pcnet_priv_data *)sc->driver_private;
504
    cyg_uint16 addr;
505
 
506
    if (regno & PCNET_ANR_FLAG) {
507
        // We could do this with recursive calls to get/put reg
508
        // functions, but might as well just do it directly.
509
        // First set ANR address
510
        HAL_PCI_IO_WRITE_UINT16(cpd->base+PCNET_IO_RAP, PCNET_BCR_MIIADDR & PCNET_RAP_MASK);
511
        HAL_PCI_IO_READ_UINT16(cpd->base+PCNET_IO_BDP, addr);
512
        addr &= PCNET_BCR_MIIADDR_PHYAD;
513
        addr |= (regno & PCNET_RAP_MASK);
514
        HAL_PCI_IO_WRITE_UINT16(cpd->base+PCNET_IO_BDP, addr);
515
        // Then write ANR register data
516
        HAL_PCI_IO_WRITE_UINT16(cpd->base+PCNET_IO_RAP, PCNET_BCR_MIIDATA & PCNET_RAP_MASK);
517
        HAL_PCI_IO_WRITE_UINT16(cpd->base+PCNET_IO_BDP, val);
518
    } else {
519
        HAL_PCI_IO_WRITE_UINT16(cpd->base+PCNET_IO_RAP, regno & PCNET_RAP_MASK);
520
        if (regno & PCNET_BCR_FLAG)
521
            HAL_PCI_IO_WRITE_UINT16(cpd->base+PCNET_IO_BDP, val);
522
        else
523
            HAL_PCI_IO_WRITE_UINT16(cpd->base+PCNET_IO_RDP, val);
524
    }
525
 
526
#if DEBUG & 2
527
    os_printf("write %s reg %d val 0x%04x\n",
528
                (regno & PCNET_ANR_FLAG) ? "anr" : (regno & PCNET_BCR_FLAG) ? "bcr" : "csr",
529
                regno & PCNET_RAP_MASK, val);
530
#endif
531
}
532
 
533
// ------------------------------------------------------------------------
534
#endif // CYGONCE_DEVS_ETH_AMD_PCNET_H
535
// EOF amd_pcnet.h

powered by: WebSVN 2.1.0

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