]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/devs/eth/amd/lancepci/v2_0/src/amd_lance.h
Initial revision
[karo-tx-redboot.git] / packages / devs / eth / amd / lancepci / v2_0 / src / amd_lance.h
1 #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 Red Hat, 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 version.
18 //
19 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22 // for more details.
23 //
24 // You should have received a copy of the GNU General Public License along
25 // with eCos; if not, write to the Free Software Foundation, Inc.,
26 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27 //
28 // As a special exception, if other files instantiate templates or use macros
29 // or inline functions from this file, or you compile this file and link it
30 // with other works to produce a work based on this file, this file does not
31 // by itself cause the resulting work to be covered by the GNU General Public
32 // License. However the source code for this file must still be made available
33 // in accordance with section (3) of the GNU General Public License.
34 //
35 // This exception does not invalidate any other reasons why a work based on
36 // this file might be covered by the GNU General Public License.
37 //
38 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
39 // at http://sources.redhat.com/ecos/ecos-license/
40 // -------------------------------------------
41 //####ECOSGPLCOPYRIGHTEND####
42 //####BSDCOPYRIGHTBEGIN####
43 //
44 // -------------------------------------------
45 //
46 // Portions of this software may have been derived from OpenBSD or other sources,
47 // and are covered by the appropriate copyright disclaimers included herein.
48 //
49 // -------------------------------------------
50 //
51 //####BSDCOPYRIGHTEND####
52 //==========================================================================
53 //#####DESCRIPTIONBEGIN####
54 //
55 // Author(s):    jskov, iz
56 // Contributors: jskov, hmt, iz
57 // Date:         2002-07-17
58 // Purpose:      Hardware description of AMD Lance series.
59 // Description:  
60 //
61 //####DESCRIPTIONEND####
62 //
63 //==========================================================================
64
65 #include <cyg/hal/hal_io.h>
66
67 //------------------------------------------------------------------------
68 // Get macros from platform header
69 #define __WANT_CONFIG
70 #include CYGDAT_DEVS_ETH_AMD_LANCEPCI_INL
71 #undef  __WANT_CONFIG
72
73 //------------------------------------------------------------------------
74 // Set to perms of:
75 // 0 disables all debug output
76 // 1 for process debug output
77 // 2 for added data IO output: get_reg, put_reg
78 // 4 for packet allocation/free output
79 // 8 for only startup status, so we can tell we're installed OK
80 #define DEBUG 0x0
81
82 #if DEBUG & 1
83 #define DEBUG_FUNCTION() do { os_printf("%s\n", __FUNCTION__); } while (0)
84 #else
85 #define DEBUG_FUNCTION() do {} while(0)
86 #endif
87
88 // ------------------------------------------------------------------------
89 // Macros for keeping track of statistics
90 #if defined(ETH_DRV_GET_IF_STATS) || defined (ETH_DRV_GET_IF_STATS_UD)
91 # define KEEP_STATISTICS
92 #endif
93
94 #ifdef KEEP_STATISTICS
95 # define INCR_STAT( _x_ )        (cpd->stats. _x_ ++)
96 #else
97 # define INCR_STAT( _x_ )        CYG_EMPTY_STATEMENT
98 #endif
99
100 //------------------------------------------------------------------------
101 // Cache translation
102 #ifndef CYGARC_UNCACHED_ADDRESS
103 # define CYGARC_UNCACHED_ADDRESS(x) (x)
104 #endif
105
106 //------------------------------------------------------------------------
107 // Address translation
108 #ifndef HAL_PCI_CPU_TO_BUS
109 # error "HAL PCI support must define translation macros"
110 #endif
111
112 // ------------------------------------------------------------------------
113 // Macros for accessing structure elements
114
115 #define _SU8( _base_, _offset_) \
116         *((cyg_uint8 *)((CYG_ADDRWORD)_base_+(_offset_)))
117 #define _SU16( _base_, _offset_) \
118         *((cyg_uint16 *)((CYG_ADDRWORD)_base_+(_offset_)))
119 #define _SU32( _base_, _offset_) \
120         *((cyg_uint32 *)((CYG_ADDRWORD)_base_+(_offset_)))
121
122 #define _SI8( _base_, _offset_) \
123         *((cyg_int8 *)((CYG_ADDRWORD)_base_+(_offset_)))
124 #define _SI16( _base_, _offset_) \
125         *((cyg_int16 *)((CYG_ADDRWORD)_base_+(_offset_)))
126 #define _SI32( _base_, _offset_) \
127         *((cyg_int32 *)((CYG_ADDRWORD)_base_+(_offset_)))
128
129 // ------------------------------------------------------------------------
130 // Macros for accessing controller registers
131 #ifndef HAL_PCI_IO_READ_UINT8
132 # define HAL_PCI_IO_READ_UINT8(addr, datum)   HAL_READ_UINT8(addr, datum)
133 # define HAL_PCI_IO_WRITE_UINT8(addr, datum)  HAL_WRITE_UINT8(addr, datum)
134 # define HAL_PCI_IO_READ_UINT16(addr, datum)  HAL_READ_UINT16(addr, datum)
135 # define HAL_PCI_IO_WRITE_UINT16(addr, datum) HAL_WRITE_UINT16(addr, datum)
136 # define HAL_PCI_IO_READ_UINT32(addr, datum)  HAL_READ_UINT32(addr, datum)
137 # define HAL_PCI_IO_WRITE_UINT32(addr, datum) HAL_WRITE_UINT32(addr, datum)
138 #endif
139
140 // ------------------------------------------------------------------------
141 // IO map registers
142 #define LANCE_IO_EEPROM   0x00
143 #define LANCE_IO_ID       0x0e
144 #define LANCE_IO_RDP      0x10
145 #define LANCE_IO_RAP      0x12
146 #define LANCE_IO_RESET    0x14
147 #define LANCE_IO_BDP      0x16
148
149 // The ID of the 79C790 is 0x5757 - that may be different in other
150 // (older) cards.
151 #define LANCE_IO_ID_KEY   0x5757
152
153 // ------------------------------------------------------------------------
154 // Controller registers come in three sets: CSR, BCR and ANR. Use
155 // high-bits do differentiate, make the put/get functions do the right
156 // thing depending the state of these bits.
157 #define LANCE_RAP_MASK    0x007f
158 //#define LANCE_CSR_FLAG  0x0000        // implied
159 #define LANCE_BCR_FLAG    0x0080
160 #define LANCE_ANR_FLAG    0x0100
161
162
163 // CSR registers
164 #define LANCE_CSR_CSCR    0
165 #define LANCE_CSR_IBA0    1
166 #define LANCE_CSR_IBA1    2
167 #define LANCE_CSR_IM      3
168 #define LANCE_CSR_TFC     4
169 #define LANCE_CSR_ECI     5
170 #define LANCE_CSR_LAR0    8
171 #define LANCE_CSR_LAR1    9
172 #define LANCE_CSR_LAR2    10
173 #define LANCE_CSR_LAR3    11
174 #define LANCE_CSR_PAR0    12
175 #define LANCE_CSR_PAR1    13
176 #define LANCE_CSR_PAR2    14
177 #define LANCE_CSR_MODE    15
178 #define LANCE_CSR_BARRL   24
179 #define LANCE_CSR_BARRU   25
180 #define LANCE_CSR_BATRL   30
181 #define LANCE_CSR_BATRU   31
182 #define LANCE_CSR_RRC     72
183 #define LANCE_CSR_TRC     74
184 #define LANCE_CSR_RRLEN   76
185 #define LANCE_CSR_TRLEN   78
186 #define LANCE_CSR_ID_LO   88
187 #define LANCE_CSR_ID_HI   89
188
189
190 #define LANCE_CSR_CSCR_ERR       0x8000
191 #define LANCE_CSR_CSCR_RES       0x4000
192 #define LANCE_CSR_CSCR_CERR      0x2000
193 #define LANCE_CSR_CSCR_MISS      0x1000
194 #define LANCE_CSR_CSCR_MERR      0x0800
195 #define LANCE_CSR_CSCR_RINT      0x0400
196 #define LANCE_CSR_CSCR_TINT      0x0200
197 #define LANCE_CSR_CSCR_IDON      0x0100
198 #define LANCE_CSR_CSCR_INTR      0x0080
199 #define LANCE_CSR_CSCR_IENA      0x0040
200 #define LANCE_CSR_CSCR_RXON      0x0020
201 #define LANCE_CSR_CSCR_TXON      0x0010
202 #define LANCE_CSR_CSCR_TDMD      0x0008
203 #define LANCE_CSR_CSCR_STOP      0x0004
204 #define LANCE_CSR_CSCR_STRT      0x0002
205 #define LANCE_CSR_CSCR_INIT      0x0001
206
207 #define LANCE_CSR_CSCR_EV_MASK   0x007f
208
209 #define LANCE_CSR_IM_MISSM       0x1000
210 #define LANCE_CSR_IM_MERRM       0x0800
211 #define LANCE_CSR_IM_RINTM       0x0400
212 #define LANCE_CSR_IM_TINTM       0x0200
213 #define LANCE_CSR_IM_IDONM       0x0100
214 #define LANCE_CSR_IM_DXSUFLO     0x0040
215 #define LANCE_CSR_IM_LAPPEN      0x0020
216 #define LANCE_CSR_IM_DXMT2PD     0x0010
217 #define LANCE_CSR_IM_EMBA        0x0008
218 #define LANCE_CSR_IM_BSWP        0x0004
219
220 #define LANCE_CSR_TFC_TXDPOLL    0x1000
221 #define LANCE_CSR_TFC_APAD_XMT   0x0800
222 #define LANCE_CSR_TFC_ASTRP_RCV  0x0400
223 #define LANCE_CSR_TFC_MFCO       0x0200
224 #define LANCE_CSR_TFC_MFCOM      0x0100
225 #define LANCE_CSR_TFC_UINTCMD    0x0080
226 #define LANCE_CSR_TFC_UINT       0x0040
227 #define LANCE_CSR_TFC_RCVCCO     0x0020
228 #define LANCE_CSR_TFC_RCVCCOM    0x0010
229 #define LANCE_CSR_TFC_TXSTRT     0x0008
230 #define LANCE_CSR_TFC_TXSTRTM    0x0004
231
232 #define LANCE_CSR_ECI_TOKINTD      0x8000
233 #define LANCE_CSR_ECI_LTINTEN      0x4000
234 #define LANCE_CSR_ECI_SINT         0x0800
235 #define LANCE_CSR_ECI_SINTE        0x0400
236 #define LANCE_CSR_ECI_EXDINT       0x0080
237 #define LANCE_CSR_ECI_EXDINTE      0x0040
238 #define LANCE_CSR_ECI_MPPLBA       0x0020
239 #define LANCE_CSR_ECI_MPINT        0x0010
240 #define LANCE_CSR_ECI_MPINTE       0x0008
241 #define LANCE_CSR_ECI_MPEN         0x0004
242 #define LANCE_CSR_ECI_MPMODE       0x0002
243 #define LANCE_CSR_ECI_SPND         0x0001
244
245 #define LANCE_CSR_MODE_PROM        0x8000
246 #define LANCE_CSR_MODE_DRCVBC      0x4000
247 #define LANCE_CSR_MODE_DRCVPA      0x2000
248 #define LANCE_CSR_MODE_PORTSEL     0x0180
249 #define LANCE_CSR_MODE_INTL        0x0040
250 #define LANCE_CSR_MODE_DRTY        0x0020
251 #define LANCE_CSR_MODE_FCOLL       0x0010
252 #define LANCE_CSR_MODE_DXMTFCS     0x0008
253 #define LANCE_CSR_MODE_LOOP        0x0004
254 #define LANCE_CSR_MODE_DTX         0x0002
255 #define LANCE_CSR_MODE_DRX         0x0001
256
257 // BCR registers
258 #define LANCE_BCR_SWSTYLE (20 |LANCE_BCR_FLAG)
259 #define LANCE_BCR_MIIADDR (33 |LANCE_BCR_FLAG)
260 #define LANCE_BCR_MIIDATA (34 |LANCE_BCR_FLAG)
261
262 #define LANCE_BCR_MIIADDR_PHYAD    0x03e0
263
264
265 //----------------------------------------------------------------------------
266 // Receive buffer Descriptor
267 #if 1
268 #define LANCE_RD_PTR       0x00        // 32 bit
269 #define LANCE_RD_BLEN      0x04        // 16 bit (2's complement, negative)
270 #define LANCE_RD_MLEN      0x06        // 16 bit
271 #define LANCE_RD_SIZE      0x08
272
273 #define LANCE_RD_PTR_OWN       0x80000000
274 #define LANCE_RD_PTR_ERR       0x40000000
275 #define LANCE_RD_PTR_FRAM      0x20000000
276 #define LANCE_RD_PTR_OFLO      0x10000000
277 #define LANCE_RD_PTR_CRC       0x08000000
278 #define LANCE_RD_PTR_BUFF      0x04000000
279 #define LANCE_RD_PTR_STP       0x02000000
280 #define LANCE_RD_PTR_ENP       0x01000000
281 #define LANCE_RD_PTR_MASK      0x00ffffff
282 #else
283
284 #define LANCE_RD_PTR       0x00
285 #define LANCE_RD_BLEN      0x04
286 #define LANCE_RD_MLEN      0x08
287 #define LANCE_RD_USER      0x0c
288 #define LANCE_RD_SIZE      0x10
289
290 #define LANCE_RD_BLEN_OWN       0x80000000
291 #define LANCE_RD_BLEN_ERR       0x40000000
292 #define LANCE_RD_BLEN_FRAM      0x20000000
293 #define LANCE_RD_BLEN_OFLO      0x10000000
294 #define LANCE_RD_BLEN_CRC       0x08000000
295 #define LANCE_RD_BLEN_BUFF      0x04000000
296 #define LANCE_RD_BLEN_STP       0x02000000
297 #define LANCE_RD_BLEN_ENP       0x01000000
298 #define LANCE_RD_BLEN_BPE       0x00800000
299 #define LANCE_RD_BLEN_PAM       0x00400000
300 #define LANCE_RD_BLEN_LAFM      0x00200000
301 #define LANCE_RD_BLEN_BAM       0x00100000
302 #define LANCE_RD_BLEN_MASK      0x0000ffff
303 #endif
304
305 // Transmit buffer Descriptor
306 #if 1
307 #define LANCE_TD_PTR       0x00        // 32 bit
308 #define LANCE_TD_LEN       0x04        // 16 bit (2's complement, negative)
309 #define LANCE_TD_MISC      0x06        // 16 bit
310 #define LANCE_TD_SIZE      0x08
311
312 #define LANCE_TD_PTR_OWN       0x80000000
313 #define LANCE_TD_PTR_ERR       0x40000000
314 #define LANCE_TD_PTR_ADD_FCS   0x20000000
315 #define LANCE_TD_PTR_MORE      0x10000000
316 #define LANCE_TD_PTR_ONE       0x08000000
317 #define LANCE_TD_PTR_DEF       0x04000000
318 #define LANCE_TD_PTR_STP       0x02000000
319 #define LANCE_TD_PTR_ENP       0x01000000
320 #define LANCE_TD_PTR_MASK      0x00ffffff
321 #else
322 #define LANCE_TD_PTR       0x00
323 #define LANCE_TD_LEN       0x04
324 #define LANCE_TD_MISC      0x08
325 #define LANCE_TD_USER      0x0c
326 #define LANCE_TD_SIZE      0x10
327
328 #define LANCE_TD_LEN_OWN       0x80000000
329 #define LANCE_TD_LEN_ERR       0x40000000
330 #define LANCE_TD_LEN_ADD_FCS   0x20000000
331 #define LANCE_TD_LEN_MORE      0x10000000
332 #define LANCE_TD_LEN_ONE       0x08000000
333 #define LANCE_TD_LEN_DEF       0x04000000
334 #define LANCE_TD_LEN_STP       0x02000000
335 #define LANCE_TD_LEN_ENP       0x01000000
336 #define LANCE_TD_LEN_BPE       0x00800000
337 #define LANCE_TD_LEN_MASK      0x0000ffff
338
339 #define LANCE_TD_FLAGS_BUFF     0x80000000
340 #define LANCE_TD_FLAGS_UFLO     0x40000000
341 #define LANCE_TD_FLAGS_EX_DEF   0x20000000
342 #define LANCE_TD_FLAGS_LCOL     0x10000000
343 #define LANCE_TD_FLAGS_LCAR     0x08000000
344 #define LANCE_TD_FLAGS_RTRY     0x04000000
345 #define LANCE_TD_FLAGS_TRC_MASK 0x0000000f
346 #endif
347
348
349 #define LANCE_TD_MISC_BUFF     0x8000
350 #define LANCE_TD_MISC_UFLO     0x4000
351 #define LANCE_TD_MISC_EXDEF    0x2000
352 #define LANCE_TD_MISC_LCOL     0x1000
353 #define LANCE_TD_MISC_LCAR     0x0800
354 #define LANCE_TD_MISC_RTRY     0x0400
355 #define LANCE_TD_MISC_TDR      0x03ff
356
357 // Initialization Buffer
358 #define LANCE_IB_MODE            0
359 #define LANCE_IB_PADR0           2
360 #define LANCE_IB_PADR1           4
361 #define LANCE_IB_PADR2           6
362 #define LANCE_IB_LADRF0          8
363 #define LANCE_IB_LADRF1          10
364 #define LANCE_IB_LADRF2          12
365 #define LANCE_IB_LADRF3          14
366 #define LANCE_IB_RDRA            16
367 #define LANCE_IB_TDRA            20
368 #define LANCE_IB_SIZE            24
369
370 #define LANCE_IB_TDRA_CNT_shift  29
371 #define LANCE_IB_TDRA_PTR_mask   0x00ffffff
372 #define LANCE_IB_RDRA_CNT_shift  29
373 #define LANCE_IB_RDRA_PTR_mask   0x00ffffff
374
375 // ------------------------------------------------------------------------
376
377 #ifdef KEEP_STATISTICS
378 struct amd_lancepci_stats {
379     unsigned int tx_good             ;
380     unsigned int tx_max_collisions   ;
381     unsigned int tx_late_collisions  ;
382     unsigned int tx_underrun         ;
383     unsigned int tx_carrier_loss     ;
384     unsigned int tx_deferred         ;
385     unsigned int tx_sqetesterrors    ;
386     unsigned int tx_single_collisions;
387     unsigned int tx_mult_collisions  ;
388     unsigned int tx_total_collisions ;
389     unsigned int rx_good             ;
390     unsigned int rx_crc_errors       ;
391     unsigned int rx_align_errors     ;
392     unsigned int rx_resource_errors  ;
393     unsigned int rx_overrun_errors   ;
394     unsigned int rx_collisions       ;
395     unsigned int rx_short_frames     ;
396     unsigned int rx_too_long_frames  ;
397     unsigned int rx_symbol_errors    ;
398     unsigned int interrupts          ;
399     unsigned int rx_count            ;
400     unsigned int rx_deliver          ;
401     unsigned int rx_resource         ;
402     unsigned int rx_restart          ;
403     unsigned int tx_count            ;
404     unsigned int tx_complete         ;
405     unsigned int tx_dropped          ;
406 };
407 #endif
408
409 typedef struct lancepci_priv_data {
410     int index;
411     cyg_uint8                           // (split up for atomic byte access)
412         found:1,                        // was hardware discovered?
413         mac_addr_ok:1,                  // can we bring up?
414         active:1,                       // has this if been brung up?
415         hardwired_esa:1,                // set if ESA is hardwired via CDL
416         txbusy:1,                       // A packet has been sent
417         txbusyh:1,                      // A packet has been sent for HW
418         spare1:2; 
419
420     cyg_uint16 event;
421     
422     unsigned long txkey;                // Used to ack when packet sent
423     unsigned char* base;                // Base address of controller EPROM region
424     int interrupt;                      // Interrupt vector used by controller
425     unsigned char esa[6];            // Controller ESA
426     // Function to configure the ESA - may fetch ESA from EPROM or 
427     // RedBoot config option.
428     void (*config_esa)(struct lancepci_priv_data* cpd);
429     void *ndp;                          // Network Device Pointer
430
431     cyg_handle_t  interrupt_handle;
432     cyg_interrupt interrupt_object;
433     int devid;
434
435     cyg_uint8* rx_buffers;              // ptr to base of buffer mem
436     cyg_uint8* rx_ring;                 // ptr to base of rx ring memory
437     int rx_ring_cnt;                    // number of entries in ring
438     int rx_ring_log_cnt;                // log of above
439     int rx_ring_next;                   // index of next full ring entry
440
441     cyg_uint8* tx_buffers;
442     cyg_uint8* tx_ring;
443     int tx_ring_cnt;
444     int tx_ring_log_cnt;
445     int tx_ring_free;                   // index of next free ring entry
446     int tx_ring_alloc;                  // index of first controller owned ring
447     int tx_ring_owned;                  // number of controller owned ring entries
448
449     int rxpacket;
450 #ifdef KEEP_STATISTICS
451     struct amd_lancepci_stats stats;
452 #endif
453 #if DEBUG & 1
454     cyg_uint32 txd;
455 #endif
456     cyg_uint8* init_table;                              // lance init table pointer
457
458 } lancepci_priv_data;
459
460 // ------------------------------------------------------------------------
461
462 static __inline__ cyg_uint16
463 get_reg(struct eth_drv_sc *sc, int regno)
464 {
465     struct lancepci_priv_data *cpd =
466         (struct lancepci_priv_data *)sc->driver_private;
467     cyg_uint16 val, addr;
468
469     if (regno & LANCE_ANR_FLAG) {
470         // We could do this with recursive calls to get/put reg
471         // functions, but might as well just do it directly.
472         // First set ANR address
473         HAL_PCI_IO_WRITE_UINT16(cpd->base+LANCE_IO_RAP, LANCE_BCR_MIIADDR & LANCE_RAP_MASK);
474         HAL_PCI_IO_READ_UINT16(cpd->base+LANCE_IO_BDP, addr);
475         addr &= LANCE_BCR_MIIADDR_PHYAD;
476         addr |= (regno & LANCE_RAP_MASK);
477         HAL_PCI_IO_WRITE_UINT16(cpd->base+LANCE_IO_BDP, addr);
478         // Then read ANR register data
479         HAL_PCI_IO_WRITE_UINT16(cpd->base+LANCE_IO_RAP, LANCE_BCR_MIIDATA & LANCE_RAP_MASK);
480         HAL_PCI_IO_READ_UINT16(cpd->base+LANCE_IO_BDP, val);
481     } else {
482         HAL_PCI_IO_WRITE_UINT16(cpd->base+LANCE_IO_RAP, regno & LANCE_RAP_MASK);
483         if (regno & LANCE_BCR_FLAG)
484             HAL_PCI_IO_READ_UINT16(cpd->base+LANCE_IO_BDP, val);
485         else
486             HAL_PCI_IO_READ_UINT16(cpd->base+LANCE_IO_RDP, val);
487     }
488 #if DEBUG & 2
489     os_printf("read %s reg %d val 0x%04x\n", 
490                 (regno & LANCE_ANR_FLAG) ? "anr" : (regno & LANCE_BCR_FLAG) ? "bcr" : "csr", 
491                 regno & LANCE_RAP_MASK, val);
492 #endif
493     return val;
494 }
495
496 static __inline__ void
497 put_reg(struct eth_drv_sc *sc, int regno, cyg_uint16 val)
498 {
499     struct lancepci_priv_data *cpd =
500         (struct lancepci_priv_data *)sc->driver_private;
501     cyg_uint16 addr;
502
503     if (regno & LANCE_ANR_FLAG) {
504         // We could do this with recursive calls to get/put reg
505         // functions, but might as well just do it directly.
506         // First set ANR address
507         HAL_PCI_IO_WRITE_UINT16(cpd->base+LANCE_IO_RAP, LANCE_BCR_MIIADDR & LANCE_RAP_MASK);
508         HAL_PCI_IO_READ_UINT16(cpd->base+LANCE_IO_BDP, addr);
509         addr &= LANCE_BCR_MIIADDR_PHYAD;
510         addr |= (regno & LANCE_RAP_MASK);
511         HAL_PCI_IO_WRITE_UINT16(cpd->base+LANCE_IO_BDP, addr);
512         // Then write ANR register data
513         HAL_PCI_IO_WRITE_UINT16(cpd->base+LANCE_IO_RAP, LANCE_BCR_MIIDATA & LANCE_RAP_MASK);
514         HAL_PCI_IO_WRITE_UINT16(cpd->base+LANCE_IO_BDP, val);
515     } else {
516         HAL_PCI_IO_WRITE_UINT16(cpd->base+LANCE_IO_RAP, regno & LANCE_RAP_MASK);
517         if (regno & LANCE_BCR_FLAG)
518             HAL_PCI_IO_WRITE_UINT16(cpd->base+LANCE_IO_BDP, val);
519         else
520             HAL_PCI_IO_WRITE_UINT16(cpd->base+LANCE_IO_RDP, val);
521     }
522
523 #if DEBUG & 2
524     os_printf("write %s reg %d val 0x%04x\n", 
525                 (regno & LANCE_ANR_FLAG) ? "anr" : (regno & LANCE_BCR_FLAG) ? "bcr" : "csr", 
526                 regno & LANCE_RAP_MASK, val);
527 #endif
528 }
529
530 // ------------------------------------------------------------------------
531 #endif // CYGONCE_DEVS_ETH_AMD_LANCE_H
532 // EOF amd_lance.h