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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [devs/] [eth/] [amd/] [lancepci/] [current/] [src/] [amd_lance.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_LANCE_H
2
#define CYGONCE_DEVS_ETH_AMD_LANCE_H
3
//==========================================================================
4
//
5
//      amd_lance.h
6
//
7
//      AMD Lance 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, iz
45
// Contributors: jskov, hmt, iz
46
// Date:         2002-07-17
47
// Purpose:      Hardware description of AMD Lance 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_LANCEPCI_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 LANCE_IO_EEPROM   0x00
132
#define LANCE_IO_ID       0x0e
133
#define LANCE_IO_RDP      0x10
134
#define LANCE_IO_RAP      0x12
135
#define LANCE_IO_RESET    0x14
136
#define LANCE_IO_BDP      0x16
137
 
138
// The ID of the 79C790 is 0x5757 - that may be different in other
139
// (older) cards.
140
#define LANCE_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 LANCE_RAP_MASK    0x007f
147
//#define LANCE_CSR_FLAG  0x0000        // implied
148
#define LANCE_BCR_FLAG    0x0080
149
#define LANCE_ANR_FLAG    0x0100
150
 
151
 
152
// CSR registers
153
#define LANCE_CSR_CSCR    0
154
#define LANCE_CSR_IBA0    1
155
#define LANCE_CSR_IBA1    2
156
#define LANCE_CSR_IM      3
157
#define LANCE_CSR_TFC     4
158
#define LANCE_CSR_ECI     5
159
#define LANCE_CSR_LAR0    8
160
#define LANCE_CSR_LAR1    9
161
#define LANCE_CSR_LAR2    10
162
#define LANCE_CSR_LAR3    11
163
#define LANCE_CSR_PAR0    12
164
#define LANCE_CSR_PAR1    13
165
#define LANCE_CSR_PAR2    14
166
#define LANCE_CSR_MODE    15
167
#define LANCE_CSR_BARRL   24
168
#define LANCE_CSR_BARRU   25
169
#define LANCE_CSR_BATRL   30
170
#define LANCE_CSR_BATRU   31
171
#define LANCE_CSR_RRC     72
172
#define LANCE_CSR_TRC     74
173
#define LANCE_CSR_RRLEN   76
174
#define LANCE_CSR_TRLEN   78
175
#define LANCE_CSR_ID_LO   88
176
#define LANCE_CSR_ID_HI   89
177
 
178
 
179
#define LANCE_CSR_CSCR_ERR       0x8000
180
#define LANCE_CSR_CSCR_RES       0x4000
181
#define LANCE_CSR_CSCR_CERR      0x2000
182
#define LANCE_CSR_CSCR_MISS      0x1000
183
#define LANCE_CSR_CSCR_MERR      0x0800
184
#define LANCE_CSR_CSCR_RINT      0x0400
185
#define LANCE_CSR_CSCR_TINT      0x0200
186
#define LANCE_CSR_CSCR_IDON      0x0100
187
#define LANCE_CSR_CSCR_INTR      0x0080
188
#define LANCE_CSR_CSCR_IENA      0x0040
189
#define LANCE_CSR_CSCR_RXON      0x0020
190
#define LANCE_CSR_CSCR_TXON      0x0010
191
#define LANCE_CSR_CSCR_TDMD      0x0008
192
#define LANCE_CSR_CSCR_STOP      0x0004
193
#define LANCE_CSR_CSCR_STRT      0x0002
194
#define LANCE_CSR_CSCR_INIT      0x0001
195
 
196
#define LANCE_CSR_CSCR_EV_MASK   0x007f
197
 
198
#define LANCE_CSR_IM_MISSM       0x1000
199
#define LANCE_CSR_IM_MERRM       0x0800
200
#define LANCE_CSR_IM_RINTM       0x0400
201
#define LANCE_CSR_IM_TINTM       0x0200
202
#define LANCE_CSR_IM_IDONM       0x0100
203
#define LANCE_CSR_IM_DXSUFLO     0x0040
204
#define LANCE_CSR_IM_LAPPEN      0x0020
205
#define LANCE_CSR_IM_DXMT2PD     0x0010
206
#define LANCE_CSR_IM_EMBA        0x0008
207
#define LANCE_CSR_IM_BSWP        0x0004
208
 
209
#define LANCE_CSR_TFC_TXDPOLL    0x1000
210
#define LANCE_CSR_TFC_APAD_XMT   0x0800
211
#define LANCE_CSR_TFC_ASTRP_RCV  0x0400
212
#define LANCE_CSR_TFC_MFCO       0x0200
213
#define LANCE_CSR_TFC_MFCOM      0x0100
214
#define LANCE_CSR_TFC_UINTCMD    0x0080
215
#define LANCE_CSR_TFC_UINT       0x0040
216
#define LANCE_CSR_TFC_RCVCCO     0x0020
217
#define LANCE_CSR_TFC_RCVCCOM    0x0010
218
#define LANCE_CSR_TFC_TXSTRT     0x0008
219
#define LANCE_CSR_TFC_TXSTRTM    0x0004
220
 
221
#define LANCE_CSR_ECI_TOKINTD      0x8000
222
#define LANCE_CSR_ECI_LTINTEN      0x4000
223
#define LANCE_CSR_ECI_SINT         0x0800
224
#define LANCE_CSR_ECI_SINTE        0x0400
225
#define LANCE_CSR_ECI_EXDINT       0x0080
226
#define LANCE_CSR_ECI_EXDINTE      0x0040
227
#define LANCE_CSR_ECI_MPPLBA       0x0020
228
#define LANCE_CSR_ECI_MPINT        0x0010
229
#define LANCE_CSR_ECI_MPINTE       0x0008
230
#define LANCE_CSR_ECI_MPEN         0x0004
231
#define LANCE_CSR_ECI_MPMODE       0x0002
232
#define LANCE_CSR_ECI_SPND         0x0001
233
 
234
#define LANCE_CSR_MODE_PROM        0x8000
235
#define LANCE_CSR_MODE_DRCVBC      0x4000
236
#define LANCE_CSR_MODE_DRCVPA      0x2000
237
#define LANCE_CSR_MODE_PORTSEL     0x0180
238
#define LANCE_CSR_MODE_INTL        0x0040
239
#define LANCE_CSR_MODE_DRTY        0x0020
240
#define LANCE_CSR_MODE_FCOLL       0x0010
241
#define LANCE_CSR_MODE_DXMTFCS     0x0008
242
#define LANCE_CSR_MODE_LOOP        0x0004
243
#define LANCE_CSR_MODE_DTX         0x0002
244
#define LANCE_CSR_MODE_DRX         0x0001
245
 
246
// BCR registers
247
#define LANCE_BCR_SWSTYLE (20 |LANCE_BCR_FLAG)
248
#define LANCE_BCR_MIIADDR (33 |LANCE_BCR_FLAG)
249
#define LANCE_BCR_MIIDATA (34 |LANCE_BCR_FLAG)
250
 
251
#define LANCE_BCR_MIIADDR_PHYAD    0x03e0
252
 
253
 
254
//----------------------------------------------------------------------------
255
// Receive buffer Descriptor
256
#if 1
257
#define LANCE_RD_PTR       0x00        // 32 bit
258
#define LANCE_RD_BLEN      0x04        // 16 bit (2's complement, negative)
259
#define LANCE_RD_MLEN      0x06        // 16 bit
260
#define LANCE_RD_SIZE      0x08
261
 
262
#define LANCE_RD_PTR_OWN       0x80000000
263
#define LANCE_RD_PTR_ERR       0x40000000
264
#define LANCE_RD_PTR_FRAM      0x20000000
265
#define LANCE_RD_PTR_OFLO      0x10000000
266
#define LANCE_RD_PTR_CRC       0x08000000
267
#define LANCE_RD_PTR_BUFF      0x04000000
268
#define LANCE_RD_PTR_STP       0x02000000
269
#define LANCE_RD_PTR_ENP       0x01000000
270
#define LANCE_RD_PTR_MASK      0x00ffffff
271
#else
272
 
273
#define LANCE_RD_PTR       0x00
274
#define LANCE_RD_BLEN      0x04
275
#define LANCE_RD_MLEN      0x08
276
#define LANCE_RD_USER      0x0c
277
#define LANCE_RD_SIZE      0x10
278
 
279
#define LANCE_RD_BLEN_OWN       0x80000000
280
#define LANCE_RD_BLEN_ERR       0x40000000
281
#define LANCE_RD_BLEN_FRAM      0x20000000
282
#define LANCE_RD_BLEN_OFLO      0x10000000
283
#define LANCE_RD_BLEN_CRC       0x08000000
284
#define LANCE_RD_BLEN_BUFF      0x04000000
285
#define LANCE_RD_BLEN_STP       0x02000000
286
#define LANCE_RD_BLEN_ENP       0x01000000
287
#define LANCE_RD_BLEN_BPE       0x00800000
288
#define LANCE_RD_BLEN_PAM       0x00400000
289
#define LANCE_RD_BLEN_LAFM      0x00200000
290
#define LANCE_RD_BLEN_BAM       0x00100000
291
#define LANCE_RD_BLEN_MASK      0x0000ffff
292
#endif
293
 
294
// Transmit buffer Descriptor
295
#if 1
296
#define LANCE_TD_PTR       0x00        // 32 bit
297
#define LANCE_TD_LEN       0x04        // 16 bit (2's complement, negative)
298
#define LANCE_TD_MISC      0x06        // 16 bit
299
#define LANCE_TD_SIZE      0x08
300
 
301
#define LANCE_TD_PTR_OWN       0x80000000
302
#define LANCE_TD_PTR_ERR       0x40000000
303
#define LANCE_TD_PTR_ADD_FCS   0x20000000
304
#define LANCE_TD_PTR_MORE      0x10000000
305
#define LANCE_TD_PTR_ONE       0x08000000
306
#define LANCE_TD_PTR_DEF       0x04000000
307
#define LANCE_TD_PTR_STP       0x02000000
308
#define LANCE_TD_PTR_ENP       0x01000000
309
#define LANCE_TD_PTR_MASK      0x00ffffff
310
#else
311
#define LANCE_TD_PTR       0x00
312
#define LANCE_TD_LEN       0x04
313
#define LANCE_TD_MISC      0x08
314
#define LANCE_TD_USER      0x0c
315
#define LANCE_TD_SIZE      0x10
316
 
317
#define LANCE_TD_LEN_OWN       0x80000000
318
#define LANCE_TD_LEN_ERR       0x40000000
319
#define LANCE_TD_LEN_ADD_FCS   0x20000000
320
#define LANCE_TD_LEN_MORE      0x10000000
321
#define LANCE_TD_LEN_ONE       0x08000000
322
#define LANCE_TD_LEN_DEF       0x04000000
323
#define LANCE_TD_LEN_STP       0x02000000
324
#define LANCE_TD_LEN_ENP       0x01000000
325
#define LANCE_TD_LEN_BPE       0x00800000
326
#define LANCE_TD_LEN_MASK      0x0000ffff
327
 
328
#define LANCE_TD_FLAGS_BUFF     0x80000000
329
#define LANCE_TD_FLAGS_UFLO     0x40000000
330
#define LANCE_TD_FLAGS_EX_DEF   0x20000000
331
#define LANCE_TD_FLAGS_LCOL     0x10000000
332
#define LANCE_TD_FLAGS_LCAR     0x08000000
333
#define LANCE_TD_FLAGS_RTRY     0x04000000
334
#define LANCE_TD_FLAGS_TRC_MASK 0x0000000f
335
#endif
336
 
337
 
338
#define LANCE_TD_MISC_BUFF     0x8000
339
#define LANCE_TD_MISC_UFLO     0x4000
340
#define LANCE_TD_MISC_EXDEF    0x2000
341
#define LANCE_TD_MISC_LCOL     0x1000
342
#define LANCE_TD_MISC_LCAR     0x0800
343
#define LANCE_TD_MISC_RTRY     0x0400
344
#define LANCE_TD_MISC_TDR      0x03ff
345
 
346
// Initialization Buffer
347
#define LANCE_IB_MODE            0
348
#define LANCE_IB_PADR0           2
349
#define LANCE_IB_PADR1           4
350
#define LANCE_IB_PADR2           6
351
#define LANCE_IB_LADRF0          8
352
#define LANCE_IB_LADRF1          10
353
#define LANCE_IB_LADRF2          12
354
#define LANCE_IB_LADRF3          14
355
#define LANCE_IB_RDRA            16
356
#define LANCE_IB_TDRA            20
357
#define LANCE_IB_SIZE            24
358
 
359
#define LANCE_IB_TDRA_CNT_shift  29
360
#define LANCE_IB_TDRA_PTR_mask   0x00ffffff
361
#define LANCE_IB_RDRA_CNT_shift  29
362
#define LANCE_IB_RDRA_PTR_mask   0x00ffffff
363
 
364
// ------------------------------------------------------------------------
365
 
366
#ifdef KEEP_STATISTICS
367
struct amd_lancepci_stats {
368
    unsigned int tx_good             ;
369
    unsigned int tx_max_collisions   ;
370
    unsigned int tx_late_collisions  ;
371
    unsigned int tx_underrun         ;
372
    unsigned int tx_carrier_loss     ;
373
    unsigned int tx_deferred         ;
374
    unsigned int tx_sqetesterrors    ;
375
    unsigned int tx_single_collisions;
376
    unsigned int tx_mult_collisions  ;
377
    unsigned int tx_total_collisions ;
378
    unsigned int rx_good             ;
379
    unsigned int rx_crc_errors       ;
380
    unsigned int rx_align_errors     ;
381
    unsigned int rx_resource_errors  ;
382
    unsigned int rx_overrun_errors   ;
383
    unsigned int rx_collisions       ;
384
    unsigned int rx_short_frames     ;
385
    unsigned int rx_too_long_frames  ;
386
    unsigned int rx_symbol_errors    ;
387
    unsigned int interrupts          ;
388
    unsigned int rx_count            ;
389
    unsigned int rx_deliver          ;
390
    unsigned int rx_resource         ;
391
    unsigned int rx_restart          ;
392
    unsigned int tx_count            ;
393
    unsigned int tx_complete         ;
394
    unsigned int tx_dropped          ;
395
};
396
#endif
397
 
398
typedef struct lancepci_priv_data {
399
    int index;
400
    cyg_uint8                           // (split up for atomic byte access)
401
        found:1,                        // was hardware discovered?
402
        mac_addr_ok:1,                  // can we bring up?
403
        active:1,                       // has this if been brung up?
404
        hardwired_esa:1,                // set if ESA is hardwired via CDL
405
        txbusy:1,                       // A packet has been sent
406
        txbusyh:1,                      // A packet has been sent for HW
407
        spare1:2;
408
 
409
    cyg_uint16 event;
410
 
411
    unsigned long txkey;                // Used to ack when packet sent
412
    unsigned char* base;                // Base address of controller EPROM region
413
    int interrupt;                      // Interrupt vector used by controller
414
    unsigned char esa[6];            // Controller ESA
415
    // Function to configure the ESA - may fetch ESA from EPROM or 
416
    // RedBoot config option.
417
    void (*config_esa)(struct lancepci_priv_data* cpd);
418
    void *ndp;                          // Network Device Pointer
419
 
420
    cyg_handle_t  interrupt_handle;
421
    cyg_interrupt interrupt_object;
422
    int devid;
423
 
424
    cyg_uint8* rx_buffers;              // ptr to base of buffer mem
425
    cyg_uint8* rx_ring;                 // ptr to base of rx ring memory
426
    int rx_ring_cnt;                    // number of entries in ring
427
    int rx_ring_log_cnt;                // log of above
428
    int rx_ring_next;                   // index of next full ring entry
429
 
430
    cyg_uint8* tx_buffers;
431
    cyg_uint8* tx_ring;
432
    int tx_ring_cnt;
433
    int tx_ring_log_cnt;
434
    int tx_ring_free;                   // index of next free ring entry
435
    int tx_ring_alloc;                  // index of first controller owned ring
436
    int tx_ring_owned;                  // number of controller owned ring entries
437
 
438
    int rxpacket;
439
#ifdef KEEP_STATISTICS
440
    struct amd_lancepci_stats stats;
441
#endif
442
#if DEBUG & 1
443
    cyg_uint32 txd;
444
#endif
445
    cyg_uint8* init_table;                              // lance init table pointer
446
 
447
} lancepci_priv_data;
448
 
449
// ------------------------------------------------------------------------
450
 
451
static __inline__ cyg_uint16
452
get_reg(struct eth_drv_sc *sc, int regno)
453
{
454
    struct lancepci_priv_data *cpd =
455
        (struct lancepci_priv_data *)sc->driver_private;
456
    cyg_uint16 val, addr;
457
 
458
    if (regno & LANCE_ANR_FLAG) {
459
        // We could do this with recursive calls to get/put reg
460
        // functions, but might as well just do it directly.
461
        // First set ANR address
462
        HAL_PCI_IO_WRITE_UINT16(cpd->base+LANCE_IO_RAP, LANCE_BCR_MIIADDR & LANCE_RAP_MASK);
463
        HAL_PCI_IO_READ_UINT16(cpd->base+LANCE_IO_BDP, addr);
464
        addr &= LANCE_BCR_MIIADDR_PHYAD;
465
        addr |= (regno & LANCE_RAP_MASK);
466
        HAL_PCI_IO_WRITE_UINT16(cpd->base+LANCE_IO_BDP, addr);
467
        // Then read ANR register data
468
        HAL_PCI_IO_WRITE_UINT16(cpd->base+LANCE_IO_RAP, LANCE_BCR_MIIDATA & LANCE_RAP_MASK);
469
        HAL_PCI_IO_READ_UINT16(cpd->base+LANCE_IO_BDP, val);
470
    } else {
471
        HAL_PCI_IO_WRITE_UINT16(cpd->base+LANCE_IO_RAP, regno & LANCE_RAP_MASK);
472
        if (regno & LANCE_BCR_FLAG)
473
            HAL_PCI_IO_READ_UINT16(cpd->base+LANCE_IO_BDP, val);
474
        else
475
            HAL_PCI_IO_READ_UINT16(cpd->base+LANCE_IO_RDP, val);
476
    }
477
#if DEBUG & 2
478
    os_printf("read %s reg %d val 0x%04x\n",
479
                (regno & LANCE_ANR_FLAG) ? "anr" : (regno & LANCE_BCR_FLAG) ? "bcr" : "csr",
480
                regno & LANCE_RAP_MASK, val);
481
#endif
482
    return val;
483
}
484
 
485
static __inline__ void
486
put_reg(struct eth_drv_sc *sc, int regno, cyg_uint16 val)
487
{
488
    struct lancepci_priv_data *cpd =
489
        (struct lancepci_priv_data *)sc->driver_private;
490
    cyg_uint16 addr;
491
 
492
    if (regno & LANCE_ANR_FLAG) {
493
        // We could do this with recursive calls to get/put reg
494
        // functions, but might as well just do it directly.
495
        // First set ANR address
496
        HAL_PCI_IO_WRITE_UINT16(cpd->base+LANCE_IO_RAP, LANCE_BCR_MIIADDR & LANCE_RAP_MASK);
497
        HAL_PCI_IO_READ_UINT16(cpd->base+LANCE_IO_BDP, addr);
498
        addr &= LANCE_BCR_MIIADDR_PHYAD;
499
        addr |= (regno & LANCE_RAP_MASK);
500
        HAL_PCI_IO_WRITE_UINT16(cpd->base+LANCE_IO_BDP, addr);
501
        // Then write ANR register data
502
        HAL_PCI_IO_WRITE_UINT16(cpd->base+LANCE_IO_RAP, LANCE_BCR_MIIDATA & LANCE_RAP_MASK);
503
        HAL_PCI_IO_WRITE_UINT16(cpd->base+LANCE_IO_BDP, val);
504
    } else {
505
        HAL_PCI_IO_WRITE_UINT16(cpd->base+LANCE_IO_RAP, regno & LANCE_RAP_MASK);
506
        if (regno & LANCE_BCR_FLAG)
507
            HAL_PCI_IO_WRITE_UINT16(cpd->base+LANCE_IO_BDP, val);
508
        else
509
            HAL_PCI_IO_WRITE_UINT16(cpd->base+LANCE_IO_RDP, val);
510
    }
511
 
512
#if DEBUG & 2
513
    os_printf("write %s reg %d val 0x%04x\n",
514
                (regno & LANCE_ANR_FLAG) ? "anr" : (regno & LANCE_BCR_FLAG) ? "bcr" : "csr",
515
                regno & LANCE_RAP_MASK, val);
516
#endif
517
}
518
 
519
// ------------------------------------------------------------------------
520
#endif // CYGONCE_DEVS_ETH_AMD_LANCE_H
521
// EOF amd_lance.h

powered by: WebSVN 2.1.0

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