ia64/xen-unstable

changeset 139:2f78322be16a

bitkeeper revision 1.22.1.11 (3e48f52fRxNrVg2Tsq7Qa1P9cXmCeA)

Merge with main repository.
author akw27@boulderdash.cl.cam.ac.uk
date Tue Feb 11 13:05:51 2003 +0000 (2003-02-11)
parents 4a4ae256b9b5 4c6ae683ed61
children 9d397996348f
files .rootkeys xen-2.4.16/Makefile xen-2.4.16/Rules.mk xen-2.4.16/arch/i386/Rules.mk xen-2.4.16/arch/i386/apic.c xen-2.4.16/arch/i386/entry.S xen-2.4.16/arch/i386/i8259.c xen-2.4.16/arch/i386/io_apic.c xen-2.4.16/arch/i386/ioremap.c xen-2.4.16/arch/i386/process.c xen-2.4.16/arch/i386/smpboot.c xen-2.4.16/arch/i386/traps.c xen-2.4.16/common/dom0_ops.c xen-2.4.16/common/domain.c xen-2.4.16/common/kernel.c xen-2.4.16/common/memory.c xen-2.4.16/drivers/net/Makefile xen-2.4.16/drivers/net/e1000/LICENSE xen-2.4.16/drivers/net/e1000/Makefile xen-2.4.16/drivers/net/e1000/e1000.h xen-2.4.16/drivers/net/e1000/e1000_ethtool.c xen-2.4.16/drivers/net/e1000/e1000_hw.c xen-2.4.16/drivers/net/e1000/e1000_hw.h xen-2.4.16/drivers/net/e1000/e1000_main.c xen-2.4.16/drivers/net/e1000/e1000_osdep.h xen-2.4.16/drivers/net/e1000/e1000_param.c xen-2.4.16/drivers/net/ne/8390.c xen-2.4.16/drivers/net/ne/8390.h xen-2.4.16/drivers/net/ne/Makefile xen-2.4.16/drivers/net/ne/ne.c xen-2.4.16/drivers/net/tg3.c xen-2.4.16/drivers/net/tg3.h xen-2.4.16/drivers/pci/Makefile xen-2.4.16/drivers/pci/pci.c xen-2.4.16/include/asm-i386/irq.h xen-2.4.16/include/asm-i386/param.h xen-2.4.16/include/asm-i386/pci.h xen-2.4.16/include/asm-i386/processor.h xen-2.4.16/include/asm-i386/timex.h xen-2.4.16/include/asm-i386/uaccess.h xen-2.4.16/include/hypervisor-ifs/hypervisor-if.h xen-2.4.16/include/stdarg.h xen-2.4.16/include/xeno/config.h xen-2.4.16/include/xeno/ethtool.h xen-2.4.16/include/xeno/if_vlan.h xen-2.4.16/include/xeno/in.h xen-2.4.16/include/xeno/kernel.h xen-2.4.16/include/xeno/mm.h xen-2.4.16/include/xeno/netdevice.h xen-2.4.16/include/xeno/notifier.h xen-2.4.16/include/xeno/pci.h xen-2.4.16/include/xeno/pci_ids.h xen-2.4.16/include/xeno/reboot.h xen-2.4.16/include/xeno/sched.h xen-2.4.16/include/xeno/types.h xenolinux-2.4.16-sparse/arch/xeno/kernel/traps.c xenolinux-2.4.16-sparse/fs/nfs/nfsroot.c xenolinux-2.4.16-sparse/include/asm-xeno/hypervisor.h
line diff
     1.1 --- a/.rootkeys	Tue Feb 11 13:04:09 2003 +0000
     1.2 +++ b/.rootkeys	Tue Feb 11 13:05:51 2003 +0000
     1.3 @@ -71,10 +71,25 @@ 3ddb79bfMlOcWUwjtg6oMYhGySHDDw xen-2.4.1
     1.4  3ddb79bfl_DWxZQFKiJ2BXrSedV4lg xen-2.4.16/drivers/net/8139cp.c
     1.5  3ddb79c0tWiE8xIFHszxipeVCGKTSA xen-2.4.16/drivers/net/Makefile
     1.6  3ddb79bfU-H1Hms4BuJEPPydjXUEaQ xen-2.4.16/drivers/net/Space.c
     1.7 +3e4540ccS4bfbx9rLiLElP0F1OVwZA xen-2.4.16/drivers/net/e1000/LICENSE
     1.8 +3e4540ccXG6af_6-u0IiKKvtdGHJyA xen-2.4.16/drivers/net/e1000/Makefile
     1.9 +3e4540ccoY2eo4VIkbR4sCOj0bVzSA xen-2.4.16/drivers/net/e1000/e1000.h
    1.10 +3e4540ccvUz0j2ejQ9Z9djEGc93wRA xen-2.4.16/drivers/net/e1000/e1000_ethtool.c
    1.11 +3e4540ccjqsc94nU3C4w3ZJaxFZFjA xen-2.4.16/drivers/net/e1000/e1000_hw.c
    1.12 +3e4540cczrrQVyyj-s1-viyX1kMUlA xen-2.4.16/drivers/net/e1000/e1000_hw.h
    1.13 +3e4540ccvQ9Dtoh9tV-L3ULUwN9X7g xen-2.4.16/drivers/net/e1000/e1000_main.c
    1.14 +3e4540cc3t7_y-YLeyMG2pX9xtdXPA xen-2.4.16/drivers/net/e1000/e1000_osdep.h
    1.15 +3e4540cct_8Ig-Y1W_vM2gS_u7mC0A xen-2.4.16/drivers/net/e1000/e1000_param.c
    1.16  3ddb79c0GejJrp1U6W4G6dYi-RiH4A xen-2.4.16/drivers/net/eepro100.c
    1.17 +3e465c00t2nochqR27eEY_FBjxsUCw xen-2.4.16/drivers/net/ne/8390.c
    1.18 +3e465c00AIRmk20x1vYETtnL71eGvA xen-2.4.16/drivers/net/ne/8390.h
    1.19 +3e465c00UIvPTAtAcgcQWCVFa2bwww xen-2.4.16/drivers/net/ne/Makefile
    1.20 +3e465c00rWSHiXmHuOWLRf7r2n8S3g xen-2.4.16/drivers/net/ne/ne.c
    1.21  3ddb79bfKvn9mt0kofpkw0QaWjxO6A xen-2.4.16/drivers/net/net_init.c
    1.22  3ddb79c0fQgORkFlqWZdP-6cDHyFIQ xen-2.4.16/drivers/net/pcnet32.c
    1.23  3ddb79bf_CBcu3QWYwq4bNAOnM2RqQ xen-2.4.16/drivers/net/setup.c
    1.24 +3e45a0c6u66EL2AI36eLOmf_abXs7g xen-2.4.16/drivers/net/tg3.c
    1.25 +3e45a0c6yrXj5pmQT0PvVSJ01YLABQ xen-2.4.16/drivers/net/tg3.h
    1.26  3ddb79bfh8ucmq_HqRSaURalpeAmPg xen-2.4.16/drivers/net/tulip/.depend
    1.27  3ddb79bfsJ-hdQ17EXTFiUOHisjNgQ xen-2.4.16/drivers/net/tulip/21142.c
    1.28  3ddb79bf0lzTL-ywAdOO7vctTYAmJA xen-2.4.16/drivers/net/tulip/ChangeLog
    1.29 @@ -146,6 +161,7 @@ 3ddb79c3I98vWcQR8xEo34JMJ4Ahyw xen-2.4.1
    1.30  3ddb79c3n_UbPuxlkNxvvLycClIkxA xen-2.4.16/include/asm-i386/mpspec.h
    1.31  3ddb79c2wa0dA_LGigxOelSGbJ284Q xen-2.4.16/include/asm-i386/msr.h
    1.32  3ddb79c3xjYnrv5t3VqYlR4tNEOl4Q xen-2.4.16/include/asm-i386/page.h
    1.33 +3e450943kzme29HPCtq5HNOVQkddfw xen-2.4.16/include/asm-i386/param.h
    1.34  3ddb79c3ysKUbxZuwKBRK3WXU2TlEg xen-2.4.16/include/asm-i386/pci.h
    1.35  3ddb79c3nm2zdzeO6Mj8g7ex3txgGw xen-2.4.16/include/asm-i386/pgalloc.h
    1.36  3ddb79c2QF5-pZGzuX4QukPCDAl59A xen-2.4.16/include/asm-i386/processor.h
    1.37 @@ -157,6 +173,7 @@ 3ddb79c3jn8ALV_S9W5aeTYUQRKBpg xen-2.4.1
    1.38  3ddb79c3e9DCEoR-WzNxcOQDzLu7BQ xen-2.4.16/include/asm-i386/softirq.h
    1.39  3ddb79c3NiyQE2vQnyGiaBnNjBO1rA xen-2.4.16/include/asm-i386/spinlock.h
    1.40  3ddb79c3ezddh34MdelJpa5tNR00Dw xen-2.4.16/include/asm-i386/system.h
    1.41 +3e450943TfE-iovQIY_tMO_VdGsPhA xen-2.4.16/include/asm-i386/timex.h
    1.42  3ddb79c4HugMq7IYGxcQKFBpKwKhzA xen-2.4.16/include/asm-i386/types.h
    1.43  3ddb79c3M2n1ROZH6xk3HbyN4CPDqg xen-2.4.16/include/asm-i386/uaccess.h
    1.44  3ddb79c3uPGcP_l_2xyGgBSWd5aC-Q xen-2.4.16/include/asm-i386/unaligned.h
    1.45 @@ -167,6 +184,7 @@ 3ddb79c4qbCoOFHrv9sCGshbWzBVlQ xen-2.4.1
    1.46  3ddb79c4R4iVwqIIeychVQYmIH4FUg xen-2.4.16/include/scsi/scsi_ioctl.h
    1.47  3ddb79c4yw_mfd4Uikn3v_IOPRpa1Q xen-2.4.16/include/scsi/scsicam.h
    1.48  3ddb79c4HKPMLvDBP9LxzPi_szVxGA xen-2.4.16/include/scsi/sg.h
    1.49 +3e450943xQztorJxTGW3BPZ4LhRHbw xen-2.4.16/include/stdarg.h
    1.50  3ddb79c0nTsjSpVK4ZVTI9WwN24xtQ xen-2.4.16/include/xeno/blk.h
    1.51  3ddb79c0dVhTHLsv6CPTf4baKix4mA xen-2.4.16/include/xeno/blkdev.h
    1.52  3ddb79c18ePBgitnOs7GiOCFilODVw xen-2.4.16/include/xeno/blkpg.h
    1.53 @@ -195,6 +213,7 @@ 3ddb79c0MM575N4YvMSiw9EqKH4JDA xen-2.4.1
    1.54  3ddb79c1yHLp08JhgPxIMcZ8DwN9hg xen-2.4.16/include/xeno/if.h
    1.55  3ddb79c1RCWOkWPQRzbYVTX_e-E7CA xen-2.4.16/include/xeno/if_ether.h
    1.56  3ddb79c2IYah7z7hkzPyOiG8szKkyw xen-2.4.16/include/xeno/if_packet.h
    1.57 +3e4540ccefnCkeqtD_dW_CBOjXUSYw xen-2.4.16/include/xeno/if_vlan.h
    1.58  3df0af1c-QrOEqpPHq4uL3NZzCeJCg xen-2.4.16/include/xeno/in.h
    1.59  3ddb79c0GurNF9tDWqQbAwJFH8ugfA xen-2.4.16/include/xeno/init.h
    1.60  3ddb79c1Vi5VleJAOKHAlY0G2zAsgw xen-2.4.16/include/xeno/interrupt.h
    1.61 @@ -203,6 +222,7 @@ 3ddb79c1nzaWu8NoF4xCCMSFJR4MlA xen-2.4.1
    1.62  3ddb79c2qAxCOABlkKtD8Txohe-qEw xen-2.4.16/include/xeno/irq.h
    1.63  3ddb79c2b3qe-6Ann09FqZBF4IrJaQ xen-2.4.16/include/xeno/irq_cpustat.h
    1.64  3ddb79c11w_O7z7YZJnzuDSxaK5LlA xen-2.4.16/include/xeno/kdev_t.h
    1.65 +3e4540ccPHqIIv2pvnQ1gV8LUnoHIg xen-2.4.16/include/xeno/kernel.h
    1.66  3ddb79c1NfYlOrWNqgZkj9EwtFfJow xen-2.4.16/include/xeno/lib.h
    1.67  3ddb79c18Ajy7micDGQQfJ0zWgEHtA xen-2.4.16/include/xeno/list.h
    1.68  3ddb79c0_s2_wgV0cA6tztEaeyy1NA xen-2.4.16/include/xeno/major.h
    1.69 @@ -211,10 +231,12 @@ 3ddb79c1gs2VbLbQlw0dcDUXYIepDA xen-2.4.1
    1.70  3ddb79c13p9iHn1XAp0IS1qvj4yDsg xen-2.4.16/include/xeno/module.h
    1.71  3ddb79c1ieLZfGSFwfvvSQ2NK1BMSg xen-2.4.16/include/xeno/multiboot.h
    1.72  3ddb79c0CLfAlJLg1ohdPD-Jjn-jxg xen-2.4.16/include/xeno/netdevice.h
    1.73 +3e4540ccaugeWGdOuphJKj6WFw1jkw xen-2.4.16/include/xeno/notifier.h
    1.74  3ddb79c2Fg44_PBPVxHSC0gTOMq4Ow xen-2.4.16/include/xeno/pci.h
    1.75  3ddb79c0MOVXq8qZDQRGb6z64_xAwg xen-2.4.16/include/xeno/pci_ids.h
    1.76  3ddb79c2byJwwNNkiES__A9H4Cvc4g xen-2.4.16/include/xeno/pkt_sched.h
    1.77  3ddb79c04nQVR3EYM5L4zxDV_MCo1g xen-2.4.16/include/xeno/prefetch.h
    1.78 +3e4540ccU1sgCx8seIMGlahmMfv7yQ xen-2.4.16/include/xeno/reboot.h
    1.79  3ddb79c0LzqqS0LhAQ50ekgj4oGl7Q xen-2.4.16/include/xeno/sched.h
    1.80  3ddb79c0VDeD-Oft5eNfMneTU3D1dQ xen-2.4.16/include/xeno/skbuff.h
    1.81  3ddb79c14dXIhP7C2ahnoD08K90G_w xen-2.4.16/include/xeno/slab.h
    1.82 @@ -294,7 +316,6 @@ 3ddb79bbx682YH6vR2zbVOXwg73ULg xenolinux
    1.83  3ddb79bcJfHdwrPsjqgI33_OsGdVCg xenolinux-2.4.16-sparse/drivers/block/rd.c
    1.84  3ddb79bcpVu-IbnqwQqpRqsEbLpsuw xenolinux-2.4.16-sparse/drivers/char/tty_io.c
    1.85  3e15d5273gfR2fbcYe05kqBSAvCX_w xenolinux-2.4.16-sparse/fs/exec.c
    1.86 -3ddb79bba_zKpuurHVeWfgDkyPoq8A xenolinux-2.4.16-sparse/fs/nfs/nfsroot.c
    1.87  3ddb79b8VFtfWSCrXKPN2K21zd_vtw xenolinux-2.4.16-sparse/include/asm-xeno/a.out.h
    1.88  3ddb79b8Zzi13p3OAPV25QgiC3THAQ xenolinux-2.4.16-sparse/include/asm-xeno/apic.h
    1.89  3ddb79baZDlsdV_m6C5CXnWMl15p1g xenolinux-2.4.16-sparse/include/asm-xeno/apicdef.h
     2.1 --- a/xen-2.4.16/Makefile	Tue Feb 11 13:04:09 2003 +0000
     2.2 +++ b/xen-2.4.16/Makefile	Tue Feb 11 13:05:51 2003 +0000
     2.3 @@ -5,6 +5,7 @@ include Rules.mk
     2.4  
     2.5  default: $(TARGET)
     2.6  	gzip -f -9 < $(TARGET) > $(TARGET).gz
     2.7 +#	objdump -D -S image >image.s
     2.8  
     2.9  install: $(TARGET)
    2.10  	gzip -f -9 < $(TARGET) > $(TARGET).gz
     3.1 --- a/xen-2.4.16/Rules.mk	Tue Feb 11 13:04:09 2003 +0000
     3.2 +++ b/xen-2.4.16/Rules.mk	Tue Feb 11 13:05:51 2003 +0000
     3.3 @@ -21,10 +21,13 @@ ALL_OBJS += $(BASEDIR)/drivers/block/dri
     3.4  ALL_OBJS += $(BASEDIR)/drivers/ide/driver.o
     3.5  ALL_OBJS += $(BASEDIR)/arch/$(ARCH)/arch.o
     3.6  
     3.7 +HOSTCC     = gcc
     3.8 +HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer 
     3.9 +
    3.10  include $(BASEDIR)/arch/$(ARCH)/Rules.mk
    3.11  
    3.12  %.o: %.c $(HDRS) Makefile
    3.13 -	$(CC) $(CFLAGS) -c $< -o $@
    3.14 +	$(CC) -g $(CFLAGS) -c $< -o $@
    3.15  
    3.16  %.o: %.S $(HDRS) Makefile
    3.17  	$(CC) $(CFLAGS) -D__ASSEMBLY__ -c $< -o $@
     4.1 --- a/xen-2.4.16/arch/i386/Rules.mk	Tue Feb 11 13:04:09 2003 +0000
     4.2 +++ b/xen-2.4.16/arch/i386/Rules.mk	Tue Feb 11 13:05:51 2003 +0000
     4.3 @@ -7,8 +7,8 @@ LD := ld
     4.4  MONITOR_BASE := 0xFC500000
     4.5  # Bootloader should load monitor to this real address
     4.6  LOAD_BASE    := 0x00100000
     4.7 -CFLAGS  := -fno-builtin -O3 -Wall -DMONITOR_BASE=$(MONITOR_BASE) 
     4.8 -CFLAGS  += -I$(BASEDIR)/include -D__KERNEL__ -DNDEBUG
     4.9 +CFLAGS  := -nostdinc -fno-builtin -O3 -Wall -DMONITOR_BASE=$(MONITOR_BASE) 
    4.10 +CFLAGS  += -fomit-frame-pointer -I$(BASEDIR)/include -D__KERNEL__ -DNDEBUG
    4.11  LDFLAGS := -T xeno.lds -N
    4.12  
    4.13  
     5.1 --- a/xen-2.4.16/arch/i386/apic.c	Tue Feb 11 13:04:09 2003 +0000
     5.2 +++ b/xen-2.4.16/arch/i386/apic.c	Tue Feb 11 13:05:51 2003 +0000
     5.3 @@ -200,45 +200,16 @@ void __init sync_Arb_IDs(void)
     5.4  extern void __error_in_apic_c (void);
     5.5  
     5.6  /*
     5.7 - * An initial setup of the virtual wire mode.
     5.8 + * WAS: An initial setup of the virtual wire mode.
     5.9 + * NOW: We don't bother doing anything. All we need at this point
    5.10 + * is to receive timer ticks, so that 'jiffies' is incremented.
    5.11 + * If we're SMP, then we can assume BIOS did setup for us.
    5.12 + * If we're UP, then the APIC should be disabled (it is at reset).
    5.13 + * If we're UP and APIC is enabled, then BIOS is clever and has 
    5.14 + * probably done initial interrupt routing for us.
    5.15   */
    5.16  void __init init_bsp_APIC(void)
    5.17  {
    5.18 -    unsigned long value, ver;
    5.19 -
    5.20 -    /*
    5.21 -     * Don't do the setup now if we have a SMP BIOS as the
    5.22 -     * through-I/O-APIC virtual wire mode might be active.
    5.23 -     */
    5.24 -    if (smp_found_config || !cpu_has_apic)
    5.25 -        return;
    5.26 -
    5.27 -    value = apic_read(APIC_LVR);
    5.28 -    ver = GET_APIC_VERSION(value);
    5.29 -
    5.30 -    /*
    5.31 -     * Do not trust the local APIC being empty at bootup.
    5.32 -     */
    5.33 -    clear_local_APIC();
    5.34 -
    5.35 -    /*
    5.36 -     * Enable APIC.
    5.37 -     */
    5.38 -    value = apic_read(APIC_SPIV);
    5.39 -    value &= ~APIC_VECTOR_MASK;
    5.40 -    value |= APIC_SPIV_APIC_ENABLED;
    5.41 -    value |= APIC_SPIV_FOCUS_DISABLED;
    5.42 -    value |= SPURIOUS_APIC_VECTOR;
    5.43 -    apic_write_around(APIC_SPIV, value);
    5.44 -
    5.45 -    /*
    5.46 -     * Set up the virtual wire mode.
    5.47 -     */
    5.48 -    apic_write_around(APIC_LVT0, APIC_DM_EXTINT);
    5.49 -    value = APIC_DM_NMI;
    5.50 -    if (!APIC_INTEGRATED(ver))		/* 82489DX */
    5.51 -        value |= APIC_LVT_LEVEL_TRIGGER;
    5.52 -    apic_write_around(APIC_LVT1, value);
    5.53  }
    5.54  
    5.55  void __init setup_local_APIC (void)
    5.56 @@ -401,10 +372,8 @@ static int __init detect_init_APIC (void
    5.57              wrmsr(MSR_IA32_APICBASE, l, h);
    5.58          }
    5.59      }
    5.60 -    /*
    5.61 -     * The APIC feature bit should now be enabled
    5.62 -     * in `cpuid'
    5.63 -     */
    5.64 +
    5.65 +    /* The APIC feature bit should now be enabled in `cpuid' */
    5.66      features = cpuid_edx(1);
    5.67      if (!(features & (1 << X86_FEATURE_APIC))) {
    5.68          printk("Could not enable APIC!\n");
     6.1 --- a/xen-2.4.16/arch/i386/entry.S	Tue Feb 11 13:04:09 2003 +0000
     6.2 +++ b/xen-2.4.16/arch/i386/entry.S	Tue Feb 11 13:05:51 2003 +0000
     6.3 @@ -102,7 +102,7 @@ PROCESSOR       =  0
     6.4  STATE           =  4
     6.5  HYP_EVENTS      =  8
     6.6  DOMAIN          = 12        
     6.7 -SHARED_INFO     = 24
     6.8 +SHARED_INFO     = 16
     6.9  
    6.10  /* Offsets in shared_info_t */
    6.11  EVENTS          =  0
    6.12 @@ -527,6 +527,7 @@ ENTRY(hypervisor_call_table)
    6.13          .long SYMBOL_NAME(do_set_debugreg)
    6.14          .long SYMBOL_NAME(do_get_debugreg)
    6.15          .long SYMBOL_NAME(do_update_descriptor)
    6.16 +        .long SYMBOL_NAME(do_set_fast_trap)
    6.17          .rept NR_syscalls-(.-hypervisor_call_table)/4
    6.18          .long SYMBOL_NAME(sys_ni_syscall)
    6.19  	.endr
     7.1 --- a/xen-2.4.16/arch/i386/i8259.c	Tue Feb 11 13:04:09 2003 +0000
     7.2 +++ b/xen-2.4.16/arch/i386/i8259.c	Tue Feb 11 13:05:51 2003 +0000
     7.3 @@ -46,7 +46,7 @@ BUILD_COMMON_IRQ()
     7.4  
     7.5  /*
     7.6   * ISA PIC or low IO-APIC triggered (INTA-cycle or APIC) interrupts:
     7.7 - * (these are usually mapped to vectors 0x20-0x2f)
     7.8 + * (these are usually mapped to vectors 0x30-0x3f)
     7.9   */
    7.10      BUILD_16_IRQS(0x0)
    7.11  
    7.12 @@ -64,7 +64,7 @@ BUILD_COMMON_IRQ()
    7.13      BUILD_16_IRQS(0x1) BUILD_16_IRQS(0x2) BUILD_16_IRQS(0x3)
    7.14      BUILD_16_IRQS(0x4) BUILD_16_IRQS(0x5) BUILD_16_IRQS(0x6) BUILD_16_IRQS(0x7)
    7.15      BUILD_16_IRQS(0x8) BUILD_16_IRQS(0x9) BUILD_16_IRQS(0xa) BUILD_16_IRQS(0xb)
    7.16 -    BUILD_16_IRQS(0xc) BUILD_16_IRQS(0xd)
    7.17 +    BUILD_16_IRQS(0xc)
    7.18  #endif
    7.19  
    7.20  #undef BUILD_16_IRQS
    7.21 @@ -111,7 +111,7 @@ BUILD_COMMON_IRQ()
    7.22          IRQLIST_16(0x1), IRQLIST_16(0x2), IRQLIST_16(0x3),
    7.23  	IRQLIST_16(0x4), IRQLIST_16(0x5), IRQLIST_16(0x6), IRQLIST_16(0x7),
    7.24  	IRQLIST_16(0x8), IRQLIST_16(0x9), IRQLIST_16(0xa), IRQLIST_16(0xb),
    7.25 -	IRQLIST_16(0xc), IRQLIST_16(0xd)
    7.26 +	IRQLIST_16(0xc)
    7.27  #endif
    7.28      };
    7.29  
    7.30 @@ -344,7 +344,7 @@ void __init init_8259A(int auto_eoi)
    7.31       * outb_p - this has to work on a wide range of PC hardware.
    7.32       */
    7.33      outb_p(0x11, 0x20);	/* ICW1: select 8259A-1 init */
    7.34 -    outb_p(0x20 + 0, 0x21);	/* ICW2: 8259A-1 IR0-7 mapped to 0x20-0x27 */
    7.35 +    outb_p(0x30 + 0, 0x21);	/* ICW2: 8259A-1 IR0-7 mapped to 0x30-0x37 */
    7.36      outb_p(0x04, 0x21);	/* 8259A-1 (the master) has a slave on IR2 */
    7.37      if (auto_eoi)
    7.38          outb_p(0x03, 0x21);	/* master does Auto EOI */
    7.39 @@ -352,7 +352,7 @@ void __init init_8259A(int auto_eoi)
    7.40          outb_p(0x01, 0x21);	/* master expects normal EOI */
    7.41  
    7.42      outb_p(0x11, 0xA0);	/* ICW1: select 8259A-2 init */
    7.43 -    outb_p(0x20 + 8, 0xA1);	/* ICW2: 8259A-2 IR0-7 mapped to 0x28-0x2f */
    7.44 +    outb_p(0x30 + 8, 0xA1);	/* ICW2: 8259A-2 IR0-7 mapped to 0x38-0x3f */
    7.45      outb_p(0x02, 0xA1);	/* 8259A-2 is a slave on master's IR2 */
    7.46      outb_p(0x01, 0xA1);	/* (slave's support for AEOI in flat mode
    7.47                             is to be investigated) */
     8.1 --- a/xen-2.4.16/arch/i386/io_apic.c	Tue Feb 11 13:04:09 2003 +0000
     8.2 +++ b/xen-2.4.16/arch/i386/io_apic.c	Tue Feb 11 13:05:51 2003 +0000
     8.3 @@ -495,8 +495,10 @@ static int __init assign_irq_vector(int 
     8.4  		return IO_APIC_VECTOR(irq);
     8.5  next:
     8.6  	current_vector += 8;
     8.7 -	if (current_vector == HYPERVISOR_CALL_VECTOR)
     8.8 -		goto next;
     8.9 +        /* XXX Skip the guestOS -> Xen syscall vector! XXX */
    8.10 +	if (current_vector == HYPERVISOR_CALL_VECTOR) goto next;
    8.11 +        /* XXX Skip the Linux/BSD fast-trap vector! XXX */
    8.12 +        if (current_vector == 0x80) goto next;
    8.13  
    8.14  	if (current_vector > FIRST_SYSTEM_VECTOR) {
    8.15  		offset++;
    10.1 --- a/xen-2.4.16/arch/i386/process.c	Tue Feb 11 13:04:09 2003 +0000
    10.2 +++ b/xen-2.4.16/arch/i386/process.c	Tue Feb 11 13:05:51 2003 +0000
    10.3 @@ -12,8 +12,6 @@
    10.4   */
    10.5  
    10.6  #define __KERNEL_SYSCALLS__
    10.7 -#include <stdarg.h>
    10.8 -
    10.9  #include <xeno/config.h>
   10.10  #include <xeno/lib.h>
   10.11  #include <xeno/errno.h>
   10.12 @@ -326,6 +324,9 @@ void new_thread(struct task_struct *p,
   10.13  
   10.14      __save_flags(regs->eflags);
   10.15      regs->eflags |= X86_EFLAGS_IF;
   10.16 +
   10.17 +    /* No fast trap at start of day. */
   10.18 +    SET_DEFAULT_FAST_TRAP(&p->thread);
   10.19  }
   10.20  
   10.21  
   10.22 @@ -363,12 +364,17 @@ void new_thread(struct task_struct *p,
   10.23  /* NB. prev_p passed in %eax, next_p passed in %edx */
   10.24  void __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
   10.25  {
   10.26 +    extern struct desc_struct idt_table[];
   10.27      struct thread_struct *prev = &prev_p->thread,
   10.28          *next = &next_p->thread;
   10.29      struct tss_struct *tss = init_tss + smp_processor_id();
   10.30  
   10.31      unlazy_fpu(prev_p);
   10.32  
   10.33 +    /* Switch the fast-trap handler. */
   10.34 +    CLEAR_FAST_TRAP(&prev_p->thread);
   10.35 +    SET_FAST_TRAP(&next_p->thread);
   10.36 +
   10.37      tss->esp0 = next->esp0;
   10.38      tss->esp1 = next->esp1;
   10.39      tss->ss1  = next->ss1;
    11.1 --- a/xen-2.4.16/arch/i386/smpboot.c	Tue Feb 11 13:04:09 2003 +0000
    11.2 +++ b/xen-2.4.16/arch/i386/smpboot.c	Tue Feb 11 13:05:51 2003 +0000
    11.3 @@ -685,6 +685,8 @@ static void __init do_boot_cpu (int apic
    11.4      idle->thread.esp = idle->thread.esp0 = (unsigned long)idle + THREAD_SIZE;
    11.5      idle->thread.eip = (unsigned long) start_secondary;
    11.6  
    11.7 +    SET_DEFAULT_FAST_TRAP(&idle->thread);
    11.8 +
    11.9      /* start_eip had better be page-aligned! */
   11.10      start_eip = setup_trampoline();
   11.11  
    12.1 --- a/xen-2.4.16/arch/i386/traps.c	Tue Feb 11 13:04:09 2003 +0000
    12.2 +++ b/xen-2.4.16/arch/i386/traps.c	Tue Feb 11 13:05:51 2003 +0000
    12.3 @@ -277,20 +277,21 @@ asmlinkage void do_general_protection(st
    12.4       * Cunning trick to allow arbitrary "INT n" handling.
    12.5       * 
    12.6       * We set DPL == 0 on all vectors in the IDT. This prevents any INT <n>
    12.7 -     * instruction from trapping to the appropriate vector, when that might not 
    12.8 +     * instruction from trapping to the appropriate vector, when that might not
    12.9       * be expected by Xen or the guest OS. For example, that entry might be for
   12.10       * a fault handler (unlike traps, faults don't increment EIP), or might
   12.11       * expect an error code on the stack (which a software trap never
   12.12       * provides), or might be a hardware interrupt handler that doesn't like
   12.13 -     * being called spuriously.  
   12.14 +     * being called spuriously.
   12.15       * 
   12.16       * Instead, a GPF occurs with the faulting IDT vector in the error code.
   12.17 -     * Bit 1 is set to indicate that an IDT entry caused the fault.
   12.18 -     * Bit 0 is clear to indicate that it's a software fault, not hardware.
   12.19 +     * Bit 1 is set to indicate that an IDT entry caused the fault. Bit 0 is 
   12.20 +     * clear to indicate that it's a software fault, not hardware.
   12.21       * 
   12.22 -     * NOTE: Vectors 3 and 4 are dealt with from their own handler. This is okay
   12.23 -     * because they can only be triggered by an explicit DPL-checked instruction.
   12.24 -     * The DPL specified by the guest OS for these vectors is NOT CHECKED!!
   12.25 +     * NOTE: Vectors 3 and 4 are dealt with from their own handler. This is
   12.26 +     * okay because they can only be triggered by an explicit DPL-checked
   12.27 +     * instruction. The DPL specified by the guest OS for these vectors is NOT
   12.28 +     * CHECKED!!
   12.29       */
   12.30      if ( (error_code & 3) == 2 )
   12.31      {
   12.32 @@ -298,6 +299,7 @@ asmlinkage void do_general_protection(st
   12.33          ti = current->thread.traps + (error_code>>3);
   12.34          if ( ti->dpl >= (regs->xcs & 3) )
   12.35          {
   12.36 +            if ( (error_code>>3)==0x80 ) { printk("!!!\n"); BUG(); }
   12.37              gtb->flags = GTBF_TRAP_NOCODE;
   12.38              gtb->cs    = ti->cs;
   12.39              gtb->eip   = ti->address;
   12.40 @@ -570,6 +572,40 @@ long do_set_trap_table(trap_info_t *trap
   12.41  }
   12.42  
   12.43  
   12.44 +long do_set_fast_trap(int idx)
   12.45 +{
   12.46 +    trap_info_t *ti;
   12.47 +
   12.48 +    /* Index 0 is special: it disables fast traps. */
   12.49 +    if ( idx == 0 )
   12.50 +    {
   12.51 +        CLEAR_FAST_TRAP(&current->thread);
   12.52 +        SET_DEFAULT_FAST_TRAP(&current->thread);
   12.53 +        return 0;
   12.54 +    }
   12.55 +
   12.56 +    /*
   12.57 +     * We only fast-trap vectors 0x20-0x2f, and vector 0x80.
   12.58 +     * The former range is used by Windows and MS-DOS.
   12.59 +     * Vector 0x80 is used by Linux and the BSD variants.
   12.60 +     */
   12.61 +    if ( (idx != 0x80) && ((idx < 0x20) || (idx > 0x2f)) ) return -1;
   12.62 +
   12.63 +    ti = current->thread.traps + idx;
   12.64 +
   12.65 +    CLEAR_FAST_TRAP(&current->thread);
   12.66 +
   12.67 +    current->thread.fast_trap_idx    = idx;
   12.68 +    current->thread.fast_trap_desc.a = (ti->cs << 16) | (ti->address & 0xffff);
   12.69 +    current->thread.fast_trap_desc.b = 
   12.70 +        (ti->address & 0xffff0000) | 0x8f00 | (ti->dpl&3)<<13;
   12.71 +
   12.72 +    SET_FAST_TRAP(&current->thread);
   12.73 +
   12.74 +    return 0;
   12.75 +}
   12.76 +
   12.77 +
   12.78  long do_fpu_taskswitch(void)
   12.79  {
   12.80      current->flags |= PF_GUEST_STTS;
    13.1 --- a/xen-2.4.16/common/dom0_ops.c	Tue Feb 11 13:04:09 2003 +0000
    13.2 +++ b/xen-2.4.16/common/dom0_ops.c	Tue Feb 11 13:05:51 2003 +0000
    13.3 @@ -32,26 +32,26 @@ static unsigned int get_domnr(void)
    13.4  
    13.5  static void build_page_list(struct task_struct *p)
    13.6  {
    13.7 -    unsigned long * list;
    13.8 +    unsigned long *list;
    13.9      unsigned long curr;
   13.10 -    unsigned long page;
   13.11      struct list_head *list_ent;
   13.12  
   13.13 -    list = (unsigned long *)map_domain_mem(p->pg_head << PAGE_SHIFT);
   13.14 -    curr = page = p->pg_head;
   13.15 -    do {
   13.16 -        *list++ = page;
   13.17 -        list_ent = frame_table[page].list.next;
   13.18 -        page = list_entry(list_ent, struct pfn_info, list) - frame_table;
   13.19 -        if( !((unsigned long)list & (PAGE_SIZE-1)) )
   13.20 +    curr = list_entry(p->pg_head.next, struct pfn_info, list) - frame_table;
   13.21 +    list = (unsigned long *)map_domain_mem(curr << PAGE_SHIFT);
   13.22 +
   13.23 +    list_for_each(list_ent, &p->pg_head)
   13.24 +    {
   13.25 +        *list++ = list_entry(list_ent, struct pfn_info, list) - frame_table;
   13.26 +
   13.27 +        if( ((unsigned long)list & ~PAGE_MASK) == 0 )
   13.28          {
   13.29 -            list_ent = frame_table[curr].list.next;
   13.30 -            curr = list_entry(list_ent, struct pfn_info, list) - frame_table;
   13.31 +            struct list_head *ent = frame_table[curr].list.next;
   13.32 +            curr = list_entry(ent, struct pfn_info, list) - frame_table;
   13.33              unmap_domain_mem(list-1);
   13.34              list = (unsigned long *)map_domain_mem(curr << PAGE_SHIFT);
   13.35          }
   13.36      }
   13.37 -    while ( page != p->pg_head );
   13.38 +
   13.39      unmap_domain_mem(list);
   13.40  }
   13.41      
   13.42 @@ -97,37 +97,20 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
   13.43          pro = (pro+1) % smp_num_cpus;
   13.44          p->processor = pro;
   13.45  
   13.46 -        /* if we are not booting dom 0 than only mem 
   13.47 -         * needs to be allocated
   13.48 -         */
   13.49 -        if(dom != 0){
   13.50 +        if ( dom == 0 ) BUG();
   13.51  
   13.52 -            if(alloc_new_dom_mem(p, op.u.newdomain.memory_kb) != 0){
   13.53 -                ret = -1;
   13.54 -                break;
   13.55 -            }
   13.56 -            build_page_list(p);
   13.57 -            
   13.58 -            ret = p->domain;
   13.59 +        ret = alloc_new_dom_mem(p, op.u.newdomain.memory_kb);
   13.60 +        if ( ret != 0 ) break;
   13.61  
   13.62 -            op.u.newdomain.domain = ret;
   13.63 -            op.u.newdomain.pg_head = p->pg_head;
   13.64 -            copy_to_user(u_dom0_op, &op, sizeof(op));
   13.65 -
   13.66 -            break;
   13.67 -        }
   13.68 -
   13.69 -        /* executed only in case of domain 0 */
   13.70 -        ret = setup_guestos(p, &op.u.newdomain);    /* Load guest OS into @p */
   13.71 -        if ( ret != 0 ) 
   13.72 -        {
   13.73 -            p->state = TASK_DYING;
   13.74 -            release_task(p);
   13.75 -            break;
   13.76 -        }
   13.77 -        wake_up(p);          /* Put @p on runqueue */
   13.78 -        reschedule(p);       /* Force a scheduling decision on @p's CPU */
   13.79 +        build_page_list(p);
   13.80 +        
   13.81          ret = p->domain;
   13.82 +        
   13.83 +        op.u.newdomain.domain = ret;
   13.84 +        op.u.newdomain.pg_head = 
   13.85 +            list_entry(p->pg_head.next, struct pfn_info, list) -
   13.86 +            frame_table;
   13.87 +        copy_to_user(u_dom0_op, &op, sizeof(op));
   13.88      }
   13.89      break;
   13.90  
    14.1 --- a/xen-2.4.16/common/domain.c	Tue Feb 11 13:04:09 2003 +0000
    14.2 +++ b/xen-2.4.16/common/domain.c	Tue Feb 11 13:05:51 2003 +0000
    14.3 @@ -70,7 +70,8 @@ struct task_struct *do_newdomain(void)
    14.4       */
    14.5      p->blk_ring_base = (blk_ring_t *)(p->shared_info + 1);
    14.6      p->net_ring_base = (net_ring_t *)(p->blk_ring_base + 1);
    14.7 -    p->pg_head = p->tot_pages = 0;
    14.8 +    INIT_LIST_HEAD(&p->pg_head);
    14.9 +    p->tot_pages = 0;
   14.10      write_lock_irqsave(&tasklist_lock, flags);
   14.11      SET_LINKS(p);
   14.12      write_unlock_irqrestore(&tasklist_lock, flags);
   14.13 @@ -244,6 +245,8 @@ long kill_other_domain(unsigned int dom)
   14.14  /* Release resources belonging to task @p. */
   14.15  void release_task(struct task_struct *p)
   14.16  {
   14.17 +    struct list_head *list_ent, *tmp;
   14.18 +
   14.19      ASSERT(!__task_on_runqueue(p));
   14.20      ASSERT(p->state == TASK_DYING);
   14.21      ASSERT(!p->has_cpu);
   14.22 @@ -262,17 +265,15 @@ void release_task(struct task_struct *p)
   14.23      }
   14.24      if ( p->mm.perdomain_pt ) free_page((unsigned long)p->mm.perdomain_pt);
   14.25      free_page((unsigned long)p->shared_info);
   14.26 -    if ( p->tot_pages != 0 )
   14.27 +
   14.28 +    list_for_each_safe(list_ent, tmp, &p->pg_head)
   14.29      {
   14.30 -        /* Splice domain's pages into the free list. */
   14.31 -        struct list_head *first = &frame_table[p->pg_head].list;
   14.32 -        struct list_head *last  = first->prev;
   14.33 -        free_list.next->prev = last;
   14.34 -        last->next = free_list.next;
   14.35 -        free_list.next = first;
   14.36 -        first->prev = &free_list;            
   14.37 -        free_pfns += p->tot_pages;
   14.38 +        struct pfn_info *pf = list_entry(list_ent, struct pfn_info, list);
   14.39 +        pf->type_count = pf->tot_count = pf->flags = 0;
   14.40 +        list_del(list_ent);
   14.41 +        list_add(list_ent, &free_list);
   14.42      }
   14.43 +
   14.44      free_task_struct(p);
   14.45  }
   14.46  
   14.47 @@ -351,7 +352,7 @@ asmlinkage void schedule(void)
   14.48  unsigned int alloc_new_dom_mem(struct task_struct *p, unsigned int kbytes)
   14.49  {
   14.50      struct list_head *temp;
   14.51 -    struct pfn_info *pf, *pf_head;
   14.52 +    struct pfn_info *pf;
   14.53      unsigned int alloc_pfns;
   14.54      unsigned int req_pages;
   14.55      unsigned long flags;
   14.56 @@ -362,33 +363,18 @@ unsigned int alloc_new_dom_mem(struct ta
   14.57      spin_lock_irqsave(&free_list_lock, flags);
   14.58      
   14.59      /* is there enough mem to serve the request? */   
   14.60 -    if(req_pages > free_pfns)
   14.61 -        return -1;
   14.62 +    if ( req_pages > free_pfns ) return -1;
   14.63      
   14.64      /* allocate pages and build a thread through frame_table */
   14.65      temp = free_list.next;
   14.66 -
   14.67 -    /* allocate first page */
   14.68 -    pf = pf_head = list_entry(temp, struct pfn_info, list);
   14.69 -    pf->flags |= p->domain;
   14.70 -    temp = temp->next;
   14.71 -    list_del(&pf->list);
   14.72 -    INIT_LIST_HEAD(&pf->list);
   14.73 -    p->pg_head = pf - frame_table;
   14.74 -    pf->type_count = pf->tot_count = 0;
   14.75 -    free_pfns--;
   14.76 -
   14.77 -    /* allocate the rest */
   14.78 -    for ( alloc_pfns = req_pages - 1; alloc_pfns; alloc_pfns-- )
   14.79 +    for ( alloc_pfns = 0; alloc_pfns < req_pages; alloc_pfns++ )
   14.80      {
   14.81          pf = list_entry(temp, struct pfn_info, list);
   14.82          pf->flags |= p->domain;
   14.83 +        pf->type_count = pf->tot_count = 0;
   14.84          temp = temp->next;
   14.85          list_del(&pf->list);
   14.86 -
   14.87 -        list_add_tail(&pf->list, &pf_head->list);
   14.88 -        pf->type_count = pf->tot_count = 0;
   14.89 -
   14.90 +        list_add_tail(&pf->list, &p->pg_head);
   14.91          free_pfns--;
   14.92      }
   14.93     
   14.94 @@ -538,11 +524,12 @@ int final_setup_guestos(struct task_stru
   14.95  static unsigned long alloc_page_from_domain(unsigned long * cur_addr, 
   14.96      unsigned long * index)
   14.97  {
   14.98 -    struct list_head *ent = frame_table[*cur_addr >> PAGE_SHIFT].list.prev;
   14.99 +    unsigned long ret = *cur_addr;
  14.100 +    struct list_head *ent = frame_table[ret >> PAGE_SHIFT].list.prev;
  14.101      *cur_addr = list_entry(ent, struct pfn_info, list) - frame_table;
  14.102      *cur_addr <<= PAGE_SHIFT;
  14.103      (*index)--;    
  14.104 -    return *cur_addr;
  14.105 +    return ret;
  14.106  }
  14.107  
  14.108  /* setup_guestos is used for building dom0 solely. other domains are built in
  14.109 @@ -585,7 +572,9 @@ int setup_guestos(struct task_struct *p,
  14.110      }
  14.111  
  14.112      if ( alloc_new_dom_mem(p, params->memory_kb) ) return -ENOMEM;
  14.113 -    alloc_address = p->pg_head << PAGE_SHIFT;
  14.114 +    alloc_address = list_entry(p->pg_head.prev, struct pfn_info, list) -
  14.115 +        frame_table;
  14.116 +    alloc_address <<= PAGE_SHIFT;
  14.117      alloc_index = p->tot_pages;
  14.118  
  14.119      if ( (mod[nr_mods-1].mod_end-mod[0].mod_start) > 
  14.120 @@ -622,7 +611,9 @@ int setup_guestos(struct task_struct *p,
  14.121       */
  14.122  
  14.123      l2tab += l2_table_offset(virt_load_address);
  14.124 -    cur_address = p->pg_head << PAGE_SHIFT;
  14.125 +    cur_address = list_entry(p->pg_head.next, struct pfn_info, list) -
  14.126 +        frame_table;
  14.127 +    cur_address <<= PAGE_SHIFT;
  14.128      for ( count = 0; count < p->tot_pages + 1; count++ )
  14.129      {
  14.130          if ( !((unsigned long)l1tab & (PAGE_SIZE-1)) )
  14.131 @@ -654,7 +645,9 @@ int setup_guestos(struct task_struct *p,
  14.132      unmap_domain_mem(l1start);
  14.133  
  14.134      /* pages that are part of page tables must be read only */
  14.135 -    cur_address = p->pg_head << PAGE_SHIFT;
  14.136 +    cur_address = list_entry(p->pg_head.next, struct pfn_info, list) -
  14.137 +        frame_table;
  14.138 +    cur_address <<= PAGE_SHIFT;
  14.139      for ( count = 0; count < alloc_index; count++ ) 
  14.140      {
  14.141          list_ent = frame_table[cur_address >> PAGE_SHIFT].list.next;
    15.1 --- a/xen-2.4.16/common/kernel.c	Tue Feb 11 13:04:09 2003 +0000
    15.2 +++ b/xen-2.4.16/common/kernel.c	Tue Feb 11 13:05:51 2003 +0000
    15.3 @@ -44,6 +44,7 @@ void start_of_day(void);
    15.4  unsigned long opt_ipbase=0, opt_nfsserv=0, opt_gateway=0, opt_netmask=0;
    15.5  unsigned char opt_nfsroot[50]="";
    15.6  unsigned int opt_dom0_mem = 16000; /* default kbytes for DOM0 */
    15.7 +unsigned int opt_ne_base = 0; /* NE2k NICs cannot be probed */
    15.8  enum { OPT_IP, OPT_STR, OPT_UINT };
    15.9  static struct {
   15.10      unsigned char *name;
   15.11 @@ -56,6 +57,7 @@ static struct {
   15.12      { "netmask",  OPT_IP,   &opt_netmask },
   15.13      { "nfsroot",  OPT_STR,  &opt_nfsroot },
   15.14      { "dom0_mem", OPT_UINT, &opt_dom0_mem }, 
   15.15 +    { "ne_base",  OPT_UINT, &opt_ne_base },
   15.16      { NULL,       0,        NULL     }
   15.17  };
   15.18  
   15.19 @@ -144,7 +146,8 @@ void cmain (unsigned long magic, multibo
   15.20                      }
   15.21                      else /* opts[i].type == OPT_UINT */
   15.22                      {
   15.23 -                        *(unsigned int *)opts[i].var = simple_strtol(opt, (char **)&opt, 10);
   15.24 +                        *(unsigned int *)opts[i].var =
   15.25 +                            simple_strtol(opt, (char **)&opt, 0);
   15.26                      }
   15.27                      break;
   15.28                  }
    16.1 --- a/xen-2.4.16/common/memory.c	Tue Feb 11 13:04:09 2003 +0000
    16.2 +++ b/xen-2.4.16/common/memory.c	Tue Feb 11 13:05:51 2003 +0000
    16.3 @@ -176,7 +176,7 @@
    16.4  #include <asm/uaccess.h>
    16.5  #include <asm/domain_page.h>
    16.6  
    16.7 -#if 1
    16.8 +#if 0
    16.9  #define MEM_LOG(_f, _a...) printk("DOM%d: (file=memory.c, line=%d) " _f "\n", current->domain, __LINE__, ## _a )
   16.10  #else
   16.11  #define MEM_LOG(_f, _a...) ((void)0)
   16.12 @@ -230,18 +230,18 @@ void __init init_frametable(unsigned lon
   16.13      frame_table = (frame_table_t *)FRAMETABLE_VIRT_START;
   16.14      memset(frame_table, 0, frame_table_size);
   16.15  
   16.16 -    free_pfns = nr_pages - 
   16.17 -        ((__pa(frame_table) + frame_table_size) >> PAGE_SHIFT);
   16.18 +    free_pfns = 0;
   16.19  
   16.20      /* Put all domain-allocatable memory on a free list. */
   16.21      spin_lock_irqsave(&free_list_lock, flags);
   16.22      INIT_LIST_HEAD(&free_list);
   16.23      for( page_index = (__pa(frame_table) + frame_table_size) >> PAGE_SHIFT; 
   16.24 -         page_index < nr_pages; 
   16.25 +         page_index < nr_pages;
   16.26           page_index++ )      
   16.27      {
   16.28          pf = list_entry(&frame_table[page_index].list, struct pfn_info, list);
   16.29          list_add_tail(&pf->list, &free_list);
   16.30 +        free_pfns++;
   16.31      }
   16.32      spin_unlock_irqrestore(&free_list_lock, flags);
   16.33  }
    17.1 --- a/xen-2.4.16/drivers/net/Makefile	Tue Feb 11 13:04:09 2003 +0000
    17.2 +++ b/xen-2.4.16/drivers/net/Makefile	Tue Feb 11 13:05:51 2003 +0000
    17.3 @@ -2,9 +2,15 @@
    17.4  include $(BASEDIR)/Rules.mk
    17.5  
    17.6  default: $(OBJS)
    17.7 +	$(MAKE) -C ne
    17.8  	$(MAKE) -C tulip
    17.9 -	$(LD) -r -o driver.o $(OBJS) tulip/tulip.o 
   17.10 +	$(MAKE) -C e1000
   17.11 +	$(LD) -r -o driver.o $(OBJS) tulip/tulip.o e1000/e1000.o ne/ne_drv.o
   17.12  
   17.13  clean:
   17.14 +	$(MAKE) -C ne clean
   17.15  	$(MAKE) -C tulip clean
   17.16 +	$(MAKE) -C e1000 clean
   17.17  	rm -f *.o *~ core
   17.18 +
   17.19 +.PHONY: default clean
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/xen-2.4.16/drivers/net/e1000/LICENSE	Tue Feb 11 13:05:51 2003 +0000
    18.3 @@ -0,0 +1,339 @@
    18.4 +
    18.5 +"This software program is licensed subject to the GNU General Public License 
    18.6 +(GPL). Version 2, June 1991, available at 
    18.7 +<http://www.fsf.org/copyleft/gpl.html>"
    18.8 +
    18.9 +GNU General Public License 
   18.10 +
   18.11 +Version 2, June 1991
   18.12 +
   18.13 +Copyright (C) 1989, 1991 Free Software Foundation, Inc.  
   18.14 +59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
   18.15 +
   18.16 +Everyone is permitted to copy and distribute verbatim copies of this license
   18.17 +document, but changing it is not allowed.
   18.18 +
   18.19 +Preamble
   18.20 +
   18.21 +The licenses for most software are designed to take away your freedom to 
   18.22 +share and change it. By contrast, the GNU General Public License is intended
   18.23 +to guarantee your freedom to share and change free software--to make sure 
   18.24 +the software is free for all its users. This General Public License applies 
   18.25 +to most of the Free Software Foundation's software and to any other program 
   18.26 +whose authors commit to using it. (Some other Free Software Foundation 
   18.27 +software is covered by the GNU Library General Public License instead.) You 
   18.28 +can apply it to your programs, too.
   18.29 +
   18.30 +When we speak of free software, we are referring to freedom, not price. Our
   18.31 +General Public Licenses are designed to make sure that you have the freedom 
   18.32 +to distribute copies of free software (and charge for this service if you 
   18.33 +wish), that you receive source code or can get it if you want it, that you 
   18.34 +can change the software or use pieces of it in new free programs; and that 
   18.35 +you know you can do these things.
   18.36 +
   18.37 +To protect your rights, we need to make restrictions that forbid anyone to 
   18.38 +deny you these rights or to ask you to surrender the rights. These 
   18.39 +restrictions translate to certain responsibilities for you if you distribute
   18.40 +copies of the software, or if you modify it.
   18.41 +
   18.42 +For example, if you distribute copies of such a program, whether gratis or 
   18.43 +for a fee, you must give the recipients all the rights that you have. You 
   18.44 +must make sure that they, too, receive or can get the source code. And you 
   18.45 +must show them these terms so they know their rights.
   18.46 + 
   18.47 +We protect your rights with two steps: (1) copyright the software, and (2) 
   18.48 +offer you this license which gives you legal permission to copy, distribute 
   18.49 +and/or modify the software. 
   18.50 +
   18.51 +Also, for each author's protection and ours, we want to make certain that 
   18.52 +everyone understands that there is no warranty for this free software. If 
   18.53 +the software is modified by someone else and passed on, we want its 
   18.54 +recipients to know that what they have is not the original, so that any 
   18.55 +problems introduced by others will not reflect on the original authors' 
   18.56 +reputations. 
   18.57 +
   18.58 +Finally, any free program is threatened constantly by software patents. We 
   18.59 +wish to avoid the danger that redistributors of a free program will 
   18.60 +individually obtain patent licenses, in effect making the program 
   18.61 +proprietary. To prevent this, we have made it clear that any patent must be 
   18.62 +licensed for everyone's free use or not licensed at all. 
   18.63 +
   18.64 +The precise terms and conditions for copying, distribution and modification 
   18.65 +follow. 
   18.66 +
   18.67 +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
   18.68 +
   18.69 +0. This License applies to any program or other work which contains a notice
   18.70 +   placed by the copyright holder saying it may be distributed under the 
   18.71 +   terms of this General Public License. The "Program", below, refers to any
   18.72 +   such program or work, and a "work based on the Program" means either the 
   18.73 +   Program or any derivative work under copyright law: that is to say, a 
   18.74 +   work containing the Program or a portion of it, either verbatim or with 
   18.75 +   modifications and/or translated into another language. (Hereinafter, 
   18.76 +   translation is included without limitation in the term "modification".) 
   18.77 +   Each licensee is addressed as "you". 
   18.78 +
   18.79 +   Activities other than copying, distribution and modification are not 
   18.80 +   covered by this License; they are outside its scope. The act of running 
   18.81 +   the Program is not restricted, and the output from the Program is covered 
   18.82 +   only if its contents constitute a work based on the Program (independent 
   18.83 +   of having been made by running the Program). Whether that is true depends
   18.84 +   on what the Program does. 
   18.85 +
   18.86 +1. You may copy and distribute verbatim copies of the Program's source code 
   18.87 +   as you receive it, in any medium, provided that you conspicuously and 
   18.88 +   appropriately publish on each copy an appropriate copyright notice and 
   18.89 +   disclaimer of warranty; keep intact all the notices that refer to this 
   18.90 +   License and to the absence of any warranty; and give any other recipients 
   18.91 +   of the Program a copy of this License along with the Program. 
   18.92 +
   18.93 +   You may charge a fee for the physical act of transferring a copy, and you 
   18.94 +   may at your option offer warranty protection in exchange for a fee. 
   18.95 +
   18.96 +2. You may modify your copy or copies of the Program or any portion of it, 
   18.97 +   thus forming a work based on the Program, and copy and distribute such 
   18.98 +   modifications or work under the terms of Section 1 above, provided that 
   18.99 +   you also meet all of these conditions: 
  18.100 +
  18.101 +   * a) You must cause the modified files to carry prominent notices stating 
  18.102 +        that you changed the files and the date of any change. 
  18.103 +
  18.104 +   * b) You must cause any work that you distribute or publish, that in 
  18.105 +        whole or in part contains or is derived from the Program or any part 
  18.106 +        thereof, to be licensed as a whole at no charge to all third parties
  18.107 +        under the terms of this License. 
  18.108 +
  18.109 +   * c) If the modified program normally reads commands interactively when 
  18.110 +        run, you must cause it, when started running for such interactive 
  18.111 +        use in the most ordinary way, to print or display an announcement 
  18.112 +        including an appropriate copyright notice and a notice that there is
  18.113 +        no warranty (or else, saying that you provide a warranty) and that 
  18.114 +        users may redistribute the program under these conditions, and 
  18.115 +        telling the user how to view a copy of this License. (Exception: if 
  18.116 +        the Program itself is interactive but does not normally print such 
  18.117 +        an announcement, your work based on the Program is not required to 
  18.118 +        print an announcement.) 
  18.119 +
  18.120 +   These requirements apply to the modified work as a whole. If identifiable 
  18.121 +   sections of that work are not derived from the Program, and can be 
  18.122 +   reasonably considered independent and separate works in themselves, then 
  18.123 +   this License, and its terms, do not apply to those sections when you 
  18.124 +   distribute them as separate works. But when you distribute the same 
  18.125 +   sections as part of a whole which is a work based on the Program, the 
  18.126 +   distribution of the whole must be on the terms of this License, whose 
  18.127 +   permissions for other licensees extend to the entire whole, and thus to 
  18.128 +   each and every part regardless of who wrote it. 
  18.129 +
  18.130 +   Thus, it is not the intent of this section to claim rights or contest 
  18.131 +   your rights to work written entirely by you; rather, the intent is to 
  18.132 +   exercise the right to control the distribution of derivative or 
  18.133 +   collective works based on the Program. 
  18.134 +
  18.135 +   In addition, mere aggregation of another work not based on the Program 
  18.136 +   with the Program (or with a work based on the Program) on a volume of a 
  18.137 +   storage or distribution medium does not bring the other work under the 
  18.138 +   scope of this License. 
  18.139 +
  18.140 +3. You may copy and distribute the Program (or a work based on it, under 
  18.141 +   Section 2) in object code or executable form under the terms of Sections 
  18.142 +   1 and 2 above provided that you also do one of the following: 
  18.143 +
  18.144 +   * a) Accompany it with the complete corresponding machine-readable source 
  18.145 +        code, which must be distributed under the terms of Sections 1 and 2 
  18.146 +        above on a medium customarily used for software interchange; or, 
  18.147 +
  18.148 +   * b) Accompany it with a written offer, valid for at least three years, 
  18.149 +        to give any third party, for a charge no more than your cost of 
  18.150 +        physically performing source distribution, a complete machine-
  18.151 +        readable copy of the corresponding source code, to be distributed 
  18.152 +        under the terms of Sections 1 and 2 above on a medium customarily 
  18.153 +        used for software interchange; or, 
  18.154 +
  18.155 +   * c) Accompany it with the information you received as to the offer to 
  18.156 +        distribute corresponding source code. (This alternative is allowed 
  18.157 +        only for noncommercial distribution and only if you received the 
  18.158 +        program in object code or executable form with such an offer, in 
  18.159 +        accord with Subsection b above.) 
  18.160 +
  18.161 +   The source code for a work means the preferred form of the work for 
  18.162 +   making modifications to it. For an executable work, complete source code 
  18.163 +   means all the source code for all modules it contains, plus any 
  18.164 +   associated interface definition files, plus the scripts used to control 
  18.165 +   compilation and installation of the executable. However, as a special 
  18.166 +   exception, the source code distributed need not include anything that is 
  18.167 +   normally distributed (in either source or binary form) with the major 
  18.168 +   components (compiler, kernel, and so on) of the operating system on which
  18.169 +   the executable runs, unless that component itself accompanies the 
  18.170 +   executable. 
  18.171 +
  18.172 +   If distribution of executable or object code is made by offering access 
  18.173 +   to copy from a designated place, then offering equivalent access to copy 
  18.174 +   the source code from the same place counts as distribution of the source 
  18.175 +   code, even though third parties are not compelled to copy the source 
  18.176 +   along with the object code. 
  18.177 +
  18.178 +4. You may not copy, modify, sublicense, or distribute the Program except as
  18.179 +   expressly provided under this License. Any attempt otherwise to copy, 
  18.180 +   modify, sublicense or distribute the Program is void, and will 
  18.181 +   automatically terminate your rights under this License. However, parties 
  18.182 +   who have received copies, or rights, from you under this License will not
  18.183 +   have their licenses terminated so long as such parties remain in full 
  18.184 +   compliance. 
  18.185 +
  18.186 +5. You are not required to accept this License, since you have not signed 
  18.187 +   it. However, nothing else grants you permission to modify or distribute 
  18.188 +   the Program or its derivative works. These actions are prohibited by law 
  18.189 +   if you do not accept this License. Therefore, by modifying or 
  18.190 +   distributing the Program (or any work based on the Program), you 
  18.191 +   indicate your acceptance of this License to do so, and all its terms and
  18.192 +   conditions for copying, distributing or modifying the Program or works 
  18.193 +   based on it. 
  18.194 +
  18.195 +6. Each time you redistribute the Program (or any work based on the 
  18.196 +   Program), the recipient automatically receives a license from the 
  18.197 +   original licensor to copy, distribute or modify the Program subject to 
  18.198 +   these terms and conditions. You may not impose any further restrictions 
  18.199 +   on the recipients' exercise of the rights granted herein. You are not 
  18.200 +   responsible for enforcing compliance by third parties to this License. 
  18.201 +
  18.202 +7. If, as a consequence of a court judgment or allegation of patent 
  18.203 +   infringement or for any other reason (not limited to patent issues), 
  18.204 +   conditions are imposed on you (whether by court order, agreement or 
  18.205 +   otherwise) that contradict the conditions of this License, they do not 
  18.206 +   excuse you from the conditions of this License. If you cannot distribute 
  18.207 +   so as to satisfy simultaneously your obligations under this License and 
  18.208 +   any other pertinent obligations, then as a consequence you may not 
  18.209 +   distribute the Program at all. For example, if a patent license would 
  18.210 +   not permit royalty-free redistribution of the Program by all those who 
  18.211 +   receive copies directly or indirectly through you, then the only way you 
  18.212 +   could satisfy both it and this License would be to refrain entirely from 
  18.213 +   distribution of the Program. 
  18.214 +
  18.215 +   If any portion of this section is held invalid or unenforceable under any
  18.216 +   particular circumstance, the balance of the section is intended to apply
  18.217 +   and the section as a whole is intended to apply in other circumstances. 
  18.218 +
  18.219 +   It is not the purpose of this section to induce you to infringe any 
  18.220 +   patents or other property right claims or to contest validity of any 
  18.221 +   such claims; this section has the sole purpose of protecting the 
  18.222 +   integrity of the free software distribution system, which is implemented 
  18.223 +   by public license practices. Many people have made generous contributions
  18.224 +   to the wide range of software distributed through that system in 
  18.225 +   reliance on consistent application of that system; it is up to the 
  18.226 +   author/donor to decide if he or she is willing to distribute software 
  18.227 +   through any other system and a licensee cannot impose that choice. 
  18.228 +
  18.229 +   This section is intended to make thoroughly clear what is believed to be 
  18.230 +   a consequence of the rest of this License. 
  18.231 +
  18.232 +8. If the distribution and/or use of the Program is restricted in certain 
  18.233 +   countries either by patents or by copyrighted interfaces, the original 
  18.234 +   copyright holder who places the Program under this License may add an 
  18.235 +   explicit geographical distribution limitation excluding those countries, 
  18.236 +   so that distribution is permitted only in or among countries not thus 
  18.237 +   excluded. In such case, this License incorporates the limitation as if 
  18.238 +   written in the body of this License. 
  18.239 +
  18.240 +9. The Free Software Foundation may publish revised and/or new versions of 
  18.241 +   the General Public License from time to time. Such new versions will be 
  18.242 +   similar in spirit to the present version, but may differ in detail to 
  18.243 +   address new problems or concerns. 
  18.244 +
  18.245 +   Each version is given a distinguishing version number. If the Program 
  18.246 +   specifies a version number of this License which applies to it and "any 
  18.247 +   later version", you have the option of following the terms and 
  18.248 +   conditions either of that version or of any later version published by 
  18.249 +   the Free Software Foundation. If the Program does not specify a version 
  18.250 +   number of this License, you may choose any version ever published by the 
  18.251 +   Free Software Foundation. 
  18.252 +
  18.253 +10. If you wish to incorporate parts of the Program into other free programs
  18.254 +    whose distribution conditions are different, write to the author to ask 
  18.255 +    for permission. For software which is copyrighted by the Free Software 
  18.256 +    Foundation, write to the Free Software Foundation; we sometimes make 
  18.257 +    exceptions for this. Our decision will be guided by the two goals of 
  18.258 +    preserving the free status of all derivatives of our free software and 
  18.259 +    of promoting the sharing and reuse of software generally. 
  18.260 +
  18.261 +   NO WARRANTY
  18.262 +
  18.263 +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 
  18.264 +    FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 
  18.265 +    OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 
  18.266 +    PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 
  18.267 +    EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
  18.268 +    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE 
  18.269 +    ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH 
  18.270 +    YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL 
  18.271 +    NECESSARY SERVICING, REPAIR OR CORRECTION. 
  18.272 +
  18.273 +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 
  18.274 +    WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 
  18.275 +    REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR 
  18.276 +    DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL 
  18.277 +    DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM 
  18.278 +    (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED 
  18.279 +    INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF 
  18.280 +    THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR 
  18.281 +    OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 
  18.282 +
  18.283 +END OF TERMS AND CONDITIONS
  18.284 +
  18.285 +How to Apply These Terms to Your New Programs
  18.286 +
  18.287 +If you develop a new program, and you want it to be of the greatest 
  18.288 +possible use to the public, the best way to achieve this is to make it free 
  18.289 +software which everyone can redistribute and change under these terms. 
  18.290 +
  18.291 +To do so, attach the following notices to the program. It is safest to 
  18.292 +attach them to the start of each source file to most effectively convey the
  18.293 +exclusion of warranty; and each file should have at least the "copyright" 
  18.294 +line and a pointer to where the full notice is found. 
  18.295 +
  18.296 +one line to give the program's name and an idea of what it does.
  18.297 +Copyright (C) yyyy  name of author
  18.298 +
  18.299 +This program is free software; you can redistribute it and/or modify it 
  18.300 +under the terms of the GNU General Public License as published by the Free 
  18.301 +Software Foundation; either version 2 of the License, or (at your option) 
  18.302 +any later version.
  18.303 +
  18.304 +This program is distributed in the hope that it will be useful, but WITHOUT 
  18.305 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
  18.306 +FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
  18.307 +more details.
  18.308 +
  18.309 +You should have received a copy of the GNU General Public License along with
  18.310 +this program; if not, write to the Free Software Foundation, Inc., 59 
  18.311 +Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.312 +
  18.313 +Also add information on how to contact you by electronic and paper mail. 
  18.314 +
  18.315 +If the program is interactive, make it output a short notice like this when 
  18.316 +it starts in an interactive mode: 
  18.317 +
  18.318 +Gnomovision version 69, Copyright (C) year name of author Gnomovision comes 
  18.319 +with ABSOLUTELY NO WARRANTY; for details type 'show w'.  This is free 
  18.320 +software, and you are welcome to redistribute it under certain conditions; 
  18.321 +type 'show c' for details.
  18.322 +
  18.323 +The hypothetical commands 'show w' and 'show c' should show the appropriate 
  18.324 +parts of the General Public License. Of course, the commands you use may be 
  18.325 +called something other than 'show w' and 'show c'; they could even be 
  18.326 +mouse-clicks or menu items--whatever suits your program. 
  18.327 +
  18.328 +You should also get your employer (if you work as a programmer) or your 
  18.329 +school, if any, to sign a "copyright disclaimer" for the program, if 
  18.330 +necessary. Here is a sample; alter the names: 
  18.331 +
  18.332 +Yoyodyne, Inc., hereby disclaims all copyright interest in the program 
  18.333 +'Gnomovision' (which makes passes at compilers) written by James Hacker.
  18.334 +
  18.335 +signature of Ty Coon, 1 April 1989
  18.336 +Ty Coon, President of Vice
  18.337 +
  18.338 +This General Public License does not permit incorporating your program into 
  18.339 +proprietary programs. If your program is a subroutine library, you may 
  18.340 +consider it more useful to permit linking proprietary applications with the 
  18.341 +library. If this is what you want to do, use the GNU Library General Public 
  18.342 +License instead of this License.
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/xen-2.4.16/drivers/net/e1000/Makefile	Tue Feb 11 13:05:51 2003 +0000
    19.3 @@ -0,0 +1,39 @@
    19.4 +################################################################################
    19.5 +#
    19.6 +# 
    19.7 +# Copyright(c) 1999 - 2002 Intel Corporation. All rights reserved.
    19.8 +# 
    19.9 +# This program is free software; you can redistribute it and/or modify it 
   19.10 +# under the terms of the GNU General Public License as published by the Free 
   19.11 +# Software Foundation; either version 2 of the License, or (at your option) 
   19.12 +# any later version.
   19.13 +# 
   19.14 +# This program is distributed in the hope that it will be useful, but WITHOUT 
   19.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
   19.16 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
   19.17 +# more details.
   19.18 +# 
   19.19 +# You should have received a copy of the GNU General Public License along with
   19.20 +# this program; if not, write to the Free Software Foundation, Inc., 59 
   19.21 +# Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   19.22 +# 
   19.23 +# The full GNU General Public License is included in this distribution in the
   19.24 +# file called LICENSE.
   19.25 +# 
   19.26 +# Contact Information:
   19.27 +# Linux NICS <linux.nics@intel.com>
   19.28 +# Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
   19.29 +#
   19.30 +################################################################################
   19.31 +
   19.32 +#
   19.33 +# Makefile for the Intel(R) PRO/1000 ethernet driver
   19.34 +#
   19.35 +
   19.36 +include $(BASEDIR)/Rules.mk
   19.37 +
   19.38 +default: $(OBJS)
   19.39 +	$(LD) -r -o e1000.o $(OBJS)
   19.40 +
   19.41 +clean:
   19.42 +	rm -f *.o *~ core
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/xen-2.4.16/drivers/net/e1000/e1000.h	Tue Feb 11 13:05:51 2003 +0000
    20.3 @@ -0,0 +1,209 @@
    20.4 +/*******************************************************************************
    20.5 +
    20.6 +  
    20.7 +  Copyright(c) 1999 - 2002 Intel Corporation. All rights reserved.
    20.8 +  
    20.9 +  This program is free software; you can redistribute it and/or modify it 
   20.10 +  under the terms of the GNU General Public License as published by the Free 
   20.11 +  Software Foundation; either version 2 of the License, or (at your option) 
   20.12 +  any later version.
   20.13 +  
   20.14 +  This program is distributed in the hope that it will be useful, but WITHOUT 
   20.15 +  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
   20.16 +  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
   20.17 +  more details.
   20.18 +  
   20.19 +  You should have received a copy of the GNU General Public License along with
   20.20 +  this program; if not, write to the Free Software Foundation, Inc., 59 
   20.21 +  Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   20.22 +  
   20.23 +  The full GNU General Public License is included in this distribution in the
   20.24 +  file called LICENSE.
   20.25 +  
   20.26 +  Contact Information:
   20.27 +  Linux NICS <linux.nics@intel.com>
   20.28 +  Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
   20.29 +
   20.30 +*******************************************************************************/
   20.31 +
   20.32 +
   20.33 +/* Linux PRO/1000 Ethernet Driver main header file */
   20.34 +
   20.35 +#ifndef _E1000_H_
   20.36 +#define _E1000_H_
   20.37 +
   20.38 +//#include <linux/stddef.h>
   20.39 +#include <linux/config.h>
   20.40 +#include <linux/module.h>
   20.41 +#include <linux/types.h>
   20.42 +#include <asm/byteorder.h>
   20.43 +#include <linux/init.h>
   20.44 +#include <linux/mm.h>
   20.45 +#include <linux/errno.h>
   20.46 +#include <linux/ioport.h>
   20.47 +#include <linux/pci.h>
   20.48 +#include <linux/kernel.h>
   20.49 +#include <linux/netdevice.h>
   20.50 +#include <linux/etherdevice.h>
   20.51 +#include <linux/skbuff.h>
   20.52 +#include <linux/delay.h>
   20.53 +#include <linux/timer.h>
   20.54 +#include <linux/slab.h>
   20.55 +#include <linux/interrupt.h>
   20.56 +//#include <linux/string.h>
   20.57 +//#include <linux/pagemap.h>
   20.58 +#include <asm/bitops.h>
   20.59 +#include <asm/io.h>
   20.60 +#include <asm/irq.h>
   20.61 +//#include <linux/capability.h>
   20.62 +#include <linux/in.h>
   20.63 +//#include <linux/ip.h>
   20.64 +//#include <linux/tcp.h>
   20.65 +//#include <linux/udp.h>
   20.66 +//#include <net/pkt_sched.h>
   20.67 +#include <linux/list.h>
   20.68 +#include <linux/reboot.h>
   20.69 +#include <linux/tqueue.h>
   20.70 +#include <linux/ethtool.h>
   20.71 +#include <linux/if_vlan.h>
   20.72 +
   20.73 +#define BAR_0		0
   20.74 +#define BAR_1		1
   20.75 +#define BAR_5		5
   20.76 +#define PCI_DMA_64BIT	0xffffffffffffffffULL
   20.77 +#define PCI_DMA_32BIT	0x00000000ffffffffULL
   20.78 +
   20.79 +
   20.80 +struct e1000_adapter;
   20.81 +
   20.82 +// XEN XXX
   20.83 +#define DBG 1
   20.84 +
   20.85 +#include "e1000_hw.h"
   20.86 +
   20.87 +#if DBG
   20.88 +#define E1000_DBG(args...) printk(KERN_DEBUG "e1000: " args)
   20.89 +#else
   20.90 +XXX
   20.91 +#define E1000_DBG(args...)
   20.92 +#endif
   20.93 +
   20.94 +#define E1000_ERR(args...) printk(KERN_ERR "e1000: " args)
   20.95 +
   20.96 +#define E1000_MAX_INTR 10
   20.97 +
   20.98 +/* Supported Rx Buffer Sizes */
   20.99 +#define E1000_RXBUFFER_2048  2048
  20.100 +#define E1000_RXBUFFER_4096  4096
  20.101 +#define E1000_RXBUFFER_8192  8192
  20.102 +#define E1000_RXBUFFER_16384 16384
  20.103 +
  20.104 +/* Flow Control High-Watermark: 43464 bytes */
  20.105 +#define E1000_FC_HIGH_THRESH 0xA9C8
  20.106 +
  20.107 +/* Flow Control Low-Watermark: 43456 bytes */
  20.108 +#define E1000_FC_LOW_THRESH 0xA9C0
  20.109 +
  20.110 +/* Flow Control Pause Time: 858 usec */
  20.111 +#define E1000_FC_PAUSE_TIME 0x0680
  20.112 +
  20.113 +/* How many Tx Descriptors do we need to call netif_wake_queue ? */
  20.114 +#define E1000_TX_QUEUE_WAKE	16
  20.115 +/* How many Rx Buffers do we bundle into one write to the hardware ? */
  20.116 +#define E1000_RX_BUFFER_WRITE	16
  20.117 +
  20.118 +#define E1000_JUMBO_PBA      0x00000028
  20.119 +#define E1000_DEFAULT_PBA    0x00000030
  20.120 +
  20.121 +#define AUTO_ALL_MODES       0
  20.122 +#define E1000_EEPROM_APME    4
  20.123 +
  20.124 +/* only works for sizes that are powers of 2 */
  20.125 +#define E1000_ROUNDUP(i, size) ((i) = (((i) + (size) - 1) & ~((size) - 1)))
  20.126 +
  20.127 +/* wrapper around a pointer to a socket buffer,
  20.128 + * so a DMA handle can be stored along with the buffer */
  20.129 +struct e1000_buffer {
  20.130 +	struct sk_buff *skb;
  20.131 +	uint64_t dma;
  20.132 +	unsigned long length;
  20.133 +	unsigned long time_stamp;
  20.134 +};
  20.135 +
  20.136 +struct e1000_desc_ring {
  20.137 +	/* pointer to the descriptor ring memory */
  20.138 +	void *desc;
  20.139 +	/* physical address of the descriptor ring */
  20.140 +	dma_addr_t dma;
  20.141 +	/* length of descriptor ring in bytes */
  20.142 +	unsigned int size;
  20.143 +	/* number of descriptors in the ring */
  20.144 +	unsigned int count;
  20.145 +	/* next descriptor to associate a buffer with */
  20.146 +	unsigned int next_to_use;
  20.147 +	/* next descriptor to check for DD status bit */
  20.148 +	unsigned int next_to_clean;
  20.149 +	/* array of buffer information structs */
  20.150 +	struct e1000_buffer *buffer_info;
  20.151 +};
  20.152 +
  20.153 +#define E1000_DESC_UNUSED(R) \
  20.154 +((((R)->next_to_clean + (R)->count) - ((R)->next_to_use + 1)) % ((R)->count))
  20.155 +
  20.156 +#define E1000_GET_DESC(R, i, type)	(&(((struct type *)((R).desc))[i]))
  20.157 +#define E1000_RX_DESC(R, i)		E1000_GET_DESC(R, i, e1000_rx_desc)
  20.158 +#define E1000_TX_DESC(R, i)		E1000_GET_DESC(R, i, e1000_tx_desc)
  20.159 +#define E1000_CONTEXT_DESC(R, i)	E1000_GET_DESC(R, i, e1000_context_desc)
  20.160 +
  20.161 +/* board specific private data structure */
  20.162 +
  20.163 +struct e1000_adapter {
  20.164 +	struct timer_list watchdog_timer;
  20.165 +	struct timer_list phy_info_timer;
  20.166 +	struct vlan_group *vlgrp;
  20.167 +	char *id_string;
  20.168 +	uint32_t bd_number;
  20.169 +	uint32_t rx_buffer_len;
  20.170 +	uint32_t part_num;
  20.171 +	uint32_t wol;
  20.172 +	uint16_t link_speed;
  20.173 +	uint16_t link_duplex;
  20.174 +	spinlock_t stats_lock;
  20.175 +	atomic_t irq_sem;
  20.176 +	struct tq_struct tx_timeout_task;
  20.177 +
  20.178 +	struct timer_list blink_timer;
  20.179 +	unsigned long led_status;
  20.180 +
  20.181 +	/* TX */
  20.182 +	struct e1000_desc_ring tx_ring;
  20.183 +	uint32_t txd_cmd;
  20.184 +	uint32_t tx_int_delay;
  20.185 +	uint32_t tx_abs_int_delay;
  20.186 +	int max_data_per_txd;
  20.187 +
  20.188 +	/* RX */
  20.189 +	struct e1000_desc_ring rx_ring;
  20.190 +	uint64_t hw_csum_err;
  20.191 +	uint64_t hw_csum_good;
  20.192 +	uint32_t rx_int_delay;
  20.193 +	uint32_t rx_abs_int_delay;
  20.194 +	boolean_t rx_csum;
  20.195 +
  20.196 +	/* OS defined structs */
  20.197 +	struct net_device *netdev;
  20.198 +	struct pci_dev *pdev;
  20.199 +	struct net_device_stats net_stats;
  20.200 +
  20.201 +	/* structs defined in e1000_hw.h */
  20.202 +	struct e1000_hw hw;
  20.203 +	struct e1000_hw_stats stats;
  20.204 +	struct e1000_phy_info phy_info;
  20.205 +	struct e1000_phy_stats phy_stats;
  20.206 +
  20.207 +
  20.208 +
  20.209 +	uint32_t pci_state[16];
  20.210 +	char ifname[IFNAMSIZ];
  20.211 +};
  20.212 +#endif /* _E1000_H_ */
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/xen-2.4.16/drivers/net/e1000/e1000_ethtool.c	Tue Feb 11 13:05:51 2003 +0000
    21.3 @@ -0,0 +1,611 @@
    21.4 +/*******************************************************************************
    21.5 +
    21.6 +  
    21.7 +  Copyright(c) 1999 - 2002 Intel Corporation. All rights reserved.
    21.8 +  
    21.9 +  This program is free software; you can redistribute it and/or modify it 
   21.10 +  under the terms of the GNU General Public License as published by the Free 
   21.11 +  Software Foundation; either version 2 of the License, or (at your option) 
   21.12 +  any later version.
   21.13 +  
   21.14 +  This program is distributed in the hope that it will be useful, but WITHOUT 
   21.15 +  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
   21.16 +  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
   21.17 +  more details.
   21.18 +  
   21.19 +  You should have received a copy of the GNU General Public License along with
   21.20 +  this program; if not, write to the Free Software Foundation, Inc., 59 
   21.21 +  Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   21.22 +  
   21.23 +  The full GNU General Public License is included in this distribution in the
   21.24 +  file called LICENSE.
   21.25 +  
   21.26 +  Contact Information:
   21.27 +  Linux NICS <linux.nics@intel.com>
   21.28 +  Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
   21.29 +
   21.30 +*******************************************************************************/
   21.31 +
   21.32 +/* ethtool support for e1000 */
   21.33 +
   21.34 +#include "e1000.h"
   21.35 +
   21.36 +#include <asm/uaccess.h>
   21.37 +
   21.38 +extern char e1000_driver_name[];
   21.39 +extern char e1000_driver_version[];
   21.40 +
   21.41 +extern int e1000_up(struct e1000_adapter *adapter);
   21.42 +extern void e1000_down(struct e1000_adapter *adapter);
   21.43 +extern void e1000_reset(struct e1000_adapter *adapter);
   21.44 +
   21.45 +static char e1000_gstrings_stats[][ETH_GSTRING_LEN] = {
   21.46 +	"rx_packets", "tx_packets", "rx_bytes", "tx_bytes", "rx_errors",
   21.47 +	"tx_errors", "rx_dropped", "tx_dropped", "multicast", "collisions",
   21.48 +	"rx_length_errors", "rx_over_errors", "rx_crc_errors",
   21.49 +	"rx_frame_errors", "rx_fifo_errors", "rx_missed_errors",
   21.50 +	"tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors",
   21.51 +	"tx_heartbeat_errors", "tx_window_errors",
   21.52 +};
   21.53 +#define E1000_STATS_LEN	sizeof(e1000_gstrings_stats) / ETH_GSTRING_LEN
   21.54 +
   21.55 +static void
   21.56 +e1000_ethtool_gset(struct e1000_adapter *adapter, struct ethtool_cmd *ecmd)
   21.57 +{
   21.58 +	struct e1000_hw *hw = &adapter->hw;
   21.59 +
   21.60 +	if(hw->media_type == e1000_media_type_copper) {
   21.61 +
   21.62 +		ecmd->supported = (SUPPORTED_10baseT_Half |
   21.63 +		                   SUPPORTED_10baseT_Full |
   21.64 +		                   SUPPORTED_100baseT_Half |
   21.65 +		                   SUPPORTED_100baseT_Full |
   21.66 +		                   SUPPORTED_1000baseT_Full|
   21.67 +		                   SUPPORTED_Autoneg |
   21.68 +		                   SUPPORTED_TP);
   21.69 +
   21.70 +		ecmd->advertising = ADVERTISED_TP;
   21.71 +
   21.72 +		if(hw->autoneg == 1) {
   21.73 +			ecmd->advertising |= ADVERTISED_Autoneg;
   21.74 +
   21.75 +			/* the e1000 autoneg seems to match ethtool nicely */
   21.76 +
   21.77 +			ecmd->advertising |= hw->autoneg_advertised;
   21.78 +		}
   21.79 +
   21.80 +		ecmd->port = PORT_TP;
   21.81 +		ecmd->phy_address = hw->phy_addr;
   21.82 +
   21.83 +		if(hw->mac_type == e1000_82543)
   21.84 +			ecmd->transceiver = XCVR_EXTERNAL;
   21.85 +		else
   21.86 +			ecmd->transceiver = XCVR_INTERNAL;
   21.87 +
   21.88 +	} else {
   21.89 +		ecmd->supported   = (SUPPORTED_1000baseT_Full |
   21.90 +				     SUPPORTED_FIBRE |
   21.91 +				     SUPPORTED_Autoneg);
   21.92 +
   21.93 +		ecmd->advertising = (SUPPORTED_1000baseT_Full |
   21.94 +				     SUPPORTED_FIBRE |
   21.95 +				     SUPPORTED_Autoneg);
   21.96 +
   21.97 +		ecmd->port = PORT_FIBRE;
   21.98 +
   21.99 +		if(hw->mac_type >= e1000_82545)
  21.100 +			ecmd->transceiver = XCVR_INTERNAL;
  21.101 +		else
  21.102 +			ecmd->transceiver = XCVR_EXTERNAL;
  21.103 +	}
  21.104 +
  21.105 +	if(netif_carrier_ok(adapter->netdev)) {
  21.106 +
  21.107 +		e1000_get_speed_and_duplex(hw, &adapter->link_speed,
  21.108 +		                                   &adapter->link_duplex);
  21.109 +		ecmd->speed = adapter->link_speed;
  21.110 +
  21.111 +		/* unfortunatly FULL_DUPLEX != DUPLEX_FULL
  21.112 +		 *          and HALF_DUPLEX != DUPLEX_HALF */
  21.113 +
  21.114 +		if(adapter->link_duplex == FULL_DUPLEX)
  21.115 +			ecmd->duplex = DUPLEX_FULL;
  21.116 +		else
  21.117 +			ecmd->duplex = DUPLEX_HALF;
  21.118 +	} else {
  21.119 +		ecmd->speed = -1;
  21.120 +		ecmd->duplex = -1;
  21.121 +	}
  21.122 +
  21.123 +	ecmd->autoneg = (hw->autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
  21.124 +}
  21.125 +
  21.126 +static int
  21.127 +e1000_ethtool_sset(struct e1000_adapter *adapter, struct ethtool_cmd *ecmd)
  21.128 +{
  21.129 +	struct e1000_hw *hw = &adapter->hw;
  21.130 +
  21.131 +	if(ecmd->autoneg == AUTONEG_ENABLE) {
  21.132 +		hw->autoneg = 1;
  21.133 +		hw->autoneg_advertised = 0x002F;
  21.134 +		ecmd->advertising = 0x002F;
  21.135 +	} else {
  21.136 +		hw->autoneg = 0;
  21.137 +		switch(ecmd->speed + ecmd->duplex) {
  21.138 +		case SPEED_10 + DUPLEX_HALF:
  21.139 +			hw->forced_speed_duplex = e1000_10_half;
  21.140 +			break;
  21.141 +		case SPEED_10 + DUPLEX_FULL:
  21.142 +			hw->forced_speed_duplex = e1000_10_full;
  21.143 +			break;
  21.144 +		case SPEED_100 + DUPLEX_HALF:
  21.145 +			hw->forced_speed_duplex = e1000_100_half;
  21.146 +			break;
  21.147 +		case SPEED_100 + DUPLEX_FULL:
  21.148 +			hw->forced_speed_duplex = e1000_100_full;
  21.149 +			break;
  21.150 +		case SPEED_1000 + DUPLEX_FULL:
  21.151 +			hw->autoneg = 1;
  21.152 +			hw->autoneg_advertised = ADVERTISE_1000_FULL;
  21.153 +			break;
  21.154 +		case SPEED_1000 + DUPLEX_HALF: /* not supported */
  21.155 +		default:
  21.156 +			return -EINVAL;
  21.157 +		}
  21.158 +	}
  21.159 +
  21.160 +	/* reset the link */
  21.161 +
  21.162 +	if(netif_running(adapter->netdev)) {
  21.163 +		e1000_down(adapter);
  21.164 +		e1000_up(adapter);
  21.165 +	} else
  21.166 +		e1000_reset(adapter);
  21.167 +
  21.168 +	return 0;
  21.169 +}
  21.170 +
  21.171 +static inline int
  21.172 +e1000_eeprom_size(struct e1000_hw *hw)
  21.173 +{
  21.174 +	if((hw->mac_type > e1000_82544) &&
  21.175 +	   (E1000_READ_REG(hw, EECD) & E1000_EECD_SIZE))
  21.176 +		return 512;
  21.177 +	else
  21.178 +		return 128;
  21.179 +}
  21.180 +
  21.181 +static void
  21.182 +e1000_ethtool_gdrvinfo(struct e1000_adapter *adapter,
  21.183 +                       struct ethtool_drvinfo *drvinfo)
  21.184 +{
  21.185 +	strncpy(drvinfo->driver,  e1000_driver_name, 32);
  21.186 +	strncpy(drvinfo->version, e1000_driver_version, 32);
  21.187 +	strncpy(drvinfo->fw_version, "N/A", 32);
  21.188 +	strncpy(drvinfo->bus_info, adapter->pdev->slot_name, 32);
  21.189 +	drvinfo->n_stats = E1000_STATS_LEN;
  21.190 +#define E1000_REGS_LEN 32
  21.191 +	drvinfo->regdump_len  = E1000_REGS_LEN * sizeof(uint32_t);
  21.192 +	drvinfo->eedump_len  = e1000_eeprom_size(&adapter->hw);
  21.193 +}
  21.194 +
  21.195 +static void
  21.196 +e1000_ethtool_gregs(struct e1000_adapter *adapter,
  21.197 +                    struct ethtool_regs *regs, uint32_t *regs_buff)
  21.198 +{
  21.199 +	struct e1000_hw *hw = &adapter->hw;
  21.200 +
  21.201 +	regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
  21.202 +
  21.203 +	regs_buff[0]  = E1000_READ_REG(hw, CTRL);
  21.204 +	regs_buff[1]  = E1000_READ_REG(hw, STATUS);
  21.205 +
  21.206 +	regs_buff[2]  = E1000_READ_REG(hw, RCTL);
  21.207 +	regs_buff[3]  = E1000_READ_REG(hw, RDLEN);
  21.208 +	regs_buff[4]  = E1000_READ_REG(hw, RDH);
  21.209 +	regs_buff[5]  = E1000_READ_REG(hw, RDT);
  21.210 +	regs_buff[6]  = E1000_READ_REG(hw, RDTR);
  21.211 +
  21.212 +	regs_buff[7]  = E1000_READ_REG(hw, TCTL);
  21.213 +	regs_buff[8]  = E1000_READ_REG(hw, TDLEN);
  21.214 +	regs_buff[9]  = E1000_READ_REG(hw, TDH);
  21.215 +	regs_buff[10] = E1000_READ_REG(hw, TDT);
  21.216 +	regs_buff[11] = E1000_READ_REG(hw, TIDV);
  21.217 +
  21.218 +	return;
  21.219 +}
  21.220 +
  21.221 +static int
  21.222 +e1000_ethtool_geeprom(struct e1000_adapter *adapter,
  21.223 +                      struct ethtool_eeprom *eeprom, uint16_t *eeprom_buff)
  21.224 +{
  21.225 +	struct e1000_hw *hw = &adapter->hw;
  21.226 +	int max_len, first_word, last_word;
  21.227 +	int ret_val = 0;
  21.228 +	int i;
  21.229 +
  21.230 +	if(eeprom->len == 0) {
  21.231 +		ret_val = -EINVAL;
  21.232 +		goto geeprom_error;
  21.233 +	}
  21.234 +
  21.235 +	eeprom->magic = hw->vendor_id | (hw->device_id << 16);
  21.236 +
  21.237 +	max_len = e1000_eeprom_size(hw);
  21.238 +
  21.239 +	if(eeprom->offset > eeprom->offset + eeprom->len) {
  21.240 +		ret_val = -EINVAL;
  21.241 +		goto geeprom_error;
  21.242 +	}
  21.243 +
  21.244 +	if((eeprom->offset + eeprom->len) > max_len)
  21.245 +		eeprom->len = (max_len - eeprom->offset);
  21.246 +
  21.247 +	first_word = eeprom->offset >> 1;
  21.248 +	last_word = (eeprom->offset + eeprom->len - 1) >> 1;
  21.249 +
  21.250 +	for(i = 0; i <= (last_word - first_word); i++)
  21.251 +		e1000_read_eeprom(hw, first_word + i, &eeprom_buff[i]);
  21.252 +
  21.253 +geeprom_error:
  21.254 +	return ret_val;
  21.255 +}
  21.256 +
  21.257 +static int
  21.258 +e1000_ethtool_seeprom(struct e1000_adapter *adapter,
  21.259 +                      struct ethtool_eeprom *eeprom, void *user_data)
  21.260 +{
  21.261 +	struct e1000_hw *hw = &adapter->hw;
  21.262 +	uint16_t *eeprom_buff;
  21.263 +	int max_len, first_word, last_word;
  21.264 +	void *ptr;
  21.265 +	int i;
  21.266 +
  21.267 +	if(eeprom->len == 0)
  21.268 +		return -EOPNOTSUPP;
  21.269 +
  21.270 +	if(eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
  21.271 +		return -EFAULT;
  21.272 +
  21.273 +	max_len = e1000_eeprom_size(hw);
  21.274 +
  21.275 +	if((eeprom->offset + eeprom->len) > max_len)
  21.276 +		eeprom->len = (max_len - eeprom->offset);
  21.277 +
  21.278 +	first_word = eeprom->offset >> 1;
  21.279 +	last_word = (eeprom->offset + eeprom->len - 1) >> 1;
  21.280 +	eeprom_buff = kmalloc(max_len, GFP_KERNEL);
  21.281 +	if(eeprom_buff == NULL)
  21.282 +		return -ENOMEM;
  21.283 +
  21.284 +	ptr = (void *)eeprom_buff;
  21.285 +
  21.286 +	if(eeprom->offset & 1) {
  21.287 +		/* need read/modify/write of first changed EEPROM word */
  21.288 +		/* only the second byte of the word is being modified */
  21.289 +		e1000_read_eeprom(hw, first_word, &eeprom_buff[0]);
  21.290 +		ptr++;
  21.291 +	}
  21.292 +	if((eeprom->offset + eeprom->len) & 1) {
  21.293 +		/* need read/modify/write of last changed EEPROM word */
  21.294 +		/* only the first byte of the word is being modified */
  21.295 +		e1000_read_eeprom(hw, last_word,
  21.296 +		                  &eeprom_buff[last_word - first_word]);
  21.297 +	}
  21.298 +	if(copy_from_user(ptr, user_data, eeprom->len)) {
  21.299 +		kfree(eeprom_buff);
  21.300 +		return -EFAULT;
  21.301 +	}
  21.302 +
  21.303 +	for(i = 0; i <= (last_word - first_word); i++)
  21.304 +		e1000_write_eeprom(hw, first_word + i, eeprom_buff[i]);
  21.305 +
  21.306 +	/* Update the checksum over the first part of the EEPROM if needed */
  21.307 +	if(first_word <= EEPROM_CHECKSUM_REG)
  21.308 +		e1000_update_eeprom_checksum(hw);
  21.309 +
  21.310 +	kfree(eeprom_buff);
  21.311 +
  21.312 +	return 0;
  21.313 +}
  21.314 +
  21.315 +static void
  21.316 +e1000_ethtool_gwol(struct e1000_adapter *adapter, struct ethtool_wolinfo *wol)
  21.317 +{
  21.318 +	struct e1000_hw *hw = &adapter->hw;
  21.319 +
  21.320 +	switch(adapter->hw.device_id) {
  21.321 +	case E1000_DEV_ID_82542:
  21.322 +	case E1000_DEV_ID_82543GC_FIBER:
  21.323 +	case E1000_DEV_ID_82543GC_COPPER:
  21.324 +	case E1000_DEV_ID_82544EI_FIBER:
  21.325 +		wol->supported = 0;
  21.326 +		wol->wolopts   = 0;
  21.327 +		return;
  21.328 +
  21.329 +	case E1000_DEV_ID_82546EB_FIBER:
  21.330 +		/* Wake events only supported on port A for dual fiber */
  21.331 +		if(E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1) {
  21.332 +			wol->supported = 0;
  21.333 +			wol->wolopts   = 0;
  21.334 +			return;
  21.335 +		}
  21.336 +		/* Fall Through */
  21.337 +
  21.338 +	default:
  21.339 +		wol->supported = WAKE_UCAST | WAKE_MCAST
  21.340 +			         | WAKE_BCAST | WAKE_MAGIC;
  21.341 +
  21.342 +		wol->wolopts = 0;
  21.343 +		if(adapter->wol & E1000_WUFC_EX)
  21.344 +			wol->wolopts |= WAKE_UCAST;
  21.345 +		if(adapter->wol & E1000_WUFC_MC)
  21.346 +			wol->wolopts |= WAKE_MCAST;
  21.347 +		if(adapter->wol & E1000_WUFC_BC)
  21.348 +			wol->wolopts |= WAKE_BCAST;
  21.349 +		if(adapter->wol & E1000_WUFC_MAG)
  21.350 +			wol->wolopts |= WAKE_MAGIC;
  21.351 +		return;
  21.352 +	}
  21.353 +}
  21.354 +
  21.355 +static int
  21.356 +e1000_ethtool_swol(struct e1000_adapter *adapter, struct ethtool_wolinfo *wol)
  21.357 +{
  21.358 +	struct e1000_hw *hw = &adapter->hw;
  21.359 +
  21.360 +	switch(adapter->hw.device_id) {
  21.361 +	case E1000_DEV_ID_82542:
  21.362 +	case E1000_DEV_ID_82543GC_FIBER:
  21.363 +	case E1000_DEV_ID_82543GC_COPPER:
  21.364 +	case E1000_DEV_ID_82544EI_FIBER:
  21.365 +		return wol->wolopts ? -EOPNOTSUPP : 0;
  21.366 +
  21.367 +	case E1000_DEV_ID_82546EB_FIBER:
  21.368 +		/* Wake events only supported on port A for dual fiber */
  21.369 +		if(E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
  21.370 +			return wol->wolopts ? -EOPNOTSUPP : 0;
  21.371 +		/* Fall Through */
  21.372 +
  21.373 +	default:
  21.374 +		if(wol->wolopts & (WAKE_ARP | WAKE_MAGICSECURE | WAKE_PHY))
  21.375 +			return -EOPNOTSUPP;
  21.376 +
  21.377 +		adapter->wol = 0;
  21.378 +
  21.379 +		if(wol->wolopts & WAKE_UCAST)
  21.380 +			adapter->wol |= E1000_WUFC_EX;
  21.381 +		if(wol->wolopts & WAKE_MCAST)
  21.382 +			adapter->wol |= E1000_WUFC_MC;
  21.383 +		if(wol->wolopts & WAKE_BCAST)
  21.384 +			adapter->wol |= E1000_WUFC_BC;
  21.385 +		if(wol->wolopts & WAKE_MAGIC)
  21.386 +			adapter->wol |= E1000_WUFC_MAG;
  21.387 +	}
  21.388 +
  21.389 +	return 0;
  21.390 +}
  21.391 +
  21.392 +
  21.393 +/* toggle LED 4 times per second = 2 "blinks" per second */
  21.394 +#define E1000_ID_INTERVAL	(HZ/4)
  21.395 +
  21.396 +/* bit defines for adapter->led_status */
  21.397 +#define E1000_LED_ON		0
  21.398 +
  21.399 +static void
  21.400 +e1000_led_blink_callback(unsigned long data)
  21.401 +{
  21.402 +	struct e1000_adapter *adapter = (struct e1000_adapter *) data;
  21.403 +
  21.404 +	if(test_and_change_bit(E1000_LED_ON, &adapter->led_status))
  21.405 +		e1000_led_off(&adapter->hw);
  21.406 +	else
  21.407 +		e1000_led_on(&adapter->hw);
  21.408 +
  21.409 +	mod_timer(&adapter->blink_timer, jiffies + E1000_ID_INTERVAL);
  21.410 +}
  21.411 +
  21.412 +static int
  21.413 +e1000_ethtool_led_blink(struct e1000_adapter *adapter, struct ethtool_value *id)
  21.414 +{
  21.415 +	if(!adapter->blink_timer.function) {
  21.416 +		init_timer(&adapter->blink_timer);
  21.417 +		adapter->blink_timer.function = e1000_led_blink_callback;
  21.418 +		adapter->blink_timer.data = (unsigned long) adapter;
  21.419 +	}
  21.420 +
  21.421 +	e1000_setup_led(&adapter->hw);
  21.422 +	mod_timer(&adapter->blink_timer, jiffies);
  21.423 +
  21.424 +	set_current_state(TASK_INTERRUPTIBLE);
  21.425 +	if(id->data)
  21.426 +		schedule_timeout(id->data * HZ);
  21.427 +	else
  21.428 +		schedule_timeout(MAX_SCHEDULE_TIMEOUT);
  21.429 +
  21.430 +	del_timer_sync(&adapter->blink_timer);
  21.431 +	e1000_led_off(&adapter->hw);
  21.432 +	clear_bit(E1000_LED_ON, &adapter->led_status);
  21.433 +	e1000_cleanup_led(&adapter->hw);
  21.434 +
  21.435 +	return 0;
  21.436 +}
  21.437 +
  21.438 +int
  21.439 +e1000_ethtool_ioctl(struct net_device *netdev, struct ifreq *ifr)
  21.440 +{
  21.441 +	struct e1000_adapter *adapter = netdev->priv;
  21.442 +	void *addr = ifr->ifr_data;
  21.443 +	uint32_t cmd;
  21.444 +
  21.445 +	if(get_user(cmd, (uint32_t *) addr))
  21.446 +		return -EFAULT;
  21.447 +
  21.448 +	switch(cmd) {
  21.449 +	case ETHTOOL_GSET: {
  21.450 +		struct ethtool_cmd ecmd = {ETHTOOL_GSET};
  21.451 +		e1000_ethtool_gset(adapter, &ecmd);
  21.452 +		if(copy_to_user(addr, &ecmd, sizeof(ecmd)))
  21.453 +			return -EFAULT;
  21.454 +		return 0;
  21.455 +	}
  21.456 +	case ETHTOOL_SSET: {
  21.457 +		struct ethtool_cmd ecmd;
  21.458 +		if(!capable(CAP_NET_ADMIN))
  21.459 +			return -EPERM;
  21.460 +		if(copy_from_user(&ecmd, addr, sizeof(ecmd)))
  21.461 +			return -EFAULT;
  21.462 +		return e1000_ethtool_sset(adapter, &ecmd);
  21.463 +	}
  21.464 +	case ETHTOOL_GDRVINFO: {
  21.465 +		struct ethtool_drvinfo drvinfo = {ETHTOOL_GDRVINFO};
  21.466 +		e1000_ethtool_gdrvinfo(adapter, &drvinfo);
  21.467 +		if(copy_to_user(addr, &drvinfo, sizeof(drvinfo)))
  21.468 +			return -EFAULT;
  21.469 +		return 0;
  21.470 +	}
  21.471 +	case ETHTOOL_GSTRINGS: {
  21.472 +		struct ethtool_gstrings gstrings = { ETHTOOL_GSTRINGS };
  21.473 +		char *strings = NULL;
  21.474 +
  21.475 +		if(copy_from_user(&gstrings, addr, sizeof(gstrings)))
  21.476 +			return -EFAULT;
  21.477 +		switch(gstrings.string_set) {
  21.478 +		case ETH_SS_STATS:
  21.479 +			gstrings.len = E1000_STATS_LEN;
  21.480 +			strings = *e1000_gstrings_stats;
  21.481 +			break;
  21.482 +		default:
  21.483 +			return -EOPNOTSUPP;
  21.484 +		}
  21.485 +		if(copy_to_user(addr, &gstrings, sizeof(gstrings)))
  21.486 +			return -EFAULT;
  21.487 +		addr += offsetof(struct ethtool_gstrings, data);
  21.488 +		if(copy_to_user(addr, strings,
  21.489 +		   gstrings.len * ETH_GSTRING_LEN))
  21.490 +			return -EFAULT;
  21.491 +		return 0;
  21.492 +	}
  21.493 +	case ETHTOOL_GREGS: {
  21.494 +		struct ethtool_regs regs = {ETHTOOL_GREGS};
  21.495 +		uint32_t regs_buff[E1000_REGS_LEN];
  21.496 +
  21.497 +		if(copy_from_user(&regs, addr, sizeof(regs)))
  21.498 +			return -EFAULT;
  21.499 +		e1000_ethtool_gregs(adapter, &regs, regs_buff);
  21.500 +		if(copy_to_user(addr, &regs, sizeof(regs)))
  21.501 +			return -EFAULT;
  21.502 +
  21.503 +		addr += offsetof(struct ethtool_regs, data);
  21.504 +		if(copy_to_user(addr, regs_buff, regs.len))
  21.505 +			return -EFAULT;
  21.506 +
  21.507 +		return 0;
  21.508 +	}
  21.509 +	case ETHTOOL_NWAY_RST: {
  21.510 +		if(!capable(CAP_NET_ADMIN))
  21.511 +			return -EPERM;
  21.512 +		if(netif_running(netdev)) {
  21.513 +			e1000_down(adapter);
  21.514 +			e1000_up(adapter);
  21.515 +		}
  21.516 +		return 0;
  21.517 +	}
  21.518 +	case ETHTOOL_PHYS_ID: {
  21.519 +		struct ethtool_value id;
  21.520 +		if(copy_from_user(&id, addr, sizeof(id)))
  21.521 +			return -EFAULT;
  21.522 +		return e1000_ethtool_led_blink(adapter, &id);
  21.523 +	}
  21.524 +	case ETHTOOL_GLINK: {
  21.525 +		struct ethtool_value link = {ETHTOOL_GLINK};
  21.526 +		link.data = netif_carrier_ok(netdev);
  21.527 +		if(copy_to_user(addr, &link, sizeof(link)))
  21.528 +			return -EFAULT;
  21.529 +		return 0;
  21.530 +	}
  21.531 +	case ETHTOOL_GWOL: {
  21.532 +		struct ethtool_wolinfo wol = {ETHTOOL_GWOL};
  21.533 +		e1000_ethtool_gwol(adapter, &wol);
  21.534 +		if(copy_to_user(addr, &wol, sizeof(wol)) != 0)
  21.535 +			return -EFAULT;
  21.536 +		return 0;
  21.537 +	}
  21.538 +	case ETHTOOL_SWOL: {
  21.539 +		struct ethtool_wolinfo wol;
  21.540 +		if(!capable(CAP_NET_ADMIN))
  21.541 +			return -EPERM;
  21.542 +		if(copy_from_user(&wol, addr, sizeof(wol)) != 0)
  21.543 +			return -EFAULT;
  21.544 +		return e1000_ethtool_swol(adapter, &wol);
  21.545 +	}
  21.546 +	case ETHTOOL_GEEPROM: {
  21.547 +		struct ethtool_eeprom eeprom = {ETHTOOL_GEEPROM};
  21.548 +		uint16_t *eeprom_buff;
  21.549 +		void *ptr;
  21.550 +		int max_len, err = 0;
  21.551 +
  21.552 +		max_len = e1000_eeprom_size(&adapter->hw);
  21.553 +
  21.554 +		eeprom_buff = kmalloc(max_len, GFP_KERNEL);
  21.555 +
  21.556 +		if(eeprom_buff == NULL)
  21.557 +			return -ENOMEM;
  21.558 +
  21.559 +		if(copy_from_user(&eeprom, addr, sizeof(eeprom))) {
  21.560 +			err = -EFAULT;
  21.561 +			goto err_geeprom_ioctl;
  21.562 +		}
  21.563 +
  21.564 +		if((err = e1000_ethtool_geeprom(adapter, &eeprom,
  21.565 +						eeprom_buff)))
  21.566 +			goto err_geeprom_ioctl;
  21.567 +
  21.568 +		if(copy_to_user(addr, &eeprom, sizeof(eeprom))) {
  21.569 +			err = -EFAULT;
  21.570 +			goto err_geeprom_ioctl;
  21.571 +		}
  21.572 +
  21.573 +		addr += offsetof(struct ethtool_eeprom, data);
  21.574 +		ptr = ((void *)eeprom_buff) + (eeprom.offset & 1);
  21.575 +
  21.576 +		if(copy_to_user(addr, ptr, eeprom.len))
  21.577 +			err = -EFAULT;
  21.578 +
  21.579 +err_geeprom_ioctl:
  21.580 +		kfree(eeprom_buff);
  21.581 +		return err;
  21.582 +	}
  21.583 +	case ETHTOOL_SEEPROM: {
  21.584 +		struct ethtool_eeprom eeprom;
  21.585 +
  21.586 +		if(!capable(CAP_NET_ADMIN))
  21.587 +			return -EPERM;
  21.588 +
  21.589 +		if(copy_from_user(&eeprom, addr, sizeof(eeprom)))
  21.590 +			return -EFAULT;
  21.591 +
  21.592 +		addr += offsetof(struct ethtool_eeprom, data);
  21.593 +		return e1000_ethtool_seeprom(adapter, &eeprom, addr);
  21.594 +	}
  21.595 +	case ETHTOOL_GSTATS: {
  21.596 +		struct {
  21.597 +			struct ethtool_stats cmd;
  21.598 +			uint64_t data[E1000_STATS_LEN];
  21.599 +		} stats = { {ETHTOOL_GSTATS, E1000_STATS_LEN} };
  21.600 +		int i;
  21.601 +
  21.602 +		for(i = 0; i < E1000_STATS_LEN; i++)
  21.603 +			stats.data[i] =
  21.604 +				((unsigned long *)&adapter->net_stats)[i];
  21.605 +		if(copy_to_user(addr, &stats, sizeof(stats)))
  21.606 +			return -EFAULT;
  21.607 +		return 0;
  21.608 +	}
  21.609 +	default:
  21.610 +		return -EOPNOTSUPP;
  21.611 +	}
  21.612 +}
  21.613 +
  21.614 +
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/xen-2.4.16/drivers/net/e1000/e1000_hw.c	Tue Feb 11 13:05:51 2003 +0000
    22.3 @@ -0,0 +1,3610 @@
    22.4 +/*******************************************************************************
    22.5 +
    22.6 +  
    22.7 +  Copyright(c) 1999 - 2002 Intel Corporation. All rights reserved.
    22.8 +  
    22.9 +  This program is free software; you can redistribute it and/or modify it 
   22.10 +  under the terms of the GNU General Public License as published by the Free 
   22.11 +  Software Foundation; either version 2 of the License, or (at your option) 
   22.12 +  any later version.
   22.13 +  
   22.14 +  This program is distributed in the hope that it will be useful, but WITHOUT 
   22.15 +  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
   22.16 +  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
   22.17 +  more details.
   22.18 +  
   22.19 +  You should have received a copy of the GNU General Public License along with
   22.20 +  this program; if not, write to the Free Software Foundation, Inc., 59 
   22.21 +  Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   22.22 +  
   22.23 +  The full GNU General Public License is included in this distribution in the
   22.24 +  file called LICENSE.
   22.25 +  
   22.26 +  Contact Information:
   22.27 +  Linux NICS <linux.nics@intel.com>
   22.28 +  Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
   22.29 +
   22.30 +*******************************************************************************/
   22.31 +
   22.32 +/* e1000_hw.c
   22.33 + * Shared functions for accessing and configuring the MAC
   22.34 + */
   22.35 +
   22.36 +#include "e1000_hw.h"
   22.37 +
   22.38 +static int32_t e1000_setup_fiber_link(struct e1000_hw *hw);
   22.39 +static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
   22.40 +static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
   22.41 +static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
   22.42 +static int32_t e1000_force_mac_fc(struct e1000_hw *hw);
   22.43 +static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
   22.44 +static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
   22.45 +static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data, uint16_t count);
   22.46 +static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
   22.47 +static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
   22.48 +static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
   22.49 +static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
   22.50 +static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data, uint16_t count);
   22.51 +static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw);
   22.52 +static void e1000_setup_eeprom(struct e1000_hw *hw);
   22.53 +static void e1000_clock_eeprom(struct e1000_hw *hw);
   22.54 +static void e1000_cleanup_eeprom(struct e1000_hw *hw);
   22.55 +static void e1000_standby_eeprom(struct e1000_hw *hw);
   22.56 +static int32_t e1000_id_led_init(struct e1000_hw * hw);
   22.57 +
   22.58 +/******************************************************************************
   22.59 + * Set the mac type member in the hw struct.
   22.60 + * 
   22.61 + * hw - Struct containing variables accessed by shared code
   22.62 + *****************************************************************************/
   22.63 +int32_t
   22.64 +e1000_set_mac_type(struct e1000_hw *hw)
   22.65 +{
   22.66 +    DEBUGFUNC("e1000_set_mac_type");
   22.67 +
   22.68 +    switch (hw->device_id) {
   22.69 +    case E1000_DEV_ID_82542:
   22.70 +        switch (hw->revision_id) {
   22.71 +        case E1000_82542_2_0_REV_ID:
   22.72 +            hw->mac_type = e1000_82542_rev2_0;
   22.73 +            break;
   22.74 +        case E1000_82542_2_1_REV_ID:
   22.75 +            hw->mac_type = e1000_82542_rev2_1;
   22.76 +            break;
   22.77 +        default:
   22.78 +            /* Invalid 82542 revision ID */
   22.79 +            return -E1000_ERR_MAC_TYPE;
   22.80 +        }
   22.81 +        break;
   22.82 +    case E1000_DEV_ID_82543GC_FIBER:
   22.83 +    case E1000_DEV_ID_82543GC_COPPER:
   22.84 +        hw->mac_type = e1000_82543;
   22.85 +        break;
   22.86 +    case E1000_DEV_ID_82544EI_COPPER:
   22.87 +    case E1000_DEV_ID_82544EI_FIBER:
   22.88 +    case E1000_DEV_ID_82544GC_COPPER:
   22.89 +    case E1000_DEV_ID_82544GC_LOM:
   22.90 +        hw->mac_type = e1000_82544;
   22.91 +        break;
   22.92 +    case E1000_DEV_ID_82540EM:
   22.93 +    case E1000_DEV_ID_82540EM_LOM:
   22.94 +    case E1000_DEV_ID_82540EP:
   22.95 +    case E1000_DEV_ID_82540EP_LOM:
   22.96 +    case E1000_DEV_ID_82540EP_LP:
   22.97 +        hw->mac_type = e1000_82540;
   22.98 +        break;
   22.99 +    case E1000_DEV_ID_82545EM_COPPER:
  22.100 +    case E1000_DEV_ID_82545EM_FIBER:
  22.101 +        hw->mac_type = e1000_82545;
  22.102 +        break;
  22.103 +    case E1000_DEV_ID_82546EB_COPPER:
  22.104 +    case E1000_DEV_ID_82546EB_FIBER:
  22.105 +        hw->mac_type = e1000_82546;
  22.106 +        break;
  22.107 +    default:
  22.108 +        /* Should never have loaded on this device */
  22.109 +        return -E1000_ERR_MAC_TYPE;
  22.110 +    }
  22.111 +    return E1000_SUCCESS;
  22.112 +}
  22.113 +/******************************************************************************
  22.114 + * Reset the transmit and receive units; mask and clear all interrupts.
  22.115 + *
  22.116 + * hw - Struct containing variables accessed by shared code
  22.117 + *****************************************************************************/
  22.118 +void
  22.119 +e1000_reset_hw(struct e1000_hw *hw)
  22.120 +{
  22.121 +    uint32_t ctrl;
  22.122 +    uint32_t ctrl_ext;
  22.123 +    uint32_t icr;
  22.124 +    uint32_t manc;
  22.125 +
  22.126 +    DEBUGFUNC("e1000_reset_hw");
  22.127 +    /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
  22.128 +    if(hw->mac_type == e1000_82542_rev2_0) {
  22.129 +        DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
  22.130 +        e1000_pci_clear_mwi(hw);
  22.131 +    }
  22.132 +
  22.133 +    /* Clear interrupt mask to stop board from generating interrupts */
  22.134 +    DEBUGOUT("Masking off all interrupts\n");
  22.135 +    E1000_WRITE_REG(hw, IMC, 0xffffffff);
  22.136 +
  22.137 +    /* Disable the Transmit and Receive units.  Then delay to allow
  22.138 +     * any pending transactions to complete before we hit the MAC with
  22.139 +     * the global reset.
  22.140 +     */
  22.141 +    E1000_WRITE_REG(hw, RCTL, 0);
  22.142 +    E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
  22.143 +    E1000_WRITE_FLUSH(hw);
  22.144 +
  22.145 +    /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
  22.146 +    hw->tbi_compatibility_on = FALSE;
  22.147 +
  22.148 +    /* Delay to allow any outstanding PCI transactions to complete before
  22.149 +     * resetting the device
  22.150 +     */ 
  22.151 +    DEBUGOUT("Before delay\n");
  22.152 +    msec_delay(10);
  22.153 +
  22.154 +    /* Issue a global reset to the MAC.  This will reset the chip's
  22.155 +     * transmit, receive, DMA, and link units.  It will not effect
  22.156 +     * the current PCI configuration.  The global reset bit is self-
  22.157 +     * clearing, and should clear within a microsecond.
  22.158 +     */
  22.159 +    DEBUGOUT("Issuing a global reset to MAC\n");
  22.160 +    ctrl = E1000_READ_REG(hw, CTRL);
  22.161 +
  22.162 +    if(hw->mac_type > e1000_82543)
  22.163 +        E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
  22.164 +    else
  22.165 +        E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
  22.166 +
  22.167 +    /* Force a reload from the EEPROM if necessary */
  22.168 +    if(hw->mac_type < e1000_82540) {
  22.169 +        /* Wait for reset to complete */
  22.170 +        udelay(10);
  22.171 +        ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  22.172 +        ctrl_ext |= E1000_CTRL_EXT_EE_RST;
  22.173 +        E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  22.174 +        E1000_WRITE_FLUSH(hw);
  22.175 +        /* Wait for EEPROM reload */
  22.176 +        msec_delay(2);
  22.177 +    } else {
  22.178 +        /* Wait for EEPROM reload (it happens automatically) */
  22.179 +        msec_delay(4);
  22.180 +        /* Dissable HW ARPs on ASF enabled adapters */
  22.181 +        manc = E1000_READ_REG(hw, MANC);
  22.182 +        manc &= ~(E1000_MANC_ARP_EN);
  22.183 +        E1000_WRITE_REG(hw, MANC, manc);
  22.184 +    }
  22.185 +    
  22.186 +    /* Clear interrupt mask to stop board from generating interrupts */
  22.187 +    DEBUGOUT("Masking off all interrupts\n");
  22.188 +    E1000_WRITE_REG(hw, IMC, 0xffffffff);
  22.189 +
  22.190 +    /* Clear any pending interrupt events. */
  22.191 +    icr = E1000_READ_REG(hw, ICR);
  22.192 +
  22.193 +    /* If MWI was previously enabled, reenable it. */
  22.194 +    if(hw->mac_type == e1000_82542_rev2_0) {
  22.195 +        if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
  22.196 +            e1000_pci_set_mwi(hw);
  22.197 +    }
  22.198 +}
  22.199 +
  22.200 +/******************************************************************************
  22.201 + * Performs basic configuration of the adapter.
  22.202 + *
  22.203 + * hw - Struct containing variables accessed by shared code
  22.204 + * 
  22.205 + * Assumes that the controller has previously been reset and is in a 
  22.206 + * post-reset uninitialized state. Initializes the receive address registers,
  22.207 + * multicast table, and VLAN filter table. Calls routines to setup link
  22.208 + * configuration and flow control settings. Clears all on-chip counters. Leaves
  22.209 + * the transmit and receive units disabled and uninitialized.
  22.210 + *****************************************************************************/
  22.211 +int32_t
  22.212 +e1000_init_hw(struct e1000_hw *hw)
  22.213 +{
  22.214 +    uint32_t ctrl, status;
  22.215 +    uint32_t i;
  22.216 +    int32_t ret_val;
  22.217 +    uint16_t pcix_cmd_word;
  22.218 +    uint16_t pcix_stat_hi_word;
  22.219 +    uint16_t cmd_mmrbc;
  22.220 +    uint16_t stat_mmrbc;
  22.221 +
  22.222 +    DEBUGFUNC("e1000_init_hw");
  22.223 +
  22.224 +    /* Initialize Identification LED */
  22.225 +    ret_val = e1000_id_led_init(hw);
  22.226 +    if(ret_val < 0) {
  22.227 +        DEBUGOUT("Error Initializing Identification LED\n");
  22.228 +        return ret_val;
  22.229 +    }
  22.230 +    
  22.231 +    /* Set the Media Type and exit with error if it is not valid. */
  22.232 +    if(hw->mac_type != e1000_82543) {
  22.233 +        /* tbi_compatibility is only valid on 82543 */
  22.234 +        hw->tbi_compatibility_en = FALSE;
  22.235 +    }
  22.236 +
  22.237 +    if(hw->mac_type >= e1000_82543) {
  22.238 +        status = E1000_READ_REG(hw, STATUS);
  22.239 +        if(status & E1000_STATUS_TBIMODE) {
  22.240 +            hw->media_type = e1000_media_type_fiber;
  22.241 +            /* tbi_compatibility not valid on fiber */
  22.242 +            hw->tbi_compatibility_en = FALSE;
  22.243 +        } else {
  22.244 +            hw->media_type = e1000_media_type_copper;
  22.245 +        }
  22.246 +    } else {
  22.247 +        /* This is an 82542 (fiber only) */
  22.248 +        hw->media_type = e1000_media_type_fiber;
  22.249 +    }
  22.250 +
  22.251 +    /* Disabling VLAN filtering. */
  22.252 +    DEBUGOUT("Initializing the IEEE VLAN\n");
  22.253 +    E1000_WRITE_REG(hw, VET, 0);
  22.254 +
  22.255 +    e1000_clear_vfta(hw);
  22.256 +
  22.257 +    /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
  22.258 +    if(hw->mac_type == e1000_82542_rev2_0) {
  22.259 +        DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
  22.260 +        e1000_pci_clear_mwi(hw);
  22.261 +        E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
  22.262 +        E1000_WRITE_FLUSH(hw);
  22.263 +        msec_delay(5);
  22.264 +    }
  22.265 +
  22.266 +    /* Setup the receive address. This involves initializing all of the Receive
  22.267 +     * Address Registers (RARs 0 - 15).
  22.268 +     */
  22.269 +    e1000_init_rx_addrs(hw);
  22.270 +
  22.271 +    /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
  22.272 +    if(hw->mac_type == e1000_82542_rev2_0) {
  22.273 +        E1000_WRITE_REG(hw, RCTL, 0);
  22.274 +        E1000_WRITE_FLUSH(hw);
  22.275 +        msec_delay(1);
  22.276 +        if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
  22.277 +            e1000_pci_set_mwi(hw);
  22.278 +    }
  22.279 +
  22.280 +    /* Zero out the Multicast HASH table */
  22.281 +    DEBUGOUT("Zeroing the MTA\n");
  22.282 +    for(i = 0; i < E1000_MC_TBL_SIZE; i++)
  22.283 +        E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
  22.284 +
  22.285 +    /* Set the PCI priority bit correctly in the CTRL register.  This
  22.286 +     * determines if the adapter gives priority to receives, or if it
  22.287 +     * gives equal priority to transmits and receives.
  22.288 +     */
  22.289 +    if(hw->dma_fairness) {
  22.290 +        ctrl = E1000_READ_REG(hw, CTRL);
  22.291 +        E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
  22.292 +    }
  22.293 +
  22.294 +    /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
  22.295 +    if(hw->bus_type == e1000_bus_type_pcix) {
  22.296 +        e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
  22.297 +        e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI, &pcix_stat_hi_word);
  22.298 +        cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
  22.299 +            PCIX_COMMAND_MMRBC_SHIFT;
  22.300 +        stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
  22.301 +            PCIX_STATUS_HI_MMRBC_SHIFT;
  22.302 +        if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
  22.303 +            stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
  22.304 +        if(cmd_mmrbc > stat_mmrbc) {
  22.305 +            pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
  22.306 +            pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
  22.307 +            e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
  22.308 +        }
  22.309 +    }
  22.310 +
  22.311 +    /* Call a subroutine to configure the link and setup flow control. */
  22.312 +    ret_val = e1000_setup_link(hw);
  22.313 +
  22.314 +    /* Set the transmit descriptor write-back policy */
  22.315 +    if(hw->mac_type > e1000_82544) {
  22.316 +        ctrl = E1000_READ_REG(hw, TXDCTL);
  22.317 +        ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
  22.318 +        E1000_WRITE_REG(hw, TXDCTL, ctrl);
  22.319 +    }
  22.320 +
  22.321 +    /* Clear all of the statistics registers (clear on read).  It is
  22.322 +     * important that we do this after we have tried to establish link
  22.323 +     * because the symbol error count will increment wildly if there
  22.324 +     * is no link.
  22.325 +     */
  22.326 +    e1000_clear_hw_cntrs(hw);
  22.327 +
  22.328 +    return ret_val;
  22.329 +}
  22.330 +
  22.331 +/******************************************************************************
  22.332 + * Configures flow control and link settings.
  22.333 + * 
  22.334 + * hw - Struct containing variables accessed by shared code
  22.335 + * 
  22.336 + * Determines which flow control settings to use. Calls the apropriate media-
  22.337 + * specific link configuration function. Configures the flow control settings.
  22.338 + * Assuming the adapter has a valid link partner, a valid link should be
  22.339 + * established. Assumes the hardware has previously been reset and the 
  22.340 + * transmitter and receiver are not enabled.
  22.341 + *****************************************************************************/
  22.342 +int32_t
  22.343 +e1000_setup_link(struct e1000_hw *hw)
  22.344 +{
  22.345 +    uint32_t ctrl_ext;
  22.346 +    int32_t ret_val;
  22.347 +    uint16_t eeprom_data;
  22.348 +
  22.349 +    DEBUGFUNC("e1000_setup_link");
  22.350 +
  22.351 +    /* Read and store word 0x0F of the EEPROM. This word contains bits
  22.352 +     * that determine the hardware's default PAUSE (flow control) mode,
  22.353 +     * a bit that determines whether the HW defaults to enabling or
  22.354 +     * disabling auto-negotiation, and the direction of the
  22.355 +     * SW defined pins. If there is no SW over-ride of the flow
  22.356 +     * control setting, then the variable hw->fc will
  22.357 +     * be initialized based on a value in the EEPROM.
  22.358 +     */
  22.359 +    if(e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, &eeprom_data) < 0) {
  22.360 +        DEBUGOUT("EEPROM Read Error\n");
  22.361 +        return -E1000_ERR_EEPROM;
  22.362 +    }
  22.363 +
  22.364 +    if(hw->fc == e1000_fc_default) {
  22.365 +        if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
  22.366 +            hw->fc = e1000_fc_none;
  22.367 +        else if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 
  22.368 +                EEPROM_WORD0F_ASM_DIR)
  22.369 +            hw->fc = e1000_fc_tx_pause;
  22.370 +        else
  22.371 +            hw->fc = e1000_fc_full;
  22.372 +    }
  22.373 +
  22.374 +    /* We want to save off the original Flow Control configuration just
  22.375 +     * in case we get disconnected and then reconnected into a different
  22.376 +     * hub or switch with different Flow Control capabilities.
  22.377 +     */
  22.378 +    if(hw->mac_type == e1000_82542_rev2_0)
  22.379 +        hw->fc &= (~e1000_fc_tx_pause);
  22.380 +
  22.381 +    if((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
  22.382 +        hw->fc &= (~e1000_fc_rx_pause);
  22.383 +
  22.384 +    hw->original_fc = hw->fc;
  22.385 +
  22.386 +    DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
  22.387 +
  22.388 +    /* Take the 4 bits from EEPROM word 0x0F that determine the initial
  22.389 +     * polarity value for the SW controlled pins, and setup the
  22.390 +     * Extended Device Control reg with that info.
  22.391 +     * This is needed because one of the SW controlled pins is used for
  22.392 +     * signal detection.  So this should be done before e1000_setup_pcs_link()
  22.393 +     * or e1000_phy_setup() is called.
  22.394 +     */
  22.395 +    if(hw->mac_type == e1000_82543) {
  22.396 +        ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) << 
  22.397 +                    SWDPIO__EXT_SHIFT);
  22.398 +        E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  22.399 +    }
  22.400 +
  22.401 +    /* Call the necessary subroutine to configure the link. */
  22.402 +    ret_val = (hw->media_type == e1000_media_type_fiber) ?
  22.403 +              e1000_setup_fiber_link(hw) :
  22.404 +              e1000_setup_copper_link(hw);
  22.405 +
  22.406 +    /* Initialize the flow control address, type, and PAUSE timer
  22.407 +     * registers to their default values.  This is done even if flow
  22.408 +     * control is disabled, because it does not hurt anything to
  22.409 +     * initialize these registers.
  22.410 +     */
  22.411 +    DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
  22.412 +
  22.413 +    E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
  22.414 +    E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
  22.415 +    E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
  22.416 +    E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
  22.417 +
  22.418 +    /* Set the flow control receive threshold registers.  Normally,
  22.419 +     * these registers will be set to a default threshold that may be
  22.420 +     * adjusted later by the driver's runtime code.  However, if the
  22.421 +     * ability to transmit pause frames in not enabled, then these
  22.422 +     * registers will be set to 0. 
  22.423 +     */
  22.424 +    if(!(hw->fc & e1000_fc_tx_pause)) {
  22.425 +        E1000_WRITE_REG(hw, FCRTL, 0);
  22.426 +        E1000_WRITE_REG(hw, FCRTH, 0);
  22.427 +    } else {
  22.428 +        /* We need to set up the Receive Threshold high and low water marks
  22.429 +         * as well as (optionally) enabling the transmission of XON frames.
  22.430 +         */
  22.431 +        if(hw->fc_send_xon) {
  22.432 +            E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
  22.433 +            E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
  22.434 +        } else {
  22.435 +            E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
  22.436 +            E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
  22.437 +        }
  22.438 +    }
  22.439 +    return ret_val;
  22.440 +}
  22.441 +
  22.442 +/******************************************************************************
  22.443 + * Sets up link for a fiber based adapter
  22.444 + *
  22.445 + * hw - Struct containing variables accessed by shared code
  22.446 + *
  22.447 + * Manipulates Physical Coding Sublayer functions in order to configure
  22.448 + * link. Assumes the hardware has been previously reset and the transmitter
  22.449 + * and receiver are not enabled.
  22.450 + *****************************************************************************/
  22.451 +static int32_t 
  22.452 +e1000_setup_fiber_link(struct e1000_hw *hw)
  22.453 +{
  22.454 +    uint32_t ctrl;
  22.455 +    uint32_t status;
  22.456 +    uint32_t txcw = 0;
  22.457 +    uint32_t i;
  22.458 +    uint32_t signal;
  22.459 +    int32_t ret_val;
  22.460 +
  22.461 +    DEBUGFUNC("e1000_setup_fiber_link");
  22.462 +
  22.463 +    /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be 
  22.464 +     * set when the optics detect a signal. On older adapters, it will be 
  22.465 +     * cleared when there is a signal
  22.466 +     */
  22.467 +    ctrl = E1000_READ_REG(hw, CTRL);
  22.468 +    if(hw->mac_type > e1000_82544) signal = E1000_CTRL_SWDPIN1;
  22.469 +    else signal = 0;
  22.470 +   
  22.471 +    /* Take the link out of reset */
  22.472 +    ctrl &= ~(E1000_CTRL_LRST);
  22.473 +    
  22.474 +    e1000_config_collision_dist(hw);
  22.475 +
  22.476 +    /* Check for a software override of the flow control settings, and setup
  22.477 +     * the device accordingly.  If auto-negotiation is enabled, then software
  22.478 +     * will have to set the "PAUSE" bits to the correct value in the Tranmsit
  22.479 +     * Config Word Register (TXCW) and re-start auto-negotiation.  However, if
  22.480 +     * auto-negotiation is disabled, then software will have to manually 
  22.481 +     * configure the two flow control enable bits in the CTRL register.
  22.482 +     *
  22.483 +     * The possible values of the "fc" parameter are:
  22.484 +     *      0:  Flow control is completely disabled
  22.485 +     *      1:  Rx flow control is enabled (we can receive pause frames, but 
  22.486 +     *          not send pause frames).
  22.487 +     *      2:  Tx flow control is enabled (we can send pause frames but we do
  22.488 +     *          not support receiving pause frames).
  22.489 +     *      3:  Both Rx and TX flow control (symmetric) are enabled.
  22.490 +     */
  22.491 +    switch (hw->fc) {
  22.492 +    case e1000_fc_none:
  22.493 +        /* Flow control is completely disabled by a software over-ride. */
  22.494 +        txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
  22.495 +        break;
  22.496 +    case e1000_fc_rx_pause:
  22.497 +        /* RX Flow control is enabled and TX Flow control is disabled by a 
  22.498 +         * software over-ride. Since there really isn't a way to advertise 
  22.499 +         * that we are capable of RX Pause ONLY, we will advertise that we
  22.500 +         * support both symmetric and asymmetric RX PAUSE. Later, we will
  22.501 +         *  disable the adapter's ability to send PAUSE frames.
  22.502 +         */
  22.503 +        txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  22.504 +        break;
  22.505 +    case e1000_fc_tx_pause:
  22.506 +        /* TX Flow control is enabled, and RX Flow control is disabled, by a 
  22.507 +         * software over-ride.
  22.508 +         */
  22.509 +        txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
  22.510 +        break;
  22.511 +    case e1000_fc_full:
  22.512 +        /* Flow control (both RX and TX) is enabled by a software over-ride. */
  22.513 +        txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  22.514 +        break;
  22.515 +    default:
  22.516 +        DEBUGOUT("Flow control param set incorrectly\n");
  22.517 +        return -E1000_ERR_CONFIG;
  22.518 +        break;
  22.519 +    }
  22.520 +
  22.521 +    /* Since auto-negotiation is enabled, take the link out of reset (the link
  22.522 +     * will be in reset, because we previously reset the chip). This will
  22.523 +     * restart auto-negotiation.  If auto-neogtiation is successful then the
  22.524 +     * link-up status bit will be set and the flow control enable bits (RFCE
  22.525 +     * and TFCE) will be set according to their negotiated value.
  22.526 +     */
  22.527 +    DEBUGOUT("Auto-negotiation enabled\n");
  22.528 +
  22.529 +    E1000_WRITE_REG(hw, TXCW, txcw);
  22.530 +    E1000_WRITE_REG(hw, CTRL, ctrl);
  22.531 +    E1000_WRITE_FLUSH(hw);
  22.532 +
  22.533 +    hw->txcw = txcw;
  22.534 +    msec_delay(1);
  22.535 +
  22.536 +    /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
  22.537 +     * indication in the Device Status Register.  Time-out if a link isn't 
  22.538 +     * seen in 500 milliseconds seconds (Auto-negotiation should complete in 
  22.539 +     * less than 500 milliseconds even if the other end is doing it in SW).
  22.540 +     */
  22.541 +    if((E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
  22.542 +        DEBUGOUT("Looking for Link\n");
  22.543 +        for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
  22.544 +            msec_delay(10);
  22.545 +            status = E1000_READ_REG(hw, STATUS);
  22.546 +            if(status & E1000_STATUS_LU) break;
  22.547 +        }
  22.548 +        if(i == (LINK_UP_TIMEOUT / 10)) {
  22.549 +            /* AutoNeg failed to achieve a link, so we'll call 
  22.550 +             * e1000_check_for_link. This routine will force the link up if we
  22.551 +             * detect a signal. This will allow us to communicate with
  22.552 +             * non-autonegotiating link partners.
  22.553 +             */
  22.554 +            DEBUGOUT("Never got a valid link from auto-neg!!!\n");
  22.555 +            hw->autoneg_failed = 1;
  22.556 +            ret_val = e1000_check_for_link(hw);
  22.557 +            if(ret_val < 0) {
  22.558 +                DEBUGOUT("Error while checking for link\n");
  22.559 +                return ret_val;
  22.560 +            }
  22.561 +            hw->autoneg_failed = 0;
  22.562 +        } else {
  22.563 +            hw->autoneg_failed = 0;
  22.564 +            DEBUGOUT("Valid Link Found\n");
  22.565 +        }
  22.566 +    } else {
  22.567 +        DEBUGOUT("No Signal Detected\n");
  22.568 +    }
  22.569 +    return 0;
  22.570 +}
  22.571 +
  22.572 +/******************************************************************************
  22.573 +* Detects which PHY is present and the speed and duplex
  22.574 +*
  22.575 +* hw - Struct containing variables accessed by shared code
  22.576 +******************************************************************************/
  22.577 +static int32_t 
  22.578 +e1000_setup_copper_link(struct e1000_hw *hw)
  22.579 +{
  22.580 +    uint32_t ctrl;
  22.581 +    int32_t ret_val;
  22.582 +    uint16_t i;
  22.583 +    uint16_t phy_data;
  22.584 +
  22.585 +    DEBUGFUNC("e1000_setup_copper_link");
  22.586 +
  22.587 +    ctrl = E1000_READ_REG(hw, CTRL);
  22.588 +    /* With 82543, we need to force speed and duplex on the MAC equal to what
  22.589 +     * the PHY speed and duplex configuration is. In addition, we need to
  22.590 +     * perform a hardware reset on the PHY to take it out of reset.
  22.591 +     */
  22.592 +    if(hw->mac_type > e1000_82543) {
  22.593 +        ctrl |= E1000_CTRL_SLU;
  22.594 +        ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  22.595 +        E1000_WRITE_REG(hw, CTRL, ctrl);
  22.596 +    } else {
  22.597 +        ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
  22.598 +        E1000_WRITE_REG(hw, CTRL, ctrl);
  22.599 +        e1000_phy_hw_reset(hw);
  22.600 +    }
  22.601 +
  22.602 +    /* Make sure we have a valid PHY */
  22.603 +    ret_val = e1000_detect_gig_phy(hw);
  22.604 +    if(ret_val < 0) {
  22.605 +        DEBUGOUT("Error, did not detect valid phy.\n");
  22.606 +        return ret_val;
  22.607 +    }
  22.608 +    DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
  22.609 +
  22.610 +    /* Enable CRS on TX. This must be set for half-duplex operation. */
  22.611 +    if(e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data) < 0) {
  22.612 +        DEBUGOUT("PHY Read Error\n");
  22.613 +        return -E1000_ERR_PHY;
  22.614 +    }
  22.615 +    phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  22.616 +
  22.617 +    /* Options:
  22.618 +     *   MDI/MDI-X = 0 (default)
  22.619 +     *   0 - Auto for all speeds
  22.620 +     *   1 - MDI mode
  22.621 +     *   2 - MDI-X mode
  22.622 +     *   3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
  22.623 +     */
  22.624 +    phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  22.625 +
  22.626 +    switch (hw->mdix) {
  22.627 +    case 1:
  22.628 +        phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
  22.629 +        break;
  22.630 +    case 2:
  22.631 +        phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
  22.632 +        break;
  22.633 +    case 3:
  22.634 +        phy_data |= M88E1000_PSCR_AUTO_X_1000T;
  22.635 +        break;
  22.636 +    case 0:
  22.637 +    default:
  22.638 +        phy_data |= M88E1000_PSCR_AUTO_X_MODE;
  22.639 +        break;
  22.640 +    }
  22.641 +
  22.642 +    /* Options:
  22.643 +     *   disable_polarity_correction = 0 (default)
  22.644 +     *       Automatic Correction for Reversed Cable Polarity
  22.645 +     *   0 - Disabled
  22.646 +     *   1 - Enabled
  22.647 +     */
  22.648 +    phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
  22.649 +    if(hw->disable_polarity_correction == 1)
  22.650 +        phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
  22.651 +    if(e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data) < 0) {
  22.652 +        DEBUGOUT("PHY Write Error\n");
  22.653 +        return -E1000_ERR_PHY;
  22.654 +    }
  22.655 +
  22.656 +    /* Force TX_CLK in the Extended PHY Specific Control Register
  22.657 +     * to 25MHz clock.
  22.658 +     */
  22.659 +    if(e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data) < 0) {
  22.660 +        DEBUGOUT("PHY Read Error\n");
  22.661 +        return -E1000_ERR_PHY;
  22.662 +    }
  22.663 +    phy_data |= M88E1000_EPSCR_TX_CLK_25;
  22.664 +
  22.665 +    if (hw->phy_revision < M88E1011_I_REV_4) {
  22.666 +        /* Configure Master and Slave downshift values */
  22.667 +        phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
  22.668 +                      M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
  22.669 +        phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
  22.670 +                     M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
  22.671 +        if(e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data) < 0) {
  22.672 +            DEBUGOUT("PHY Write Error\n");
  22.673 +            return -E1000_ERR_PHY;
  22.674 +        }
  22.675 +    }
  22.676 +
  22.677 +    /* SW Reset the PHY so all changes take effect */
  22.678 +    ret_val = e1000_phy_reset(hw);
  22.679 +    if(ret_val < 0) {
  22.680 +        DEBUGOUT("Error Resetting the PHY\n");
  22.681 +        return ret_val;
  22.682 +    }
  22.683 +    
  22.684 +    /* Options:
  22.685 +     *   autoneg = 1 (default)
  22.686 +     *      PHY will advertise value(s) parsed from
  22.687 +     *      autoneg_advertised and fc
  22.688 +     *   autoneg = 0
  22.689 +     *      PHY will be set to 10H, 10F, 100H, or 100F
  22.690 +     *      depending on value parsed from forced_speed_duplex.
  22.691 +     */
  22.692 +
  22.693 +    /* Is autoneg enabled?  This is enabled by default or by software override.
  22.694 +     * If so, call e1000_phy_setup_autoneg routine to parse the
  22.695 +     * autoneg_advertised and fc options. If autoneg is NOT enabled, then the
  22.696 +     * user should have provided a speed/duplex override.  If so, then call
  22.697 +     * e1000_phy_force_speed_duplex to parse and set this up.
  22.698 +     */
  22.699 +    if(hw->autoneg) {
  22.700 +        /* Perform some bounds checking on the hw->autoneg_advertised
  22.701 +         * parameter.  If this variable is zero, then set it to the default.
  22.702 +         */
  22.703 +        hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
  22.704 +
  22.705 +        /* If autoneg_advertised is zero, we assume it was not defaulted
  22.706 +         * by the calling code so we set to advertise full capability.
  22.707 +         */
  22.708 +        if(hw->autoneg_advertised == 0)
  22.709 +            hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  22.710 +
  22.711 +        DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
  22.712 +        ret_val = e1000_phy_setup_autoneg(hw);
  22.713 +        if(ret_val < 0) {
  22.714 +            DEBUGOUT("Error Setting up Auto-Negotiation\n");
  22.715 +            return ret_val;
  22.716 +        }
  22.717 +        DEBUGOUT("Restarting Auto-Neg\n");
  22.718 +
  22.719 +        /* Restart auto-negotiation by setting the Auto Neg Enable bit and
  22.720 +         * the Auto Neg Restart bit in the PHY control register.
  22.721 +         */
  22.722 +        if(e1000_read_phy_reg(hw, PHY_CTRL, &phy_data) < 0) {
  22.723 +            DEBUGOUT("PHY Read Error\n");
  22.724 +            return -E1000_ERR_PHY;
  22.725 +        }
  22.726 +        phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
  22.727 +        if(e1000_write_phy_reg(hw, PHY_CTRL, phy_data) < 0) {
  22.728 +            DEBUGOUT("PHY Write Error\n");
  22.729 +            return -E1000_ERR_PHY;
  22.730 +        }
  22.731 +
  22.732 +        /* Does the user want to wait for Auto-Neg to complete here, or
  22.733 +         * check at a later time (for example, callback routine).
  22.734 +         */
  22.735 +        if(hw->wait_autoneg_complete) {
  22.736 +            ret_val = e1000_wait_autoneg(hw);
  22.737 +            if(ret_val < 0) {
  22.738 +                DEBUGOUT("Error while waiting for autoneg to complete\n");
  22.739 +                return ret_val;
  22.740 +            }
  22.741 +        }
  22.742 +    } else {
  22.743 +        DEBUGOUT("Forcing speed and duplex\n");
  22.744 +        ret_val = e1000_phy_force_speed_duplex(hw);
  22.745 +        if(ret_val < 0) {
  22.746 +            DEBUGOUT("Error Forcing Speed and Duplex\n");
  22.747 +            return ret_val;
  22.748 +        }
  22.749 +    }
  22.750 +
  22.751 +    /* Check link status. Wait up to 100 microseconds for link to become
  22.752 +     * valid.
  22.753 +     */
  22.754 +    for(i = 0; i < 10; i++) {
  22.755 +        if(e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
  22.756 +            DEBUGOUT("PHY Read Error\n");
  22.757 +            return -E1000_ERR_PHY;
  22.758 +        }
  22.759 +        if(e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
  22.760 +            DEBUGOUT("PHY Read Error\n");
  22.761 +            return -E1000_ERR_PHY;
  22.762 +        }
  22.763 +        if(phy_data & MII_SR_LINK_STATUS) {
  22.764 +            /* We have link, so we need to finish the config process:
  22.765 +             *   1) Set up the MAC to the current PHY speed/duplex
  22.766 +             *      if we are on 82543.  If we
  22.767 +             *      are on newer silicon, we only need to configure
  22.768 +             *      collision distance in the Transmit Control Register.
  22.769 +             *   2) Set up flow control on the MAC to that established with
  22.770 +             *      the link partner.
  22.771 +             */
  22.772 +            if(hw->mac_type >= e1000_82544) {
  22.773 +                e1000_config_collision_dist(hw);
  22.774 +            } else {
  22.775 +                ret_val = e1000_config_mac_to_phy(hw);
  22.776 +                if(ret_val < 0) {
  22.777 +                    DEBUGOUT("Error configuring MAC to PHY settings\n");
  22.778 +                    return ret_val;
  22.779 +                  }
  22.780 +            }
  22.781 +            ret_val = e1000_config_fc_after_link_up(hw);
  22.782 +            if(ret_val < 0) {
  22.783 +                DEBUGOUT("Error Configuring Flow Control\n");
  22.784 +                return ret_val;
  22.785 +            }
  22.786 +            DEBUGOUT("Valid link established!!!\n");
  22.787 +            return 0;
  22.788 +        }
  22.789 +        udelay(10);
  22.790 +    }
  22.791 +
  22.792 +    DEBUGOUT("Unable to establish link!!!\n");
  22.793 +    return 0;
  22.794 +}
  22.795 +
  22.796 +/******************************************************************************
  22.797 +* Configures PHY autoneg and flow control advertisement settings
  22.798 +*
  22.799 +* hw - Struct containing variables accessed by shared code
  22.800 +******************************************************************************/
  22.801 +int32_t
  22.802 +e1000_phy_setup_autoneg(struct e1000_hw *hw)
  22.803 +{
  22.804 +    uint16_t mii_autoneg_adv_reg;
  22.805 +    uint16_t mii_1000t_ctrl_reg;
  22.806 +
  22.807 +    DEBUGFUNC("e1000_phy_setup_autoneg");
  22.808 +
  22.809 +    /* Read the MII Auto-Neg Advertisement Register (Address 4). */
  22.810 +    if(e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg) < 0) {
  22.811 +        DEBUGOUT("PHY Read Error\n");
  22.812 +        return -E1000_ERR_PHY;
  22.813 +    }
  22.814 +
  22.815 +    /* Read the MII 1000Base-T Control Register (Address 9). */
  22.816 +    if(e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg) < 0) {
  22.817 +        DEBUGOUT("PHY Read Error\n");
  22.818 +        return -E1000_ERR_PHY;
  22.819 +    }
  22.820 +
  22.821 +    /* Need to parse both autoneg_advertised and fc and set up
  22.822 +     * the appropriate PHY registers.  First we will parse for
  22.823 +     * autoneg_advertised software override.  Since we can advertise
  22.824 +     * a plethora of combinations, we need to check each bit
  22.825 +     * individually.
  22.826 +     */
  22.827 +
  22.828 +    /* First we clear all the 10/100 mb speed bits in the Auto-Neg
  22.829 +     * Advertisement Register (Address 4) and the 1000 mb speed bits in
  22.830 +     * the  1000Base-T Control Register (Address 9).
  22.831 +     */
  22.832 +    mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
  22.833 +    mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
  22.834 +
  22.835 +    DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
  22.836 +
  22.837 +    /* Do we want to advertise 10 Mb Half Duplex? */
  22.838 +    if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
  22.839 +        DEBUGOUT("Advertise 10mb Half duplex\n");
  22.840 +        mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
  22.841 +    }
  22.842 +
  22.843 +    /* Do we want to advertise 10 Mb Full Duplex? */
  22.844 +    if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
  22.845 +        DEBUGOUT("Advertise 10mb Full duplex\n");
  22.846 +        mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
  22.847 +    }
  22.848 +
  22.849 +    /* Do we want to advertise 100 Mb Half Duplex? */
  22.850 +    if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
  22.851 +        DEBUGOUT("Advertise 100mb Half duplex\n");
  22.852 +        mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
  22.853 +    }
  22.854 +
  22.855 +    /* Do we want to advertise 100 Mb Full Duplex? */
  22.856 +    if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
  22.857 +        DEBUGOUT("Advertise 100mb Full duplex\n");
  22.858 +        mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
  22.859 +    }
  22.860 +
  22.861 +    /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
  22.862 +    if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
  22.863 +        DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
  22.864 +    }
  22.865 +
  22.866 +    /* Do we want to advertise 1000 Mb Full Duplex? */
  22.867 +    if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
  22.868 +        DEBUGOUT("Advertise 1000mb Full duplex\n");
  22.869 +        mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
  22.870 +    }
  22.871 +
  22.872 +    /* Check for a software override of the flow control settings, and
  22.873 +     * setup the PHY advertisement registers accordingly.  If
  22.874 +     * auto-negotiation is enabled, then software will have to set the
  22.875 +     * "PAUSE" bits to the correct value in the Auto-Negotiation
  22.876 +     * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
  22.877 +     *
  22.878 +     * The possible values of the "fc" parameter are:
  22.879 +     *      0:  Flow control is completely disabled
  22.880 +     *      1:  Rx flow control is enabled (we can receive pause frames
  22.881 +     *          but not send pause frames).
  22.882 +     *      2:  Tx flow control is enabled (we can send pause frames
  22.883 +     *          but we do not support receiving pause frames).
  22.884 +     *      3:  Both Rx and TX flow control (symmetric) are enabled.
  22.885 +     *  other:  No software override.  The flow control configuration
  22.886 +     *          in the EEPROM is used.
  22.887 +     */
  22.888 +    switch (hw->fc) {
  22.889 +    case e1000_fc_none: /* 0 */
  22.890 +        /* Flow control (RX & TX) is completely disabled by a
  22.891 +         * software over-ride.
  22.892 +         */
  22.893 +        mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  22.894 +        break;
  22.895 +    case e1000_fc_rx_pause: /* 1 */
  22.896 +        /* RX Flow control is enabled, and TX Flow control is
  22.897 +         * disabled, by a software over-ride.
  22.898 +         */
  22.899 +        /* Since there really isn't a way to advertise that we are
  22.900 +         * capable of RX Pause ONLY, we will advertise that we
  22.901 +         * support both symmetric and asymmetric RX PAUSE.  Later
  22.902 +         * (in e1000_config_fc_after_link_up) we will disable the
  22.903 +         *hw's ability to send PAUSE frames.
  22.904 +         */
  22.905 +        mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  22.906 +        break;
  22.907 +    case e1000_fc_tx_pause: /* 2 */
  22.908 +        /* TX Flow control is enabled, and RX Flow control is
  22.909 +         * disabled, by a software over-ride.
  22.910 +         */
  22.911 +        mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
  22.912 +        mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
  22.913 +        break;
  22.914 +    case e1000_fc_full: /* 3 */
  22.915 +        /* Flow control (both RX and TX) is enabled by a software
  22.916 +         * over-ride.
  22.917 +         */
  22.918 +        mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  22.919 +        break;
  22.920 +    default:
  22.921 +        DEBUGOUT("Flow control param set incorrectly\n");
  22.922 +        return -E1000_ERR_CONFIG;
  22.923 +    }
  22.924 +
  22.925 +    if(e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg) < 0) {
  22.926 +        DEBUGOUT("PHY Write Error\n");
  22.927 +        return -E1000_ERR_PHY;
  22.928 +    }
  22.929 +
  22.930 +    DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
  22.931 +
  22.932 +    if(e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg) < 0) {
  22.933 +        DEBUGOUT("PHY Write Error\n");
  22.934 +        return -E1000_ERR_PHY;
  22.935 +    }
  22.936 +    return 0;
  22.937 +}
  22.938 +
  22.939 +/******************************************************************************
  22.940 +* Force PHY speed and duplex settings to hw->forced_speed_duplex
  22.941 +*
  22.942 +* hw - Struct containing variables accessed by shared code
  22.943 +******************************************************************************/
  22.944 +static int32_t
  22.945 +e1000_phy_force_speed_duplex(struct e1000_hw *hw)
  22.946 +{
  22.947 +    uint32_t ctrl;
  22.948 +    int32_t ret_val;
  22.949 +    uint16_t mii_ctrl_reg;
  22.950 +    uint16_t mii_status_reg;
  22.951 +    uint16_t phy_data;
  22.952 +    uint16_t i;
  22.953 +
  22.954 +    DEBUGFUNC("e1000_phy_force_speed_duplex");
  22.955 +
  22.956 +    /* Turn off Flow control if we are forcing speed and duplex. */
  22.957 +    hw->fc = e1000_fc_none;
  22.958 +
  22.959 +    DEBUGOUT1("hw->fc = %d\n", hw->fc);
  22.960 +
  22.961 +    /* Read the Device Control Register. */
  22.962 +    ctrl = E1000_READ_REG(hw, CTRL);
  22.963 +
  22.964 +    /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
  22.965 +    ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  22.966 +    ctrl &= ~(DEVICE_SPEED_MASK);
  22.967 +
  22.968 +    /* Clear the Auto Speed Detect Enable bit. */
  22.969 +    ctrl &= ~E1000_CTRL_ASDE;
  22.970 +
  22.971 +    /* Read the MII Control Register. */
  22.972 +    if(e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg) < 0) {
  22.973 +        DEBUGOUT("PHY Read Error\n");
  22.974 +        return -E1000_ERR_PHY;
  22.975 +    }
  22.976 +
  22.977 +    /* We need to disable autoneg in order to force link and duplex. */
  22.978 +
  22.979 +    mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
  22.980 +
  22.981 +    /* Are we forcing Full or Half Duplex? */
  22.982 +    if(hw->forced_speed_duplex == e1000_100_full ||
  22.983 +       hw->forced_speed_duplex == e1000_10_full) {
  22.984 +        /* We want to force full duplex so we SET the full duplex bits in the
  22.985 +         * Device and MII Control Registers.
  22.986 +         */
  22.987 +        ctrl |= E1000_CTRL_FD;
  22.988 +        mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
  22.989 +        DEBUGOUT("Full Duplex\n");
  22.990 +    } else {
  22.991 +        /* We want to force half duplex so we CLEAR the full duplex bits in
  22.992 +         * the Device and MII Control Registers.
  22.993 +         */
  22.994 +        ctrl &= ~E1000_CTRL_FD;
  22.995 +        mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
  22.996 +        DEBUGOUT("Half Duplex\n");
  22.997 +    }
  22.998 +
  22.999 +    /* Are we forcing 100Mbps??? */
 22.1000 +    if(hw->forced_speed_duplex == e1000_100_full ||
 22.1001 +       hw->forced_speed_duplex == e1000_100_half) {
 22.1002 +        /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
 22.1003 +        ctrl |= E1000_CTRL_SPD_100;
 22.1004 +        mii_ctrl_reg |= MII_CR_SPEED_100;
 22.1005 +        mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
 22.1006 +        DEBUGOUT("Forcing 100mb ");
 22.1007 +    } else {
 22.1008 +        /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
 22.1009 +        ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
 22.1010 +        mii_ctrl_reg |= MII_CR_SPEED_10;
 22.1011 +        mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
 22.1012 +        DEBUGOUT("Forcing 10mb ");
 22.1013 +    }
 22.1014 +
 22.1015 +    e1000_config_collision_dist(hw);
 22.1016 +
 22.1017 +    /* Write the configured values back to the Device Control Reg. */
 22.1018 +    E1000_WRITE_REG(hw, CTRL, ctrl);
 22.1019 +
 22.1020 +    if(e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data) < 0) {
 22.1021 +        DEBUGOUT("PHY Read Error\n");
 22.1022 +        return -E1000_ERR_PHY;
 22.1023 +    }
 22.1024 +
 22.1025 +    /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
 22.1026 +     * forced whenever speed are duplex are forced.
 22.1027 +     */
 22.1028 +    phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
 22.1029 +    if(e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data) < 0) {
 22.1030 +        DEBUGOUT("PHY Write Error\n");
 22.1031 +        return -E1000_ERR_PHY;
 22.1032 +    }
 22.1033 +    DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
 22.1034 +
 22.1035 +    /* Need to reset the PHY or these changes will be ignored */
 22.1036 +    mii_ctrl_reg |= MII_CR_RESET;
 22.1037 +
 22.1038 +    /* Write back the modified PHY MII control register. */
 22.1039 +    if(e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg) < 0) {
 22.1040 +        DEBUGOUT("PHY Write Error\n");
 22.1041 +        return -E1000_ERR_PHY;
 22.1042 +    }
 22.1043 +    udelay(1);
 22.1044 +
 22.1045 +    /* The wait_autoneg_complete flag may be a little misleading here.
 22.1046 +     * Since we are forcing speed and duplex, Auto-Neg is not enabled.
 22.1047 +     * But we do want to delay for a period while forcing only so we
 22.1048 +     * don't generate false No Link messages.  So we will wait here
 22.1049 +     * only if the user has set wait_autoneg_complete to 1, which is
 22.1050 +     * the default.
 22.1051 +     */
 22.1052 +    if(hw->wait_autoneg_complete) {
 22.1053 +        /* We will wait for autoneg to complete. */
 22.1054 +        DEBUGOUT("Waiting for forced speed/duplex link.\n");
 22.1055 +        mii_status_reg = 0;
 22.1056 +
 22.1057 +        /* We will wait for autoneg to complete or 4.5 seconds to expire. */
 22.1058 +        for(i = PHY_FORCE_TIME; i > 0; i--) {
 22.1059 +            /* Read the MII Status Register and wait for Auto-Neg Complete bit
 22.1060 +             * to be set.
 22.1061 +             */
 22.1062 +            if(e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
 22.1063 +                DEBUGOUT("PHY Read Error\n");
 22.1064 +                return -E1000_ERR_PHY;
 22.1065 +            }
 22.1066 +            if(e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
 22.1067 +                DEBUGOUT("PHY Read Error\n");
 22.1068 +                return -E1000_ERR_PHY;
 22.1069 +            }
 22.1070 +            if(mii_status_reg & MII_SR_LINK_STATUS) break;
 22.1071 +            msec_delay(100);
 22.1072 +        }
 22.1073 +        if(i == 0) { /* We didn't get link */
 22.1074 +            /* Reset the DSP and wait again for link. */
 22.1075 +            
 22.1076 +            ret_val = e1000_phy_reset_dsp(hw);
 22.1077 +            if(ret_val < 0) {
 22.1078 +                DEBUGOUT("Error Resetting PHY DSP\n");
 22.1079 +                return ret_val;
 22.1080 +            }
 22.1081 +        }
 22.1082 +        /* This loop will early-out if the link condition has been met.  */
 22.1083 +        for(i = PHY_FORCE_TIME; i > 0; i--) {
 22.1084 +            if(mii_status_reg & MII_SR_LINK_STATUS) break;
 22.1085 +            msec_delay(100);
 22.1086 +            /* Read the MII Status Register and wait for Auto-Neg Complete bit
 22.1087 +             * to be set.
 22.1088 +             */
 22.1089 +            if(e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
 22.1090 +                DEBUGOUT("PHY Read Error\n");
 22.1091 +                return -E1000_ERR_PHY;
 22.1092 +            }
 22.1093 +            if(e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
 22.1094 +                DEBUGOUT("PHY Read Error\n");
 22.1095 +                return -E1000_ERR_PHY;
 22.1096 +            }
 22.1097 +        }
 22.1098 +    }
 22.1099 +    
 22.1100 +    /* Because we reset the PHY above, we need to re-force TX_CLK in the
 22.1101 +     * Extended PHY Specific Control Register to 25MHz clock.  This value
 22.1102 +     * defaults back to a 2.5MHz clock when the PHY is reset.
 22.1103 +     */
 22.1104 +    if(e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data) < 0) {
 22.1105 +        DEBUGOUT("PHY Read Error\n");
 22.1106 +        return -E1000_ERR_PHY;
 22.1107 +    }
 22.1108 +    phy_data |= M88E1000_EPSCR_TX_CLK_25;
 22.1109 +    if(e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data) < 0) {
 22.1110 +        DEBUGOUT("PHY Write Error\n");
 22.1111 +        return -E1000_ERR_PHY;
 22.1112 +    }
 22.1113 +
 22.1114 +    /* In addition, because of the s/w reset above, we need to enable CRS on
 22.1115 +     * TX.  This must be set for both full and half duplex operation.
 22.1116 +     */
 22.1117 +    if(e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data) < 0) {
 22.1118 +        DEBUGOUT("PHY Read Error\n");
 22.1119 +        return -E1000_ERR_PHY;
 22.1120 +    }
 22.1121 +    phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
 22.1122 +    if(e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data) < 0) {
 22.1123 +        DEBUGOUT("PHY Write Error\n");
 22.1124 +        return -E1000_ERR_PHY;
 22.1125 +    }
 22.1126 +    return 0;
 22.1127 +}
 22.1128 +
 22.1129 +/******************************************************************************
 22.1130 +* Sets the collision distance in the Transmit Control register
 22.1131 +*
 22.1132 +* hw - Struct containing variables accessed by shared code
 22.1133 +*
 22.1134 +* Link should have been established previously. Reads the speed and duplex
 22.1135 +* information from the Device Status register.
 22.1136 +******************************************************************************/
 22.1137 +void
 22.1138 +e1000_config_collision_dist(struct e1000_hw *hw)
 22.1139 +{
 22.1140 +    uint32_t tctl;
 22.1141 +
 22.1142 +    tctl = E1000_READ_REG(hw, TCTL);
 22.1143 +
 22.1144 +    tctl &= ~E1000_TCTL_COLD;
 22.1145 +    tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
 22.1146 +
 22.1147 +    E1000_WRITE_REG(hw, TCTL, tctl);
 22.1148 +    E1000_WRITE_FLUSH(hw);
 22.1149 +}
 22.1150 +
 22.1151 +/******************************************************************************
 22.1152 +* Sets MAC speed and duplex settings to reflect the those in the PHY
 22.1153 +*
 22.1154 +* hw - Struct containing variables accessed by shared code
 22.1155 +* mii_reg - data to write to the MII control register
 22.1156 +*
 22.1157 +* The contents of the PHY register containing the needed information need to
 22.1158 +* be passed in.
 22.1159 +******************************************************************************/
 22.1160 +static int32_t
 22.1161 +e1000_config_mac_to_phy(struct e1000_hw *hw)
 22.1162 +{
 22.1163 +    uint32_t ctrl;
 22.1164 +    uint16_t phy_data;
 22.1165 +
 22.1166 +    DEBUGFUNC("e1000_config_mac_to_phy");
 22.1167 +
 22.1168 +    /* Read the Device Control Register and set the bits to Force Speed
 22.1169 +     * and Duplex.
 22.1170 +     */
 22.1171 +    ctrl = E1000_READ_REG(hw, CTRL);
 22.1172 +    ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
 22.1173 +    ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
 22.1174 +
 22.1175 +    /* Set up duplex in the Device Control and Transmit Control
 22.1176 +     * registers depending on negotiated values.
 22.1177 +     */
 22.1178 +    if(e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data) < 0) {
 22.1179 +        DEBUGOUT("PHY Read Error\n");
 22.1180 +        return -E1000_ERR_PHY;
 22.1181 +    }
 22.1182 +    if(phy_data & M88E1000_PSSR_DPLX) ctrl |= E1000_CTRL_FD;
 22.1183 +    else ctrl &= ~E1000_CTRL_FD;
 22.1184 +
 22.1185 +    e1000_config_collision_dist(hw);
 22.1186 +
 22.1187 +    /* Set up speed in the Device Control register depending on
 22.1188 +     * negotiated values.
 22.1189 +     */
 22.1190 +    if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
 22.1191 +        ctrl |= E1000_CTRL_SPD_1000;
 22.1192 +    else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
 22.1193 +        ctrl |= E1000_CTRL_SPD_100;
 22.1194 +    /* Write the configured values back to the Device Control Reg. */
 22.1195 +    E1000_WRITE_REG(hw, CTRL, ctrl);
 22.1196 +    return 0;
 22.1197 +}
 22.1198 +
 22.1199 +/******************************************************************************
 22.1200 + * Forces the MAC's flow control settings.
 22.1201 + * 
 22.1202 + * hw - Struct containing variables accessed by shared code
 22.1203 + *
 22.1204 + * Sets the TFCE and RFCE bits in the device control register to reflect
 22.1205 + * the adapter settings. TFCE and RFCE need to be explicitly set by
 22.1206 + * software when a Copper PHY is used because autonegotiation is managed
 22.1207 + * by the PHY rather than the MAC. Software must also configure these
 22.1208 + * bits when link is forced on a fiber connection.
 22.1209 + *****************************************************************************/
 22.1210 +static int32_t
 22.1211 +e1000_force_mac_fc(struct e1000_hw *hw)
 22.1212 +{
 22.1213 +    uint32_t ctrl;
 22.1214 +
 22.1215 +    DEBUGFUNC("e1000_force_mac_fc");
 22.1216 +
 22.1217 +    /* Get the current configuration of the Device Control Register */
 22.1218 +    ctrl = E1000_READ_REG(hw, CTRL);
 22.1219 +
 22.1220 +    /* Because we didn't get link via the internal auto-negotiation
 22.1221 +     * mechanism (we either forced link or we got link via PHY
 22.1222 +     * auto-neg), we have to manually enable/disable transmit an
 22.1223 +     * receive flow control.
 22.1224 +     *
 22.1225 +     * The "Case" statement below enables/disable flow control
 22.1226 +     * according to the "hw->fc" parameter.
 22.1227 +     *
 22.1228 +     * The possible values of the "fc" parameter are:
 22.1229 +     *      0:  Flow control is completely disabled
 22.1230 +     *      1:  Rx flow control is enabled (we can receive pause
 22.1231 +     *          frames but not send pause frames).
 22.1232 +     *      2:  Tx flow control is enabled (we can send pause frames
 22.1233 +     *          frames but we do not receive pause frames).
 22.1234 +     *      3:  Both Rx and TX flow control (symmetric) is enabled.
 22.1235 +     *  other:  No other values should be possible at this point.
 22.1236 +     */
 22.1237 +
 22.1238 +    switch (hw->fc) {
 22.1239 +    case e1000_fc_none:
 22.1240 +        ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
 22.1241 +        break;
 22.1242 +    case e1000_fc_rx_pause:
 22.1243 +        ctrl &= (~E1000_CTRL_TFCE);
 22.1244 +        ctrl |= E1000_CTRL_RFCE;
 22.1245 +        break;
 22.1246 +    case e1000_fc_tx_pause:
 22.1247 +        ctrl &= (~E1000_CTRL_RFCE);
 22.1248 +        ctrl |= E1000_CTRL_TFCE;
 22.1249 +        break;
 22.1250 +    case e1000_fc_full:
 22.1251 +        ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
 22.1252 +        break;
 22.1253 +    default:
 22.1254 +        DEBUGOUT("Flow control param set incorrectly\n");
 22.1255 +        return -E1000_ERR_CONFIG;
 22.1256 +    }
 22.1257 +
 22.1258 +    /* Disable TX Flow Control for 82542 (rev 2.0) */
 22.1259 +    if(hw->mac_type == e1000_82542_rev2_0)
 22.1260 +        ctrl &= (~E1000_CTRL_TFCE);
 22.1261 +
 22.1262 +    E1000_WRITE_REG(hw, CTRL, ctrl);
 22.1263 +    return 0;
 22.1264 +}
 22.1265 +
 22.1266 +/******************************************************************************
 22.1267 + * Configures flow control settings after link is established
 22.1268 + * 
 22.1269 + * hw - Struct containing variables accessed by shared code
 22.1270 + *
 22.1271 + * Should be called immediately after a valid link has been established.
 22.1272 + * Forces MAC flow control settings if link was forced. When in MII/GMII mode
 22.1273 + * and autonegotiation is enabled, the MAC flow control settings will be set
 22.1274 + * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
 22.1275 + * and RFCE bits will be automaticaly set to the negotiated flow control mode.
 22.1276 + *****************************************************************************/
 22.1277 +int32_t
 22.1278 +e1000_config_fc_after_link_up(struct e1000_hw *hw)
 22.1279 +{
 22.1280 +    int32_t ret_val;
 22.1281 +    uint16_t mii_status_reg;
 22.1282 +    uint16_t mii_nway_adv_reg;
 22.1283 +    uint16_t mii_nway_lp_ability_reg;
 22.1284 +    uint16_t speed;
 22.1285 +    uint16_t duplex;
 22.1286 +
 22.1287 +    DEBUGFUNC("e1000_config_fc_after_link_up");
 22.1288 +
 22.1289 +    /* Check for the case where we have fiber media and auto-neg failed
 22.1290 +     * so we had to force link.  In this case, we need to force the
 22.1291 +     * configuration of the MAC to match the "fc" parameter.
 22.1292 +     */
 22.1293 +    if(((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
 22.1294 +       ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
 22.1295 +        ret_val = e1000_force_mac_fc(hw);
 22.1296 +        if(ret_val < 0) {
 22.1297 +            DEBUGOUT("Error forcing flow control settings\n");
 22.1298 +            return ret_val;
 22.1299 +        }
 22.1300 +    }
 22.1301 +
 22.1302 +    /* Check for the case where we have copper media and auto-neg is
 22.1303 +     * enabled.  In this case, we need to check and see if Auto-Neg
 22.1304 +     * has completed, and if so, how the PHY and link partner has
 22.1305 +     * flow control configured.
 22.1306 +     */
 22.1307 +    if((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
 22.1308 +        /* Read the MII Status Register and check to see if AutoNeg
 22.1309 +         * has completed.  We read this twice because this reg has
 22.1310 +         * some "sticky" (latched) bits.
 22.1311 +         */
 22.1312 +        if(e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
 22.1313 +            DEBUGOUT("PHY Read Error \n");
 22.1314 +            return -E1000_ERR_PHY;
 22.1315 +        }
 22.1316 +        if(e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
 22.1317 +            DEBUGOUT("PHY Read Error \n");
 22.1318 +            return -E1000_ERR_PHY;
 22.1319 +        }
 22.1320 +
 22.1321 +        if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
 22.1322 +            /* The AutoNeg process has completed, so we now need to
 22.1323 +             * read both the Auto Negotiation Advertisement Register
 22.1324 +             * (Address 4) and the Auto_Negotiation Base Page Ability
 22.1325 +             * Register (Address 5) to determine how flow control was
 22.1326 +             * negotiated.
 22.1327 +             */
 22.1328 +            if(e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_nway_adv_reg) < 0) {
 22.1329 +                DEBUGOUT("PHY Read Error\n");
 22.1330 +                return -E1000_ERR_PHY;
 22.1331 +            }
 22.1332 +            if(e1000_read_phy_reg(hw, PHY_LP_ABILITY, &mii_nway_lp_ability_reg) < 0) {
 22.1333 +                DEBUGOUT("PHY Read Error\n");
 22.1334 +                return -E1000_ERR_PHY;
 22.1335 +            }
 22.1336 +
 22.1337 +            /* Two bits in the Auto Negotiation Advertisement Register
 22.1338 +             * (Address 4) and two bits in the Auto Negotiation Base
 22.1339 +             * Page Ability Register (Address 5) determine flow control
 22.1340 +             * for both the PHY and the link partner.  The following
 22.1341 +             * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
 22.1342 +             * 1999, describes these PAUSE resolution bits and how flow
 22.1343 +             * control is determined based upon these settings.
 22.1344 +             * NOTE:  DC = Don't Care
 22.1345 +             *
 22.1346 +             *   LOCAL DEVICE  |   LINK PARTNER
 22.1347 +             * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
 22.1348 +             *-------|---------|-------|---------|--------------------
 22.1349 +             *   0   |    0    |  DC   |   DC    | e1000_fc_none
 22.1350 +             *   0   |    1    |   0   |   DC    | e1000_fc_none
 22.1351 +             *   0   |    1    |   1   |    0    | e1000_fc_none
 22.1352 +             *   0   |    1    |   1   |    1    | e1000_fc_tx_pause
 22.1353 +             *   1   |    0    |   0   |   DC    | e1000_fc_none
 22.1354 +             *   1   |   DC    |   1   |   DC    | e1000_fc_full
 22.1355 +             *   1   |    1    |   0   |    0    | e1000_fc_none
 22.1356 +             *   1   |    1    |   0   |    1    | e1000_fc_rx_pause
 22.1357 +             *
 22.1358 +             */
 22.1359 +            /* Are both PAUSE bits set to 1?  If so, this implies
 22.1360 +             * Symmetric Flow Control is enabled at both ends.  The
 22.1361 +             * ASM_DIR bits are irrelevant per the spec.
 22.1362 +             *
 22.1363 +             * For Symmetric Flow Control:
 22.1364 +             *
 22.1365 +             *   LOCAL DEVICE  |   LINK PARTNER
 22.1366 +             * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
 22.1367 +             *-------|---------|-------|---------|--------------------
 22.1368 +             *   1   |   DC    |   1   |   DC    | e1000_fc_full
 22.1369 +             *
 22.1370 +             */
 22.1371 +            if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
 22.1372 +               (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
 22.1373 +                /* Now we need to check if the user selected RX ONLY
 22.1374 +                 * of pause frames.  In this case, we had to advertise
 22.1375 +                 * FULL flow control because we could not advertise RX
 22.1376 +                 * ONLY. Hence, we must now check to see if we need to
 22.1377 +                 * turn OFF  the TRANSMISSION of PAUSE frames.
 22.1378 +                 */
 22.1379 +                if(hw->original_fc == e1000_fc_full) {
 22.1380 +                    hw->fc = e1000_fc_full;
 22.1381 +                    DEBUGOUT("Flow Control = FULL.\r\n");
 22.1382 +                } else {
 22.1383 +                    hw->fc = e1000_fc_rx_pause;
 22.1384 +                    DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
 22.1385 +                }
 22.1386 +            }
 22.1387 +            /* For receiving PAUSE frames ONLY.
 22.1388 +             *
 22.1389 +             *   LOCAL DEVICE  |   LINK PARTNER
 22.1390 +             * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
 22.1391 +             *-------|---------|-------|---------|--------------------
 22.1392 +             *   0   |    1    |   1   |    1    | e1000_fc_tx_pause
 22.1393 +             *
 22.1394 +             */
 22.1395 +            else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
 22.1396 +                    (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
 22.1397 +                    (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
 22.1398 +                    (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
 22.1399 +                hw->fc = e1000_fc_tx_pause;
 22.1400 +                DEBUGOUT("Flow Control = TX PAUSE frames only.\r\n");
 22.1401 +            }
 22.1402 +            /* For transmitting PAUSE frames ONLY.
 22.1403 +             *
 22.1404 +             *   LOCAL DEVICE  |   LINK PARTNER
 22.1405 +             * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
 22.1406 +             *-------|---------|-------|---------|--------------------
 22.1407 +             *   1   |    1    |   0   |    1    | e1000_fc_rx_pause
 22.1408 +             *
 22.1409 +             */
 22.1410 +            else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
 22.1411 +                    (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
 22.1412 +                    !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
 22.1413 +                    (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
 22.1414 +                hw->fc = e1000_fc_rx_pause;
 22.1415 +                DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
 22.1416 +            }
 22.1417 +            /* Per the IEEE spec, at this point flow control should be
 22.1418 +             * disabled.  However, we want to consider that we could
 22.1419 +             * be connected to a legacy switch that doesn't advertise
 22.1420 +             * desired flow control, but can be forced on the link
 22.1421 +             * partner.  So if we advertised no flow control, that is
 22.1422 +             * what we will resolve to.  If we advertised some kind of
 22.1423 +             * receive capability (Rx Pause Only or Full Flow Control)
 22.1424 +             * and the link partner advertised none, we will configure
 22.1425 +             * ourselves to enable Rx Flow Control only.  We can do
 22.1426 +             * this safely for two reasons:  If the link partner really
 22.1427 +             * didn't want flow control enabled, and we enable Rx, no
 22.1428 +             * harm done since we won't be receiving any PAUSE frames
 22.1429 +             * anyway.  If the intent on the link partner was to have
 22.1430 +             * flow control enabled, then by us enabling RX only, we
 22.1431 +             * can at least receive pause frames and process them.
 22.1432 +             * This is a good idea because in most cases, since we are
 22.1433 +             * predominantly a server NIC, more times than not we will
 22.1434 +             * be asked to delay transmission of packets than asking
 22.1435 +             * our link partner to pause transmission of frames.
 22.1436 +             */
 22.1437 +            else if(hw->original_fc == e1000_fc_none ||
 22.1438 +                    hw->original_fc == e1000_fc_tx_pause) {
 22.1439 +                hw->fc = e1000_fc_none;
 22.1440 +                DEBUGOUT("Flow Control = NONE.\r\n");
 22.1441 +            } else {
 22.1442 +                hw->fc = e1000_fc_rx_pause;
 22.1443 +                DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
 22.1444 +            }
 22.1445 +
 22.1446 +            /* Now we need to do one last check...  If we auto-
 22.1447 +             * negotiated to HALF DUPLEX, flow control should not be
 22.1448 +             * enabled per IEEE 802.3 spec.
 22.1449 +             */
 22.1450 +            e1000_get_speed_and_duplex(hw, &speed, &duplex);
 22.1451 +
 22.1452 +            if(duplex == HALF_DUPLEX)
 22.1453 +                hw->fc = e1000_fc_none;
 22.1454 +
 22.1455 +            /* Now we call a subroutine to actually force the MAC
 22.1456 +             * controller to use the correct flow control settings.
 22.1457 +             */
 22.1458 +            ret_val = e1000_force_mac_fc(hw);
 22.1459 +            if(ret_val < 0) {
 22.1460 +                DEBUGOUT("Error forcing flow control settings\n");
 22.1461 +                return ret_val;
 22.1462 +             }
 22.1463 +        } else {
 22.1464 +            DEBUGOUT("Copper PHY and Auto Neg has not completed.\r\n");
 22.1465 +        }
 22.1466 +    }
 22.1467 +    return 0;
 22.1468 +}
 22.1469 +
 22.1470 +/******************************************************************************
 22.1471 + * Checks to see if the link status of the hardware has changed.
 22.1472 + *
 22.1473 + * hw - Struct containing variables accessed by shared code
 22.1474 + *
 22.1475 + * Called by any function that needs to check the link status of the adapter.
 22.1476 + *****************************************************************************/
 22.1477 +int32_t
 22.1478 +e1000_check_for_link(struct e1000_hw *hw)
 22.1479 +{
 22.1480 +    uint32_t rxcw;
 22.1481 +    uint32_t ctrl;
 22.1482 +    uint32_t status;
 22.1483 +    uint32_t rctl;
 22.1484 +    uint32_t signal;
 22.1485 +    int32_t ret_val;
 22.1486 +    uint16_t phy_data;
 22.1487 +    uint16_t lp_capability;
 22.1488 +
 22.1489 +    DEBUGFUNC("e1000_check_for_link");
 22.1490 +    
 22.1491 +    /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be 
 22.1492 +     * set when the optics detect a signal. On older adapters, it will be 
 22.1493 +     * cleared when there is a signal
 22.1494 +     */
 22.1495 +    if(hw->mac_type > e1000_82544) signal = E1000_CTRL_SWDPIN1;
 22.1496 +    else signal = 0;
 22.1497 +
 22.1498 +    ctrl = E1000_READ_REG(hw, CTRL);
 22.1499 +    status = E1000_READ_REG(hw, STATUS);
 22.1500 +    rxcw = E1000_READ_REG(hw, RXCW);
 22.1501 +
 22.1502 +    /* If we have a copper PHY then we only want to go out to the PHY
 22.1503 +     * registers to see if Auto-Neg has completed and/or if our link
 22.1504 +     * status has changed.  The get_link_status flag will be set if we
 22.1505 +     * receive a Link Status Change interrupt or we have Rx Sequence
 22.1506 +     * Errors.
 22.1507 +     */
 22.1508 +    if((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
 22.1509 +        /* First we want to see if the MII Status Register reports
 22.1510 +         * link.  If so, then we want to get the current speed/duplex
 22.1511 +         * of the PHY.
 22.1512 +         * Read the register twice since the link bit is sticky.
 22.1513 +         */
 22.1514 +        if(e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
 22.1515 +            DEBUGOUT("PHY Read Error\n");
 22.1516 +            return -E1000_ERR_PHY;
 22.1517 +        }
 22.1518 +        if(e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
 22.1519 +            DEBUGOUT("PHY Read Error\n");
 22.1520 +            return -E1000_ERR_PHY;
 22.1521 +        }
 22.1522 +
 22.1523 +        if(phy_data & MII_SR_LINK_STATUS) {
 22.1524 +            hw->get_link_status = FALSE;
 22.1525 +        } else {
 22.1526 +            /* No link detected */
 22.1527 +            return 0;
 22.1528 +        }
 22.1529 +
 22.1530 +        /* If we are forcing speed/duplex, then we simply return since
 22.1531 +         * we have already determined whether we have link or not.
 22.1532 +         */
 22.1533 +        if(!hw->autoneg) return -E1000_ERR_CONFIG;
 22.1534 +
 22.1535 +        /* We have a M88E1000 PHY and Auto-Neg is enabled.  If we
 22.1536 +         * have Si on board that is 82544 or newer, Auto
 22.1537 +         * Speed Detection takes care of MAC speed/duplex
 22.1538 +         * configuration.  So we only need to configure Collision
 22.1539 +         * Distance in the MAC.  Otherwise, we need to force
 22.1540 +         * speed/duplex on the MAC to the current PHY speed/duplex
 22.1541 +         * settings.
 22.1542 +         */
 22.1543 +        if(hw->mac_type >= e1000_82544)
 22.1544 +            e1000_config_collision_dist(hw);
 22.1545 +        else {
 22.1546 +            ret_val = e1000_config_mac_to_phy(hw);
 22.1547 +            if(ret_val < 0) {
 22.1548 +                DEBUGOUT("Error configuring MAC to PHY settings\n");
 22.1549 +                return ret_val;
 22.1550 +            }
 22.1551 +        }
 22.1552 +
 22.1553 +        /* Configure Flow Control now that Auto-Neg has completed. First, we 
 22.1554 +         * need to restore the desired flow control settings because we may
 22.1555 +         * have had to re-autoneg with a different link partner.
 22.1556 +         */
 22.1557 +        ret_val = e1000_config_fc_after_link_up(hw);
 22.1558 +        if(ret_val < 0) {
 22.1559 +            DEBUGOUT("Error configuring flow control\n");
 22.1560 +            return ret_val;
 22.1561 +        }
 22.1562 +
 22.1563 +        /* At this point we know that we are on copper and we have
 22.1564 +         * auto-negotiated link.  These are conditions for checking the link
 22.1565 +         * parter capability register.  We use the link partner capability to
 22.1566 +         * determine if TBI Compatibility needs to be turned on or off.  If
 22.1567 +         * the link partner advertises any speed in addition to Gigabit, then
 22.1568 +         * we assume that they are GMII-based, and TBI compatibility is not
 22.1569 +         * needed. If no other speeds are advertised, we assume the link
 22.1570 +         * partner is TBI-based, and we turn on TBI Compatibility.
 22.1571 +         */
 22.1572 +        if(hw->tbi_compatibility_en) {
 22.1573 +            if(e1000_read_phy_reg(hw, PHY_LP_ABILITY, &lp_capability) < 0) {
 22.1574 +                DEBUGOUT("PHY Read Error\n");
 22.1575 +                return -E1000_ERR_PHY;
 22.1576 +            }
 22.1577 +            if(lp_capability & (NWAY_LPAR_10T_HD_CAPS |
 22.1578 +                                NWAY_LPAR_10T_FD_CAPS |
 22.1579 +                                NWAY_LPAR_100TX_HD_CAPS |
 22.1580 +                                NWAY_LPAR_100TX_FD_CAPS |
 22.1581 +                                NWAY_LPAR_100T4_CAPS)) {
 22.1582 +                /* If our link partner advertises anything in addition to 
 22.1583 +                 * gigabit, we do not need to enable TBI compatibility.
 22.1584 +                 */
 22.1585 +                if(hw->tbi_compatibility_on) {
 22.1586 +                    /* If we previously were in the mode, turn it off. */
 22.1587 +                    rctl = E1000_READ_REG(hw, RCTL);
 22.1588 +                    rctl &= ~E1000_RCTL_SBP;
 22.1589 +                    E1000_WRITE_REG(hw, RCTL, rctl);
 22.1590 +                    hw->tbi_compatibility_on = FALSE;
 22.1591 +                }
 22.1592 +            } else {
 22.1593 +                /* If TBI compatibility is was previously off, turn it on. For
 22.1594 +                 * compatibility with a TBI link partner, we will store bad
 22.1595 +                 * packets. Some frames have an additional byte on the end and
 22.1596 +                 * will look like CRC errors to to the hardware.
 22.1597 +                 */
 22.1598 +                if(!hw->tbi_compatibility_on) {
 22.1599 +                    hw->tbi_compatibility_on = TRUE;
 22.1600 +                    rctl = E1000_READ_REG(hw, RCTL);
 22.1601 +                    rctl |= E1000_RCTL_SBP;
 22.1602 +                    E1000_WRITE_REG(hw, RCTL, rctl);
 22.1603 +                }
 22.1604 +            }
 22.1605 +        }
 22.1606 +    }
 22.1607 +    /* If we don't have link (auto-negotiation failed or link partner cannot
 22.1608 +     * auto-negotiate), the cable is plugged in (we have signal), and our
 22.1609 +     * link partner is not trying to auto-negotiate with us (we are receiving
 22.1610 +     * idles or data), we need to force link up. We also need to give
 22.1611 +     * auto-negotiation time to complete, in case the cable was just plugged
 22.1612 +     * in. The autoneg_failed flag does this.
 22.1613 +     */
 22.1614 +    else if((hw->media_type == e1000_media_type_fiber) &&
 22.1615 +            (!(status & E1000_STATUS_LU)) &&
 22.1616 +            ((ctrl & E1000_CTRL_SWDPIN1) == signal) &&
 22.1617 +            (!(rxcw & E1000_RXCW_C))) {
 22.1618 +        if(hw->autoneg_failed == 0) {
 22.1619 +            hw->autoneg_failed = 1;
 22.1620 +            return 0;
 22.1621 +        }
 22.1622 +        DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
 22.1623 +
 22.1624 +        /* Disable auto-negotiation in the TXCW register */
 22.1625 +        E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
 22.1626 +
 22.1627 +        /* Force link-up and also force full-duplex. */
 22.1628 +        ctrl = E1000_READ_REG(hw, CTRL);
 22.1629 +        ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
 22.1630 +        E1000_WRITE_REG(hw, CTRL, ctrl);
 22.1631 +
 22.1632 +        /* Configure Flow Control after forcing link up. */
 22.1633 +        ret_val = e1000_config_fc_after_link_up(hw);
 22.1634 +        if(ret_val < 0) {
 22.1635 +            DEBUGOUT("Error configuring flow control\n");
 22.1636 +            return ret_val;
 22.1637 +        }
 22.1638 +    }
 22.1639 +    /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
 22.1640 +     * auto-negotiation in the TXCW register and disable forced link in the
 22.1641 +     * Device Control register in an attempt to auto-negotiate with our link
 22.1642 +     * partner.
 22.1643 +     */
 22.1644 +    else if((hw->media_type == e1000_media_type_fiber) &&
 22.1645 +              (ctrl & E1000_CTRL_SLU) &&
 22.1646 +              (rxcw & E1000_RXCW_C)) {
 22.1647 +        DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
 22.1648 +        E1000_WRITE_REG(hw, TXCW, hw->txcw);
 22.1649 +        E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
 22.1650 +    }
 22.1651 +    return 0;
 22.1652 +}
 22.1653 +
 22.1654 +/******************************************************************************
 22.1655 + * Detects the current speed and duplex settings of the hardware.
 22.1656 + *
 22.1657 + * hw - Struct containing variables accessed by shared code
 22.1658 + * speed - Speed of the connection
 22.1659 + * duplex - Duplex setting of the connection
 22.1660 + *****************************************************************************/
 22.1661 +void
 22.1662 +e1000_get_speed_and_duplex(struct e1000_hw *hw,
 22.1663 +                           uint16_t *speed,
 22.1664 +                           uint16_t *duplex)
 22.1665 +{
 22.1666 +    uint32_t status;
 22.1667 +
 22.1668 +    DEBUGFUNC("e1000_get_speed_and_duplex");
 22.1669 +
 22.1670 +    if(hw->mac_type >= e1000_82543) {
 22.1671 +        status = E1000_READ_REG(hw, STATUS);
 22.1672 +        if(status & E1000_STATUS_SPEED_1000) {
 22.1673 +            *speed = SPEED_1000;
 22.1674 +            DEBUGOUT("1000 Mbs, ");
 22.1675 +        } else if(status & E1000_STATUS_SPEED_100) {
 22.1676 +            *speed = SPEED_100;
 22.1677 +            DEBUGOUT("100 Mbs, ");
 22.1678 +        } else {
 22.1679 +            *speed = SPEED_10;
 22.1680 +            DEBUGOUT("10 Mbs, ");
 22.1681 +        }
 22.1682 +
 22.1683 +        if(status & E1000_STATUS_FD) {
 22.1684 +            *duplex = FULL_DUPLEX;
 22.1685 +            DEBUGOUT("Full Duplex\r\n");
 22.1686 +        } else {
 22.1687 +            *duplex = HALF_DUPLEX;
 22.1688 +            DEBUGOUT(" Half Duplex\r\n");
 22.1689 +        }
 22.1690 +    } else {
 22.1691 +        DEBUGOUT("1000 Mbs, Full Duplex\r\n");
 22.1692 +        *speed = SPEED_1000;
 22.1693 +        *duplex = FULL_DUPLEX;
 22.1694 +    }
 22.1695 +}
 22.1696 +
 22.1697 +/******************************************************************************
 22.1698 +* Blocks until autoneg completes or times out (~4.5 seconds)
 22.1699 +*
 22.1700 +* hw - Struct containing variables accessed by shared code
 22.1701 +******************************************************************************/
 22.1702 +int32_t
 22.1703 +e1000_wait_autoneg(struct e1000_hw *hw)
 22.1704 +{
 22.1705 +    uint16_t i;
 22.1706 +    uint16_t phy_data;
 22.1707 +
 22.1708 +    DEBUGFUNC("e1000_wait_autoneg");
 22.1709 +    DEBUGOUT("Waiting for Auto-Neg to complete.\n");
 22.1710 +
 22.1711 +    /* We will wait for autoneg to complete or 4.5 seconds to expire. */
 22.1712 +    for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
 22.1713 +        /* Read the MII Status Register and wait for Auto-Neg
 22.1714 +         * Complete bit to be set.
 22.1715 +         */
 22.1716 +        if(e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
 22.1717 +            DEBUGOUT("PHY Read Error\n");
 22.1718 +            return -E1000_ERR_PHY;
 22.1719 +        }
 22.1720 +        if(e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
 22.1721 +            DEBUGOUT("PHY Read Error\n");
 22.1722 +            return -E1000_ERR_PHY;
 22.1723 +        }
 22.1724 +        if(phy_data & MII_SR_AUTONEG_COMPLETE) {
 22.1725 +            return 0;
 22.1726 +        }
 22.1727 +        msec_delay(100);
 22.1728 +    }
 22.1729 +    return 0;
 22.1730 +}
 22.1731 +
 22.1732 +/******************************************************************************
 22.1733 +* Raises the Management Data Clock
 22.1734 +*
 22.1735 +* hw - Struct containing variables accessed by shared code
 22.1736 +* ctrl - Device control register's current value
 22.1737 +******************************************************************************/
 22.1738 +static void
 22.1739 +e1000_raise_mdi_clk(struct e1000_hw *hw,
 22.1740 +                    uint32_t *ctrl)
 22.1741 +{
 22.1742 +    /* Raise the clock input to the Management Data Clock (by setting the MDC
 22.1743 +     * bit), and then delay 2 microseconds.
 22.1744 +     */
 22.1745 +    E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
 22.1746 +    E1000_WRITE_FLUSH(hw);
 22.1747 +    udelay(2);
 22.1748 +}
 22.1749 +
 22.1750 +/******************************************************************************
 22.1751 +* Lowers the Management Data Clock
 22.1752 +*
 22.1753 +* hw - Struct containing variables accessed by shared code
 22.1754 +* ctrl - Device control register's current value
 22.1755 +******************************************************************************/
 22.1756 +static void
 22.1757 +e1000_lower_mdi_clk(struct e1000_hw *hw,
 22.1758 +                    uint32_t *ctrl)
 22.1759 +{
 22.1760 +    /* Lower the clock input to the Management Data Clock (by clearing the MDC
 22.1761 +     * bit), and then delay 2 microseconds.
 22.1762 +     */
 22.1763 +    E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
 22.1764 +    E1000_WRITE_FLUSH(hw);
 22.1765 +    udelay(2);
 22.1766 +}
 22.1767 +
 22.1768 +/******************************************************************************
 22.1769 +* Shifts data bits out to the PHY
 22.1770 +*
 22.1771 +* hw - Struct containing variables accessed by shared code
 22.1772 +* data - Data to send out to the PHY
 22.1773 +* count - Number of bits to shift out
 22.1774 +*
 22.1775 +* Bits are shifted out in MSB to LSB order.
 22.1776 +******************************************************************************/
 22.1777 +static void
 22.1778 +e1000_shift_out_mdi_bits(struct e1000_hw *hw,
 22.1779 +                         uint32_t data,
 22.1780 +                         uint16_t count)
 22.1781 +{
 22.1782 +    uint32_t ctrl;
 22.1783 +    uint32_t mask;
 22.1784 +
 22.1785 +    /* We need to shift "count" number of bits out to the PHY. So, the value
 22.1786 +     * in the "data" parameter will be shifted out to the PHY one bit at a 
 22.1787 +     * time. In order to do this, "data" must be broken down into bits.
 22.1788 +     */
 22.1789 +    mask = 0x01;
 22.1790 +    mask <<= (count - 1);
 22.1791 +
 22.1792 +    ctrl = E1000_READ_REG(hw, CTRL);
 22.1793 +
 22.1794 +    /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
 22.1795 +    ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
 22.1796 +
 22.1797 +    while(mask) {
 22.1798 +        /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
 22.1799 +         * then raising and lowering the Management Data Clock. A "0" is
 22.1800 +         * shifted out to the PHY by setting the MDIO bit to "0" and then
 22.1801 +         * raising and lowering the clock.
 22.1802 +         */
 22.1803 +        if(data & mask) ctrl |= E1000_CTRL_MDIO;
 22.1804 +        else ctrl &= ~E1000_CTRL_MDIO;
 22.1805 +
 22.1806 +        E1000_WRITE_REG(hw, CTRL, ctrl);
 22.1807 +        E1000_WRITE_FLUSH(hw);
 22.1808 +
 22.1809 +        udelay(2);
 22.1810 +
 22.1811 +        e1000_raise_mdi_clk(hw, &ctrl);
 22.1812 +        e1000_lower_mdi_clk(hw, &ctrl);
 22.1813 +
 22.1814 +        mask = mask >> 1;
 22.1815 +    }
 22.1816 +}
 22.1817 +
 22.1818 +/******************************************************************************
 22.1819 +* Shifts data bits in from the PHY
 22.1820 +*
 22.1821 +* hw - Struct containing variables accessed by shared code
 22.1822 +*
 22.1823 +* Bits are shifted in in MSB to LSB order. 
 22.1824 +******************************************************************************/
 22.1825 +static uint16_t
 22.1826 +e1000_shift_in_mdi_bits(struct e1000_hw *hw)
 22.1827 +{
 22.1828 +    uint32_t ctrl;
 22.1829 +    uint16_t data = 0;
 22.1830 +    uint8_t i;
 22.1831 +
 22.1832 +    /* In order to read a register from the PHY, we need to shift in a total
 22.1833 +     * of 18 bits from the PHY. The first two bit (turnaround) times are used
 22.1834 +     * to avoid contention on the MDIO pin when a read operation is performed.
 22.1835 +     * These two bits are ignored by us and thrown away. Bits are "shifted in"
 22.1836 +     * by raising the input to the Management Data Clock (setting the MDC bit),
 22.1837 +     * and then reading the value of the MDIO bit.
 22.1838 +     */ 
 22.1839 +    ctrl = E1000_READ_REG(hw, CTRL);
 22.1840 +
 22.1841 +    /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
 22.1842 +    ctrl &= ~E1000_CTRL_MDIO_DIR;
 22.1843 +    ctrl &= ~E1000_CTRL_MDIO;
 22.1844 +
 22.1845 +    E1000_WRITE_REG(hw, CTRL, ctrl);
 22.1846 +    E1000_WRITE_FLUSH(hw);
 22.1847 +
 22.1848 +    /* Raise and Lower the clock before reading in the data. This accounts for
 22.1849 +     * the turnaround bits. The first clock occurred when we clocked out the
 22.1850 +     * last bit of the Register Address.
 22.1851 +     */
 22.1852 +    e1000_raise_mdi_clk(hw, &ctrl);
 22.1853 +    e1000_lower_mdi_clk(hw, &ctrl);
 22.1854 +
 22.1855 +    for(data = 0, i = 0; i < 16; i++) {
 22.1856 +        data = data << 1;
 22.1857 +        e1000_raise_mdi_clk(hw, &ctrl);
 22.1858 +        ctrl = E1000_READ_REG(hw, CTRL);
 22.1859 +        /* Check to see if we shifted in a "1". */
 22.1860 +        if(ctrl & E1000_CTRL_MDIO) data |= 1;
 22.1861 +        e1000_lower_mdi_clk(hw, &ctrl);
 22.1862 +    }
 22.1863 +
 22.1864 +    e1000_raise_mdi_clk(hw, &ctrl);
 22.1865 +    e1000_lower_mdi_clk(hw, &ctrl);
 22.1866 +
 22.1867 +    return data;
 22.1868 +}
 22.1869 +
 22.1870 +/*****************************************************************************
 22.1871 +* Reads the value from a PHY register
 22.1872 +*
 22.1873 +* hw - Struct containing variables accessed by shared code
 22.1874 +* reg_addr - address of the PHY register to read
 22.1875 +******************************************************************************/
 22.1876 +int32_t
 22.1877 +e1000_read_phy_reg(struct e1000_hw *hw,
 22.1878 +                   uint32_t reg_addr,
 22.1879 +                   uint16_t *phy_data)
 22.1880 +{
 22.1881 +    uint32_t i;
 22.1882 +    uint32_t mdic = 0;
 22.1883 +    const uint32_t phy_addr = 1;
 22.1884 +
 22.1885 +    DEBUGFUNC("e1000_read_phy_reg");
 22.1886 +
 22.1887 +    if(reg_addr > MAX_PHY_REG_ADDRESS) {
 22.1888 +        DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
 22.1889 +        return -E1000_ERR_PARAM;
 22.1890 +    }
 22.1891 +
 22.1892 +    if(hw->mac_type > e1000_82543) {
 22.1893 +        /* Set up Op-code, Phy Address, and register address in the MDI
 22.1894 +         * Control register.  The MAC will take care of interfacing with the
 22.1895 +         * PHY to retrieve the desired data.
 22.1896 +         */
 22.1897 +        mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
 22.1898 +                (phy_addr << E1000_MDIC_PHY_SHIFT) | 
 22.1899 +                (E1000_MDIC_OP_READ));
 22.1900 +
 22.1901 +        E1000_WRITE_REG(hw, MDIC, mdic);
 22.1902 +
 22.1903 +        /* Poll the ready bit to see if the MDI read completed */
 22.1904 +        for(i = 0; i < 64; i++) {
 22.1905 +            udelay(10);
 22.1906 +            mdic = E1000_READ_REG(hw, MDIC);
 22.1907 +            if(mdic & E1000_MDIC_READY) break;
 22.1908 +        }
 22.1909 +        if(!(mdic & E1000_MDIC_READY)) {
 22.1910 +            DEBUGOUT("MDI Read did not complete\n");
 22.1911 +            return -E1000_ERR_PHY;
 22.1912 +        }
 22.1913 +        if(mdic & E1000_MDIC_ERROR) {
 22.1914 +            DEBUGOUT("MDI Error\n");
 22.1915 +            return -E1000_ERR_PHY;
 22.1916 +        }
 22.1917 +        *phy_data = (uint16_t) mdic;
 22.1918 +    } else {
 22.1919 +        /* We must first send a preamble through the MDIO pin to signal the
 22.1920 +         * beginning of an MII instruction.  This is done by sending 32
 22.1921 +         * consecutive "1" bits.
 22.1922 +         */
 22.1923 +        e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
 22.1924 +
 22.1925 +        /* Now combine the next few fields that are required for a read
 22.1926 +         * operation.  We use this method instead of calling the
 22.1927 +         * e1000_shift_out_mdi_bits routine five different times. The format of
 22.1928 +         * a MII read instruction consists of a shift out of 14 bits and is
 22.1929 +         * defined as follows:
 22.1930 +         *    <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
 22.1931 +         * followed by a shift in of 18 bits.  This first two bits shifted in
 22.1932 +         * are TurnAround bits used to avoid contention on the MDIO pin when a
 22.1933 +         * READ operation is performed.  These two bits are thrown away
 22.1934 +         * followed by a shift in of 16 bits which contains the desired data.
 22.1935 +         */
 22.1936 +        mdic = ((reg_addr) | (phy_addr << 5) | 
 22.1937 +                (PHY_OP_READ << 10) | (PHY_SOF << 12));
 22.1938 +
 22.1939 +        e1000_shift_out_mdi_bits(hw, mdic, 14);
 22.1940 +
 22.1941 +        /* Now that we've shifted out the read command to the MII, we need to
 22.1942 +         * "shift in" the 16-bit value (18 total bits) of the requested PHY
 22.1943 +         * register address.
 22.1944 +         */
 22.1945 +        *phy_data = e1000_shift_in_mdi_bits(hw);
 22.1946 +    }
 22.1947 +    return 0;
 22.1948 +}
 22.1949 +
 22.1950 +/******************************************************************************
 22.1951 +* Writes a value to a PHY register
 22.1952 +*
 22.1953 +* hw - Struct containing variables accessed by shared code
 22.1954 +* reg_addr - address of the PHY register to write
 22.1955 +* data - data to write to the PHY
 22.1956 +******************************************************************************/
 22.1957 +int32_t
 22.1958 +e1000_write_phy_reg(struct e1000_hw *hw,
 22.1959 +                    uint32_t reg_addr,
 22.1960 +                    uint16_t phy_data)
 22.1961 +{
 22.1962 +    uint32_t i;
 22.1963 +    uint32_t mdic = 0;
 22.1964 +    const uint32_t phy_addr = 1;
 22.1965 +
 22.1966 +    DEBUGFUNC("e1000_write_phy_reg");
 22.1967 +
 22.1968 +    if(reg_addr > MAX_PHY_REG_ADDRESS) {
 22.1969 +        DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
 22.1970 +        return -E1000_ERR_PARAM;
 22.1971 +    }
 22.1972 +
 22.1973 +    if(hw->mac_type > e1000_82543) {
 22.1974 +        /* Set up Op-code, Phy Address, register address, and data intended
 22.1975 +         * for the PHY register in the MDI Control register.  The MAC will take
 22.1976 +         * care of interfacing with the PHY to send the desired data.
 22.1977 +         */
 22.1978 +        mdic = (((uint32_t) phy_data) |
 22.1979 +                (reg_addr << E1000_MDIC_REG_SHIFT) |
 22.1980 +                (phy_addr << E1000_MDIC_PHY_SHIFT) | 
 22.1981 +                (E1000_MDIC_OP_WRITE));
 22.1982 +
 22.1983 +        E1000_WRITE_REG(hw, MDIC, mdic);
 22.1984 +
 22.1985 +        /* Poll the ready bit to see if the MDI read completed */
 22.1986 +        for(i = 0; i < 64; i++) {
 22.1987 +            udelay(10);
 22.1988 +            mdic = E1000_READ_REG(hw, MDIC);
 22.1989 +            if(mdic & E1000_MDIC_READY) break;
 22.1990 +        }
 22.1991 +        if(!(mdic & E1000_MDIC_READY)) {
 22.1992 +            DEBUGOUT("MDI Write did not complete\n");
 22.1993 +            return -E1000_ERR_PHY;
 22.1994 +        }
 22.1995 +    } else {
 22.1996 +        /* We'll need to use the SW defined pins to shift the write command
 22.1997 +         * out to the PHY. We first send a preamble to the PHY to signal the
 22.1998 +         * beginning of the MII instruction.  This is done by sending 32 
 22.1999 +         * consecutive "1" bits.
 22.2000 +         */
 22.2001 +        e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
 22.2002 +
 22.2003 +        /* Now combine the remaining required fields that will indicate a 
 22.2004 +         * write operation. We use this method instead of calling the
 22.2005 +         * e1000_shift_out_mdi_bits routine for each field in the command. The
 22.2006 +         * format of a MII write instruction is as follows:
 22.2007 +         * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
 22.2008 +         */
 22.2009 +        mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
 22.2010 +                (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
 22.2011 +        mdic <<= 16;
 22.2012 +        mdic |= (uint32_t) phy_data;
 22.2013 +
 22.2014 +        e1000_shift_out_mdi_bits(hw, mdic, 32);
 22.2015 +    }
 22.2016 +    return 0;
 22.2017 +}
 22.2018 +
 22.2019 +/******************************************************************************
 22.2020 +* Returns the PHY to the power-on reset state
 22.2021 +*
 22.2022 +* hw - Struct containing variables accessed by shared code
 22.2023 +******************************************************************************/
 22.2024 +void
 22.2025 +e1000_phy_hw_reset(struct e1000_hw *hw)
 22.2026 +{
 22.2027 +    uint32_t ctrl;
 22.2028 +    uint32_t ctrl_ext;
 22.2029 +
 22.2030 +    DEBUGFUNC("e1000_phy_hw_reset");
 22.2031 +
 22.2032 +    DEBUGOUT("Resetting Phy...\n");
 22.2033 +
 22.2034 +    if(hw->mac_type > e1000_82543) {
 22.2035 +        /* Read the device control register and assert the E1000_CTRL_PHY_RST
 22.2036 +         * bit. Then, take it out of reset.
 22.2037 +         */
 22.2038 +        ctrl = E1000_READ_REG(hw, CTRL);
 22.2039 +        E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
 22.2040 +        E1000_WRITE_FLUSH(hw);
 22.2041 +        msec_delay(10);
 22.2042 +        E1000_WRITE_REG(hw, CTRL, ctrl);
 22.2043 +        E1000_WRITE_FLUSH(hw);
 22.2044 +    } else {
 22.2045 +        /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
 22.2046 +         * bit to put the PHY into reset. Then, take it out of reset.
 22.2047 +         */
 22.2048 +        ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
 22.2049 +        ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
 22.2050 +        ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
 22.2051 +        E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
 22.2052 +        E1000_WRITE_FLUSH(hw);
 22.2053 +        msec_delay(10);
 22.2054 +        ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
 22.2055 +        E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
 22.2056 +        E1000_WRITE_FLUSH(hw);
 22.2057 +    }
 22.2058 +    udelay(150);
 22.2059 +}
 22.2060 +
 22.2061 +/******************************************************************************
 22.2062 +* Resets the PHY
 22.2063 +*
 22.2064 +* hw - Struct containing variables accessed by shared code
 22.2065 +*
 22.2066 +* Sets bit 15 of the MII Control regiser
 22.2067 +******************************************************************************/
 22.2068 +int32_t
 22.2069 +e1000_phy_reset(struct e1000_hw *hw)
 22.2070 +{
 22.2071 +    uint16_t phy_data;
 22.2072 +
 22.2073 +    DEBUGFUNC("e1000_phy_reset");
 22.2074 +
 22.2075 +    if(e1000_read_phy_reg(hw, PHY_CTRL, &phy_data) < 0) {
 22.2076 +        DEBUGOUT("PHY Read Error\n");
 22.2077 +        return -E1000_ERR_PHY;
 22.2078 +    }
 22.2079 +    phy_data |= MII_CR_RESET;
 22.2080 +    if(e1000_write_phy_reg(hw, PHY_CTRL, phy_data) < 0) {
 22.2081 +        DEBUGOUT("PHY Write Error\n");
 22.2082 +        return -E1000_ERR_PHY;
 22.2083 +    }
 22.2084 +    udelay(1);
 22.2085 +    return 0;
 22.2086 +}
 22.2087 +
 22.2088 +/******************************************************************************
 22.2089 +* Probes the expected PHY address for known PHY IDs
 22.2090 +*
 22.2091 +* hw - Struct containing variables accessed by shared code
 22.2092 +******************************************************************************/
 22.2093 +int32_t
 22.2094 +e1000_detect_gig_phy(struct e1000_hw *hw)
 22.2095 +{
 22.2096 +    uint16_t phy_id_high, phy_id_low;
 22.2097 +    boolean_t match = FALSE;
 22.2098 +
 22.2099 +    DEBUGFUNC("e1000_detect_gig_phy");
 22.2100 +
 22.2101 +    /* Read the PHY ID Registers to identify which PHY is onboard. */
 22.2102 +    if(e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high) < 0) {
 22.2103 +        DEBUGOUT("PHY Read Error\n");
 22.2104 +        return -E1000_ERR_PHY;
 22.2105 +    }
 22.2106 +    hw->phy_id = (uint32_t) (phy_id_high << 16);
 22.2107 +    udelay(2);
 22.2108 +    if(e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low) < 0) {
 22.2109 +        DEBUGOUT("PHY Read Error\n");
 22.2110 +        return -E1000_ERR_PHY;
 22.2111 +    }
 22.2112 +    hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
 22.2113 +    hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
 22.2114 +
 22.2115 +    switch(hw->mac_type) {
 22.2116 +    case e1000_82543:
 22.2117 +        if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
 22.2118 +        break;
 22.2119 +    case e1000_82544:
 22.2120 +        if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
 22.2121 +        break;
 22.2122 +    case e1000_82540:
 22.2123 +    case e1000_82545:
 22.2124 +    case e1000_82546:
 22.2125 +        if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
 22.2126 +        break;
 22.2127 +    default:
 22.2128 +        DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
 22.2129 +        return -E1000_ERR_CONFIG;
 22.2130 +    }
 22.2131 +    if(match) {
 22.2132 +        DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
 22.2133 +        return 0;
 22.2134 +    }
 22.2135 +    DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
 22.2136 +    return -E1000_ERR_PHY;
 22.2137 +}
 22.2138 +
 22.2139 +/******************************************************************************
 22.2140 +* Resets the PHY's DSP
 22.2141 +*
 22.2142 +* hw - Struct containing variables accessed by shared code
 22.2143 +******************************************************************************/
 22.2144 +static int32_t
 22.2145 +e1000_phy_reset_dsp(struct e1000_hw *hw)
 22.2146 +{
 22.2147 +    int32_t ret_val = -E1000_ERR_PHY;
 22.2148 +    DEBUGFUNC("e1000_phy_reset_dsp");
 22.2149 +    
 22.2150 +    do {
 22.2151 +        if(e1000_write_phy_reg(hw, 29, 0x001d) < 0) break;
 22.2152 +        if(e1000_write_phy_reg(hw, 30, 0x00c1) < 0) break;
 22.2153 +        if(e1000_write_phy_reg(hw, 30, 0x0000) < 0) break;
 22.2154 +        ret_val = 0;
 22.2155 +    } while(0);
 22.2156 +
 22.2157 +    if(ret_val < 0) DEBUGOUT("PHY Write Error\n");
 22.2158 +    return ret_val;
 22.2159 +}
 22.2160 +
 22.2161 +/******************************************************************************
 22.2162 +* Get PHY information from various PHY registers
 22.2163 +*
 22.2164 +* hw - Struct containing variables accessed by shared code
 22.2165 +* phy_info - PHY information structure
 22.2166 +******************************************************************************/
 22.2167 +int32_t
 22.2168 +e1000_phy_get_info(struct e1000_hw *hw,
 22.2169 +                   struct e1000_phy_info *phy_info)
 22.2170 +{
 22.2171 +    int32_t ret_val = -E1000_ERR_PHY;
 22.2172 +    uint16_t phy_data;
 22.2173 +
 22.2174 +    DEBUGFUNC("e1000_phy_get_info");
 22.2175 +
 22.2176 +    phy_info->cable_length = e1000_cable_length_undefined;
 22.2177 +    phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
 22.2178 +    phy_info->cable_polarity = e1000_rev_polarity_undefined;
 22.2179 +    phy_info->polarity_correction = e1000_polarity_reversal_undefined;
 22.2180 +    phy_info->mdix_mode = e1000_auto_x_mode_undefined;
 22.2181 +    phy_info->local_rx = e1000_1000t_rx_status_undefined;
 22.2182 +    phy_info->remote_rx = e1000_1000t_rx_status_undefined;
 22.2183 +
 22.2184 +    if(hw->media_type != e1000_media_type_copper) {
 22.2185 +        DEBUGOUT("PHY info is only valid for copper media\n");
 22.2186 +        return -E1000_ERR_CONFIG;
 22.2187 +    }
 22.2188 +
 22.2189 +    do {
 22.2190 +        if(e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) break;
 22.2191 +        if(e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) break;
 22.2192 +        if((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
 22.2193 +            DEBUGOUT("PHY info is only valid if link is up\n");
 22.2194 +            return -E1000_ERR_CONFIG;
 22.2195 +        }
 22.2196 +
 22.2197 +        if(e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data) < 0)
 22.2198 +            break;
 22.2199 +        phy_info->extended_10bt_distance =
 22.2200 +            (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
 22.2201 +            M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT;
 22.2202 +        phy_info->polarity_correction =
 22.2203 +            (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
 22.2204 +            M88E1000_PSCR_POLARITY_REVERSAL_SHIFT;
 22.2205 +
 22.2206 +        if(e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data) < 0)
 22.2207 +            break;
 22.2208 +        phy_info->cable_polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >>
 22.2209 +            M88E1000_PSSR_REV_POLARITY_SHIFT;
 22.2210 +        phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >>
 22.2211 +            M88E1000_PSSR_MDIX_SHIFT;
 22.2212 +        if(phy_data & M88E1000_PSSR_1000MBS) {
 22.2213 +            /* Cable Length Estimation and Local/Remote Receiver Informatoion
 22.2214 +             * are only valid at 1000 Mbps
 22.2215 +             */
 22.2216 +            phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
 22.2217 +                                      M88E1000_PSSR_CABLE_LENGTH_SHIFT);
 22.2218 +            if(e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data) < 0) 
 22.2219 +                break;
 22.2220 +            phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
 22.2221 +                SR_1000T_LOCAL_RX_STATUS_SHIFT;
 22.2222 +            phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
 22.2223 +                SR_1000T_REMOTE_RX_STATUS_SHIFT;
 22.2224 +        }
 22.2225 +        ret_val = 0;
 22.2226 +    } while(0);
 22.2227 +
 22.2228 +    if(ret_val < 0) DEBUGOUT("PHY Read Error\n");
 22.2229 +    return ret_val;
 22.2230 +}
 22.2231 +
 22.2232 +int32_t
 22.2233 +e1000_validate_mdi_setting(struct e1000_hw *hw)
 22.2234 +{
 22.2235 +    DEBUGFUNC("e1000_validate_mdi_settings");
 22.2236 +
 22.2237 +    if(!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
 22.2238 +        DEBUGOUT("Invalid MDI setting detected\n");
 22.2239 +        hw->mdix = 1;
 22.2240 +        return -E1000_ERR_CONFIG;
 22.2241 +    }
 22.2242 +    return 0;
 22.2243 +}
 22.2244 +
 22.2245 +/******************************************************************************
 22.2246 + * Raises the EEPROM's clock input.
 22.2247 + *
 22.2248 + * hw - Struct containing variables accessed by shared code
 22.2249 + * eecd - EECD's current value
 22.2250 + *****************************************************************************/
 22.2251 +static void
 22.2252 +e1000_raise_ee_clk(struct e1000_hw *hw,
 22.2253 +                   uint32_t *eecd)
 22.2254 +{
 22.2255 +    /* Raise the clock input to the EEPROM (by setting the SK bit), and then
 22.2256 +     * wait <delay> microseconds.
 22.2257 +     */
 22.2258 +    *eecd = *eecd | E1000_EECD_SK;
 22.2259 +    E1000_WRITE_REG(hw, EECD, *eecd);
 22.2260 +    E1000_WRITE_FLUSH(hw);
 22.2261 +    udelay(50);
 22.2262 +}
 22.2263 +
 22.2264 +/******************************************************************************
 22.2265 + * Lowers the EEPROM's clock input.
 22.2266 + *
 22.2267 + * hw - Struct containing variables accessed by shared code 
 22.2268 + * eecd - EECD's current value
 22.2269 + *****************************************************************************/
 22.2270 +static void
 22.2271 +e1000_lower_ee_clk(struct e1000_hw *hw,
 22.2272 +                   uint32_t *eecd)
 22.2273 +{
 22.2274 +    /* Lower the clock input to the EEPROM (by clearing the SK bit), and then 
 22.2275 +     * wait 50 microseconds. 
 22.2276 +     */
 22.2277 +    *eecd = *eecd & ~E1000_EECD_SK;
 22.2278 +    E1000_WRITE_REG(hw, EECD, *eecd);
 22.2279 +    E1000_WRITE_FLUSH(hw);
 22.2280 +    udelay(50);
 22.2281 +}
 22.2282 +
 22.2283 +/******************************************************************************
 22.2284 + * Shift data bits out to the EEPROM.
 22.2285 + *
 22.2286 + * hw - Struct containing variables accessed by shared code
 22.2287 + * data - data to send to the EEPROM
 22.2288 + * count - number of bits to shift out
 22.2289 + *****************************************************************************/
 22.2290 +static void
 22.2291 +e1000_shift_out_ee_bits(struct e1000_hw *hw,
 22.2292 +                        uint16_t data,
 22.2293 +                        uint16_t count)
 22.2294 +{
 22.2295 +    uint32_t eecd;
 22.2296 +    uint32_t mask;
 22.2297 +
 22.2298 +    /* We need to shift "count" bits out to the EEPROM. So, value in the
 22.2299 +     * "data" parameter will be shifted out to the EEPROM one bit at a time.
 22.2300 +     * In order to do this, "data" must be broken down into bits. 
 22.2301 +     */
 22.2302 +    mask = 0x01 << (count - 1);
 22.2303 +    eecd = E1000_READ_REG(hw, EECD);
 22.2304 +    eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
 22.2305 +    do {
 22.2306 +        /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
 22.2307 +         * and then raising and then lowering the clock (the SK bit controls
 22.2308 +         * the clock input to the EEPROM).  A "0" is shifted out to the EEPROM
 22.2309 +         * by setting "DI" to "0" and then raising and then lowering the clock.
 22.2310 +         */
 22.2311 +        eecd &= ~E1000_EECD_DI;
 22.2312 +
 22.2313 +        if(data & mask)
 22.2314 +            eecd |= E1000_EECD_DI;
 22.2315 +
 22.2316 +        E1000_WRITE_REG(hw, EECD, eecd);
 22.2317 +        E1000_WRITE_FLUSH(hw);
 22.2318 +
 22.2319 +        udelay(50);
 22.2320 +
 22.2321 +        e1000_raise_ee_clk(hw, &eecd);
 22.2322 +        e1000_lower_ee_clk(hw, &eecd);
 22.2323 +
 22.2324 +        mask = mask >> 1;
 22.2325 +
 22.2326 +    } while(mask);
 22.2327 +
 22.2328 +    /* We leave the "DI" bit set to "0" when we leave this routine. */
 22.2329 +    eecd &= ~E1000_EECD_DI;
 22.2330 +    E1000_WRITE_REG(hw, EECD, eecd);
 22.2331 +}
 22.2332 +
 22.2333 +/******************************************************************************
 22.2334 + * Shift data bits in from the EEPROM
 22.2335 + *
 22.2336 + * hw - Struct containing variables accessed by shared code
 22.2337 + *****************************************************************************/
 22.2338 +static uint16_t
 22.2339 +e1000_shift_in_ee_bits(struct e1000_hw *hw)
 22.2340 +{
 22.2341 +    uint32_t eecd;
 22.2342 +    uint32_t i;
 22.2343 +    uint16_t data;
 22.2344 +
 22.2345 +    /* In order to read a register from the EEPROM, we need to shift 'count'
 22.2346 +     * bits in from the EEPROM. Bits are "shifted in" by raising the clock
 22.2347 +     * input to the EEPROM (setting the SK bit), and then reading the value of
 22.2348 +     * the "DO" bit.  During this "shifting in" process the "DI" bit should
 22.2349 +     * always be clear.
 22.2350 +     */
 22.2351 +
 22.2352 +    eecd = E1000_READ_REG(hw, EECD);
 22.2353 +
 22.2354 +    eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
 22.2355 +    data = 0;
 22.2356 +
 22.2357 +    for(i = 0; i < 16; i++) {
 22.2358 +        data = data << 1;
 22.2359 +        e1000_raise_ee_clk(hw, &eecd);
 22.2360 +
 22.2361 +        eecd = E1000_READ_REG(hw, EECD);
 22.2362 +
 22.2363 +        eecd &= ~(E1000_EECD_DI);
 22.2364 +        if(eecd & E1000_EECD_DO)
 22.2365 +            data |= 1;
 22.2366 +
 22.2367 +        e1000_lower_ee_clk(hw, &eecd);
 22.2368 +    }
 22.2369 +
 22.2370 +    return data;
 22.2371 +}
 22.2372 +
 22.2373 +/******************************************************************************
 22.2374 + * Prepares EEPROM for access
 22.2375 + *
 22.2376 + * hw - Struct containing variables accessed by shared code
 22.2377 + *
 22.2378 + * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This 
 22.2379 + * function should be called before issuing a command to the EEPROM.
 22.2380 + *****************************************************************************/
 22.2381 +static void
 22.2382 +e1000_setup_eeprom(struct e1000_hw *hw)
 22.2383 +{
 22.2384 +    uint32_t eecd;
 22.2385 +
 22.2386 +    eecd = E1000_READ_REG(hw, EECD);
 22.2387 +
 22.2388 +    /* Clear SK and DI */
 22.2389 +    eecd &= ~(E1000_EECD_SK | E1000_EECD_DI);
 22.2390 +    E1000_WRITE_REG(hw, EECD, eecd);
 22.2391 +
 22.2392 +    /* Set CS */
 22.2393 +    eecd |= E1000_EECD_CS;
 22.2394 +    E1000_WRITE_REG(hw, EECD, eecd);
 22.2395 +}
 22.2396 +
 22.2397 +/******************************************************************************
 22.2398 + * Returns EEPROM to a "standby" state
 22.2399 + * 
 22.2400 + * hw - Struct containing variables accessed by shared code
 22.2401 + *****************************************************************************/
 22.2402 +static void
 22.2403 +e1000_standby_eeprom(struct e1000_hw *hw)
 22.2404 +{
 22.2405 +    uint32_t eecd;
 22.2406 +
 22.2407 +    eecd = E1000_READ_REG(hw, EECD);
 22.2408 +
 22.2409 +    /* Deselct EEPROM */
 22.2410 +    eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
 22.2411 +    E1000_WRITE_REG(hw, EECD, eecd);
 22.2412 +    E1000_WRITE_FLUSH(hw);
 22.2413 +    udelay(50);
 22.2414 +
 22.2415 +    /* Clock high */
 22.2416 +    eecd |= E1000_EECD_SK;
 22.2417 +    E1000_WRITE_REG(hw, EECD, eecd);
 22.2418 +    E1000_WRITE_FLUSH(hw);
 22.2419 +    udelay(50);
 22.2420 +
 22.2421 +    /* Select EEPROM */
 22.2422 +    eecd |= E1000_EECD_CS;
 22.2423 +    E1000_WRITE_REG(hw, EECD, eecd);
 22.2424 +    E1000_WRITE_FLUSH(hw);
 22.2425 +    udelay(50);
 22.2426 +
 22.2427 +    /* Clock low */
 22.2428 +    eecd &= ~E1000_EECD_SK;
 22.2429 +    E1000_WRITE_REG(hw, EECD, eecd);
 22.2430 +    E1000_WRITE_FLUSH(hw);
 22.2431 +    udelay(50);
 22.2432 +}
 22.2433 +
 22.2434 +/******************************************************************************
 22.2435 + * Raises then lowers the EEPROM's clock pin
 22.2436 + *
 22.2437 + * hw - Struct containing variables accessed by shared code
 22.2438 + *****************************************************************************/
 22.2439 +static void
 22.2440 +e1000_clock_eeprom(struct e1000_hw *hw)
 22.2441 +{
 22.2442 +    uint32_t eecd;
 22.2443 +
 22.2444 +    eecd = E1000_READ_REG(hw, EECD);
 22.2445 +
 22.2446 +    /* Rising edge of clock */
 22.2447 +    eecd |= E1000_EECD_SK;
 22.2448 +    E1000_WRITE_REG(hw, EECD, eecd);
 22.2449 +    E1000_WRITE_FLUSH(hw);
 22.2450 +    udelay(50);
 22.2451 +
 22.2452 +    /* Falling edge of clock */
 22.2453 +    eecd &= ~E1000_EECD_SK;
 22.2454 +    E1000_WRITE_REG(hw, EECD, eecd);
 22.2455 +    E1000_WRITE_FLUSH(hw);
 22.2456 +    udelay(50);
 22.2457 +}
 22.2458 +
 22.2459 +/******************************************************************************
 22.2460 + * Terminates a command by lowering the EEPROM's chip select pin
 22.2461 + *
 22.2462 + * hw - Struct containing variables accessed by shared code
 22.2463 + *****************************************************************************/
 22.2464 +static void
 22.2465 +e1000_cleanup_eeprom(struct e1000_hw *hw)
 22.2466 +{
 22.2467 +    uint32_t eecd;
 22.2468 +
 22.2469 +    eecd = E1000_READ_REG(hw, EECD);
 22.2470 +
 22.2471 +    eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
 22.2472 +
 22.2473 +    E1000_WRITE_REG(hw, EECD, eecd);
 22.2474 +
 22.2475 +    e1000_clock_eeprom(hw);
 22.2476 +}
 22.2477 +
 22.2478 +/******************************************************************************
 22.2479 + * Reads a 16 bit word from the EEPROM.
 22.2480 + *
 22.2481 + * hw - Struct containing variables accessed by shared code
 22.2482 + * offset - offset of  word in the EEPROM to read
 22.2483 + * data - word read from the EEPROM 
 22.2484 + *****************************************************************************/
 22.2485 +int32_t
 22.2486 +e1000_read_eeprom(struct e1000_hw *hw,
 22.2487 +                  uint16_t offset,
 22.2488 +                  uint16_t *data)
 22.2489 +{
 22.2490 +    uint32_t eecd;
 22.2491 +    uint32_t i = 0;
 22.2492 +    boolean_t large_eeprom = FALSE;
 22.2493 +
 22.2494 +    DEBUGFUNC("e1000_read_eeprom");
 22.2495 +
 22.2496 +    /* Request EEPROM Access */
 22.2497 +    if(hw->mac_type > e1000_82544) {
 22.2498 +        eecd = E1000_READ_REG(hw, EECD);
 22.2499 +        if(eecd & E1000_EECD_SIZE) large_eeprom = TRUE;
 22.2500 +        eecd |= E1000_EECD_REQ;
 22.2501 +        E1000_WRITE_REG(hw, EECD, eecd);
 22.2502 +        eecd = E1000_READ_REG(hw, EECD);
 22.2503 +        while((!(eecd & E1000_EECD_GNT)) && (i < 100)) {
 22.2504 +            i++;
 22.2505 +            udelay(5);
 22.2506 +            eecd = E1000_READ_REG(hw, EECD);
 22.2507 +        }
 22.2508 +        if(!(eecd & E1000_EECD_GNT)) {
 22.2509 +            eecd &= ~E1000_EECD_REQ;
 22.2510 +            E1000_WRITE_REG(hw, EECD, eecd);
 22.2511 +            DEBUGOUT("Could not acquire EEPROM grant\n");
 22.2512 +            return -E1000_ERR_EEPROM;
 22.2513 +        }
 22.2514 +    }
 22.2515 +
 22.2516 +    /*  Prepare the EEPROM for reading  */
 22.2517 +    e1000_setup_eeprom(hw);
 22.2518 +
 22.2519 +    /*  Send the READ command (opcode + addr)  */
 22.2520 +    e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE, 3);
 22.2521 +    if(large_eeprom) {
 22.2522 +        /* If we have a 256 word EEPROM, there are 8 address bits */
 22.2523 +        e1000_shift_out_ee_bits(hw, offset, 8);
 22.2524 +    } else {
 22.2525 +        /* If we have a 64 word EEPROM, there are 6 address bits */
 22.2526 +        e1000_shift_out_ee_bits(hw, offset, 6);
 22.2527 +    }
 22.2528 +
 22.2529 +    /* Read the data */
 22.2530 +    *data = e1000_shift_in_ee_bits(hw);
 22.2531 +
 22.2532 +    /* End this read operation */
 22.2533 +    e1000_standby_eeprom(hw);
 22.2534 +
 22.2535 +    /* Stop requesting EEPROM access */
 22.2536 +    if(hw->mac_type > e1000_82544) {
 22.2537 +        eecd = E1000_READ_REG(hw, EECD);
 22.2538 +        eecd &= ~E1000_EECD_REQ;
 22.2539 +        E1000_WRITE_REG(hw, EECD, eecd);
 22.2540 +    }
 22.2541 +
 22.2542 +    return 0;
 22.2543 +}
 22.2544 +
 22.2545 +/******************************************************************************
 22.2546 + * Verifies that the EEPROM has a valid checksum
 22.2547 + * 
 22.2548 + * hw - Struct containing variables accessed by shared code
 22.2549 + *
 22.2550 + * Reads the first 64 16 bit words of the EEPROM and sums the values read.
 22.2551 + * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
 22.2552 + * valid.
 22.2553 + *****************************************************************************/
 22.2554 +int32_t
 22.2555 +e1000_validate_eeprom_checksum(struct e1000_hw *hw)
 22.2556 +{
 22.2557 +    uint16_t checksum = 0;
 22.2558 +    uint16_t i, eeprom_data;
 22.2559 +
 22.2560 +    DEBUGFUNC("e1000_validate_eeprom_checksum");
 22.2561 +
 22.2562 +    for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
 22.2563 +        if(e1000_read_eeprom(hw, i, &eeprom_data) < 0) {
 22.2564 +            DEBUGOUT("EEPROM Read Error\n");
 22.2565 +            return -E1000_ERR_EEPROM;
 22.2566 +        }
 22.2567 +        checksum += eeprom_data;
 22.2568 +    }
 22.2569 +
 22.2570 +    if(checksum == (uint16_t) EEPROM_SUM) {
 22.2571 +        return 0;
 22.2572 +    } else {
 22.2573 +        DEBUGOUT("EEPROM Checksum Invalid\n");    
 22.2574 +        return -E1000_ERR_EEPROM;
 22.2575 +    }
 22.2576 +}
 22.2577 +
 22.2578 +/******************************************************************************
 22.2579 + * Calculates the EEPROM checksum and writes it to the EEPROM
 22.2580 + *
 22.2581 + * hw - Struct containing variables accessed by shared code
 22.2582 + *
 22.2583 + * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
 22.2584 + * Writes the difference to word offset 63 of the EEPROM.
 22.2585 + *****************************************************************************/
 22.2586 +int32_t
 22.2587 +e1000_update_eeprom_checksum(struct e1000_hw *hw)
 22.2588 +{
 22.2589 +    uint16_t checksum = 0;
 22.2590 +    uint16_t i, eeprom_data;
 22.2591 +
 22.2592 +    DEBUGFUNC("e1000_update_eeprom_checksum");
 22.2593 +
 22.2594 +    for(i = 0; i < EEPROM_CHECKSUM_REG; i++) {
 22.2595 +        if(e1000_read_eeprom(hw, i, &eeprom_data) < 0) {
 22.2596 +            DEBUGOUT("EEPROM Read Error\n");
 22.2597 +            return -E1000_ERR_EEPROM;
 22.2598 +        }
 22.2599 +        checksum += eeprom_data;
 22.2600 +    }
 22.2601 +    checksum = (uint16_t) EEPROM_SUM - checksum;
 22.2602 +    if(e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, checksum) < 0) {
 22.2603 +        DEBUGOUT("EEPROM Write Error\n");
 22.2604 +        return -E1000_ERR_EEPROM;
 22.2605 +    }
 22.2606 +    return 0;
 22.2607 +}
 22.2608 +
 22.2609 +/******************************************************************************
 22.2610 + * Writes a 16 bit word to a given offset in the EEPROM.
 22.2611 + *
 22.2612 + * hw - Struct containing variables accessed by shared code
 22.2613 + * offset - offset within the EEPROM to be written to
 22.2614 + * data - 16 bit word to be writen to the EEPROM
 22.2615 + *
 22.2616 + * If e1000_update_eeprom_checksum is not called after this function, the 
 22.2617 + * EEPROM will most likely contain an invalid checksum.
 22.2618 + *****************************************************************************/
 22.2619 +int32_t
 22.2620 +e1000_write_eeprom(struct e1000_hw *hw,
 22.2621 +                   uint16_t offset,
 22.2622 +                   uint16_t data)
 22.2623 +{
 22.2624 +    uint32_t eecd;
 22.2625 +    uint32_t i = 0;
 22.2626 +    int32_t status = 0;
 22.2627 +    boolean_t large_eeprom = FALSE;
 22.2628 +
 22.2629 +    DEBUGFUNC("e1000_write_eeprom");
 22.2630 +
 22.2631 +    /* Request EEPROM Access */
 22.2632 +    if(hw->mac_type > e1000_82544) {
 22.2633 +        eecd = E1000_READ_REG(hw, EECD);
 22.2634 +        if(eecd & E1000_EECD_SIZE) large_eeprom = TRUE;
 22.2635 +        eecd |= E1000_EECD_REQ;
 22.2636 +        E1000_WRITE_REG(hw, EECD, eecd);
 22.2637 +        eecd = E1000_READ_REG(hw, EECD);
 22.2638 +        while((!(eecd & E1000_EECD_GNT)) && (i < 100)) {
 22.2639 +            i++;
 22.2640 +            udelay(5);
 22.2641 +            eecd = E1000_READ_REG(hw, EECD);
 22.2642 +        }
 22.2643 +        if(!(eecd & E1000_EECD_GNT)) {
 22.2644 +            eecd &= ~E1000_EECD_REQ;
 22.2645 +            E1000_WRITE_REG(hw, EECD, eecd);
 22.2646 +            DEBUGOUT("Could not acquire EEPROM grant\n");
 22.2647 +            return -E1000_ERR_EEPROM;
 22.2648 +        }
 22.2649 +    }
 22.2650 +
 22.2651 +    /* Prepare the EEPROM for writing  */
 22.2652 +    e1000_setup_eeprom(hw);
 22.2653 +
 22.2654 +    /* Send the 9-bit (or 11-bit on large EEPROM) EWEN (write enable) command
 22.2655 +     * to the EEPROM (5-bit opcode plus 4/6-bit dummy). This puts the EEPROM
 22.2656 +     * into write/erase mode. 
 22.2657 +     */
 22.2658 +    e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE, 5);
 22.2659 +    if(large_eeprom) 
 22.2660 +        e1000_shift_out_ee_bits(hw, 0, 6);
 22.2661 +    else
 22.2662 +        e1000_shift_out_ee_bits(hw, 0, 4);
 22.2663 +
 22.2664 +    /* Prepare the EEPROM */
 22.2665 +    e1000_standby_eeprom(hw);
 22.2666 +
 22.2667 +    /* Send the Write command (3-bit opcode + addr) */
 22.2668 +    e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE, 3);
 22.2669 +    if(large_eeprom) 
 22.2670 +        /* If we have a 256 word EEPROM, there are 8 address bits */
 22.2671 +        e1000_shift_out_ee_bits(hw, offset, 8);
 22.2672 +    else
 22.2673 +        /* If we have a 64 word EEPROM, there are 6 address bits */
 22.2674 +        e1000_shift_out_ee_bits(hw, offset, 6);
 22.2675 +
 22.2676 +    /* Send the data */
 22.2677 +    e1000_shift_out_ee_bits(hw, data, 16);
 22.2678 +
 22.2679 +    /* Toggle the CS line.  This in effect tells to EEPROM to actually execute 
 22.2680 +     * the command in question.
 22.2681 +     */
 22.2682 +    e1000_standby_eeprom(hw);
 22.2683 +
 22.2684 +    /* Now read DO repeatedly until is high (equal to '1').  The EEEPROM will
 22.2685 +     * signal that the command has been completed by raising the DO signal.
 22.2686 +     * If DO does not go high in 10 milliseconds, then error out.
 22.2687 +     */
 22.2688 +    for(i = 0; i < 200; i++) {
 22.2689 +        eecd = E1000_READ_REG(hw, EECD);
 22.2690 +        if(eecd & E1000_EECD_DO) break;
 22.2691 +        udelay(50);
 22.2692 +    }
 22.2693 +    if(i == 200) {
 22.2694 +        DEBUGOUT("EEPROM Write did not complete\n");
 22.2695 +        status = -E1000_ERR_EEPROM;
 22.2696 +    }
 22.2697 +
 22.2698 +    /* Recover from write */
 22.2699 +    e1000_standby_eeprom(hw);
 22.2700 +
 22.2701 +    /* Send the 9-bit (or 11-bit on large EEPROM) EWDS (write disable) command
 22.2702 +     * to the EEPROM (5-bit opcode plus 4/6-bit dummy). This takes the EEPROM
 22.2703 +     * out of write/erase mode.
 22.2704 +     */
 22.2705 +    e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE, 5);
 22.2706 +    if(large_eeprom) 
 22.2707 +        e1000_shift_out_ee_bits(hw, 0, 6);
 22.2708 +    else
 22.2709 +        e1000_shift_out_ee_bits(hw, 0, 4);
 22.2710 +
 22.2711 +    /* Done with writing */
 22.2712 +    e1000_cleanup_eeprom(hw);
 22.2713 +
 22.2714 +    /* Stop requesting EEPROM access */
 22.2715 +    if(hw->mac_type > e1000_82544) {
 22.2716 +        eecd = E1000_READ_REG(hw, EECD);
 22.2717 +        eecd &= ~E1000_EECD_REQ;
 22.2718 +        E1000_WRITE_REG(hw, EECD, eecd);
 22.2719 +    }
 22.2720 +
 22.2721 +    return status;
 22.2722 +}
 22.2723 +
 22.2724 +/******************************************************************************
 22.2725 + * Reads the adapter's part number from the EEPROM
 22.2726 + *
 22.2727 + * hw - Struct containing variables accessed by shared code
 22.2728 + * part_num - Adapter's part number
 22.2729 + *****************************************************************************/
 22.2730 +int32_t
 22.2731 +e1000_read_part_num(struct e1000_hw *hw,
 22.2732 +                    uint32_t *part_num)
 22.2733 +{
 22.2734 +    uint16_t offset = EEPROM_PBA_BYTE_1;
 22.2735 +    uint16_t eeprom_data;
 22.2736 +
 22.2737 +    DEBUGFUNC("e1000_read_part_num");
 22.2738 +
 22.2739 +    /* Get word 0 from EEPROM */
 22.2740 +    if(e1000_read_eeprom(hw, offset, &eeprom_data) < 0) {
 22.2741 +        DEBUGOUT("EEPROM Read Error\n");
 22.2742 +        return -E1000_ERR_EEPROM;
 22.2743 +    }
 22.2744 +    /* Save word 0 in upper half of part_num */
 22.2745 +    *part_num = (uint32_t) (eeprom_data << 16);
 22.2746 +
 22.2747 +    /* Get word 1 from EEPROM */
 22.2748 +    if(e1000_read_eeprom(hw, ++offset, &eeprom_data) < 0) {
 22.2749 +        DEBUGOUT("EEPROM Read Error\n");
 22.2750 +        return -E1000_ERR_EEPROM;
 22.2751 +    }
 22.2752 +    /* Save word 1 in lower half of part_num */
 22.2753 +    *part_num |= eeprom_data;
 22.2754 +
 22.2755 +    return 0;
 22.2756 +}
 22.2757 +
 22.2758 +/******************************************************************************
 22.2759 + * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
 22.2760 + * second function of dual function devices
 22.2761 + *
 22.2762 + * hw - Struct containing variables accessed by shared code
 22.2763 + *****************************************************************************/
 22.2764 +int32_t
 22.2765 +e1000_read_mac_addr(struct e1000_hw * hw)
 22.2766 +{
 22.2767 +    uint16_t offset;
 22.2768 +    uint16_t eeprom_data, i;
 22.2769 +
 22.2770 +    DEBUGFUNC("e1000_read_mac_addr");
 22.2771 +
 22.2772 +    for(i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
 22.2773 +        offset = i >> 1;
 22.2774 +        if(e1000_read_eeprom(hw, offset, &eeprom_data) < 0) {
 22.2775 +            DEBUGOUT("EEPROM Read Error\n");
 22.2776 +            return -E1000_ERR_EEPROM;
 22.2777 +        }
 22.2778 +        hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
 22.2779 +        hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
 22.2780 +    }
 22.2781 +    if((hw->mac_type == e1000_82546) &&
 22.2782 +       (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
 22.2783 +        if(hw->perm_mac_addr[5] & 0x01)
 22.2784 +            hw->perm_mac_addr[5] &= ~(0x01);
 22.2785 +        else
 22.2786 +            hw->perm_mac_addr[5] |= 0x01;
 22.2787 +    }
 22.2788 +    for(i = 0; i < NODE_ADDRESS_SIZE; i++)
 22.2789 +        hw->mac_addr[i] = hw->perm_mac_addr[i];
 22.2790 +    return 0;
 22.2791 +}
 22.2792 +
 22.2793 +/******************************************************************************
 22.2794 + * Initializes receive address filters.
 22.2795 + *
 22.2796 + * hw - Struct containing variables accessed by shared code 
 22.2797 + *
 22.2798 + * Places the MAC address in receive address register 0 and clears the rest
 22.2799 + * of the receive addresss registers. Clears the multicast table. Assumes
 22.2800 + * the receiver is in reset when the routine is called.
 22.2801 + *****************************************************************************/
 22.2802 +void
 22.2803 +e1000_init_rx_addrs(struct e1000_hw *hw)
 22.2804 +{
 22.2805 +    uint32_t i;
 22.2806 +    uint32_t addr_low;
 22.2807 +    uint32_t addr_high;
 22.2808 +
 22.2809 +    DEBUGFUNC("e1000_init_rx_addrs");
 22.2810 +
 22.2811 +    /* Setup the receive address. */
 22.2812 +    DEBUGOUT("Programming MAC Address into RAR[0]\n");
 22.2813 +    addr_low = (hw->mac_addr[0] |
 22.2814 +                (hw->mac_addr[1] << 8) |
 22.2815 +                (hw->mac_addr[2] << 16) | (hw->mac_addr[3] << 24));
 22.2816 +
 22.2817 +    addr_high = (hw->mac_addr[4] |
 22.2818 +                 (hw->mac_addr[5] << 8) | E1000_RAH_AV);
 22.2819 +
 22.2820 +    E1000_WRITE_REG_ARRAY(hw, RA, 0, addr_low);
 22.2821 +    E1000_WRITE_REG_ARRAY(hw, RA, 1, addr_high);
 22.2822 +
 22.2823 +    /* Zero out the other 15 receive addresses. */
 22.2824 +    DEBUGOUT("Clearing RAR[1-15]\n");
 22.2825 +    for(i = 1; i < E1000_RAR_ENTRIES; i++) {
 22.2826 +        E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
 22.2827 +        E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
 22.2828 +    }
 22.2829 +}
 22.2830 +
 22.2831 +/******************************************************************************
 22.2832 + * Updates the MAC's list of multicast addresses.
 22.2833 + *
 22.2834 + * hw - Struct containing variables accessed by shared code
 22.2835 + * mc_addr_list - the list of new multicast addresses
 22.2836 + * mc_addr_count - number of addresses
 22.2837 + * pad - number of bytes between addresses in the list
 22.2838 + *
 22.2839 + * The given list replaces any existing list. Clears the last 15 receive
 22.2840 + * address registers and the multicast table. Uses receive address registers
 22.2841 + * for the first 15 multicast addresses, and hashes the rest into the 
 22.2842 + * multicast table.
 22.2843 + *****************************************************************************/
 22.2844 +void
 22.2845 +e1000_mc_addr_list_update(struct e1000_hw *hw,
 22.2846 +                          uint8_t *mc_addr_list,
 22.2847 +                          uint32_t mc_addr_count,
 22.2848 +                          uint32_t pad)
 22.2849 +{
 22.2850 +    uint32_t hash_value;
 22.2851 +    uint32_t i;
 22.2852 +    uint32_t rar_used_count = 1; /* RAR[0] is used for our MAC address */
 22.2853 +
 22.2854 +    DEBUGFUNC("e1000_mc_addr_list_update");
 22.2855 +
 22.2856 +    /* Set the new number of MC addresses that we are being requested to use. */
 22.2857 +    hw->num_mc_addrs = mc_addr_count;
 22.2858 +
 22.2859 +    /* Clear RAR[1-15] */
 22.2860 +    DEBUGOUT(" Clearing RAR[1-15]\n");
 22.2861 +    for(i = rar_used_count; i < E1000_RAR_ENTRIES; i++) {
 22.2862 +        E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
 22.2863 +        E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
 22.2864 +    }
 22.2865 +
 22.2866 +    /* Clear the MTA */
 22.2867 +    DEBUGOUT(" Clearing MTA\n");
 22.2868 +    for(i = 0; i < E1000_NUM_MTA_REGISTERS; i++) {
 22.2869 +        E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
 22.2870 +    }
 22.2871 +
 22.2872 +    /* Add the new addresses */
 22.2873 +    for(i = 0; i < mc_addr_count; i++) {
 22.2874 +        DEBUGOUT(" Adding the multicast addresses:\n");
 22.2875 +        DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
 22.2876 +                  mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
 22.2877 +                  mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
 22.2878 +                  mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
 22.2879 +                  mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
 22.2880 +                  mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
 22.2881 +                  mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
 22.2882 +
 22.2883 +        hash_value = e1000_hash_mc_addr(hw,
 22.2884 +                                        mc_addr_list +
 22.2885 +                                        (i * (ETH_LENGTH_OF_ADDRESS + pad)));
 22.2886 +
 22.2887 +        DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
 22.2888 +
 22.2889 +        /* Place this multicast address in the RAR if there is room, *
 22.2890 +         * else put it in the MTA            
 22.2891 +         */
 22.2892 +        if(rar_used_count < E1000_RAR_ENTRIES) {
 22.2893 +            e1000_rar_set(hw,
 22.2894 +                          mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
 22.2895 +                          rar_used_count);
 22.2896 +            rar_used_count++;
 22.2897 +        } else {
 22.2898 +            e1000_mta_set(hw, hash_value);
 22.2899 +        }
 22.2900 +    }
 22.2901 +    DEBUGOUT("MC Update Complete\n");
 22.2902 +}
 22.2903 +
 22.2904 +/******************************************************************************
 22.2905 + * Hashes an address to determine its location in the multicast table
 22.2906 + *
 22.2907 + * hw - Struct containing variables accessed by shared code
 22.2908 + * mc_addr - the multicast address to hash 
 22.2909 + *****************************************************************************/
 22.2910 +uint32_t
 22.2911 +e1000_hash_mc_addr(struct e1000_hw *hw,
 22.2912 +                   uint8_t *mc_addr)
 22.2913 +{
 22.2914 +    uint32_t hash_value = 0;
 22.2915 +
 22.2916 +    /* The portion of the address that is used for the hash table is
 22.2917 +     * determined by the mc_filter_type setting.  
 22.2918 +     */
 22.2919 +    switch (hw->mc_filter_type) {
 22.2920 +    /* [0] [1] [2] [3] [4] [5]
 22.2921 +     * 01  AA  00  12  34  56
 22.2922 +     * LSB                 MSB
 22.2923 +     */
 22.2924 +    case 0:
 22.2925 +        /* [47:36] i.e. 0x563 for above example address */
 22.2926 +        hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
 22.2927 +        break;
 22.2928 +    case 1:
 22.2929 +        /* [46:35] i.e. 0xAC6 for above example address */
 22.2930 +        hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
 22.2931 +        break;
 22.2932 +    case 2:
 22.2933 +        /* [45:34] i.e. 0x5D8 for above example address */
 22.2934 +        hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
 22.2935 +        break;
 22.2936 +    case 3:
 22.2937 +        /* [43:32] i.e. 0x634 for above example address */
 22.2938 +        hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
 22.2939 +        break;
 22.2940 +    }
 22.2941 +
 22.2942 +    hash_value &= 0xFFF;
 22.2943 +    return hash_value;
 22.2944 +}
 22.2945 +
 22.2946 +/******************************************************************************
 22.2947 + * Sets the bit in the multicast table corresponding to the hash value.
 22.2948 + *
 22.2949 + * hw - Struct containing variables accessed by shared code
 22.2950 + * hash_value - Multicast address hash value
 22.2951 + *****************************************************************************/
 22.2952 +void
 22.2953 +e1000_mta_set(struct e1000_hw *hw,
 22.2954 +              uint32_t hash_value)
 22.2955 +{
 22.2956 +    uint32_t hash_bit, hash_reg;
 22.2957 +    uint32_t mta;
 22.2958 +    uint32_t temp;
 22.2959 +
 22.2960 +    /* The MTA is a register array of 128 32-bit registers.  
 22.2961 +     * It is treated like an array of 4096 bits.  We want to set 
 22.2962 +     * bit BitArray[hash_value]. So we figure out what register
 22.2963 +     * the bit is in, read it, OR in the new bit, then write
 22.2964 +     * back the new value.  The register is determined by the 
 22.2965 +     * upper 7 bits of the hash value and the bit within that 
 22.2966 +     * register are determined by the lower 5 bits of the value.
 22.2967 +     */
 22.2968 +    hash_reg = (hash_value >> 5) & 0x7F;
 22.2969 +    hash_bit = hash_value & 0x1F;
 22.2970 +
 22.2971 +    mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
 22.2972 +
 22.2973 +    mta |= (1 << hash_bit);
 22.2974 +
 22.2975 +    /* If we are on an 82544 and we are trying to write an odd offset
 22.2976 +     * in the MTA, save off the previous entry before writing and
 22.2977 +     * restore the old value after writing.
 22.2978 +     */
 22.2979 +    if((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
 22.2980 +        temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
 22.2981 +        E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
 22.2982 +        E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
 22.2983 +    } else {
 22.2984 +        E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
 22.2985 +    }
 22.2986 +}
 22.2987 +
 22.2988 +/******************************************************************************
 22.2989 + * Puts an ethernet address into a receive address register.
 22.2990 + *
 22.2991 + * hw - Struct containing variables accessed by shared code
 22.2992 + * addr - Address to put into receive address register
 22.2993 + * index - Receive address register to write
 22.2994 + *****************************************************************************/
 22.2995 +void
 22.2996 +e1000_rar_set(struct e1000_hw *hw,
 22.2997 +              uint8_t *addr,
 22.2998 +              uint32_t index)
 22.2999 +{
 22.3000 +    uint32_t rar_low, rar_high;
 22.3001 +
 22.3002 +    /* HW expects these in little endian so we reverse the byte order
 22.3003 +     * from network order (big endian) to little endian              
 22.3004 +     */
 22.3005 +    rar_low = ((uint32_t) addr[0] |
 22.3006 +               ((uint32_t) addr[1] << 8) |
 22.3007 +               ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
 22.3008 +
 22.3009 +    rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8) | E1000_RAH_AV);
 22.3010 +
 22.3011 +    E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
 22.3012 +    E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
 22.3013 +}
 22.3014 +
 22.3015 +/******************************************************************************
 22.3016 + * Writes a value to the specified offset in the VLAN filter table.
 22.3017 + *
 22.3018 + * hw - Struct containing variables accessed by shared code
 22.3019 + * offset - Offset in VLAN filer table to write
 22.3020 + * value - Value to write into VLAN filter table
 22.3021 + *****************************************************************************/
 22.3022 +void
 22.3023 +e1000_write_vfta(struct e1000_hw *hw,
 22.3024 +                 uint32_t offset,
 22.3025 +                 uint32_t value)
 22.3026 +{
 22.3027 +    uint32_t temp;
 22.3028 +
 22.3029 +    if((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
 22.3030 +        temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
 22.3031 +        E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
 22.3032 +        E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
 22.3033 +    } else {
 22.3034 +        E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
 22.3035 +    }
 22.3036 +}
 22.3037 +
 22.3038 +/******************************************************************************
 22.3039 + * Clears the VLAN filer table
 22.3040 + *
 22.3041 + * hw - Struct containing variables accessed by shared code
 22.3042 + *****************************************************************************/
 22.3043 +void
 22.3044 +e1000_clear_vfta(struct e1000_hw *hw)
 22.3045 +{
 22.3046 +    uint32_t offset;
 22.3047 +
 22.3048 +    for(offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++)
 22.3049 +        E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
 22.3050 +}
 22.3051 +
 22.3052 +static int32_t
 22.3053 +e1000_id_led_init(struct e1000_hw * hw)
 22.3054 +{
 22.3055 +    uint32_t ledctl;
 22.3056 +    const uint32_t ledctl_mask = 0x000000FF;
 22.3057 +    const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
 22.3058 +    const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
 22.3059 +    uint16_t eeprom_data, i, temp;
 22.3060 +    const uint16_t led_mask = 0x0F;
 22.3061 +        
 22.3062 +    DEBUGFUNC("e1000_id_led_init");
 22.3063 +    
 22.3064 +    if(hw->mac_type < e1000_82540) {
 22.3065 +        /* Nothing to do */
 22.3066 +        return 0;
 22.3067 +    }
 22.3068 +    
 22.3069 +    ledctl = E1000_READ_REG(hw, LEDCTL);
 22.3070 +    hw->ledctl_default = ledctl;
 22.3071 +    hw->ledctl_mode1 = hw->ledctl_default;
 22.3072 +    hw->ledctl_mode2 = hw->ledctl_default;
 22.3073 +        
 22.3074 +    if(e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, &eeprom_data) < 0) {
 22.3075 +        DEBUGOUT("EEPROM Read Error\n");
 22.3076 +        return -E1000_ERR_EEPROM;
 22.3077 +    }
 22.3078 +    if((eeprom_data== ID_LED_RESERVED_0000) || 
 22.3079 +       (eeprom_data == ID_LED_RESERVED_FFFF)) eeprom_data = ID_LED_DEFAULT;
 22.3080 +    for(i = 0; i < 4; i++) {
 22.3081 +        temp = (eeprom_data >> (i << 2)) & led_mask;
 22.3082 +        switch(temp) {
 22.3083 +        case ID_LED_ON1_DEF2:
 22.3084 +        case ID_LED_ON1_ON2:
 22.3085 +        case ID_LED_ON1_OFF2:
 22.3086 +            hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
 22.3087 +            hw->ledctl_mode1 |= ledctl_on << (i << 3);
 22.3088 +            break;
 22.3089 +        case ID_LED_OFF1_DEF2:
 22.3090 +        case ID_LED_OFF1_ON2:
 22.3091 +        case ID_LED_OFF1_OFF2:
 22.3092 +            hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
 22.3093 +            hw->ledctl_mode1 |= ledctl_off << (i << 3);
 22.3094 +            break;
 22.3095 +        default:
 22.3096 +            /* Do nothing */
 22.3097 +            break;
 22.3098 +        }
 22.3099 +        switch(temp) {
 22.3100 +        case ID_LED_DEF1_ON2:
 22.3101 +        case ID_LED_ON1_ON2:
 22.3102 +        case ID_LED_OFF1_ON2:
 22.3103 +            hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
 22.3104 +            hw->ledctl_mode2 |= ledctl_on << (i << 3);
 22.3105 +            break;
 22.3106 +        case ID_LED_DEF1_OFF2:
 22.3107 +        case ID_LED_ON1_OFF2:
 22.3108 +        case ID_LED_OFF1_OFF2:
 22.3109 +            hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
 22.3110 +            hw->ledctl_mode2 |= ledctl_off << (i << 3);
 22.3111 +            break;
 22.3112 +        default:
 22.3113 +            /* Do nothing */
 22.3114 +            break;
 22.3115 +        }
 22.3116 +    }
 22.3117 +    return 0;
 22.3118 +}
 22.3119 +
 22.3120 +/******************************************************************************
 22.3121 + * Prepares SW controlable LED for use and saves the current state of the LED.
 22.3122 + *
 22.3123 + * hw - Struct containing variables accessed by shared code
 22.3124 + *****************************************************************************/
 22.3125 +int32_t
 22.3126 +e1000_setup_led(struct e1000_hw *hw)
 22.3127 +{
 22.3128 +    uint32_t ledctl;
 22.3129 + 
 22.3130 +    DEBUGFUNC("e1000_setup_led");
 22.3131 +   
 22.3132 +    switch(hw->device_id) {
 22.3133 +    case E1000_DEV_ID_82542:
 22.3134 +    case E1000_DEV_ID_82543GC_FIBER:
 22.3135 +    case E1000_DEV_ID_82543GC_COPPER:
 22.3136 +    case E1000_DEV_ID_82544EI_COPPER:
 22.3137 +    case E1000_DEV_ID_82544EI_FIBER:
 22.3138 +    case E1000_DEV_ID_82544GC_COPPER:
 22.3139 +    case E1000_DEV_ID_82544GC_LOM:
 22.3140 +        /* No setup necessary */
 22.3141 +        break;
 22.3142 +    case E1000_DEV_ID_82545EM_FIBER:
 22.3143 +    case E1000_DEV_ID_82546EB_FIBER:
 22.3144 +        ledctl = E1000_READ_REG(hw, LEDCTL);
 22.3145 +        /* Save current LEDCTL settings */
 22.3146 +        hw->ledctl_default = ledctl;
 22.3147 +        /* Turn off LED0 */
 22.3148 +        ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
 22.3149 +                    E1000_LEDCTL_LED0_BLINK | 
 22.3150 +                    E1000_LEDCTL_LED0_MODE_MASK);
 22.3151 +        ledctl |= (E1000_LEDCTL_MODE_LED_OFF << E1000_LEDCTL_LED0_MODE_SHIFT);
 22.3152 +        E1000_WRITE_REG(hw, LEDCTL, ledctl);
 22.3153 +        break;
 22.3154 +    case E1000_DEV_ID_82540EP:
 22.3155 +    case E1000_DEV_ID_82540EP_LOM:
 22.3156 +    case E1000_DEV_ID_82540EP_LP:
 22.3157 +    case E1000_DEV_ID_82540EM:
 22.3158 +    case E1000_DEV_ID_82540EM_LOM:
 22.3159 +    case E1000_DEV_ID_82545EM_COPPER:
 22.3160 +    case E1000_DEV_ID_82546EB_COPPER:
 22.3161 +        E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
 22.3162 +        break;
 22.3163 +    default:
 22.3164 +        DEBUGOUT("Invalid device ID\n");
 22.3165 +        return -E1000_ERR_CONFIG;
 22.3166 +    }
 22.3167 +    return 0;
 22.3168 +}
 22.3169 +
 22.3170 +/******************************************************************************
 22.3171 + * Restores the saved state of the SW controlable LED.
 22.3172 + *
 22.3173 + * hw - Struct containing variables accessed by shared code
 22.3174 + *****************************************************************************/
 22.3175 +int32_t
 22.3176 +e1000_cleanup_led(struct e1000_hw *hw)
 22.3177 +{
 22.3178 +    DEBUGFUNC("e1000_cleanup_led");
 22.3179 +
 22.3180 +    switch(hw->device_id) {
 22.3181 +    case E1000_DEV_ID_82542:
 22.3182 +    case E1000_DEV_ID_82543GC_FIBER:
 22.3183 +    case E1000_DEV_ID_82543GC_COPPER:
 22.3184 +    case E1000_DEV_ID_82544EI_COPPER:
 22.3185 +    case E1000_DEV_ID_82544EI_FIBER:
 22.3186 +    case E1000_DEV_ID_82544GC_COPPER:
 22.3187 +    case E1000_DEV_ID_82544GC_LOM:
 22.3188 +        /* No cleanup necessary */
 22.3189 +        break;
 22.3190 +    case E1000_DEV_ID_82540EP:
 22.3191 +    case E1000_DEV_ID_82540EP_LOM:
 22.3192 +    case E1000_DEV_ID_82540EP_LP:
 22.3193 +    case E1000_DEV_ID_82540EM:
 22.3194 +    case E1000_DEV_ID_82540EM_LOM:
 22.3195 +    case E1000_DEV_ID_82545EM_COPPER:
 22.3196 +    case E1000_DEV_ID_82545EM_FIBER:
 22.3197 +    case E1000_DEV_ID_82546EB_COPPER:
 22.3198 +    case E1000_DEV_ID_82546EB_FIBER:
 22.3199 +        /* Restore LEDCTL settings */
 22.3200 +        E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
 22.3201 +        break;
 22.3202 +    default:
 22.3203 +        DEBUGOUT("Invalid device ID\n");
 22.3204 +        return -E1000_ERR_CONFIG;
 22.3205 +    }
 22.3206 +    return 0;
 22.3207 +}
 22.3208 +    
 22.3209 +/******************************************************************************
 22.3210 + * Turns on the software controllable LED
 22.3211 + *
 22.3212 + * hw - Struct containing variables accessed by shared code
 22.3213 + *****************************************************************************/
 22.3214 +int32_t
 22.3215 +e1000_led_on(struct e1000_hw *hw)
 22.3216 +{
 22.3217 +    uint32_t ctrl;
 22.3218 +
 22.3219 +    DEBUGFUNC("e1000_led_on");
 22.3220 +
 22.3221 +    switch(hw->device_id) {
 22.3222 +    case E1000_DEV_ID_82542:
 22.3223 +    case E1000_DEV_ID_82543GC_FIBER:
 22.3224 +    case E1000_DEV_ID_82543GC_COPPER:
 22.3225 +    case E1000_DEV_ID_82544EI_FIBER:
 22.3226 +        ctrl = E1000_READ_REG(hw, CTRL);
 22.3227 +        /* Set SW Defineable Pin 0 to turn on the LED */
 22.3228 +        ctrl |= E1000_CTRL_SWDPIN0;
 22.3229 +        ctrl |= E1000_CTRL_SWDPIO0;
 22.3230 +        E1000_WRITE_REG(hw, CTRL, ctrl);
 22.3231 +        break;
 22.3232 +    case E1000_DEV_ID_82544EI_COPPER:
 22.3233 +    case E1000_DEV_ID_82544GC_COPPER:
 22.3234 +    case E1000_DEV_ID_82544GC_LOM:
 22.3235 +    case E1000_DEV_ID_82545EM_FIBER:
 22.3236 +    case E1000_DEV_ID_82546EB_FIBER:
 22.3237 +        ctrl = E1000_READ_REG(hw, CTRL);
 22.3238 +        /* Clear SW Defineable Pin 0 to turn on the LED */
 22.3239 +        ctrl &= ~E1000_CTRL_SWDPIN0;
 22.3240 +        ctrl |= E1000_CTRL_SWDPIO0;
 22.3241 +        E1000_WRITE_REG(hw, CTRL, ctrl);
 22.3242 +        break;
 22.3243 +    case E1000_DEV_ID_82540EP:
 22.3244 +    case E1000_DEV_ID_82540EP_LOM:
 22.3245 +    case E1000_DEV_ID_82540EP_LP:
 22.3246 +    case E1000_DEV_ID_82540EM:
 22.3247 +    case E1000_DEV_ID_82540EM_LOM:
 22.3248 +    case E1000_DEV_ID_82545EM_COPPER:
 22.3249 +    case E1000_DEV_ID_82546EB_COPPER:
 22.3250 +        E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
 22.3251 +        break;
 22.3252 +    default:
 22.3253 +        DEBUGOUT("Invalid device ID\n");
 22.3254 +        return -E1000_ERR_CONFIG;
 22.3255 +    }
 22.3256 +    return 0;
 22.3257 +}
 22.3258 +
 22.3259 +/******************************************************************************
 22.3260 + * Turns off the software controllable LED
 22.3261 + *
 22.3262 + * hw - Struct containing variables accessed by shared code
 22.3263 + *****************************************************************************/
 22.3264 +int32_t
 22.3265 +e1000_led_off(struct e1000_hw *hw)
 22.3266 +{
 22.3267 +    uint32_t ctrl;
 22.3268 +
 22.3269 +    DEBUGFUNC("e1000_led_off");
 22.3270 +
 22.3271 +    switch(hw->device_id) {
 22.3272 +    case E1000_DEV_ID_82542:
 22.3273 +    case E1000_DEV_ID_82543GC_FIBER:
 22.3274 +    case E1000_DEV_ID_82543GC_COPPER:
 22.3275 +    case E1000_DEV_ID_82544EI_FIBER:
 22.3276 +        ctrl = E1000_READ_REG(hw, CTRL);
 22.3277 +        /* Clear SW Defineable Pin 0 to turn off the LED */
 22.3278 +        ctrl &= ~E1000_CTRL_SWDPIN0;
 22.3279 +        ctrl |= E1000_CTRL_SWDPIO0;
 22.3280 +        E1000_WRITE_REG(hw, CTRL, ctrl);
 22.3281 +        break;
 22.3282 +    case E1000_DEV_ID_82544EI_COPPER:
 22.3283 +    case E1000_DEV_ID_82544GC_COPPER:
 22.3284 +    case E1000_DEV_ID_82544GC_LOM:
 22.3285 +    case E1000_DEV_ID_82545EM_FIBER:
 22.3286 +    case E1000_DEV_ID_82546EB_FIBER:
 22.3287 +        ctrl = E1000_READ_REG(hw, CTRL);
 22.3288 +        /* Set SW Defineable Pin 0 to turn off the LED */
 22.3289 +        ctrl |= E1000_CTRL_SWDPIN0;
 22.3290 +        ctrl |= E1000_CTRL_SWDPIO0;
 22.3291 +        E1000_WRITE_REG(hw, CTRL, ctrl);
 22.3292 +        break;
 22.3293 +    case E1000_DEV_ID_82540EP:
 22.3294 +    case E1000_DEV_ID_82540EP_LOM:
 22.3295 +    case E1000_DEV_ID_82540EP_LP:
 22.3296 +    case E1000_DEV_ID_82540EM:
 22.3297 +    case E1000_DEV_ID_82540EM_LOM:
 22.3298 +    case E1000_DEV_ID_82545EM_COPPER:
 22.3299 +    case E1000_DEV_ID_82546EB_COPPER:
 22.3300 +        E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
 22.3301 +        break;
 22.3302 +    default:
 22.3303 +        DEBUGOUT("Invalid device ID\n");
 22.3304 +        return -E1000_ERR_CONFIG;
 22.3305 +    }
 22.3306 +    return 0;
 22.3307 +}
 22.3308 +
 22.3309 +/******************************************************************************
 22.3310 + * Clears all hardware statistics counters. 
 22.3311 + *
 22.3312 + * hw - Struct containing variables accessed by shared code
 22.3313 + *****************************************************************************/
 22.3314 +void
 22.3315 +e1000_clear_hw_cntrs(struct e1000_hw *hw)
 22.3316 +{
 22.3317 +    volatile uint32_t temp;
 22.3318 +
 22.3319 +    temp = E1000_READ_REG(hw, CRCERRS);
 22.3320 +    temp = E1000_READ_REG(hw, SYMERRS);
 22.3321 +    temp = E1000_READ_REG(hw, MPC);
 22.3322 +    temp = E1000_READ_REG(hw, SCC);
 22.3323 +    temp = E1000_READ_REG(hw, ECOL);
 22.3324 +    temp = E1000_READ_REG(hw, MCC);
 22.3325 +    temp = E1000_READ_REG(hw, LATECOL);
 22.3326 +    temp = E1000_READ_REG(hw, COLC);
 22.3327 +    temp = E1000_READ_REG(hw, DC);
 22.3328 +    temp = E1000_READ_REG(hw, SEC);
 22.3329 +    temp = E1000_READ_REG(hw, RLEC);
 22.3330 +    temp = E1000_READ_REG(hw, XONRXC);
 22.3331 +    temp = E1000_READ_REG(hw, XONTXC);
 22.3332 +    temp = E1000_READ_REG(hw, XOFFRXC);
 22.3333 +    temp = E1000_READ_REG(hw, XOFFTXC);
 22.3334 +    temp = E1000_READ_REG(hw, FCRUC);
 22.3335 +    temp = E1000_READ_REG(hw, PRC64);
 22.3336 +    temp = E1000_READ_REG(hw, PRC127);
 22.3337 +    temp = E1000_READ_REG(hw, PRC255);
 22.3338 +    temp = E1000_READ_REG(hw, PRC511);
 22.3339 +    temp = E1000_READ_REG(hw, PRC1023);
 22.3340 +    temp = E1000_READ_REG(hw, PRC1522);
 22.3341 +    temp = E1000_READ_REG(hw, GPRC);
 22.3342 +    temp = E1000_READ_REG(hw, BPRC);
 22.3343 +    temp = E1000_READ_REG(hw, MPRC);
 22.3344 +    temp = E1000_READ_REG(hw, GPTC);
 22.3345 +    temp = E1000_READ_REG(hw, GORCL);
 22.3346 +    temp = E1000_READ_REG(hw, GORCH);
 22.3347 +    temp = E1000_READ_REG(hw, GOTCL);
 22.3348 +    temp = E1000_READ_REG(hw, GOTCH);
 22.3349 +    temp = E1000_READ_REG(hw, RNBC);
 22.3350 +    temp = E1000_READ_REG(hw, RUC);
 22.3351 +    temp = E1000_READ_REG(hw, RFC);
 22.3352 +    temp = E1000_READ_REG(hw, ROC);
 22.3353 +    temp = E1000_READ_REG(hw, RJC);
 22.3354 +    temp = E1000_READ_REG(hw, TORL);
 22.3355 +    temp = E1000_READ_REG(hw, TORH);
 22.3356 +    temp = E1000_READ_REG(hw, TOTL);
 22.3357 +    temp = E1000_READ_REG(hw, TOTH);
 22.3358 +    temp = E1000_READ_REG(hw, TPR);
 22.3359 +    temp = E1000_READ_REG(hw, TPT);
 22.3360 +    temp = E1000_READ_REG(hw, PTC64);
 22.3361 +    temp = E1000_READ_REG(hw, PTC127);
 22.3362 +    temp = E1000_READ_REG(hw, PTC255);
 22.3363 +    temp = E1000_READ_REG(hw, PTC511);
 22.3364 +    temp = E1000_READ_REG(hw, PTC1023);
 22.3365 +    temp = E1000_READ_REG(hw, PTC1522);
 22.3366 +    temp = E1000_READ_REG(hw, MPTC);
 22.3367 +    temp = E1000_READ_REG(hw, BPTC);
 22.3368 +
 22.3369 +    if(hw->mac_type < e1000_82543) return;
 22.3370 +
 22.3371 +    temp = E1000_READ_REG(hw, ALGNERRC);
 22.3372 +    temp = E1000_READ_REG(hw, RXERRC);
 22.3373 +    temp = E1000_READ_REG(hw, TNCRS);
 22.3374 +    temp = E1000_READ_REG(hw, CEXTERR);
 22.3375 +    temp = E1000_READ_REG(hw, TSCTC);
 22.3376 +    temp = E1000_READ_REG(hw, TSCTFC);
 22.3377 +
 22.3378 +    if(hw->mac_type <= e1000_82544) return;
 22.3379 +
 22.3380 +    temp = E1000_READ_REG(hw, MGTPRC);
 22.3381 +    temp = E1000_READ_REG(hw, MGTPDC);
 22.3382 +    temp = E1000_READ_REG(hw, MGTPTC);
 22.3383 +}
 22.3384 +
 22.3385 +/******************************************************************************
 22.3386 + * Resets Adaptive IFS to its default state.
 22.3387 + *
 22.3388 + * hw - Struct containing variables accessed by shared code
 22.3389 + *
 22.3390 + * Call this after e1000_init_hw. You may override the IFS defaults by setting
 22.3391 + * hw->ifs_params_forced to TRUE. However, you must initialize hw->
 22.3392 + * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
 22.3393 + * before calling this function.
 22.3394 + *****************************************************************************/
 22.3395 +void
 22.3396 +e1000_reset_adaptive(struct e1000_hw *hw)
 22.3397 +{
 22.3398 +    DEBUGFUNC("e1000_reset_adaptive");
 22.3399 +
 22.3400 +    if(hw->adaptive_ifs) {
 22.3401 +        if(!hw->ifs_params_forced) {
 22.3402 +            hw->current_ifs_val = 0;
 22.3403 +            hw->ifs_min_val = IFS_MIN;
 22.3404 +            hw->ifs_max_val = IFS_MAX;
 22.3405 +            hw->ifs_step_size = IFS_STEP;
 22.3406 +            hw->ifs_ratio = IFS_RATIO;
 22.3407 +        }
 22.3408 +        hw->in_ifs_mode = FALSE;
 22.3409 +        E1000_WRITE_REG(hw, AIT, 0);
 22.3410 +    } else {
 22.3411 +        DEBUGOUT("Not in Adaptive IFS mode!\n");
 22.3412 +    }
 22.3413 +}
 22.3414 +
 22.3415 +/******************************************************************************
 22.3416 + * Called during the callback/watchdog routine to update IFS value based on
 22.3417 + * the ratio of transmits to collisions.
 22.3418 + *
 22.3419 + * hw - Struct containing variables accessed by shared code
 22.3420 + * tx_packets - Number of transmits since last callback
 22.3421 + * total_collisions - Number of collisions since last callback
 22.3422 + *****************************************************************************/
 22.3423 +void
 22.3424 +e1000_update_adaptive(struct e1000_hw *hw)
 22.3425 +{
 22.3426 +    DEBUGFUNC("e1000_update_adaptive");
 22.3427 +
 22.3428 +    if(hw->adaptive_ifs) {
 22.3429 +        if((hw->collision_delta * hw->ifs_ratio) > 
 22.3430 +           hw->tx_packet_delta) {
 22.3431 +            if(hw->tx_packet_delta > MIN_NUM_XMITS) {
 22.3432 +                hw->in_ifs_mode = TRUE;
 22.3433 +                if(hw->current_ifs_val < hw->ifs_max_val) {
 22.3434 +                    if(hw->current_ifs_val == 0)
 22.3435 +                        hw->current_ifs_val = hw->ifs_min_val;
 22.3436 +                    else
 22.3437 +                        hw->current_ifs_val += hw->ifs_step_size;
 22.3438 +                    E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
 22.3439 +                }
 22.3440 +            }
 22.3441 +        } else {
 22.3442 +            if((hw->in_ifs_mode == TRUE) && 
 22.3443 +               (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
 22.3444 +                hw->current_ifs_val = 0;
 22.3445 +                hw->in_ifs_mode = FALSE;
 22.3446 +                E1000_WRITE_REG(hw, AIT, 0);
 22.3447 +            }
 22.3448 +        }
 22.3449 +    } else {
 22.3450 +        DEBUGOUT("Not in Adaptive IFS mode!\n");
 22.3451 +    }
 22.3452 +}
 22.3453 +
 22.3454 +/******************************************************************************
 22.3455 + * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
 22.3456 + * 
 22.3457 + * hw - Struct containing variables accessed by shared code
 22.3458 + * frame_len - The length of the frame in question
 22.3459 + * mac_addr - The Ethernet destination address of the frame in question
 22.3460 + *****************************************************************************/
 22.3461 +void
 22.3462 +e1000_tbi_adjust_stats(struct e1000_hw *hw,
 22.3463 +                       struct e1000_hw_stats *stats,
 22.3464 +                       uint32_t frame_len,
 22.3465 +                       uint8_t *mac_addr)
 22.3466 +{
 22.3467 +    uint64_t carry_bit;
 22.3468 +
 22.3469 +    /* First adjust the frame length. */
 22.3470 +    frame_len--;
 22.3471 +    /* We need to adjust the statistics counters, since the hardware
 22.3472 +     * counters overcount this packet as a CRC error and undercount
 22.3473 +     * the packet as a good packet
 22.3474 +     */
 22.3475 +    /* This packet should not be counted as a CRC error.    */
 22.3476 +    stats->crcerrs--;
 22.3477 +    /* This packet does count as a Good Packet Received.    */
 22.3478 +    stats->gprc++;
 22.3479 +
 22.3480 +    /* Adjust the Good Octets received counters             */
 22.3481 +    carry_bit = 0x80000000 & stats->gorcl;
 22.3482 +    stats->gorcl += frame_len;
 22.3483 +    /* If the high bit of Gorcl (the low 32 bits of the Good Octets
 22.3484 +     * Received Count) was one before the addition, 
 22.3485 +     * AND it is zero after, then we lost the carry out, 
 22.3486 +     * need to add one to Gorch (Good Octets Received Count High).
 22.3487 +     * This could be simplified if all environments supported 
 22.3488 +     * 64-bit integers.
 22.3489 +     */
 22.3490 +    if(carry_bit && ((stats->gorcl & 0x80000000) == 0))
 22.3491 +        stats->gorch++;
 22.3492 +    /* Is this a broadcast or multicast?  Check broadcast first,
 22.3493 +     * since the test for a multicast frame will test positive on 
 22.3494 +     * a broadcast frame.
 22.3495 +     */
 22.3496 +    if((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
 22.3497 +        /* Broadcast packet */
 22.3498 +        stats->bprc++;
 22.3499 +    else if(*mac_addr & 0x01)
 22.3500 +        /* Multicast packet */
 22.3501 +        stats->mprc++;
 22.3502 +
 22.3503 +    if(frame_len == hw->max_frame_size) {
 22.3504 +        /* In this case, the hardware has overcounted the number of
 22.3505 +         * oversize frames.
 22.3506 +         */
 22.3507 +        if(stats->roc > 0)
 22.3508 +            stats->roc--;
 22.3509 +    }
 22.3510 +
 22.3511 +    /* Adjust the bin counters when the extra byte put the frame in the
 22.3512 +     * wrong bin. Remember that the frame_len was adjusted above.
 22.3513 +     */
 22.3514 +    if(frame_len == 64) {
 22.3515 +        stats->prc64++;
 22.3516 +        stats->prc127--;
 22.3517 +    } else if(frame_len == 127) {
 22.3518 +        stats->prc127++;
 22.3519 +        stats->prc255--;
 22.3520 +    } else if(frame_len == 255) {
 22.3521 +        stats->prc255++;
 22.3522 +        stats->prc511--;
 22.3523 +    } else if(frame_len == 511) {
 22.3524 +        stats->prc511++;
 22.3525 +        stats->prc1023--;
 22.3526 +    } else if(frame_len == 1023) {
 22.3527 +        stats->prc1023++;
 22.3528 +        stats->prc1522--;
 22.3529 +    } else if(frame_len == 1522) {
 22.3530 +        stats->prc1522++;
 22.3531 +    }
 22.3532 +}
 22.3533 +
 22.3534 +/******************************************************************************
 22.3535 + * Gets the current PCI bus type, speed, and width of the hardware
 22.3536 + *
 22.3537 + * hw - Struct containing variables accessed by shared code
 22.3538 + *****************************************************************************/
 22.3539 +void
 22.3540 +e1000_get_bus_info(struct e1000_hw *hw)
 22.3541 +{
 22.3542 +    uint32_t status;
 22.3543 +
 22.3544 +    if(hw->mac_type < e1000_82543) {
 22.3545 +        hw->bus_type = e1000_bus_type_unknown;
 22.3546 +        hw->bus_speed = e1000_bus_speed_unknown;
 22.3547 +        hw->bus_width = e1000_bus_width_unknown;
 22.3548 +        return;
 22.3549 +    }
 22.3550 +
 22.3551 +    status = E1000_READ_REG(hw, STATUS);
 22.3552 +    hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
 22.3553 +                   e1000_bus_type_pcix : e1000_bus_type_pci;
 22.3554 +    if(hw->bus_type == e1000_bus_type_pci) {
 22.3555 +        hw->bus_speed = (status & E1000_STATUS_PCI66) ?
 22.3556 +                        e1000_bus_speed_66 : e1000_bus_speed_33;
 22.3557 +    } else {
 22.3558 +        switch (status & E1000_STATUS_PCIX_SPEED) {
 22.3559 +        case E1000_STATUS_PCIX_SPEED_66:
 22.3560 +            hw->bus_speed = e1000_bus_speed_66;
 22.3561 +            break;
 22.3562 +        case E1000_STATUS_PCIX_SPEED_100:
 22.3563 +            hw->bus_speed = e1000_bus_speed_100;
 22.3564 +            break;
 22.3565 +        case E1000_STATUS_PCIX_SPEED_133:
 22.3566 +            hw->bus_speed = e1000_bus_speed_133;
 22.3567 +            break;
 22.3568 +        default:
 22.3569 +            hw->bus_speed = e1000_bus_speed_reserved;
 22.3570 +            break;
 22.3571 +        }
 22.3572 +    }
 22.3573 +    hw->bus_width = (status & E1000_STATUS_BUS64) ?
 22.3574 +                    e1000_bus_width_64 : e1000_bus_width_32;
 22.3575 +}
 22.3576 +/******************************************************************************
 22.3577 + * Reads a value from one of the devices registers using port I/O (as opposed
 22.3578 + * memory mapped I/O). Only 82544 and newer devices support port I/O.
 22.3579 + *
 22.3580 + * hw - Struct containing variables accessed by shared code
 22.3581 + * offset - offset to read from
 22.3582 + *****************************************************************************/
 22.3583 +uint32_t
 22.3584 +e1000_read_reg_io(struct e1000_hw *hw,
 22.3585 +                  uint32_t offset)
 22.3586 +{
 22.3587 +    uint32_t io_addr = hw->io_base;
 22.3588 +    uint32_t io_data = hw->io_base + 4;
 22.3589 +
 22.3590 +    e1000_io_write(hw, io_addr, offset);
 22.3591 +    return e1000_io_read(hw, io_data);
 22.3592 +}
 22.3593 +
 22.3594 +/******************************************************************************
 22.3595 + * Writes a value to one of the devices registers using port I/O (as opposed to
 22.3596 + * memory mapped I/O). Only 82544 and newer devices support port I/O.
 22.3597 + *
 22.3598 + * hw - Struct containing variables accessed by shared code
 22.3599 + * offset - offset to write to
 22.3600 + * value - value to write
 22.3601 + *****************************************************************************/
 22.3602 +void
 22.3603 +e1000_write_reg_io(struct e1000_hw *hw,
 22.3604 +                   uint32_t offset,
 22.3605 +                   uint32_t value)
 22.3606 +{
 22.3607 +    uint32_t io_addr = hw->io_base;
 22.3608 +    uint32_t io_data = hw->io_base + 4;
 22.3609 +
 22.3610 +    e1000_io_write(hw, io_addr, offset);
 22.3611 +    e1000_io_write(hw, io_data, value);
 22.3612 +}
 22.3613 +
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/xen-2.4.16/drivers/net/e1000/e1000_hw.h	Tue Feb 11 13:05:51 2003 +0000
    23.3 @@ -0,0 +1,1789 @@
    23.4 +/*******************************************************************************
    23.5 +
    23.6 +  
    23.7 +  Copyright(c) 1999 - 2002 Intel Corporation. All rights reserved.
    23.8 +  
    23.9 +  This program is free software; you can redistribute it and/or modify it 
   23.10 +  under the terms of the GNU General Public License as published by the Free 
   23.11 +  Software Foundation; either version 2 of the License, or (at your option) 
   23.12 +  any later version.
   23.13 +  
   23.14 +  This program is distributed in the hope that it will be useful, but WITHOUT 
   23.15 +  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
   23.16 +  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
   23.17 +  more details.
   23.18 +  
   23.19 +  You should have received a copy of the GNU General Public License along with
   23.20 +  this program; if not, write to the Free Software Foundation, Inc., 59 
   23.21 +  Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   23.22 +  
   23.23 +  The full GNU General Public License is included in this distribution in the
   23.24 +  file called LICENSE.
   23.25 +  
   23.26 +  Contact Information:
   23.27 +  Linux NICS <linux.nics@intel.com>
   23.28 +  Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
   23.29 +
   23.30 +*******************************************************************************/
   23.31 +
   23.32 +/* e1000_hw.h
   23.33 + * Structures, enums, and macros for the MAC
   23.34 + */
   23.35 +
   23.36 +#ifndef _E1000_HW_H_
   23.37 +#define _E1000_HW_H_
   23.38 +
   23.39 +#include "e1000_osdep.h"
   23.40 +
   23.41 +/* Forward declarations of structures used by the shared code */
   23.42 +struct e1000_hw;
   23.43 +struct e1000_hw_stats;
   23.44 +
   23.45 +/* Enumerated types specific to the e1000 hardware */
   23.46 +/* Media Access Controlers */
   23.47 +typedef enum {
   23.48 +    e1000_undefined = 0,
   23.49 +    e1000_82542_rev2_0,
   23.50 +    e1000_82542_rev2_1,
   23.51 +    e1000_82543,
   23.52 +    e1000_82544,
   23.53 +    e1000_82540,
   23.54 +    e1000_82545,
   23.55 +    e1000_82546,
   23.56 +    e1000_num_macs
   23.57 +} e1000_mac_type;
   23.58 +
   23.59 +/* Media Types */
   23.60 +typedef enum {
   23.61 +    e1000_media_type_copper = 0,
   23.62 +    e1000_media_type_fiber = 1,
   23.63 +    e1000_num_media_types
   23.64 +} e1000_media_type;
   23.65 +
   23.66 +typedef enum {
   23.67 +    e1000_10_half = 0,
   23.68 +    e1000_10_full = 1,
   23.69 +    e1000_100_half = 2,
   23.70 +    e1000_100_full = 3
   23.71 +} e1000_speed_duplex_type;
   23.72 +
   23.73 +/* Flow Control Settings */
   23.74 +typedef enum {
   23.75 +    e1000_fc_none = 0,
   23.76 +    e1000_fc_rx_pause = 1,
   23.77 +    e1000_fc_tx_pause = 2,
   23.78 +    e1000_fc_full = 3,
   23.79 +    e1000_fc_default = 0xFF
   23.80 +} e1000_fc_type;
   23.81 +
   23.82 +/* PCI bus types */
   23.83 +typedef enum {
   23.84 +    e1000_bus_type_unknown = 0,
   23.85 +    e1000_bus_type_pci,
   23.86 +    e1000_bus_type_pcix
   23.87 +} e1000_bus_type;
   23.88 +
   23.89 +/* PCI bus speeds */
   23.90 +typedef enum {
   23.91 +    e1000_bus_speed_unknown = 0,
   23.92 +    e1000_bus_speed_33,
   23.93 +    e1000_bus_speed_66,
   23.94 +    e1000_bus_speed_100,
   23.95 +    e1000_bus_speed_133,
   23.96 +    e1000_bus_speed_reserved
   23.97 +} e1000_bus_speed;
   23.98 +
   23.99 +/* PCI bus widths */
  23.100 +typedef enum {
  23.101 +    e1000_bus_width_unknown = 0,
  23.102 +    e1000_bus_width_32,
  23.103 +    e1000_bus_width_64
  23.104 +} e1000_bus_width;
  23.105 +
  23.106 +/* PHY status info structure and supporting enums */
  23.107 +typedef enum {
  23.108 +    e1000_cable_length_50 = 0,
  23.109 +    e1000_cable_length_50_80,
  23.110 +    e1000_cable_length_80_110,
  23.111 +    e1000_cable_length_110_140,
  23.112 +    e1000_cable_length_140,
  23.113 +    e1000_cable_length_undefined = 0xFF
  23.114 +} e1000_cable_length;
  23.115 +
  23.116 +typedef enum {
  23.117 +    e1000_10bt_ext_dist_enable_normal = 0,
  23.118 +    e1000_10bt_ext_dist_enable_lower,
  23.119 +    e1000_10bt_ext_dist_enable_undefined = 0xFF
  23.120 +} e1000_10bt_ext_dist_enable;
  23.121 +
  23.122 +typedef enum {
  23.123 +    e1000_rev_polarity_normal = 0,
  23.124 +    e1000_rev_polarity_reversed,
  23.125 +    e1000_rev_polarity_undefined = 0xFF
  23.126 +} e1000_rev_polarity;
  23.127 +
  23.128 +typedef enum {
  23.129 +    e1000_polarity_reversal_enabled = 0,
  23.130 +    e1000_polarity_reversal_disabled,
  23.131 +    e1000_polarity_reversal_undefined = 0xFF
  23.132 +} e1000_polarity_reversal;
  23.133 +
  23.134 +typedef enum {
  23.135 +    e1000_auto_x_mode_manual_mdi = 0,
  23.136 +    e1000_auto_x_mode_manual_mdix,
  23.137 +    e1000_auto_x_mode_auto1,
  23.138 +    e1000_auto_x_mode_auto2,
  23.139 +    e1000_auto_x_mode_undefined = 0xFF
  23.140 +} e1000_auto_x_mode;
  23.141 +
  23.142 +typedef enum {
  23.143 +    e1000_1000t_rx_status_not_ok = 0,
  23.144 +    e1000_1000t_rx_status_ok,
  23.145 +    e1000_1000t_rx_status_undefined = 0xFF
  23.146 +} e1000_1000t_rx_status;
  23.147 +
  23.148 +struct e1000_phy_info {
  23.149 +    e1000_cable_length cable_length;
  23.150 +    e1000_10bt_ext_dist_enable extended_10bt_distance;
  23.151 +    e1000_rev_polarity cable_polarity;
  23.152 +    e1000_polarity_reversal polarity_correction;
  23.153 +    e1000_auto_x_mode mdix_mode;
  23.154 +    e1000_1000t_rx_status local_rx;
  23.155 +    e1000_1000t_rx_status remote_rx;
  23.156 +};
  23.157 +
  23.158 +struct e1000_phy_stats {
  23.159 +    uint32_t idle_errors;
  23.160 +    uint32_t receive_errors;
  23.161 +};
  23.162 +
  23.163 +
  23.164 +
  23.165 +/* Error Codes */
  23.166 +#define E1000_SUCCESS      0
  23.167 +#define E1000_ERR_EEPROM   1
  23.168 +#define E1000_ERR_PHY      2
  23.169 +#define E1000_ERR_CONFIG   3
  23.170 +#define E1000_ERR_PARAM    4
  23.171 +#define E1000_ERR_MAC_TYPE 5
  23.172 +
  23.173 +/* Function prototypes */
  23.174 +/* Initialization */
  23.175 +void e1000_reset_hw(struct e1000_hw *hw);
  23.176 +int32_t e1000_init_hw(struct e1000_hw *hw);
  23.177 +int32_t e1000_set_mac_type(struct e1000_hw *hw);
  23.178 +
  23.179 +/* Link Configuration */
  23.180 +int32_t e1000_setup_link(struct e1000_hw *hw);
  23.181 +int32_t e1000_phy_setup_autoneg(struct e1000_hw *hw);
  23.182 +void e1000_config_collision_dist(struct e1000_hw *hw);
  23.183 +int32_t e1000_config_fc_after_link_up(struct e1000_hw *hw);
  23.184 +int32_t e1000_check_for_link(struct e1000_hw *hw);
  23.185 +void e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t * speed, uint16_t * duplex);
  23.186 +int32_t e1000_wait_autoneg(struct e1000_hw *hw);
  23.187 +
  23.188 +/* PHY */
  23.189 +int32_t e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *phy_data);
  23.190 +int32_t e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data);
  23.191 +void e1000_phy_hw_reset(struct e1000_hw *hw);
  23.192 +int32_t e1000_phy_reset(struct e1000_hw *hw);
  23.193 +int32_t e1000_detect_gig_phy(struct e1000_hw *hw);
  23.194 +int32_t e1000_phy_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
  23.195 +int32_t e1000_validate_mdi_setting(struct e1000_hw *hw);
  23.196 +
  23.197 +/* EEPROM Functions */
  23.198 +int32_t e1000_read_eeprom(struct e1000_hw *hw, uint16_t reg, uint16_t *data);
  23.199 +int32_t e1000_validate_eeprom_checksum(struct e1000_hw *hw);
  23.200 +int32_t e1000_update_eeprom_checksum(struct e1000_hw *hw);
  23.201 +int32_t e1000_write_eeprom(struct e1000_hw *hw, uint16_t reg, uint16_t data);
  23.202 +int32_t e1000_read_part_num(struct e1000_hw *hw, uint32_t * part_num);
  23.203 +int32_t e1000_read_mac_addr(struct e1000_hw * hw);
  23.204 +
  23.205 +/* Filters (multicast, vlan, receive) */
  23.206 +void e1000_init_rx_addrs(struct e1000_hw *hw);
  23.207 +void e1000_mc_addr_list_update(struct e1000_hw *hw, uint8_t * mc_addr_list, uint32_t mc_addr_count, uint32_t pad);
  23.208 +uint32_t e1000_hash_mc_addr(struct e1000_hw *hw, uint8_t * mc_addr);
  23.209 +void e1000_mta_set(struct e1000_hw *hw, uint32_t hash_value);
  23.210 +void e1000_rar_set(struct e1000_hw *hw, uint8_t * mc_addr, uint32_t rar_index);
  23.211 +void e1000_write_vfta(struct e1000_hw *hw, uint32_t offset, uint32_t value);
  23.212 +void e1000_clear_vfta(struct e1000_hw *hw);
  23.213 +
  23.214 +/* LED functions */
  23.215 +int32_t e1000_setup_led(struct e1000_hw *hw);
  23.216 +int32_t e1000_cleanup_led(struct e1000_hw *hw);
  23.217 +int32_t e1000_led_on(struct e1000_hw *hw);
  23.218 +int32_t e1000_led_off(struct e1000_hw *hw);
  23.219 +
  23.220 +/* Adaptive IFS Functions */
  23.221 +
  23.222 +/* Everything else */
  23.223 +void e1000_clear_hw_cntrs(struct e1000_hw *hw);
  23.224 +void e1000_reset_adaptive(struct e1000_hw *hw);
  23.225 +void e1000_update_adaptive(struct e1000_hw *hw);
  23.226 +void e1000_tbi_adjust_stats(struct e1000_hw *hw, struct e1000_hw_stats *stats, uint32_t frame_len, uint8_t * mac_addr);
  23.227 +void e1000_get_bus_info(struct e1000_hw *hw);
  23.228 +void e1000_pci_set_mwi(struct e1000_hw *hw);
  23.229 +void e1000_pci_clear_mwi(struct e1000_hw *hw);
  23.230 +void e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t * value);
  23.231 +void e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t * value);
  23.232 +/* Port I/O is only supported on 82544 and newer */
  23.233 +uint32_t e1000_io_read(struct e1000_hw *hw, uint32_t port);
  23.234 +uint32_t e1000_read_reg_io(struct e1000_hw *hw, uint32_t offset);
  23.235 +void e1000_io_write(struct e1000_hw *hw, uint32_t port, uint32_t value);
  23.236 +void e1000_write_reg_io(struct e1000_hw *hw, uint32_t offset, uint32_t value);
  23.237 +#define E1000_READ_REG_IO(a, reg) \
  23.238 +    e1000_read_reg_io((a), E1000_##reg)
  23.239 +#define E1000_WRITE_REG_IO(a, reg, val) \
  23.240 +    e1000_write_reg_io((a), E1000_##reg, val)
  23.241 +
  23.242 +/* PCI Device IDs */
  23.243 +#define E1000_DEV_ID_82542               0x1000
  23.244 +#define E1000_DEV_ID_82543GC_FIBER       0x1001
  23.245 +#define E1000_DEV_ID_82543GC_COPPER      0x1004
  23.246 +#define E1000_DEV_ID_82544EI_COPPER      0x1008
  23.247 +#define E1000_DEV_ID_82544EI_FIBER       0x1009
  23.248 +#define E1000_DEV_ID_82544GC_COPPER      0x100C
  23.249 +#define E1000_DEV_ID_82544GC_LOM         0x100D
  23.250 +#define E1000_DEV_ID_82540EM             0x100E
  23.251 +#define E1000_DEV_ID_82540EM_LOM         0x1015
  23.252 +#define E1000_DEV_ID_82540EP_LOM         0x1016
  23.253 +#define E1000_DEV_ID_82540EP             0x1017
  23.254 +#define E1000_DEV_ID_82540EP_LP          0x101E
  23.255 +#define E1000_DEV_ID_82545EM_COPPER      0x100F
  23.256 +#define E1000_DEV_ID_82545EM_FIBER       0x1011
  23.257 +#define E1000_DEV_ID_82546EB_COPPER      0x1010
  23.258 +#define E1000_DEV_ID_82546EB_FIBER       0x1012
  23.259 +#define NUM_DEV_IDS 16
  23.260 +
  23.261 +#define NODE_ADDRESS_SIZE 6
  23.262 +#define ETH_LENGTH_OF_ADDRESS 6
  23.263 +
  23.264 +/* MAC decode size is 128K - This is the size of BAR0 */
  23.265 +#define MAC_DECODE_SIZE (128 * 1024)
  23.266 +
  23.267 +#define E1000_82542_2_0_REV_ID 2
  23.268 +#define E1000_82542_2_1_REV_ID 3
  23.269 +
  23.270 +#define SPEED_10    10
  23.271 +#define SPEED_100   100
  23.272 +#define SPEED_1000  1000
  23.273 +#define HALF_DUPLEX 1
  23.274 +#define FULL_DUPLEX 2
  23.275 +
  23.276 +/* The sizes (in bytes) of a ethernet packet */
  23.277 +#define ENET_HEADER_SIZE             14
  23.278 +#define MAXIMUM_ETHERNET_FRAME_SIZE  1518 /* With FCS */
  23.279 +#define MINIMUM_ETHERNET_FRAME_SIZE  64   /* With FCS */
  23.280 +#define ETHERNET_FCS_SIZE            4
  23.281 +#define MAXIMUM_ETHERNET_PACKET_SIZE \
  23.282 +    (MAXIMUM_ETHERNET_FRAME_SIZE - ETHERNET_FCS_SIZE)
  23.283 +#define MINIMUM_ETHERNET_PACKET_SIZE \
  23.284 +    (MINIMUM_ETHERNET_FRAME_SIZE - ETHERNET_FCS_SIZE)
  23.285 +#define CRC_LENGTH                   ETHERNET_FCS_SIZE
  23.286 +#define MAX_JUMBO_FRAME_SIZE         0x3F00
  23.287 +
  23.288 +
  23.289 +/* 802.1q VLAN Packet Sizes */
  23.290 +#define VLAN_TAG_SIZE                     4     /* 802.3ac tag (not DMAed) */
  23.291 +
  23.292 +/* Ethertype field values */
  23.293 +#define ETHERNET_IEEE_VLAN_TYPE 0x8100  /* 802.3ac packet */
  23.294 +#define ETHERNET_IP_TYPE        0x0800  /* IP packets */
  23.295 +#define ETHERNET_ARP_TYPE       0x0806  /* Address Resolution Protocol (ARP) */
  23.296 +
  23.297 +/* Packet Header defines */
  23.298 +#define IP_PROTOCOL_TCP    6
  23.299 +#define IP_PROTOCOL_UDP    0x11
  23.300 +
  23.301 +/* This defines the bits that are set in the Interrupt Mask
  23.302 + * Set/Read Register.  Each bit is documented below:
  23.303 + *   o RXDMT0 = Receive Descriptor Minimum Threshold hit (ring 0)
  23.304 + *   o RXSEQ  = Receive Sequence Error 
  23.305 + */
  23.306 +#define POLL_IMS_ENABLE_MASK ( \
  23.307 +    E1000_IMS_RXDMT0 |         \
  23.308 +    E1000_IMS_RXSEQ)
  23.309 +
  23.310 +/* This defines the bits that are set in the Interrupt Mask
  23.311 + * Set/Read Register.  Each bit is documented below:
  23.312 + *   o RXT0   = Receiver Timer Interrupt (ring 0)
  23.313 + *   o TXDW   = Transmit Descriptor Written Back
  23.314 + *   o RXDMT0 = Receive Descriptor Minimum Threshold hit (ring 0)
  23.315 + *   o RXSEQ  = Receive Sequence Error
  23.316 + *   o LSC    = Link Status Change
  23.317 + */
  23.318 +#define IMS_ENABLE_MASK ( \
  23.319 +    E1000_IMS_RXT0   |    \
  23.320 +    E1000_IMS_TXDW   |    \
  23.321 +    E1000_IMS_RXDMT0 |    \
  23.322 +    E1000_IMS_RXSEQ  |    \
  23.323 +    E1000_IMS_LSC)
  23.324 +
  23.325 +/* The number of high/low register pairs in the RAR. The RAR (Receive Address
  23.326 + * Registers) holds the directed and multicast addresses that we monitor. We
  23.327 + * reserve one of these spots for our directed address, allowing us room for
  23.328 + * E1000_RAR_ENTRIES - 1 multicast addresses. 
  23.329 + */
  23.330 +#define E1000_RAR_ENTRIES 16
  23.331 +
  23.332 +#define MIN_NUMBER_OF_DESCRIPTORS 8
  23.333 +#define MAX_NUMBER_OF_DESCRIPTORS 0xFFF8
  23.334 +
  23.335 +/* Receive Descriptor */
  23.336 +struct e1000_rx_desc {
  23.337 +    uint64_t buffer_addr; /* Address of the descriptor's data buffer */
  23.338 +    uint16_t length;     /* Length of data DMAed into data buffer */
  23.339 +    uint16_t csum;       /* Packet checksum */
  23.340 +    uint8_t status;      /* Descriptor status */
  23.341 +    uint8_t errors;      /* Descriptor Errors */
  23.342 +    uint16_t special;
  23.343 +};
  23.344 +
  23.345 +/* Receive Decriptor bit definitions */
  23.346 +#define E1000_RXD_STAT_DD       0x01    /* Descriptor Done */
  23.347 +#define E1000_RXD_STAT_EOP      0x02    /* End of Packet */
  23.348 +#define E1000_RXD_STAT_IXSM     0x04    /* Ignore checksum */
  23.349 +#define E1000_RXD_STAT_VP       0x08    /* IEEE VLAN Packet */
  23.350 +#define E1000_RXD_STAT_TCPCS    0x20    /* TCP xsum calculated */
  23.351 +#define E1000_RXD_STAT_IPCS     0x40    /* IP xsum calculated */
  23.352 +#define E1000_RXD_STAT_PIF      0x80    /* passed in-exact filter */
  23.353 +#define E1000_RXD_ERR_CE        0x01    /* CRC Error */
  23.354 +#define E1000_RXD_ERR_SE        0x02    /* Symbol Error */
  23.355 +#define E1000_RXD_ERR_SEQ       0x04    /* Sequence Error */
  23.356 +#define E1000_RXD_ERR_CXE       0x10    /* Carrier Extension Error */
  23.357 +#define E1000_RXD_ERR_TCPE      0x20    /* TCP/UDP Checksum Error */
  23.358 +#define E1000_RXD_ERR_IPE       0x40    /* IP Checksum Error */
  23.359 +#define E1000_RXD_ERR_RXE       0x80    /* Rx Data Error */
  23.360 +#define E1000_RXD_SPC_VLAN_MASK 0x0FFF  /* VLAN ID is in lower 12 bits */
  23.361 +#define E1000_RXD_SPC_PRI_MASK  0xE000  /* Priority is in upper 3 bits */
  23.362 +#define E1000_RXD_SPC_PRI_SHIFT 0x000D  /* Priority is in upper 3 of 16 */
  23.363 +#define E1000_RXD_SPC_CFI_MASK  0x1000  /* CFI is bit 12 */
  23.364 +#define E1000_RXD_SPC_CFI_SHIFT 0x000C  /* CFI is bit 12 */
  23.365 +
  23.366 +/* mask to determine if packets should be dropped due to frame errors */
  23.367 +#define E1000_RXD_ERR_FRAME_ERR_MASK ( \
  23.368 +    E1000_RXD_ERR_CE  |                \
  23.369 +    E1000_RXD_ERR_SE  |                \
  23.370 +    E1000_RXD_ERR_SEQ |                \
  23.371 +    E1000_RXD_ERR_CXE |                \
  23.372 +    E1000_RXD_ERR_RXE)
  23.373 +
  23.374 +/* Transmit Descriptor */
  23.375 +struct e1000_tx_desc {
  23.376 +    uint64_t buffer_addr;       /* Address of the descriptor's data buffer */
  23.377 +    union {
  23.378 +        uint32_t data;
  23.379 +        struct {
  23.380 +            uint16_t length;    /* Data buffer length */
  23.381 +            uint8_t cso;        /* Checksum offset */
  23.382 +            uint8_t cmd;        /* Descriptor control */
  23.383 +        } flags;
  23.384 +    } lower;
  23.385 +    union {
  23.386 +        uint32_t data;
  23.387 +        struct {
  23.388 +            uint8_t status;     /* Descriptor status */
  23.389 +            uint8_t css;        /* Checksum start */
  23.390 +            uint16_t special;
  23.391 +        } fields;
  23.392 +    } upper;
  23.393 +};
  23.394 +
  23.395 +/* Transmit Descriptor bit definitions */
  23.396 +#define E1000_TXD_DTYP_D     0x00100000 /* Data Descriptor */
  23.397 +#define E1000_TXD_DTYP_C     0x00000000 /* Context Descriptor */
  23.398 +#define E1000_TXD_POPTS_IXSM 0x01       /* Insert IP checksum */
  23.399 +#define E1000_TXD_POPTS_TXSM 0x02       /* Insert TCP/UDP checksum */
  23.400 +#define E1000_TXD_CMD_EOP    0x01000000 /* End of Packet */
  23.401 +#define E1000_TXD_CMD_IFCS   0x02000000 /* Insert FCS (Ethernet CRC) */
  23.402 +#define E1000_TXD_CMD_IC     0x04000000 /* Insert Checksum */
  23.403 +#define E1000_TXD_CMD_RS     0x08000000 /* Report Status */
  23.404 +#define E1000_TXD_CMD_RPS    0x10000000 /* Report Packet Sent */
  23.405 +#define E1000_TXD_CMD_DEXT   0x20000000 /* Descriptor extension (0 = legacy) */
  23.406 +#define E1000_TXD_CMD_VLE    0x40000000 /* Add VLAN tag */
  23.407 +#define E1000_TXD_CMD_IDE    0x80000000 /* Enable Tidv register */
  23.408 +#define E1000_TXD_STAT_DD    0x00000001 /* Descriptor Done */
  23.409 +#define E1000_TXD_STAT_EC    0x00000002 /* Excess Collisions */
  23.410 +#define E1000_TXD_STAT_LC    0x00000004 /* Late Collisions */
  23.411 +#define E1000_TXD_STAT_TU    0x00000008 /* Transmit underrun */
  23.412 +#define E1000_TXD_CMD_TCP    0x01000000 /* TCP packet */
  23.413 +#define E1000_TXD_CMD_IP     0x02000000 /* IP packet */
  23.414 +#define E1000_TXD_CMD_TSE    0x04000000 /* TCP Seg enable */
  23.415 +#define E1000_TXD_STAT_TC    0x00000004 /* Tx Underrun */
  23.416 +
  23.417 +/* Offload Context Descriptor */
  23.418 +struct e1000_context_desc {
  23.419 +    union {
  23.420 +        uint32_t ip_config;
  23.421 +        struct {
  23.422 +            uint8_t ipcss;      /* IP checksum start */
  23.423 +            uint8_t ipcso;      /* IP checksum offset */
  23.424 +            uint16_t ipcse;     /* IP checksum end */
  23.425 +        } ip_fields;
  23.426 +    } lower_setup;
  23.427 +    union {
  23.428 +        uint32_t tcp_config;
  23.429 +        struct {
  23.430 +            uint8_t tucss;      /* TCP checksum start */
  23.431 +            uint8_t tucso;      /* TCP checksum offset */
  23.432 +            uint16_t tucse;     /* TCP checksum end */
  23.433 +        } tcp_fields;
  23.434 +    } upper_setup;
  23.435 +    uint32_t cmd_and_length;    /* */
  23.436 +    union {
  23.437 +        uint32_t data;
  23.438 +        struct {
  23.439 +            uint8_t status;     /* Descriptor status */
  23.440 +            uint8_t hdr_len;    /* Header length */
  23.441 +            uint16_t mss;       /* Maximum segment size */
  23.442 +        } fields;
  23.443 +    } tcp_seg_setup;
  23.444 +};
  23.445 +
  23.446 +/* Offload data descriptor */
  23.447 +struct e1000_data_desc {
  23.448 +    uint64_t buffer_addr;       /* Address of the descriptor's buffer address */
  23.449 +    union {
  23.450 +        uint32_t data;
  23.451 +        struct {
  23.452 +            uint16_t length;    /* Data buffer length */
  23.453 +            uint8_t typ_len_ext;        /* */
  23.454 +            uint8_t cmd;        /* */
  23.455 +        } flags;
  23.456 +    } lower;
  23.457 +    union {
  23.458 +        uint32_t data;
  23.459 +        struct {
  23.460 +            uint8_t status;     /* Descriptor status */
  23.461 +            uint8_t popts;      /* Packet Options */
  23.462 +            uint16_t special;   /* */
  23.463 +        } fields;
  23.464 +    } upper;
  23.465 +};
  23.466 +
  23.467 +/* Filters */
  23.468 +#define E1000_NUM_UNICAST          16   /* Unicast filter entries */
  23.469 +#define E1000_MC_TBL_SIZE          128  /* Multicast Filter Table (4096 bits) */
  23.470 +#define E1000_VLAN_FILTER_TBL_SIZE 128  /* VLAN Filter Table (4096 bits) */
  23.471 +
  23.472 +
  23.473 +/* Receive Address Register */
  23.474 +struct e1000_rar {
  23.475 +    volatile uint32_t low;      /* receive address low */
  23.476 +    volatile uint32_t high;     /* receive address high */
  23.477 +};
  23.478 +
  23.479 +/* The number of entries in the Multicast Table Array (MTA). */
  23.480 +#define E1000_NUM_MTA_REGISTERS 128
  23.481 +
  23.482 +/* IPv4 Address Table Entry */
  23.483 +struct e1000_ipv4_at_entry {
  23.484 +    volatile uint32_t ipv4_addr;        /* IP Address (RW) */
  23.485 +    volatile uint32_t reserved;
  23.486 +};
  23.487 +
  23.488 +/* Four wakeup IP addresses are supported */
  23.489 +#define E1000_WAKEUP_IP_ADDRESS_COUNT_MAX 4
  23.490 +#define E1000_IP4AT_SIZE                  E1000_WAKEUP_IP_ADDRESS_COUNT_MAX
  23.491 +#define E1000_IP6AT_SIZE                  1
  23.492 +
  23.493 +/* IPv6 Address Table Entry */
  23.494 +struct e1000_ipv6_at_entry {
  23.495 +    volatile uint8_t ipv6_addr[16];
  23.496 +};
  23.497 +
  23.498 +/* Flexible Filter Length Table Entry */
  23.499 +struct e1000_fflt_entry {
  23.500 +    volatile uint32_t length;   /* Flexible Filter Length (RW) */
  23.501 +    volatile uint32_t reserved;
  23.502 +};
  23.503 +
  23.504 +/* Flexible Filter Mask Table Entry */
  23.505 +struct e1000_ffmt_entry {
  23.506 +    volatile uint32_t mask;     /* Flexible Filter Mask (RW) */
  23.507 +    volatile uint32_t reserved;
  23.508 +};
  23.509 +
  23.510 +/* Flexible Filter Value Table Entry */
  23.511 +struct e1000_ffvt_entry {
  23.512 +    volatile uint32_t value;    /* Flexible Filter Value (RW) */
  23.513 +    volatile uint32_t reserved;
  23.514 +};
  23.515 +
  23.516 +/* Four Flexible Filters are supported */
  23.517 +#define E1000_FLEXIBLE_FILTER_COUNT_MAX 4
  23.518 +
  23.519 +/* Each Flexible Filter is at most 128 (0x80) bytes in length */
  23.520 +#define E1000_FLEXIBLE_FILTER_SIZE_MAX  128
  23.521 +
  23.522 +#define E1000_FFLT_SIZE E1000_FLEXIBLE_FILTER_COUNT_MAX
  23.523 +#define E1000_FFMT_SIZE E1000_FLEXIBLE_FILTER_SIZE_MAX
  23.524 +#define E1000_FFVT_SIZE E1000_FLEXIBLE_FILTER_SIZE_MAX
  23.525 +
  23.526 +/* Register Set. (82543, 82544)
  23.527 + *
  23.528 + * Registers are defined to be 32 bits and  should be accessed as 32 bit values.
  23.529 + * These registers are physically located on the NIC, but are mapped into the 
  23.530 + * host memory address space.
  23.531 + *
  23.532 + * RW - register is both readable and writable
  23.533 + * RO - register is read only
  23.534 + * WO - register is write only
  23.535 + * R/clr - register is read only and is cleared when read
  23.536 + * A - register array
  23.537 + */
  23.538 +#define E1000_CTRL     0x00000  /* Device Control - RW */
  23.539 +#define E1000_STATUS   0x00008  /* Device Status - RO */
  23.540 +#define E1000_EECD     0x00010  /* EEPROM/Flash Control - RW */
  23.541 +#define E1000_EERD     0x00014  /* EEPROM Read - RW */
  23.542 +#define E1000_CTRL_EXT 0x00018  /* Extended Device Control - RW */
  23.543 +#define E1000_MDIC     0x00020  /* MDI Control - RW */
  23.544 +#define E1000_FCAL     0x00028  /* Flow Control Address Low - RW */
  23.545 +#define E1000_FCAH     0x0002C  /* Flow Control Address High -RW */
  23.546 +#define E1000_FCT      0x00030  /* Flow Control Type - RW */
  23.547 +#define E1000_VET      0x00038  /* VLAN Ether Type - RW */
  23.548 +#define E1000_ICR      0x000C0  /* Interrupt Cause Read - R/clr */
  23.549 +#define E1000_ITR      0x000C4  /* Interrupt Throttling Rate - RW */
  23.550 +#define E1000_ICS      0x000C8  /* Interrupt Cause Set - WO */
  23.551 +#define E1000_IMS      0x000D0  /* Interrupt Mask Set - RW */
  23.552 +#define E1000_IMC      0x000D8  /* Interrupt Mask Clear - WO */
  23.553 +#define E1000_RCTL     0x00100  /* RX Control - RW */
  23.554 +#define E1000_FCTTV    0x00170  /* Flow Control Transmit Timer Value - RW */
  23.555 +#define E1000_TXCW     0x00178  /* TX Configuration Word - RW */
  23.556 +#define E1000_RXCW     0x00180  /* RX Configuration Word - RO */
  23.557 +#define E1000_TCTL     0x00400  /* TX Control - RW */
  23.558 +#define E1000_TIPG     0x00410  /* TX Inter-packet gap -RW */
  23.559 +#define E1000_TBT      0x00448  /* TX Burst Timer - RW */
  23.560 +#define E1000_AIT      0x00458  /* Adaptive Interframe Spacing Throttle - RW */
  23.561 +#define E1000_LEDCTL   0x00E00  /* LED Control - RW */
  23.562 +#define E1000_PBA      0x01000  /* Packet Buffer Allocation - RW */
  23.563 +#define E1000_FCRTL    0x02160  /* Flow Control Receive Threshold Low - RW */
  23.564 +#define E1000_FCRTH    0x02168  /* Flow Control Receive Threshold High - RW */
  23.565 +#define E1000_RDBAL    0x02800  /* RX Descriptor Base Address Low - RW */
  23.566 +#define E1000_RDBAH    0x02804  /* RX Descriptor Base Address High - RW */
  23.567 +#define E1000_RDLEN    0x02808  /* RX Descriptor Length - RW */
  23.568 +#define E1000_RDH      0x02810  /* RX Descriptor Head - RW */
  23.569 +#define E1000_RDT      0x02818  /* RX Descriptor Tail - RW */
  23.570 +#define E1000_RDTR     0x02820  /* RX Delay Timer - RW */
  23.571 +#define E1000_RXDCTL   0x02828  /* RX Descriptor Control - RW */
  23.572 +#define E1000_RADV     0x0282C  /* RX Interrupt Absolute Delay Timer - RW */
  23.573 +#define E1000_RSRPD    0x02C00  /* RX Small Packet Detect - RW */
  23.574 +#define E1000_TXDMAC   0x03000  /* TX DMA Control - RW */
  23.575 +#define E1000_TDBAL    0x03800  /* TX Descriptor Base Address Low - RW */
  23.576 +#define E1000_TDBAH    0x03804  /* TX Descriptor Base Address High - RW */
  23.577 +#define E1000_TDLEN    0x03808  /* TX Descriptor Length - RW */
  23.578 +#define E1000_TDH      0x03810  /* TX Descriptor Head - RW */
  23.579 +#define E1000_TDT      0x03818  /* TX Descripotr Tail - RW */
  23.580 +#define E1000_TIDV     0x03820  /* TX Interrupt Delay Value - RW */
  23.581 +#define E1000_TXDCTL   0x03828  /* TX Descriptor Control - RW */
  23.582 +#define E1000_TADV     0x0382C  /* TX Interrupt Absolute Delay Val - RW */
  23.583 +#define E1000_TSPMT    0x03830  /* TCP Segmentation PAD & Min Threshold - RW */
  23.584 +#define E1000_CRCERRS  0x04000  /* CRC Error Count - R/clr */
  23.585 +#define E1000_ALGNERRC 0x04004  /* Alignment Error Count - R/clr */
  23.586 +#define E1000_SYMERRS  0x04008  /* Symbol Error Count - R/clr */
  23.587 +#define E1000_RXERRC   0x0400C  /* Receive Error Count - R/clr */
  23.588 +#define E1000_MPC      0x04010  /* Missed Packet Count - R/clr */
  23.589 +#define E1000_SCC      0x04014  /* Single Collision Count - R/clr */
  23.590 +#define E1000_ECOL     0x04018  /* Excessive Collision Count - R/clr */
  23.591 +#define E1000_MCC      0x0401C  /* Multiple Collision Count - R/clr */
  23.592 +#define E1000_LATECOL  0x04020  /* Late Collision Count - R/clr */
  23.593 +#define E1000_COLC     0x04028  /* Collision Count - R/clr */
  23.594 +#define E1000_DC       0x04030  /* Defer Count - R/clr */
  23.595 +#define E1000_TNCRS    0x04034  /* TX-No CRS - R/clr */
  23.596 +#define E1000_SEC      0x04038  /* Sequence Error Count - R/clr */
  23.597 +#define E1000_CEXTERR  0x0403C  /* Carrier Extension Error Count - R/clr */
  23.598 +#define E1000_RLEC     0x04040  /* Receive Length Error Count - R/clr */
  23.599 +#define E1000_XONRXC   0x04048  /* XON RX Count - R/clr */
  23.600 +#define E1000_XONTXC   0x0404C  /* XON TX Count - R/clr */
  23.601 +#define E1000_XOFFRXC  0x04050  /* XOFF RX Count - R/clr */
  23.602 +#define E1000_XOFFTXC  0x04054  /* XOFF TX Count - R/clr */
  23.603 +#define E1000_FCRUC    0x04058  /* Flow Control RX Unsupported Count- R/clr */
  23.604 +#define E1000_PRC64    0x0405C  /* Packets RX (64 bytes) - R/clr */
  23.605 +#define E1000_PRC127   0x04060  /* Packets RX (65-127 bytes) - R/clr */
  23.606 +#define E1000_PRC255   0x04064  /* Packets RX (128-255 bytes) - R/clr */
  23.607 +#define E1000_PRC511   0x04068  /* Packets RX (255-511 bytes) - R/clr */
  23.608 +#define E1000_PRC1023  0x0406C  /* Packets RX (512-1023 bytes) - R/clr */
  23.609 +#define E1000_PRC1522  0x04070  /* Packets RX (1024-1522 bytes) - R/clr */
  23.610 +#define E1000_GPRC     0x04074  /* Good Packets RX Count - R/clr */
  23.611 +#define E1000_BPRC     0x04078  /* Broadcast Packets RX Count - R/clr */
  23.612 +#define E1000_MPRC     0x0407C  /* Multicast Packets RX Count - R/clr */
  23.613 +#define E1000_GPTC     0x04080  /* Good Packets TX Count - R/clr */
  23.614 +#define E1000_GORCL    0x04088  /* Good Octets RX Count Low - R/clr */
  23.615 +#define E1000_GORCH    0x0408C  /* Good Octets RX Count High - R/clr */
  23.616 +#define E1000_GOTCL    0x04090  /* Good Octets TX Count Low - R/clr */
  23.617 +#define E1000_GOTCH    0x04094  /* Good Octets TX Count High - R/clr */
  23.618 +#define E1000_RNBC     0x040A0  /* RX No Buffers Count - R/clr */
  23.619 +#define E1000_RUC      0x040A4  /* RX Undersize Count - R/clr */
  23.620 +#define E1000_RFC      0x040A8  /* RX Fragment Count - R/clr */
  23.621 +#define E1000_ROC      0x040AC  /* RX Oversize Count - R/clr */
  23.622 +#define E1000_RJC      0x040B0  /* RX Jabber Count - R/clr */
  23.623 +#define E1000_MGTPRC   0x040B4  /* Management Packets RX Count - R/clr */
  23.624 +#define E1000_MGTPDC   0x040B8  /* Management Packets Dropped Count - R/clr */
  23.625 +#define E1000_MGTPTC   0x040BC  /* Management Packets TX Count - R/clr */
  23.626 +#define E1000_TORL     0x040C0  /* Total Octets RX Low - R/clr */
  23.627 +#define E1000_TORH     0x040C4  /* Total Octets RX High - R/clr */
  23.628 +#define E1000_TOTL     0x040C8  /* Total Octets TX Low - R/clr */
  23.629 +#define E1000_TOTH     0x040CC  /* Total Octets TX High - R/clr */
  23.630 +#define E1000_TPR      0x040D0  /* Total Packets RX - R/clr */
  23.631 +#define E1000_TPT      0x040D4  /* Total Packets TX - R/clr */
  23.632 +#define E1000_PTC64    0x040D8  /* Packets TX (64 bytes) - R/clr */
  23.633 +#define E1000_PTC127   0x040DC  /* Packets TX (65-127 bytes) - R/clr */
  23.634 +#define E1000_PTC255   0x040E0  /* Packets TX (128-255 bytes) - R/clr */
  23.635 +#define E1000_PTC511   0x040E4  /* Packets TX (256-511 bytes) - R/clr */
  23.636 +#define E1000_PTC1023  0x040E8  /* Packets TX (512-1023 bytes) - R/clr */
  23.637 +#define E1000_PTC1522  0x040EC  /* Packets TX (1024-1522 Bytes) - R/clr */
  23.638 +#define E1000_MPTC     0x040F0  /* Multicast Packets TX Count - R/clr */
  23.639 +#define E1000_BPTC     0x040F4  /* Broadcast Packets TX Count - R/clr */
  23.640 +#define E1000_TSCTC    0x040F8  /* TCP Segmentation Context TX - R/clr */
  23.641 +#define E1000_TSCTFC   0x040FC  /* TCP Segmentation Context TX Fail - R/clr */
  23.642 +#define E1000_RXCSUM   0x05000  /* RX Checksum Control - RW */
  23.643 +#define E1000_MTA      0x05200  /* Multicast Table Array - RW Array */
  23.644 +#define E1000_RA       0x05400  /* Receive Address - RW Array */
  23.645 +#define E1000_VFTA     0x05600  /* VLAN Filter Table Array - RW Array */
  23.646 +#define E1000_WUC      0x05800  /* Wakeup Control - RW */
  23.647 +#define E1000_WUFC     0x05808  /* Wakeup Filter Control - RW */
  23.648 +#define E1000_WUS      0x05810  /* Wakeup Status - RO */
  23.649 +#define E1000_MANC     0x05820  /* Management Control - RW */
  23.650 +#define E1000_IPAV     0x05838  /* IP Address Valid - RW */
  23.651 +#define E1000_IP4AT    0x05840  /* IPv4 Address Table - RW Array */
  23.652 +#define E1000_IP6AT    0x05880  /* IPv6 Address Table - RW Array */
  23.653 +#define E1000_WUPL     0x05900  /* Wakeup Packet Length - RW */
  23.654 +#define E1000_WUPM     0x05A00  /* Wakeup Packet Memory - RO A */
  23.655 +#define E1000_FFLT     0x05F00  /* Flexible Filter Length Table - RW Array */
  23.656 +#define E1000_FFMT     0x09000  /* Flexible Filter Mask Table - RW Array */
  23.657 +#define E1000_FFVT     0x09800  /* Flexible Filter Value Table - RW Array */
  23.658 +
  23.659 +/* Register Set (82542)
  23.660 + *
  23.661 + * Some of the 82542 registers are located at different offsets than they are
  23.662 + * in more current versions of the 8254x. Despite the difference in location,
  23.663 + * the registers function in the same manner.
  23.664 + */
  23.665 +#define E1000_82542_CTRL     E1000_CTRL
  23.666 +#define E1000_82542_STATUS   E1000_STATUS
  23.667 +#define E1000_82542_EECD     E1000_EECD
  23.668 +#define E1000_82542_EERD     E1000_EERD
  23.669 +#define E1000_82542_CTRL_EXT E1000_CTRL_EXT
  23.670 +#define E1000_82542_MDIC     E1000_MDIC
  23.671 +#define E1000_82542_FCAL     E1000_FCAL
  23.672 +#define E1000_82542_FCAH     E1000_FCAH
  23.673 +#define E1000_82542_FCT      E1000_FCT
  23.674 +#define E1000_82542_VET      E1000_VET
  23.675 +#define E1000_82542_RA       0x00040
  23.676 +#define E1000_82542_ICR      E1000_ICR
  23.677 +#define E1000_82542_ITR      E1000_ITR
  23.678 +#define E1000_82542_ICS      E1000_ICS
  23.679 +#define E1000_82542_IMS      E1000_IMS
  23.680 +#define E1000_82542_IMC      E1000_IMC
  23.681 +#define E1000_82542_RCTL     E1000_RCTL
  23.682 +#define E1000_82542_RDTR     0x00108
  23.683 +#define E1000_82542_RDBAL    0x00110
  23.684 +#define E1000_82542_RDBAH    0x00114
  23.685 +#define E1000_82542_RDLEN    0x00118
  23.686 +#define E1000_82542_RDH      0x00120
  23.687 +#define E1000_82542_RDT      0x00128
  23.688 +#define E1000_82542_FCRTH    0x00160
  23.689 +#define E1000_82542_FCRTL    0x00168
  23.690 +#define E1000_82542_FCTTV    E1000_FCTTV
  23.691 +#define E1000_82542_TXCW     E1000_TXCW
  23.692 +#define E1000_82542_RXCW     E1000_RXCW
  23.693 +#define E1000_82542_MTA      0x00200
  23.694 +#define E1000_82542_TCTL     E1000_TCTL
  23.695 +#define E1000_82542_TIPG     E1000_TIPG
  23.696 +#define E1000_82542_TDBAL    0x00420
  23.697 +#define E1000_82542_TDBAH    0x00424
  23.698 +#define E1000_82542_TDLEN    0x00428
  23.699 +#define E1000_82542_TDH      0x00430
  23.700 +#define E1000_82542_TDT      0x00438
  23.701 +#define E1000_82542_TIDV     0x00440
  23.702 +#define E1000_82542_TBT      E1000_TBT
  23.703 +#define E1000_82542_AIT      E1000_AIT
  23.704 +#define E1000_82542_VFTA     0x00600
  23.705 +#define E1000_82542_LEDCTL   E1000_LEDCTL
  23.706 +#define E1000_82542_PBA      E1000_PBA
  23.707 +#define E1000_82542_RXDCTL   E1000_RXDCTL
  23.708 +#define E1000_82542_RADV     E1000_RADV
  23.709 +#define E1000_82542_RSRPD    E1000_RSRPD
  23.710 +#define E1000_82542_TXDMAC   E1000_TXDMAC
  23.711 +#define E1000_82542_TXDCTL   E1000_TXDCTL
  23.712 +#define E1000_82542_TADV     E1000_TADV
  23.713 +#define E1000_82542_TSPMT    E1000_TSPMT
  23.714 +#define E1000_82542_CRCERRS  E1000_CRCERRS
  23.715 +#define E1000_82542_ALGNERRC E1000_ALGNERRC
  23.716 +#define E1000_82542_SYMERRS  E1000_SYMERRS
  23.717 +#define E1000_82542_RXERRC   E1000_RXERRC
  23.718 +#define E1000_82542_MPC      E1000_MPC
  23.719 +#define E1000_82542_SCC      E1000_SCC
  23.720 +#define E1000_82542_ECOL     E1000_ECOL
  23.721 +#define E1000_82542_MCC      E1000_MCC
  23.722 +#define E1000_82542_LATECOL  E1000_LATECOL
  23.723 +#define E1000_82542_COLC     E1000_COLC
  23.724 +#define E1000_82542_DC       E1000_DC
  23.725 +#define E1000_82542_TNCRS    E1000_TNCRS
  23.726 +#define E1000_82542_SEC      E1000_SEC
  23.727 +#define E1000_82542_CEXTERR  E1000_CEXTERR
  23.728 +#define E1000_82542_RLEC     E1000_RLEC
  23.729 +#define E1000_82542_XONRXC   E1000_XONRXC
  23.730 +#define E1000_82542_XONTXC   E1000_XONTXC
  23.731 +#define E1000_82542_XOFFRXC  E1000_XOFFRXC
  23.732 +#define E1000_82542_XOFFTXC  E1000_XOFFTXC
  23.733 +#define E1000_82542_FCRUC    E1000_FCRUC
  23.734 +#define E1000_82542_PRC64    E1000_PRC64
  23.735 +#define E1000_82542_PRC127   E1000_PRC127
  23.736 +#define E1000_82542_PRC255   E1000_PRC255
  23.737 +#define E1000_82542_PRC511   E1000_PRC511
  23.738 +#define E1000_82542_PRC1023  E1000_PRC1023
  23.739 +#define E1000_82542_PRC1522  E1000_PRC1522
  23.740 +#define E1000_82542_GPRC     E1000_GPRC
  23.741 +#define E1000_82542_BPRC     E1000_BPRC
  23.742 +#define E1000_82542_MPRC     E1000_MPRC
  23.743 +#define E1000_82542_GPTC     E1000_GPTC
  23.744 +#define E1000_82542_GORCL    E1000_GORCL
  23.745 +#define E1000_82542_GORCH    E1000_GORCH
  23.746 +#define E1000_82542_GOTCL    E1000_GOTCL
  23.747 +#define E1000_82542_GOTCH    E1000_GOTCH
  23.748 +#define E1000_82542_RNBC     E1000_RNBC
  23.749 +#define E1000_82542_RUC      E1000_RUC
  23.750 +#define E1000_82542_RFC      E1000_RFC
  23.751 +#define E1000_82542_ROC      E1000_ROC
  23.752 +#define E1000_82542_RJC      E1000_RJC
  23.753 +#define E1000_82542_MGTPRC   E1000_MGTPRC
  23.754 +#define E1000_82542_MGTPDC   E1000_MGTPDC
  23.755 +#define E1000_82542_MGTPTC   E1000_MGTPTC
  23.756 +#define E1000_82542_TORL     E1000_TORL
  23.757 +#define E1000_82542_TORH     E1000_TORH
  23.758 +#define E1000_82542_TOTL     E1000_TOTL
  23.759 +#define E1000_82542_TOTH     E1000_TOTH
  23.760 +#define E1000_82542_TPR      E1000_TPR
  23.761 +#define E1000_82542_TPT      E1000_TPT
  23.762 +#define E1000_82542_PTC64    E1000_PTC64
  23.763 +#define E1000_82542_PTC127   E1000_PTC127
  23.764 +#define E1000_82542_PTC255   E1000_PTC255
  23.765 +#define E1000_82542_PTC511   E1000_PTC511
  23.766 +#define E1000_82542_PTC1023  E1000_PTC1023
  23.767 +#define E1000_82542_PTC1522  E1000_PTC1522
  23.768 +#define E1000_82542_MPTC     E1000_MPTC
  23.769 +#define E1000_82542_BPTC     E1000_BPTC
  23.770 +#define E1000_82542_TSCTC    E1000_TSCTC
  23.771 +#define E1000_82542_TSCTFC   E1000_TSCTFC
  23.772 +#define E1000_82542_RXCSUM   E1000_RXCSUM
  23.773 +#define E1000_82542_WUC      E1000_WUC
  23.774 +#define E1000_82542_WUFC     E1000_WUFC
  23.775 +#define E1000_82542_WUS      E1000_WUS
  23.776 +#define E1000_82542_MANC     E1000_MANC
  23.777 +#define E1000_82542_IPAV     E1000_IPAV
  23.778 +#define E1000_82542_IP4AT    E1000_IP4AT
  23.779 +#define E1000_82542_IP6AT    E1000_IP6AT
  23.780 +#define E1000_82542_WUPL     E1000_WUPL
  23.781 +#define E1000_82542_WUPM     E1000_WUPM
  23.782 +#define E1000_82542_FFLT     E1000_FFLT
  23.783 +#define E1000_82542_FFMT     E1000_FFMT
  23.784 +#define E1000_82542_FFVT     E1000_FFVT
  23.785 +
  23.786 +/* Statistics counters collected by the MAC */
  23.787 +struct e1000_hw_stats {
  23.788 +    uint64_t crcerrs;
  23.789 +    uint64_t algnerrc;
  23.790 +    uint64_t symerrs;
  23.791 +    uint64_t rxerrc;
  23.792 +    uint64_t mpc;
  23.793 +    uint64_t scc;
  23.794 +    uint64_t ecol;
  23.795 +    uint64_t mcc;
  23.796 +    uint64_t latecol;
  23.797 +    uint64_t colc;
  23.798 +    uint64_t dc;
  23.799 +    uint64_t tncrs;
  23.800 +    uint64_t sec;
  23.801 +    uint64_t cexterr;
  23.802 +    uint64_t rlec;
  23.803 +    uint64_t xonrxc;
  23.804 +    uint64_t xontxc;
  23.805 +    uint64_t xoffrxc;
  23.806 +    uint64_t xofftxc;
  23.807 +    uint64_t fcruc;
  23.808 +    uint64_t prc64;
  23.809 +    uint64_t prc127;
  23.810 +    uint64_t prc255;
  23.811 +    uint64_t prc511;
  23.812 +    uint64_t prc1023;
  23.813 +    uint64_t prc1522;
  23.814 +    uint64_t gprc;
  23.815 +    uint64_t bprc;
  23.816 +    uint64_t mprc;
  23.817 +    uint64_t gptc;
  23.818 +    uint64_t gorcl;
  23.819 +    uint64_t gorch;
  23.820 +    uint64_t gotcl;
  23.821 +    uint64_t gotch;
  23.822 +    uint64_t rnbc;
  23.823 +    uint64_t ruc;
  23.824 +    uint64_t rfc;
  23.825 +    uint64_t roc;
  23.826 +    uint64_t rjc;
  23.827 +    uint64_t mgprc;
  23.828 +    uint64_t mgpdc;
  23.829 +    uint64_t mgptc;
  23.830 +    uint64_t torl;
  23.831 +    uint64_t torh;
  23.832 +    uint64_t totl;
  23.833 +    uint64_t toth;
  23.834 +    uint64_t tpr;
  23.835 +    uint64_t tpt;
  23.836 +    uint64_t ptc64;
  23.837 +    uint64_t ptc127;
  23.838 +    uint64_t ptc255;
  23.839 +    uint64_t ptc511;
  23.840 +    uint64_t ptc1023;
  23.841 +    uint64_t ptc1522;
  23.842 +    uint64_t mptc;
  23.843 +    uint64_t bptc;
  23.844 +    uint64_t tsctc;
  23.845 +    uint64_t tsctfc;
  23.846 +};
  23.847 +
  23.848 +/* Structure containing variables used by the shared code (e1000_hw.c) */
  23.849 +struct e1000_hw {
  23.850 +    uint8_t *hw_addr;
  23.851 +    e1000_mac_type mac_type;
  23.852 +    e1000_media_type media_type;
  23.853 +    void *back;
  23.854 +    e1000_fc_type fc;
  23.855 +    e1000_bus_speed bus_speed;
  23.856 +    e1000_bus_width bus_width;
  23.857 +    e1000_bus_type bus_type;
  23.858 +    uint32_t io_base;
  23.859 +    uint32_t phy_id;
  23.860 +    uint32_t phy_revision;
  23.861 +    uint32_t phy_addr;
  23.862 +    uint32_t original_fc;
  23.863 +    uint32_t txcw;
  23.864 +    uint32_t autoneg_failed;
  23.865 +    uint32_t max_frame_size;
  23.866 +    uint32_t min_frame_size;
  23.867 +    uint32_t mc_filter_type;
  23.868 +    uint32_t num_mc_addrs;
  23.869 +    uint32_t collision_delta;
  23.870 +    uint32_t tx_packet_delta;
  23.871 +    uint32_t ledctl_default;
  23.872 +    uint32_t ledctl_mode1;
  23.873 +    uint32_t ledctl_mode2;
  23.874 +    uint16_t autoneg_advertised;
  23.875 +    uint16_t pci_cmd_word;
  23.876 +    uint16_t fc_high_water;
  23.877 +    uint16_t fc_low_water;
  23.878 +    uint16_t fc_pause_time;
  23.879 +    uint16_t current_ifs_val;
  23.880 +    uint16_t ifs_min_val;
  23.881 +    uint16_t ifs_max_val;
  23.882 +    uint16_t ifs_step_size;
  23.883 +    uint16_t ifs_ratio;
  23.884 +    uint16_t device_id;
  23.885 +    uint16_t vendor_id;
  23.886 +    uint16_t subsystem_id;
  23.887 +    uint16_t subsystem_vendor_id;
  23.888 +    uint8_t revision_id;
  23.889 +    uint8_t autoneg;
  23.890 +    uint8_t mdix;
  23.891 +    uint8_t forced_speed_duplex;
  23.892 +    uint8_t wait_autoneg_complete;
  23.893 +    uint8_t dma_fairness;
  23.894 +    uint8_t mac_addr[NODE_ADDRESS_SIZE];
  23.895 +    uint8_t perm_mac_addr[NODE_ADDRESS_SIZE];
  23.896 +    boolean_t disable_polarity_correction;
  23.897 +    boolean_t get_link_status;
  23.898 +    boolean_t tbi_compatibility_en;
  23.899 +    boolean_t tbi_compatibility_on;
  23.900 +    boolean_t fc_send_xon;
  23.901 +    boolean_t report_tx_early;
  23.902 +    boolean_t adaptive_ifs;
  23.903 +    boolean_t ifs_params_forced;
  23.904 +    boolean_t in_ifs_mode;
  23.905 +};
  23.906 +
  23.907 +
  23.908 +#define E1000_EEPROM_SWDPIN0   0x0001   /* SWDPIN 0 EEPROM Value */
  23.909 +#define E1000_EEPROM_LED_LOGIC 0x0020   /* Led Logic Word */
  23.910 +
  23.911 +/* Register Bit Masks */
  23.912 +/* Device Control */
  23.913 +#define E1000_CTRL_FD       0x00000001  /* Full duplex.0=half; 1=full */
  23.914 +#define E1000_CTRL_BEM      0x00000002  /* Endian Mode.0=little,1=big */
  23.915 +#define E1000_CTRL_PRIOR    0x00000004  /* Priority on PCI. 0=rx,1=fair */
  23.916 +#define E1000_CTRL_LRST     0x00000008  /* Link reset. 0=normal,1=reset */
  23.917 +#define E1000_CTRL_TME      0x00000010  /* Test mode. 0=normal,1=test */
  23.918 +#define E1000_CTRL_SLE      0x00000020  /* Serial Link on 0=dis,1=en */
  23.919 +#define E1000_CTRL_ASDE     0x00000020  /* Auto-speed detect enable */
  23.920 +#define E1000_CTRL_SLU      0x00000040  /* Set link up (Force Link) */
  23.921 +#define E1000_CTRL_ILOS     0x00000080  /* Invert Loss-Of Signal */
  23.922 +#define E1000_CTRL_SPD_SEL  0x00000300  /* Speed Select Mask */
  23.923 +#define E1000_CTRL_SPD_10   0x00000000  /* Force 10Mb */
  23.924 +#define E1000_CTRL_SPD_100  0x00000100  /* Force 100Mb */
  23.925 +#define E1000_CTRL_SPD_1000 0x00000200  /* Force 1Gb */
  23.926 +#define E1000_CTRL_BEM32    0x00000400  /* Big Endian 32 mode */
  23.927 +#define E1000_CTRL_FRCSPD   0x00000800  /* Force Speed */
  23.928 +#define E1000_CTRL_FRCDPX   0x00001000  /* Force Duplex */
  23.929 +#define E1000_CTRL_SWDPIN0  0x00040000  /* SWDPIN 0 value */
  23.930 +#define E1000_CTRL_SWDPIN1  0x00080000  /* SWDPIN 1 value */
  23.931 +#define E1000_CTRL_SWDPIN2  0x00100000  /* SWDPIN 2 value */
  23.932 +#define E1000_CTRL_SWDPIN3  0x00200000  /* SWDPIN 3 value */
  23.933 +#define E1000_CTRL_SWDPIO0  0x00400000  /* SWDPIN 0 Input or output */
  23.934 +#define E1000_CTRL_SWDPIO1  0x00800000  /* SWDPIN 1 input or output */
  23.935 +#define E1000_CTRL_SWDPIO2  0x01000000  /* SWDPIN 2 input or output */
  23.936 +#define E1000_CTRL_SWDPIO3  0x02000000  /* SWDPIN 3 input or output */
  23.937 +#define E1000_CTRL_RST      0x04000000  /* Global reset */
  23.938 +#define E1000_CTRL_RFCE     0x08000000  /* Receive Flow Control enable */
  23.939 +#define E1000_CTRL_TFCE     0x10000000  /* Transmit flow control enable */
  23.940 +#define E1000_CTRL_RTE      0x20000000  /* Routing tag enable */
  23.941 +#define E1000_CTRL_VME      0x40000000  /* IEEE VLAN mode enable */
  23.942 +#define E1000_CTRL_PHY_RST  0x80000000  /* PHY Reset */
  23.943 +
  23.944 +/* Device Status */
  23.945 +#define E1000_STATUS_FD         0x00000001      /* Full duplex.0=half,1=full */
  23.946 +#define E1000_STATUS_LU         0x00000002      /* Link up.0=no,1=link */
  23.947 +#define E1000_STATUS_FUNC_MASK  0x0000000C      /* PCI Function Mask */
  23.948 +#define E1000_STATUS_FUNC_0     0x00000000      /* Function 0 */
  23.949 +#define E1000_STATUS_FUNC_1     0x00000004      /* Function 1 */
  23.950 +#define E1000_STATUS_TXOFF      0x00000010      /* transmission paused */
  23.951 +#define E1000_STATUS_TBIMODE    0x00000020      /* TBI mode */
  23.952 +#define E1000_STATUS_SPEED_MASK 0x000000C0
  23.953 +#define E1000_STATUS_SPEED_10   0x00000000      /* Speed 10Mb/s */
  23.954 +#define E1000_STATUS_SPEED_100  0x00000040      /* Speed 100Mb/s */
  23.955 +#define E1000_STATUS_SPEED_1000 0x00000080      /* Speed 1000Mb/s */
  23.956 +#define E1000_STATUS_ASDV       0x00000300      /* Auto speed detect value */
  23.957 +#define E1000_STATUS_MTXCKOK    0x00000400      /* MTX clock running OK */
  23.958 +#define E1000_STATUS_PCI66      0x00000800      /* In 66Mhz slot */
  23.959 +#define E1000_STATUS_BUS64      0x00001000      /* In 64 bit slot */
  23.960 +#define E1000_STATUS_PCIX_MODE  0x00002000      /* PCI-X mode */
  23.961 +#define E1000_STATUS_PCIX_SPEED 0x0000C000      /* PCI-X bus speed */
  23.962 +
  23.963 +/* Constants used to intrepret the masked PCI-X bus speed. */
  23.964 +#define E1000_STATUS_PCIX_SPEED_66  0x00000000 /* PCI-X bus speed  50-66 MHz */
  23.965 +#define E1000_STATUS_PCIX_SPEED_100 0x00004000 /* PCI-X bus speed  66-100 MHz */
  23.966 +#define E1000_STATUS_PCIX_SPEED_133 0x00008000 /* PCI-X bus speed 100-133 MHz */
  23.967 +
  23.968 +/* EEPROM/Flash Control */
  23.969 +#define E1000_EECD_SK        0x00000001 /* EEPROM Clock */
  23.970 +#define E1000_EECD_CS        0x00000002 /* EEPROM Chip Select */
  23.971 +#define E1000_EECD_DI        0x00000004 /* EEPROM Data In */
  23.972 +#define E1000_EECD_DO        0x00000008 /* EEPROM Data Out */
  23.973 +#define E1000_EECD_FWE_MASK  0x00000030 
  23.974 +#define E1000_EECD_FWE_DIS   0x00000010 /* Disable FLASH writes */
  23.975 +#define E1000_EECD_FWE_EN    0x00000020 /* Enable FLASH writes */
  23.976 +#define E1000_EECD_FWE_SHIFT 4
  23.977 +#define E1000_EECD_SIZE      0x00000200 /* EEPROM Size (0=64 word 1=256 word) */
  23.978 +#define E1000_EECD_REQ       0x00000040 /* EEPROM Access Request */
  23.979 +#define E1000_EECD_GNT       0x00000080 /* EEPROM Access Grant */
  23.980 +#define E1000_EECD_PRES      0x00000100 /* EEPROM Present */
  23.981 +
  23.982 +/* EEPROM Read */
  23.983 +#define E1000_EERD_START      0x00000001 /* Start Read */
  23.984 +#define E1000_EERD_DONE       0x00000010 /* Read Done */
  23.985 +#define E1000_EERD_ADDR_SHIFT 8
  23.986 +#define E1000_EERD_ADDR_MASK  0x0000FF00 /* Read Address */
  23.987 +#define E1000_EERD_DATA_SHIFT 16
  23.988 +#define E1000_EERD_DATA_MASK  0xFFFF0000 /* Read Data */
  23.989 +
  23.990 +/* Extended Device Control */
  23.991 +#define E1000_CTRL_EXT_GPI0_EN   0x00000001 /* Maps SDP4 to GPI0 */ 
  23.992 +#define E1000_CTRL_EXT_GPI1_EN   0x00000002 /* Maps SDP5 to GPI1 */
  23.993 +#define E1000_CTRL_EXT_PHYINT_EN E1000_CTRL_EXT_GPI1_EN
  23.994 +#define E1000_CTRL_EXT_GPI2_EN   0x00000004 /* Maps SDP6 to GPI2 */
  23.995 +#define E1000_CTRL_EXT_GPI3_EN   0x00000008 /* Maps SDP7 to GPI3 */
  23.996 +#define E1000_CTRL_EXT_SDP4_DATA 0x00000010 /* Value of SW Defineable Pin 4 */
  23.997 +#define E1000_CTRL_EXT_SDP5_DATA 0x00000020 /* Value of SW Defineable Pin 5 */
  23.998 +#define E1000_CTRL_EXT_PHY_INT   E1000_CTRL_EXT_SDP5_DATA
  23.999 +#define E1000_CTRL_EXT_SDP6_DATA 0x00000040 /* Value of SW Defineable Pin 6 */
 23.1000 +#define E1000_CTRL_EXT_SDP7_DATA 0x00000080 /* Value of SW Defineable Pin 7 */
 23.1001 +#define E1000_CTRL_EXT_SDP4_DIR  0x00000100 /* Direction of SDP4 0=in 1=out */
 23.1002 +#define E1000_CTRL_EXT_SDP5_DIR  0x00000200 /* Direction of SDP5 0=in 1=out */
 23.1003 +#define E1000_CTRL_EXT_SDP6_DIR  0x00000400 /* Direction of SDP6 0=in 1=out */
 23.1004 +#define E1000_CTRL_EXT_SDP7_DIR  0x00000800 /* Direction of SDP7 0=in 1=out */
 23.1005 +#define E1000_CTRL_EXT_ASDCHK    0x00001000 /* Initiate an ASD sequence */
 23.1006 +#define E1000_CTRL_EXT_EE_RST    0x00002000 /* Reinitialize from EEPROM */
 23.1007 +#define E1000_CTRL_EXT_IPS       0x00004000 /* Invert Power State */
 23.1008 +#define E1000_CTRL_EXT_SPD_BYPS  0x00008000 /* Speed Select Bypass */
 23.1009 +#define E1000_CTRL_EXT_LINK_MODE_MASK 0x00C00000
 23.1010 +#define E1000_CTRL_EXT_LINK_MODE_GMII 0x00000000
 23.1011 +#define E1000_CTRL_EXT_LINK_MODE_TBI  0x00C00000
 23.1012 +#define E1000_CTRL_EXT_WR_WMARK_MASK  0x03000000
 23.1013 +#define E1000_CTRL_EXT_WR_WMARK_256   0x00000000
 23.1014 +#define E1000_CTRL_EXT_WR_WMARK_320   0x01000000
 23.1015 +#define E1000_CTRL_EXT_WR_WMARK_384   0x02000000
 23.1016 +#define E1000_CTRL_EXT_WR_WMARK_448   0x03000000
 23.1017 +
 23.1018 +/* MDI Control */
 23.1019 +#define E1000_MDIC_DATA_MASK 0x0000FFFF
 23.1020 +#define E1000_MDIC_REG_MASK  0x001F0000
 23.1021 +#define E1000_MDIC_REG_SHIFT 16
 23.1022 +#define E1000_MDIC_PHY_MASK  0x03E00000
 23.1023 +#define E1000_MDIC_PHY_SHIFT 21
 23.1024 +#define E1000_MDIC_OP_WRITE  0x04000000
 23.1025 +#define E1000_MDIC_OP_READ   0x08000000
 23.1026 +#define E1000_MDIC_READY     0x10000000
 23.1027 +#define E1000_MDIC_INT_EN    0x20000000
 23.1028 +#define E1000_MDIC_ERROR     0x40000000
 23.1029 +
 23.1030 +/* LED Control */
 23.1031 +#define E1000_LEDCTL_LED0_MODE_MASK  0x0000000F
 23.1032 +#define E1000_LEDCTL_LED0_MODE_SHIFT 0
 23.1033 +#define E1000_LEDCTL_LED0_IVRT       0x00000040
 23.1034 +#define E1000_LEDCTL_LED0_BLINK      0x00000080
 23.1035 +#define E1000_LEDCTL_LED1_MODE_MASK  0x00000F00
 23.1036 +#define E1000_LEDCTL_LED1_MODE_SHIFT 8
 23.1037 +#define E1000_LEDCTL_LED1_IVRT       0x00004000
 23.1038 +#define E1000_LEDCTL_LED1_BLINK      0x00008000
 23.1039 +#define E1000_LEDCTL_LED2_MODE_MASK  0x000F0000
 23.1040 +#define E1000_LEDCTL_LED2_MODE_SHIFT 16
 23.1041 +#define E1000_LEDCTL_LED2_IVRT       0x00400000
 23.1042 +#define E1000_LEDCTL_LED2_BLINK      0x00800000
 23.1043 +#define E1000_LEDCTL_LED3_MODE_MASK  0x0F000000
 23.1044 +#define E1000_LEDCTL_LED3_MODE_SHIFT 24
 23.1045 +#define E1000_LEDCTL_LED3_IVRT       0x40000000
 23.1046 +#define E1000_LEDCTL_LED3_BLINK      0x80000000
 23.1047 +
 23.1048 +#define E1000_LEDCTL_MODE_LINK_10_1000  0x0
 23.1049 +#define E1000_LEDCTL_MODE_LINK_100_1000 0x1
 23.1050 +#define E1000_LEDCTL_MODE_LINK_UP       0x2
 23.1051 +#define E1000_LEDCTL_MODE_ACTIVITY      0x3
 23.1052 +#define E1000_LEDCTL_MODE_LINK_ACTIVITY 0x4
 23.1053 +#define E1000_LEDCTL_MODE_LINK_10       0x5
 23.1054 +#define E1000_LEDCTL_MODE_LINK_100      0x6
 23.1055 +#define E1000_LEDCTL_MODE_LINK_1000     0x7
 23.1056 +#define E1000_LEDCTL_MODE_PCIX_MODE     0x8
 23.1057 +#define E1000_LEDCTL_MODE_FULL_DUPLEX   0x9
 23.1058 +#define E1000_LEDCTL_MODE_COLLISION     0xA
 23.1059 +#define E1000_LEDCTL_MODE_BUS_SPEED     0xB
 23.1060 +#define E1000_LEDCTL_MODE_BUS_SIZE      0xC
 23.1061 +#define E1000_LEDCTL_MODE_PAUSED        0xD
 23.1062 +#define E1000_LEDCTL_MODE_LED_ON        0xE
 23.1063 +#define E1000_LEDCTL_MODE_LED_OFF       0xF
 23.1064 +
 23.1065 +/* Receive Address */
 23.1066 +#define E1000_RAH_AV  0x80000000        /* Receive descriptor valid */
 23.1067 +
 23.1068 +/* Interrupt Cause Read */
 23.1069 +#define E1000_ICR_TXDW    0x00000001    /* Transmit desc written back */
 23.1070 +#define E1000_ICR_TXQE    0x00000002    /* Transmit Queue empty */
 23.1071 +#define E1000_ICR_LSC     0x00000004    /* Link Status Change */
 23.1072 +#define E1000_ICR_RXSEQ   0x00000008    /* rx sequence error */
 23.1073 +#define E1000_ICR_RXDMT0  0x00000010    /* rx desc min. threshold (0) */
 23.1074 +#define E1000_ICR_RXO     0x00000040    /* rx overrun */
 23.1075 +#define E1000_ICR_RXT0    0x00000080    /* rx timer intr (ring 0) */
 23.1076 +#define E1000_ICR_MDAC    0x00000200    /* MDIO access complete */
 23.1077 +#define E1000_ICR_RXCFG   0x00000400    /* RX /c/ ordered set */
 23.1078 +#define E1000_ICR_GPI_EN0 0x00000800    /* GP Int 0 */
 23.1079 +#define E1000_ICR_GPI_EN1 0x00001000    /* GP Int 1 */
 23.1080 +#define E1000_ICR_GPI_EN2 0x00002000    /* GP Int 2 */
 23.1081 +#define E1000_ICR_GPI_EN3 0x00004000    /* GP Int 3 */
 23.1082 +#define E1000_ICR_TXD_LOW 0x00008000
 23.1083 +#define E1000_ICR_SRPD    0x00010000
 23.1084 +
 23.1085 +/* Interrupt Cause Set */
 23.1086 +#define E1000_ICS_TXDW    E1000_ICR_TXDW        /* Transmit desc written back */
 23.1087 +#define E1000_ICS_TXQE    E1000_ICR_TXQE        /* Transmit Queue empty */
 23.1088 +#define E1000_ICS_LSC     E1000_ICR_LSC         /* Link Status Change */
 23.1089 +#define E1000_ICS_RXSEQ   E1000_ICR_RXSEQ       /* rx sequence error */
 23.1090 +#define E1000_ICS_RXDMT0  E1000_ICR_RXDMT0      /* rx desc min. threshold */
 23.1091 +#define E1000_ICS_RXO     E1000_ICR_RXO         /* rx overrun */
 23.1092 +#define E1000_ICS_RXT0    E1000_ICR_RXT0        /* rx timer intr */
 23.1093 +#define E1000_ICS_MDAC    E1000_ICR_MDAC        /* MDIO access complete */
 23.1094 +#define E1000_ICS_RXCFG   E1000_ICR_RXCFG       /* RX /c/ ordered set */
 23.1095 +#define E1000_ICS_GPI_EN0 E1000_ICR_GPI_EN0     /* GP Int 0 */
 23.1096 +#define E1000_ICS_GPI_EN1 E1000_ICR_GPI_EN1     /* GP Int 1 */
 23.1097 +#define E1000_ICS_GPI_EN2 E1000_ICR_GPI_EN2     /* GP Int 2 */
 23.1098 +#define E1000_ICS_GPI_EN3 E1000_ICR_GPI_EN3     /* GP Int 3 */
 23.1099 +#define E1000_ICS_TXD_LOW E1000_ICR_TXD_LOW
 23.1100 +#define E1000_ICS_SRPD    E1000_ICR_SRPD
 23.1101 +
 23.1102 +/* Interrupt Mask Set */
 23.1103 +#define E1000_IMS_TXDW    E1000_ICR_TXDW        /* Transmit desc written back */
 23.1104 +#define E1000_IMS_TXQE    E1000_ICR_TXQE        /* Transmit Queue empty */
 23.1105 +#define E1000_IMS_LSC     E1000_ICR_LSC         /* Link Status Change */
 23.1106 +#define E1000_IMS_RXSEQ   E1000_ICR_RXSEQ       /* rx sequence error */
 23.1107 +#define E1000_IMS_RXDMT0  E1000_ICR_RXDMT0      /* rx desc min. threshold */
 23.1108 +#define E1000_IMS_RXO     E1000_ICR_RXO         /* rx overrun */
 23.1109 +#define E1000_IMS_RXT0    E1000_ICR_RXT0        /* rx timer intr */
 23.1110 +#define E1000_IMS_MDAC    E1000_ICR_MDAC        /* MDIO access complete */
 23.1111 +#define E1000_IMS_RXCFG   E1000_ICR_RXCFG       /* RX /c/ ordered set */
 23.1112 +#define E1000_IMS_GPI_EN0 E1000_ICR_GPI_EN0     /* GP Int 0 */
 23.1113 +#define E1000_IMS_GPI_EN1 E1000_ICR_GPI_EN1     /* GP Int 1 */
 23.1114 +#define E1000_IMS_GPI_EN2 E1000_ICR_GPI_EN2     /* GP Int 2 */
 23.1115 +#define E1000_IMS_GPI_EN3 E1000_ICR_GPI_EN3     /* GP Int 3 */
 23.1116 +#define E1000_IMS_TXD_LOW E1000_ICR_TXD_LOW
 23.1117 +#define E1000_IMS_SRPD    E1000_ICR_SRPD
 23.1118 +
 23.1119 +/* Interrupt Mask Clear */
 23.1120 +#define E1000_IMC_TXDW    E1000_ICR_TXDW        /* Transmit desc written back */
 23.1121 +#define E1000_IMC_TXQE    E1000_ICR_TXQE        /* Transmit Queue empty */
 23.1122 +#define E1000_IMC_LSC     E1000_ICR_LSC         /* Link Status Change */
 23.1123 +#define E1000_IMC_RXSEQ   E1000_ICR_RXSEQ       /* rx sequence error */
 23.1124 +#define E1000_IMC_RXDMT0  E1000_ICR_RXDMT0      /* rx desc min. threshold */
 23.1125 +#define E1000_IMC_RXO     E1000_ICR_RXO         /* rx overrun */
 23.1126 +#define E1000_IMC_RXT0    E1000_ICR_RXT0        /* rx timer intr */
 23.1127 +#define E1000_IMC_MDAC    E1000_ICR_MDAC        /* MDIO access complete */
 23.1128 +#define E1000_IMC_RXCFG   E1000_ICR_RXCFG       /* RX /c/ ordered set */
 23.1129 +#define E1000_IMC_GPI_EN0 E1000_ICR_GPI_EN0     /* GP Int 0 */
 23.1130 +#define E1000_IMC_GPI_EN1 E1000_ICR_GPI_EN1     /* GP Int 1 */
 23.1131 +#define E1000_IMC_GPI_EN2 E1000_ICR_GPI_EN2     /* GP Int 2 */
 23.1132 +#define E1000_IMC_GPI_EN3 E1000_ICR_GPI_EN3     /* GP Int 3 */
 23.1133 +#define E1000_IMC_TXD_LOW E1000_ICR_TXD_LOW
 23.1134 +#define E1000_IMC_SRPD    E1000_ICR_SRPD
 23.1135 +
 23.1136 +/* Receive Control */
 23.1137 +#define E1000_RCTL_RST          0x00000001      /* Software reset */
 23.1138 +#define E1000_RCTL_EN           0x00000002      /* enable */
 23.1139 +#define E1000_RCTL_SBP          0x00000004      /* store bad packet */
 23.1140 +#define E1000_RCTL_UPE          0x00000008      /* unicast promiscuous enable */
 23.1141 +#define E1000_RCTL_MPE          0x00000010      /* multicast promiscuous enab */
 23.1142 +#define E1000_RCTL_LPE          0x00000020      /* long packet enable */
 23.1143 +#define E1000_RCTL_LBM_NO       0x00000000      /* no loopback mode */
 23.1144 +#define E1000_RCTL_LBM_MAC      0x00000040      /* MAC loopback mode */
 23.1145 +#define E1000_RCTL_LBM_SLP      0x00000080      /* serial link loopback mode */
 23.1146 +#define E1000_RCTL_LBM_TCVR     0x000000C0      /* tcvr loopback mode */
 23.1147 +#define E1000_RCTL_RDMTS_HALF   0x00000000      /* rx desc min threshold size */
 23.1148 +#define E1000_RCTL_RDMTS_QUAT   0x00000100      /* rx desc min threshold size */
 23.1149 +#define E1000_RCTL_RDMTS_EIGTH  0x00000200      /* rx desc min threshold size */
 23.1150 +#define E1000_RCTL_MO_SHIFT     12              /* multicast offset shift */
 23.1151 +#define E1000_RCTL_MO_0         0x00000000      /* multicast offset 11:0 */
 23.1152 +#define E1000_RCTL_MO_1         0x00001000      /* multicast offset 12:1 */
 23.1153 +#define E1000_RCTL_MO_2         0x00002000      /* multicast offset 13:2 */
 23.1154 +#define E1000_RCTL_MO_3         0x00003000      /* multicast offset 15:4 */
 23.1155 +#define E1000_RCTL_MDR          0x00004000      /* multicast desc ring 0 */
 23.1156 +#define E1000_RCTL_BAM          0x00008000      /* broadcast enable */
 23.1157 +/* these buffer sizes are valid if E1000_RCTL_BSEX is 0 */
 23.1158 +#define E1000_RCTL_SZ_2048      0x00000000      /* rx buffer size 2048 */
 23.1159 +#define E1000_RCTL_SZ_1024      0x00010000      /* rx buffer size 1024 */
 23.1160 +#define E1000_RCTL_SZ_512       0x00020000      /* rx buffer size 512 */
 23.1161 +#define E1000_RCTL_SZ_256       0x00030000      /* rx buffer size 256 */
 23.1162 +/* these buffer sizes are valid if E1000_RCTL_BSEX is 1 */
 23.1163 +#define E1000_RCTL_SZ_16384     0x00010000      /* rx buffer size 16384 */
 23.1164 +#define E1000_RCTL_SZ_8192      0x00020000      /* rx buffer size 8192 */
 23.1165 +#define E1000_RCTL_SZ_4096      0x00030000      /* rx buffer size 4096 */
 23.1166 +#define E1000_RCTL_VFE          0x00040000      /* vlan filter enable */
 23.1167 +#define E1000_RCTL_CFIEN        0x00080000      /* canonical form enable */
 23.1168 +#define E1000_RCTL_CFI          0x00100000      /* canonical form indicator */
 23.1169 +#define E1000_RCTL_DPF          0x00400000      /* discard pause frames */
 23.1170 +#define E1000_RCTL_PMCF         0x00800000      /* pass MAC control frames */
 23.1171 +#define E1000_RCTL_BSEX         0x02000000      /* Buffer size extension */
 23.1172 +
 23.1173 +/* Receive Descriptor */
 23.1174 +#define E1000_RDT_DELAY 0x0000ffff      /* Delay timer (1=1024us) */
 23.1175 +#define E1000_RDT_FPDB  0x80000000      /* Flush descriptor block */
 23.1176 +#define E1000_RDLEN_LEN 0x0007ff80      /* descriptor length */
 23.1177 +#define E1000_RDH_RDH   0x0000ffff      /* receive descriptor head */
 23.1178 +#define E1000_RDT_RDT   0x0000ffff      /* receive descriptor tail */
 23.1179 +
 23.1180 +/* Flow Control */
 23.1181 +#define E1000_FCRTH_RTH  0x0000FFF8     /* Mask Bits[15:3] for RTH */
 23.1182 +#define E1000_FCRTH_XFCE 0x80000000     /* External Flow Control Enable */
 23.1183 +#define E1000_FCRTL_RTL  0x0000FFF8     /* Mask Bits[15:3] for RTL */
 23.1184 +#define E1000_FCRTL_XONE 0x80000000     /* Enable XON frame transmission */
 23.1185 +
 23.1186 +/* Receive Descriptor Control */
 23.1187 +#define E1000_RXDCTL_PTHRESH 0x0000003F /* RXDCTL Prefetch Threshold */
 23.1188 +#define E1000_RXDCTL_HTHRESH 0x00003F00 /* RXDCTL Host Threshold */
 23.1189 +#define E1000_RXDCTL_WTHRESH 0x003F0000 /* RXDCTL Writeback Threshold */
 23.1190 +#define E1000_RXDCTL_GRAN    0x01000000 /* RXDCTL Granularity */
 23.1191 +
 23.1192 +/* Transmit Descriptor Control */
 23.1193 +#define E1000_TXDCTL_PTHRESH 0x000000FF /* TXDCTL Prefetch Threshold */
 23.1194 +#define E1000_TXDCTL_HTHRESH 0x0000FF00 /* TXDCTL Host Threshold */
 23.1195 +#define E1000_TXDCTL_WTHRESH 0x00FF0000 /* TXDCTL Writeback Threshold */
 23.1196 +#define E1000_TXDCTL_GRAN    0x01000000 /* TXDCTL Granularity */
 23.1197 +#define E1000_TXDCTL_LWTHRESH 0xFE000000 /* TXDCTL Low Threshold */
 23.1198 +#define E1000_TXDCTL_FULL_TX_DESC_WB 0x01010000 /* GRAN=1, WTHRESH=1 */
 23.1199 +
 23.1200 +/* Transmit Configuration Word */
 23.1201 +#define E1000_TXCW_FD         0x00000020        /* TXCW full duplex */
 23.1202 +#define E1000_TXCW_HD         0x00000040        /* TXCW half duplex */
 23.1203 +#define E1000_TXCW_PAUSE      0x00000080        /* TXCW sym pause request */
 23.1204 +#define E1000_TXCW_ASM_DIR    0x00000100        /* TXCW astm pause direction */
 23.1205 +#define E1000_TXCW_PAUSE_MASK 0x00000180        /* TXCW pause request mask */
 23.1206 +#define E1000_TXCW_RF         0x00003000        /* TXCW remote fault */
 23.1207 +#define E1000_TXCW_NP         0x00008000        /* TXCW next page */
 23.1208 +#define E1000_TXCW_CW         0x0000ffff        /* TxConfigWord mask */
 23.1209 +#define E1000_TXCW_TXC        0x40000000        /* Transmit Config control */
 23.1210 +#define E1000_TXCW_ANE        0x80000000        /* Auto-neg enable */
 23.1211 +
 23.1212 +/* Receive Configuration Word */
 23.1213 +#define E1000_RXCW_CW    0x0000ffff     /* RxConfigWord mask */
 23.1214 +#define E1000_RXCW_NC    0x04000000     /* Receive config no carrier */
 23.1215 +#define E1000_RXCW_IV    0x08000000     /* Receive config invalid */
 23.1216 +#define E1000_RXCW_CC    0x10000000     /* Receive config change */
 23.1217 +#define E1000_RXCW_C     0x20000000     /* Receive config */
 23.1218 +#define E1000_RXCW_SYNCH 0x40000000     /* Receive config synch */
 23.1219 +#define E1000_RXCW_ANC   0x80000000     /* Auto-neg complete */
 23.1220 +
 23.1221 +/* Transmit Control */
 23.1222 +#define E1000_TCTL_RST    0x00000001    /* software reset */
 23.1223 +#define E1000_TCTL_EN     0x00000002    /* enable tx */
 23.1224 +#define E1000_TCTL_BCE    0x00000004    /* busy check enable */
 23.1225 +#define E1000_TCTL_PSP    0x00000008    /* pad short packets */
 23.1226 +#define E1000_TCTL_CT     0x00000ff0    /* collision threshold */
 23.1227 +#define E1000_TCTL_COLD   0x003ff000    /* collision distance */
 23.1228 +#define E1000_TCTL_SWXOFF 0x00400000    /* SW Xoff transmission */
 23.1229 +#define E1000_TCTL_PBE    0x00800000    /* Packet Burst Enable */
 23.1230 +#define E1000_TCTL_RTLC   0x01000000    /* Re-transmit on late collision */
 23.1231 +#define E1000_TCTL_NRTU   0x02000000    /* No Re-transmit on underrun */
 23.1232 +
 23.1233 +/* Receive Checksum Control */
 23.1234 +#define E1000_RXCSUM_PCSS_MASK 0x000000FF   /* Packet Checksum Start */
 23.1235 +#define E1000_RXCSUM_IPOFL     0x00000100   /* IPv4 checksum offload */
 23.1236 +#define E1000_RXCSUM_TUOFL     0x00000200   /* TCP / UDP checksum offload */
 23.1237 +#define E1000_RXCSUM_IPV6OFL   0x00000400   /* IPv6 checksum offload */
 23.1238 +
 23.1239 +/* Definitions for power management and wakeup registers */
 23.1240 +/* Wake Up Control */
 23.1241 +#define E1000_WUC_APME       0x00000001 /* APM Enable */
 23.1242 +#define E1000_WUC_PME_EN     0x00000002 /* PME Enable */
 23.1243 +#define E1000_WUC_PME_STATUS 0x00000004 /* PME Status */
 23.1244 +#define E1000_WUC_APMPME     0x00000008 /* Assert PME on APM Wakeup */
 23.1245 +
 23.1246 +/* Wake Up Filter Control */
 23.1247 +#define E1000_WUFC_LNKC 0x00000001 /* Link Status Change Wakeup Enable */
 23.1248 +#define E1000_WUFC_MAG  0x00000002 /* Magic Packet Wakeup Enable */
 23.1249 +#define E1000_WUFC_EX   0x00000004 /* Directed Exact Wakeup Enable */
 23.1250 +#define E1000_WUFC_MC   0x00000008 /* Directed Multicast Wakeup Enable */
 23.1251 +#define E1000_WUFC_BC   0x00000010 /* Broadcast Wakeup Enable */
 23.1252 +#define E1000_WUFC_ARP  0x00000020 /* ARP Request Packet Wakeup Enable */
 23.1253 +#define E1000_WUFC_IPV4 0x00000040 /* Directed IPv4 Packet Wakeup Enable */
 23.1254 +#define E1000_WUFC_IPV6 0x00000080 /* Directed IPv6 Packet Wakeup Enable */
 23.1255 +#define E1000_WUFC_FLX0 0x00010000 /* Flexible Filter 0 Enable */
 23.1256 +#define E1000_WUFC_FLX1 0x00020000 /* Flexible Filter 1 Enable */
 23.1257 +#define E1000_WUFC_FLX2 0x00040000 /* Flexible Filter 2 Enable */
 23.1258 +#define E1000_WUFC_FLX3 0x00080000 /* Flexible Filter 3 Enable */
 23.1259 +#define E1000_WUFC_ALL_FILTERS 0x000F00FF /* Mask for all wakeup filters */
 23.1260 +#define E1000_WUFC_FLX_OFFSET 16       /* Offset to the Flexible Filters bits */
 23.1261 +#define E1000_WUFC_FLX_FILTERS 0x000F0000 /* Mask for the 4 flexible filters */
 23.1262 +
 23.1263 +/* Wake Up Status */
 23.1264 +#define E1000_WUS_LNKC 0x00000001 /* Link Status Changed */
 23.1265 +#define E1000_WUS_MAG  0x00000002 /* Magic Packet Received */
 23.1266 +#define E1000_WUS_EX   0x00000004 /* Directed Exact Received */
 23.1267 +#define E1000_WUS_MC   0x00000008 /* Directed Multicast Received */
 23.1268 +#define E1000_WUS_BC   0x00000010 /* Broadcast Received */
 23.1269 +#define E1000_WUS_ARP  0x00000020 /* ARP Request Packet Received */
 23.1270 +#define E1000_WUS_IPV4 0x00000040 /* Directed IPv4 Packet Wakeup Received */
 23.1271 +#define E1000_WUS_IPV6 0x00000080 /* Directed IPv6 Packet Wakeup Received */
 23.1272 +#define E1000_WUS_FLX0 0x00010000 /* Flexible Filter 0 Match */
 23.1273 +#define E1000_WUS_FLX1 0x00020000 /* Flexible Filter 1 Match */
 23.1274 +#define E1000_WUS_FLX2 0x00040000 /* Flexible Filter 2 Match */
 23.1275 +#define E1000_WUS_FLX3 0x00080000 /* Flexible Filter 3 Match */
 23.1276 +#define E1000_WUS_FLX_FILTERS 0x000F0000 /* Mask for the 4 flexible filters */
 23.1277 +
 23.1278 +/* Management Control */
 23.1279 +#define E1000_MANC_SMBUS_EN      0x00000001 /* SMBus Enabled - RO */
 23.1280 +#define E1000_MANC_ASF_EN        0x00000002 /* ASF Enabled - RO */
 23.1281 +#define E1000_MANC_R_ON_FORCE    0x00000004 /* Reset on Force TCO - RO */
 23.1282 +#define E1000_MANC_RMCP_EN       0x00000100 /* Enable RCMP 026Fh Filtering */
 23.1283 +#define E1000_MANC_0298_EN       0x00000200 /* Enable RCMP 0298h Filtering */
 23.1284 +#define E1000_MANC_IPV4_EN       0x00000400 /* Enable IPv4 */
 23.1285 +#define E1000_MANC_IPV6_EN       0x00000800 /* Enable IPv6 */
 23.1286 +#define E1000_MANC_SNAP_EN       0x00001000 /* Accept LLC/SNAP */
 23.1287 +#define E1000_MANC_ARP_EN        0x00002000 /* Enable ARP Request Filtering */
 23.1288 +#define E1000_MANC_NEIGHBOR_EN   0x00004000 /* Enable Neighbor Discovery 
 23.1289 +                                             * Filtering */
 23.1290 +#define E1000_MANC_TCO_RESET     0x00010000 /* TCO Reset Occurred */
 23.1291 +#define E1000_MANC_RCV_TCO_EN    0x00020000 /* Receive TCO Packets Enabled */
 23.1292 +#define E1000_MANC_REPORT_STATUS 0x00040000 /* Status Reporting Enabled */
 23.1293 +#define E1000_MANC_SMB_REQ       0x01000000 /* SMBus Request */
 23.1294 +#define E1000_MANC_SMB_GNT       0x02000000 /* SMBus Grant */
 23.1295 +#define E1000_MANC_SMB_CLK_IN    0x04000000 /* SMBus Clock In */
 23.1296 +#define E1000_MANC_SMB_DATA_IN   0x08000000 /* SMBus Data In */
 23.1297 +#define E1000_MANC_SMB_DATA_OUT  0x10000000 /* SMBus Data Out */
 23.1298 +#define E1000_MANC_SMB_CLK_OUT   0x20000000 /* SMBus Clock Out */
 23.1299 +
 23.1300 +#define E1000_MANC_SMB_DATA_OUT_SHIFT  28 /* SMBus Data Out Shift */
 23.1301 +#define E1000_MANC_SMB_CLK_OUT_SHIFT   29 /* SMBus Clock Out Shift */
 23.1302 +
 23.1303 +/* Wake Up Packet Length */
 23.1304 +#define E1000_WUPL_LENGTH_MASK 0x0FFF   /* Only the lower 12 bits are valid */
 23.1305 +
 23.1306 +#define E1000_MDALIGN          4096
 23.1307 +
 23.1308 +/* EEPROM Commands */
 23.1309 +#define EEPROM_READ_OPCODE  0x6  /* EERPOM read opcode */
 23.1310 +#define EEPROM_WRITE_OPCODE 0x5  /* EERPOM write opcode */
 23.1311 +#define EEPROM_ERASE_OPCODE 0x7  /* EERPOM erase opcode */
 23.1312 +#define EEPROM_EWEN_OPCODE  0x13 /* EERPOM erase/write enable */
 23.1313 +#define EEPROM_EWDS_OPCODE  0x10 /* EERPOM erast/write disable */
 23.1314 +
 23.1315 +/* EEPROM Word Offsets */
 23.1316 +#define EEPROM_COMPAT              0x0003
 23.1317 +#define EEPROM_ID_LED_SETTINGS     0x0004
 23.1318 +#define EEPROM_INIT_CONTROL1_REG   0x000A
 23.1319 +#define EEPROM_INIT_CONTROL2_REG   0x000F
 23.1320 +#define EEPROM_FLASH_VERSION       0x0032
 23.1321 +#define EEPROM_CHECKSUM_REG        0x003F
 23.1322 +
 23.1323 +/* Word definitions for ID LED Settings */
 23.1324 +#define ID_LED_RESERVED_0000 0x0000
 23.1325 +#define ID_LED_RESERVED_FFFF 0xFFFF
 23.1326 +#define ID_LED_DEFAULT       ((ID_LED_OFF1_ON2 << 12) | \
 23.1327 +                              (ID_LED_OFF1_OFF2 << 8) | \
 23.1328 +                              (ID_LED_DEF1_DEF2 << 4) | \
 23.1329 +                              (ID_LED_DEF1_DEF2))
 23.1330 +#define ID_LED_DEF1_DEF2     0x1
 23.1331 +#define ID_LED_DEF1_ON2      0x2
 23.1332 +#define ID_LED_DEF1_OFF2     0x3
 23.1333 +#define ID_LED_ON1_DEF2      0x4
 23.1334 +#define ID_LED_ON1_ON2       0x5
 23.1335 +#define ID_LED_ON1_OFF2      0x6
 23.1336 +#define ID_LED_OFF1_DEF2     0x7
 23.1337 +#define ID_LED_OFF1_ON2      0x8
 23.1338 +#define ID_LED_OFF1_OFF2     0x9
 23.1339 +
 23.1340 +/* Mask bits for fields in Word 0x03 of the EEPROM */
 23.1341 +#define EEPROM_COMPAT_SERVER 0x0400
 23.1342 +#define EEPROM_COMPAT_CLIENT 0x0200
 23.1343 +
 23.1344 +/* Mask bits for fields in Word 0x0a of the EEPROM */
 23.1345 +#define EEPROM_WORD0A_ILOS   0x0010
 23.1346 +#define EEPROM_WORD0A_SWDPIO 0x01E0
 23.1347 +#define EEPROM_WORD0A_LRST   0x0200
 23.1348 +#define EEPROM_WORD0A_FD     0x0400
 23.1349 +#define EEPROM_WORD0A_66MHZ  0x0800
 23.1350 +
 23.1351 +/* Mask bits for fields in Word 0x0f of the EEPROM */
 23.1352 +#define EEPROM_WORD0F_PAUSE_MASK 0x3000
 23.1353 +#define EEPROM_WORD0F_PAUSE      0x1000
 23.1354 +#define EEPROM_WORD0F_ASM_DIR    0x2000
 23.1355 +#define EEPROM_WORD0F_ANE        0x0800
 23.1356 +#define EEPROM_WORD0F_SWPDIO_EXT 0x00F0
 23.1357 +
 23.1358 +/* For checksumming, the sum of all words in the EEPROM should equal 0xBABA. */
 23.1359 +#define EEPROM_SUM 0xBABA
 23.1360 +
 23.1361 +/* EEPROM Map defines (WORD OFFSETS)*/
 23.1362 +#define EEPROM_NODE_ADDRESS_BYTE_0 0
 23.1363 +#define EEPROM_PBA_BYTE_1          8
 23.1364 +
 23.1365 +/* EEPROM Map Sizes (Byte Counts) */
 23.1366 +#define PBA_SIZE 4
 23.1367 +
 23.1368 +/* Collision related configuration parameters */
 23.1369 +#define E1000_COLLISION_THRESHOLD       16
 23.1370 +#define E1000_CT_SHIFT                  4
 23.1371 +#define E1000_COLLISION_DISTANCE        64
 23.1372 +#define E1000_FDX_COLLISION_DISTANCE    E1000_COLLISION_DISTANCE
 23.1373 +#define E1000_HDX_COLLISION_DISTANCE    E1000_COLLISION_DISTANCE
 23.1374 +#define E1000_GB_HDX_COLLISION_DISTANCE 512
 23.1375 +#define E1000_COLD_SHIFT                12
 23.1376 +
 23.1377 +/* The number of Transmit and Receive Descriptors must be a multiple of 8 */
 23.1378 +#define REQ_TX_DESCRIPTOR_MULTIPLE  8
 23.1379 +#define REQ_RX_DESCRIPTOR_MULTIPLE  8
 23.1380 +
 23.1381 +/* Default values for the transmit IPG register */
 23.1382 +#define DEFAULT_82542_TIPG_IPGT        10
 23.1383 +#define DEFAULT_82543_TIPG_IPGT_FIBER  9
 23.1384 +#define DEFAULT_82543_TIPG_IPGT_COPPER 8
 23.1385 +
 23.1386 +#define E1000_TIPG_IPGT_MASK  0x000003FF
 23.1387 +#define E1000_TIPG_IPGR1_MASK 0x000FFC00
 23.1388 +#define E1000_TIPG_IPGR2_MASK 0x3FF00000
 23.1389 +
 23.1390 +#define DEFAULT_82542_TIPG_IPGR1 2
 23.1391 +#define DEFAULT_82543_TIPG_IPGR1 8
 23.1392 +#define E1000_TIPG_IPGR1_SHIFT  10
 23.1393 +
 23.1394 +#define DEFAULT_82542_TIPG_IPGR2 10
 23.1395 +#define DEFAULT_82543_TIPG_IPGR2 6
 23.1396 +#define E1000_TIPG_IPGR2_SHIFT  20
 23.1397 +
 23.1398 +#define E1000_TXDMAC_DPP 0x00000001
 23.1399 +
 23.1400 +/* Adaptive IFS defines */
 23.1401 +#define TX_THRESHOLD_START     8
 23.1402 +#define TX_THRESHOLD_INCREMENT 10
 23.1403 +#define TX_THRESHOLD_DECREMENT 1
 23.1404 +#define TX_THRESHOLD_STOP      190
 23.1405 +#define TX_THRESHOLD_DISABLE   0
 23.1406 +#define TX_THRESHOLD_TIMER_MS  10000
 23.1407 +#define MIN_NUM_XMITS          1000
 23.1408 +#define IFS_MAX                80
 23.1409 +#define IFS_STEP               10
 23.1410 +#define IFS_MIN                40
 23.1411 +#define IFS_RATIO              4
 23.1412 +
 23.1413 +/* PBA constants */
 23.1414 +#define E1000_PBA_16K 0x0010    /* 16KB, default TX allocation */
 23.1415 +#define E1000_PBA_24K 0x0018
 23.1416 +#define E1000_PBA_40K 0x0028
 23.1417 +#define E1000_PBA_48K 0x0030    /* 48KB, default RX allocation */
 23.1418 +
 23.1419 +/* Flow Control Constants */
 23.1420 +#define FLOW_CONTROL_ADDRESS_LOW  0x00C28001
 23.1421 +#define FLOW_CONTROL_ADDRESS_HIGH 0x00000100
 23.1422 +#define FLOW_CONTROL_TYPE         0x8808
 23.1423 +
 23.1424 +/* The historical defaults for the flow control values are given below. */
 23.1425 +#define FC_DEFAULT_HI_THRESH        (0x8000)    /* 32KB */
 23.1426 +#define FC_DEFAULT_LO_THRESH        (0x4000)    /* 16KB */
 23.1427 +#define FC_DEFAULT_TX_TIMER         (0x100)     /* ~130 us */
 23.1428 +
 23.1429 +/* PCIX Config space */
 23.1430 +#define PCIX_COMMAND_REGISTER    0xE6
 23.1431 +#define PCIX_STATUS_REGISTER_LO  0xE8
 23.1432 +#define PCIX_STATUS_REGISTER_HI  0xEA
 23.1433 +
 23.1434 +#define PCIX_COMMAND_MMRBC_MASK      0x000C
 23.1435 +#define PCIX_COMMAND_MMRBC_SHIFT     0x2
 23.1436 +#define PCIX_STATUS_HI_MMRBC_MASK    0x0060
 23.1437 +#define PCIX_STATUS_HI_MMRBC_SHIFT   0x5
 23.1438 +#define PCIX_STATUS_HI_MMRBC_4K      0x3
 23.1439 +#define PCIX_STATUS_HI_MMRBC_2K      0x2
 23.1440 +
 23.1441 +
 23.1442 +/* The number of bits that we need to shift right to move the "pause"
 23.1443 + * bits from the EEPROM (bits 13:12) to the "pause" (bits 8:7) field
 23.1444 + * in the TXCW register 
 23.1445 + */
 23.1446 +#define PAUSE_SHIFT 5
 23.1447 +
 23.1448 +/* The number of bits that we need to shift left to move the "SWDPIO"
 23.1449 + * bits from the EEPROM (bits 8:5) to the "SWDPIO" (bits 25:22) field
 23.1450 + * in the CTRL register 
 23.1451 + */
 23.1452 +#define SWDPIO_SHIFT 17
 23.1453 +
 23.1454 +/* The number of bits that we need to shift left to move the "SWDPIO_EXT"
 23.1455 + * bits from the EEPROM word F (bits 7:4) to the bits 11:8 of The
 23.1456 + * Extended CTRL register.
 23.1457 + * in the CTRL register 
 23.1458 + */
 23.1459 +#define SWDPIO__EXT_SHIFT 4
 23.1460 +
 23.1461 +/* The number of bits that we need to shift left to move the "ILOS"
 23.1462 + * bit from the EEPROM (bit 4) to the "ILOS" (bit 7) field
 23.1463 + * in the CTRL register 
 23.1464 + */
 23.1465 +#define ILOS_SHIFT  3
 23.1466 +
 23.1467 +
 23.1468 +#define RECEIVE_BUFFER_ALIGN_SIZE  (256)
 23.1469 +
 23.1470 +/* The number of milliseconds we wait for auto-negotiation to complete */
 23.1471 +#define LINK_UP_TIMEOUT             500
 23.1472 +
 23.1473 +#define E1000_TX_BUFFER_SIZE ((uint32_t)1514)
 23.1474 +
 23.1475 +/* The carrier extension symbol, as received by the NIC. */
 23.1476 +#define CARRIER_EXTENSION   0x0F
 23.1477 +
 23.1478 +/* TBI_ACCEPT macro definition:
 23.1479 + *
 23.1480 + * This macro requires:
 23.1481 + *      adapter = a pointer to struct e1000_hw 
 23.1482 + *      status = the 8 bit status field of the RX descriptor with EOP set
 23.1483 + *      error = the 8 bit error field of the RX descriptor with EOP set
 23.1484 + *      length = the sum of all the length fields of the RX descriptors that
 23.1485 + *               make up the current frame
 23.1486 + *      last_byte = the last byte of the frame DMAed by the hardware
 23.1487 + *      max_frame_length = the maximum frame length we want to accept.
 23.1488 + *      min_frame_length = the minimum frame length we want to accept.
 23.1489 + *
 23.1490 + * This macro is a conditional that should be used in the interrupt 
 23.1491 + * handler's Rx processing routine when RxErrors have been detected.
 23.1492 + *
 23.1493 + * Typical use:
 23.1494 + *  ...
 23.1495 + *  if (TBI_ACCEPT) {
 23.1496 + *      accept_frame = TRUE;
 23.1497 + *      e1000_tbi_adjust_stats(adapter, MacAddress);
 23.1498 + *      frame_length--;
 23.1499 + *  } else {
 23.1500 + *      accept_frame = FALSE;
 23.1501 + *  }
 23.1502 + *  ...
 23.1503 + */
 23.1504 +
 23.1505 +#define TBI_ACCEPT(adapter, status, errors, length, last_byte) \
 23.1506 +    ((adapter)->tbi_compatibility_on && \
 23.1507 +     (((errors) & E1000_RXD_ERR_FRAME_ERR_MASK) == E1000_RXD_ERR_CE) && \
 23.1508 +     ((last_byte) == CARRIER_EXTENSION) && \
 23.1509 +     (((status) & E1000_RXD_STAT_VP) ? \
 23.1510 +          (((length) > ((adapter)->min_frame_size - VLAN_TAG_SIZE)) && \
 23.1511 +           ((length) <= ((adapter)->max_frame_size + 1))) : \
 23.1512 +          (((length) > (adapter)->min_frame_size) && \
 23.1513 +           ((length) <= ((adapter)->max_frame_size + VLAN_TAG_SIZE + 1)))))
 23.1514 +
 23.1515 +
 23.1516 +/* Structures, enums, and macros for the PHY */
 23.1517 +
 23.1518 +/* Bit definitions for the Management Data IO (MDIO) and Management Data
 23.1519 + * Clock (MDC) pins in the Device Control Register.
 23.1520 + */
 23.1521 +#define E1000_CTRL_PHY_RESET_DIR  E1000_CTRL_SWDPIO0
 23.1522 +#define E1000_CTRL_PHY_RESET      E1000_CTRL_SWDPIN0
 23.1523 +#define E1000_CTRL_MDIO_DIR       E1000_CTRL_SWDPIO2
 23.1524 +#define E1000_CTRL_MDIO           E1000_CTRL_SWDPIN2
 23.1525 +#define E1000_CTRL_MDC_DIR        E1000_CTRL_SWDPIO3
 23.1526 +#define E1000_CTRL_MDC            E1000_CTRL_SWDPIN3
 23.1527 +#define E1000_CTRL_PHY_RESET_DIR4 E1000_CTRL_EXT_SDP4_DIR
 23.1528 +#define E1000_CTRL_PHY_RESET4     E1000_CTRL_EXT_SDP4_DATA
 23.1529 +
 23.1530 +/* PHY 1000 MII Register/Bit Definitions */
 23.1531 +/* PHY Registers defined by IEEE */
 23.1532 +#define PHY_CTRL         0x00 /* Control Register */
 23.1533 +#define PHY_STATUS       0x01 /* Status Regiser */
 23.1534 +#define PHY_ID1          0x02 /* Phy Id Reg (word 1) */
 23.1535 +#define PHY_ID2          0x03 /* Phy Id Reg (word 2) */
 23.1536 +#define PHY_AUTONEG_ADV  0x04 /* Autoneg Advertisement */
 23.1537 +#define PHY_LP_ABILITY   0x05 /* Link Partner Ability (Base Page) */
 23.1538 +#define PHY_AUTONEG_EXP  0x06 /* Autoneg Expansion Reg */
 23.1539 +#define PHY_NEXT_PAGE_TX 0x07 /* Next Page TX */
 23.1540 +#define PHY_LP_NEXT_PAGE 0x08 /* Link Partner Next Page */
 23.1541 +#define PHY_1000T_CTRL   0x09 /* 1000Base-T Control Reg */
 23.1542 +#define PHY_1000T_STATUS 0x0A /* 1000Base-T Status Reg */
 23.1543 +#define PHY_EXT_STATUS   0x0F /* Extended Status Reg */
 23.1544 +
 23.1545 +/* M88E1000 Specific Registers */
 23.1546 +#define M88E1000_PHY_SPEC_CTRL     0x10  /* PHY Specific Control Register */
 23.1547 +#define M88E1000_PHY_SPEC_STATUS   0x11  /* PHY Specific Status Register */
 23.1548 +#define M88E1000_INT_ENABLE        0x12  /* Interrupt Enable Register */
 23.1549 +#define M88E1000_INT_STATUS        0x13  /* Interrupt Status Register */
 23.1550 +#define M88E1000_EXT_PHY_SPEC_CTRL 0x14  /* Extended PHY Specific Control */
 23.1551 +#define M88E1000_RX_ERR_CNTR       0x15  /* Receive Error Counter */
 23.1552 +
 23.1553 +#define MAX_PHY_REG_ADDRESS 0x1F        /* 5 bit address bus (0-0x1F) */
 23.1554 +
 23.1555 +/* PHY Control Register */
 23.1556 +#define MII_CR_SPEED_SELECT_MSB 0x0040  /* bits 6,13: 10=1000, 01=100, 00=10 */
 23.1557 +#define MII_CR_COLL_TEST_ENABLE 0x0080  /* Collision test enable */
 23.1558 +#define MII_CR_FULL_DUPLEX      0x0100  /* FDX =1, half duplex =0 */
 23.1559 +#define MII_CR_RESTART_AUTO_NEG 0x0200  /* Restart auto negotiation */
 23.1560 +#define MII_CR_ISOLATE          0x0400  /* Isolate PHY from MII */
 23.1561 +#define MII_CR_POWER_DOWN       0x0800  /* Power down */
 23.1562 +#define MII_CR_AUTO_NEG_EN      0x1000  /* Auto Neg Enable */
 23.1563 +#define MII_CR_SPEED_SELECT_LSB 0x2000  /* bits 6,13: 10=1000, 01=100, 00=10 */
 23.1564 +#define MII_CR_LOOPBACK         0x4000  /* 0 = normal, 1 = loopback */
 23.1565 +#define MII_CR_RESET            0x8000  /* 0 = normal, 1 = PHY reset */
 23.1566 +
 23.1567 +/* PHY Status Register */
 23.1568 +#define MII_SR_EXTENDED_CAPS     0x0001 /* Extended register capabilities */
 23.1569 +#define MII_SR_JABBER_DETECT     0x0002 /* Jabber Detected */
 23.1570 +#define MII_SR_LINK_STATUS       0x0004 /* Link Status 1 = link */
 23.1571 +#define MII_SR_AUTONEG_CAPS      0x0008 /* Auto Neg Capable */
 23.1572 +#define MII_SR_REMOTE_FAULT      0x0010 /* Remote Fault Detect */
 23.1573 +#define MII_SR_AUTONEG_COMPLETE  0x0020 /* Auto Neg Complete */
 23.1574 +#define MII_SR_PREAMBLE_SUPPRESS 0x0040 /* Preamble may be suppressed */
 23.1575 +#define MII_SR_EXTENDED_STATUS   0x0100 /* Ext. status info in Reg 0x0F */
 23.1576 +#define MII_SR_100T2_HD_CAPS     0x0200 /* 100T2 Half Duplex Capable */
 23.1577 +#define MII_SR_100T2_FD_CAPS     0x0400 /* 100T2 Full Duplex Capable */
 23.1578 +#define MII_SR_10T_HD_CAPS       0x0800 /* 10T   Half Duplex Capable */
 23.1579 +#define MII_SR_10T_FD_CAPS       0x1000 /* 10T   Full Duplex Capable */
 23.1580 +#define MII_SR_100X_HD_CAPS      0x2000 /* 100X  Half Duplex Capable */
 23.1581 +#define MII_SR_100X_FD_CAPS      0x4000 /* 100X  Full Duplex Capable */
 23.1582 +#define MII_SR_100T4_CAPS        0x8000 /* 100T4 Capable */
 23.1583 +
 23.1584 +/* Autoneg Advertisement Register */
 23.1585 +#define NWAY_AR_SELECTOR_FIELD 0x0001   /* indicates IEEE 802.3 CSMA/CD */
 23.1586 +#define NWAY_AR_10T_HD_CAPS    0x0020   /* 10T   Half Duplex Capable */
 23.1587 +#define NWAY_AR_10T_FD_CAPS    0x0040   /* 10T   Full Duplex Capable */
 23.1588 +#define NWAY_AR_100TX_HD_CAPS  0x0080   /* 100TX Half Duplex Capable */
 23.1589 +#define NWAY_AR_100TX_FD_CAPS  0x0100   /* 100TX Full Duplex Capable */
 23.1590 +#define NWAY_AR_100T4_CAPS     0x0200   /* 100T4 Capable */
 23.1591 +#define NWAY_AR_PAUSE          0x0400   /* Pause operation desired */
 23.1592 +#define NWAY_AR_ASM_DIR        0x0800   /* Asymmetric Pause Direction bit */
 23.1593 +#define NWAY_AR_REMOTE_FAULT   0x2000   /* Remote Fault detected */
 23.1594 +#define NWAY_AR_NEXT_PAGE      0x8000   /* Next Page ability supported */
 23.1595 +
 23.1596 +/* Link Partner Ability Register (Base Page) */
 23.1597 +#define NWAY_LPAR_SELECTOR_FIELD 0x0000 /* LP protocol selector field */
 23.1598 +#define NWAY_LPAR_10T_HD_CAPS    0x0020 /* LP is 10T   Half Duplex Capable */
 23.1599 +#define NWAY_LPAR_10T_FD_CAPS    0x0040 /* LP is 10T   Full Duplex Capable */
 23.1600 +#define NWAY_LPAR_100TX_HD_CAPS  0x0080 /* LP is 100TX Half Duplex Capable */
 23.1601 +#define NWAY_LPAR_100TX_FD_CAPS  0x0100 /* LP is 100TX Full Duplex Capable */
 23.1602 +#define NWAY_LPAR_100T4_CAPS     0x0200 /* LP is 100T4 Capable */
 23.1603 +#define NWAY_LPAR_PAUSE          0x0400 /* LP Pause operation desired */
 23.1604 +#define NWAY_LPAR_ASM_DIR        0x0800 /* LP Asymmetric Pause Direction bit */
 23.1605 +#define NWAY_LPAR_REMOTE_FAULT   0x2000 /* LP has detected Remote Fault */
 23.1606 +#define NWAY_LPAR_ACKNOWLEDGE    0x4000 /* LP has rx'd link code word */
 23.1607 +#define NWAY_LPAR_NEXT_PAGE      0x8000 /* Next Page ability supported */
 23.1608 +
 23.1609 +/* Autoneg Expansion Register */
 23.1610 +#define NWAY_ER_LP_NWAY_CAPS      0x0001 /* LP has Auto Neg Capability */
 23.1611 +#define NWAY_ER_PAGE_RXD          0x0002 /* LP is 10T   Half Duplex Capable */
 23.1612 +#define NWAY_ER_NEXT_PAGE_CAPS    0x0004 /* LP is 10T   Full Duplex Capable */
 23.1613 +#define NWAY_ER_LP_NEXT_PAGE_CAPS 0x0008 /* LP is 100TX Half Duplex Capable */
 23.1614 +#define NWAY_ER_PAR_DETECT_FAULT  0x0100 /* LP is 100TX Full Duplex Capable */
 23.1615 +
 23.1616 +/* Next Page TX Register */
 23.1617 +#define NPTX_MSG_CODE_FIELD 0x0001 /* NP msg code or unformatted data */
 23.1618 +#define NPTX_TOGGLE         0x0800 /* Toggles between exchanges
 23.1619 +                                    * of different NP
 23.1620 +                                    */
 23.1621 +#define NPTX_ACKNOWLDGE2    0x1000 /* 1 = will comply with msg
 23.1622 +                                    * 0 = cannot comply with msg
 23.1623 +                                    */
 23.1624 +#define NPTX_MSG_PAGE       0x2000 /* formatted(1)/unformatted(0) pg */
 23.1625 +#define NPTX_NEXT_PAGE      0x8000 /* 1 = addition NP will follow 
 23.1626 +                                    * 0 = sending last NP
 23.1627 +                                    */
 23.1628 +
 23.1629 +/* Link Partner Next Page Register */
 23.1630 +#define LP_RNPR_MSG_CODE_FIELD 0x0001 /* NP msg code or unformatted data */
 23.1631 +#define LP_RNPR_TOGGLE         0x0800 /* Toggles between exchanges
 23.1632 +                                       * of different NP
 23.1633 +                                       */
 23.1634 +#define LP_RNPR_ACKNOWLDGE2    0x1000 /* 1 = will comply with msg 
 23.1635 +                                       * 0 = cannot comply with msg
 23.1636 +                                       */
 23.1637 +#define LP_RNPR_MSG_PAGE       0x2000  /* formatted(1)/unformatted(0) pg */
 23.1638 +#define LP_RNPR_ACKNOWLDGE     0x4000  /* 1 = ACK / 0 = NO ACK */
 23.1639 +#define LP_RNPR_NEXT_PAGE      0x8000  /* 1 = addition NP will follow
 23.1640 +                                        * 0 = sending last NP 
 23.1641 +                                        */
 23.1642 +
 23.1643 +/* 1000BASE-T Control Register */
 23.1644 +#define CR_1000T_ASYM_PAUSE      0x0080 /* Advertise asymmetric pause bit */
 23.1645 +#define CR_1000T_HD_CAPS         0x0100 /* Advertise 1000T HD capability */
 23.1646 +#define CR_1000T_FD_CAPS         0x0200 /* Advertise 1000T FD capability  */
 23.1647 +#define CR_1000T_REPEATER_DTE    0x0400 /* 1=Repeater/switch device port */
 23.1648 +                                        /* 0=DTE device */
 23.1649 +#define CR_1000T_MS_VALUE        0x0800 /* 1=Configure PHY as Master */
 23.1650 +                                        /* 0=Configure PHY as Slave */
 23.1651 +#define CR_1000T_MS_ENABLE       0x1000 /* 1=Master/Slave manual config value */
 23.1652 +                                        /* 0=Automatic Master/Slave config */
 23.1653 +#define CR_1000T_TEST_MODE_NORMAL 0x0000 /* Normal Operation */
 23.1654 +#define CR_1000T_TEST_MODE_1     0x2000 /* Transmit Waveform test */
 23.1655 +#define CR_1000T_TEST_MODE_2     0x4000 /* Master Transmit Jitter test */
 23.1656 +#define CR_1000T_TEST_MODE_3     0x6000 /* Slave Transmit Jitter test */
 23.1657 +#define CR_1000T_TEST_MODE_4     0x8000 /* Transmitter Distortion test */
 23.1658 +
 23.1659 +/* 1000BASE-T Status Register */
 23.1660 +#define SR_1000T_IDLE_ERROR_CNT   0x00FF /* Num idle errors since last read */
 23.1661 +#define SR_1000T_ASYM_PAUSE_DIR   0x0100 /* LP asymmetric pause direction bit */
 23.1662 +#define SR_1000T_LP_HD_CAPS       0x0400 /* LP is 1000T HD capable */
 23.1663 +#define SR_1000T_LP_FD_CAPS       0x0800 /* LP is 1000T FD capable */
 23.1664 +#define SR_1000T_REMOTE_RX_STATUS 0x1000 /* Remote receiver OK */
 23.1665 +#define SR_1000T_LOCAL_RX_STATUS  0x2000 /* Local receiver OK */
 23.1666 +#define SR_1000T_MS_CONFIG_RES    0x4000 /* 1=Local TX is Master, 0=Slave */
 23.1667 +#define SR_1000T_MS_CONFIG_FAULT  0x8000 /* Master/Slave config fault */
 23.1668 +#define SR_1000T_REMOTE_RX_STATUS_SHIFT 12
 23.1669 +#define SR_1000T_LOCAL_RX_STATUS_SHIFT  13
 23.1670 +
 23.1671 +/* Extended Status Register */
 23.1672 +#define IEEE_ESR_1000T_HD_CAPS 0x1000 /* 1000T HD capable */
 23.1673 +#define IEEE_ESR_1000T_FD_CAPS 0x2000 /* 1000T FD capable */
 23.1674 +#define IEEE_ESR_1000X_HD_CAPS 0x4000 /* 1000X HD capable */
 23.1675 +#define IEEE_ESR_1000X_FD_CAPS 0x8000 /* 1000X FD capable */
 23.1676 +
 23.1677 +#define PHY_TX_POLARITY_MASK   0x0100 /* register 10h bit 8 (polarity bit) */
 23.1678 +#define PHY_TX_NORMAL_POLARITY 0      /* register 10h bit 8 (normal polarity) */
 23.1679 +
 23.1680 +#define AUTO_POLARITY_DISABLE  0x0010 /* register 11h bit 4 */
 23.1681 +                                      /* (0=enable, 1=disable) */
 23.1682 +
 23.1683 +/* M88E1000 PHY Specific Control Register */
 23.1684 +#define M88E1000_PSCR_JABBER_DISABLE    0x0001 /* 1=Jabber Function disabled */
 23.1685 +#define M88E1000_PSCR_POLARITY_REVERSAL 0x0002 /* 1=Polarity Reversal enabled */
 23.1686 +#define M88E1000_PSCR_SQE_TEST          0x0004 /* 1=SQE Test enabled */
 23.1687 +#define M88E1000_PSCR_CLK125_DISABLE    0x0010 /* 1=CLK125 low, 
 23.1688 +                                                * 0=CLK125 toggling
 23.1689 +                                                */
 23.1690 +#define M88E1000_PSCR_MDI_MANUAL_MODE  0x0000  /* MDI Crossover Mode bits 6:5 */
 23.1691 +                                               /* Manual MDI configuration */
 23.1692 +#define M88E1000_PSCR_MDIX_MANUAL_MODE 0x0020  /* Manual MDIX configuration */
 23.1693 +#define M88E1000_PSCR_AUTO_X_1000T     0x0040  /* 1000BASE-T: Auto crossover,
 23.1694 +                                                *  100BASE-TX/10BASE-T: 
 23.1695 +                                                *  MDI Mode
 23.1696 +                                                */
 23.1697 +#define M88E1000_PSCR_AUTO_X_MODE      0x0060  /* Auto crossover enabled 
 23.1698 +                                                * all speeds. 
 23.1699 +                                                */
 23.1700 +#define M88E1000_PSCR_10BT_EXT_DIST_ENABLE 0x0080 
 23.1701 +                                        /* 1=Enable Extended 10BASE-T distance
 23.1702 +                                         * (Lower 10BASE-T RX Threshold)
 23.1703 +                                         * 0=Normal 10BASE-T RX Threshold */
 23.1704 +#define M88E1000_PSCR_MII_5BIT_ENABLE      0x0100
 23.1705 +                                        /* 1=5-Bit interface in 100BASE-TX
 23.1706 +                                         * 0=MII interface in 100BASE-TX */
 23.1707 +#define M88E1000_PSCR_SCRAMBLER_DISABLE    0x0200 /* 1=Scrambler disable */
 23.1708 +#define M88E1000_PSCR_FORCE_LINK_GOOD      0x0400 /* 1=Force link good */
 23.1709 +#define M88E1000_PSCR_ASSERT_CRS_ON_TX     0x0800 /* 1=Assert CRS on Transmit */
 23.1710 +
 23.1711 +#define M88E1000_PSCR_POLARITY_REVERSAL_SHIFT    1
 23.1712 +#define M88E1000_PSCR_AUTO_X_MODE_SHIFT          5
 23.1713 +#define M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT 7
 23.1714 +
 23.1715 +/* M88E1000 PHY Specific Status Register */
 23.1716 +#define M88E1000_PSSR_JABBER             0x0001 /* 1=Jabber */
 23.1717 +#define M88E1000_PSSR_REV_POLARITY       0x0002 /* 1=Polarity reversed */
 23.1718 +#define M88E1000_PSSR_MDIX               0x0040 /* 1=MDIX; 0=MDI */
 23.1719 +#define M88E1000_PSSR_CABLE_LENGTH       0x0380 /* 0=<50M;1=50-80M;2=80-110M;
 23.1720 +                                            * 3=110-140M;4=>140M */
 23.1721 +#define M88E1000_PSSR_LINK               0x0400 /* 1=Link up, 0=Link down */
 23.1722 +#define M88E1000_PSSR_SPD_DPLX_RESOLVED  0x0800 /* 1=Speed & Duplex resolved */
 23.1723 +#define M88E1000_PSSR_PAGE_RCVD          0x1000 /* 1=Page received */
 23.1724 +#define M88E1000_PSSR_DPLX               0x2000 /* 1=Duplex 0=Half Duplex */
 23.1725 +#define M88E1000_PSSR_SPEED              0xC000 /* Speed, bits 14:15 */
 23.1726 +#define M88E1000_PSSR_10MBS              0x0000 /* 00=10Mbs */
 23.1727 +#define M88E1000_PSSR_100MBS             0x4000 /* 01=100Mbs */
 23.1728 +#define M88E1000_PSSR_1000MBS            0x8000 /* 10=1000Mbs */
 23.1729 +
 23.1730 +#define M88E1000_PSSR_REV_POLARITY_SHIFT 1
 23.1731 +#define M88E1000_PSSR_MDIX_SHIFT         6
 23.1732 +#define M88E1000_PSSR_CABLE_LENGTH_SHIFT 7
 23.1733 +
 23.1734 +/* M88E1000 Extended PHY Specific Control Register */
 23.1735 +#define M88E1000_EPSCR_FIBER_LOOPBACK 0x4000 /* 1=Fiber loopback */
 23.1736 +#define M88E1000_EPSCR_DOWN_NO_IDLE   0x8000 /* 1=Lost lock detect enabled.
 23.1737 +                                              * Will assert lost lock and bring
 23.1738 +                                              * link down if idle not seen
 23.1739 +                                              * within 1ms in 1000BASE-T 
 23.1740 +                                              */
 23.1741 +/* Number of times we will attempt to autonegotiate before downshifting if we
 23.1742 + * are the master */
 23.1743 +#define M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK 0x0C00
 23.1744 +#define M88E1000_EPSCR_MASTER_DOWNSHIFT_1X   0x0000    
 23.1745 +#define M88E1000_EPSCR_MASTER_DOWNSHIFT_2X   0x0400
 23.1746 +#define M88E1000_EPSCR_MASTER_DOWNSHIFT_3X   0x0800
 23.1747 +#define M88E1000_EPSCR_MASTER_DOWNSHIFT_4X   0x0C00
 23.1748 +/* Number of times we will attempt to autonegotiate before downshifting if we
 23.1749 + * are the slave */
 23.1750 +#define M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK  0x0300
 23.1751 +#define M88E1000_EPSCR_SLAVE_DOWNSHIFT_DIS   0x0000
 23.1752 +#define M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X    0x0100
 23.1753 +#define M88E1000_EPSCR_SLAVE_DOWNSHIFT_2X    0x0200
 23.1754 +#define M88E1000_EPSCR_SLAVE_DOWNSHIFT_3X    0x0300
 23.1755 +#define M88E1000_EPSCR_TX_CLK_2_5     0x0060 /* 2.5 MHz TX_CLK */
 23.1756 +#define M88E1000_EPSCR_TX_CLK_25      0x0070 /* 25  MHz TX_CLK */
 23.1757 +#define M88E1000_EPSCR_TX_CLK_0       0x0000 /* NO  TX_CLK */
 23.1758 +
 23.1759 +/* Bit definitions for valid PHY IDs. */
 23.1760 +#define M88E1000_E_PHY_ID  0x01410C50
 23.1761 +#define M88E1000_I_PHY_ID  0x01410C30
 23.1762 +#define M88E1011_I_PHY_ID  0x01410C20
 23.1763 +#define M88E1000_12_PHY_ID M88E1000_E_PHY_ID
 23.1764 +#define M88E1000_14_PHY_ID M88E1000_E_PHY_ID
 23.1765 +#define M88E1011_I_REV_4   0x04
 23.1766 +
 23.1767 +/* Miscellaneous PHY bit definitions. */
 23.1768 +#define PHY_PREAMBLE        0xFFFFFFFF
 23.1769 +#define PHY_SOF             0x01
 23.1770 +#define PHY_OP_READ         0x02
 23.1771 +#define PHY_OP_WRITE        0x01
 23.1772 +#define PHY_TURNAROUND      0x02
 23.1773 +#define PHY_PREAMBLE_SIZE   32
 23.1774 +#define MII_CR_SPEED_1000   0x0040
 23.1775 +#define MII_CR_SPEED_100    0x2000
 23.1776 +#define MII_CR_SPEED_10     0x0000
 23.1777 +#define E1000_PHY_ADDRESS   0x01
 23.1778 +#define PHY_AUTO_NEG_TIME   45  /* 4.5 Seconds */
 23.1779 +#define PHY_FORCE_TIME      20  /* 2.0 Seconds */
 23.1780 +#define PHY_REVISION_MASK   0xFFFFFFF0
 23.1781 +#define DEVICE_SPEED_MASK   0x00000300  /* Device Ctrl Reg Speed Mask */
 23.1782 +#define REG4_SPEED_MASK     0x01E0
 23.1783 +#define REG9_SPEED_MASK     0x0300
 23.1784 +#define ADVERTISE_10_HALF   0x0001
 23.1785 +#define ADVERTISE_10_FULL   0x0002
 23.1786 +#define ADVERTISE_100_HALF  0x0004
 23.1787 +#define ADVERTISE_100_FULL  0x0008
 23.1788 +#define ADVERTISE_1000_HALF 0x0010
 23.1789 +#define ADVERTISE_1000_FULL 0x0020
 23.1790 +#define AUTONEG_ADVERTISE_SPEED_DEFAULT 0x002F  /* Everything but 1000-Half */
 23.1791 +
 23.1792 +#endif /* _E1000_HW_H_ */
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/xen-2.4.16/drivers/net/e1000/e1000_main.c	Tue Feb 11 13:05:51 2003 +0000
    24.3 @@ -0,0 +1,2284 @@
    24.4 +/*******************************************************************************
    24.5 +
    24.6 +  
    24.7 +  Copyright(c) 1999 - 2002 Intel Corporation. All rights reserved.
    24.8 +  
    24.9 +  This program is free software; you can redistribute it and/or modify it 
   24.10 +  under the terms of the GNU General Public License as published by the Free 
   24.11 +  Software Foundation; either version 2 of the License, or (at your option) 
   24.12 +  any later version.
   24.13 +  
   24.14 +  This program is distributed in the hope that it will be useful, but WITHOUT 
   24.15 +  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
   24.16 +  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
   24.17 +  more details.
   24.18 +  
   24.19 +  You should have received a copy of the GNU General Public License along with
   24.20 +  this program; if not, write to the Free Software Foundation, Inc., 59 
   24.21 +  Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   24.22 +  
   24.23 +  The full GNU General Public License is included in this distribution in the
   24.24 +  file called LICENSE.
   24.25 +  
   24.26 +  Contact Information:
   24.27 +  Linux NICS <linux.nics@intel.com>
   24.28 +  Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
   24.29 +
   24.30 +*******************************************************************************/
   24.31 +
   24.32 +#include "e1000.h"
   24.33 +
   24.34 +/* Change Log
   24.35 + *
   24.36 + * 4.4.19       11/27/02
   24.37 + *   o Feature: Added user-settable knob for interrupt throttle rate (ITR).
   24.38 + *   o Cleanup: removed large static array allocations.
   24.39 + *   o Cleanup: C99 struct initializer format.
   24.40 + *   o Bug fix: restore VLAN settings when interface is brought up.
   24.41 + *   o Bug fix: return cleanly in probe if error in detecting MAC type.
   24.42 + *   o Bug fix: Wake up on magic packet by default only if enabled in eeprom.
   24.43 + *   o Bug fix: Validate MAC address in set_mac.
   24.44 + *   o Bug fix: Throw away zero-length Tx skbs.
   24.45 + *   o Bug fix: Make ethtool EEPROM acceses work on older versions of ethtool.
   24.46 + * 
   24.47 + * 4.4.12       10/15/02
   24.48 + *   o Clean up: use members of pci_device rather than direct calls to
   24.49 + *     pci_read_config_word.
   24.50 + *   o Bug fix: changed default flow control settings.
   24.51 + *   o Clean up: ethtool file now has an inclusive list for adapters in the
   24.52 + *     Wake-On-LAN capabilities instead of an exclusive list.
   24.53 + *   o Bug fix: miscellaneous WoL bug fixes.
   24.54 + *   o Added software interrupt for clearing rx ring
   24.55 + *   o Bug fix: easier to undo "forcing" of 1000/fd using ethtool.
   24.56 + *   o Now setting netdev->mem_end in e1000_probe.
   24.57 + *   o Clean up: Moved tx_timeout from interrupt context to process context
   24.58 + *     using schedule_task.
   24.59 + * 
   24.60 + * 4.3.15       8/9/02
   24.61 + */
   24.62 +
   24.63 +char e1000_driver_name[] = "e1000";
   24.64 +char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
   24.65 +char e1000_driver_version[] = "4.4.19-k2";
   24.66 +char e1000_copyright[] = "Copyright (c) 1999-2002 Intel Corporation.";
   24.67 +
   24.68 +/* e1000_pci_tbl - PCI Device ID Table
   24.69 + *
   24.70 + * Private driver_data field (last one) stores an index into e1000_strings
   24.71 + * Wildcard entries (PCI_ANY_ID) should come last
   24.72 + * Last entry must be all 0s
   24.73 + *
   24.74 + * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
   24.75 + *   Class, Class Mask, String Index }
   24.76 + */
   24.77 +static struct pci_device_id e1000_pci_tbl[] __devinitdata = {
   24.78 +	/* Intel(R) PRO/1000 Network Connection */
   24.79 +	{0x8086, 0x1000, 0x8086, 0x1000, 0, 0, 0},
   24.80 +	{0x8086, 0x1001, 0x8086, 0x1003, 0, 0, 0},
   24.81 +	{0x8086, 0x1004, 0x8086, 0x1004, 0, 0, 0},
   24.82 +	{0x8086, 0x1008, 0x8086, 0x1107, 0, 0, 0},
   24.83 +	{0x8086, 0x1009, 0x8086, 0x1109, 0, 0, 0},
   24.84 +	{0x8086, 0x100C, 0x8086, 0x1112, 0, 0, 0},
   24.85 +	{0x8086, 0x100E, 0x8086, 0x001E, 0, 0, 0},
   24.86 +	/* Compaq Gigabit Ethernet Server Adapter */
   24.87 +	{0x8086, 0x1000, 0x0E11, PCI_ANY_ID, 0, 0, 1},
   24.88 +	{0x8086, 0x1001, 0x0E11, PCI_ANY_ID, 0, 0, 1},
   24.89 +	{0x8086, 0x1004, 0x0E11, PCI_ANY_ID, 0, 0, 1},
   24.90 +	/* IBM Mobile, Desktop & Server Adapters */
   24.91 +	{0x8086, 0x1000, 0x1014, PCI_ANY_ID, 0, 0, 2},
   24.92 +	{0x8086, 0x1001, 0x1014, PCI_ANY_ID, 0, 0, 2},
   24.93 +	{0x8086, 0x1004, 0x1014, PCI_ANY_ID, 0, 0, 2},
   24.94 +	/* Generic */
   24.95 +	{0x8086, 0x1000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
   24.96 +	{0x8086, 0x1001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
   24.97 +	{0x8086, 0x1004, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
   24.98 +	{0x8086, 0x1008, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
   24.99 +	{0x8086, 0x1009, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  24.100 +	{0x8086, 0x100C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  24.101 +	{0x8086, 0x100D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  24.102 +	{0x8086, 0x100E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  24.103 +	{0x8086, 0x100F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  24.104 +	{0x8086, 0x1011, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  24.105 +	{0x8086, 0x1010, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  24.106 +	{0x8086, 0x1012, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  24.107 +	{0x8086, 0x1016, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  24.108 +	{0x8086, 0x1017, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  24.109 +	{0x8086, 0x101E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  24.110 +	/* required last entry */
  24.111 +	{0,}
  24.112 +};
  24.113 +
  24.114 +MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
  24.115 +
  24.116 +static char *e1000_strings[] = {
  24.117 +	"Intel(R) PRO/1000 Network Connection",
  24.118 +	"Compaq Gigabit Ethernet Server Adapter",
  24.119 +	"IBM Mobile, Desktop & Server Adapters"
  24.120 +};
  24.121 +
  24.122 +/* Local Function Prototypes */
  24.123 +
  24.124 +int e1000_up(struct e1000_adapter *adapter);
  24.125 +void e1000_down(struct e1000_adapter *adapter);
  24.126 +void e1000_reset(struct e1000_adapter *adapter);
  24.127 +
  24.128 +static int e1000_init_module(void);
  24.129 +static void e1000_exit_module(void);
  24.130 +static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
  24.131 +static void e1000_remove(struct pci_dev *pdev);
  24.132 +static int e1000_sw_init(struct e1000_adapter *adapter);
  24.133 +static int e1000_open(struct net_device *netdev);
  24.134 +static int e1000_close(struct net_device *netdev);
  24.135 +static int e1000_setup_tx_resources(struct e1000_adapter *adapter);
  24.136 +static int e1000_setup_rx_resources(struct e1000_adapter *adapter);
  24.137 +static void e1000_configure_tx(struct e1000_adapter *adapter);
  24.138 +static void e1000_configure_rx(struct e1000_adapter *adapter);
  24.139 +static void e1000_setup_rctl(struct e1000_adapter *adapter);
  24.140 +static void e1000_clean_tx_ring(struct e1000_adapter *adapter);
  24.141 +static void e1000_clean_rx_ring(struct e1000_adapter *adapter);
  24.142 +static void e1000_free_tx_resources(struct e1000_adapter *adapter);
  24.143 +static void e1000_free_rx_resources(struct e1000_adapter *adapter);
  24.144 +static void e1000_set_multi(struct net_device *netdev);
  24.145 +static void e1000_update_phy_info(unsigned long data);
  24.146 +static void e1000_watchdog(unsigned long data);
  24.147 +static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
  24.148 +static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
  24.149 +static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
  24.150 +static int e1000_set_mac(struct net_device *netdev, void *p);
  24.151 +static void e1000_update_stats(struct e1000_adapter *adapter);
  24.152 +static inline void e1000_irq_disable(struct e1000_adapter *adapter);
  24.153 +static inline void e1000_irq_enable(struct e1000_adapter *adapter);
  24.154 +static void e1000_intr(int irq, void *data, struct pt_regs *regs);
  24.155 +static void e1000_clean_tx_irq(struct e1000_adapter *adapter);
  24.156 +static void e1000_clean_rx_irq(struct e1000_adapter *adapter);
  24.157 +static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter);
  24.158 +static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
  24.159 +static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
  24.160 +static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
  24.161 +static inline void e1000_rx_checksum(struct e1000_adapter *adapter,
  24.162 +                                     struct e1000_rx_desc *rx_desc,
  24.163 +                                     struct sk_buff *skb);
  24.164 +static void e1000_tx_timeout(struct net_device *dev);
  24.165 +static void e1000_tx_timeout_task(struct net_device *dev);
  24.166 +
  24.167 +static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
  24.168 +static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
  24.169 +static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
  24.170 +static void e1000_restore_vlan(struct e1000_adapter *adapter);
  24.171 +
  24.172 +static int e1000_notify_reboot(struct notifier_block *, unsigned long event, void *ptr);
  24.173 +static int e1000_suspend(struct pci_dev *pdev, uint32_t state);
  24.174 +#ifdef CONFIG_PM
  24.175 +static int e1000_resume(struct pci_dev *pdev);
  24.176 +#endif
  24.177 +
  24.178 +struct notifier_block e1000_notifier_reboot = {
  24.179 +	.notifier_call	= e1000_notify_reboot,
  24.180 +	.next		= NULL,
  24.181 +	.priority	= 0
  24.182 +};
  24.183 +
  24.184 +/* Exported from other modules */
  24.185 +
  24.186 +extern void e1000_check_options(struct e1000_adapter *adapter);
  24.187 +extern int e1000_ethtool_ioctl(struct net_device *netdev, struct ifreq *ifr);
  24.188 +
  24.189 +static struct pci_driver e1000_driver = {
  24.190 +	.name     = e1000_driver_name,
  24.191 +	.id_table = e1000_pci_tbl,
  24.192 +	.probe    = e1000_probe,
  24.193 +	.remove   = __devexit_p(e1000_remove),
  24.194 +	/* Power Managment Hooks */
  24.195 +#ifdef CONFIG_PM
  24.196 +	.suspend  = e1000_suspend,
  24.197 +	.resume   = e1000_resume
  24.198 +#endif
  24.199 +};
  24.200 +
  24.201 +MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  24.202 +MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
  24.203 +MODULE_LICENSE("GPL");
  24.204 +
  24.205 +/**
  24.206 + * e1000_init_module - Driver Registration Routine
  24.207 + *
  24.208 + * e1000_init_module is the first routine called when the driver is
  24.209 + * loaded. All it does is register with the PCI subsystem.
  24.210 + **/
  24.211 +
  24.212 +static int __init
  24.213 +e1000_init_module(void)
  24.214 +{
  24.215 +	int ret;
  24.216 +
  24.217 +#if 0 /* Avoid disconcerting noise. */
  24.218 +	printk(KERN_INFO "%s - version %s\n",
  24.219 +	       e1000_driver_string, e1000_driver_version);
  24.220 +
  24.221 +	printk(KERN_INFO "%s\n", e1000_copyright);
  24.222 +#endif
  24.223 +
  24.224 +	ret = pci_module_init(&e1000_driver);
  24.225 +//	if(ret >= 0)
  24.226 +//		register_reboot_notifier(&e1000_notifier_reboot);
  24.227 +	return ret;
  24.228 +}
  24.229 +
  24.230 +module_init(e1000_init_module);
  24.231 +
  24.232 +/**
  24.233 + * e1000_exit_module - Driver Exit Cleanup Routine
  24.234 + *
  24.235 + * e1000_exit_module is called just before the driver is removed
  24.236 + * from memory.
  24.237 + **/
  24.238 +
  24.239 +static void __exit
  24.240 +e1000_exit_module(void)
  24.241 +{
  24.242 +//	unregister_reboot_notifier(&e1000_notifier_reboot);
  24.243 +	pci_unregister_driver(&e1000_driver);
  24.244 +}
  24.245 +
  24.246 +module_exit(e1000_exit_module);
  24.247 +
  24.248 +
  24.249 +int
  24.250 +e1000_up(struct e1000_adapter *adapter)
  24.251 +{
  24.252 +	struct net_device *netdev = adapter->netdev;
  24.253 +
  24.254 +	if(request_irq(netdev->irq, &e1000_intr, SA_SHIRQ | SA_SAMPLE_RANDOM,
  24.255 +	               netdev->name, netdev))
  24.256 +		return -1;
  24.257 +
  24.258 +	/* hardware has been reset, we need to reload some things */
  24.259 +
  24.260 +	e1000_set_multi(netdev);
  24.261 +	e1000_restore_vlan(adapter);
  24.262 +
  24.263 +	e1000_configure_tx(adapter);
  24.264 +	e1000_setup_rctl(adapter);
  24.265 +	e1000_configure_rx(adapter);
  24.266 +	e1000_alloc_rx_buffers(adapter);
  24.267 +
  24.268 +	mod_timer(&adapter->watchdog_timer, jiffies);
  24.269 +	e1000_irq_enable(adapter);
  24.270 +
  24.271 +	return 0;
  24.272 +}
  24.273 +
  24.274 +void
  24.275 +e1000_down(struct e1000_adapter *adapter)
  24.276 +{
  24.277 +	struct net_device *netdev = adapter->netdev;
  24.278 +
  24.279 +	e1000_irq_disable(adapter);
  24.280 +	free_irq(netdev->irq, netdev);
  24.281 +	del_timer_sync(&adapter->watchdog_timer);
  24.282 +	del_timer_sync(&adapter->phy_info_timer);
  24.283 +	adapter->link_speed = 0;
  24.284 +	adapter->link_duplex = 0;
  24.285 +	netif_carrier_off(netdev);
  24.286 +	netif_stop_queue(netdev);
  24.287 +
  24.288 +	e1000_reset(adapter);
  24.289 +	e1000_clean_tx_ring(adapter);
  24.290 +	e1000_clean_rx_ring(adapter);
  24.291 +}
  24.292 +
  24.293 +void
  24.294 +e1000_reset(struct e1000_adapter *adapter)
  24.295 +{
  24.296 +	/* Repartition Pba for greater than 9k mtu
  24.297 +	 * To take effect CTRL.RST is required.
  24.298 +	 */
  24.299 +
  24.300 +	if(adapter->rx_buffer_len > E1000_RXBUFFER_8192)
  24.301 +		E1000_WRITE_REG(&adapter->hw, PBA, E1000_JUMBO_PBA);
  24.302 +	else
  24.303 +		E1000_WRITE_REG(&adapter->hw, PBA, E1000_DEFAULT_PBA);
  24.304 +
  24.305 +	adapter->hw.fc = adapter->hw.original_fc;
  24.306 +	e1000_reset_hw(&adapter->hw);
  24.307 +printk("RESET_H/W\n");
  24.308 +	if(adapter->hw.mac_type >= e1000_82544)
  24.309 +		E1000_WRITE_REG(&adapter->hw, WUC, 0);
  24.310 +	e1000_init_hw(&adapter->hw);
  24.311 +printk("INIT H/W\n");
  24.312 +	e1000_reset_adaptive(&adapter->hw);
  24.313 +	e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
  24.314 +}
  24.315 +
  24.316 +/**
  24.317 + * e1000_probe - Device Initialization Routine
  24.318 + * @pdev: PCI device information struct
  24.319 + * @ent: entry in e1000_pci_tbl
  24.320 + *
  24.321 + * Returns 0 on success, negative on failure
  24.322 + *
  24.323 + * e1000_probe initializes an adapter identified by a pci_dev structure.
  24.324 + * The OS initialization, configuring of the adapter private structure,
  24.325 + * and a hardware reset occur.
  24.326 + **/
  24.327 +
  24.328 +static int __devinit
  24.329 +e1000_probe(struct pci_dev *pdev,
  24.330 +            const struct pci_device_id *ent)
  24.331 +{
  24.332 +	struct net_device *netdev;
  24.333 +	struct e1000_adapter *adapter;
  24.334 +	static int cards_found = 0;
  24.335 +	unsigned long mmio_start;
  24.336 +	int mmio_len;
  24.337 +	int pci_using_dac;
  24.338 +	int i;
  24.339 +	uint16_t eeprom_data;
  24.340 +
  24.341 +	if((i = pci_enable_device(pdev)))
  24.342 +		return i;
  24.343 +
  24.344 +	if(!(i = pci_set_dma_mask(pdev, PCI_DMA_64BIT))) {
  24.345 +		pci_using_dac = 1;
  24.346 +	} else {
  24.347 +		if((i = pci_set_dma_mask(pdev, PCI_DMA_32BIT))) {
  24.348 +			E1000_ERR("No usable DMA configuration, aborting\n");
  24.349 +			return i;
  24.350 +		}
  24.351 +		pci_using_dac = 0;
  24.352 +	}
  24.353 +
  24.354 +	if((i = pci_request_regions(pdev, e1000_driver_name)))
  24.355 +		return i;
  24.356 +
  24.357 +	pci_set_master(pdev);
  24.358 +
  24.359 +	netdev = alloc_etherdev(sizeof(struct e1000_adapter));
  24.360 +	if(!netdev)
  24.361 +		goto err_alloc_etherdev;
  24.362 +
  24.363 +	SET_MODULE_OWNER(netdev);
  24.364 +
  24.365 +	pci_set_drvdata(pdev, netdev);
  24.366 +	adapter = netdev->priv;
  24.367 +	adapter->netdev = netdev;
  24.368 +	adapter->pdev = pdev;
  24.369 +	adapter->hw.back = adapter;
  24.370 +
  24.371 +	mmio_start = pci_resource_start(pdev, BAR_0);
  24.372 +	mmio_len = pci_resource_len(pdev, BAR_0);
  24.373 +
  24.374 +	adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
  24.375 +	if(!adapter->hw.hw_addr)
  24.376 +		goto err_ioremap;
  24.377 +
  24.378 +	for(i = BAR_1; i <= BAR_5; i++) {
  24.379 +		if(pci_resource_len(pdev, i) == 0)
  24.380 +			continue;
  24.381 +		if(pci_resource_flags(pdev, i) & IORESOURCE_IO) {
  24.382 +			adapter->hw.io_base = pci_resource_start(pdev, i);
  24.383 +			break;
  24.384 +		}
  24.385 +	}
  24.386 +
  24.387 +	netdev->open = &e1000_open;
  24.388 +	netdev->stop = &e1000_close;
  24.389 +	netdev->hard_start_xmit = &e1000_xmit_frame;
  24.390 +	netdev->get_stats = &e1000_get_stats;
  24.391 +	netdev->set_multicast_list = &e1000_set_multi;
  24.392 +	netdev->set_mac_address = &e1000_set_mac;
  24.393 +	netdev->change_mtu = &e1000_change_mtu;
  24.394 +	netdev->do_ioctl = &e1000_ioctl;
  24.395 +	netdev->tx_timeout = &e1000_tx_timeout;
  24.396 +	netdev->watchdog_timeo = HZ;
  24.397 +	netdev->vlan_rx_register = e1000_vlan_rx_register;
  24.398 +	netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
  24.399 +	netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
  24.400 +
  24.401 +	netdev->irq = pdev->irq;
  24.402 +	netdev->mem_start = mmio_start;
  24.403 +	netdev->mem_end = mmio_start + mmio_len;
  24.404 +	netdev->base_addr = adapter->hw.io_base;
  24.405 +
  24.406 +	adapter->bd_number = cards_found;
  24.407 +	adapter->id_string = e1000_strings[ent->driver_data];
  24.408 +
  24.409 +	/* setup the private structure */
  24.410 +
  24.411 +	if(e1000_sw_init(adapter))
  24.412 +		goto err_sw_init;
  24.413 +
  24.414 +	if(adapter->hw.mac_type >= e1000_82543) {
  24.415 +		netdev->features = NETIF_F_SG |
  24.416 +			           NETIF_F_HW_CSUM |
  24.417 +		       	           NETIF_F_HW_VLAN_TX |
  24.418 +		                   NETIF_F_HW_VLAN_RX |
  24.419 +				   NETIF_F_HW_VLAN_FILTER;
  24.420 +	} else {
  24.421 +		netdev->features = NETIF_F_SG;
  24.422 +	}
  24.423 +
  24.424 +	if(pci_using_dac)
  24.425 +		netdev->features |= NETIF_F_HIGHDMA;
  24.426 +
  24.427 +	/* make sure the EEPROM is good */
  24.428 +
  24.429 +	if(e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
  24.430 +		printk(KERN_ERR "The EEPROM Checksum Is Not Valid\n");
  24.431 +		goto err_eeprom;
  24.432 +	}
  24.433 +
  24.434 +	/* copy the MAC address out of the EEPROM */
  24.435 +
  24.436 +	e1000_read_mac_addr(&adapter->hw);
  24.437 +	memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
  24.438 +
  24.439 +	if(!is_valid_ether_addr(netdev->dev_addr))
  24.440 +		goto err_eeprom;
  24.441 +
  24.442 +	e1000_read_part_num(&adapter->hw, &(adapter->part_num));
  24.443 +
  24.444 +	e1000_get_bus_info(&adapter->hw);
  24.445 +
  24.446 +	if((adapter->hw.mac_type == e1000_82544) &&
  24.447 +	   (adapter->hw.bus_type == e1000_bus_type_pcix))
  24.448 +
  24.449 +		adapter->max_data_per_txd = 4096;
  24.450 +	else
  24.451 +		adapter->max_data_per_txd = MAX_JUMBO_FRAME_SIZE;
  24.452 +
  24.453 +
  24.454 +	init_timer(&adapter->watchdog_timer);
  24.455 +	adapter->watchdog_timer.function = &e1000_watchdog;
  24.456 +	adapter->watchdog_timer.data = (unsigned long) adapter;
  24.457 +
  24.458 +	init_timer(&adapter->phy_info_timer);
  24.459 +	adapter->phy_info_timer.function = &e1000_update_phy_info;
  24.460 +	adapter->phy_info_timer.data = (unsigned long) adapter;
  24.461 +
  24.462 +	INIT_TQUEUE(&adapter->tx_timeout_task,
  24.463 +		(void (*)(void *))e1000_tx_timeout_task, netdev);
  24.464 +
  24.465 +	register_netdev(netdev);
  24.466 +	memcpy(adapter->ifname, netdev->name, IFNAMSIZ);
  24.467 +	adapter->ifname[IFNAMSIZ-1] = 0;
  24.468 +
  24.469 +	/* we're going to reset, so assume we have no link for now */
  24.470 +
  24.471 +	netif_carrier_off(netdev);
  24.472 +	netif_stop_queue(netdev);
  24.473 +
  24.474 +	printk(KERN_INFO "%s: %s\n", netdev->name, adapter->id_string);
  24.475 +	e1000_check_options(adapter);
  24.476 +printk("OPTIONS OVER\n");
  24.477 +	/* Initial Wake on LAN setting
  24.478 +	 * If APM wake is enabled in the EEPROM,
  24.479 +	 * enable the ACPI Magic Packet filter
  24.480 +	 */
  24.481 +
  24.482 +	e1000_read_eeprom(&adapter->hw, EEPROM_INIT_CONTROL2_REG, &eeprom_data);
  24.483 +printk("EPROM OVER\n");
  24.484 +	if((adapter->hw.mac_type >= e1000_82544) &&
  24.485 +	   (eeprom_data & E1000_EEPROM_APME))
  24.486 +		adapter->wol |= E1000_WUFC_MAG;
  24.487 +
  24.488 +	/* reset the hardware with the new settings */
  24.489 +
  24.490 +	e1000_reset(adapter);
  24.491 +printk("PROBE OVER\n");
  24.492 +	cards_found++;
  24.493 +	return 0;
  24.494 +
  24.495 +err_sw_init:
  24.496 +err_eeprom:
  24.497 +	iounmap(adapter->hw.hw_addr);
  24.498 +err_ioremap:
  24.499 +	pci_release_regions(pdev);
  24.500 +	kfree(netdev);
  24.501 +err_alloc_etherdev:
  24.502 +	return -ENOMEM;
  24.503 +}
  24.504 +
  24.505 +/**
  24.506 + * e1000_remove - Device Removal Routine
  24.507 + * @pdev: PCI device information struct
  24.508 + *
  24.509 + * e1000_remove is called by the PCI subsystem to alert the driver
  24.510 + * that it should release a PCI device.  The could be caused by a
  24.511 + * Hot-Plug event, or because the driver is going to be removed from
  24.512 + * memory.
  24.513 + **/
  24.514 +
  24.515 +static void __devexit
  24.516 +e1000_remove(struct pci_dev *pdev)
  24.517 +{
  24.518 +	struct net_device *netdev = pci_get_drvdata(pdev);
  24.519 +	struct e1000_adapter *adapter = netdev->priv;
  24.520 +	uint32_t manc;
  24.521 +
  24.522 +	if(adapter->hw.mac_type >= e1000_82540) {
  24.523 +		manc = E1000_READ_REG(&adapter->hw, MANC);
  24.524 +		if(manc & E1000_MANC_SMBUS_EN) {
  24.525 +			manc |= E1000_MANC_ARP_EN;
  24.526 +			E1000_WRITE_REG(&adapter->hw, MANC, manc);
  24.527 +		}
  24.528 +	}
  24.529 +
  24.530 +	unregister_netdev(netdev);
  24.531 +
  24.532 +	e1000_phy_hw_reset(&adapter->hw);
  24.533 +
  24.534 +	iounmap(adapter->hw.hw_addr);
  24.535 +	pci_release_regions(pdev);
  24.536 +
  24.537 +	kfree(netdev);
  24.538 +}
  24.539 +
  24.540 +/**
  24.541 + * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
  24.542 + * @adapter: board private structure to initialize
  24.543 + *
  24.544 + * e1000_sw_init initializes the Adapter private data structure.
  24.545 + * Fields are initialized based on PCI device information and
  24.546 + * OS network device settings (MTU size).
  24.547 + **/
  24.548 +
  24.549 +static int __devinit
  24.550 +e1000_sw_init(struct e1000_adapter *adapter)
  24.551 +{
  24.552 +	struct e1000_hw *hw = &adapter->hw;
  24.553 +	struct net_device *netdev = adapter->netdev;
  24.554 +	struct pci_dev *pdev = adapter->pdev;
  24.555 +
  24.556 +	/* PCI config space info */
  24.557 +
  24.558 +	hw->vendor_id = pdev->vendor;
  24.559 +	hw->device_id = pdev->device;
  24.560 +	hw->subsystem_vendor_id = pdev->subsystem_vendor;
  24.561 +	hw->subsystem_id = pdev->subsystem_device;
  24.562 +
  24.563 +	pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
  24.564 +
  24.565 +	pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
  24.566 +
  24.567 +	adapter->rx_buffer_len = E1000_RXBUFFER_2048;
  24.568 +	hw->max_frame_size = netdev->mtu +
  24.569 +	                         ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
  24.570 +	hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
  24.571 +
  24.572 +	/* identify the MAC */
  24.573 +
  24.574 +	if (e1000_set_mac_type(hw)) {
  24.575 +		E1000_ERR("Unknown MAC Type\n");
  24.576 +		return -1;
  24.577 +	}
  24.578 +
  24.579 +	/* flow control settings */
  24.580 +
  24.581 +	hw->fc_high_water = E1000_FC_HIGH_THRESH;
  24.582 +	hw->fc_low_water = E1000_FC_LOW_THRESH;
  24.583 +	hw->fc_pause_time = E1000_FC_PAUSE_TIME;
  24.584 +	hw->fc_send_xon = 1;
  24.585 +
  24.586 +	/* Media type - copper or fiber */
  24.587 +
  24.588 +	if(hw->mac_type >= e1000_82543) {
  24.589 +		uint32_t status = E1000_READ_REG(hw, STATUS);
  24.590 +
  24.591 +		if(status & E1000_STATUS_TBIMODE)
  24.592 +			hw->media_type = e1000_media_type_fiber;
  24.593 +		else
  24.594 +			hw->media_type = e1000_media_type_copper;
  24.595 +	} else {
  24.596 +		hw->media_type = e1000_media_type_fiber;
  24.597 +	}
  24.598 +
  24.599 +	if(hw->mac_type < e1000_82543)
  24.600 +		hw->report_tx_early = 0;
  24.601 +	else
  24.602 +		hw->report_tx_early = 1;
  24.603 +
  24.604 +	hw->wait_autoneg_complete = FALSE;
  24.605 +	hw->tbi_compatibility_en = TRUE;
  24.606 +	hw->adaptive_ifs = TRUE;
  24.607 +
  24.608 +	/* Copper options */
  24.609 +
  24.610 +	if(hw->media_type == e1000_media_type_copper) {
  24.611 +		hw->mdix = AUTO_ALL_MODES;
  24.612 +		hw->disable_polarity_correction = FALSE;
  24.613 +	}
  24.614 +
  24.615 +	atomic_set(&adapter->irq_sem, 1);
  24.616 +	spin_lock_init(&adapter->stats_lock);
  24.617 +
  24.618 +	return 0;
  24.619 +}
  24.620 +
  24.621 +/**
  24.622 + * e1000_open - Called when a network interface is made active
  24.623 + * @netdev: network interface device structure
  24.624 + *
  24.625 + * Returns 0 on success, negative value on failure
  24.626 + *
  24.627 + * The open entry point is called when a network interface is made
  24.628 + * active by the system (IFF_UP).  At this point all resources needed
  24.629 + * for transmit and receive operations are allocated, the interrupt
  24.630 + * handler is registered with the OS, the watchdog timer is started,
  24.631 + * and the stack is notified that the interface is ready.
  24.632 + **/
  24.633 +
  24.634 +static int
  24.635 +e1000_open(struct net_device *netdev)
  24.636 +{
  24.637 +	struct e1000_adapter *adapter = netdev->priv;
  24.638 +
  24.639 +	/* allocate transmit descriptors */
  24.640 +
  24.641 +	if(e1000_setup_tx_resources(adapter))
  24.642 +		goto err_setup_tx;
  24.643 +
  24.644 +	/* allocate receive descriptors */
  24.645 +
  24.646 +	if(e1000_setup_rx_resources(adapter))
  24.647 +		goto err_setup_rx;
  24.648 +
  24.649 +	if(e1000_up(adapter))
  24.650 +		goto err_up;
  24.651 +
  24.652 +	return 0;
  24.653 +
  24.654 +err_up:
  24.655 +	e1000_free_rx_resources(adapter);
  24.656 +err_setup_rx:
  24.657 +	e1000_free_tx_resources(adapter);
  24.658 +err_setup_tx:
  24.659 +	e1000_reset(adapter);
  24.660 +
  24.661 +	return -EBUSY;
  24.662 +}
  24.663 +
  24.664 +/**
  24.665 + * e1000_close - Disables a network interface
  24.666 + * @netdev: network interface device structure
  24.667 + *
  24.668 + * Returns 0, this is not allowed to fail
  24.669 + *
  24.670 + * The close entry point is called when an interface is de-activated
  24.671 + * by the OS.  The hardware is still under the drivers control, but
  24.672 + * needs to be disabled.  A global MAC reset is issued to stop the
  24.673 + * hardware, and all transmit and receive resources are freed.
  24.674 + **/
  24.675 +
  24.676 +static int
  24.677 +e1000_close(struct net_device *netdev)
  24.678 +{
  24.679 +	struct e1000_adapter *adapter = netdev->priv;
  24.680 +
  24.681 +	e1000_down(adapter);
  24.682 +
  24.683 +	e1000_free_tx_resources(adapter);
  24.684 +	e1000_free_rx_resources(adapter);
  24.685 +
  24.686 +	return 0;
  24.687 +}
  24.688 +
  24.689 +/**
  24.690 + * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
  24.691 + * @adapter: board private structure
  24.692 + *
  24.693 + * Return 0 on success, negative on failure
  24.694 + **/
  24.695 +
  24.696 +static int
  24.697 +e1000_setup_tx_resources(struct e1000_adapter *adapter)
  24.698 +{
  24.699 +	struct e1000_desc_ring *txdr = &adapter->tx_ring;
  24.700 +	struct pci_dev *pdev = adapter->pdev;
  24.701 +	int size;
  24.702 +
  24.703 +	size = sizeof(struct e1000_buffer) * txdr->count;
  24.704 +	txdr->buffer_info = kmalloc(size, GFP_KERNEL);
  24.705 +	if(!txdr->buffer_info) {
  24.706 +		return -ENOMEM;
  24.707 +	}
  24.708 +	memset(txdr->buffer_info, 0, size);
  24.709 +
  24.710 +	/* round up to nearest 4K */
  24.711 +
  24.712 +	txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
  24.713 +	E1000_ROUNDUP(txdr->size, 4096);
  24.714 +
  24.715 +	txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
  24.716 +	if(!txdr->desc) {
  24.717 +		kfree(txdr->buffer_info);
  24.718 +		return -ENOMEM;
  24.719 +	}
  24.720 +	memset(txdr->desc, 0, txdr->size);
  24.721 +
  24.722 +	txdr->next_to_use = 0;
  24.723 +	txdr->next_to_clean = 0;
  24.724 +
  24.725 +	return 0;
  24.726 +}
  24.727 +
  24.728 +/**
  24.729 + * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
  24.730 + * @adapter: board private structure
  24.731 + *
  24.732 + * Configure the Tx unit of the MAC after a reset.
  24.733 + **/
  24.734 +
  24.735 +static void
  24.736 +e1000_configure_tx(struct e1000_adapter *adapter)
  24.737 +{
  24.738 +	uint64_t tdba = adapter->tx_ring.dma;
  24.739 +	uint32_t tdlen = adapter->tx_ring.count * sizeof(struct e1000_tx_desc);
  24.740 +	uint32_t tctl, tipg;
  24.741 +
  24.742 +	E1000_WRITE_REG(&adapter->hw, TDBAL, (tdba & 0x00000000ffffffffULL));
  24.743 +	E1000_WRITE_REG(&adapter->hw, TDBAH, (tdba >> 32));
  24.744 +
  24.745 +	E1000_WRITE_REG(&adapter->hw, TDLEN, tdlen);
  24.746 +
  24.747 +	/* Setup the HW Tx Head and Tail descriptor pointers */
  24.748 +
  24.749 +	E1000_WRITE_REG(&adapter->hw, TDH, 0);
  24.750 +	E1000_WRITE_REG(&adapter->hw, TDT, 0);
  24.751 +
  24.752 +	/* Set the default values for the Tx Inter Packet Gap timer */
  24.753 +
  24.754 +	switch (adapter->hw.mac_type) {
  24.755 +	case e1000_82542_rev2_0:
  24.756 +	case e1000_82542_rev2_1:
  24.757 +		tipg = DEFAULT_82542_TIPG_IPGT;
  24.758 +		tipg |= DEFAULT_82542_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
  24.759 +		tipg |= DEFAULT_82542_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
  24.760 +		break;
  24.761 +	default:
  24.762 +		if(adapter->hw.media_type == e1000_media_type_fiber)
  24.763 +			tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
  24.764 +		else
  24.765 +			tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
  24.766 +		tipg |= DEFAULT_82543_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
  24.767 +		tipg |= DEFAULT_82543_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
  24.768 +	}
  24.769 +	E1000_WRITE_REG(&adapter->hw, TIPG, tipg);
  24.770 +
  24.771 +	/* Set the Tx Interrupt Delay register */
  24.772 +
  24.773 +	E1000_WRITE_REG(&adapter->hw, TIDV, adapter->tx_int_delay);
  24.774 +	if(adapter->hw.mac_type >= e1000_82540)
  24.775 +		E1000_WRITE_REG(&adapter->hw, TADV, adapter->tx_abs_int_delay);
  24.776 +
  24.777 +	/* Program the Transmit Control Register */
  24.778 +
  24.779 +	tctl = E1000_READ_REG(&adapter->hw, TCTL);
  24.780 +
  24.781 +	tctl &= ~E1000_TCTL_CT;
  24.782 +	tctl |= E1000_TCTL_EN | E1000_TCTL_PSP |
  24.783 +	       (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
  24.784 +
  24.785 +	E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
  24.786 +
  24.787 +	e1000_config_collision_dist(&adapter->hw);
  24.788 +
  24.789 +	/* Setup Transmit Descriptor Settings for this adapter */
  24.790 +	adapter->txd_cmd = E1000_TXD_CMD_IFCS | E1000_TXD_CMD_IDE;
  24.791 +
  24.792 +	if(adapter->hw.report_tx_early == 1)
  24.793 +		adapter->txd_cmd |= E1000_TXD_CMD_RS;
  24.794 +	else
  24.795 +		adapter->txd_cmd |= E1000_TXD_CMD_RPS;
  24.796 +}
  24.797 +
  24.798 +/**
  24.799 + * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
  24.800 + * @adapter: board private structure
  24.801 + *
  24.802 + * Returns 0 on success, negative on failure
  24.803 + **/
  24.804 +
  24.805 +static int
  24.806 +e1000_setup_rx_resources(struct e1000_adapter *adapter)
  24.807 +{
  24.808 +	struct e1000_desc_ring *rxdr = &adapter->rx_ring;
  24.809 +	struct pci_dev *pdev = adapter->pdev;
  24.810 +	int size;
  24.811 +
  24.812 +	size = sizeof(struct e1000_buffer) * rxdr->count;
  24.813 +	rxdr->buffer_info = kmalloc(size, GFP_KERNEL);
  24.814 +	if(!rxdr->buffer_info) {
  24.815 +		return -ENOMEM;
  24.816 +	}
  24.817 +	memset(rxdr->buffer_info, 0, size);
  24.818 +
  24.819 +	/* Round up to nearest 4K */
  24.820 +
  24.821 +	rxdr->size = rxdr->count * sizeof(struct e1000_rx_desc);
  24.822 +	E1000_ROUNDUP(rxdr->size, 4096);
  24.823 +
  24.824 +	rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
  24.825 +
  24.826 +	if(!rxdr->desc) {
  24.827 +		kfree(rxdr->buffer_info);
  24.828 +		return -ENOMEM;
  24.829 +	}
  24.830 +	memset(rxdr->desc, 0, rxdr->size);
  24.831 +
  24.832 +	rxdr->next_to_clean = 0;
  24.833 +	rxdr->next_to_use = 0;
  24.834 +
  24.835 +	return 0;
  24.836 +}
  24.837 +
  24.838 +/**
  24.839 + * e1000_setup_rctl - configure the receive control register
  24.840 + * @adapter: Board private structure
  24.841 + **/
  24.842 +
  24.843 +static void
  24.844 +e1000_setup_rctl(struct e1000_adapter *adapter)
  24.845 +{
  24.846 +	uint32_t rctl;
  24.847 +
  24.848 +	rctl = E1000_READ_REG(&adapter->hw, RCTL);
  24.849 +
  24.850 +	rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
  24.851 +
  24.852 +	rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
  24.853 +	        E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
  24.854 +	        (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
  24.855 +
  24.856 +	if(adapter->hw.tbi_compatibility_on == 1)
  24.857 +		rctl |= E1000_RCTL_SBP;
  24.858 +	else
  24.859 +		rctl &= ~E1000_RCTL_SBP;
  24.860 +
  24.861 +	rctl &= ~(E1000_RCTL_SZ_4096);
  24.862 +	switch (adapter->rx_buffer_len) {
  24.863 +	case E1000_RXBUFFER_2048:
  24.864 +	default:
  24.865 +		rctl |= E1000_RCTL_SZ_2048;
  24.866 +		rctl &= ~(E1000_RCTL_BSEX | E1000_RCTL_LPE);
  24.867 +		break;
  24.868 +	case E1000_RXBUFFER_4096:
  24.869 +		rctl |= E1000_RCTL_SZ_4096 | E1000_RCTL_BSEX | E1000_RCTL_LPE;
  24.870 +		break;
  24.871 +	case E1000_RXBUFFER_8192:
  24.872 +		rctl |= E1000_RCTL_SZ_8192 | E1000_RCTL_BSEX | E1000_RCTL_LPE;
  24.873 +		break;
  24.874 +	case E1000_RXBUFFER_16384:
  24.875 +		rctl |= E1000_RCTL_SZ_16384 | E1000_RCTL_BSEX | E1000_RCTL_LPE;
  24.876 +		break;
  24.877 +	}
  24.878 +
  24.879 +	E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
  24.880 +}
  24.881 +
  24.882 +/**
  24.883 + * e1000_configure_rx - Configure 8254x Receive Unit after Reset
  24.884 + * @adapter: board private structure
  24.885 + *
  24.886 + * Configure the Rx unit of the MAC after a reset.
  24.887 + **/
  24.888 +
  24.889 +static void
  24.890 +e1000_configure_rx(struct e1000_adapter *adapter)
  24.891 +{
  24.892 +	uint64_t rdba = adapter->rx_ring.dma;
  24.893 +	uint32_t rdlen = adapter->rx_ring.count * sizeof(struct e1000_rx_desc);
  24.894 +	uint32_t rctl;
  24.895 +	uint32_t rxcsum;
  24.896 +
  24.897 +	/* make sure receives are disabled while setting up the descriptors */
  24.898 +
  24.899 +	rctl = E1000_READ_REG(&adapter->hw, RCTL);
  24.900 +	E1000_WRITE_REG(&adapter->hw, RCTL, rctl & ~E1000_RCTL_EN);
  24.901 +
  24.902 +	/* set the Receive Delay Timer Register */
  24.903 +
  24.904 +	E1000_WRITE_REG(&adapter->hw, RDTR, adapter->rx_int_delay);
  24.905 +
  24.906 +	if(adapter->hw.mac_type >= e1000_82540) {
  24.907 +		E1000_WRITE_REG(&adapter->hw, RADV, adapter->rx_abs_int_delay);
  24.908 +
  24.909 +		/* Set the interrupt throttling rate.  Value is calculated
  24.910 +		 * as DEFAULT_ITR = 1/(MAX_INTS_PER_SEC * 256ns) */
  24.911 +#define MAX_INTS_PER_SEC        8000
  24.912 +#define DEFAULT_ITR             1000000000/(MAX_INTS_PER_SEC * 256)
  24.913 +		E1000_WRITE_REG(&adapter->hw, ITR, DEFAULT_ITR);
  24.914 +	}
  24.915 +
  24.916 +	/* Setup the Base and Length of the Rx Descriptor Ring */
  24.917 +
  24.918 +	E1000_WRITE_REG(&adapter->hw, RDBAL, (rdba & 0x00000000ffffffffULL));
  24.919 +	E1000_WRITE_REG(&adapter->hw, RDBAH, (rdba >> 32));
  24.920 +
  24.921 +	E1000_WRITE_REG(&adapter->hw, RDLEN, rdlen);
  24.922 +
  24.923 +	/* Setup the HW Rx Head and Tail Descriptor Pointers */
  24.924 +	E1000_WRITE_REG(&adapter->hw, RDH, 0);
  24.925 +	E1000_WRITE_REG(&adapter->hw, RDT, 0);
  24.926 +
  24.927 +	/* Enable 82543 Receive Checksum Offload for TCP and UDP */
  24.928 +	if((adapter->hw.mac_type >= e1000_82543) &&
  24.929 +	   (adapter->rx_csum == TRUE)) {
  24.930 +		rxcsum = E1000_READ_REG(&adapter->hw, RXCSUM);
  24.931 +		rxcsum |= E1000_RXCSUM_TUOFL;
  24.932 +		E1000_WRITE_REG(&adapter->hw, RXCSUM, rxcsum);
  24.933 +	}
  24.934 +
  24.935 +	/* Enable Receives */
  24.936 +
  24.937 +	E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
  24.938 +}
  24.939 +
  24.940 +/**
  24.941 + * e1000_free_tx_resources - Free Tx Resources
  24.942 + * @adapter: board private structure
  24.943 + *
  24.944 + * Free all transmit software resources
  24.945 + **/
  24.946 +
  24.947 +static void
  24.948 +e1000_free_tx_resources(struct e1000_adapter *adapter)
  24.949 +{
  24.950 +	struct pci_dev *pdev = adapter->pdev;
  24.951 +
  24.952 +	e1000_clean_tx_ring(adapter);
  24.953 +
  24.954 +	kfree(adapter->tx_ring.buffer_info);
  24.955 +	adapter->tx_ring.buffer_info = NULL;
  24.956 +
  24.957 +	pci_free_consistent(pdev, adapter->tx_ring.size,
  24.958 +	                    adapter->tx_ring.desc, adapter->tx_ring.dma);
  24.959 +
  24.960 +	adapter->tx_ring.desc = NULL;
  24.961 +}
  24.962 +
  24.963 +/**
  24.964 + * e1000_clean_tx_ring - Free Tx Buffers
  24.965 + * @adapter: board private structure
  24.966 + **/
  24.967 +
  24.968 +static void
  24.969 +e1000_clean_tx_ring(struct e1000_adapter *adapter)
  24.970 +{
  24.971 +	struct pci_dev *pdev = adapter->pdev;
  24.972 +	unsigned long size;
  24.973 +	int i;
  24.974 +
  24.975 +	/* Free all the Tx ring sk_buffs */
  24.976 +
  24.977 +	for(i = 0; i < adapter->tx_ring.count; i++) {
  24.978 +		if(adapter->tx_ring.buffer_info[i].skb) {
  24.979 +
  24.980 +			pci_unmap_page(pdev,
  24.981 +			               adapter->tx_ring.buffer_info[i].dma,
  24.982 +			               adapter->tx_ring.buffer_info[i].length,
  24.983 +			               PCI_DMA_TODEVICE);
  24.984 +
  24.985 +			dev_kfree_skb(adapter->tx_ring.buffer_info[i].skb);
  24.986 +
  24.987 +			adapter->tx_ring.buffer_info[i].skb = NULL;
  24.988 +		}
  24.989 +	}
  24.990 +
  24.991 +	size = sizeof(struct e1000_buffer) * adapter->tx_ring.count;
  24.992 +	memset(adapter->tx_ring.buffer_info, 0, size);
  24.993 +
  24.994 +	/* Zero out the descriptor ring */
  24.995 +
  24.996 +	memset(adapter->tx_ring.desc, 0, adapter->tx_ring.size);
  24.997 +
  24.998 +	adapter->tx_ring.next_to_use = 0;
  24.999 +	adapter->tx_ring.next_to_clean = 0;
 24.1000 +
 24.1001 +	E1000_WRITE_REG(&adapter->hw, TDH, 0);
 24.1002 +	E1000_WRITE_REG(&adapter->hw, TDT, 0);
 24.1003 +}
 24.1004 +
 24.1005 +/**
 24.1006 + * e1000_free_rx_resources - Free Rx Resources
 24.1007 + * @adapter: board private structure
 24.1008 + *
 24.1009 + * Free all receive software resources
 24.1010 + **/
 24.1011 +
 24.1012 +static void
 24.1013 +e1000_free_rx_resources(struct e1000_adapter *adapter)
 24.1014 +{
 24.1015 +	struct pci_dev *pdev = adapter->pdev;
 24.1016 +
 24.1017 +	e1000_clean_rx_ring(adapter);
 24.1018 +
 24.1019 +	kfree(adapter->rx_ring.buffer_info);
 24.1020 +	adapter->rx_ring.buffer_info = NULL;
 24.1021 +
 24.1022 +	pci_free_consistent(pdev, adapter->rx_ring.size,
 24.1023 +	                    adapter->rx_ring.desc, adapter->rx_ring.dma);
 24.1024 +
 24.1025 +	adapter->rx_ring.desc = NULL;
 24.1026 +}
 24.1027 +
 24.1028 +/**
 24.1029 + * e1000_clean_rx_ring - Free Rx Buffers
 24.1030 + * @adapter: board private structure
 24.1031 + **/
 24.1032 +
 24.1033 +static void
 24.1034 +e1000_clean_rx_ring(struct e1000_adapter *adapter)
 24.1035 +{
 24.1036 +	struct pci_dev *pdev = adapter->pdev;
 24.1037 +	unsigned long size;
 24.1038 +	int i;
 24.1039 +
 24.1040 +	/* Free all the Rx ring sk_buffs */
 24.1041 +
 24.1042 +	for(i = 0; i < adapter->rx_ring.count; i++) {
 24.1043 +		if(adapter->rx_ring.buffer_info[i].skb) {
 24.1044 +
 24.1045 +			pci_unmap_single(pdev,
 24.1046 +			                 adapter->rx_ring.buffer_info[i].dma,
 24.1047 +			                 adapter->rx_ring.buffer_info[i].length,
 24.1048 +			                 PCI_DMA_FROMDEVICE);
 24.1049 +
 24.1050 +			dev_kfree_skb(adapter->rx_ring.buffer_info[i].skb);
 24.1051 +
 24.1052 +			adapter->rx_ring.buffer_info[i].skb = NULL;
 24.1053 +		}
 24.1054 +	}
 24.1055 +
 24.1056 +	size = sizeof(struct e1000_buffer) * adapter->rx_ring.count;
 24.1057 +	memset(adapter->rx_ring.buffer_info, 0, size);
 24.1058 +
 24.1059 +	/* Zero out the descriptor ring */
 24.1060 +
 24.1061 +	memset(adapter->rx_ring.desc, 0, adapter->rx_ring.size);
 24.1062 +
 24.1063 +	adapter->rx_ring.next_to_clean = 0;
 24.1064 +	adapter->rx_ring.next_to_use = 0;
 24.1065 +
 24.1066 +	E1000_WRITE_REG(&adapter->hw, RDH, 0);
 24.1067 +	E1000_WRITE_REG(&adapter->hw, RDT, 0);
 24.1068 +}
 24.1069 +
 24.1070 +/* The 82542 2.0 (revision 2) needs to have the receive unit in reset
 24.1071 + * and memory write and invalidate disabled for certain operations
 24.1072 + */
 24.1073 +static void
 24.1074 +e1000_enter_82542_rst(struct e1000_adapter *adapter)
 24.1075 +{
 24.1076 +	struct net_device *netdev = adapter->netdev;
 24.1077 +	uint32_t rctl;
 24.1078 +
 24.1079 +	e1000_pci_clear_mwi(&adapter->hw);
 24.1080 +
 24.1081 +	rctl = E1000_READ_REG(&adapter->hw, RCTL);
 24.1082 +	rctl |= E1000_RCTL_RST;
 24.1083 +	E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
 24.1084 +	E1000_WRITE_FLUSH(&adapter->hw);
 24.1085 +	mdelay(5);
 24.1086 +
 24.1087 +	if(netif_running(netdev))
 24.1088 +		e1000_clean_rx_ring(adapter);
 24.1089 +}
 24.1090 +
 24.1091 +static void
 24.1092 +e1000_leave_82542_rst(struct e1000_adapter *adapter)
 24.1093 +{
 24.1094 +	struct net_device *netdev = adapter->netdev;
 24.1095 +	uint32_t rctl;
 24.1096 +
 24.1097 +	rctl = E1000_READ_REG(&adapter->hw, RCTL);
 24.1098 +	rctl &= ~E1000_RCTL_RST;
 24.1099 +	E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
 24.1100 +	E1000_WRITE_FLUSH(&adapter->hw);
 24.1101 +	mdelay(5);
 24.1102 +
 24.1103 +	if(adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
 24.1104 +		e1000_pci_set_mwi(&adapter->hw);
 24.1105 +
 24.1106 +	if(netif_running(netdev)) {
 24.1107 +		e1000_configure_rx(adapter);
 24.1108 +		e1000_alloc_rx_buffers(adapter);
 24.1109 +	}
 24.1110 +}
 24.1111 +
 24.1112 +/**
 24.1113 + * e1000_set_mac - Change the Ethernet Address of the NIC
 24.1114 + * @netdev: network interface device structure
 24.1115 + * @p: pointer to an address structure
 24.1116 + *
 24.1117 + * Returns 0 on success, negative on failure
 24.1118 + **/
 24.1119 +
 24.1120 +static int
 24.1121 +e1000_set_mac(struct net_device *netdev, void *p)
 24.1122 +{
 24.1123 +	struct e1000_adapter *adapter = netdev->priv;
 24.1124 +	struct sockaddr *addr = p;
 24.1125 +
 24.1126 +	if(!is_valid_ether_addr(addr->sa_data))
 24.1127 +		return -EADDRNOTAVAIL;
 24.1128 +
 24.1129 +	/* 82542 2.0 needs to be in reset to write receive address registers */
 24.1130 +
 24.1131 +	if(adapter->hw.mac_type == e1000_82542_rev2_0)
 24.1132 +		e1000_enter_82542_rst(adapter);
 24.1133 +
 24.1134 +	memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
 24.1135 +	memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
 24.1136 +
 24.1137 +	e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
 24.1138 +
 24.1139 +	if(adapter->hw.mac_type == e1000_82542_rev2_0)
 24.1140 +		e1000_leave_82542_rst(adapter);
 24.1141 +
 24.1142 +	return 0;
 24.1143 +}
 24.1144 +
 24.1145 +/**
 24.1146 + * e1000_set_multi - Multicast and Promiscuous mode set
 24.1147 + * @netdev: network interface device structure
 24.1148 + *
 24.1149 + * The set_multi entry point is called whenever the multicast address
 24.1150 + * list or the network interface flags are updated.  This routine is
 24.1151 + * resposible for configuring the hardware for proper multicast,
 24.1152 + * promiscuous mode, and all-multi behavior.
 24.1153 + **/
 24.1154 +
 24.1155 +static void
 24.1156 +e1000_set_multi(struct net_device *netdev)
 24.1157 +{
 24.1158 +	struct e1000_adapter *adapter = netdev->priv;
 24.1159 +	struct e1000_hw *hw = &adapter->hw;
 24.1160 +	struct dev_mc_list *mc_ptr;
 24.1161 +	uint32_t rctl;
 24.1162 +	uint32_t hash_value;
 24.1163 +	int i;
 24.1164 +
 24.1165 +	/* Check for Promiscuous and All Multicast modes */
 24.1166 +
 24.1167 +	rctl = E1000_READ_REG(hw, RCTL);
 24.1168 +
 24.1169 +	if(netdev->flags & IFF_PROMISC) {
 24.1170 +		rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
 24.1171 +	} else if(netdev->flags & IFF_ALLMULTI) {
 24.1172 +		rctl |= E1000_RCTL_MPE;
 24.1173 +		rctl &= ~E1000_RCTL_UPE;
 24.1174 +	} else {
 24.1175 +		rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
 24.1176 +	}
 24.1177 +
 24.1178 +	E1000_WRITE_REG(hw, RCTL, rctl);
 24.1179 +
 24.1180 +	/* 82542 2.0 needs to be in reset to write receive address registers */
 24.1181 +
 24.1182 +	if(hw->mac_type == e1000_82542_rev2_0)
 24.1183 +		e1000_enter_82542_rst(adapter);
 24.1184 +
 24.1185 +	/* load the first 15 multicast address into the exact filters 1-15
 24.1186 +	 * RAR 0 is used for the station MAC adddress
 24.1187 +	 * if there are not 15 addresses, go ahead and clear the filters
 24.1188 +	 */
 24.1189 +	mc_ptr = netdev->mc_list;
 24.1190 +
 24.1191 +	for(i = 1; i < E1000_RAR_ENTRIES; i++) {
 24.1192 +		if(mc_ptr) {
 24.1193 +			e1000_rar_set(hw, mc_ptr->dmi_addr, i);
 24.1194 +			mc_ptr = mc_ptr->next;
 24.1195 +		} else {
 24.1196 +			E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
 24.1197 +			E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
 24.1198 +		}
 24.1199 +	}
 24.1200 +
 24.1201 +	/* clear the old settings from the multicast hash table */
 24.1202 +
 24.1203 +	for(i = 0; i < E1000_NUM_MTA_REGISTERS; i++)
 24.1204 +		E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
 24.1205 +
 24.1206 +	/* load any remaining addresses into the hash table */
 24.1207 +
 24.1208 +	for(; mc_ptr; mc_ptr = mc_ptr->next) {
 24.1209 +		hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
 24.1210 +		e1000_mta_set(hw, hash_value);
 24.1211 +	}
 24.1212 +
 24.1213 +	if(hw->mac_type == e1000_82542_rev2_0)
 24.1214 +		e1000_leave_82542_rst(adapter);
 24.1215 +}
 24.1216 +
 24.1217 +
 24.1218 +/* need to wait a few seconds after link up to get diagnostic information from the phy */
 24.1219 +
 24.1220 +static void
 24.1221 +e1000_update_phy_info(unsigned long data)
 24.1222 +{
 24.1223 +	struct e1000_adapter *adapter = (struct e1000_adapter *) data;
 24.1224 +	e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
 24.1225 +}
 24.1226 +
 24.1227 +/**
 24.1228 + * e1000_watchdog - Timer Call-back
 24.1229 + * @data: pointer to netdev cast into an unsigned long
 24.1230 + **/
 24.1231 +
 24.1232 +static void
 24.1233 +e1000_watchdog(unsigned long data)
 24.1234 +{
 24.1235 +	struct e1000_adapter *adapter = (struct e1000_adapter *) data;
 24.1236 +	struct net_device *netdev = adapter->netdev;
 24.1237 +	struct e1000_desc_ring *txdr = &adapter->tx_ring;
 24.1238 +	int i;
 24.1239 +
 24.1240 +	e1000_check_for_link(&adapter->hw);
 24.1241 +
 24.1242 +	if(E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU) {
 24.1243 +		if(!netif_carrier_ok(netdev)) {
 24.1244 +			e1000_get_speed_and_duplex(&adapter->hw,
 24.1245 +			                           &adapter->link_speed,
 24.1246 +			                           &adapter->link_duplex);
 24.1247 +
 24.1248 +			printk(KERN_INFO
 24.1249 +			       "e1000: %s NIC Link is Up %d Mbps %s\n",
 24.1250 +			       netdev->name, adapter->link_speed,
 24.1251 +			       adapter->link_duplex == FULL_DUPLEX ?
 24.1252 +			       "Full Duplex" : "Half Duplex");
 24.1253 +
 24.1254 +			netif_carrier_on(netdev);
 24.1255 +			netif_wake_queue(netdev);
 24.1256 +			mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
 24.1257 +		}
 24.1258 +	} else {
 24.1259 +		if(netif_carrier_ok(netdev)) {
 24.1260 +			adapter->link_speed = 0;
 24.1261 +			adapter->link_duplex = 0;
 24.1262 +			printk(KERN_INFO
 24.1263 +			       "e1000: %s NIC Link is Down\n",
 24.1264 +			       netdev->name);
 24.1265 +			netif_carrier_off(netdev);
 24.1266 +			netif_stop_queue(netdev);
 24.1267 +			mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
 24.1268 +		}
 24.1269 +	}
 24.1270 +
 24.1271 +	e1000_update_stats(adapter);
 24.1272 +	e1000_update_adaptive(&adapter->hw);
 24.1273 +
 24.1274 +
 24.1275 +	/* Cause software interrupt to ensure rx ring is cleaned */
 24.1276 +	E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
 24.1277 +
 24.1278 +	/* Early detection of hung controller */
 24.1279 +	i = txdr->next_to_clean;
 24.1280 +	if(txdr->buffer_info[i].dma &&
 24.1281 +	   time_after(jiffies, txdr->buffer_info[i].time_stamp + HZ) &&
 24.1282 +	   !(E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_TXOFF))
 24.1283 +		netif_stop_queue(netdev);
 24.1284 +
 24.1285 +	/* Reset the timer */
 24.1286 +	mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
 24.1287 +}
 24.1288 +
 24.1289 +#define E1000_TX_FLAGS_CSUM		0x00000001
 24.1290 +#define E1000_TX_FLAGS_VLAN		0x00000002
 24.1291 +#define E1000_TX_FLAGS_VLAN_MASK	0xffff0000
 24.1292 +#define E1000_TX_FLAGS_VLAN_SHIFT	16
 24.1293 +
 24.1294 +static inline boolean_t
 24.1295 +e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
 24.1296 +{
 24.1297 +	struct e1000_context_desc *context_desc;
 24.1298 +	int i;
 24.1299 +	uint8_t css, cso;
 24.1300 +
 24.1301 +	if(skb->ip_summed == CHECKSUM_HW) {
 24.1302 +		css = skb->h.raw - skb->data;
 24.1303 +		cso = (skb->h.raw + skb->csum) - skb->data;
 24.1304 +
 24.1305 +		i = adapter->tx_ring.next_to_use;
 24.1306 +		context_desc = E1000_CONTEXT_DESC(adapter->tx_ring, i);
 24.1307 +
 24.1308 +		context_desc->upper_setup.tcp_fields.tucss = css;
 24.1309 +		context_desc->upper_setup.tcp_fields.tucso = cso;
 24.1310 +		context_desc->upper_setup.tcp_fields.tucse = 0;
 24.1311 +		context_desc->tcp_seg_setup.data = 0;
 24.1312 +		context_desc->cmd_and_length =
 24.1313 +			cpu_to_le32(adapter->txd_cmd | E1000_TXD_CMD_DEXT);
 24.1314 +
 24.1315 +		i = (i + 1) % adapter->tx_ring.count;
 24.1316 +		adapter->tx_ring.next_to_use = i;
 24.1317 +
 24.1318 +		return TRUE;
 24.1319 +	}
 24.1320 +
 24.1321 +	return FALSE;
 24.1322 +}
 24.1323 +
 24.1324 +static inline int
 24.1325 +e1000_tx_map(struct e1000_adapter *adapter, struct sk_buff *skb)
 24.1326 +{
 24.1327 +	struct e1000_desc_ring *tx_ring = &adapter->tx_ring;
 24.1328 +	int len, offset, size, count, i;
 24.1329 +
 24.1330 +	int f;
 24.1331 +	len = skb->len - skb->data_len;
 24.1332 +	i = (tx_ring->next_to_use + tx_ring->count - 1) % tx_ring->count;
 24.1333 +	count = 0;
 24.1334 +
 24.1335 +	offset = 0;
 24.1336 +
 24.1337 +	while(len) {
 24.1338 +		i = (i + 1) % tx_ring->count;
 24.1339 +		size = min(len, adapter->max_data_per_txd);
 24.1340 +		tx_ring->buffer_info[i].length = size;
 24.1341 +		tx_ring->buffer_info[i].dma =
 24.1342 +			pci_map_single(adapter->pdev,
 24.1343 +				skb->data + offset,
 24.1344 +				size,
 24.1345 +				PCI_DMA_TODEVICE);
 24.1346 +		tx_ring->buffer_info[i].time_stamp = jiffies;
 24.1347 +
 24.1348 +		len -= size;
 24.1349 +		offset += size;
 24.1350 +		count++;
 24.1351 +	}
 24.1352 +
 24.1353 +	for(f = 0; f < skb_shinfo(skb)->nr_frags; f++) {
 24.1354 +		struct skb_frag_struct *frag;
 24.1355 +
 24.1356 +		frag = &skb_shinfo(skb)->frags[f];
 24.1357 +		len = frag->size;
 24.1358 +		offset = 0;
 24.1359 +
 24.1360 +		while(len) {
 24.1361 +			i = (i + 1) % tx_ring->count;
 24.1362 +			size = min(len, adapter->max_data_per_txd);
 24.1363 +			tx_ring->buffer_info[i].length = size;
 24.1364 +			tx_ring->buffer_info[i].dma =
 24.1365 +				pci_map_page(adapter->pdev,
 24.1366 +					frag->page,
 24.1367 +					frag->page_offset + offset,
 24.1368 +					size,
 24.1369 +					PCI_DMA_TODEVICE);
 24.1370 +
 24.1371 +			len -= size;
 24.1372 +			offset += size;
 24.1373 +			count++;
 24.1374 +		}
 24.1375 +	}
 24.1376 +	tx_ring->buffer_info[i].skb = skb;
 24.1377 +
 24.1378 +	return count;
 24.1379 +}
 24.1380 +
 24.1381 +static inline void
 24.1382 +e1000_tx_queue(struct e1000_adapter *adapter, int count, int tx_flags)
 24.1383 +{
 24.1384 +	struct e1000_desc_ring *tx_ring = &adapter->tx_ring;
 24.1385 +	struct e1000_tx_desc *tx_desc = NULL;
 24.1386 +	uint32_t txd_upper, txd_lower;
 24.1387 +	int i;
 24.1388 +
 24.1389 +	txd_upper = 0;
 24.1390 +	txd_lower = adapter->txd_cmd;
 24.1391 +
 24.1392 +	if(tx_flags & E1000_TX_FLAGS_CSUM) {
 24.1393 +		txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
 24.1394 +		txd_upper |= E1000_TXD_POPTS_TXSM << 8;
 24.1395 +	}
 24.1396 +
 24.1397 +	if(tx_flags & E1000_TX_FLAGS_VLAN) {
 24.1398 +		txd_lower |= E1000_TXD_CMD_VLE;
 24.1399 +		txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
 24.1400 +	}
 24.1401 +
 24.1402 +	i = tx_ring->next_to_use;
 24.1403 +
 24.1404 +	while(count--) {
 24.1405 +		tx_desc = E1000_TX_DESC(*tx_ring, i);
 24.1406 +		tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
 24.1407 +		tx_desc->lower.data =
 24.1408 +			cpu_to_le32(txd_lower | tx_ring->buffer_info[i].length);
 24.1409 +		tx_desc->upper.data = cpu_to_le32(txd_upper);
 24.1410 +		i = (i + 1) % tx_ring->count;
 24.1411 +	}
 24.1412 +
 24.1413 +	tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP);
 24.1414 +
 24.1415 +	/* Force memory writes to complete before letting h/w
 24.1416 +	 * know there are new descriptors to fetch.  (Only
 24.1417 +	 * applicable for weak-ordered memory model archs,
 24.1418 +	 * such as IA-64). */
 24.1419 +	wmb();
 24.1420 +
 24.1421 +	tx_ring->next_to_use = i;
 24.1422 +	E1000_WRITE_REG(&adapter->hw, TDT, i);
 24.1423 +}
 24.1424 +
 24.1425 +#define TXD_USE_COUNT(S, X) (((S) / (X)) + (((S) % (X)) ? 1 : 0))
 24.1426 +
 24.1427 +static int
 24.1428 +e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
 24.1429 +{
 24.1430 +	struct e1000_adapter *adapter = netdev->priv;
 24.1431 +	int tx_flags = 0, count;
 24.1432 +	int f;
 24.1433 +
 24.1434 +	count = TXD_USE_COUNT(skb->len - skb->data_len,
 24.1435 +	                      adapter->max_data_per_txd);
 24.1436 +
 24.1437 +	if(count == 0) {
 24.1438 +		dev_kfree_skb_any(skb);
 24.1439 +		return 0;
 24.1440 +	}
 24.1441 +
 24.1442 +	for(f = 0; f < skb_shinfo(skb)->nr_frags; f++)
 24.1443 +		count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
 24.1444 +		                       adapter->max_data_per_txd);
 24.1445 +
 24.1446 +	if(skb->ip_summed == CHECKSUM_HW)
 24.1447 +		count++;
 24.1448 +
 24.1449 +	if(E1000_DESC_UNUSED(&adapter->tx_ring) < count) {
 24.1450 +		netif_stop_queue(netdev);
 24.1451 +		return 1;
 24.1452 +	}
 24.1453 +
 24.1454 +	if(e1000_tx_csum(adapter, skb))
 24.1455 +		tx_flags |= E1000_TX_FLAGS_CSUM;
 24.1456 +
 24.1457 +	if(adapter->vlgrp && vlan_tx_tag_present(skb)) {
 24.1458 +		tx_flags |= E1000_TX_FLAGS_VLAN;
 24.1459 +		tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
 24.1460 +	}
 24.1461 +
 24.1462 +	count = e1000_tx_map(adapter, skb);
 24.1463 +
 24.1464 +	e1000_tx_queue(adapter, count, tx_flags);
 24.1465 +
 24.1466 +	netdev->trans_start = jiffies;
 24.1467 +
 24.1468 +	return 0;
 24.1469 +}
 24.1470 +
 24.1471 +/**
 24.1472 + * e1000_tx_timeout - Respond to a Tx Hang
 24.1473 + * @netdev: network interface device structure
 24.1474 + **/
 24.1475 +
 24.1476 +static void
 24.1477 +e1000_tx_timeout(struct net_device *netdev)
 24.1478 +{
 24.1479 +    //struct e1000_adapter *adapter = netdev->priv;
 24.1480 +
 24.1481 +	/* Do the reset outside of interrupt context */
 24.1482 +	//schedule_task(&adapter->tx_timeout_task); XXXX Not in Xen!!!
 24.1483 +	e1000_tx_timeout_task(netdev);  // XXX HACK
 24.1484 +}
 24.1485 +
 24.1486 +static void
 24.1487 +e1000_tx_timeout_task(struct net_device *netdev)
 24.1488 +{
 24.1489 +	struct e1000_adapter *adapter = netdev->priv;
 24.1490 +
 24.1491 +	netif_device_detach(netdev);
 24.1492 +	e1000_down(adapter);
 24.1493 +	e1000_up(adapter);
 24.1494 +	netif_device_attach(netdev);
 24.1495 +}
 24.1496 +
 24.1497 +/**
 24.1498 + * e1000_get_stats - Get System Network Statistics
 24.1499 + * @netdev: network interface device structure
 24.1500 + *
 24.1501 + * Returns the address of the device statistics structure.
 24.1502 + * The statistics are actually updated from the timer callback.
 24.1503 + **/
 24.1504 +
 24.1505 +static struct net_device_stats *
 24.1506 +e1000_get_stats(struct net_device *netdev)
 24.1507 +{
 24.1508 +	struct e1000_adapter *adapter = netdev->priv;
 24.1509 +
 24.1510 +	return &adapter->net_stats;
 24.1511 +}
 24.1512 +
 24.1513 +/**
 24.1514 + * e1000_change_mtu - Change the Maximum Transfer Unit
 24.1515 + * @netdev: network interface device structure
 24.1516 + * @new_mtu: new value for maximum frame size
 24.1517 + *
 24.1518 + * Returns 0 on success, negative on failure
 24.1519 + **/
 24.1520 +
 24.1521 +static int
 24.1522 +e1000_change_mtu(struct net_device *netdev, int new_mtu)
 24.1523 +{
 24.1524 +	struct e1000_adapter *adapter = netdev->priv;
 24.1525 +	int old_mtu = adapter->rx_buffer_len;
 24.1526 +	int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
 24.1527 +
 24.1528 +	if((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
 24.1529 +	   (max_frame > MAX_JUMBO_FRAME_SIZE)) {
 24.1530 +		E1000_ERR("Invalid MTU setting\n");
 24.1531 +		return -EINVAL;
 24.1532 +	}
 24.1533 +
 24.1534 +	if(max_frame <= MAXIMUM_ETHERNET_FRAME_SIZE) {
 24.1535 +		adapter->rx_buffer_len = E1000_RXBUFFER_2048;
 24.1536 +
 24.1537 +	} else if(adapter->hw.mac_type < e1000_82543) {
 24.1538 +		E1000_ERR("Jumbo Frames not supported on 82542\n");
 24.1539 +		return -EINVAL;
 24.1540 +
 24.1541 +	} else if(max_frame <= E1000_RXBUFFER_4096) {
 24.1542 +		adapter->rx_buffer_len = E1000_RXBUFFER_4096;
 24.1543 +
 24.1544 +	} else if(max_frame <= E1000_RXBUFFER_8192) {
 24.1545 +		adapter->rx_buffer_len = E1000_RXBUFFER_8192;
 24.1546 +
 24.1547 +	} else {
 24.1548 +		adapter->rx_buffer_len = E1000_RXBUFFER_16384;
 24.1549 +	}
 24.1550 +
 24.1551 +	if(old_mtu != adapter->rx_buffer_len && netif_running(netdev)) {
 24.1552 +
 24.1553 +		e1000_down(adapter);
 24.1554 +		e1000_up(adapter);
 24.1555 +	}
 24.1556 +
 24.1557 +	netdev->mtu = new_mtu;
 24.1558 +	adapter->hw.max_frame_size = max_frame;
 24.1559 +
 24.1560 +	return 0;
 24.1561 +}
 24.1562 +
 24.1563 +/**
 24.1564 + * e1000_update_stats - Update the board statistics counters
 24.1565 + * @adapter: board private structure
 24.1566 + **/
 24.1567 +
 24.1568 +static void
 24.1569 +e1000_update_stats(struct e1000_adapter *adapter)
 24.1570 +{
 24.1571 +	struct e1000_hw *hw = &adapter->hw;
 24.1572 +	unsigned long flags;
 24.1573 +	uint16_t phy_tmp;
 24.1574 +
 24.1575 +#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
 24.1576 +
 24.1577 +	spin_lock_irqsave(&adapter->stats_lock, flags);
 24.1578 +
 24.1579 +	/* these counters are modified from e1000_adjust_tbi_stats,
 24.1580 +	 * called from the interrupt context, so they must only
 24.1581 +	 * be written while holding adapter->stats_lock
 24.1582 +	 */
 24.1583 +
 24.1584 +	adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
 24.1585 +	adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
 24.1586 +	adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
 24.1587 +	adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
 24.1588 +	adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
 24.1589 +	adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
 24.1590 +	adapter->stats.roc += E1000_READ_REG(hw, ROC);
 24.1591 +	adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
 24.1592 +	adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
 24.1593 +	adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
 24.1594 +	adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
 24.1595 +	adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
 24.1596 +	adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
 24.1597 +
 24.1598 +	spin_unlock_irqrestore(&adapter->stats_lock, flags);
 24.1599 +
 24.1600 +	/* the rest of the counters are only modified here */
 24.1601 +
 24.1602 +	adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
 24.1603 +	adapter->stats.mpc += E1000_READ_REG(hw, MPC);
 24.1604 +	adapter->stats.scc += E1000_READ_REG(hw, SCC);
 24.1605 +	adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
 24.1606 +	adapter->stats.mcc += E1000_READ_REG(hw, MCC);
 24.1607 +	adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
 24.1608 +	adapter->stats.dc += E1000_READ_REG(hw, DC);
 24.1609 +	adapter->stats.sec += E1000_READ_REG(hw, SEC);
 24.1610 +	adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
 24.1611 +	adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
 24.1612 +	adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
 24.1613 +	adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
 24.1614 +	adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
 24.1615 +	adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
 24.1616 +	adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
 24.1617 +	adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
 24.1618 +	adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
 24.1619 +	adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
 24.1620 +	adapter->stats.ruc += E1000_READ_REG(hw, RUC);
 24.1621 +	adapter->stats.rfc += E1000_READ_REG(hw, RFC);
 24.1622 +	adapter->stats.rjc += E1000_READ_REG(hw, RJC);
 24.1623 +	adapter->stats.torl += E1000_READ_REG(hw, TORL);
 24.1624 +	adapter->stats.torh += E1000_READ_REG(hw, TORH);
 24.1625 +	adapter->stats.totl += E1000_READ_REG(hw, TOTL);
 24.1626 +	adapter->stats.toth += E1000_READ_REG(hw, TOTH);
 24.1627 +	adapter->stats.tpr += E1000_READ_REG(hw, TPR);
 24.1628 +	adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
 24.1629 +	adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
 24.1630 +	adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
 24.1631 +	adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
 24.1632 +	adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
 24.1633 +	adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
 24.1634 +	adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
 24.1635 +	adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
 24.1636 +
 24.1637 +	/* used for adaptive IFS */
 24.1638 +
 24.1639 +	hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
 24.1640 +	adapter->stats.tpt += hw->tx_packet_delta;
 24.1641 +	hw->collision_delta = E1000_READ_REG(hw, COLC);
 24.1642 +	adapter->stats.colc += hw->collision_delta;
 24.1643 +
 24.1644 +	if(hw->mac_type >= e1000_82543) {
 24.1645 +		adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
 24.1646 +		adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
 24.1647 +		adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
 24.1648 +		adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
 24.1649 +		adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
 24.1650 +		adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
 24.1651 +	}
 24.1652 +
 24.1653 +	/* Fill out the OS statistics structure */
 24.1654 +
 24.1655 +	adapter->net_stats.rx_packets = adapter->stats.gprc;
 24.1656 +	adapter->net_stats.tx_packets = adapter->stats.gptc;
 24.1657 +	adapter->net_stats.rx_bytes = adapter->stats.gorcl;
 24.1658 +	adapter->net_stats.tx_bytes = adapter->stats.gotcl;
 24.1659 +	adapter->net_stats.multicast = adapter->stats.mprc;
 24.1660 +	adapter->net_stats.collisions = adapter->stats.colc;
 24.1661 +
 24.1662 +	/* Rx Errors */
 24.1663 +
 24.1664 +	adapter->net_stats.rx_errors = adapter->stats.rxerrc +
 24.1665 +		adapter->stats.crcerrs + adapter->stats.algnerrc +
 24.1666 +		adapter->stats.rlec + adapter->stats.rnbc +
 24.1667 +		adapter->stats.mpc + adapter->stats.cexterr;
 24.1668 +	adapter->net_stats.rx_dropped = adapter->stats.rnbc;
 24.1669 +	adapter->net_stats.rx_length_errors = adapter->stats.rlec;
 24.1670 +	adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
 24.1671 +	adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
 24.1672 +	adapter->net_stats.rx_fifo_errors = adapter->stats.mpc;
 24.1673 +	adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
 24.1674 +
 24.1675 +	/* Tx Errors */
 24.1676 +
 24.1677 +	adapter->net_stats.tx_errors = adapter->stats.ecol +
 24.1678 +	                               adapter->stats.latecol;
 24.1679 +	adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
 24.1680 +	adapter->net_stats.tx_window_errors = adapter->stats.latecol;
 24.1681 +	adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
 24.1682 +
 24.1683 +	/* Tx Dropped needs to be maintained elsewhere */
 24.1684 +
 24.1685 +	/* Phy Stats */
 24.1686 +
 24.1687 +	if(hw->media_type == e1000_media_type_copper) {
 24.1688 +		if((adapter->link_speed == SPEED_1000) &&
 24.1689 +		   (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
 24.1690 +			phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
 24.1691 +			adapter->phy_stats.idle_errors += phy_tmp;
 24.1692 +		}
 24.1693 +
 24.1694 +		if((hw->mac_type <= e1000_82546) &&
 24.1695 +		   !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
 24.1696 +			adapter->phy_stats.receive_errors += phy_tmp;
 24.1697 +	}
 24.1698 +}
 24.1699 +
 24.1700 +/**
 24.1701 + * e1000_irq_disable - Mask off interrupt generation on the NIC
 24.1702 + * @adapter: board private structure
 24.1703 + **/
 24.1704 +
 24.1705 +static inline void
 24.1706 +e1000_irq_disable(struct e1000_adapter *adapter)
 24.1707 +{
 24.1708 +	atomic_inc(&adapter->irq_sem);
 24.1709 +	E1000_WRITE_REG(&adapter->hw, IMC, ~0);
 24.1710 +	E1000_WRITE_FLUSH(&adapter->hw);
 24.1711 +	synchronize_irq();
 24.1712 +}
 24.1713 +
 24.1714 +/**
 24.1715 + * e1000_irq_enable - Enable default interrupt generation settings
 24.1716 + * @adapter: board private structure
 24.1717 + **/
 24.1718 +
 24.1719 +static inline void
 24.1720 +e1000_irq_enable(struct e1000_adapter *adapter)
 24.1721 +{
 24.1722 +	if(atomic_dec_and_test(&adapter->irq_sem)) {
 24.1723 +		E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
 24.1724 +		E1000_WRITE_FLUSH(&adapter->hw);
 24.1725 +	}
 24.1726 +}
 24.1727 +
 24.1728 +/**
 24.1729 + * e1000_intr - Interrupt Handler
 24.1730 + * @irq: interrupt number
 24.1731 + * @data: pointer to a network interface device structure
 24.1732 + * @pt_regs: CPU registers structure
 24.1733 + **/
 24.1734 +
 24.1735 +static void
 24.1736 +e1000_intr(int irq, void *data, struct pt_regs *regs)
 24.1737 +{
 24.1738 +	struct net_device *netdev = data;
 24.1739 +	struct e1000_adapter *adapter = netdev->priv;
 24.1740 +	uint32_t icr;
 24.1741 +	int i = E1000_MAX_INTR;
 24.1742 +
 24.1743 +	while(i && (icr = E1000_READ_REG(&adapter->hw, ICR))) {
 24.1744 +
 24.1745 +		if(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
 24.1746 +			adapter->hw.get_link_status = 1;
 24.1747 +			mod_timer(&adapter->watchdog_timer, jiffies);
 24.1748 +		}
 24.1749 +
 24.1750 +		e1000_clean_rx_irq(adapter);
 24.1751 +		e1000_clean_tx_irq(adapter);
 24.1752 +		i--;
 24.1753 +
 24.1754 +	}
 24.1755 +}
 24.1756 +
 24.1757 +/**
 24.1758 + * e1000_clean_tx_irq - Reclaim resources after transmit completes
 24.1759 + * @adapter: board private structure
 24.1760 + **/
 24.1761 +
 24.1762 +static void
 24.1763 +e1000_clean_tx_irq(struct e1000_adapter *adapter)
 24.1764 +{
 24.1765 +	struct e1000_desc_ring *tx_ring = &adapter->tx_ring;
 24.1766 +	struct net_device *netdev = adapter->netdev;
 24.1767 +	struct pci_dev *pdev = adapter->pdev;
 24.1768 +	struct e1000_tx_desc *tx_desc;
 24.1769 +	int i;
 24.1770 +
 24.1771 +	i = tx_ring->next_to_clean;
 24.1772 +	tx_desc = E1000_TX_DESC(*tx_ring, i);
 24.1773 +
 24.1774 +	while(tx_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
 24.1775 +
 24.1776 +		if(tx_ring->buffer_info[i].dma) {
 24.1777 +
 24.1778 +			pci_unmap_page(pdev,
 24.1779 +			               tx_ring->buffer_info[i].dma,
 24.1780 +			               tx_ring->buffer_info[i].length,
 24.1781 +			               PCI_DMA_TODEVICE);
 24.1782 +
 24.1783 +			tx_ring->buffer_info[i].dma = 0;
 24.1784 +		}
 24.1785 +
 24.1786 +		if(tx_ring->buffer_info[i].skb) {
 24.1787 +
 24.1788 +			dev_kfree_skb_any(tx_ring->buffer_info[i].skb);
 24.1789 +
 24.1790 +			tx_ring->buffer_info[i].skb = NULL;
 24.1791 +		}
 24.1792 +
 24.1793 +		tx_desc->upper.data = 0;
 24.1794 +
 24.1795 +		i = (i + 1) % tx_ring->count;
 24.1796 +		tx_desc = E1000_TX_DESC(*tx_ring, i);
 24.1797 +	}
 24.1798 +
 24.1799 +	tx_ring->next_to_clean = i;
 24.1800 +
 24.1801 +	if(netif_queue_stopped(netdev) && netif_carrier_ok(netdev) &&
 24.1802 +	   (E1000_DESC_UNUSED(tx_ring) > E1000_TX_QUEUE_WAKE)) {
 24.1803 +
 24.1804 +		netif_wake_queue(netdev);
 24.1805 +	}
 24.1806 +}
 24.1807 +
 24.1808 +/**
 24.1809 + * e1000_clean_rx_irq - Send received data up the network stack,
 24.1810 + * @adapter: board private structure
 24.1811 + **/
 24.1812 +
 24.1813 +static void
 24.1814 +e1000_clean_rx_irq(struct e1000_adapter *adapter)
 24.1815 +{
 24.1816 +	struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
 24.1817 +	struct net_device *netdev = adapter->netdev;
 24.1818 +	struct pci_dev *pdev = adapter->pdev;
 24.1819 +	struct e1000_rx_desc *rx_desc;
 24.1820 +	struct sk_buff *skb;
 24.1821 +	unsigned long flags;
 24.1822 +	uint32_t length;
 24.1823 +	uint8_t last_byte;
 24.1824 +	int i;
 24.1825 +
 24.1826 +	i = rx_ring->next_to_clean;
 24.1827 +	rx_desc = E1000_RX_DESC(*rx_ring, i);
 24.1828 +
 24.1829 +	while(rx_desc->status & E1000_RXD_STAT_DD) {
 24.1830 +
 24.1831 +		pci_unmap_single(pdev,
 24.1832 +		                 rx_ring->buffer_info[i].dma,
 24.1833 +		                 rx_ring->buffer_info[i].length,
 24.1834 +		                 PCI_DMA_FROMDEVICE);
 24.1835 +
 24.1836 +		skb = rx_ring->buffer_info[i].skb;
 24.1837 +		length = le16_to_cpu(rx_desc->length);
 24.1838 +
 24.1839 +		if(!(rx_desc->status & E1000_RXD_STAT_EOP)) {
 24.1840 +
 24.1841 +			/* All receives must fit into a single buffer */
 24.1842 +
 24.1843 +			E1000_DBG("Receive packet consumed multiple buffers\n");
 24.1844 +
 24.1845 +			dev_kfree_skb_irq(skb);
 24.1846 +			rx_desc->status = 0;
 24.1847 +			rx_ring->buffer_info[i].skb = NULL;
 24.1848 +
 24.1849 +			i = (i + 1) % rx_ring->count;
 24.1850 +
 24.1851 +			rx_desc = E1000_RX_DESC(*rx_ring, i);
 24.1852 +			continue;
 24.1853 +		}
 24.1854 +
 24.1855 +		if(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK) {
 24.1856 +
 24.1857 +			last_byte = *(skb->data + length - 1);
 24.1858 +
 24.1859 +			if(TBI_ACCEPT(&adapter->hw, rx_desc->status,
 24.1860 +			              rx_desc->errors, length, last_byte)) {
 24.1861 +
 24.1862 +				spin_lock_irqsave(&adapter->stats_lock, flags);
 24.1863 +
 24.1864 +				e1000_tbi_adjust_stats(&adapter->hw,
 24.1865 +				                       &adapter->stats,
 24.1866 +				                       length, skb->data);
 24.1867 +
 24.1868 +				spin_unlock_irqrestore(&adapter->stats_lock,
 24.1869 +				                       flags);
 24.1870 +				length--;
 24.1871 +			} else {
 24.1872 +
 24.1873 +				dev_kfree_skb_irq(skb);
 24.1874 +				rx_desc->status = 0;
 24.1875