1 //==========================================================================
5 // Intel 82559 ethernet driver
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
12 // Copyright (C) 2002, 2003 Gary Thomas
14 // eCos is free software; you can redistribute it and/or modify it under
15 // the terms of the GNU General Public License as published by the Free
16 // Software Foundation; either version 2 or (at your option) any later version.
18 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
19 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 // You should have received a copy of the GNU General Public License along
24 // with eCos; if not, write to the Free Software Foundation, Inc.,
25 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27 // As a special exception, if other files instantiate templates or use macros
28 // or inline functions from this file, or you compile this file and link it
29 // with other works to produce a work based on this file, this file does not
30 // by itself cause the resulting work to be covered by the GNU General Public
31 // License. However the source code for this file must still be made available
32 // in accordance with section (3) of the GNU General Public License.
34 // This exception does not invalidate any other reasons why a work based on
35 // this file might be covered by the GNU General Public License.
37 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
38 // at http://sources.redhat.com/ecos/ecos-license/
39 // -------------------------------------------
40 //####ECOSGPLCOPYRIGHTEND####
41 //####BSDCOPYRIGHTBEGIN####
43 // -------------------------------------------
45 // Portions of this software may have been derived from OpenBSD or
46 // other sources, and are covered by the appropriate copyright
47 // disclaimers included herein.
49 // -------------------------------------------
51 //####BSDCOPYRIGHTEND####
52 //==========================================================================
53 //#####DESCRIPTIONBEGIN####
55 // Author(s): hmt, gthomas
56 // Contributors: Ron Spence, Pacific Softworks, jskov
59 // Description: hardware driver for 82559 Intel PRO/100+ ethernet
60 // Notes: CU commands such as dump and config should, according
61 // to the docs, set the CU active state while executing.
62 // That does not seem to be the case though, and the
63 // driver polls the completion bit in the packet status
66 // Platform code may provide this vector:
67 // CYGNUM_DEVS_ETH_INTEL_I82559_SEPARATE_MUX_INTERRUPT if it
68 // requires the interrupts to be handled via demuxers
69 // attached to a distinct interrupt.
71 // Platform code may alternatively define:
72 // CYGHWR_DEVS_ETH_INTEL_I82559_DEMUX_ALL if it is necessary
73 // to demux all interrupt sources - for example if they are
74 // wire-or'd together on some hardware but distinct on
75 // others. In this circumstance it is permitted for
76 // cyg_pci_translate_interrupt [HAL_PCI_TRANSLATE_INTERRUPT]
77 // to return invalid for 2nd and subsequent devices.
79 // Platform code can also define these three:
80 // CYGPRI_DEVS_ETH_INTEL_I82559_MASK_INTERRUPTS(p_i82559,old)
81 // CYGPRI_DEVS_ETH_INTEL_I82559_UNMASK_INTERRUPTS(p_i82559,old)
82 // CYGPRI_DEVS_ETH_INTEL_I82559_ACK_INTERRUPTS(p_i82559)
83 // which are particularly useful when nested interrupt
84 // management is needed (which is always IMHO).
86 // Platform code can define this:
87 // CYGHWR_DEVS_ETH_INTEL_I82559_MISSED_INTERRUPT(p_i82559)
88 // to detect a dropped interrupt and loop again or
89 // direct-call the DSR to reschedule the delivery routine.
90 // Only a problem on edge-triggered interrupt systems.
92 // Platform code can also provide this macro:
93 // CYGPRI_DEVS_ETH_INTEL_I82559_INTERRUPT_ACK_LOOP(p_i82559)
94 // to handle delaying for acks to register on the interrupt
95 // controller as necessary on the EBSA.
97 // Platform can define CYGHWR_DEVS_ETH_INTEL_I82559_GET_ESA()
98 // as an external means to get ESAs, possibly from RedBoot
99 // configuration info that's stored in flash memory.
101 // Platform def CYGHWR_DEVS_ETH_INTEL_I82559_HAS_NO_EEPROM
102 // removes all code for dealing with the EEPROM for those
103 // targets where there is none fitted. Either an external
104 // means to get ESAs should be used, or we must rely on
105 // hard-wiring the ESA's into each executable by means of the
106 // usual CDL configuration.
108 // Platform def CYGHWR_DEVS_ETH_INTEL_I82559_HAS_ONE_EEPROM
109 // is for hardware with multiple devices, but only one with a
110 // serial EEPROM installed. The 2nd device would get either
111 // the same ESA - because they are certain to be on different
112 // segment and internets - or the same ESA incremented by
113 // CYGHWR_DEVS_ETH_INTEL_I82559_HAS_ONE_EEPROM_MAC_ADJUST.
114 // CYGHWR_DEVS_ETH_INTEL_I82559_HAS_ONE_EEPROM should be the
115 // number (0 or 1) of the device that does have the EEPROM.
117 // CYGHWR_DEVS_ETH_INTEL_I82559_PCIMEM_DISCONTIGUOUS enables
118 // checking code for breaks in the physical address of PCI
119 // window memory. This can happen on some boards where a
120 // smaller SDRAM is fitted than the hardware allows, so some
121 // higher-order address bits are ignored. We make SDRAM
122 // contiguous in mapped memory, but what the i82559 sees
123 // might be discontiguous. The checking code skips any
124 // allocated chunk who appears to contain such a break, and
127 // CYGHWR_DEVS_ETH_INTEL_I82559_RESET_TIMEOUT( int32 )
128 // CYGHWR_DEVS_ETH_INTEL_I82559_TIMEOUT_FIRED( int32 ) if
129 // both defined give the driver a means to detect that we
130 // have been fixated on the same transmit operation for too
131 // long - we missed an interrupt or the device crashed. The
132 // int32 argument is used to hold a eg. the value of a
133 // fast-running hardware timer.
135 // CYGHWR_DEVS_ETH_INTEL_I82559_ENDIAN_NEUTRAL_IO if PCI IO
136 // access is not affected by CPU endianess.
138 // FIXME: replace -1/-2 return values with proper E-defines
139 // FIXME: For 82557/8 compatibility i82559_configure() function
140 // probably needs some tweaking - config bits differ
141 // slightly but crucially.
142 // FIXME: EEPROM code not tested on a BE system.
144 //####DESCRIPTIONEND####
146 //==========================================================================
148 #include <pkgconf/system.h>
149 #ifdef CYGPKG_IO_ETH_DRIVERS
150 #include <pkgconf/io_eth_drivers.h>
152 #include <pkgconf/devs_eth_intel_i82559.h>
154 #include <cyg/infra/cyg_type.h>
155 #include <cyg/infra/cyg_ass.h>
156 #include <cyg/hal/hal_arch.h>
157 #include <cyg/hal/hal_intr.h>
158 #include <cyg/infra/diag.h>
159 #include <cyg/hal/hal_if.h>
160 #include <cyg/hal/drv_api.h>
161 #include <cyg/io/eth/netdev.h>
162 #include <cyg/io/eth/eth_drv.h>
167 #include <pkgconf/net.h>
168 #include <net/if.h> /* Needed for struct ifnet */
172 #include <cyg/io/pci.h>
173 // So we can check the validity of the PCI window against the MLTs opinion,
174 // and thereby what the malloc heap consumes willy-nilly:
175 #include CYGHWR_MEMORY_LAYOUT_H
177 #error "Need PCI package here"
180 // Exported statistics and the like
181 #include <cyg/devs/eth/i82559_info.h>
182 #include <cyg/io/eth/eth_drv_stats.h>
183 #include CYGDAT_DEVS_ETH_INTEL_I82559_INL
185 #include <cyg/hal/hal_if.h>
187 // Use with care! Local variable defined!
188 #define START_CONSOLE() \
191 CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT); \
194 if ( CYGACC_CALL_IF_FLASH_CFG_OP( CYGNUM_CALL_IF_FLASH_CFG_GET, \
195 "info_console_force", &i, \
196 CYGNUM_FLASH_CFG_TYPE_CONFIG_BOOL ) ) { \
198 if ( CYGACC_CALL_IF_FLASH_CFG_OP( CYGNUM_CALL_IF_FLASH_CFG_GET, \
199 "info_console_number", &i, \
200 CYGNUM_FLASH_CFG_TYPE_CONFIG_INT ) ){ \
201 /* Then i is the console to force it to: */ \
202 CYGACC_CALL_IF_SET_CONSOLE_COMM( i ); \
208 #define END_CONSOLE() \
209 CYGACC_CALL_IF_SET_CONSOLE_COMM(_cur_console); \
212 void CheckRxRing(struct i82559* p_i82559, const char * func, int line);
214 // ------------------------------------------------------------------------
215 // Check on the environment.
217 // These are not CDL type config points; they are set up for your platform
218 // in the platform driver's include file and that's that. These messages
219 // are for the eCos driver writer, not config tool users.
221 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_DEMUX_ALL
222 #ifdef CYGNUM_DEVS_ETH_INTEL_I82559_SEPARATE_MUX_INTERRUPT
223 #error Both a separate demux interrupt *and* DEMUX_ALL are defined
227 #ifdef CYGPKG_DEVS_ETH_INTEL_I82559_WRITE_EEPROM
228 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_HAS_NO_EEPROM
229 #error This platform has no EEPROM, yet WRITE_EEPROM is enabled
233 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_HAS_NO_EEPROM
234 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_HAS_ONE_EEPROM
235 #error This platform has no EEPROM, yet it also HAS_ONE_EEPROM
239 // ------------------------------------------------------------------------
241 #ifdef CYGDBG_DEVS_ETH_INTEL_I82559_CHATTER
242 #define DEBUG // Startup printing mainly
243 #define DEBUG_EE // Some EEPROM specific retries &c
244 #if (CYGDBG_DEVS_ETH_INTEL_I82559_CHATTER > 1)
245 #define DEBUG_82559 // This one prints stuff as packets come and go
249 #ifdef CYGDBG_USE_ASSERTS
254 int waitcmd_timeouts;
255 int waitcmd_timeouts_cu;
258 } missed_interrupt = { 0,0,0, 0,0, 0, 0 };
262 console_printf(const char *fmt, ...)
270 ret = diag_vprintf(fmt, ap);
277 #define os_printf console_printf
278 #define db_printf console_printf
280 // ------------------------------------------------------------------------
284 // There is scope for confusion here; we deal with LE/BE systems and
285 // addressing issues in two separate ways depending on the type of access
288 // 1) IO-style access to the device regsiters over the PCI bus
289 // 2) Memory access to build and read the structures in shared memory
293 // 1) IO-style access to the device regsiters over the PCI bus
295 // All such access is via macros which perform byte-swapping as necessary
296 // for the endianness of the CPU. These macros are called INL, INW, INB
297 // and OUTL, OUTW, OUTB - for Long (32) Word (16) and Byte (8). Intel
298 // nomenclature seems to have crept in here for shorts.
300 // Consequently, all the constants only have to be expressed once, in their
301 // true LE format - bit 15 is 0x8000, bit 0 is 1.
303 // All the offsets are also only expressed once. This is OK so long as GIB
304 // endian addressing (sic, see below) is not employed - or so long as is
305 // does not affect the PCI bus accesses.
308 // 2) Memory access to build and read the structures in shared memory
310 // These accesses are by means of peek and poke to an address created from
311 // a base + offset. No swapping occurs within the access so all constants
312 // and flags need to be defined twice, once for BE and once for LE
313 // accesses. Worse, for BE, constants need to be defined in flavours for
314 // 16-bit versus 32-bit accesses, ie. 0x8000 sets bit 7 only in BE; for a
315 // 32-bit access you must instead write 0x80000000 to set bit 7.
317 // Thus all constants are defined twice depending on the CPU's endianness.
319 // For most BE/LE machines, this is sufficient; the layout of memory is the
320 // same. Specifically, within a 32-bit word, byte[0] will be data[0:7],
321 // short[0] will be data [0:15] and so on. &byte[0] == &short[0] == &word
322 // regardless. But data[0:7] *OF THE MEMORY SYSTEM* will hold either the
323 // LSbyte (0xFF) on a LE machine, and the MSbyte (0xFF000000) on a BE
324 // machine, for a 32-bit access.
326 // It is in terms of the memory system that the i82559 defines its view of
329 // Therefore the structure layouts remain the same for both BE and LE
330 // machines. This means that the offsets for, specifically, the status
331 // word in command blocks is always zero, and the offset for the command
332 // word is always two.
334 // But there is one furter variant: so-called GIB endian. (BIG endian
335 // backwards) Some architectures support BE only for software
336 // compatibility; they allow code to run which relies on overlaid C
337 // structures behaving in a certain way; specifically
338 // *(char *)&i == (i >> 24)
339 // ARM's BE mode is an example of this.
341 // But while such an operation would use data[0:7] for the char access in a
342 // true BE or any LE system, in a GE system, data[24:31] are used here.
343 // The implementation is that for memory accesses, A0 and A1 are inverted
344 // before going outside to the memory system. So if &i == 0x1000,
345 // accessing i uses address 0x1000, A0 and A1 being ignored for a 32-bit
346 // access. But the 8-bit access to *(char *)&i also uses 0x1000 for the
347 // address as the code sees it, the memory system sees a byte request for
348 // address 0x1003, thus picking up the MSbyte, from data[24:31].
350 // For such addressing, offsets need to be redefined to swap bytes and
351 // shorts within words. Therefore offsets are defined twice, once for
352 // "normal" addressing, and once for "GIB endian" addressing.
354 // FIXME: this BE/GE configuration probably won't work with an ARM in its
355 // BE mode - because that will define the global BE flags, yet it's not
357 // Perhaps a solution whereby the GE flag CYG_ADDRESSING_IS_GIBENDIAN
358 // overrides the BYTEORDER choices would be good; we want the constants to
359 // be LE, but address offsets to be swapped per GE.
363 // ------------------------------------------------------------------------
364 // I/O access macros as inlines for type safety
366 #if (CYG_BYTEORDER == CYG_MSBFIRST)
368 #define HAL_CTOLE32(x) ((((x) & 0xff) << 24) | (((x) & 0xff00) << 8) | (((x) & 0xff0000) >> 8) | (((x) >> 24) & 0xff))
369 #define HAL_LE32TOC(x) ((((x) & 0xff) << 24) | (((x) & 0xff00) << 8) | (((x) & 0xff0000) >> 8) | (((x) >> 24) & 0xff))
371 #define HAL_CTOLE16(x) ((((x) & 0xff) << 8) | (((x) & 0xff00) >> 8))
372 #define HAL_LE16TOC(x) ((((x) & 0xff) << 8) | (((x) & 0xff00) >> 8))
375 // Maintaining the same styleee as above...
376 #define HAL_CTOLE32(x) ((((x))))
377 #define HAL_LE32TOC(x) ((((x))))
379 #define HAL_CTOLE16(x) ((((x))))
380 #define HAL_LE16TOC(x) ((((x))))
385 #if (CYG_BYTEORDER == CYG_MSBFIRST) && !defined(CYGHWR_DEVS_ETH_INTEL_I82559_ENDIAN_NEUTRAL_IO)
387 static inline void OUTB(cyg_uint8 value, cyg_uint32 io_address)
389 HAL_WRITE_UINT8( io_address, value);
392 static inline void OUTW(cyg_uint16 value, cyg_uint32 io_address)
394 HAL_WRITE_UINT16( io_address, (((value & 0xff) << 8) | ((value & 0xff00) >> 8)) );
397 static inline void OUTL(cyg_uint32 value, cyg_uint32 io_address)
399 HAL_WRITE_UINT32( io_address,
400 ((((value) & 0xff) << 24) | (((value) & 0xff00) << 8) | (((value) & 0xff0000) >> 8) | (((value) >> 24) & 0xff)) );
403 static inline cyg_uint8 INB(cyg_uint32 io_address)
406 HAL_READ_UINT8( io_address, d );
410 static inline cyg_uint16 INW(cyg_uint32 io_address)
413 HAL_READ_UINT16( io_address, d );
414 return (((d & 0xff) << 8) | ((d & 0xff00) >> 8));
417 static inline cyg_uint32 INL(cyg_uint32 io_address)
420 HAL_READ_UINT32( io_address, d );
421 return ((((d) & 0xff) << 24) | (((d) & 0xff00) << 8) | (((d) & 0xff0000) >> 8) | (((d) >> 24) & 0xff));
425 static inline void OUTB(cyg_uint8 value, cyg_uint32 io_address)
426 { HAL_WRITE_UINT8( io_address, value ); }
428 static inline void OUTW(cyg_uint16 value, cyg_uint32 io_address)
429 { HAL_WRITE_UINT16( io_address, value ); }
431 static inline void OUTL(cyg_uint32 value, cyg_uint32 io_address)
432 { HAL_WRITE_UINT32( io_address, value ); }
434 static inline cyg_uint8 INB(cyg_uint32 io_address)
435 { cyg_uint8 _t_; HAL_READ_UINT8( io_address, _t_ ); return _t_; }
437 static inline cyg_uint16 INW(cyg_uint32 io_address)
438 { cyg_uint16 _t_; HAL_READ_UINT16( io_address, _t_ ); return _t_; }
440 static inline cyg_uint32 INL(cyg_uint32 io_address)
441 { cyg_uint32 _t_; HAL_READ_UINT32( io_address, _t_ ); return _t_; }
445 // ------------------------------------------------------------------------
446 // Macros for writing shared memory structures - no need for byte flipping
448 #define READMEM8( _reg_, _val_ ) ((_val_) = *((volatile CYG_BYTE *)(_reg_)))
449 #define WRITEMEM8( _reg_, _val_ ) (*((volatile CYG_BYTE *)(_reg_)) = (_val_))
450 #define READMEM16( _reg_, _val_ ) ((_val_) = *((volatile CYG_WORD16 *)(_reg_)))
451 #define WRITEMEM16( _reg_, _val_ ) (*((volatile CYG_WORD16 *)(_reg_)) = (_val_))
452 #define READMEM32( _reg_, _val_ ) ((_val_) = *((volatile CYG_WORD32 *)(_reg_)))
453 #define WRITEMEM32( _reg_, _val_ ) (*((volatile CYG_WORD32 *)(_reg_)) = (_val_))
455 // ------------------------------------------------------------------------
456 // Map from CPU-view addresses to PCI-bus master's view - however that is:
458 #ifdef CYGHWR_INTEL_I82559_PCI_VIRT_TO_BUS
460 #define VIRT_TO_BUS( _x_ ) CYGHWR_INTEL_I82559_PCI_VIRT_TO_BUS( _x_ )
462 #else // use default mappings: get a physical address to give to the device
464 #define VIRT_TO_BUS( _x_ ) virt_to_bus((cyg_uint32)(_x_))
465 static inline cyg_uint32 virt_to_bus(cyg_uint32 p_memory)
466 { return CYGARC_PHYSICAL_ADDRESS(p_memory); }
468 #endif // not defined CYGHWR_INTEL_I82559_PCI_VIRT_TO_BUS
470 // ------------------------------------------------------------------------
472 // 82559 REGISTER OFFSETS (I/O SPACE)
474 // ------------------------------------------------------------------------
475 #define SCBStatus 0 // Rx/Command Unit Status *Word*
476 #define SCBIntAckByte 1 // Rx/Command Unit STAT/ACK byte
477 #define SCBCmd 2 // Rx/Command Unit Command *Word*
478 #define SCBIntrCtlByte 3 // Rx/Command Unit Intr.Control Byte
479 #define SCBPointer 4 // General purpose pointer.
480 #define SCBPort 8 // Misc. commands and operands.
481 #define SCBflash 12 // Flash memory control.
482 #define SCBeeprom 14 // EEPROM memory control.
483 #define SCBCtrlMDI 16 // MDI interface control.
484 #define SCBEarlyRx 20 // Early receive byte count.
485 #define SCBGenControl 28 // 82559 General Control Register
486 #define SCBGenStatus 29 // 82559 General Status register
489 // ------------------------------------------------------------------------
491 // 82559 SCB STATUS WORD DEFNITIONS
493 // ------------------------------------------------------------------------
494 #define SCB_STATUS_CX 0x8000 // CU finished command (transmit)
495 #define SCB_STATUS_FR 0x4000 // frame received
496 #define SCB_STATUS_CNA 0x2000 // CU left active state
497 #define SCB_STATUS_RNR 0x1000 // receiver left ready state
498 #define SCB_STATUS_MDI 0x0800 // MDI read/write cycle done
499 #define SCB_STATUS_SWI 0x0400 // software generated interrupt
500 #define SCB_STATUS_FCP 0x0100 // flow control pause interrupt
502 #define SCB_INTACK_MASK 0xFD00 // all the above
503 #define SCB_INTACK_MASK_BYTE 0xFD // all the above
505 #define SCB_INTACK_TX (SCB_STATUS_CX | SCB_STATUS_CNA)
506 #define SCB_INTACK_RX (SCB_STATUS_FR | SCB_STATUS_RNR)
508 // ------------------------------------------------------------------------
510 // SYSTEM CONTROL BLOCK COMMANDS
512 // ------------------------------------------------------------------------
514 #define CU_NOP 0x0000
515 #define CU_START 0x0010
516 #define CU_RESUME 0x0020
517 #define CU_STATSADDR 0x0040 // Load Dump Statistics ctrs addr
518 #define CU_SHOWSTATS 0x0050 // Dump statistics counters.
519 #define CU_ADDR_LOAD 0x0060 // Base address to add to CU commands
520 #define CU_DUMPSTATS 0x0070 // Dump then reset stats counters.
523 #define RUC_NOP 0x0000
524 #define RUC_START 0x0001
525 #define RUC_RESUME 0x0002
526 #define RUC_ABORT 0x0004
527 #define RUC_ADDR_LOAD 0x0006 // (seems not to clear on acceptance)
528 #define RUC_RESUMENR 0x0007
530 #define CU_CMD_MASK 0x00f0
531 #define RU_CMD_MASK 0x0007
533 #define SCB_M 0x0100 // 0 = enable interrupt, 1 = disable
534 #define SCB_SWI 0x0200 // 1 - cause device to interrupt
535 #define SCB_BYTE_M 0x01 // 0 = enable interrupt, 1 = disable
536 #define SCB_BYTE_SWI 0x02 // 1 - cause device to interrupt
538 #define CU_STATUS_MASK 0x00C0
539 #define RU_STATUS_MASK 0x003C
541 #define RU_STATUS_IDLE (0<<2)
542 #define RU_STATUS_SUS (1<<2)
543 #define RU_STATUS_NORES (2<<2)
544 #define RU_STATUS_READY (4<<2)
545 #define RU_STATUS_NO_RBDS_SUS ((1<<2)|(8<<2))
546 #define RU_STATUS_NO_RBDS_NORES ((2<<2)|(8<<2))
547 #define RU_STATUS_NO_RBDS_READY ((4<<2)|(8<<2))
549 #define MAX_MEM_RESERVED_IOCTL 1000
551 // ------------------------------------------------------------------------
553 // 82559 PORT INTERFACE COMMANDS
555 // ------------------------------------------------------------------------
556 #define I82559_RESET 0x00000000 // software reset
557 #define I82559_SELFTEST 0x00000001 // 82559 selftest command
558 #define I82559_SELECTIVE_RESET 0x00000002
559 #define I82559_DUMP 0x00000003
560 #define I82559_DUMP_WAKEUP 0x00000007
563 // ------------------------------------------------------------------------
565 // 82559 EEPROM INTERFACE
567 // ------------------------------------------------------------------------
569 #define EE_SHIFT_CLK 0x01 // EEPROM shift clock.
570 #define EE_CS 0x02 // EEPROM chip select.
571 #define EE_DATA_WRITE 0x04 // EEPROM chip data in.
572 #define EE_DATA_READ 0x08 // EEPROM chip data out.
573 #define EE_ENB (0x4800 | EE_CS)
575 // Delay between EEPROM clock transitions.
576 #define eeprom_delay(usec) udelay(usec);
578 // The EEPROM commands include the always-set leading bit.
579 #define EE_WRITE_CMD(a) (5 << (a))
580 #define EE_READ_CMD(a) (6 << (a))
581 #define EE_ERASE_CMD(a) (7 << (a))
582 #define EE_WRITE_EN_CMD(a) (19 << ((a)-2))
583 #define EE_WRITE_DIS_CMD(a) (16 << ((a)-2))
584 #define EE_ERASE_ALL_CMD(a) (18 << ((a)-2))
586 #define EE_TOP_CMD_BIT(a) ((a)+2) // Counts down to zero
587 #define EE_TOP_DATA_BIT (15) // Counts down to zero
589 #define EEPROM_ENABLE_DELAY (10) // Delay at chip select
591 #define EEPROM_SK_DELAY (4) // Delay between clock edges *and* data
592 // read or transition; 3 of these per bit.
593 #define EEPROM_DONE_DELAY (100) // Delay when all done
596 // ------------------------------------------------------------------------
598 // RECEIVE FRAME DESCRIPTORS
600 // ------------------------------------------------------------------------
602 // The status is split into two shorts to get atomic access to the EL bit;
603 // the upper word is not written by the device, so we can just hit it,
604 // leaving the lower word (which the device updates) alone. Otherwise
605 // there's a race condition between software moving the end-of-list (EL)
606 // bit round and the device writing into the previous slot.
608 #if (CYG_BYTEORDER == CYG_MSBFIRST)
610 // Note that status bits are endian converted - so we don't need to
611 // fiddle the byteorder when accessing the status word!
612 #define RFD_STATUS_EL 0x00000080 // 1=last RFD in RFA
613 #define RFD_STATUS_S 0x00000040 // 1=suspend RU after receiving frame
614 #define RFD_STATUS_H 0x00001000 // 1=RFD is a header RFD
615 #define RFD_STATUS_SF 0x00000800 // 0=simplified, 1=flexible mode
616 #define RFD_STATUS_C 0x00800000 // completion of received frame
617 #define RFD_STATUS_OK 0x00200000 // frame received with no errors
619 #define RFD_STATUS_HI_EL 0x0080 // 1=last RFD in RFA
620 #define RFD_STATUS_HI_S 0x0040 // 1=suspend RU after receiving frame
621 #define RFD_STATUS_HI_H 0x1000 // 1=RFD is a header RFD
622 #define RFD_STATUS_HI_SF 0x0800 // 0=simplified, 1=flexible mode
624 #define RFD_STATUS_LO_C 0x0080 // completion of received frame
625 #define RFD_STATUS_LO_OK 0x0020 // frame received with no errors
628 #define RFD_COUNT_MASK 0x3fff
629 #define RFD_COUNT_F 0x4000
630 #define RFD_COUNT_EOF 0x8000
632 #define RFD_RX_CRC 0x00080000 // crc error
633 #define RFD_RX_ALIGNMENT 0x00040000 // alignment error
634 #define RFD_RX_RESOURCE 0x00020000 // out of space, no resources
635 #define RFD_RX_DMA_OVER 0x00010000 // DMA overrun
636 #define RFD_RX_SHORT 0x80000000 // short frame error
637 #define RFD_RX_LENGTH 0x20000000 //
638 #define RFD_RX_ERROR 0x10000000 // receive error
639 #define RFD_RX_NO_ADR_MATCH 0x04000000 // no address match
640 #define RFD_RX_IA_MATCH 0x02000000 // individual address does not match
641 #define RFD_RX_TCO 0x01000000 // TCO indication
643 #else // Little-endian
645 #define RFD_STATUS_EL 0x80000000 // 1=last RFD in RFA
646 #define RFD_STATUS_S 0x40000000 // 1=suspend RU after receiving frame
647 #define RFD_STATUS_H 0x00100000 // 1=RFD is a header RFD
648 #define RFD_STATUS_SF 0x00080000 // 0=simplified, 1=flexible mode
649 #define RFD_STATUS_C 0x00008000 // completion of received frame
650 #define RFD_STATUS_OK 0x00002000 // frame received with no errors
652 #define RFD_STATUS_HI_EL 0x8000 // 1=last RFD in RFA
653 #define RFD_STATUS_HI_S 0x4000 // 1=suspend RU after receiving frame
654 #define RFD_STATUS_HI_H 0x0010 // 1=RFD is a header RFD
655 #define RFD_STATUS_HI_SF 0x0008 // 0=simplified, 1=flexible mode
657 #define RFD_STATUS_LO_C 0x8000 // completion of received frame
658 #define RFD_STATUS_LO_OK 0x2000 // frame received with no errors
660 #define RFD_COUNT_MASK 0x3fff
661 #define RFD_COUNT_F 0x4000
662 #define RFD_COUNT_EOF 0x8000
664 #define RFD_RX_CRC 0x00000800 // crc error
665 #define RFD_RX_ALIGNMENT 0x00000400 // alignment error
666 #define RFD_RX_RESOURCE 0x00000200 // out of space, no resources
667 #define RFD_RX_DMA_OVER 0x00000100 // DMA overrun
668 #define RFD_RX_SHORT 0x00000080 // short frame error
669 #define RFD_RX_LENGTH 0x00000020 //
670 #define RFD_RX_ERROR 0x00000010 // receive error
671 #define RFD_RX_NO_ADR_MATCH 0x00000004 // no address match
672 #define RFD_RX_IA_MATCH 0x00000002 // individual address does not match
673 #define RFD_RX_TCO 0x00000001 // TCO indication
675 #endif // CYG_BYTEORDER
677 #ifndef CYG_ADDRESSING_IS_GIBENDIAN
681 #define RFD_STATUS_LO 0
682 #define RFD_STATUS_HI 2
684 #define RFD_RDB_ADDR 8
687 #define RFD_BUFFER 16
688 #define RFD_SIZEOF 16
690 #else // CYG_ADDRESSING_IS_GIBENDIAN
692 // GIBENDIAN addressing; A0 and A1 are flipped:
694 #define RFD_STATUS_LO 2 // swapped
695 #define RFD_STATUS_HI 0 // swapped
697 #define RFD_RDB_ADDR 8
698 #define RFD_COUNT 14 // swapped
699 #define RFD_SIZE 12 // swapped
700 #define RFD_BUFFER 16
701 #define RFD_SIZEOF 16
703 #endif // CYG_ADDRESSING_IS_GIBENDIAN
707 // ------------------------------------------------------------------------
709 // TRANSMIT FRAME DESCRIPTORS
711 // ------------------------------------------------------------------------
713 #if (CYG_BYTEORDER == CYG_MSBFIRST)
715 // Note that CMD/STATUS bits are endian converted - so we don't need
716 // to fiddle the byteorder when accessing the CMD/STATUS word!
718 #define TxCB_CMD_TRANSMIT 0x0400 // transmit command
719 #define TxCB_CMD_SF 0x0800 // 0=simplified, 1=flexible mode
720 #define TxCB_CMD_NC 0x0010 // 0=CRC insert by controller
721 #define TxCB_CMD_I 0x0020 // generate interrupt on completion
722 #define TxCB_CMD_S 0x0040 // suspend on completion
723 #define TxCB_CMD_EL 0x0080 // last command block in CBL
725 #define TxCB_COUNT_MASK 0x3fff
726 #define TxCB_COUNT_EOF 0x8000
728 #else // Little-endian layout
730 #define TxCB_COUNT_MASK 0x3fff
731 #define TxCB_COUNT_EOF 0x8000
733 #define TxCB_CMD_TRANSMIT 0x0004 // transmit command
734 #define TxCB_CMD_SF 0x0008 // 0=simplified, 1=flexible mode
735 #define TxCB_CMD_NC 0x0010 // 0=CRC insert by controller
736 #define TxCB_CMD_I 0x2000 // generate interrupt on completion
737 #define TxCB_CMD_S 0x4000 // suspend on completion
738 #define TxCB_CMD_EL 0x8000 // last command block in CBL
740 #endif // CYG_BYTEORDER
742 #ifndef CYG_ADDRESSING_IS_GIBENDIAN
745 #define TxCB_STATUS 0
748 #define TxCB_TBD_ADDR 8
749 #define TxCB_COUNT 12
750 #define TxCB_TX_THRESHOLD 14
751 #define TxCB_TBD_NUMBER 15
752 #define TxCB_BUFFER 16
753 #define TxCB_SIZEOF 16
755 #else // CYG_ADDRESSING_IS_GIBENDIAN
757 // GIBENDIAN addressing; A0 and A1 are flipped:
758 #define TxCB_STATUS 2 // swapped
759 #define TxCB_CMD 0 // swapped
761 #define TxCB_TBD_ADDR 8
762 #define TxCB_COUNT 14 // swapped
763 #define TxCB_TX_THRESHOLD 13 // swapped
764 #define TxCB_TBD_NUMBER 12 // swapped
765 #define TxCB_BUFFER 16
766 #define TxCB_SIZEOF 16
767 #endif // CYG_ADDRESSING_IS_GIBENDIAN
769 // ------------------------------------------------------------------------
771 // STRUCTURES ADDED FOR PROMISCUOUS MODE
773 // ------------------------------------------------------------------------
775 #if (CYG_BYTEORDER == CYG_MSBFIRST)
777 // Note CFG CMD and STATUS swapped, so no need for endian conversion
779 #define CFG_CMD_EL 0x0080
780 #define CFG_CMD_SUSPEND 0x0040
781 #define CFG_CMD_INT 0x0020
782 #define CFG_CMD_IAS 0x0100 // individual address setup
783 #define CFG_CMD_CONFIGURE 0x0200 // configure
784 #define CFG_CMD_MULTICAST 0x0300 // Multicast-Setup
786 #define CFG_STATUS_C 0x0080
787 #define CFG_STATUS_OK 0x0020
789 #else // Little-endian
791 #define CFG_CMD_EL 0x8000
792 #define CFG_CMD_SUSPEND 0x4000
793 #define CFG_CMD_INT 0x2000
794 #define CFG_CMD_IAS 0x0001 // individual address setup
795 #define CFG_CMD_CONFIGURE 0x0002 // configure
796 #define CFG_CMD_MULTICAST 0x0003 // Multicast-Setup
798 #define CFG_STATUS_C 0x8000
799 #define CFG_STATUS_OK 0x2000
801 #endif // CYG_BYTEORDER
803 #ifndef CYG_ADDRESSING_IS_GIBENDIAN
808 #define CFG_CB_LINK_OFFSET 4
810 #define CFG_SIZEOF 32
812 #else // CYG_ADDRESSING_IS_GIBENDIAN
814 // GIBENDIAN addressing; A0 and A1 are flipped:
817 #define CFG_CB_LINK_OFFSET 4
819 #define CFG_SIZEOF 32
821 #endif // CYG_ADDRESSING_IS_GIBENDIAN
824 #define CFG_MC_LIST_BYTES 8
825 #define CFG_MC_LIST_DATA 10
827 // ------------------------------------------------------------------------
829 // STATISTICAL COUNTER STRUCTURE
831 // ------------------------------------------------------------------------
832 #ifdef KEEP_STATISTICS
833 STATISTICS statistics[CYGNUM_DEVS_ETH_INTEL_I82559_DEV_COUNT];
834 I82559_COUNTERS i82559_counters[CYGNUM_DEVS_ETH_INTEL_I82559_DEV_COUNT];
835 #endif // KEEP_STATISTICS
837 // ------------------------------------------------------------------------
839 // DEVICES AND PACKET QUEUES
841 // ------------------------------------------------------------------------
843 #define MAX_RX_PACKET_SIZE 1536 // maximum Rx packet size
844 #define MAX_TX_PACKET_SIZE 1536 // maximum Tx packet size
847 // ------------------------------------------------------------------------
848 // Use arrays provided by platform header to verify pointers.
849 #ifdef CYGDBG_USE_ASSERTS
850 #define CHECK_NDP_SC_LINK() \
852 int i, valid_netdev = 0, valid_sc = 0; \
853 for(i = 0; i < CYGNUM_DEVS_ETH_INTEL_I82559_DEV_COUNT; i++) { \
854 if (i82559_netdev_array[i] == ndp) valid_netdev = 1; \
855 if (i82559_sc_array[i] == sc) valid_sc = 1; \
856 if (valid_sc || valid_netdev) break; \
858 CYG_ASSERT( valid_netdev, "Bad ndp" ); \
859 CYG_ASSERT( valid_sc, "Bad sc" ); \
860 CYG_ASSERT( (void *)p_i82559 == i82559_sc_array[i]->driver_private, \
861 "sc pointer bad" ); \
864 #define CHECK_NDP_SC_LINK()
867 #define IF_BAD_82559( _p_ ) \
869 int i, valid_p = 0; \
870 for(i = 0; i < CYGNUM_DEVS_ETH_INTEL_I82559_DEV_COUNT; i++) { \
871 if (i82559_priv_array[i] == (_p_)) { \
876 CYG_ASSERT(valid_p, "Bad pointer-to-i82559"); \
880 // ------------------------------------------------------------------------
882 // Managing the memory that is windowed onto the PCI bus
884 // ------------------------------------------------------------------------
886 static cyg_uint32 i82559_heap_size;
887 static cyg_uint8 *i82559_heap_base;
888 static cyg_uint8 *i82559_heap_free;
890 static void *mem_reserved_ioctl = (void*)0;
891 // uncacheable memory reserved for ioctl calls
893 // ------------------------------------------------------------------------
895 // FUNCTION PROTOTYPES
897 // ------------------------------------------------------------------------
899 static int pci_init_find_82559s(void);
901 static void i82559_reset(struct i82559* p_i82559);
902 static void i82559_restart(struct i82559 *p_i82559);
903 static int eth_set_mac_address(struct i82559* p_i82559, cyg_uint8 *addr, int eeprom );
905 static void InitRxRing(struct i82559* p_i82559);
906 static void ResetRxRing(struct i82559* p_i82559);
907 static void InitTxRing(struct i82559* p_i82559);
908 static void ResetTxRing(struct i82559* p_i82559);
910 #if defined(CYGHWR_DEVS_ETH_INTEL_I82559_MISSED_INTERRUPT) || \
911 defined(CYGNUM_DEVS_ETH_INTEL_I82559_SEPARATE_MUX_INTERRUPT) || \
912 !defined(CYGPKG_IO_ETH_DRIVERS_STAND_ALONE)
914 eth_dsr(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data);
917 eth_isr(cyg_vector_t vector, cyg_addrword_t data);
919 static int i82559_configure(struct i82559* p_i82559, int promisc,
920 int oversized, int multicast_all);
921 #ifdef ETH_DRV_SET_MC_LIST
922 static int i82559_set_multicast(struct i82559* p_i82559,
924 cyg_uint8 *address_list );
925 #endif // ETH_DRV_SET_MC_ALL
926 #ifdef CYGPKG_DEVS_ETH_INTEL_I82559_WRITE_EEPROM
928 program_eeprom(cyg_uint32 ioaddr, cyg_uint32 eeprom_size, cyg_uint8 *data);
930 write_eeprom(long ioaddr, int location, int addr_len, unsigned short value);
932 write_enable_eeprom(long ioaddr, int addr_len);
935 // debugging/logging only:
936 void dump_txcb(TxCB* p_txcb);
937 void DisplayStatistics(void);
938 void update_statistics(struct i82559* p_i82559);
939 void dump_rfd(RFD* p_rfd, int anyway );
940 void dump_all_rfds( int intf );
941 void dump_packet(cyg_uint8 *p_buffer, int length);
943 static void i82559_stop( struct eth_drv_sc *sc );
945 // ------------------------------------------------------------------------
947 // ------------------------------------------------------------------------
950 WAIT_RU, // wait before RU cmd
951 WAIT_CU // wait before CU cmd
956 wait_for_cmd_done(long scb_ioaddr, cmd_wait_t type)
962 do status = INW(scb_ioaddr + SCBCmd) /* nothing */ ;
963 while( (0 != ((CU_CMD_MASK | RU_CMD_MASK) & status)) && --wait >= 0);
966 // Then we timed out; reset the device and try again...
967 OUTL(I82559_SELECTIVE_RESET, scb_ioaddr + SCBPort);
968 #ifdef CYGDBG_USE_ASSERTS
969 missed_interrupt.waitcmd_timeouts++;
972 do status = INW(scb_ioaddr + SCBCmd) /* nothing */;
973 while( (0 != ((CU_CMD_MASK | RU_CMD_MASK) & status)) && --wait >= 0);
976 // special case - don't complain about RUC_ADDR_LOAD as it doesn't clear
978 if ( RUC_ADDR_LOAD != (status & RU_CMD_MASK) )
979 CYG_ASSERT( wait > 0, "wait_for_cmd_done: cmd busy" );
981 if (WAIT_CU == type) {
982 // Also check CU is idle
984 do status = INW(scb_ioaddr + SCBStatus) /* nothing */;
985 while( (status & CU_STATUS_MASK) && --wait >= 0);
987 // Then we timed out; reset the device and try again...
988 OUTL(I82559_SELECTIVE_RESET, scb_ioaddr + SCBPort);
989 #ifdef CYGDBG_USE_ASSERTS
990 missed_interrupt.waitcmd_timeouts_cu++;
993 do status = INW(scb_ioaddr + SCBCmd) /* nothing */;
994 while( (0 != ((CU_CMD_MASK | RU_CMD_MASK) & status)) && --wait >= 0);
997 CYG_ASSERT( wait > 0, "wait_for_cmd_done: CU busy" );
999 } else if (WAIT_RU == type) {
1000 // Can't see any active state in the doc to check for
1004 // ------------------------------------------------------------------------
1009 CYGACC_CALL_IF_DELAY_US(delay);
1012 // ------------------------------------------------------------------------
1013 // If we are demuxing for all interrupt sources, we must mask and unmask
1014 // *all* interrupt sources together.
1017 Mask82559Interrupt(struct i82559* p_i82559)
1021 #ifdef CYGPRI_DEVS_ETH_INTEL_I82559_MASK_INTERRUPTS
1022 CYGPRI_DEVS_ETH_INTEL_I82559_MASK_INTERRUPTS(p_i82559,old);
1024 // if (query_enabled)
1026 cyg_drv_interrupt_mask(p_i82559->vector);
1027 #ifdef CYGNUM_DEVS_ETH_INTEL_I82559_SEPARATE_MUX_INTERRUPT
1028 // if (query_enabled)
1030 cyg_drv_interrupt_mask(CYGNUM_DEVS_ETH_INTEL_I82559_SEPARATE_MUX_INTERRUPT);
1033 /* it may prove necessary to do something like this
1034 if ( mybits != (mybits & old) )
1035 /# then at least one of them was disabled, so
1036 # omit both from any restoration: #/
1044 UnMask82559Interrupt(struct i82559* p_i82559, int old)
1046 #ifdef CYGPRI_DEVS_ETH_INTEL_I82559_UNMASK_INTERRUPTS
1047 CYGPRI_DEVS_ETH_INTEL_I82559_UNMASK_INTERRUPTS(p_i82559,old);
1049 // We must only unmask (enable) those which were unmasked before,
1050 // according to the bits in old.
1052 cyg_drv_interrupt_unmask(p_i82559->vector);
1053 #ifdef CYGNUM_DEVS_ETH_INTEL_I82559_SEPARATE_MUX_INTERRUPT
1055 cyg_drv_interrupt_mask(CYGNUM_DEVS_ETH_INTEL_I82559_SEPARATE_MUX_INTERRUPT);
1062 Acknowledge82559Interrupt(struct i82559* p_i82559)
1064 #ifdef CYGPRI_DEVS_ETH_INTEL_I82559_ACK_INTERRUPTS
1065 CYGPRI_DEVS_ETH_INTEL_I82559_ACK_INTERRUPTS(p_i82559);
1067 cyg_drv_interrupt_acknowledge(p_i82559->vector);
1068 #ifdef CYGNUM_DEVS_ETH_INTEL_I82559_SEPARATE_MUX_INTERRUPT
1069 cyg_drv_interrupt_acknowledge(CYGNUM_DEVS_ETH_INTEL_I82559_SEPARATE_MUX_INTERRUPT);
1073 #ifdef CYGPRI_DEVS_ETH_INTEL_I82559_INTERRUPT_ACK_LOOP
1074 CYGPRI_DEVS_ETH_INTEL_I82559_INTERRUPT_ACK_LOOP(p_i82559);
1080 Check82559TxLockupTimeout(struct i82559* p_i82559)
1082 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_RESET_TIMEOUT
1083 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_TIMEOUT_FIRED
1084 int ints = Mask82559Interrupt(p_i82559);
1085 if ( p_i82559->tx_in_progress &&
1086 (p_i82559->tx_descriptor_timeout == p_i82559->tx_descriptor_active) ) {
1087 if ( CYGHWR_DEVS_ETH_INTEL_I82559_TIMEOUT_FIRED( p_i82559->platform_timeout ) ) {
1088 // Then reset the device; the TX unit is locked up.
1089 cyg_uint32 ioaddr = p_i82559->io_address;
1090 // Wait some time afterwards for chip to settle.
1091 OUTL(I82559_SELECTIVE_RESET, ioaddr + SCBPort);
1092 #ifdef CYGDBG_USE_ASSERTS
1093 missed_interrupt.lockup_timeouts++;
1100 CYGHWR_DEVS_ETH_INTEL_I82559_RESET_TIMEOUT( p_i82559->platform_timeout );
1101 p_i82559->tx_descriptor_timeout = p_i82559->tx_descriptor_active;
1103 UnMask82559Interrupt(p_i82559,ints);
1108 // ------------------------------------------------------------------------
1109 // Memory management
1111 // Simply carve off from the front of the PCI mapped window into real memory
1114 pciwindow_mem_alloc(int size)
1120 (CYGHWR_INTEL_I82559_PCI_MEM_MAP_BASE <= (int)i82559_heap_free)
1122 ((CYGHWR_INTEL_I82559_PCI_MEM_MAP_BASE +
1123 CYGHWR_INTEL_I82559_PCI_MEM_MAP_SIZE) > (int)i82559_heap_free)
1125 (0 < i82559_heap_size)
1127 (CYGHWR_INTEL_I82559_PCI_MEM_MAP_SIZE >= i82559_heap_size)
1129 (CYGHWR_INTEL_I82559_PCI_MEM_MAP_BASE == (int)i82559_heap_base),
1130 "Heap variables corrupted" );
1132 p_memory = (void *)0;
1133 size = (size + 3) & ~3;
1134 if ( (i82559_heap_free+size) < (i82559_heap_base+i82559_heap_size) ) {
1136 p_memory = (void *)i82559_heap_free;
1137 i82559_heap_free += size;
1138 for ( p = (cyg_uint32 *)p_memory; _size > 0; _size -= 4 )
1142 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_PCIMEM_DISCONTIGUOUS
1143 // Then the underlying physical address can have breaks in it.
1144 // We cannot use such a block, clearly, so we just discard and re-do.
1146 char *bpm = (char *)VIRT_TO_BUS( p_memory );
1147 char *bmf = (char *)VIRT_TO_BUS( i82559_heap_free );
1149 if ( bpm + size != bmf ) {
1150 // then we found a break; retry:
1151 if ( (i82559_heap_free+size) < (i82559_heap_base+i82559_heap_size) ) {
1153 p_memory = (void *)i82559_heap_free;
1154 i82559_heap_free += size;
1155 for ( p = (cyg_uint32 *)p_memory; _size > 0; _size -= 4 )
1163 VIRT_TO_BUS( p_memory ) + size == VIRT_TO_BUS( i82559_heap_free ),
1164 "Discontiguous PCI memory in real addresses" );
1170 // ------------------------------------------------------------------------
1174 // ------------------------------------------------------------------------
1175 #ifndef CYGHWR_DEVS_ETH_INTEL_I82559_HAS_NO_EEPROM
1177 get_eeprom_size(long ioaddr)
1179 unsigned short retval = 0;
1180 int ee_addr = ioaddr + SCBeeprom;
1183 // Should already be not-selected, but anyway:
1184 OUTW(EE_ENB & ~EE_CS, ee_addr);
1185 eeprom_delay(EEPROM_ENABLE_DELAY);
1186 OUTW(EE_ENB, ee_addr);
1187 eeprom_delay(EEPROM_ENABLE_DELAY);
1189 // Shift the read command bits out.
1190 for (i = 2; i >= 0; i--) {
1191 short dataval = (6 & (1 << i)) ? EE_DATA_WRITE : 0;
1192 OUTW(EE_ENB | dataval , ee_addr);
1193 eeprom_delay(EEPROM_SK_DELAY);
1194 OUTW(EE_ENB | dataval | EE_SHIFT_CLK, ee_addr);
1195 eeprom_delay(EEPROM_SK_DELAY);
1196 OUTW(EE_ENB | dataval , ee_addr);
1197 eeprom_delay(EEPROM_SK_DELAY);
1199 // Now clock out address zero, looking for the dummy 0 data bit
1200 for ( i = 1; i <= 12; i++ ) {
1201 OUTW(EE_ENB , ee_addr);
1202 eeprom_delay(EEPROM_SK_DELAY);
1203 OUTW(EE_ENB | EE_SHIFT_CLK, ee_addr);
1204 eeprom_delay(EEPROM_SK_DELAY);
1205 OUTW(EE_ENB , ee_addr);
1206 eeprom_delay(EEPROM_SK_DELAY);
1207 retval = INW(ee_addr) & EE_DATA_READ;
1209 break; // The dummy zero est arrive'
1213 os_printf( "eeprom data bits %d (ioaddr %x)\n", i, ee_addr );
1216 if ( 6 != i && 8 != i && 1 != i) {
1218 os_printf( "*****EEPROM data bits not 6, 8 or 1*****\n" );
1220 i = 6; // guess, to complete this routine
1221 addrbits = 1; // Flag no eeprom here.
1226 // clear the dataval, leave the clock low to read in the data regardless
1227 OUTW(EE_ENB, ee_addr);
1230 retval = INW(ee_addr);
1231 if ( (EE_DATA_READ & retval) != 0 ) {
1233 os_printf( "Size EEPROM: Dummy data bit not 0, reg %x\n" , retval );
1238 for (i = EE_TOP_DATA_BIT; i >= 0; i--) {
1239 OUTW(EE_ENB | EE_SHIFT_CLK, ee_addr);
1240 eeprom_delay(EEPROM_SK_DELAY);
1241 retval = INW(ee_addr);
1242 eeprom_delay(EEPROM_SK_DELAY);
1243 OUTW(EE_ENB, ee_addr);
1244 eeprom_delay(EEPROM_SK_DELAY);
1247 // Terminate the EEPROM access.
1248 OUTW(EE_ENB & ~EE_CS, ee_addr);
1249 eeprom_delay(EEPROM_DONE_DELAY);
1255 // ------------------------------------------------------------------------
1259 // ------------------------------------------------------------------------
1261 read_eeprom(long ioaddr, int location, int addr_len)
1263 unsigned short retval = 0;
1264 int ee_addr = ioaddr + SCBeeprom;
1265 int read_cmd = location | EE_READ_CMD(addr_len);
1269 // Should already be not-selected, but anyway:
1270 OUTW(EE_ENB & ~EE_CS, ee_addr);
1271 eeprom_delay(EEPROM_ENABLE_DELAY);
1272 OUTW(EE_ENB, ee_addr);
1273 eeprom_delay(EEPROM_ENABLE_DELAY);
1275 // Shift the read command bits out, changing only one bit per time.
1276 for (i = EE_TOP_CMD_BIT(addr_len); i >= 0; i--) {
1277 short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0;
1278 OUTW(EE_ENB | dataval , ee_addr);
1279 eeprom_delay(EEPROM_SK_DELAY);
1280 OUTW(EE_ENB | dataval | EE_SHIFT_CLK, ee_addr);
1281 eeprom_delay(EEPROM_SK_DELAY);
1282 OUTW(EE_ENB | dataval , ee_addr);
1283 eeprom_delay(EEPROM_SK_DELAY);
1286 // clear the dataval, leave the clock low
1287 OUTW(EE_ENB, ee_addr);
1290 retval = INW(ee_addr);
1291 // This should show a zero in the data read bit to confirm that the
1292 // address transfer is compelete. If not, go to the start and try
1294 if ( (0 != (retval & EE_DATA_READ)) && (tries-- > 0) ) {
1295 // Terminate the EEPROM access.
1296 OUTW(EE_ENB & ~EE_CS, ee_addr);
1297 eeprom_delay(EEPROM_DONE_DELAY);
1299 os_printf( "Warning: Retrying EEPROM read word %d, address %x, try %d\n",
1300 location, ee_addr, tries+1 );
1305 // This fires with one device on one of the customer boards!
1306 // (but is OK on all other h/w. Worrying huh.)
1307 if ( (EE_DATA_READ & retval) != 0 ) {
1309 os_printf( "Read EEPROM: Dummy data bit not 0, reg %x\n" , retval );
1315 for (i = EE_TOP_DATA_BIT; i >= 0; i--) {
1316 OUTW(EE_ENB | EE_SHIFT_CLK, ee_addr);
1317 eeprom_delay(EEPROM_SK_DELAY);
1318 retval = (retval << 1) | ((INW(ee_addr) & EE_DATA_READ) ? 1 : 0);
1319 eeprom_delay(EEPROM_SK_DELAY);
1320 OUTW(EE_ENB, ee_addr);
1321 eeprom_delay(EEPROM_SK_DELAY);
1324 // Terminate the EEPROM access.
1325 OUTW(EE_ENB & ~EE_CS, ee_addr);
1326 eeprom_delay(EEPROM_DONE_DELAY);
1332 read_eeprom_esa(struct i82559 *p_i82559, cyg_uint8 *addr)
1334 int addr_length, i, count;
1335 cyg_uint16 checksum;
1336 cyg_uint32 ioaddr = p_i82559->io_address;
1338 // read eeprom and get 82559's mac address
1339 addr_length = get_eeprom_size(ioaddr);
1340 // (this is the length of the *EEPROM*s address, not MAC address)
1342 // If length is 1, it _probably_ means there's no EEPROM
1343 // present. Couldn't find an explicit mention of this in the
1344 // docs, but length=1 appears to be the behaviour in that case.
1345 if (1 == addr_length) {
1347 os_printf("Error: No EEPROM present for device %d\n",
1351 for (checksum = 0, i = 0, count = 0; count < (1 << addr_length); count++) {
1353 // read word from eeprom
1354 value = read_eeprom(ioaddr, count, addr_length);
1356 os_printf( "%2d: %04x\n", count, value );
1360 addr[i++] = value & 0xFF;
1361 addr[i++] = (value >> 8) & 0xFF;
1365 #ifndef CYGHWR_DEVS_ETH_INTEL_I82559_HAS_ONE_EEPROM_WITHOUT_CRC
1366 // If the EEPROM checksum is wrong, the MAC address read
1367 // from the EEPROM is probably wrong as well. In that
1368 // case, we don't set mac_addr_ok, but continue the
1369 // initialization. If then somebody calls i82559_start
1370 // without calling eth_set_mac_address() first, we refuse
1371 // to bring up the interface, because running with an
1372 // invalid MAC address is not a very brilliant idea.
1374 if ((checksum & 0xFFFF) != 0xBABA) {
1375 // selftest verified checksum, verify again
1377 os_printf("Warning: Invalid EEPROM checksum %04X for device %d\n",
1378 checksum, p_i82559->index);
1380 } else // trailing block
1381 #endif // ! CYGHWR_DEVS_ETH_INTEL_I82559_HAS_ONE_EEPROM_WITHOUT_CRC
1384 os_printf("Valid EEPROM checksum\n");
1391 #endif // ! CYGHWR_DEVS_ETH_INTEL_I82559_HAS_NO_EEPROM
1393 // ------------------------------------------------------------------------
1395 // NETWORK INTERFACE INITIALIZATION
1397 // Function : Init82559
1400 // This routine resets, configures, and initializes the chip.
1401 // It also clears the ethernet statistics structure, and selects
1402 // which statistics are supported by this driver.
1404 // ------------------------------------------------------------------------
1406 i82559_init(struct cyg_netdevtab_entry * ndp)
1408 static int initialized = 0; // only probe PCI et al *once*
1410 struct eth_drv_sc *sc;
1411 cyg_uint32 selftest;
1412 volatile cyg_uint32 *p_selftest;
1416 struct i82559 *p_i82559;
1417 cyg_uint8 mac_address[ETHER_ADDR_LEN];
1420 // db_printf("intel_i82559_init\n");
1423 sc = (struct eth_drv_sc *)(ndp->device_instance);
1424 p_i82559 = (struct i82559 *)(sc->driver_private);
1426 IF_BAD_82559( p_i82559 ) {
1428 os_printf( "Bad device private pointer %x\n", sc->driver_private );
1433 CHECK_NDP_SC_LINK();
1435 if ( 0 == initialized++ ) {
1436 // then this is the first time ever:
1437 if ( ! pci_init_find_82559s() ) {
1439 os_printf( "pci_init_find_82559s failed\n" );
1445 // If this device is not present, exit
1446 if (0 == p_i82559->found)
1449 p_i82559->mac_addr_ok = 0;
1451 ioaddr = p_i82559->io_address; // get I/O address for 82559
1454 os_printf("Init82559 %d @ %x\n82559 Self Test\n",
1455 p_i82559->index, (int)ndp);
1458 ints = Mask82559Interrupt(p_i82559);
1461 i82559_reset(p_i82559);
1463 // Perform a system self-test. (get enough mem to round address)
1464 if ( (selftest = (cyg_uint32)pciwindow_mem_alloc(32) ) == 0)
1466 p_selftest = (cyg_uint32 *) ((selftest + 15) & ~0xf);
1467 p_selftest[0] = p_selftest[1] = -1;
1469 OUTL( (VIRT_TO_BUS(p_selftest)) | I82559_SELFTEST, ioaddr + SCBPort);
1470 count = 0x7FFFF; // Timeout for self-test.
1473 } while ( (p_selftest[1] == -1) && (--count >= 0) );
1475 // Reset device again after selftest
1476 i82559_reset(p_i82559);
1478 Acknowledge82559Interrupt(p_i82559);
1479 UnMask82559Interrupt(p_i82559, ints );
1484 os_printf("Self test failed\n");
1489 os_printf(" General self-test: %s.\n"
1490 " Serial sub-system self-test: %s.\n"
1491 " Internal registers self-test: %s.\n"
1492 " ROM checksum self-test: %s (%08X).\n",
1493 HAL_LE32TOC(p_selftest[1]) & 0x1000 ? "failed" : "passed",
1494 HAL_LE32TOC(p_selftest[1]) & 0x0020 ? "failed" : "passed",
1495 HAL_LE32TOC(p_selftest[1]) & 0x0008 ? "failed" : "passed",
1496 HAL_LE32TOC(p_selftest[1]) & 0x0004 ? "failed" : "passed",
1497 HAL_LE32TOC(p_selftest[0]));
1500 // free self-test memory?
1501 // No, there's no point: this "heap" does not support free.
1503 if (p_i82559->hardwired_esa) {
1504 // Hardwire the address without consulting the EEPROM.
1505 // When this flag is set, the p_i82559 will already contain
1506 // the ESA. Copy it to a mac_address for call to set_mac_addr
1507 mac_address[0] = p_i82559->mac_address[0];
1508 mac_address[1] = p_i82559->mac_address[1];
1509 mac_address[2] = p_i82559->mac_address[2];
1510 mac_address[3] = p_i82559->mac_address[3];
1511 mac_address[4] = p_i82559->mac_address[4];
1512 mac_address[5] = p_i82559->mac_address[5];
1514 eth_set_mac_address(p_i82559, mac_address, 0);
1518 // Acquire the ESA either from extenal means (probably RedBoot
1519 // variables) or from the attached EEPROM - if there is one.
1521 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_GET_ESA
1524 CYGHWR_DEVS_ETH_INTEL_I82559_GET_ESA( p_i82559, mac_address, ok );
1526 #ifndef CYGHWR_DEVS_ETH_INTEL_I82559_HAS_NO_EEPROM
1527 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_HAS_ONE_EEPROM
1528 if ( CYGHWR_DEVS_ETH_INTEL_I82559_HAS_ONE_EEPROM == p_i82559->index )
1529 #endif // CYGHWR_DEVS_ETH_INTEL_I82559_HAS_ONE_EEPROM
1531 cyg_uint8 tmp_addr[ETHER_ADDR_LEN];
1533 // write eeprom address unless it is already there
1535 if (read_eeprom_esa(p_i82559, tmp_addr)) {
1537 for (i = 0; i < ETHER_ADDR_LEN; i++)
1538 if (tmp_addr[i] != mac_address[i])
1540 if (i >= ETHER_ADDR_LEN)
1544 #endif // ! CYGHWR_DEVS_ETH_INTEL_I82559_HAS_NO_EEPROM
1545 eth_set_mac_address(p_i82559, mac_address, wflag);
1547 #else // ! CYGHWR_DEVS_ETH_INTEL_I82559_GET_ESA
1549 #ifndef CYGHWR_DEVS_ETH_INTEL_I82559_HAS_NO_EEPROM
1551 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_HAS_ONE_EEPROM
1552 if ( CYGHWR_DEVS_ETH_INTEL_I82559_HAS_ONE_EEPROM == p_i82559->index ) {
1553 #endif // CYGHWR_DEVS_ETH_INTEL_I82559_HAS_ONE_EEPROM
1555 if (read_eeprom_esa(p_i82559, mac_address)) {
1556 // record the MAC address in the device structure
1557 p_i82559->mac_address[0] = mac_address[0];
1558 p_i82559->mac_address[1] = mac_address[1];
1559 p_i82559->mac_address[2] = mac_address[2];
1560 p_i82559->mac_address[3] = mac_address[3];
1561 p_i82559->mac_address[4] = mac_address[4];
1562 p_i82559->mac_address[5] = mac_address[5];
1564 p_i82559->mac_addr_ok = 1;
1566 eth_set_mac_address(p_i82559, mac_address, 0);
1569 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_HAS_ONE_EEPROM
1571 else { // We are now "in" another device
1572 #if 1 < CYGNUM_DEVS_ETH_INTEL_I82559_DEV_COUNT
1573 struct i82559 *other; // The one that *is* set up from EEPROM
1574 other = i82559_priv_array[CYGHWR_DEVS_ETH_INTEL_I82559_HAS_ONE_EEPROM];
1575 if ( other->mac_addr_ok ) {
1576 mac_address[0] = other->mac_address[0];
1577 mac_address[1] = other->mac_address[1];
1578 mac_address[2] = other->mac_address[2];
1579 mac_address[3] = other->mac_address[3];
1580 mac_address[4] = other->mac_address[4];
1581 mac_address[5] = other->mac_address[5];
1583 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_HAS_ONE_EEPROM_MAC_ADJUST
1584 mac_address[5] += CYGHWR_DEVS_ETH_INTEL_I82559_HAS_ONE_EEPROM_MAC_ADJUST;
1586 eth_set_mac_address(p_i82559, mac_address, 0);
1588 #endif // 1 < CYGNUM_DEVS_ETH_INTEL_I82559_DEV_COUNT
1590 #endif // CYGHWR_DEVS_ETH_INTEL_I82559_HAS_ONE_EEPROM
1592 #endif // ! CYGHWR_DEVS_ETH_INTEL_I82559_HAS_NO_EEPROM
1593 #endif // ! CYGHWR_DEVS_ETH_INTEL_I82559_GET_ESA
1597 os_printf("i82559_init: MAC Address = %02X %02X %02X %02X %02X %02X\n",
1598 p_i82559->mac_address[0], p_i82559->mac_address[1],
1599 p_i82559->mac_address[2], p_i82559->mac_address[3],
1600 p_i82559->mac_address[4], p_i82559->mac_address[5]);
1603 // and record the net dev pointer
1604 p_i82559->ndp = (void *)ndp;
1606 p_i82559->within_send = 0; // init recursion level
1608 p_i82559->promisc = 0; // None of these initially
1609 p_i82559->multicast_all = 0;
1610 p_i82559->oversized = 1; // Enable this for VLAN mode by default
1612 InitRxRing(p_i82559);
1613 InitTxRing(p_i82559);
1615 CheckRxRing(p_i82559,__FUNCTION__,__LINE__);
1617 // Initialize upper level driver
1618 if ( p_i82559->mac_addr_ok )
1619 (sc->funs->eth_drv->init)(sc, &(p_i82559->mac_address[0]) );
1621 (sc->funs->eth_drv->init)(sc, NULL );
1623 CheckRxRing(p_i82559,__FUNCTION__,__LINE__);
1628 // ------------------------------------------------------------------------
1630 // Function : i82559_start
1632 // ------------------------------------------------------------------------
1634 i82559_start( struct eth_drv_sc *sc, unsigned char *enaddr, int flags )
1636 struct i82559 *p_i82559;
1638 #ifdef KEEP_STATISTICS
1642 struct ifnet *ifp = &sc->sc_arpcom.ac_if;
1645 p_i82559 = (struct i82559 *)sc->driver_private;
1646 ioaddr = p_i82559->io_address; // get 82559's I/O address
1648 IF_BAD_82559( p_i82559 ) {
1650 os_printf( "i82559_start: Bad device pointer %x\n", p_i82559 );
1655 if ( ! p_i82559->mac_addr_ok ) {
1657 os_printf("i82559_start %d: invalid MAC address, "
1658 "can't bring up interface\n",
1664 if ( p_i82559->active )
1667 #ifdef KEEP_STATISTICS
1668 #ifdef CYGDBG_DEVS_ETH_INTEL_I82559_KEEP_STATISTICS
1669 p_statistics = p_i82559->p_statistics;
1670 memset(p_statistics, 0xFFFFFFFF, sizeof(I82559_COUNTERS));
1671 // set statistics dump address
1672 wait_for_cmd_done(ioaddr, WAIT_CU);
1673 OUTL(VIRT_TO_BUS(p_statistics), ioaddr + SCBPointer);
1674 OUTW(SCB_M | CU_STATSADDR, ioaddr + SCBCmd);
1675 // Start dump command
1676 wait_for_cmd_done(ioaddr, WAIT_CU);
1677 OUTW(SCB_M | CU_DUMPSTATS, ioaddr + SCBCmd); // start register dump
1678 // ...and wait for it to complete operation
1680 // The code to wait was bogus; it was looking at the structure in the
1681 // wrong way. In any case, there is no need to wait, the
1682 // wait_for_cmd_done() in any following activity is good enough.
1688 p_i82559->active = 1;
1690 /* Enable promiscuous mode if requested, reception of oversized frames always.
1691 * The latter is needed for VLAN support and shouldn't hurt even if we're not
1692 * using VLANs. Reset multicastALL reception choice.
1695 p_i82559->promisc = 0
1697 || !!(ifp->if_flags & IFF_PROMISC)
1699 #ifdef ETH_DRV_FLAGS_PROMISC_MODE
1700 || !!(flags & ETH_DRV_FLAGS_PROMISC_MODE)
1704 p_i82559->multicast_all = 0;
1706 i82559_configure(p_i82559,
1708 p_i82559->oversized,
1709 p_i82559->multicast_all );
1713 int status = i82559_status( sc );
1714 os_printf("i82559_start %d flg %x Link = %s, %s Mbps, %s Duplex\n",
1717 status & GEN_STATUS_LINK ? "Up" : "Down",
1718 status & GEN_STATUS_100MBPS ? "100" : "10",
1719 status & GEN_STATUS_FDX ? "Full" : "Half");
1723 i82559_restart(p_i82559);
1724 CheckRxRing(p_i82559,__FUNCTION__,__LINE__);
1727 static void i82559_restart(struct i82559 *p_i82559)
1730 ioaddr = p_i82559->io_address; // get 82559's I/O address
1732 // Load pointer to Rx Ring and enable receiver
1733 wait_for_cmd_done(ioaddr, WAIT_RU);
1734 OUTL(VIRT_TO_BUS(p_i82559->rx_ring[0]), ioaddr + SCBPointer);
1735 OUTW(RUC_START, ioaddr + SCBCmd);
1738 // ------------------------------------------------------------------------
1740 // Function : i82559_status
1742 // ------------------------------------------------------------------------
1744 i82559_status( struct eth_drv_sc *sc )
1747 struct i82559 *p_i82559;
1749 p_i82559 = (struct i82559 *)sc->driver_private;
1751 IF_BAD_82559( p_i82559 ) {
1753 os_printf( "i82559_status: Bad device pointer %x\n", p_i82559 );
1758 ioaddr = p_i82559->io_address; // get 82559's I/O address
1760 status = INB(ioaddr + SCBGenStatus);
1765 // ------------------------------------------------------------------------
1767 // Function : BringDown82559
1769 // ------------------------------------------------------------------------
1772 i82559_stop( struct eth_drv_sc *sc )
1774 struct i82559 *p_i82559;
1776 p_i82559 = (struct i82559 *)sc->driver_private;
1778 IF_BAD_82559( p_i82559 ) {
1780 os_printf( "i82559_stop: Bad device pointer %x\n", p_i82559 );
1786 os_printf("i82559_stop %d flg %x\n", p_i82559->index, *(int *)p_i82559 );
1789 p_i82559->active = 0; // stop people tormenting it
1790 i82559_reset(p_i82559); // that should stop it
1792 // Now that it's inactive, return all pending tx status to the higher
1794 // "Done" txen are from here to active, OR
1795 // the remove one if the queue is full AND its status is nonzero:
1797 int tx_descriptor_remove = p_i82559->tx_descriptor_remove;
1798 unsigned long key = p_i82559->tx_keys[ tx_descriptor_remove ];
1800 // Break out if "remove" is the active slot
1801 // (AND the Q is not full, or the Tx is not complete yet)
1802 if ( (tx_descriptor_remove == p_i82559->tx_descriptor_active) &&
1803 ( ! p_i82559->tx_queue_full) )
1806 // Zero the key in global state before the callback:
1807 p_i82559->tx_keys[ tx_descriptor_remove ] = 0;
1810 os_printf("Stop: TxDone %d %x: KEY %x TxCB %x\n",
1811 p_i82559->index, (int)p_i82559, key,
1812 p_i82559->tx_ring[ tx_descriptor_remove ]);
1814 // tx_done() can now cope with a NULL key, no guard needed here
1815 (sc->funs->eth_drv->tx_done)( sc, key, 1 /* status */ );
1817 if ( ++tx_descriptor_remove >= MAX_TX_DESCRIPTORS )
1818 tx_descriptor_remove = 0;
1819 p_i82559->tx_descriptor_remove = tx_descriptor_remove;
1820 p_i82559->tx_queue_full = 0;
1823 ResetRxRing( p_i82559 );
1824 ResetTxRing( p_i82559 );
1825 CheckRxRing(p_i82559,__FUNCTION__,__LINE__);
1829 // ------------------------------------------------------------------------
1831 // Function : InitRxRing
1833 // ------------------------------------------------------------------------
1835 InitRxRing(struct i82559* p_i82559)
1841 os_printf("InitRxRing %d\n", p_i82559->index);
1843 for ( i = 0; i < MAX_RX_DESCRIPTORS; i++ ) {
1844 rfd = (RFD *)pciwindow_mem_alloc(RFD_SIZEOF + MAX_RX_PACKET_SIZE);
1845 p_i82559->rx_ring[i] = rfd;
1847 WRITEMEM32(p_rfd+RFD_LINK, HAL_CTOLE32(VIRT_TO_BUS(rfd)));
1850 // link last RFD to first:
1851 WRITEMEM32(p_rfd+RFD_LINK,
1852 HAL_CTOLE32(VIRT_TO_BUS(p_i82559->rx_ring[0])));
1854 CheckRxRing(p_i82559,__FUNCTION__,__LINE__);
1855 ResetRxRing( p_i82559 );
1858 // ------------------------------------------------------------------------
1860 // Function : ResetRxRing
1862 // ------------------------------------------------------------------------
1864 ResetRxRing(struct i82559* p_i82559)
1869 os_printf("ResetRxRing %d\n", p_i82559->index);
1871 for ( i = 0; i < MAX_RX_DESCRIPTORS; i++ ) {
1872 p_rfd = p_i82559->rx_ring[i];
1873 CYG_ASSERT( (cyg_uint8 *)p_rfd >= i82559_heap_base, "rfd under" );
1874 CYG_ASSERT( (cyg_uint8 *)p_rfd < i82559_heap_free, "rfd over" );
1875 #ifdef CYGDBG_USE_ASSERTS
1879 p_rfd2 = p_i82559->rx_ring[ ( i ? (i-1) : (MAX_RX_DESCRIPTORS-1) ) ];
1880 READMEM32(p_rfd2 + RFD_LINK, link);
1881 if (!(HAL_LE32TOC(link) == VIRT_TO_BUS(p_rfd))) {
1883 diag_printf("Bad link eth%d %p %p %d %p\n",
1885 HAL_LE32TOC(link), VIRT_TO_BUS(p_rfd),
1886 i, __builtin_return_address(0));
1889 CYG_ASSERT( HAL_LE32TOC(link) == VIRT_TO_BUS(p_rfd),
1890 "rfd linked list broken" );
1893 WRITEMEM32(p_rfd + RFD_STATUS, 0 ); // do NOT suspend after just one rx
1894 WRITEMEM16(p_rfd + RFD_COUNT, 0);
1895 WRITEMEM32(p_rfd + RFD_RDB_ADDR, HAL_CTOLE32(0xFFFFFFFF));
1896 WRITEMEM16(p_rfd + RFD_SIZE, HAL_CTOLE16(MAX_RX_PACKET_SIZE));
1898 p_i82559->next_rx_descriptor = 0;
1899 // And set an end-of-list marker in the previous one.
1900 WRITEMEM32(p_rfd + RFD_STATUS, RFD_STATUS_EL);
1901 CheckRxRing(p_i82559,__FUNCTION__,__LINE__);
1904 // ------------------------------------------------------------------------
1906 // Function : CheckRxRing
1908 // ------------------------------------------------------------------------
1910 CheckRxRing(struct i82559* p_i82559, const char * func, int line)
1917 // console_printf("%s:%d(eth%d)\n",func,line,p_i82559->index);
1919 for ( i = 0; i < MAX_RX_DESCRIPTORS; i++ ) {
1920 p_rfd = p_i82559->rx_ring[i];
1921 if (! ((cyg_uint8 *)p_rfd >= i82559_heap_base))
1922 console_printf("rfd under: %s:%d\n", func, line);
1923 if (! ((cyg_uint8 *)p_rfd < i82559_heap_free))
1924 console_printf("rfd over: %s:%d\n", func, line );
1926 p_rfd2 = p_i82559->rx_ring[ ( i ? (i-1) : (MAX_RX_DESCRIPTORS-1) ) ];
1927 READMEM32(p_rfd2 + RFD_LINK, link);
1928 if (!(HAL_LE32TOC(link) == VIRT_TO_BUS(p_rfd))) {
1929 console_printf("Bad link eth%d %p %p %d %p: %s:%d\n",
1931 HAL_LE32TOC(link), VIRT_TO_BUS(p_rfd),
1932 i, __builtin_return_address(0),
1934 CYG_ASSERT(HAL_LE32TOC(link) == VIRT_TO_BUS(p_rfd),"Bad Link");
1939 // ------------------------------------------------------------------------
1941 // Function : PacketRxReady (Called from delivery thread & foreground)
1943 // ------------------------------------------------------------------------
1945 PacketRxReady(struct i82559* p_i82559)
1948 int next_descriptor;
1950 struct cyg_netdevtab_entry *ndp;
1951 struct eth_drv_sc *sc;
1955 ndp = (struct cyg_netdevtab_entry *)(p_i82559->ndp);
1956 sc = (struct eth_drv_sc *)(ndp->device_instance);
1958 CheckRxRing(p_i82559,__FUNCTION__,__LINE__);
1960 CHECK_NDP_SC_LINK();
1962 ioaddr = p_i82559->io_address;
1964 next_descriptor = p_i82559->next_rx_descriptor;
1965 p_rfd = p_i82559->rx_ring[next_descriptor];
1967 CYG_ASSERT( (cyg_uint8 *)p_rfd >= i82559_heap_base, "rfd under" );
1968 CYG_ASSERT( (cyg_uint8 *)p_rfd < i82559_heap_free, "rfd over" );
1971 cyg_uint32 rxstatus;
1972 cyg_uint16 rxstatus_hi;
1973 READMEM32(p_rfd + RFD_STATUS, rxstatus);
1974 if (0 == (rxstatus & RFD_STATUS_C))
1977 READMEM16(p_rfd + RFD_STATUS_HI, rxstatus_hi);
1978 rxstatus_hi |= RFD_STATUS_HI_EL;
1979 WRITEMEM16(p_rfd + RFD_STATUS_HI, rxstatus_hi);
1981 READMEM16(p_rfd + RFD_COUNT, length);
1982 length = HAL_LE16TOC(length);
1983 length &= RFD_COUNT_MASK;
1986 os_printf( "Device %d (eth%d), rx descriptor %d:\n",
1987 p_i82559->index, p_i82559->index, next_descriptor );
1988 // dump_rfd( p_rfd, 1 );
1991 p_i82559->next_rx_descriptor = next_descriptor;
1992 // Check for bogusly short packets; can happen in promisc mode:
1993 // Asserted against and checked by upper layer driver.
1995 if ( length > sizeof( struct ether_header ) )
1996 // then it is acceptable; offer the data to the network stack
1998 (sc->funs->eth_drv->recv)( sc, length );
2000 WRITEMEM16(p_rfd + RFD_COUNT, 0);
2001 WRITEMEM16(p_rfd + RFD_STATUS_LO, 0);
2003 // The just-emptied slot is now ready for re-use and already marked EL;
2004 // we can now remove the EL marker from the previous one.
2005 if ( 0 == next_descriptor )
2006 p_rfd = p_i82559->rx_ring[ MAX_RX_DESCRIPTORS-1 ];
2008 p_rfd = p_i82559->rx_ring[ next_descriptor-1 ];
2009 // The previous one: check it *was* marked before clearing.
2010 READMEM16(p_rfd + RFD_STATUS_HI, rxstatus_hi);
2011 CYG_ASSERT( rxstatus_hi & RFD_STATUS_HI_EL, "No prev EL" );
2012 // that word is not written by the device.
2013 WRITEMEM16(p_rfd + RFD_STATUS_HI, 0);
2015 #ifdef KEEP_STATISTICS
2016 statistics[p_i82559->index].rx_deliver++;
2018 if (++next_descriptor >= MAX_RX_DESCRIPTORS)
2019 next_descriptor = 0;
2020 p_rfd = p_i82559->rx_ring[next_descriptor];
2022 CYG_ASSERT( (cyg_uint8 *)p_rfd >= i82559_heap_base, "rfd under" );
2023 CYG_ASSERT( (cyg_uint8 *)p_rfd < i82559_heap_free, "rfd over" );
2025 CheckRxRing(p_i82559,__FUNCTION__,__LINE__);
2027 #ifdef CYGPKG_IO_ETH_DRIVERS_STAND_ALONE
2028 // Can't deliver more than one packet in polled standalone mode
2033 CheckRxRing(p_i82559,__FUNCTION__,__LINE__);
2035 // See if the RU has gone idle (usually because of out of resource
2036 // condition) and restart it if needs be.
2037 ints = Mask82559Interrupt(p_i82559);
2038 status = INW(ioaddr + SCBStatus);
2039 if ( RU_STATUS_READY != (status & RU_STATUS_MASK) ) {
2040 // Acknowledge the RX INT sources
2041 OUTW( SCB_INTACK_RX, ioaddr + SCBStatus);
2042 // (see pages 6-10 & 6-90)
2044 #ifdef KEEP_STATISTICS
2045 statistics[p_i82559->index].rx_restart++;
2047 // There's an end-of-list marker out there somewhere...
2048 // So mop it up; it takes a little time but this is infrequent.
2049 ResetRxRing( p_i82559 );
2050 next_descriptor = 0; // re-initialize next desc.
2051 // load pointer to Rx Ring
2052 wait_for_cmd_done(ioaddr, WAIT_RU);
2053 OUTL(VIRT_TO_BUS(p_i82559->rx_ring[0]),
2054 ioaddr + SCBPointer);
2055 OUTW(RUC_START, ioaddr + SCBCmd);
2056 Acknowledge82559Interrupt(p_i82559);
2058 UnMask82559Interrupt(p_i82559, ints);
2060 p_i82559->next_rx_descriptor = next_descriptor;
2063 // and the callback function
2066 i82559_recv( struct eth_drv_sc *sc, struct eth_drv_sg *sg_list, int sg_len )
2068 struct i82559 *p_i82559;
2070 int next_descriptor;
2072 struct eth_drv_sg *last_sg;
2073 volatile cyg_uint8 *from_p;
2074 cyg_uint32 rxstatus;
2075 cyg_uint16 rxstatus16;
2077 p_i82559 = (struct i82559 *)sc->driver_private;
2079 IF_BAD_82559( p_i82559 ) {
2081 os_printf( "i82559_recv: Bad device pointer %x\n", p_i82559 );
2086 next_descriptor = p_i82559->next_rx_descriptor;
2087 p_rfd = p_i82559->rx_ring[next_descriptor];
2089 CYG_ASSERT( (cyg_uint8 *)p_rfd >= i82559_heap_base, "rfd under" );
2090 CYG_ASSERT( (cyg_uint8 *)p_rfd < i82559_heap_free, "rfd over" );
2092 READMEM32(p_rfd + RFD_STATUS, rxstatus);
2093 CYG_ASSERT( rxstatus & RFD_STATUS_C, "No complete frame" );
2094 CYG_ASSERT( rxstatus & RFD_STATUS_EL, "No marked frame" );
2095 READMEM16(p_rfd + RFD_STATUS_LO, rxstatus16 );
2096 CYG_ASSERT( rxstatus16 & RFD_STATUS_LO_C, "No complete frame 2" );
2097 READMEM16(p_rfd + RFD_STATUS_HI, rxstatus16 );
2098 CYG_ASSERT( rxstatus16 & RFD_STATUS_HI_EL, "No marked frame 2" );
2100 CheckRxRing(p_i82559,__FUNCTION__,__LINE__);
2102 if ( 0 == (rxstatus & RFD_STATUS_C) )
2105 READMEM16(p_rfd + RFD_COUNT, total_len);
2106 total_len = HAL_LE16TOC(total_len);
2107 total_len &= RFD_COUNT_MASK;
2110 os_printf("Rx %d %x (status %x): %d sg's, %d bytes\n",
2111 p_i82559->index, (int)p_i82559,
2112 HAL_LE32TOC(rxstatus), sg_len, total_len);
2115 // Copy the data to the network stack
2116 from_p = p_rfd + RFD_BUFFER;
2118 // check we have memory to copy into; we would be called even if
2119 // caller was out of memory in order to maintain our state.
2120 if ( 0 == sg_len || 0 == sg_list )
2121 return; // caller was out of mbufs
2123 CYG_ASSERT( 0 < sg_len, "sg_len underflow" );
2124 CYG_ASSERT( MAX_ETH_DRV_SG >= sg_len, "sg_len overflow" );
2126 for ( last_sg = &sg_list[sg_len]; sg_list < last_sg; sg_list++ ) {
2130 to_p = (cyg_uint8 *)(sg_list->buf);
2133 CYG_ASSERT( 0 <= l, "sg length -ve" );
2135 if ( 0 >= l || 0 == to_p )
2136 return; // caller was out of mbufs
2138 if ( l > total_len )
2141 memcpy( to_p, (unsigned char *)from_p, l );
2146 CYG_ASSERT( 0 == total_len, "total_len mismatch in rx" );
2147 CYG_ASSERT( last_sg == sg_list, "sg count mismatch in rx" );
2148 CYG_ASSERT( p_rfd + RFD_BUFFER < from_p, "from_p wild in rx" );
2149 CYG_ASSERT( p_rfd + RFD_BUFFER + MAX_RX_PACKET_SIZE >= from_p,
2150 "from_p overflow in rx" );
2154 // ------------------------------------------------------------------------
2156 // Function : InitTxRing
2158 // ------------------------------------------------------------------------
2160 InitTxRing(struct i82559* p_i82559)
2166 os_printf("InitTxRing %d\n", p_i82559->index);
2168 ioaddr = p_i82559->io_address;
2169 for ( i = 0; i < MAX_TX_DESCRIPTORS; i++) {
2170 p_i82559->tx_ring[i] = (TxCB *)pciwindow_mem_alloc(
2171 TxCB_SIZEOF + MAX_TX_PACKET_SIZE);
2174 ResetTxRing(p_i82559);
2177 // ------------------------------------------------------------------------
2179 // Function : ResetTxRing
2181 // ------------------------------------------------------------------------
2183 ResetTxRing(struct i82559* p_i82559)
2189 os_printf("ResetTxRing %d\n", p_i82559->index);
2191 ioaddr = p_i82559->io_address;
2192 p_i82559->tx_descriptor_add =
2193 p_i82559->tx_descriptor_active =
2194 p_i82559->tx_descriptor_remove = 0;
2195 p_i82559->tx_in_progress =
2196 p_i82559->tx_queue_full = 0;
2198 for ( i = 0; i < MAX_TX_DESCRIPTORS; i++) {
2199 TxCB *p_txcb = p_i82559->tx_ring[i];
2200 CYG_ASSERT( (cyg_uint8 *)p_txcb >= i82559_heap_base, "txcb under" );
2201 CYG_ASSERT( (cyg_uint8 *)p_txcb < i82559_heap_free, "txcb over" );
2203 WRITEMEM16(p_txcb + TxCB_STATUS, 0);
2204 WRITEMEM16(p_txcb + TxCB_CMD, 0);
2205 WRITEMEM32(p_txcb + TxCB_LINK,
2206 HAL_CTOLE32(VIRT_TO_BUS((cyg_uint32)p_txcb)));
2207 WRITEMEM32(p_txcb + TxCB_TBD_ADDR, HAL_CTOLE32(0xFFFFFFFF));
2208 WRITEMEM8(p_txcb + TxCB_TBD_NUMBER, 0);
2209 WRITEMEM8(p_txcb + TxCB_TX_THRESHOLD, 16);
2210 WRITEMEM16(p_txcb + TxCB_COUNT,
2211 HAL_CTOLE16(TxCB_COUNT_EOF | 0));
2212 p_i82559->tx_keys[i] = 0;
2215 wait_for_cmd_done(ioaddr,WAIT_CU);
2216 OUTL(0, ioaddr + SCBPointer);
2217 OUTW(SCB_M | CU_ADDR_LOAD, ioaddr + SCBCmd);
2218 CheckRxRing(p_i82559,__FUNCTION__,__LINE__);
2221 // ------------------------------------------------------------------------
2223 // Function : TxMachine (Called from FG & ISR)
2225 // This steps the Tx Machine onto the next record if necessary - allowing
2226 // for missed interrupts, and so on.
2227 // ------------------------------------------------------------------------
2230 TxMachine(struct i82559* p_i82559)
2232 int tx_descriptor_active;
2235 tx_descriptor_active = p_i82559->tx_descriptor_active;
2236 ioaddr = p_i82559->io_address;
2238 CheckRxRing(p_i82559,__FUNCTION__,__LINE__);
2239 // See if the CU is idle when we think it isn't; this is the only place
2240 // tx_descriptor_active is advanced. (Also recovers from a dropped intr)
2241 if ( p_i82559->tx_in_progress ) {
2243 status = INW(ioaddr + SCBStatus);
2244 if ( 0 == (status & CU_STATUS_MASK) ) {
2245 // It is idle. So ack the TX interrupts
2246 OUTW( SCB_INTACK_TX, ioaddr + SCBStatus);
2247 // (see pages 6-10 & 6-90)
2249 // and step on to the next queued tx.
2250 p_i82559->tx_in_progress = 0;
2251 if ( ++tx_descriptor_active >= MAX_TX_DESCRIPTORS )
2252 tx_descriptor_active = 0;
2253 p_i82559->tx_descriptor_active = tx_descriptor_active;
2257 // is the CU idle, and there a next tx to set going?
2258 if ( ( ! p_i82559->tx_in_progress )
2259 && (( p_i82559->tx_descriptor_add != tx_descriptor_active )
2260 || p_i82559->tx_queue_full ) ) {
2261 TxCB *p_txcb = p_i82559->tx_ring[tx_descriptor_active];
2264 // start Tx operation
2265 wait_for_cmd_done(ioaddr, WAIT_CU);
2266 status = INW(ioaddr + SCBStatus);
2267 // The following assert sometimes fires here, apparantly harmless!
2268 // So check a second time to let the cursed thing settle and not
2270 if ( 0 != (status & CU_STATUS_MASK) ) {
2271 #ifdef CYGDBG_USE_ASSERTS
2272 missed_interrupt.bad_cu_idles++;
2274 wait_for_cmd_done(ioaddr, WAIT_CU);
2275 status = INW(ioaddr + SCBStatus);
2277 CYG_ASSERT( ( 0 == (status & CU_STATUS_MASK)), "CU not idle");
2278 CYG_ASSERT( (cyg_uint8 *)p_txcb >= i82559_heap_base, "txcb under" );
2279 CYG_ASSERT( (cyg_uint8 *)p_txcb < i82559_heap_free, "txcb over" );
2282 unsigned long key = p_i82559->tx_keys[ tx_descriptor_active ];
2283 os_printf("Tx %d %x: Starting Engines: KEY %x TxCB %x\n",
2284 p_i82559->index, (int)p_i82559, key, p_txcb);
2288 OUTL(VIRT_TO_BUS(p_txcb), ioaddr + SCBPointer);
2289 OUTW(CU_START, ioaddr + SCBCmd);
2290 p_i82559->tx_in_progress = 1;
2292 CheckRxRing(p_i82559,__FUNCTION__,__LINE__);
2295 // ------------------------------------------------------------------------
2297 // Function : TxDone (Called from delivery thread)
2299 // This returns Tx's from the Tx Machine to the stack (ie. reports
2300 // completion) - allowing for missed interrupts, and so on.
2301 // ------------------------------------------------------------------------
2304 TxDone(struct i82559* p_i82559)
2306 struct cyg_netdevtab_entry *ndp;
2307 struct eth_drv_sc *sc;
2308 int tx_descriptor_remove = p_i82559->tx_descriptor_remove;
2310 ndp = (struct cyg_netdevtab_entry *)(p_i82559->ndp);
2311 sc = (struct eth_drv_sc *)(ndp->device_instance);
2313 CHECK_NDP_SC_LINK();
2315 // "Done" txen are from here to active, OR
2316 // the remove one if the queue is full AND its status is nonzero:
2318 cyg_uint16 txstatus;
2319 TxCB *p_txcb = p_i82559->tx_ring[ tx_descriptor_remove ];
2320 unsigned long key = p_i82559->tx_keys[ tx_descriptor_remove ];
2322 READMEM16(p_txcb + TxCB_STATUS, txstatus);
2324 // Break out if "remove" is the active slot
2325 // (AND the Q is not full, or the Tx is not complete yet)
2326 if ( (tx_descriptor_remove == p_i82559->tx_descriptor_active) &&
2327 ( ( ! p_i82559->tx_queue_full) || (0 == txstatus) ) )
2330 // Zero the key in global state before the callback:
2331 p_i82559->tx_keys[ tx_descriptor_remove ] = 0;
2334 os_printf("TxDone %d %x: KEY %x TxCB %x\n",
2335 p_i82559->index, (int)p_i82559, key, p_txcb );
2337 // tx_done() can now cope with a NULL key, no guard needed here
2338 (sc->funs->eth_drv->tx_done)( sc, key, 1 /* status */ );
2340 if ( ++tx_descriptor_remove >= MAX_TX_DESCRIPTORS )
2341 tx_descriptor_remove = 0;
2342 p_i82559->tx_descriptor_remove = tx_descriptor_remove;
2343 p_i82559->tx_queue_full = 0;
2348 // ------------------------------------------------------------------------
2350 // Function : i82559_can_send
2352 // ------------------------------------------------------------------------
2355 i82559_can_send(struct eth_drv_sc *sc)
2357 struct i82559 *p_i82559;
2360 p_i82559 = (struct i82559 *)sc->driver_private;
2362 IF_BAD_82559( p_i82559 ) {
2364 os_printf( "i82559_send: Bad device pointer %x\n", p_i82559 );
2369 // Advance TxMachine atomically
2370 ints = Mask82559Interrupt(p_i82559);
2372 // This helps unstick deadly embraces.
2373 CYG_ASSERT( p_i82559->within_send < 10, "send: Excess send recursions" );
2374 p_i82559->within_send++;
2376 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_DEMUX_ALL
2379 // The problem is, if DEMUX_ALL, either device can eat the other's
2380 // interrupts; so we must poll them *both*:
2381 for (i = 0; i < CYGNUM_DEVS_ETH_INTEL_I82559_DEV_COUNT; i++) {
2382 p_i82559 = i82559_priv_array[i];
2383 if ( p_i82559->active ) {
2384 // See if the Tx machine is wedged - reset if so:
2385 Check82559TxLockupTimeout(p_i82559);
2386 TxMachine(p_i82559);
2387 Acknowledge82559Interrupt(p_i82559);
2388 #ifndef CYGPKG_IO_ETH_DRIVERS_STAND_ALONE
2389 // We are not prepared to receive a packet now if we are in a polled
2390 // standalone configuration.
2391 PacketRxReady(p_i82559);
2393 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_MISSED_INTERRUPT
2394 if ( CYGHWR_DEVS_ETH_INTEL_I82559_MISSED_INTERRUPT(p_i82559) ) {
2395 #ifdef CYGDBG_USE_ASSERTS
2396 missed_interrupt.can_send++;
2398 eth_isr( p_i82559->vector, (cyg_addrword_t)p_i82559 );
2399 eth_dsr( p_i82559->vector, 1, (cyg_addrword_t)p_i82559 );
2405 // ensure we look at the correct device at the end
2406 p_i82559 = (struct i82559 *)sc->driver_private;
2407 #else // no CYGHWR_DEVS_ETH_INTEL_I82559_DEMUX_ALL
2409 // See if the Tx machine is wedged - reset if so:
2410 Check82559TxLockupTimeout(p_i82559);
2411 TxMachine(p_i82559);
2412 Acknowledge82559Interrupt(p_i82559); // This can eat an Rx interrupt, so
2413 #ifndef CYGPKG_IO_ETH_DRIVERS_STAND_ALONE
2414 // We are not prepared to receive a packet now if we are in a polled
2415 // standalone configuration.
2416 PacketRxReady(p_i82559);
2418 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_MISSED_INTERRUPT
2419 if ( CYGHWR_DEVS_ETH_INTEL_I82559_MISSED_INTERRUPT(p_i82559) ) {
2420 #ifdef CYGDBG_USE_ASSERTS
2421 missed_interrupt.can_send++;
2423 eth_isr( p_i82559->vector, (cyg_addrword_t)p_i82559 );
2424 eth_dsr( p_i82559->vector, 1, (cyg_addrword_t)p_i82559 );
2427 #endif // no CYGHWR_DEVS_ETH_INTEL_I82559_DEMUX_ALL
2429 p_i82559->within_send--;
2430 UnMask82559Interrupt(p_i82559,ints);
2432 return (0 == p_i82559->within_send) && ! p_i82559->tx_queue_full;
2435 // ------------------------------------------------------------------------
2437 // Function : i82559_send
2439 // ------------------------------------------------------------------------
2442 i82559_send(struct eth_drv_sc *sc,
2443 struct eth_drv_sg *sg_list, int sg_len, int total_len,
2446 struct i82559 *p_i82559;
2447 int tx_descriptor_add, ints;
2451 p_i82559 = (struct i82559 *)sc->driver_private;
2453 IF_BAD_82559( p_i82559 ) {
2455 os_printf( "i82559_send: Bad device pointer %x\n", p_i82559 );
2461 os_printf("Tx %d %x: %d sg's, %d bytes, KEY %x\n",
2462 p_i82559->index, (int)p_i82559, sg_len, total_len, key );
2465 if ( ! p_i82559->active )
2466 return; // device inactive, no return
2467 #ifdef KEEP_STATISTICS
2468 statistics[p_i82559->index].tx_count++;
2470 ioaddr = p_i82559->io_address; // get device I/O address
2472 // See if the Tx machine is wedged - reset if so:
2473 Check82559TxLockupTimeout(p_i82559);
2475 if ( p_i82559->tx_queue_full ) {
2476 #ifdef KEEP_STATISTICS
2477 statistics[p_i82559->index].tx_dropped++;
2480 os_printf( "i82559_send: Queue full, device %x, key %x\n",
2485 struct eth_drv_sg *last_sg;
2486 volatile cyg_uint8 *to_p;
2488 tx_descriptor_add = p_i82559->tx_descriptor_add;
2490 p_i82559->tx_keys[tx_descriptor_add] = key;
2492 p_txcb = p_i82559->tx_ring[tx_descriptor_add];
2494 CYG_ASSERT( (cyg_uint8 *)p_txcb >= i82559_heap_base, "txcb under" );
2495 CYG_ASSERT( (cyg_uint8 *)p_txcb < i82559_heap_free, "txcb over" );
2497 WRITEMEM16(p_txcb + TxCB_STATUS, 0);
2498 WRITEMEM16(p_txcb + TxCB_CMD,
2499 (TxCB_CMD_TRANSMIT | TxCB_CMD_S
2500 | TxCB_CMD_I | TxCB_CMD_EL));
2501 WRITEMEM32(p_txcb + TxCB_LINK,
2502 HAL_CTOLE32(VIRT_TO_BUS((cyg_uint32)p_txcb)));
2503 WRITEMEM32(p_txcb + TxCB_TBD_ADDR,
2504 HAL_CTOLE32(0xFFFFFFFF));
2505 WRITEMEM8(p_txcb + TxCB_TBD_NUMBER, 0);
2506 WRITEMEM8(p_txcb + TxCB_TX_THRESHOLD, 16);
2507 WRITEMEM16(p_txcb + TxCB_COUNT,
2508 HAL_CTOLE16(TxCB_COUNT_EOF | total_len));
2510 // Copy from the sglist into the txcb
2511 to_p = p_txcb + TxCB_BUFFER;
2513 CYG_ASSERT( 0 < sg_len, "sg_len underflow" );
2514 CYG_ASSERT( MAX_ETH_DRV_SG >= sg_len, "sg_len overflow" );
2516 for ( last_sg = &sg_list[sg_len]; sg_list < last_sg; sg_list++ ) {
2520 from_p = (cyg_uint8 *)(sg_list->buf);
2523 if ( l > total_len )
2526 memcpy( (unsigned char *)to_p, from_p, l );
2530 if ( 0 > total_len )
2531 break; // Should exit via sg_last normally
2534 CYG_ASSERT( 0 == total_len, "length mismatch in tx" );
2535 CYG_ASSERT( last_sg == sg_list, "sg count mismatch in tx" );
2536 CYG_ASSERT( p_txcb + TxCB_BUFFER < to_p, "to_p wild in tx" );
2537 CYG_ASSERT( p_txcb + TxCB_BUFFER + MAX_TX_PACKET_SIZE >= to_p,
2538 "to_p overflow in tx" );
2541 if ( ++tx_descriptor_add >= MAX_TX_DESCRIPTORS)
2542 tx_descriptor_add = 0;
2543 p_i82559->tx_descriptor_add = tx_descriptor_add;
2545 // From this instant, interrupts can advance the world and start,
2546 // even complete, this tx request...
2548 if ( p_i82559->tx_descriptor_remove == tx_descriptor_add )
2549 p_i82559->tx_queue_full = 1;
2552 // Try advancing the Tx Machine regardless
2554 // no more interrupts until started
2555 ints = Mask82559Interrupt(p_i82559);
2557 // This helps unstick deadly embraces.
2558 CYG_ASSERT( p_i82559->within_send < 10, "send: Excess send recursions" );
2559 p_i82559->within_send++;
2561 // Check that either:
2562 // tx is already active, there is other stuff queued,
2563 // OR this tx just added is the current active one
2564 // OR this tx just added is already complete
2566 // The machine is busy:
2567 (p_i82559->tx_in_progress == 1) ||
2568 // or: The machine is idle and this just added is the next one
2569 (((p_i82559->tx_descriptor_add-1) == p_i82559->tx_descriptor_active)
2570 || ((0 == p_i82559->tx_descriptor_add) &&
2571 ((MAX_TX_DESCRIPTORS-1) == p_i82559->tx_descriptor_active))) ||
2572 // or: This tx is already complete
2573 (p_i82559->tx_descriptor_add == p_i82559->tx_descriptor_active),
2574 "Active/add mismatch" );
2576 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_DEMUX_ALL
2579 // The problem is, if DEMUX_ALL, either device can eat the other's
2580 // interrupts; so we must poll them *both*:
2581 for (i = 0; i < CYGNUM_DEVS_ETH_INTEL_I82559_DEV_COUNT; i++) {
2582 p_i82559 = i82559_priv_array[i];
2583 if ( p_i82559->active ) {
2584 TxMachine(p_i82559);
2585 Acknowledge82559Interrupt(p_i82559);
2586 #ifndef CYGPKG_IO_ETH_DRIVERS_STAND_ALONE
2587 // We are not prepared to receive a packet now if we are in a polled
2588 // standalone configuration.
2589 PacketRxReady(p_i82559);
2594 // ensure we look at the correct device at the end
2595 p_i82559 = (struct i82559 *)sc->driver_private;
2596 #else // no CYGHWR_DEVS_ETH_INTEL_I82559_DEMUX_ALL
2597 // Advance TxMachine atomically
2598 TxMachine(p_i82559);
2599 Acknowledge82559Interrupt(p_i82559); // This can eat an Rx interrupt, so
2600 #ifndef CYGPKG_IO_ETH_DRIVERS_STAND_ALONE
2601 // We are not prepared to receive a packet now if we are in a polled
2602 // standalone configuration.
2603 PacketRxReady(p_i82559);
2605 #endif // no CYGHWR_DEVS_ETH_INTEL_I82559_DEMUX_ALL
2607 p_i82559->within_send--;
2608 UnMask82559Interrupt(p_i82559, ints);
2611 // ------------------------------------------------------------------------
2613 // Function : i82559_reset
2615 // ------------------------------------------------------------------------
2617 i82559_reset(struct i82559* p_i82559)
2619 cyg_uint32 ioaddr = p_i82559->io_address;
2621 // First do soft reset. This must be done before the hard reset,
2622 // otherwise we may create havoc on the PCI bus.
2623 // Wait 20 uSecs afterwards for chip to settle.
2624 OUTL(I82559_SELECTIVE_RESET, ioaddr + SCBPort);
2627 // Do hard reset now that the controller is off the PCI bus.
2628 // Wait 20 uSecs afterwards for chip to settle.
2629 OUTL(I82559_RESET, ioaddr + SCBPort);
2632 // Set the base addresses
2633 wait_for_cmd_done(ioaddr, WAIT_RU);
2634 OUTL(0, ioaddr + SCBPointer);
2635 OUTW(SCB_M | RUC_ADDR_LOAD, ioaddr + SCBCmd);
2637 wait_for_cmd_done(ioaddr, WAIT_CU);
2638 OUTL(0, ioaddr + SCBPointer);
2639 OUTW(SCB_M | CU_ADDR_LOAD, ioaddr + SCBCmd);
2642 // ------------------------------------------------------------------------
2644 // INTERRUPT HANDLERS
2646 // ------------------------------------------------------------------------
2649 eth_isr(cyg_vector_t vector, cyg_addrword_t data)
2651 struct i82559* p_i82559 = (struct i82559 *)data;
2655 IF_BAD_82559( p_i82559 ) {
2657 os_printf( "i82559_isr: Bad device pointer %x\n", p_i82559 );
2662 ioaddr = p_i82559->io_address;
2663 status = INW(ioaddr + SCBStatus);
2665 // Acknowledge all INT sources that were active
2666 OUTW( status & SCB_INTACK_MASK, ioaddr + SCBStatus);
2667 // (see pages 6-10 & 6-90)
2669 #ifdef KEEP_STATISTICS
2670 statistics[p_i82559->index].interrupts++;
2672 // receiver left ready state ?
2673 if ( status & SCB_STATUS_RNR )
2674 statistics[p_i82559->index].rx_resource++;
2676 // frame receive interrupt ?
2677 if ( status & SCB_STATUS_FR )
2678 statistics[p_i82559->index].rx_count++;
2680 // transmit interrupt ?
2681 if ( status & SCB_STATUS_CX )
2682 statistics[p_i82559->index].tx_complete++;
2685 // Advance the Tx Machine regardless
2686 TxMachine(p_i82559);
2688 // it should have settled down now...
2689 Acknowledge82559Interrupt(p_i82559);
2691 return CYG_ISR_CALL_DSR; // schedule DSR
2695 // ------------------------------------------------------------------------
2696 #if defined( CYGNUM_DEVS_ETH_INTEL_I82559_SEPARATE_MUX_INTERRUPT ) || \
2697 defined( CYGHWR_DEVS_ETH_INTEL_I82559_DEMUX_ALL )
2699 eth_mux_isr(cyg_vector_t vector, cyg_addrword_t data)
2702 struct i82559* p_i82559;
2704 for (i = 0; i < CYGNUM_DEVS_ETH_INTEL_I82559_DEV_COUNT; i++) {
2705 p_i82559 = i82559_priv_array[i];
2706 if ( p_i82559->active )
2707 (void)eth_isr( vector, (cyg_addrword_t)p_i82559 );
2710 return CYG_ISR_CALL_DSR;
2714 // ------------------------------------------------------------------------
2716 #if defined(CYGHWR_DEVS_ETH_INTEL_I82559_MISSED_INTERRUPT) || \
2717 defined(CYGNUM_DEVS_ETH_INTEL_I82559_SEPARATE_MUX_INTERRUPT) || \
2718 !defined(CYGPKG_IO_ETH_DRIVERS_STAND_ALONE)
2720 eth_dsr(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
2722 // This conditioning out is necessary because of explicit calls to this
2723 // DSR - which would not ever be called in the case of a polled mode
2724 // usage ie. in RedBoot.
2725 #ifdef CYGINT_IO_ETH_INT_SUPPORT_REQUIRED
2726 struct i82559* p_i82559 = (struct i82559 *)data;
2727 struct cyg_netdevtab_entry *ndp =
2728 (struct cyg_netdevtab_entry *)(p_i82559->ndp);
2729 struct eth_drv_sc *sc = (struct eth_drv_sc *)(ndp->device_instance);
2731 // but here, it must be a *sc:
2732 eth_drv_dsr( vector, count, (cyg_addrword_t)sc );
2734 # ifndef CYGPKG_REDBOOT
2735 # error Empty i82559 ethernet DSR is compiled. Is this what you want?
2741 // ------------------------------------------------------------------------
2743 #if defined( CYGNUM_DEVS_ETH_INTEL_I82559_SEPARATE_MUX_INTERRUPT ) || \
2744 defined( CYGHWR_DEVS_ETH_INTEL_I82559_DEMUX_ALL )
2747 i82559_deliver(struct eth_drv_sc *sc)
2750 struct i82559* p_i82559;
2752 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_MISSED_INTERRUPT
2756 // Since this must mux all devices, the incoming arg is ignored.
2757 for (i = 0; i < CYGNUM_DEVS_ETH_INTEL_I82559_DEV_COUNT; i++) {
2758 p_i82559 = i82559_priv_array[i];
2759 if ( p_i82559->active ) {
2761 // See if the Tx machine is wedged - reset if so:
2762 Check82559TxLockupTimeout(p_i82559);
2764 // First pass any rx data up the stack
2765 PacketRxReady(p_i82559);
2767 // Then scan for completed Txen and inform the stack
2772 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_MISSED_INTERRUPT
2775 for (i = 0; i < CYGNUM_DEVS_ETH_INTEL_I82559_DEV_COUNT; i++) {
2776 p_i82559 = i82559_priv_array[i];
2777 if ( p_i82559->active ) {
2778 if ( CYGHWR_DEVS_ETH_INTEL_I82559_MISSED_INTERRUPT(p_i82559) ) {
2779 int ints = Mask82559Interrupt(p_i82559);
2781 #ifdef CYGDBG_USE_ASSERTS
2782 missed_interrupt.deliver++;
2784 eth_isr( p_i82559->vector, (cyg_addrword_t)p_i82559 );
2785 UnMask82559Interrupt(p_i82559,ints);
2796 #else // no CYGHWR_DEVS_ETH_INTEL_I82559_DEMUX_ALL : Simplex version:
2799 i82559_deliver(struct eth_drv_sc *sc)
2801 struct i82559* p_i82559 = (struct i82559 *)(sc->driver_private);
2803 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_MISSED_INTERRUPT
2806 // See if the Tx machine is wedged - reset if so:
2807 Check82559TxLockupTimeout(p_i82559);
2809 // First pass any rx data up the stack
2810 PacketRxReady(p_i82559);
2812 // Then scan for completed Txen and inform the stack
2815 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_MISSED_INTERRUPT
2816 if ( CYGHWR_DEVS_ETH_INTEL_I82559_MISSED_INTERRUPT(p_i82559) ) {
2817 int ints = Mask82559Interrupt(p_i82559);
2818 #ifdef CYGDBG_USE_ASSERTS
2819 missed_interrupt.deliver++;
2821 eth_isr( p_i82559->vector, (cyg_addrword_t)p_i82559 );
2822 UnMask82559Interrupt(p_i82559,ints);
2828 #endif // no CYGHWR_DEVS_ETH_INTEL_I82559_DEMUX_ALL
2830 // ------------------------------------------------------------------------
2831 // Device table entry to operate the chip in a polled mode.
2832 // Only diddle the interface we were asked to!
2835 i82559_poll(struct eth_drv_sc *sc)
2837 struct i82559 *p_i82559;
2839 p_i82559 = (struct i82559 *)sc->driver_private;
2841 IF_BAD_82559( p_i82559 ) {
2843 os_printf( "i82559_poll: Bad device pointer %x\n", p_i82559 );
2848 // Do these atomically
2849 ints = Mask82559Interrupt(p_i82559);
2851 // As it happens, this driver always requests the DSR to be called:
2852 (void)eth_isr( p_i82559->vector, (cyg_addrword_t)p_i82559 );
2854 // (no harm in calling this ints-off also, when polled)
2855 i82559_deliver( sc );
2857 Acknowledge82559Interrupt(p_i82559);
2858 UnMask82559Interrupt(p_i82559, ints);
2861 // ------------------------------------------------------------------------
2862 // Determine interrupt vector used by a device - for attaching GDB stubs
2865 i82559_int_vector(struct eth_drv_sc *sc)
2867 struct i82559 *p_i82559;
2868 p_i82559 = (struct i82559 *)sc->driver_private;
2869 return (p_i82559->vector);
2874 i82559_int_op( struct eth_drv_sc *sc, int mask)
2876 struct i82559 *p_i82559;
2877 p_i82559 = (struct i82559 *)sc->driver_private;
2880 return Mask82559Interrupt( p_i82559 );
2883 UnMask82559Interrupt( p_i82559, 0x0fffffff ); // enable all
2890 // ------------------------------------------------------------------------
2892 // Function : pci_init_find_82559s
2894 // This is called exactly once at the start of time to:
2895 // o scan the PCI bus for objects
2896 // o record them in the device table
2897 // o acquire all the info needed for the driver to access them
2898 // o instantiate interrupts for them
2899 // o attach those interrupts appropriately
2900 // ------------------------------------------------------------------------
2901 static cyg_pci_match_func find_82559s_match_func;
2903 // Intel 82559 and 82557 are virtually identical, with different
2904 // dev codes; also 82559ER (cutdown) = 0x1209.
2906 find_82559s_match_func( cyg_uint16 v, cyg_uint16 d, cyg_uint32 c, void *p )
2918 pci_init_find_82559s( void )
2920 cyg_pci_device_id devid;
2921 cyg_pci_device dev_info;
2924 int found_devices = 0;
2926 #ifdef CYGNUM_DEVS_ETH_INTEL_I82559_SEPARATE_MUX_INTERRUPT
2927 static cyg_handle_t mux_interrupt_handle = 0;
2931 db_printf("pci_init_find_82559s()\n");
2934 // allocate memory to be used in ioctls later
2935 if (mem_reserved_ioctl != (void*)0) {
2937 db_printf("pci_init_find_82559s() called > once\n");
2942 // First initialize the heap in PCI window'd memory
2943 i82559_heap_size = CYGHWR_INTEL_I82559_PCI_MEM_MAP_SIZE;
2944 i82559_heap_base = (cyg_uint8 *)CYGHWR_INTEL_I82559_PCI_MEM_MAP_BASE;
2945 i82559_heap_free = i82559_heap_base;
2947 mem_reserved_ioctl = pciwindow_mem_alloc(MAX_MEM_RESERVED_IOCTL);
2951 db_printf("Finished cyg_pci_init();\n");
2954 devid = CYG_PCI_NULL_DEVID;
2956 for (device_index = 0;
2957 device_index < CYGNUM_DEVS_ETH_INTEL_I82559_DEV_COUNT;
2959 struct i82559 *p_i82559 = i82559_priv_array[device_index];
2961 p_i82559->index = device_index;
2963 // See above for find_82559s_match_func - it selects any of several
2964 // variants. This is necessary in case we have multiple mixed-type
2965 // devices on one board in arbitrary orders.
2966 if (cyg_pci_find_matching( &find_82559s_match_func, NULL, &devid )) {
2968 db_printf("eth%d = 82559\n", device_index);
2970 // Allocate it a stats window:
2971 p_i82559->p_statistics = pciwindow_mem_alloc(sizeof(I82559_COUNTERS));
2973 cyg_pci_get_device_info(devid, &dev_info);
2975 p_i82559->interrupt_handle = 0; // Flag not attached.
2976 if (cyg_pci_translate_interrupt(&dev_info, &p_i82559->vector)) {
2978 db_printf(" Wired to HAL vector %d\n", p_i82559->vector);
2981 #ifndef CYGPKG_IO_ETH_DRIVERS_STAND_ALONE
2982 cyg_drv_interrupt_create(
2984 0, // Priority - unused
2985 (CYG_ADDRWORD)p_i82559, // Data item passed to ISR & DSR
2986 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_DEMUX_ALL
2992 &p_i82559->interrupt_handle, // handle to intr obj
2993 &p_i82559->interrupt_object ); // space for int obj
2995 cyg_drv_interrupt_attach(p_i82559->interrupt_handle);
2997 // Don't unmask the interrupt yet, that could get us into a
2999 #ifdef CYGNUM_DEVS_ETH_INTEL_I82559_SEPARATE_MUX_INTERRUPT
3000 // ALSO attach it to MUX interrupt for multiplexed
3001 // interrupts. This is for certain boards where the
3002 // PCI backplane is wired "straight through" instead of
3003 // with a rotation of interrupt lines in the different
3006 static cyg_interrupt mux_interrupt_object;
3008 if ( ! mux_interrupt_handle ) {
3010 db_printf(" Also attaching to HAL vector %d\n",
3011 CYGNUM_DEVS_ETH_INTEL_I82559_SEPARATE_MUX_INTERRUPT);
3013 cyg_drv_interrupt_create(
3014 CYGNUM_DEVS_ETH_INTEL_I82559_SEPARATE_MUX_INTERRUPT,
3015 0, // Priority - unused
3016 (CYG_ADDRWORD)p_i82559,// Data item passed to ISR and DSR
3019 &mux_interrupt_handle,
3020 &mux_interrupt_object );
3022 cyg_drv_interrupt_attach(mux_interrupt_handle);
3025 #endif // CYGNUM_DEVS_ETH_INTEL_I82559_SEPARATE_MUX_INTERRUPT
3026 #endif // !CYGPKG_IO_ETH_DRIVERS_STAND_ALONE
3031 db_printf(" Does not generate interrupts.\n");
3035 if (cyg_pci_configure_device(&dev_info)) {
3038 db_printf("Found device on bus %d, devfn 0x%02x:\n",
3039 CYG_PCI_DEV_GET_BUS(devid),
3040 CYG_PCI_DEV_GET_DEVFN(devid));
3042 if (dev_info.command & CYG_PCI_CFG_COMMAND_ACTIVE) {
3043 db_printf(" Note that board is active. Probed"
3044 " sizes and CPU addresses invalid!\n");
3046 db_printf(" Vendor 0x%04x", dev_info.vendor);
3047 db_printf("\n Device 0x%04x", dev_info.device);
3048 db_printf("\n Command 0x%04x, Status 0x%04x\n",
3049 dev_info.command, dev_info.status);
3051 db_printf(" Class/Rev 0x%08x", dev_info.class_rev);
3052 db_printf("\n Header 0x%02x\n", dev_info.header_type);
3054 db_printf(" SubVendor 0x%04x, Sub ID 0x%04x\n",
3055 dev_info.header.normal.sub_vendor,
3056 dev_info.header.normal.sub_id);
3058 for(i = 0; i < CYG_PCI_MAX_BAR; i++) {
3059 db_printf(" BAR[%d] 0x%08x /", i, dev_info.base_address[i]);
3060 db_printf(" probed size 0x%08x / CPU addr 0x%08x\n",
3061 dev_info.base_size[i], dev_info.base_map[i]);
3063 db_printf(" eth%d configured\n", device_index);
3066 p_i82559->found = 1;
3067 p_i82559->active = 0;
3068 p_i82559->devid = devid;
3069 p_i82559->memory_address = dev_info.base_map[0];
3070 p_i82559->io_address = dev_info.base_map[1];
3072 db_printf(" memory address = 0x%08x\n", dev_info.base_map[0]);
3073 db_printf(" I/O address = 0x%08x\n", dev_info.base_map[1]);
3075 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_USE_MEMORY
3076 // Use the memory address instead of I/O. Some devices just
3077 // don't want to talk using the I/O registers :-(
3078 p_i82559->io_address = dev_info.base_map[0];
3081 // Don't use cyg_pci_set_device_info since it clears
3082 // some of the fields we want to print out below.
3083 cyg_pci_read_config_uint16(dev_info.devid,
3084 CYG_PCI_CFG_COMMAND, &cmd);
3085 cmd |= (CYG_PCI_CFG_COMMAND_IO // enable I/O space
3086 | CYG_PCI_CFG_COMMAND_MEMORY // enable memory space
3087 | CYG_PCI_CFG_COMMAND_MASTER); // enable bus master
3088 cyg_pci_write_config_uint16(dev_info.devid,
3089 CYG_PCI_CFG_COMMAND, cmd);
3091 // Now the PCI part of the device is configured, reset
3092 // it. This should make it safe to enable the
3094 i82559_reset(p_i82559);
3096 // This is the indicator for "uses an interrupt"
3097 if (p_i82559->interrupt_handle != 0) {
3098 cyg_drv_interrupt_acknowledge(p_i82559->vector);
3099 #ifndef CYGPKG_IO_ETH_DRIVERS_STAND_ALONE
3100 cyg_drv_interrupt_unmask(p_i82559->vector);
3101 #endif // !CYGPKG_IO_ETH_DRIVERS_STAND_ALONE
3104 db_printf(" **** Device enabled for I/O and Memory "
3105 "and Bus Master\n");
3109 p_i82559->found = 0;
3110 p_i82559->active = 0;
3112 db_printf("Failed to configure device %d\n",device_index);
3117 p_i82559->found = 0;
3118 p_i82559->active = 0;
3120 db_printf("eth%d not found\n", device_index);
3125 if (0 == found_devices)
3128 #ifdef CYGNUM_DEVS_ETH_INTEL_I82559_SEPARATE_MUX_INTERRUPT
3129 // Now enable the mux shared interrupt if it is in use
3130 if (mux_interrupt_handle) {
3131 cyg_drv_interrupt_acknowledge(CYGNUM_DEVS_ETH_INTEL_I82559_SEPARATE_MUX_INTERRUPT);
3132 cyg_drv_interrupt_unmask(CYGNUM_DEVS_ETH_INTEL_I82559_SEPARATE_MUX_INTERRUPT);
3136 // Now a delay to ensure the hardware has "come up" before you try to
3137 // use it. Yes, really, the full 2 seconds. It's only really
3138 // necessary if DEBUG is off - otherwise all that printout wastes
3139 // enough time. No kidding.
3144 // ------------------------------------------------------------------------
3146 // Function : i82559_set_multicast
3148 // ------------------------------------------------------------------------
3149 #ifdef ETH_DRV_SET_MC_LIST
3150 static int i82559_set_multicast(struct i82559* p_i82559,
3152 cyg_uint8 *address_list )
3156 volatile cyg_uint8* config_bytes;
3161 IF_BAD_82559( p_i82559 ) {
3163 os_printf( "eth_set_promiscuos_mode: Bad device pointer %x\n",
3169 ioaddr = p_i82559->io_address;
3170 wait_for_cmd_done(ioaddr, WAIT_CU);
3171 // load cu base address = 0 */
3172 OUTL(0, ioaddr + SCBPointer);
3173 // 32 bit linear addressing used
3174 OUTW(SCB_M | CU_ADDR_LOAD, ioaddr + SCBCmd);
3175 // wait for SCB command complete
3176 wait_for_cmd_done(ioaddr, WAIT_CU);
3178 // Check the malloc we did earlier worked
3179 ccs = (CFG *)mem_reserved_ioctl;
3180 if (ccs == (void*)0)
3184 WRITEMEM16(ccs + CFG_CMD,
3185 (CFG_CMD_EL | CFG_CMD_SUSPEND | CFG_CMD_MULTICAST));
3186 WRITEMEM16(ccs + CFG_STATUS, 0);
3187 WRITEMEM32(ccs + CFG_CB_LINK_OFFSET,
3188 HAL_CTOLE32(VIRT_TO_BUS((cyg_uint32)ccs)));
3190 count = 6 * num_addrs; // byte count
3192 WRITEMEM16(ccs + CFG_MC_LIST_BYTES,
3193 HAL_CTOLE16( count ) );
3195 config_bytes = ccs + CFG_MC_LIST_DATA;
3197 for ( i = 0; i < count; i++ )
3198 config_bytes[i] = address_list[i];
3200 // Let chip read configuration
3201 wait_for_cmd_done(ioaddr, WAIT_CU);
3203 OUTL(VIRT_TO_BUS(ccs), ioaddr + SCBPointer);
3204 OUTW(SCB_M | CU_START, ioaddr + SCBCmd);
3206 // ...and wait for it to complete operation
3210 READMEM16(ccs + CFG_STATUS, status);
3211 } while (0 == (status & CFG_STATUS_C) && (count-- > 0));
3214 if ((status & (CFG_STATUS_C | CFG_STATUS_OK))
3215 != (CFG_STATUS_C | CFG_STATUS_OK)) {
3218 os_printf("%s:%d Multicast setup failed\n", __FUNCTION__, __LINE__);
3223 wait_for_cmd_done(ioaddr, WAIT_CU);
3224 /* load pointer to Rx Ring */
3226 OUTL(VIRT_TO_BUS(p_i82559->rx_ring[0]), ioaddr + SCBPointer);
3227 OUTW(RUC_START, ioaddr + SCBCmd);
3231 #endif // ETH_DRV_SET_MC_ALL
3233 // ------------------------------------------------------------------------
3235 // Function : i82559_configure
3237 // Return : 0 = It worked.
3238 // non0 = It failed.
3239 // ------------------------------------------------------------------------
3241 static int i82559_configure(struct i82559* p_i82559, int promisc,
3242 int oversized, int multicast_all)
3246 volatile cyg_uint8* config_bytes;
3250 IF_BAD_82559( p_i82559 ) {
3252 os_printf( "eth_set_promiscuos_mode: Bad device pointer %x\n",
3258 ioaddr = p_i82559->io_address;
3259 wait_for_cmd_done(ioaddr, WAIT_CU);
3260 // load cu base address = 0 */
3261 OUTL(0, ioaddr + SCBPointer);
3262 // 32 bit linear addressing used
3263 OUTW(SCB_M | CU_ADDR_LOAD, ioaddr + SCBCmd);
3264 // wait for SCB command complete
3265 wait_for_cmd_done(ioaddr, WAIT_CU);
3267 // Check the malloc we did earlier worked
3268 ccs = (CFG *)mem_reserved_ioctl;
3269 if (ccs == (void*)0)
3273 WRITEMEM16(ccs + CFG_CMD,
3274 (CFG_CMD_EL | CFG_CMD_SUSPEND | CFG_CMD_CONFIGURE));
3275 WRITEMEM16(ccs + CFG_STATUS, 0);
3276 WRITEMEM32(ccs + CFG_CB_LINK_OFFSET,
3277 HAL_CTOLE32(VIRT_TO_BUS((cyg_uint32)ccs)));
3279 // Default values from the Intel Manual
3280 config_bytes = ccs + CFG_BYTES;
3282 config_bytes[0]= 22; // All 22 bytes
3283 config_bytes[1]=0xc;
3284 config_bytes[2]=0x0;
3285 config_bytes[3]=0x0;
3286 config_bytes[4]=0x0;
3287 config_bytes[5]=0x0;
3288 config_bytes[6]=0x32 | (promisc ? 0x80 : 0x00); // | 0x32 for small stats,
3289 config_bytes[7]=0x00 | (promisc ? 0x00 : 0x01); //\ | 0x12 for stats with PAUSE stats
3290 config_bytes[8]=0x01; // [7]:discard short frames \ | 0x16 for PAUSE + TCO stats
3291 config_bytes[9]=0x0;
3292 config_bytes[10]=0x28;
3293 config_bytes[11]=0x0;
3294 config_bytes[12]=0x60;
3295 config_bytes[13]=0x0; // arp
3296 config_bytes[14]=0x0; // arp
3298 config_bytes[15]=0x80 | (promisc ? 1 : 0); // 0x81: promiscuous mode set
3299 // 0x80: normal mode
3300 config_bytes[16]=0x0;
3301 config_bytes[17]=0x40;
3302 config_bytes[18]=0x72 | (oversized ? 8 : 0); // Keep the Padding Enable bit
3304 config_bytes[19]=0x80; // FDX pin enable is the default
3305 config_bytes[20]=0x3f; // the default
3306 config_bytes[21]=0x05 | (multicast_all ? 8 : 0); // Bit 3 is MultiCastALL enable
3308 // Let chip read configuration
3309 wait_for_cmd_done(ioaddr, WAIT_CU);
3311 OUTL(VIRT_TO_BUS(ccs), ioaddr + SCBPointer);
3312 OUTW(SCB_M | CU_START, ioaddr + SCBCmd);
3314 // ...and wait for it to complete operation
3318 READMEM16(ccs + CFG_STATUS, status);
3319 } while (0 == (status & CFG_STATUS_C) && (count-- > 0));
3322 if ((status & (CFG_STATUS_C | CFG_STATUS_OK))
3323 != (CFG_STATUS_C | CFG_STATUS_OK)) {
3326 os_printf("%s:%d Config update failed\n", __FUNCTION__, __LINE__);
3331 wait_for_cmd_done(ioaddr, WAIT_CU);
3332 /* load pointer to Rx Ring */
3334 OUTL(VIRT_TO_BUS(p_i82559->rx_ring[0]), ioaddr + SCBPointer);
3335 OUTW(RUC_START, ioaddr + SCBCmd);
3340 // ------------------------------------------------------------------------
3342 // The following table below doesn't really work with all cards.
3343 // The safest way to proceed is to do a read-modify-write of the
3344 // EEPROM contents rather than relying on a static table.
3346 #ifdef CYGPKG_DEVS_ETH_INTEL_I82559_WRITE_EEPROM
3347 // We use this as a templete when writing a new MAC address into the
3348 // eeproms. The MAC address in the first few bytes is over written
3349 // with the correct MAC address and then the whole lot is programmed
3350 // into the serial EEPROM. The checksum is calculated on the fly and
3351 // sent instead of the last two bytes.
3352 // The values are copied from the Intel EtherPro10/100+ &c devices
3353 // in the EBSA boards.
3354 static cyg_uint16 eeprom_burn[64] = {
3355 /* halfword addresses! */
3356 /* 0: */ 0x9000, 0x8c27, 0x8257, 0x0203,
3357 /* 4: */ 0x0000, 0x0201, 0x4701, 0x0000,
3358 /* 8: */ 0x7213, 0x8306, 0x40A2, 0x000c,
3359 /* C: */ 0x8086, 0x0000, 0x0000, 0x0000,
3360 /* 10: */ 0x0000, 0x0000, 0x0000, 0x0000,
3361 /* 14: */ 0x0000, 0x0000, 0x0000, 0x0000,
3362 /* 18: */ 0x0000, 0x0000, 0x0000, 0x0000,
3363 /* 1C: */ 0x0000, 0x0000, 0x0000, 0x0000,
3364 /* 20: */ 0x0000, 0x0000, 0x0000, 0x0000,
3365 /* 24: */ 0x0000, 0x0000, 0x0000, 0x0000,
3366 /* 28: */ 0x0000, 0x0000, 0x0000, 0x0000,
3367 /* 2C: */ 0x0000, 0x0000, 0x0000, 0x0000,
3368 /* 30: */ 0x0128, 0x0000, 0x0000, 0x0000,
3369 /* 34: */ 0x0000, 0x0000, 0x0000, 0x0000,
3370 /* 38: */ 0x0000, 0x0000, 0x0000, 0x0000,
3371 /* 3C: */ 0x0000, 0x0000, 0x0000, 0x0000,
3376 // ------------------------------------------------------------------------
3378 // Function : eth_set_mac_address
3380 // Return : 0 = It worked.
3381 // non0 = It failed.
3382 // ------------------------------------------------------------------------
3384 eth_set_mac_address(struct i82559* p_i82559, cyg_uint8 *addr, int eeprom)
3389 volatile cyg_uint8* config_bytes;
3392 IF_BAD_82559( p_i82559 ) {
3394 os_printf( "eth_set_mac_address : Bad device pointer %x\n",
3400 ioaddr = p_i82559->io_address;
3402 ccs = (CFG *)mem_reserved_ioctl;
3403 if (ccs == (void*)0)
3406 WRITEMEM16(ccs + CFG_CMD,
3407 (CFG_CMD_EL | CFG_CMD_SUSPEND | CFG_CMD_IAS));
3408 WRITEMEM16(ccs + CFG_STATUS, 0);
3409 WRITEMEM32(ccs + CFG_CB_LINK_OFFSET,
3410 HAL_CTOLE32(VIRT_TO_BUS((cyg_uint32)ccs)));
3412 config_bytes = ccs + CFG_BYTES;
3413 memcpy((char *)(config_bytes),addr,6);
3414 config_bytes[6]=0x0;
3415 config_bytes[7]=0x0;
3417 // Let chip read new ESA
3418 wait_for_cmd_done(ioaddr, WAIT_CU);
3419 OUTL(VIRT_TO_BUS(ccs), ioaddr + SCBPointer);
3420 OUTW(SCB_M | CU_START, ioaddr + SCBCmd);
3422 // ...and wait for it to complete operation
3425 READMEM16(ccs + CFG_STATUS, status);
3427 } while (0 == (status & CFG_STATUS_C) && (count-- > 0));
3430 READMEM16(ccs + CFG_STATUS, status);
3431 if ((status & (CFG_STATUS_C | CFG_STATUS_OK))
3432 != (CFG_STATUS_C | CFG_STATUS_OK)) {
3434 os_printf("%s:%d ESA update failed\n", __FUNCTION__, __LINE__);
3439 #ifdef CYGPKG_DEVS_ETH_INTEL_I82559_WRITE_EEPROM
3441 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_HAS_ONE_EEPROM
3442 || CYGHWR_DEVS_ETH_INTEL_I82559_HAS_ONE_EEPROM != p_i82559->index
3445 // record the MAC address in the device structure
3446 p_i82559->mac_address[0] = addr[0];
3447 p_i82559->mac_address[1] = addr[1];
3448 p_i82559->mac_address[2] = addr[2];
3449 p_i82559->mac_address[3] = addr[3];
3450 p_i82559->mac_address[4] = addr[4];
3451 p_i82559->mac_address[5] = addr[5];
3452 p_i82559->mac_addr_ok = 1;
3455 os_printf( "No EEPROM write: MAC Address = %02X %02X %02X %02X %02X %02X (ok %d)\n",
3456 p_i82559->mac_address[0],
3457 p_i82559->mac_address[1],
3458 p_i82559->mac_address[2],
3459 p_i82559->mac_address[3],
3460 p_i82559->mac_address[4],
3461 p_i82559->mac_address[5],
3462 p_i82559->mac_addr_ok );
3465 int checksum, i, count;
3466 // (this is the length of the *EEPROM*s address, not MAC address)
3468 cyg_uint16 eeprom_burn[64];
3470 addr_length = get_eeprom_size( ioaddr );
3472 for (i = 0; i < (1 << addr_length); i++)
3473 eeprom_burn[i] = read_eeprom( ioaddr, i, addr_length );
3475 // now set this address in the device eeprom ....
3476 eeprom_burn[0] = addr[0] | (addr[1] << 8);
3477 eeprom_burn[1] = addr[2] | (addr[3] << 8);
3478 eeprom_burn[2] = addr[4] | (addr[5] << 8);
3480 // No idea what these were for...
3481 // eeprom_burn[20] &= 0xfe;
3482 // eeprom_burn[20] |= p_i82559->index;
3484 program_eeprom( ioaddr, addr_length, eeprom_burn );
3486 // update 82559 driver data structure ...
3489 // by reading EEPROM to get the mac address back
3490 for (checksum = 0, i = 0, count = 0; count < (1 << addr_length); count++) {
3492 // read word from eeprom
3493 value = read_eeprom(ioaddr, count, addr_length);
3496 p_i82559->mac_address[i++] = value & 0xFF;
3497 p_i82559->mac_address[i++] = (value >> 8) & 0xFF;
3502 os_printf("eth_set_mac_address[WRITE_EEPROM]: MAC Address = %02X %02X %02X %02X %02X %02X\n",
3503 p_i82559->mac_address[0], p_i82559->mac_address[1],
3504 p_i82559->mac_address[2], p_i82559->mac_address[3],
3505 p_i82559->mac_address[4], p_i82559->mac_address[5]);
3508 p_i82559->mac_addr_ok = 1;
3510 for ( i = 0, count = 0; i < 6; i++ )
3511 if ( p_i82559->mac_address[i] != addr[i] )
3516 os_printf( "Warning: MAC Address read back wrong! %d bytes differ.\n",
3519 p_i82559->mac_addr_ok = 0;
3522 // If the EEPROM checksum is wrong, the MAC address read from
3523 // the EEPROM is probably wrong as well. In that case, we
3524 // don't set mac_addr_ok.
3525 if ((checksum & 0xFFFF) != 0xBABA) {
3527 os_printf( "Warning: Invalid EEPROM checksum %04X for device %d\n",
3528 checksum, p_i82559->index);
3530 p_i82559->mac_addr_ok = 0;
3533 #else // CYGPKG_DEVS_ETH_INTEL_I82559_WRITE_EEPROM
3535 // record the MAC address in the device structure
3536 p_i82559->mac_address[0] = addr[0];
3537 p_i82559->mac_address[1] = addr[1];
3538 p_i82559->mac_address[2] = addr[2];
3539 p_i82559->mac_address[3] = addr[3];
3540 p_i82559->mac_address[4] = addr[4];
3541 p_i82559->mac_address[5] = addr[5];
3542 p_i82559->mac_addr_ok = 1;
3545 os_printf( "Set MAC Address = %02X %02X %02X %02X %02X %02X (ok %d)\n",
3546 p_i82559->mac_address[0],
3547 p_i82559->mac_address[1],
3548 p_i82559->mac_address[2],
3549 p_i82559->mac_address[3],
3550 p_i82559->mac_address[4],
3551 p_i82559->mac_address[5],
3552 p_i82559->mac_addr_ok );
3555 #endif // ! CYGPKG_DEVS_ETH_INTEL_I82559_WRITE_EEPROM
3557 return p_i82559->mac_addr_ok ? 0 : 1;
3560 #ifdef CYGPKG_DEVS_ETH_INTEL_I82559_WRITE_EEPROM
3561 // ------------------------------------------------------------------------
3563 write_eeprom(long ioaddr, int location, int addr_len, unsigned short value)
3565 int ee_addr = ioaddr + SCBeeprom;
3566 int write_cmd = location | EE_WRITE_CMD(addr_len);
3569 OUTW(EE_ENB & ~EE_CS, ee_addr);
3570 eeprom_delay( 100 );
3571 OUTW(EE_ENB, ee_addr);
3572 eeprom_delay( 100 );
3574 // os_printf("\n write_eeprom : write_cmd : %x",write_cmd);
3575 // os_printf("\n addr_len : %x value : %x ",addr_len,value);
3577 /* Shift the write command bits out. */
3578 for (i = (addr_len+2); i >= 0; i--) {
3579 short dataval = (write_cmd & (1 << i)) ? EE_DATA_WRITE : 0;
3580 OUTW(EE_ENB | dataval, ee_addr);
3582 OUTW(EE_ENB | dataval | EE_SHIFT_CLK, ee_addr);
3585 OUTW(EE_ENB, ee_addr);
3587 for (i = 15; i >= 0; i--) {
3588 short dataval = (value & (1 << i)) ? EE_DATA_WRITE : 0;
3589 OUTW(EE_ENB | dataval, ee_addr);
3591 OUTW(EE_ENB | dataval | EE_SHIFT_CLK, ee_addr);
3595 /* Terminate the EEPROM access. */
3596 OUTW(EE_ENB & ~EE_CS, ee_addr);
3597 eeprom_delay(150000); // let the write take effect
3600 // ------------------------------------------------------------------------
3602 write_enable_eeprom(long ioaddr, int addr_len)
3604 int ee_addr = ioaddr + SCBeeprom;
3605 int write_en_cmd = EE_WRITE_EN_CMD(addr_len);
3608 OUTW(EE_ENB & ~EE_CS, ee_addr);
3609 OUTW(EE_ENB, ee_addr);
3612 os_printf("write_en_cmd : %x",write_en_cmd);
3615 // Shift the wr/er enable command bits out.
3616 for (i = (addr_len+2); i >= 0; i--) {
3617 short dataval = (write_en_cmd & (1 << i)) ? EE_DATA_WRITE : 0;
3618 OUTW(EE_ENB | dataval, ee_addr);
3620 OUTW(EE_ENB | dataval | EE_SHIFT_CLK, ee_addr);
3624 // Terminate the EEPROM access.
3625 OUTW(EE_ENB & ~EE_CS, ee_addr);
3626 eeprom_delay(EEPROM_DONE_DELAY);
3630 // ------------------------------------------------------------------------
3632 program_eeprom(cyg_uint32 ioaddr, cyg_uint32 eeprom_size, cyg_uint8 *data)
3635 cyg_uint16 checksum = 0;
3638 // First enable erase/write operations on the eeprom.
3639 // This is done through the EWEN instruction.
3640 write_enable_eeprom( ioaddr, eeprom_size );
3642 for (i=0 ; i< (1 << eeprom_size) ; i++) {
3643 value = ((unsigned short *)data)[i];
3646 os_printf("\n i : %x ... value to be written : %x",i,value);
3648 write_eeprom( ioaddr, i, eeprom_size, value);
3650 os_printf("\n val read : %x ",read_eeprom(ioaddr,i,eeprom_size));
3653 value = 0xBABA - checksum;
3655 os_printf("\n i : %x ... checksum adjustment val to be written : %x",i,value);
3657 write_eeprom( ioaddr, i, eeprom_size, value );
3660 // ------------------------------------------------------------------------
3661 #endif // ! CYGPKG_DEVS_ETH_INTEL_I82559_WRITE_EEPROM
3664 // ------------------------------------------------------------------------
3666 // Function : eth_get_mac_address
3668 // ------------------------------------------------------------------------
3669 #ifdef ETH_DRV_GET_MAC_ADDRESS
3671 eth_get_mac_address(struct i82559* p_i82559, char *addr)
3673 IF_BAD_82559( p_i82559 ) {
3675 os_printf( "eth_get_mac_address : Bad device pointer %x\n",
3681 memcpy( addr, (char *)(&p_i82559->mac_address[0]), 6 );
3685 // ------------------------------------------------------------------------
3687 // Function : i82559_ioctl
3689 // ------------------------------------------------------------------------
3691 i82559_ioctl(struct eth_drv_sc *sc, unsigned long key,
3692 void *data, int data_length)
3694 struct i82559 *p_i82559;
3696 p_i82559 = (struct i82559 *)sc->driver_private;
3698 IF_BAD_82559( p_i82559 ) {
3700 os_printf( "i82559_ioctl/control: Bad device pointer %x\n", p_i82559 );
3706 db_printf( "i82559_ioctl: device eth%d at %x; key is 0x%x, data at %x[%d]\n",
3707 p_i82559->index, p_i82559, key, data, data_length );
3712 #ifdef ETH_DRV_SET_MAC_ADDRESS
3713 case ETH_DRV_SET_MAC_ADDRESS:
3714 if ( 6 != data_length )
3716 return eth_set_mac_address( p_i82559, data, 1 /* do write eeprom */ );
3719 #ifdef ETH_DRV_GET_MAC_ADDRESS
3720 case ETH_DRV_GET_MAC_ADDRESS:
3721 return eth_get_mac_address( p_i82559, data );
3724 #ifdef ETH_DRV_GET_IF_STATS_UD
3725 case ETH_DRV_GET_IF_STATS_UD: // UD == UPDATE
3726 ETH_STATS_INIT( sc ); // so UPDATE the statistics structure
3729 #ifdef ETH_DRV_GET_IF_STATS
3730 case ETH_DRV_GET_IF_STATS:
3732 #if defined(ETH_DRV_GET_IF_STATS) || defined (ETH_DRV_GET_IF_STATS_UD)
3734 struct ether_drv_stats *p = (struct ether_drv_stats *)data;
3736 static unsigned char my_chipset[]
3737 = { ETH_DEV_DOT3STATSETHERCHIPSET };
3739 strcpy( p->description, CYGDAT_DEVS_ETH_DESCRIPTION );
3740 CYG_ASSERT( 48 > strlen(p->description), "Description too long" );
3742 for ( i = 0; i < SNMP_CHIPSET_LEN; i++ )
3743 if ( 0 == (p->snmp_chipset[i] = my_chipset[i]) )
3746 i = i82559_status( sc );
3748 if ( !( i & GEN_STATUS_LINK) ) {
3749 p->operational = 2; // LINK DOWN
3750 p->duplex = 1; // UNKNOWN
3754 p->operational = 3; // LINK UP
3755 p->duplex = (i & GEN_STATUS_FDX) ? 3 : 2; // 2 = SIMPLEX, 3 = DUPLEX
3756 p->speed = ((i & GEN_STATUS_100MBPS) ? 100 : 10) * 1000000;
3759 #ifdef KEEP_STATISTICS
3761 I82559_COUNTERS *pc = &i82559_counters[ p_i82559->index ];
3762 STATISTICS *ps = &statistics[ p_i82559->index ];
3765 p->supports_dot3 = true;
3767 // Those commented out are not available on this chip.
3769 p->tx_good = pc->tx_good ;
3770 p->tx_max_collisions = pc->tx_max_collisions ;
3771 p->tx_late_collisions = pc->tx_late_collisions ;
3772 p->tx_underrun = pc->tx_underrun ;
3773 p->tx_carrier_loss = pc->tx_carrier_loss ;
3774 p->tx_deferred = pc->tx_deferred ;
3775 //p->tx_sqetesterrors = pc->tx_sqetesterrors ;
3776 p->tx_single_collisions = pc->tx_single_collisions;
3777 p->tx_mult_collisions = pc->tx_mult_collisions ;
3778 p->tx_total_collisions = pc->tx_total_collisions ;
3779 p->rx_good = pc->rx_good ;
3780 p->rx_crc_errors = pc->rx_crc_errors ;
3781 p->rx_align_errors = pc->rx_align_errors ;
3782 p->rx_resource_errors = pc->rx_resource_errors ;
3783 p->rx_overrun_errors = pc->rx_overrun_errors ;
3784 p->rx_collisions = pc->rx_collisions ;
3785 p->rx_short_frames = pc->rx_short_frames ;
3786 //p->rx_too_long_frames = pc->rx_too_long_frames ;
3787 //p->rx_symbol_errors = pc->rx_symbol_errors ;
3789 p->interrupts = ps->interrupts ;
3790 p->rx_count = ps->rx_count ;
3791 p->rx_deliver = ps->rx_deliver ;
3792 p->rx_resource = ps->rx_resource ;
3793 p->rx_restart = ps->rx_restart ;
3794 p->tx_count = ps->tx_count ;
3795 p->tx_complete = ps->tx_complete ;
3796 p->tx_dropped = ps->tx_dropped ;
3798 #endif // KEEP_STATISTICS
3800 p->tx_queue_len = MAX_TX_DESCRIPTORS;
3806 #ifdef ETH_DRV_SET_MC_LIST
3807 case ETH_DRV_SET_MC_LIST: {
3808 struct eth_drv_mc_list *mcl = (struct eth_drv_mc_list *)data;
3810 i82559_reset(p_i82559);
3811 ResetRxRing( p_i82559 );
3812 ResetTxRing( p_i82559 );
3814 p_i82559->multicast_all = 0;
3816 i82559_configure(p_i82559,
3818 p_i82559->oversized,
3819 p_i82559->multicast_all );
3821 i82559_set_multicast( p_i82559,
3823 &(mcl->addrs[0][0]) );
3825 i82559_restart(p_i82559);
3828 #endif // ETH_DRV_SET_MC_LIST
3830 #ifdef ETH_DRV_SET_MC_ALL
3831 case ETH_DRV_SET_MC_ALL:
3832 i82559_reset(p_i82559);
3833 ResetRxRing( p_i82559 );
3834 ResetTxRing( p_i82559 );
3836 p_i82559->multicast_all = 1;
3838 i82559_configure(p_i82559,
3840 p_i82559->oversized,
3841 p_i82559->multicast_all );
3843 i82559_restart(p_i82559);
3845 #endif // ETH_DRV_SET_MC_ALL
3853 // ------------------------------------------------------------------------
3855 // Statistics update...
3857 // ------------------------------------------------------------------------
3859 #ifdef KEEP_STATISTICS
3860 #ifdef CYGDBG_DEVS_ETH_INTEL_I82559_KEEP_82559_STATISTICS
3862 update_statistics(struct i82559* p_i82559)
3864 I82559_COUNTERS *p_statistics;
3865 cyg_uint32 *p_counter;
3866 cyg_uint32 *p_register;
3867 int reg_count, ints;
3868 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_DEMUX_ALL
3869 struct i82559* op_i82559 = p_i82559;
3872 ints = Mask82559Interrupt(p_i82559);
3874 // This points to the shared memory stats area/command block
3875 p_statistics = (I82559_COUNTERS *)(p_i82559->p_statistics);
3877 if ( (p_statistics->done & 0xFFFF) == 0xA007 ) {
3878 p_counter = (cyg_uint32 *)&i82559_counters[ p_i82559->index ];
3879 p_register = (cyg_uint32 *)p_statistics;
3880 for ( reg_count = 0;
3881 reg_count < sizeof( I82559_COUNTERS ) / sizeof( cyg_uint32 ) - 1;
3883 *p_counter += *p_register;
3887 p_statistics->done = 0;
3888 // start register dump
3889 wait_for_cmd_done(p_i82559->io_address, WAIT_CU);
3890 OUTW(CU_DUMPSTATS, p_i82559->io_address + SCBCmd);
3893 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_DEMUX_ALL
3896 // The problem is, if DEMUX_ALL, either device can eat the other's
3897 // interrupts; so we must poll them *both*:
3898 for (i = 0; i < CYGNUM_DEVS_ETH_INTEL_I82559_DEV_COUNT; i++) {
3899 p_i82559 = i82559_priv_array[i];
3900 if ( p_i82559->active ) {
3901 // See if the Tx machine is wedged - reset if so:
3902 Check82559TxLockupTimeout(p_i82559);
3903 TxMachine(p_i82559);
3904 Acknowledge82559Interrupt(p_i82559);
3905 PacketRxReady(p_i82559);
3906 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_MISSED_INTERRUPT
3907 if ( CYGHWR_DEVS_ETH_INTEL_I82559_MISSED_INTERRUPT(p_i82559) ) {
3908 #ifdef CYGDBG_USE_ASSERTS
3909 missed_interrupt.stats++;
3911 eth_isr( p_i82559->vector, (cyg_addrword_t)p_i82559 );
3912 eth_dsr( p_i82559->vector, 1, (cyg_addrword_t)p_i82559 );
3918 // ensure we look at the correct device at the end
3919 p_i82559 = op_i82559;
3920 #else // no CYGHWR_DEVS_ETH_INTEL_I82559_DEMUX_ALL
3921 // See if the Tx machine is wedged - reset if so:
3922 Check82559TxLockupTimeout(p_i82559);
3923 TxMachine(p_i82559);
3924 Acknowledge82559Interrupt(p_i82559); // This can eat an Rx interrupt, so
3925 PacketRxReady(p_i82559);
3926 #ifdef CYGHWR_DEVS_ETH_INTEL_I82559_MISSED_INTERRUPT
3927 if ( CYGHWR_DEVS_ETH_INTEL_I82559_MISSED_INTERRUPT(p_i82559) ) {
3928 #ifdef CYGDBG_USE_ASSERTS
3929 missed_interrupt.stats++;
3931 eth_isr( p_i82559->vector, (cyg_addrword_t)p_i82559 );
3932 eth_dsr( p_i82559->vector, 1, (cyg_addrword_t)p_i82559 );
3935 #endif // no CYGHWR_DEVS_ETH_INTEL_I82559_DEMUX_ALL
3937 UnMask82559Interrupt(p_i82559, ints);
3940 #endif // KEEP_STATISTICS
3942 // ------------------------------------------------------------------------